12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074 |
- <?php
- $CONF_WWW = 1;
- class iassign {
- var $cm;
- var $course;
- var $iassign;
- var $striassign;
- var $striassigns;
- var $context;
- var $activity;
- var $iassign_up;
- var $iassign_down;
- var $action;
- var $iassign_submission_current;
- var $userid_iassign;
- var $bottonPost;
- var $write_solution;
- var $view_iassign;
-
-
-
-
-
-
- function __construct ($iassign, $cm, $course) {
- global $COURSE, $CFG, $USER, $DB;
- $botton = optional_param('botton', NULL, PARAM_TEXT);
- $this->userid_iassign = optional_param('userid_iassign', 0, PARAM_INT);
- if (!is_null($botton))
- $USER->iassignEdit = $botton;
-
-
- $this->iassign_up = optional_param('iassign_up', 0, PARAM_INT);
- $this->iassign_down = optional_param('iassign_down', 0, PARAM_INT);
- $this->iassign_submission_current = optional_param('iassign_submission_current', 0, PARAM_INT);
- $this->write_solution = optional_param('write_solution', 0, PARAM_INT);
- $this->action = optional_param('action', NULL, PARAM_TEXT);
- $this->cm = $cm;
- $this->context = context_module::instance($this->cm->id);
- if (!has_capability('mod/iassign:evaluateiassign', $this->context, $USER->id))
- $this->userid_iassign = $USER->id;
- if ($course) {
- $this->course = $course;
- }
- else if ($this->cm->course == $COURSE->id) {
- $this->course = $COURSE;
- }
- else if (!$this->course = $DB->get_record('course', array('id' => $this->cm->course))) {
- print_error('invalidid', 'iassign');
- }
- $this->coursecontext = context_course::instance($this->course->id);
- if ($iassign) {
- $this->iassign = $iassign;
- }
- else if (!$this->iassign = $DB->get_record('iassign', array('id' => $this->cm->instance))) {
- print_error('invalidid', 'iassign');
- }
- $USER->context = context_module::instance($this->cm->id);
- $USER->cm = $this->cm->id;
- $this->iassign->cmidnumber = $this->cm->idnumber;
- $this->iassign->courseid = $this->course->id;
- $this->context = context_module::instance($this->cm->id);
- $this->striassign = get_string('modulename', 'iassign');
- $this->striassigns = get_string('modulenameplural', 'iassign');
- $this->return = $CFG->wwwroot . "/mod/iassign/view.php?id=" . $this->cm->id;
- $this->bottonPost = 0;
- $this->view_iassign = optional_param('action', false, PARAM_BOOL);
- $this->activity = new activity(optional_param('iassign_current', NULL, PARAM_TEXT));
- }
-
-
-
- function view () {
- global $USER, $DB, $OUTPUT;
-
- if ($this->activity!=null && $this->activity->get_activity()!=null && isset($this->activity->get_activity()->id))
- $iassign_statementid = $this->activity->get_activity()->id;
- else
- $iassign_statementid = "";
-
-
- require_capability('mod/iassign:view', $this->context);
-
- $event = \mod_iassign\event\course_module_viewed::create(array(
- 'objectid' => $this->iassign->id,
- 'context' => $this->context
- ));
- $event->add_record_snapshot('course', $this->course);
- $event->trigger();
- if ($this->action) {
- $this->action();
- } else {
- print $OUTPUT->header();
- $this->view_iassigns();
- print $OUTPUT->footer();
- }
-
-
-
-
- $DB->delete_records("iassign_security", array("userid" => $USER->id, "iassign_statementid" => $iassign_statementid));
-
-
-
- }
-
- function action () {
- global $USER;
-
-
-
-
-
-
-
-
-
- $action_iassign = array(
- 'newcomment' => '$this->add_comment();',
- 'view' => '$this->view_iassign_current();',
- 'get_answer' => '$this->get_answer();',
- 'repeat' => '$this->view_iassign_current();',
- 'overwrite' => '$this->get_answer();',
- 'stats_student' => '$this->stats_students();',
- 'download_answer' => '$this->export_file_answer();',
- 'download_all_answer' => '$this->export_package_answer();',
- 'notifications' => '$this->view_notifications();');
- $action_iassign_limit = array(
- 'view' => '$this->view_iassign_current();',
-
- 'viewsubmission' => '$this->view_iassign_current();',
- 'edit_status' => '$this->edit_status();',
- 'edit_grade' => '$this->edit_grade();',
- 'export_csv' => '$this->export_csv();',
- 'report' => '$this->report();',
- 'print' => '$this->report();',
- 'stats' => '$this->stats();',
- 'printstats' => '$this->stats();');
- $restricted = array('firstdown' => '$this->activity->move_iassign("firstdown", $this->iassign_down, $this->return);',
- 'up' => '$this->activity->move_iassign("up", $this->iassign_up, $this->return);',
- 'down' => '$this->activity->move_iassign("down", $this->iassign_down, $this->return);',
- 'visible' => '$this->activity->visible_iassign($this->return);',
- 'delete' => '$this->activity->delete($this->return);',
- 'deleteno' => '$this->return_home_course("confirm_not_delete_iassign");',
- 'deleteyes' => '$this->activity->deleteyes($this->return, $this);',
- 'add' => '$this->add_edit_iassign();',
- 'edit' => '$this->add_edit_iassign();',
- 'get_answer' => '$this->get_answer();',
- 'duplicate_activity' => '$this->duplicate_activity();',
- 'move_activity' => '$this->move_activity();',
- 'auto_evaluate' => '$this->auto_evaluate();',
- 'all_submissions' => '$this->all_submissions();',
- 'delete_submissions' => '$this->delete_submissions();',
- 'download_submissions' => '$this->download_submissions();',
- 'open_individual_submission' => '$this->open_individual_submission();',
- 'get_individual_submission' => '$this->get_individual_submission();',
- 'get_student_submission' => '$this->get_student_submission();',
- 'get_teacher_exercise' => '$this->get_teacher_exercise();',
- 'post_auto_eval_result' => '$this->post_auto_eval_result();',
- 'import_activity' => '$this->import_activity();',
- 'import_activity_confirm' => '$this->import_activity_confirm();'
- );
- $action_iassign_restricted = array_merge($restricted, $action_iassign_limit, $action_iassign);
-
- if (has_capability('mod/iassign:editiassign', $this->context, $USER->id)) {
-
- eval($action_iassign_restricted[$this->action]);
- }
- elseif (has_capability('mod/iassign:evaluateiassign', $this->context, $USER->id)) {
- eval($action_iassign_limit[$this->action]);
- }
- else {
-
-
- if (isset($action_iassign[$this->action]))
- eval($action_iassign[$this->action]);
- }
- }
-
- function get_student_submission () {
- global $DB;
- $student = optional_param('iassign_student', NULL, PARAM_TEXT);
- $exercise = optional_param('iassign_exercise', NULL, PARAM_TEXT);
- if (!$student || !$exercise) exit;
- $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $exercise, "userid" => $student));
- if ($iassign_submission)
- print($iassign_submission->answer);
- die();
- }
-
- function get_teacher_exercise () {
- global $DB, $COURSE;
- $ilmid = optional_param('iassign_exercise', NULL, PARAM_INT);
- $iassign_statement = $DB->get_record("iassign_statement", array("id" => $ilmid));
- $fs = get_file_storage();
-
-
- $files = $fs->get_area_files(context_module::instance($this->cm->id)->id, 'mod_iassign', 'exercise', $iassign_statement->id);
- foreach ($files as $file) {
- if ($file->get_filename() != ".") {
- print($file->get_content());
- }
- }
- die();
- }
-
-
- function post_auto_eval_result () {
- global $COURSE, $CFG, $USER, $DB;
- if (!has_capability('mod/iassign:runautoevaluate', $USER->context, $USER->id))
- exit;
-
- $exercise = optional_param('iassign_exercise', -1, PARAM_INT);
- $student = optional_param('student', -1, PARAM_INT);
- $grade = optional_param('grade', 0, PARAM_FLOAT);
-
- $actual = $DB->get_record('iassign_submission', array('iassign_statementid' => $exercise, 'userid' => $student));
-
- $update_entry = new stdClass();
- $update_entry->id = $actual->id;
- $update_entry->previous_grade = $actual->grade;
- $update_entry->grade = $grade;
-
- $DB->update_record("iassign_submission", $update_entry);
- }
-
- function download_submissions_help ($list) {
- global $DB, $CFG, $OUTPUT;
-
- $ilm_list = $DB->get_records("iassign_ilm");
-
- $params_temp = array('shortname' => 'student');
- $role = $DB->get_record_sql("SELECT s.id, s.shortname FROM {role} s WHERE s.shortname = :shortname", $params_temp);
- $context = context_course::instance($this->course->id);
- $params_temp = array('contextid' => $context->id, 'roleid' => $role->id);
- $students_list = $DB->get_records_sql(
- "SELECT s.userid, a.firstname, a.lastname FROM {role_assignments} s, {user} a " . " WHERE s.contextid = :contextid AND s.userid = a.id AND s.roleid = :roleid " . " ORDER BY a.firstname ASC,a.lastname ASC", $params_temp);
- $json_obj = new stdclass();
- $json_obj->submissions = [];
- $csvfields = [];
- $csvfields[] = 'submissionid';
- $csvfields[] = 'file';
- $csvfields[] = 'filesize';
- $csvfields[] = 'timestamp';
- $csvfields[] = 'humandate';
- $csvfields[] = 'grade';
- $csvfields[] = 'userid';
- $csvfields[] = 'exerciseid';
- $json_obj->submissions[] = $csvfields;
- $exercise_dir = [];
- $exercises_list = [];
- foreach ($list as $item) {
- if (!in_array($item->iassign_statementid, $exercise_dir)) {
- $temp = $DB->get_record("iassign_statement", array("id" => $item->iassign_statementid));
- $exercises_list[] = $temp;
- $exercise_dir[] = $temp->id;
- }
- }
- $student_dir = [];
- $students_list = [];
- foreach ($list as $item) {
- if (!in_array($item->userid, $student_dir)) {
- $temp = $DB->get_record("user", array("id" => $item->userid));
- $students_list[] = $temp;
- $student_dir[] = $temp->id;
- }
- }
-
-
-
- $tempfilespath = $CFG->dataroot . DIRECTORY_SEPARATOR . 'temp';
- if (!file_exists($tempfilespath)) {
- mkdir($tempfilespath, 0777, true);
- }
- $iassignfilespath = $tempfilespath . DIRECTORY_SEPARATOR . 'iassign_files';
- if (!file_exists($iassignfilespath)) {
- mkdir($iassignfilespath, 0777, true);
- }
- $diretorio = $CFG->dataroot . DIRECTORY_SEPARATOR . 'temp'
- . DIRECTORY_SEPARATOR . 'iassign_files' . DIRECTORY_SEPARATOR;
- if (!file_exists($diretorio)) {
- echo 'Não foi possível criar o diretório para preparar o arquivo com as submissões. Possivelmente o caminho está bloqueado para escrita.';
- exit;
- }
- $zip_filename = $diretorio . 'package_iassign_'.time().'.zip';
- $zip = new zip_archive();
- if (!$zip->open($zip_filename)) {
- echo 'Não foi possível criar o arquivo zip com as submissões dos alunos, pois o diretório no servidor está bloqueado para escrita: ' . $diretorio;
- exit;
- }
- ;
- foreach ($exercises_list as $exercise) {
- $dir_ex = iassign_utils::format_filename($exercise->name);
- $zip->add_directory($dir_ex);
- $extension_ilm = '';
- foreach ($ilm_list as $ilm) {
- if ($exercise->iassign_ilmid == $ilm->id) {
- $extension_ilm = $ilm->extension;
- break;
- }
- }
- foreach ($students_list as $student) {
- $individual_dir =
- $dir_ex . DIRECTORY_SEPARATOR .
- iassign_utils::format_filename($student->firstname . ' ' . $student->lastname);
- $zip->add_directory($individual_dir);
- $i = 1;
- foreach($list as $item) {
- if ($item->userid == $student->id && $item->iassign_statementid == $exercise->id) {
- $date = new DateTime();
- $date->setTimestamp($item->timecreated);
- $new_file = $individual_dir . DIRECTORY_SEPARATOR . iassign_utils::format_filename('submission_' . ($i++) . '_' . date_format($date, 'Y-m-d_H-i-s')) . '.' . $extension_ilm;
- $zip->add_file_from_string($new_file, $item->answer);
- $temp_json = [];
- $temp_json[] = intval($item->id);
- $temp_json[] = $new_file;
- $temp_json[] = strlen($new_file);
- $temp_json[] = intval($item->timecreated);
- $temp_json[] = date_format($date, 'Y-m-d H-i-s');
- $temp_json[] = doubleval($item->grade);
- $temp_json[] = intval($item->userid);
- $temp_json[] = intval($exercise->id);
- $json_obj->submissions[] = $temp_json;
- }
- }
- }
- }
- $csv_str = "";
- foreach($json_obj->submissions as $sub) {
- $csv_str .= $this->csvstr($sub) . "\n";
- }
- $zip->add_file_from_string('index.csv', $csv_str);
- $zip->close();
- iassign_utils::download_file($zip_filename);
- exit;
- }
- function csvstr(array $fields) : string {
- $f = fopen('php://memory', 'r+');
- if (fputcsv($f, $fields) === false) {
- return false;
- }
- rewind($f);
- $csv_line = stream_get_contents($f);
- return rtrim($csv_line);
- }
-
- function download_submissions () {
- global $COURSE, $CFG, $USER, $DB, $OUTPUT, $PAGE;
- if (!has_capability('mod/iassign:runautoevaluate', $this->context, $USER->id))
- exit;
- $type = optional_param('type', NULL, PARAM_TEXT);
- $item = optional_param('item', NULL, PARAM_TEXT);
- $exercise = optional_param('exercise', NULL, PARAM_TEXT);
- $iassign_id = optional_param('iassign', NULL, PARAM_TEXT);
- $sub_list = [];
- if ($type == 'individual') {
- $sub_list[] = $DB->get_record(
- 'iassign_allsubmissions', array('id' => $item));
- } elseif ($type == 'student') {
- $sub_list = $DB->get_records(
- 'iassign_allsubmissions', array('userid' => $item, 'iassign_statementid' => $exercise));
- } elseif ($type == 'exercise') {
- $sub_list = $DB->get_records(
- 'iassign_allsubmissions', array('iassign_statementid' => $item));
- } elseif ($type == 'block') {
- $exercises_in_block = $DB->get_records(
- 'iassign_statement', array('iassignid' => $iassign_id));
- foreach ($exercises_in_block as $exercise) {
- $temp = $DB->get_records(
- 'iassign_allsubmissions', array('iassign_statementid' => $exercise->id));
- $sub_list = array_merge($sub_list, $temp);
- }
- }
- $this->download_submissions_help($sub_list);
- }
-
- function delete_submissions () {
- global $COURSE, $CFG, $USER, $DB, $OUTPUT, $PAGE;
- if (!has_capability('mod/iassign:runautoevaluate', $this->context, $USER->id))
- exit;
- $type = optional_param('type', NULL, PARAM_TEXT);
- $item = optional_param('item', NULL, PARAM_TEXT);
- $exercise = optional_param('exercise', NULL, PARAM_TEXT);
- if ($type == 'individual') {
- $DB->delete_records('iassign_allsubmissions', array('id' => $item));
- } elseif ($type == 'student') {
- $DB->delete_records('iassign_allsubmissions', array('userid' => $item, 'iassign_statementid' => $exercise));
- } elseif ($type == 'exercise') {
- $DB->delete_records('iassign_allsubmissions', array('iassign_statementid' => $item));
- }
- }
- function get_individual_submission () {
- global $DB, $USER;
- if (!has_capability('mod/iassign:runautoevaluate', $this->context, $USER->id))
- exit;
- $submissionid = optional_param('submissionid', NULL, PARAM_TEXT);
- $submission = $DB->get_record("iassign_allsubmissions", array("id" => $submissionid));
- print $submission->answer;
- }
-
- function open_individual_submission () {
- global $DB, $USER, $CFG;
- if (!has_capability('mod/iassign:runautoevaluate', $this->context, $USER->id))
- exit;
- $submissionid = optional_param('item', NULL, PARAM_TEXT);
- $id = $this->cm->id;
- $param_aux = "id=" . $id . "&userid_iassign=" . $USER->id;
- $url = "" . $CFG->wwwroot . "/mod/iassign/view.php?action=get_individual_submission&" . $param_aux . "&submissionid=" . $submissionid;
- $atual_submission = $DB->get_record('iassign_allsubmissions', array('id' => $submissionid));
- $atual_statement = $DB->get_record("iassign_statement", array("id" => $atual_submission->iassign_statementid));
- $all_submissions = $DB->get_records('iassign_allsubmissions',
- array('iassign_statementid' => $atual_submission->iassign_statementid, 'userid' => $atual_submission->userid));
- $user = $DB->get_record('user', array('id' => $atual_submission->userid));
- $previous = null;
- $next = null;
- $i = 0;
- $found = false;
- foreach($all_submissions as $individual) {
- if (!$found && $individual->id != $submissionid) {
- $previous = $individual;
- }
- if ($found) {
- $next = $individual;
- break;
- }
- if ($individual->id === $submissionid) {
- $found = true;
- }
- $i++;
- }
- print '<center>' . "\n";
- print '<table cellpading=5 cellspacing=5 style="padding-bottom: 2rem;font-size: 1.1em;"><tr><td>' . get_string('exercise', 'iassign') . ':</td><td>' . $atual_statement->name . '</td></tr>' . "\n";
- print '<tr><td>' . get_string('student', 'iassign') . '</td><td>' . $user->firstname . ' ' . $user->lastname . '</td></tr>' . "\n";
- print '<tr><td>' . get_string('grade_student', 'iassign') . ':</td><td>' . $atual_submission->grade . '</td></tr>' . "\n";
- print '<tr><td>' . get_string('all_submissions_manager_date', 'iassign') . ':</td><td>' . userdate($atual_submission->timecreated) . '</td></tr>' . "\n";
- print '</table>' . "\n";
- if ($previous) {
- $url_prev = "" . $CFG->wwwroot . "/mod/iassign/view.php?action=open_individual_submission&" . $param_aux . "&item=" . $previous->id;
- print '<a href="' . $url_prev . '" style="color: blue; text-decoration: none;margin: 1rem;"><span>◀</span> ' . get_string('all_submissions_manager_previous', 'iassign') . '</a> ';
- } else {
- print '<a href="#" style="color: gray; text-decoration: none;margin: 1rem;"><span>◀</span> ' . get_string('all_submissions_manager_previous', 'iassign') . '</a> ';
- }
- print ' (' . $i . '/' . count($all_submissions) . ')';
- if ($next) {
- $url_next = "" . $CFG->wwwroot . "/mod/iassign/view.php?action=open_individual_submission&" . $param_aux . "&item=" . $next->id;
- print '<a href="' . $url_next . '" style="color: blue; text-decoration: none;margin: 1rem;">' . get_string('all_submissions_manager_next', 'iassign') . ' <span>▶</span></a>' . "\n";
- } else {
- print '<a href="#" style="color: gray; text-decoration: none;margin: 1rem;">' . get_string('all_submissions_manager_next', 'iassign') . ' <span>▶</span></a>' . "\n";
- }
- $statement = $DB->get_record('iassign_statement', array('id' => $atual_submission->iassign_statementid));
-
- print ilm_settings::build_ilm_tags($statement->iassign_ilmid, ['type' => "activity", 'Proposition' => $url, "notSEND" => "false"]);
- print '</center>' . "\n";
- }
-
- function import_activity_confirm () {
- global $USER, $DB;
- if (!has_capability('mod/iassign:runautoevaluate', $this->context, $USER->id))
- exit;
- if (!isset($_REQUEST['statements'])) exit;
- $iassign_destiny = $this->iassign->id;
- $activities_list = $_REQUEST['statements'];
- foreach ($activities_list as $activity) {
- $activity_source = $DB->get_record('iassign_statement', array('id' => $activity));
- $activity_source->id = 0;
- $iassign_id_from = $activity_source->iassignid;
- $filesid_from = $activity_source->filesid;
- $activity_source->iassignid = $iassign_destiny;
- $author = $DB->get_record("user", array('id' => $USER->id));
- $activity_source->author_modified_name = $author->firstname . ' ' . $author->lastname;
- $activity_source->author_modified = $activity_source->author_modified_name;
- if ($id_ = $DB->insert_record("iassign_statement", $activity_source)) {
- $fs = get_file_storage();
-
- $files_ids = $DB->get_records_sql('SELECT id FROM {files} WHERE component="mod_iassign" AND itemid=' . $filesid_from);
- print 'Arquivos a serem copiados: ';
- print_r($files_ids);
- foreach ($files_ids as $fileid) {
- $source_file = $fs->get_file_by_id($fileid->id);
- $newfile = $fs->create_file_from_storedfile(array('contextid' => $this->context->id, 'component' => 'mod_iassign', 'filearea' => 'exercise', 'itemid' => $id_), $source_file);
- $updateentry = new stdClass();
- $updateentry->id = $id_;
- $updateentry->filesid = $id_;
-
- $DB->update_record("iassign_statement", $updateentry);
- }
- }
- }
- $destiny_url = new moodle_url('/mod/iassign/view.php', array('id' => $this->context->id));
- $str_index = count($activities_list) > 1 ? 'import_activities_success' : 'import_activity_success';
- redirect($this->return, get_string($str_index, 'iassign'), null, \core\output\notification::NOTIFY_SUCCESS);
- exit;
- }
- function import_activity () {
- global $COURSE, $CFG, $USER, $DB, $OUTPUT, $PAGE;
- if (!has_capability('mod/iassign:runautoevaluate', $this->context, $USER->id))
- exit;
- print '<script>
- function verify_selection () {
- document.getElementById("msg-error").classList.add("d-none");
- var checkboxes = document.getElementsByName("statements[]");
- for (var i = 0; i < checkboxes.length; i++)
- if (checkboxes[i].checked) return true;
- document.getElementById("msg-error").classList.remove("d-none");
- return false;
- }
- </script>';
- $destiny_url = new moodle_url('/mod/iassign/view.php', array('id' => $this->cm->id, 'action' => 'import_activity_confirm'));
- print $OUTPUT->header();
- $this->print_main_menu();
- print '<h2 class="m-b-2 mt-4">' . get_string('import_activity', 'iassign') . '</h2>' . "\n";
- print '<form action="' . $destiny_url . '" method="post" onsubmit="return verify_selection()">' . "\n";
- $courses_as_teacher = $this->get_courses_enroled_as_teacher($USER->id);
- foreach ($courses_as_teacher as $course) {
- print '<a href="#item-' . $course->id . '" class="list-group-item list-group-item-action h5" style="margin-top: 1rem;" data-toggle="collapse" onclick=\'$(".fa-caret-right, .fa-caret-down", this).toggleClass("fa-caret-right").toggleClass("fa-caret-down");\' > <i class="fa fa-caret-right"></i> ' . $course->fullname . ' </a>' . "\n";
- print '<div class="collapse" style="padding: 0 1.5rem;" id="item-' . $course->id . '">' . "\n";
- $iassigns = $this->get_iassign_items_by_course($course->id);
- if ($iassigns) {
- foreach ($iassigns as $iassign) {
- print '<a href="#item-' . $course->id . '-' . $iassign->id . '" class="list-group-item list-group-item-action" data-toggle="collapse" onclick=\'$(".fa-caret-right, .fa-caret-down", this).toggleClass("fa-caret-right").toggleClass("fa-caret-down");\'><i class="fa fa-caret-right"></i> ' . $iassign->name . '</a>' . "\n";
- print '<div class="collapse" style="padding: 0 1.5rem;" id="item-' . $course->id . '-' . $iassign->id . '">' . "\n";
- $statements = $this->get_iassign_statement_by_iassign($iassign->id);
- print '<table class="table table-hover">' . "\n";
- if ($statements) {
- foreach ($statements as $statement) {
- print '<tr><td> <div class="form-check"> <input class="form-check-input" name="statements[]" type="checkbox" value="' . $statement->id . '" id="statement-' . $statement->id . '">' . "\n";
- print '<label class="form-check-label w-100" for="statement-' . $statement->id . '">' . $statement->name;
- print '</label></div></td></tr>' . "\n";
- }
- }
- else {
- print '<tr><td>' . get_string('no_activity', 'iassign') . '</td></tr>' . "\n";
- }
- print '</table></div>' . "\n";
- }
- }
- else {
- print '<div class="p-2">' . get_string('import_statement_empty', 'iassign') . '</div>' . "\n";
- }
- print '</div>' . "\n";
- }
- print '<div class="text-center"><button type="submit" class="btn btn-primary mt-2">Confirmar</button></div>' . "\n";
- print '<div class="text-center text-danger d-none" id="msg-error">' . get_string('import_statement_no_exercise', 'iassign') . '</div>' . "\n";
- print "</form>\n";
- print $OUTPUT->footer();
- }
- function get_iassign_items_by_course ($courseid) {
- global $DB;
- return $DB->get_records("iassign", array("course" => $courseid));
- }
- function get_iassign_statement_by_iassign ($iassignid) {
- global $DB;
- return $DB->get_records("iassign_statement", array("iassignid" => $iassignid));
- }
- function get_courses_enroled_as_teacher($userid) {
- $all_enroled = enrol_get_users_courses($userid);
- $return = array();
- foreach ($all_enroled as $enroled) {
- $context_course = context_course::instance($enroled->id);
- if (has_capability('mod/iassign:runautoevaluate', $context_course, $userid, false) ) {
- array_push($return, $enroled);
- }
- }
- return $return;
- }
-
-
- function all_submissions () {
- global $COURSE, $CFG, $USER, $DB, $OUTPUT, $PAGE;
- if (!has_capability('mod/iassign:runautoevaluate', $this->context, $USER->id))
- exit;
- print $OUTPUT->header();
- $this->print_main_menu();
- $id = $this->cm->id;
- $param_aux = "id=" . $id . "&userid_iassign=" . $USER->id;
- $enderecoPOST = "" . $CFG->wwwroot . "/mod/iassign/view.php?" . $param_aux;
- print '
- <div class="modal" id="modalConfirm" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
- <div class="modal-dialog modal-dialog-centered" role="document">
- <div class="modal-content">
- <div class="modal-header">
- <h5 class="modal-title" id="exampleModalLongTitle">' . get_string('delete', 'iassign') . '</h5>
- <button type="button" class="close" data-dismiss="modal" aria-label="Close">
- <span aria-hidden="true">×</span>
- </button>
- </div>
- <div class="modal-body">' . get_string('all_submissions_manager_confirm', 'iassign') . '</div>
- <div class="modal-footer">
- <button type="button" onclick="confirm_delete()" class="btn btn-primary">'.get_string('confirm', 'iassign').'</button>
- <button type="button" class="btn btn-secondary" data-dismiss="modal">'.get_string('cancel', 'iassign').'</button>
- </div>
- </div>
- </div>
- </div>';
- print '
- <script>
- var sub_type;
- var sub_item;
- var sub_el;
- var sub_exercise;
- function delete_submission (type, item, el, exercise = 0) {
- sub_type = type;
- sub_item = item;
- sub_exercise = exercise;
- sub_el = el.closest("tr");
- if (!sub_el) sub_el = el.closest("a");
- $("#modalConfirm").modal();
- }
- function confirm_delete () {
- var url = "'.$enderecoPOST.'&action=delete_submissions";
- var xhttp = new XMLHttpRequest();
- xhttp.open("GET", url + "&type=" + sub_type + "&item=" + sub_item + "&exercise=" + sub_exercise, true);
- xhttp.send();
- $("#modalConfirm").modal("hide");
- if ($(sub_el).attr("href"))
- $($(sub_el).attr("href")).remove();
- if (sub_el) sub_el.remove();
- }
- function download_submission(type, item, exercise = 0, iassign = 0) {
- var url = "'.$enderecoPOST.'&action=download_submissions";
- url += "&type=" + type + "&item=" + item + "&exercise=" + exercise + "&iassign=" + iassign;
- document.location = url;
- }
- function open_submission(item) {
- var url = "'.$enderecoPOST.'&action=open_individual_submission&item=" + item;
- var poupup = window.open(url, "popup", "width=900,height=900");
- }
- </script>' . chr(13);
-
- $iassignid = optional_param('iassignid', NULL, PARAM_TEXT);
- $exercises_list = $DB->get_records("iassign_statement", array("iassignid" => $iassignid));
- print '<h2 class="m-b-2 mt-5">' . get_string('all_submissions_manager', 'iassign') . '';
- print '<i onclick="download_submission(\'block\', 0, 0, '.$iassignid.')" class="fa fa-download" style="float: right; color: #1fa67a; font-size: 1.5rem; cursor: pointer; margin-left: 1rem; margin-top: .2rem;" aria-hidden="true"></i> </h2>';
-
- $params_temp = array('shortname' => 'student');
- $role = $DB->get_record_sql("SELECT s.id, s.shortname FROM {role} s WHERE s.shortname = :shortname", $params_temp);
- $context = context_course::instance($this->course->id);
- $params_temp = array('contextid' => $context->id, 'roleid' => $role->id);
- $students_list = $DB->get_records_sql(
- "SELECT s.userid, a.firstname, a.lastname FROM {role_assignments} s, {user} a " . " WHERE s.contextid = :contextid AND s.userid = a.id AND s.roleid = :roleid " . " ORDER BY a.firstname ASC,a.lastname ASC", $params_temp);
- print '<div>';
- foreach ($exercises_list as $exercise) {
- $submissions_list = $DB->get_records("iassign_allsubmissions", array("iassign_statementid" => $exercise->id));
- $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $exercise->iassign_ilmid));
- print '
- <a href="#item-'.$exercise->id.'" class="list-group-item list-group-item-action h4" style="margin-top: 1rem;" data-toggle="collapse" onclick=\'$(".fa-caret-right, .fa-caret-down", this).toggleClass("fa-caret-right").toggleClass("fa-caret-down");\' > <i class="fa fa-caret-right"></i> '
- . $exercise->name
- . ' - ' . $iassign_ilm->name
- . '<i class="fa fa-times" onclick="event.stopPropagation(); delete_submission(\'exercise\', '
- . $exercise->id .', this)" style="color:#C62828; cursor: pointer; font-size: 1.5rem; float: right; margin-left: .5rem;" aria-hidden="true"></i>'
- . '<i onclick="event.stopPropagation(); download_submission(\'exercise\', '
- . $exercise->id .')" class="fa fa-download" style="float: right; color: #1fa67a; font-size: 1.2rem; cursor: pointer; margin-left: 1rem; margin-top: .2rem;" aria-hidden="true"></i> '
- . '<span class="badge badge-primary badge-pill" style="float: right;">' . count($submissions_list) . '</span>'
- . '</a>';
- print '<div class="collapse" style="padding: 0 1.5rem;" id="item-'.$exercise->id.'">';
- foreach ($students_list as $student) {
- $total = 0;
- $student_submissions = [];
- foreach ($submissions_list as $submission) {
- if ($submission->userid == $student->userid) {
- $student_submissions[] = $submission;
- $total++;
- }
- }
- print '<a href="#item-'.$exercise->id.'-'.$student->userid.'" class="list-group-item list-group-item-action" data-toggle="collapse" onclick=\'$(".fa-caret-right, .fa-caret-down", this).toggleClass("fa-caret-right").toggleClass("fa-caret-down");\'>
- <i class="fa fa-caret-right"></i> ' . $student->firstname . ' ' . $student->lastname
- . '<i class="fa fa-times" onclick="event.stopPropagation(); delete_submission(\'student\', '
- . $student->userid .', this, '.$exercise->id.')" style="color:#C62828; cursor: pointer; font-size: 1.5rem; float: right; margin-left: .5rem;" aria-hidden="true"></i>'
- . '<i onclick="event.stopPropagation(); download_submission(\'student\', '.$student->userid.', '.$exercise->id.')" class="fa fa-download" style="float: right; color: #1fa67a; font-size: 1.3rem; cursor: pointer; margin-left: 1rem; margin-top: .1rem;" aria-hidden="true"></i> '
- . '<span class="badge badge-primary badge-pill" style="float: right;">' . $total . '</span>'
- . ' </a>';
- print '<div class="collapse" style="padding-left: 5rem;padding-right: 5rem;" id="item-'.$exercise->id.'-'.$student->userid.'">';
- print '<table class="table table-striped table-hover"><thead>
- <tr>
- <th scope="col">#</th>
- <th scope="col">'.get_string('all_submissions_manager_date', 'iassign').'</th>
- <th scope="col">'.get_string('grade_student', 'iassign').'</th>
- <th scope="col">'.get_string('config_param_actions', 'iassign').'</th>
- </tr>
- </thead><tbody>';
- $i = 1;
- foreach ($student_submissions as $individual) {
- $date = new DateTime();
- $date->setTimestamp($individual->timecreated);
- print '<tr>';
- print '<td>' . ($i++) . '</td>';
- print '<td>' . date_format($date, 'd/m/Y H:i:s') . '</td>';
- print '<td>' . $individual->grade . '</td>';
- print '<td>
- <i onclick="open_submission('.$individual->id.')" class="fa fa-external-link" style="color:#1177d1; cursor: pointer; font-size: 1.2rem; margin-right: .5rem;" aria-hidden="true"></i>
- <i onclick="download_submission(\'individual\', '.$individual->id.')" class="fa fa-download" style="color: #1fa67a; font-size: 1.2rem; cursor: pointer; margin-right: .5rem;" aria-hidden="true"></i>
- <i class="fa fa-times" onclick="delete_submission(\'individual\', '.$individual->id.', this)" style="color:#C62828; cursor: pointer; font-size: 1.5rem; " aria-hidden="true"></i></td>';
- print " </tr>\n";
- }
- print '</tbody></table>';
-
- print '</div>';
- }
- print '</div>';
- }
- print '</div>';
- print $OUTPUT->footer();
- }
-
- function auto_evaluate () {
- global $COURSE, $CFG, $USER, $DB, $OUTPUT, $PAGE;
- if (!has_capability('mod/iassign:runautoevaluate', $USER->context, $USER->id))
- exit;
- $actual_link = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
- $PAGE->navbar->add(get_string('auto_evaluate_title', 'iassign'), $actual_link);
-
- $iassignid = optional_param('iassignid', NULL, PARAM_TEXT);
- $exercises_list = $DB->get_records("iassign_statement", array("iassignid" => $iassignid));
-
- $params_temp = array('shortname' => 'student');
- $role = $DB->get_record_sql("SELECT s.id, s.shortname FROM {role} s WHERE s.shortname = :shortname", $params_temp);
- $context = context_course::instance($this->course->id);
- $params_temp = array('contextid' => $context->id, 'roleid' => $role->id);
- $students_list = $DB->get_records_sql(
- "SELECT s.userid, a.firstname, a.lastname FROM {role_assignments} s, {user} a " .
- " WHERE s.contextid = :contextid AND s.userid = a.id AND s.roleid = :roleid " .
- " ORDER BY a.firstname ASC,a.lastname ASC", $params_temp);
- print $OUTPUT->header();
- $this->print_main_menu();
- print '<div class="mt-5 mb-4"><div>' . get_string('auto_evaluate_select', 'iassign') . '</div>';
- print '<ul style="list-style-type: none; margin: 1em;">';
- foreach ($exercises_list as $exercise) {
- $matches = [];
- preg_match('/[0-9]*\.?[0-9]*/', $exercise->name, $matches, PREG_OFFSET_CAPTURE);
- $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $exercise->iassign_ilmid));
- if ($iassign_ilm && $iassign_ilm->reevaluate == 1) {
- if ($matches[0][0]) {
- print '<li id="li-item-'.$exercise->id.'"><input data-iditem="'.$matches[0][0].'" data-exercise="'.$exercise->id.'" class="form-check-input" type="checkbox" id="ex_'.$exercise->id.'"><label id="label_ex_'.$exercise->id.'" for="ex_'.$exercise->id.'">' . $exercise->name . '</label></li>';
- } else {
- print '<li id="li-item-'.$exercise->id.'"><input data-iditem="('.$exercise->id.')" data-exercise="'.$exercise->id.'" class="form-check-input" type="checkbox" id="ex_'.$exercise->id.'"><label id="label_ex_'.$exercise->id.'" for="ex_'.$exercise->id.'">(' . $exercise->id . ') - ' . $exercise->name . '</label></li>';
- }
- } else {
- if ($matches[0][0]) {
- print '<li id="li-item-'.$exercise->id.'"> <i onmouseenter="$(\'#li-item-'.$exercise->id.'\').find(\'i\').tooltip(\'show\');" class="fa fa-times without-reevaluator" style="font-size: 1.1em;color: red;margin-bottom: .7em;margin-left: -1.3em;margin-right: .58em;" data-toggle="tooltip" data-original-title="'.get_string('auto_evaluate_missing', 'iassign').'"></i>' . $exercise->name . '</li>';
- } else {
- print '<li id="li-item-'.$exercise->id.'"> <i onmouseenter="$(\'#li-item-'.$exercise->id.'\').find(\'i\').tooltip(\'show\');" class="fa fa-times without-reevaluator" style="font-size: 1.1em;color: red;margin-bottom: .7em;margin-left: -1.3em;margin-right: .58em;" data-toggle="tooltip" data-original-title="'.get_string('auto_evaluate_missing', 'iassign').'"></i>(' . $exercise->id . ') - ' . $exercise->name . '</li>';
- }
- }
- }
- print '</ul>
- <center>
- <button class="btn btn-primary" onclick="start_evaluation()" id="button_start">'.get_string('auto_evaluate_start', 'iassign').'</button>
- <button class="btn btn-danger" disabled="disabled" onclick="stop_evaluation()" id="button_stop">'.get_string('auto_evaluate_stop', 'iassign').'</button>
- <div id="evaluate_message" style="color: red"></div>
- <div id="evaluate_alerts"></div>
- <div>
- <div id="progress_bar" class="progress" style="width: 40em; height: 30px; margin-top: 1em; display: none; text-align: left;">
- <div class="progress-bar progress-bar-striped progress-bar-animated" role="progressbar" style="width: 1%; height: 100%;" aria-valuenow="0" aria-valuemin="1" aria-valuemax="100">1%</div>
- </div>
- </center>';
- print ' </div>' . "\n";
- print ' <script>' . "\n";
- print '// #submissions = ' . count($exercises_list) . "\n";
- print ' var submissions = [';
-
- foreach ($exercises_list as $exercise) {
- $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $exercise->iassign_ilmid));
- print '
- {
- "exerciseid": "' . $exercise->id . '",
- "grade": ' . $exercise->grade . ',
- "ilm": "' . $CFG->wwwroot . '/mod/iassign/' . $iassign_ilm->file_jar . $iassign_ilm->file_class . '",
- "submited": [';
- $params_temp = array('iassign_statementid' => $exercise->id);
- $submited = $DB->get_records_sql(
- "SELECT s.userid, s.grade FROM {iassign_submission} s " .
- " WHERE s.iassign_statementid = :iassign_statementid", $params_temp);
- foreach ($submited as $ss) {
- print($ss->userid . ',');
- }
- print '],';
- print '"allgrades": [';
- foreach ($submited as $ss) {
- print( $ss->grade . ',');
- }
- print ']
- },';
- }
- print " ];\n";
- print '
- var total_submissions = 0;
- var selected_exercises;
- var count_steps;
- var value_by_step;
- var stoped = false;
- var time_interval = 5000;
- var var_interval;
- function add_hover_th (id_th, id_li) { //AJAX
- $("#" + id_th).hover(function() {
- $("#" + id_li).css("background-color", "#d9d8d8");
- $(this).css("background-color", "#d9d8d8");
- }, function() {
- $("#" + id_li).css("background-color", "");
- $(this).css("background-color", "");
- });
- }
- function start_evaluation () {
- stoped = false;
- //AJAX
- $("#progress_bar").css("display", "none");
- $("#evaluate_message").text("");
- $("#evaluate_alerts").text("");
- $(".added-col").remove();
- $(".progress-bar").addClass("progress-bar-animated progress-bar-striped").text("0%").css("width", "1%");
- selected_exercises = [];
- var c = 0;
- for (var i = 0; i < exercises.length; i++) {
- if ($("#ex_"+exercises[i]).is(":checked") == true) {
- selected_exercises[c++] = exercises[i];
- }
- }
- if (selected_exercises.length == 0) {
- $("#evaluate_message").text("'.get_string('auto_evaluate_select_msg', 'iassign').'");
- return;
- } else {
- $("input:checkbox").attr("disabled", true); //AJAX
- for (var i = 0; i < selected_exercises.length; i++) {
- var desc = $("#ex_" + selected_exercises[i]).data("iditem");
- //AJAX
- $("#cols-exercises").append( $("<th />", { class : "added-col text-center", text : desc, id : "th-item-"+selected_exercises[i] }));
- $("#table-results tbody tr").each(function(e) {
- var id_t = "std_" + $(this).data("student") + "_ex_" + selected_exercises[i];
- $(this).append( $("<td />", {class : "added-col text-center", id : id_t, text : "", data : {"student": $(this).data("student"), "exercise": selected_exercises[i]} }));
- });
- add_hover_th("th-item-"+selected_exercises[i], "li-item-"+selected_exercises[i]);
- }
- //AJAX
- $("#button_start").prop("disabled", true);
- $("#button_stop").prop("disabled", false);
- $("#progress_bar").css("display", "block");
- }
- total_submissions = selected_exercises.length * students.length;
- count_steps = 0;
- value_by_step = 100/total_submissions;
- actual_exercise = 0;
- actual_student = 0;
- actual_submission = 0;
- get_original_propositions();
- var_interval = setInterval(verifyBreak, time_interval);
- } // function start_evaluation()
- var actual_exercise;
- var actual_student;
- var actual_submission;
- var actual_answer_url; // to provide the current student answer (to "iassing_integration_functios.js" of iLM
- function run_individual_evaluation () {
- if (stoped) return;
- // Verify if student really sent his answer
- var found = false;
- for (var j = 0; j < submissions.length; j++) {
- if (submissions[j].exerciseid == selected_exercises[actual_exercise]) {
- for (var k = 0; k < submissions[j].submited.length; k++) {
- if (students[actual_student] == submissions[j].submited[k]) {
- found = true;
- break;
- }
- }
- break;
- }
- }
- if (found == false) {
- postResultAutoEval();
- } else {
- // If it was sent, search it...
- var final_url = "";
- var student_answer = "' . $CFG->wwwroot . "/mod/iassign/view.php?action=get_student_submission&id=" . $this->cm->id . '" + "&iassign_student=" + students[actual_student] + "&iassign_exercise=" + selected_exercises[actual_exercise];
- for (var j = 0; j < submissions.length; j++) {
- if (submissions[j].exerciseid == selected_exercises[actual_exercise]) {
- final_url = submissions[j].ilm;
- break;
- }
- }
- final_url += "?iLM_PARAM_AssignmentURL=true&iLM_PARAM_Assignment=" + encodeURIComponent(student_answer) + "&iLM_PARAM_TeacherAutoEval=true";
- actual_answer_url = student_answer; // to provide the current student answer (to "iassing_integration_functios.js" of iLM)
- window.frames["ifrm"].location=final_url;
- }
- } // function run_individual_evaluation()
- var break_student = -1;
- var break_exercise = -1;
- function verifyBreak () {
- if (actual_student == break_student && actual_exercise == break_exercise) {
- postResultAutoEval(-6);
- break_student = -1;
- break_exercise = -1;
- return;
- } else {
- break_student = actual_student;
- break_exercise = actual_exercise;
- }
- }
- // This function is called by the iLM to get the student s answer (to compare with re-evaluation)
- function getStudentAnswerURL () {
- return actual_answer_url; // to provide the current student answer (to "iassing_integration_functios.js" of iLM)
- }
- // This function is called by the iLM!!!
- function getAutoEvalOriginalData () {
- return original_propositions[actual_exercise];
- }
- function updateProgressBar () {
- if (stoped) return;
- var temp = (count_steps * value_by_step)|0;
- count_steps++;
- temp = temp > 100 ? 100 : temp;
- $(".progress-bar").css("width", temp + "%").text(temp + "%");
- if (temp >= 100) {
- $(".progress-bar").removeClass("progress-bar-animated progress-bar-striped");
- $("#button_start").prop("disabled", false);
- $("#button_stop").prop("disabled", true);
- $("input:checkbox").attr("disabled", false);
- clearInterval(var_interval);
- }
- }
- // Process the re-evaluated "grade" - DEVELOPER: here, do NOT use apostrophe!
- // The iLM method "getiLMContent()" must, after re-evaluate getting "new_grade", call this with "postResultAutoEval(new_grade)"
- function postResultAutoEval (grade = null) {
- var id_t = "std_" + students[actual_student] + "_ex_" + selected_exercises[actual_exercise];
- if (grade == null) {
- $("#"+id_t).html(\'<i class="fa fa-circle-o text-muted" aria-hidden="true" style="font-size: 2em;" data-toggle="tooltip" data-original-title="'.get_string('not_post', 'iassign').'"></i>\');
- $("#"+id_t).find(\'[data-toggle="tooltip"]\').tooltip();
- } else {
- // Verify if the re-evaluation grade is the of that one registered:
- var actual_value = 0;
- var actual_student_grade = 0;
- for (var k = 0; k < submissions.length; k++) {
- if (submissions[k].exerciseid == selected_exercises[actual_exercise]) {
- actual_value = submissions[k].grade;
- for (var h = 0; h < submissions[k].submited.length; h++) {
- if (submissions[k].submited[h] == students[actual_student]) {
- actual_student_grade = submissions[k].allgrades[h];
- break;
- }
- }
- break;
- }
- }
- // @FeedbackConvention
- if (grade < 0) {
- switch (grade) {
- case -1:
- // Test-cases are empty:
- $("#"+id_t).html(\'<i data-toggle="modal" class="details-button" data-target="#exampleModalCenter"><i class="fa fa-times-circle-o fa-6" aria-hidden="true" style="color: #ef5151; font-size: 2em; cursor: pointer;" data-toggle="tooltip" data-original-title="'.get_string('auto_evaluate_msg_t_empty_cases', 'iassign').'"></i></i>\');
- var mm = actual_exercise;
- $("#"+id_t).find(".details-button").click(function(e) {
- $(".modal-body").html(\'<table class="table"><tr><td style="width: 30%;">'.get_string('exercise', 'iassign').':</td><td>\'+$("#label_ex_"+selected_exercises[mm]).text()+\'</td></tr><tr><td style="width: 30%;">'.get_string('student', 'iassign').'</td><td>\'+$(this).closest("tr").find(".student-name").text()+\'</td></tr><tr><td style="width: 30%;" colspan="2"><b>'.get_string('auto_result', 'iassign').'</b><br>'.get_string('auto_evaluate_msg_empty_cases', 'iassign').'</td></tr></table>\');
- });
- break;
- case -2:
- // Test-cases were manually altered by the student (fraud!):
- $("#"+id_t).html(\'<i data-toggle="modal" class="details-button" data-target="#exampleModalCenter"><i class="fa fa-times-circle-o fa-6" aria-hidden="true" style="color: #ef5151; font-size: 2em; cursor: pointer;" data-toggle="tooltip" data-original-title="'.get_string('auto_evaluate_msg_t_diff_cases', 'iassign').'"></i></i>\');
- var mm = actual_exercise;
- $("#"+id_t).find(".details-button").click(function(e) {
- $(".modal-body").html(\'<table class="table"><tr><td style="width: 30%;">'.get_string('exercise', 'iassign').':</td><td>\'+$("#label_ex_"+selected_exercises[mm]).text()+\'</td></tr><tr><td style="width: 30%;">'.get_string('student', 'iassign').'</td><td>\'+$(this).closest("tr").find(".student-name").text()+"</td></tr><tr><td style=\'width: 30%;\' colspan=\'2\'><b>'.get_string('auto_result', 'iassign').'</b><br>'.get_string('auto_evaluate_msg_diff_cases', 'iassign').'</td></tr></table>");
- });
- //AJAX
- $.ajax({
- dataType: "html",
- url: "'.$CFG->wwwroot.'/mod/iassign/view.php?action=post_auto_eval_result&id='.$this->cm->id.'&iassign_exercise="+selected_exercises[actual_exercise]+"&student="+students[actual_student]+"&grade=0",
- success: function(d) {} });
- break;
- case -5:
- // Execution failed:
- $("#"+id_t).html(\'<i data-toggle="modal" class="details-button" data-target="#exampleModalCenter"><i class="fa fa-times-circle-o fa-6" aria-hidden="true" style="color: #ef5151; font-size: 2em; cursor: pointer;" data-toggle="tooltip" data-original-title="'.get_string('auto_evaluate_msg_t_fail', 'iassign').'"></i></i>\');
- var mm = actual_exercise;
- //AJAX
- $("#"+id_t).find(".details-button").click(function(e) {
- $(".modal-body").html(\'<table class="table"><tr><td style="width: 30%;">'.get_string('exercise', 'iassign').':</td><td>\'+$("#label_ex_"+selected_exercises[mm]).text()+\'</td></tr><tr><td style="width: 30%;">'.get_string('student', 'iassign').'</td><td>\'+$(this).closest("tr").find(".student-name").text()+\'</td></tr><tr><td style="width: 30%;" colspan="2"><b>'.get_string('auto_result', 'iassign').'</b><br>'.get_string('auto_evaluate_msg_fail', 'iassign').'</td></tr></table>\');
- });
- break;
- case -6: // iLM not answering was detected in "verifyBreak()"
- // The iLM are not answering:
- //AJAX
- $("#"+id_t).html(\'<i data-toggle="modal" class="details-button" data-target="#exampleModalCenter"><i class="fa fa-clock-o fa-6" aria-hidden="true" style="color: orange; font-size: 2em; cursor: pointer;" data-toggle="tooltip" data-original-title="'.get_string('auto_evaluate_title_time', 'iassign').'"></i></i>\');
- $("#"+id_t).find(".details-button").click(function(e) {
- $(".modal-body").html(\'<table class="table"><tr><td style="width: 30%;">' . get_string('auto_evaluate_msg_time', 'iassign') . '</td></tr></table>\');
- });
- break;
- }
- //AJAX
- $("#"+id_t).find(\'[data-toggle="tooltip"]\').tooltip();
- } else {
- console.log((grade), (actual_student_grade));
- if ((grade) == (actual_student_grade)) {
- $("#"+id_t).html(\'<i class="fa fa-check-circle-o text-success" aria-hidden="true" style="font-size: 2em;" data-toggle="tooltip" data-original-title="'.get_string('auto_evaluate_ok', 'iassign').'"></i>\');
- } else { // Notas diferem:
- $("#"+id_t).html(\'<i data-toggle="modal" class="details-button" data-target="#exampleModalCenter"><i class="fa fa-exclamation-circle text-warning" aria-hidden="true" style="font-size: 2em; cursor: pointer;" data-toggle="tooltip" data-original-title="'.get_string('auto_evaluate_different_grades', 'iassign').'"></i></i>\');
- var mm = actual_exercise;
- //AJAX
- $("#"+id_t).find(".details-button").click(function(e) {
- $(".modal-body").html(\'<table class="table"><tr><td style="width: 30%;">'.get_string('exercise', 'iassign').':</td><td>\'+$("#label_ex_"+selected_exercises[mm]).text()+\'</td></tr><tr><td style="width: 30%;">'.get_string('student', 'iassign').'</td><td>\'+$(this).closest("tr").find(".student-name").text()+\'</td></tr><tr><td style="width: 30%;">'.get_string('auto_evaluate_grade_registered', 'iassign').'</td><td>\'+(actual_student_grade*grade)+\'</td></tr><tr><td style="width: 30%;"><b>'.get_string('auto_evaluate_grade_new', 'iassign').'</b></td><td>\'+(grade * actual_value)+\'</td></tr><tr><td colspan="2">'.get_string('auto_evaluate_msg_grade_update', 'iassign').'</tr></table>\');
- });
- //AJAX
- // Send to the endpoint the post_auto_eval_result to verify:
- $.ajax({
- dataType: "html",
- url: "' . $CFG->wwwroot . '/mod/iassign/view.php?action=post_auto_eval_result&id=' . $this->cm->id . '&iassign_exercise=" + selected_exercises[actual_exercise] + "&student=" + students[actual_student] + "&grade=" + (grade),
- success: function(d) {}
- });
- }
- //AJAX
- $("#"+id_t).find(\'[data-toggle="tooltip"]\').tooltip();
- }
- }
- updateProgressBar();
- // Does it must continue in the same exercise or stop?
- if (actual_student < students.length) {
- actual_student++;
- run_individual_evaluation();
- } else {
- actual_student = 0;
- // Does it go to next exercise or is it finished?
- if (actual_exercise < selected_exercises.length) {
- actual_exercise++;
- run_individual_evaluation();
- } else {
- //AJAX
- $("#evaluate_alerts").text("' . get_string('auto_evaluate_finished', 'iassign') . '");
- }
- }
- }
- var original_propositions;
- function get_original_propositions () {
- original_propositions = [];
- var count = 0;
- for (var i = 0; i < exercises.length; i++) {
- if ($("#ex_"+exercises[i]).is(":checked") == true) {
- //AJAX
- $.ajax({
- dataType: "html",
- url: "' . $CFG->wwwroot . '/mod/iassign/view.php?action=get_teacher_exercise&id=' . $this->cm->id . '&iassign_exercise="+exercises[i],
- success: function(d) { // variable "d" has the iLM content
- original_propositions[count] = d; // exercise original content
- count++;
- if (count == selected_exercises.length) {
- run_individual_evaluation();
- }
- }
- });
- }
- }
- }
- function stop_evaluation () {
- stoped = true;
- //AJAX
- $("#button_start").prop("disabled", false);
- $("#button_stop").prop("disabled", true);
- $(".progress-bar").removeClass("progress-bar-animated progress-bar-striped");
- $("input:checkbox").attr("disabled", false);
- $("#evaluate_alerts").text("' . get_string('auto_evaluate_stopped', 'iassign') . '");
- clearInterval(var_interval);
- }
- var exercises = [ ';
- foreach ($exercises_list as $exercise) {
- print $exercise->id . ',';
- }
- print ' ];';
- print ' var students = [ ';
- foreach ($students_list as $student) {
- print $student->userid . ',';
- }
- print '];';
- print ' var ilms = [';
- foreach ($exercises_list as $exercise) {
- $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $exercise->iassign_ilmid));
- print "'" . $CFG->wwwroot . "/mod/iassign/" . $iassign_ilm->file_jar . "/" . $iassign_ilm->file_class . "',";
- }
- print ']';
- print '</script>';
- print '
- <div class="modal fade" id="exampleModalCenter" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
- <div class="modal-dialog modal-dialog-centered" role="document">
- <div class="modal-content">
- <div class="modal-header">
- <h5 class="modal-title" id="exampleModalLongTitle">' . get_string('auto_evaluate_details', 'iassign') . '</h5>
- <button type="button" class="close" data-dismiss="modal" aria-label="Close">
- <span aria-hidden="true">×</span>
- </button>
- </div>
- <div class="modal-body">
- ...
- </div>
- <div class="modal-footer">
- <button type="button" class="btn btn-secondary" data-dismiss="modal">' . get_string('close', 'iassign') . '</button>
- </div>
- </div>
- </div>
- </div>';
- print '<iframe name="ifrm" style="position: absolute; top: -1000px;"></iframe>';
- print '<table id="table-results" class="table table-hover m-t-1">
- <thead>
- <tr id="cols-exercises">
- <th scope="col" style="width: 30rem;">'.get_string('students', 'iassign').'</th>
- </tr>
- </thead>
- <tbody>';
- foreach ($students_list as $student) {
- $user = $DB->get_record('user', array('id' => $student->userid));
- $avatar = new user_picture($user);
- $avatar->courseid = $COURSE->id;
- $avatar->link = true;
- print ' <tr data-student="' . $student->userid . '">
- <td>' . $OUTPUT->render($avatar) . ' <span class="student-name">' . $user->firstname . ' ' . $user->lastname . '</span></td>
- </tr>' . "\n";
- }
- print " </tbody>
- </table>\n";
- print $OUTPUT->footer();
- }
-
- function move_activity () {
- global $USER, $CFG, $DB, $COURSE;
- $iassign_id = optional_param('iassign_current', NULL, PARAM_TEXT);
- $iassign_destiny = optional_param('iassign_destiny', NULL, PARAM_TEXT);
- $update_entry_new_iassign = new stdClass();
- $update_entry_new_iassign->id = $iassign_id;
- $update_entry_new_iassign->iassignid = $iassign_destiny;
-
- $DB->update_record("iassign_statement", $update_entry_new_iassign);
-
- $c_i = context_module::instance($this->cm->id);
- $ret = get_coursemodule_from_id("iassign", $c_i->instanceid);
- $course_module_info = $DB->get_record("course_modules", array("course" => $COURSE->id, "module" => $ret->module, "instance" => $iassign_destiny));
- $path_module = context_course::instance($COURSE->id);
- $context_file = $DB->get_record_sql('SELECT * FROM {context} WHERE instanceid="' . $course_module_info->id . '" AND path like "'.$path_module->path.'%"');
- $course_module = get_coursemodule_from_instance('iassign', $iassign_destiny);
- if ($context_file) {
- $id_context = $context_file->id;
- $iassign_statement = $DB->get_record("iassign_statement", array("id" => $iassign_id));
- $fs = get_file_storage();
- $context = context_module::instance($USER->cm);
-
-
- $files = $fs->get_area_files($context->id, 'mod_iassign', 'exercise', $iassign_statement->id);
- foreach ($files as $value) {
- if ($value->get_filename() != ".") {
-
-
- $fs->delete_area_files(context_module::instance($this->cm->id)->id, 'mod_iassign', 'exercise', $value->get_itemid());
- $destiny_context = context_module::instance($course_module->id);
- $newfile = $fs->create_file_from_string(array('contextid' => $destiny_context->id, 'component' => 'mod_iassign', 'filearea' => 'exercise', 'itemid' => $iassign_id, 'filepath' => '/', 'filename' => $value->get_filename()), $value->get_content());
- $updateentry = new stdClass();
- $updateentry->id = $iassign_id;
- $updateentry->filesid = $iassign_id;
- $DB->update_record("iassign_statement", $updateentry);
-
- break;
- }
- }
- }
-
- $destiny_url = new moodle_url('/mod/iassign/view.php', array('id' => $course_module->id));
- redirect($this->return, get_string('moved_activity', 'iassign').' <a href="'.$destiny_url.'">' . get_string('move_activity_access', 'iassign') . '\'' . $course_module->name . '\'</a>', null, \core\output\notification::NOTIFY_SUCCESS);
- exit;
- }
-
- function duplicate_activity () {
- global $USER, $CFG, $COURSE, $DB, $OUTPUT;
- $id = $this->cm->id;
- $iassignid = optional_param('iassign_current', NULL, PARAM_TEXT);
- $context = context_module::instance($this->cm->id);
- $contextuser = context_user::instance($USER->id);
-
- $iassign_statement = $DB->get_record("iassign_statement", array("id" => $iassignid));
-
- $id_source_copy = $iassign_statement->id;
- $iassign_statement->id=0;
-
- $iassign_statement->name = get_string('duplicate_iassign_prefix', 'iassign') . ' ' . $iassign_statement->name;
-
- $author = $DB->get_record("user", array('id' => $USER->id));
- $iassign_statement->author_modified_name = $author->firstname . ' ' . $author->lastname;
- $iassign_statement->author_modified = $iassign_statement->author_modified_name;
-
- if ($id_ = $DB->insert_record("iassign_statement", $iassign_statement)) {
-
- $fs = get_file_storage();
-
- $files = $fs->get_area_files($context->id, 'mod_iassign', 'exercise', $id_source_copy);
- foreach ($files as $value) {
- if ($value->get_filename() != ".") {
- $last_id = $DB->get_record_sql('SELECT itemid FROM {files} WHERE component="mod_iassign" ORDER BY itemid DESC LIMIT 1')->itemid;
-
- $newfile = $fs->create_file_from_storedfile(array('contextid' => $context->id, 'component' => 'mod_iassign', 'filearea' => 'exercise', 'itemid' => $id_), $value);
- $updateentry = new stdClass();
- $updateentry->id = $id_;
-
- $updateentry->filesid = $id_;
-
- $DB->update_record("iassign_statement", $updateentry);
- }
- }
- }
-
- iassign_log::add_log('duplicate_iassign_exercise', 'name: ' . $author->firstname, $id_, $this->cm->id);
- $this->return_home_course('duplicated_activity');
- exit;
- }
-
- function add_comment () {
- global $USER, $DB;
- $submission_comment = optional_param('submission_comment', NULL, PARAM_TEXT);
- $comment = false;
- if ($submission_comment)
- $comment = $this->write_comment_submission();
- $id_submission = optional_param('iassign_submission_current', NULL, PARAM_TEXT);
- if (!$id_submission) {
- $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $this->activity->get_activity()->id, "userid" => $USER->id));
- if ($iassign_submission) {
- $id_submission = $iassign_submission->id;
- }
- }
- $content = $this->search_comment_submission($id_submission);
- ob_end_clean();
- header("Connection: close\r\n");
- header("Content-Encoding: none\r\n");
- header('Content-Type: text/html');
- ob_start();
- print $this->search_comment_submission($id_submission);
- $size = ob_get_length();
- header("Content-Length: $size");
- ob_end_flush();
- flush();
- ob_end_clean();
-
- $iassign_submission = $DB->get_record("iassign_submission", array("id" => $id_submission));
- $this->send_alert_new_comment($submission_comment, $iassign_submission->userid);
- }
-
- function send_alert_new_comment ($comment, $student_id = -1) {
- global $USER, $DB, $COURSE, $SITE;
- $subject = $COURSE->shortname . ": " . get_string('new_comment_mail_subject', 'iassign') . " ";
- $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $this->activity->get_activity()->iassign_ilmid));
- $subject .= $iassign_ilm->name . ' ' . get_string('new_comment_mail_at', 'iassign') . ' ' . get_string("iassign", "iassign") . '/Moodle';
-
- $text = "<p style='margin-top: 1rem;'>\n";
- $text .= "<a href=\"" . new moodle_url('/course/view.php', array('id' => $COURSE->id)) . "\">" . $COURSE->shortname . "</a> " . " ≫ \n";
- $modinfo = get_fast_modinfo($COURSE);
- for ($i = 0; $i < count($modinfo->sections); $i++) {
- if ($modinfo->get_section_info($i) && $modinfo->get_section_info($i)->id == $this->cm->section) {
- $url_curso = new moodle_url('/course/view.php', array('id' => $COURSE->id));
- $text .= "<a href=\"" . $url_curso . "#section-" . $modinfo->get_section_info($i)->section . "\">" . get_section_name($COURSE, $modinfo->get_section_info($i)->section) . "</a> ≫ \n";
- break;
- }
- }
- $iassign = $DB->get_record('iassign', array('id' => $this->activity->get_activity()->iassignid));
- $text .= "<a href=\"" . new moodle_url('/mod/iassign/view.php', array('id' => $this->cm->id)) . "\">" . $iassign->name . "</a> ≫ \n";
- $url_submissao = new moodle_url('/mod/iassign/view.php',
- array(
- 'id' => $this->cm->id,
- 'action' => 'viewsubmission',
- 'iassign_current' => $this->activity->get_activity()->id,
- 'userid_iassign' => $USER->id));
- $text .= "<a href=\"" . $url_submissao . "\">" . $this->activity->get_activity()->name . "</a></p>\n";
- $text .= "<div style='margin-left: .5rem;'>\n";
- $text .= get_string('new_comment_mail_course', 'iassign') . ": <a href=\"" . $url_curso . "\">" . $COURSE->fullname . "</a>\n";
- $text .= "</div><div style='margin-top: .3rem; margin-left: .5rem;'>\n";
- $text .= get_string('exercise', 'iassign') . ": <a href=\"" . $url_submissao . "\">" . $this->activity->get_activity()->name . "</a>\n";
- $text .= "</div><div style='margin-top: .3rem; margin-left: .5rem;'>\n";
- $text .= get_string('new_comment_mail_sent_by', 'iassign') . ': ' . "<a href=\"" .
- new moodle_url('/user/view.php', array('id' => $USER->id, 'course' => $COURSE->id)) . "\">" . $USER->firstname . " " . $USER->lastname . "</a>\n";
- $text .= " - " . userdate(time());
- $text .= "</div><div style='margin: 2rem;'>\n";
- $text .= $comment;
- $text .= "</div><div>\n";
- $text .= "<a href=\"" . $url_submissao . "#comments\">" . get_string('new_comment_mail_open_exercise', 'iassign') . "</a> | \n";
- $text .= "<a href=\"" . $url_submissao . "#comments\">" . get_string('new_comment_mail_answer', 'iassign') . "</a>\n";
- $text .= "</div>\n";
-
- $teachers = get_users_by_capability($this->context, 'mod/iassign:evaluateiassign');
- $userfrom = \core_user::get_noreply_user();
- if (has_capability('mod/iassign:evaluateiassign', $this->context, $USER->id)) {
-
- foreach ($teachers as $teacher) {
- if ($teacher->id != $USER->id) {
- email_to_user(
- $teacher,
- $USER->firstname . " " . $USER->lastname . " (via " . $SITE->shortname . ")",
- $subject,
- "",
- $text,
- '',
- '',
- false,
- $userfrom->email,
- 'Não responda a esta mensagem'
- );
- $message = new \core\message\message();
- $message->component = 'mod_iassign';
- $message->name = 'message';
- $message->userfrom = core_user::get_noreply_user();
- $message->userto = $teacher;
- $message->subject = $subject;
- $message->fullmessage = $text;
- $message->fullmessageformat = FORMAT_MARKDOWN;
- $message->fullmessagehtml = $text;
- $message->smallmessage = $subject;
- $message->notification = 1;
- $message->contexturl = $url_submissao . '#comments';
- $message->contexturlname = $this->activity->get_activity()->name;
- $messageid = message_send($message);
- }
- }
-
- $student = $DB->get_record('user', array('id' => $student_id));
- $formated_text = str_replace("viewsubmission", "view", $text);
- email_to_user(
- $student,
- $USER->firstname . " " . $USER->lastname . " (via " . $SITE->shortname . ")",
- $subject,
- "",
- $formated_text,
- '',
- '',
- false,
- $userfrom->email,
- 'Não responda a esta mensagem'
- );
- $url_student = new moodle_url('/mod/iassign/view.php',
- array(
- 'id' => $this->cm->id,
- 'action' => 'view',
- 'iassign_current' => $this->activity->get_activity()->id));
- $message = new \core\message\message();
- $message->component = 'mod_iassign';
- $message->name = 'message';
- $message->userfrom = core_user::get_noreply_user();
- $message->userto = $student;
- $message->subject = $subject;
- $message->fullmessage = $formated_text;
- $message->fullmessageformat = FORMAT_MARKDOWN;
- $message->fullmessagehtml = $formated_text;
- $message->smallmessage = $subject;
- $message->notification = 1;
- $message->contexturl = $url_student . '#comments';
- $message->contexturlname = $this->activity->get_activity()->name;
- $messageid = message_send($message);
- }
- else {
- foreach ($teachers as $teacher) {
- email_to_user(
- $teacher,
- $USER->firstname . " " . $USER->lastname . " (via " . $SITE->shortname . ")",
- $subject,
- "",
- $text,
- '',
- '',
- false,
- $userfrom->email,
- 'Não responda a esta mensagem'
- );
- $message = new \core\message\message();
- $message->component = 'mod_iassign';
- $message->name = 'message';
- $message->userfrom = core_user::get_noreply_user();
- $message->userto = $teacher;
- $message->subject = $subject;
- $message->fullmessage = $text;
- $message->fullmessageformat = FORMAT_MARKDOWN;
- $message->fullmessagehtml = $text;
- $message->smallmessage = $subject;
- $message->notification = 1;
- $message->contexturl = $url_submissao . '#comments';
- $message->contexturlname = $this->activity->get_activity()->name;
- $messageid = message_send($message);
- }
- }
- }
-
-
- function get_answer () {
- global $USER, $CFG, $DB, $OUTPUT;
- $id = $this->cm->id;
- $submission_comment = optional_param('submission_comment', NULL, PARAM_TEXT);
- $submission_ajax = optional_param('iLM_ajax', NULL, PARAM_TEXT);
- if ($submission_ajax == 1) ob_start();
- $comment = false;
- if ($submission_comment)
- $comment = $this->write_comment_submission();
-
- $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $this->activity->get_activity()->iassign_ilmid));
- $iassign = $DB->get_record("iassign", array("id" => $this->activity->get_activity()->iassignid));
-
- $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $this->activity->get_activity()->id, "userid" => $this->userid_iassign));
-
- $iLM_PARAM_ActivityEvaluation = optional_param('iLM_PARAM_ActivityEvaluation', 0, PARAM_INT);
- $iLM_PARAM_RealGrade = optional_param('iLM_PARAM_RealGrade', 0, PARAM_FLOAT);
-
- $iLM_PARAM_ArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_RAW);
- $MA_POST_Info = optional_param('MA_POST_Info', NULL, PARAM_FORMAT);
- $MA_POST_SystemData = optional_param('MA_POST_SystemData', NULL, PARAM_FORMAT);
- $return_get_answer = optional_param('return_get_answer', 0, PARAM_INT);
- $msg = '';
- if ($this->activity->get_activity()->store_all_submissions == 1) {
- $newentry = new stdClass();
- $newentry->iassign_statementid = $this->activity->get_activity()->id;
- $newentry->userid = $this->userid_iassign;
- $newentry->timecreated = time();
- $newentry->grade = round($iLM_PARAM_RealGrade, 2);
- $newentry->answer = $iLM_PARAM_ArchiveContent;
- $DB->insert_record("iassign_allsubmissions", $newentry);
- }
-
-
- $str_action = "view";
- if (strtolower($iassign_ilm->name) == "igeom") {
- }
- $title = get_string('evaluate_iassign', 'iassign');
- print $OUTPUT->header();
- print $OUTPUT->box_start();
-
-
-
-
- $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;
- $return_last = " <a href='" . $return . "'>" . iassign_icons::insert('return_home') . ' ' . get_string('return_iassign', 'iassign') . "</a>";
- $link_return = " <a href='" . $this->return . "'>" . iassign_icons::insert('home') . ' ' . get_string('activities_page', 'iassign') . "</a>";
- print '<table width=100% >';
- if ($iLM_PARAM_ArchiveContent == - 1 || empty($iLM_PARAM_ArchiveContent)) {
-
- $this->write_solution = 0;
-
- if ($comment)
- print '<tr><td colspan=2><br>' . get_string('empty_answer_post', 'iassign') . '</br>' . get_string('confirm_add_comment', 'iassign') . '</td>';
- else
- print '<tr><td colspan=2><br>' . get_string('empty_answer_post', 'iassign') . '</td>';
- print '<tr><td width=40% align=right>' . $return_last . ' ' . $link_return . '</td></tr>';
- } else {
- if ($iassign_ilm->evaluate == 1 && $this->activity->get_activity()->automatic_evaluate == 1) {
- if (intval($iLM_PARAM_ActivityEvaluation) == 1) {
-
-
- $this->write_solution = 1;
- $status = 3;
- $grade_student = $iLM_PARAM_RealGrade;
- $msg = '<tr><td colspan=2>' . iassign_icons::insert('feedback_correct') . '<br>' . get_string('get_answer_correct', 'iassign') . '</td>';
-
- $info = $iassign->name . " - " . $this->activity->get_activity()->name . " - " . get_string('feedback_correct', 'iassign') . " - " . get_string('grade_iassign', 'iassign') . ":" . $grade_student;
-
- $event = \mod_iassign\event\submission_created::create(array(
- 'objectid' => $this->iassign->id,
- 'context' => $this->context,
- 'other' => $info
- ));
- $event->add_record_snapshot('course', $this->course);
- $event->trigger();
- } else {
-
- $status = 2;
- $grade_student = $iLM_PARAM_RealGrade;
- $msg = '<tr><td colspan=2>' . iassign_icons::insert('feedback_incorrect') . '<br>' . get_string('get_answer_incorrect', 'iassign') . '</td>';
-
- $info = $iassign->name . " - " . $this->activity->get_activity()->name . " - " . get_string('feedback_incorrect', 'iassign') .
- ' - ' . get_string('grade_iassign', 'iassign') . $grade_student;
-
- $event = \mod_iassign\event\submission_created::create(array(
- 'objectid' => $this->iassign->id,
- 'context' => $this->context,
- 'other' => $info
- ));
- $event->add_record_snapshot('course', $this->course);
- $event->trigger();
- }
-
- if ($this->activity->get_activity()->show_answer == 0) {
- print '<tr><td width=60% ><strong>' . iassign_icons::insert('post') . get_string('get_answer', 'iassign') . '</strong></td>';
- print '<tr><td width=40% align=right>' . $return_last . ' ' . $link_return . '</td></tr>';
- print '<tr>';
-
- $info = $iassign->name . " - " . $this->activity->get_activity()->name . " - " . get_string('get_answer', 'iassign');
-
- $event = \mod_iassign\event\submission_created::create(array(
- 'objectid' => $this->iassign->id,
- 'context' => $this->context,
- 'other' => $info
- ));
- $event->add_record_snapshot('course', $this->course);
- $event->trigger();
- } else {
- print '<tr><td width=60% ><strong>' . get_string('auto_result', 'iassign') . '</strong></td>';
- print '<td width=40% align=right>' . $return_last . ' ' . $link_return . '</td></tr>';
- print '<tr>';
- print $msg;
- }
- } else {
- $status = 1;
- $grade_student = $iLM_PARAM_RealGrade;
- print '<tr><td colspan=2>' . iassign_icons::insert('post') . get_string('get_answer_post', 'iassign') . '</td>';
- print '<tr><td width=40% align=right>' . $return_last . ' ' . $link_return . '</td></tr>';
- print '<tr>';
-
- $info = $iassign->name . " - " . $this->activity->get_activity()->name . " - " . get_string('get_answer_post', 'iassign');
- $event = \mod_iassign\event\submission_created::create(array(
- 'objectid' => $this->iassign->id,
- 'context' => $this->context,
- 'other' => $info
- ));
- $event->add_record_snapshot('course', $this->course);
- $event->trigger();
- }
- }
- print '</tr></table>';
- print $OUTPUT->box_end();
-
- if ($this->write_solution == 1) {
- $timenow = time();
-
- if (!$iassign_submission) {
- $newentry = new stdClass();
- $newentry->userid = $this->userid_iassign;
-
- $newentry->iassign_statementid = $this->activity->get_activity()->id;
- $newentry->timecreated = $timenow;
- $newentry->timemodified = $timenow;
- $newentry->answer = $iLM_PARAM_ArchiveContent;
- $newentry->grade = round($grade_student, 2);
- $newentry->status = $status;
- $newentry->experiment = 1;
- if (!$newentry->id = $DB->insert_record("iassign_submission", $newentry)) {
- print_error('error_insert', 'iassign');
- } else {
-
- $event = \mod_iassign\event\submission_created::create(array(
- 'objectid' => $this->iassign->id,
- 'context' => $this->context
- ));
- $event->add_record_snapshot('course', $this->course);
- $event->trigger();
- $this->update_grade_student($newentry->userid, $newentry->iassign_statementid, $this->iassign->id);
- }
- } elseif ($iassign_submission->status != 3) {
- $newentry = new stdClass();
- $newentry->id = $iassign_submission->id;
- $newentry->iassign_statementid = $iassign_submission->iassign_statementid;
- $newentry->userid = $iassign_submission->userid;
- $newentry->timecreated = $iassign_submission->timecreated;
- $newentry->timemodified = $timenow;
- $newentry->answer = $iLM_PARAM_ArchiveContent;
- $newentry->grade = round($grade_student, 2);
- $newentry->status = $status;
- $newentry->experiment = $iassign_submission->experiment + 1;
- if (!$DB->update_record("iassign_submission", $newentry)) {
- print_error('error_update', 'iassign');
-
-
-
-
- } else {
-
- $event = \mod_iassign\event\submission_updated::create(array(
- 'objectid' => $this->iassign->id,
- 'context' => $this->context
- ));
- $event->add_record_snapshot('course', $this->course);
- $this->update_grade_student($newentry->userid, $newentry->iassign_statementid, $this->iassign->id);
- }
- } else {
- if ($return_get_answer == 1) {
- $newentry = new stdClass();
- $newentry->id = $iassign_submission->id;
- $newentry->iassign_statementid = $iassign_submission->iassign_statementid;
- $newentry->userid = $iassign_submission->userid;
- $newentry->timecreated = $iassign_submission->timecreated;
- $newentry->timemodified = $timenow;
- $newentry->answer = $iLM_PARAM_ArchiveContent;
- $newentry->grade = round($grade_student, 2);
- $newentry->status = $status;
- $newentry->experiment = $iassign_submission->experiment + 1;
- if (!$DB->update_record("iassign_submission", $newentry))
- print_error('error_update', 'iassign');
- else {
- $event = \mod_iassign\event\submission_updated::create(array(
- 'objectid' => $this->iassign->id,
- 'context' => $this->context
- ));
- $event->add_record_snapshot('course', $this->course);
- $event->trigger();
- $this->update_grade_student($newentry->userid, $newentry->iassign_statementid, $this->iassign->id);
- print $OUTPUT->box_start();
- print "<p>" . get_string('iassign_update', 'iassign') . "</p>";
- print $OUTPUT->box_end();
- }
- } elseif ($return_get_answer == 2) {
- print $OUTPUT->box_start();
- print "<p>" . get_string('iassign_cancel', 'iassign') . "</p>";
- print $OUTPUT->box_end();
- } else {
- print $OUTPUT->box_start();
- print "
- <script type='text/javascript'>
- //<![CDATA[
- function overwrite () {
- document.formEnvio.return_get_answer.value = 1;
- document.formEnvio.submit();
- }
- function nooverwrite () {
- document.formEnvio.return_get_answer.value = 2;
- document.formEnvio.submit();
- }
- //]]>
- </script>";
- $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;
- $get_answer_overwrite = $CFG->wwwroot . "/mod/iassign/view.php?" . $param_aux;
- print "<form name='formEnvio' method='post' action='$get_answer_overwrite' enctype='multipart/form-data'>";
- print "<p>" . get_string('last_iassign_correct', 'iassign') . "</p>";
- print "<p>" . get_string('update_iassign', 'iassign') . "</p>";
- print "<input type='hidden' name='iLM_PARAM_ArchiveContent' value='$iLM_PARAM_ArchiveContent'/>
- <input type='hidden' name='iLM_PARAM_ActivityEvaluation' value='$iLM_PARAM_ActivityEvaluation'/>
- <input type='hidden' name='MA_POST_Info' value='$MA_POST_Info'/>
- <input type='hidden' name='MA_POST_SystemData' value='$MA_POST_SystemData'/>
- <input type='hidden' name='return_get_answer'/> ";
- print "<input type=button value='" . get_string('yes', 'iassign') . "' onClick = 'overwrite()'
- title='" . get_string('message_update_iassign', 'iassign') . "'/> ";
- print "<input type=button value='" . get_string('no', 'iassign') . "' onClick = 'nooverwrite()'
- title='" . get_string('message_no_update_iassign', 'iassign') . "'/>";
- print " </form>";
- print $OUTPUT->box_end();
- }
- }
- }
- print $OUTPUT->footer();
- if ($submission_ajax == 1) {
- ob_end_clean();
- print 'OK';
- }
- die();
- }
-
- function export_file_answer () {
- global $DB;
- $iassign_submission_id = optional_param('iassign_submission_id', NULL, PARAM_INT);
- $iassign_submission = $DB->get_record("iassign_submission", array("id" => $iassign_submission_id));
- $iassign_statement = $DB->get_record("iassign_statement", array("id" => $iassign_submission->iassign_statementid));
- $name = iassign_utils::format_filename(strip_tags($iassign_statement->name));
- $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $iassign_statement->iassign_ilmid));
- $extensions = explode(",", $iassign_ilm->extension);
- $iassign_user = $DB->get_record("user", array("id" => $iassign_submission->userid));
- $username = iassign_utils::format_filename($iassign_user->firstname . ' ' . $iassign_user->lastname);
- $name_answer = $username . '-' . $name . '-' . userdate($iassign_submission->timemodified, '%Y%m%d-%H%M') . '.' . $extensions[0];
- header("Pragma: public");
- header("Expires: 0");
- header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
- header("Cache-Control: private", false);
- header("Content-Type: document/unknown");
- header("Content-Disposition: attachment; filename=\"" . $name_answer . "\";");
- set_time_limit(0);
- print($iassign_submission->answer);
- exit;
- }
-
-
-
- function htmlcode_2_export ($course_fullname, $course_id, $iassign_block_id, $iassign_block_name, $array_iassign_name, $array_iassign_id, $userid, $username) {
- $str_html = "<html dir='ltr' lang='pt-br' xml:lang='pt-br'>
- <head>
- <title>" . get_string('pluginname', 'iassign') . "</title>\n";
- $str_html .= " </head>
- <body>\n";
- $tam = sizeof($array_iassign_name);
- for ($ii=0; $ii<$tam; $ii++) {
-
- }
- $str_html .= "
- </body>\n</html>";
- return $str_html;
- }
-
-
- function export_package_answer () {
- global $DB, $CFG, $OUTPUT;
- $iassign_id = optional_param('iassign_id', NULL, PARAM_INT);
- $iassign = $DB->get_record("iassign", array("id" => $iassign_id));
- $iassign_block_name = iassign_utils::format_filename($iassign->name);
-
-
- $userid = optional_param('userid', NULL, PARAM_INT);
- $iassign_user = $DB->get_record("user", array("id" => $userid));
- $username = iassign_utils::format_filename($iassign_user->firstname . '_' . $iassign_user->lastname);
-
- $current_date = date('Y_m_d_H');
- $diretorio = $CFG->dataroot . DIRECTORY_SEPARATOR . 'temp' . DIRECTORY_SEPARATOR . 'files' . DIRECTORY_SEPARATOR;
-
- if (!is_dir($diretorio)) {
- mkdir($diretorio, 0755, true);
-
- }
- $zip_filename = $diretorio . 'package_iassign_' . $username . '-' . $iassign_block_name . '_' . $current_date . '.zip';
- if (!is_writable($diretorio)) {
- print_error('error_answer_export_dir', 'iassign');
- exit;
- }
-
- $zip = new zip_archive();
- $zip->open($zip_filename);
- $iassign_statements = $DB->get_records("iassign_statement", array("iassignid" => $iassign_id));
-
- $vet_student_filename = array();
- $vet_student_content = array();
- foreach ($iassign_statements as $iassign_statement) {
- $activity_name = iassign_utils::format_filename(strip_tags($iassign_statement->name));
- $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $iassign_statement->iassign_ilmid));
-
- $extensions = explode(",", $iassign_ilm->extension);
- $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $iassign_statement->id, "userid" => $userid));
- if ($iassign_submission) {
- $timemodified = '-' . userdate($iassign_submission->timemodified, '%Y_%m_%d_%H_%M');
- $student_content = $iassign_submission->answer;
- $student_filename = iassign_utils::format_filename($activity_name) . $timemodified . '.' . $extensions[0];
- $resp = $zip->add_file_from_string($student_filename, $student_content);
-
- if ($resp) {
- $vet_student_filename[] = $student_filename;
- $vet_student_content[] = $student_content;
- }
- else {
- print_error('error_answer_export_file', 'iassign');
- exit;
- }
- }
- }
- $zip->close();
- if (count($vet_student_filename)>0) {
- $vet_result = iassign_utils::register_temporary_file($zip_filename, $vet_student_filename, $vet_student_content);
- $result_tf = $vet_result[0];
- $filenameZip = $vet_result[1]->filename;
- }
- iassign_utils::download_file($zip_filename);
- exit;
- }
-
- function edit_status () {
- global $USER, $DB, $OUTPUT;
- $newentry = new stdClass();
- $newentry->id = $this->iassign_submission_current;
- $newentry->status = optional_param('return_status', 0, PARAM_INT);
- $iassign_submission = $DB->get_record('iassign_submission', array('id' => $this->iassign_submission_current));
- if ($iassign_submission->status != 0 && $newentry->status == 0)
- $newentry->status = $iassign_submission->status;
- $newentry->teacher = $USER->id;
- if (!$DB->update_record('iassign_submission', $newentry))
- print_error('error_update', 'iassign');
- else {
-
- $event = \mod_iassign\event\submission_updated::create(array(
- 'objectid' => $this->iassign->id,
- 'context' => $this->context
- ));
- $event->add_record_snapshot('course', $this->course);
- $event->trigger();
- $this->action = 'viewsubmission';
- $this->view_iassign_current();
- }
- }
-
- function edit_grade () {
- global $USER, $DB, $OUTPUT;
- $newgrade = optional_param('return_grade', 0, PARAM_INT);
- if ($newgrade && $newgrade >= 0) {
- $newentry = new stdClass();
- $newentry->id = $this->iassign_submission_current;
- $newentry->grade = optional_param('return_grade', 0, PARAM_INT);
- $newentry->teacher = $USER->id;
- if (!$DB->update_record('iassign_submission', $newentry))
- print_error('error_update', 'iassign');
- else {
-
- $event = \mod_iassign\event\submission_updated::create(array(
- 'objectid' => $this->iassign->id,
- 'context' => $this->context
- ));
- $event->add_record_snapshot('course', $this->course);
- $event->trigger();
- }
- }
- $this->action = 'viewsubmission';
- $this->view_iassign_current();
- }
-
-
-
- function add_edit_iassign () {
- global $USER, $CFG, $COURSE, $DB, $OUTPUT;
- require_once('iassign_form.php');
- $id = $this->cm->id;
- $iassignid = $this->iassign->id;
- $param = new stdClass();
- $param->action = $this->action;
- $param->id = $id;
- $param->special_param1 = 0;
- $COURSE->cm = $id;
- $COURSE->iassignid = $iassignid;
- $COURSE->iassign_file_id = NULL;
- $context = context_module::instance($this->cm->id);
- $contextuser = context_user::instance($USER->id);
- $component = 'mod_iassign';
- $filearea = 'exercise';
- if (!empty($this->iassign_current))
- $COURSE->iassign_id = $this->iassign_current;
- else
- $COURSE->iassign_id = 0;
- $total_of_activities = 0;
- if ($this->action == 'add') {
- $iassign_data = $DB->get_record("iassign", array('id' => $iassignid));
- $params_temp = array('iassignid' => $iassignid);
- $query_str = "SELECT s.id, s.name, s.dependency FROM {iassign_statement} s WHERE s.iassignid = :iassignid ORDER BY s.position ASC";
- $iassign_statement = $DB->get_records_sql($query_str, $params_temp);
- $total_of_activities = count($iassign_statement);
- $param->iassignid = $iassignid;
- $param->name = "";
- $param->oldname = "";
- $param->type_iassign = 3;
- $param->proposition = "";
- $author = $DB->get_record("user", array("id" => $USER->id));
- $param->author_name = $author->firstname . ' ' . $author->lastname;
- $param->author_modified_name = $author->firstname . ' ' . $author->lastname;
- $param->author = $param->author_name;
- $param->author_modified = $param->author_modified_name;
- $COURSE->iassign_list = array();
- $param->iassign_list = array();
- if ($iassign_statement) {
- foreach ($iassign_statement as $iassign) {
- $iassignid = $iassign->id;
- $param->iassign_list[$iassignid] = 0;
- $COURSE->iassign_list[$iassignid] = new stdClass();
- $COURSE->iassign_list[$iassignid]->id = $iassignid;
- $COURSE->iassign_list[$iassignid]->name = $iassign->name;
- $COURSE->iassign_list[$iassignid]->enable = 1;
- }
- }
- $param->iassign_ilmid = 0;
- $param->file = 0;
- $param->fileold = 0;
- $param->filename = "";
- $param->grade = $iassign_data->grade;
- $param->timemodified = time();
- $param->timecreated = time();
- $param->timeavailable = $iassign_data->timeavailable;
- $param->timedue = $iassign_data->timedue;
- $param->preventlate = $iassign_data->preventlate;
- $param->test = $iassign_data->test;
- $param->special_param1 = 0;
- $param->visible = 1;
- $param->max_experiment = $iassign_data->max_experiment;
- $param->dependency = 0;
- $param->automatic_evaluate = 1;
- $param->show_answer = 1;
- }
- elseif ($this->action == 'edit') {
- $COURSE->iassign_list = array();
- $this_activity = $this->activity->get_activity();
- if ($this_activity != null) {
- $iassign_statement_current = $this_activity;
- $param->iassign_id = $iassign_statement_current->id;
- $param->iassignid = $iassign_statement_current->iassignid;
- $param->name = $iassign_statement_current->name;
- $param->oldname = $iassign_statement_current->name;
- $param->type_iassign = $iassign_statement_current->type_iassign;
- $param->store_all_submissions = $iassign_statement_current->store_all_submissions;
- $param->proposition = array('text' => $iassign_statement_current->proposition, '');
- $param->author_name = $iassign_statement_current->author_name;
- $param->author = $iassign_statement_current->author_name;
- $author = $DB->get_record("user", array('id' => $USER->id));
- $param->author_modified_name = $author->firstname . ' ' . $author->lastname;
- $param->author_modified = $param->author_modified_name;
- $dependency = explode(';', $iassign_statement_current->dependency);
- $param->iassign_list = array();
-
- $str_query = "SELECT * FROM {iassign_statement} s WHERE s.iassignid = '" . $iassignid . "' AND s.id!='" . $iassign_statement_current->id . "' AND s.dependency!=0";
- $iassign_statement_dependency = $DB->get_records_sql($str_query);
- $array_dependency = array();
- $subdependency = "";
- $sub_subdependency = "";
-
- if ($iassign_statement_dependency) {
- $subdependency .= $this->search_dependency($iassign_statement_current->id, $iassign_statement_dependency);
-
- foreach ($inter as $tmp)
- $sub_subdependency .= $this->search_sub_dependency($tmp);
- $list_dependency = $subdependency . $sub_subdependency;
- $array_dependency = explode(";", $list_dependency);
- }
-
- $str_query = "SELECT id, name FROM {iassign_statement} WHERE iassignid = '" . $iassignid . "' AND id!='" . $iassign_statement_current->id . "' ORDER BY position ASC";
- $all_others_iassign_statement = $DB->get_records_sql($str_query);
- $total_of_activities = count($all_others_iassign_statement) + 1;
- $inter = array();
- if ($all_others_iassign_statement) {
- foreach ($all_others_iassign_statement as $iassign)
- if (in_array($iassign->id, $dependency))
- $inter[] = $iassign->id;
- }
- if ($all_others_iassign_statement) {
- foreach ($all_others_iassign_statement as $iassign) {
- $iassignid = $iassign->id;
- $COURSE->iassign_list[$iassignid] = new stdClass();
- $COURSE->iassign_list[$iassignid]->name = $iassign->name;
- $COURSE->iassign_list[$iassignid]->id = $iassignid;
- if (in_array($iassignid, $dependency))
- $param->iassign_list[$iassignid] = 1;
- else
- $param->iassign_list[$iassignid] = 0;
- if (in_array($iassignid, $array_dependency))
- $COURSE->iassign_list[$iassignid]->enable = 0;
- else
- $COURSE->iassign_list[$iassignid]->enable = 1;
- }
- }
- $param->iassign_ilmid = $iassign_statement_current->iassign_ilmid;
- $param->fileold = 0;
- $param->filesid = 0;
- $param->file = 0;
- $param->filename = '';
- $param->grade = $iassign_statement_current->grade;
- $param->timecreated = $iassign_statement_current->timecreated;
- $param->timeavailable = $iassign_statement_current->timeavailable;
- $param->timedue = $iassign_statement_current->timedue;
- $param->preventlate = $iassign_statement_current->preventlate;
- $param->test = $iassign_statement_current->test;
- $param->special_param1 = $iassign_statement_current->special_param1;
- $param->position = $iassign_statement_current->position;
- $param->visible = $iassign_statement_current->visible;
- $param->max_experiment = $iassign_statement_current->max_experiment;
- $param->automatic_evaluate = $iassign_statement_current->automatic_evaluate;
- $param->show_answer = $iassign_statement_current->show_answer;
- $fs = get_file_storage();
-
-
- $files = $fs->get_area_files($context->id, $component, $filearea, $iassign_statement_current->file);
- if ($files) {
- foreach ($files as $file) {
- if ($file->get_filename() != '.') {
- $param->filename = $file->get_filename();
- $param->file = $file->get_id();
- $param->fileold = $file->get_id();
- $COURSE->iassign_file_id = $file->get_id();
- }
- }
- }
-
-
-
-
-
-
- }
- }
-
-
- $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array($this->iassign->id), 'position ASC');
-
-
-
- $param->position = $total_of_activities;
-
-
-
-
- if (isset($param->iassign_ilmid)) {
-
-
- $mform = new mod_iassign_form(null, array('special_param1'=>$param->special_param1), 'post', null, array('id'=>'mform1', 'iassign_ilmid'=>$param->iassign_ilmid), true, null);
- }
- else {
- $mform = new mod_iassign_form(null, null, null, null, array('id'=>'mform1'));
- }
- $mform->set_data($param);
- if ($mform->is_cancelled()) {
- $this->return_home_course('iassign_cancel');
- exit;
- }
- else {
- $result = $mform->get_data();
-
- if ($result) {
- $result->context = $context;
- if ($result->type_iassign == 1 || $result->type_iassign == 2)
- $result->grade = 0;
- if ($result->type_iassign == 1) {
- $result->automatic_evaluate = 0;
- $result->show_answer = 0;
- }
- elseif ($result->automatic_evaluate == 0)
- $result->show_answer = 0;
-
- $result->iassign_list = optional_param_array('iassign_list', array(), PARAM_RAW);
- if ($result->iassign_list) {
- foreach ($result->iassign_list as $key => $value)
- $result->dependency .= $key . ';';
- }
- else
- $result->dependency = 0;
-
-
-
- if (!isset($result->iassign_ilmid) && isset($_POST['iassign_ilmid']))
- $result->iassign_ilmid = $_POST['iassign_ilmid'];
- $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $result->iassign_ilmid));
- if ($this->action == 'add') {
- $iassign_statement_name = $DB->get_records('iassign_statement', array('iassignid' => $result->iassignid, 'name' => $result->name));
- if ($iassign_statement_name) {
- $this->return_home_course('error_iassign_name');
- die();
- }
-
- $iassignid = $this->activity->new_iassign($result);
- $this->activity->add_calendar($iassignid);
-
- $event = \mod_iassign\event\iassign_created::create(array(
- 'objectid' => $iassignid,
- 'context' => $context
- ));
- $event->add_record_snapshot('course', $this->course);
- $event->trigger();
- $this->return_home_course('iassign_add');
- }
- elseif ($this->action == 'edit') {
- $iassignid = $this->activity->update_iassign($result);
- $this->activity->update_calendar($iassignid, $result->oldname);
-
- $event = \mod_iassign\event\iassign_updated::create(array(
- 'objectid' => $iassignid,
- 'context' => $context
- ));
- $event->add_record_snapshot('course', $this->course);
- $event->trigger();
- $this->return_home_course('iassign_update');
- }
- die();
- }
- }
- print $OUTPUT->header();
- $mform->display();
- print $OUTPUT->footer();
- die();
- }
-
- function search_dependency ($search_iassing_id, $iassign_statement) {
- global $DB, $OUTPUT;
- $dependency = "";
- if ($iassign_statement)
- foreach ($iassign_statement as $iassign) {
- $inter_dependency = explode(';', $iassign->dependency);
- if (in_array($search_iassing_id, $inter_dependency)) {
- $dependency .= $iassign->id . ";";
- $dependency .= $this->search_dependency($iassign->id, $iassign_statement);
- }
- }
- return $dependency;
- }
-
- function search_sub_dependency ($search_iassing_id) {
- global $DB, $OUTPUT;
- $iassign_statement = $DB->get_record("iassign_statement", array("id" => $search_iassing_id));
- $dependency = "";
- if ($iassign_statement) {
- $inter_dependency = explode(';', $iassign_statement->dependency);
- foreach ($inter_dependency as $tmp) {
- if ($tmp != 0)
- $dependency .= $tmp . ";";
- $dependency .= $this->search_sub_dependency($tmp);
- }
- }
- return $dependency;
- }
-
- static function warning_message_iassign ($strcode) {
- return "<div class='warning' style='display:inline; font-weight: bold; color:#a00'>" . get_string($strcode, 'iassign') . "</div>\n";
- }
-
-
-
- static function update_grade_iassign ($iassignid) {
- global $USER, $CFG, $COURSE, $DB, $OUTPUT;
- require_once($CFG->libdir . '/gradelib.php');
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- $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");
-
- if (key($array_sum_grade))
- $sum_grade = key($array_sum_grade);
- else
- $sum_grade = 0;
- $grade_iassign = $DB->get_record("iassign", array("id" => $iassignid));
- $grades = NULL;
- $params_temp = array('itemname' => $grade_iassign->name);
- $params_temp['iteminstance'] = $iassignid;
- $params_temp['gradetype'] = GRADE_TYPE_VALUE;
-
- $params_temp['grademax'] = $sum_grade;
- $params_temp['rawgrademax'] = $sum_grade;
-
- $params_temp['grademin'] = 0;
-
-
-
-
- grade_update('mod/iassign', $grade_iassign->course, 'mod', 'iassign', $iassignid, 0, $grades, $params_temp);
- }
-
- function update_grade_student ($userid, $iassign_statementid, $iassignid) {
- global $CFG, $DB, $OUTPUT;
- require_once($CFG->libdir . '/gradelib.php');
- $grade_iassign = $DB->get_record('iassign', array('id' => $iassignid));
-
- $grade_iassign_statements = $DB->get_records('iassign_statement', array('iassignid' => $iassignid));
- $total_grade = 0;
- foreach ($grade_iassign_statements as $grade_iassign_statement) {
- $iassign_submission = $DB->get_record('iassign_submission', array('iassign_statementid' => $grade_iassign_statement->id, 'userid' => $userid));
- if ($iassign_submission)
- $total_grade += $iassign_submission->grade;
- }
-
-
-
-
-
- $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");
- if (key($array_sum_grade))
- $sum_grade = key($array_sum_grade);
- else
- $sum_grade = 0;
- $grades['userid'] = $userid;
- $grades['rawgrade'] = $total_grade;
- $params_temp = array('itemname' => $grade_iassign->name);
- $params_temp['iteminstance'] = $iassignid;
- $params_temp['gradetype'] = GRADE_TYPE_VALUE;
-
- $params_temp['grademax'] = $sum_grade;
- $params_temp['rawgrademax'] = $sum_grade;
-
- grade_update('mod/iassign', $grade_iassign->course, 'mod', 'iassign', $iassignid, 0, $grades, $params_temp);
- }
-
- function view_legend_icons () {
- global $USER, $CFG, $DB, $OUTPUT;
- $id = $this->cm->id;
- if ($this->action == 'print')
- print '<table border=1 width=100%><tr>';
- else
- print '<table width=100%><tr>';
- print '<td >';
- if (has_capability('mod/iassign:viewreport', $this->context, $USER->id) && $this->action == 'report') {
- if ($this->action != 'print') {
- $link_print = "<a href='" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&action=print&iassignid=" . $this->iassign->id . "'>" . iassign_icons::insert('print') . ' ' . get_string('print', 'iassign') . "</a>\n";
- $link_export = "<a href='" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&action=export_csv&iassignid=" . $this->iassign->id . "'>" . iassign_icons::insert('export_ilm') . ' ' . get_string('export_csv', 'iassign') . "</a>\n";
- print '<td width=10% align="right">' . $link_export . '</td>' . "\n";
- print '<td width=15% align="right">' . $link_print . '</td>' . "\n";
- }
- print '</tr></table>' . "\n";
- }
- print '</td></tr></table>' . "\n";
- }
-
-
- function view_iassign_current () {
- global $USER, $CFG, $COURSE, $DB, $OUTPUT, $PAGE;
- $id = $this->cm->id;
- $iassignid = $this->iassign->id;
- $only_one_send_button = 0;
- $iassign = $DB->get_record("iassign", array("id" => $iassignid));
-
- $iassign_statement_activity_item = $this->activity->get_activity();
- if (!$iassign_statement_activity_item) {
- print $OUTPUT->header();
- \core\notification::error(get_string('activity_not_found', 'iassign'));
- print $OUTPUT->footer();
- exit;
- }
- $ilm = new ilm($iassign_statement_activity_item->iassign_ilmid);
- $ilm_name = '';
- if ($ilm->ilm)
- $ilm_name = strtolower($ilm->ilm->name);
-
- $allow_resubmission = (substr($ilm_name, 0, 5) != "igeom" ? 1 : 0);
-
- $info = $iassign->name . ":" . $iassign_statement_activity_item->name;
-
- $event = \mod_iassign\event\submission_viewed::create(array(
- 'objectid' => $iassign->id,
- 'context' => $this->context,
- 'other' => $info
- ));
- $event->add_record_snapshot('course', $this->course);
- $event->trigger();
-
- $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $iassign_statement_activity_item->iassign_ilmid));
-
- $actual_link = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
- $PAGE->navbar->add($iassign_statement_activity_item->name, $actual_link);
- print $OUTPUT->header();
- if ($this->action == 'viewsubmission') {
- if (!empty($this->iassign_submission_current) || $this->iassign_submission_current != 0)
- $iassign_submission = $DB->get_record("iassign_submission", array("id" => $this->iassign_submission_current));
- else
- $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $this->activity->get_activity()->id, "userid" => $this->userid_iassign));
- } else {
- $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $this->activity->get_activity()->id, "userid" => $this->userid_iassign));
- }
- if ($iassign_submission)
- $this->update_comment($iassign_submission->id);
-
- $file = $iassign_statement_activity_item->id;
-
-
-
-
- $this->bottonPost = 0;
-
- $this->view_iassign = false;
- $repeat = "";
- $last_iassign = "";
- $student_answer = "";
- $comment = "";
-
- if (($this->action != 'viewsubmission') && has_capability('mod/iassign:evaluateiassign', $USER->context, $USER->id)) {
-
-
-
- if ($iassign_statement_activity_item->type_iassign != 1)
- $this->bottonPost = 1;
- print $OUTPUT->box('<p><strong>' . get_string('area_specific_teacher', 'iassign') . '</strong></p>');
- $this->activity->view_dates();
- $USER->iassignEdit = $this->bottonPost;
- $this->activity->show_info_iassign();
- if ($iassign_submission) {
-
- $param_aux = "action=get_answer&iassign_submission_current=" . $iassign_submission->id . "&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id . "&userid_iassign=" . $USER->id;
- } else {
-
- $param_aux = "action=get_answer&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id . "&userid_iassign=" . $USER->id;
- }
- $enderecoPOST = "" . $CFG->wwwroot . "/mod/iassign/view.php?" . $param_aux;
-
-
- print $OUTPUT->box($ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, true));
- }
-
-
- elseif (($this->action == 'viewsubmission') && has_capability('mod/iassign:evaluateiassign', $USER->context, $USER->id)) {
-
-
- $row = optional_param('row', 0, PARAM_INT);
- $column = optional_param('column', 0, PARAM_INT);
- $link_next = iassign_icons::insert('right_disable');
- $link_previous = iassign_icons::insert('left_disable');
- $link_up = iassign_icons::insert('up_disable');
- $link_down = iassign_icons::insert('down_disable');
- if (isset($USER->matrix_iassign[$row][$column])) {
- $has_row_column = True;
- $element_matrix_iassign = $USER->matrix_iassign[$row][$column];
- }
- else {
- $has_row_column = False;
- $element_matrix_iassign = $USER->matrix_iassign[$row][$column];
- }
- $msgViewAction = "view.php?action=viewsubmission&id=$id&iassign_submission_current=";
- $msgUserId_current = "&userid_iassign=" . $this->userid_iassign . "&iassign_current=";
-
- if ($has_row_column && $element_matrix_iassign->iassign_next != - 1) {
- $url_next = $msgViewAction . $USER->matrix_iassign[$row][$column + 1]->iassign_submission_current . $msgUserId_current . $element_matrix_iassign->iassign_next . "&view_iassign=report&row=" . ($row) . "&column=" . ($column + 1);
- $link_next = "<a href='" . $url_next . "'>" . (iassign_icons::insert('next_activity')) . "</a>";
- }
-
- if ($has_row_column && $element_matrix_iassign->iassign_previous != - 1) {
- $url_previous = $msgViewAction . $USER->matrix_iassign[$row][$column - 1]->iassign_submission_current . $msgUserId_current . $element_matrix_iassign->iassign_previous . "&view_iassign=report&row=" . ($row) . "&column=" . ($column - 1);
- $link_previous = "<a href='" . $url_previous . "'>" . (iassign_icons::insert('previous_activity')) . "</a>";
- }
-
- if ($has_row_column && $element_matrix_iassign->user_next != - 1) {
- $url_down = $msgViewAction . $USER->matrix_iassign[$row + 1][$column]->iassign_submission_current . "&userid_iassign=" . $element_matrix_iassign->user_next . "&iassign_current=" . $this->activity->get_activity()->id . "&view_iassign=report&row=" . ($row + 1) . "&column=" . ($column);
- $link_down = "<a href='" . $url_down . "'>" . (iassign_icons::insert('previous_student')) . "</a>";
- }
-
- if ($has_row_column && $element_matrix_iassign->user_previous != - 1) {
- $url_up = $msgViewAction . $USER->matrix_iassign[$row - 1][$column]->iassign_submission_current . "&userid_iassign=" . $element_matrix_iassign->user_previous . "&iassign_current=" . $this->activity->get_activity()->id . "&view_iassign=report&row=" . ($row - 1) . "&column=" . ($column);
- $link_up = "<a href='" . $url_up . "'>" . (iassign_icons::insert('next_student')) . "</a>";
- }
- if ($iassign_submission) {
- $student_answer = $iassign_submission->answer;
- }
- $last_iassign = get_string('last_iassign', 'iassign');
- $user_data = $DB->get_record("user", array('id' => $this->userid_iassign));
-
- $this->activity->view_dates();
- print $OUTPUT->box_start();
- print '<table width=100% border=0 valign="top"><tr>' . "\n";
- print '<td width=80%><font color="blue"><strong>' . get_string('area_available', 'iassign') . '</strong></font><br>' . "\n";
- if ($user_data)
- print $OUTPUT->user_picture($user_data);
- print ' ' . $user_data->firstname . ' ' . $user_data->lastname;
- print '</td>' . "\n";
- print '<td width=20% align=right>' . "\n";
- print '<table width=50 cellpadding="0">';
- print '<tr><td colspan=2 align=center>' . $link_up . '</td></tr>' . "\n";
- print '<tr><td align=center>' . $link_previous . '</td>' . "\n";
- print '<td align=center>' . $link_next . '</td></tr>' . "\n";
- print '<td colspan=2 align=center>' . $link_down . '</td></tr>' . "\n";
- print '</table>' . "\n";
- print '</td></tr></table>' . "\n";
- print $OUTPUT->box_end();
- print $OUTPUT->box_start();
- print '<table width=100% border=0 valign="top"><tr>' . "\n";
- print '<td width=60% valign="top">' . "\n";
- print '<p><strong>' . get_string('proposition', 'iassign') . ':</strong></p>' . "\n";
- print '<div class="proposition">' . $iassign_statement_activity_item->proposition . '</div>' . "\n";
- if ($iassign_statement_activity_item->automatic_evaluate == 1)
- $resp = get_string('yes');
- else
- $resp = get_string('no');
- print '<p>' . get_string('automatic_evaluate', 'iassign') . ' ' . $resp . '</p>' . "\n";
- if ($iassign_statement_activity_item->show_answer == 1)
- $resp = get_string('yes');
- else
- $resp = get_string('no');
- print '<p>' . get_string('show_answer', 'iassign') . ' ' . $resp . '</p>' . "\n";
- print '</td>';
- if ($iassign_statement_activity_item->type_iassign == 3) {
- print '<td width=40% valign="top" align="left">';
- print '<strong>' . get_string('status', 'iassign') . '</strong>' . "\n";
-
- if ($iassign_submission) {
- switch ($iassign_submission->status) {
- case 3 :
- print iassign_icons::insert('correct') . ' ' . get_string('correct', 'iassign') . ' ' . $comment;
- break;
- case 2 :
- print iassign_icons::insert('incorrect') . ' ' . get_string('incorrect', 'iassign') . ' ' . $comment;
- break;
- case 1 :
- print iassign_icons::insert('post') . ' ' . get_string('post', 'iassign') . ' ' . $comment;
- break;
- default :
- print iassign_icons::insert('not_post') . ' ' . get_string('not_post', 'iassign') . ' ' . $comment;
- $last_iassign = get_string('no_iLM_PARAM_ArchiveContent', 'iassign');
- }
- }
- else {
- print iassign_icons::insert('not_post') . ' ' . get_string('not_post', 'iassign') . ' ' . $comment;
- $last_iassign = get_string('no_iLM_PARAM_ArchiveContent', 'iassign');
- }
-
- if ($iassign_submission && $iassign_submission->experiment > 0) {
- $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);
- print " <script type='text/javascript'>
- //<![CDATA[
- function overwriteStatus (newstatus) {
- if (confirm('" . get_string('confirm_change_situation', 'iassign') . "')) {
- document.formEditStatus.return_status.value=newstatus;
- document.formEditStatus.submit();
- }
- else
- document.formEditStatus.return_status.value=-1;
- }
- //]]>
- </script>";
- print "<form name='formEditStatus' method='post' action='$edit_status' enctype='multipart/form-data'>\n";
- print ' <font color="blue"><strong>' . get_string('changeto', 'iassign') . "</strong></font>\n";
- 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";
- print " <input type='hidden' name='return_status'>\n";
- print "</form>\n";
- print '<p><strong>' . get_string('grade_student', 'iassign') . '</strong> ' . $iassign_submission->grade . "</p>\n";
- print '<p><strong>' . get_string('grade_iassign', 'iassign') . '</strong> ' . $iassign_statement_activity_item->grade . "</p>\n";
- $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);
- print "
- <script type='text/javascript'>
- //<![CDATA[
- function overwriteGrade (newgrade,maxgrade) {
- if (newgrade<0 || newgrade>maxgrade) {
- alert('" . get_string('erro_grade', 'iassign') . " '+maxgrade)
- document.formEditGrade.return_grade.value=-1;
- document.formEditGrade.submit();
- }
- else {
- document.formEditGrade.return_grade.value=newgrade;
- document.formEditGrade.submit();
- }
- }
- //]]>
- </script>";
- print "<form name='formEditGrade' method='post' action='$edit_grade' enctype='multipart/form-data'>\n";
- print ' <font color="blue"><strong>' . get_string('changeto', 'iassign') . "</strong></font>" . "\n";
- print " <input type='text' name='grade' size='6'>";
- print " <input type='hidden' name='return_grade'> ";
- 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";
- print "</form>";
- $url_answer = "" . $CFG->wwwroot . "/mod/iassign/view.php?" . "action=download_answer&iassign_submission_id=" . $iassign_submission->id . "&id=" . $id;
- print '<p><strong>' . get_string('experiment', 'iassign') . '</strong> ' . $iassign_submission->experiment . ' <a href="' . $url_answer . '">' . iassign_icons::insert('download_assign') . '</a></p>';
- print '<p><strong>' . get_string('timemodified', 'iassign') . '</strong> ' . userdate($iassign_submission->timemodified) . '</p>';
- $teacher = $DB->get_record("user", array('id' => $iassign_submission->teacher));
- if ($teacher)
- print '<p><strong>' . get_string('last_modification', 'iassign') . '</strong> ' . $teacher->firstname . '</p>' . "\n";
- }
- print '</td>';
- }
- print '</tr></table>';
- print $OUTPUT->box_end();
- $USER->iassignEdit = $this->bottonPost;
- print activity::toggle_columns_script();
- if ($iassign_submission && $allow_resubmission) {
-
- print $OUTPUT->box_start();
- print '<p><strong>' . $last_iassign . '</strong></p>';
-
- $enderecoPOST = "";
-
- print $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, false);
-
- print $OUTPUT->box_end();
- }
- else {
-
-
- $loadTeacherActivity = false;
- if (substr($ilm_name, 0, 5)=="igeom") {
- if ($iassign_statement_activity_item->special_param1 == 1)
- $loadTeacherActivity = true;
- }
- else
- if (!$student_answer) {
- $loadTeacherActivity = true;
- }
- print $OUTPUT->box('<p><strong>' . $last_iassign . '</strong></p>' . "\n");
- if (!isset($enderecoPOST)) $enderecoPOST = "";
- print activity::toggle_columns_script();
-
- print $OUTPUT->box($ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, $loadTeacherActivity));
- }
-
-
-
-
- }
-
-
- elseif (has_capability('mod/iassign:submitiassign', $USER->context, $USER->id)) {
-
-
- $time_now = time();
- if ($iassign_statement_activity_item->type_iassign == 1) {
-
- $this->view_iassign = true;
-
- } elseif ($iassign_statement_activity_item->type_iassign == 2 && $iassign_ilm->evaluate == 1) {
-
- if ($iassign_statement_activity_item->timeavailable < $time_now && $iassign_statement_activity_item->timedue > $time_now) {
- $this->bottonPost = 1;
- $this->view_iassign = true;
- } else
- $this->view_iassign = false;
- } elseif ($iassign_statement_activity_item->type_iassign == 3) {
-
- $this->view_iassign = true;
- if ($iassign_statement_activity_item->timeavailable > $time_now)
- $this->view_iassign = false;
- elseif ($iassign_statement_activity_item->timedue > $time_now || $iassign_statement_activity_item->preventlate == 1) {
- $this->bottonPost = 1;
-
- $repeat_title = ' title="' . get_string('repeat_alt', 'iassign') . '" ';
- if (!$iassign_submission || $this->action == 'repeat' || ($iassign_submission && $allow_resubmission)) {
- if (!$iassign_submission) {
- $str_iassign_submission_id = '';
- $str_iassign_submission_answer = '';
- }
- else {
- $str_iassign_submission_id = $iassign_submission->id;
- $str_iassign_submission_answer = $iassign_submission->answer;
- }
- if ($this->action != 'repeat') {
- $repeat = "<a href='view.php?action=repeat&id="
- . $id . "&userid_iassign=" . $USER->id . "&iassign_current="
- . $this->activity->get_activity()->id . "&iassign_submission_current="
- . $str_iassign_submission_id . "'" . $repeat_title . ">"
- . iassign_icons::insert('repeat') . ' ' . get_string('repeat', 'iassign') . "</a>\n";
- }
- $this->bottonPost = 1;
- $this->write_solution = 1;
- $student_answer = $str_iassign_submission_answer;
- }
- else {
-
- $last_iassign = get_string('last_iassign', 'iassign');
- if ($iassign_submission) {
- $repeat = "<a href='view.php?action=repeat&id=" . $id . "&userid_iassign=$USER->id&iassign_current=" . $this->activity->get_activity()->id .
- "&iassign_submission_current=" . $iassign_submission->id . "'" . $repeat_title . ">" . iassign_icons::insert('repeat') . ' ' . get_string('repeat', 'iassign') . "</a>\n";
- $student_answer = $iassign_submission->answer;
- } else {
- $repeat = "<a href='view.php?action=repeat&id=" . $id . "&userid_iassign=$USER->id&iassign_current=" . $this->activity->get_activity()->id .
- "'" . $repeat_title . ">" . iassign_icons::insert('repeat') . ' ' . get_string('repeat', 'iassign') . "</a>\n";
- }
- }
- } elseif ($iassign_statement_activity_item->test == 1) {
- if ($this->action == 'repeat' || ($iassign_submission && $iassign_submission->experiment < 1)) {
- $this->bottonPost = 1;
- $this->write_solution = 0;
- } else {
- $last_iassign = get_string('last_iassign', 'iassign');
- if ($iassign_submission) {
- $repeat = "<a href='view.php?action=repeat&id=" . $id . "&userid_iassign=$USER->id&iassign_current=" . $this->activity->get_activity()->id .
- "&iassign_submission_current=" . $iassign_submission->id . "'" . $repeat_title . ">" . iassign_icons::insert('repeat') . ' ' . get_string('repeat', 'iassign') . "</a>\n";
- $student_answer = $iassign_submission->answer;
- } else {
-
- $repeat = "<a href='view.php?action=repeat&id=" . $id . "&userid_iassign=$USER->id&iassign_current=" . $this->activity->get_activity()->id .
- "'" . $repeat_title . ">" . iassign_icons::insert('repeat') . ' ' . get_string('repeat', 'iassign') . "</a>\n";
- }
- }
- }
- elseif ($iassign_statement_activity_item->test == 0)
- $this->view_iassign = false;
- }
- if ($iassign_submission)
- $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;
- else
- $param_aux = "action=get_answer&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id . "&write_solution=" . $this->write_solution . "&userid_iassign=" . $USER->id;
- $enderecoPOST = "" . $CFG->wwwroot . "/mod/iassign/view.php?" . $param_aux;
- $this->activity->view_dates();
- if ($this->view_iassign) {
- print $OUTPUT->box_start();
- print '<table width=100% border=0 valign="top">' . "\n";
- print '<tr><td width=60% valign="top">' . "\n";
- $flag_dependency = true;
- if ($iassign_statement_activity_item->type_iassign == 3) {
- if ($iassign_statement_activity_item->dependency == 0) {
- print '<strong>' . get_string('independent_activity', 'iassign') . '</strong>' . "\n";
- } else {
- $dependencys = explode(';', $iassign_statement_activity_item->dependency);
- print '<p><strong>' . get_string('dependency', 'iassign') . '</strong></p>' . "\n";
- foreach ($dependencys as $dependency) {
- if ($dependency) {
- $dependencyiassign = $DB->get_record("iassign_statement", array("id" => $dependency));
- $dependencysubmissions = $DB->get_record("iassign_submission", array("iassign_statementid" => $dependencyiassign->id, 'userid' => $USER->id));
- if ($dependencysubmissions) {
- if ($dependencysubmissions->status == 3)
- $icon = iassign_icons::insert('correct');
- elseif ($dependencysubmissions->status == 2) {
- $icon = iassign_icons::insert('incorrect');
- $flag_dependency = false;
- } elseif ($dependencysubmissions->status == 1) {
- $icon = iassign_icons::insert('post');
- $flag_dependency = false;
- } elseif ($dependencysubmissions->status == 0) {
- $icon = iassign_icons::insert('not_post');
- $flag_dependency = false;
- }
- } else {
- $icon = iassign_icons::insert('not_post');
- $flag_dependency = false;
- }
- print '<p> ' . $icon . $dependencyiassign->name . '</p>' . "\n";
- }
- }
- }
- }
- if ($flag_dependency == false) {
- print '<strong>' . get_string('message_dependency', 'iassign') . '</strong>' . "\n";
- $this->view_iassign = false;
- print '</tr></table>' . "\n";
- }
- else {
- $this->view_iassign = true;
- print '</td>' . "\n";
- }
- if ($this->view_iassign) {
- if ($iassign_statement_activity_item->type_iassign == 3) {
-
-
- if ($iassign_submission) {
- $verify_message = $DB->get_record('iassign_submission_comment', array('iassign_submissionid' => $iassign_submission->id, 'return_status' => 0, 'receiver' => 2));
- if ($verify_message)
- $comment = iassign_icons::insert('comment_unread');
- }
- print '<td width=40% valign="top" align="left">';
- print '<strong>' . get_string('status', 'iassign') . '</strong>' . "\n";
- if ($iassign_statement_activity_item->show_answer == 1) {
-
- if ($iassign_submission) {
- switch ($iassign_submission->status) {
- case 3 :
- print iassign_icons::insert('correct') . ' ' . get_string('correct', 'iassign') . ' ' . $comment;
- break;
- case 2 :
- print iassign_icons::insert('incorrect') . ' ' . get_string('incorrect', 'iassign') . ' ' . $comment;
- break;
- case 1 :
- print iassign_icons::insert('post') . ' ' . get_string('post', 'iassign') . ' ' . $comment;
- break;
- default :
- print iassign_icons::insert('not_post') . ' ' . get_string('not_post', 'iassign') . ' ' . $comment;
- $repeat = "";
- $last_iassign = "";
- }
- } else {
- print iassign_icons::insert('not_post') . ' ' . get_string('not_post', 'iassign') . ' ' . $comment;
- $repeat = "";
- $last_iassign = "";
- }
- if ($iassign_submission && $iassign_submission->experiment > 0) {
- print '<p><strong>' . get_string('grade_student', 'iassign') . ':</strong> ' . $iassign_submission->grade;
- print ' (' . get_string('grade_iassign', 'iassign') . ': ' . $iassign_statement_activity_item->grade . ')</p>' . "\n";
- print '<p><strong>' . get_string('experiment_student', 'iassign') . '</strong> ' . $iassign_submission->experiment;
- if ($iassign_statement_activity_item->max_experiment == 0)
- print '  (' . get_string('experiment_iassign', 'iassign') . ' ' . get_string('ilimit', 'iassign') . ')</p>' . "\n";
- else {
- print '  (' . get_string('experiment_iassign', 'iassign') . ' ' . $iassign_statement_activity_item->max_experiment . ')</p>' . "\n";
- if ($iassign_submission->experiment >= $iassign_statement_activity_item->max_experiment) {
- $repeat = "";
- $last_iassign .= " <font color=red>" . get_string('attempts_exhausted', 'iassign') . '</font>' . "\n";
- $this->bottonPost = 0;
- $this->write_solution = 0;
- }
- }
- print '<p><strong>' . get_string('timemodified', 'iassign') . '</strong> ' . userdate($iassign_submission->timemodified) . '</p>' . "\n";
- $teacher = $DB->get_record("user", array('id' => $iassign_submission->teacher));
- if ($teacher)
- print '<p><strong>' . get_string('last_modification', 'iassign') . '</strong> ' . $teacher->firstname . '</p>' . "\n";
- }
- }
- else {
- if (!isset($iassign_submission) || $iassign_submission->status == 0) {
- print iassign_icons::insert('not_post') . ' ' . get_string('not_post', 'iassign') . ' ' . $comment;
- $repeat = "";
- $last_iassign = "";
- } elseif ($iassign_submission->status == 1) {
- print iassign_icons::insert('post') . ' ' . get_string('post', 'iassign') . ' ' . $comment;
- }
- }
- print '</td>';
- }
- print '</tr></table>' . "\n";
-
- print '<table width=100% border=0 valign="top">' . "\n";
- print '<td width=80% align="left">';
- print '<strong>' . $last_iassign . ' ' . get_string('repeat_msg', 'iassign') . '</strong></td>' . "\n";
- print '<td width=20% align="rigth">';
-
- print $repeat;
- print '</td></tr></table>' . "\n";
-
- print activity::toggle_columns_script();
- print '<p class="mt-5"><strong>' . get_string('proposition', 'iassign') . '</strong></p>' . "\n";
- print '<div class="proposition">' . $iassign_statement_activity_item->proposition . '</div>' . "\n";
- $output = '';
- if (!$iassign_ilm) {
- $iassign_ilm = new stdClass();
- $iassign_ilm->file_jar = "";
- }
- $output .= $OUTPUT->box_start();
- $USER->iassignEdit = $this->bottonPost;
-
-
-
- if (!$iassign_submission || $this->action == 'repeat') {
- $student_answer = "";
- $output .= $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, true);
- } elseif ($iassign_submission && $iassign_submission->answer == '0') {
- $student_answer = "";
- $output .= $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, true);
- } else {
-
-
- $loadTeacherActivity = false;
- if (substr($ilm_name, 0, 5)=="igeom") {
- if ($iassign_statement_activity_item->special_param1 == 1)
- $loadTeacherActivity = true;
- }
- $output .= $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, $loadTeacherActivity);
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- $output .= $OUTPUT->box_end();
- print $output;
- }
- print $OUTPUT->box_end();
- }
- }
- else
- if (isguestuser()) {
- print($OUTPUT->notification(get_string('no_permission_iassign', 'iassign'), 'notifyproblem'));
- print '<table width=100% border=0 valign="top">' . "\n";
- print '<tr><td width=60% valign="top">' . "\n";
- print '<strong>' . get_string('proposition', 'iassign') . '</strong>' . "\n";
- print '<p>' . $iassign_statement_activity_item->proposition . '</p>' . "\n";
- print '</tr></table>' . "\n";
- $student_answer = "";
- $enderecoPOST = "";
-
- $output = $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, true);
- print $output;
- }
-
-
- if ($only_one_send_button==0 && $iassign_statement_activity_item->type_iassign == 3) {
-
- $output = '';
- $history_comment = '';
- $row = optional_param('row', 0, PARAM_INT);
- $column = optional_param('column', 0, PARAM_INT);
- if ($iassign_submission) {
- $enderecoPOSTcomment = "" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&action=newcomment&iassign_current=" . $this->activity->get_activity()->id .
- "&iassign_submission_current=" . $iassign_submission->id . "&userid_iassign=" . $this->userid_iassign . "&row=" . ($row) . "&column=" . ($column);
- $history_comment = $this->search_comment_submission($iassign_submission->id);
- }
- else {
- $enderecoPOSTcomment = "" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&action=newcomment&iassign_current=" . $this->activity->get_activity()->id .
- "&userid_iassign=" . $this->userid_iassign . "&row=" . ($row) . "&column=" . ($column);
- }
- $output .= $OUTPUT->box_start();
-
- $output .= "<a id='comments'></a>";
- $output .= " <table id='outlinetable' class='generaltable boxaligncenter' cellpadding='5' width='100%'> \n";
- $output .= " <tr><th><i style='font-size: 20px' class='icon fa fa-comments-o'></i>" . get_string('history_comments', 'iassign') . "</th></tr>";
- $output .= "</table>";
- print " <script type='text/javascript'>
- //<![CDATA[
- function submit_comment(url) {
- if (document.formEnvioComment.submission_comment.value.length < 1) return;
- var formData = new FormData();
- formData.append('submission_comment', document.formEnvioComment.submission_comment.value);
- var request = new XMLHttpRequest();
- request.open('POST', url);
- document.getElementById('comments_history').innerHTML = '';
- request.onload = function (e) {
- if (request.readyState === 4) {
- if (request.status === 200) {
- document.getElementById('comments_history').innerHTML = request.responseText;
- document.getElementById('check-message-success').style.visibility = 'visible';
- setTimeout(function(){
- document.getElementById('check-message-success').style.visibility = 'hidden';
- }, 3000);
- }
- }
- };
- document.formEnvioComment.submission_comment.value = '';
- request.send(formData);
- }
- function event_text_area (event) {
- if (event.ctrlKey && event.keyCode == 13)
- submit_comment('" . $enderecoPOSTcomment . "');
- }
- //]]>
- </script>";
- $output .= "<center><form name='formEnvioComment' id='formEnvioComment1' enctype='multipart/form-data'>\n";
- $output .= "<br><p><textarea class='form-control w-50' rows='2' cols='60' name='submission_comment' onkeypress='event_text_area(event)'></textarea></p>\n";
- $output .= "<p><button class='btn btn-primary' onclick=\"submit_comment('$enderecoPOSTcomment')\" type=button value='" . get_string('submit_comment', 'iassign') . "'>".get_string('submit_comment', 'iassign')."</button> <i id='check-message-success' class='fa fa-check' aria-hidden='true' style='position: absolute; color: green; font-size: 2.0rem; margin-left: 1rem; visibility: hidden;'></i> </p> \n";
- $output .= "</form> </center>\n";
- $output .= "<table id='comments_history' class='generaltable boxaligncenter' cellpadding='5' width='100%'>".$history_comment."</table>";
-
- $output .= $OUTPUT->box_end();
- print $output;
- }
-
- print $OUTPUT->footer();
- die();
- }
-
- function export_csv () {
- global $USER, $CFG, $DB, $OUTPUT;
- $str = "";
- $fields = "student_id, student_name";
-
- $id = $this->cm->id;
- $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array('iassignid' => $this->iassign->id), "position ASC");
- $c = 1;
- foreach ($iassign_list as $iassign) {
- $fields .= ", activity_id_" . $c . ", activity_name_" . $c . ", total_submissions_activity_" . $c . ", grade_activity_" . $c . ""
- . ", status_activity_" . $c . ", ilm_id_activity_" . $c . ", ilm_name_activity_" . $c;
- $c++;
- }
-
- $params_temp = array('shortname' => 'student');
- $role = $DB->get_record_sql("SELECT s.id, s.shortname FROM {role} s WHERE s.shortname = :shortname", $params_temp);
- $context = context_course::instance($this->course->id);
- $params_temp = array('contextid' => $context->id, 'roleid' => $role->id);
- $students = $DB->get_records_sql(
- "SELECT s.userid, a.firstname, a.lastname FROM {role_assignments} s, {user} a " .
- " WHERE s.contextid = :contextid AND s.userid = a.id AND s.roleid = :roleid " .
- " ORDER BY a.firstname ASC,a.lastname ASC", $params_temp);
- foreach ($students as $student) {
- $str .= $student->userid . ',';
- $str .= '"' . $student->firstname . ' ' . $student->lastname . '"';
- foreach ($iassign_list as $iassign) {
- $str .= ',' . $iassign->id . ',';
- $str .= '"' . $iassign->name . '",';
- $student_submissions = $DB->get_record("iassign_submission", array('iassign_statementid' => $iassign->id, 'userid' => $student->userid));
- if ($student_submissions) {
- $str .= $student_submissions->experiment . ',';
- $str .= $student_submissions->grade . ',';
- switch ($student_submissions->status) {
- case 3:
- $str .= '"correct",';
- break;
- case 2:
- $str .= '"incorrect",';
- break;
- case 1:
- $str .= '"post",';
- break;
- case 0:
- $str .= '"not_post",';
- break;
- }
- }
- else {
- $str .= ',,"not_post",';
- }
- $str .= $iassign->iassign_ilmid . ',';
- $ilm_activity = $DB->get_record("iassign_ilm", array('id' => $iassign->iassign_ilmid));
- $str .= '"' . $ilm_activity->name . '"';
- }
- $str .= "\n";
- }
- $str = $fields . "\n" . $str;
- header("Content-type: text/csv");
- header("Content-disposition: attachment; filename=report.csv");
- header("Pragma: no-cache");
- header("Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0");
- header('Content-Length: ' . strlen($str));
- header('Connection: close');
- print $str;
- flush();
- }
-
- function report () {
- global $USER, $CFG, $DB, $OUTPUT;
- $id = $this->cm->id;
- $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array('iassignid' => $this->iassign->id), "position ASC");
- if ($this->action != 'print') {
- $title = get_string('report', 'iassign');
- print $OUTPUT->header();
- }
- $this->print_main_menu();
- print $OUTPUT->box_start();
- $this->view_legend_icons();
- print $OUTPUT->box_end();
- if ($this->action == 'print')
- print '<table border=1 width="100%">' . "\n";
- else
- print '<table id="outlinetable" class="generaltable boxaligncenter table table-hover table-striped mt-5" width="100%">' . "\n";
- print '<tr><th colspan=2 class="header c1">' . iassign_utils::remove_code_message($this->iassign->name) . '</th></tr>' . "\n";
-
- $i = 1;
- $num = array();
- $stylebutton = "background: none; -webkit-box-shadow: 2px 2px 5px 0px rgba(0,0,0,0.75);-moz-box-shadow: 2px 2px 5px 0px rgba(0,0,0,0.75);box-shadow: 2px 2px 5px 0px rgba(0,0,0,0.75); min-width: 4.5rem;";
- foreach ($iassign_list as $iassign) {
- $test_exercise = "";
- $iassign_submission = $DB->get_records("iassign_submission", array("iassign_statementid" => $iassign->id));
- if (($iassign_submission) && $iassign->type_iassign < 3) {
- $test_exercise = " <b>(" . get_string('iassign_exercise', 'iassign') . ")</b>";
- }
- if ($iassign->type_iassign == 3 || ($iassign_submission)) {
- $num[$i] = new stdClass();
- $num[$i]->name = $iassign->name;
- $num[$i]->id = $i;
- $num[$i]->iassignid = $iassign->id;
- print ' <tr >' . "\n";
- print " <td class=\"cell c1 numviews\" width=5% align='center'><strong>" . $num[$i]->id . "</strong></td>\n";
- print "<td class=\"cell c0 actvity\">";
- print ' ' . $num[$i]->name . ' ' . $test_exercise . "</td>";
- print ' </tr>' . "\n";
- $i++;
- }
- }
- $num_exerc = $i;
- print "</table>";
- print "<p></p>";
- if ($this->action == 'print')
- print '<table border=1 width="100%">' . "\n";
- else
- print '<table id="outlinetable" class="generaltable boxaligncenter table table-hover table-striped table-bordered" cellpadding="5" width="100%">' . "\n";
- $context = context_course::instance($this->course->id);
- if ($num_exerc > 1) {
-
- $params_temp = array('shortname' => 'student');
- $role = $DB->get_record_sql(
- "SELECT s.id, s.shortname FROM {role} s " .
- " WHERE s.shortname = :shortname", $params_temp);
-
- $params_temp = array('contextid' => $context->id, 'roleid' => $role->id);
- $students = $DB->get_records_sql(
- "SELECT s.userid, a.firstname, a.lastname FROM {role_assignments} s, {user} a " .
- " WHERE s.contextid = :contextid AND s.userid = a.id AND s.roleid = :roleid " .
- " ORDER BY a.firstname ASC,a.lastname ASC", $params_temp);
- print '<tr><th class="header c1">' . get_string('students', 'iassign') . '</th>' . "\n";
- $width = 90/$num_exerc;
- for ($j=1; $j<$num_exerc; $j++) {
- $sum_iassign_correct[$j] = 0;
- print '<th class="header c1" scope="col" style="width:'.$width.'%; text-align: center;">' . $num[$j]->id . '</th>' . "\n";
- }
- print '<th class="header c1" width=5%> ' . get_string('functions', 'iassign') . '</th>';
- $sum_iassign = $j - 1;
- print '</tr>' . "\n";
- $total = 0;
- $sum_student = 0;
- $comment = iassign_icons::insert('comment_read');
- $sum_comment = 0;
- $sum_correct_iassign = array();
- $sum_correct_student = array();
- $USER->matrix_iassign = array();
- if ($students) {
- $w = 0;
- foreach ($students as $tmp) {
- $users_array[$w] = $tmp;
- $w++;
- }
- for ($x=0; $x<$w; $x++) {
- print '<tr>' . "\n";
- $sum_student++;
- $name = $users_array[$x]->firstname . ' ' . $users_array[$x]->lastname;
- print ' <td style="vertical-align: middle;">' . $name . '</td>' . "\n";
- $total_student = 0;
- $tentativas = 0;
- for ($j=1; $j<$num_exerc; $j++) {
- $sum_comment = $sum_verify_message = 0;
- $student_submissions = $DB->get_record("iassign_submission", array('iassign_statementid' => $num[$j]->iassignid, 'userid' => $users_array[$x]->userid));
- if ($student_submissions) {
- $last_solution_submission = " title=\"" . userdate($student_submissions->timemodified) . "\" ";
- $tentativas = $student_submissions->experiment;
-
-
- $params_temp = array('iassign_submissionid' => $student_submissions->id);
- $student_submissions_comment = $DB->get_record_sql(
- "SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
- "WHERE iassign_submissionid = :iassign_submissionid", $params_temp);
- if ($student_submissions_comment)
- foreach ($student_submissions_comment as $tmp)
- $sum_comment = $tmp;
-
- if ($j - 1 < 1 || $j == $num_exerc) $iassign_previous = "-1";
- else $iassign_previous = $num[$j - 1]->iassignid;
- if ($x - 1 < 0 || $x == $w) $user_previous = "-1";
- else $user_previous = $users_array[$x - 1]->userid;
-
- if ($i - 1 > $j) $iassign_next = $num[$j + 1]->iassignid;
- else $iassign_next = "-1";
- if ($w - 1 > $x) $user_next = $users_array[$x + 1]->userid;
- else $user_next = "-1";
- $position = "&row= $x&column=$j";
- $url = "" . $CFG->wwwroot . "/mod/iassign/view.php?action=viewsubmission&id=" . $id . "&iassign_submission_current=" . $student_submissions->id .
- "&userid_iassign=" . $users_array[$x]->userid . "&iassign_current=" . $num[$j]->iassignid . "&view_iassign=" . $this->view_iassign;
- $url .= $position;
-
-
-
-
- $params_temp = array('iassign_submissionid' => $student_submissions->id, 'return_status' => '0', 'receiver' => '1');
- $verify_message = $DB->get_record_sql(
- "SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
- "WHERE iassign_submissionid = :iassign_submissionid " .
- " AND return_status= :return_status " .
- " AND receiver= :receiver", $params_temp);
- if ($verify_message)
- foreach ($verify_message as $tmp)
- $sum_verify_message = $tmp;
- if ($sum_verify_message > 0)
- $comment = '<i class="fa fa-comments" style="color: #658af7; font-size: 1.4rem;" aria-hidden="true"></i>';
- else
- $comment = '<i class="fa fa-comments" style="color: gray; font-size: 1.3rem;" aria-hidden="true"></i>';
- if ($student_submissions->status == 3) {
- $sum_iassign_correct[$j]++;
- $total_student++;
- $feedback = '<i class="fa fa-check" style="color: green; font-size: 1.2rem;" aria-hidden="true"></i>';
- }
- elseif ($student_submissions->status == 2) {
- $feedback = '<i class="fa fa-times" style="color: red; font-size: 1.2rem;" aria-hidden="true"></i>';
- }
- elseif ($student_submissions->status == 1) {
- $feedback = '<i class="fa fa-question" style="color: #77229c; font-size: 1.2rem;" aria-hidden="true"></i>';
- }
- elseif ($student_submissions->status == 0) {
- $feedback = '<i class="fa fa-question" style="color: #77229c; font-size: 1.2rem;" aria-hidden="true"></i>';
- }
- if ($this->action != 'print') {
- if ($tentativas > 0)
- print '<td style="text-align: center;"> <a href="' . $url . '" ' . $last_solution_submission . '>'
- . '<button type="button" class="btn btn-secondary" style="'.$stylebutton.'">'
- . $feedback
- .'<span class="badge badge-light" style="font-size: 1rem; margin-left: .5rem;">'
- . $tentativas
- . '</span> </button>'
- . '</a>' . "\n";
- else
- print '<td style="text-align: center;"> <a href="' . $url . '" ' . $last_solution_submission . '>'
- . '<button type="button" class="btn btn-secondary" style="'.$stylebutton.'">'
- . $feedback
- .'</button>'
- . '</a>' . "\n";
- if ($sum_comment > 0 && $sum_verify_message > 0)
- print '<a href="' . $url . '"> '
- . '<button type="button" class="btn btn-secondary" style="'.$stylebutton.'">'
- . $comment
- .'<span class="badge badge-light" style="font-size: 1rem; margin-left: .5rem;">'
- . $sum_verify_message . '/' . $sum_comment
- . '</span> </button>'
- . '</a>';
- else if ($sum_comment > 0)
- print '<a href="' . $url . '"> '
- . '<button type="button" class="btn btn-secondary" style="'.$stylebutton.'"> '
- . $comment
- .'<span class="badge badge-light" style="font-size: 1rem; margin-left: .5rem;">'
- . $sum_comment
- . '</span> </button>'
- . '</a>';
- print '</td>' . "\n";
- }
- if ($this->action == 'print')
- print $feedback . ' (' . $tentativas . ')<br>' . $comment . ' (' . $sum_comment . ') ' . "\n";
- }
- else {
-
-
- if ($j - 1 < 1 || $j == $i) $iassign_previous = "-1";
- else $iassign_previous = $num[$j - 1]->iassignid;
- if ($x - 1 < 0 || $x == $w) $user_previous = "-1";
- else $user_previous = $users_array[$x - 1]->userid;
-
- if ($i - 1 > $j) $iassign_next = $num[$j + 1]->iassignid;
- else $iassign_next = "-1";
- if ($w - 1 > $x) $user_next = $users_array[$x + 1]->userid;
- else $user_next = "-1";
- $position = "&row= $x&column=$j";
- $url = $CFG->wwwroot . "/mod/iassign/view.php?action=viewsubmission&id=" . $id . "&userid_iassign=" . $users_array[$x]->userid .
- "&iassign_current=" . $num[$j]->iassignid . "&view_iassign=" . $this->view_iassign;
- $url .= $position;
- $feedback = '<i class="fa fa-question" style="color: #77229c; font-size: 1.2rem;" aria-hidden="true"></i>';
- if ($this->action == 'print')
- print $feedback . ' (0)<br>' . $comment . ' (' . $sum_comment . ') ' . "\n";
- else {
- print '<td style="text-align: center;"> <a href="' . $url . '">'
- . '<button type="button" class="btn btn-secondary" style="'.$stylebutton.'">'
- . $feedback
- .'</button>'
- . '</a>' . "\n";
-
- if ($sum_comment > 0)
- print '<a href="' . $url . '">' . $comment . '</a> (' . $sum_comment . ') ' . "\n";
-
- print '</td>';
- }
- }
- $USER->matrix_iassign[$x][$j] = new stdClass();
- $USER->matrix_iassign[$x][$j]->iassign_previous = $iassign_previous;
- $USER->matrix_iassign[$x][$j]->user_previous = $user_previous;
- $USER->matrix_iassign[$x][$j]->iassign_next = $iassign_next;
- $USER->matrix_iassign[$x][$j]->user_next = $user_next;
- if ($student_submissions)
- $USER->matrix_iassign[$x][$j]->iassign_submission_current = $student_submissions->id;
- else
- $USER->matrix_iassign[$x][$j]->iassign_submission_current = 0;
-
- }
- $total = $total + $total_student;
- $porcentagem = ($total_student / ($j - 1)) * 100;
- if ($tentativas != 0 && $tentativas != null) {
- $url_answer = "" . $CFG->wwwroot . "/mod/iassign/view.php?" . "action=download_all_answer&iassign_id=" . $this->iassign->id . "&userid=" . $users_array[$x]->userid . "&id=" . $id;
- print ' <td align="center"><a href="' . $url_answer . '">' . iassign_icons::insert('download_all_assign') . '</a></td>' . "\n";
- }
- else {
- print ' <td align="center">' . iassign_icons::insert('download_all_assign_disabled') . '</td>' . "\n";
- }
- print '</tr>' . "\n";
- $sum_correct_student[$sum_student] = new stdClass();
- $sum_correct_student[$sum_student]->name = $name;
- $sum_correct_student[$sum_student]->sum = $total_student;
- }
- for ($i = 1; $i < $j; $i++) {
- if (is_null($sum_iassign_correct[$i]))
- $sum_iassign_correct[$i] = 0;
- $sum_correct_iassign[$i] = new stdClass();
- $sum_correct_iassign[$i]->sum = $sum_iassign_correct[$i];
- $sum_correct_iassign[$i]->name = $num[$i]->name;
- }
-
- }
- }
- else {
- print_string('no_activity', 'iassign');
- }
- print "</table>\n";
- print '<p class="mt-5">' . get_string('ps_experiment', 'iassign') . "</p>\n";
- print '<p>' . get_string('ps_comment', 'iassign') . "</p>\n";
- if ($this->action != 'print')
- print $OUTPUT->footer();
- die();
- }
-
- function stats () {
- global $USER, $CFG, $DB, $OUTPUT;
- $id = $this->cm->id;
- $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array('iassignid' => $this->iassign->id), "position ASC");
- if ($this->action != 'printstats')
- $title = get_string('graphic', 'iassign');
- $num = array();
- $sum_correct_iassign = array();
- $sum_correct_student = array();
- $sum_student = 0;
- $i = 1;
- foreach ($iassign_list as $iassign) {
- $iassign_submission = $DB->get_records("iassign_submission", array("iassign_statementid" => $iassign->id));
- if ($iassign->type_iassign == 3) {
- $sum_iassign_correct[$i] = 0;
- $num[$i] = new stdClass();
- $num[$i]->name = $iassign->name;
- $num[$i]->id = $i;
- $num[$i]->iassignid = $iassign->id;
- $i++;
- }
- }
- $sum_iassign = $i - 1;
- $context = context_course::instance($this->course->id);
- if ($i > 1) {
-
- $params_temp = array('shortname' => 'student');
- $role = $DB->get_record_sql(
- "SELECT s.id, s.shortname FROM {role} s " .
- " WHERE s.shortname = :shortname", $params_temp);
-
- $params_temp = array('contextid' => $context->id, 'roleid' => $role->id);
- $students = $DB->get_records_sql(
- "SELECT s.userid, a.firstname, a.lastname FROM {role_assignments} s, {user} a " .
- " WHERE s.contextid = :contextid AND s.userid = a.id AND s.roleid = :roleid " .
- " ORDER BY a.firstname ASC,a.lastname ASC", $params_temp);
- $total = 0;
- $sum_student = 0;
- $j = 0;
- $sum_correct_iassign = array();
- $sum_correct_student = array();
- $sum_experiment = array();
- if ($students) {
- foreach ($students as $users) {
- $sum_student++;
- $name = $users->firstname . ' ' . $users->lastname;
-
- $total_student = 0;
- for ($j = 1; $j < $i; $j++) {
- $total_experiment = 0;
- $student_submissions = $DB->get_record("iassign_submission", array('iassign_statementid' => $num[$j]->iassignid, 'userid' => $users->userid));
- if ($student_submissions) {
- if ($student_submissions->status == 3) {
- $sum_iassign_correct[$j]++;
- $total_student++;
- }
- $total_experiment += $student_submissions->experiment;
- }
- $sum_experiment[$j] = $total_experiment;
- }
- $total = $total + $total_student;
- $sum_correct_student[$sum_student] = new stdClass();
- $sum_correct_student[$sum_student]->name = $name;
- $sum_correct_student[$sum_student]->sum = $total_student;
- }
- }
- for ($i = 1; $i < $j; $i++) {
- if (is_null($sum_iassign_correct[$i]))
- $sum_iassign_correct[$i] = 0;
- $sum_correct_iassign[$i] = new stdClass();
- $sum_correct_iassign[$i]->sum = $sum_iassign_correct[$i];
- $sum_correct_iassign[$i]->name = $num[$i]->name;
- $sum_correct_iassign[$i]->experiment = $sum_experiment[$i];
- }
- }
- print $OUTPUT->header();
- $this->print_main_menu();
- if ($this->action != 'printstats') {
- $title = get_string('graphic', 'iassign');
- $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>";
- $link_print_stats = "<a href='" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&action=printstats&&iassignid=" . $this->iassign->id . "'>" . iassign_icons::insert('print') . ' ' . get_string('print', 'iassign') . "</a>";
- print '<table width=100%><tr>';
- print '<td align="right">' . $link_print_stats . '</td>' . "\n";
- print '<td width=15% align="right">' . $link_report . '</td>';
- print '</td></tr></table>' . "\n";
- print "<br><br>";
- print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
- print '<tr><th colspan=5 class="header c1">' . get_string('distribution_activity', 'iassign') . '</th></tr>' . "\n";
- print '<tr><td class=\'cell c0 actvity\' width=35%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
- print '<td class=\'cell c0 actvity\' width=35%><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>' . "\n";
- print '<td class=\'cell c0 actvity\' width=10% align="right"><strong>' . get_string('proportion_correct', 'iassign') . '</strong>' . "\n";
- print '<td class=\'cell c0 actvity\' width=10% align="right"><strong>' . get_string('sum_experiment', 'iassign') . '</strong></td>' . "\n";
- print '<td class=\'cell c0 actvity\' width=10% align="right"><strong>' . get_string('avg_experiment', 'iassign') . '</strong></td>' . "\n";
- print '</tr>' . "\n";
- $sum_correct = 0;
- if ($sum_correct_iassign) {
- foreach ($sum_correct_iassign as $iassign) {
- if (is_null($iassign->experiment))
- $iassign->experiment = 0;
- $bar = "";
- $sum = $iassign->sum;
- $percent = ($sum / $sum_student) * 100;
- $text = number_format($percent, 1) . '%';
- $sum_correct += $sum;
- if ($sum > 0) {
- for ($i = 1; $i < $percent * 2; $i++)
- $bar .= iassign_icons::insert('hbar_blue');
- $bar .= iassign_icons::insert('hbar_blue_r');
- }
- print '<tr ><td class=\'cell c0 actvity\'width=35%>' . $iassign->name . '</td>' . "\n";
- print ' <td class=\'cell c0 actvity\' width=35%>' . $bar . ' ' . $text . '</td>' . "\n";
- print ' <td class=\'cell c0 actvity\' width=10% align="right">' . $sum . '/' . $sum_student . '</td>' . "\n";
- print ' <td class=\'cell c0 actvity\' width=10% align="right">' . $iassign->experiment . '</td>' . "\n";
- print ' <td class=\'cell c0 actvity\' width=10% align="right">' . number_format($iassign->experiment / $sum_iassign, 1) . '</td>' . "\n";
- print '</tr>' . "\n";
- }
- }
- print "</table>";
- print "<br><br>";
- print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
- print '<tr><th colspan=3 class="header c1">' . get_string('distribution_student', 'iassign') . '</th></tr>' . "\n";
- print '<tr><td class=\'cell c0 actvity\' width=50%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
- print ' <td class=\'cell c0 actvity\' width=40%><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>';
- print ' <td class=\'cell c0 actvity\' width=10% align="right"><strong>' . get_string('sum_correct', 'iassign') . '</strong></td>';
- print '</tr>' . "\n";
- $sum_correct = 0;
- foreach ($sum_correct_student as $student) {
- $bar = "";
- $sum = $student->sum;
- $percent = ($sum / $sum_iassign) * 100;
- $text = number_format($percent, 1) . '%';
- $sum_correct += $sum;
- if ($sum > 0) {
- for ($i = 1; $i < $percent * 2; $i++)
- $bar .= iassign_icons::insert('hbar_blue');
- $bar .= iassign_icons::insert('hbar_blue_r');
- }
- print '<tr ><td class=\'cell c0 actvity\'width=50%>' . $student->name . '</td>' . "\n";
- print '<td class=\'cell c0 actvity\' width=40%>' . $bar . ' ' . $text . '</td>' . "\n";
- print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum . '/' . $sum_iassign . '</td>' . "\n";
- print '</tr>' . "\n";
- }
- print "</table>\n";
- print "<br><br>\n";
- $var = 0;
- $cv = 0;
- $dv = 0;
- $avg = 0;
- if ($sum_correct_student) {
- $avg = $sum_correct / $sum_student;
- if ($avg > 0) {
- foreach ($sum_correct_student as $student)
- $var += pow($student->sum - $avg, 2);
- $var = $var / $sum_student;
- $dv = sqrt($var);
- $cv = ($dv / $avg) * 100;
- }
- }
- print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
- print '<tr><th colspan=5 class="header c1">' . get_string('statistics', 'iassign') . '</th></tr>' . "\n";
- print '<tr><td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('sum_activity', 'iassign') . '</strong></td>' . "\n";
- print ' <td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('sum_student', 'iassign') . '</strong></td>' . "\n";
- print ' <td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('mean_score', 'iassign') . '</strong></td>' . "\n";
- print ' <td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('standard_deviation', 'iassign') . '</strong></td>' . "\n";
- print ' <td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('coefficient_variation', 'iassign') . '</strong></td></tr>' . "\n";
- print '<tr><td class=\'cell c0 actvity\' width=20% align="center">' . $sum_iassign . '</td>' . "\n";
- print ' <td class=\'cell c0 actvity\' width=20% align="center">' . $sum_student . '</td>' . "\n";
- print ' <td class=\'cell c0 actvity\' width=20% align="center">' . number_format($avg, 1) . '</td>' . "\n";
- print ' <td class=\'cell c0 actvity\' width=20% align="center">' . number_format($dv, 1) . '</td>' . "\n";
- print ' <td class=\'cell c0 actvity\' width=20% align="center">' . number_format($cv, 1) . '%</td></tr>' . "\n";
- print "</table>\n";
- print $OUTPUT->footer();
- } else {
- print "<STYLE TYPE='text/css'>
- <!--
- .boldtable {
- font-family:sans-serif;
- font-size:10pt;
- }
- -->
- </STYLE>\n";
- print '<table border=1 width=100%>' . "\n";
- print '<tr><td colspan=3 align="center"><strong>' . get_string('distribution_activity', 'iassign') . '</strong></td></tr>' . "\n";
- print '<tr><td width=50%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
- print '<td width=40%><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>';
- print '<td width=10% align="right"><strong>' . get_string('sum_correct', 'iassign') . '</strong></td>';
- print '</tr>' . "\n";
- $sum_correct = 0;
- foreach ($sum_correct_iassign as $iassign) {
- $bar = "";
- $sum = $iassign->sum;
- $percent = ($sum / $sum_student) * 100;
- $text = number_format($percent, 1) . '%';
- $sum_correct += $sum;
- if ($sum > 0) {
- for ($i = 1; $i < $percent * 2; $i++)
- $bar .= iassign_icons::insert('hbar_blue');
- $bar .= iassign_icons::insert('hbar_blue_r');
- }
- print '<tr><td width=50%>' . $iassign->name . '</td>' . "\n";
- print '<td width=40%>' . $bar . ' ' . $text . '</td>';
- print '<td width=10% align="right">' . $sum . '/' . $sum_student . '</td>';
- print '</tr>' . "\n";
- }
- print "</table>";
- print "<br><br>";
- print '<table border=1 class="boldtable" width=100%>' . "\n";
- print '<tr><td colspan=3 align="center" ><strong>' . get_string('distribution_student', 'iassign') . '</strong></td></tr>' . "\n";
- print '<tr><td width=50%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
- print '<td width=40%><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>';
- print '<td width=10% align="right"><strong>' . get_string('sum_correct', 'iassign') . '</strong></td>';
- print '</tr>' . "\n";
- $sum_correct = 0;
- foreach ($sum_correct_student as $student) {
- $bar = "";
- $sum = $student->sum;
- $percent = ($sum / $sum_iassign) * 100;
- $text = number_format($percent, 1) . '%';
- $sum_correct += $sum;
- if ($sum > 0) {
- for ($i = 1; $i < $percent * 2; $i++)
- $bar .= iassign_icons::insert('hbar_blue');
- $bar .= iassign_icons::insert('hbar_blue_r');
- }
- print "<tr><td width=50%>" . $student->name . "</td>\n";
- print ' <td width=40%>' . $bar . ' ' . $text . '</td>' . "\n";
- print ' <td width=10% align="right">' . $sum . '/' . $sum_iassign . '</td>' . "\n";
- print '</tr>' . "\n";
- }
- print "</table>\n";
- print "<br/><br/>\n";
- $var = 0;
- $cv = 0;
- $dv = 0;
- $avg = 0;
- if ($sum_correct_student) {
- $avg = $sum_correct / $sum_student;
- if ($avg > 0) {
- foreach ($sum_correct_student as $student)
- $var += pow($student->sum - $avg, 2);
- $var = $var / $sum_student;
- $dv = sqrt($var);
- $cv = ($dv / $avg) * 100;
- }
- }
- print '<table border=1 class="boldtable" width=100%>' . "\n";
- print '<tr><td colspan=5 align="center"><strong>' . get_string('statistics', 'iassign') . '</strong></th></tr>' . "\n";
- print '<tr><td width=20% align="center"><strong>' . get_string('sum_activity', 'iassign') . '</strong></td>' . "\n";
- print '<td width=20% align="center"><strong>' . get_string('sum_student', 'iassign') . '</strong></td>' . "\n";
- print '<td width=20% align="center"><strong>' . get_string('mean_score', 'iassign') . '</strong></td>' . "\n";
- print '<td width=20% align="center"><strong>' . get_string('standard_deviation', 'iassign') . '</strong></td>' . "\n";
- print '<td width=20% align="center"><strong>' . get_string('coefficient_variation', 'iassign') . '</strong></td></tr>' . "\n";
- print '<tr><td width=20% align="center">' . $sum_iassign . '</td>' . "\n";
- print '<td width=20% align="center">' . $sum_student . '</td>' . "\n";
- print '<td width=20% align="center">' . number_format($avg, 1) . '</td>' . "\n";
- print '<td width=20% align="center">' . number_format($dv, 1) . '</td>' . "\n";
- print '<td width=20% align="center">' . number_format($cv, 1) . '%</td></tr>' . "\n";
- print "</table>\n";
- }
- die();
- }
-
- function stats_students () {
- global $USER, $CFG, $DB, $OUTPUT;
- $id = $this->cm->id;
- $iassign_statement_list = $DB->get_records_sql("SELECT * FROM {iassign_statement} s " .
- " WHERE s.iassignid = '{$this->iassign->id}' AND s.type_iassign=3 ORDER BY s.position");
- $title = get_string('results', 'iassign');
- $sum_correct = 0;
- $sum_incorrect = 0;
- $sum_post = 0;
- $sum_nopost = 0;
- $sum_iassign = count($iassign_statement_list);
- $bar_nopost = "";
- $bar_correct = "";
- $bar_incorrect = "";
- $bar_post = "";
- $text_nopost = "";
- $text_correct = "";
- $text_incorrect = "";
- foreach ($iassign_statement_list as $iassign_statement_activity_item) {
- $iassign_submission = $DB->get_record("iassign_submission", array('iassign_statementid' => $iassign_statement_activity_item->id, 'userid' => $USER->id));
- if ($iassign_submission) {
- if ($iassign_submission->status == 3)
- $sum_correct++;
- elseif ($iassign_submission->status == 2)
- $sum_incorrect++;
- elseif ($iassign_submission->status == 1)
- $sum_post++;
- elseif ($iassign_submission->status == 0 || !$iassign_submission)
- $sum_nopost++;
- }
- }
- if ($sum_iassign > 0) {
- $percent_correct = ($sum_correct / $sum_iassign) * 100;
- $text_correct = number_format($percent_correct, 1) . '%';
- }
- if ($sum_correct > 0) {
- for ($i = 1; $i < $percent_correct * 2; $i++)
- $bar_correct .= iassign_icons::insert('hbar_green');
- $bar_correct .= iassign_icons::insert('hbar_green_r');
- }
- if ($sum_iassign > 0) {
- $percent_incorrect = ($sum_incorrect / $sum_iassign) * 100;
- $text_incorrect = number_format($percent_incorrect, 1) . '%';
- }
- if ($sum_incorrect > 0) {
- for ($i = 1; $i < $percent_incorrect * 2; $i++)
- $bar_incorrect .= iassign_icons::insert('hbar_red');
- $bar_incorrect .= iassign_icons::insert('hbar_red_r');
- }
- if ($sum_iassign > 0) {
- $percent_post = ($sum_post / $sum_iassign) * 100;
- $text_post = number_format($percent_post, 1) . '%';
- }
- if ($sum_post > 0) {
- for ($i = 1; $i < $percent_post * 2; $i++)
- $bar_post .= iassign_icons::insert('hbar_blue');
- $bar_post .= iassign_icons::insert('hbar_blue_r');
- }
- if ($sum_iassign > 0) {
- $percent_nopost = ($sum_nopost / $sum_iassign) * 100;
- $text_nopost = number_format($percent_nopost, 1) . '%';
- }
- if ($sum_nopost > 0) {
- for ($i = 1; $i < $percent_nopost * 2; $i++)
- $bar_nopost .= iassign_icons::insert('hbar_orange');
- $bar_nopost .= iassign_icons::insert('hbar_orange_r');
- }
- print $OUTPUT->header();
- $this->print_main_menu();
-
-
-
-
- print "<br/><br/>\n";
- print '<table id="outlinetable" class="generaltable box aligncenter mt-5" cellpadding="5" width="100%">' . "\n";
- print '<tr><th colspan=3 class="header c1">' . "\n";
-
-
- print iassign_utils::remove_code_message($this->iassign->name) . '</th></tr>' . "\n";
- print '<tr ><td class=\'cell c0 actvity\'width=50%>' . get_string('correct', 'iassign') . '</td>' . "\n";
- print '<td class=\'cell c0 actvity\' width=40%>' . $bar_correct . ' ' . $text_correct . '</td>';
- print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum_correct . '/' . $sum_iassign . '</td>';
- print '</tr>' . "\n";
- print '<tr ><td class=\'cell c0 actvity\'width=50%>' . get_string('incorrect', 'iassign') . '</td>' . "\n";
- print '<td class=\'cell c0 actvity\' width=40%>' . $bar_incorrect . ' ' . $text_incorrect . '</td>';
- print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum_incorrect . '/' . $sum_iassign . '</td>';
- print '</tr>' . "\n";
- if ($sum_post) {
- print '<tr ><td class=\'cell c0 actvity\'width=50%>' . get_string('post', 'iassign') . '</td>' . "\n";
- print '<td class=\'cell c0 actvity\' width=40%>' . $bar_post . ' ' . $text_post . '</td>';
- print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum_post . '/' . $sum_iassign . '</td>';
- print '</tr>' . "\n";
- }
- print '<tr ><td class=\'cell c0 actvity\'width=50%>' . get_string('not_post', 'iassign') . '</td>' . "\n";
- print '<td class=\'cell c0 actvity\' width=40%>' . $bar_nopost . ' ' . $text_nopost . '</td>';
- print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum_nopost . '/' . $sum_iassign . '</td>';
- print '</tr>' . "\n";
- print "</table>";
- print "<br><br>";
- print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
- print '<tr><th colspan=3 class="header c1">' . get_string('grades', 'iassign') . '</th></tr>' . "\n";
- print '<tr><td class=\'cell c0 actvity\' width=50%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
- print '<td class=\'cell c0 actvity\' width=25% align=right><strong>' . get_string('grade_student', 'iassign') . '</strong></td>' . "\n";
- print '<td class=\'cell c0 actvity\' width=25% align=right><strong>' . get_string('grade_iassign', 'iassign') . '</strong></tr>' . "\n";
- $sum_grade = 0;
- $sum_grade_student = 0;
- $avg = 0;
- foreach ($iassign_statement_list as $iassign_statement_activity_item) {
- $iassign_submission = $DB->get_record("iassign_submission", array('iassign_statementid' => $iassign_statement_activity_item->id, 'userid' => $USER->id));
- if (!$iassign_submission) {
- $iassign_submission = new stdClass();
- $iassign_submission->grade = 0;
- }
- print '<tr ><td class=\'cell c0 actvity\'width=50%>' . $iassign_statement_activity_item->name . '</td>' . "\n";
- print '<td class=\'cell c0 actvity\' width=25% align=right>' . $iassign_submission->grade . '</td>';
- print '<td class=\'cell c0 actvity\' width=25% align=right>' . $iassign_statement_activity_item->grade . '</td>';
- print '</tr>' . "\n";
- $sum_grade += $iassign_statement_activity_item->grade;
- $sum_grade_student += $iassign_submission->grade;
- }
- if ($sum_grade > 0)
- $avg = $sum_grade_student / $sum_grade * 100;
- print '<tr><td class=\'cell c0 actvity\' width=50%><strong>' . get_string('total', 'iassign') . '</strong></td>' . "\n";
- print '<td class=\'cell c0 actvity\' width=25% align=right><strong>' . $sum_grade_student . '</strong></td>' . "\n";
- print '<td class=\'cell c0 actvity\' width=25% align=right><strong>' . $sum_grade . '</strong></tr>' . "\n";
- print '<tr><td class=\'cell c0 actvity\' width=25% align=left><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>' . "\n";
- print '<td colspan=2 class=\'cell c0 actvity\' align=right><strong>' . number_format($avg, 1) . '%</strong></tr>' . "\n";
- print "</table>";
- print $OUTPUT->footer();
- die();
- }
- function get_total_notifications () {
- global $DB, $USER, $COURSE;
- $total_messages = 0;
- if (has_capability('mod/iassign:editiassign', $this->context, $USER->id)) {
- $params = array('userid' => $USER->id, 'course' => $COURSE->id, 'receiver' => '1');
- $total_messages = $DB->get_record_sql("SELECT COUNT(*) AS total FROM {iassign_submission_comment} AS c, {iassign_submission} AS s, {iassign_statement} AS st, {iassign} AS ias "
- . " WHERE c.return_status=0 AND c.receiver=:receiver AND c.iassign_submissionid=s.id AND s.iassign_statementid=st.id AND st.iassignid=ias.id AND ias.course=:course", $params);
- }
- else {
- $params = array('userid' => $USER->id, 'course' => $COURSE->id, 'receiver' => '2');
- $total_messages = $DB->get_record_sql("SELECT COUNT(*) AS total FROM {iassign_submission_comment} AS c, {iassign_submission} AS s, {iassign_statement} AS st, {iassign} AS ias "
- . " WHERE c.return_status=0 AND c.receiver=:receiver AND c.iassign_submissionid=s.id AND s.userid=:userid AND s.iassign_statementid=st.id AND st.iassignid=ias.id AND ias.course=:course", $params);
- }
- return $total_messages->total;
- }
- function get_iassign_statement_messages () {
- global $DB, $USER, $COURSE;
- if (has_capability('mod/iassign:editiassign', $this->context, $USER->id)) {
- $params = array('userid' => $USER->id, 'course' => $COURSE->id, 'receiver' => '1');
- $totais = array();
- $messages = $DB->get_records_sql("SELECT c.id AS commentid, st.id AS stid, s.userid AS user, ias.id AS iasid, s.id AS subid, st.name AS stname, ias.name AS iasname FROM {iassign_submission_comment} AS c, {iassign_submission} AS s, {iassign_statement} AS st, {iassign} AS ias "
- . " WHERE c.return_status=0 AND c.receiver=:receiver AND c.iassign_submissionid=s.id AND s.iassign_statementid=st.id AND st.iassignid=ias.id AND ias.course=:course", $params);
- foreach($messages as $item) {
- if (isset($totais[$item->subid])) {
- $totais[$item->subid]->total++;
- }
- else {
- $totais[$item->subid] = new stdclass();
- $item->total = 1;
- $totais[$item->subid] = $item;
- }
- }
- return $totais;
- }
- else {
- $params = array('userid' => $USER->id, 'course' => $COURSE->id, 'receiver' => '2');
- $totais = array();
- $messages = $DB->get_records_sql("SELECT c.id as commentid, s.id AS subid, st.id AS stid, ias.id AS iasid, s.userid AS userid, st.name AS stname, ias.name AS iasname FROM {iassign_submission_comment} AS c, {iassign_submission} AS s, {iassign_statement} AS st, {iassign} AS ias "
- . " WHERE c.return_status=0 AND c.receiver=:receiver AND c.iassign_submissionid=s.id AND s.userid=:userid AND s.iassign_statementid=st.id AND st.iassignid=ias.id AND ias.course=:course", $params);
- foreach($messages as $item) {
- if (isset($totais[$item->subid])) {
- $totais[$item->subid]->total++;
- }
- else {
- $totais[$item->subid] = new stdclass();
- $item->total = 1;
- $totais[$item->subid] = $item;
- }
- }
- return $totais;
- }
- }
- function view_notifications_teachers () {
- global $OUTPUT, $USER, $DB;
- $messages = $this->get_iassign_statement_messages();
- print '<table class="table table-hover ml-4 mb-4 w-75 mt-3" style="border-bottom: 1px solid #dee2e6;">';
-
- $actual_block = $this->iassign->id;
- $id = $this->cm->id;
- $total_include = 0;
- $activities_actual_block = array();
- if ($messages)
- foreach ($messages as $item)
- if ($item->iasid == $actual_block)
- if (!in_array($item->stid, $activities_actual_block))
- array_push($activities_actual_block, $item->stid);
- if ($activities_actual_block)
- foreach ($activities_actual_block as $activity_id) {
- $printed = false;
- foreach ($messages as $item) {
- if ($item->stid == $activity_id) {
- if (!$printed) {
- $student_url = "view.php?id=$id&userid_iassign=$USER->id&action=view&iassign_current=$item->stid";
- $link_student = "<a href='$student_url'>" . $item->stname . "</a>";
- print '<tr><td style="white-space: nowrap; width: 1%; padding-right: 2rem;" class="align-middle">' . $link_student . '';
- print '<table class="table table-hover ml-4 mb-4 w-75 mt-3" style="border-bottom: 1px solid #dee2e6;">';
- $printed = true;
- }
- $submission_url = "view.php?id=$id&userid_iassign=$item->user&action=viewsubmission&iassign_current=$item->stid";
- $user = $DB->get_record('user', array('id' => $item->user));
- $label = $item->total > 1 ? get_string('comment_unread', 'iassign') : get_string('comment_unread_one', 'iassign');
- print '<tr><td style="white-space: nowrap; width: 1%; padding-right: 2rem;" class="align-middle"><i class="fa fa-user" aria-hidden="true"></i> '
- . $user->firstname . ' ' . $user->lastname . ' </td>'.
- '<td class="align-middle"> <a href="'.$submission_url.'#comments"><span class="badge bg-danger" style="color:white; font-size: .9em;"><i class="fa fa-envelope" aria-hidden="true"></i> ' . $label . ' <span class="badge rounded-pill bg-light text-dark" style="font-size: .8em;">'.$item->total.'</span> </span></a></td>'
- .'</tr>';
- $total_include++;
- }
- }
- print '</td></tr></table>';
- }
- print '</table>';
- if (count($activities_actual_block) == 0) {
- print '<h6 class="ml-5">'.get_string('empty_new_messages_block', 'iassign').'</h6>';
- print '<hr class="my-4">';
- }
- if ($messages && $total_include == count($messages)) {
- print $OUTPUT->footer();
- return;
- }
- print '<h4 class="mt-4 mb-3 ml-2"><i class="fa fa-comments-o" aria-hidden="true"></i> '.get_string('new_messages_other_blocks', 'iassign').'</h4>';
- $iassign_ids = array();
- if ($messages)
- foreach ($messages as $item)
- if (!in_array($item->iasid, $iassign_ids) && $item->iasid != $actual_block)
- array_push($iassign_ids, $item->iasid);
- foreach ($iassign_ids as $id_iassign) {
- $printed = false;
- $activities_in_block = array();
- foreach ($messages as $subitem)
- if ($subitem->iasid == $id_iassign)
- if (!in_array($item->stid, $activities_in_block))
- array_push($activities_in_block, $item->stid);
- foreach ($messages as $item) {
- if ($item->iasid == $id_iassign) {
- if (!$printed) {
- $printed = true;
- print '<i class="fa fa-th-large ml-4 mb-3 mt-2" aria-hidden="true"></i> ' . $item->iasname . '<br>';
- print '<table class="table table-hover ml-5 w-75" style="border-bottom: 1px solid #dee2e6;">';
- }
- foreach ($activities_in_block as $id_activity) {
- $print = false;
- foreach ($messages as $subitem) {
- if ($subitem->stid == $id_activity) {
- if (!$print) {
- $student_url = "view.php?id=$id&userid_iassign=$USER->id&action=view&iassign_current=$subitem->stid";
- $link_student = "<a href='$student_url'>" . $subitem->stname . "</a>";
- print '<tr><td style="white-space: nowrap; width: 1%; padding-right: 2rem;" class="align-middle">' . $link_student . '';
- print '<table class="table table-hover ml-4 mb-4 w-75 mt-3" style="border-bottom: 1px solid #dee2e6;">';
- $print = true;
- }
- foreach ($messages as $comment_student) {
- if ($comment_student->stid == $id_activity) {
- $submission_url = "view.php?id=$id&userid_iassign=$comment_student->user&action=viewsubmission&iassign_current=$comment_student->stid";
- $user = $DB->get_record('user', array('id' => $comment_student->user));
- $label = $comment_student->total > 1 ? get_string('comment_unread', 'iassign') : get_string('comment_unread_one', 'iassign');
- print '<tr><td style="white-space: nowrap; width: 1%; padding-right: 2rem;" class="align-middle"><i class="fa fa-user" aria-hidden="true"></i> '
- . $user->firstname . ' ' . $user->lastname . ' </td>'.
- '<td class="align-middle"> <a href="'.$submission_url.'#comments"><span class="badge bg-danger" style="color:white; font-size: .9em;"><i class="fa fa-envelope" aria-hidden="true"></i> ' . $label . ' <span class="badge rounded-pill bg-light text-dark" style="font-size: .8em;">'.$comment_student->total.'</span> </span></a></td>'
- .'</tr>';
- }
- }
- break;
- }
- }
- }
- print '</table></td></tr></table>';
- break;
- }
- }
- }
- print $OUTPUT->footer();
- }
- function view_notifications () {
- global $OUTPUT, $USER;
- print $OUTPUT->header();
- $this->print_main_menu();
- print '<h4 class="mt-4 ml-2"><i class="fa fa-comments-o" aria-hidden="true"></i> '.get_string('new_messages', 'iassign').'</h4>';
- if ($this->get_total_notifications() == 0) {
- print '<h6 class="mt-3 ml-5">'.get_string('empty_new_messages', 'iassign').'</h6>';
- print '<hr class="my-4">';
- print $OUTPUT->footer();
- return;
- }
- if (has_capability('mod/iassign:editiassign', $this->context, $USER->id)) {
- $this->view_notifications_teachers();
- return;
- }
- $messages = $this->get_iassign_statement_messages();
- print '<table class="table table-hover ml-4 mb-4 w-75 mt-3" style="border-bottom: 1px solid #dee2e6;">';
-
- $actual_block = $this->iassign->id;
- $id = $this->cm->id;
- $total_include = 0;
- if ($messages)
- foreach ($messages as $item) {
- if ($item->iasid == $actual_block) {
- $student_url = "view.php?id=$id&userid_iassign=$USER->id&action=view&iassign_current=$item->stid#comments";
- $link_student = "<a href='$student_url'>" . $item->stname . "</a>";
- $label = $item->total > 1 ? get_string('comment_unread', 'iassign') : get_string('comment_unread_one', 'iassign');
- print '<tr><td style="white-space: nowrap; width: 1%; padding-right: 2rem;" class="align-middle">' . $link_student . '</td><td class="align-middle"> <a href="'.$student_url.'"><span class="badge bg-danger" style="color:white; font-size: .9em;"><i class="fa fa-envelope" aria-hidden="true"></i> ' . $label . ' <span class="badge rounded-pill bg-light text-dark" style="font-size: .8em;">'.$item->total.'</span> </span></a></td></tr>';
- $total_include++;
- }
- }
- print '</table>';
- if ($total_include == 0) {
- print '<h6 class="ml-5">'.get_string('empty_new_messages_block', 'iassign').'</h6>';
- print '<hr class="my-4">';
- }
- if ($messages && $total_include == count($messages)) {
- print $OUTPUT->footer();
- return;
- }
- print '<h4 class="mt-4 mb-3 ml-2"><i class="fa fa-comments-o" aria-hidden="true"></i> '.get_string('new_messages_other_blocks', 'iassign').'</h4>';
-
- $iassign_ids = array();
- if ($messages)
- foreach ($messages as $item)
- if (!in_array($item->iasid, $iassign_ids) && $item->iasid != $actual_block)
- array_push($iassign_ids, $item->iasid);
- foreach ($iassign_ids as $id_iassign) {
- $printed = false;
- foreach ($messages as $item) {
- if ($item->iasid == $id_iassign) {
- if (!$printed) {
- $printed = true;
- print '<i class="fa fa-th-large ml-4 mb-3 mt-2" aria-hidden="true"></i> ' . $item->iasname . '<br>';
- print '<table class="table table-hover ml-5 w-75" style="border-bottom: 1px solid #dee2e6;">';
- }
- $student_url = "view.php?id=$id&userid_iassign=$USER->id&action=view&iassign_current=$item->stid#comments";
- $link_student = "<a href='$student_url'>" . $item->stname . "</a>";
- $label = $item->total > 1 ? get_string('comment_unread', 'iassign') : get_string('comment_unread_one', 'iassign');
- print '<tr><td style="white-space: nowrap; width: 1%; padding-right: 2rem;" class="align-middle">' . $link_student . '</td><td class="align-middle"> <a href="'.$student_url.'"><span class="badge bg-danger" style="color:white; font-size: .9em;"><i class="fa fa-envelope" aria-hidden="true"></i> ' . $label . ' <span class="badge rounded-pill bg-light text-dark" style="font-size: .8em;">'.$item->total.'</span> </span></a> </td></tr>';
- }
- }
- print '</table>';
- }
- print $OUTPUT->footer();
- }
- function print_main_menu () {
- global $USER;
- $id = $this->cm->id;
- $actual_action = optional_param('action', '', PARAM_TEXT);
- $url_help = new moodle_url('/mod/iassign/settings_ilm.php', array('action' => 'list', 'ilm_id' => 1));
- $url_report = new moodle_url('/mod/iassign/view.php', array('action' => 'report', 'id' => $id, 'iassignid' => $this->iassign->id));
- $url_add = new moodle_url('/mod/iassign/view.php', array('id' => $id, 'action' => 'add', 'iassignid' => $this->iassign->id));
- $url_stats = new moodle_url('/mod/iassign/view.php', array('id' => $id, 'action' => 'stats_student', 'iassignid' => $this->iassign->id));
- $url_home = new moodle_url('/mod/iassign/view.php', array('id' => $id));
- $url_notifications = new moodle_url('/mod/iassign/view.php', array('id' => $id, 'action' => 'notifications', 'iassignid' => $this->iassign->id));
- $url_auto_evaluate = new moodle_url('/mod/iassign/view.php', array('id' => $id, 'action' => 'auto_evaluate', 'iassignid' => $this->iassign->id));
- $url_sub_stats = new moodle_url('/mod/iassign/view.php', array('id' => $id, 'action' => 'stats', 'iassignid' => $this->iassign->id));
- $url_all_submissions = new moodle_url('/mod/iassign/view.php', array('id' => $id, 'action' => 'all_submissions', 'iassignid' => $this->iassign->id));
- $url_import_activity = new moodle_url('/mod/iassign/view.php', array('id' => $id, 'action' => 'import_activity', 'iassignid' => $this->iassign->id));
- print '<div class="btn-group" role="group" aria-label="">';
- print '<a href="' . $url_home . '" class="btn btn-outline-primary ' . ($actual_action == '' ? 'active' : '') . '">' . "\n";
- print ' <i class="fa fa-home" aria-hidden="true"></i> ' . get_string('activities_page', 'iassign') . "</a>\n";
- if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id)) {
-
-
- print '<a href="'.$url_help.'" class="btn btn-outline-primary"><i class="fa fa-question-circle" aria-hidden="true"></i> '.get_string('help_ilm', 'iassign').'</a>';
- print '<div class="btn-group"><div class="btn-group">
- <a href="'.$url_report.'" class="btn btn-outline-primary '.($actual_action == 'report' || $actual_action == 'stats' || $actual_action == 'all_submissions' ? 'active' : '').' dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
- <i class="fa fa-bar-chart" aria-hidden="true"></i> '.get_string('report', 'iassign').'</a>
- <div class="dropdown-menu">
- <a href="'.$url_report.'" class=" '.($actual_action == 'report' ? 'active' : ''). ' dropdown-item"><i class="fa fa-bar-chart" aria-hidden="true"></i> '.get_string('home', 'iassign').'</a>
- <div class="dropdown-divider"></div>
- <a href="'.$url_sub_stats.'" class="dropdown-item '.($actual_action == 'stats' ? 'active' : '').'"><i class="fa fa-pie-chart" aria-hidden="true"></i> '.get_string('graphic', 'iassign') .'</a>
- <div class="dropdown-divider"></div>
- <a href="'.$url_all_submissions.'" class="dropdown-item '.($actual_action == 'all_submissions' ? 'active' : '').'"><i class="fa fa-files-o" aria-hidden="true"></i> '.get_string('all_submissions_manager', 'iassign') .'</a>
- </div>
- </div>
- ';
- print '<a href="' . $url_stats . '" class="btn btn-outline-primary ' . ($actual_action == 'stats_student' ? 'active' : '') . '"><i class="fa fa-list" aria-hidden="true"></i> ' . get_string('results', 'iassign') . '</a>';
- print '<a href="' . $url_auto_evaluate . '" class="btn btn-outline-primary ' . ($actual_action == 'auto_evaluate' ? 'active' : '') . '"><i class="fa fa-check-square-o" aria-hidden="true"></i> ' . get_string('auto_evaluate_name_config', 'iassign') . '</a>';
- }
- $notifications = $this->get_total_notifications();
- print '<a href="' . $url_notifications . '" class="btn btn-outline-primary ' . ($actual_action == 'notifications' ? 'active' : '') . '">' . "\n";
- print ' <i class="fa fa-bell" aria-hidden="true"></i> ' . get_string('notifications', 'iassign');
- if ($notifications > 0)
- print ' <span class="badge bg-danger rounded-pill" style="color: white; font-size: .9rem;">'.$notifications.'</span>';
- print '</a></div><div class="btn-group">';
- if (has_capability('mod/iassign:editiassign', $this->context, $USER->id)) {
- print '<a href="' . $url_add . '" class="btn btn-success"><i class="fa fa-plus" aria-hidden="true"></i> ' . get_string('add_iassign', 'iassign') . "</a>\n";
- print '
- <button type="button" class="btn btn-success dropdown-toggle dropdown-toggle-split" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
- </button>
- <div class="dropdown-menu">
- <a class="dropdown-item" href="' . $url_import_activity . '">' . get_string('import_activity', 'iassign') . '</a>
- </div>';
- }
- print '</div></div>' . "\n";
- }
-
- function view_iassigns () {
- global $USER, $CFG, $COURSE, $DB, $OUTPUT;
- $id = $this->cm->id;
- $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array('iassignid' => $this->iassign->id), 'position ASC');
- $notice = optional_param('notice', '', PARAM_TEXT);
- if (strpos($notice, 'error'))
- print($OUTPUT->notification(get_string($notice, 'iassign'), 'notifyproblem'));
- else if ($notice != '')
- print($OUTPUT->notification(get_string($notice, 'iassign'), 'notifysuccess'));
- $this->print_main_menu();
- print $OUTPUT->box_start();
- if (has_capability('mod/iassign:editiassign', $this->context, $USER->id)) {
- print '<div class="border float-right">' . "\n";
- if ($iassign_list) {
-
-
- if (!isset($USER->iassignEdit))
- $USER->iassignEdit = 0;
- if ($USER->iassignEdit == 0) {
- $bottonEdit_message = get_string('turneditingon', 'iassign');
- $botton = 1;
- }
- elseif ($USER->iassignEdit == 1) {
- $bottonEdit_message = get_string('turneditingoff', 'iassign');
- $botton = 0;
- }
- $editPost = "" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&botton=" . $botton;
- print "\n<form name='formEditPost' id='formEditPost' method='post' action='$editPost' enctype='multipart/form-data'>\n";
- print " <input class='btn btn-primary' type=submit value='" . $bottonEdit_message . "'/>\n";
- print "</form>\n";
- }
- print "</div>\n";
- }
-
-
- print $OUTPUT->box_end();
- $iassign_array_exercise = array();
- $i_exercise = 0;
- $iassign_array_test = array();
- $i_test = 0;
- $iassign_array_example = array();
- $i_example = 0;
- $iassign_array_general = array();
- $i_general = 0;
- if ($iassign_list) {
- if ($this->iassign->activity_group == 0) {
- foreach ($iassign_list as $iassign) {
- $iassign_array_general[$i_general] = $iassign;
- $i_general++;
- }
- }
- else {
- foreach ($iassign_list as $iassign) {
- if ($iassign->type_iassign == 3) {
- $iassign_array_exercise[$i_exercise] = $iassign;
- $i_exercise++;
- }
- if ($iassign->type_iassign == 2) {
- $iassign_array_test[$i_test] = $iassign;
- $i_test++;
- }
- if ($iassign->type_iassign == 1) {
- $iassign_array_example[$i_example] = $iassign;
- $i_example++;
- }
- }
- }
- if ($iassign_array_exercise) {
- $title = get_string('exercise', 'iassign').(count($iassign_array_exercise)>1?'s':'');
- $this->show_iassign($title, $iassign_array_exercise, $i_exercise);
- }
- if ($iassign_array_test) {
- $title = get_string('test', 'iassign').(count($iassign_array_test)>1?'s':'');
- $this->show_iassign($title, $iassign_array_test, $i_test);
- }
- if ($iassign_array_example) {
- $title = get_string('example', 'iassign').(count($iassign_array_example)>1?'s':'');;
- $this->show_iassign($title, $iassign_array_example, $i_example);
- }
- if ($iassign_array_general) {
- $title = "";
- $this->show_iassign($title, $iassign_array_general, $i_general);
- }
- } else {
- print $OUTPUT->notification(get_string('no_activity', 'iassign'), 'notifysuccess');
- }
- if (count($iassign_list) > 5 && !(has_capability('mod/iassign:submitiassign', $this->context, $USER->id))) {
- if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id)) {
- print $OUTPUT->box_start();
- print '<table width=100% border=0><tr>' . "\n";
- print '<td width=10% align="left">' . "\n";
- print $link_report;
- print '</td>' . "\n";
- print '</tr></table>' . "\n";
- print $OUTPUT->box_end();
- }
- if (has_capability('mod/iassign:editiassign', $this->context, $USER->id)) {
- print $OUTPUT->box_start();
- print '<table width=100% border=0><tr>' . "\n";
- print '<td align="left">' . "\n";
- print $link_add;
- print '</td>' . "\n";
- print '</tr></table>' . "\n";
- print $OUTPUT->box_end();
- }
- }
-
-
- }
-
-
- function show_iassign ($title, $iassign_array, $total_of_activities) {
- global $USER, $CFG, $DB, $OUTPUT, $PAGE;
- $id = $this->cm->id;
- print $OUTPUT->box_start();
- print " <script type='text/javascript'>
- //<![CDATA[
- function validate_move () {
- var radios = document.getElementsByName('iassign_destiny');
- var formValid = false;
- //alert('aqui validate_move()');
- var i = 0;
- while (!formValid && i < radios.length) {
- if (radios[i].checked) formValid = true;
- i++;
- }
- if (!formValid) {
- document.getElementById('move_dest').classList.add('alert-danger');
- }
- return formValid;
- }
- var modal;
- function load_move(id_ias) {
- document.form_move_activity.iassign_current.value = id_ias;
- modal.style.display = 'block';
- var radios = document.getElementsByName('iassign_destiny');
- var i = 0;
- while (i < radios.length) {
- radios[i].checked = false;
- i++;
- }
- document.getElementById('move_dest').classList.remove('alert-danger');
- }
- function closeModal () {
- modal.style.display = 'none';
- }
- function load_modal_elements () {
- modal = document.getElementById('myModal');
- var span = document.getElementById('close_modal');
- span.onclick = function() {
- modal.style.display = 'none';
- }
- window.onclick = function(event) {
- if (event.target == modal) {
- modal.style.display = 'none';
- }
- }
- }
- window.onload = load_modal_elements;
- //]]>
- </script>\n";
- print " <div id='myModal' class='modal'>\n <div class='modal-content'>\n <span id='close_modal'>×</span>\n" .
- " <div id='modal_title' class='moodle-dialogue-hd yui3-widget-hd'>" . get_string('move_activity', 'iassign') . "</div>\n" .
- " <div style='padding: 10px; padding-left: 20px;' id='move_dest'>" . get_string('move_destination', 'iassign') . ":\n <div style='margin: 5px;'>";
- $ccm = get_coursemodule_from_id('iassign', optional_param('id', 0, PARAM_INT));
- $radio_buttons = " <form name='form_move_activity'><input type='hidden' name='action' value='move_activity' />
- <input type='hidden' name='id' value='" . optional_param('id', NULL, PARAM_TEXT) . "' />
- <input type='hidden' name='iassign_current' value='' />";
- $course_sections = get_fast_modinfo($PAGE->course->id)->get_section_info_all();
- $section = $course_sections[0];
- $ids_sections = array_keys($section->__get('modinfo')->get_sections());
- for ($k = 0; $k < count($ids_sections); $k++) {
- $radio_buttons .= get_section_name($PAGE->course->id, $ids_sections[$k]). "<ul style='list-style-type: none'>";
- for ($j = 0; $j < count($section->__get('modinfo')->get_sections()[$ids_sections[$k]]); $j++) {
- $c_cm = get_coursemodule_from_id('iassign', $section->__get('modinfo')->get_sections()[$ids_sections[$k]][$j]);
- if ($c_cm) {
- if ($ccm->instance == $c_cm->instance) {
- $radio_buttons .= " <li><input type='radio' disabled='disabled' id='radio_" . $c_cm->instance . "' name='iassign_destiny' value='" . $c_cm->instance . "'>
- <label for='radio_" . $c_cm->instance . "'>" . $c_cm->name . "</label></li>\n";
- }
- else {
- $radio_buttons .= " <li><input type='radio' id='radio_" . $c_cm->instance . "' name='iassign_destiny' value='" . $c_cm->instance . "'>
- <label class='input_move' for='radio_" . $c_cm->instance . "'>" . $c_cm->name . "</label></li>\n";
- }
- }
- }
- $radio_buttons .= "</ul>";
- }
- print $radio_buttons . " <center><input type='submit' value='OK' onClick='return validate_move();' />\n
- <input type='button' value='" . get_string('cancel', 'iassign') . "' onClick='closeModal()' data-bs-dismiss='modal' /></center>
- </form>
- </div></div> </div></div>\n";
- print " <style>.modal {
- display: none;
- position: fixed;
- z-index: 1;
- left: 0;
- top: 0;
- width: 100%;
- height: 100%;
- overflow: scroll;
- background-color: rgb(0,0,0);
- background-color: rgba(0,0,0,0.4);
- }
- .modal-content {
- background-color: #fefefe;
- margin: 15% auto;
- padding: 10px 10px;
- border: 1px solid #888;
- width: 50%;
- }
- #close_modal {
- color: #aaa;
- float: right;
- font-size: 28px;
- font-weight: bold;
- margin-top: -15px;
- margin-right: -3px;
- }
- #close_modal:hover,
- #close_modal:focus {
- color: black;
- text-decoration: none;
- cursor: pointer;
- }
- #modal_title {
- min-height: 3rem;
- color: initial;
- background: initial;
- font-size: 1.5rem;
- line-height: 1.5;
- padding: 15px;
- border-bottom: 1px solid #e5e5e5;
- }
- .input_move {
- width: 90%;
- padding: 2px;
- }
- .input_move:hover {
- background: #eff0ef;
- }
- </style>";
- $action_links = "";
- if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id)) {
- print '<h5 class="fw-bold" style="font-weight: 400; margin: -1rem 0 1.5rem 0;">' . $title . "</h5>\n";
- print '<table class="table table-hover" style="border-bottom: 1px solid #dee2e6;">' . "\n";
- for ($j=0; $j<$total_of_activities; $j++) {
- $iassign_current = $iassign_array[$j]->id;
-
-
- $sum_comment = 0;
- $iassign_submissions = $DB->get_records('iassign_submission', array('iassign_statementid' => $iassign_current));
- foreach ($iassign_submissions as $iassign_submission) {
- $params_temp = array('iassign_submissionid' => $iassign_submission->id, 'return_status' => '0', 'receiver' => '1');
- $verify_message = $DB->get_record_sql("SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
- " WHERE iassign_submissionid = :iassign_submissionid AND return_status= :return_status AND receiver= :receiver", $params_temp);
- if ($verify_message)
- foreach ($verify_message as $tmp)
- $sum_comment += $tmp;
- }
- if ($sum_comment == 0)
- $comment_unread = "";
- else {
- $comment_unread_message = get_string('comment_unread', 'iassign');
- if ($sum_comment == 1)
- $comment_unread_message = get_string('comment_unread_one', 'iassign');
- $comment_unread = ' <a href="' . $CFG->wwwroot . '/mod/iassign/view.php?id=' . $id . '&action=report&iassignid=' . $this->iassign->id . '">' .
- ' <span class="badge bg-danger ml-2" style="color:white; font-size: .9em;"><i class="fa fa-envelope" aria-hidden="true"></i> ' . $comment_unread_message .
- ' <span class="badge rounded-pill bg-light text-dark" style="font-size: .8em;">' . $sum_comment . '</span> </span></a>' . "\n";
- }
- if ($j == $total_of_activities - 1)
- $iassign_down = $iassign_array[$j]->id;
- else
- $iassign_down = $iassign_array[$j + 1]->id;
- if ($j > 0)
- $iassign_up = $iassign_array[$j - 1]->id;
- else
- $iassign_up = $iassign_array[$j]->id;
- if ($iassign_array[$j]->visible == 0)
- $links = " <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>\n";
- else
- $links = " <a href='view.php?id=" . $id . "&userid_iassign=" . $USER->id . "&action=view&iassign_current=" . $iassign_current . "'>" . $iassign_array[$j]->name . "</a>\n";
- $links .= $comment_unread;
- if (has_capability('mod/iassign:editiassign', $this->context, $USER->id) && $USER->iassignEdit == 1) {
- $action_links = "<nav aria-label='Action links'><ul class='pagination pagination-sm mb-0 my-1 text-success'>\n";
- $str_aux = "&id=" . $id . "&iassign_current=" . $iassign_current . "&iassign_up=" . $iassign_up . "&iassign_down=" . $iassign_down;
- $link_up = "<li class='page-item'><a href='view.php?action=up" . $str_aux . "' class='page-link' title='" . get_string('move_up_iassign', 'iassign') . "'><i class='fa fa-arrow-up' aria-hidden='true'></i></a></li>\n";
- if ($j==0)
- $link_down = "<li class='page-item'><a href='view.php?action=firstdown" . $str_aux . "' class='page-link' title='" . get_string('move_down_iassign', 'iassign') . "'><i class='fa fa-arrow-down' aria-hidden='true'></i></a></li>\n";
- else
- $link_down = "<li class='page-item'><a href='view.php?action=down" . $str_aux . "' class='page-link' title='" . get_string('move_up_iassign', 'iassign') . "'><i class='fa fa-arrow-down' aria-hidden='true'></i></a></li>\n";
- $link_delete = "<li class='page-item'><a href='view.php?action=delete" . $str_aux . "' class='page-link' title='" . get_string('delete_iassign', 'iassign') . "'><i class='fa fa-trash-o' aria-hidden='true'></i></a></li>\n";
- $link_visible_hide = "<li class='page-item'><a href='view.php?action=visible" . $str_aux . "' class='page-link' title='" . get_string('hide_iassign', 'iassign') . "'><i class='fa fa-eye' aria-hidden='true'></i></a></li>\n";
- $link_visible_show = "<li class='page-item'><a href='view.php?action=visible" . $str_aux . "' class='page-link' title='" . get_string('show_iassign', 'iassign') . "'><i class='fa fa-eye-slash' aria-hidden='true'></i></a></li>\n";
- $link_edit = "<li class='page-item'><a href='view.php?action=edit" . $str_aux . "' class='page-link' title='" . get_string('edit_iassign', 'iassign') . "'><i class='fa fa-pencil-square-o' aria-hidden='true'></i></a></li>\n";
- $link_duplicate_activity = "<li class='page-item'><a href='view.php?action=duplicate_activity" . $str_aux . "' class='page-link' title='" . get_string('duplicate_iassign', 'iassign') . "'><i class='fa fa-clone' aria-hidden='true'></i></a></li>\n";
- $link_move_activity = "<li class='page-item'><a href='#' onclick='load_move(" . $iassign_current . "); return false;' class='page-link' title='" . get_string('move_activity', 'iassign') . "'><i class='fa fa-sign-out' aria-hidden='true'></i></a></li>\n";
- if (count($iassign_array) > 1) {
- if ($j == 0)
- $action_links .= $link_down;
- elseif ($j == $total_of_activities - 1)
- $action_links .= $link_up;
- else
- $action_links .= $link_up . $link_down;
- }
- $action_links .= $link_edit . $link_delete;
- if ($iassign_array[$j]->visible == 0)
- $action_links .= $link_visible_show;
- else
- $action_links .= $link_visible_hide;
- $action_links .= $link_duplicate_activity . $link_move_activity;
- }
- $action_links .= "</ul></nav>\n";
- print '<tr><td style="white-space: nowrap; width: 1%; padding-right: 2rem;" class="align-middle">' . $links . '</td><td class="align-middle">' . $action_links . "</td></tr>\n";
- }
-
-
- $vector_final_order = array();
- for ($j=0; $j<$total_of_activities; $j++) {
-
- if ($iassign_array[$j]->position!=($j+1)) {
- activity::move_change_activity_position($DB, $iassign_array[$j]->id, $iassign_array[$j]->id, $j+1, $j+1);
- }
- }
- print "</tbody></table>\n";
- }
- elseif (has_capability('mod/iassign:submitiassign', $this->context, $USER->id)) {
- print '<h5 class="fw-bold" style="font-weight: 400; margin: -1rem 0 1.5rem 0;">' . $title . "</h5>\n";
- print '<table class="table table-hover" style="border-bottom: 1px solid #dee2e6;">' . "\n";
- for ($j=0; $j<$total_of_activities; $j++) {
- $icon_status = "";
- $icon_comment = "";
- if ($iassign_array[$j]->visible == 1) {
- $iassign_current = $iassign_array[$j]->id;
- $iassign_submission = $DB->get_record('iassign_submission', array('iassign_statementid' => $iassign_current, 'userid' => $USER->id));
- $links = " <a href='view.php?id=" . $id . "&userid_iassign=" . $USER->id . "&action=view&iassign_current=" . $iassign_current . "'>" . $iassign_array[$j]->name . "</a>\n";
- $icon_status = "";
- $icon_comment = "";
- if ($iassign_submission) {
-
-
-
- $params_temp = array('iassign_submissionid' => $iassign_submission->id, 'return_status' => '0', 'receiver' => '2');
- $verify_message = $DB->get_record_sql(
- "SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
- " WHERE iassign_submissionid = :iassign_submissionid AND return_status= :return_status AND receiver= :receiver", $params_temp);
- if ($verify_message)
- foreach ($verify_message as $tmp)
- $sum_comment = $tmp;
- if ($sum_comment > 0) {
- $comment_unread_message = get_string('comment_unread', 'iassign');
- if ($sum_comment == 1)
- $comment_unread_message = get_string('comment_unread_one', 'iassign');
- $icon_comment = "<a href='view.php?id=" . $id . "&userid_iassign=" . $USER->id . "&action=view&iassign_current=" . $iassign_current . "#comments'>\n" .
- ' <span class="badge bg-danger" style="color:white; font-size: .9em;"><i class="fa fa-envelope" aria-hidden="true"></i> ' . $comment_unread_message . "\n" .
- ' <span class="badge rounded-pill bg-light text-dark" style="font-size: .8em;">' . $sum_comment . "</span> </span></a>\n";
- }
-
- if ($iassign_array[$j]->type_iassign == 3) {
- if ($iassign_array[$j]->show_answer == 1) {
- if ($iassign_submission->status == 3)
- $icon_status = '<i class="fa fa-check" style="color: green; font-size: 1.2rem;" aria-hidden="true" title="' . get_string('correct', 'iassign') . '"></i>' . "\n";
- elseif ($iassign_submission->status == 2)
- $icon_status = '<i class="fa fa-times" style="color: red; font-size: 1.2rem;" aria-hidden="true" title="' . get_string('incorrect', 'iassign') . '"></i>' . "\n";
- elseif ($iassign_submission->status == 1)
- $icon_status = '<i class="fa fa-question" style="color: #77229; font-size: 1.2rem;" aria-hidden="true" title="' . get_string('post', 'iassign') . '"></i>' . "\n";
-
- elseif ($iassign_submission->status == 0)
- $icon_status = '<i class="fa fa-question" style="color: red; font-size: 1.2rem;" aria-hidden="true" title="' . get_string('not_post', 'iassign') . '"></i>' . "\n";
- }
- else {
- if ($iassign_submission->status == 0) {
-
- $icon_status = iassign_icons::insert('not_post');
- }
- else {
-
- $icon_status = iassign_icons::insert('post');
- }
- }
- }
- }
- elseif ($iassign_array[$j]->type_iassign == 3) {
- $icon_status = '<i class="fa fa-question" style="color: #77229c; font-size: 1.2rem;" aria-hidden="true" title="' . get_string('not_post', 'iassign') . '"></i>' . "\n";
-
- }
- print '<tr><td style="white-space: nowrap; width: 1%; padding-right: 0; text-align: center;">' . $icon_status . '</td><td style="white-space: nowrap; width: 1%; padding-right: 2rem; padding-left: 0.2rem;">'
- . $links . '</td><td>' . $icon_comment . '</td></tr>' . "\n";
-
- }
- }
- print "</table>\n";
- }
- else if (isguestuser()) {
- print($OUTPUT->notification(get_string('no_permission_iassign', 'iassign'), 'notifyproblem'));
- print '<table width=100% ><tr>' . "\n";
- print "<td width=70% align='left'><font color='#0000aa'><strong>" . $title . "</strong></font></td>" . "\n";
- print '</tr></table>' . "\n";
- for ($j=0; $j<$total_of_activities; $j++) {
- $icon_status = "";
- $icon_comment = "";
- if ($iassign_array[$j]->visible == 1) {
- $iassign_current = $iassign_array[$j]->id;
- $links = " <a href='view.php?id=" . $id . "&userid_iassign=" . $USER->id . "&action=view&iassign_current=" . $iassign_current . "'>" . $iassign_array[$j]->name . "</a>\n";
- print '<p>' . $links . '</p>' . "\n";
- }
- }
- }
- print $OUTPUT->box_end();
- }
-
- function return_home_course ($message) {
-
-
-
-
-
-
-
-
-
-
-
-
- redirect(new moodle_url($this->return . '¬ice=' . $message));
- exit;
- }
-
- function search_comment_submission ($iassign_submissionid) {
- global $USER, $DB, $OUTPUT, $COURSE;
-
- $colorEdit1 = "#b7ceee";
- $colorEdit2 = "#d2e5fc";
- $has_capability = 0;
- $comments = $DB->get_records_list('iassign_submission_comment', 'iassign_submissionid', array('iassign_submissionid' => $iassign_submissionid), 'timecreated DESC');
- $text = "";
- if ($comments) {
- $even = 1;
- foreach ($comments as $tmp) {
- $user_data = $DB->get_record("user", array('id' => $tmp->comment_authorid));
-
-
-
-
-
- $avatar = new user_picture($user_data);
- $avatar->courseid = $COURSE->id;
- $avatar->link = true;
- $user_picture = $OUTPUT->render($avatar);
- $user_picture = str_replace('"35"', '"45"', $user_picture);
- if ($even) {
- $text .= "<tr><td style='vertical-align: middle; width: 55px !important;' bgcolor='" . $colorEdit1 . "'>$user_picture</td><td bgcolor='" . $colorEdit1 . "' style='padding-left: 0px !important;'><b style='font-size: 1.1rem;'>" . $user_data->firstname . "</b> <span style='color: #686969; font-size: 90%'><i class='fa fa-clock-o' aria-hidden='true' style='margin-left: 2rem; margin-right: .1rem;'></i> " . userdate($tmp->timecreated) . "</span></br>\n";
- $even = 0;
- } else {
- $text .= "<tr><td style='vertical-align: middle; width: 55px !important;' bgcolor='" . $colorEdit2 . "'>$user_picture</td><td bgcolor='" . $colorEdit2 . "' style='padding-left: 0px !important;'><b style='font-size: 1.1rem;'>" . $user_data->firstname . "</b> <span style='color: #686969; font-size: 90%'><i class='fa fa-clock-o' aria-hidden='true' style='margin-left: 2rem; margin-right: .1rem;'></i> " . userdate($tmp->timecreated) . "</span></br>\n";
- $even = 1;
- }
- $text .= "<div style='padding-left: 0rem; padding-top: .2rem;'>" . $tmp->comment . "</div></td></tr>\n";
- }
- }
- return $text;
- }
-
- function update_comment ($iassign_submissionid) {
- global $USER, $DB, $OUTPUT;
- if (!has_capability('mod/iassign:submitiassign', $this->context, $USER->id) || is_siteadmin())
- $receiver = 1;
- else
- $receiver = 2;
- $verify_message = $DB->get_records('iassign_submission_comment', array('iassign_submissionid' => $iassign_submissionid));
- if ($verify_message) {
- foreach ($verify_message as $message) {
- if ($message->receiver == $receiver) {
- $newentry = new stdClass();
- $newentry->id = $message->id;
- $newentry->return_status = 1;
- if (!$DB->update_record('iassign_submission_comment', $newentry)) {
- print_error('error_update', 'iassign');
- }
- }
-
- $event = \mod_iassign\event\submission_comment_updated::create(array(
- 'objectid' => $this->iassign->id,
- 'context' => $this->context
- ));
- $event->add_record_snapshot('course', $this->course);
- $event->trigger();
- }
- }
- }
-
- function write_comment_submission () {
- global $USER, $CFG, $DB;
- $id = $this->cm->id;
- $submission_comment = optional_param('submission_comment', NULL, PARAM_TEXT);
- $row = optional_param('row', 0, PARAM_INT);
- $column = optional_param('column', 0, PARAM_INT);
- $sum_comment = 0;
- $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);
- $link_return = " <a href='" . $return . "'>" . iassign_icons::insert('return_home') . get_string('return', 'iassign') . "</a>";
- $str1 = trim($submission_comment);
- $str2 = trim(get_string('box_comment_message', 'iassign'));
- if (!empty($submission_comment) && (strcmp($str1, $str2) != 0)) {
-
- if (has_capability('mod/iassign:submitiassign', $this->context, $USER->id) && !is_siteadmin()) {
- $receiver = 1;
- $this->action = 'view';
-
-
- } else {
- $receiver = 2;
- $this->action = 'viewsubmission';
-
-
- }
-
- $iassign_submission = $DB->get_record("iassign_submission", array("id" => $this->iassign_submission_current));
-
- if (!$iassign_submission) {
- $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $this->activity->get_activity()->id, "userid" => $USER->id));
- }
- if (!$iassign_submission) {
- $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $this->activity->get_activity()->id));
- $id_submission = $this->new_submission($iassign_statement_activity_item->id, $this->userid_iassign, $receiver);
- $this->iassign_submission_current = $id_submission;
- }
- else {
- $id_submission = $iassign_submission->id;
- }
-
-
-
- $params_temp = array("iassign_submissionid" => $id_submission, "comment" => $submission_comment, "comment_authorid" => $USER->id);
- $comments = $DB->get_record_sql(
- "SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
- " WHERE iassign_submissionid = :iassign_submissionid AND comment= :comment AND comment_authorid= :comment_authorid", $params_temp);
- if ($comments)
- foreach ($comments as $tmp)
- $sum_comment = $tmp;
- if ($sum_comment == 0) {
- $newentry = new stdClass();
- $newentry->iassign_submissionid = $id_submission;
- $newentry->comment_authorid = $USER->id;
- $newentry->timecreated = time();
- $newentry->comment = $submission_comment;
- $newentry->receiver = $receiver;
- $ia_assign_submissions_comment_id = $DB->insert_record('iassign_submission_comment', $newentry);
-
-
- $event = \mod_iassign\event\submission_comment_created::create(array(
- 'objectid' => $this->iassign->id,
- 'context' => $this->context
- ));
- $event->add_record_snapshot('course', $this->course);
- $event->trigger();
- }
- }
-
-
-
-
-
- return true;
- }
-
-
- function new_submission ($iassignid, $id_user, $receiver) {
- global $USER, $DB, $OUTPUT;
- $newentry = new stdClass();
- $newentry->iassign_statementid = $iassignid;
- $newentry->userid = $id_user;
- $newentry->timecreated = time();
- $newentry->timemodified = time();
- $newentry->answer = 0;
- if ($receiver == 2)
- $newentry->teacher = $USER->id;
- if (!$newentry->id = $DB->insert_record("iassign_submission", $newentry))
- return_home_course('error_insert_submissions');
- else {
-
- $event = \mod_iassign\event\submission_created::create(array(
- 'objectid' => $this->iassign->id,
- 'context' => $this->context
- ));
- $event->add_record_snapshot('course', $this->course);
- $event->trigger();
- }
- return $newentry->id;
- }
-
- function return_last ($message, $link_return) {
- global $DB, $OUTPUT;
- print $OUTPUT->box_start();
- print '<table width=100% border=0 valign="top">' . "\n";
- print '<tr><td align="left"><strong>' . "\n";
- print_string($message, 'iassign');
- print '</strong></td>' . "\n";
- print '<td width=20% align="right">' . "\n";
- print $link_return;
- print '</td></tr></table>' . "\n";
- print $OUTPUT->box_end();
- print $OUTPUT->footer();
- die();
- }
- }
- class activity {
- var $activity;
-
-
-
-
- function __construct ($id) {
- global $DB;
- $this->activity = $DB->get_record("iassign_statement", array("id" => $id));
- if (empty($this->activity))
- $this->activity = null;
- }
-
-
- function get_activity () {
- if ($this->activity != null)
- return $this->activity;
- else
- return null;
- }
-
- function delete ($return) {
- global $USER, $CFG, $DB, $OUTPUT;
- $iassign_submission_currents = $DB->get_records("iassign_submission", array("iassign_statementid" => $this->activity->id));
- print $OUTPUT->header();
- $output .= $OUTPUT->box_start();
- $output .= "<p>" . get_string('delete_activity', 'iassign') . " <strong>" . $this->activity->name . "</strong></p>";
- if ($iassign_submission_currents) {
- $output .= "<p>" . get_string('number_submissions', 'iassign') . " <strong>" . count($iassign_submission_currents) . "</strong></p>";
- if (!has_capability('mod/iassign:deleteiassignnotnull', $USER->context, $USER->id)) {
- $output .= $OUTPUT->heading(get_string('delete_activity_permission_adm', 'iassign'));
- $output .= $OUTPUT->single_button($return, get_string('return', 'iassign'), 'get');
- $output .= $OUTPUT->box_end();
- $output .= $OUTPUT->footer();
- print $output;
- die();
- }
- }
- else
- $output .= "<p>" . get_string('not_submissions_activity', 'iassign') . "</p>\n";
- $output .= '<table width=50% border=0>';
- $output .= '<tr valign="top"><td>';
- $output .= "<p>" . get_string('what_do', 'iassign') . "</p>\n";
- $output .= '</td><td>';
- $bottonDelete_yes = get_string('delete_iassign', 'iassign');
- $deleteiassignyes = $CFG->wwwroot . "/mod/iassign/view.php?id=" . $USER->cm . "&action=deleteyes&iassign_current=" . $this->activity->id;
- $output .= "<form name='formDelete' id='formDelete' method='post' action='$deleteiassignyes' enctype='multipart/form-data'>\n";
- $output .= " <input type=submit value='$bottonDelete_yes'/>\n";
- $output .= "</form>\n";
- $output .= '</td><td>';
- $bottonDelete_no = get_string('delete_cancel', 'iassign');
- $deleteiassignno = $CFG->wwwroot . "/mod/iassign/view.php?id=" . $USER->cm . "&action=deleteno&iassign_current=" . $this->activity->id;
- $output .= "<form name='formDelete' id='formDelete' method='post' action='$deleteiassignno' enctype='multipart/form-data'>\n";
- $output .= " <p><input type=submit value='$bottonDelete_no'/></p>\n";
- $output .= "</form>\n";
- $output .= '</td></tr></table>' . "\n";
- $output .= $OUTPUT->box_end();
- $output .= $OUTPUT->footer();
- print $output;
- }
-
-
-
- function deleteyes ($return, $iassign) {
- global $USER, $CFG, $DB, $OUTPUT, $COURSE;
- $msg = '';
- if (!empty($this->activity->id)) {
- $iassign_submission_currents = $DB->get_records("iassign_submission", array("iassign_statementid" => $this->activity->id));
- if ($iassign_submission_currents) {
- if (has_capability('mod/iassign:deleteassignnull', $USER->context, $USER->id)) {
- foreach ($iassign_submission_currents as $iassign_submission)
- $DB->delete_records('iassign_submission_comment', array('iassign_submissionid' => $iassign_submission->id));
- $delete_iassign_submission_currents = $DB->delete_records("iassign_submission ", array("iassign_statementid" => $this->activity->id));
- }
- }
-
-
- $fs = get_file_storage();
-
- $fs->delete_area_files($iassign->context->id, 'mod_iassign', 'exercise', $this->activity->id);
- $this->delete_calendar($this->activity->id);
- $delete_iassign_current = $DB->delete_records('iassign_statement', array('id' => $this->activity->id));
- iassign::update_grade_iassign($this->activity->iassignid);
- if ($delete_iassign_current) {
- $iassign->return_home_course('confirm_delete_iassign');
-
- }
- else {
- $iassign->return_home_course('error_confirm_delete_iassign');
-
- }
-
- }
- }
-
-
-
- static function move_change_activity_position ($DB, $idFrom, $idTo, $posFrom, $posTo) {
- $newentry = new stdClass();
- $newentry->id = $idFrom;
- $newentry->position = $posFrom;
- if (!$DB->update_record('iassign_statement', $newentry)) {
- print_error('error_update_move_iassign', 'iassign');
- }
-
- if ($idFrom != $idTo) {
- $newentry->id = $idTo;
- $newentry->position = $posTo;
- if (!$DB->update_record('iassign_statement', $newentry))
- print_error('error_update_move_iassign', 'iassign');
- }
- }
-
-
-
- function move_iassign ($move_action, $target, $return) {
- global $DB, $OUTPUT;
- $initial_position_source = $this->activity->position;
- $iassign_target = $DB->get_record("iassign_statement", array("id" => $target));
- if ($move_action=="firstdown") {
- $final_position_source = 2;
- $final_position_target = 1;
- }
- else
- if ($move_action=="down") {
- $final_position_target = $this->activity->position;
- $final_position_source = $final_position_target + 1;
- }
- else
- if ($move_action=="up") {
- $final_position_target = $this->activity->position;
- $final_position_source = $final_position_target - 1;
- }
- else {
- print_error('error_update_move_iassign', 'iassign');
- exit;
- }
- activity::move_change_activity_position($DB, $this->activity->id, $iassign_target->id, $final_position_source, $final_position_target);
- redirect($return);
- }
-
- function visible_iassign ($return) {
- global $DB;
- $newentry = new stdClass();
- $newentry->id = $this->activity->id;
- $newentry->visible = $this->activity->visible == 0 ? 1 : 0;
- if (!$DB->update_record('iassign_statement', $newentry))
- print_error('error_update_visible_iassign', 'iassign');
- redirect($return);
- }
-
-
-
- function new_iassign ($param) {
- global $DB;
- $newentry = new stdClass();
- $newentry->iassignid = $param->iassignid;
- $newentry->name = $param->name;
- $newentry->type_iassign = $param->type_iassign;
- $newentry->store_all_submissions = $param->store_all_submissions;
-
- $proposition = $param->proposition;
- if (is_array($proposition)) $proposition_text = $proposition['text'];
- else $proposition_text = $proposition;
- $newentry->proposition = $proposition_text;
-
-
-
- if (!isset($param->iassign_ilmid) && isset($_POST['iassign_ilmid']))
- $param->iassign_ilmid = $_POST['iassign_ilmid'];
- $newentry->author_name = $param->author_name;
- $newentry->author_modified_name = $param->author_modified_name;
- $newentry->iassign_ilmid = $param->iassign_ilmid;
- $newentry->filesid = $param->file;
-
- $newentry->grade = $param->grade;
- $newentry->timemodified = time();
- $newentry->timecreated = time();
- if ($param->type_iassign == 1) {
- $newentry->timedue = 0;
- $newentry->timeavailable = 0;
- }
- else {
- $newentry->timedue = $param->timedue;
- $newentry->timeavailable = $param->timeavailable;
- }
- $newentry->preventlate = $param->preventlate;
- $newentry->test = $param->test;
- $newentry->special_param1 = $param->special_param1;
- $newentry->visible = $param->visible;
- $newentry->position = $param->position;
- $newentry->max_experiment = $param->max_experiment;
- $newentry->dependency = $param->dependency;
- $newentry->automatic_evaluate = $param->automatic_evaluate;
- $newentry->show_answer = $param->show_answer;
- $id = $DB->insert_record("iassign_statement", $newentry);
- if ($id) {
- $component = 'mod_iassign';
- $filearea = 'exercise';
- $fs = get_file_storage();
- $file = $fs->get_file_by_id($param->file);
- $itemid = $file->get_itemid() + $id;
-
-
-
-
- $newfile = $fs->create_file_from_storedfile(array('contextid' => $param->context->id, 'component' => $component, 'filearea' => $filearea, 'itemid' => $itemid), $file);
- $updateentry = new stdClass();
- $updateentry->id = $id;
-
- $updateentry->filesid = $newfile->get_itemid();
- if (!$DB->update_record("iassign_statement", $updateentry))
- print_error('error_add', 'iassign');
- if ($param->type_iassign == 3)
- iassign::update_grade_iassign($param->iassignid);
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- iassign_log::add_log('add_iassign_exercise', 'name: ' . $param->name, $id, $param->iassign_ilmid);
-
- return $id;
- }
- else
- print_error('error_add', 'iassign');
- }
-
-
-
- static function add_calendar ($iassignid) {
- global $DB, $CFG;
- require_once($CFG->dirroot . '/calendar/lib.php');
- $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $iassignid));
- $iassign = $DB->get_record("iassign", array("id" => $iassign_statement_activity_item->iassignid));
- $event = new stdClass();
- $event->name = $iassign->name . ' - ' . $iassign_statement_activity_item->name;
- $event->description = $iassign_statement_activity_item->name;
- $event->courseid = $iassign->course;
- $event->groupid = 0;
- $event->userid = 0;
- $event->modulename = 'iassign';
- $event->instance = $iassign->id;
- $event->eventtype = 'due';
- $event->timestart = $iassign_statement_activity_item->timeavailable;
- $event->timeduration = ($iassign_statement_activity_item->timedue - $iassign_statement_activity_item->timeavailable);
- calendar_event::create($event);
- }
-
-
-
- function update_calendar ($iassignid, $olddescription) {
- global $DB, $CFG;
- require_once($CFG->dirroot . '/calendar/lib.php');
- $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $iassignid));
- $iassign = $DB->get_record("iassign", array("id" => $iassign_statement_activity_item->iassignid));
- $event = new stdClass();
- $event->id = 0;
- $events = $DB->get_records('event', array('modulename' => 'iassign', 'instance' => $iassign->id));
- if ($events) {
- foreach ($events as $value) {
- if ($value->description == $olddescription) {
- $event->id = $value->id;
- }
- }
- }
- if ($event->id != 0) {
- $event->name = $iassign->name . ' - ' . $iassign_statement_activity_item->name;
- $event->description = $iassign_statement_activity_item->name;
- $event->timestart = $iassign_statement_activity_item->timeavailable;
- $event->timeduration = ($iassign_statement_activity_item->timedue - $iassign_statement_activity_item->timeavailable);
- $calendarevent = calendar_event::load($event->id);
- $calendarevent->update($event);
- } else
- $this->add_calendar($iassignid);
- }
-
-
-
- function delete_calendar ($iassignid) {
- global $DB, $CFG;
- require_once($CFG->dirroot . '/calendar/lib.php');
- $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $iassignid));
- $iassign = $DB->get_record("iassign", array("id" => $iassign_statement_activity_item->iassignid));
- $events = $DB->get_records('event', array('modulename' => 'iassign', 'instance' => $iassign->id));
- if ($events) {
- foreach ($events as $value) {
- if ($value->description == $iassign_statement_activity_item->name) {
- $DB->delete_records('event', array('id' => $value->id));
- }
- }
- }
- }
-
- function update_iassign ($param) {
- global $DB;
- $component = 'mod_iassign';
- $filearea = 'exercise';
- $fs = get_file_storage();
- $file = $fs->get_file_by_id($param->file);
- $fileold = $fs->get_file_by_id($param->fileold);
- if ($param->file != $param->fileold) {
- if ($fileold) {
- $fileoldarea = $fs->get_area_files($fileold->get_contextid(), $fileold->get_component(), $fileold->get_filearea(), $fileold->get_itemid());
- foreach ($fileoldarea as $value) {
- $value->delete();
- }
- }
- if (!$fs->file_exists($param->context->id, $component, $filearea, $file->get_itemid(), $file->get_filepath(), $file->get_filename())) {
- $itemid = $file->get_itemid() + $param->iassign_id;
- $newfile = $fs->create_file_from_storedfile(array('contextid' => $param->context->id, 'component' => $component, 'filearea' => $filearea, 'itemid' => $itemid), $file);
- $param->file = $newfile->get_itemid();
- }
- else
- $param->file = $file->get_itemid();
- }
- else {
- $param->file = $file->get_itemid();
- }
- $newentry = new stdClass();
- $newentry->id = $param->iassign_id;
- $newentry->name = $param->name;
- $newentry->type_iassign = $param->type_iassign;
- $newentry->store_all_submissions = $param->store_all_submissions;
-
- $proposition = $param->proposition;
- if (is_array($proposition))
- $proposition_text = $proposition['text'];
- else
- $proposition_text = $proposition;
- $newentry->proposition = $proposition_text;
- $newentry->iassign_ilmid = $param->iassign_ilmid;
- $newentry->filesid = $param->file;
- $newentry->grade = $param->grade;
- $newentry->author_modified_name = $param->author_modified_name;
- $newentry->timemodified = time();
- if ($param->type_iassign == 1) {
- $newentry->timedue = 0;
- $newentry->timeavailable = 0;
- }
- else {
- $newentry->timedue = $param->timedue;
- $newentry->timeavailable = $param->timeavailable;
- }
- $newentry->preventlate = $param->preventlate;
- $newentry->test = $param->test;
- if (isset($param->special_param1))
- $newentry->special_param1 = $param->special_param1;
- else
- $newentry->special_param1 = NULL;
- $newentry->visible = $param->visible;
- $newentry->max_experiment = $param->max_experiment;
- $newentry->dependency = $param->dependency;
- $newentry->automatic_evaluate = $param->automatic_evaluate;
- $newentry->show_answer = $param->show_answer;
- if (!$DB->update_record("iassign_statement", $newentry))
- print_error('error_update', 'iassign');
- if ($param->type_iassign == 3) {
- iassign::update_grade_iassign($param->iassignid);
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- iassign_log::add_log('update_iassign_exercise', 'name: ' . $param->name, $param->iassign_id, $param->iassign_ilmid);
-
- return $newentry->id;
-
-
- }
-
- function show_info_iassign () {
- global $DB, $OUTPUT;
- $output = '';
- if ($this->activity->type_iassign == 3) {
- if ($this->activity->dependency == 0) {
- $output .= '<p style="margin-top: -1rem;"><strong>' . get_string('independent_activity', 'iassign') . '</strong>' . "\n";
- } else {
- $dependencys = explode(';', $this->activity->dependency);
- $output .= '<p style="margin-top: -1rem;"><strong>' . get_string('dependency', 'iassign') . '</strong>';
- foreach ($dependencys as $dependency) {
- $dependencyiassign = $DB->get_record("iassign_statement", array("id" => $dependency));
- if ($dependencyiassign)
- $output .= '<p>' . $dependencyiassign->name . '</p>' . "\n";
- }
- }
- if ($this->activity->max_experiment == 0)
- $output .= '<strong style="margin-left: 3rem;">' . get_string('experiment', 'iassign') . '</strong> ' . get_string('ilimit', 'iassign');
- else
- $output .= '<strong style="margin-left: 3rem;">' . get_string('experiment_iassign', 'iassign') . '</strong> ' . $this->activity->max_experiment . "\n";
- $output .= '<strong style="margin-left: 3rem;">' . get_string('grade_iassign', 'iassign') . ':</strong> ' . $this->activity->grade . '</p>' . "\n";
- }
- $output .= $this->toggle_columns_script();
- $output .= '<p><strong>' . get_string('proposition', 'iassign') . ':</strong></p> <div class="proposition">' . $this->activity->proposition . '</div>' . "\n";
- print $OUTPUT->box($output);
- }
-
- static function toggle_columns_script () {
- $output = "";
- $output .= '<script>
- function toLeft () {
- document.getElementsByClassName("proposition")[0].style.cssFloat = "left";
- document.getElementsByClassName("proposition")[0].style.width = "40%";
- document.getElementById("fullscreen").style.marginTop = "-3rem";
- document.getElementById("columnsbutton").style.color = "#1da075";
- }
- function toDefault () {
- document.getElementsByClassName("proposition")[0].style.cssFloat = "none";
- document.getElementsByClassName("proposition")[0].style.width = "100%";
- document.getElementById("fullscreen").style.marginTop = "0";
- document.getElementById("columnsbutton").style.color = "#343a40";
- }
- var activate = false;
- function toggleColumns () {
- if (activate) {
- activate = false;
- toDefault();
- } else {
- activate = true;
- toLeft();
- }
- }
- </script>';
- $output .= '<span tabindex="0" data-toggle="tooltip" title="' . get_string('enable_disable_columns', 'iassign')
- . '" style="float: right"> <i id="columnsbutton" onclick="toggleColumns()" class="fa fa-columns" style="font-size: 1.5rem;" aria-hidden="true" role="button"></i></span>' . "\n";
- return $output;
- }
- static function get_latest_array_item ($DB, $iassignid, $position) {
- $iassign_statement = $DB->get_records('iassign_statement', array('iassignid' => $iassignid, 'position' => $position));
- $item = NULL;
- foreach ($iassign_statement as $item) ;
- if ($item) return $item;
- return NULL;
- }
-
- function view_dates () {
- global $USER, $CFG, $DB, $OUTPUT;
- $return = $CFG->wwwroot . "/mod/iassign/view.php?id=" . $USER->cm;
- $link_return = " <a href='" . $return . "'>" . iassign_icons::insert('home') . get_string('activities_page', 'iassign') . "</a>";
- $status_iassign = "";
- $status_iassign1 = "";
- $status_iassign2 = "";
- if ($this->activity->type_iassign == 1)
- $type_iassign = get_string('example_iassign', 'iassign');
- elseif ($this->activity->type_iassign == 2) {
- $type_iassign = get_string('test_iassign', 'iassign');
- if ($this->activity->timeavailable > time()) {
- $status_iassign = get_string('previous_timeavailable', 'iassign');
- } elseif ($this->activity->timedue < time()) {
- $status_iassign = get_string('last_timedue', 'iassign');
- }
- } elseif ($this->activity->type_iassign == 3) {
- $type_iassign = get_string('exercise_iassign', 'iassign');
- if ($this->activity->timeavailable > time()) {
- $status_iassign = get_string('previous_timeavailable', 'iassign');
- } elseif ($this->activity->timedue < time()) {
- $status_iassign = get_string('last_timedue', 'iassign');
- if ($this->activity->preventlate == 1)
- $status_iassign1 = get_string('duedate_preventlate_enable', 'iassign');
- elseif ($this->activity->preventlate == 0) {
- $status_iassign1 = get_string('duedate_preventlate_desable', 'iassign');
- if ($this->activity->test == 1)
- $status_iassign2 = get_string('test_preventlate', 'iassign');
- elseif ($this->activity->test == 0) {
- $status_iassign2 = get_string('test_preventlate_no', 'iassign');
- }
- }
- }
- }
- $output = '<table width=100% >' . "\n";
- $output .= '<tr><td colspan=2><h4>' . $this->activity->name . '</h4></td></tr>' . "\n";
- $output .= '<tr>' . "\n";
-
- $output .= '<td width=60%>' . $type_iassign . '</td>' . "\n";
-
-
-
- if (has_capability('mod/iassign:viewiassignall', $USER->context, $USER->id) && ($this->activity->type_iassign == 3)) {
-
- $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') . ' ' . get_string('report', 'iassign') . "</a>";
- $output .= '<td width=40% align="right">' . ' ' . $link_report . '</td>' . "\n";
- }
- else {
-
-
- $iassign_previous = activity::get_latest_array_item($DB, $this->activity->iassignid, $this->activity->position-1);
-
- $iassign_next = activity::get_latest_array_item($DB, $this->activity->iassignid, $this->activity->position+1);
- $link_next = "";
- $link_previous = "";
- if ($iassign_previous) {
- $url_previous = "view.php?id=" . $USER->cm . "&userid_iassign=" . $USER->id . "&action=view&iassign_current=" . $iassign_previous->id;
- $link_previous = "<a href='" . $url_previous . "'>" . (iassign_icons::insert('previous_student_activity')) . "</a>\n";
- }
- if ($iassign_next) {
- $url_next = "view.php?id=" . $USER->cm . "&userid_iassign=" . $USER->id . "&action=view&iassign_current=" . $iassign_next->id;
- $link_next = "<a href='" . $url_next . "'>" . (iassign_icons::insert('next_student_activity')) . "</a>\n";
- }
- $output .= '<td width=40% align="right">' . $link_previous . ' ' . $link_return . ' ' . $link_next . '</td>' . "\n";
- }
- $output .= '</tr></table>' . "\n";
- $output .= '<table width=100% >' . "\n";
- if ($this->activity->type_iassign > 1) {
- if ($this->activity->timeavailable)
- $output .= '<tr><td width=50% align="left"> <strong>' . get_string('availabledate', 'iassign') . ':</strong> ' . userdate($this->activity->timeavailable) . '</td>' . "\n";
- if ($this->activity->timedue)
- $output .= '<td width=50% align="left"><strong>' . get_string('duedate', 'iassign') . ':</strong> ' . userdate($this->activity->timedue) . '</td>' . "\n";
- }
- if ($status_iassign != "" && $status_iassign1 != "" && $status_iassign2 != "")
- $output .= '<tr><td><font color="red">' . $status_iassign . ' ' . $status_iassign1 . ' ' . $status_iassign2 . '</font></td></tr>' . "\n";
- $output .= '</table>' . "\n";
- print $OUTPUT->box($output);
- }
- }
- class ilm {
- var $ilm;
-
-
-
-
- function __construct ($id) {
- global $DB;
- $this->ilm = $DB->get_record("iassign_ilm", array("id" => $id));
- if (empty($this->ilm))
- $this->ilm = null;
- }
-
-
- function view_iLM ($iassign_statement_activity_item, $student_answer, $enderecoPOST, $view_teacherfileversion) {
- global $USER, $CFG, $DB;
- $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $iassign_statement_activity_item->iassign_ilmid));
-
- $typec = strtolower($iassign_ilm->type);
- require_once 'ilm_handlers/' . $typec . '.php';
-
- $retorno = $typec::show_activity_in_ilm($iassign_statement_activity_item, $student_answer, $enderecoPOST, $view_teacherfileversion);
- return $retorno;
- }
-
-
-
-
-
- function write_iLM_security ($iassign_activity_itemid, $content_or_id_from_ilm_security) {
- global $CFG, $USER, $COURSE, $DB, $OUTPUT;
- $newentry = new stdClass();
- $newentry->iassign_statementid = $iassign_activity_itemid;
- $newentry->userid = $USER->id;
- $newentry->filesid = $content_or_id_from_ilm_security;
- $newentry->timecreated = time();
- $newentry->view = 1;
- $id_iLM_security = $DB->insert_record("iassign_security", $newentry);
- if (!$id_iLM_security) {
- print_error('error_security', 'iassign');
- }
- return $id_iLM_security;
- }
-
-
-
-
- function remove_old_iLM_security_entries ($userid, $iassign_activity_itemid) {
- global $DB;
-
- $result = $DB->delete_records_select("iassign_security", "userid=" . $userid . " AND iassign_statementid<>" . $iassign_activity_itemid, null);
- }
- }
- class ilm_settings {
-
-
-
-
-
- static function build_ilm_tags ($ilm_id, $options = array()) {
- global $DB;
- $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
-
- $typec = strtolower($iassign_ilm->type);
- require_once 'ilm_handlers/' . $typec . '.php';
- $retorno = $typec::build_ilm_tags($ilm_id, $options);
- return $retorno;
- }
-
-
-
- static function applet_filetime ($file_jar) {
- $filetime = "";
- $fs = get_file_storage();
- $files_jar = explode(",", $file_jar);
- foreach ($files_jar as $one_file) {
- $file = $fs->get_file_by_id($one_file);
- if ($file)
- $filetime .= "\n" . $file->get_filename() . ' (' . userdate($file->get_timemodified()) . ')' . '</br>';
- }
- return $filetime;
- }
-
-
-
- static function applet_default ($file_jar) {
- $is_default = true;
- $fs = get_file_storage();
- $files_jar = explode(",", $file_jar);
- foreach ($files_jar as $one_file) {
- $file = $fs->get_file_by_id($one_file);
- if ($file)
- $is_default &= ($file->get_itemid() == 0);
- }
- return $is_default;
- }
-
-
-
-
-
-
-
- static function add_edit_copy_ilm ($ilm_id, $action) {
- global $USER, $DB, $CFG;
- require_once('settings_form.php');
- $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
- $param = new stdClass();
-
- $param->action = $action;
- $param->ilm_id = $ilm_id;
- $CFG->action_ilm = $action;
- $CFG->ilm_id = $ilm_id;
- if ($action == 'add') {
- $param->title = get_string('add_ilm', 'iassign');
- $param->name = "";
- $param->version = "";
- $param->url = "";
- $param->description = "";
- $param->extension = "";
- $param->author = $USER->id;
- $param->file_jar = "";
- $param->file_jar_static = "";
- $param->file_class = "";
- $param->width = 800;
- $param->height = 600;
- $param->enable = 0;
- $param->timecreated = time();
- $param->timemodified = time();
- $param->evaluate = 0;
- $param->parent = 0;
- }
- elseif ($action == 'edit') {
- if ($iassign_ilm) {
- $description = json_decode($iassign_ilm->description);
- $param->title = get_string('edit_ilm', 'iassign');
- $param->id = $iassign_ilm->id;
- $param->name_ilm = $iassign_ilm->name;
- $param->name = $iassign_ilm->name;
- $param->version = $iassign_ilm->version;
- $param->ilm_type = $iassign_ilm->type;
- $param->type = $iassign_ilm->type;
- $param->url = $iassign_ilm->url;
-
- $param->submissionbehavior = $iassign_ilm->submissionbehavior;
- $param->editingbehavior = $iassign_ilm->editingbehavior;
-
- if (!isset($description->{current_language()})) {
- if (isset($description->{"en_us"})) $param->description = $description->{"en_us"};
- else
- if (isset($description->{"pt_br"})) $param->description = $description->{"pt_br"};
- else $param->description = "";
- }
- else
- $param->description = $description->{current_language()};
- $param->description_lang = $iassign_ilm->description;
- $param->extension = $iassign_ilm->extension;
- $param->author = $iassign_ilm->author;
- $param->file_jar = $iassign_ilm->file_jar;
- $param->file_jar_static = ilm_settings::applet_filetime($iassign_ilm->file_jar);
- $param->file_class = $iassign_ilm->file_class;
- $param->width = $iassign_ilm->width;
- $param->height = $iassign_ilm->height;
- $param->enable = $iassign_ilm->enable;
- $param->timecreated = $iassign_ilm->timecreated;
- $param->timemodified = time();
- $param->evaluate = $iassign_ilm->evaluate;
- $param->parent = $iassign_ilm->parent;
- }
- }
- elseif ($action == 'new_version') {
-
-
- if (!$iassign_ilm) {
- print get_string('empty_file', 'iassign') . "?<br/>\n";
-
- return;
- }
- $description = json_decode($iassign_ilm->description);
- if ($iassign_ilm) {
- if ($iassign_ilm->parent == 0)
- $iassign_ilm->parent = $ilm_id;
- $param->ilm_id = $ilm_id;
- $param->title = get_string('new_version_ilm', 'iassign');
- $param->name_ilm = $iassign_ilm->name;
- $param->name = $iassign_ilm->name;
- $param->version = "";
- $param->version_last = $iassign_ilm->version;
- $param->version = $iassign_ilm->version;
- $param->ilm_type = $iassign_ilm->type;
- $param->url = $iassign_ilm->url;
- $param->description = $description->{current_language()};
- $param->description_lang = $iassign_ilm->description;
-
- $param->extension = $iassign_ilm->extension;
- $param->author = $USER->id;
-
- $param->file_jar = $iassign_ilm->file_jar;
- $param->file_jar_static = '';
- $param->file_class = $iassign_ilm->file_class;
- $param->width = $iassign_ilm->width;
- $param->height = $iassign_ilm->height;
- $param->enable = 0;
- $param->timecreated = time();
- $param->timemodified = time();
- $param->evaluate = $iassign_ilm->evaluate;
- $param->parent = $iassign_ilm->parent;
- }
- }
- elseif ($action == 'copy') {
- $description = json_decode($iassign_ilm->description);
- if ($iassign_ilm) {
- if ($iassign_ilm->parent == 0)
- $iassign_ilm->parent = $ilm_id;
- $param->title = get_string('copy_ilm', 'iassign');
- $param->id = $iassign_ilm->id;
- $param->name_ilm = $iassign_ilm->name;
- $param->name = $iassign_ilm->name;
- $param->version = "";
- $param->ilm_type = $iassign_ilm->type;
- $param->type = $iassign_ilm->type;
- $param->url = $iassign_ilm->url;
- $param->description = $description->{current_language()};
- $param->description_lang = $iassign_ilm->description;
- $param->extension = $iassign_ilm->extension;
- $param->author = $USER->id;
- $param->file_jar = '';
- $param->file_jar_static = '';
- $param->file_class = $iassign_ilm->file_class;
- $param->width = $iassign_ilm->width;
- $param->height = $iassign_ilm->height;
- $param->enable = 0;
- $param->timecreated = time();
- $param->timemodified = time();
- $param->evaluate = $iassign_ilm->evaluate;
- $param->parent = $iassign_ilm->parent;
- }
- }
-
-
-
- return $param;
- }
-
-
-
-
- static function new_file_ilm ($itemid, $iassign_ilm) {
- global $CFG, $USER, $DB;
- $return = null;
- $file_jar = array();
- $fs = get_file_storage();
- $contextuser = context_user::instance($USER->id);
- $contextsystem = context_system::instance();
- $files_ilm = $fs->get_area_files($contextuser->id, 'user', 'draft', $itemid);
- if ($files_ilm) {
- foreach ($files_ilm as $value) {
-
- if ($iassign_ilm->type == 1) {
-
- $ext = pathinfo($value->get_filename(), PATHINFO_EXTENSION);
-
- if ((strtolower($ext) == 'zip')) {
-
- $destination = 'ilm_debug/' . $value->get_filename();
- $value->copy_content_to($destination);
-
- $zip = new ZipArchive();
- $extracted = './ilm';
- $dir = "";
- if ($zip->open($destination) === TRUE) {
- $dir = './ilm/' . trim($zip->getNameIndex(0));
- if (is_dir($dir)) {
- $i = 1;
- $previous = str_replace("/", "", $zip->getNameIndex(0));
- while (file_exists('./ilm/' . $previous . "_" . $i)) {
- $i++;
- }
- $name = $previous . "_" . $i;
- $dir = './ilm/' . $name . "/";
- $j = 0;
- while ($item_name = $zip->getNameIndex($j)) {
- $zip->renameIndex($j, str_replace($previous, $name, $item_name));
- $j++;
- }
- $zip->close();
- }
- $zip->open($destination);
- $zip->extractTo($extracted);
- $zip->close();
-
- unlink($destination);
- } else {
-
- unlink($destination);
- print_error('error_add_ilm_zip', 'iassign');
- }
- return $dir;
- }
- }
- if ($value->get_filename() != '.') {
- $file_ilm = array(
- 'userid' => $USER->id,
- 'contextid' => $contextsystem->id,
- 'component' => 'mod_iassign',
- 'filearea' => 'ilm',
- 'itemid' => rand(1, 999999999),
- 'filepath' => '/iassign/ilm/' . iassign_utils::format_pathname($iassign_ilm->name) . '/' . iassign_utils::format_pathname($iassign_ilm->version) . '/',
- 'filename' => $value->get_filename());
- $file_ilm = $fs->create_file_from_storedfile($file_ilm, $value);
- array_push($file_jar, $file_ilm->get_id());
- }
- }
- if (!empty($file_jar)) {
- $return = implode(",", $file_jar);
- $old_file_jar = explode(",", $iassign_ilm->file_jar);
- foreach ($old_file_jar as $value) {
- $file = $fs->get_file_by_id($value);
- if ($file)
- $fs->delete_area_files($contextsystem->id, 'mod_iassign', 'ilm', $file->get_itemid());
- }
- }
- }
- else
- $return = $iassign_ilm->file_jar;
- $delete_file = $fs->delete_area_files($contextuser->id, 'user', 'draft', $itemid);
- return $return;
- }
-
-
- static function new_ilm ($itemid) {
- global $CFG, $USER, $OUTPUT;
-
- if (file_exists($CFG->dataroot . '/temp/' . 'ilm-application.xml')) {
- unlink($CFG->dataroot . '/temp/' . 'ilm-application.xml');
- }
- $pathtemp = $CFG->dataroot . '/temp/';
- $contextuser = context_user::instance($USER->id);
- $fs = get_file_storage();
- $zip = new zip_packer();
- $files = $fs->get_directory_files($contextuser->id, 'user', 'draft', $itemid, '/');
- foreach ($files as $file) {
- if (!$file->is_directory())
- $files_extract = $zip->extract_to_pathname($file, $pathtemp);
- }
- $application_xml = @simplexml_load_file($CFG->dataroot . '/temp/' . 'ilm-application.xml', null, LIBXML_NOCDATA);
-
- if (!$application_xml) {
- print($OUTPUT->notification(get_string('error_xml_ilm', 'iassign'), 'notifyproblem'));
- return;
- } else {
- $missing = "";
- if (!isset($application_xml->name)) {
- $missing .= "name";
- }
- if (!isset($application_xml->version)) {
- $missing .= ", version";
- }
- if (!isset($application_xml->type)) {
- $missing .= ", type";
- }
- if (!isset($application_xml->extension)) {
- $missing .= ", extension";
- }
- if (!isset($application_xml->file_jar)) {
- $missing .= ", file_jar";
- }
- if (!isset($application_xml->file_class)) {
- $missing .= ", file_class";
- }
- if (!isset($application_xml->width)) {
- $missing .= ", width";
- }
- if (!isset($application_xml->height)) {
- $missing .= ", height";
- }
- if (!isset($application_xml->evaluate)) {
- $missing .= ", evaluate";
- }
- if (strlen($missing) > 2) {
- print($OUTPUT->notification(get_string('error_xml_missing', 'iassign') . $missing . ".", 'notifyproblem'));
- return;
- }
- }
-
- $typec = strtolower($application_xml->type);
- require_once 'ilm_handlers/' . $typec . '.php';
- $retorno = $typec::new_ilm($itemid, $files_extract, $application_xml, $contextuser, $fs);
- return $retorno;
- }
-
-
- static function edit_ilm ($param, $itemid) {
-
- global $DB, $USER, $CFG;
- $iassign_t = $DB->get_record('iassign_ilm', array('id' => $param->id));
- $pathtemp = $CFG->dataroot . '/temp/';
- $contextuser = context_user::instance($USER->id);
- $fs = get_file_storage();
- $zip = new zip_packer();
- $files = $fs->get_directory_files($contextuser->id, 'user', 'draft', $itemid, '/');
- $files_extract = null;
- foreach ($files as $file) {
- if (!$file->is_directory())
- $files_extract = $zip->extract_to_pathname($file, $pathtemp);
- }
-
- $typec = strtolower($iassign_t->type);
- require_once 'ilm_handlers/' . $typec . '.php';
- $typec::edit_ilm($param, $itemid, $files_extract, $contextuser);
- }
-
-
-
- static function copy_new_version_ilm ($param) {
- global $DB, $CFG, $USER;
- $itemid = $param->file;
- $pathtemp = $CFG->dataroot . '/temp/';
-
-
- $contextuser = context_user::instance($USER->id);
- $fs = get_file_storage();
- $zip = new zip_packer();
- $files = $fs->get_directory_files($contextuser->id, 'user', 'draft', $itemid, '/');
- $files_extract = null;
- foreach ($files as $file) {
- if (!$file->is_directory())
- $files_extract = $zip->extract_to_pathname($file, $pathtemp);
- }
-
- $iassign_t = $DB->get_record('iassign_ilm', array('id' => $param->parent));
- $typec = strtolower($iassign_t->type);
- require_once 'ilm_handlers/' . $typec . '.php';
-
- $typec::copy_new_version_ilm($param, $files_extract);
- }
-
-
-
-
-
-
-
- static function visible_ilm ($ilm_id, $status) {
- global $DB;
- if ($status == 0)
- $visible = 1;
- else
- $visible = 0;
- $newentry = new stdClass();
- $newentry->id = $ilm_id;
- $newentry->enable = $visible;
- if (!$DB->update_record("iassign_ilm", $newentry))
- error(get_string('error_edit_ilm', 'iassign'));
- }
-
-
-
-
- static function confirm_default_ilm ($ilm_id, $ilm_parent) {
- global $OUTPUT, $DB;
- $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
- $optionsno = new moodle_url('/admin/settings.php', array('section' => 'modsettingiassign', 'action' => 'config', 'ilm_id' => $ilm_parent));
- $optionsyes = new moodle_url('/mod/iassign/settings_ilm.php', array('action' => 'default', 'ilm_id' => $ilm_id, 'ilm_parent' => $ilm_parent));
- $return = $OUTPUT->heading(get_string('confirm_default', 'iassign') . ': ' . $iassign_ilm->name);
- $return .= $OUTPUT->confirm(get_string('confirm_default_ilm', 'iassign') . $OUTPUT->help_icon('confirm_default_ilm', 'iassign'), $optionsyes, $optionsno);
- return $return;
- }
-
-
-
-
- static function default_ilm ($ilm_id) {
- global $DB;
- $iassign_ilm_default = $DB->get_record("iassign_ilm", array('id' => $ilm_id));
- $iassign_ilm = $DB->get_record("iassign_ilm", array('id' => $iassign_ilm_default->parent));
- $DB->delete_records("iassign_ilm", array('id' => $iassign_ilm_default->id));
- $iassign_ilm_default->id = $iassign_ilm->id;
- $iassign_ilm_default->parent = 0;
- $iassign_ilm->parent = $iassign_ilm_default->id;
- $iassign_ilm->id = 0;
- $iassign_ilm_default->enable = 1;
- if (!$DB->update_record("iassign_ilm", $iassign_ilm_default)) {
- print_error('error_edit_ilm', 'iassign');
- }
- $inserted = $DB->insert_record("iassign_ilm", $iassign_ilm);
- if (!$inserted) {
- $msg_error = get_string('error_add_ilm', 'iassign') . "<br/>In default_ilm(" . $ilm_id . ")<br/>\n";
- print_error($msg_error);
-
- }
- return $iassign_ilm_default->id;
- }
-
-
-
-
- static function confirm_delete_ilm ($ilm_id, $ilm_parent) {
- global $OUTPUT, $DB;
- $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
- $optionsno = new moodle_url('/admin/settings.php', array('section' => 'modsettingiassign', 'action' => 'config', 'ilm_id' => $ilm_parent));
- $optionsyes = new moodle_url('/mod/iassign/settings_ilm.php', array('action' => 'delete', 'ilm_id' => $ilm_id, 'ilm_parent' => $ilm_parent));
- return $OUTPUT->confirm(get_string('confirm_delete_ilm', 'iassign', $iassign_ilm->name . ' ' . $iassign_ilm->version), $optionsyes, $optionsno);
- }
-
-
-
- public static function delete_dir ($dirPath) {
- if (substr($dirPath, strlen($dirPath) - 1, 1) != '/') {
- $dirPath .= '/';
- }
- $files = glob($dirPath . '*', GLOB_MARK);
- foreach ($files as $file) {
- if (is_dir($file)) {
- ilm_settings::delete_dir($file);
- } else {
- unlink($file);
- }
- }
- rmdir($dirPath);
- }
-
-
-
- static function delete_ilm ($ilm_id) {
- global $DB;
- $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
-
- $typec = strtolower($iassign_ilm->type);
- require_once 'ilm_handlers/' . $typec . '.php';
- $retorno = $typec::delete_ilm($ilm_id);
- return $retorno;
- }
-
-
- static function export_ilm ($ilm_id) {
- global $DB;
- $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
- if (!$iassign_ilm) return;
-
- $typec = strtolower($iassign_ilm->type);
- if (!$typec) $typec = "html5";
- require_once 'ilm_handlers/' . $typec . '.php';
- $typec::export_ilm($ilm_id);
- }
-
-
-
- static function export_update_ilm ($ilm_id) {
- global $DB, $CFG;
- $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
- $xml_filename = $CFG->dataroot . '/temp/ilm-upgrade_' . iassign_utils::format_pathname($iassign_ilm->name) . '.xml';
- $zip_filename = 'ilm-' . iassign_utils::format_pathname($iassign_ilm->name . '-v' . $iassign_ilm->version) . '.ipz';
- $upgrade_descriptor = '<?xml version="1.0" encoding="utf-8"?>' . "\n";
- $upgrade_descriptor .= '<upgrade xmlns="http://line.ime.usp.br/application/1.5">' . "\n";
- $upgrade_descriptor .= ' <version>' . $iassign_ilm->version . '</version>' . "\n";
- $upgrade_descriptor .= ' <file>' . $zip_filename . '</file>' . "\n";
- $upgrade_descriptor .= ' <description>' . iassign_language::json_to_xml($iassign_ilm->description) . "\n " . '</description>' . "\n";
- $upgrade_descriptor .= '</upgrade>' . "\n";
- file_put_contents($xml_filename, $upgrade_descriptor);
- header("Pragma: public");
- header("Expires: 0");
- header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
- header("Cache-Control: private", false);
- header('Content-Type: application/xml; charset=utf-8');
- header("Content-Disposition: attachment; filename=\"" . basename($xml_filename) . "\";");
- header("Content-Length: " . @filesize($xml_filename));
- set_time_limit(0);
- @readfile("$xml_filename") || die("File not found.");
- unlink($xml_filename);
- exit;
- }
-
-
-
-
- static function save_ilm_by_xml ($application_xml, $files_extract) {
- global $CFG, $USER;
-
- $source = "";
- $diretorio = "";
- if (strtolower($application_xml->type) == 'html5') {
- $i = 0;
- foreach ($files_extract as $key => $value) {
- $file = $CFG->dataroot . '/temp/' . $key;
-
- if ($i == 0) {
- $source = $file;
- if (file_exists("ilm/" . basename($file))) {
- $j = 1;
- while (file_exists('ilm/' . basename($file) . "_" . $j)) {
- $j++;
- }
- $diretorio = 'ilm/' . basename($file) . "_" . $j;
-
- mkdir($diretorio, 0755, true);
- }
- else {
- $diretorio = 'ilm/' . basename($file);
-
- mkdir($diretorio, 0755, true);
- }
- break;
- }
- $i++;
- }
- foreach ($iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($source, RecursiveDirectoryIterator::SKIP_DOTS), RecursiveIteratorIterator::SELF_FIRST) as $item) {
- if ($item->isDir()) {
- mkdir($diretorio . DIRECTORY_SEPARATOR . $iterator->getSubPathName(), 0755, true);
- }
- else {
- copy($item, $diretorio . DIRECTORY_SEPARATOR . $iterator->getSubPathName());
- }
- }
- ilm_settings::delete_dir($source);
- return "./" . $diretorio;
- }
- $fs = get_file_storage();
- $file_jar = array();
- $files_ilm = explode(",", $application_xml->file_jar);
- $contextsystem = context_system::instance();
- foreach ($files_ilm as $value) {
- $file_ilm = array(
- 'userid' => $USER->id,
- 'contextid' => $contextsystem->id,
- 'component' => 'mod_iassign',
- 'filearea' => 'ilm',
- 'itemid' => rand(1, 999999999),
- 'filepath' => '/iassign/ilm/' . iassign_utils::format_pathname($application_xml->name) . '/' . iassign_utils::format_pathname($application_xml->version) . '/',
- 'filename' => $value);
- $file_ilm = $fs->create_file_from_pathname($file_ilm, $CFG->dataroot . '/temp/' . $value);
- array_push($file_jar, $file_ilm->get_id());
- }
- foreach ($files_extract as $key => $value) {
- $file = $CFG->dataroot . '/temp/' . $key;
- if (file_exists($file))
- unlink($file);
- }
- return $file_jar;
- }
-
-
- static function import_ilm ($itemid) {
- global $CFG, $USER, $OUTPUT;
-
- if (file_exists($CFG->dataroot . '/temp/' . 'ilm-application.xml')) {
- unlink($CFG->dataroot . '/temp/' . 'ilm-application.xml');
- }
- $pathtemp = $CFG->dataroot . '/temp/';
- $contextuser = context_user::instance($USER->id);
- $fs = get_file_storage();
- $zip = new zip_packer();
- $files = $fs->get_directory_files($contextuser->id, 'user', 'draft', $itemid, '/');
- foreach ($files as $file) {
- if (!$file->is_directory())
- $files_extract = $zip->extract_to_pathname($file, $pathtemp);
- }
- $application_xml = @simplexml_load_file($CFG->dataroot . '/temp/' . 'ilm-application.xml', null, LIBXML_NOCDATA);
-
- if (!$application_xml) {
- print($OUTPUT->notification(get_string('error_xml_ilm', 'iassign'), 'notifyproblem'));
- return;
- } else {
- $missing = "";
- if (!isset($application_xml->name)) {
- $missing .= "name";
- }
- if (!isset($application_xml->version)) {
- $missing .= ", version";
- }
- if (!isset($application_xml->type)) {
- $missing .= ", type";
- }
- if (!isset($application_xml->extension)) {
- $missing .= ", extension";
- }
- if (!isset($application_xml->file_jar)) {
- $missing .= ", file_jar";
- }
- if (!isset($application_xml->file_class)) {
- $missing .= ", file_class";
- }
- if (!isset($application_xml->width)) {
- $missing .= ", width";
- }
- if (!isset($application_xml->height)) {
- $missing .= ", height";
- }
- if (!isset($application_xml->evaluate)) {
- $missing .= ", evaluate";
- }
- if (strlen($missing) > 2) {
- print($OUTPUT->notification(get_string('error_xml_missing', 'iassign') . $missing . ".", 'notifyproblem'));
- return;
- }
- }
-
- $typec = strtolower($application_xml->type);
- require_once 'ilm_handlers/' . $typec . '.php';
- $typec::import_ilm($itemid, $files_extract, $application_xml, $contextuser, $fs);
- }
-
-
- static function list_ilm () {
- global $DB, $OUTPUT;
- $iassign_ilm = $DB->get_records('iassign_ilm', array("enable" => 1));
- $str = '';
- $str .= '<table id="outlinetable" cellpadding="5" width="100%" >' . "\n";
- $str .= '<tr><td align=right><input type=button value="' . get_string('close', 'iassign') . '" onclick="javascript:window.close ();"></td></tr>';
- if ($iassign_ilm) {
- foreach ($iassign_ilm as $ilm) {
- $url_view = new moodle_url('/mod/iassign/settings_ilm.php', array('action' => 'view', 'ilm_id' => $ilm->id));
- $link_view = $OUTPUT->action_link($url_view, iassign_icons::insert('view_ilm') . ' ' . get_string('read_more', 'iassign'));
- $str .= '<tr><td>';
- $str .= '<table class="generaltable boxaligncenter" width="100%">';
- $str .= '<tr>';
- $str .= '<td class=\'cell c0 actvity\' width=40%><strong>' . get_string('name_ilm', 'iassign') . ':</strong> ' . $ilm->name . '</td>' . "\n";
- $str .= '<td><strong>' . get_string('version_ilm', 'iassign') . ':</strong> ' . $ilm->version . '</td>' . "\n";
- $str .= '<td align=right>' . $link_view . '</td>' . "\n";
- $str .= '</tr>';
- $str .= '<tr><td colspan=3>' . iassign_language::get_description_lang(current_language(), $ilm->description) . '</td></tr>';
- $str .= '<tr><td colspan=3><a href="' . $ilm->url . '">' . $ilm->url . '</a></td></tr>';
- $str .= '</table>';
- $str .= '</td></tr>';
- }
- }
- $str .= '</table>';
- return $str;
- }
-
-
- static function upgrade_ilm ($ilm_id) {
- global $DB, $CFG, $USER;
- $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
- $upgrade_file = $iassign_ilm->url . 'ilm-upgrade_' . strtolower($iassign_ilm->name) . '.xml';
- $update_xml = @simplexml_load_file($upgrade_file, null, LIBXML_NOCDATA);
- $result = file_put_contents($CFG->dataroot . '/temp/' . $update_xml->file, fopen($iassign_ilm->url . $update_xml->file, 'r'));
- if (!$result)
- print_error('error_upgrade_ilm', 'iassign');
- else {
- $zip_filename = $CFG->dataroot . '/temp/' . $update_xml->file;
- $extension = explode(".", $zip_filename);
- if ($extension[count($extension) - 1] != 'ipz') {
- print($OUTPUT->notification(get_string('error_upload_ilm', 'iassign'), 'notifyproblem'));
- die;
- }
- $zip = new zip_packer();
- $fs = get_file_storage();
- $contextuser = context_user::instance($USER->id);
- $files_extract = $zip->extract_to_pathname($zip_filename, $CFG->dataroot . '/temp/');
- $application_xml = @simplexml_load_file($CFG->dataroot . '/temp/' . 'ilm-application.xml', null, LIBXML_NOCDATA);
- $description_str = htmlentities(str_replace(array('<description>', '</description>'), array('', ''), $application_xml->description->asXML()));
- $file_jar = self::save_ilm_by_xml($application_xml, $files_extract);
- if (file_exists($zip_filename))
- unlink($zip_filename);
- if (empty($file_jar)) {
- $msg_error = get_string('error_add_ilm', 'iassign') . "<br/>In upgrade_ilm(" . $ilm_id . ")<br/>\n";
- print_error($msg_error);
-
- }
- else {
- $newentry = new stdClass();
- $newentry->name = (String) $application_xml->name;
- $newentry->version = (String) $application_xml->version;
- $newentry->url = (String) $application_xml->url;
- $newentry->description = $description_str;
- $newentry->extension = strtolower((String) $application_xml->extension);
- $newentry->file_jar = implode(",", $file_jar);
- $newentry->file_class = (String) $application_xml->file_class;
- $newentry->width = (String) $application_xml->width;
- $newentry->height = (String) $application_xml->height;
- $newentry->enable = 0;
- $newentry->timemodified = time();
- $newentry->author = $USER->id;
- $newentry->timecreated = time();
- $newentry->evaluate = (String) $application_xml->evaluate;
- $newentry->parent = $ilm_id;
- }
- }
- return $iassign_ilm->id;
- }
-
-
-
-
-
-
-
- static function view_ilm ($ilmid, $from) {
- global $DB;
- $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilmid));
-
- $typec = strtolower($iassign_ilm->type);
- require_once 'ilm_handlers/' . $typec . '.php';
- $retorno = $typec::view_ilm($ilmid, $from);
- return $retorno;
- }
-
-
-
-
- static function add_edit_copy_param ($ilm_param_id, $action) {
- global $DB;
- require_once('params_form.php');
- $iassign_ilm_config = $DB->get_record('iassign_ilm_config', array('id' => $ilm_param_id));
- $param = new stdClass();
- $param->action = $action;
- $param->ilm_param_id = $ilm_param_id;
- $type = optional_param('type', NULL, PARAM_TEXT);
- if ($type == NULL && $iassign_ilm_config)
- $type = $iassign_ilm_config->param_type;
- if ($action == 'add') {
- $param->title = get_string('add_ilm', 'iassign');
- $param->iassign_ilmid = $ilm_param_id;
- $param->param_name = "";
- $param->param_value = "";
- $param->description = "";
- $param->visible = 1;
- }
- elseif ($action == 'edit') {
- if ($iassign_ilm_config) {
- $param->title = get_string('edit_ilm', 'iassign');
- $param->id = $iassign_ilm_config->id;
- $param->iassign_ilmid = $iassign_ilm_config->iassign_ilmid;
- $param->param_type = $type;
- $param->param_name = $iassign_ilm_config->param_name;
- if ($type != 'choice' && $type != 'multiple')
- $param->param_value = $iassign_ilm_config->param_value;
- else
- $param->param_value = str_replace(", ", "\n", $iassign_ilm_config->param_value);
- $param->param_value = $iassign_ilm_config->param_value;
- $param->description = $iassign_ilm_config->description;
- $param->visible = $iassign_ilm_config->visible;
- }
- }
- elseif ($action == 'copy') {
- if ($iassign_ilm_config) {
- $param->title = get_string('copy_ilm', 'iassign');
- $param->iassign_ilmid = $iassign_ilm_config->iassign_ilmid;
- $param->param_type = $type;
- $param->param_name = $iassign_ilm_config->param_name;
- if ($type != 'choice' && $type != 'multiple')
- $param->param_value = $iassign_ilm_config->param_value;
- else
- $param->param_value = str_replace(", ", "\n", $iassign_ilm_config->param_value);
- $param->description = $iassign_ilm_config->description;
- $param->visible = $iassign_ilm_config->visible;
- }
- }
- return $param;
- }
-
-
-
- static function visible_param ($ilm_param_id, $status) {
- global $DB, $CFG;
- if ($status == 0)
- $visible = 1;
- else
- $visible = 0;
- $newentry = new stdClass();
- $newentry->id = $ilm_param_id;
- $newentry->visible = $visible;
- if (!$DB->update_record("iassign_ilm_config", $newentry))
- error(get_string('error_edit_param', 'iassign'));
- }
-
-
- static function add_param ($param) {
- global $DB;
- $newentry = new stdClass();
- $newentry->iassign_ilmid = $param->iassign_ilmid;
-
- $newentry->param_type = $param->param_type;
- $newentry->param_name = iassign_utils::format_filename($param->param_name);
- if ($newentry->param_type != 'choice' && $newentry->param_type != 'multiple')
- $newentry->param_value = $param->param_value;
- else
- $newentry->param_value = str_replace("\r\n", ", ", $param->param_value);
- $newentry->description = $param->description;
- $newentry->visible = $param->visible;
- $newentry->id = $DB->insert_record("iassign_ilm_config", $newentry);
- if (!$newentry->id) {
- print_error('error_add_param', 'iassign');
- }
- }
-
-
- static function edit_param ($param) {
- global $DB;
- $updentry = new stdClass();
- $updentry->id = $param->id;
- $updentry->iassign_ilmid = $param->iassign_ilmid;
- $updentry->param_type = $param->param_type;
-
- $newentry->param_name = iassign_utils::format_filename($param->param_name);
- if ($updentry->param_type != 'choice' && $updentry->param_type != 'multiple')
- $updentry->param_value = $param->param_value;
- else
- $updentry->param_value = str_replace("\r\n", ", ", $param->param_value);
- $updentry->description = $param->description;
- $updentry->visible = $param->visible;
- if (!$DB->update_record("iassign_ilm_config", $updentry)) {
- error(get_string('error_edit_param', 'iassign'));
- }
- }
-
-
- static function copy_param ($param) {
- global $DB;
- $newentry = new stdClass();
- $newentry->iassign_ilmid = $param->iassign_ilmid;
-
- $newentry->param_name = iassign_utils::format_filename($param->param_name);
- if ($newentry->param_type != 'choice' && $newentry->param_type != 'multiple')
- $newentry->param_value = $param->param_value;
- else
- $newentry->param_value = str_replace("\r\n", ", ", $param->param_value);
- $newentry->description = $param->description;
- $newentry->visible = $param->visible;
- $newentry->id = $DB->insert_record("iassign_ilm_config", $newentry);
- if (!$newentry->id) {
- print_error('error_add_param', 'iassign');
- }
- }
-
-
- static function delete_param ($param_id) {
- global $DB;
- if (!$DB->delete_records("iassign_ilm_config", array('id' => $param_id))) {
- print_error('error_delete_param', 'iassign');
- }
- }
- }
- class ilm_manager {
- var $id;
- var $url;
- var $from;
-
-
-
- function __construct ($id, $url, $from) {
- $this->id = $id;
- $this->url = $url;
- $this->from = $from;
- }
-
-
-
- function get_file_ilm () {
- $ilmid = optional_param('ilmid', NULL, PARAM_INT);
- $fileid = optional_param('fileid', NULL, PARAM_INT);
-
- $fs = get_file_storage();
- $md_file = $fs->get_file_by_id($fileid);
- $ilm_content_file = $md_file->get_content();
- return $ilm_content_file;
- }
-
-
- function ilm_editor_new () {
- global $CFG, $DB, $OUTPUT, $PAGE;
- $ilmid = optional_param('ilmid', NULL, PARAM_INT);
- $dirid = optional_param('dirid', NULL, PARAM_INT);
- $iassign = $DB->get_record("iassign_ilm", array("id" => $ilmid));
- $context = context_course::instance($this->id);
- $returnurl = $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=$this->id&dirid=$dirid&ilmid=$ilmid";
-
- if (!$iassign) {
- print $OUTPUT->notification(get_string('error_confirms_ilm', 'iassign'), 'notifysuccess');
- die();
- }
- $temp = explode(",", $iassign->extension);
- $extension = $temp[0];
-
-
- $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_RAW);
-
- if ($stringArchiveContent != NULL) {
-
-
-
- $filename = optional_param('filename', NULL, PARAM_RAW);
-
- $filename = iassign_utils::filter_filename_extension($filename, $extension);
-
-
-
-
-
-
-
-
-
-
-
-
-
- $_SESSION['file_name'] = $filename;
-
-
- $this->write_file_iassign($stringArchiveContent, $filename);
- die();
- }
- else {
-
- if ($extension == "html" || $extension == "ivph" || strtolower($iassign->type) == 'html5') {
- $str_get_iLM = "window.frames.iLM";
- $str_submitbutton_name = "javascript:window.submit_iLM_Answer()";
- }
- else {
- $str_get_iLM = "document.iLM";
- $str_submitbutton_name = "submit_iLM_Answer()";
- }
- $fs = get_file_storage();
- $files = $fs->get_area_files($context->id, 'mod_iassign', 'activity');
- $files_array = '';
- foreach ($files as $value) {
- if ($value->get_filename() != ".")
- $files_array .= "'" . $value->get_filename() . "',";
- }
- $files_array .= "''";
- $file = null;
- $ia_content = "";
- $filename = "";
- $error_files_exists = get_string('error_file_exists', 'iassign');
- $output = "<script type='text/javascript'>
- //<![CDATA[
- //D alert('locallib.php: ilm_editor_new');
- function submit_iLM_Answer () {
- var docFormOnLineEditor = document.formEnvio;
- var resposta_exerc = new Array(3);
- var valor_resposta = new Array(3);
- var sessao = new Array(3);
- var doc_iLM = " . $str_get_iLM . "; // 'window.frames.iLM' or 'document.iLM'
- resposta_exerc[0] = doc_iLM.getAnswer();
- valor_resposta[0] = doc_iLM.getEvaluation();
- docFormOnLineEditor.iLM_PARAM_ActivityEvaluation.value = valor_resposta[0];
- docFormOnLineEditor.iLM_PARAM_ArchiveContent.value = resposta_exerc[0];
- var files = new Array(" . $files_array . ");
- var filename = docFormOnLineEditor.filename.value+'.'+'" . $extension . "';
- if (docFormOnLineEditor.filename.value=='') {
- // ERROR: the file name is empty
- alert('" . get_string('error_file_null_iassign', 'iassign') . "');
- return false;
- }
- // }
- for (i=0; i<files.length; i++) {
- if (files[i]==docFormOnLineEditor.filename.value || files[i]==filename) {
- alert('" . $error_files_exists . "');
- return false;
- }
- }
- docFormOnLineEditor.submit();
- return true;
- }
- //]]>
- </script>\n";
- $output .= "
- <form name='formEnvio' id='formEnvio' method='post' enctype='multipart/form-data'>\n";
- $output .= $OUTPUT->box_start();
-
- $output .= "
- <table width='100%' cellpadding='20'>
- <tr><td>" . get_string('label_file_iassign', 'iassign') . " <input type='text' name='filename' size=50/>
- <input type=button value='" . get_string('label_write_iassign', 'iassign') . "' title='' onclick='" . $str_submitbutton_name . ";'/></td>
- </tr>
- </table>\n";
- $output .= $OUTPUT->box_end();
- $output .= "<center>\n";
-
-
- $output_ilm = ilm_settings::build_ilm_tags($ilmid, array("type" => "editor_new", "notSEND" => "true"));
- $output .= $output_ilm;
- $output .= " <input type='hidden' name='iLM_PARAM_ArchiveContent' value='" . $ia_content . "'>
- <input type='hidden' name='iLM_PARAM_ActivityEvaluation'>
- </center>
- </form>\n";
- $title = get_string('title_editor_iassign', 'iassign') . " - " . $iassign->name . " " . $iassign->version;
- $PAGE->navbar->add($title);
- $PAGE->set_title($title);
- $PAGE->set_heading($title);
- print $OUTPUT->header();
-
- print $output;
- print $OUTPUT->footer();
- }
- die();
- }
-
-
- function ilm_editor_update ($filename, $content_file, $token, $secure_id) {
- global $CFG, $DB, $OUTPUT, $PAGE;
- $ilmid = optional_param('ilmid', NULL, PARAM_INT);
- $dirid = optional_param('dirid', NULL, PARAM_INT);
- $fileid = optional_param('fileid', NULL, PARAM_TEXT);
- $iassign = $DB->get_record("iassign_ilm", array("id" => $ilmid));
- $returnurl = $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=$this->id&dirid=$dirid&ilmid=$ilmid";
-
- if (!$iassign) {
- print $OUTPUT->notification(get_string('error_confirms_ilm', 'iassign'), 'notifyproblem');
- die;
- }
-
-
-
-
-
-
- $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_RAW);
-
- if ($stringArchiveContent != NULL) {
- $this->update_file_iassign($stringArchiveContent, $filename, $fileid);
- die();
- } else {
- $end_file = '';
- if ($content_file) {
-
- $end_file = $CFG->wwwroot . '/mod/iassign/ilm_security.php?id=' . $secure_id . '&action=update&token=' . $token . '&view=0';
- }
- $temp = explode(",", $iassign->extension);
- $extension = $temp[0];
- if ($extension == "html" || $extension == "ivph" || strtolower($iassign->type) == 'html5') {
- $str_get_iLM = "window.frames.iLM";
- $str_submitbutton_name = "javascript:window.submit_iLM_Answer()";
- } else {
- $str_get_iLM = "document.iLM";
- $str_submitbutton_name = "submit_iLM_Answer()";
- }
- $output = "<script type='text/javascript'>
- //<![CDATA[
- function submit_iLM_Answer () {
- var docFormEditor = document.formEnvio;
- var activityAnswer; // to get activity answer (text)
- var activityValue; // to get activity answer value (float)
- var doc_iLM = " . $str_get_iLM . "; // 'window.frames.iLM' or 'document.iLM'
- //activityAnswer = doc_iLM.getAnswer();
- //activityValue = doc_iLM.getEvaluation();
- activityAnswer = " . $str_get_iLM . ".getAnswer();
- activityValue = " . $str_get_iLM . ".getEvaluation();
- docFormEditor.iLM_PARAM_ActivityEvaluation.value = activityValue;
- docFormEditor.iLM_PARAM_ArchiveContent.value = activityAnswer;
- docFormEditor.submit();
- return true;
- }
- //]]>
- </script>\n";
-
-
-
-
-
- $output .= "
- <form name='formEnvio' id='formEnvio' method='post' enctype='multipart/form-data'>\n";
- $output .= $OUTPUT->box_start();
- $output .= "
- <table width='100%' cellpadding='20'>
- <tr><td width='75%'>" . get_string('label_file_iassign', 'iassign') . "<b>$filename</b></td>
- <td align='right' width='25%'><input type=button value='" . get_string('label_write_iassign', 'iassign') . "' title='' onclick='submit_iLM_Answer();'/>
- <input type='hidden' name='filename' value='$filename'/></td>
- <td>
- <input type=button value='" . get_string('close', 'iassign') . "' title='' onclick='javascript:window.location = \"$returnurl\";'/></td>
- </tr>
- </table>\n";
- $output .= $OUTPUT->box_end();
- $output .= " <center>\n";
-
- $output .= ilm_settings::build_ilm_tags($ilmid, array("type" => "editor_update", "notSEND" => "false", "Proposition" => $end_file));
- $output .= " <input type='hidden' name='iLM_PARAM_ArchiveContent' value=''>
- <input type='hidden' name='iLM_PARAM_ActivityEvaluation' value=''>
- </center>
- </form>\n";
- $title = get_string('title_editor_iassign', 'iassign') . " - " . $iassign->name . " " . $iassign->version;
- $PAGE->navbar->add($title);
- $PAGE->set_title($title);
- $PAGE->set_heading($title);
- print $OUTPUT->header();
-
- print $output;
- print $OUTPUT->footer();
- }
- die();
- }
-
-
-
-
- function write_file_iassign ($stringArchiveContent, $filename) {
- global $USER;
- $ilmid = optional_param('ilmid', NULL, PARAM_INT);
- $context = context_course::instance($this->id);
- $fs = get_file_storage();
- $dirid = $this->get_dir_ilm('dirid');
- $dir = $fs->get_file_by_id($dirid);
- $fileinfo = array('contextid' => $context->id,
- 'component' => 'mod_iassign',
- 'filearea' => 'activity',
- 'itemid' => 0,
- 'filepath' => '/',
- 'userid' => $USER->id,
- 'author' => $USER->firstname . ' ' . $USER->lastname, 'license' => 'allrightsreserved',
- 'filename' => $filename);
-
-
- $file_course = $fs->create_file_from_string($fileinfo, $stringArchiveContent);
-
-
-
-
- $output = "
- <script type='text/javascript'>
- //<![CDATA[
- alert('" . get_string('sucess_write', 'iassign') . " " . $filename . "');
- window.location='" . $this->url . "&dirid=$dirid&ilmid=$ilmid';
- //]]>
- </script>";
- print $output;
- die();
- }
-
-
-
-
- function update_file_iassign ($stringArchiveContent, $filename, $fileid) {
- global $OUTPUT, $USER;
- $ilmid = optional_param('ilmid', NULL, PARAM_INT);
- $context = context_course::instance($this->id);
- $dirid = $this->get_dir_ilm('dirid');
- if ($stringArchiveContent != (-1)) {
- $fs = get_file_storage();
- $file = $fs->get_file_by_id($fileid);
- if (!$file) {
- print $OUTPUT->notification(get_string('error_view_ilm', 'iassign'), 'notifyproblem');
- die;
- }
- $fileinfo = array('contextid' => $context->id,
- 'component' => 'mod_iassign',
- 'filearea' => 'activity',
- 'itemid' => 0,
- 'filepath' => $file->get_filepath(),
- 'userid' => $USER->id,
- 'author' => $USER->firstname . ' ' . $USER->lastname,
- 'license' => 'allrightsreserved',
- 'timecreated' => $file->get_timecreated(),
- 'filename' => $file->get_filename());
- $file->delete();
-
- $file_course = $fs->create_file_from_string($fileinfo, $stringArchiveContent);
- }
- $output = "<script type='text/javascript'>
- //<![CDATA[
- alert('" . get_string('sucess_update', 'iassign') . "');\n
- window.location='" . $this->url . "&dirid=$dirid&ilmid=$ilmid';
- //]]>
- </script>";
- print $output;
- die();
- }
-
-
-
-
-
-
-
- function tag_ilm ($fileid) {
- global $DB;
- $fs = get_file_storage();
- $width = '600';
- $height = '400';
- $file = $fs->get_file_by_id($fileid);
- $filetype = explode(".", $file->get_filename());
- $iassign_ilm = $DB->get_records('iassign_ilm', array("enable" => 1, "parent" => 0));
- foreach ($iassign_ilm as $value) {
- $extensions = explode(",", $value->extension);
- if (in_array($filetype[1], $extensions)) {
- $width = $value->width;
- $height = $value->height;
- }
- }
- return("<p><ia toolbar=disable width=$width height=$height >$fileid</ia></p>");
- }
-
- function delete_file_ilm () {
- $ilmid = optional_param('ilmid', NULL, PARAM_INT);
- $fs = get_file_storage();
- $fileid = optional_param('fileid', NULL, PARAM_RAW);
- $file = $fs->get_file_by_id($fileid);
- if ($file)
- $file->delete();
- redirect(new moodle_url($this->url . '&dirid=' . $this->get_dir_ilm('dirid') . '&ilmid=' . $ilmid));
- die();
- }
-
- function delete_selected_ilm () {
- $ilmid = optional_param('ilmid', NULL, PARAM_INT);
- $fs = get_file_storage();
- $context = context_course::instance($this->id);
- $files_id = explode(",", optional_param('files_id', '', PARAM_TEXT));
- $dirid = $this->get_dir_ilm('dirid');
- foreach ($files_id as $file_id) {
- $file = $fs->get_file_by_id($file_id);
- if ($file) {
- if (!$file->is_directory())
- $file->delete();
- else {
- $files_delete = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $file->get_filepath(), true, true);
- foreach ($files_delete as $value)
- $value->delete();
- $file->delete();
- }
- }
- }
- redirect(new moodle_url($this->url . '&dirid=' . $dirid . '&ilmid=' . $ilmid));
- die();
- }
-
-
- function duplicate_file_ilm () {
- global $USER, $COURSE;
- $ilmid = optional_param('ilmid', NULL, PARAM_INT);
- $fs = get_file_storage();
- $fileid = optional_param('fileid', NULL, PARAM_INT);
- $filename = optional_param('filename', NULL, PARAM_RAW);
- $file = $fs->get_file_by_id($fileid);
- $context = context_course::instance($this->id);
- $fileinfo = array(
- 'contextid' => $context->id,
- 'component' => 'mod_iassign',
- 'filearea' => 'activity',
- 'itemid' => 0,
- 'filepath' => $this->get_dir_ilm('dir_base'),
- 'userid' => $USER->id,
- 'author' => $USER->firstname . ' ' . $USER->lastname, 'license' => 'allrightsreserved',
- 'timecreated' => $file->get_timecreated(), 'filename' => $filename);
- $newfile = $fs->create_file_from_string($fileinfo, $file->get_content());
- redirect(new moodle_url($this->url . "&dirid=" . $this->get_dir_ilm('dirid') . "&ilmid=" . $ilmid));
- die();
- }
-
- function rename_file_ilm () {
- $ilmid = optional_param('ilmid', NULL, PARAM_INT);
- $fs = get_file_storage();
- $fileid = optional_param('fileid', NULL, PARAM_INT);
- $filename = optional_param('filename', NULL, PARAM_TEXT);
- $file = $fs->get_file_by_id($fileid);
- $file->rename($this->get_dir_ilm('dir_base'), $filename);
-
- redirect(new moodle_url($this->url . '&dirid=' . $this->get_dir_ilm('dirid') . '&ilmid=' . $ilmid));
-
- die();
- }
-
- function add_ilm () {
- $fileid = optional_param('fileid', NULL, PARAM_INT);
- $filename = optional_param('filename', NULL, PARAM_TEXT);
- $output = "
- <script type='text/javascript'>
- //<![CDATA[
- var iassign_file_link = window.opener.document.getElementById('iassign_file_link');
- iassign_file_link.innerHTML = '$filename';
- window.opener.document.forms['mform1'].file.value='$fileid';
- window.opener.document.forms['mform1'].filename.value='$filename';
- window.close();
- //]]>
- </script>";
- print $output;
- die();
- }
-
-
-
- function preview_ilm ($courseid, $iassign_ilm) {
- global $OUTPUT, $CFG, $USER;
- $fileid = optional_param('fileid', NULL, PARAM_TEXT);
- $title = get_string('modulename', 'iassign');
- print $OUTPUT->header();
- print $OUTPUT->box_start();
- $javascript = "
- <!-- iAssign preview iLM content / LInE - http://line.ime.usp.br -->
- <script type='text/javascript'>
- //<![CDATA[
- function submit_close () {
- window.opener.location.reload();
- window.close();
- }
- //]]>
- </script>\n";
-
-
-
-
-
-
-
- $ilm_name = substr(strtolower($iassign_ilm->name), 0, 6);
- if ($ilm_name != "ivprog") {
-
- $tag_filter = $this->tag_ilm($fileid);
- $tag_filter_filtered = format_text($tag_filter, FORMAT_MOODLE, array('overflowdiv' => true, 'allowid' => true));
- } else {
- require_once($CFG->dirroot . '/mod/iassign/ilm_security.php');
- $content_or_id_from_ilm_security = $this->get_file_ilm();
- $timecreated = time();
- $token = md5($timecreated);
- $id_iLM_security = ilm_security::write_iLM_security($USER->id, $timecreated, -1, $content_or_id_from_ilm_security);
- $param = 'id=' . $id_iLM_security . '&ilmid=' . $iassign_ilm->id . '&token=' . $token . '&view=0';
- $url_file = $CFG->wwwroot . '/mod/iassign/ilm_security.php?action=preview&' . $param;
- $tag_filter_filtered = ilm_settings::build_ilm_tags($iassign_ilm->id, array("type" => "view", "notSEND" => "true", "Proposition" => $url_file));
- }
- $html = "
- <form name='formEnvio' id='formEnvio' method='post' enctype='multipart/form-data'>
- <table border='1'>
- <tr><td>
- <!-- iLM calls : begin -->\n" . $tag_filter_filtered . "\n
- <!-- iLM calls : end -->
- </td></tr>
- </table>
- <table>
- <tr>
- <td align='center'>
- <input type=button value='" . get_string('close', 'iassign') . "' title='' onclick='submit_close();' />
- </td></tr>
- </table>
- </form>\n";
- print $javascript . $html;
- print $OUTPUT->box_end();
-
- die();
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- function export_files_ilm () {
- global $CFG;
- $context = context_course::instance($this->id);
- $files_id = explode(",", optional_param('files_id', '', PARAM_TEXT));
- $zip_filename = $CFG->dataroot . '/temp/backup-iassign-files-' . date("Ymd-Hi") . '.zip';
- $zip = new zip_archive();
- $zip->open($zip_filename);
- $fs = get_file_storage();
- foreach ($files_id as $file_id) {
- $file = $fs->get_file_by_id($file_id);
- if (!$file->is_directory())
- $zip->add_file_from_string($file->get_filename(), $file->get_content());
- else {
- $zip->add_directory($file->get_filepath());
- $files_zip = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $file->get_filepath(), true, true);
- foreach ($files_zip as $value) {
- if (!$value->is_directory())
- $zip->add_file_from_string($value->get_filepath() . $value->get_filename(), $value->get_content());
- else
- $zip->add_directory($value->get_filepath());
- }
- }
- }
- $zip->close();
- header("Pragma: public");
- header("Expires: 0");
- header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
- header("Cache-Control: private", false);
- header("Content-Type: application/zip");
- header("Content-Disposition: attachment; filename=\"" . basename($zip_filename) . "\";");
- header("Content-Transfer-Encoding: binary");
- header("Content-Length: " . @filesize($zip_filename));
- set_time_limit(0);
- @readfile("$zip_filename") || die("File not found.");
- unlink($zip_filename);
- exit;
- }
-
-
- function tinymce_ilm ($fileid) {
- $tag_filter = $this->tag_ilm($fileid);
- $output = "<script type='text/javascript'>
- //<![CDATA[
- var tag_filter = '$tag_filter';
- if (window.opener.tinyMCE.execCommand('mceiAssignReturn', tag_filter)) {
- // all right, insert it
- } else {
- alert('Error trying to insert iLM content (tinymce_ilm " + $fileid + ")');
- }
- // window.close();
- //]]>
- </script>\n";
- print $output;
- die();
- }
-
-
-
-
- function editor_ilm ($fileid, $editor) {
- $tag_filter = $this->tag_ilm($fileid);
- $output1 = "<script type='text/javascript'>
- //<![CDATA[
- var tag_filter = '$tag_filter';\n";
- if ($editor == 'atto') {
- $output2 = " if (window.opener.document.execCommand('insertHTML', false, tag_filter)) { } // all right, insert it";
- } elseif ($editor == 'tinyMCE') {
- $output2 = " if (window.opener.tinyMCE.execCommand('mceiAssignReturn', tag_filter)) { } // all right, insert it";
- } else
- $output2 = "";
- $output3 = " else { console.log('Error trying to insert iLM content (atto_ilm " . $fileid . ")'); }
- window.close();
- //]]>
- </script>\n";
-
- print $output1 . $output2 . $output3;
- die();
- }
-
-
-
- function atto_ilm ($fileid) {
- global $CFG, $DB;
- $tag_filter = $this->tag_ilm($fileid);
- $output = "<script type='text/javascript'>
- //<![CDATA[
- var tag_filter = '$tag_filter';
- if (window.opener.document.execCommand('insertHTML', false, tag_filter)) {
- // all right, insert iLM tag to this editor
- } else {
- // error trying to insert
- alert('Error trying to insert iLM content (atto_ilm " + $fileid + ")');
- }
- //window.close();
- //]]>
- </script>\n";
- print $output;
- die();
- }
-
-
-
- function get_dir_ilm ($key) {
- $fs = get_file_storage();
- $context = context_course::instance($this->id);
- $dirid = optional_param('dirid', 0, PARAM_INT);
- $dir_home = $fs->get_file($context->id, 'mod_iassign', 'activity', 0, $dir_base = '/', '.');
- if ($dirid == 0) {
- $dir = ($dir_home = $fs->create_directory($context->id, 'mod_iassign', 'activity', 0, $dir_base));
- $dirid = $dir->get_id();
- }
- else {
- $dir = $fs->get_file_by_id($dirid);
- $dir_base = $dir->get_filepath();
- }
- $dir_parent = $dir->get_parent_directory();
- $data = array('dirid' => $dirid, 'dir_base' => $dir_base, 'dir_parent' => ($dir_parent == NULL ? 0 : $dir_parent->get_id()), 'dir_home' => $dir_home->get_id());
- return $data[$key];
- }
-
- function new_dir_ilm () {
- global $USER;
- $ilmid = optional_param('ilmid', NULL, PARAM_INT);
- $dirname = optional_param('dirname', NULL, PARAM_TEXT);
- $dir_base = $this->get_dir_ilm('dir_base');
- $context = context_course::instance($this->id);
- $fs = get_file_storage();
- $fs->create_directory($context->id, 'mod_iassign', 'activity', 0, $dir_base . $dirname . "/", $USER->id);
- $dir_base = $fs->get_file($context->id, 'mod_iassign', 'activity', 0, $dir_base . $dirname . "/", '.');
- $dir_base->set_author($USER->firstname . ' ' . $USER->lastname);
- redirect(new moodle_url($this->url . '&dirid=' . $this->get_dir_ilm('dirid') . '&ilmid=' . $ilmid));
- }
-
- function delete_dir_ilm () {
- $fs = get_file_storage();
- $ilmid = optional_param('ilmid', NULL, PARAM_INT);
- $context = context_course::instance($this->id);
- $dir = $fs->get_file_by_id($this->get_dir_ilm('dirid'));
- $dir_parent = $this->get_dir_ilm('dir_parent');
- if ($dir) {
- if ($dir->is_directory()) {
- $files_delete = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $dir->get_filepath(), true, true);
- foreach ($files_delete as $value)
- $value->delete();
- $dir->delete();
- }
- }
- redirect(new moodle_url($this->url . '&dirid=' . $dir_parent . '&ilmid=' . $ilmid));
- die();
- }
-
- function rename_dir_ilm () {
- $fs = get_file_storage();
- $ilmid = optional_param('ilmid', NULL, PARAM_INT);
- $context = context_course::instance($this->id);
- $dir = $fs->get_file_by_id($this->get_dir_ilm('dirid'));
- $dir_parent = $this->get_dir_ilm('dir_parent');
- $dirname = optional_param('dirname', NULL, PARAM_TEXT);
- $pathname = explode("/", substr($dir->get_filepath(), 0, strlen($dir->get_filepath()) - 1));
- if ($dir->is_directory()) {
- $files_rename_path = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $dir->get_filepath(), true, true);
- foreach ($files_rename_path as $value)
- $value->rename(str_replace($pathname[count($pathname) - 1], $dirname, $value->get_filepath()), $value->get_filename());
- $dir->rename(str_replace($pathname[count($pathname) - 1], $dirname, $dir->get_filepath()), $dir->get_filename());
- }
- redirect(new moodle_url($this->url . '&dirid=' . $dir_parent . '&ilmid=' . $ilmid));
- die();
- }
-
- function selected_move_ilm () {
- global $PAGE, $OUTPUT, $CFG;
- $fs = get_file_storage();
- $context = context_course::instance($this->id);
- $ilmid = optional_param('ilmid', NULL, PARAM_INT);
- $dirid = $this->get_dir_ilm('dirid');
- $dir_base = $this->get_dir_ilm('dir_base');
- $files_id = explode(",", optional_param('files_id', '', PARAM_TEXT));
- $code_javascript_ilm = "
- <script type='text/javascript'>
- //<![CDATA[
- function getRadiobutton () {
- var radioButtons = document.getElementsByTagName('input');
- var param = '';
- for (var counter=0; counter < radioButtons.length; counter++) {
- if (radioButtons[counter].type.toUpperCase()=='RADIO' && radioButtons[counter].checked == true && radioButtons[counter].name == 'selected_dir')
- param = radioButtons[counter].value;
- }
- return param;
- }
- function move_selected_ilm () {
- var msgAnswer;
- if (getRadiobutton() != '') {
- msgAnswer = confirm('" . get_string('question_move_dir', 'iassign') . "');
- if (msgAnswer)
- window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=move&ilmid=" . $ilmid . "&dirid=" . $dirid . "&files_id=" .
- optional_param('files_id', '', PARAM_TEXT) . "&dir_move='+getRadiobutton();
- }
- else
- alert('" . get_string('error_dir_not_selected_to_move', 'iassign') . "');
- }
- function cancel_selected_ilm () {
- window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&ilmid=" . $ilmid . "&dirid=" . $dirid . "';
- }
- //]]>
- </script>\n";
- $title = get_string('move_files', 'iassign');
- $PAGE->set_title($title);
- $PAGE->set_pagelayout('base');
- print $OUTPUT->header();
- print $OUTPUT->heading($title);
- $dir_paths = array();
- print $OUTPUT->box_start();
- print "<center>";
- foreach ($files_id as $file_id) {
- $file = $fs->get_file_by_id($file_id);
- if ($file) {
- if (!$file->is_directory())
- print "<p>" . iassign_icons::insert('file') . " " . $file->get_filepath() . $file->get_filename() . "</p>";
- else {
- print "<p>" . iassign_icons::insert('dir') . " " . $file->get_filepath() . "</p>";
- array_push($dir_paths, $file->get_filepath());
- }
- }
- }
- print $OUTPUT->heading(get_string('select_move_ilm', 'iassign'), 3, 'move', 'move_files');
- if ($dir_base != '/') {
- $check_select = "<input name='selected_dir' type='radio' value='" . $this->get_dir_ilm('dir_home') . "'/>";
- print $check_select . " " . iassign_icons::insert('dir') . " /<br>";
- }
- $files_tree = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, '/', true, true, 'filepath');
- foreach ($files_tree as $file) {
- if ($file->is_directory() && $file->get_filepath() != $dir_base) {
- $is_parent = false;
- foreach ($dir_paths as $dir) {
- $path = explode("/", $dir);
- array_pop($path);
- $path[count($path) - 1] = '';
- $path = implode("/", $path);
- $is_parent |= (strpos($file->get_filepath(), $dir) === false ? false : true);
- $is_parent |= ($file->get_filepath() != $path ? false : true);
- }
- if ($is_parent == false) {
- $check_select = "<input name='selected_dir' type='radio' value='" . $file->get_id() . "'/>";
- print "<p>" . $check_select . " " . iassign_icons::insert('dir') . " " . $file->get_filepath() . "</p>";
- }
- }
- }
- print "<p><input type='button' value='" . get_string('ok') . "' onclick='move_selected_ilm();'/> ";
- print "<input type='button' value='" . get_string('cancel') . "' onclick='cancel_selected_ilm();'/></p>";
- print "</center>";
- print $OUTPUT->box_end();
- print $OUTPUT->footer();
- print $code_javascript_ilm;
- die;
- }
-
- function move_files_ilm () {
- $fs = get_file_storage();
- $context = context_course::instance($this->id);
- $ilmid = optional_param('ilmid', NULL, PARAM_INT);
- $dirid = $this->get_dir_ilm('dirid');
- $dir_move = $fs->get_file_by_id(optional_param('dir_move', 0, PARAM_INT));
- $files_id = explode(",", optional_param('files_id', '', PARAM_TEXT));
- foreach ($files_id as $file_id) {
- $file = $fs->get_file_by_id($file_id);
- if ($file) {
- if ($file->is_directory()) {
- $pathname = explode("/", $file->get_filepath());
- $files_move_path = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $file->get_filepath(), true, true);
- foreach ($files_move_path as $value) {
- $path_move = $dir_move->get_filepath() . $pathname[count($pathname) - 2] . '/' . str_replace($file->get_filepath(), '', $value->get_filepath());
- $value->rename($path_move, $value->get_filename());
-
- }
- $path_move = $dir_move->get_filepath() . $pathname[count($pathname) - 2] . '/';
-
- $file->rename($path_move, $file->get_filename());
- } else {
-
- $file->rename($dir_move->get_filepath(), $file->get_filename());
- }
- }
- }
-
- redirect(new moodle_url($this->url . '&ilmid=' . $ilmid . '&dirid=' . $dirid));
- die();
- }
-
- function recover_files_ilm () {
- global $DB, $USER;
- $fs = get_file_storage();
- $courseid = optional_param('id', NULL, PARAM_INT);
- $dirid = $this->get_dir_ilm('dirid');
- $ilmid = optional_param('ilmid', NULL, PARAM_INT);
- $contextfile = context_course::instance($this->id);
- $iassigns = $DB->get_records("iassign", array("course" => $courseid));
- foreach ($iassigns as $iassign) {
- $iassign_statement_activity_list = $DB->get_records("iassign_statement", array("iassignid" => $iassign->id));
- foreach ($iassign_statement_activity_list as $iassign_statement_activity_item) {
- $cm = get_coursemodule_from_instance("iassign", $iassign->id, $courseid);
- $context = context_module::instance($cm->id);
-
- $files = $fs->get_area_files($context->id, 'mod_iassign', 'exercise', $iassign_statement_activity_item->id);
- if ($files) {
- foreach ($files as $value) {
- $extension = explode(".", $value->get_filename());
- if (!$value->is_directory()) {
- $fileinfo = array('contextid' => $contextfile->id,
- 'component' => 'mod_iassign',
- 'filearea' => 'activity',
- 'itemid' => 0,
- 'filepath' => $this->get_dir_ilm('dir_base'),
- 'userid' => $USER->id,
- 'author' => $USER->firstname . ' ' . $USER->lastname,
- 'license' => 'allrightsreserved',
- 'timecreated' => time(),
- 'filename' => $iassign_statement_activity_item->name . "." . $extension[1]);
- $newfile = $fs->create_file_from_string($fileinfo, $value->get_content());
- }
- }
- }
- }
- }
- redirect(new moodle_url($this->url . '&dirid=' . $dirid . '&ilmid=' . $ilmid));
- die();
- }
-
-
-
-
-
- function get_files_in_context (&$filesfrommine, &$filesfromothers, $contextid, $extension, $userid) {
-
-
- $fs = get_file_storage();
- $dir_base = $this->get_dir_ilm('dir_base');
- $files_course = $fs->get_directory_files($contextid, 'mod_iassign', 'activity', 0, $dir_base, false, true, 'filename');
- $countf = 0;
- $array_files_id = array();
- foreach ($files_course as $item_fc) {
-
-
-
- $fileuserid = $item_fc->get_userid();
-
- $itemid = $item_fc->get_id();
- if (!in_array($itemid, $array_files_id)) {
-
- if ($fileuserid == $userid)
- $filesfrommine[] = $item_fc;
- else
- $filesfromothers[] = $item_fc;
- $array_files_id[] = $itemid;
- $countf++;
- }
- }
-
- return $countf;
- }
-
-
- function get_all_ilm_files_by_fileid ($fileid) {
- global $DB, $USER;
-
-
- $str_query = "SELECT * FROM {iassign_statement} WHERE file = " . $fileid . " ORDER BY author_name, timecreated DESC";
- $array_iassign_ilm = $DB->get_records_sql($str_query);
- return $array_iassign_ilm;
- }
-
-
-
- function get_string_JavaScript_functions ($dirid, $ilmid, $files_array, $dirs_array) {
- global $CFG;
- $error_files_exists = get_string('error_file_exists', 'iassign');
- $error_dir_exists = get_string('error_dir_exists', 'iassign');
- $code_javascript_ilm = "
- <script type='text/javascript'>
- //<![CDATA[
- function preview_ilm (fileid, ilmid) { //JavaScript function
- var param = '" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=preview&fileid='+fileid+'&ilmid='+ilmid;
- var preview_ilm=window.open(param,'','menubar=0,location=0,scrollbars,status,resizable,width=900 height=700');
- }
- function update_ilm (ilmid, fileid) { //JavaScript function
- window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=update&ilmid='+ilmid+'&dirid=" . $dirid . "&fileid='+fileid;
- }
- function delete_ilm (ilmid, fileid) { //JavaScript function
- var msgAnswer;
- msgAnswer = confirm('" . get_string('delete_file', 'iassign') . "');
- if (msgAnswer) {
- window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=delete&ilmid='+ilmid+'&dirid=" . $dirid . "&fileid='+fileid;
- }
- }
- function delete_selected_ilm () { //JavaScript function
- var msgAnswer;
- var param = getCheckbox();
- if (param.join() != '') {
- msgAnswer = confirm('" . get_string('delete_files', 'iassign') . "');
- if (msgAnswer)
- window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=selected_delete&dirid=" . $dirid . "&files_id='+param.join();
- }
- else
- alert('" . get_string('er_file_not_selected_to_delete', 'iassign') . "');
- }
- function add_ilm_iassign (ilmid, filename, fileid) { //JavaScript function
- window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=addilm&ilmid='+ilmid+'&fileid='+fileid+'&filename='+filename;
- }
- function duplicate_ilm (ilmid, filename, fileid) { //JavaScript function
- var filenamecopy;
- var i;
- var files = new Array(" . $files_array . ");
- do {
- filenamecopy = prompt ('" . get_string('duplicate_file', 'iassign') . "',filename);
- } while (filenamecopy == '');
- if (filenamecopy == null)
- return false;\n
- else {
- for (i=0;i<files.length;i++) {
- if (files[i]==filenamecopy) {
- alert('" . $error_files_exists . "');
- return false;\n
- }
- }\n" .
-
- "
- window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?" .
- "from=" . $this->from . "&id=" . $this->id . "&action=duplicate&ilmid=' + ilmid + '&dirid=" . $dirid . "&fileid=' + fileid + '&filename=' + filenamecopy;
- } // else
- }
- function rename_ilm (ilmid, filename, fileid) { //JavaScript function
- var filenamecopy;
- var i;
- var files = new Array($files_array);
- do {
- filenamecopy = prompt('" . get_string('rename_file', 'iassign') . "',filename);
- } while (filenamecopy == '');
- if (filenamecopy == null)
- return false;
- else {
- for (i=0;i<files.length;i++) {
- if (files[i]==filenamecopy) {
- alert('" . $error_files_exists . "');
- return false;
- }
- }
- 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;
- }
- }
- function export_files_ilm () { //JavaScript function
- var param = getCheckbox();
- if (param.join() != '')
- window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=export&dirid=" . $dirid . "&files_id='+param.join();
- else
- alert('" . get_string('er_file_not_selected_to_export', 'iassign') . "');
- }
- function select_all_ilm () { //JavaScript function
- var checkBoxes = document.getElementsByTagName('input');
- var selectAll = document.getElementById('select_all');
- for (var counter=0; counter < checkBoxes.length; counter++) {
- if (checkBoxes[counter].type.toUpperCase()=='CHECKBOX' && checkBoxes[counter].name == 'selected_file')
- checkBoxes[counter].checked = selectAll.checked;
- }
- }
- function getCheckbox () { //JavaScript function
- var checkBoxes = document.getElementsByTagName('input');
- var param = new Array();
- for (var counter=0; counter < checkBoxes.length; counter++) {
- if (checkBoxes[counter].type.toUpperCase()=='CHECKBOX' && checkBoxes[counter].checked == true && checkBoxes[counter].name == 'selected_file')
- param.push(checkBoxes[counter].value);
- }
- return param;
- }
- function new_dir_ilm () { //JavaScript function
- var dirname = '';
- var i;
- var dirs = new Array(" . $dirs_array . ");
- do {
- var dirname = prompt ('" . get_string('question_new_dir', 'iassign') . "', '');
- } while (dirname == '');
- if (dirname == null)
- return false;\n
- else {
- for (i=0;i<dirs.length;i++) {
- if (dirs[i]==dirname) {
- alert('" . $error_dir_exists . "');
- return false;\n
- }
- }
- window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=new_dir&ilmid=" . $ilmid . "&dirid=" . $dirid . "&dirname='+dirname;
- }
- }
- function delete_dir_ilm (ilmid, dirid) { //JavaScript function
- var msgAnswer;
- msgAnswer = confirm('" . get_string('question_delete_dir', 'iassign') . "');
- if (msgAnswer) {
- window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=delete_dir&ilmid='+ilmid+'&dirid='+dirid;
- }
- }
- function rename_dir_ilm (ilmid, dirname, dirid) { //JavaScript function
- var dirnamecopy;
- var i;
- var dirs = new Array($dirs_array);
- do {
- dirnamecopy = prompt ('" . get_string('question_rename_dir', 'iassign') . "',dirname);
- } while (dirnamecopy == '');
- if (dirnamecopy == null)
- return false;\n
- else {
- for (i=0;i<dirs.length;i++) {
- if (dirs[i]==dirnamecopy) {
- alert('" . $error_dir_exists . "');
- return false;\n
- }
- }
- window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=rename_dir&ilmid='+ilmid+'&dirid='+dirid+'&dirname='+dirnamecopy;
- }
- }
- function move_selected_ilm (ilmid) { //JavaScript function
- var param = getCheckbox();
- if (param.join() != '')
- 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();
- else
- alert('" . get_string('er_file_not_selected_to_move', 'iassign') . "');
- }
- function recover_files_ilm () { //JavaScript function
- var msgAnswer;
- msgAnswer = confirm('" . get_string('question_recover_files', 'iassign') . "');
- if (msgAnswer) {
- window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=recover&ilmid=" . $ilmid . "&dirid=" . $dirid . "';
- }
- }
- window.onload = function() { //JavaScript function
- var xPosition = 0;
- var yPosition = 0;
- element=document.getElementById('new_file');
- while(element) {
- xPosition += (element.offsetLeft - element.scrollLeft + element.clientLeft);
- yPosition += (element.offsetTop - element.scrollTop + element.clientTop);
- element = element.offsetParent;
- }
- document.getElementById('new_file').style.top = '' + (yPosition - 400) + 'px';
- document.getElementById('new_file').style.right = '' + 0 + 'px';
- location.hash = '#new_file';
- };
- //]]>
- </script>\n";
- return $code_javascript_ilm;
- }
-
-
- function view_files_ilm ($iassign_ilm_class, $extension) {
- global $CFG, $DB, $USER, $OUTPUT;
- $fs = get_file_storage();
- $context = context_course::instance($this->id);
- $ilmid = optional_param('ilmid', NULL, PARAM_INT);
- $dirid = $this->get_dir_ilm('dirid');
- $dir_base = $this->get_dir_ilm('dir_base');
- $files_course = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $dir_base, false, true, 'filename');
-
-
- $files_array = '';
- foreach ($files_course as $value) {
- if (!$value->is_directory())
- $files_array .= "'" . $value->get_filename() . "',";
- }
- $files_array .= "''";
- $error_files_exists = get_string('error_file_exists', 'iassign');
- $dirs_array = '';
- foreach ($files_course as $value) {
- if ($value->is_directory()) {
- $pathname = explode("/", substr($value->get_filepath(), 0, strlen($value->get_filepath()) - 1));
- $dirs_array .= "'" . $pathname[count($pathname) - 1] . "',";
- }
- }
- $dirs_array .= "''";
- $error_dir_exists = get_string('error_dir_exists', 'iassign');
-
- $code_javascript_ilm = "
- <script type='text/javascript'>
- //<![CDATA[
- function preview_ilm (fileid, ilmid) {
- var param = '" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=preview&fileid='+fileid+'&ilmid='+ilmid;
- var preview_ilm=window.open(param,'','menubar=0,location=0,scrollbars,status,resizable,width=900 height=700');
- }
- function update_ilm (ilmid, fileid) {
- window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=update&ilmid='+ilmid+'&dirid=" . $dirid . "&fileid='+fileid;
- }
- function delete_ilm (ilmid, fileid) {
- var msgAnswer;
- msgAnswer = confirm('" . get_string('delete_file', 'iassign') . "');
- if (msgAnswer) {
- window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=delete&ilmid='+ilmid+'&dirid=" . $dirid . "&fileid='+fileid;
- }
- }
- function delete_selected_ilm () {
- var msgAnswer;
- var param = getCheckbox();
- if (param.join() != '') {
- msgAnswer = confirm('" . get_string('delete_files', 'iassign') . "');
- if (msgAnswer)
- window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=selected_delete&dirid=" . $dirid . "&files_id='+param.join();
- }
- else
- alert('" . get_string('er_file_not_selected_to_delete', 'iassign') . "');
- }
- function add_ilm_iassign (ilmid, filename, fileid) {
- window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=addilm&ilmid='+ilmid+'&fileid='+fileid+'&filename='+filename;
- }
- function duplicate_ilm (ilmid, filename, fileid) {
- var filenamecopy;
- var i;
- var files = new Array($files_array);
- do {
- filenamecopy = prompt ('" . get_string('duplicate_file', 'iassign') . "',filename);
- } while (filenamecopy == '');
- if (filenamecopy == null)
- return false;\n
- else {
- for (i=0;i<files.length;i++) {
- if (files[i]==filenamecopy) {
- alert('$error_files_exists');
- return false;\n
- }
- }\n" .
-
- "
- window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?" .
- "from=" . $this->from . "&id=" . $this->id . "&action=duplicate&ilmid=' + ilmid + '&dirid=" . $dirid . "&fileid=' + fileid + '&filename=' + filenamecopy;
- } // else
- }
- function rename_ilm (ilmid, filename, fileid) {
- var filenamecopy;
- var i;
- var files = new Array($files_array);
- do {
- filenamecopy = prompt('" . get_string('rename_file', 'iassign') . "',filename);
- } while (filenamecopy == '');
- if (filenamecopy == null)
- return false;
- else {
- for (i=0;i<files.length;i++) {
- if (files[i]==filenamecopy) {
- alert('$error_files_exists');
- return false;
- }
- }
- 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;
- }
- }
- function export_files_ilm () {
- var param = getCheckbox();
- if (param.join() != '')
- window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=export&dirid=" . $dirid . "&files_id='+param.join();
- else
- alert('" . get_string('er_file_not_selected_to_export', 'iassign') . "');
- }
- function select_all_ilm () {
- var checkBoxes = document.getElementsByTagName('input');
- var selectAll = document.getElementById('select_all');
- for (var counter=0; counter < checkBoxes.length; counter++) {
- if (checkBoxes[counter].type.toUpperCase()=='CHECKBOX' && checkBoxes[counter].name == 'selected_file')
- checkBoxes[counter].checked = selectAll.checked;
- }
- }
- function getCheckbox () {
- var checkBoxes = document.getElementsByTagName('input');
- var param = new Array();
- for (var counter=0; counter < checkBoxes.length; counter++) {
- if (checkBoxes[counter].type.toUpperCase()=='CHECKBOX' && checkBoxes[counter].checked == true && checkBoxes[counter].name == 'selected_file')
- param.push(checkBoxes[counter].value);
- }
- return param;
- }
- function new_dir_ilm () {
- var dirname = '';
- var i;
- var dirs = new Array($dirs_array);
- do {
- var dirname = prompt ('" . get_string('question_new_dir', 'iassign') . "', '');
- } while (dirname == '');
- if (dirname == null)
- return false;\n
- else {
- for (i=0;i<dirs.length;i++) {
- if (dirs[i]==dirname) {
- alert('$error_dir_exists');
- return false;\n
- }
- }
- window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=new_dir&ilmid=" . $ilmid . "&dirid=" . $dirid . "&dirname='+dirname;
- }
- }
- function delete_dir_ilm (ilmid, dirid) {
- var msgAnswer;
- msgAnswer = confirm('" . get_string('question_delete_dir', 'iassign') . "');
- if (msgAnswer) {
- window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=delete_dir&ilmid='+ilmid+'&dirid='+dirid;
- }
- }
- function rename_dir_ilm (ilmid, dirname, dirid) {
- var dirnamecopy;
- var i;
- var dirs = new Array($dirs_array);
- do {
- dirnamecopy = prompt ('" . get_string('question_rename_dir', 'iassign') . "',dirname);
- } while (dirnamecopy == '');
- if (dirnamecopy == null)
- return false;\n
- else {
- for (i=0;i<dirs.length;i++) {
- if (dirs[i]==dirnamecopy) {
- alert('$error_dir_exists');
- return false;\n
- }
- }
- window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=rename_dir&ilmid='+ilmid+'&dirid='+dirid+'&dirname='+dirnamecopy;
- }
- }
- function move_selected_ilm (ilmid) {
- var param = getCheckbox();
- if (param.join() != '')
- 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();
- else
- alert('" . get_string('er_file_not_selected_to_move', 'iassign') . "');
- }
- function recover_files_ilm () {
- var msgAnswer;
- msgAnswer = confirm('" . get_string('question_recover_files', 'iassign') . "');
- if (msgAnswer) {
- window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=recover&ilmid=" . $ilmid . "&dirid=" . $dirid . "';
- }
- }
- window.onload = function() {
- var xPosition = 0;
- var yPosition = 0;
- element=document.getElementById('new_file');
- while(element) {
- xPosition += (element.offsetLeft - element.scrollLeft + element.clientLeft);
- yPosition += (element.offsetTop - element.scrollTop + element.clientTop);
- element = element.offsetParent;
- }
- document.getElementById('new_file').style.top = '' + (yPosition - 400) + 'px';
- document.getElementById('new_file').style.right = '' + 0 + 'px';
- location.hash = '#new_file';
- };
- //]]>
- </script>\n";
- $output = "";
- $select_all = "";
- $count_files = 0;
- $extensions_allow = array();
- $iassign_ilm = $DB->get_records('iassign_ilm', array("enable" => 1));
- foreach ($iassign_ilm as $item_iassign_ilm)
- $extensions_allow = array_merge($extensions_allow, explode(",", $item_iassign_ilm->extension));
- foreach ($files_course as $value) {
- $filename = $value->get_filename();
- $filepath = $value->get_filepath();
- $pathname = explode("/", substr($filepath, 0, strlen($filepath) - 1));
- $pathname = $pathname[count($pathname) - 1];
- $fileid = $value->get_id();
- $tmp = explode(".", $filename);
- if (count($tmp)>1)
- $filetype = $tmp[1];
- else
- $filetype = '';
- $author = $value->get_author();
- $timemodified = date("d/m/Y H:i:s", $value->get_timemodified());
- $timecreated = date("d/m/Y H:i:s", $value->get_timecreated());
- $extensions = explode(",", $extension);
- if (in_array(strtolower($filetype), $extensions) || $value->is_directory() || $this->from == 'block' || $this->from == 'tinymce' || $this->from == 'atto') {
- $count_files++;
-
- $list_filein_use = "";
- $iassign_statement_activity_list = $DB->get_records("iassign_statement", array("file" => $fileid));
- if ($iassign_statement_activity_list) {
- foreach ($iassign_statement_activity_list as $iassign_statement_activity_item) {
- $list_filein_use .= $iassign_statement_activity_item->name . "</br>\n";
- }
- }
- $iassign_ilm = $DB->get_record("iassign_ilm", array('extension' => $filetype, 'id' => $ilmid, 'enable' => '1'));
- if (!$iassign_ilm) {
- $iassign_ilm = new stdClass();
- $iassign_ilm->id = $ilmid;
- }
-
- $url = $CFG->wwwroot . "/pluginfile.php/" . $value->get_contextid() . "/mod_iassign/activity";
- $fileurl = $url . '/' . $value->get_itemid() . $filepath . $filename;
- $dirurl = new moodle_url($this->url) . '&ilmid=' . $iassign_ilm->id . '&dirid=' . $fileid;
- $straux = $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&fileid=" . $fileid . "&";
- $link_add_ilm_iassign = " <a href='" . $straux . "action=addilm&filename=$filename '>" . iassign_icons::insert('add_ilm_iassign') . "</a>\n";
- $link_add_ilm_tinymce = " <a href='" . $straux . "action=tinymceilm'>" . iassign_icons::insert('add_ilm_iassign') . "</a>\n";
- $link_add_ilm_atto = " <a href='" . $straux . "action=attoilm'>" . iassign_icons::insert('add_ilm_iassign') . "</a>\n";
- $check_select = "";
- $link_rename = "";
- $link_delete = "";
- $link_duplicate = " <a href='#' onclick='duplicate_ilm(\"$iassign_ilm->id\", \"$filename\"," . $fileid . ");'>" . iassign_icons::insert('duplicate_iassign') . "</a>\n";
- $link_edit = " " . iassign_icons::insert('no_edit_iassign');
- $link_filter = " <a href='#' onclick='preview_ilm(" . $fileid . "," . $ilmid . ");'>" . iassign_icons::insert('preview_iassign') . "</a>\n";
- $link_duplicate = " <a href='#' onclick='duplicate_ilm(\"$iassign_ilm->id\", \"$filename\"," . $fileid . ");'>" .
- iassign_icons::insert('duplicate_iassign') . "</a>\n";
- $link_edit = " " . iassign_icons::insert('no_edit_iassign');
- $link_filter = " <a href='#' onclick='preview_ilm(" . $fileid . "," . $ilmid . ");'>" . iassign_icons::insert('preview_iassign') . "</a>\n";
- if ($value->get_userid() == $USER->id) {
- if ($iassign_statement_activity_list) {
- $check_select = "";
- $link_edit = iassign_icons::insert('edit_iassign_disable');
- $link_delete = " " . iassign_icons::insert('delete_iassign_disable');
- $link_rename = "";
- } else {
- $check_select = "<input name='selected_file' type='checkbox' value='$fileid'/>\n";
- $link_edit = " <a href='#' onclick='update_ilm(\"$iassign_ilm->id\", $fileid)'>" . iassign_icons::insert('edit_iassign') . "</a>\n";
- $link_delete = " <a href='#' onclick='delete_ilm(\"$iassign_ilm->id\", $fileid);'>" . iassign_icons::insert('delete_iassign') . "</a>\n";
- $link_rename = " <a href='#' onclick='rename_ilm(\"$iassign_ilm->id\", \"$filename\"," . $fileid . ");'>" . iassign_icons::insert('rename_iassign') . "</a>\n";
- }
- }
- if (!in_array($filetype, $extensions_allow)) {
- $link_edit = "";
- $link_add_ilm_iassign = "";
- $link_add_ilm_tinymce = "";
- $link_add_ilm_atto = "";
- $link_filter = "";
- }
- if ($value->is_directory()) {
- $link_delete = " <a href='#' onclick='delete_dir_ilm(\"$iassign_ilm->id\", $fileid);'>" . iassign_icons::insert('delete_dir') . "</a>\n";
- $link_rename = " <a href='#' onclick='rename_dir_ilm(\"$iassign_ilm->id\", \"" . $pathname . "\"," . $fileid . ");'>" . iassign_icons::insert('rename_dir') . "</a>\n";
- $output .= "<tr><td>$check_select$link_rename$link_delete</td>
- <td><a href='$dirurl' title='" . get_string('dir', 'iassign') . $pathname . "'>" . iassign_icons::insert('dir') . ' ' . $pathname . "</a></td>
- <td><center>$author</center></td>
- <td><center>$timecreated</center></td>
- <td><center>$timemodified</center></td></tr>\n";
- }
- else if ($this->from == 'iassign') {
- $new_id = "";
- $new_class = "";
- if (isset($_SESSION['file_name']) && $filename == $_SESSION['file_name']) {
- $new_class = "<div id='new_file' style='position: absolute;'></div>"; unset($_SESSION['file_name']);
- $new_id = "id='id_new_blink' style='background-color: hsl(244,61%,90%);'";
- }
- $output .= "<tr $new_id><td>$new_class $check_select$link_rename$link_delete$link_duplicate$link_edit$link_filter$link_add_ilm_iassign</td>
- <td><a href='$fileurl' title='" . get_string('download_file', 'iassign') . "$filename'>$filename</a></td>
- <td><center>$author</center></td>
- <td><center>$timecreated</center></td>
- <td><center>$timemodified</center></td></tr>\n";
- }
- else if ($this->from == 'block') {
- $output .= "<tr><td>$check_select$link_rename$link_delete$link_duplicate$link_edit$link_filter</td>
- <td><a href='$fileurl' title='" . get_string('download_file', 'iassign') . "$filename'>$filename</a></td>
- <td><center>$author</center></td>
- <td><center>$timecreated</center></td>
- <td><center>$timemodified</center></td></tr>\n";
- }
- else if ($this->from == 'tinymce') {
- $output .= "<tr><td>$check_select$link_rename$link_delete$link_duplicate$link_edit$link_filter$link_add_ilm_tinymce</td>
- <td><a href='$fileurl' title='" . get_string('download_file', 'iassign') . "$filename'>$filename</a></td>
- <td><center>$author</center></td>
- <td><center>$timecreated</center></td>
- <td><center>$timemodified</center></td></tr>\n";
- }
- else if ($this->from == 'atto') {
- $output .= "<tr><td>$check_select$link_rename$link_delete$link_duplicate$link_edit$link_filter$link_add_ilm_atto</td>
- <td><a href='$fileurl' title='" . get_string('download_file', 'iassign') . "$filename'>$filename</a></td>
- <td><center>$author</center></td>
- <td><center>$timecreated</center></td>
- <td><center>$timemodified</center></td></tr>\n";
- }
- }
- }
- $basename = explode("/", substr($dir_base, 0, strlen($dir_base) - 1));
- $dir_base = "";
- $header = "";
-
-
- foreach ($basename as $value) {
- $dir_base .= $value . "/";
- $dir_id = $fs->get_file($context->id, 'mod_iassign', 'activity', 0, $dir_base, '.');
- if ($dir_id) {
- if ($value == "") {
- $fileurl = new moodle_url($this->url) . '&dirid=' . $dir_id->get_id() . '&ilmid=' . $ilmid;
- $header .= " <a href='$fileurl' title='" . get_string('dir', 'iassign') . "Home'>Home</a>\n";
- } else {
- $fileurl = new moodle_url($this->url) . '&dirid=' . $dir_id->get_id() . '&ilmid=' . $ilmid;
- $header .= " " . $OUTPUT->rarrow() . " <a href='$fileurl' title='" . get_string('dir', 'iassign') . "$dir_base'>$value</a>\n";
- }
- }
- }
- $html = $OUTPUT->heading(iassign_icons::insert('open_dir') . $header, 2, 'dirtitle', 'iassign');
- $select_all = "<input id='select_all' type='checkbox' onclick='select_all_ilm();'/>\n";
- $html .= "
- <table id='outlinetable' class='generaltable boxaligncenter' cellpadding='5' width='100%'>
- <tr><th class='header c1' width='20%'>$select_all " . get_string('functions', 'iassign') . "</th>
- <th class='header c1' width='*'>" . get_string('file', 'iassign') . "</th>
- <th class='header c1' width='10%'>" . get_string('author', 'iassign') . "</th>
- <th class='header c1' width='10%'>" . get_string('file_created', 'iassign') . "</th>
- <th class='header c1' width='10%'>" . get_string('file_modified', 'iassign') . "</th>\n " . $output . "
- </table>\n";
- $html .= "<form id='form_buttons' method='post' enctype='multipart/form-data'>\n";
- $html .= "<table width='100%'><tr>\n";
- $html .= "<td width='80%'><input type='button' value='" . get_string('new_dir', 'iassign') . "' onClick='new_dir_ilm();'>\n";
- if ($count_files != 0) {
- $html .= " | <input type='button' value='" . get_string('file_ilm_move', 'iassign') . "' onClick='move_selected_ilm(\"$iassign_ilm->id\");'/> | \n";
- $html .= "<input type='button' value='" . get_string('file_ilm_delete', 'iassign') . "' onClick='delete_selected_ilm(\"$iassign_ilm->id\");'> | \n";
- $html .= "<input type='button' value='" . get_string('file_ilm_export', 'iassign') . "' onClick='export_files_ilm();'>\n";
- }
- $html .= "</td><td width='100%' align='right'><input type='button' value='" . get_string('file_ilm_recover', 'iassign') . "' onClick='recover_files_ilm();'>\n";
- $html .= $OUTPUT->help_icon('file_ilm_recover', 'iassign') . "</td></tr></table>\n";
- $html .= "</form>\n";
- print $code_javascript_ilm;
- print $html;
- }
- }
- class iassign_icons {
- static function insert ($icon) {
- global $CFG;
- $string = '<img src="' . $CFG->wwwroot . '/mod/iassign/icon/' . $icon . '.gif" title="' . get_string($icon, 'iassign') . '" alt="' . get_string($icon, 'iassign') . '"/>';
- return $string;
- }
- }
- class iassign_utils {
-
-
-
- static function filename_extension ($filename) {
- if ($filename == null || $filename == '') {
- return null;
- }
- $itens = explode('.', $filename);
- $num = count($itens);
- if ($num < 2) {
- return null;
- }
- return $itens[$num - 1];
- }
-
-
-
-
- static function register_temporary_file ($full_path_zip_filename, $vet_student_filename, $vet_student_content) {
-
- $zip = new zip_archive();
- $res = $zip->open($full_path_zip_filename);
- $total_vet = count($vet_student_filename);
- for ($ii=0; $ii<$total_vet; $ii++) {
-
- $zip->add_file_from_string($vet_student_filename[$ii], $vet_student_content[$ii]);
- }
- $ret = $zip->close();
- iassign_utils::download_file($full_path_zip_filename);
- $filenameZip = $zip->filename;
- return array($ret, $zip);
- }
- static function download_file ($zip_filename) {
- header("Pragma: public");
- header("Expires: 0");
- header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
- header("Cache-Control: private", false);
- header("Content-Type: application/zip");
- header("Content-Disposition: attachment; filename=\"" . basename($zip_filename) . "\";");
- header("Content-Transfer-Encoding: binary");
- header("Content-Length: " . @filesize($zip_filename));
- set_time_limit(0);
- @readfile("$zip_filename") || die("File not found.");
- unlink($zip_filename);
- }
-
-
-
-
- static function format_filename ($text) {
- if ($text != '.') {
-
-
- if (is_object($text))
- $text = json_decode($text)->{current_language()};
-
- $array1 = array("(", ")", ",", "/", "\\", "!", "@", "#", "$", "&", "*", "+", "!", "?", ".", " ", ":",
- "á", "à", "â", "ã", "ä", "é", "è", "ê", "ë", "ẽ", "í", "ì", "î", "ï", "ó", "ò", "ô", "õ", "ö", "ú", "ù", "û", "ü",
- "ç", "Á", "À", "Â", "Ã", "Ä", "É", "È", "Ê", "Ë", "Í", "Ì", "Î", "Ï", "Ó", "Ò", "Ô", "Õ", "Ö", "Ú", "Ù", "Û", "Ü", "Ç");
- $array2 = array("", "", "_", "_", "_", "", "", "", "", "", "", "", "", "", "_", "_", "-",
- "a", "a", "a", "a", "a", "e", "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");
-
-
- $index_lastposition = strrpos($text, ".");
- $text2 = substr($text, 0, $index_lastposition);
- $ext = substr($text, $index_lastposition);
- $text = str_replace(".", "", $text2) . $ext;
- $text = str_replace($array1, $array2, $text);
-
-
-
- }
- return $text;
- }
-
-
-
-
- static function filter_filename_extension ($filename, $ext) {
- if ($filename != '.') {
- $arrFrom = array("=","~","`","!","@","$","%","^","&","*","(",")");
- $arrTo = array("_","","","","","","","","","","","","");
- $filename = str_replace($arrFrom, $arrTo, $filename);
-
- $filenameF = preg_replace('/[^\x20-\x7E]/','', $filename);
- $index_lastposition = strrpos($filenameF, ".");
- if (!isset($index_lastposition) || $index_lastposition=="" || $index_lastposition<0)
- $index_lastposition = strlen($filenameF);
- $text = substr($filenameF, 0, $index_lastposition);
- $text = str_replace(".", "_", $text);
- $existext = substr($filenameF, $index_lastposition);
- $filenameF = $text . "." . $ext;
- }
- else
- $filenameF = 'file_without_name.' . $ext;
- return $filenameF;
- }
-
-
-
-
- static function format_pathname ($text, $is_lowercase = true) {
- $array1 = array("á", "à", "â", "ã", "ä", "é", "è", "ê", "ë", "í", "ì", "î", "ï", "ó", "ò", "ô", "õ", "ö", "ú", "ù", "û", "ü", "ç", "Á", "À", "Â", "Ã", "Ä", "É", "È", "Ê", "Ë", "Í", "Ì", "Î", "Ï", "Ó", "Ò", "Ô", "Õ", "Ö", "Ú", "Ù", "Û", "Ü", "Ç", "@", " ", "!", "?", ".");
- $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", "-", "_", "", "", "");
- $text = str_replace($array1, $array2, $text);
- if ($is_lowercase)
- $text = strtolower($text);
- return $text;
- }
-
-
-
-
- static function filename_from_iLM_name ($ilm_name, $is_lowercase = true) {
- $array1 = array("á", "à", "â", "ã", "ä", "é", "è", "ê", "ë", "í", "ì", "î", "ï", "ó", "ò", "ô", "õ", "ö", "ú", "ù", "û", "ü", "ç", "Á", "À", "Â", "Ã", "Ä", "É", "È", "Ê", "Ë", "Í", "Ì", "Î", "Ï", "Ó", "Ò", "Ô", "Õ", "Ö", "Ú", "Ù", "Û", "Ü", "Ç", "@", " ", "!", "?", ".");
- $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", "-", "_", "", "", "");
- $index_firstposition_blank = strpos($ilm_name, " ");
- if ($index_firstposition_blank) {
- $ilm_name = substr($ilm_name, 0, $index_firstposition_blank);
- }
- $index_firstposition_dots = strpos($ilm_name, ":");
- if ($index_firstposition_dots) {
- $ilm_name = substr($ilm_name, 0, $index_firstposition_dots);
- }
- $namefiltered = str_replace($array1, $array2, $ilm_name);
- if ($is_lowercase)
- $namefiltered = strtolower($namefiltered);
- return $namefiltered;
- }
-
-
-
- static function version_filename ($filename) {
- $array_filename = explode('.', $filename);
- if (count($array_filename) > 1)
- $filename = $array_filename[0] . '-' . date("Ymd-His") . '.' . $array_filename[1];
- else
- $filename = $array_filename[0] . '-' . date("Ymd-His");
- return $filename;
- }
-
- static function remove_code_message ($string) {
- $array = explode("<ia_uc>", $string);
- return $array[0];
- }
- }
- class iassign_language {
-
-
-
-
- static function get_description_lang ($lang, $descriptions) {
- $description_lang = "";
- $description = json_decode($descriptions);
- if ($description == null) {
- $description_lang = $descriptions;
- }
- else {
- if (isset($description->{$lang}))
- $description_lang = $description->{$lang};
- else
- if (isset($description->en))
- $description_lang = $description->en;
- else
- $description_lang = "en";
- }
- return $description_lang;
- }
-
-
-
- static function get_all_lang ($descriptions) {
- $langs = "";
- $description = json_decode($descriptions);
- if ($description) {
- foreach ($description as $key => $value) {
- $langs .= $key . " ; ";
- }
- $langs = substr($langs, 0, strlen($langs) - 3);
- }
- return $langs;
- }
-
-
-
- static function json_to_xml ($json) {
- $xml = "";
- $json = json_decode($json);
- foreach ($json as $key => $value) {
- $xml .= "\n <" . $key . ">" . $value . "</" . $key . ">";
- }
- return $xml;
- }
- }
- class iassign_log {
-
-
-
-
-
- static function add_log ($action, $information = "", $cmid = 0, $ilmid = 0) {
- global $COURSE, $CFG, $USER, $DB;
- $newentry = new stdClass();
- $newentry->time = time();
- $newentry->userid = $USER->id;
- $newentry->ip = $_SERVER['REMOTE_ADDR'];
- $newentry->course = $COURSE->id;
- $newentry->cmid = $cmid;
- $newentry->ilmid = $ilmid;
- $newentry->action = $action;
- $newentry->info = $information;
- $newentry->language = current_language();
- $newentry->user_agent = $_SERVER['HTTP_USER_AGENT'];
- if (ini_get("browscap") && function_exists('get_browse')) {
- $browser = get_browse(null, true);
- $newentry->javascript = $browser['javascript'];
- $newentry->java = $browser['javaapplets'];
- }
- if (!$newentry->id = $DB->insert_record("iassign_log", $newentry))
- print_error('error_add_log', 'iassign');
- }
- }
|