locallib.php 333 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067
  1. <?php
  2. /**
  3. * This class provides all the functionality for an ia (interactive activities).
  4. *
  5. * Release Notes:
  6. * - v 4.9.3 2020/01/16
  7. * + Several fixes to allow to move activities in a block and improvements in repository and to appear comment submission button
  8. *
  9. * - v 4.9.2 2019/03/13
  10. * + Several fixes to allow iLM under HTML stack
  11. *
  12. * - v 4.9.1 2017/11/02
  13. * + Fixed a bug with iGeom script - the view was not loading the CEO with activity (resulting in an error "Erro ao gravar na base de dados")
  14. * + function view_iassign_current(): it were inserted 2 'if(substr($ilm_name,0,5)=="igeom") if($iassign_statement_activity_item->special_param1==1) $lTA=true;' to call '$ilm->view_iLM(...lTA)'
  15. *
  16. * - v 4.9 2017/03/13
  17. * + Great number of changes to allow the use o iVProgH5 (e.g. function changed: from 'applet_ilm' to 'build_ilm_tags')
  18. *
  19. * - v 4.8 2016/05/12
  20. * + Function add_to_log() is deprecated it was then rewritten to the new events API
  21. * + Resolved: the field "description" table "iassign_ilm" was being filled with the codes in HTML when importing magnet package and
  22. * due to this the language field was not being displayed because in place of the quotes was recorded in the & quot field.
  23. * ("$description_str = htmlentities(str_replace(array('<description>','</description>'), array('',''), $application_xml->description->asXML()));"
  24. * replaced by
  25. * "description_str = str_replace(array('<description>','</description>'), array('',''), $application_xml->description->asXML());")
  26. * - v 4.7 2016/02/17
  27. * + Moodle 3.X: now iAssign is working fine under version 3.X (iassign/version.php: '$module->' changed to '$plugin->'; iassign/locallib.php: 'format_text(...)' replaced 'filter_text(...)')
  28. * + Improved: now is possible to see the iGeom menus in preview (from iAssign Repository) - it depends on the version 1.3 of iAssign filter!
  29. * + Improved: new names for 'form.input.MA_POST_Archive' and 'form.input.MA_POST_Value', now: 'iLM_PARAM_ArchiveContent' and 'iLM_PARAM_ActivityEvaluation'
  30. * + BUG fixed: now it is fine the "online" edition of activities (in iAssign Repository) - inserted 'iLM_PARAM_Authoring' (iLM 2) and 'MA_POST_ArchiveTeacher' (iLM 1)
  31. * + BUG fixed: it is possible to change the name of any file in iAssign Repository - problems was in 'optional_param(...)', 'PARAM_TEXT' replaced 'PARAM_ALPHANUMEXT'
  32. * + BUG fixed: it is possible to duplicate any file in iAssign Repository - problems also in 'optional_param(...)', 'PARAM_TEXT' replaced 'PARAM_ALPHANUMEXT'
  33. * + BUG fixed: now is possible to edit an iAssign activity with no new object been created (in iGeom: turn an example in exercise)
  34. *
  35. * --------------- (code bellow was used at our MOOC 2014)
  36. * - v 4.6 2014/02/25
  37. * + Fix bugs in filter function for open applets.
  38. * - v 4.5 2014/02/24
  39. * + Fix bugs in params.
  40. * + Insert new param type.
  41. * - v 4.4 2014/01/24
  42. * + Allow select type of params.
  43. * + Insert the use of applet params specific for activities.
  44. * - v 4.3 2014/01/23
  45. * + Insert function for move activities for other iLM (ilm_settings::confirm_move_iassign, ilm_settings::move_iassign).
  46. * - v 4.2 2016/02/13
  47. * + Fixed API usage to work fine under Moodle 3.X: ilm_editor_new()
  48. * --------------- (above code used at our MOOC 2014)
  49. *
  50. * - v 4.1 2013/12/13
  51. * + Insert log in iAssign actions.
  52. * + Allow use the language in iLM description (ilm_settings::new_file_ilm, ilm_settings::new_ilm, ilm_settings::edit_ilm, ilm_settings::copy_new_version_ilm, ilm_settings::add_edit_copy_ilm, iassign_language::get_description_lang, iassign_language::get_all_lang).
  53. * + Insert class for Log actions in system.
  54. * - v 4.0 2013/10/31
  55. * + Insert support of export iLM in zip packages (ilm_settings::export_ilm).
  56. * + Insert support of import iLM from zip packages (ilm_settings::import_ilm).
  57. * + Fix bugs in message alert in iassign title and remove message alert of the description by cache error.
  58. * - v 3.9 2013/10/25
  59. * + Insert support of upgrade iLM.
  60. * + Insert support for more than one extension in iLM.
  61. * + Fix bugs in verion control.
  62. * - v 3.8 2013/09/19
  63. * + Get data of general fields in iassign statement table (iassign::add_edit_iassign).
  64. * - v 3.7 2013/09/12
  65. * + Change tag APPLET in all functions of module (ilm::view_iLM, ilm_manager::ilm_editor_new, ilm_manager::ilm_editor_update).
  66. * + Insert tool for manage aditional params for iLM (ilm_settings::add_edit_copy_param, ilm_settings::visible_param, ilm_settings::add_param, ilm_settings::edit_param, ilm_settings::copy_param, ilm_settings::delete_param).
  67. * - v 3.6 2013/09/05
  68. * + Insert function ilm_settings::applet_ilm for create APPLET html tag.
  69. * + Insert function ilm_settings::applet_filetime for get modified date of iLM file.
  70. * + Change tag APPLET in function ilm_settings::view_ilm.
  71. * - v 3.5 2013/08/26
  72. * + Fix bug in download package iassign without answers (iassign::report).
  73. * - v 3.4 2013/08/23
  74. * + Fix bug in export package iassign.
  75. * - v 3.3 2013/08/22
  76. * + Insert functions for export users answer in iassign (iassign::export_file_answer, iassign::export_package_answer, iassign::view_iassign_current, iassign::report).
  77. * + Insert function for rename iassign file (ilm_manager::rename_file_ilm, ilm_manager::view_files_ilm).
  78. * - v 3.2 2013/08/21
  79. * + Change title link with message for get file for donwload file (ilm_manager::view_files_ilm).
  80. * + Change functions for import files for ilm_manager.php.
  81. * + Create static utils class for functions system utils (iassign_utils::format_filename, iassign_utils::version_filename).
  82. * - v 3.1 2013/08/15
  83. * + Change return file selected (ilm_manager::add_ilm).
  84. * + Insert functions for import files, export files and remove selected files (ilm_manager::view_files_ilm, ilm_manager::import_files_ilm, ilm_manager::export_files_ilm, ilm_manager::delete_selected_ilm).
  85. * - v 3.0 2013/08/02
  86. * + Insert link for view informations of iLMs in teacher view, same screen of admin view but wiht some features hide (ilm_settings::list_ilm, ilm_settings::view_ilm, iassign::view_iassigns).
  87. * - v 2.9 2013/08/01
  88. * + Fix bugs in functions ilm_settings::new_file_ilm, ilm_settings::copy_new_version_ilm, ilm_settings::add_edit_copy_ilm.
  89. * - v 2.8 2013/07/25
  90. * + Insert the activity name in header of view (activity::view_dates).
  91. * + Set function default iLM in view iLMs versions (ilm_settings::default_ilm and ilm_settings::confirm_default_ilm).
  92. * - v 2.7 2013/07/24
  93. * + Create link previous and next for student view in one activity (activity::view_dates).
  94. * + Fix bugs for view error in iLM not on DB in function iassign::view_iassign_current.
  95. * - v 2.6 2013/07/23
  96. * + Fix bugs for view files in function ilm_manager::view_files_ilm.
  97. * + Fix bugs for comment on teacher view in function iassign::view_iassign_current.
  98. * - v 2.5 2013/07/12
  99. * + Change iLM settings for accept versions (ilm_settings::new_file_ilm, ilm_settings::new_ilm, ilm_settings::edit_ilm, ilm_settings::copy_new_version_ilm).
  100. * + Insert new informations in iLMs table: created date, modified date, author, version, modified date of JAR (ilm_settings::view_ilm).
  101. * + Added support for PHP 7.0 Constructors and fallback for previous Moodle Versions (<3.1) - Márcio
  102. *
  103. * @author Patricia Alves Rodrigues
  104. * @author Leônidas O. Brandão
  105. * @contributor Igor Moreira Félix (2018-)
  106. * @contributor Márcio de Lima Passos (2014)
  107. * @version v 4.9.2 2019/03/13
  108. * @version v 4.8 2016/05/12
  109. * @package mod_iassign_lib
  110. * @since 2010/09/27
  111. * @copyright iMath (http://www.matematica.br) and LInE (http://line.ime.usp.br) - Computer Science Dep. of IME-USP (Brazil)
  112. *
  113. * <b>License</b>
  114. * - http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  115. */
  116. //TODO Review: eliminate iLM JAR under MoodleData? It is necessary to HTML5 packages (like iVProgH5), anyway
  117. //TODO Whenever under HTTPS, verify if MoodleData is working, if it is not, please use iLM JAR under WWW setting $CONF_WWW = 1
  118. //TODO (under HTTPS could fail 'pluginfile', like 'https://saw.atp.usp.br/pluginfile.php/1/mod_iassign/ilm/182563135/iassign/ilm/igeom/5920/iGeom.jar"'
  119. $CONF_WWW = 1; //TODO get iLM (JAR) from WWW, avoiding MoodleData
  120. /**
  121. * Standard base class for all iAssign
  122. */
  123. class iassign {
  124. var $cm;
  125. var $course;
  126. var $iassign;
  127. var $striassign;
  128. var $striassigns;
  129. var $context;
  130. var $activity;
  131. var $iassign_up;
  132. var $iassign_down;
  133. var $action;
  134. var $iassign_submission_current;
  135. var $userid_iassign;
  136. var $bottonPost;
  137. var $write_solution;
  138. var $view_iassign;
  139. // 3.1 update PHP 7.0 compatibility for all moodle versions
  140. //D public function iassign($iassign, $cm, $course) { self::__construct($iassign, $cm, $course); }
  141. /// Constructor for the base iassign class
  142. // @calledby ./mod/iassign/view.php : $iassigninstance = new iassign($iassign, $cm, $course)
  143. // @calledby ./mod/iassign/grade.php : $iassigninstance = new iassign($iassign, $cm, $course);
  144. // @calledby ./mod/iassign/renderer.php : return $this->render(new iassign_files($context, $itemid, $filearea));
  145. function __construct ($iassign, $cm, $course) {
  146. global $COURSE, $CFG, $USER, $DB;
  147. $botton = optional_param('botton', NULL, PARAM_TEXT);
  148. $this->userid_iassign = optional_param('userid_iassign', 0, PARAM_INT);
  149. if (!is_null($botton))
  150. $USER->iassignEdit = $botton;
  151. // The Moodle function 'optional_param(...)' allow to filter GET parameters over a click that launches, e.g., './mod/iassign/view.php&userid_iassign=6'
  152. // If "$var1 = optional_param('userid_iassign', 'NOT', PARAM_TEXT);", $var1 will be set to 6 (if 'userid_iassign' is not present, $var1 will be set to 'NOT'
  153. $this->iassign_up = optional_param('iassign_up', 0, PARAM_INT); // if parameter 'iassign_up' does not exists or it is not integer => use 0 as "default"
  154. $this->iassign_down = optional_param('iassign_down', 0, PARAM_INT);
  155. $this->iassign_submission_current = optional_param('iassign_submission_current', 0, PARAM_INT);
  156. $this->write_solution = optional_param('write_solution', 0, PARAM_INT);
  157. $this->action = optional_param('action', NULL, PARAM_TEXT);
  158. $this->cm = $cm;
  159. $this->context = context_module::instance($this->cm->id);
  160. if (!has_capability('mod/iassign:evaluateiassign', $this->context, $USER->id))
  161. $this->userid_iassign = $USER->id;
  162. if ($course) {
  163. $this->course = $course;
  164. }
  165. else if ($this->cm->course == $COURSE->id) {
  166. $this->course = $COURSE;
  167. }
  168. else if (!$this->course = $DB->get_record('course', array('id' => $this->cm->course))) {
  169. print_error('invalidid', 'iassign');
  170. }
  171. $this->coursecontext = context_course::instance($this->course->id);
  172. if ($iassign) {
  173. $this->iassign = $iassign;
  174. }
  175. else if (!$this->iassign = $DB->get_record('iassign', array('id' => $this->cm->instance))) {
  176. print_error('invalidid', 'iassign');
  177. }
  178. $USER->context = context_module::instance($this->cm->id);
  179. $USER->cm = $this->cm->id;
  180. $this->iassign->cmidnumber = $this->cm->idnumber; // compatibility with modedit ia obj
  181. $this->iassign->courseid = $this->course->id; // compatibility with modedit ia obj
  182. $this->context = context_module::instance($this->cm->id);
  183. $this->striassign = get_string('modulename', 'iassign');
  184. $this->striassigns = get_string('modulenameplural', 'iassign');
  185. $this->return = $CFG->wwwroot . "/mod/iassign/view.php?id=" . $this->cm->id;
  186. $this->bottonPost = 0;
  187. $this->view_iassign = optional_param('action', false, PARAM_BOOL);
  188. $this->activity = new activity(optional_param('iassign_current', NULL, PARAM_TEXT));
  189. $this->view();
  190. } // function __construct($iassign, $cm, $course)
  191. /// Show iAssign by using the security filter (temporary data on '*_iassign_security')
  192. // This method provides the page to view each iLM with any interactive activity
  193. // @calledby view.php : $iassigninstance->view($id); that instantiate 'iassign' (constructor above)
  194. function view () { // This is an standard function for each iAssign instance (to not use parameters, it is ignored)
  195. global $USER, $DB, $OUTPUT;
  196. // $iassign_statementid = $this->iassign->iassign_statementid;
  197. if ($this->activity!=null && $this->activity->get_activity()!=null && isset($this->activity->get_activity()->id))
  198. $iassign_statementid = $this->activity->get_activity()->id;
  199. else
  200. $iassign_statementid = "";
  201. // '$this' has : iassign Object = cm ; course ; iassign ; striassign ; striassigns ; context ; activity ; iassign_up ; iassign_down ; action ; ... ; coursecontext ; return
  202. // If this user has no capability to View 'iassign': stop here
  203. require_capability('mod/iassign:view', $this->context);
  204. // Trigger module view event
  205. $event = \mod_iassign\event\course_module_viewed::create(array(
  206. 'objectid' => $this->iassign->id,
  207. 'context' => $this->context
  208. ));
  209. $event->add_record_snapshot('course', $this->course);
  210. $event->trigger();
  211. if ($this->action) { // when student do/redo activity or teacher see student solution
  212. $this->action(); // calls '$this->view_iLM();'
  213. }
  214. else {
  215. print $OUTPUT->header();
  216. $this->view_iassigns(); // show the iLM with the content
  217. print $OUTPUT->footer();
  218. }
  219. // Security: delete all records with an error loading iLM - 'iassign_security : id iassign_statementid userid file timecreated view'
  220. //D $DB->delete_records("iassign_security", array("userid" => $USER->id, "view" => 1));
  221. //D $iassign_iLM_security = $DB->get_record("iassign_security", array("iassign_statementid" => $iassign_statementid));
  222. //D foreach ($iassign_iLM_security as $item) { echo $iassign_iLM_security->id . " ; " . $iassign_iLM_security->iassign_statementid . " ; " . $iassign_iLM_security->userid . " ; " . $iassign_iLM_security->timecreated . " ; " . $iassign_iLM_security->view . " ; " . $iassign_iLM_security->file . "<br/>\n" }
  223. $DB->delete_records("iassign_security", array("userid" => $USER->id, "iassign_statementid" => $iassign_statementid));
  224. //D $iassign_iLM_security = $DB->get_record("iassign_security", array("iassign_statementid" => $iassign_statementid));
  225. //D if ($iassign_iLM_security) foreach ($iassign_iLM_security as $item) { echo $iassign_iLM_security->id . " ; " . $iassign_iLM_security->iassign_statementid . " ; " . $iassign_iLM_security->userid . " ; " . $iassign_iLM_security->timecreated . " ; " . $iassign_iLM_security->view . " ; " . $iassign_iLM_security->file . "<br/>\n" }
  226. //D else echo "Apagou!<br/>";
  227. die();
  228. } // function view()
  229. /// Execute the action from Moodle (move, make visible, register the exercise (teacher) or its answer (learner)...)
  230. function action () {
  231. global $USER;
  232. // action:
  233. // up - move up activity (mover atividade para cima)
  234. // down - move down activity (mover atividade para baixo)
  235. // visible - view/hide activity (exibir/ocultar atividade)
  236. // delete - delete activity (excluir atividade)
  237. // deleteyes - confirms exclusion of activity (confirma exclusão de atividade)
  238. // deleteno - does not erase activity (não apaga atividade)
  239. // add - add activity (adicionar atividade)
  240. // edit - edit activity (modificar atividade)
  241. $action_iassign = array(
  242. 'newcomment' => '$this->get_answer();',
  243. 'view' => '$this->view_iassign_current();',
  244. 'get_answer' => '$this->get_answer();',
  245. 'repeat' => '$this->view_iassign_current();',
  246. 'overwrite' => '$this->get_answer();',
  247. 'stats_student' => '$this->stats_students();',
  248. 'download_answer' => '$this->export_file_answer();',
  249. 'download_all_answer' => '$this->export_package_answer();');
  250. $action_iassign_limit = array(
  251. 'view' => '$this->view_iassign_current();',
  252. 'newcomment' => '$this->get_answer();',
  253. 'viewsubmission' => '$this->view_iassign_current();',
  254. 'edit_status' => '$this->edit_status();',
  255. 'edit_grade' => '$this->edit_grade();',
  256. 'export_csv' => '$this->export_csv();',
  257. 'report' => '$this->report();',
  258. 'print' => '$this->report();',
  259. 'stats' => '$this->stats();',
  260. 'printstats' => '$this->stats();');
  261. $restricted = array('firstdown' => '$this->activity->move_iassign("firstdown", $this->iassign_down, $this->return);',
  262. 'up' => '$this->activity->move_iassign("up", $this->iassign_up, $this->return);',
  263. 'down' => '$this->activity->move_iassign("down", $this->iassign_down, $this->return);',
  264. 'visible' => '$this->activity->visible_iassign($this->return);',
  265. 'delete' => '$this->activity->delete($this->return);',
  266. 'deleteno' => '$this->return_home_course("confirm_not_delete_iassign");',
  267. 'deleteyes' => '$this->activity->deleteyes($this->return, $this);',
  268. 'add' => '$this->add_edit_iassign();',
  269. 'edit' => '$this->add_edit_iassign();',
  270. 'get_answer' => '$this->get_answer();',
  271. 'duplicate_activity' => '$this->duplicate_activity();',
  272. 'move_activity' => '$this->move_activity();',
  273. 'auto_evaluate' => '$this->auto_evaluate();');
  274. $action_iassign_restricted = array_merge($restricted, $action_iassign_limit, $action_iassign);
  275. // On depends the user's capability: precedence to edit power ('editiassign'); after to analyse ('evaluateiassign'); otherwise only view (any other).
  276. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id)) { //xxxxxxxxxxxxxxxxxxxxxxxxxxx
  277. // When teacher is seeing student solution. By 'viewsubmission' goes to the function 'view_iassign_current()'
  278. eval($action_iassign_restricted[$this->action]); // Now load 'view_iassign_current()' with 'viewsubmission' or 'new_iassign($param)' by '$this->add_edit_iassign()'
  279. }
  280. elseif (has_capability('mod/iassign:evaluateiassign', $this->context, $USER->id)) {
  281. eval($action_iassign_limit[$this->action]);
  282. }
  283. else { // Student reaches this point
  284. // When student do/redo activity: do => action = "view"; redo => action = "repeat"
  285. // Arrive here with: "get_answer"; "view"
  286. if (isset($action_iassign[$this->action])) // avoid error if non capable user try direct acess
  287. eval($action_iassign[$this->action]); // Now load 'view_iassign_current()' with 'view'
  288. }
  289. } // function action()
  290. /// This method runs activities auto evaluation in teacher area
  291. function auto_evaluate () {
  292. global $COURSE, $CFG, $USER, $DB, $OUTPUT;
  293. if (!has_capability('mod/iassign:runautoevaluate', $USER->context, $USER->id))
  294. exit;
  295. print $OUTPUT->header();
  296. print $OUTPUT->footer();
  297. }
  298. /// This method moves an iAssign activity
  299. function move_activity () {
  300. global $USER, $CFG, $DB, $COURSE;
  301. $iassign_id = optional_param('iassign_current', NULL, PARAM_TEXT);
  302. $iassign_destiny = optional_param('iassign_destiny', NULL, PARAM_TEXT);
  303. $update_entry_new_iassign = new stdClass();
  304. $update_entry_new_iassign->id = $iassign_id;
  305. $update_entry_new_iassign->iassignid = $iassign_destiny;
  306. // Update the iassign_statement
  307. $DB->update_record("iassign_statement", $update_entry_new_iassign);
  308. // Update file context
  309. $c_i = context_module::instance($this->cm->id);
  310. $ret = get_coursemodule_from_id("iassign", $c_i->instanceid);
  311. $course_module_info = $DB->get_record("course_modules", array("course" => $COURSE->id, "module" => $ret->module, "instance" => $iassign_destiny));
  312. $path_module = context_course::instance($COURSE->id);
  313. $context_file = $DB->get_record_sql('SELECT * FROM {context} WHERE instanceid="' . $course_module_info->id . '" AND path like "'.$path_module->path.'%"');
  314. if ($context_file) {
  315. $id_context = $context_file->id;
  316. $iassign_statement = $DB->get_record("iassign_statement", array("id" => $iassign_id));
  317. $fs = get_file_storage(); // Get reference to all files in Moodle data
  318. $files = $fs->get_area_files(context_module::instance($this->cm->id)->id, 'mod_iassign', 'exercise', $iassign_statement->file);
  319. foreach ($files as $value) {
  320. if ($value->get_filename() != ".") {
  321. $last_id = $DB->get_record_sql('SELECT itemid FROM {files} WHERE component="mod_iassign" ORDER BY itemid DESC LIMIT 1')->itemid;
  322. $newfile = $fs->create_file_from_storedfile(array('contextid' => $id_context, 'component' => 'mod_iassign', 'filearea' => 'exercise', 'itemid' => ($last_id + 1)), $value);
  323. $updateentry = new stdClass();
  324. $updateentry->id = $iassign_id;
  325. $updateentry->file = $newfile->get_itemid();
  326. $DB->update_record("iassign_statement", $updateentry);
  327. $fs->delete_area_files(context_module::instance($this->cm->id)->id, 'mod_iassign', 'exercise', $value->get_itemid());
  328. break;
  329. }
  330. }
  331. }
  332. $this->return_home_course('moved_activity');
  333. exit;
  334. }
  335. /// This method duplicates an iAssign activity
  336. function duplicate_activity () {
  337. global $USER, $CFG, $COURSE, $DB, $OUTPUT;
  338. $id = $this->cm->id;
  339. $iassignid = optional_param('iassign_current', NULL, PARAM_TEXT);
  340. $context = context_module::instance($this->cm->id);
  341. $contextuser = context_user::instance($USER->id);
  342. // Get the the iAssign acitivity to be duplicated
  343. $iassign_statement = $DB->get_record("iassign_statement", array("id" => $iassignid));
  344. // Remove the current id of activity
  345. $iassign_statement->id=0;
  346. // Get the information about current author, and add this information in author_modified field
  347. $author = $DB->get_record("user", array('id' => $USER->id));
  348. $iassign_statement->author_modified_name = $author->firstname . '&nbsp;' . $author->lastname;
  349. $iassign_statement->author_modified = $iassign_statement->author_modified_name;
  350. // Store the activity in the table
  351. if ($id_ = $DB->insert_record("iassign_statement", $iassign_statement)) {
  352. // Duplicate activity file
  353. $fs = get_file_storage(); // Get reference to all files in Moodle data
  354. $files = $fs->get_area_files($context->id, 'mod_iassign', 'exercise', $iassign_statement->file);
  355. foreach ($files as $value) {
  356. if ($value->get_filename() != ".") {
  357. $last_id = $DB->get_record_sql('SELECT itemid FROM {files} WHERE component="mod_iassign" ORDER BY itemid DESC LIMIT 1')->itemid;
  358. $newfile = $fs->create_file_from_storedfile(array('contextid' => $context->id, 'component' => 'mod_iassign', 'filearea' => 'exercise', 'itemid' => ($last_id + 1)), $value);
  359. $updateentry = new stdClass();
  360. $updateentry->id = $id_;
  361. $updateentry->file = $newfile->get_itemid();
  362. // Update the duplicated iLM iAssign with new file id
  363. $DB->update_record("iassign_statement", $updateentry);
  364. }
  365. }
  366. }
  367. // log event --------------------------------------------------------------------------------------
  368. iassign_log::add_log('duplicate_iassign_exercise', 'name: ' . $author->firstname, $id_, $this->cm->id);
  369. $this->return_home_course('duplicated_activity');
  370. exit;
  371. }
  372. /// This method gets the content from the iLM and register it
  373. // It could be the "exercise template" (teacher) or an answer (student)
  374. function get_answer () {
  375. global $USER, $CFG, $DB, $OUTPUT;
  376. $id = $this->cm->id;
  377. $submission_comment = optional_param('submission_comment', NULL, PARAM_TEXT);
  378. $comment = false;
  379. if ($submission_comment)
  380. $comment = $this->write_comment_submission();
  381. // receives data of iLM using the current activity
  382. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $this->activity->get_activity()->iassign_ilmid)); // has automatic evaluation?
  383. $iassign = $DB->get_record("iassign", array("id" => $this->activity->get_activity()->iassignid)); // activity
  384. // receives data of submission of current activity
  385. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $this->activity->get_activity()->id, "userid" => $this->userid_iassign)); // data about student solution
  386. // receives post and get
  387. $iLM_PARAM_ActivityEvaluation = optional_param('iLM_PARAM_ActivityEvaluation', 0, PARAM_INT); // 1 - activity evaluated as correct / 0 - activity evaluated as incorrect
  388. $iLM_PARAM_RealGrade = optional_param('iLM_PARAM_RealGrade', 0, PARAM_FLOAT);
  389. //2016/02/16: IMPORTANTE trocar formatador para "nao formatado", pois esta destruindo o conteudo do arquivo
  390. $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)
  391. $MA_POST_Info = optional_param('MA_POST_Info', NULL, PARAM_FORMAT);
  392. $MA_POST_SystemData = optional_param('MA_POST_SystemData', NULL, PARAM_FORMAT);
  393. $return_get_answer = optional_param('return_get_answer', 0, PARAM_INT);
  394. $msg = '';
  395. // Feedback
  396. // Activity status: 0 => not post 1; => post; 2 => evaluated as incorrect; 3 => evaluated as correct
  397. $str_action = "view"; // repeat
  398. if (strtolower($iassign_ilm->name) == "igeom") {
  399. }
  400. $title = get_string('evaluate_iassign', 'iassign');
  401. print $OUTPUT->header();
  402. print $OUTPUT->box_start();
  403. // Action = { view ; repeat ; viewsubmission }
  404. // * '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")
  405. // * 'repeat' => student explicitly requested to redo the activiy or enter in the last submission under iLM other then iGeom
  406. // * 'viewsubmission' => teacher/non editing teacher seeing the learner's activity
  407. $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;
  408. $return_last = "&nbsp;<a href='" . $return . "'>" . iassign_icons::insert('return_home') . '&nbsp;' . get_string('return_iassign', 'iassign') . "</a>";
  409. $link_return = "&nbsp;<a href='" . $this->return . "'>" . iassign_icons::insert('home') . '&nbsp;' . get_string('activities_page', 'iassign') . "</a>";
  410. print '<table width=100% >';
  411. if ($iLM_PARAM_ArchiveContent == - 1 || empty($iLM_PARAM_ArchiveContent)) { // if ($iLM_PARAM_ActivityEvaluation == -1)
  412. //TODO alterar aqui???
  413. $this->write_solution = 0; // necessary in order to take note in Moodle 'grade' system
  414. // empty_answer_post = No solution was posted.
  415. if ($comment)
  416. print '<tr><td colspan=2><br>' . get_string('empty_answer_post', 'iassign') . '</br>' . get_string('confirm_add_comment', 'iassign') . '</td>';
  417. else
  418. print '<tr><td colspan=2><br>' . get_string('empty_answer_post', 'iassign') . '</td>';
  419. print '<tr><td width=40% align=right>' . $return_last . '&nbsp;' . $link_return . '</td></tr>';
  420. } else {
  421. if ($iassign_ilm->evaluate == 1 && $this->activity->get_activity()->automatic_evaluate == 1) { // iLM with automatic evaluator
  422. if (intval($iLM_PARAM_ActivityEvaluation) == 1) {
  423. // Correct answer!!
  424. //TODO apelei - o melhor e' alterar acima o 'write_solution=0'?
  425. $this->write_solution = 1; //
  426. $status = 3;
  427. $grade_student = $iLM_PARAM_RealGrade; // evaluated as correct solution submitted is assigned the note pattern of activity
  428. $msg = '<tr><td colspan=2>' . iassign_icons::insert('feedback_correct') . '<br>' . get_string('get_answer_correct', 'iassign') . '</td>';
  429. // log record
  430. $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;
  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 { // else if (intval($iLM_PARAM_ActivityEvaluation) == 1)
  440. // Wrong answer...: get_answer_incorrect
  441. $status = 2;
  442. $grade_student = $iLM_PARAM_RealGrade; // evaluated as incorrect solution
  443. $msg = '<tr><td colspan=2>' . iassign_icons::insert('feedback_incorrect') . '<br>' . get_string('get_answer_incorrect', 'iassign') . '</td>';
  444. // log record
  445. $info = $iassign->name . "&nbsp;-&nbsp;" . $this->activity->get_activity()->name . "&nbsp;-&nbsp;" . get_string('feedback_incorrect', 'iassign') .
  446. '&nbsp;-&nbsp;' . get_string('grade_iassign', 'iassign') . $grade_student;
  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 if (intval($iLM_PARAM_ActivityEvaluation) == 1)
  456. // Presents to the learner the result of the automatic evaluate?
  457. if ($this->activity->get_activity()->show_answer == 0) { // no...
  458. print '<tr><td width=60% ><strong>' . iassign_icons::insert('post') . get_string('get_answer', 'iassign') . '</strong></td>';
  459. print '<tr><td width=40% align=right>' . $return_last . '&nbsp;' . $link_return . '</td></tr>';
  460. print '<tr>';
  461. // log record
  462. $info = $iassign->name . "&nbsp;-&nbsp;" . $this->activity->get_activity()->name . "&nbsp;-&nbsp;" . get_string('get_answer', 'iassign');
  463. // Trigger module viewed event.
  464. $event = \mod_iassign\event\submission_created::create(array(
  465. 'objectid' => $this->iassign->id,
  466. 'context' => $this->context,
  467. 'other' => $info
  468. ));
  469. $event->add_record_snapshot('course', $this->course);
  470. $event->trigger();
  471. } else { // yes!!!
  472. print '<tr><td width=60% ><strong>' . get_string('auto_result', 'iassign') . '</strong></td>';
  473. print '<td width=40% align=right>' . $return_last . '&nbsp;' . $link_return . '</td></tr>';
  474. print '<tr>';
  475. print $msg;
  476. }
  477. } else { // if ($iassign_ilm->evaluate == 1 && $this->activity->get_activity()->automatic_evaluate == 1)
  478. $status = 1;
  479. $grade_student = $iLM_PARAM_RealGrade; // iLM not have automatic evaluator
  480. print '<tr><td colspan=2>' . iassign_icons::insert('post') . get_string('get_answer_post', 'iassign') . '</td>';
  481. print '<tr><td width=40% align=right>' . $return_last . '&nbsp;' . $link_return . '</td></tr>';
  482. print '<tr>';
  483. // log record
  484. $info = $iassign->name . "&nbsp;-&nbsp;" . $this->activity->get_activity()->name . "&nbsp;-&nbsp;" . get_string('get_answer_post', 'iassign');
  485. $event = \mod_iassign\event\submission_created::create(array(
  486. 'objectid' => $this->iassign->id,
  487. 'context' => $this->context,
  488. 'other' => $info
  489. ));
  490. $event->add_record_snapshot('course', $this->course);
  491. $event->trigger();
  492. } // if ($iassign_ilm->evaluate == 1)
  493. } // if ($iLM_PARAM_ActivityEvaluation == -1)
  494. print '</tr></table>';
  495. print $OUTPUT->box_end();
  496. // add or update evaluate
  497. if ($this->write_solution == 1) {
  498. $timenow = time();
  499. // new record
  500. if (!$iassign_submission) {
  501. $newentry = new stdClass();
  502. $newentry->userid = $this->userid_iassign;
  503. // $newentry->userid = $USER->id;
  504. $newentry->iassign_statementid = $this->activity->get_activity()->id;
  505. $newentry->timecreated = $timenow;
  506. $newentry->timemodified = $timenow;
  507. $newentry->answer = $iLM_PARAM_ArchiveContent;
  508. $newentry->grade = $grade_student;
  509. $newentry->status = $status;
  510. $newentry->experiment = 1;
  511. if (!$newentry->id = $DB->insert_record("iassign_submission", $newentry)) {
  512. print_error('error_insert', 'iassign');
  513. } else {
  514. // Trigger module viewed event.
  515. $event = \mod_iassign\event\submission_created::create(array(
  516. 'objectid' => $this->iassign->id,
  517. 'context' => $this->context
  518. ));
  519. $event->add_record_snapshot('course', $this->course);
  520. $event->trigger();
  521. $this->update_grade_student($newentry->userid, $newentry->iassign_statementid, $this->iassign->id);
  522. }
  523. } elseif ($iassign_submission->status != 3) {
  524. $newentry = new stdClass();
  525. $newentry->id = $iassign_submission->id;
  526. $newentry->iassign_statementid = $iassign_submission->iassign_statementid;
  527. $newentry->userid = $iassign_submission->userid;
  528. $newentry->timecreated = $iassign_submission->timecreated;
  529. $newentry->timemodified = $timenow;
  530. $newentry->answer = $iLM_PARAM_ArchiveContent;
  531. $newentry->grade = $grade_student;
  532. $newentry->status = $status;
  533. $newentry->experiment = $iassign_submission->experiment + 1;
  534. if (!$DB->update_record("iassign_submission", $newentry)) {
  535. print_error('error_update', 'iassign');
  536. //D depurar...
  537. //D $stringAux = "ia.class.php: ".$iLM_PARAM_ArchiveContent."<br/> ".utf8_encode($iLM_PARAM_ArchiveContent)."<br/>".utf8_encode(utf8_encode($iLM_PARAM_ArchiveContent))."<br/>";
  538. //D $fp = fopen("teste1.txt","w");
  539. //D fwrite($fp,$stringAux);
  540. } else {
  541. // Trigger module viewed event.
  542. $event = \mod_iassign\event\submission_updated::create(array(
  543. 'objectid' => $this->iassign->id,
  544. 'context' => $this->context
  545. ));
  546. $event->add_record_snapshot('course', $this->course);
  547. $this->update_grade_student($newentry->userid, $newentry->iassign_statementid, $this->iassign->id);
  548. }
  549. } else {
  550. if ($return_get_answer == 1) {
  551. $newentry = new stdClass();
  552. $newentry->id = $iassign_submission->id;
  553. $newentry->iassign_statementid = $iassign_submission->iassign_statementid;
  554. $newentry->userid = $iassign_submission->userid;
  555. $newentry->timecreated = $iassign_submission->timecreated;
  556. $newentry->timemodified = $timenow;
  557. $newentry->answer = $iLM_PARAM_ArchiveContent;
  558. $newentry->grade = $grade_student;
  559. $newentry->status = $status;
  560. $newentry->experiment = $iassign_submission->experiment + 1;
  561. if (!$DB->update_record("iassign_submission", $newentry))
  562. print_error('error_update', 'iassign');
  563. else {
  564. $event = \mod_iassign\event\submission_updated::create(array(
  565. 'objectid' => $this->iassign->id,
  566. 'context' => $this->context
  567. ));
  568. $event->add_record_snapshot('course', $this->course);
  569. $event->trigger();
  570. $this->update_grade_student($newentry->userid, $newentry->iassign_statementid, $this->iassign->id);
  571. print $OUTPUT->box_start();
  572. print "<p>" . get_string('iassign_update', 'iassign') . "</p>";
  573. print $OUTPUT->box_end();
  574. }
  575. } elseif ($return_get_answer == 2) {
  576. print $OUTPUT->box_start();
  577. print "<p>" . get_string('iassign_cancel', 'iassign') . "</p>";
  578. print $OUTPUT->box_end();
  579. } else {
  580. print $OUTPUT->box_start();
  581. print "
  582. <script type='text/javascript'>
  583. //<![CDATA[
  584. function overwrite () {
  585. document.formEnvio.return_get_answer.value = 1;
  586. document.formEnvio.submit();
  587. }
  588. function nooverwrite () {
  589. document.formEnvio.return_get_answer.value = 2;
  590. document.formEnvio.submit();
  591. }
  592. //]]>
  593. </script>";
  594. $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;
  595. $get_answer_overwrite = $CFG->wwwroot . "/mod/iassign/view.php?" . $param_aux;
  596. print "<form name='formEnvio' method='post' action='$get_answer_overwrite' enctype='multipart/form-data'>";
  597. print "<p>" . get_string('last_iassign_correct', 'iassign') . "</p>";
  598. print "<p>" . get_string('update_iassign', 'iassign') . "</p>";
  599. print "<input type='hidden' name='iLM_PARAM_ArchiveContent' value='$iLM_PARAM_ArchiveContent'/>
  600. <input type='hidden' name='iLM_PARAM_ActivityEvaluation' value='$iLM_PARAM_ActivityEvaluation'/>
  601. <input type='hidden' name='MA_POST_Info' value='$MA_POST_Info'/>
  602. <input type='hidden' name='MA_POST_SystemData' value='$MA_POST_SystemData'/>
  603. <input type='hidden' name='return_get_answer'/> ";
  604. print "<input type=button value='" . get_string('yes', 'iassign') . "' onClick = 'overwrite()'
  605. title='" . get_string('message_update_iassign', 'iassign') . "'/>&nbsp;&nbsp;";
  606. print "<input type=button value='" . get_string('no', 'iassign') . "' onClick = 'nooverwrite()'
  607. title='" . get_string('message_no_update_iassign', 'iassign') . "'/>";
  608. print " </form>";
  609. print $OUTPUT->box_end();
  610. }
  611. }
  612. } // if ($this->write_solution == 1)
  613. print $OUTPUT->footer();
  614. die();
  615. } // function get_answer()
  616. /// Export in file the answer of student.
  617. function export_file_answer () {
  618. global $DB;
  619. $iassign_submission_id = optional_param('iassign_submission_id', NULL, PARAM_INT);
  620. $iassign_submission = $DB->get_record("iassign_submission", array("id" => $iassign_submission_id));
  621. $iassign_statement = $DB->get_record("iassign_statement", array("id" => $iassign_submission->iassign_statementid));
  622. $name = iassign_utils::format_filename(strip_tags($iassign_statement->name));
  623. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $iassign_statement->iassign_ilmid));
  624. $extensions = explode(",", $iassign_ilm->extension);
  625. $iassign_user = $DB->get_record("user", array("id" => $iassign_submission->userid));
  626. $username = iassign_utils::format_filename($iassign_user->firstname . ' ' . $iassign_user->lastname);
  627. $name_answer = $username . '-' . $name . '-' . userdate($iassign_submission->timemodified, '%Y%m%d-%H%M') . '.' . $extensions[0];
  628. header("Pragma: public");
  629. header("Expires: 0");
  630. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  631. header("Cache-Control: private", false);
  632. header("Content-Type: document/unknown");
  633. header("Content-Disposition: attachment; filename=\"" . $name_answer . "\";");
  634. set_time_limit(0);
  635. print($iassign_submission->answer);
  636. exit;
  637. } // function export_file_answer()
  638. /// Prepare data to static exportation (with course name, iAsssing block name, and exercices names
  639. // @calledby $this->export_package_answer()
  640. //TODO Precisa terminar! //TODO_HTML
  641. function htmlcode_2_export ($course_fullname, $course_id, $iassign_block_id, $iassign_block_name, $array_iassign_name, $array_iassign_id, $userid, $username) {
  642. $str_html = "<html dir='ltr' lang='pt-br' xml:lang='pt-br'>
  643. <head>
  644. <title>" . get_string('pluginname', 'iassign') . "</title>\n"; // 'iAssign: interactive Learning Activities'
  645. $str_html .= " </head>
  646. <body>\n";
  647. $tam = sizeof($array_iassign_name);
  648. for ($ii=0; $ii<$tam; $ii++) {
  649. //TODO_HTML completar construir HTML com titulo do exercicio e talvez legar com HTML para abri-lo com o iMA
  650. }
  651. $str_html .= "
  652. </body>\n</html>";
  653. return $str_html;
  654. }
  655. /// Export an package (zip) with all answer of students
  656. // @calledby $this->action()
  657. function export_package_answer () {
  658. global $DB, $CFG, $OUTPUT;
  659. $iassign_id = optional_param('iassign_id', NULL, PARAM_INT); // ID of iAssign block of activities
  660. $iassign = $DB->get_record("iassign", array("id" => $iassign_id)); // all data from this block of iAssign activities (table '*_iassign')
  661. $iassign_block_name = iassign_utils::format_filename($iassign->name);
  662. //TODO_HTML $this->course: [fullname] => Curso teste [shortname] => cursoteste1 [idnumber]
  663. //TODO_HTML //echo "<br/>" . $iassign->name . ": <br/>";
  664. $userid = optional_param('userid', NULL, PARAM_INT);
  665. $iassign_user = $DB->get_record("user", array("id" => $userid));
  666. $username = iassign_utils::format_filename($iassign_user->firstname . '_' . $iassign_user->lastname); // user information
  667. //TODO_HTML echo "username=$username<br/>"; exit;
  668. $current_date = date('Y_m_d_H');
  669. $diretorio = $CFG->dataroot . DIRECTORY_SEPARATOR . 'temp' . DIRECTORY_SEPARATOR . 'files' . DIRECTORY_SEPARATOR; // /var/<moodledata>/temp/files/
  670. // If temporary directory under Moodle data does not exists => create it
  671. if (!is_dir($diretorio)) {
  672. mkdir($diretorio, 0755, true); // permissions: drwxr-xr-x
  673. // created directory with permissions to be seen by everyone
  674. }
  675. $zip_filename = $diretorio . 'package_iassign_' . $username . '-' . $iassign_block_name . '_' . $current_date . '.zip';
  676. if (!is_writable($diretorio)) { // send a highlighted message!
  677. print_error('error_answer_export_dir', 'iassign'); // Error: the target directory has no permission! Please, send this message to the Moodle admin!
  678. exit; // just in case
  679. }
  680. //MOOC 2014: $zip_filename = $CFG->dataroot . '/temp/ilm-' . iassign_utils::format_pathname($iassign_ilm->name . '-v' . $iassign_ilm->version) . '.ipz';
  681. $zip = new zip_archive(); // create ZIP
  682. $zip->open($zip_filename); // open ZIP using the temporary file/directory
  683. $iassign_statements = $DB->get_records("iassign_statement", array("iassignid" => $iassign_id));
  684. //TODO $vet_exerc_title = array(); //TODO to be used with 'htmlcode_2_export(...)' - missing: build the HTML and directories linking files
  685. $vet_student_filename = array();
  686. $vet_student_content = array();
  687. foreach ($iassign_statements as $iassign_statement) {
  688. $activity_name = iassign_utils::format_filename(strip_tags($iassign_statement->name));
  689. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $iassign_statement->iassign_ilmid));
  690. //TODO_HTML $vet_exerc_title[] = $iassign_statement->name;
  691. $extensions = explode(",", $iassign_ilm->extension);
  692. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $iassign_statement->id, "userid" => $userid));
  693. if ($iassign_submission) {
  694. $timemodified = '-' . userdate($iassign_submission->timemodified, '%Y_%m_%d_%H_%M');
  695. $student_content = $iassign_submission->answer;
  696. $student_filename = iassign_utils::format_filename($activity_name) . $timemodified . '.' . $extensions[0];
  697. $resp = $zip->add_file_from_string($student_filename, $student_content); // add file to ZIP
  698. //$resp = $zip->add_file_from_string($path_dir . $one_file, $destination . $ds . $one_file); //2 Esta versao funciona!
  699. if ($resp) {
  700. $vet_student_filename[] = $student_filename;
  701. $vet_student_content[] = $student_content;
  702. }
  703. else { // send a highlighted message!
  704. print_error('error_answer_export_file', 'iassign'); // Error: fail to insert content to the file
  705. exit; // just in case
  706. }
  707. }
  708. }
  709. $zip->close(); // close the ZIP file
  710. if (count($vet_student_filename)>0) {
  711. $vet_result = iassign_utils::register_temporary_file($zip_filename, $vet_student_filename, $vet_student_content);
  712. $result_tf = $vet_result[0];
  713. $filenameZip = $vet_result[1]->filename;
  714. }
  715. iassign_utils::download_file($zip_filename); // download the ZIP file
  716. exit;
  717. } // function export_package_answer()
  718. /// Editing status of interactive activities
  719. function edit_status () {
  720. global $USER, $DB, $OUTPUT;
  721. $newentry = new stdClass();
  722. $newentry->id = $this->iassign_submission_current;
  723. $newentry->status = optional_param('return_status', 0, PARAM_INT);
  724. $iassign_submission = $DB->get_record('iassign_submission', array('id' => $this->iassign_submission_current));
  725. if ($iassign_submission->status != 0 && $newentry->status == 0)
  726. $newentry->status = $iassign_submission->status;
  727. $newentry->teacher = $USER->id;
  728. if (!$DB->update_record('iassign_submission', $newentry))
  729. print_error('error_update', 'iassign');
  730. else {
  731. // Trigger module viewed event.
  732. $event = \mod_iassign\event\submission_updated::create(array(
  733. 'objectid' => $this->iassign->id,
  734. 'context' => $this->context
  735. ));
  736. $event->add_record_snapshot('course', $this->course);
  737. $event->trigger();
  738. $this->action = 'viewsubmission';
  739. $this->view_iassign_current();
  740. } // if (!$DB->update_record('iassign_submission', $newentry))
  741. } // function edit_status()
  742. /// Editing grade of interactive activities
  743. function edit_grade () {
  744. global $USER, $DB, $OUTPUT;
  745. $newgrade = optional_param('return_grade', 0, PARAM_INT);
  746. if ($newgrade && $newgrade >= 0) {
  747. $newentry = new stdClass();
  748. $newentry->id = $this->iassign_submission_current;
  749. $newentry->grade = optional_param('return_grade', 0, PARAM_INT);
  750. $newentry->teacher = $USER->id;
  751. if (!$DB->update_record('iassign_submission', $newentry))
  752. print_error('error_update', 'iassign');
  753. else {
  754. // Trigger module viewed event.
  755. $event = \mod_iassign\event\submission_updated::create(array(
  756. 'objectid' => $this->iassign->id,
  757. 'context' => $this->context
  758. ));
  759. $event->add_record_snapshot('course', $this->course);
  760. $event->trigger();
  761. }
  762. } // if ($newgrade >= 0)
  763. $this->action = 'viewsubmission';
  764. $this->view_iassign_current();
  765. }
  766. /// Add or Edit interactive activities
  767. // @calledby $this->action()
  768. function add_edit_iassign () {
  769. global $USER, $CFG, $COURSE, $DB, $OUTPUT;
  770. require_once('iassign_form.php');
  771. $id = $this->cm->id;
  772. $iassignid = $this->iassign->id;
  773. $param = new stdClass();
  774. $param->action = $this->action; // oculto
  775. $param->id = $id; // oculto
  776. $COURSE->cm = $id;
  777. $COURSE->iassignid = $iassignid;
  778. $COURSE->iassign_file_id = NULL;
  779. $context = context_module::instance($this->cm->id);
  780. $contextuser = context_user::instance($USER->id);
  781. $component = 'mod_iassign';
  782. $filearea = 'exercise';
  783. if (!empty($this->iassign_current))
  784. $COURSE->iassign_id = $this->iassign_current;
  785. else
  786. $COURSE->iassign_id = 0;
  787. $total_of_activities = 0; // get the total number of activities in this iAssign block
  788. if ($this->action == 'add') {
  789. $iassign_data = $DB->get_record("iassign", array('id' => $iassignid));
  790. $total_of_activities = count($iassign_data);
  791. $params = array('iassignid' => $iassignid);
  792. $query_str = "SELECT s.id, s.name, s.dependency FROM {iassign_statement} s WHERE s.iassignid = :iassignid ORDER BY s.position ASC";
  793. $iassign_statement = $DB->get_records_sql($query_str, $params); //
  794. $param->iassignid = $iassignid;
  795. $param->name = "";
  796. $param->oldname = "";
  797. $param->type_iassign = 3;
  798. $param->proposition = "";
  799. $author = $DB->get_record("user", array("id" => $USER->id));
  800. $param->author_name = $author->firstname . '&nbsp;' . $author->lastname;
  801. $param->author_modified_name = $author->firstname . '&nbsp;' . $author->lastname;
  802. $param->author = $param->author_name;
  803. $param->author_modified = $param->author_modified_name;
  804. $COURSE->iassign_list = array();
  805. $param->iassign_list = array();
  806. if ($iassign_statement) {
  807. foreach ($iassign_statement as $iassign) {
  808. $iassignid = $iassign->id;
  809. $param->iassign_list[$iassignid] = 0;
  810. $COURSE->iassign_list[$iassignid] = new stdClass();
  811. $COURSE->iassign_list[$iassignid]->id = $iassignid;
  812. $COURSE->iassign_list[$iassignid]->name = $iassign->name;
  813. $COURSE->iassign_list[$iassignid]->enable = 1;
  814. } // foreach ($iassign_statement as $iassign)
  815. }
  816. $param->iassign_ilmid = 0;
  817. //echo "locallib.php: add_edit_iassign(): add<br/>";
  818. $param->file = 0;
  819. $param->fileold = 0;
  820. $param->filename = "";
  821. $param->grade = $iassign_data->grade;
  822. $param->timemodified = time();
  823. $param->timecreated = time();
  824. $param->timeavailable = $iassign_data->timeavailable;
  825. $param->timedue = $iassign_data->timedue;
  826. $param->preventlate = $iassign_data->preventlate;
  827. $param->test = $iassign_data->test;
  828. $param->special_param1 = 0;
  829. $param->visible = 1;
  830. $param->max_experiment = $iassign_data->max_experiment;
  831. $param->dependency = 0;
  832. $param->automatic_evaluate = 1;
  833. $param->show_answer = 1;
  834. } // if ($this->action == 'add')
  835. elseif ($this->action == 'edit') {
  836. $COURSE->iassign_list = array();
  837. $this_activity = $this->activity->get_activity();
  838. if ($this_activity != null) {
  839. //2019 $iassign_statement_current = $DB->get_record("iassign_statement", array("id" => $this_activity->id));
  840. $iassign_statement_current = $this_activity; // $DB->get_record("iassign_statement", array("id" => $this_activity->id));
  841. $param->iassign_id = $iassign_statement_current->id; // oculto
  842. $param->iassignid = $iassign_statement_current->iassignid; // oculto
  843. $param->name = $iassign_statement_current->name;
  844. $param->oldname = $iassign_statement_current->name;
  845. $param->type_iassign = $iassign_statement_current->type_iassign;
  846. //2019: Moodle 3 uses proposition in 'textarea' as "('text' => <text>, 'format' => '')
  847. //2019 $param->proposition = $iassign_statement_current->proposition;
  848. $param->proposition = array('text' => $iassign_statement_current->proposition, ''); //'format' => $instance->introformat
  849. $param->author_name = $iassign_statement_current->author_name; // oculto
  850. $param->author = $iassign_statement_current->author_name;
  851. $author = $DB->get_record("user", array('id' => $USER->id));
  852. $param->author_modified_name = $author->firstname . '&nbsp;' . $author->lastname;
  853. $param->author_modified = $param->author_modified_name;
  854. $dependency = explode(';', $iassign_statement_current->dependency);
  855. $param->iassign_list = array();
  856. $str_query = "SELECT * FROM {iassign_statement} s WHERE s.iassignid = '$iassignid' AND s.id!='$iassign_statement_current->id' AND s.dependency!=0";
  857. $iassign_statement_dependency = $DB->get_records_sql($str_query);
  858. $array_dependency = array();
  859. $subdependency = "";
  860. $sub_subdependency = "";
  861. // dependent on this exercise
  862. if ($iassign_statement_dependency) {
  863. $subdependency .= $this->search_dependency($iassign_statement_current->id, $iassign_statement_dependency);
  864. // to whom this exercise depends
  865. foreach ($inter as $tmp)
  866. $sub_subdependency .= $this->search_sub_dependency($tmp);
  867. $list_dependency = $subdependency . $sub_subdependency;
  868. $array_dependency = explode(";", $list_dependency);
  869. }
  870. // Get all activity with the same iLM - iassignid
  871. $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";
  872. $all_others_iassign_statement = $DB->get_records_sql($str_query);
  873. $total_of_activities = count($all_others_iassign_statement) + 1;
  874. $inter = array();
  875. if ($all_others_iassign_statement) {
  876. foreach ($all_others_iassign_statement as $iassign)
  877. if (in_array($iassign->id, $dependency))
  878. $inter[] = $iassign->id;
  879. }
  880. if ($all_others_iassign_statement) {
  881. foreach ($all_others_iassign_statement as $iassign) {
  882. $iassignid = $iassign->id;
  883. $COURSE->iassign_list[$iassignid] = new stdClass();
  884. $COURSE->iassign_list[$iassignid]->name = $iassign->name;
  885. $COURSE->iassign_list[$iassignid]->id = $iassignid;
  886. if (in_array($iassignid, $dependency))
  887. $param->iassign_list[$iassignid] = 1;
  888. else
  889. $param->iassign_list[$iassignid] = 0;
  890. if (in_array($iassignid, $array_dependency))
  891. $COURSE->iassign_list[$iassignid]->enable = 0;
  892. else
  893. $COURSE->iassign_list[$iassignid]->enable = 1;
  894. } // foreach ($all_others_iassign_statement as $iassign)
  895. }
  896. $param->iassign_ilmid = $iassign_statement_current->iassign_ilmid;
  897. $param->fileold = 0;
  898. $param->file = 0; //TODO Criar campo 'iassign_statement.filesid' para registar 'files.id' - abaixo faz '$file->get_id();'
  899. $param->filename = '';
  900. $param->grade = $iassign_statement_current->grade;
  901. $param->timecreated = $iassign_statement_current->timecreated; // oculto
  902. $param->timeavailable = $iassign_statement_current->timeavailable;
  903. $param->timedue = $iassign_statement_current->timedue;
  904. $param->preventlate = $iassign_statement_current->preventlate;
  905. $param->test = $iassign_statement_current->test;
  906. $param->special_param1 = $iassign_statement_current->special_param1;
  907. $param->position = $iassign_statement_current->position; // oculto
  908. $param->visible = $iassign_statement_current->visible;
  909. $param->max_experiment = $iassign_statement_current->max_experiment;
  910. $param->automatic_evaluate = $iassign_statement_current->automatic_evaluate;
  911. $param->show_answer = $iassign_statement_current->show_answer;
  912. $fs = get_file_storage(); // Get reference to all files in Moodle data
  913. $files = $fs->get_area_files($context->id, $component, $filearea, $iassign_statement_current->file);
  914. if ($files) {
  915. foreach ($files as $file) {
  916. if ($file->get_filename() != '.') {
  917. $param->filename = $file->get_filename();
  918. $param->file = $file->get_id();
  919. $param->fileold = $file->get_id();
  920. $COURSE->iassign_file_id = $file->get_id();
  921. }
  922. }
  923. }
  924. //TODO //MOOC2014 -- inicio
  925. //D $iassign_ilm_configs = $DB->get_records('iassign_statement_config', array('iassign_statementid' => $iassign_statement_current->id));
  926. //D if ($iassign_ilm_configs) {
  927. //D foreach ($iassign_ilm_configs as $iassign_ilm_config)
  928. //D $param->{'param_'.$iassign_ilm_config->iassign_ilm_configid} = $iassign_ilm_config->param_value;
  929. //D } //MOOC2014 -- fim
  930. } // if ($this_activity != null)
  931. } // elseif ($this->action == 'edit')
  932. // Get all iActivity in the iAssign block with id = $this->iassign->id
  933. // It could be used to define dependency of the current activity (considering those list $iassign_list)
  934. $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array($this->iassign->id), 'position ASC');
  935. //D echo "locallib.php: add_edit_iassign(): this->iassign->id=" . $this->iassign->id . "<br/>";
  936. //D foreach ($iassign_list as $item) echo " - id=" . $item->id . ", name=" . $item->name . ", iassignid=" . $item->iassignid . ", type_iassign=" . $item->type_iassign . "<br/>";
  937. // if ($iassign_list) { $end_list = array_pop($iassign_list); $param->position = $end_list->position + 1; } else $param->position = 1;
  938. $param->position = $total_of_activities;
  939. $mform = new mod_iassign_form(null, null, null, null, array('id'=>'mform1'));
  940. $mform->set_data($param);
  941. if ($mform->is_cancelled()) {
  942. $this->return_home_course('iassign_cancel');
  943. exit;
  944. }
  945. else { // if ($mform->is_cancelled())
  946. $result = $mform->get_data();
  947. // echo "locallib.php: add_edit_iassign(): result="; print_r($result); echo "<br/>";
  948. if ($result) {
  949. $result->context = $context;
  950. if ($result->type_iassign == 1 || $result->type_iassign == 2)
  951. $result->grade = 0;
  952. if ($result->type_iassign == 1) {
  953. $result->automatic_evaluate = 0;
  954. $result->show_answer = 0;
  955. }
  956. elseif ($result->automatic_evaluate == 0)
  957. $result->show_answer = 0;
  958. // $_POST['iassign_list']
  959. $result->iassign_list = optional_param_array('iassign_list', array(), PARAM_RAW);
  960. if ($result->iassign_list) {
  961. foreach ($result->iassign_list as $key => $value)
  962. $result->dependency .= $key . ';';
  963. }
  964. else
  965. $result->dependency = 0;
  966. //TODO I used in 'iassign_form.php' '<select name='iassign_ilmid'...>' with 'optgroup' by hand! But MoodleForm clear/do not register the 'iassign_ilmid'
  967. //TODO Then get it directly from the form data $_POST!
  968. //TODO See: 'iassign_form.php' field 'iassign_ilmid' and here 'function new_iassign($param)'
  969. if (!isset($result->iassign_ilmid) && isset($_POST['iassign_ilmid']))
  970. $result->iassign_ilmid = $_POST['iassign_ilmid'];
  971. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $result->iassign_ilmid));
  972. if ($this->action == 'add') {
  973. $iassign_statement_name = $DB->get_records('iassign_statement', array('iassignid' => $result->iassignid, 'name' => $result->name));
  974. if ($iassign_statement_name) {
  975. $this->return_home_course('error_iassign_name');
  976. die();
  977. }
  978. // Really insert the new iActivity in table '*_iassign_statement'
  979. $iassignid = $this->activity->new_iassign($result); // class activity : function new_iassign($param)
  980. $this->activity->add_calendar($iassignid); ///line 3584 of /mod/iassign/locallib.php: call to calendar_event::create()
  981. // Trigger module viewed event.
  982. $event = \mod_iassign\event\iassign_created::create(array(
  983. 'objectid' => $iassignid,
  984. 'context' => $context
  985. ));
  986. $event->add_record_snapshot('course', $this->course);
  987. $event->trigger();
  988. $this->return_home_course('iassign_add');
  989. } // if ($this->action == 'add')
  990. elseif ($this->action == 'edit') {
  991. $iassignid = $this->activity->update_iassign($result);
  992. $this->activity->update_calendar($iassignid, $result->oldname);
  993. // Trigger module viewed event.
  994. $event = \mod_iassign\event\iassign_updated::create(array(
  995. 'objectid' => $iassignid,
  996. 'context' => $context
  997. ));
  998. $event->add_record_snapshot('course', $this->course);
  999. $event->trigger();
  1000. $this->return_home_course('iassign_update');
  1001. } // elseif ($this->action == 'edit')
  1002. die();
  1003. } // if ($result)
  1004. } // else if ($mform->is_cancelled())
  1005. print $OUTPUT->header();
  1006. $mform->display();
  1007. print $OUTPUT->footer();
  1008. die();
  1009. } // function add_edit_iassign()
  1010. /// Search for dependencies
  1011. function search_dependency ($search_iassing_id, $iassign_statement) {
  1012. global $DB, $OUTPUT;
  1013. $dependency = "";
  1014. if ($iassign_statement)
  1015. foreach ($iassign_statement as $iassign) {
  1016. $inter_dependency = explode(';', $iassign->dependency);
  1017. if (in_array($search_iassing_id, $inter_dependency)) {
  1018. $dependency .= $iassign->id . ";";
  1019. $dependency .= $this->search_dependency($iassign->id, $iassign_statement);
  1020. } // if (in_array($search_iassing_id, $inter_dependency))
  1021. } // foreach ($iassign_statement as $iassign)
  1022. return $dependency;
  1023. }
  1024. /// Search for "sub"dependency
  1025. function search_sub_dependency ($search_iassing_id) {
  1026. global $DB, $OUTPUT;
  1027. $iassign_statement = $DB->get_record("iassign_statement", array("id" => $search_iassing_id));
  1028. $dependency = "";
  1029. if ($iassign_statement) {
  1030. $inter_dependency = explode(';', $iassign_statement->dependency);
  1031. foreach ($inter_dependency as $tmp) {
  1032. if ($tmp != 0)
  1033. $dependency .= $tmp . ";";
  1034. $dependency .= $this->search_sub_dependency($tmp);
  1035. } // foreach ($inter_dependency as $tmp)
  1036. } // if ($iassign_statement)
  1037. return $dependency;
  1038. }
  1039. // Warning message
  1040. static function warning_message_iassign ($strcode) {
  1041. return "<div class='warning' style='display:inline; font-weight: bold; color:#a00'>" . get_string($strcode, 'iassign') . "</div>\n";
  1042. }
  1043. /// Update grade of iAssign
  1044. // Called always any iAssign activity is created
  1045. // @see /mod/iassign/view.php: call to iassign->iassign(): starting point
  1046. static function update_grade_iassign ($iassignid) {
  1047. global $USER, $CFG, $COURSE, $DB, $OUTPUT;
  1048. require_once($CFG->libdir . '/gradelib.php');
  1049. //D $sum_grade = $DB->get_records_sql ( "SELECT SUM(grade) as total
  1050. //D FROM {$CFG->prefix}iassign_statement s WHERE s.iassignid = '$iassignid' AND s.type_iassign=3" );
  1051. //TODO: REVIEW: wich one is more efficienty, '$DB->get_records' geting objects or '$DB->get_records' with 'foreach'?
  1052. // Each iAssign item is associated with one item on the "gradebook"
  1053. // Sum all '*_iassign_statement' associated with one item in '*_grade_items': iassignid AND type_iassign=3
  1054. //$sum_grade = 0;
  1055. //$grade = $DB->get_records('iassign_statement', array('iassignid' => $iassignid, 'type_iassign' => 3));
  1056. //foreach($grade as $tmp) {
  1057. // $sum_grade += $tmp->grade;
  1058. // }
  1059. //1 Solution 1
  1060. //1 $grade = $DB->get_records('iassign_statement', array('iassignid' => $iassignid, 'type_iassign' => 3)); //1
  1061. //1 $sum_grade = 0; //1
  1062. //1 foreach ($grade as $tmp) { $sum_grade += $tmp->grade; } //1
  1063. //2 Solution 2
  1064. $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
  1065. //2 foreach ($array_sum_grade as $array_item) { $sum_grade = $array_item->total; break; } // nao necessario, basta 'key(...)' abaixo
  1066. if (key($array_sum_grade))
  1067. $sum_grade = key($array_sum_grade); //2
  1068. else
  1069. $sum_grade = 0; //2
  1070. $grade_iassign = $DB->get_record("iassign", array("id" => $iassignid));
  1071. $grades = NULL;
  1072. $params = array('itemname' => $grade_iassign->name);
  1073. $params['iteminstance'] = $iassignid;
  1074. $params['gradetype'] = GRADE_TYPE_VALUE;
  1075. //2016 if ($sum_grade != 0) {
  1076. $params['grademax'] = $sum_grade;
  1077. $params['rawgrademax'] = $sum_grade;
  1078. //2016 } else { $params['grademax'] = 0; $params['rawgrademax'] = 0; }
  1079. $params['grademin'] = 0;
  1080. // @calls /lib/gradelib.php: call to grade_item->insert()
  1081. //TODO: is there any error here in Moodle version 3.0?
  1082. //TODO: Incorrect property 'grademax' found when inserting grade object
  1083. //TODO: line 899 of /mod/iassign/locallib.php: call to grade_update()
  1084. grade_update('mod/iassign', $grade_iassign->course, 'mod', 'iassign', $iassignid, 0, $grades, $params);
  1085. }
  1086. /// Update grade of student
  1087. function update_grade_student ($userid, $iassign_statementid, $iassignid) {
  1088. global $CFG, $DB, $OUTPUT;
  1089. require_once($CFG->libdir . '/gradelib.php');
  1090. $grade_iassign = $DB->get_record('iassign', array('id' => $iassignid));
  1091. // Review all the student submission for this iAssign activity
  1092. $grade_iassign_statements = $DB->get_records('iassign_statement', array('iassignid' => $iassignid));
  1093. $total_grade = 0;
  1094. foreach ($grade_iassign_statements as $grade_iassign_statement) {
  1095. $iassign_submission = $DB->get_record('iassign_submission', array('iassign_statementid' => $grade_iassign_statement->id, 'userid' => $userid));
  1096. if ($iassign_submission)
  1097. $total_grade += $iassign_submission->grade;
  1098. } // foreach ($grade_iassign_statements as $grade_iassign_statement)
  1099. //D $sum_grade = $DB->get_records_sql("SELECT SUM(grade) as total
  1100. //D FROM {$CFG->prefix}iassign_statement s WHERE s.iassignid = '$iassignid' AND s.type_iassign=3" );
  1101. //TODO: REVIEW: wich one is more efficienty, '$DB->get_records' geting objects or '$DB->get_records' with 'foreach'?
  1102. //1 $sum_grade = 0; $grade = $DB->get_records('iassign_statement', array('iassignid' => $iassignid, 'type_iassign' => 3));
  1103. //1 foreach ($grade as $tmp) { $sum_grade += $tmp->grade; }
  1104. $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
  1105. if (key($array_sum_grade))
  1106. $sum_grade = key($array_sum_grade); //2
  1107. else
  1108. $sum_grade = 0; //2
  1109. $grades['userid'] = $userid;
  1110. $grades['rawgrade'] = $total_grade; // sum of all submissions for this iAssign activity
  1111. $params = array('itemname' => $grade_iassign->name);
  1112. $params['iteminstance'] = $iassignid;
  1113. $params['gradetype'] = GRADE_TYPE_VALUE;
  1114. //2016 if ($sum_grade != 0) { // depois eliminar comentario
  1115. $params['grademax'] = $sum_grade;
  1116. $params['rawgrademax'] = $sum_grade;
  1117. //2016 } else { $params['grademax'] = 0; $params['rawgrademax'] = 0; }
  1118. grade_update('mod/iassign', $grade_iassign->course, 'mod', 'iassign', $iassignid, 0, $grades, $params);
  1119. }
  1120. /// Display caption of icons
  1121. function view_legend_icons () {
  1122. global $USER, $CFG, $DB, $OUTPUT;
  1123. $id = $this->cm->id;
  1124. if ($this->action == 'print')
  1125. print '<table border=1 width=100%><tr>';
  1126. else
  1127. print '<table width=100%><tr>';
  1128. print '<td >';
  1129. if ($this->action != 'print')
  1130. print $OUTPUT->help_icon('legend', 'iassign');
  1131. // helpbutton('legend', get_string('legend', 'iassign'), 'iassign', $image = true, $linktext = false, $text = '', $return = false,
  1132. // $imagetext = '');
  1133. print '<strong>' . get_string('legend', 'iassign') . '</strong>';
  1134. print '&nbsp;' . iassign_icons::insert('correct') . '&nbsp;' . get_string('correct', 'iassign');
  1135. print '&nbsp;' . iassign_icons::insert('incorrect') . '&nbsp;' . get_string('incorrect', 'iassign');
  1136. print '&nbsp;' . iassign_icons::insert('post') . '&nbsp;' . get_string('post', 'iassign');
  1137. print '&nbsp;' . iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign');
  1138. print '&nbsp;' . iassign_icons::insert('comment_unread') . '&nbsp;' . get_string('comment_unread', 'iassign');
  1139. if (has_capability('mod/iassign:viewreport', $this->context, $USER->id) && $this->action == 'report') {
  1140. print '&nbsp;' . iassign_icons::insert('comment_read') . '&nbsp;' . get_string('comment_read', 'iassign');
  1141. print '</td>' . "\n";
  1142. if ($this->action != 'print') {
  1143. $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>";
  1144. $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>";
  1145. $link_export = "<a href='" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&action=export_csv&iassignid=" . $this->iassign->id . "'>" . iassign_icons::insert('export_ilm') . '&nbsp;' . get_string('export_csv', 'iassign') . "</a>";
  1146. $link_auto_evaluate = "<a href='" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&action=auto_evaluate&iassignid=" . $this->iassign->id . "'>" . iassign_icons::insert('correct') . '&nbsp;' . get_string('auto_evaluate_reprocess', 'iassign') . "</a>";
  1147. print '<td width=15% align="right">' . $link_stats . '</td>' . "\n";
  1148. print '<td width=15% align="right">' . $link_export . '</td>' . "\n";
  1149. print '<td width=15% align="right">' . $link_auto_evaluate . '</td>' . "\n";
  1150. print '<td width=15% align="right">' . $link_print . '</td>' . "\n";
  1151. } // if ($this->action != 'print')
  1152. print '</tr></table>' . "\n";
  1153. } // if (has_capability('mod/iassign:viewreport', $this->context, $USER->id) && $this->action == 'report')
  1154. elseif (has_capability('mod/iassign:submitiassign', $this->context, $USER->id)) {
  1155. $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>";
  1156. print '<td width=15% align="right">' . $link_stats . '</td>' . "\n";
  1157. print '</tr></table>' . "\n";
  1158. } // elseif (has_capability('mod/iassign:submitiassign', $this->context, $USER->id))
  1159. else
  1160. print '</td></tr></table>' . "\n";
  1161. } // function view_legend_icons()
  1162. /// Display activity current
  1163. // @calledby view() -> action() : when student do/redo activity and teacher see student answer
  1164. function view_iassign_current () {
  1165. global $USER, $CFG, $COURSE, $DB, $OUTPUT;
  1166. $id = $this->cm->id;
  1167. $iassignid = $this->iassign->id;
  1168. $only_one_send_button = 0; // to avoid to put 2 copies of comments (area to send and see comments between teacher and student)
  1169. $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
  1170. // 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 ...
  1171. $iassign_statement_activity_item = $this->activity->get_activity(); // search data of current activity: the teacher activity model
  1172. $ilm = new ilm($iassign_statement_activity_item->iassign_ilmid);
  1173. $ilm_name = strtolower($ilm->ilm->name); // class ilm has a unique property ('ilm'), get the iLM name
  1174. // 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
  1175. $allow_resubmission = (substr($ilm_name, 0, 5) != "igeom" ? 1 : 0);
  1176. // log record
  1177. $info = $iassign->name . ":" . $iassign_statement_activity_item->name;
  1178. //Trigger module viewed event.
  1179. $event = \mod_iassign\event\submission_viewed::create(array(
  1180. 'objectid' => $iassign->id,
  1181. 'context' => $this->context,
  1182. 'other' => $info
  1183. ));
  1184. $event->add_record_snapshot('course', $this->course);
  1185. $event->trigger();
  1186. print $OUTPUT->header();
  1187. // Search of iLM data used in the current activity
  1188. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $iassign_statement_activity_item->iassign_ilmid));
  1189. if ($this->action == 'viewsubmission') {
  1190. if (!empty($this->iassign_submission_current) || $this->iassign_submission_current != 0)
  1191. $iassign_submission = $DB->get_record("iassign_submission", array("id" => $this->iassign_submission_current)); // data about activity current
  1192. else
  1193. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $this->activity->get_activity()->id, "userid" => $this->userid_iassign)); // data about student solution
  1194. } else {
  1195. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $this->activity->get_activity()->id, "userid" => $this->userid_iassign)); // data about student solution
  1196. }
  1197. if ($iassign_submission)
  1198. $this->update_comment($iassign_submission->id);
  1199. $file = $iassign_statement_activity_item->file;
  1200. // 1 when open previous file; 2 when the activity is redone!; 3 when the teacher enter in the activity
  1201. // 1 => locallib.php: view_iassign_current(): action=view will set write_solution=0!!!!!
  1202. // 2 => locallib.php: view_iassign_current(): action=repeat will set write_solution=0!!!!!
  1203. // 3 => locallib.php: view_iassign_current(): action=viewsubmission will set write_solution=0!!!!!
  1204. $this->bottonPost = 0; // hide submit button
  1205. //xxx $this->write_solution = 0; // disable recording solution (however, iVProg allow the learner to edit previou solution)
  1206. $this->view_iassign = false; // disable visualization of activity
  1207. $repeat = "";
  1208. $last_iassign = "";
  1209. $student_answer = "";
  1210. $comment = "";
  1211. // *** Teacher access (view learner's submission)
  1212. if (($this->action != 'viewsubmission') && has_capability('mod/iassign:evaluateiassign', $USER->context, $USER->id)) {
  1213. //TODO leo Verificar se o correto eh '$this->context' ou '$USER->context' como deixei
  1214. // It is not 'viewsubmission' and it is teacher or 'non editing teacher'?
  1215. // ---> access teacher for test
  1216. if ($iassign_statement_activity_item->type_iassign != 1) // type_iassign=1 => activity of type "example" - not submit button for submission
  1217. $this->bottonPost = 1;
  1218. print $OUTPUT->box('<p><strong>' . get_string('area_specific_teacher', 'iassign') . '</strong></p>');
  1219. $this->activity->view_dates();
  1220. $USER->iassignEdit = $this->bottonPost;
  1221. $this->activity->show_info_iassign();
  1222. if ($iassign_submission) {
  1223. //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;
  1224. $param_aux = "action=get_answer&iassign_submission_current=" . $iassign_submission->id . "&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id . "&userid_iassign=" . $USER->id;
  1225. } else {
  1226. //xxx $param_aux = "action=get_answer&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id . "&write_solution=" . $this->write_solution . "&userid_iassign=" . $USER->id;
  1227. $param_aux = "action=get_answer&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id . "&userid_iassign=" . $USER->id;
  1228. }
  1229. $enderecoPOST = "" . $CFG->wwwroot . "/mod/iassign/view.php?" . $param_aux;
  1230. //if ($ilm->confirms_jar($iassign_statement_activity_item->file, $iassign_ilm->file_jar, $this->cm->id))
  1231. // Prepare tags to present the iLM
  1232. print $OUTPUT->box($ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, true));
  1233. } // if (($this->action != 'viewsubmission') && has_capability('mod/iassign:evaluateiassign', $USER->context, $USER->id))
  1234. // *** (end) Teacher access (view the activity)
  1235. // *** Teacher access (view learner's submission to the activity)
  1236. elseif (($this->action == 'viewsubmission') && has_capability('mod/iassign:evaluateiassign', $USER->context, $USER->id)) {
  1237. // It is teacher or 'nonediting teacher' that can evaluate
  1238. // ----> area teacher evaluate
  1239. $row = optional_param('row', 0, PARAM_INT);
  1240. $column = optional_param('column', 0, PARAM_INT);
  1241. $link_next = iassign_icons::insert('right_disable');
  1242. $link_previous = iassign_icons::insert('left_disable');
  1243. $link_up = iassign_icons::insert('up_disable');
  1244. $link_down = iassign_icons::insert('down_disable');
  1245. // next_activity
  1246. if ($USER->matrix_iassign[$row][$column]->iassign_next != - 1) {
  1247. $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);
  1248. $link_next = "<a href='" . $url_next . "'>" . (iassign_icons::insert('next_activity')) . "</a>";
  1249. }
  1250. // previous_activity
  1251. if ($USER->matrix_iassign[$row][$column]->iassign_previous != - 1) {
  1252. $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);
  1253. $link_previous = "<a href='" . $url_previous . "'>" . (iassign_icons::insert('previous_activity')) . "</a>";
  1254. }
  1255. // previous_student
  1256. if ($USER->matrix_iassign[$row][$column]->user_next != - 1) {
  1257. $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);
  1258. $link_down = "<a href='" . $url_down . "'>" . (iassign_icons::insert('previous_student')) . "</a>";
  1259. }
  1260. // next_student
  1261. if ($USER->matrix_iassign[$row][$column]->user_previous != - 1) {
  1262. $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);
  1263. $link_up = "<a href='" . $url_up . "'>" . (iassign_icons::insert('next_student')) . "</a>";
  1264. }
  1265. if ($iassign_submission) {
  1266. $student_answer = $iassign_submission->answer;
  1267. }
  1268. $last_iassign = get_string('last_iassign', 'iassign');
  1269. $user_data = $DB->get_record("user", array('id' => $this->userid_iassign));
  1270. // Messages related to due date (and user role)
  1271. $this->activity->view_dates();
  1272. print $OUTPUT->box_start();
  1273. print '<table width=100% border=0 valign="top"><tr>' . "\n";
  1274. print '<td width=80%><font color="blue"><strong>' . get_string('area_available', 'iassign') . '</strong></font><br>' . "\n";
  1275. print $OUTPUT->user_picture($user_data);
  1276. print '&nbsp;' . $user_data->firstname . '&nbsp;' . $user_data->lastname;
  1277. print '</td>' . "\n";
  1278. print '<td width=20% align=right>' . "\n";
  1279. print '<table width=50 cellpadding="0">';
  1280. print '<tr><td colspan=2 align=center>' . $link_up . '</td></tr>' . "\n";
  1281. print '<tr><td align=center>' . $link_previous . '</td>' . "\n";
  1282. print '<td align=center>' . $link_next . '</td></tr>' . "\n";
  1283. print '<td colspan=2 align=center>' . $link_down . '</td></tr>' . "\n";
  1284. print '</table>' . "\n";
  1285. print '</td></tr></table>' . "\n";
  1286. print $OUTPUT->box_end();
  1287. print $OUTPUT->box_start();
  1288. print '<table width=100% border=0 valign="top"><tr>' . "\n";
  1289. print '<td width=60% valign="top">' . "\n";
  1290. print '<strong>' . get_string('proposition', 'iassign') . '</strong>' . "\n";
  1291. print '<p>' . $iassign_statement_activity_item->proposition . '</p>' . "\n";
  1292. if ($iassign_statement_activity_item->automatic_evaluate == 1)
  1293. $resp = get_string('yes');
  1294. else
  1295. $resp = get_string('no');
  1296. print '<p>' . get_string('automatic_evaluate', 'iassign') . '&nbsp;' . $resp . '</p>' . "\n";
  1297. if ($iassign_statement_activity_item->show_answer == 1)
  1298. $resp = get_string('yes');
  1299. else
  1300. $resp = get_string('no');
  1301. print '<p>' . get_string('show_answer', 'iassign') . '&nbsp;' . $resp . '</p>' . "\n";
  1302. print '</td>';
  1303. if ($iassign_statement_activity_item->type_iassign == 3) { // type_iassign=3 => activity of type "exercise" - submit button and automatic evaluation
  1304. print '<td width=40% valign="top" align="left">';
  1305. print '<strong>' . get_string('status', 'iassign') . '</strong>' . "\n";
  1306. // check status of solution sent by the student
  1307. if ($iassign_submission) {
  1308. switch ($iassign_submission->status) {
  1309. case 3 :
  1310. print iassign_icons::insert('correct') . '&nbsp;' . get_string('correct', 'iassign') . '&nbsp;' . $comment;
  1311. break;
  1312. case 2 :
  1313. print iassign_icons::insert('incorrect') . '&nbsp;' . get_string('incorrect', 'iassign') . '&nbsp;' . $comment;
  1314. break;
  1315. case 1 :
  1316. print iassign_icons::insert('post') . '&nbsp;' . get_string('post', 'iassign') . '&nbsp;' . $comment;
  1317. break;
  1318. default :
  1319. print iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign') . '&nbsp;' . $comment;
  1320. $last_iassign = get_string('no_iLM_PARAM_ArchiveContent', 'iassign');
  1321. } // switch ($iassign_submission->status)
  1322. }
  1323. else { // if ($iassign_submission)
  1324. print iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign') . '&nbsp;' . $comment;
  1325. $last_iassign = get_string('no_iLM_PARAM_ArchiveContent', 'iassign');
  1326. }
  1327. // update_status
  1328. if ($iassign_submission && $iassign_submission->experiment > 0) {
  1329. $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);
  1330. print " <script type='text/javascript'>
  1331. //<![CDATA[
  1332. function overwriteStatus (newstatus) {
  1333. if (confirm('" . get_string('confirm_change_situation', 'iassign') . "')) {
  1334. document.formEditStatus.return_status.value=newstatus;
  1335. document.formEditStatus.submit();
  1336. }
  1337. else
  1338. document.formEditStatus.return_status.value=-1;
  1339. }
  1340. //]]>
  1341. </script>";
  1342. print "<form name='formEditStatus' method='post' action='$edit_status' enctype='multipart/form-data'>\n";
  1343. print ' <font color="blue"><strong>' . get_string('changeto', 'iassign') . "</strong></font>\n";
  1344. 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";
  1345. print " <input type='hidden' name='return_status'>\n";
  1346. print "</form>\n";
  1347. print '<p><strong>' . get_string('grade_student', 'iassign') . '</strong>&nbsp;' . $iassign_submission->grade . "</p>\n";
  1348. print '<p><strong>' . get_string('grade_iassign', 'iassign') . '</strong>&nbsp;' . $iassign_statement_activity_item->grade . "</p>\n";
  1349. $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);
  1350. print "
  1351. <script type='text/javascript'>
  1352. //<![CDATA[
  1353. function overwriteGrade (newgrade,maxgrade) {
  1354. if (newgrade<0 || newgrade>maxgrade) {
  1355. alert('" . get_string('erro_grade', 'iassign') . " '+maxgrade)
  1356. document.formEditGrade.return_grade.value=-1;
  1357. document.formEditGrade.submit();
  1358. }
  1359. else {
  1360. document.formEditGrade.return_grade.value=newgrade;
  1361. document.formEditGrade.submit();
  1362. }
  1363. }
  1364. //]]>
  1365. </script>";
  1366. print "<form name='formEditGrade' method='post' action='$edit_grade' enctype='multipart/form-data'>\n";
  1367. print ' <font color="blue"><strong>' . get_string('changeto', 'iassign') . "</strong></font>" . "\n";
  1368. print " <input type='text' name='grade' size='6'>";
  1369. print " <input type='hidden' name='return_grade'> ";
  1370. 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";
  1371. print "</form>";
  1372. $url_answer = "" . $CFG->wwwroot . "/mod/iassign/view.php?" . "action=download_answer&iassign_submission_id=" . $iassign_submission->id . "&id=" . $id;
  1373. print '<p><strong>' . get_string('experiment', 'iassign') . '</strong>&nbsp;' . $iassign_submission->experiment . ' <a href="' . $url_answer . '">' . iassign_icons::insert('download_assign') . '</a></p>';
  1374. print '<p><strong>' . get_string('timemodified', 'iassign') . '</strong>&nbsp;' . userdate($iassign_submission->timemodified) . '</p>';
  1375. $teacher = $DB->get_record("user", array('id' => $iassign_submission->teacher));
  1376. if ($teacher)
  1377. print '<p><strong>' . get_string('last_modification', 'iassign') . '</strong>&nbsp;' . $teacher->firstname . '</p>' . "\n";
  1378. } // if ($iassign_submission->experiment > 0)
  1379. print '</td>';
  1380. } // if ($iassign_statement_activity_item->type_iassign == 3)
  1381. print '</tr></table>';
  1382. print $OUTPUT->box_end();
  1383. $USER->iassignEdit = $this->bottonPost;
  1384. if ($iassign_submission && $allow_resubmission) {
  1385. // Put the iLM to
  1386. print $OUTPUT->box_start();
  1387. print '<p><strong>' . $last_iassign . '</strong></p>';
  1388. //d if ($ilm->confirms_jar ( $iassign_statement_activity_item->file, $iassign_ilm->file_jar, $this->cm->id )) {
  1389. $enderecoPOST = "";
  1390. // Prepare tags to present the iLM
  1391. print $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, false);
  1392. //d } // if ($this->confirms_jar($iassign_statement_activity_item->file, $iassign_ilm->file_jar))
  1393. print $OUTPUT->box_end();
  1394. } else { // if ($iassign_submission && $allow_resubmission) - techer view student answer
  1395. // ATTENTION: exception used by iGeom (exercise with "script")
  1396. $loadTeacherActivity = false; // use 'true' whenever 'special_param1 == 1'
  1397. if (substr($ilm_name, 0, 5)=="igeom") {
  1398. if ($iassign_statement_activity_item->special_param1 == 1) // if 1 => use the teacher activity with some complement from the student (in iGeom = GEO + SCR)
  1399. $loadTeacherActivity = true;
  1400. }
  1401. print $OUTPUT->box('<p><strong>' . $last_iassign . '</strong></p>' . "\n");
  1402. if (!isset($enderecoPOST)) $enderecoPOST = "";
  1403. // Prepare tags to present the iLM
  1404. print $OUTPUT->box($ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, $loadTeacherActivity));
  1405. }
  1406. //2020 Eliminei daqui o codigo para colocar o quadro com area para enivar e ler comentarios
  1407. //2020 Estava subordinado ao: elseif (($this->action == 'viewsubmission') && has_capability('mod/iassign:evaluateiassign', $USER->context, $USER->id))
  1408. //2020 e com isso NAO permitia aluno ter o quadro para envio!
  1409. //2020 Foi para final dessa funcao 'view_iassign_current()'
  1410. } // elseif (($this->action == 'viewsubmission') && has_capability('mod/iassign:evaluateiassign', $USER->context, $USER->id))
  1411. // *** (end) Teacher access (view learner's submission to the activity)
  1412. // *** Student access (view the activity)
  1413. elseif (has_capability('mod/iassign:submitiassign', $USER->context, $USER->id)) {
  1414. // It could be the learner (he could send or resend the activity)
  1415. // ---> access student
  1416. $time_now = time();
  1417. if ($iassign_statement_activity_item->type_iassign == 1) { // type_iassign=1 => activity of type "exemple" - no submit button
  1418. // activity of type example - not submit button for submission
  1419. $this->view_iassign = true;
  1420. //TODO rever esta condicao para iMA que nao fazem autoavaliacao
  1421. } elseif ($iassign_statement_activity_item->type_iassign == 2 && $iassign_ilm->evaluate == 1) {
  1422. // activity of type test - iLM automatic evaluator - submit button for submission
  1423. if ($iassign_statement_activity_item->timeavailable < $time_now && $iassign_statement_activity_item->timedue > $time_now) { // activity within of deadline
  1424. $this->bottonPost = 1;
  1425. $this->view_iassign = true;
  1426. } else
  1427. $this->view_iassign = false;
  1428. } elseif ($iassign_statement_activity_item->type_iassign == 3) { // type_iassign=3 => activity of type "exercise" - submit button and automatic evaluation
  1429. // activity of type exercise (learner can send his answer, if yet open...)
  1430. $this->view_iassign = true;
  1431. if ($iassign_statement_activity_item->timeavailable > $time_now) // due date expired
  1432. $this->view_iassign = false;
  1433. elseif ($iassign_statement_activity_item->timedue > $time_now || $iassign_statement_activity_item->preventlate == 1) { // activity within due date
  1434. $this->bottonPost = 1; // allow the submit button
  1435. // Look at table 'iassign_submission' ('iassign_submission.experiment' is the number of submissions)
  1436. $repeat_title = ' title="' . get_string('repeat_alt', 'iassign') . '" '; // 'Use this button to redo the activity'
  1437. if (!$iassign_submission || $this->action == 'repeat' || ($iassign_submission && $allow_resubmission)) {
  1438. if (!$iassign_submission) {
  1439. $str_iassign_submission_id = '';
  1440. $str_iassign_submission_answer = '';
  1441. }
  1442. else {
  1443. $str_iassign_submission_id = $iassign_submission->id;
  1444. $str_iassign_submission_answer = $iassign_submission->answer;
  1445. }
  1446. if ($this->action != 'repeat') {
  1447. $repeat = "<a href='view.php?action=repeat&id="
  1448. . $id . "&userid_iassign=" . $USER->id . "&iassign_current="
  1449. . $this->activity->get_activity()->id . "&iassign_submission_current="
  1450. . $str_iassign_submission_id . "'" . $repeat_title . ">"
  1451. . iassign_icons::insert('repeat') . '&nbsp;' . get_string('repeat', 'iassign') . "</a>\n";
  1452. }
  1453. $this->bottonPost = 1;
  1454. $this->write_solution = 1; // can register his submission
  1455. $student_answer = $str_iassign_submission_answer;
  1456. }
  1457. else { // if (!$iassign_submission || $this->action == 'repeat' || ($iassign_submission && $allow_resubmission))
  1458. // In 'class ilm : view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, $view)'
  1459. $last_iassign = get_string('last_iassign', 'iassign');
  1460. if ($iassign_submission) {
  1461. $repeat = "<a href='view.php?action=repeat&id=" . $id . "&userid_iassign=$USER->id&iassign_current=" . $this->activity->get_activity()->id .
  1462. "&iassign_submission_current=" . $iassign_submission->id . "'" . $repeat_title . ">" . iassign_icons::insert('repeat') . '&nbsp;' . get_string('repeat', 'iassign') . "</a>\n";
  1463. $student_answer = $iassign_submission->answer;
  1464. } else {
  1465. $repeat = "<a href='view.php?action=repeat&id=" . $id . "&userid_iassign=$USER->id&iassign_current=" . $this->activity->get_activity()->id .
  1466. "'" . $repeat_title . ">" . iassign_icons::insert('repeat') . '&nbsp;' . get_string('repeat', 'iassign') . "</a>\n";
  1467. }
  1468. }
  1469. } elseif ($iassign_statement_activity_item->test == 1) { // allowed to test after expired due date
  1470. if ($this->action == 'repeat' || ($iassign_submission && $iassign_submission->experiment < 1)) {
  1471. $this->bottonPost = 1;
  1472. $this->write_solution = 0; // if iVProg it is valid to the learner to edit previous solution
  1473. } else {
  1474. $last_iassign = get_string('last_iassign', 'iassign');
  1475. if ($iassign_submission) {
  1476. $repeat = "<a href='view.php?action=repeat&id=" . $id . "&userid_iassign=$USER->id&iassign_current=" . $this->activity->get_activity()->id .
  1477. "&iassign_submission_current=" . $iassign_submission->id . "'" . $repeat_title . ">" . iassign_icons::insert('repeat') . '&nbsp;' . get_string('repeat', 'iassign') . "</a>\n";
  1478. $student_answer = $iassign_submission->answer;
  1479. } else {
  1480. // Symbol of "redo activity"
  1481. $repeat = "<a href='view.php?action=repeat&id=" . $id . "&userid_iassign=$USER->id&iassign_current=" . $this->activity->get_activity()->id .
  1482. "'" . $repeat_title . ">" . iassign_icons::insert('repeat') . '&nbsp;' . get_string('repeat', 'iassign') . "</a>\n";
  1483. }
  1484. }
  1485. } // elseif ($iassign_statement_activity_item->test == 1)
  1486. elseif ($iassign_statement_activity_item->test == 0)
  1487. $this->view_iassign = false;
  1488. } // elseif ($iassign_statement_activity_item->type_iassign == 3)
  1489. if ($iassign_submission)
  1490. $param_aux = "action=get_answer&iassign_submission_current=" . $iassign_submission->id . "&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id .
  1491. "&write_solution=" . $this->write_solution . "&userid_iassign=" . $USER->id;
  1492. else
  1493. $param_aux = "action=get_answer&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id . "&write_solution=" . $this->write_solution . "&userid_iassign=" . $USER->id;
  1494. $enderecoPOST = "" . $CFG->wwwroot . "/mod/iassign/view.php?" . $param_aux;
  1495. $this->view_legend_icons();
  1496. $this->activity->view_dates();
  1497. if ($this->view_iassign) { // Box 5 to 'proposition' - open
  1498. print $OUTPUT->box_start();
  1499. print '<table width=100% border=0 valign="top">' . "\n";
  1500. print '<tr><td width=60% valign="top">' . "\n";
  1501. print '<strong>' . get_string('proposition', 'iassign') . '</strong>' . "\n";
  1502. print '<p>' . $iassign_statement_activity_item->proposition . '</p>' . "\n";
  1503. $flag_dependency = true;
  1504. if ($iassign_statement_activity_item->type_iassign == 3) {
  1505. if ($iassign_statement_activity_item->dependency == 0) {
  1506. print '<strong>' . get_string('independent_activity', 'iassign') . '</strong>' . "\n";
  1507. } else {
  1508. $dependencys = explode(';', $iassign_statement_activity_item->dependency);
  1509. print '<p><strong>' . get_string('dependency', 'iassign') . '</strong></p>' . "\n";
  1510. foreach ($dependencys as $dependency) {
  1511. if ($dependency) {
  1512. $dependencyiassign = $DB->get_record("iassign_statement", array("id" => $dependency));
  1513. $dependencysubmissions = $DB->get_record("iassign_submission", array("iassign_statementid" => $dependencyiassign->id, 'userid' => $USER->id));
  1514. if ($dependencysubmissions) {
  1515. if ($dependencysubmissions->status == 3)
  1516. $icon = iassign_icons::insert('correct');
  1517. elseif ($dependencysubmissions->status == 2) {
  1518. $icon = iassign_icons::insert('incorrect');
  1519. $flag_dependency = false;
  1520. } elseif ($dependencysubmissions->status == 1) {
  1521. $icon = iassign_icons::insert('post');
  1522. $flag_dependency = false;
  1523. } elseif ($dependencysubmissions->status == 0) {
  1524. $icon = iassign_icons::insert('not_post');
  1525. $flag_dependency = false;
  1526. }
  1527. } else {
  1528. $icon = iassign_icons::insert('not_post');
  1529. $flag_dependency = false;
  1530. } // if ($dependencysubmissions)
  1531. print '<p>&nbsp;' . $icon . $dependencyiassign->name . '</p>' . "\n";
  1532. } // if ($dependency)
  1533. } // foreach ($dependencys as $dependency)
  1534. } // if ($iassign_statement_activity_item->dependency == 0)
  1535. } // if ($iassign_statement_activity_item->type_iassign == 3)
  1536. if ($flag_dependency == false) {
  1537. print '<strong>' . get_string('message_dependency', 'iassign') . '</strong>' . "\n";
  1538. $this->view_iassign = false;
  1539. print '</tr></table>' . "\n";
  1540. }
  1541. else {
  1542. $this->view_iassign = true;
  1543. print '</td>' . "\n";
  1544. } // if ($flag_dependency == false)
  1545. if ($this->view_iassign) { // it is already inside 'if ($this->view_iassign)' but the dependency check could had change its value (above)
  1546. if ($iassign_statement_activity_item->type_iassign == 3) { // activity is present only if exercise
  1547. // receiver=1 - message to teacher
  1548. // receiver=2 - message to student
  1549. if ($iassign_submission) {
  1550. $verify_message = $DB->get_record('iassign_submission_comment', array('iassign_submissionid' => $iassign_submission->id, 'return_status' => 0, 'receiver' => 2));
  1551. if ($verify_message)
  1552. $comment = iassign_icons::insert('comment_unread');
  1553. }
  1554. print '<td width=40% valign="top" align="left">';
  1555. print '<strong>' . get_string('status', 'iassign') . '</strong>' . "\n";
  1556. if ($iassign_statement_activity_item->show_answer == 1) {
  1557. // check status of solution sent by the student
  1558. if ($iassign_submission) {
  1559. switch ($iassign_submission->status) {
  1560. case 3 :
  1561. print iassign_icons::insert('correct') . '&nbsp;' . get_string('correct', 'iassign') . '&nbsp;' . $comment;
  1562. break;
  1563. case 2 :
  1564. print iassign_icons::insert('incorrect') . '&nbsp;' . get_string('incorrect', 'iassign') . '&nbsp;' . $comment;
  1565. break;
  1566. case 1 :
  1567. print iassign_icons::insert('post') . '&nbsp;' . get_string('post', 'iassign') . '&nbsp;' . $comment;
  1568. break;
  1569. default :
  1570. print iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign') . '&nbsp;' . $comment;
  1571. $repeat = "";
  1572. $last_iassign = "";
  1573. } // switch ($iassign_submission->status)
  1574. } else {
  1575. print iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign') . '&nbsp;' . $comment;
  1576. $repeat = "";
  1577. $last_iassign = "";
  1578. }
  1579. if ($iassign_submission && $iassign_submission->experiment > 0) {
  1580. print '<p><strong>' . get_string('grade_student', 'iassign') . ':</strong>&nbsp;' . $iassign_submission->grade;
  1581. print '&nbsp;&nbsp;(' . get_string('grade_iassign', 'iassign') . ':&nbsp;' . $iassign_statement_activity_item->grade . ')</p>' . "\n";
  1582. print '<p><strong>' . get_string('experiment_student', 'iassign') . '</strong>&nbsp;' . $iassign_submission->experiment;
  1583. if ($iassign_statement_activity_item->max_experiment == 0)
  1584. print '&nbsp;&nbsp(' . get_string('experiment_iassign', 'iassign') . '&nbsp;' . get_string('ilimit', 'iassign') . ')</p>' . "\n";
  1585. else {
  1586. print '&nbsp;&nbsp(' . get_string('experiment_iassign', 'iassign') . '&nbsp;' . $iassign_statement_activity_item->max_experiment . ')</p>' . "\n";
  1587. if ($iassign_submission->experiment >= $iassign_statement_activity_item->max_experiment) {
  1588. $repeat = "";
  1589. $last_iassign .= "&nbsp;<font color=red>" . get_string('attempts_exhausted', 'iassign') . '</font>' . "\n";
  1590. $this->bottonPost = 0;
  1591. $this->write_solution = 0;
  1592. }
  1593. } // else if ($iassign_statement_activity_item->max_experiment == 0)
  1594. print '<p><strong>' . get_string('timemodified', 'iassign') . '</strong>&nbsp;' . userdate($iassign_submission->timemodified) . '</p>' . "\n";
  1595. $teacher = $DB->get_record("user", array('id' => $iassign_submission->teacher));
  1596. if ($teacher)
  1597. print '<p><strong>' . get_string('last_modification', 'iassign') . '</strong>&nbsp;' . $teacher->firstname . '</p>' . "\n"; // "
  1598. } // if ($iassign_submission && $iassign_submission->experiment > 0)
  1599. } // if ($iassign_statement_activity_item->show_answer==1)
  1600. else {
  1601. if (!isset($iassign_submission) || $iassign_submission->status == 0) {
  1602. print iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign') . '&nbsp;' . $comment;
  1603. $repeat = "";
  1604. $last_iassign = "";
  1605. } elseif ($iassign_submission->status == 1) {
  1606. print iassign_icons::insert('post') . '&nbsp;' . get_string('post', 'iassign') . '&nbsp;' . $comment;
  1607. }
  1608. }
  1609. print '</td>';
  1610. } // if ($iassign_statement_activity_item->type_iassign == 3)
  1611. print '</tr></table>' . "\n";
  1612. // Presents the iLM
  1613. print '<table width=100% border=0 valign="top">' . "\n";
  1614. print '<td width=80% align="left">';
  1615. 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\".
  1616. print '<td width=20% align="rigth">';
  1617. //D $ilm_name = strtolower($this->ilm->name); //if (substr($ilm_name, 0, 5) == "igeom") ; // is iGeom exercise
  1618. print $repeat; // symbol of "redo activity"
  1619. print '</td></tr></table>' . "\n";
  1620. //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)'
  1621. $output = '';
  1622. if (!$iassign_ilm) {
  1623. $iassign_ilm = new stdClass();
  1624. $iassign_ilm->file_jar = "";
  1625. }
  1626. $output .= $OUTPUT->box_start();
  1627. $USER->iassignEdit = $this->bottonPost;
  1628. // ---
  1629. // Presents the iLM
  1630. // Prepare tags to present the iLM
  1631. if (!$iassign_submission || $this->action == 'repeat') { // or $iassign_submission->answer==0
  1632. $student_answer = ""; //?
  1633. $output .= $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, true); // presents iLM and true => see the teacher file
  1634. } elseif ($iassign_submission && $iassign_submission->answer == '0') {
  1635. $student_answer = "";
  1636. $output .= $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, true); // presents iLM
  1637. } else {
  1638. // When student is redoing his activity
  1639. // ATTENTION: exception used by iGeom (exercise with "script")
  1640. $loadTeacherActivity = false; // trocar para 'true' se 'special_param1 == 1'
  1641. if (substr($ilm_name, 0, 5)=="igeom") {
  1642. if ($iassign_statement_activity_item->special_param1 == 1) // if 1 => use the teacher activity with some complement from the student (in iGeom = GEO + SCR)
  1643. $loadTeacherActivity = true;
  1644. }
  1645. $output .= $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, $loadTeacherActivity); // presents iLM
  1646. }
  1647. //1 Desse modo entre area para comentario, mas nao seu botao separado - deixar para o final com botao!
  1648. //1 if ($iassign_statement_activity_item->type_iassign == 3) {
  1649. //1 $history_comment = '';
  1650. //1 if ($iassign_submission) {
  1651. //1 $history_comment = $this->search_comment_submission($iassign_submission->id);
  1652. //1 }
  1653. //1 if (!empty($history_comment)) {
  1654. //1 $output .= "\n <table id='outlinetable' class='generaltable boxaligncenter' cellpadding='5' width='100%'>\n" .
  1655. //1 " <tr><th>" . get_string('history_comments', 'iassign') . "</th></tr>\n"; //
  1656. //1 $output .= $history_comment;
  1657. //1 $output .= "</table>\n";
  1658. //1 }
  1659. //1 $output .= "</form></center>\n";
  1660. //1 $only_one_send_button = 1; // avoid put comment frame again (bellow)
  1661. //1 }
  1662. $output .= $OUTPUT->box_end();
  1663. print $output;
  1664. } // if ($this->view_iassign)
  1665. print $OUTPUT->box_end(); // Box 5 to 'proposition' - close
  1666. } // if ($this->view_iassign)
  1667. } // elseif (has_capability('mod/iassign:submitiassign', $USER->context, $USER->id))
  1668. else
  1669. if (isguestuser()) { // else of elseif (has_capability('mod/iassign:submitiassign', $USER->context, $USER->id))
  1670. print($OUTPUT->notification(get_string('no_permission_iassign', 'iassign'), 'notifyproblem'));
  1671. print '<table width=100% border=0 valign="top">' . "\n";
  1672. print '<tr><td width=60% valign="top">' . "\n";
  1673. print '<strong>' . get_string('proposition', 'iassign') . '</strong>' . "\n";
  1674. print '<p>' . $iassign_statement_activity_item->proposition . '</p>' . "\n";
  1675. print '</tr></table>' . "\n";
  1676. $student_answer = "";
  1677. $enderecoPOST = "";
  1678. // Prepare tags to present the iLM
  1679. $output = $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, true);
  1680. print $output;
  1681. }
  1682. //2020 Quadro com area para enivar e ler comentarios veio para este ponto para permitir todos o terem
  1683. // $only_one_send_button is to avoid to put 2 copies of comments (area to send and see comments between teacher and student)
  1684. if ($only_one_send_button==0 && $iassign_statement_activity_item->type_iassign == 3) { // type_iassign=3 => activity of type "exercise" - submit button and automatic evaluation
  1685. // Put a block with area to sent/answer comments
  1686. $output = '';
  1687. $history_comment = '';
  1688. $row = optional_param('row', 0, PARAM_INT);
  1689. $column = optional_param('column', 0, PARAM_INT);
  1690. if ($iassign_submission) {
  1691. $enderecoPOSTcomment = "" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&action=newcomment&iassign_current=" . $this->activity->get_activity()->id .
  1692. "&iassign_submission_current=" . $iassign_submission->id . "&userid_iassign=" . $this->userid_iassign . "&row=" . ($row) . "&column=" . ($column);
  1693. $history_comment = $this->search_comment_submission($iassign_submission->id);
  1694. }
  1695. else {
  1696. $enderecoPOSTcomment = "" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&action=newcomment&iassign_current=" . $this->activity->get_activity()->id .
  1697. "&userid_iassign=" . $this->userid_iassign . "&row=" . ($row) . "&column=" . ($column);
  1698. }
  1699. $output .= $OUTPUT->box_start();
  1700. $output .= "<center><form name='formEnvioComment' id='formEnvioComment1' method='post' action='$enderecoPOSTcomment' enctype='multipart/form-data'>\n";
  1701. $output .= "<p><textarea rows='2' cols='60' name='submission_comment'></textarea></p>\n";
  1702. $output .= "<p><input type=submit value='" . get_string('submit_comment', 'iassign') . "'\></p>\n";
  1703. $output .= "</form></center>\n";
  1704. if (!empty($history_comment)) {
  1705. $output .= " <table id='outlinetable' class='generaltable boxaligncenter' cellpadding='5' width='100%'> \n";
  1706. $output .= " <tr><th>" . get_string('history_comments', 'iassign') . "</th></tr>";
  1707. $output .= $history_comment;
  1708. $output .= "</table>";
  1709. }
  1710. $output .= $OUTPUT->box_end();
  1711. print $output;
  1712. } // if ($iassign_statement_activity_item->type_iassign == 3)
  1713. // final block 'studant'
  1714. print $OUTPUT->footer();
  1715. die();
  1716. } // function view_iassign_current()
  1717. /// Export the data from performance report into CSV file format
  1718. function export_csv () {
  1719. global $USER, $CFG, $DB, $OUTPUT;
  1720. $str = "";
  1721. $fields = "student_id, student_name";
  1722. // Finding all iassign activities for the iassign:
  1723. $id = $this->cm->id;
  1724. $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array('iassignid' => $this->iassign->id), "position ASC");
  1725. $c = 1;
  1726. foreach ($iassign_list as $iassign) {
  1727. $fields .= ", activity_id_$c, activity_name_$c, total_submissions_activity_$c, grade_activity_$c"
  1728. . ", status_activity_$c, ilm_id_activity_$c, ilm_name_activity_$c";
  1729. $c ++;
  1730. }
  1731. // Finding enrolled students:
  1732. $params = array('shortname' => 'student');
  1733. $role = $DB->get_record_sql("SELECT s.id, s.shortname FROM {role} s WHERE s.shortname = :shortname", $params);
  1734. $context = context_course::instance($this->course->id);
  1735. $params = array('contextid' => $context->id, 'roleid' => $role->id);
  1736. $students = $DB->get_records_sql(
  1737. "SELECT s.userid, a.firstname, a.lastname FROM {role_assignments} s, {user} a " .
  1738. " WHERE s.contextid = :contextid AND s.userid = a.id AND s.roleid = :roleid " .
  1739. " ORDER BY a.firstname ASC,a.lastname ASC", $params);
  1740. foreach ($students as $student) {
  1741. $str .= $student->userid . ',';
  1742. $str .= '"' . $student->firstname . ' ' . $student->lastname . '"';
  1743. foreach ($iassign_list as $iassign) {
  1744. $str .= ',' . $iassign->id . ',';
  1745. $str .= '"' . $iassign->name . '",';
  1746. $student_submissions = $DB->get_record("iassign_submission", array('iassign_statementid' => $iassign->id, 'userid' => $student->userid));
  1747. $str .= $student_submissions->experiment . ',';
  1748. $str .= $student_submissions->grade . ',';
  1749. switch ($student_submissions->status) {
  1750. case 3:
  1751. $str .= '"correct",';
  1752. break;
  1753. case 2:
  1754. $str .= '"incorrect",';
  1755. break;
  1756. case 1:
  1757. $str .= '"post",';
  1758. break;
  1759. case 0:
  1760. $str .= '"not_post",';
  1761. break;
  1762. }
  1763. $str .= $iassign->iassign_ilmid . ',';
  1764. $ilm_activity = $DB->get_record("iassign_ilm", array('id' => $iassign->iassign_ilmid));
  1765. $str .= '"' . $ilm_activity->name . '"';
  1766. }
  1767. $str .= "\n";
  1768. }
  1769. $str = $fields . "\n" . $str;
  1770. header("Content-disposition: attachment; filename=report.csv");
  1771. header("Pragma: no-cache");
  1772. header("Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0");
  1773. header('Content-Length: ' . strlen($str));
  1774. header('Connection: close');
  1775. print $str;
  1776. flush();
  1777. } // function export_csv()
  1778. /// Display report of performance
  1779. function report () {
  1780. global $USER, $CFG, $DB, $OUTPUT;
  1781. $id = $this->cm->id;
  1782. $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array('iassignid' => $this->iassign->id), "position ASC");
  1783. if ($this->action != 'print') {
  1784. $title = get_string('report', 'iassign');
  1785. print $OUTPUT->header();
  1786. } // if ($this->action != 'print')
  1787. print $OUTPUT->box_start();
  1788. $this->view_legend_icons();
  1789. print '<p>' . get_string('ps_experiment', 'iassign') . '</p>';
  1790. print '<p>' . get_string('ps_comment', 'iassign') . '</p>';
  1791. print $OUTPUT->box_end();
  1792. if ($this->action == 'print')
  1793. print '<table border=1 width="100%">' . "\n";
  1794. else
  1795. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  1796. print '<tr><th colspan=2 class="header c1">' . iassign_utils::remove_code_message($this->iassign->name) . '</th></tr>' . "\n";
  1797. // $num = array();
  1798. $i = 1;
  1799. $num = array();
  1800. foreach ($iassign_list as $iassign) {
  1801. $test_exercise = "";
  1802. $iassign_submission = $DB->get_records("iassign_submission", array("iassign_statementid" => $iassign->id));
  1803. if (($iassign_submission) && $iassign->type_iassign < 3) {
  1804. $test_exercise = "&nbsp;<b>(" . get_string('iassign_exercise', 'iassign') . ")</b>";
  1805. } // if (($iassign_submission) && $iassign->type_iassign < 3)
  1806. if ($iassign->type_iassign == 3 || ($iassign_submission)) {
  1807. $num[$i] = new stdClass();
  1808. $num[$i]->name = $iassign->name;
  1809. $num[$i]->id = $i;
  1810. $num[$i]->iassignid = $iassign->id;
  1811. print ' <tr >' . "\n";
  1812. print " <td class=\"cell c1 numviews\" width=5% align='center'><strong>" . $num[$i]->id . "</strong></td>\n";
  1813. print "<td class=\"cell c0 actvity\">";
  1814. print '&nbsp;' . $num[$i]->name . '&nbsp;' . $test_exercise . "</td>";
  1815. print ' </tr>' . "\n";
  1816. $i ++;
  1817. } // if ($iassign->type_iassign == 3 || ($iassign_submission))
  1818. } // foreach ($iassign_list as $iassign)
  1819. print "</table>";
  1820. print "<p></p>";
  1821. if ($this->action == 'print')
  1822. print '<table border=1 width="100%">' . "\n";
  1823. else
  1824. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  1825. $context = context_course::instance($this->course->id);
  1826. if ($i > 1) {
  1827. // $role = $DB->get_record_sql("SELECT s.id, s.shortname FROM {$CFG->prefix}role s WHERE s.shortname = 'student'");
  1828. $params = array('shortname' => 'student');
  1829. $role = $DB->get_record_sql(
  1830. "SELECT s.id, s.shortname FROM {role} s " .
  1831. " WHERE s.shortname = :shortname", $params);
  1832. // $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");
  1833. $params = array('contextid' => $context->id, 'roleid' => $role->id);
  1834. $students = $DB->get_records_sql(
  1835. "SELECT s.userid, a.firstname, a.lastname FROM {role_assignments} s, {user} a " .
  1836. " WHERE s.contextid = :contextid AND s.userid = a.id AND s.roleid = :roleid " .
  1837. " ORDER BY a.firstname ASC,a.lastname ASC", $params);
  1838. print '<tr><th class="header c1">' . get_string('students', 'iassign') . '</th>' . "\n";
  1839. for ($j = 1; $j < $i; $j ++) {
  1840. $sum_iassign_correct[$j] = 0;
  1841. print '<th class="header c1" scope="col">' . $num[$j]->id . '</th>' . "\n"; // <th class="header c1" scope="col">
  1842. }
  1843. print '<th class="header c1" width=5%> ' . get_string('functions', 'iassign') . '</th>';
  1844. $sum_iassign = $j - 1;
  1845. print '</tr>' . "\n";
  1846. $total = 0;
  1847. $sum_student = 0;
  1848. $comment = iassign_icons::insert('comment_read');
  1849. $sum_comment = 0;
  1850. $sum_correct_iassign = array();
  1851. $sum_correct_student = array();
  1852. $USER->matrix_iassign = array();
  1853. if ($students) {
  1854. $w = 0;
  1855. foreach ($students as $tmp) {
  1856. $users_array[$w] = $tmp;
  1857. $w ++;
  1858. }
  1859. for ($x = 0; $x < $w; $x ++) {
  1860. print '<tr>' . "\n";
  1861. $sum_student ++;
  1862. $name = $users_array[$x]->firstname . '&nbsp;' . $users_array[$x]->lastname;
  1863. print ' <td >' . $name . '</td>' . "\n";
  1864. $total_student = 0;
  1865. $tentativas = 0;
  1866. for ($j = 1; $j < $i; $j ++) {
  1867. $sum_comment = 0;
  1868. $student_submissions = $DB->get_record("iassign_submission", array('iassign_statementid' => $num[$j]->iassignid, 'userid' => $users_array[$x]->userid)); // data about student solution
  1869. print ' <td valign="bottom" align="center">' . "\n";
  1870. if ($student_submissions) {
  1871. $last_solution_submission = " title=\"" . userdate($student_submissions->timemodified) . "\" "; // timemodified: time of the last student solution
  1872. $tentativas = $student_submissions->experiment;
  1873. // $student_submissions_comment = $DB->get_record_sql("SELECT COUNT(iassign_submissionid) FROM {$CFG->prefix}ia_assign_submissions_comment WHERE iassign_submissionid = '$student_submissions->id'");
  1874. $params = array('iassign_submissionid' => $student_submissions->id);
  1875. $student_submissions_comment = $DB->get_record_sql(
  1876. "SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
  1877. "WHERE iassign_submissionid = :iassign_submissionid", $params);
  1878. if ($student_submissions_comment)
  1879. foreach ($student_submissions_comment as $tmp)
  1880. $sum_comment = $tmp;
  1881. // informations to previous activities
  1882. if ($j - 1 < 1 || $j == $i)
  1883. $iassign_previous = "-1";
  1884. else
  1885. $iassign_previous = $num[$j - 1]->iassignid;
  1886. if ($x - 1 < 0 || $x == $w)
  1887. $user_previous = "-1";
  1888. else
  1889. $user_previous = $users_array[$x - 1]->userid;
  1890. // next
  1891. if ($i - 1 > $j)
  1892. $iassign_next = $num[$j + 1]->iassignid;
  1893. else
  1894. $iassign_next = "-1";
  1895. if ($w - 1 > $x)
  1896. $user_next = $users_array[$x + 1]->userid;
  1897. else
  1898. $user_next = "-1";
  1899. $position = "&row= $x&column=$j";
  1900. $url = "" . $CFG->wwwroot . "/mod/iassign/view.php?action=viewsubmission&id=" . $id . "&iassign_submission_current=" . $student_submissions->id .
  1901. "&userid_iassign=" . $users_array[$x]->userid . "&iassign_current=" . $num[$j]->iassignid . "&view_iassign=" . $this->view_iassign;
  1902. $url .= $position;
  1903. // receiver=1 - message to teacher
  1904. // receiver=2 - message to student
  1905. // $verify_message = $DB->get_record_sql("SELECT COUNT(iassign_submissionid) FROM {$CFG->prefix}ia_assign_submissions_comment " .
  1906. // "WHERE iassign_submissionid = '$student_submissions->id' AND return_status='0' AND receiver='1'");
  1907. $params = array('iassign_submissionid' => $student_submissions->id, 'return_status' => '0', 'receiver' => '1');
  1908. $verify_message = $DB->get_record_sql(
  1909. "SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
  1910. "WHERE iassign_submissionid = :iassign_submissionid " .
  1911. " AND return_status= :return_status " .
  1912. " AND receiver= :receiver", $params);
  1913. if ($verify_message)
  1914. foreach ($verify_message as $tmp)
  1915. $sum_verify_message = $tmp;
  1916. if ($sum_verify_message > 0)
  1917. $comment = iassign_icons::insert('comment_unread');
  1918. else
  1919. $comment = iassign_icons::insert('comment_read');
  1920. if ($student_submissions->status == 3) {
  1921. $sum_iassign_correct[$j] ++;
  1922. $total_student ++;
  1923. $feedback = iassign_icons::insert('correct');
  1924. }
  1925. elseif ($student_submissions->status == 2) {
  1926. $feedback = iassign_icons::insert('incorrect');
  1927. }
  1928. elseif ($student_submissions->status == 1) {
  1929. $feedback = iassign_icons::insert('post');
  1930. }
  1931. elseif ($student_submissions->status == 0) {
  1932. $feedback = iassign_icons::insert('not_post');
  1933. }
  1934. if ($this->action != 'print') {
  1935. print '<table><tr>';
  1936. if ($tentativas > 0)
  1937. print '<td> <a href="' . $url . '" ' . $last_solution_submission . '>' . $feedback . '</a> &nbsp;(' . $tentativas . ')</td>' . "\n";
  1938. else
  1939. print '<td> <a href="' . $url . '" ' . $last_solution_submission . '>' . $feedback . '</a> </td>' . "\n";
  1940. print '<td> &nbsp; </td>';
  1941. print '</tr>' . "\n";
  1942. if ($sum_comment > 0 && $sum_verify_message > 0)
  1943. print '<tr><td colspan="2"> <a href="' . $url . '"> ' . $comment . '</a> &nbsp;(' . $sum_verify_message . '/' . $sum_comment . ') </td></tr>' . "\n";
  1944. else if ($sum_comment > 0)
  1945. print '<tr><td colspan="2"> <a href="' . $url . '"> ' . $comment . '</a> &nbsp;(' . $sum_comment . ') </td></tr>' . "\n";
  1946. print '</table>' . "\n";
  1947. }
  1948. if ($this->action == 'print')
  1949. print $feedback . '&nbsp;(' . $tentativas . ')<br>' . $comment . '&nbsp;(' . $sum_comment . ')&nbsp;' . "\n";
  1950. } // if ($student_submissions)
  1951. else { // if ($student_submissions)
  1952. // informations to browse previous activities
  1953. if ($j - 1 < 1 || $j == $i)
  1954. $iassign_previous = "-1";
  1955. else
  1956. $iassign_previous = $num[$j - 1]->iassignid;
  1957. if ($x - 1 < 0 || $x == $w)
  1958. $user_previous = "-1";
  1959. else
  1960. $user_previous = $users_array[$x - 1]->userid;
  1961. // next
  1962. if ($i - 1 > $j)
  1963. $iassign_next = $num[$j + 1]->iassignid;
  1964. else
  1965. $iassign_next = "-1";
  1966. if ($w - 1 > $x)
  1967. $user_next = $users_array[$x + 1]->userid;
  1968. else
  1969. $user_next = "-1";
  1970. $position = "&row= $x&column=$j";
  1971. $url = $CFG->wwwroot . "/mod/iassign/view.php?action=viewsubmission&id=" . $id . "&userid_iassign=" . $users_array[$x]->userid .
  1972. "&iassign_current=" . $num[$j]->iassignid . "&view_iassign=" . $this->view_iassign;
  1973. $url .= $position;
  1974. $feedback = iassign_icons::insert('not_post');
  1975. if ($this->action == 'print')
  1976. print $feedback . '&nbsp;(0)<br>' . $comment . '&nbsp;(' . $sum_comment . ')&nbsp;' . "\n";
  1977. else {
  1978. print '<table><tr>';
  1979. print '<td> <a href="' . $url . '">' . $feedback . '</a> </td>' . "\n";
  1980. print '<td> &nbsp; </td>';
  1981. print '</tr><tr>' . "\n";
  1982. print '<td> &nbsp;</td>';
  1983. if ($sum_comment > 0)
  1984. print '<td> <a href="' . $url . '">' . $comment . '</a> &nbsp;(' . $sum_comment . ') </td>' . "\n";
  1985. else
  1986. print '<td> &nbsp;</td>';
  1987. print '</tr></table>';
  1988. }
  1989. } // else if ($student_submissions)
  1990. $USER->matrix_iassign[$x][$j] = new stdClass();
  1991. $USER->matrix_iassign[$x][$j]->iassign_previous = $iassign_previous;
  1992. $USER->matrix_iassign[$x][$j]->user_previous = $user_previous;
  1993. $USER->matrix_iassign[$x][$j]->iassign_next = $iassign_next;
  1994. $USER->matrix_iassign[$x][$j]->user_next = $user_next;
  1995. if ($student_submissions)
  1996. $USER->matrix_iassign[$x][$j]->iassign_submission_current = $student_submissions->id;
  1997. else
  1998. $USER->matrix_iassign[$x][$j]->iassign_submission_current = 0;
  1999. print '</td>' . "\n";
  2000. } // for ($j=1; $j<$i; $j++)
  2001. $total = $total + $total_student;
  2002. $porcentagem = ($total_student / ($j - 1)) * 100;
  2003. if ($tentativas != 0 && $tentativas != null) {
  2004. $url_answer = "" . $CFG->wwwroot . "/mod/iassign/view.php?" . "action=download_all_answer&iassign_id=" . $this->iassign->id . "&userid=" . $users_array[$x]->userid . "&id=" . $id;
  2005. print ' <td align="center"><a href="' . $url_answer . '">' . iassign_icons::insert('download_all_assign') . '</a></td>' . "\n";
  2006. }
  2007. else {
  2008. print ' <td align="center">' . iassign_icons::insert('download_all_assign_disabled') . '</td>' . "\n";
  2009. }
  2010. print '</tr>' . "\n";
  2011. $sum_correct_student[$sum_student] = new stdClass();
  2012. $sum_correct_student[$sum_student]->name = $name;
  2013. $sum_correct_student[$sum_student]->sum = $total_student;
  2014. } // for ($x = 0; $x < $w; $x ++)
  2015. for ($i = 1; $i < $j; $i ++) {
  2016. if (is_null($sum_iassign_correct[$i]))
  2017. $sum_iassign_correct[$i] = 0;
  2018. $sum_correct_iassign[$i] = new stdClass();
  2019. $sum_correct_iassign[$i]->sum = $sum_iassign_correct[$i];
  2020. $sum_correct_iassign[$i]->name = $num[$i]->name;
  2021. }
  2022. // print '</tr></table>' . "\n";
  2023. }
  2024. } // if ($i>1)
  2025. else {
  2026. print_string('no_activity', 'iassign');
  2027. }
  2028. print "</table>\n";
  2029. if ($this->action != 'print')
  2030. print $OUTPUT->footer();
  2031. die();
  2032. } // function report()
  2033. /// Display graphics of performance
  2034. function stats () {
  2035. global $USER, $CFG, $DB, $OUTPUT;
  2036. $id = $this->cm->id;
  2037. $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array('iassignid' => $this->iassign->id), "position ASC");
  2038. if ($this->action != 'printstats')
  2039. $title = get_string('graphic', 'iassign');
  2040. $num = array();
  2041. $sum_correct_iassign = array();
  2042. $sum_correct_student = array();
  2043. $sum_student = 0;
  2044. $i = 1;
  2045. foreach ($iassign_list as $iassign) {
  2046. $iassign_submission = $DB->get_records("iassign_submission", array("iassign_statementid" => $iassign->id));
  2047. if ($iassign->type_iassign == 3) { // || ($iassign_submission)
  2048. $sum_iassign_correct[$i] = 0;
  2049. $num[$i] = new stdClass();
  2050. $num[$i]->name = $iassign->name;
  2051. $num[$i]->id = $i;
  2052. $num[$i]->iassignid = $iassign->id;
  2053. $i ++;
  2054. } // if ($iassign->type_iassign == 3)
  2055. } // foreach ($iassign_list as $iassign)
  2056. $sum_iassign = $i - 1;
  2057. $context = context_course::instance($this->course->id);
  2058. if ($i > 1) {
  2059. // $role = $DB->get_record_sql("SELECT s.id, s.shortname FROM {$CFG->prefix}role s WHERE s.shortname = 'student'");
  2060. $params = array('shortname' => 'student');
  2061. $role = $DB->get_record_sql(
  2062. "SELECT s.id, s.shortname FROM {role} s " .
  2063. " WHERE s.shortname = :shortname", $params);
  2064. // $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");
  2065. $params = array('contextid' => $context->id, 'roleid' => $role->id);
  2066. $students = $DB->get_records_sql(
  2067. "SELECT s.userid, a.firstname, a.lastname FROM {role_assignments} s, {user} a " .
  2068. " WHERE s.contextid = :contextid AND s.userid = a.id AND s.roleid = :roleid " .
  2069. " ORDER BY a.firstname ASC,a.lastname ASC", $params);
  2070. $total = 0;
  2071. $sum_student = 0;
  2072. $j = 0;
  2073. $sum_correct_iassign = array();
  2074. $sum_correct_student = array();
  2075. $sum_experiment = array();
  2076. if ($students) {
  2077. foreach ($students as $users) {
  2078. $sum_student ++;
  2079. $name = $users->firstname . '&nbsp;' . $users->lastname;
  2080. // rows
  2081. $total_student = 0;
  2082. for ($j = 1; $j < $i; $j ++) {
  2083. $total_experiment = 0;
  2084. $student_submissions = $DB->get_record("iassign_submission", array('iassign_statementid' => $num[$j]->iassignid, 'userid' => $users->userid)); // data about student solution
  2085. if ($student_submissions) {
  2086. if ($student_submissions->status == 3) {
  2087. $sum_iassign_correct[$j] ++;
  2088. $total_student ++;
  2089. } // if ($student_submissions->status == 3)
  2090. $total_experiment += $student_submissions->experiment;
  2091. }
  2092. $sum_experiment[$j] = $total_experiment;
  2093. } // for ($j=1; $j<$i; $j++)
  2094. $total = $total + $total_student;
  2095. $sum_correct_student[$sum_student] = new stdClass();
  2096. $sum_correct_student[$sum_student]->name = $name;
  2097. $sum_correct_student[$sum_student]->sum = $total_student;
  2098. } // foreach ($students as $users)
  2099. }
  2100. for ($i = 1; $i < $j; $i ++) {
  2101. if (is_null($sum_iassign_correct[$i]))
  2102. $sum_iassign_correct[$i] = 0;
  2103. $sum_correct_iassign[$i] = new stdClass();
  2104. $sum_correct_iassign[$i]->sum = $sum_iassign_correct[$i];
  2105. $sum_correct_iassign[$i]->name = $num[$i]->name;
  2106. $sum_correct_iassign[$i]->experiment = $sum_experiment[$i];
  2107. } // for ($i = 1; $i < $j; $i++)
  2108. } // if ($i > 1)
  2109. if ($this->action != 'printstats') {
  2110. $title = get_string('graphic', 'iassign');
  2111. print $OUTPUT->header();
  2112. $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>";
  2113. $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>";
  2114. print '<table width=100%><tr>';
  2115. print '<td align="right">' . $link_print_stats . '</td>' . "\n";
  2116. print '<td width=15% align="right">' . $link_report . '</td>';
  2117. print '</td></tr></table>' . "\n";
  2118. print "<br><br>";
  2119. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  2120. print '<tr><th colspan=5 class="header c1">' . get_string('distribution_activity', 'iassign') . '</th></tr>' . "\n";
  2121. print '<tr><td class=\'cell c0 actvity\' width=35%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
  2122. print '<td class=\'cell c0 actvity\' width=35%><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>' . "\n";
  2123. print '<td class=\'cell c0 actvity\' width=10% align="right"><strong>' . get_string('proportion_correct', 'iassign') . '</strong>' . "\n";
  2124. print '<td class=\'cell c0 actvity\' width=10% align="right"><strong>' . get_string('sum_experiment', 'iassign') . '</strong></td>' . "\n";
  2125. print '<td class=\'cell c0 actvity\' width=10% align="right"><strong>' . get_string('avg_experiment', 'iassign') . '</strong></td>' . "\n";
  2126. print '</tr>' . "\n";
  2127. $sum_correct = 0;
  2128. if ($sum_correct_iassign) {
  2129. foreach ($sum_correct_iassign as $iassign) {
  2130. if (is_null($iassign->experiment))
  2131. $iassign->experiment = 0;
  2132. $bar = "";
  2133. $sum = $iassign->sum;
  2134. $percent = ($sum / $sum_student) * 100;
  2135. $text = number_format($percent, 1) . '%';
  2136. $sum_correct += $sum;
  2137. if ($sum > 0) {
  2138. for ($i = 1; $i < $percent * 2; $i ++)
  2139. $bar .= iassign_icons::insert('hbar_blue');
  2140. $bar .= iassign_icons::insert('hbar_blue_r');
  2141. } // if ($sum > 0)
  2142. print '<tr ><td class=\'cell c0 actvity\'width=35%>' . $iassign->name . '</td>' . "\n";
  2143. print ' <td class=\'cell c0 actvity\' width=35%>' . $bar . '&nbsp;' . $text . '</td>' . "\n";
  2144. print ' <td class=\'cell c0 actvity\' width=10% align="right">' . $sum . '/' . $sum_student . '</td>' . "\n";
  2145. print ' <td class=\'cell c0 actvity\' width=10% align="right">' . $iassign->experiment . '</td>' . "\n";
  2146. print ' <td class=\'cell c0 actvity\' width=10% align="right">' . number_format($iassign->experiment / $sum_iassign, 1) . '</td>' . "\n";
  2147. print '</tr>' . "\n";
  2148. } // foreach ($sum_correct_iassign as $iassign)
  2149. }
  2150. print "</table>";
  2151. print "<br><br>";
  2152. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  2153. print '<tr><th colspan=3 class="header c1">' . get_string('distribution_student', 'iassign') . '</th></tr>' . "\n";
  2154. print '<tr><td class=\'cell c0 actvity\' width=50%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
  2155. print ' <td class=\'cell c0 actvity\' width=40%><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>';
  2156. print ' <td class=\'cell c0 actvity\' width=10% align="right"><strong>' . get_string('sum_correct', 'iassign') . '</strong></td>';
  2157. print '</tr>' . "\n";
  2158. $sum_correct = 0;
  2159. foreach ($sum_correct_student as $student) {
  2160. $bar = "";
  2161. $sum = $student->sum;
  2162. $percent = ($sum / $sum_iassign) * 100;
  2163. $text = number_format($percent, 1) . '%';
  2164. $sum_correct += $sum;
  2165. if ($sum > 0) {
  2166. for ($i = 1; $i < $percent * 2; $i ++)
  2167. $bar .= iassign_icons::insert('hbar_blue');
  2168. $bar .= iassign_icons::insert('hbar_blue_r');
  2169. } // if ($sum > 0)
  2170. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . $student->name . '</td>' . "\n";
  2171. print '<td class=\'cell c0 actvity\' width=40%>' . $bar . '&nbsp;' . $text . '</td>' . "\n";
  2172. print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum . '/' . $sum_iassign . '</td>' . "\n";
  2173. print '</tr>' . "\n";
  2174. } // foreach ($sum_correct_student as $student)
  2175. print "</table>\n";
  2176. print "<br><br>\n";
  2177. $var = 0;
  2178. $cv = 0;
  2179. $dv = 0;
  2180. $avg = 0;
  2181. if ($sum_correct_student) {
  2182. $avg = $sum_correct / $sum_student;
  2183. if ($avg > 0) {
  2184. foreach ($sum_correct_student as $student)
  2185. $var += pow($student->sum - $avg, 2);
  2186. $var = $var / $sum_student;
  2187. $dv = sqrt($var);
  2188. $cv = ($dv / $avg) * 100;
  2189. }
  2190. }
  2191. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  2192. print '<tr><th colspan=5 class="header c1">' . get_string('statistics', 'iassign') . '</th></tr>' . "\n";
  2193. print '<tr><td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('sum_activity', 'iassign') . '</strong></td>' . "\n";
  2194. print ' <td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('sum_student', 'iassign') . '</strong></td>' . "\n";
  2195. print ' <td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('mean_score', 'iassign') . '</strong></td>' . "\n";
  2196. print ' <td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('standard_deviation', 'iassign') . '</strong></td>' . "\n";
  2197. print ' <td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('coefficient_variation', 'iassign') . '</strong></td></tr>' . "\n";
  2198. print '<tr><td class=\'cell c0 actvity\' width=20% align="center">' . $sum_iassign . '</td>' . "\n";
  2199. print ' <td class=\'cell c0 actvity\' width=20% align="center">' . $sum_student . '</td>' . "\n";
  2200. print ' <td class=\'cell c0 actvity\' width=20% align="center">' . number_format($avg, 1) . '</td>' . "\n";
  2201. print ' <td class=\'cell c0 actvity\' width=20% align="center">' . number_format($dv, 1) . '</td>' . "\n";
  2202. print ' <td class=\'cell c0 actvity\' width=20% align="center">' . number_format($cv, 1) . '%</td></tr>' . "\n";
  2203. print "</table>\n";
  2204. print $OUTPUT->footer();
  2205. } else {
  2206. print "<STYLE TYPE='text/css'>
  2207. <!--
  2208. .boldtable {
  2209. font-family:sans-serif;
  2210. font-size:10pt;
  2211. }
  2212. -->
  2213. </STYLE>\n";
  2214. print '<table border=1 width=100%>' . "\n";
  2215. print '<tr><td colspan=3 align="center"><strong>' . get_string('distribution_activity', 'iassign') . '</strong></td></tr>' . "\n";
  2216. print '<tr><td width=50%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
  2217. print '<td width=40%><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>';
  2218. print '<td width=10% align="right"><strong>' . get_string('sum_correct', 'iassign') . '</strong></td>';
  2219. print '</tr>' . "\n";
  2220. $sum_correct = 0;
  2221. foreach ($sum_correct_iassign as $iassign) {
  2222. $bar = "";
  2223. $sum = $iassign->sum;
  2224. $percent = ($sum / $sum_student) * 100;
  2225. $text = number_format($percent, 1) . '%';
  2226. $sum_correct += $sum;
  2227. if ($sum > 0) {
  2228. for ($i = 1; $i < $percent * 2; $i ++)
  2229. $bar .= iassign_icons::insert('hbar_blue');
  2230. $bar .= iassign_icons::insert('hbar_blue_r');
  2231. } // if ($sum > 0)
  2232. print '<tr><td width=50%>' . $iassign->name . '</td>' . "\n";
  2233. print '<td width=40%>' . $bar . '&nbsp;' . $text . '</td>';
  2234. print '<td width=10% align="right">' . $sum . '/' . $sum_student . '</td>';
  2235. print '</tr>' . "\n";
  2236. } // foreach ($sum_correct_iassign as $iassign)
  2237. print "</table>";
  2238. print "<br><br>";
  2239. print '<table border=1 class="boldtable" width=100%>' . "\n";
  2240. print '<tr><td colspan=3 align="center" ><strong>' . get_string('distribution_student', 'iassign') . '</strong></td></tr>' . "\n";
  2241. print '<tr><td width=50%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
  2242. print '<td width=40%><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>';
  2243. print '<td width=10% align="right"><strong>' . get_string('sum_correct', 'iassign') . '</strong></td>';
  2244. print '</tr>' . "\n";
  2245. $sum_correct = 0;
  2246. foreach ($sum_correct_student as $student) {
  2247. $bar = "";
  2248. $sum = $student->sum;
  2249. $percent = ($sum / $sum_iassign) * 100;
  2250. $text = number_format($percent, 1) . '%';
  2251. $sum_correct += $sum;
  2252. if ($sum > 0) {
  2253. for ($i = 1; $i < $percent * 2; $i ++)
  2254. $bar .= iassign_icons::insert('hbar_blue');
  2255. $bar .= iassign_icons::insert('hbar_blue_r');
  2256. } // if ($sum > 0)
  2257. print "<tr><td width=50%>" . $student->name . "</td>\n";
  2258. print ' <td width=40%>' . $bar . '&nbsp;' . $text . '</td>' . "\n";
  2259. print ' <td width=10% align="right">' . $sum . '/' . $sum_iassign . '</td>' . "\n";
  2260. print '</tr>' . "\n";
  2261. } // foreach ($sum_correct_student as $student)
  2262. print "</table>\n";
  2263. print "<br/><br/>\n";
  2264. $var = 0;
  2265. $cv = 0;
  2266. $dv = 0;
  2267. $avg = 0;
  2268. if ($sum_correct_student) {
  2269. $avg = $sum_correct / $sum_student;
  2270. if ($avg > 0) {
  2271. foreach ($sum_correct_student as $student)
  2272. $var += pow($student->sum - $avg, 2);
  2273. $var = $var / $sum_student;
  2274. $dv = sqrt($var);
  2275. $cv = ($dv / $avg) * 100;
  2276. }
  2277. }
  2278. print '<table border=1 class="boldtable" width=100%>' . "\n";
  2279. print '<tr><td colspan=5 align="center"><strong>' . get_string('statistics', 'iassign') . '</strong></th></tr>' . "\n";
  2280. print '<tr><td width=20% align="center"><strong>' . get_string('sum_activity', 'iassign') . '</strong></td>' . "\n";
  2281. print '<td width=20% align="center"><strong>' . get_string('sum_student', 'iassign') . '</strong></td>' . "\n";
  2282. print '<td width=20% align="center"><strong>' . get_string('mean_score', 'iassign') . '</strong></td>' . "\n";
  2283. print '<td width=20% align="center"><strong>' . get_string('standard_deviation', 'iassign') . '</strong></td>' . "\n";
  2284. print '<td width=20% align="center"><strong>' . get_string('coefficient_variation', 'iassign') . '</strong></td></tr>' . "\n";
  2285. print '<tr><td width=20% align="center">' . $sum_iassign . '</td>' . "\n";
  2286. print '<td width=20% align="center">' . $sum_student . '</td>' . "\n";
  2287. print '<td width=20% align="center">' . number_format($avg, 1) . '</td>' . "\n";
  2288. print '<td width=20% align="center">' . number_format($dv, 1) . '</td>' . "\n";
  2289. print '<td width=20% align="center">' . number_format($cv, 1) . '%</td></tr>' . "\n";
  2290. print "</table>\n";
  2291. } // if ($this->action != 'printstats')
  2292. die();
  2293. }
  2294. /// Display graphics of performance for students
  2295. function stats_students () {
  2296. global $USER, $CFG, $DB, $OUTPUT;
  2297. $id = $this->cm->id;
  2298. $iassign_statement_list = $DB->get_records_sql("SELECT * FROM {iassign_statement} s " .
  2299. " WHERE s.iassignid = '{$this->iassign->id}' AND s.type_iassign=3 ORDER BY s.position");
  2300. $title = get_string('results', 'iassign');
  2301. $sum_correct = 0;
  2302. $sum_incorrect = 0;
  2303. $sum_post = 0;
  2304. $sum_nopost = 0;
  2305. $sum_iassign = count($iassign_statement_list);
  2306. $bar_nopost = "";
  2307. $bar_correct = "";
  2308. $bar_incorrect = "";
  2309. $bar_post = "";
  2310. $text_nopost = "";
  2311. $text_correct = "";
  2312. $text_incorrect = "";
  2313. foreach ($iassign_statement_list as $iassign_statement_activity_item) {
  2314. $iassign_submission = $DB->get_record("iassign_submission", array('iassign_statementid' => $iassign_statement_activity_item->id, 'userid' => $USER->id)); // data about student solution
  2315. if ($iassign_submission) {
  2316. if ($iassign_submission->status == 3)
  2317. $sum_correct ++;
  2318. elseif ($iassign_submission->status == 2)
  2319. $sum_incorrect ++;
  2320. elseif ($iassign_submission->status == 1)
  2321. $sum_post ++;
  2322. elseif ($iassign_submission->status == 0 || !$iassign_submission)
  2323. $sum_nopost ++;
  2324. } // if ($iassign_submission)
  2325. } // foreach ($iassign_statement_list as $iassign_statement_activity_item)
  2326. if ($sum_iassign > 0) {
  2327. $percent_correct = ($sum_correct / $sum_iassign) * 100;
  2328. $text_correct = number_format($percent_correct, 1) . '%';
  2329. }
  2330. if ($sum_correct > 0) {
  2331. for ($i = 1; $i < $percent_correct * 2; $i ++)
  2332. $bar_correct .= iassign_icons::insert('hbar_green');
  2333. $bar_correct .= iassign_icons::insert('hbar_green_r');
  2334. } // if ($sum_correct > 0)
  2335. if ($sum_iassign > 0) {
  2336. $percent_incorrect = ($sum_incorrect / $sum_iassign) * 100;
  2337. $text_incorrect = number_format($percent_incorrect, 1) . '%';
  2338. }
  2339. if ($sum_incorrect > 0) {
  2340. for ($i = 1; $i < $percent_incorrect * 2; $i ++)
  2341. $bar_incorrect .= iassign_icons::insert('hbar_red');
  2342. $bar_incorrect .= iassign_icons::insert('hbar_red_r');
  2343. } // if ($sum_incorrect > 0)
  2344. if ($sum_iassign > 0) {
  2345. $percent_post = ($sum_post / $sum_iassign) * 100;
  2346. $text_post = number_format($percent_post, 1) . '%';
  2347. }
  2348. if ($sum_post > 0) {
  2349. for ($i = 1; $i < $percent_post * 2; $i ++)
  2350. $bar_post .= iassign_icons::insert('hbar_blue');
  2351. $bar_post .= iassign_icons::insert('hbar_blue_r');
  2352. } // if ($sum_post > 0)
  2353. if ($sum_iassign > 0) {
  2354. $percent_nopost = ($sum_nopost / $sum_iassign) * 100;
  2355. $text_nopost = number_format($percent_nopost, 1) . '%';
  2356. }
  2357. if ($sum_nopost > 0) {
  2358. for ($i = 1; $i < $percent_nopost * 2; $i ++)
  2359. $bar_nopost .= iassign_icons::insert('hbar_orange');
  2360. $bar_nopost .= iassign_icons::insert('hbar_orange_r');
  2361. } // if ($sum_nopost > 0)
  2362. print $OUTPUT->header();
  2363. $link_return = "&nbsp;<a href='" . $this->return . "'>" . iassign_icons::insert('home') . get_string('activities_page', 'iassign') . "</a>";
  2364. print '<table width=100%><tr>';
  2365. print '<td align="right">' . $link_return . '</td>' . "\n";
  2366. print '</td></tr></table>' . "\n";
  2367. print "<br/><br/>\n";
  2368. print '<table id="outlinetable" class="generaltable box aligncenter" cellpadding="5" width="100%">' . "\n";
  2369. print '<tr><th colspan=3 class="header c1">' . "\n";
  2370. // helpbutton('legend', get_string('legend', 'iassign'), 'iassign', $image = true, $linktext = false, $text = '', $return = false,
  2371. // $imagetext = '');
  2372. print iassign_utils::remove_code_message($this->iassign->name) . '</th></tr>' . "\n";
  2373. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . get_string('correct', 'iassign') . '</td>' . "\n";
  2374. print '<td class=\'cell c0 actvity\' width=40%>' . $bar_correct . '&nbsp;' . $text_correct . '</td>';
  2375. print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum_correct . '/' . $sum_iassign . '</td>';
  2376. print '</tr>' . "\n";
  2377. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . get_string('incorrect', 'iassign') . '</td>' . "\n";
  2378. print '<td class=\'cell c0 actvity\' width=40%>' . $bar_incorrect . '&nbsp;' . $text_incorrect . '</td>';
  2379. print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum_incorrect . '/' . $sum_iassign . '</td>';
  2380. print '</tr>' . "\n";
  2381. if ($sum_post) {
  2382. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . get_string('post', 'iassign') . '</td>' . "\n";
  2383. print '<td class=\'cell c0 actvity\' width=40%>' . $bar_post . '&nbsp;' . $text_post . '</td>';
  2384. print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum_post . '/' . $sum_iassign . '</td>';
  2385. print '</tr>' . "\n";
  2386. } // if ($sum_post)
  2387. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . get_string('not_post', 'iassign') . '</td>' . "\n";
  2388. print '<td class=\'cell c0 actvity\' width=40%>' . $bar_nopost . '&nbsp;' . $text_nopost . '</td>';
  2389. print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum_nopost . '/' . $sum_iassign . '</td>';
  2390. print '</tr>' . "\n";
  2391. print "</table>";
  2392. print "<br><br>";
  2393. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  2394. print '<tr><th colspan=3 class="header c1">' . get_string('grades', 'iassign') . '</th></tr>' . "\n";
  2395. print '<tr><td class=\'cell c0 actvity\' width=50%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
  2396. print '<td class=\'cell c0 actvity\' width=25% align=right><strong>' . get_string('grade_student', 'iassign') . '</strong></td>' . "\n";
  2397. print '<td class=\'cell c0 actvity\' width=25% align=right><strong>' . get_string('grade_iassign', 'iassign') . '</strong></tr>' . "\n";
  2398. $sum_grade = 0;
  2399. $sum_grade_student = 0;
  2400. $avg = 0;
  2401. foreach ($iassign_statement_list as $iassign_statement_activity_item) {
  2402. $iassign_submission = $DB->get_record("iassign_submission", array('iassign_statementid' => $iassign_statement_activity_item->id, 'userid' => $USER->id));
  2403. if (!$iassign_submission) {
  2404. $iassign_submission = new stdClass();
  2405. $iassign_submission->grade = 0;
  2406. }
  2407. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . $iassign_statement_activity_item->name . '</td>' . "\n";
  2408. print '<td class=\'cell c0 actvity\' width=25% align=right>' . $iassign_submission->grade . '</td>';
  2409. print '<td class=\'cell c0 actvity\' width=25% align=right>' . $iassign_statement_activity_item->grade . '</td>';
  2410. print '</tr>' . "\n";
  2411. $sum_grade += $iassign_statement_activity_item->grade;
  2412. $sum_grade_student += $iassign_submission->grade;
  2413. } // foreach ($iassign_statement_list as $iassign_statement_activity_item)
  2414. if ($sum_grade > 0)
  2415. $avg = $sum_grade_student / $sum_grade * 100;
  2416. print '<tr><td class=\'cell c0 actvity\' width=50%><strong>' . get_string('total', 'iassign') . '</strong></td>' . "\n";
  2417. print '<td class=\'cell c0 actvity\' width=25% align=right><strong>' . $sum_grade_student . '</strong></td>' . "\n";
  2418. print '<td class=\'cell c0 actvity\' width=25% align=right><strong>' . $sum_grade . '</strong></tr>' . "\n";
  2419. print '<tr><td class=\'cell c0 actvity\' width=25% align=left><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>' . "\n";
  2420. print '<td colspan=2 class=\'cell c0 actvity\' align=right><strong>' . number_format($avg, 1) . '%</strong></tr>' . "\n";
  2421. print "</table>";
  2422. print $OUTPUT->footer();
  2423. die();
  2424. } // function stats_students()
  2425. /// Display page of iAssign's activity
  2426. function view_iassigns () {
  2427. global $USER, $CFG, $COURSE, $DB, $OUTPUT;
  2428. $id = $this->cm->id;
  2429. $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array('iassignid' => $this->iassign->id), 'position ASC');
  2430. $notice = optional_param('notice', '', PARAM_TEXT);
  2431. if (strpos($notice, 'error'))
  2432. print($OUTPUT->notification(get_string($notice, 'iassign'), 'notifyproblem'));
  2433. else if ($notice != '')
  2434. print($OUTPUT->notification(get_string($notice, 'iassign'), 'notifysuccess'));
  2435. print $OUTPUT->box_start();
  2436. print '<table width=100% border=0><tr>' . "\n";
  2437. $url_help = new moodle_url('/mod/iassign/settings_ilm.php', array('action' => 'list', 'ilm_id' => 1));
  2438. $action_help = new popup_action('click', $url_help, 'iplookup', array('title' => get_string('help_ilm', 'iassign'), 'width' => 1200, 'height' => 700));
  2439. $link_help = $OUTPUT->action_link($url_help, iassign_icons::insert('help_ilm') . get_string('help_ilm', 'iassign'), $action_help);
  2440. $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>";
  2441. $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>";
  2442. // TODO: esta consulta esta sendo feita novamente na linha +/- 2258
  2443. if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id)) {
  2444. // could be "has_capability('mod/iassign:viewiassignall', $this->context, $USER->id)"
  2445. // Has capability to see "report": teacher or up
  2446. print '<td width=10% align="left">' . "\n";
  2447. print $link_help;
  2448. print '</td>' . "\n";
  2449. print '<td width=10% align="left">' . "\n";
  2450. print $link_report;
  2451. print '</td>' . "\n";
  2452. } // if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id))
  2453. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id)) {
  2454. print '<td width=15% align="left">' . "\n";
  2455. print $link_add;
  2456. print "</td>\n";
  2457. } // if (has_capability('mod/iassign:editiassign', $this->context, $USER->id))
  2458. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id)) {
  2459. if ($iassign_list) {
  2460. print '<td align="right">' . "\n";
  2461. // $USER->iassignEdit == 0 view 'Turn editing off'
  2462. // $USER->iassignEdit == 1 view 'Turn editing on'
  2463. if (!isset($USER->iassignEdit))
  2464. $USER->iassignEdit = 0;
  2465. if ($USER->iassignEdit == 0) {
  2466. $bottonEdit_message = get_string('turneditingon', 'iassign');
  2467. $botton = 1;
  2468. } // if ($USER->iassignEdit == 0)
  2469. elseif ($USER->iassignEdit == 1) {
  2470. $bottonEdit_message = get_string('turneditingoff', 'iassign');
  2471. $botton = 0;
  2472. } // elseif ($USER->iassignEdit == 1)
  2473. $editPost = "" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&botton=" . $botton;
  2474. print "\n<form name='formEditPost' id='formEditPost' method='post' action='$editPost' enctype='multipart/form-data'>\n";
  2475. print " <input type=submit value='$bottonEdit_message'/>\n";
  2476. print "</form>\n";
  2477. print "</td>\n";
  2478. } // if ($iassign_list)
  2479. }
  2480. print '</tr></table>' . "\n";
  2481. if (has_capability('mod/iassign:submitiassign', $this->context, $USER->id))
  2482. $this->view_legend_icons();
  2483. print $OUTPUT->box_end();
  2484. $iassign_array_exercise = array();
  2485. $i_exercise = 0;
  2486. $iassign_array_test = array();
  2487. $i_test = 0;
  2488. $iassign_array_example = array();
  2489. $i_example = 0;
  2490. $iassign_array_general = array();
  2491. $i_general = 0;
  2492. if ($iassign_list) {
  2493. if ($this->iassign->activity_group == 0) {
  2494. foreach ($iassign_list as $iassign) {
  2495. $iassign_array_general[$i_general] = $iassign;
  2496. $i_general ++;
  2497. }
  2498. } // if ($this->iassign->activity_group == 0)
  2499. else {
  2500. foreach ($iassign_list as $iassign) {
  2501. if ($iassign->type_iassign == 3) {
  2502. $iassign_array_exercise[$i_exercise] = $iassign;
  2503. $i_exercise ++;
  2504. } // if ($iassign->type_iassign == 3)
  2505. if ($iassign->type_iassign == 2) {
  2506. $iassign_array_test[$i_test] = $iassign;
  2507. $i_test ++;
  2508. } // if ($iassign->type_iassign == 2)
  2509. if ($iassign->type_iassign == 1) {
  2510. $iassign_array_example[$i_example] = $iassign;
  2511. $i_example ++;
  2512. } // if ($iassign->type_iassign == 1)
  2513. }
  2514. }
  2515. if ($iassign_array_exercise) {
  2516. $title = get_string('exercise', 'iassign');
  2517. $this->show_iassign($title, $iassign_array_exercise, $i_exercise);
  2518. }
  2519. if ($iassign_array_test) {
  2520. $title = get_string('test', 'iassign');
  2521. $this->show_iassign($title, $iassign_array_test, $i_test);
  2522. }
  2523. if ($iassign_array_example) {
  2524. $title = get_string('example', 'iassign');
  2525. $this->show_iassign($title, $iassign_array_example, $i_example);
  2526. }
  2527. if ($iassign_array_general) {
  2528. $title = "";
  2529. $this->show_iassign($title, $iassign_array_general, $i_general);
  2530. }
  2531. } else { // if ($iassign_list)
  2532. print $OUTPUT->notification(get_string('no_activity', 'iassign'), 'notifysuccess');
  2533. }
  2534. if (count($iassign_list) > 5 && !(has_capability('mod/iassign:submitiassign', $this->context, $USER->id))) {
  2535. if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id)) {
  2536. print $OUTPUT->box_start();
  2537. print '<table width=100% border=0><tr>' . "\n";
  2538. print '<td width=10% align="left">' . "\n";
  2539. print $link_report;
  2540. print '</td>' . "\n";
  2541. print '</tr></table>' . "\n";
  2542. print $OUTPUT->box_end();
  2543. } // if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id))
  2544. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id)) {
  2545. print $OUTPUT->box_start();
  2546. print '<table width=100% border=0><tr>' . "\n";
  2547. print '<td align="left">' . "\n";
  2548. print $link_add;
  2549. print '</td>' . "\n";
  2550. print '</tr></table>' . "\n";
  2551. print $OUTPUT->box_end();
  2552. } // if (has_capability('mod/iassign:editiassign', $this->context, $USER->id))
  2553. } // if (count($iassign_list) > 5 && !(has_capability('mod/iassign:submitiassign', $this->context, $USER->id)))
  2554. } // function view_iassigns()
  2555. /// Display all iAssigns
  2556. function show_iassign ($title, $iassign_array, $i) {
  2557. global $USER, $CFG, $DB, $OUTPUT, $PAGE;
  2558. $id = $this->cm->id;
  2559. print $OUTPUT->box_start();
  2560. print " <script type='text/javascript'>
  2561. //<![CDATA[
  2562. function validate_move () {
  2563. var radios = document.getElementsByName('iassign_destiny');
  2564. var formValid = false;
  2565. //alert('aqui validate_move()');
  2566. var i = 0;
  2567. while (!formValid && i < radios.length) {
  2568. if (radios[i].checked) formValid = true;
  2569. i++;
  2570. }
  2571. if (!formValid) {
  2572. document.getElementById('move_dest').classList.add('alert-danger');
  2573. }
  2574. return formValid;
  2575. }
  2576. var modal;
  2577. function load_move(id_ias) {
  2578. document.form_move_activity.iassign_current.value = id_ias;
  2579. modal.style.display = 'block';
  2580. var radios = document.getElementsByName('iassign_destiny');
  2581. var i = 0;
  2582. while (i < radios.length) {
  2583. radios[i].checked = false;
  2584. i++;
  2585. }
  2586. document.getElementById('move_dest').classList.remove('alert-danger');
  2587. }
  2588. function load_modal_elements() {
  2589. modal = document.getElementById('myModal');
  2590. var span = document.getElementById('close_modal');
  2591. span.onclick = function() {
  2592. modal.style.display = 'none';
  2593. }
  2594. window.onclick = function(event) {
  2595. if (event.target == modal) {
  2596. modal.style.display = 'none';
  2597. }
  2598. }
  2599. }
  2600. window.onload = load_modal_elements;
  2601. //]]>
  2602. </script>\n";
  2603. print " <div id='myModal' class='modal'>\n <div class='modal-content'>\n <span id='close_modal'>&times;</span>\n" .
  2604. " <div id='modal_title' class='moodle-dialogue-hd yui3-widget-hd'>" . get_string('move_activity', 'iassign') . "</div>\n" .
  2605. " <div style='padding: 10px; padding-left: 20px;' id='move_dest'>" . get_string('move_destination', 'iassign') . ":\n <div style='margin: 5px;'>";
  2606. $ccm = get_coursemodule_from_id('iassign', optional_param('id', 0, PARAM_INT));
  2607. $radio_buttons = " <form name='form_move_activity'><input type='hidden' name='action' value='move_activity' />
  2608. <input type='hidden' name='id' value='" . optional_param('id', NULL, PARAM_TEXT) . "' />
  2609. <input type='hidden' name='iassign_current' value='' />";
  2610. $course_sections = get_fast_modinfo($PAGE->course->id)->get_section_info_all();
  2611. $section = $course_sections[0];
  2612. $ids_sections = array_keys($section->__get('modinfo')->get_sections());
  2613. for ($k = 0; $k < count($ids_sections); $k++) {
  2614. $radio_buttons .= get_section_name($PAGE->course->id, $ids_sections[$k]). "<ul style='list-style-type: none'>";
  2615. for($j = 0; $j < count($section->__get('modinfo')->get_sections()[$ids_sections[$k]]); $j++) {
  2616. $c_cm = get_coursemodule_from_id('iassign', $section->__get('modinfo')->get_sections()[$ids_sections[$k]][$j]);
  2617. if ($c_cm) {
  2618. if ($ccm->instance == $c_cm->instance) {
  2619. $radio_buttons .= " <li><input type='radio' disabled='disabled' id='radio_" . $c_cm->instance . "' name='iassign_destiny' value='" . $c_cm->instance . "'>
  2620. <label for='radio_" . $c_cm->instance . "'>" . $c_cm->name . "</label></li>\n";
  2621. }
  2622. else {
  2623. $radio_buttons .= " <li><input type='radio' id='radio_" . $c_cm->instance . "' name='iassign_destiny' value='" . $c_cm->instance . "'>
  2624. <label class='input_move' for='radio_" . $c_cm->instance . "'>" . $c_cm->name . "</label></li>\n";
  2625. }
  2626. }
  2627. }
  2628. $radio_buttons .= "</ul>";
  2629. }
  2630. print $radio_buttons . " <center><input type='submit' value='OK' onClick='return validate_move();' />\n &nbsp;
  2631. <input type='button' value='" . get_string('cancel', 'iassign') . "' onClick='modal.style.display = \'none\';' /></center>
  2632. </form>
  2633. </div></div> </div></div>\n";
  2634. print " <style>.modal {
  2635. display: none;
  2636. position: fixed;
  2637. z-index: 1;
  2638. left: 0;
  2639. top: 0;
  2640. width: 100%;
  2641. height: 100%;
  2642. overflow: scroll;
  2643. background-color: rgb(0,0,0);
  2644. background-color: rgba(0,0,0,0.4);
  2645. }
  2646. .modal-content {
  2647. background-color: #fefefe;
  2648. margin: 15% auto;
  2649. padding: 10px 10px;
  2650. border: 1px solid #888;
  2651. width: 50%;
  2652. }
  2653. #close_modal {
  2654. color: #aaa;
  2655. float: right;
  2656. font-size: 28px;
  2657. font-weight: bold;
  2658. margin-top: -15px;
  2659. margin-right: -3px;
  2660. }
  2661. #close_modal:hover,
  2662. #close_modal:focus {
  2663. color: black;
  2664. text-decoration: none;
  2665. cursor: pointer;
  2666. }
  2667. #modal_title {
  2668. min-height: 3rem;
  2669. color: initial;
  2670. background: initial;
  2671. font-size: 1.5rem;
  2672. line-height: 1.5;
  2673. padding: 15px;
  2674. border-bottom: 1px solid #e5e5e5;
  2675. }
  2676. .input_move {
  2677. width: 90%;
  2678. padding: 2px;
  2679. }
  2680. .input_move:hover {
  2681. background: #eff0ef;
  2682. }
  2683. </style>";
  2684. if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id)) {
  2685. print "<p><font color='#0000aa'><strong>" . $title . "</strong></font></p>";
  2686. for ($j = 0; $j < $i; $j ++) {
  2687. $iassign_current = $iassign_array[$j]->id;
  2688. // receiver=1 - message to teacher
  2689. // receiver=2 - message to student
  2690. $sum_comment = 0;
  2691. $iassign_submissions = $DB->get_records('iassign_submission', array('iassign_statementid' => $iassign_current));
  2692. foreach ($iassign_submissions as $iassign_submission) {
  2693. $params = array('iassign_submissionid' => $iassign_submission->id, 'return_status' => '0', 'receiver' => '1');
  2694. $verify_message = $DB->get_record_sql("SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
  2695. " WHERE iassign_submissionid = :iassign_submissionid AND return_status= :return_status AND receiver= :receiver", $params);
  2696. if ($verify_message)
  2697. foreach ($verify_message as $tmp)
  2698. $sum_comment += $tmp;
  2699. } // foreach ($iassign_submissions as $iassign_submission)
  2700. if ($sum_comment == 0)
  2701. $comment_unread = "";
  2702. else {
  2703. $comment_unread_message = get_string('comment_unread', 'iassign');
  2704. if ($sum_comment == 1)
  2705. $comment_unread_message = get_string('comment_unread_one', 'iassign');
  2706. $comment_unread = "&nbsp;<a href='" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&action=report&iassignid=" . $this->iassign->id . "'><font color='red'>" .
  2707. iassign_icons::insert('comment_unread') . "&nbsp;($sum_comment&nbsp;" . $comment_unread_message . ")</font></a>";
  2708. }
  2709. if ($j == $i - 1)
  2710. $iassign_down = $iassign_array[$j]->id;
  2711. else
  2712. $iassign_down = $iassign_array[$j + 1]->id;
  2713. if ($j > 0)
  2714. $iassign_up = $iassign_array[$j - 1]->id;
  2715. else
  2716. $iassign_up = $iassign_array[$j]->id;
  2717. if ($iassign_array[$j]->visible == 0)
  2718. $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>";
  2719. else
  2720. $links = "&nbsp;<a href='view.php?id=$id&userid_iassign=$USER->id&action=view&iassign_current=$iassign_current'>" . $iassign_array[$j]->name . "</a>";
  2721. $links .= $comment_unread;
  2722. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id) && $USER->iassignEdit == 1) {
  2723. //D echo "id=$id, iassign_current=$iassign_current, iassign_up=$iassign_up, iassign_down=$iassign_down<br/>";
  2724. $str_aux = "&id=$id&iassign_current=$iassign_current&iassign_up=$iassign_up&iassign_down=$iassign_down";
  2725. $link_up = "&nbsp;<a href='view.php?action=up$str_aux'>" . iassign_icons::insert('move_up_iassign') . "</a>";
  2726. if ($j==0) // first activity
  2727. $link_down = "&nbsp;<a href='view.php?action=firstdown$str_aux'>" . iassign_icons::insert('move_down_iassign') . "</a>";
  2728. else
  2729. $link_down = "&nbsp;<a href='view.php?action=down$str_aux'>" . iassign_icons::insert('move_down_iassign') . "</a>";
  2730. $link_delete = "&nbsp;<a href='view.php?action=delete$str_aux'>" . iassign_icons::insert('delete_iassign') . "</a>";
  2731. $link_visible_hide = "&nbsp;<a href='view.php?action=visible$str_aux'>" . iassign_icons::insert('hide_iassign') . "</a>";
  2732. $link_visible_show = "&nbsp;<a href='view.php?action=visible$str_aux'>" . iassign_icons::insert('show_iassign') . "</a>";
  2733. $link_edit = "&nbsp;<a href='view.php?action=edit$str_aux'>" . iassign_icons::insert('edit_iassign') . "</a>";
  2734. $link_duplicate_activity = "&nbsp;<a href='view.php?action=duplicate_activity$str_aux' >" . iassign_icons::insert('duplicate_iassign') . "</a>\n";
  2735. $link_move_activity = "&nbsp;<a href='#' onclick='load_move($iassign_current); return false;' >" . iassign_icons::insert('move_activity') . "</a>\n";
  2736. if (count($iassign_array) > 1) {
  2737. if ($j == 0)
  2738. $links .= $link_down;
  2739. elseif ($j == $i - 1)
  2740. $links .= $link_up;
  2741. else
  2742. $links .= $link_up . $link_down;
  2743. } // if (count($iassign_array) > 1)
  2744. $links .= $link_edit . $link_delete;
  2745. if ($iassign_array[$j]->visible == 0)
  2746. $links .= $link_visible_show;
  2747. else
  2748. $links .= $link_visible_hide;
  2749. $links .= $link_duplicate_activity . $link_move_activity;
  2750. } // if ($USER->iassignEdit == 1 && has_capability('mod/iassign:editiassign', $this->context, $USER->id))
  2751. print '<p>' . $links . '</p>' . "\n";
  2752. }
  2753. } // if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id))
  2754. elseif (has_capability('mod/iassign:submitiassign', $this->context, $USER->id)) { // student
  2755. print '<table width=100% ><tr>' . "\n";
  2756. print "<td width=70% align='left'><font color='#0000aa'><strong>" . $title . "</strong></font></td>" . "\n";
  2757. print '</tr></table>' . "\n";
  2758. for ($j = 0; $j < $i; $j ++) {
  2759. $icon_status = "";
  2760. $icon_comment = "";
  2761. if ($iassign_array[$j]->visible == 1) {
  2762. $iassign_current = $iassign_array[$j]->id;
  2763. $iassign_submission = $DB->get_record('iassign_submission', array('iassign_statementid' => $iassign_current, 'userid' => $USER->id));
  2764. $links = "&nbsp;<a href='view.php?id=$id&userid_iassign=$USER->id&action=view&iassign_current=$iassign_current'>" . $iassign_array[$j]->name . "</a>";
  2765. $icon_status = "";
  2766. $icon_comment = "";
  2767. if ($iassign_submission) {
  2768. // receiver=1 - message to teacher
  2769. // receiver=2 - message to student
  2770. // $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");
  2771. $params = array('iassign_submissionid' => $iassign_submission->id, 'return_status' => '0', 'receiver' => '2');
  2772. $verify_message = $DB->get_record_sql(
  2773. "SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
  2774. " WHERE iassign_submissionid = :iassign_submissionid AND return_status= :return_status AND receiver= :receiver", $params);
  2775. if ($verify_message)
  2776. foreach ($verify_message as $tmp)
  2777. $sum_comment = $tmp;
  2778. if ($sum_comment > 0) {
  2779. $comment_unread_message = get_string('comment_unread', 'iassign');
  2780. if ($sum_comment == 1)
  2781. $comment_unread_message = get_string('comment_unread_one', 'iassign');
  2782. $icon_comment = "&nbsp;<font color='red'>" . iassign_icons::insert('comment_unread') . "&nbsp;($sum_comment&nbsp;" . $comment_unread_message . ")</font>";
  2783. }
  2784. // $icon_comment = iassign_icons::insert('comment_unread');
  2785. if ($iassign_array[$j]->type_iassign == 3) {
  2786. if ($iassign_array[$j]->show_answer == 1) {
  2787. if ($iassign_submission->status == 3)
  2788. $icon_status = iassign_icons::insert('correct');
  2789. elseif ($iassign_submission->status == 2)
  2790. $icon_status = iassign_icons::insert('incorrect');
  2791. elseif ($iassign_submission->status == 1)
  2792. $icon_status = iassign_icons::insert('post');
  2793. elseif ($iassign_submission->status == 0)
  2794. $icon_status = iassign_icons::insert('not_post');
  2795. } // if ($iassign_array[$j]->show_answer==1)
  2796. else {
  2797. if ($iassign_submission->status == 0)
  2798. $icon_status = iassign_icons::insert('not_post');
  2799. else
  2800. $icon_status = iassign_icons::insert('post');
  2801. }
  2802. } // if ($iassign_array[$j]->type_iassign == 3)
  2803. } // if ($iassign_submission)
  2804. elseif ($iassign_array[$j]->type_iassign == 3) {
  2805. $icon_status = iassign_icons::insert('not_post');
  2806. } // if ($iassign_array[$j]->type_iassign == 3)
  2807. print '<p>' . $icon_status . '&nbsp;' . $links . '&nbsp;' . $icon_comment . '</p>' . "\n";
  2808. } // if ($iassign_array[$j]->visible == 1)
  2809. } // for ($j = 0; $j < $i; $j++)
  2810. } else if (isguestuser()) {
  2811. print($OUTPUT->notification(get_string('no_permission_iassign', 'iassign'), 'notifyproblem'));
  2812. print '<table width=100% ><tr>' . "\n";
  2813. print "<td width=70% align='left'><font color='#0000aa'><strong>" . $title . "</strong></font></td>" . "\n";
  2814. print '</tr></table>' . "\n";
  2815. for ($j = 0; $j < $i; $j ++) {
  2816. $icon_status = "";
  2817. $icon_comment = "";
  2818. if ($iassign_array[$j]->visible == 1) {
  2819. $iassign_current = $iassign_array[$j]->id;
  2820. $links = "&nbsp;<a href='view.php?id=$id&userid_iassign=$USER->id&action=view&iassign_current=$iassign_current'>" . $iassign_array[$j]->name . "</a>";
  2821. print '<p>' . $links . '</p>' . "\n";
  2822. } // if ($iassign_array[$j]->visible == 1)
  2823. }
  2824. }
  2825. print $OUTPUT->box_end();
  2826. } // function show_iassign($title, $iassign_array, $i)
  2827. /// Show message of return
  2828. function return_home_course ($message) {
  2829. //D global $DB, $OUTPUT;
  2830. //D $link_return = "&nbsp;<a href='" . $this->return . "'>" . iassign_icons::insert('home') . get_string('activities_page', 'iassign') . "</a>";
  2831. //D echo $OUTPUT->box_start();
  2832. //D echo '<table width=100% border=0 valign="top">' . "\n";
  2833. //D echo '<tr><td align="left"><strong>' . "\n";
  2834. //D print_string($message, 'iassign');
  2835. //D echo '</strong></td>' . "\n";
  2836. //D echo '<td width=20% align="right">' . "\n";
  2837. //D echo $link_return;
  2838. //D echo '</td></tr></table>' . "\n";
  2839. //D echo $OUTPUT->box_end();
  2840. //D // echo $OUTPUT->footer();
  2841. redirect(new moodle_url($this->return . '&notice=' . $message));
  2842. exit;
  2843. }
  2844. /// Search comment of activity
  2845. function search_comment_submission ($iassign_submissionid) {
  2846. global $USER, $DB, $OUTPUT, $COURSE;
  2847. // $context = context_course::instance($COURSE->id);
  2848. $colorEdit1 = "#a7bede"; // "#dce7ec"
  2849. $colorEdit2 = "#b7ceee";
  2850. $has_capability = 0;
  2851. $comments = $DB->get_records_list('iassign_submission_comment', 'iassign_submissionid', array('iassign_submissionid' => $iassign_submissionid), 'timecreated DESC'); // 'ORDER BY "timecreated" ASC'
  2852. $text = "";
  2853. if ($comments) {
  2854. $even = 1;
  2855. foreach ($comments as $tmp) {
  2856. $user_data = $DB->get_record("user", array('id' => $tmp->comment_authorid));
  2857. // if (has_capability('mod/iassign:editiassign', $context, $tmp->comment_authorid)) {
  2858. // $text .= "<tr><td bgcolor='#fee7ae'><b> $user_data->firstname</b>&nbsp;(" . userdate($tmp->timecreated) . ")</br>\n";
  2859. // $text .= $tmp->comment . "</td></tr>";
  2860. //} else {
  2861. // $text .= "<tr><td bgcolor='#dce7ec'>&raquo;<b>" . $user_data->firstname . "</b>&nbsp;(" . userdate($tmp->timecreated) . "</br>\n";
  2862. if ($even) {
  2863. $text .= "<tr><td bgcolor='" . $colorEdit1 . "'>&raquo;<b>" . $user_data->firstname . "</b>&nbsp;(" . userdate($tmp->timecreated) . ")</br>\n";
  2864. $even = 0;
  2865. } else {
  2866. $text .= "<tr><td bgcolor='" . $colorEdit2 . "'>&raquo;<b>" . $user_data->firstname . "</b>&nbsp;(" . userdate($tmp->timecreated) . ")</br>\n";
  2867. $even = 1;
  2868. }
  2869. $text .= $tmp->comment . "</td></tr>\n";
  2870. } // foreach ($comments as $tmp)
  2871. }
  2872. return $text;
  2873. }
  2874. /// Update comment of activity
  2875. function update_comment ($iassign_submissionid) {
  2876. global $USER, $DB, $OUTPUT;
  2877. if (!has_capability('mod/iassign:submitiassign', $this->context, $USER->id) || is_siteadmin())
  2878. $receiver = 1; // student message to teacher
  2879. else
  2880. $receiver = 2; // teacher message to student
  2881. $verify_message = $DB->get_records('iassign_submission_comment', array('iassign_submissionid' => $iassign_submissionid)); //
  2882. if ($verify_message) {
  2883. foreach ($verify_message as $message) {
  2884. if ($message->receiver == $receiver) {
  2885. $newentry = new stdClass();
  2886. $newentry->id = $message->id;
  2887. $newentry->return_status = 1;
  2888. if (!$DB->update_record('iassign_submission_comment', $newentry)) {
  2889. print_error('error_update', 'iassign');
  2890. } // if (!$DB->update_record('iassign_submission_comment', $newentry))
  2891. } // if ($message->receiver == $receiver)
  2892. // Trigger module viewed event.
  2893. $event = \mod_iassign\event\submission_comment_updated::create(array(
  2894. 'objectid' => $this->iassign->id,
  2895. 'context' => $this->context
  2896. ));
  2897. $event->add_record_snapshot('course', $this->course);
  2898. $event->trigger();
  2899. } // foreach ($verify_message as $message)
  2900. }
  2901. }
  2902. /// Record comment of activity
  2903. function write_comment_submission () {
  2904. global $USER, $CFG, $DB;
  2905. $id = $this->cm->id;
  2906. $submission_comment = optional_param('submission_comment', NULL, PARAM_TEXT);
  2907. $row = optional_param('row', 0, PARAM_INT);
  2908. $column = optional_param('column', 0, PARAM_INT);
  2909. $sum_comment = 0;
  2910. $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);
  2911. $link_return = "&nbsp;<a href='" . $return . "'>" . iassign_icons::insert('return_home') . get_string('return', 'iassign') . "</a>";
  2912. $str1 = trim($submission_comment);
  2913. $str2 = trim(get_string('box_comment_message', 'iassign'));
  2914. if (!empty($submission_comment) && (strcmp($str1, $str2) != 0)) { // there is comment and it is different from "previous"
  2915. //D $iassign_submission = $DB->get_record("iassign_submission", array("id" => $this->iassign_submission_current)); //MOOC 2016
  2916. if (has_capability('mod/iassign:submitiassign', $this->context, $USER->id) && !is_siteadmin()) { //MOOC '&& !is_siteadmin()'
  2917. $receiver = 1; // student message to teacher
  2918. $this->action = 'view';
  2919. //D $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $iassign_submission->iassign_statementid)); //MOOC 2016
  2920. //D $tousers = get_users_by_capability($this->context, 'mod/iassign:evaluateiassign'); //MOOC 2016
  2921. } else {
  2922. $receiver = 2; // teacher message to student
  2923. $this->action = 'viewsubmission';
  2924. //D $tousers = array(); //MOOC 2016
  2925. //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
  2926. }
  2927. //MOOC 2016: foi p/ 15 linhas acima:
  2928. $iassign_submission = $DB->get_record("iassign_submission", array("id" => $this->iassign_submission_current));
  2929. if (!$iassign_submission) {
  2930. $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $this->activity->get_activity()->id));
  2931. $id_submission = $this->new_submission($iassign_statement_activity_item->id, $this->userid_iassign, $receiver);
  2932. $this->iassign_submission_current = $id_submission;
  2933. } else {
  2934. $id_submission = $iassign_submission->id;
  2935. } // if (!$iassign_submission)
  2936. // $comments = $DB->get_record_sql("SELECT COUNT(iassign_submissionid) FROM {$CFG->prefix}ia_assign_submissions_comment
  2937. // WHERE iassign_submissionid = '$id_submission' and comment='$submission_comment' and comment_authorid='$USER->id'"); //
  2938. // Attention: this Moodle function 'get_record_sql' makes a replace in ':comment'
  2939. $params = array("iassign_submissionid" => $id_submission, "comment" => $submission_comment, "comment_authorid" => $USER->id);
  2940. $comments = $DB->get_record_sql(
  2941. "SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
  2942. " WHERE iassign_submissionid = :iassign_submissionid AND comment= :comment AND comment_authorid= :comment_authorid", $params);
  2943. if ($comments)
  2944. foreach ($comments as $tmp)
  2945. $sum_comment = $tmp;
  2946. if ($sum_comment == 0) {
  2947. $newentry = new stdClass();
  2948. $newentry->iassign_submissionid = $id_submission;
  2949. $newentry->comment_authorid = $USER->id;
  2950. $newentry->timecreated = time();
  2951. $newentry->comment = $submission_comment;
  2952. $newentry->receiver = $receiver;
  2953. $ia_assign_submissions_comment_id = $DB->insert_record('iassign_submission_comment', $newentry);
  2954. //T foreach ($tousers as $touser) { //TODO Para registrar mensagem na area do Moodle - tem que ativar '$tousers[] = $DB->get_record(...);' acima
  2955. //T $eventdata = new stdClass();
  2956. //T $eventdata->component = 'mod_iassign'; //your component name
  2957. //T $eventdata->name = 'comment'; //this is the message name from messages.php
  2958. //T $eventdata->userfrom = $USER;
  2959. //T $eventdata->userto = $touser;
  2960. //T $eventdata->subject = "Teste de Subject";
  2961. //T $eventdata->fullmessage = "Teste de Mensagem...";
  2962. //T $eventdata->fullmessageformat = FORMAT_PLAIN;
  2963. //T $eventdata->fullmessagehtml = "<b>Teste de Mensagem...</b>";
  2964. //T $eventdata->smallmessage = "Teste de Mensagem";
  2965. //T $eventdata->notification = 1; //this is only set to 0 for personal messages between users
  2966. //T // alteracao tulio faria
  2967. //T //message_send($eventdata);
  2968. //T } //MOOC 2016 - TODO NAO finalizado, iniciado pelo Tulio
  2969. // Trigger module viewed event.
  2970. $event = \mod_iassign\event\submission_comment_created::create(array(
  2971. 'objectid' => $this->iassign->id,
  2972. 'context' => $this->context
  2973. ));
  2974. $event->add_record_snapshot('course', $this->course);
  2975. $event->trigger();
  2976. }
  2977. } // if (!empty($submission_comment) && (strcmp($str1, $str2) != 0))
  2978. // if ($this->action=='viewsubmission') {
  2979. // echo $OUTPUT->header();
  2980. // $this->return_last('confirm_add_comment', $link_return);
  2981. // die;
  2982. // }
  2983. return true;
  2984. } // function write_comment_submission()
  2985. /// Writes a new submission
  2986. // The first student answer is under 'function get_answer()'
  2987. function new_submission ($iassignid, $id_user, $receiver) {
  2988. global $USER, $DB, $OUTPUT;
  2989. $newentry = new stdClass();
  2990. $newentry->iassign_statementid = $iassignid;
  2991. $newentry->userid = $id_user;
  2992. $newentry->timecreated = time();
  2993. $newentry->timemodified = time();
  2994. $newentry->answer = 0; // student only submit message
  2995. if ($receiver == 2) // teacher message to student (write id teacher)
  2996. $newentry->teacher = $USER->id;
  2997. if (!$newentry->id = $DB->insert_record("iassign_submission", $newentry))
  2998. return_home_course('error_insert_submissions');
  2999. else {
  3000. // Trigger module view event
  3001. $event = \mod_iassign\event\submission_created::create(array(
  3002. 'objectid' => $this->iassign->id,
  3003. 'context' => $this->context
  3004. ));
  3005. $event->add_record_snapshot('course', $this->course);
  3006. $event->trigger();
  3007. }
  3008. return $newentry->id;
  3009. }
  3010. /// Return to a specific address of page
  3011. function return_last ($message, $link_return) {
  3012. global $DB, $OUTPUT;
  3013. print $OUTPUT->box_start();
  3014. print '<table width=100% border=0 valign="top">' . "\n";
  3015. print '<tr><td align="left"><strong>' . "\n";
  3016. print_string($message, 'iassign');
  3017. print '</strong></td>' . "\n";
  3018. print '<td width=20% align="right">' . "\n";
  3019. print $link_return;
  3020. print '</td></tr></table>' . "\n";
  3021. print $OUTPUT->box_end();
  3022. print $OUTPUT->footer();
  3023. die();
  3024. } // function return_last($message, $link_return)
  3025. } // class iassign
  3026. /// Class for manage activities
  3027. class activity {
  3028. var $activity;
  3029. /// Constructor of class.
  3030. // @param int $id Id of activity
  3031. // 3.1 update PHP 7.0 compatibility for all moodle versions
  3032. //D public function activity($id) { self::__construct($id); }
  3033. function __construct ($id) {
  3034. global $DB;
  3035. $this->activity = $DB->get_record("iassign_statement", array("id" => $id));
  3036. if (empty($this->activity))
  3037. $this->activity = null;
  3038. }
  3039. /// Get an activity
  3040. // @return NULL
  3041. function get_activity () {
  3042. if ($this->activity != null)
  3043. return $this->activity;
  3044. else
  3045. return null;
  3046. }
  3047. /// Delete interactive activities
  3048. function delete ($return) {
  3049. global $USER, $CFG, $DB, $OUTPUT;
  3050. $iassign_submission_currents = $DB->get_records("iassign_submission", array("iassign_statementid" => $this->activity->id));
  3051. $output = $OUTPUT->header();
  3052. $output .= $OUTPUT->box_start();
  3053. $output .= "<p>" . get_string('delete_activity', 'iassign') . "&nbsp;<strong>" . $this->activity->name . "</strong></p>";
  3054. if ($iassign_submission_currents) {
  3055. $output .= "<p>" . get_string('number_submissions', 'iassign') . "&nbsp;<strong>" . count($iassign_submission_currents) . "</strong></p>";
  3056. if (!has_capability('mod/iassign:deleteiassignnotnull', $USER->context, $USER->id)) {
  3057. $output .= $OUTPUT->heading(get_string('delete_activity_permission_adm', 'iassign'));
  3058. $output .= $OUTPUT->single_button($return, get_string('return', 'iassign'), 'get');
  3059. $output .= $OUTPUT->box_end();
  3060. $output .= $OUTPUT->footer();
  3061. print $output;
  3062. die();
  3063. } // if (!has_capability('mod/iassign:deleteiassignnotnull', $this->context, $USER->id))
  3064. } // if ($iassign_submission_currents)
  3065. else
  3066. $output .= "<p>" . get_string('not_submissions_activity', 'iassign') . "</p>";
  3067. $output .= '<table width=50% border=0>';
  3068. $output .= '<tr valign="top"><td>';
  3069. $output .= "<p>" . get_string('what_do', 'iassign') . "</p>";
  3070. $output .= '</td><td>';
  3071. $bottonDelete_yes = get_string('delete_iassign', 'iassign');
  3072. $deleteiassignyes = $CFG->wwwroot . "/mod/iassign/view.php?id=" . $USER->cm . "&action=deleteyes&iassign_current=" . $this->activity->id;
  3073. $output .= "<form name='formDelete' id='formDelete' method='post' action='$deleteiassignyes' enctype='multipart/form-data'>";
  3074. $output .= " <input type=submit value='$bottonDelete_yes'/>\n";
  3075. $output .= "</form>\n";
  3076. $output .= '</td><td>';
  3077. $bottonDelete_no = get_string('delete_cancel', 'iassign');
  3078. $deleteiassignno = $CFG->wwwroot . "/mod/iassign/view.php?id=" . $USER->cm . "&action=deleteno&iassign_current=" . $this->activity->id;
  3079. $output .= "<form name='formDelete' id='formDelete' method='post' action='$deleteiassignno' enctype='multipart/form-data'>\n";
  3080. $output .= " <p><input type=submit value='$bottonDelete_no'/></p>\n";
  3081. $output .= "</form>\n";
  3082. $output .= '</td></tr></table>' . "\n";
  3083. $output .= $OUTPUT->box_end();
  3084. $output .= $OUTPUT->footer();
  3085. print $output;
  3086. } // function delete($return)
  3087. /// Function for confirm the delete of activity
  3088. // @param String $return Url of return
  3089. // @param Object $iassign Object content an activity
  3090. function deleteyes ($return, $iassign) {
  3091. global $USER, $CFG, $DB, $OUTPUT;
  3092. $msg = '';
  3093. if (!empty($this->activity->id)) {
  3094. $iassign_submission_currents = $DB->get_records("iassign_submission", array("iassign_statementid" => $this->activity->id));
  3095. if ($iassign_submission_currents) {
  3096. if (has_capability('mod/iassign:deleteassignnull', $USER->context, $USER->id)) {
  3097. foreach ($iassign_submission_currents as $iassign_submission)
  3098. $DB->delete_records('iassign_submission_comment', array('iassign_submissionid' => $iassign_submission->id));
  3099. $delete_iassign_submission_currents = $DB->delete_records("iassign_submission ", array("iassign_statementid" => $this->activity->id));
  3100. } // if ($iassign_submission_currents)
  3101. }
  3102. //$delete_iassign_statement_config = $DB->delete_records('iassign_statement_config', array('iassign_statementid' => $this->activity->id)); //MOOC 2016
  3103. $this->delete_calendar($this->activity->id);
  3104. $delete_iassign_current = $DB->delete_records('iassign_statement', array('id' => $this->activity->id));
  3105. iassign::update_grade_iassign($this->activity->iassignid);
  3106. if ($delete_iassign_current) {
  3107. $iassign->return_home_course('confirm_delete_iassign');
  3108. //$msg = get_string ( 'confirm_delete_iassign', 'iassign' );
  3109. } else {
  3110. $iassign->return_home_course('error_confirm_delete_iassign');
  3111. //$msg = get_string ( 'error_confirm_delete_iassign', 'iassign' );
  3112. }
  3113. // if (($this->action == 'deleteyes') && (has_capability('mod/iassign:deleteassignnull', $this->context, $USER->id)))
  3114. }
  3115. }
  3116. /// Changes position of activities (between those inside a group of interactive activities)
  3117. // @param $move_action = must be "up" or "down"
  3118. // @param $target = if 'down' => is 'iassign_statement.id' of the activity bellow the current one; if 'up' => is activity above the current one
  3119. function move_iassign ($move_action, $target, $return) {
  3120. global $DB, $OUTPUT;
  3121. //D echo "mover: this->id=" . $this->activity->id . ", target = $target<br/>";
  3122. $initial_position_source = $this->activity->position; // the position of the "source activity" (that one to be moved)
  3123. $iassign_target = $DB->get_record("iassign_statement", array("id" => $target)); // "target activity" = the activity in the position the receive "source activity"
  3124. if ($move_action=="firstdown") {
  3125. $final_position_source = 2;
  3126. $final_position_target = 1;
  3127. }
  3128. else
  3129. if ($move_action=="down") {
  3130. $final_position_target = $this->activity->position;
  3131. $final_position_source = $final_position_target + 1;
  3132. }
  3133. else
  3134. if ($move_action=="up") {
  3135. $final_position_target = $this->activity->position;
  3136. $final_position_source = $final_position_target - 1;
  3137. }
  3138. else { // error:
  3139. print_error('error_update_move_iassign', 'iassign');
  3140. exit;
  3141. }
  3142. $newentry = new stdClass(); // define a new object (activity) to receive only 2 fields: 'id' and 'position'
  3143. $newentry->id = $this->activity->id; // ID of the "source activity"
  3144. $newentry->position = $final_position_source;
  3145. //D echo "mover: id=" . $this->activity->id . ": de " . $this->activity->position . " -> " . $final_position_source . "<br/>";
  3146. //D echo "mover: id=" . $iassign_target->id . ": de " . $iassign_target->position . " -> " . $final_position_target . "<br/>"; exit;
  3147. if (!$DB->update_record('iassign_statement', $newentry)) { // modify 'position' of the activity with 'id'=$target
  3148. print_error('error_update_move_iassign', 'iassign');
  3149. }
  3150. else { // first update performed successfully
  3151. $newentry->id = $iassign_target->id;
  3152. $newentry->position = $final_position_target;
  3153. if (!$DB->update_record('iassign_statement', $newentry))
  3154. print_error('error_update_move_iassign', 'iassign');
  3155. }
  3156. redirect($return);
  3157. }
  3158. /// Enable or disable the display of interactive activities
  3159. function visible_iassign ($return) {
  3160. global $DB;
  3161. $newentry = new stdClass();
  3162. $newentry->id = $this->activity->id;
  3163. $newentry->visible = $this->activity->visible == 0 ? 1 : 0;
  3164. if (!$DB->update_record('iassign_statement', $newentry))
  3165. print_error('error_update_visible_iassign', 'iassign');
  3166. redirect($return);
  3167. }
  3168. /// Add news interactive activities (register in table 'iassign_statement')
  3169. // @calledby this->add_edit_iassign() : $iassignid = $this->activity->new_iassign($result);
  3170. // @see ilm_manager.php: $ilm_manager_instance->ilm_editor_new();
  3171. function new_iassign ($param) {
  3172. global $DB;
  3173. $newentry = new stdClass();
  3174. $newentry->iassignid = $param->iassignid;
  3175. $newentry->name = $param->name;
  3176. $newentry->type_iassign = $param->type_iassign;
  3177. // $newentry->proposition = $param->proposition; // 2019/02/13 - With the use of 'editor' in 'mform', field 'proposition' is Array ( [text] => <DESCRIPTION> [format] => 1 )
  3178. $proposition = $param->proposition;
  3179. if (is_array($proposition)) $proposition_text = $proposition['text'];
  3180. else $proposition_text = $proposition;
  3181. $newentry->proposition = $proposition_text; // Notice: Trying to get property of non-object
  3182. //TODO I used in 'iassign_form.php' '<select name='iassign_ilmid'...>' with 'optgroup' by hand! But MoodleForm clear/do not register the 'iassign_ilmid'
  3183. //TODO Then get it directly from the form data $_POST!
  3184. //TODO See: 'iassign_form.php' field 'iassign_ilmid' and here (above) 'function add_edit_iassign()'
  3185. if (!isset($param->iassign_ilmid) && isset($_POST['iassign_ilmid']))
  3186. $param->iassign_ilmid = $_POST['iassign_ilmid'];
  3187. $newentry->author_name = $param->author_name;
  3188. $newentry->author_modified_name = $param->author_modified_name;
  3189. $newentry->iassign_ilmid = $param->iassign_ilmid;
  3190. $newentry->file = $param->file; // came from a file from 'get_file_storage()' (it is its ID)
  3191. //TODO criar o campo 'iassign_statement.filesid' e usar: $newentry->filesid = $param->file; // register 'files.id' here in 'iassign_statement.filesid'
  3192. $newentry->grade = $param->grade;
  3193. $newentry->timemodified = time();
  3194. $newentry->timecreated = time();
  3195. if ($param->type_iassign == 1) {
  3196. $newentry->timedue = 0;
  3197. $newentry->timeavailable = 0;
  3198. } // if ($param->type_iassign == 1)
  3199. else {
  3200. $newentry->timedue = $param->timedue;
  3201. $newentry->timeavailable = $param->timeavailable;
  3202. }
  3203. $newentry->preventlate = $param->preventlate;
  3204. $newentry->test = $param->test;
  3205. $newentry->special_param1 = $param->special_param1;
  3206. $newentry->visible = $param->visible;
  3207. $newentry->position = $param->position;
  3208. $newentry->max_experiment = $param->max_experiment;
  3209. $newentry->dependency = $param->dependency;
  3210. $newentry->automatic_evaluate = $param->automatic_evaluate;
  3211. $newentry->show_answer = $param->show_answer;
  3212. $id = $DB->insert_record("iassign_statement", $newentry);
  3213. if ($id) {
  3214. $component = 'mod_iassign';
  3215. $filearea = 'exercise';
  3216. $fs = get_file_storage(); // Get reference to all files in Moodle data
  3217. $file = $fs->get_file_by_id($param->file);
  3218. $itemid = $file->get_itemid() + $id; //TODO Verificar: melhor deixar "$itemid = $file->get_itemid()" pois assim 'files.itemid' guarda 'iassign_statement.id'???
  3219. // File already inserted in other context!
  3220. //TODO Verificar se apenas esta' inserindo nova referencia em 'files' (NAO deve duplicar no Moodle Data)
  3221. $newfile = $fs->create_file_from_storedfile(array('contextid' => $param->context->id, 'component' => $component, 'filearea' => $filearea, 'itemid' => $itemid), $file);
  3222. $updateentry = new stdClass();
  3223. $updateentry->id = $id;
  3224. //TODO Implementar campo 'iassign_statement.filesid' e usar: $updateentry->filesid = $param->file; // register in 'iassign_statement' the 'files.id'
  3225. $updateentry->file = $newfile->get_itemid();
  3226. if (!$DB->update_record("iassign_statement", $updateentry))
  3227. print_error('error_add', 'iassign');
  3228. if ($param->type_iassign == 3)
  3229. iassign::update_grade_iassign($param->iassignid);
  3230. //TODO iLM_HTML5 :: //MOOC2014
  3231. //D $iassign_ilm_configs = $DB->get_records('iassign_ilm_config', array('iassign_ilmid' => $param->iassign_ilmid, 'visible' => '1'));
  3232. //D if ($iassign_ilm_configs) {
  3233. //D foreach ($iassign_ilm_configs as $iassign_ilm_config) {
  3234. //D if ($iassign_ilm_config->param_type != 'static') {
  3235. //D $newentry = new stdClass();
  3236. //D $newentry->iassign_statementid = $id;
  3237. //D $newentry->iassign_ilm_configid = $iassign_ilm_config->id;
  3238. //D $newentry->param_name = $iassign_ilm_config->param_name;
  3239. //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});
  3240. //D if (!$DB->insert_record("iassign_statement_config", $newentry))
  3241. //D print_error('error_add_param', 'iassign');
  3242. //D }
  3243. //D }
  3244. //D }
  3245. // log event --------------------------------------------------------------------------------------
  3246. iassign_log::add_log('add_iassign_exercise', 'name: ' . $param->name, $id, $param->iassign_ilmid);
  3247. // log event --------------------------------------------------------------------------------------
  3248. return $id;
  3249. }
  3250. else
  3251. print_error('error_add', 'iassign');
  3252. } // function new_iassign($param)
  3253. /// Add the calendar entries for this iassign
  3254. // @param int $coursemoduleid - Required to pass this in because it might not exist in the database yet
  3255. // @return bool
  3256. static function add_calendar ($iassignid) {
  3257. global $DB, $CFG;
  3258. require_once($CFG->dirroot . '/calendar/lib.php');
  3259. $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $iassignid));
  3260. $iassign = $DB->get_record("iassign", array("id" => $iassign_statement_activity_item->iassignid));
  3261. $event = new stdClass();
  3262. $event->name = $iassign->name . '&nbsp;-&nbsp;' . $iassign_statement_activity_item->name;
  3263. $event->description = $iassign_statement_activity_item->name;
  3264. $event->courseid = $iassign->course;
  3265. $event->groupid = 0;
  3266. $event->userid = 0;
  3267. $event->modulename = 'iassign';
  3268. $event->instance = $iassign->id;
  3269. $event->eventtype = 'due';
  3270. $event->timestart = $iassign_statement_activity_item->timeavailable;
  3271. $event->timeduration = ($iassign_statement_activity_item->timedue - $iassign_statement_activity_item->timeavailable);
  3272. calendar_event::create($event);
  3273. }
  3274. /// Update the calendar entries for this iassign
  3275. // @param int $coursemoduleid - Required to pass this in because it might not exist in the database yet
  3276. // @return bool
  3277. function update_calendar ($iassignid, $olddescription) {
  3278. global $DB, $CFG;
  3279. require_once($CFG->dirroot . '/calendar/lib.php');
  3280. $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $iassignid));
  3281. $iassign = $DB->get_record("iassign", array("id" => $iassign_statement_activity_item->iassignid));
  3282. $event = new stdClass();
  3283. $event->id = 0;
  3284. $events = $DB->get_records('event', array('modulename' => 'iassign', 'instance' => $iassign->id));
  3285. if ($events) {
  3286. foreach ($events as $value) {
  3287. if ($value->description == $olddescription) {
  3288. $event->id = $value->id;
  3289. }
  3290. }
  3291. }
  3292. if ($event->id != 0) {
  3293. $event->name = $iassign->name . '&nbsp;-&nbsp;' . $iassign_statement_activity_item->name;
  3294. $event->description = $iassign_statement_activity_item->name;
  3295. $event->timestart = $iassign_statement_activity_item->timeavailable;
  3296. $event->timeduration = ($iassign_statement_activity_item->timedue - $iassign_statement_activity_item->timeavailable);
  3297. $calendarevent = calendar_event::load($event->id);
  3298. $calendarevent->update($event);
  3299. } else
  3300. $this->add_calendar($iassignid);
  3301. }
  3302. /// Update the calendar entries for this iassign
  3303. // @param int $coursemoduleid - Required to pass this in because it might not exist in the database yet
  3304. // @return bool
  3305. function delete_calendar ($iassignid) {
  3306. global $DB, $CFG;
  3307. require_once($CFG->dirroot . '/calendar/lib.php');
  3308. $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $iassignid));
  3309. $iassign = $DB->get_record("iassign", array("id" => $iassign_statement_activity_item->iassignid));
  3310. $events = $DB->get_records('event', array('modulename' => 'iassign', 'instance' => $iassign->id));
  3311. if ($events) {
  3312. foreach ($events as $value) {
  3313. if ($value->description == $iassign_statement_activity_item->name) {
  3314. $DB->delete_records('event', array('id' => $value->id));
  3315. }
  3316. }
  3317. }
  3318. }
  3319. /// Update interactive activities
  3320. function update_iassign ($param) {
  3321. global $DB;
  3322. $component = 'mod_iassign';
  3323. $filearea = 'exercise';
  3324. $fs = get_file_storage(); // Get reference to all files in Moodle data
  3325. $file = $fs->get_file_by_id($param->file);
  3326. $fileold = $fs->get_file_by_id($param->fileold);
  3327. if ($param->file != $param->fileold) {
  3328. if ($fileold) {
  3329. $fileoldarea = $fs->get_area_files($fileold->get_contextid(), $fileold->get_component(), $fileold->get_filearea(), $fileold->get_itemid());
  3330. foreach ($fileoldarea as $value) {
  3331. $value->delete();
  3332. }
  3333. }
  3334. if (!$fs->file_exists($param->context->id, $component, $filearea, $file->get_itemid(), $file->get_filepath(), $file->get_filename())) {
  3335. $itemid = $file->get_itemid() + $param->iassign_id;
  3336. $newfile = $fs->create_file_from_storedfile(array('contextid' => $param->context->id, 'component' => $component, 'filearea' => $filearea, 'itemid' => $itemid), $file);
  3337. $param->file = $newfile->get_itemid();
  3338. } else
  3339. $param->file = $file->get_itemid();
  3340. } else {
  3341. $param->file = $file->get_itemid();
  3342. }
  3343. $newentry = new stdClass();
  3344. $newentry->id = $param->iassign_id;
  3345. $newentry->name = $param->name;
  3346. $newentry->type_iassign = $param->type_iassign;
  3347. //2019 $newentry->proposition = $param->proposition;
  3348. $proposition = $param->proposition;
  3349. if (is_array($proposition))
  3350. $proposition_text = $proposition['text'];
  3351. else
  3352. $proposition_text = $proposition;
  3353. $newentry->proposition = $proposition_text;
  3354. $newentry->iassign_ilmid = $param->iassign_ilmid;
  3355. $newentry->file = $param->file; // came from a file from 'get_file_storage()' (it is its ID)
  3356. $newentry->grade = $param->grade;
  3357. $newentry->author_modified_name = $param->author_modified_name;
  3358. $newentry->timemodified = time();
  3359. if ($param->type_iassign == 1) {
  3360. $newentry->timedue = 0;
  3361. $newentry->timeavailable = 0;
  3362. } // if ($param->type_iassign == 1)
  3363. else {
  3364. $newentry->timedue = $param->timedue;
  3365. $newentry->timeavailable = $param->timeavailable;
  3366. }
  3367. $newentry->preventlate = $param->preventlate;
  3368. $newentry->test = $param->test;
  3369. $newentry->special_param1 = $param->special_param1;
  3370. $newentry->visible = $param->visible;
  3371. $newentry->max_experiment = $param->max_experiment;
  3372. $newentry->dependency = $param->dependency;
  3373. $newentry->automatic_evaluate = $param->automatic_evaluate;
  3374. $newentry->show_answer = $param->show_answer;
  3375. if (!$DB->update_record("iassign_statement", $newentry))
  3376. print_error('error_update', 'iassign');
  3377. if ($param->type_iassign == 3) {
  3378. iassign::update_grade_iassign($param->iassignid);
  3379. }
  3380. //$id = $newentry->id; // MOOC 2016 --- inicio
  3381. //$iassign_activity_item_configs = $DB->get_records('iassign_statement_config', array('iassign_statementid' => $newentry->id));
  3382. //if ($iassign_activity_item_configs) {
  3383. //foreach ($iassign_activity_item_configs as $iassign_activity_item_config) {
  3384. // $newentry = new stdClass();
  3385. // $newentry->id = $iassign_activity_item_config->id;
  3386. // $newentry->param_value =(is_array($param->{'param_'.$iassign_activity_item_config->iassign_ilm_configid}) ? implode(",",
  3387. // $newentry->param_value =(is_array($param->{'param_' . $iassign_activity_item_config->iassign_ilm_configid}) ? implode(",",
  3388. // $param->{'param_' . $iassign_activity_item_config->iassign_ilm_configid}) : $param->{'param_' . $iassign_activity_item_config->iassign_ilm_configid});
  3389. // if (!$DB->update_record("iassign_statement_config", $newentry))
  3390. // print_error('error_edit_param', 'iassign');
  3391. // }
  3392. // } // MOOC 2016 --- final
  3393. // log event --------------------------------------------------------------------------------------
  3394. iassign_log::add_log('update_iassign_exercise', 'name: ' . $param->name, $param->iassign_id, $param->iassign_ilmid);
  3395. // log event --------------------------------------------------------------------------------------
  3396. return $newentry->id;
  3397. // if ($param->type_iassign==3)
  3398. // $this->update_grade_iassign($param->iassignid);
  3399. } // function update_iassign($param)
  3400. /// Show information of activity
  3401. function show_info_iassign () {
  3402. global $DB, $OUTPUT;
  3403. $output = '<p><strong>' . get_string('proposition', 'iassign') . ':</strong>&nbsp;' . $this->activity->proposition . '</p>' . "\n";
  3404. if ($this->activity->type_iassign == 3) {
  3405. if ($this->activity->dependency == 0) {
  3406. $output .= '<p><strong>' . get_string('independent_activity', 'iassign') . '</strong></p>' . "\n";
  3407. } else {
  3408. $dependencys = explode(';', $this->activity->dependency);
  3409. $output .= '<p><strong>' . get_string('dependency', 'iassign') . '</strong></p>';
  3410. foreach ($dependencys as $dependency) {
  3411. $dependencyiassign = $DB->get_record("iassign_statement", array("id" => $dependency));
  3412. if ($dependencyiassign)
  3413. $output .= '<p>' . $dependencyiassign->name . '</p>' . "\n";
  3414. } // foreach ($dependencys as $dependency)
  3415. } // if ($iassign_statement_activity_item->dependency == 0)
  3416. if ($this->activity->max_experiment == 0)
  3417. $output .= '<p><strong>' . get_string('experiment', 'iassign') . '</strong>&nbsp;' . get_string('ilimit', 'iassign');
  3418. else
  3419. $output .= '<p><strong>' . get_string('experiment_iassign', 'iassign') . '</strong>&nbsp;' . $this->activity->max_experiment . "\n";
  3420. $output .= '&nbsp;&nbsp;&nbsp;<strong>' . get_string('grade_iassign', 'iassign') . '</strong>&nbsp;' . $this->activity->grade . '</p>' . "\n";
  3421. } // if ($iassign_statement_activity_item->type_iassign == 3)
  3422. print $OUTPUT->box($output);
  3423. } // function show_info_iassign()
  3424. /// Shows date of opening and closing activities
  3425. function view_dates () {
  3426. global $USER, $CFG, $DB, $OUTPUT;
  3427. $return = $CFG->wwwroot . "/mod/iassign/view.php?id=" . $USER->cm;
  3428. $link_return = "&nbsp;<a href='" . $return . "'>" . iassign_icons::insert('home') . get_string('activities_page', 'iassign') . "</a>";
  3429. $status_iassign = "";
  3430. $status_iassign1 = "";
  3431. $status_iassign2 = "";
  3432. if ($this->activity->type_iassign == 1) // activity of type example
  3433. $type_iassign = get_string('example_iassign', 'iassign');
  3434. elseif ($this->activity->type_iassign == 2) { // activity of type test
  3435. $type_iassign = get_string('test_iassign', 'iassign');
  3436. if ($this->activity->timeavailable > time()) {
  3437. $status_iassign = get_string('previous_timeavailable', 'iassign');
  3438. } elseif ($this->activity->timedue < time()) {
  3439. $status_iassign = get_string('last_timedue', 'iassign');
  3440. }
  3441. } elseif ($this->activity->type_iassign == 3) { // activity of type exercise
  3442. $type_iassign = get_string('exercise_iassign', 'iassign');
  3443. if ($this->activity->timeavailable > time()) {
  3444. $status_iassign = get_string('previous_timeavailable', 'iassign'); // before of deadline
  3445. } elseif ($this->activity->timedue < time()) { // after delivery
  3446. $status_iassign = get_string('last_timedue', 'iassign');
  3447. if ($this->activity->preventlate == 1) // permitted to submit after the deadline
  3448. $status_iassign1 = get_string('duedate_preventlate_enable', 'iassign');
  3449. elseif ($this->activity->preventlate == 0) { // not permitted to submit after the deadline
  3450. $status_iassign1 = get_string('duedate_preventlate_desable', 'iassign');
  3451. if ($this->activity->test == 1) // allowed to test after of deadline
  3452. $status_iassign2 = get_string('test_preventlate', 'iassign');
  3453. elseif ($this->activity->test == 0) { // not allowed to test after of deadline
  3454. $status_iassign2 = get_string('test_preventlate_no', 'iassign');
  3455. } // elseif ($iassign_statement_activity_item->test == 0)
  3456. } // elseif ($iassign_statement_activity_item->preventlate == 0)
  3457. } // elseif ($iassign_statement_activity_item->timedue < time())
  3458. } // elseif ($iassign_statement_activity_item->type_iassign == 3)
  3459. $output = '<table width=100% >' . "\n";
  3460. $output .= '<tr><td colspan=2><h4>' . $this->activity->name . '</h4></td></tr>' . "\n";
  3461. $output .= '<tr>' . "\n";
  3462. // TODO duvida: como permitir ao admin,professor,monitor ver a atividade mesmo apos prazo???
  3463. // Leo testes para passar por cima com 'has_capability('mod/iassign:...', $this->context, $USER->id)
  3464. $output .= '<td width=60%>' . $type_iassign . '</td>' . "\n";
  3465. // leo $output .= '<td width=80%>' . $type_iassign;
  3466. // $output .= $auxStr . " - status_assign=$status_iassign - this->activity->type_iassign=" . $this->activity->type_iassign. "<br/>"; // Period ended.
  3467. // $output .= '</td>' . "\n";
  3468. if (has_capability('mod/iassign:viewiassignall', $USER->context, $USER->id) && ($this->activity->type_iassign == 3)) {
  3469. // Link (with icon) to report survey of this batch of these insteractivy exercises
  3470. $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>";
  3471. $output .= '<td width=40% align="right">' . '&nbsp;' . $link_report . '</td>' . "\n";
  3472. } else {
  3473. $link_next = "";
  3474. $link_previous = "";
  3475. $iassign_previous = $DB->get_record('iassign_statement', array('iassignid' => $this->activity->iassignid, 'position' => $this->activity->position - 1));
  3476. $iassign_next = $DB->get_record('iassign_statement', array('iassignid' => $this->activity->iassignid, 'position' => $this->activity->position + 1));
  3477. // previous_activity
  3478. if ($iassign_previous) {
  3479. $url_previous = "view.php?id=$USER->cm&userid_iassign=$USER->id&action=view&iassign_current=$iassign_previous->id";
  3480. $link_previous = "<a href='" . $url_previous . "'>" . (iassign_icons::insert('previous_student_activity')) . "</a>";
  3481. } // next_activity
  3482. if ($iassign_next) {
  3483. $url_next = "view.php?id=$USER->cm&userid_iassign=$USER->id&action=view&iassign_current=$iassign_next->id";
  3484. $link_next = "<a href='" . $url_next . "'>" . (iassign_icons::insert('next_student_activity')) . "</a>";
  3485. }
  3486. $output .= '<td width=40% align="right">' . $link_previous . '&nbsp;&nbsp;&nbsp;' . $link_return . '&nbsp;&nbsp;&nbsp;' . $link_next . '</td>' . "\n";
  3487. } // if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id) && ($iassign_statement_activity_item->type_iassign == 3))
  3488. $output .= '</tr></table>' . "\n";
  3489. $output .= '<table width=100% >' . "\n";
  3490. if ($this->activity->type_iassign > 1) {
  3491. if ($this->activity->timeavailable)
  3492. $output .= '<tr><td width=50% align="left"> <strong>' . get_string('availabledate', 'iassign') . ':</strong>&nbsp;' . userdate($this->activity->timeavailable) . '</td>' . "\n";
  3493. if ($this->activity->timedue)
  3494. $output .= '<td width=50% align="left"><strong>' . get_string('duedate', 'iassign') . ':</strong>&nbsp;' . userdate($this->activity->timedue) . '</td>' . "\n";
  3495. } // if ($iassign_statement_activity_item->type_iassign > 1)
  3496. if ($status_iassign != "" && $status_iassign1 != "" && $status_iassign2 != "")
  3497. $output .= '<tr><td><font color="red">' . $status_iassign . '&nbsp;' . $status_iassign1 . '&nbsp;' . $status_iassign2 . '</font></td></tr>' . "\n";
  3498. $output .= '</table>' . "\n";
  3499. print $OUTPUT->box($output);
  3500. } // function view_dates()
  3501. } // class activity
  3502. /// Class to manage Interactive Learning Module (iLM)
  3503. class ilm {
  3504. var $ilm;
  3505. /// Constructor of class
  3506. // @param int $id Id of iLM
  3507. //D 3.1 update PHP 7.0 compatibility for all moodle versions
  3508. //D public function ilm($id) { self::__construct($iassign, $cm, $course); }
  3509. function __construct ($id) {
  3510. global $DB;
  3511. $this->ilm = $DB->get_record("iassign_ilm", array("id" => $id));
  3512. if (empty($this->ilm))
  3513. $this->ilm = null;
  3514. }
  3515. /// Shows activity in iLM
  3516. // @calledby view_iassign_current()
  3517. function view_iLM ($iassign_statement_activity_item, $student_answer, $enderecoPOST, $view_teacherfileversion) {
  3518. global $USER, $CFG, $DB;
  3519. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $iassign_statement_activity_item->iassign_ilmid));
  3520. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  3521. $typec = strtolower($iassign_ilm->type);
  3522. require_once 'ilm_handlers/' . $typec . '.php';
  3523. $retorno = $typec::show_activity_in_ilm($iassign_statement_activity_item, $student_answer, $enderecoPOST, $view_teacherfileversion);
  3524. return $retorno;
  3525. } // function view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, $view_teacherfileversion)
  3526. /// Function to give a single access to an iLM content avoi (after used, 'view()', after 'view_iLM(...)', will erase the entry)
  3527. // @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);
  3528. // @param int $iassign_statement_activity_itemid Id of iassign statement
  3529. // @param Object $file File in use in activity
  3530. // @return int Return the id of log
  3531. function write_iLM_security ($iassign_activity_itemid, $content_or_id_from_ilm_security) {
  3532. global $CFG, $USER, $COURSE, $DB, $OUTPUT;
  3533. $newentry = new stdClass();
  3534. $newentry->iassign_statementid = $iassign_activity_itemid;
  3535. $newentry->userid = $USER->id;
  3536. $newentry->file = $content_or_id_from_ilm_security;
  3537. $newentry->timecreated = time();
  3538. $newentry->view = 1;
  3539. $id_iLM_security = $DB->insert_record("iassign_security", $newentry);
  3540. if (!$id_iLM_security) {
  3541. print_error('error_security', 'iassign'); // ./lib/setuplib.php: moodle_exception thrown
  3542. } // from (!$DB->insert_record("iassign_security", $newentry))
  3543. return $id_iLM_security;
  3544. }
  3545. /// Function to avoid that erros in remotion of entries in table 'iassign_security' allow future access to this contents
  3546. // @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);
  3547. // @param int $userid
  3548. // @param int $iassign_activity_itemid Id of iassign statement
  3549. function remove_old_iLM_security_entries ($userid, $iassign_activity_itemid) {
  3550. global $DB;
  3551. // 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")
  3552. $result = $DB->delete_records_select("iassign_security", "userid=" . $userid . " AND iassign_statementid<>" . $iassign_activity_itemid, null);
  3553. }
  3554. } // class ilm
  3555. /// Class to manage settings of iLM.
  3556. class ilm_settings {
  3557. /// Function to prepare tag to load iLM (that is stored in Moodle file system - usually /var/moodledata/filedir/).
  3558. // In case of JAR it will prepare the tag "applet". In case of HTML5 will prepare an "iframe".
  3559. // @param int $ilm_id Id of iLM
  3560. // @param array $options An array with options for create dynamic tag html APPLET
  3561. // @return string Return with a tag html APPLET created
  3562. static function build_ilm_tags ($ilm_id, $options = array()) {
  3563. global $DB;
  3564. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  3565. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  3566. $typec = strtolower($iassign_ilm->type);
  3567. require_once 'ilm_handlers/' . $typec . '.php';
  3568. $retorno = $typec::build_ilm_tags($ilm_id, $options);
  3569. return $retorno;
  3570. } // static function build_ilm_tags($ilm_id, $options = array())
  3571. /// Function for get modified date of iLM file
  3572. // @param string $file_jar String with Ids of iLM files
  3573. // @return string Return with the filenames and modified date
  3574. static function applet_filetime ($file_jar) {
  3575. $filetime = "";
  3576. $fs = get_file_storage(); // Get reference to all files in Moodle data
  3577. $files_jar = explode(",", $file_jar);
  3578. foreach ($files_jar as $one_file) {
  3579. $file = $fs->get_file_by_id($one_file);
  3580. if ($file)
  3581. $filetime .= "\n" . $file->get_filename() . ' (' . userdate($file->get_timemodified()) . ')' . '</br>';
  3582. }
  3583. return $filetime;
  3584. }
  3585. /// Function for verify an default applet
  3586. // @param String $file_jar String containing an list de ids of applet files
  3587. // @return boolean Return true or fale if applet is default
  3588. static function applet_default ($file_jar) {
  3589. $is_default = true;
  3590. $fs = get_file_storage(); // Get reference to all files in Moodle data
  3591. $files_jar = explode(",", $file_jar);
  3592. foreach ($files_jar as $one_file) {
  3593. $file = $fs->get_file_by_id($one_file);
  3594. if ($file)
  3595. $is_default &= ($file->get_itemid() == 0);
  3596. }
  3597. return $is_default;
  3598. }
  3599. /// Function for get form variables for add, edit, or copy iLM
  3600. // @calledby settings_ilm.php (2 times, initially to fill the form, second to register the iLM)
  3601. // @see settings_form.php
  3602. // @see locallib.php : static function copy_new_version_ilm ($param) : perform the data register (files and database)
  3603. // @param int $ilm_id Id of iLM
  3604. // @param string $action String with the action
  3605. // @return object Return an object with forms variables
  3606. static function add_edit_copy_ilm ($ilm_id, $action) {
  3607. global $USER, $DB, $CFG;
  3608. require_once('settings_form.php'); // put the form
  3609. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  3610. $param = new stdClass();
  3611. $param->action = $action;
  3612. $param->ilm_id = $ilm_id;
  3613. $CFG->action_ilm = $action;
  3614. $CFG->ilm_id = $ilm_id;
  3615. if ($action == 'add') {
  3616. $param->title = get_string('add_ilm', 'iassign');
  3617. $param->name = "";
  3618. $param->version = "";
  3619. $param->url = "";
  3620. $param->description = "";
  3621. $param->extension = "";
  3622. $param->author = $USER->id;
  3623. $param->file_jar = "";
  3624. $param->file_jar_static = "";
  3625. $param->file_class = "";
  3626. $param->width = 800;
  3627. $param->height = 600;
  3628. $param->enable = 0; // 0 - hide / 1 - show
  3629. $param->timecreated = time();
  3630. $param->timemodified = time();
  3631. $param->evaluate = 0;
  3632. $param->parent = 0;
  3633. }
  3634. elseif ($action == 'edit') { // static function add_edit_copy_ilm($ilm_id, $action)
  3635. if ($iassign_ilm) {
  3636. $description = json_decode($iassign_ilm->description);
  3637. $param->title = get_string('edit_ilm', 'iassign');
  3638. $param->id = $iassign_ilm->id;
  3639. $param->name_ilm = $iassign_ilm->name;
  3640. $param->name = $iassign_ilm->name;
  3641. $param->version = $iassign_ilm->version;
  3642. $param->ilm_type = $iassign_ilm->type;
  3643. $param->type = $iassign_ilm->type; // using as 'type' in ilm_handlers/html5.php
  3644. $param->url = $iassign_ilm->url;
  3645. // If the iLM does not present curret language => Notice: Undefined property: stdClass::$en_us in...
  3646. if (!isset($description->{current_language()})) {
  3647. if (isset($description->{"en_us"})) $param->description = $description->{"en_us"};
  3648. else
  3649. if (isset($description->{"pt_br"})) $param->description = $description->{"pt_br"};
  3650. else $param->description = ""; //TODO Providenciar uma mensagem!? Pegar alguma lingua existente?
  3651. }
  3652. else
  3653. $param->description = $description->{current_language()};
  3654. $param->description_lang = $iassign_ilm->description;
  3655. $param->extension = $iassign_ilm->extension;
  3656. $param->author = $iassign_ilm->author;
  3657. $param->file_jar = $iassign_ilm->file_jar;
  3658. $param->file_jar_static = ilm_settings::applet_filetime($iassign_ilm->file_jar);
  3659. $param->file_class = $iassign_ilm->file_class;
  3660. $param->width = $iassign_ilm->width;
  3661. $param->height = $iassign_ilm->height;
  3662. $param->enable = $iassign_ilm->enable;
  3663. $param->timecreated = $iassign_ilm->timecreated;
  3664. $param->timemodified = time();
  3665. $param->evaluate = $iassign_ilm->evaluate;
  3666. $param->parent = $iassign_ilm->parent;
  3667. }
  3668. }
  3669. elseif ($action == 'new_version') { // Reaches this point from the form to add new iLM
  3670. // @see ./settings_ilm.php: $param = ilm_settings::add_edit_copy_ilm($ilm_id, $action);
  3671. // $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  3672. if (!$iassign_ilm) { // The second turn (form sended) reaches this point - Just in case (if the admin use back and forward in the browser)
  3673. print get_string('empty_file', 'iassign') . "?<br/>\n"; //TODO warning not to use back?
  3674. // echo "Sem dados<br/>"; exit;
  3675. return;
  3676. }
  3677. $description = json_decode($iassign_ilm->description);
  3678. if ($iassign_ilm) {
  3679. if ($iassign_ilm->parent == 0)
  3680. $iassign_ilm->parent = $ilm_id;
  3681. $param->ilm_id = $ilm_id; //2019 after 'settings_ilm.php' it reaches this point again, better to define 'ilm_id'
  3682. $param->title = get_string('new_version_ilm', 'iassign');
  3683. $param->name_ilm = $iassign_ilm->name;
  3684. $param->name = $iassign_ilm->name;
  3685. $param->version = ""; // erase field 'version' - in order to present this field empty on the form (in 'settings_form.php')
  3686. $param->version_last = $iassign_ilm->version; //TODO not yet used!
  3687. $param->version = $iassign_ilm->version; // do not erase field 'version'
  3688. $param->ilm_type = $iassign_ilm->type;
  3689. $param->url = $iassign_ilm->url;
  3690. $param->description = $description->{current_language()};
  3691. $param->description_lang = $iassign_ilm->description; // JSON format: {"en":"Visual Interactive Programming on the Internet HTML5","pt_br":"Programação visual interativa na Internet"}
  3692. //D echo "locallib.php: add_edit_copy_ilm(...): param->description=" . $param->description . ", param->description_lang=". $param->description_lang . "<br/>";
  3693. $param->extension = $iassign_ilm->extension;
  3694. $param->author = $USER->id;
  3695. //D $param->file_jar = ''; // do not erase field 'file_jar'!
  3696. $param->file_jar = $iassign_ilm->file_jar; // do not erase field 'file_jar'!
  3697. $param->file_jar_static = '';
  3698. $param->file_class = $iassign_ilm->file_class;
  3699. $param->width = $iassign_ilm->width;
  3700. $param->height = $iassign_ilm->height;
  3701. $param->enable = 0;
  3702. $param->timecreated = time();
  3703. $param->timemodified = time();
  3704. $param->evaluate = $iassign_ilm->evaluate;
  3705. $param->parent = $iassign_ilm->parent;
  3706. }
  3707. }
  3708. elseif ($action == 'copy') {
  3709. $description = json_decode($iassign_ilm->description);
  3710. if ($iassign_ilm) {
  3711. if ($iassign_ilm->parent == 0)
  3712. $iassign_ilm->parent = $ilm_id;
  3713. $param->title = get_string('copy_ilm', 'iassign');
  3714. $param->id = $iassign_ilm->id;
  3715. $param->name_ilm = $iassign_ilm->name;
  3716. $param->name = $iassign_ilm->name;
  3717. $param->version = "";
  3718. $param->ilm_type = $iassign_ilm->type;
  3719. $param->type = $iassign_ilm->type; // using as 'type' in ilm_handlers/html5.php
  3720. $param->url = $iassign_ilm->url;
  3721. $param->description = $description->{current_language()};
  3722. $param->description_lang = $iassign_ilm->description;
  3723. $param->extension = $iassign_ilm->extension;
  3724. $param->author = $USER->id;
  3725. $param->file_jar = '';
  3726. $param->file_jar_static = '';
  3727. $param->file_class = $iassign_ilm->file_class;
  3728. $param->width = $iassign_ilm->width;
  3729. $param->height = $iassign_ilm->height;
  3730. $param->enable = 0;
  3731. $param->timecreated = time();
  3732. $param->timemodified = time();
  3733. $param->evaluate = $iassign_ilm->evaluate;
  3734. $param->parent = $iassign_ilm->parent;
  3735. }
  3736. }
  3737. return $param;
  3738. } // static function add_edit_copy_ilm($ilm_id, $action)
  3739. /// Function for save iLM file in moodledata
  3740. // @param int $itemid Itemid of file save in draft (upload file)
  3741. // @param int $ilm_id Id of iLM
  3742. // @return string Return an string with ids of iLM files
  3743. static function new_file_ilm ($itemid, $iassign_ilm) {
  3744. global $CFG, $USER, $DB;
  3745. $return = null;
  3746. $file_jar = array();
  3747. $fs = get_file_storage(); // Get reference to all files in Moodle data
  3748. $contextuser = context_user::instance($USER->id);
  3749. $contextsystem = context_system::instance();
  3750. $files_ilm = $fs->get_area_files($contextuser->id, 'user', 'draft', $itemid);
  3751. if ($files_ilm) {
  3752. foreach ($files_ilm as $value) {
  3753. // CHECK IF file is HTML type
  3754. if ($iassign_ilm->type == 1) {
  3755. // Check if the file extension is ZIP
  3756. $ext = pathinfo($value->get_filename(), PATHINFO_EXTENSION);
  3757. // It is ZIP: copy it to the 'ilm_debug' and unpack it on directory 'ilm/'
  3758. if ((strtolower($ext) == 'zip')) {
  3759. // Coping...:
  3760. $destination = 'ilm_debug/' . $value->get_filename();
  3761. $value->copy_content_to($destination);
  3762. // Extracting content...:
  3763. $zip = new ZipArchive();
  3764. $extracted = './ilm';
  3765. $dir = "";
  3766. if ($zip->open($destination) === TRUE) {
  3767. $dir = './ilm/' . trim($zip->getNameIndex(0));
  3768. if (is_dir($dir)) {
  3769. $i = 1;
  3770. $previous = str_replace("/", "", $zip->getNameIndex(0));
  3771. while (file_exists('./ilm/' . $previous . "_" . $i)) {
  3772. $i ++;
  3773. }
  3774. $name = $previous . "_" . $i;
  3775. $dir = './ilm/' . $name . "/";
  3776. $j = 0;
  3777. while ($item_name = $zip->getNameIndex($j)) {
  3778. $zip->renameIndex($j, str_replace($previous, $name, $item_name));
  3779. $j++;
  3780. }
  3781. $zip->close();
  3782. }
  3783. $zip->open($destination);
  3784. $zip->extractTo($extracted);
  3785. $zip->close();
  3786. // After the extraction, remove it from DEBUG
  3787. unlink($destination);
  3788. } else { // Error trying to open destination...
  3789. // After the extraction error, also remove it from DEBUG
  3790. unlink($destination);
  3791. print_error('error_add_ilm_zip', 'iassign');
  3792. }
  3793. return $dir;
  3794. }
  3795. } // if ($iassign_ilm->type == 1)
  3796. if ($value->get_filename() != '.') {
  3797. $file_ilm = array(
  3798. 'userid' => $USER->id,
  3799. 'contextid' => $contextsystem->id,
  3800. 'component' => 'mod_iassign',
  3801. 'filearea' => 'ilm',
  3802. 'itemid' => rand(1, 999999999),
  3803. 'filepath' => '/iassign/ilm/' . iassign_utils::format_pathname($iassign_ilm->name) . '/' . iassign_utils::format_pathname($iassign_ilm->version) . '/',
  3804. 'filename' => $value->get_filename());
  3805. $file_ilm = $fs->create_file_from_storedfile($file_ilm, $value);
  3806. array_push($file_jar, $file_ilm->get_id());
  3807. }
  3808. }
  3809. if (!empty($file_jar)) {
  3810. $return = implode(",", $file_jar);
  3811. $old_file_jar = explode(",", $iassign_ilm->file_jar);
  3812. foreach ($old_file_jar as $value) {
  3813. $file = $fs->get_file_by_id($value);
  3814. if ($file)
  3815. $fs->delete_area_files($contextsystem->id, 'mod_iassign', 'ilm', $file->get_itemid());
  3816. }
  3817. }
  3818. }
  3819. else // if ($files_ilm)
  3820. $return = $iassign_ilm->file_jar;
  3821. $delete_file = $fs->delete_area_files($contextuser->id, 'user', 'draft', $itemid);
  3822. return $return;
  3823. } // static function new_file_ilm($itemid, $iassign_ilm)
  3824. /// Function for save in database an new iLM
  3825. // @param object $param An object with iLM params
  3826. static function new_ilm ($itemid) {
  3827. global $CFG, $USER, $OUTPUT;
  3828. // Verifica se existe algum XML anterior na pasta temp e o exclui
  3829. if (file_exists($CFG->dataroot . '/temp/' . 'ilm-application.xml')) {
  3830. unlink($CFG->dataroot . '/temp/' . 'ilm-application.xml');
  3831. }
  3832. $pathtemp = $CFG->dataroot . '/temp/';
  3833. $contextuser = context_user::instance($USER->id);
  3834. $fs = get_file_storage(); // Get reference to all files in Moodle data
  3835. $zip = new zip_packer();
  3836. $files = $fs->get_directory_files($contextuser->id, 'user', 'draft', $itemid, '/');
  3837. foreach ($files as $file) {
  3838. if (!$file->is_directory())
  3839. $files_extract = $zip->extract_to_pathname($file, $pathtemp);
  3840. }
  3841. $application_xml = @simplexml_load_file($CFG->dataroot . '/temp/' . 'ilm-application.xml', null, LIBXML_NOCDATA);
  3842. // Verifica se o pacote possui o XML
  3843. if (!$application_xml) {
  3844. print($OUTPUT->notification(get_string('error_xml_ilm', 'iassign'), 'notifyproblem'));
  3845. return;
  3846. } else {
  3847. $missing = "";
  3848. if (!isset($application_xml->name)) {
  3849. $missing .= "name";
  3850. }
  3851. if (!isset($application_xml->version)) {
  3852. $missing .= ", version";
  3853. }
  3854. if (!isset($application_xml->type)) {
  3855. $missing .= ", type";
  3856. }
  3857. if (!isset($application_xml->extension)) {
  3858. $missing .= ", extension";
  3859. }
  3860. if (!isset($application_xml->file_jar)) {
  3861. $missing .= ", file_jar";
  3862. }
  3863. if (!isset($application_xml->file_class)) {
  3864. $missing .= ", file_class";
  3865. }
  3866. if (!isset($application_xml->width)) {
  3867. $missing .= ", width";
  3868. }
  3869. if (!isset($application_xml->height)) {
  3870. $missing .= ", height";
  3871. }
  3872. if (!isset($application_xml->evaluate)) {
  3873. $missing .= ", evaluate";
  3874. }
  3875. if (strlen($missing) > 2) {
  3876. print($OUTPUT->notification(get_string('error_xml_missing', 'iassign') . $missing . ".", 'notifyproblem'));
  3877. return;
  3878. }
  3879. }
  3880. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  3881. $typec = strtolower($application_xml->type);
  3882. require_once 'ilm_handlers/' . $typec . '.php';
  3883. $retorno = $typec::new_ilm($itemid, $files_extract, $application_xml, $contextuser, $fs);
  3884. return $retorno;
  3885. } // static function new_ilm($itemid)
  3886. /// Function for save in database an iLM edit
  3887. // @param object $param An object with iLM params
  3888. static function edit_ilm ($param, $itemid) {
  3889. // Descobrir o tipo de iLM:
  3890. global $DB, $USER, $CFG;
  3891. $iassign_t = $DB->get_record('iassign_ilm', array('id' => $param->id));
  3892. $pathtemp = $CFG->dataroot . '/temp/';
  3893. $contextuser = context_user::instance($USER->id);
  3894. $fs = get_file_storage(); // Get reference to all files in Moodle data
  3895. $zip = new zip_packer();
  3896. $files = $fs->get_directory_files($contextuser->id, 'user', 'draft', $itemid, '/');
  3897. $files_extract = null;
  3898. foreach ($files as $file) {
  3899. if (!$file->is_directory())
  3900. $files_extract = $zip->extract_to_pathname($file, $pathtemp);
  3901. }
  3902. // Get the iLM type (HTML5 or Java) to call the correspondent updater
  3903. $typec = strtolower($iassign_t->type);
  3904. require_once 'ilm_handlers/' . $typec . '.php';
  3905. $typec::edit_ilm($param, $itemid, $files_extract, $contextuser); // ilm_handlers/html5.php or ilm_handlers/java.php
  3906. }
  3907. /// Function for register the new iLM (in database and in the directory)
  3908. // @see settings_ilm.php : ilm_settings::copy_new_version_ilm($formdata)
  3909. // @param object $param An object with iLM params
  3910. static function copy_new_version_ilm ($param) {
  3911. global $DB, $CFG, $USER;
  3912. $itemid = $param->file;
  3913. $pathtemp = $CFG->dataroot . '/temp/';
  3914. //D echo "locallib.php: copy_new_version_ilm(...): param->description=" . $param->description . ", param->description_lang=". $param->description_lang . "<br/>";
  3915. //D echo "pathtemp=$pathtemp<br/>";
  3916. $contextuser = context_user::instance($USER->id);
  3917. $fs = get_file_storage(); // Get reference to all files in Moodle data
  3918. $zip = new zip_packer();
  3919. $files = $fs->get_directory_files($contextuser->id, 'user', 'draft', $itemid, '/');
  3920. $files_extract = null;
  3921. foreach ($files as $file) {
  3922. if (!$file->is_directory())
  3923. $files_extract = $zip->extract_to_pathname($file, $pathtemp);
  3924. }
  3925. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  3926. $iassign_t = $DB->get_record('iassign_ilm', array('id' => $param->parent));
  3927. $typec = strtolower($iassign_t->type);
  3928. require_once 'ilm_handlers/' . $typec . '.php';
  3929. //D echo "locallib.php: copy_new_version_ilm(...): antes - param->description=" . $param->description . "<br/>";
  3930. $typec::copy_new_version_ilm($param, $files_extract); // ./mod/iassign/ilm_handlers/html5.php: in fact, here the new iLM is inserted
  3931. } // static function copy_new_version_ilm($param)
  3932. //VER::
  3933. //Notice: Undefined variable: output_ilm in ./mod/iassign/locallib.php on line 5054
  3934. //Notice: Trying to get property of non-object in ./mod/iassign/locallib.php on line 192
  3935. //Notice: Trying to get property of non-object in ./mod/iassign/locallib.php on line 194
  3936. /// Function for change visibility of iLM
  3937. // @param int $ilm_id Id of iLM
  3938. // @param int $status Indicator of change vibility (0 = hide, 1 = show)
  3939. static function visible_ilm ($ilm_id, $status) {
  3940. global $DB;
  3941. if ($status == 0)
  3942. $visible = 1;
  3943. else
  3944. $visible = 0;
  3945. $newentry = new stdClass();
  3946. $newentry->id = $ilm_id;
  3947. $newentry->enable = $visible;
  3948. if (!$DB->update_record("iassign_ilm", $newentry))
  3949. error(get_string('error_edit_ilm', 'iassign'));
  3950. }
  3951. /// Function for confirm change default iLM
  3952. // @param int $ilm_id Id of iLM
  3953. // @param int $ilm_parent Id of parent iLM
  3954. // @return string Return with an string for create default page confirmation
  3955. static function confirm_default_ilm ($ilm_id, $ilm_parent) {
  3956. global $OUTPUT, $DB;
  3957. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  3958. $optionsno = new moodle_url('/admin/settings.php', array('section' => 'modsettingiassign', 'action' => 'config', 'ilm_id' => $ilm_parent));
  3959. $optionsyes = new moodle_url('/mod/iassign/settings_ilm.php', array('action' => 'default', 'ilm_id' => $ilm_id, 'ilm_parent' => $ilm_parent));
  3960. $return = $OUTPUT->heading(get_string('confirm_default', 'iassign') . ': ' . $iassign_ilm->name);
  3961. $return .= $OUTPUT->confirm(get_string('confirm_default_ilm', 'iassign') . $OUTPUT->help_icon('confirm_default_ilm', 'iassign'), $optionsyes, $optionsno);
  3962. return $return;
  3963. }
  3964. /// Function for change the default iLM
  3965. // @see settings_ilm.php
  3966. // @param int $ilm_id Id of iLM
  3967. // @return int Return Id of default iLM
  3968. static function default_ilm ($ilm_id) {
  3969. global $DB;
  3970. $iassign_ilm_default = $DB->get_record("iassign_ilm", array('id' => $ilm_id));
  3971. $iassign_ilm = $DB->get_record("iassign_ilm", array('id' => $iassign_ilm_default->parent));
  3972. $DB->delete_records("iassign_ilm", array('id' => $iassign_ilm_default->id));
  3973. $iassign_ilm_default->id = $iassign_ilm->id;
  3974. $iassign_ilm_default->parent = 0;
  3975. $iassign_ilm->parent = $iassign_ilm_default->id;
  3976. $iassign_ilm->id = 0;
  3977. $iassign_ilm_default->enable = 1;
  3978. if (!$DB->update_record("iassign_ilm", $iassign_ilm_default)) {
  3979. print_error('error_edit_ilm', 'iassign');
  3980. }
  3981. $inserted = $DB->insert_record("iassign_ilm", $iassign_ilm);
  3982. if (!$inserted) {
  3983. $msg_error = get_string('error_add_ilm', 'iassign') . "<br/>In default_ilm(" . $ilm_id . ")<br/>\n";
  3984. print_error($msg_error);
  3985. //xx print_error('error_add_ilm', 'iassign');
  3986. }
  3987. return $iassign_ilm_default->id;
  3988. } // static function default_ilm ($ilm_id)
  3989. /// Function for confirm delete iLM
  3990. // @param int $ilm_id Id of iLM
  3991. // @param int $ilm_parent Id of parent iLM
  3992. // @return string Return with an string for create delete page confirmation
  3993. static function confirm_delete_ilm ($ilm_id, $ilm_parent) {
  3994. global $OUTPUT, $DB;
  3995. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  3996. $optionsno = new moodle_url('/admin/settings.php', array('section' => 'modsettingiassign', 'action' => 'config', 'ilm_id' => $ilm_parent));
  3997. $optionsyes = new moodle_url('/mod/iassign/settings_ilm.php', array('action' => 'delete', 'ilm_id' => $ilm_id, 'ilm_parent' => $ilm_parent));
  3998. return $OUTPUT->confirm(get_string('confirm_delete_ilm', 'iassign', $iassign_ilm->name . ' ' . $iassign_ilm->version), $optionsyes, $optionsno);
  3999. }
  4000. /// Function for delete directory where the iLM is allocated.
  4001. // @param string $dirPath
  4002. // @throws InvalidArgumentException
  4003. public static function delete_dir ($dirPath) {
  4004. if (substr($dirPath, strlen($dirPath) - 1, 1) != '/') {
  4005. $dirPath .= '/';
  4006. }
  4007. $files = glob($dirPath . '*', GLOB_MARK);
  4008. foreach ($files as $file) {
  4009. if (is_dir($file)) {
  4010. ilm_settings::delete_dir($file);
  4011. } else {
  4012. unlink($file);
  4013. }
  4014. }
  4015. rmdir($dirPath);
  4016. }
  4017. /// Function for delete iLM
  4018. // @param int $ilm_id Id of iLM
  4019. // @return int Return Id of parent iLM
  4020. static function delete_ilm ($ilm_id) {
  4021. global $DB;
  4022. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4023. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  4024. $typec = strtolower($iassign_ilm->type);
  4025. require_once 'ilm_handlers/' . $typec . '.php';
  4026. $retorno = $typec::delete_ilm($ilm_id);
  4027. return $retorno;
  4028. }
  4029. /// Function to export iLM package (ZIP file), eventually to install in other Moodle
  4030. // @param int $ilm_id Id of iLM
  4031. static function export_ilm ($ilm_id) {
  4032. global $DB;
  4033. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4034. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  4035. $typec = strtolower($iassign_ilm->type);
  4036. require_once 'ilm_handlers/' . $typec . '.php';
  4037. $typec::export_ilm($ilm_id);
  4038. } // static function export_ilm($ilm_id)
  4039. //TODO iLM_HTML5 :: //MOOC 2016
  4040. // Function to export iLM package descriptor for allow online update. //TODO a ser usado onde? como?
  4041. // @param int $ilm_id Id of iLM
  4042. static function export_update_ilm ($ilm_id) {
  4043. global $DB, $CFG;
  4044. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4045. $xml_filename = $CFG->dataroot . '/temp/ilm-upgrade_' . iassign_utils::format_pathname($iassign_ilm->name) . '.xml';
  4046. $zip_filename = 'ilm-' . iassign_utils::format_pathname($iassign_ilm->name . '-v' . $iassign_ilm->version) . '.ipz';
  4047. $upgrade_descriptor = '<?xml version="1.0" encoding="utf-8"?>' . "\n";
  4048. $upgrade_descriptor .= '<upgrade xmlns="http://line.ime.usp.br/application/1.5">' . "\n";
  4049. $upgrade_descriptor .= ' <version>' . $iassign_ilm->version . '</version>' . "\n";
  4050. $upgrade_descriptor .= ' <file>' . $zip_filename . '</file>' . "\n";
  4051. $upgrade_descriptor .= ' <description>' . iassign_language::json_to_xml($iassign_ilm->description) . "\n " . '</description>' . "\n";
  4052. $upgrade_descriptor .= '</upgrade>' . "\n";
  4053. file_put_contents($xml_filename, $upgrade_descriptor);
  4054. header("Pragma: public");
  4055. header("Expires: 0");
  4056. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  4057. header("Cache-Control: private", false);
  4058. header('Content-Type: application/xml; charset=utf-8');
  4059. header("Content-Disposition: attachment; filename=\"" . basename($xml_filename) . "\";");
  4060. header("Content-Length: " . @filesize($xml_filename));
  4061. set_time_limit(0);
  4062. @readfile("$xml_filename") || die("File not found.");
  4063. unlink($xml_filename);
  4064. exit;
  4065. } // static function export_update_ilm($ilm_id) //MOOC 2016
  4066. /// Function for save iLM from XML descriptor
  4067. // @param array $application_xml Data of XML descriptor
  4068. // @param array $files_extract Filenames of extract files
  4069. // @return array Return an array content id of JAR files
  4070. static function save_ilm_by_xml ($application_xml, $files_extract) {
  4071. global $CFG, $USER;
  4072. // Tratamento diferenciado se for do tipo HTML5:
  4073. $source = "";
  4074. $diretorio = "";
  4075. if (strtolower($application_xml->type) == 'html5') {
  4076. $i = 0;
  4077. foreach ($files_extract as $key => $value) {
  4078. $file = $CFG->dataroot . '/temp/' . $key;
  4079. // Verifica se já existe a pasta no diretório dos iLM:
  4080. if ($i == 0) {
  4081. $source = $file;
  4082. if (file_exists("ilm/" . basename($file))) {
  4083. $j = 1;
  4084. while (file_exists('ilm/' . basename($file) . "_" . $j)) {
  4085. $j ++;
  4086. }
  4087. $diretorio = 'ilm/' . basename($file) . "_" . $j;
  4088. // mkdir($diretorio, 0777, true);
  4089. mkdir($diretorio, 0755, true); // permissions: drwxr-xr-x
  4090. }
  4091. else {
  4092. $diretorio = 'ilm/' . basename($file);
  4093. // mkdir($diretorio, 0777, true);
  4094. mkdir($diretorio, 0755, true);
  4095. }
  4096. break;
  4097. }
  4098. $i ++;
  4099. }
  4100. foreach ($iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($source, RecursiveDirectoryIterator::SKIP_DOTS), RecursiveIteratorIterator::SELF_FIRST) as $item) {
  4101. if ($item->isDir()) {
  4102. mkdir($diretorio . DIRECTORY_SEPARATOR . $iterator->getSubPathName(), 0755, true);
  4103. }
  4104. else {
  4105. copy($item, $diretorio . DIRECTORY_SEPARATOR . $iterator->getSubPathName());
  4106. }
  4107. }
  4108. ilm_settings::delete_dir($source);
  4109. return "./" . $diretorio;
  4110. }
  4111. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4112. $file_jar = array();
  4113. $files_ilm = explode(",", $application_xml->file_jar);
  4114. $contextsystem = context_system::instance();
  4115. foreach ($files_ilm as $value) {
  4116. $file_ilm = array(
  4117. 'userid' => $USER->id,
  4118. 'contextid' => $contextsystem->id,
  4119. 'component' => 'mod_iassign',
  4120. 'filearea' => 'ilm',
  4121. 'itemid' => rand(1, 999999999),
  4122. 'filepath' => '/iassign/ilm/' . iassign_utils::format_pathname($application_xml->name) . '/' . iassign_utils::format_pathname($application_xml->version) . '/',
  4123. 'filename' => $value);
  4124. $file_ilm = $fs->create_file_from_pathname($file_ilm, $CFG->dataroot . '/temp/' . $value);
  4125. array_push($file_jar, $file_ilm->get_id());
  4126. }
  4127. foreach ($files_extract as $key => $value) {
  4128. $file = $CFG->dataroot . '/temp/' . $key;
  4129. if (file_exists($file))
  4130. unlink($file);
  4131. }
  4132. return $file_jar;
  4133. } // static function save_ilm_by_xml($application_xml, $files_extract)
  4134. /// Function for import the iLM from an package
  4135. // @param int $itemid Itemid of zip file
  4136. static function import_ilm ($itemid) {
  4137. global $CFG, $USER, $OUTPUT;
  4138. // Verifica se existe algum XML anterior na pasta temp e o exclui
  4139. if (file_exists($CFG->dataroot . '/temp/' . 'ilm-application.xml')) {
  4140. unlink($CFG->dataroot . '/temp/' . 'ilm-application.xml');
  4141. }
  4142. $pathtemp = $CFG->dataroot . '/temp/';
  4143. $contextuser = context_user::instance($USER->id);
  4144. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4145. $zip = new zip_packer();
  4146. $files = $fs->get_directory_files($contextuser->id, 'user', 'draft', $itemid, '/');
  4147. foreach ($files as $file) {
  4148. if (!$file->is_directory())
  4149. $files_extract = $zip->extract_to_pathname($file, $pathtemp);
  4150. }
  4151. $application_xml = @simplexml_load_file($CFG->dataroot . '/temp/' . 'ilm-application.xml', null, LIBXML_NOCDATA);
  4152. // Verifica se o pacote possui o XML
  4153. if (!$application_xml) {
  4154. print($OUTPUT->notification(get_string('error_xml_ilm', 'iassign'), 'notifyproblem'));
  4155. return;
  4156. } else {
  4157. $missing = "";
  4158. if (!isset($application_xml->name)) {
  4159. $missing .= "name";
  4160. }
  4161. if (!isset($application_xml->version)) {
  4162. $missing .= ", version";
  4163. }
  4164. if (!isset($application_xml->type)) {
  4165. $missing .= ", type";
  4166. }
  4167. if (!isset($application_xml->extension)) {
  4168. $missing .= ", extension";
  4169. }
  4170. if (!isset($application_xml->file_jar)) {
  4171. $missing .= ", file_jar";
  4172. }
  4173. if (!isset($application_xml->file_class)) {
  4174. $missing .= ", file_class";
  4175. }
  4176. if (!isset($application_xml->width)) {
  4177. $missing .= ", width";
  4178. }
  4179. if (!isset($application_xml->height)) {
  4180. $missing .= ", height";
  4181. }
  4182. if (!isset($application_xml->evaluate)) {
  4183. $missing .= ", evaluate";
  4184. }
  4185. if (strlen($missing) > 2) {
  4186. print($OUTPUT->notification(get_string('error_xml_missing', 'iassign') . $missing . ".", 'notifyproblem'));
  4187. return;
  4188. }
  4189. }
  4190. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  4191. $typec = strtolower($application_xml->type);
  4192. require_once 'ilm_handlers/' . $typec . '.php';
  4193. $typec::import_ilm($itemid, $files_extract, $application_xml, $contextuser, $fs);
  4194. } // static function import_ilm($itemid)
  4195. /// Function for list iLM defaults
  4196. // @return string Return an string with a table of iLM
  4197. static function list_ilm () {
  4198. global $DB, $OUTPUT;
  4199. $iassign_ilm = $DB->get_records('iassign_ilm', array("enable" => 1));
  4200. $str = '';
  4201. $str .= '<table id="outlinetable" cellpadding="5" width="100%" >' . "\n";
  4202. $str .= '<tr><td align=right><input type=button value="' . get_string('close', 'iassign') . '" onclick="javascript:window.close ();"></td></tr>';
  4203. if ($iassign_ilm) {
  4204. foreach ($iassign_ilm as $ilm) {
  4205. $url_view = new moodle_url('/mod/iassign/settings_ilm.php', array('action' => 'view', 'ilm_id' => $ilm->id));
  4206. $link_view = $OUTPUT->action_link($url_view, iassign_icons::insert('view_ilm') . ' ' . get_string('read_more', 'iassign'));
  4207. $str .= '<tr><td>';
  4208. $str .= '<table class="generaltable boxaligncenter" width="100%">';
  4209. $str .= '<tr>';
  4210. $str .= '<td class=\'cell c0 actvity\' width=40%><strong>' . get_string('name_ilm', 'iassign') . ':</strong>&nbsp;' . $ilm->name . '</td>' . "\n";
  4211. $str .= '<td><strong>' . get_string('version_ilm', 'iassign') . ':</strong>&nbsp;' . $ilm->version . '</td>' . "\n";
  4212. $str .= '<td align=right>' . $link_view . '</td>' . "\n";
  4213. $str .= '</tr>';
  4214. $str .= '<tr><td colspan=3>' . iassign_language::get_description_lang(current_language(), $ilm->description) . '</td></tr>';
  4215. $str .= '<tr><td colspan=3><a href="' . $ilm->url . '">' . $ilm->url . '</a></td></tr>';
  4216. $str .= '</table>';
  4217. $str .= '</td></tr>';
  4218. }
  4219. }
  4220. $str .= '</table>';
  4221. return $str;
  4222. }
  4223. /// Function for download and install an upgrade of an iLM
  4224. // @param int $ilm_id Id of iLM
  4225. static function upgrade_ilm ($ilm_id) {
  4226. global $DB, $CFG, $USER;
  4227. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4228. $upgrade_file = $iassign_ilm->url . 'ilm-upgrade_' . strtolower($iassign_ilm->name) . '.xml';
  4229. $update_xml = @simplexml_load_file($upgrade_file, null, LIBXML_NOCDATA);
  4230. $result = file_put_contents($CFG->dataroot . '/temp/' . $update_xml->file, fopen($iassign_ilm->url . $update_xml->file, 'r'));
  4231. if (!$result)
  4232. print_error('error_upgrade_ilm', 'iassign');
  4233. else {
  4234. $zip_filename = $CFG->dataroot . '/temp/' . $update_xml->file;
  4235. $extension = explode(".", $zip_filename);
  4236. if ($extension[count($extension) - 1] != 'ipz') {
  4237. print($OUTPUT->notification(get_string('error_upload_ilm', 'iassign'), 'notifyproblem'));
  4238. die;
  4239. }
  4240. $zip = new zip_packer();
  4241. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4242. $contextuser = context_user::instance($USER->id);
  4243. $files_extract = $zip->extract_to_pathname($zip_filename, $CFG->dataroot . '/temp/');
  4244. $application_xml = @simplexml_load_file($CFG->dataroot . '/temp/' . 'ilm-application.xml', null, LIBXML_NOCDATA);
  4245. $description_str = htmlentities(str_replace(array('<description>', '</description>'), array('', ''), $application_xml->description->asXML()));
  4246. $file_jar = self::save_ilm_by_xml($application_xml, $files_extract);
  4247. if (file_exists($zip_filename))
  4248. unlink($zip_filename);
  4249. if (empty($file_jar)) {
  4250. $msg_error = get_string('error_add_ilm', 'iassign') . "<br/>In upgrade_ilm(" . $ilm_id . ")<br/>\n";
  4251. print_error($msg_error);
  4252. //xx print_error('error_add_ilm', 'iassign');
  4253. }
  4254. else {
  4255. $newentry = new stdClass();
  4256. $newentry->name = (String) $application_xml->name;
  4257. $newentry->version = (String) $application_xml->version;
  4258. $newentry->url = (String) $application_xml->url;
  4259. $newentry->description = $description_str;
  4260. $newentry->extension = strtolower((String) $application_xml->extension);
  4261. $newentry->file_jar = implode(",", $file_jar);
  4262. $newentry->file_class = (String) $application_xml->file_class;
  4263. $newentry->width = (String) $application_xml->width;
  4264. $newentry->height = (String) $application_xml->height;
  4265. $newentry->enable = 0;
  4266. $newentry->timemodified = time();
  4267. $newentry->author = $USER->id;
  4268. $newentry->timecreated = time();
  4269. $newentry->evaluate = (String) $application_xml->evaluate;
  4270. $newentry->parent = $ilm_id;
  4271. }
  4272. }
  4273. return $iassign_ilm->id;
  4274. } // static function upgrade_ilm($ilm_id)
  4275. //MOOC2014 -- inicio
  4276. //TODO: REVIEW
  4277. // static function confirm_move_iassign($ilmid, $ilm_parent)
  4278. // static function move_iassign($ilm_id)
  4279. //MOOC2014 -- final
  4280. /// Function for list iLM versions with all informations
  4281. // @return string Return an string with a table of iLM
  4282. static function view_ilm ($ilmid, $from) {
  4283. global $DB;
  4284. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilmid));
  4285. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  4286. $typec = strtolower($iassign_ilm->type);
  4287. require_once 'ilm_handlers/' . $typec . '.php';
  4288. $retorno = $typec::view_ilm($ilmid, $from);
  4289. return $retorno;
  4290. }
  4291. /// Function for get form variables for add, edit, or copy iLM params
  4292. // @param int $ilm_param_id Id of iLM param
  4293. // @param string $action String with the action
  4294. // @return object Return an object with forms variables
  4295. static function add_edit_copy_param ($ilm_param_id, $action) {
  4296. global $DB;
  4297. require_once('params_form.php');
  4298. $iassign_ilm_config = $DB->get_record('iassign_ilm_config', array('id' => $ilm_param_id));
  4299. $param = new stdClass();
  4300. $param->action = $action;
  4301. $param->ilm_param_id = $ilm_param_id;
  4302. $type = optional_param('type', NULL, PARAM_TEXT); //MOOC2014
  4303. if ($type == NULL && $iassign_ilm_config) //MOOC2014
  4304. $type = $iassign_ilm_config->param_type;
  4305. if ($action == 'add') {
  4306. $param->title = get_string('add_ilm', 'iassign');
  4307. $param->iassign_ilmid = $ilm_param_id;
  4308. $param->param_name = "";
  4309. $param->param_value = "";
  4310. $param->description = "";
  4311. $param->visible = 1;
  4312. }
  4313. elseif ($action == 'edit') {
  4314. if ($iassign_ilm_config) {
  4315. $param->title = get_string('edit_ilm', 'iassign');
  4316. $param->id = $iassign_ilm_config->id;
  4317. $param->iassign_ilmid = $iassign_ilm_config->iassign_ilmid;
  4318. $param->param_type = $type; //MOOC2014
  4319. $param->param_name = $iassign_ilm_config->param_name;
  4320. if ($type != 'choice' && $type != 'multiple') //MOOC2014
  4321. $param->param_value = $iassign_ilm_config->param_value;
  4322. else //MOOC2014
  4323. $param->param_value = str_replace(", ", "\n", $iassign_ilm_config->param_value); //MOOC2014
  4324. $param->param_value = $iassign_ilm_config->param_value;
  4325. $param->description = $iassign_ilm_config->description;
  4326. $param->visible = $iassign_ilm_config->visible;
  4327. }
  4328. }
  4329. elseif ($action == 'copy') {
  4330. if ($iassign_ilm_config) {
  4331. $param->title = get_string('copy_ilm', 'iassign');
  4332. $param->iassign_ilmid = $iassign_ilm_config->iassign_ilmid;
  4333. $param->param_type = $type; //MOOC2014
  4334. $param->param_name = $iassign_ilm_config->param_name;
  4335. if ($type != 'choice' && $type != 'multiple') //MOOC2014
  4336. $param->param_value = $iassign_ilm_config->param_value;
  4337. else //MOOC2014
  4338. $param->param_value = str_replace(", ", "\n", $iassign_ilm_config->param_value); //MOOC2014
  4339. $param->description = $iassign_ilm_config->description;
  4340. $param->visible = $iassign_ilm_config->visible;
  4341. }
  4342. }
  4343. return $param;
  4344. } // static function add_edit_copy_param($ilm_param_id, $action)
  4345. /// Function for change visibility of iLM param
  4346. // @param int $ilm_param_id Id of iLM param
  4347. // @param int $status Indicator of change vibility (0 = hide, 1 = show)
  4348. static function visible_param ($ilm_param_id, $status) {
  4349. global $DB, $CFG;
  4350. if ($status == 0)
  4351. $visible = 1;
  4352. else
  4353. $visible = 0;
  4354. $newentry = new stdClass();
  4355. $newentry->id = $ilm_param_id;
  4356. $newentry->visible = $visible;
  4357. if (!$DB->update_record("iassign_ilm_config", $newentry))
  4358. error(get_string('error_edit_param', 'iassign'));
  4359. }
  4360. /// Function for save in database an new iLM param
  4361. // @param object $param An object with iLM params
  4362. static function add_param ($param) {
  4363. global $DB;
  4364. $newentry = new stdClass();
  4365. $newentry->iassign_ilmid = $param->iassign_ilmid;
  4366. //MOOC2014 $newentry->param_name = $param->param_name;
  4367. $newentry->param_type = $param->param_type; //MOOC2014
  4368. $newentry->param_name = iassign_utils::format_filename($param->param_name); //MOOC2014
  4369. if ($newentry->param_type != 'choice' && $newentry->param_type != 'multiple') //MOOC2014
  4370. $newentry->param_value = $param->param_value;
  4371. else //MOOC2014
  4372. $newentry->param_value = str_replace("\r\n", ", ", $param->param_value); //MOOC2014
  4373. $newentry->description = $param->description;
  4374. $newentry->visible = $param->visible;
  4375. $newentry->id = $DB->insert_record("iassign_ilm_config", $newentry);
  4376. if (!$newentry->id) {
  4377. print_error('error_add_param', 'iassign');
  4378. }
  4379. }
  4380. /// Function for save in database a iLM param edit
  4381. // @param object $param An object with iLM params
  4382. static function edit_param ($param) {
  4383. global $DB;
  4384. $updentry = new stdClass();
  4385. $updentry->id = $param->id;
  4386. $updentry->iassign_ilmid = $param->iassign_ilmid;
  4387. $updentry->param_type = $param->param_type; //MOOC2014
  4388. // $updentry->param_name = $param->param_name;
  4389. $newentry->param_name = iassign_utils::format_filename($param->param_name); //MOOC2014
  4390. if ($updentry->param_type != 'choice' && $updentry->param_type != 'multiple') //MOOC2014
  4391. $updentry->param_value = $param->param_value;
  4392. else //MOOC2014
  4393. $updentry->param_value = str_replace("\r\n", ", ", $param->param_value); //MOOC2014
  4394. $updentry->description = $param->description;
  4395. $updentry->visible = $param->visible;
  4396. if (!$DB->update_record("iassign_ilm_config", $updentry)) {
  4397. error(get_string('error_edit_param', 'iassign'));
  4398. }
  4399. }
  4400. /// Function for save in database a iLM param copy
  4401. // @param object $param An object with iLM params
  4402. static function copy_param ($param) {
  4403. global $DB;
  4404. $newentry = new stdClass();
  4405. $newentry->iassign_ilmid = $param->iassign_ilmid;
  4406. //$newentry->param_name = $param->param_name;
  4407. $newentry->param_name = iassign_utils::format_filename($param->param_name); //MOOC2014
  4408. if ($newentry->param_type != 'choice' && $newentry->param_type != 'multiple') //MOOC2014
  4409. $newentry->param_value = $param->param_value;
  4410. else //MOOC2014
  4411. $newentry->param_value = str_replace("\r\n", ", ", $param->param_value); //MOOC2014
  4412. $newentry->description = $param->description;
  4413. $newentry->visible = $param->visible;
  4414. $newentry->id = $DB->insert_record("iassign_ilm_config", $newentry);
  4415. if (!$newentry->id) {
  4416. print_error('error_add_param', 'iassign');
  4417. }
  4418. }
  4419. /// Function for delete iLM param of database
  4420. // @param int $param_id Id of iLM param
  4421. static function delete_param ($param_id) {
  4422. global $DB;
  4423. if (!$DB->delete_records("iassign_ilm_config", array('id' => $param_id))) {
  4424. print_error('error_delete_param', 'iassign');
  4425. }
  4426. }
  4427. } // class ilm_settings
  4428. /// Class for manage iLM files (editor).
  4429. class ilm_manager {
  4430. var $id; // course id
  4431. var $url;
  4432. var $from;
  4433. /// Constructor for the base ilm_manager class
  4434. // 3.1 update PHP 7.0 compatibility for all moodle versions
  4435. //D public function ilm_manager($id, $url, $from) { self::__construct($iassign, $cm, $course); }
  4436. function __construct ($id, $url, $from) {
  4437. $this->id = $id; // course id
  4438. $this->url = $url;
  4439. $this->from = $from;
  4440. }
  4441. /// Function to get iAssign content file in Moodle data (exercise)
  4442. // @calledby x function preview_ilm($iassign_ilm) :
  4443. // @calledby ilm_manager.php : with 'action=get' in '$ilm_manager_instance->get_file_ilm($ilmid, $fileid)'
  4444. function get_file_ilm () {
  4445. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  4446. $fileid = optional_param('fileid', NULL, PARAM_INT);
  4447. //$filename = optional_param('filename', NULL, PARAM_TEXT);
  4448. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4449. $md_file = $fs->get_file_by_id($fileid);
  4450. $ilm_content_file = $md_file->get_content();
  4451. return $ilm_content_file;
  4452. }
  4453. /// Function for creating a new file from the iLM online editor
  4454. // @calledby ilm_manager.php: case 'new': $ilm_manager_instance->ilm_editor_new();
  4455. function ilm_editor_new () {
  4456. global $CFG, $DB, $OUTPUT, $PAGE;
  4457. $ilmid = optional_param('ilmid', NULL, PARAM_INT); // iAssign ID
  4458. $dirid = optional_param('dirid', NULL, PARAM_INT);
  4459. $iassign = $DB->get_record("iassign_ilm", array("id" => $ilmid));
  4460. $context = context_course::instance($this->id);
  4461. $returnurl = $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=$this->id&dirid=$dirid&ilmid=$ilmid";
  4462. // verify if the JAR file $PAGE->set_course($course); is registered in DB (table '*_iassign_ilm')
  4463. if (!$iassign) {
  4464. print $OUTPUT->notification(get_string('error_confirms_ilm', 'iassign'), 'notifysuccess');
  4465. die();
  4466. }
  4467. $temp = explode(",", $iassign->extension);
  4468. $extension = $temp[0]; // default extension for this iLM
  4469. //2016/02/16: IMPORTANTE trocar formatador para "nao formatado", pois esta destruindo o nome do arquivo (e.g. limpa brancos)
  4470. //2016/02/16: $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_ALPHANUMEXT);
  4471. $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_RAW); // iLM 2
  4472. // $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_RAW); // iLM 1
  4473. if ($stringArchiveContent != NULL) {
  4474. // $stringArchiveContent = $_POST['iLM_PARAM_ArchiveContent'];
  4475. //2016/02/16: IMPORTANTE trocar formatador para "nao formatado", pois esta destruindo o conteudo do arquivo
  4476. //2016/02/16: $filename = optional_param('filename', NULL, PARAM_ALPHANUMEXT);
  4477. $filename = optional_param('filename', NULL, PARAM_RAW);
  4478. //Leo $filename = iassign_utils::format_filename($filename); //
  4479. $filename = iassign_utils::filter_filename_extension($filename, $extension); // here: class iassign_utils
  4480. //2019/02 It is not necessary, since 'iassign_utils::filter_filename_extension(...)' does all the work!
  4481. //2019/02 $arrayfilename = explode(".", $filename);
  4482. //2019/02 // if (count($arrayfilename) == 1) $filename = $arrayfilename[0] . '.' . $extension;
  4483. //2019/02 $count_dots = count($arrayfilename);
  4484. //2019/02 if ($count_dots > 0) { // at least one dot mark
  4485. //2019/02 $last_name = $arrayfilename[$count_dots - 1];
  4486. //2019/02 if ($last_name != $extension)
  4487. //2019/02 $filename = $filename . '.' . $extension;
  4488. //2019/02 }
  4489. //2019/02 else { // no extension...
  4490. //2019/02 $filename = $filename . '.' . $extension;
  4491. //2019/02 }
  4492. // Store the name of recent created file
  4493. $_SESSION['file_name'] = $filename;
  4494. //$this->write_file_iassign($string, $filename);
  4495. // Register and (by JS.alet(.)) inform the user about the result (and the final name of the file)
  4496. $this->write_file_iassign($stringArchiveContent, $filename); // class ilm_manager - inform the user about the file insertion result
  4497. die();
  4498. }
  4499. else { // if ($stringArchiveContent != NULL)
  4500. // iLM On-line editor
  4501. if ($extension == "html" || $extension == "ivph" || strtolower($iassign->type) == 'html5') { // if iLM is HTML5 is inside a frame
  4502. $str_get_iLM = "window.frames.iLM";
  4503. $str_submitbutton_name = "javascript:window.submit_iLM_Answer()";
  4504. }
  4505. else { // otherwise it is JAR named 'iLM'
  4506. $str_get_iLM = "document.iLM";
  4507. $str_submitbutton_name = "submit_iLM_Answer()"; // to call 'submit_iLM_Answer()'
  4508. }
  4509. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4510. $files = $fs->get_area_files($context->id, 'mod_iassign', 'activity');
  4511. $files_array = '';
  4512. foreach ($files as $value) {
  4513. if ($value->get_filename() != ".")
  4514. $files_array .= "'" . $value->get_filename() . "',";
  4515. }
  4516. $files_array .= "''";
  4517. $file = null;
  4518. $ia_content = "";
  4519. $filename = "";
  4520. $error_files_exists = get_string('error_file_exists', 'iassign');
  4521. $output = "<script type='text/javascript'>
  4522. //<![CDATA[
  4523. //D alert('locallib.php: ilm_editor_new');
  4524. function submit_iLM_Answer () {
  4525. var docFormOnLineEditor = document.formEnvio;
  4526. var resposta_exerc = new Array(3);
  4527. var valor_resposta = new Array(3);
  4528. var sessao = new Array(3);
  4529. var doc_iLM = " . $str_get_iLM . "; // 'window.frames.iLM' or 'document.iLM'
  4530. resposta_exerc[0] = doc_iLM.getAnswer();
  4531. valor_resposta[0] = doc_iLM.getEvaluation();
  4532. docFormOnLineEditor.iLM_PARAM_ActivityEvaluation.value = valor_resposta[0];
  4533. docFormOnLineEditor.iLM_PARAM_ArchiveContent.value = resposta_exerc[0];
  4534. var files = new Array(" . $files_array . ");
  4535. var filename = docFormOnLineEditor.filename.value+'.'+'" . $extension . "';
  4536. if (docFormOnLineEditor.filename.value=='') {
  4537. // ERROR: the file name is empty
  4538. alert('" . get_string('error_file_null_iassign', 'iassign') . "');
  4539. return false;
  4540. }
  4541. // }
  4542. for (i=0; i<files.length; i++) {
  4543. if (files[i]==docFormOnLineEditor.filename.value || files[i]==filename) {
  4544. alert('" . $error_files_exists . "');
  4545. return false;
  4546. }
  4547. }
  4548. docFormOnLineEditor.submit();
  4549. return true;
  4550. }
  4551. //]]>
  4552. </script>\n";
  4553. $output .= "
  4554. <form name='formEnvio' id='formEnvio' method='post' enctype='multipart/form-data'>\n";
  4555. $output .= $OUTPUT->box_start();
  4556. // Put text "File name" and the corresponding "input" to enter the file nama: "File name: [ ]"
  4557. $output .= "
  4558. <table width='100%' cellpadding='20'>
  4559. <tr><td>" . get_string('label_file_iassign', 'iassign') . " <input type='text' name='filename' size=50/>
  4560. <input type=button value='" . get_string('label_write_iassign', 'iassign') . "' title='' onclick='" . $str_submitbutton_name . ";'/></td>
  4561. <td><input type=button value='" . get_string('close', 'iassign') . "' title='' onclick='javascript:window.location = \"$returnurl\";'/></td>
  4562. </tr>
  4563. </table>\n";
  4564. $output .= $OUTPUT->box_end();
  4565. $output .= "<center>\n";
  4566. // Prepare tag to load the iLM. In case of JAR it will prepare the tag "applet". In case of HTML5 will prepare an "iframe".
  4567. // Since it is the activity file, it is not necessary to use 'ilm_security'
  4568. $output_ilm = ilm_settings::build_ilm_tags($ilmid, array("type" => "editor_new", "notSEND" => "true"));
  4569. $output .= $output_ilm;
  4570. $output .= " <input type='hidden' name='iLM_PARAM_ArchiveContent' value='" . $ia_content . "'>
  4571. <input type='hidden' name='iLM_PARAM_ActivityEvaluation'>
  4572. </center>
  4573. </form>\n";
  4574. $title = get_string('title_editor_iassign', 'iassign') . " - " . $iassign->name . " " . $iassign->version; //MOOC2014
  4575. $PAGE->navbar->add($title);
  4576. $PAGE->set_title($title);
  4577. $PAGE->set_heading($title); // insert title above the navigation bar
  4578. print $OUTPUT->header();
  4579. //print $OUTPUT->heading("&nbsp;&nbsp;" . $title); // insert title below the navigation bar
  4580. print $output;
  4581. print $OUTPUT->footer();
  4582. }
  4583. die();
  4584. } // function ilm_editor_new()
  4585. /// Function for editing an file in online editor
  4586. // @calledby ilm_manager.php: case 'update': $ilm_manager_instance->ilm_editor_update($security['content'], $security['token'], $security['secure_id']);
  4587. function ilm_editor_update ($filename, $content_file, $token, $secure_id) {
  4588. global $CFG, $DB, $OUTPUT, $PAGE;
  4589. $ilmid = optional_param('ilmid', NULL, PARAM_INT); // iAssign ID
  4590. $dirid = optional_param('dirid', NULL, PARAM_INT);
  4591. $fileid = optional_param('fileid', NULL, PARAM_TEXT);
  4592. $iassign = $DB->get_record("iassign_ilm", array("id" => $ilmid));
  4593. $returnurl = $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=$this->id&dirid=$dirid&ilmid=$ilmid";
  4594. // If iLM is not registered, error!
  4595. if (!$iassign) {
  4596. print $OUTPUT->notification(get_string('error_confirms_ilm', 'iassign'), 'notifyproblem');
  4597. die;
  4598. }
  4599. //2017/03/12 //QUARANTINE agora vindo de 'ilm_manager.php' via os 3 parametros
  4600. //2017/03/12 $fs = get_file_storage(); // Get reference to all files in Moodle data // from Moodle data
  4601. //2017/03/12 $filename = ''; $end_file = ''; $file = $fs->get_file_by_id($fileid); if ($file) $filename = iassign_utils::format_filename($file->get_filename());
  4602. //D echo "locallib.php: ilm_editor_update(): filename=$filename<br/>\n";
  4603. //2016/02/16: IMPORTANTE trocar formatador para "nao formatado", pois esta destruindo o conteudo do arquivo
  4604. //2016/02/16: $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_ALPHANUMEXT);
  4605. $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_RAW);
  4606. //D echo "stringArchiveContent:$stringArchiveContent<br/>\n";
  4607. if ($stringArchiveContent != NULL) {
  4608. $this->update_file_iassign($stringArchiveContent, $filename, $fileid);
  4609. die();
  4610. } else { // if ($stringArchiveContent != NULL)
  4611. $end_file = '';
  4612. if ($content_file) {
  4613. // 2017/03/12 $token=''; $view=-1; $end_file = $CFG->wwwroot . '/mod/iassign/ilm_security.php?id=' . $fileid . '&token=' . $token . '&view=' . $view; // need full path...
  4614. $end_file = $CFG->wwwroot . '/mod/iassign/ilm_security.php?id=' . $secure_id . '&action=update&token=' . $token . '&view=0'; // need full path...
  4615. }
  4616. $temp = explode(",", $iassign->extension);
  4617. $extension = $temp[0]; // default extension for this iLM
  4618. if ($extension == "html" || $extension == "ivph") { // if iLM is HTML5 is inside a frame
  4619. $str_get_iLM = "window.frames.iLM";
  4620. $str_submitbutton_name = "javascript:window.submit_iLM_Answer()";
  4621. } else { // otherwise it is JAR named 'iLM'
  4622. $str_get_iLM = "document.iLM";
  4623. $str_submitbutton_name = "submit_iLM_Answer()"; // to call 'submit_iLM_Answer()'
  4624. }
  4625. $output = "<script type='text/javascript'>
  4626. //<![CDATA[
  4627. function submit_iLM_Answer () {
  4628. var docFormEditor = document.formEnvio;
  4629. var activityAnswer; // to get activity answer (text)
  4630. var activityValue; // to get activity answer value (float)
  4631. var doc_iLM = " . $str_get_iLM . "; // 'window.frames.iLM' or 'document.iLM'
  4632. //activityAnswer = doc_iLM.getAnswer();
  4633. //activityValue = doc_iLM.getEvaluation();
  4634. activityAnswer = " . $str_get_iLM . ".getAnswer();
  4635. activityValue = " . $str_get_iLM . ".getEvaluation();
  4636. docFormEditor.iLM_PARAM_ActivityEvaluation.value = activityValue;
  4637. docFormEditor.iLM_PARAM_ArchiveContent.value = activityAnswer;
  4638. docFormEditor.submit();
  4639. return true;
  4640. }
  4641. //]]>
  4642. </script>\n";
  4643. // 2016/02/16: NOT necessary, since it is teacher editing (perhaps he only make an example as exercise)
  4644. // if (activityAnswer == -1) { // E.g. in iGeom it is possible to turn an example in exercise
  4645. // alert('" . get_string('error_null_iassign', 'iassign') . "'); // ERRO: O exercício esta vazio ou não foi alterado
  4646. // return true;
  4647. // }
  4648. $output .= "
  4649. <form name='formEnvio' id='formEnvio' method='post' enctype='multipart/form-data'>\n";
  4650. $output .= $OUTPUT->box_start();
  4651. $output .= "
  4652. <table width='100%' cellpadding='20'>
  4653. <tr><td width='75%'>" . get_string('label_file_iassign', 'iassign') . "<b>$filename</b></td>
  4654. <td align='right' width='25%'><input type=button value='" . get_string('label_write_iassign', 'iassign') . "' title='' onclick='submit_iLM_Answer();'/>
  4655. <input type='hidden' name='filename' value='$filename'/></td>
  4656. <td>
  4657. <input type=button value='" . get_string('close', 'iassign') . "' title='' onclick='javascript:window.location = \"$returnurl\";'/></td>
  4658. </tr>
  4659. </table>\n";
  4660. $output .= $OUTPUT->box_end();
  4661. $output .= " <center>\n";
  4662. // Since it is the activity file, it is not necessary to use 'ilm_security' (id_iLM_security)
  4663. $output .= ilm_settings::build_ilm_tags($ilmid, array("type" => "editor_update", "notSEND" => "false", "Proposition" => $end_file));
  4664. $output .= " <input type='hidden' name='iLM_PARAM_ArchiveContent' value=''>
  4665. <input type='hidden' name='iLM_PARAM_ActivityEvaluation' value=''>
  4666. </center>
  4667. </form>\n";
  4668. $title = get_string('title_editor_iassign', 'iassign') . " - " . $iassign->name . " " . $iassign->version; //MOOC2014
  4669. $PAGE->navbar->add($title);
  4670. $PAGE->set_title($title);
  4671. $PAGE->set_heading($title); // insert title above the navigation bar
  4672. print $OUTPUT->header();
  4673. //print $OUTPUT->heading("&nbsp;&nbsp;" . $title); // insert title below the navigation bar
  4674. print $output;
  4675. print $OUTPUT->footer();
  4676. } // else if ($stringArchiveContent != NULL)
  4677. die();
  4678. } // function ilm_editor_update()
  4679. /// Function for write iAssign file in Moodle data (exercise)
  4680. // @calledby ilm_editor_new(): $this->write_file_iassign($stringArchiveContent, $filename);
  4681. // @param string $stringArchiveContent Content of iassign file
  4682. // @param string $filename Filename of iassign file
  4683. function write_file_iassign ($stringArchiveContent, $filename) {
  4684. global $USER;
  4685. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  4686. $context = context_course::instance($this->id);
  4687. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4688. $dirid = $this->get_dir_ilm('dirid');
  4689. $dir = $fs->get_file_by_id($dirid);
  4690. $fileinfo = array('contextid' => $context->id, // ID of course
  4691. 'component' => 'mod_iassign', // usually = table name
  4692. 'filearea' => 'activity', // usually = table name
  4693. 'itemid' => 0, // usually = ID of row in table
  4694. 'filepath' => $dir->get_filepath(), // any path beginning and ending whith '/'
  4695. 'userid' => $USER->id,
  4696. 'author' => $USER->firstname . ' ' . $USER->lastname, 'license' => 'allrightsreserved', // allrightsreserved
  4697. 'filename' => $filename); // any filename
  4698. // Create file containing text. '$stringArchiveContent'
  4699. //TODO Verificar se apenas esta' inserindo nova referencia em 'files' (NAO deve duplicar no Moodle Data)
  4700. $file_course = $fs->create_file_from_string($fileinfo, $stringArchiveContent);
  4701. // sucess_write -> 'Interactive assignment successfully registered under the name: '
  4702. // 'Tarea interactiva registrada exitosamente bajo el nombre:'
  4703. // 'Activité interactive enregistrée avec succès sous le nom:';
  4704. // 'Atividade interativa gravada com sucesso sob o nome:'
  4705. $output = "
  4706. <script type='text/javascript'>
  4707. //<![CDATA[
  4708. alert('" . get_string('sucess_write', 'iassign') . " " . $filename . "');
  4709. window.location='" . $this->url . "&dirid=$dirid&ilmid=$ilmid';
  4710. //]]>
  4711. </script>";
  4712. print $output;
  4713. die();
  4714. }
  4715. /// Function for write iAssign file in Moodle data (exercise)
  4716. // @param string $stringArchiveContent Content of iassign file
  4717. // @param string $filename Filename of iassign file
  4718. // @param int $itemid Itemid of iassign file
  4719. function update_file_iassign ($stringArchiveContent, $filename, $fileid) {
  4720. global $OUTPUT, $USER;
  4721. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  4722. $context = context_course::instance($this->id);
  4723. $dirid = $this->get_dir_ilm('dirid');
  4724. if ($stringArchiveContent != (-1)) {
  4725. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4726. $file = $fs->get_file_by_id($fileid);
  4727. if (!$file) {
  4728. print $OUTPUT->notification(get_string('error_view_ilm', 'iassign'), 'notifyproblem');
  4729. die;
  4730. }
  4731. $fileinfo = array('contextid' => $context->id, // ID of context
  4732. 'component' => 'mod_iassign', // usually = table name
  4733. 'filearea' => 'activity', // usually = table name
  4734. 'itemid' => 0, // usually = ID of row in table
  4735. 'filepath' => $file->get_filepath(), // any path beginning and ending with '/'
  4736. 'userid' => $USER->id,
  4737. 'author' => $USER->firstname . ' ' . $USER->lastname,
  4738. 'license' => 'allrightsreserved', // allrightsreserved
  4739. 'timecreated' => $file->get_timecreated(),
  4740. 'filename' => $file->get_filename()); // any filename
  4741. $file->delete();
  4742. //TODO Verificar se apenas esta' inserindo nova referencia em 'files' (NAO deve duplicar no Moodle Data)
  4743. $file_course = $fs->create_file_from_string($fileinfo, $stringArchiveContent); //$string
  4744. }
  4745. $output = "<script type='text/javascript'>
  4746. //<![CDATA[
  4747. alert('" . get_string('sucess_update', 'iassign') . "');\n
  4748. window.location='" . $this->url . "&dirid=$dirid&ilmid=$ilmid';
  4749. //]]>
  4750. </script>";
  4751. print $output;
  4752. die();
  4753. }
  4754. /// Function for create an tag for iAssign filter
  4755. // @calledby function preview_ilm($iassign_ilm) : $tag_filter = $this->tag_ilm($fileid);
  4756. // @calledby function tinymce_ilm($fileid) : $tag_filter = $this->tag_ilm($fileid);
  4757. // @calledby function editor_ilm($fileid, $editor) : $tag_filter = $this->tag_ilm($fileid);
  4758. // @calledby function atto_ilm ($fileid) : $tag_filter = $this->tag_ilm($fileid);
  4759. // @param int $fileid Id of file
  4760. // @return string Return an string with an tag of iassign filter
  4761. function tag_ilm ($fileid) {
  4762. global $DB;
  4763. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4764. $width = '600';
  4765. $height = '400';
  4766. $file = $fs->get_file_by_id($fileid);
  4767. $filetype = explode(".", $file->get_filename());
  4768. $iassign_ilm = $DB->get_records('iassign_ilm', array("enable" => 1, "parent" => 0));
  4769. foreach ($iassign_ilm as $value) {
  4770. $extensions = explode(",", $value->extension);
  4771. if (in_array($filetype[1], $extensions)) {
  4772. $width = $value->width;
  4773. $height = $value->height;
  4774. }
  4775. }
  4776. return("<p>&lt;ia toolbar=disable width=$width height=$height &gt;$fileid&lt;/ia&gt;</p>");
  4777. }
  4778. /// Function for delete iAssign file in Moodle data (exercise)
  4779. function delete_file_ilm () {
  4780. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  4781. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4782. $fileid = optional_param('fileid', NULL, PARAM_RAW);
  4783. $file = $fs->get_file_by_id($fileid);
  4784. if ($file)
  4785. $file->delete();
  4786. redirect(new moodle_url($this->url . '&dirid=' . $this->get_dir_ilm('dirid') . '&ilmid=' . $ilmid));
  4787. die();
  4788. }
  4789. /// Function for delete selected iAssign file in Moodle data (exercise)
  4790. function delete_selected_ilm () {
  4791. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  4792. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4793. $context = context_course::instance($this->id);
  4794. $files_id = explode(",", optional_param('files_id', '', PARAM_TEXT));
  4795. $dirid = $this->get_dir_ilm('dirid');
  4796. foreach ($files_id as $file_id) {
  4797. $file = $fs->get_file_by_id($file_id);
  4798. if ($file) {
  4799. if (!$file->is_directory())
  4800. $file->delete();
  4801. else {
  4802. $files_delete = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $file->get_filepath(), true, true);
  4803. foreach ($files_delete as $value)
  4804. $value->delete();
  4805. $file->delete();
  4806. }
  4807. }
  4808. }
  4809. redirect(new moodle_url($this->url . '&dirid=' . $dirid . '&ilmid=' . $ilmid));
  4810. die();
  4811. }
  4812. /// Function for duplicate iAssign file from "online" edition
  4813. // @callby JavaScript function 'duplicate_ilm(ilmid, filename, fileid)' bellow
  4814. function duplicate_file_ilm () {
  4815. global $USER, $COURSE;
  4816. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  4817. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4818. $fileid = optional_param('fileid', NULL, PARAM_INT);
  4819. $filename = optional_param('filename', NULL, PARAM_RAW);
  4820. $file = $fs->get_file_by_id($fileid);
  4821. $context = context_course::instance($this->id);
  4822. $fileinfo = array(
  4823. 'contextid' => $context->id, // ID of context
  4824. 'component' => 'mod_iassign', // usually = table name
  4825. 'filearea' => 'activity', // usually = table name
  4826. 'itemid' => 0, // usually = ID of row in table
  4827. 'filepath' => $this->get_dir_ilm('dir_base'), // any path beginning and ending in /
  4828. 'userid' => $USER->id,
  4829. 'author' => $USER->firstname . ' ' . $USER->lastname, 'license' => 'allrightsreserved', // allrightsreserved
  4830. 'timecreated' => $file->get_timecreated(), 'filename' => $filename); // any filename
  4831. $newfile = $fs->create_file_from_string($fileinfo, $file->get_content());
  4832. redirect(new moodle_url($this->url . "&dirid=" . $this->get_dir_ilm('dirid') . "&ilmid=" . $ilmid));
  4833. die();
  4834. }
  4835. /// Function for rename iAssign file
  4836. function rename_file_ilm () {
  4837. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  4838. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4839. $fileid = optional_param('fileid', NULL, PARAM_INT);
  4840. $filename = optional_param('filename', NULL, PARAM_TEXT);
  4841. $file = $fs->get_file_by_id($fileid);
  4842. $file->rename($this->get_dir_ilm('dir_base'), $filename);
  4843. //MOOC2014 redirect(new moodle_url($this->url . "&dirid=" . $dir_parent . "&ilmid=$ilmid"));
  4844. redirect(new moodle_url($this->url . '&dirid=' . $this->get_dir_ilm('dirid') . '&ilmid=' . $ilmid));
  4845. //D echo "locallib.php: rename_file_ilm; ilmid=$ilmid, dirid=" . $this->get_dir_ilm('dirid') . "<br/>\n"; //
  4846. die();
  4847. }
  4848. /// Function for get iassign file for iassign form
  4849. function add_ilm () {
  4850. $fileid = optional_param('fileid', NULL, PARAM_INT);
  4851. $filename = optional_param('filename', NULL, PARAM_TEXT);
  4852. $output = "
  4853. <script type='text/javascript'>
  4854. //<![CDATA[
  4855. var iassign_file_link = window.opener.document.getElementById('iassign_file_link');
  4856. iassign_file_link.innerHTML = '$filename';
  4857. window.opener.document.forms['mform1'].file.value='$fileid';
  4858. window.opener.document.forms['mform1'].filename.value='$filename';
  4859. window.close();
  4860. //]]>
  4861. </script>";
  4862. print $output;
  4863. die();
  4864. }
  4865. /// Function for preview iAssign file from iAssign Repository (it uses iAssign filter)
  4866. // @see /iassign_filter/filter.php : function 'filter($text, array $options = array())' and exit (do not continue bellow)
  4867. // @see ilm_manager.php : $ilm_manager_instance->preview_ilm();
  4868. function preview_ilm ($courseid, $iassign_ilm) {
  4869. global $OUTPUT, $CFG, $USER;
  4870. $fileid = optional_param('fileid', NULL, PARAM_TEXT);
  4871. $title = get_string('modulename', 'iassign'); // iAssign
  4872. print $OUTPUT->header();
  4873. print $OUTPUT->box_start();
  4874. $javascript = "
  4875. <!-- iAssign preview iLM content / LInE - http://line.ime.usp.br -->
  4876. <script type='text/javascript'>
  4877. //<![CDATA[
  4878. function submit_close () {
  4879. window.opener.location.reload();
  4880. window.close();
  4881. }
  4882. //]]>
  4883. </script>\n";
  4884. // Use iAssin filter to change "&lt;ia toolbar=disable width=800 height=600 &gt;45&lt;/ia&gt;"
  4885. // to the complete "applet" tag
  4886. // Version previous to: 2016/02/16: do not present menus' options - similar to the filter
  4887. //TODO: E' melhor apresentar o iMA completo, sem usar o filtro com opcao "<param name='SOH_ADD' value='ADD'>"
  4888. //TODO: Talvez seja melhor colocar opcao no filtro para evitar opcao 'ADD'!
  4889. //TODO: Here reaches '/iassign_filter/filter.php : function 'filter($text, array $options = array())' with parameter 'originalformat=0' (in glossary is 1)
  4890. //TODO: then, I changed '/iassign_filter/filter.php' (functions 'filter(...) to avoid 'SOH_ADD' if 'originalformat=0'
  4891. $ilm_name = substr(strtolower($iassign_ilm->name), 0, 6);
  4892. if ($ilm_name != "ivprog") {
  4893. //MOOC2014 $tag_filter = format_text($this->tag_ilm($fileid));
  4894. $tag_filter = $this->tag_ilm($fileid); // build the iAssign filter tag, something like: <ia toolbar=disable width=800 height=600 >58</ia>
  4895. $tag_filter_filtered = format_text($tag_filter, FORMAT_MOODLE, array('overflowdiv' => true, 'allowid' => true)); // Moodle 3.X
  4896. } else {
  4897. require_once($CFG->dirroot . '/mod/iassign/ilm_security.php');
  4898. $content_or_id_from_ilm_security = $this->get_file_ilm();
  4899. $timecreated = time();
  4900. $token = md5($timecreated);
  4901. $id_iLM_security = ilm_security::write_iLM_security($USER->id, $timecreated, -1, $content_or_id_from_ilm_security); // insert in 'iassign_security'
  4902. $param = 'id=' . $id_iLM_security . '&ilmid=' . $iassign_ilm->id . '&token=' . $token . '&view=0';
  4903. $url_file = $CFG->wwwroot . '/mod/iassign/ilm_security.php?action=preview&' . $param;
  4904. $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)
  4905. }
  4906. $html = "
  4907. <form name='formEnvio' id='formEnvio' method='post' enctype='multipart/form-data'>
  4908. <table border='1'>
  4909. <tr><td>
  4910. <!-- iLM calls : begin -->\n" . $tag_filter_filtered . "\n
  4911. <!-- iLM calls : end -->
  4912. </td></tr>
  4913. </table>
  4914. <table>
  4915. <tr>
  4916. <td align='center'>
  4917. <input type=button value='" . get_string('close', 'iassign') . "' title='' onclick='submit_close();' />
  4918. </td></tr>
  4919. </table>
  4920. </form>\n";
  4921. print $javascript . $html;
  4922. print $OUTPUT->box_end();
  4923. //NAO echo format_string($html); // Moodle 3.X
  4924. die();
  4925. } // function preview_ilm($courseid, $iassign_ilm)
  4926. //r_ function preview_ilm ($iassign_ilm)
  4927. //r_ /// Function for preview iassign file from iassign filter.
  4928. //r_ function preview_ilm() {
  4929. //r_ $fileid = optional_param('fileid', NULL, PARAM_TEXT);
  4930. //r_ $tag_filter = $this->tag_ilm($fileid);
  4931. //r_ $javascript = "<script type='text/javascript'>
  4932. //r_ //<![CDATA[
  4933. //r_ function submit_close() { window.opener.location.reload(); window.close(); }
  4934. //r_ //]]>
  4935. //r_ </script>";
  4936. //r_ $html = "<html><head></head><body><form name='formEnvio' id='formEnvio' method='post' enctype='multipart/form-data'>
  4937. //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>
  4938. //r_ </table></form></body></html>";
  4939. //r_ echo $javascript . format_text($html);
  4940. //r_ die;
  4941. //r_ }
  4942. /// Function for export an package (zip) of iassign files
  4943. function export_files_ilm () {
  4944. global $CFG;
  4945. $context = context_course::instance($this->id);
  4946. $files_id = explode(",", optional_param('files_id', '', PARAM_TEXT));
  4947. $zip_filename = $CFG->dataroot . '/temp/backup-iassign-files-' . date("Ymd-Hi") . '.zip';
  4948. $zip = new zip_archive();
  4949. $zip->open($zip_filename);
  4950. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4951. foreach ($files_id as $file_id) {
  4952. $file = $fs->get_file_by_id($file_id);
  4953. if (!$file->is_directory())
  4954. $zip->add_file_from_string($file->get_filename(), $file->get_content());
  4955. else {
  4956. $zip->add_directory($file->get_filepath());
  4957. $files_zip = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $file->get_filepath(), true, true);
  4958. foreach ($files_zip as $value) {
  4959. if (!$value->is_directory())
  4960. $zip->add_file_from_string($value->get_filepath() . $value->get_filename(), $value->get_content());
  4961. else
  4962. $zip->add_directory($value->get_filepath());
  4963. }
  4964. }
  4965. }
  4966. $zip->close();
  4967. header("Pragma: public");
  4968. header("Expires: 0");
  4969. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  4970. header("Cache-Control: private", false);
  4971. header("Content-Type: application/zip");
  4972. header("Content-Disposition: attachment; filename=\"" . basename($zip_filename) . "\";");
  4973. header("Content-Transfer-Encoding: binary");
  4974. header("Content-Length: " . @filesize($zip_filename));
  4975. set_time_limit(0);
  4976. @readfile("$zip_filename") || die("File not found.");
  4977. unlink($zip_filename);
  4978. exit;
  4979. }
  4980. /// Function of execute a command in button editor tinymce
  4981. // @param int $fileid Id of file
  4982. function tinymce_ilm ($fileid) {
  4983. $tag_filter = $this->tag_ilm($fileid);
  4984. $output = "<script type='text/javascript'>
  4985. //<![CDATA[
  4986. var tag_filter = '$tag_filter';
  4987. if (window.opener.tinyMCE.execCommand('mceiAssignReturn', tag_filter)) {
  4988. // all right, insert it
  4989. } else {
  4990. alert('Error trying to insert iLM content (tinymce_ilm " + $fileid + ")');
  4991. }
  4992. // window.close();
  4993. //]]>
  4994. </script>\n";
  4995. print $output;
  4996. die();
  4997. }
  4998. //TODO sugestao para uso de apenas uma funcao para chamar os editores, cortando 17 linhas de codigo
  4999. /// Function to add content to the Editor Window
  5000. // Updated: Marcio Passos - marciopassosbel[at]gmail[dot]com :: 07 / Jul / 2016
  5001. // @param int $fileid Id of file
  5002. function editor_ilm ($fileid, $editor) {
  5003. $tag_filter = $this->tag_ilm($fileid); // Prepare tag like: <ia toolbar=disable width=800 height=600>ID</ia>
  5004. $output1 = "<script type='text/javascript'>
  5005. //<![CDATA[
  5006. var tag_filter = '$tag_filter';\n";
  5007. if ($editor == 'atto') {
  5008. $output2 = " if (window.opener.document.execCommand('insertHTML', false, tag_filter)) { } // all right, insert it";
  5009. } elseif ($editor == 'tinyMCE') {
  5010. $output2 = " if (window.opener.tinyMCE.execCommand('mceiAssignReturn', tag_filter)) { } // all right, insert it";
  5011. } else
  5012. $output2 = "";
  5013. $output3 = " else { console.log('Error trying to insert iLM content (atto_ilm " . $fileid . ")'); }
  5014. window.close();
  5015. //]]>
  5016. </script>\n";
  5017. //D var_dump($output);
  5018. print $output1 . $output2 . $output3;
  5019. die();
  5020. }
  5021. /// Function to add content to the Atto Editor Window
  5022. // Updated: Marcio Passos - marciopassosbel[at]gmail[dot]com :: 07 / Jul / 2016
  5023. // @param int $fileid Id of file
  5024. function atto_ilm ($fileid) {
  5025. global $CFG, $DB;
  5026. $tag_filter = $this->tag_ilm($fileid);
  5027. $output = "<script type='text/javascript'>
  5028. //<![CDATA[
  5029. var tag_filter = '$tag_filter';
  5030. if (window.opener.document.execCommand('insertHTML', false, tag_filter)) {
  5031. // all right, insert iLM tag to this editor
  5032. } else {
  5033. // error trying to insert
  5034. alert('Error trying to insert iLM content (atto_ilm " + $fileid + ")');
  5035. }
  5036. //window.close();
  5037. //]]>
  5038. </script>\n";
  5039. print $output;
  5040. die();
  5041. }
  5042. /// Function for get path and info of directories: dirid, dir_base, dir_parent, dir_home
  5043. // @param string $key Key for return information
  5044. // @return Ambigous <unknown, number, string, NULL> Return an information requested
  5045. function get_dir_ilm ($key) {
  5046. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5047. $context = context_course::instance($this->id);
  5048. $dirid = optional_param('dirid', 0, PARAM_INT);
  5049. $dir_home = $fs->get_file($context->id, 'mod_iassign', 'activity', 0, $dir_base = '/', '.');
  5050. if ($dirid == 0) {
  5051. $dir = ($dir_home = $fs->create_directory($context->id, 'mod_iassign', 'activity', 0, $dir_base));
  5052. $dirid = $dir->get_id();
  5053. }
  5054. else {
  5055. $dir = $fs->get_file_by_id($dirid);
  5056. if (!isset($dir) || !is_dir($dir)) {
  5057. // print "Error: $key - $dirid => dir=''<br/>";
  5058. //exit;
  5059. return;
  5060. }
  5061. $dir_base = $dir->get_filepath();
  5062. }
  5063. $dir_parent = $dir->get_parent_directory();
  5064. $data = array('dirid' => $dirid, 'dir_base' => $dir_base, 'dir_parent' => ($dir_parent == NULL ? 0 : $dir_parent->get_id()), 'dir_home' => $dir_home->get_id());
  5065. return $data[$key];
  5066. }
  5067. /// Function for create an new dir
  5068. function new_dir_ilm () {
  5069. global $USER;
  5070. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5071. $dirname = optional_param('dirname', NULL, PARAM_TEXT);
  5072. $dir_base = $this->get_dir_ilm('dir_base');
  5073. $context = context_course::instance($this->id);
  5074. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5075. $fs->create_directory($context->id, 'mod_iassign', 'activity', 0, $dir_base . $dirname . "/", $USER->id);
  5076. $dir_base = $fs->get_file($context->id, 'mod_iassign', 'activity', 0, $dir_base . $dirname . "/", '.');
  5077. $dir_base->set_author($USER->firstname . ' ' . $USER->lastname);
  5078. redirect(new moodle_url($this->url . '&dirid=' . $this->get_dir_ilm('dirid') . '&ilmid=' . $ilmid));
  5079. }
  5080. /// Function for delete an dir
  5081. function delete_dir_ilm () { //
  5082. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5083. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5084. $context = context_course::instance($this->id);
  5085. $dir = $fs->get_file_by_id($this->get_dir_ilm('dirid'));
  5086. $dir_parent = $this->get_dir_ilm('dir_parent');
  5087. if ($dir) {
  5088. if ($dir->is_directory()) {
  5089. $files_delete = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $dir->get_filepath(), true, true);
  5090. foreach ($files_delete as $value)
  5091. $value->delete();
  5092. $dir->delete();
  5093. }
  5094. }
  5095. redirect(new moodle_url($this->url . '&dirid=' . $dir_parent . '&ilmid=' . $ilmid));
  5096. die();
  5097. }
  5098. /// Function for rename an dir
  5099. function rename_dir_ilm () {
  5100. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5101. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5102. $context = context_course::instance($this->id);
  5103. $dir = $fs->get_file_by_id($this->get_dir_ilm('dirid'));
  5104. $dir_parent = $this->get_dir_ilm('dir_parent');
  5105. $dirname = optional_param('dirname', NULL, PARAM_TEXT);
  5106. $pathname = explode("/", substr($dir->get_filepath(), 0, strlen($dir->get_filepath()) - 1));
  5107. if ($dir->is_directory()) {
  5108. $files_rename_path = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $dir->get_filepath(), true, true);
  5109. foreach ($files_rename_path as $value)
  5110. $value->rename(str_replace($pathname[count($pathname) - 1], $dirname, $value->get_filepath()), $value->get_filename());
  5111. $dir->rename(str_replace($pathname[count($pathname) - 1], $dirname, $dir->get_filepath()), $dir->get_filename());
  5112. }
  5113. redirect(new moodle_url($this->url . '&dirid=' . $dir_parent . '&ilmid=' . $ilmid));
  5114. die();
  5115. }
  5116. /// Function for move an dir and your content for other dir
  5117. function selected_move_ilm () {
  5118. global $PAGE, $OUTPUT, $CFG;
  5119. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5120. $context = context_course::instance($this->id);
  5121. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5122. $dirid = $this->get_dir_ilm('dirid');
  5123. $dir_base = $this->get_dir_ilm('dir_base');
  5124. $files_id = explode(",", optional_param('files_id', '', PARAM_TEXT));
  5125. $code_javascript_ilm = "
  5126. <script type='text/javascript'>
  5127. //<![CDATA[
  5128. function getRadiobutton () {
  5129. var radioButtons = document.getElementsByTagName('input');
  5130. var param = '';
  5131. for (var counter=0; counter < radioButtons.length; counter++) {
  5132. if (radioButtons[counter].type.toUpperCase()=='RADIO' && radioButtons[counter].checked == true && radioButtons[counter].name == 'selected_dir')
  5133. param = radioButtons[counter].value;
  5134. }
  5135. return param;
  5136. }
  5137. function move_selected_ilm () {
  5138. var msgAnswer;
  5139. if (getRadiobutton() != '') {
  5140. msgAnswer = confirm('" . get_string('question_move_dir', 'iassign') . "');
  5141. if (msgAnswer)
  5142. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=move&ilmid=" . $ilmid . "&dirid=" . $dirid . "&files_id=" .
  5143. optional_param('files_id', '', PARAM_TEXT) . "&dir_move='+getRadiobutton();
  5144. }
  5145. else
  5146. alert('" . get_string('error_dir_not_selected_to_move', 'iassign') . "');
  5147. }
  5148. function cancel_selected_ilm () {
  5149. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&ilmid=" . $ilmid . "&dirid=" . $dirid . "';
  5150. }
  5151. //]]>
  5152. </script>\n";
  5153. $title = get_string('move_files', 'iassign');
  5154. $PAGE->set_title($title);
  5155. $PAGE->set_pagelayout('base');
  5156. print $OUTPUT->header();
  5157. print $OUTPUT->heading($title);
  5158. $dir_paths = array();
  5159. print $OUTPUT->box_start();
  5160. print "<center>";
  5161. foreach ($files_id as $file_id) {
  5162. $file = $fs->get_file_by_id($file_id);
  5163. if ($file) {
  5164. if (!$file->is_directory())
  5165. print "<p>" . iassign_icons::insert('file') . "&nbsp;" . $file->get_filepath() . $file->get_filename() . "</p>";
  5166. else {
  5167. print "<p>" . iassign_icons::insert('dir') . "&nbsp;" . $file->get_filepath() . "</p>";
  5168. array_push($dir_paths, $file->get_filepath());
  5169. }
  5170. }
  5171. }
  5172. print $OUTPUT->heading(get_string('select_move_ilm', 'iassign'), 3, 'move', 'move_files');
  5173. if ($dir_base != '/') {
  5174. $check_select = "<input name='selected_dir' type='radio' value='" . $this->get_dir_ilm('dir_home') . "'/>";
  5175. print $check_select . "&nbsp;" . iassign_icons::insert('dir') . "&nbsp;/<br>";
  5176. }
  5177. $files_tree = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, '/', true, true, 'filepath');
  5178. foreach ($files_tree as $file) {
  5179. if ($file->is_directory() && $file->get_filepath() != $dir_base) {
  5180. $is_parent = false;
  5181. foreach ($dir_paths as $dir) {
  5182. $path = explode("/", $dir);
  5183. array_pop($path);
  5184. $path[count($path) - 1] = '';
  5185. $path = implode("/", $path);
  5186. $is_parent |= (strpos($file->get_filepath(), $dir) === false ? false : true);
  5187. $is_parent |= ($file->get_filepath() != $path ? false : true);
  5188. }
  5189. if ($is_parent == false) {
  5190. $check_select = "<input name='selected_dir' type='radio' value='" . $file->get_id() . "'/>";
  5191. print "<p>" . $check_select . "&nbsp;" . iassign_icons::insert('dir') . "&nbsp;" . $file->get_filepath() . "</p>";
  5192. }
  5193. }
  5194. }
  5195. print "<p><input type='button' value='" . get_string('ok') . "' onclick='move_selected_ilm();'/>&nbsp;&nbsp;&nbsp;&nbsp;";
  5196. print "<input type='button' value='" . get_string('cancel') . "' onclick='cancel_selected_ilm();'/></p>";
  5197. print "</center>";
  5198. print $OUTPUT->box_end();
  5199. print $OUTPUT->footer();
  5200. print $code_javascript_ilm;
  5201. die;
  5202. }
  5203. /// Function for move files for an dir
  5204. function move_files_ilm () {
  5205. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5206. $context = context_course::instance($this->id);
  5207. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5208. $dirid = $this->get_dir_ilm('dirid');
  5209. $dir_move = $fs->get_file_by_id(optional_param('dir_move', 0, PARAM_INT));
  5210. $files_id = explode(",", optional_param('files_id', '', PARAM_TEXT));
  5211. foreach ($files_id as $file_id) {
  5212. $file = $fs->get_file_by_id($file_id);
  5213. if ($file) {
  5214. if ($file->is_directory()) {
  5215. $pathname = explode("/", $file->get_filepath());
  5216. $files_move_path = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $file->get_filepath(), true, true);
  5217. foreach ($files_move_path as $value) {
  5218. $path_move = $dir_move->get_filepath() . $pathname[count($pathname) - 2] . '/' . str_replace($file->get_filepath(), '', $value->get_filepath());
  5219. $value->rename($path_move, $value->get_filename());
  5220. //echo($value->get_filepath().$value->get_filename()." - $path_move".$value->get_filename()."<br>");
  5221. }
  5222. $path_move = $dir_move->get_filepath() . $pathname[count($pathname) - 2] . '/';
  5223. //echo($file->get_filepath().$file->get_filename()." - $path_move".$file->get_filename()."<br>");
  5224. $file->rename($path_move, $file->get_filename());
  5225. } else {
  5226. //echo($file->get_filepath().$file->get_filename()." -> ".$dir_move->get_filepath().$file->get_filename()."<br>");
  5227. $file->rename($dir_move->get_filepath(), $file->get_filename());
  5228. }
  5229. }
  5230. }
  5231. //die;
  5232. redirect(new moodle_url($this->url . '&ilmid=' . $ilmid . '&dirid=' . $dirid));
  5233. die();
  5234. } // function move_files_ilm()
  5235. /// Function for recover files in use on all activities of a course
  5236. function recover_files_ilm () {
  5237. global $DB, $USER;
  5238. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5239. $courseid = optional_param('id', NULL, PARAM_INT);
  5240. $dirid = $this->get_dir_ilm('dirid');
  5241. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5242. $contextfile = context_course::instance($this->id);
  5243. $iassigns = $DB->get_records("iassign", array("course" => $courseid));
  5244. foreach ($iassigns as $iassign) {
  5245. $iassign_statement_activity_list = $DB->get_records("iassign_statement", array("iassignid" => $iassign->id));
  5246. foreach ($iassign_statement_activity_list as $iassign_statement_activity_item) {
  5247. $cm = get_coursemodule_from_instance("iassign", $iassign->id, $courseid);
  5248. $context = context_module::instance($cm->id);
  5249. $files = $fs->get_area_files($context->id, 'mod_iassign', 'exercise', $iassign_statement_activity_item->file);
  5250. if ($files) {
  5251. foreach ($files as $value) {
  5252. $extension = explode(".", $value->get_filename());
  5253. if (!$value->is_directory()) {
  5254. $fileinfo = array('contextid' => $contextfile->id,
  5255. 'component' => 'mod_iassign',
  5256. 'filearea' => 'activity',
  5257. 'itemid' => 0,
  5258. 'filepath' => $this->get_dir_ilm('dir_base'),
  5259. 'userid' => $USER->id,
  5260. 'author' => $USER->firstname . ' ' . $USER->lastname,
  5261. 'license' => 'allrightsreserved',
  5262. 'timecreated' => time(),
  5263. 'filename' => $iassign_statement_activity_item->name . "." . $extension[1]); // any filename
  5264. $newfile = $fs->create_file_from_string($fileinfo, $value->get_content());
  5265. }
  5266. }
  5267. } // if ($files)
  5268. } // foreach ($iassign_statement_activity_list as $iassign_statement_activity_item)
  5269. } // foreach ($iassigns as $iassign)
  5270. redirect(new moodle_url($this->url . '&dirid=' . $dirid . '&ilmid=' . $ilmid));
  5271. die();
  5272. } // function recover_files_ilm()
  5273. /// Auxiliary function the get all files in a given context
  5274. // @calledby view_files_ilm($iassign_ilm_class, $extension, $start = 0)
  5275. // @return [array_contextid_files_thisauthor[], array_contextid_files_otherauthors[], array_contextid_files_otherauthors_userid[]]
  5276. //TODO Falta separar os arquivos listados, apresentar primeiro aqueles do autor e depois os demais.
  5277. //TODO Nao devemos listar aqueles que estao sem permissao (license == 'allrightsreserved')
  5278. function get_files_in_context (&$filesfrommine, &$filesfromothers, $contextid, $extension, $userid) {
  5279. // s_iassign_statement: id name iassignid type_iassign proposition author_name author_modified_name iassign_ilmid
  5280. // (NAO s_iassign_statement.file = s_files.id)
  5281. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5282. $dir_base = $this->get_dir_ilm('dir_base');
  5283. $files_course = $fs->get_directory_files($contextid, 'mod_iassign', 'activity', 0, $dir_base, false, true, 'filename');
  5284. $countf = 0;
  5285. $array_files_id = array(); // all files from this context
  5286. foreach ($files_course as $item_fc) { // license = not "allrightsreserved" AND is not from this author => present it
  5287. //$filename = $item_fc->get_filename();
  5288. //$filepath = $item_fc->get_filepath();
  5289. //$fileid = $item_fc->get_id(); // get file ID (in *_iassign_statement table)
  5290. $fileuserid = $item_fc->get_userid(); // get user.id of the author
  5291. // $array_files_aux[] = $item_fc;
  5292. $itemid = $item_fc->get_id();
  5293. if (!in_array($itemid, $array_files_id)) {
  5294. //TODO Avoid to insert twice - necessary since it has been inserting 2 copies in iassign_statement
  5295. if ($fileuserid == $userid)
  5296. $filesfrommine[] = $item_fc;
  5297. else
  5298. $filesfromothers[] = $item_fc;
  5299. $array_files_id[] = $itemid;
  5300. $countf++;
  5301. }
  5302. }
  5303. //D echo "get_files_in_context: dir_base=$dir_base, contextid=$contextid, #array_files_id=".count($array_files_id) . " = $countf<br/>";
  5304. return $countf;
  5305. } // function get_files_in_context(&$filesfrommine, &$filesfromothers, $contextid, $extension, $userid)
  5306. // Function to get all iLM files from the same "file type": (usually) files under the same directory
  5307. // @calledby view_files_ilm($iassign_ilm_class, $extension, $start = 0)
  5308. function get_all_ilm_files_by_fileid ($fileid) {
  5309. global $DB, $USER;
  5310. // $iassign_statement_activity_list = $DB->get_records("iassign_statement", array("file" => $fileid));
  5311. //TODO Criar coluna 'authorid'
  5312. $str_query = "SELECT * FROM {iassign_statement} " .
  5313. " WHERE file = " . $fileid . " ORDER BY author_name, timecreated DESC";
  5314. $array_iassign_ilm = $DB->get_records_sql($str_query);
  5315. return $array_iassign_ilm;
  5316. }
  5317. //NN
  5318. // Build string with JavaScript code with function to edit/remove/double iLM files
  5319. // @calledby view_files_ilm($iassign_ilm_class, $extension, $start = 0)
  5320. function get_string_JavaScript_functions ($dirid, $ilmid, $files_array, $dirs_array) {
  5321. global $CFG;
  5322. $error_files_exists = get_string('error_file_exists', 'iassign');
  5323. $error_dir_exists = get_string('error_dir_exists', 'iassign');
  5324. $code_javascript_ilm = "
  5325. <script type='text/javascript'>
  5326. //<![CDATA[
  5327. function preview_ilm (fileid, ilmid) { //JavaScript function
  5328. var param = '" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=preview&fileid='+fileid+'&ilmid='+ilmid;
  5329. var preview_ilm=window.open(param,'','menubar=0,location=0,scrollbars,status,resizable,width=900 height=700');
  5330. }
  5331. function update_ilm (ilmid, fileid) { //JavaScript function
  5332. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=update&ilmid='+ilmid+'&dirid=" . $dirid . "&fileid='+fileid;
  5333. }
  5334. function delete_ilm (ilmid, fileid) { //JavaScript function
  5335. var msgAnswer;
  5336. msgAnswer = confirm('" . get_string('delete_file', 'iassign') . "');
  5337. if (msgAnswer) {
  5338. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=delete&ilmid='+ilmid+'&dirid=" . $dirid . "&fileid='+fileid;
  5339. }
  5340. }
  5341. function delete_selected_ilm () { //JavaScript function
  5342. var msgAnswer;
  5343. var param = getCheckbox();
  5344. if (param.join() != '') {
  5345. msgAnswer = confirm('" . get_string('delete_files', 'iassign') . "');
  5346. if (msgAnswer)
  5347. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=selected_delete&dirid=" . $dirid . "&files_id='+param.join();
  5348. }
  5349. else
  5350. alert('" . get_string('er_file_not_selected_to_delete', 'iassign') . "');
  5351. }
  5352. function add_ilm_iassign (ilmid, filename, fileid) { //JavaScript function
  5353. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=addilm&ilmid='+ilmid+'&fileid='+fileid+'&filename='+filename;
  5354. }
  5355. function duplicate_ilm (ilmid, filename, fileid) { //JavaScript function
  5356. var filenamecopy;
  5357. var i;
  5358. var files = new Array(" . $files_array . ");
  5359. do {
  5360. filenamecopy = prompt ('" . get_string('duplicate_file', 'iassign') . "',filename);
  5361. } while (filenamecopy == '');
  5362. if (filenamecopy == null)
  5363. return false;\n
  5364. else {
  5365. for (i=0;i<files.length;i++) {
  5366. if (files[i]==filenamecopy) {
  5367. alert('" . $error_files_exists . "');
  5368. return false;\n
  5369. }
  5370. }\n" .
  5371. // @see: function 'duplicate_file_ilm()' above
  5372. "
  5373. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?" .
  5374. "from=" . $this->from . "&id=" . $this->id . "&action=duplicate&ilmid=' + ilmid + '&dirid=" . $dirid . "&fileid=' + fileid + '&filename=' + filenamecopy;
  5375. } // else
  5376. }
  5377. function rename_ilm (ilmid, filename, fileid) { //JavaScript function
  5378. var filenamecopy;
  5379. var i;
  5380. var files = new Array($files_array);
  5381. do {
  5382. filenamecopy = prompt('" . get_string('rename_file', 'iassign') . "',filename);
  5383. } while (filenamecopy == '');
  5384. if (filenamecopy == null)
  5385. return false;
  5386. else {
  5387. for (i=0;i<files.length;i++) {
  5388. if (files[i]==filenamecopy) {
  5389. alert('" . $error_files_exists . "');
  5390. return false;
  5391. }
  5392. }
  5393. 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;
  5394. }
  5395. }
  5396. function export_files_ilm () { //JavaScript function
  5397. var param = getCheckbox();
  5398. if (param.join() != '')
  5399. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=export&dirid=" . $dirid . "&files_id='+param.join();
  5400. else
  5401. alert('" . get_string('er_file_not_selected_to_export', 'iassign') . "');
  5402. }
  5403. function select_all_ilm () { //JavaScript function
  5404. var checkBoxes = document.getElementsByTagName('input');
  5405. var selectAll = document.getElementById('select_all');
  5406. for (var counter=0; counter < checkBoxes.length; counter++) {
  5407. if (checkBoxes[counter].type.toUpperCase()=='CHECKBOX' && checkBoxes[counter].name == 'selected_file')
  5408. checkBoxes[counter].checked = selectAll.checked;
  5409. }
  5410. }
  5411. function getCheckbox () { //JavaScript function
  5412. var checkBoxes = document.getElementsByTagName('input');
  5413. var param = new Array();
  5414. for (var counter=0; counter < checkBoxes.length; counter++) {
  5415. if (checkBoxes[counter].type.toUpperCase()=='CHECKBOX' && checkBoxes[counter].checked == true && checkBoxes[counter].name == 'selected_file')
  5416. param.push(checkBoxes[counter].value);
  5417. }
  5418. return param;
  5419. }
  5420. function new_dir_ilm () { //JavaScript function
  5421. var dirname = '';
  5422. var i;
  5423. var dirs = new Array(" . $dirs_array . ");
  5424. do {
  5425. var dirname = prompt ('" . get_string('question_new_dir', 'iassign') . "', '');
  5426. } while (dirname == '');
  5427. if (dirname == null)
  5428. return false;\n
  5429. else {
  5430. for (i=0;i<dirs.length;i++) {
  5431. if (dirs[i]==dirname) {
  5432. alert('" . $error_dir_exists . "');
  5433. return false;\n
  5434. }
  5435. }
  5436. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=new_dir&ilmid=" . $ilmid . "&dirid=" . $dirid . "&dirname='+dirname;
  5437. }
  5438. }
  5439. function delete_dir_ilm (ilmid, dirid) { //JavaScript function
  5440. var msgAnswer;
  5441. msgAnswer = confirm('" . get_string('question_delete_dir', 'iassign') . "');
  5442. if (msgAnswer) {
  5443. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=delete_dir&ilmid='+ilmid+'&dirid='+dirid;
  5444. }
  5445. }
  5446. function rename_dir_ilm (ilmid, dirname, dirid) { //JavaScript function
  5447. var dirnamecopy;
  5448. var i;
  5449. var dirs = new Array($dirs_array);
  5450. do {
  5451. dirnamecopy = prompt ('" . get_string('question_rename_dir', 'iassign') . "',dirname);
  5452. } while (dirnamecopy == '');
  5453. if (dirnamecopy == null)
  5454. return false;\n
  5455. else {
  5456. for (i=0;i<dirs.length;i++) {
  5457. if (dirs[i]==dirnamecopy) {
  5458. alert('" . $error_dir_exists . "');
  5459. return false;\n
  5460. }
  5461. }
  5462. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=rename_dir&ilmid='+ilmid+'&dirid='+dirid+'&dirname='+dirnamecopy;
  5463. }
  5464. }
  5465. function move_selected_ilm (ilmid) { //JavaScript function
  5466. var param = getCheckbox();
  5467. if (param.join() != '')
  5468. 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();
  5469. else
  5470. alert('" . get_string('er_file_not_selected_to_move', 'iassign') . "');
  5471. }
  5472. function recover_files_ilm () { //JavaScript function
  5473. var msgAnswer;
  5474. msgAnswer = confirm('" . get_string('question_recover_files', 'iassign') . "');
  5475. if (msgAnswer) {
  5476. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=recover&ilmid=" . $ilmid . "&dirid=" . $dirid . "';
  5477. }
  5478. }
  5479. window.onload = function() { //JavaScript function
  5480. var xPosition = 0;
  5481. var yPosition = 0;
  5482. element=document.getElementById('new_file');
  5483. while(element) {
  5484. xPosition += (element.offsetLeft - element.scrollLeft + element.clientLeft);
  5485. yPosition += (element.offsetTop - element.scrollTop + element.clientTop);
  5486. element = element.offsetParent;
  5487. }
  5488. document.getElementById('new_file').style.top = '' + (yPosition - 400) + 'px';
  5489. document.getElementById('new_file').style.right = '' + 0 + 'px';
  5490. location.hash = '#new_file';
  5491. };
  5492. //]]>
  5493. </script>\n"; // end of $code_javascript_ilm
  5494. return $code_javascript_ilm;
  5495. } // function get_string_JavaScript_functions($dirid, $ilmid, $files_array, $dirs_array)
  5496. /// List iassign files from course directory
  5497. // @calledby ilm_manager.php : $ilm_manager_instance->view_files_ilm($iassign_ilm->extension);
  5498. function view_files_ilm ($iassign_ilm_class, $extension, $start = 0) {
  5499. //TODO usar $start para trazer no maximo 50 arquivos iniciando em $start
  5500. global $CFG, $DB, $USER, $OUTPUT;
  5501. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5502. $context = context_course::instance($this->id); // $this->id = ID of the current course
  5503. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5504. $dirid = $this->get_dir_ilm('dirid');
  5505. $dir_base = $this->get_dir_ilm('dir_base');
  5506. // Get all files in module iAssign
  5507. // -- start
  5508. $array_contextid_files = array(); // context.id in data decreasing order
  5509. $array_contextid_files_aux = array(); // all context.id in data creasing order
  5510. // Get all files from table '*_files': id ; contenthash ; pathnamehash ; contextid ; component ;... filename ; userid ...
  5511. // $DB is 'mysqli_native_moodle_database' object
  5512. // if (has_capability("moodle/site:config", $context, $USER->id, true))
  5513. // if (has_capability("mod/iassign:addinstance", $context, $USER->id, true))
  5514. $hascapability = has_capability("moodle/site:config", $context, $USER->id); // *_capabilities="moodle/site:config" : greatest one)
  5515. if ($hascapability==1) {
  5516. //$array_query = array('component' => 'mod_iassign');
  5517. $query_sql = "SELECT * FROM {files} WHERE component='mod_iassign' AND filearea='activity'";
  5518. }
  5519. else {
  5520. // $array_query = array('component' => 'mod_iassign', 'userid' => $USER->id);
  5521. $query_sql = "SELECT * FROM {files} WHERE component='mod_iassign' AND filearea='activity' AND " .
  5522. " (license<>'allrightsreserved' OR contextid=" . $context->id . " OR userid=" . $USER->id . ")";
  5523. }
  5524. // files : id contenthash pathnamehash contextid component filearea itemid filepath filename userid filesize mimetype status source author license timecreated timemodified sortorder referencefileid
  5525. // $files_iassign = $DB->get_records('files', $array_query); // extensions for all iLM...
  5526. $files_iassign = $DB->get_records_sql($query_sql);
  5527. //D echo "view_files_ilm: " . $USER->id . ", " . $hascapability . ": " . $query_sql . "<br/>";
  5528. //D SELECT id,contextid,component,filearea,itemid,filepath,filename,userid FROM s_files WHERE component='mod_iassign' AND filearea='exercise';
  5529. $count_all_files_others = 0;
  5530. $count_all_files_my = 0;
  5531. $count_files_with_ext = 0;
  5532. $count_thisauthor_contextid = 0;
  5533. $count_otherauthors_contextid = 0;
  5534. //D echo "view_files_ilm: user.id=" . $USER->id . ", ext=$extension, #files=" . count($files_iassign) . "<br/>";
  5535. //$files_from_others + $files_from_mine
  5536. $files_from_mine = array(); // all files from all context.id (in data decreasing order) from this user
  5537. $files_from_others = array(); // all files from all context.id (in data decreasing order) from others then this user
  5538. if (is_array($files_iassign)) {
  5539. if ($hascapability == 1) { // is Admin => get all files from this extension $extension
  5540. foreach ($files_iassign as $item_files_iassign) {
  5541. $extensionF = explode(".", $item_files_iassign->filename); // $item_files_iassign->get_filename()
  5542. $lastitem = sizeof($extensionF);
  5543. if ($lastitem>0) $lastitem--;
  5544. else {
  5545. // print "x";// error: it must have extension (after ".")
  5546. continue;
  5547. }
  5548. $str_extension = $extensionF[$lastitem];
  5549. $count_files_with_ext++;
  5550. if ($extension == $str_extension) {
  5551. $contextid = $item_files_iassign->contextid;
  5552. if (!in_array($contextid, $array_contextid_files_aux)) { // not yet in array of context with this extension
  5553. $array_contextid_files_aux[] = $contextid;
  5554. // Parameters '$files_from_mine' and '$files_from_others' are by reference (will be altered by 'get_files_in_context(...)'
  5555. $total_in_context = $this->get_files_in_context($files_from_mine, $files_from_others, $contextid, $extension, $USER->id);
  5556. $count_all_files_others += $total_in_context;
  5557. }
  5558. }
  5559. }
  5560. }
  5561. else { // not admin, get only on this context
  5562. $contextid = $context->id;
  5563. $array_contextid_files_aux[] = $contextid;
  5564. // Parameters '$files_from_mine' and '$files_from_others' are by reference (will be altered by 'get_files_in_context(...)'
  5565. $total_in_context = $this->get_files_in_context($files_from_mine, $files_from_others, $contextid, $extension, $USER->id);
  5566. $count_all_files_others = $total_in_context;
  5567. }
  5568. }
  5569. // Joint all files to $array_all_files
  5570. $totalFromMine = count($files_from_mine);
  5571. $totalOthers = count($files_from_others);
  5572. $total_files = $totalFromMine + $totalOthers; //$count_all_files_others;
  5573. $array_all_files = array(); // all files from all context.id (in data decreasing order)
  5574. for ($ii=0; $ii<$totalOthers; $ii++) // Insert in first position all files from other then this user (bellow is inverted)
  5575. $array_all_files[] = $files_from_others[$ii];
  5576. for ($ii=0; $ii<$totalFromMine; $ii++) // Now insert the user's files (bellow is inverted) => will appear on first
  5577. $array_all_files[] = $files_from_mine[$ii];
  5578. //D echo "view_files_ilm: #array_contextid_files_aux=".count($array_contextid_files_aux). ", count_all_files_others=$total_files<br/>";
  5579. //view_files_ilm: #array_contextid_files_aux=54
  5580. //TODO Deste modo vem: se ADMIN => todos os arquivos de extensao compativel; senao todos os arquivos do usuario
  5581. //TODO Implementar: se NAO ADMIN => pegar TODOS os arquivos do curso
  5582. //TODO Tabela pegar todos '*_files.contextid' tais que '*_files.component=="mod_iassign"'
  5583. $array_files_course = array();
  5584. $dirs_array = ''; // if there are none 'exercise' file
  5585. $files_array = ''; // idem
  5586. $files_array = "''"; // idem
  5587. //NN $error_files_exists = "''"; // idem
  5588. for ($ii=$total_files-1; $ii>0; $ii--) {
  5589. //$contextid = $array_contextid_files[$ii];
  5590. //$files_course = $fs->get_directory_files($contextid, 'mod_iassign', 'activity', 0, $dir_base, false, true, 'filename');
  5591. //$array_files_course[] = $files_course;
  5592. $files_course = $array_all_files[$ii];
  5593. $files_array = '';
  5594. $files_array .= "''";
  5595. //NN $error_files_exists = get_string('error_file_exists', 'iassign');
  5596. $dirs_array = '';
  5597. foreach ($files_course as $one_file) {
  5598. if (!$one_file->is_directory())
  5599. $files_array .= "'" . $one_file->get_filename() . "',";
  5600. else { //if ($one_file->is_directory())
  5601. $pathname = explode("/", substr($one_file->get_filepath(), 0, strlen($one_file->get_filepath()) - 1));
  5602. $dirs_array .= "'" . $pathname[count($pathname) - 1] . "',";
  5603. }
  5604. } // foreach ($files_course as $one_file)
  5605. } // for ($ii=0; $ii<$num_contexts; $ii++)
  5606. print "#" . $total_files . "<br/>";
  5607. // -- end
  5608. $dirs_array .= "''";
  5609. //NN $error_dir_exists = get_string('error_dir_exists', 'iassign');
  5610. //TODO Rever o 'preview' pois soh poder deixar ver uma vez
  5611. //NN Retirei daqui as X linhas para definir javascript via variavel '$code_javascript_ilm'
  5612. //NN Agora em funcao get_string_JavaScript_functions(...) bellow
  5613. $output = "";
  5614. $select_all = "";
  5615. $count_files = 0;
  5616. $extensions_allow = array();
  5617. $iassign_ilm = $DB->get_records('iassign_ilm', array("enable" => 1)); // extensions for all iLM...
  5618. foreach ($iassign_ilm as $item_iassign_ilm)
  5619. $extensions_allow = array_merge($extensions_allow, explode(",", $item_iassign_ilm->extension));
  5620. // Estava foreach ($files_course as $one_file)
  5621. for ($ii=$total_files-1; $ii>0; $ii--) { // function view_files_ilm ($iassign_ilm_class, $extension)
  5622. //$contextid = $array_contextid_files[$ii]; // Notice: Undefined offset: 2257 in /var/www/html/saw/mod/iassign/locallib.php on line 6333
  5623. //$files_course = $array_files_course[$ii];
  5624. $one_file = $array_all_files[$ii];
  5625. $filename = $one_file->get_filename();
  5626. $filepath = $one_file->get_filepath();
  5627. $pathname = explode("/", substr($filepath, 0, strlen($filepath) - 1));
  5628. $pathname = $pathname[count($pathname) - 1];
  5629. $fileid = $one_file->get_id(); // get the file id (in table 'files')
  5630. $tmp = explode(".", $filename);
  5631. if (is_array($tmp)) { // define file type
  5632. if (sizeof($tmp)>1)
  5633. $filetype = $tmp[1];
  5634. else
  5635. $filetype = $extension;
  5636. }
  5637. else
  5638. $filetype = $extension;
  5639. $author = $one_file->get_author();
  5640. $timemodified = date("d/m/Y H:i:s", $one_file->get_timemodified());
  5641. $timecreated = date("d/m/Y H:i:s", $one_file->get_timecreated());
  5642. $extensions = explode(",", $extension);
  5643. if (in_array(strtolower($filetype), $extensions) || $one_file->is_directory() || $this->from == 'block' || $this->from == 'tinymce' || $this->from == 'atto') {
  5644. $count_files ++;
  5645. // buscar fileid nas tabelas do iassign
  5646. $list_filein_use = "";
  5647. // $iassign_statement_activity_list = $DB->get_records("iassign_statement", array("file" => $fileid));
  5648. $iassign_statement_activity_list = $this->get_all_ilm_files_by_fileid($fileid); // get all files under this directory (if it is the case)
  5649. if ($iassign_statement_activity_list) {
  5650. foreach ($iassign_statement_activity_list as $iassign_statement_activity_item) {
  5651. $list_filein_use .= $iassign_statement_activity_item->name . "</br>\n";
  5652. }
  5653. }
  5654. $array_iassign_ilm = $DB->get_records("iassign_ilm", array('extension' => $filetype, 'parent' => '0', 'enable' => '1')); // get all iLM from this "file type"
  5655. foreach ($array_iassign_ilm as $iassign_ilm) { // get files from all iLM equivalent
  5656. if (!$iassign_ilm) {
  5657. $iassign_ilm = new stdClass();
  5658. $iassign_ilm->id = $ilmid;
  5659. }
  5660. // Do not use $var inside "..." - problem with some "unusual" operational system
  5661. $url = $CFG->wwwroot . "/pluginfile.php/" . $one_file->get_contextid() . "/mod_iassign/activity";
  5662. $fileurl = $url . '/' . $one_file->get_itemid() . $filepath . $filename;
  5663. $dirurl = new moodle_url($this->url) . '&ilmid=' . $iassign_ilm->id . '&dirid=' . $fileid;
  5664. $straux = $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&fileid=" . $fileid . "&";
  5665. $link_add_ilm_iassign = "&nbsp;&nbsp;<a href='" . $straux . "action=addilm&filename=$filename&nbsp;&nbsp;&nbsp;'>" . iassign_icons::insert('add_ilm_iassign') . "</a>\n";
  5666. $link_add_ilm_tinymce = "&nbsp;&nbsp;<a href='" . $straux . "action=tinymceilm'>" . iassign_icons::insert('add_ilm_iassign') . "</a>\n";
  5667. $link_add_ilm_atto = "&nbsp;&nbsp;<a href='" . $straux . "action=attoilm'>" . iassign_icons::insert('add_ilm_iassign') . "</a>\n";
  5668. $check_select = "";
  5669. $link_rename = "";
  5670. $link_delete = "";
  5671. $link_duplicate = "&nbsp;&nbsp;<a href='#' onclick='duplicate_ilm(\"$iassign_ilm->id\", \"$filename\"," . $fileid . ");'>" . iassign_icons::insert('duplicate_iassign') . "</a>\n";
  5672. $link_edit = "&nbsp;&nbsp;" . iassign_icons::insert('no_edit_iassign');
  5673. $link_filter = "&nbsp;&nbsp;<a href='#' onclick='preview_ilm(" . $fileid . "," . $ilmid . ");'>" . iassign_icons::insert('preview_iassign') . "</a>\n";
  5674. $link_duplicate = "&nbsp;&nbsp;<a href='#' onclick='duplicate_ilm(\"$iassign_ilm->id\", \"$filename\"," . $fileid . ");'>" .
  5675. iassign_icons::insert('duplicate_iassign') . "</a>\n";
  5676. $link_edit = "&nbsp;&nbsp;" . iassign_icons::insert('no_edit_iassign');
  5677. $link_filter = "&nbsp;&nbsp;<a href='#' onclick='preview_ilm(" . $fileid . "," . $ilmid . ");'>" . iassign_icons::insert('preview_iassign') . "</a>\n";
  5678. if ($one_file->get_userid() == $USER->id || $hascapability==1) { // is the author or is Admin
  5679. if ($iassign_statement_activity_list) {
  5680. $check_select = "";
  5681. $link_edit = iassign_icons::insert('edit_iassign_disable');
  5682. $link_delete = "&nbsp;&nbsp;" . iassign_icons::insert('delete_iassign_disable');
  5683. $link_rename = "";
  5684. }
  5685. else {
  5686. $check_select = "<input name='selected_file' type='checkbox' value='$fileid'/>\n";
  5687. $link_edit = "&nbsp;&nbsp;<a href='#' onclick='update_ilm(\"" . $iassign_ilm->id . "\", $fileid)'>" . iassign_icons::insert('edit_iassign') . "</a>\n";
  5688. $link_delete = "&nbsp;&nbsp;<a href='#' onclick='delete_ilm(\"$iassign_ilm->id\", $fileid);'>" . iassign_icons::insert('delete_iassign') . "</a>\n";
  5689. $link_rename = "&nbsp;&nbsp;<a href='#' onclick='rename_ilm(\"$iassign_ilm->id\", \"$filename\"," . $fileid . ");'>" . iassign_icons::insert('rename_iassign') . "</a>\n";
  5690. }
  5691. } // if ($one_file->get_userid() == $USER->id)
  5692. if (!in_array($filetype, $extensions_allow)) {
  5693. $link_edit = "";
  5694. $link_add_ilm_iassign = "";
  5695. $link_add_ilm_tinymce = "";
  5696. $link_add_ilm_atto = "";
  5697. $link_filter = "";
  5698. }
  5699. if ($one_file->is_directory()) {
  5700. $link_delete = "&nbsp;&nbsp;<a href='#' onclick='delete_dir_ilm(\"$iassign_ilm->id\", $fileid);'>" . iassign_icons::insert('delete_dir') . "</a>\n";
  5701. $link_rename = "&nbsp;&nbsp;<a href='#' onclick='rename_dir_ilm(\"$iassign_ilm->id\", \"" . $pathname . "\"," . $fileid . ");'>" . iassign_icons::insert('rename_dir') . "</a>\n";
  5702. $output .= "<tr><td>$check_select$link_rename$link_delete</td>
  5703. <td><a href='$dirurl' title='" . get_string('dir', 'iassign') . $pathname . "'>" . iassign_icons::insert('dir') . '&nbsp;' . $pathname . "</a></td>
  5704. <td><center>$author</center></td>
  5705. <td><center>$timecreated</center></td>
  5706. <td><center>$timemodified</center></td></tr>\n";
  5707. }
  5708. else if ($this->from == 'iassign') {
  5709. $new_id = "";
  5710. $new_class = "";
  5711. if (isset($_SESSION['file_name']) && $filename == $_SESSION['file_name']) {
  5712. $new_class = "<div id='new_file' style='position: absolute;'></div>"; unset($_SESSION['file_name']);
  5713. $new_id = "id='id_new_blink' style='background-color: hsl(244,61%,90%);'";
  5714. }
  5715. $output .= "<tr $new_id><td>$new_class $check_select$link_rename$link_delete$link_duplicate$link_edit$link_filter$link_add_ilm_iassign</td>
  5716. <td><a href='$fileurl' title='" . get_string('download_file', 'iassign') . "$filename'>$filename</a></td>
  5717. <td><center>$author</center></td>
  5718. <td><center>$timecreated</center></td>
  5719. <td><center>$timemodified</center></td></tr>\n";
  5720. }
  5721. else if ($this->from == 'block') {
  5722. $output .= "<tr><td>$check_select$link_rename$link_delete$link_duplicate$link_edit$link_filter</td>
  5723. <td><a href='$fileurl' title='" . get_string('download_file', 'iassign') . "$filename'>$filename</a></td>
  5724. <td><center>$author</center></td>
  5725. <td><center>$timecreated</center></td>
  5726. <td><center>$timemodified</center></td></tr>\n";
  5727. }
  5728. else if ($this->from == 'tinymce') {
  5729. $output .= "<tr><td>$check_select$link_rename$link_delete$link_duplicate$link_edit$link_filter$link_add_ilm_tinymce</td>
  5730. <td><a href='$fileurl' title='" . get_string('download_file', 'iassign') . "$filename'>$filename</a></td>
  5731. <td><center>$author</center></td>
  5732. <td><center>$timecreated</center></td>
  5733. <td><center>$timemodified</center></td></tr>\n";
  5734. }
  5735. else if ($this->from == 'atto') {
  5736. $output .= "<tr><td>$check_select$link_rename$link_delete$link_duplicate$link_edit$link_filter$link_add_ilm_atto</td>
  5737. <td><a href='$fileurl' title='" . get_string('download_file', 'iassign') . "$filename'>$filename</a></td>
  5738. <td><center>$author</center></td>
  5739. <td><center>$timecreated</center></td>
  5740. <td><center>$timemodified</center></td></tr>\n";
  5741. }
  5742. } // foreach ($array_iassign_ilm as $iassign_ilm)
  5743. } // if (in_array(strtolower($filetype), $extensions) || $one_file->is_directory() || $this->from == 'block' || $this->from == 'tinymce' || $this->from == 'atto')
  5744. } // for ($ii=$total_files-1; $ii>0; $ii--) // for ($ii=0; $ii<$num_contexts; $ii++)
  5745. $basename = explode("/", substr($dir_base, 0, strlen($dir_base) - 1));
  5746. $dir_base = "";
  5747. $header = "";
  5748. // echo "locallib.php: view_files_ilm(iassign_ilm_class,extension): iassign_ilm_class->extension=" . $iassign_ilm_class->extension . ", extension=" . $extension. "<br/>\n";
  5749. // Get all files in the course context with the associated iLM extension (e.g., iLM=iVProgH => extension "*ivph")
  5750. foreach ($basename as $value) {
  5751. $dir_base .= $value . "/";
  5752. $dir_id = $fs->get_file($context->id, 'mod_iassign', 'activity', 0, $dir_base, '.');
  5753. if ($dir_id) {
  5754. if ($value == "") {
  5755. $fileurl = new moodle_url($this->url) . '&dirid=' . $dir_id->get_id() . '&ilmid=' . $ilmid;
  5756. $header .= "&nbsp;<a href='$fileurl' title='" . get_string('dir', 'iassign') . "Home'>Home</a>\n";
  5757. } else {
  5758. $fileurl = new moodle_url($this->url) . '&dirid=' . $dir_id->get_id() . '&ilmid=' . $ilmid;
  5759. $header .= "&nbsp;" . $OUTPUT->rarrow() . "&nbsp;<a href='$fileurl' title='" . get_string('dir', 'iassign') . "$dir_base'>$value</a>\n";
  5760. }
  5761. }
  5762. } // foreach ($basename as $value)
  5763. $html = $OUTPUT->heading(iassign_icons::insert('open_dir') . $header, 2, 'dirtitle', 'iassign');
  5764. $select_all = "<input id='select_all' type='checkbox' onclick='select_all_ilm();'/>\n";
  5765. $html .= "
  5766. <table id='outlinetable' class='generaltable boxaligncenter' cellpadding='5' width='100%'>
  5767. <tr><th class='header c1' width='20%'>$select_all " . get_string('functions', 'iassign') . "</th>
  5768. <th class='header c1' width='*'>" . get_string('file', 'iassign') . "</th>
  5769. <th class='header c1' width='10%'>" . get_string('author', 'iassign') . "</th>
  5770. <th class='header c1' width='10%'>" . get_string('file_created', 'iassign') . "</th>
  5771. <th class='header c1' width='10%'>" . get_string('file_modified', 'iassign') . "</th>\n " . $output . "
  5772. </table>\n";
  5773. $html .= "<form id='form_buttons' method='post' enctype='multipart/form-data'>\n";
  5774. $html .= "<table width='100%'><tr>\n";
  5775. $html .= "<td width='80%'><input type='button' value='" . get_string('new_dir', 'iassign') . "' onClick='new_dir_ilm();'>\n";
  5776. if ($count_files != 0) {
  5777. $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";
  5778. $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";
  5779. $html .= "<input type='button' value='" . get_string('file_ilm_export', 'iassign') . "' onClick='export_files_ilm();'>\n";
  5780. }
  5781. $html .= "</td><td width='100%' align='right'><input type='button' value='" . get_string('file_ilm_recover', 'iassign') . "' onClick='recover_files_ilm();'>\n";
  5782. $html .= $OUTPUT->help_icon('file_ilm_recover', 'iassign') . "</td></tr></table>\n";
  5783. $html .= "</form>\n";
  5784. print $this->get_string_JavaScript_functions($ilmid, $dirid, $files_array, $dirs_array); //NN put here all JavaScript code to edit/remove/double ($code_javascript_ilm)
  5785. print $html;
  5786. } // function view_files_ilm($extension)
  5787. } // class ilm_manager
  5788. /// Class to insert of icons
  5789. class iassign_icons {
  5790. static function insert ($icon) {
  5791. global $CFG;
  5792. $string = '<img src="' . $CFG->wwwroot . '/mod/iassign/icon/' . $icon . '.gif" title="' . get_string($icon, 'iassign') . '" alt="' . get_string($icon, 'iassign') . '"/>'; // "\n"
  5793. return $string;
  5794. }
  5795. }
  5796. /// Class with util functions for plugin manage
  5797. class iassign_utils {
  5798. /// Function to return the filename extension
  5799. // @param string The $filename as an string
  5800. // @return string Return an string (last group after '.')
  5801. static function filename_extension ($filename) {
  5802. if ($filename == null || $filename == '') {
  5803. return null;
  5804. }
  5805. $itens = explode('.', $filename);
  5806. $num = count($itens);
  5807. if ($num < 2) {
  5808. return null;
  5809. }
  5810. return $itens[$num - 1];
  5811. }
  5812. /// Use the PHP class/package ZipArchive to create a Zip file
  5813. // The version 1 with ZipArchive (with '$zip->addFile(...)') is NOT working:
  5814. // 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
  5815. // @param $full_path_zip_filename, $vet_student_filename, $vet_student_content
  5816. static function register_temporary_file ($full_path_zip_filename, $vet_student_filename, $vet_student_content) {
  5817. //1 $zip = new ZipArchive(); //TODO this version uses '$zip->addFile(...)' and it is NOT working!
  5818. $zip = new zip_archive(); //2
  5819. $res = $zip->open($full_path_zip_filename);
  5820. $total_vet = count($vet_student_filename);
  5821. for ($ii=0; $ii<$total_vet; $ii++) {
  5822. // $zip->addFile($vet_student_filename[$ii], $vet_student_content[$ii]); //1 to ZipArchive
  5823. $zip->add_file_from_string($vet_student_filename[$ii], $vet_student_content[$ii]); //2 to zip_archive
  5824. }
  5825. $ret = $zip->close();
  5826. iassign_utils::download_file($full_path_zip_filename);
  5827. $filenameZip = $zip->filename;
  5828. return array($ret, $zip);
  5829. }
  5830. static function download_file ($zip_filename) {
  5831. header("Pragma: public");
  5832. header("Expires: 0");
  5833. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  5834. header("Cache-Control: private", false);
  5835. header("Content-Type: application/zip");
  5836. header("Content-Disposition: attachment; filename=\"" . basename($zip_filename) . "\";");
  5837. header("Content-Transfer-Encoding: binary");
  5838. header("Content-Length: " . @filesize($zip_filename));
  5839. set_time_limit(0);
  5840. @readfile("$zip_filename") || die("File not found.");
  5841. unlink($zip_filename);
  5842. }
  5843. /// Function for format filename remove special caracters
  5844. // @param string $text String for clean
  5845. // @param boolean $is_lowercase Boolean for apply lowercase in filename
  5846. // @return string Return an string in clean format
  5847. static function format_filename ($text) {
  5848. if ($text != '.') {
  5849. //D $text = htmlspecialchars(urldecode($text));
  5850. //D echo "locallib.php: format_filename: $text<br/>";
  5851. if (is_object($text)) // with iAssign did not filtered text from JSON format
  5852. $text = json_decode($text)->{current_language()};
  5853. // $text = htmlspecialchars($text); // not good ideia, it results strange at 'iassign_ilm' field
  5854. $array1 = array("(", ")", ",", "/", "\\", "!", "@", "#", "$", "&", "*", "+", "!", "?", ".", " ",
  5855. "á", "à", "â", "ã", "ä", "é", "è", "ê", "ë", "ẽ", "í", "ì", "î", "ï", "ó", "ò", "ô", "õ", "ö", "ú", "ù", "û", "ü",
  5856. "ç", "Á", "À", "Â", "Ã", "Ä", "É", "È", "Ê", "Ë", "Í", "Ì", "Î", "Ï", "Ó", "Ò", "Ô", "Õ", "Ö", "Ú", "Ù", "Û", "Ü", "Ç");
  5857. $array2 = array("", "", "_", "_", "_", "", "", "", "", "", "", "", "", "", "_", "_",
  5858. "a", "a", "a", "a", "a", "e", "e", "e", "e", "e", "i", "i", "i", "i", "o", "o", "o", "o", "o", "u", "u", "u", "u",
  5859. "c", "A", "A", "A", "A", "A", "E", "E", "E", "E", "I", "I", "I", "I", "O", "O", "O", "O", "O", "U", "U", "U", "U", "C");
  5860. // E.g. text = "exerc_midpoint.course.geo"
  5861. // 0123456789012345678901234
  5862. $index_lastposition = strrpos($text, "."); // Find the position of the last occurrence of a substring in a string (21)
  5863. $text2 = substr($text, 0, $index_lastposition); // Erase the final point and its extension ("exerc_midpoint.course")
  5864. $ext = substr($text, $index_lastposition); // Point with extention (".geo")
  5865. $text = str_replace(".", "", $text2) . $ext; // Clear any other point and redefine the name ("exerc_midpoint.course.geo")
  5866. $text = str_replace($array1, $array2, $text); // Replace any letter with accent mark under the UTF8 format
  5867. //$ext = strrpos($text, ".");
  5868. //$text = str_replace(".", "", substr($text, 0, $ext)).substr($text, $ext);
  5869. //$text = str_replace($array1, $array2, $text);
  5870. }
  5871. return $text;
  5872. }
  5873. /// Function to filter characters to the file name to iLM content
  5874. // @param string $text String for clean
  5875. // @param string $ext String ot the extension of the iLM
  5876. // @return string Return an string in clean format
  5877. static function filter_filename_extension ($filename, $ext) {
  5878. if ($filename != '.') {
  5879. $arrFrom = array("=","~","`","!","@","$","%","^","&","*","(",")");
  5880. $arrTo = array("_","","","","","","","","","","","","");
  5881. $filename = str_replace($arrFrom, $arrTo, $filename);
  5882. //D echo "locallib.php: filter_filename_extension: 1 : " . $filename . "<br/>";
  5883. $filenameF = preg_replace('/[^\x20-\x7E]/','', $filename); // only ASCII - https://stackoverflow.com/questions/8781911/remove-non-ascii-characters-from-string
  5884. $index_lastposition = strrpos($filenameF, "."); // find the position of the last occurrence of a substring in a string (21)
  5885. if (!isset($index_lastposition) || $index_lastposition=="" || $index_lastposition<0) // Just in case (logic of function 'strrpos(...)' change, ensure to preserve name without '.'
  5886. $index_lastposition = strlen($filenameF);
  5887. $text = substr($filenameF, 0, $index_lastposition); // erase the final point and its extension ("exerc_midpoint.course")
  5888. $text = str_replace(".", "_", $text); // erase all other "."
  5889. $existext = substr($filenameF, $index_lastposition); // get the possibly extension
  5890. $filenameF = $text . "." . $ext; // no matter, use the prefiz with oficial extension
  5891. }
  5892. else
  5893. $filenameF = 'file_without_name.' . $ext; // Just in case... if the use do not enter a valid name, only entered '.'!
  5894. return $filenameF;
  5895. }
  5896. /// Function for format pathname remove special caracters
  5897. // @param string $text String for clean
  5898. // @param boolean $is_lowercase Boolean for apply lowercase in pathname
  5899. // @return string Return an string in clean format
  5900. static function format_pathname ($text, $is_lowercase = true) {
  5901. $array1 = array("á", "à", "â", "ã", "ä", "é", "è", "ê", "ë", "í", "ì", "î", "ï", "ó", "ò", "ô", "õ", "ö", "ú", "ù", "û", "ü", "ç", "Á", "À", "Â", "Ã", "Ä", "É", "È", "Ê", "Ë", "Í", "Ì", "Î", "Ï", "Ó", "Ò", "Ô", "Õ", "Ö", "Ú", "Ù", "Û", "Ü", "Ç", "@", " ", "!", "?", ".");
  5902. $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", "-", "_", "", "", "");
  5903. $text = str_replace($array1, $array2, $text);
  5904. if ($is_lowercase)
  5905. $text = strtolower($text);
  5906. return $text;
  5907. }
  5908. /// Function for format file name from iLM original name
  5909. // @param string $text String to build the file neam
  5910. // @param boolean $is_lowercase Boolean for apply lowercase in pathname
  5911. // @return string Return an string in clean format
  5912. static function filename_from_iLM_name ($ilm_name, $is_lowercase = true) {
  5913. $array1 = array("á", "à", "â", "ã", "ä", "é", "è", "ê", "ë", "í", "ì", "î", "ï", "ó", "ò", "ô", "õ", "ö", "ú", "ù", "û", "ü", "ç", "Á", "À", "Â", "Ã", "Ä", "É", "È", "Ê", "Ë", "Í", "Ì", "Î", "Ï", "Ó", "Ò", "Ô", "Õ", "Ö", "Ú", "Ù", "Û", "Ü", "Ç", "@", " ", "!", "?", ".");
  5914. $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", "-", "_", "", "", "");
  5915. $index_firstposition_blank = strpos($ilm_name, " ");
  5916. if ($index_firstposition_blank) { // truncate the name!
  5917. $ilm_name = substr($ilm_name, 0, $index_firstposition_blank);
  5918. }
  5919. $index_firstposition_dots = strpos($ilm_name, ":");
  5920. if ($index_firstposition_dots) { // truncate the name!
  5921. $ilm_name = substr($ilm_name, 0, $index_firstposition_dots);
  5922. }
  5923. $namefiltered = str_replace($array1, $array2, $ilm_name);
  5924. if ($is_lowercase)
  5925. $namefiltered = strtolower($namefiltered);
  5926. return $namefiltered;
  5927. }
  5928. /// Function for insert version in the filename
  5929. // @param string $filename Name of file
  5930. // @return string Return the filename with version
  5931. static function version_filename ($filename) {
  5932. $array_filename = explode('.', $filename);
  5933. if (count($array_filename) > 1)
  5934. $filename = $array_filename[0] . '-' . date("Ymd-His") . '.' . $array_filename[1];
  5935. else
  5936. $filename = $array_filename[0] . '-' . date("Ymd-His");
  5937. return $filename;
  5938. }
  5939. //TODO Retirar quando atualizar todo os iassign que estão com a tag &lt;ia_uc&gt;
  5940. static function remove_code_message ($string) {
  5941. $array = explode("&lt;ia_uc&gt;", $string);
  5942. return $array[0];
  5943. }
  5944. }
  5945. // class iassign_utils
  5946. /// Class with language functions for plugin manage
  5947. class iassign_language {
  5948. /// Function for return text in language or get default language (en)
  5949. // @param string $lang Code of language
  5950. // @param string $description JSON text content all languages
  5951. // @return string Return an string in the language selected
  5952. static function get_description_lang ($lang, $descriptions) {
  5953. $description_lang = "";
  5954. $description = json_decode($descriptions);
  5955. if ($description == null) {
  5956. $description_lang = $descriptions;
  5957. }
  5958. else {
  5959. if (isset($description->{$lang}))
  5960. $description_lang = $description->{$lang};
  5961. else
  5962. if (isset($description->en)) //MOOC2014
  5963. $description_lang = $description->en;
  5964. else //MOOC2014
  5965. $description_lang = "en"; //MOOC2014
  5966. }
  5967. return $description_lang;
  5968. }
  5969. /// Function for return all language supported by iLM
  5970. // @param string $descriptions JSON text content all languages
  5971. // @return string Return as string with all languages
  5972. static function get_all_lang ($descriptions) {
  5973. $langs = "";
  5974. $description = json_decode($descriptions);
  5975. if ($description) {
  5976. foreach ($description as $key => $value) {
  5977. $langs .= $key . " ; ";
  5978. }
  5979. $langs = substr($langs, 0, strlen($langs) - 3);
  5980. }
  5981. return $langs;
  5982. }
  5983. /// Function for convert json in xml //MOOC2014
  5984. // @param string $json JSON text
  5985. // @return string Return as string with xml tags
  5986. static function json_to_xml ($json) {
  5987. $xml = "";
  5988. $json = json_decode($json);
  5989. foreach ($json as $key => $value) {
  5990. $xml .= "\n <" . $key . ">" . $value . "</" . $key . ">";
  5991. }
  5992. return $xml;
  5993. }
  5994. }
  5995. // class iassign_language
  5996. /// Class with log functions for plugin manage.
  5997. class iassign_log {
  5998. /// Function for insert log event
  5999. // @param string $action Code action of event
  6000. // @param string $information Text for describe action of event
  6001. // @param int $cmid Id of context module
  6002. // @param int $ilmid Id of iLM
  6003. static function add_log ($action, $information = "", $cmid = 0, $ilmid = 0) {
  6004. global $COURSE, $CFG, $USER, $DB;
  6005. $newentry = new stdClass();
  6006. $newentry->time = time();
  6007. $newentry->userid = $USER->id;
  6008. $newentry->ip = $_SERVER['REMOTE_ADDR'];
  6009. $newentry->course = $COURSE->id;
  6010. $newentry->cmid = $cmid;
  6011. $newentry->ilmid = $ilmid;
  6012. $newentry->action = $action;
  6013. $newentry->info = $information;
  6014. $newentry->language = current_language();
  6015. $newentry->user_agent = $_SERVER['HTTP_USER_AGENT'];
  6016. if (ini_get("browscap") && function_exists('get_browse')) {
  6017. $browser = get_browse(null, true);
  6018. $newentry->javascript = $browser['javascript'];
  6019. $newentry->java = $browser['javaapplets'];
  6020. }
  6021. if (!$newentry->id = $DB->insert_record("iassign_log", $newentry))
  6022. print_error('error_add_log', 'iassign');
  6023. } // static function add_log($action, $information = "", $cmid = 0, $ilmid = 0)
  6024. } // class iassign_log