12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726 |
- <?php
- class learnpath {
- public $attempt = 0;
- public $cc;
- public $current;
- public $current_score;
- public $current_time_start;
- public $current_time_stop;
- public $default_status = 'not attempted';
- public $encoding = 'UTF-8';
- public $error = '';
- public $extra_information = '';
- public $force_commit = false;
- public $index;
- public $items = array();
- public $last;
- public $last_item_seen = 0;
- public $license;
- public $lp_id;
- public $lp_view_id;
- public $log_file;
- public $maker;
- public $message = '';
- public $mode = 'embedded';
- public $name;
- public $ordered_items = array();
- public $path = '';
- public $theme;
- public $preview_image;
-
- public $prevent_reinit = 1;
-
- public $progress_bar_mode = '%';
-
- public $progress_db = '0';
- public $proximity;
- public $refs_list = array ();
-
-
- public $type;
-
- public $user_id;
- public $update_queue = array();
- public $scorm_debug = 0;
- public $arrMenu = array();
- public $debug = 0;
- public $lp_session_id =0;
- public $lp_view_session_id =0;
- public $prerequisite = 0;
- public $use_max_score = 1;
- public $created_on = '';
- public $modified_on = '';
- public $publicated_on = '';
- public $expired_on = '';
-
- public function __construct($course, $lp_id, $user_id) {
- $this->encoding = api_get_system_encoding();
-
-
- $course_db = '';
- if ($this->debug > 0) {error_log('New LP - In learnpath::__construct('.$course.','.$lp_id.','.$user_id.')', 0); }
- if (empty($course)) {
- $this->error = 'Course code is empty';
- return false;
- } else {
- $main_table = Database::get_main_table(TABLE_MAIN_COURSE);
-
- $course = $this->escape_string($course);
- $sql = "SELECT * FROM $main_table WHERE code = '$course'";
- if ($this->debug > 2) { error_log('New LP - learnpath::__construct() '.__LINE__.' - Querying course: '.$sql, 0); }
- $res = Database::query($sql);
- if (Database::num_rows($res) > 0) {
- $this->cc = $course;
- $row_course = Database::fetch_array($res);
- $course_db = $row_course['db_name'];
- } else {
- $this->error = 'Course code does not exist in database ('.$sql.')';
- return false;
- }
- }
-
- if (empty($lp_id)) {
- $this->error = 'Learnpath ID is empty';
- return false;
- } else {
-
- $lp_table = Database::get_course_table(TABLE_LP_MAIN, $course_db);
-
- $lp_id = $this->escape_string($lp_id);
- $sql = "SELECT * FROM $lp_table WHERE id = '$lp_id'";
- if ($this->debug > 2) { error_log('New LP - learnpath::__construct() '.__LINE__.' - Querying lp: '.$sql, 0); }
- $res = Database::query($sql);
- if (Database::num_rows($res) > 0) {
- $this->lp_id = $lp_id;
- $row = Database::fetch_array($res);
- $this->type = $row['lp_type'];
- $this->name = stripslashes($row['name']);
-
- $this->proximity = $row['content_local'];
- $this->theme = $row['theme'];
- $this->maker = $row['content_maker'];
- $this->prevent_reinit = $row['prevent_reinit'];
- $this->license = $row['content_license'];
- $this->scorm_debug = $row['debug'];
- $this->js_lib = $row['js_lib'];
- $this->path = $row['path'];
- $this->preview_image = $row['preview_image'];
- $this->author = $row['author'];
- $this->lp_session_id = $row['session_id'];
- $this->use_max_score = $row['use_max_score'];
- $this->created_on = $row['created_on'];
- $this->modified_on = $row['modified_on'];
- if ($row['publicated_on'] != '0000-00-00 00:00:00') {
- $this->publicated_on = $row['publicated_on'];
- }
- if ($row['expired_on'] != '0000-00-00 00:00:00') {
- $this->expired_on = $row['expired_on'];
- }
- if ($this->type == 2) {
- if ($row['force_commit'] == 1) {
- $this->force_commit = true;
- }
- }
- $this->mode = $row['default_view_mod'];
- } else {
- $this->error = 'Learnpath ID does not exist in database ('.$sql.')';
- return false;
- }
- }
-
- if (empty($user_id)) {
- $this->error = 'User ID is empty';
- return false;
- } else {
-
- $main_table = Database::get_main_table(TABLE_MAIN_USER);
-
- $user_id = $this->escape_string($user_id);
- $sql = "SELECT * FROM $main_table WHERE user_id = '$user_id'";
- if ($this->debug > 2) { error_log('New LP - learnpath::__construct() '.__LINE__.' - Querying user: '.$sql, 0); }
- $res = Database::query($sql);
- if (Database::num_rows($res) > 0) {
- $this->user_id = $user_id;
- } else {
- $this->error = 'User ID does not exist in database ('.$sql.')';
- return false;
- }
- }
-
- $session_id = api_get_session_id();
-
- $session = api_get_session_condition($session_id);
-
- $lp_table = Database::get_course_table(TABLE_LP_VIEW, $course_db);
-
- $sql = "SELECT * FROM $lp_table WHERE lp_id = '$lp_id' AND user_id = '$user_id' $session ORDER BY view_count DESC";
- if ($this->debug > 2) { error_log('New LP - learnpath::__construct() ' . __LINE__ . ' - querying lp_view: ' . $sql, 0); }
- $res = Database::query($sql);
- $view_id = 0;
- if (Database :: num_rows($res) > 0) {
- if ($this->debug > 2) {
- error_log('New LP - learnpath::__construct() ' . __LINE__ . ' - Found previous view', 0);
- }
- $row = Database :: fetch_array($res);
- $this->attempt = $row['view_count'];
- $this->lp_view_id = $row['id'];
- $this->last_item_seen = $row['last_item'];
- $this->progress_db = $row['progress'];
- $this->lp_view_session_id = $row['session_id'];
- } else {
- if ($this->debug > 2) {
- error_log('New LP - learnpath::__construct() ' . __LINE__ . ' - NOT Found previous view', 0);
- }
- $this->attempt = 1;
- $sql_ins = "INSERT INTO $lp_table (lp_id,user_id,view_count, session_id) VALUES ($lp_id,$user_id,1,$session_id)";
- $res_ins = Database::query($sql_ins);
- $this->lp_view_id = Database :: insert_id();
- if ($this->debug > 2) {
- error_log('New LP - learnpath::__construct() ' . __LINE__ . ' - inserting new lp_view: ' . $sql_ins, 0);
- }
- }
-
- $lp_item_table = Database::get_course_table(TABLE_LP_ITEM, $course_db);
- $sql = "SELECT * FROM $lp_item_table WHERE lp_id = '".$this->lp_id."' ORDER BY parent_item_id, display_order";
- $res = Database::query($sql);
- while ($row = Database::fetch_array($res)) {
- $oItem = '';
-
- switch ($this->type) {
- case 3:
- $oItem = new aiccItem('db', $row['id'], $course_db);
- if (is_object($oItem)) {
- $my_item_id = $oItem->get_id();
- $oItem->set_lp_view($this->lp_view_id, $course_db);
- $oItem->set_prevent_reinit($this->prevent_reinit);
-
- $this->items[$my_item_id] = $oItem;
- $this->refs_list[$oItem->ref] = $my_item_id;
- if ($this->debug > 2) {
- error_log('New LP - learnpath::__construct() - aicc object with id ' . $my_item_id . ' set in items[]', 0);
- }
- }
- break;
- case 2:
- require_once 'scorm.class.php';
- require_once 'scormItem.class.php';
- $oItem = new scormItem('db', $row['id'], $course_db);
- if (is_object($oItem)) {
- $my_item_id = $oItem->get_id();
- $oItem->set_lp_view($this->lp_view_id, $course_db);
- $oItem->set_prevent_reinit($this->prevent_reinit);
-
- error_log('my_item_id->'.$my_item_id);
- $this->items[$my_item_id] = $oItem;
- $this->refs_list[$oItem->ref] = $my_item_id;
- if ($this->debug > 2) {
- error_log('New LP - object with id ' . $my_item_id . ' set in items[]', 0);
- }
- }
- break;
- case 1:
- default:
- require_once 'learnpathItem.class.php';
- $oItem = new learnpathItem($row['id'], $user_id, $course_db);
- if (is_object($oItem)) {
- $my_item_id = $oItem->get_id();
-
- $oItem->set_prevent_reinit($this->prevent_reinit);
-
- $this->items[$my_item_id] = $oItem;
- $this->refs_list[$my_item_id] = $my_item_id;
- if ($this->debug > 2) {
- error_log('New LP - learnpath::__construct() ' . __LINE__ . ' - object with id ' . $my_item_id . ' set in items[]', 0);
- }
- }
- break;
- }
-
- if ($row['parent_item_id'] == 0 || empty ($this->items[$row['parent_item_id']])) {
- if (is_object($this->items[$row['id']])) {
- $this->items[$row['id']]->set_level(0);
- }
- } else {
- $level = $this->items[$row['parent_item_id']]->get_level() + 1;
- $this->items[$row['id']]->set_level($level);
- if (is_object($this->items[$row['parent_item_id']])) {
-
- $this->items[$row['parent_item_id']]->add_child($row['id']);
- } else {
- if ($this->debug > 2) {
- error_log('New LP - learnpath::__construct() ' . __LINE__ . ' - The parent item (' . $row['parent_item_id'] . ') of item ' . $row['id'] . ' could not be found', 0);
- }
- }
- }
-
- $lp_item_view_table = Database :: get_course_table(TABLE_LP_ITEM_VIEW, $course_db);
-
- $sql = "SELECT * " .
- "FROM $lp_item_view_table " .
- "WHERE lp_view_id = " . $this->lp_view_id . " " .
- "AND lp_item_id = " . $row['id'] . " ORDER BY view_count DESC ";
- if ($this->debug > 2) {
- error_log('New LP - learnpath::__construct() - Selecting item_views: ' . $sql, 0);
- }
-
- $res2 = Database::query($sql);
- if (Database :: num_rows($res2) > 0) {
-
-
-
- $row2 = Database :: fetch_array($res2);
- if ($this->debug > 2) {
- error_log('New LP - learnpath::__construct() - Got item_view: ' . print_r($row2, true), 0);
- }
- if (is_object($this->items[$row['id']])) {
- $this->items[$row['id']]->set_status($row2['status']);
- if (empty ($row2['status'])) {
- $this->items[$row['id']]->set_status($this->default_status);
- }
- }
-
-
- } else {
-
-
-
-
- if (is_object($this->items[$row['id']])) {
- $this->items[$row['id']]->set_status($this->default_status);
- }
-
- $sql_ins = "INSERT INTO $lp_item_view_table " .
- "(lp_item_id, lp_view_id, view_count, status) VALUES " .
- "(" . $row['id'] . "," . $this->lp_view_id . ",1,'not attempted')";
- if ($this->debug > 2) {
- error_log('New LP - learnpath::__construct() ' . __LINE__ . ' - Inserting blank item_view : ' . $sql_ins, 0);
- }
- $res_ins = Database::query($sql_ins);
- }
-
- if (is_object($this->items[$row['id']])) {
- $this->items[$row['id']]->set_lp_view($this->lp_view_id, $course_db);
- }
- }
- $this->ordered_items = $this->get_flat_ordered_items_list($this->get_id(), 0, $course_db);
- $this->max_ordered_items = 0;
- foreach ($this->ordered_items as $index => $dummy) {
- if ($index > $this->max_ordered_items && !empty($dummy)) {
- $this->max_ordered_items = $index;
- }
- }
-
- $this->first();
- if ($this->debug > 2) {
- error_log('New LP - learnpath::__construct() ' . __LINE__ . ' - End of learnpath constructor for learnpath ' . $this->get_id(), 0);
- }
- }
-
- public function add_item($parent, $previous, $type = 'dokeos_chapter', $id, $title, $description, $prerequisites = 0, $max_time_allowed = 0) {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::add_item(' . $parent . ',' . $previous . ',' . $type . ',' . $id . ',' . $title . ')', 0);
- }
- $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
- $parent = intval($parent);
- $previous = intval($previous);
- $type = $this->escape_string($type);
- $id = intval($id);
- $max_time_allowed = $this->escape_string(htmlentities($max_time_allowed));
- if (empty ($max_time_allowed)) {
- $max_time_allowed = 0;
- }
- $title = $this->escape_string($title);
- $description = $this->escape_string($description);
- $sql_count = " SELECT COUNT(id) AS num
- FROM " . $tbl_lp_item . "
- WHERE lp_id = " . $this->get_id() . " AND parent_item_id = " . $parent;
- $res_count = Database::query($sql_count);
- $row = Database :: fetch_array($res_count);
- $num = $row['num'];
- if ($num > 0) {
- if ($previous == 0) {
- $sql = "SELECT id, next_item_id, display_order
- FROM " . $tbl_lp_item . "
- WHERE
- lp_id = " . $this->get_id() . " AND
- parent_item_id = " . $parent . " AND
- previous_item_id = 0 OR previous_item_id=" . $parent;
- $result = Database::query($sql);
- $row = Database :: fetch_array($result);
- $tmp_previous = 0;
- $next = $row['id'];
- $display_order = 0;
- } else {
- $previous = (int) $previous;
- $sql = "
- SELECT
- id,
- previous_item_id,
- next_item_id,
- display_order
- FROM " . $tbl_lp_item . "
- WHERE
- lp_id = " . $this->get_id() . " AND
- id = " . $previous;
- $result = Database::query($sql);
- $row = Database :: fetch_array($result);
- $tmp_previous = $row['id'];
- $next = $row['next_item_id'];
- $display_order = $row['display_order'];
- }
- } else {
- $tmp_previous = 0;
- $next = 0;
- $display_order = 0;
- }
- $new_item_id = -1;
- $id = $this->escape_string($id);
- if ($type == 'quiz') {
- $sql = 'SELECT SUM(ponderation)
- FROM ' . Database :: get_course_table(TABLE_QUIZ_QUESTION) . ' as quiz_question
- INNER JOIN ' . Database :: get_course_table(TABLE_QUIZ_TEST_QUESTION) . ' as quiz_rel_question
- ON quiz_question.id = quiz_rel_question.question_id
- AND quiz_rel_question.exercice_id = ' . $id;
- $rsQuiz = Database::query($sql);
- $max_score = Database :: result($rsQuiz, 0, 0);
- } else {
- $max_score = 100;
- }
- if ($prerequisites != 0) {
- $sql_ins = "
- INSERT INTO " . $tbl_lp_item . " ( ".
- "lp_id, ".
- "item_type, ".
- "ref, ".
- "title, ".
- "description, ".
- "path, ".
- "max_score, ".
- "parent_item_id, ".
- "previous_item_id, ".
- "next_item_id, ".
- "display_order, ".
- "prerequisite, ".
- "max_time_allowed ".
- ") VALUES ( ".
- $this->get_id() . ", ".
- "'" . $type . "', ".
- "'', ".
- "'" . $title . "', ".
- "'" . $description . "', ".
- "'" . $id . "', ".
- "'" . $max_score . "', ".
- $parent . ", ".
- $previous . ", ".
- $next . ", ".
- ($display_order +1) . ", ".
- $prerequisites . ", ".
- $max_time_allowed .
- ")";
- } else {
-
- $sql_ins = "
- INSERT INTO " . $tbl_lp_item . " ( ".
- "lp_id, ".
- "item_type, ".
- "ref, ".
- "title, ".
- "description, ".
- "path, ".
- "max_score, ".
- "parent_item_id, ".
- "previous_item_id, ".
- "next_item_id, ".
- "display_order, ".
- "max_time_allowed ".
- ") VALUES (".
- $this->get_id() . ",".
- "'" . $type . "',".
- "'',".
- "'" . $title . "',".
- "'" . $description . "',".
- "'" . $id . "',".
- "'" . $max_score . "',".
- $parent . ",".
- $previous . ",".
- $next . ",".
- ($display_order +1) . ",".
- $max_time_allowed .
- ")";
- }
- if ($this->debug > 2) {
- error_log('New LP - Inserting dokeos_chapter: ' . $sql_ins, 0);
- }
- $res_ins = Database::query($sql_ins);
- if ($res_ins > 0) {
- $new_item_id = Database :: insert_id($res_ins);
-
- $sql_update_next = "
- UPDATE " . $tbl_lp_item . "
- SET previous_item_id = " . $new_item_id . "
- WHERE id = " . $next;
- $res_update_next = Database::query($sql_update_next);
-
- $sql_update_previous = "
- UPDATE " . $tbl_lp_item . "
- SET next_item_id = " . $new_item_id . "
- WHERE id = " . $tmp_previous;
- $res_update_previous = Database::query($sql_update_previous);
-
- $sql_update_order = "
- UPDATE " . $tbl_lp_item . "
- SET display_order = display_order + 1
- WHERE
- lp_id = " . $this->get_id() . " AND
- id <> " . $new_item_id . " AND
- parent_item_id = " . $parent . " AND
- display_order > " . $display_order;
- $res_update_previous = Database::query($sql_update_order);
-
- $sql_update_ref = "
- UPDATE " . $tbl_lp_item . "
- SET ref = " . $new_item_id . "
- WHERE id = " . $new_item_id;
- Database::query($sql_update_ref);
- }
-
- if (!empty ($_FILES['mp3']['name'])) {
-
- global $_course;
- $filepath = api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document/';
- if (!is_dir($filepath . 'audio')) {
- mkdir($filepath . 'audio', api_get_permissions_for_new_directories());
- $audio_id = add_document($_course, '/audio', 'folder', 0, 'audio');
- api_item_property_update($_course, TOOL_DOCUMENT, $audio_id, 'FolderCreated', api_get_user_id(), null, null, null, null, api_get_session_id());
- }
-
- include_once api_get_path(LIBRARY_PATH).'fileUpload.lib.php';
- $file_path = handle_uploaded_document($_course, $_FILES['mp3'], api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document', '/audio', api_get_user_id(), '', '', '', '', '', false);
-
- $file_components = explode('/', $file_path);
- $file = $file_components[count($file_components) - 1];
-
- $sql_insert_audio = "UPDATE $tbl_lp_item SET audio = '" . Database :: escape_string($file) . "' WHERE id = '" . Database :: escape_string($new_item_id) . "'";
- Database::query($sql_insert_audio);
- }
- return $new_item_id;
- }
-
- public function add_lp($course, $name, $description = '', $learnpath = 'guess', $origin = 'zip', $zipname = '', $publicated_on = '', $expired_on = '') {
- global $charset;
-
- $tbl_lp = Database :: get_course_table(TABLE_LP_MAIN);
-
-
- $i = 0;
- $name = learnpath :: escape_string($name);
-
- $session_id = api_get_session_id();
- $check_name = "SELECT * FROM $tbl_lp WHERE name = '$name'";
-
- $res_name = Database::query($check_name);
- if ($publicated_on == '0000-00-00 00:00:00' || empty($publicated_on)) {
-
- $publicated_on = api_get_utc_datetime();
- } else {
- $publicated_on = Database::escape_string(api_get_utc_datetime($publicated_on));
- }
- if ($expired_on == '0000-00-00 00:00:00' || empty($expired_on)) {
- $expired_on = '';
- } else {
- $expired_on = Database::escape_string(api_get_utc_datetime($expired_on));
- }
- while (Database :: num_rows($res_name)) {
-
- $i++;
- $name = $name . ' - ' . $i;
- $check_name = "SELECT * FROM $tbl_lp WHERE name = '$name'";
-
- $res_name = Database::query($check_name);
- }
-
-
- $description = learnpath :: escape_string(api_htmlentities($description, ENT_QUOTES, $charset));
- $type = 1;
- switch ($learnpath) {
- case 'guess':
- break;
- case 'dokeos':
- case 'chamilo':
- $type = 1;
- break;
- case 'aicc':
- break;
- }
- switch ($origin) {
- case 'zip':
-
- break;
- case 'manual':
- default:
- $get_max = "SELECT MAX(display_order) FROM $tbl_lp";
- $res_max = Database::query($get_max);
- if (Database :: num_rows($res_max) < 1) {
- $dsp = 1;
- } else {
- $row = Database :: fetch_array($res_max);
- $dsp = $row[0] + 1;
- }
- $sql_insert = "INSERT INTO $tbl_lp (lp_type,name,description,path,default_view_mod, default_encoding,display_order,content_maker,content_local,js_lib,session_id, created_on, publicated_on, expired_on) " .
- "VALUES ($type,'$name','$description','','embedded','UTF-8','$dsp','Chamilo','local','','".$session_id."', '".api_get_utc_datetime()."' , '".$publicated_on."' , '".$expired_on."')";
-
- $res_insert = Database::query($sql_insert);
- $id = Database :: insert_id();
- if ($id > 0) {
-
- api_item_property_update(api_get_course_info(), TOOL_LEARNPATH, $id, 'LearnpathAdded', api_get_user_id());
- return $id;
- }
- break;
- }
- }
-
- public function append_message($string) {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::append_message()', 0);
- }
- $this->message .= $string;
- }
-
- public function autocomplete_parents($item) {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::autocomplete_parents()', 0);
- }
- if (empty ($item)) {
- $item = $this->current;
- }
- $parent_id = $this->items[$item]->get_parent();
- if ($this->debug > 2) {
- error_log('New LP - autocompleting parent of item ' . $item . ' (item ' . $parent_id . ')', 0);
- }
- if (is_object($this->items[$item]) and !empty ($parent_id)) {
-
- if ($this->debug > 2) {
- error_log('New LP - ' . $item . ' is an item, proceed', 0);
- }
- $current_item = & $this->items[$item];
- $parent = & $this->items[$parent_id];
-
- $current_status = $current_item->get_status();
- if ($current_item->is_done() || $current_status == 'browsed' || $current_status == 'failed') {
-
- $completed = true;
- if ($this->debug > 2) {
- error_log('New LP - Status of current item is alright', 0);
- }
- foreach ($parent->get_children() as $child) {
-
- if ($child != $item) {
- if ($this->debug > 2) {
- error_log('New LP - Looking at brother with ID ' . $child . ', status is ' . $this->items[$child]->get_status(), 0);
- }
-
-
- if ($this->items[$child]->status_is(array (
- 'completed',
- 'passed',
- 'succeeded',
- 'browsed',
- 'failed'
- ))) {
-
- } else {
- if ($this->debug > 2) {
- error_log('New LP - Found one incomplete child of ' . $parent_id . ': ' . $child . ' is ' . $this->items[$child]->get_status(), 0);
- }
- $completed = false;
- }
- }
- }
- if ($completed) {
- $parent->set_status('completed');
- $parent->save(false, $this->prerequisites_match($parent->get_id()));
- $this->update_queue[$parent->get_id()] = $parent->get_status();
- if ($this->debug > 2) {
- error_log('New LP - Added parent to update queue ' . print_r($this->update_queue, true), 0);
- }
- $this->autocomplete_parents($parent->get_id());
- }
- } else {
-
- }
- }
- }
-
- public function autosave() {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::autosave()', 0);
- }
-
- }
-
- public function clear_message() {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::clear_message()', 0);
- }
- $this->message = '';
- }
-
- public function close() {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::close()', 0);
- }
- if (empty ($this->lp_id)) {
- $this->error = 'Trying to close this learnpath but no ID is set';
- return false;
- }
- $this->current_time_stop = time();
- if ($this->save) {
- $learnpath_view_table = Database :: get_course_table(TABLE_LP_VIEW);
-
- }
- $this->ordered_items = array ();
- $this->index = 0;
- unset ($this->lp_id);
-
- return true;
- }
-
- public function delete($course = null, $id = null, $delete = 'keep') {
-
-
-
-
-
- if (!empty ($id) && ($id != $this->lp_id)) {
- return false;
- }
- $lp = Database :: get_course_table(TABLE_LP_MAIN);
- $lp_item = Database :: get_course_table(TABLE_LP_ITEM);
- $lp_view = Database :: get_course_table(TABLE_LP_VIEW);
- $lp_item_view = Database :: get_course_table(TABLE_LP_ITEM_VIEW);
-
-
- foreach ($this->items as $id => $dummy) {
-
- $sql_del_view = "DELETE FROM $lp_item_view WHERE lp_item_id = '" . $id . "'";
- $res_del_item_view = Database::query($sql_del_view);
- }
-
- $sql_del_item = "DELETE FROM $lp_item WHERE lp_id = " . $this->lp_id;
- $res_del_item = Database::query($sql_del_item);
- $sql_del_view = "DELETE FROM $lp_view WHERE lp_id = " . $this->lp_id;
-
- $res_del_view = Database::query($sql_del_view);
- $this->toggle_publish($this->lp_id, 'i');
-
- if ($this->type == 2 || $this->type == 3) {
-
- $sql = "SELECT path FROM $lp WHERE id = " . $this->lp_id;
- $res = Database::query($sql);
- if (Database :: num_rows($res) > 0) {
- $row = Database :: fetch_array($res);
- $path = $row['path'];
- $sql = "SELECT id FROM $lp WHERE path = '$path' AND id != " . $this->lp_id;
- $res = Database::query($sql);
- if (Database :: num_rows($res) > 0) {
- if ($this->debug > 2) {
- error_log('New LP - In learnpath::delete(), found other LP using path ' . $path . ', keeping directory', 0);
- }
- } else {
-
- $course_rel_dir = api_get_course_path() . '/scorm/';
- $course_scorm_dir = api_get_path(SYS_COURSE_PATH) . $course_rel_dir;
- if ($delete == 'remove' && is_dir($course_scorm_dir . $path) and !empty ($course_scorm_dir)) {
- if ($this->debug > 2) {
- error_log('New LP - In learnpath::delete(), found SCORM, deleting directory: ' . $course_scorm_dir . $path, 0);
- }
-
- if (strcmp(substr($path, -2), "/.") == 0) {
- $path = substr($path, 0, -1);
- }
-
- rmdirr($course_scorm_dir . $path);
- }
- }
- }
- }
- $sql_del_lp = "DELETE FROM $lp WHERE id = " . $this->lp_id;
-
- $res_del_lp = Database::query($sql_del_lp);
- $this->update_display_order();
- api_item_property_update(api_get_course_info(), TOOL_LEARNPATH, $this->lp_id, 'delete', api_get_user_id());
- require_once '../gradebook/lib/be.inc.php';
- $tbl_grade_link = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_LINK);
-
- $sql = 'SELECT gl.id FROM ' . $tbl_grade_link . ' gl WHERE gl.type="4" AND gl.ref_id="' . $id . '";';
- $result = Database::query($sql);
- $row = Database :: fetch_array($result, 'ASSOC');
-
- if (!empty($row['id'])) {
- $link = LinkFactory :: load($row['id']);
- if ($link[0] != null) {
- $link[0]->delete();
- }
- }
- if (api_get_setting('search_enabled') == 'true') {
- require_once api_get_path(LIBRARY_PATH).'specific_fields_manager.lib.php';
- $r = delete_all_values_for_item($this->cc, TOOL_LEARNPATH, $this->lp_id);
- }
- }
-
- public function delete_children_items($id) {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::delete_children_items(' . $id . ')', 0);
- }
- $num = 0;
- if (empty ($id) || $id != strval(intval($id))) {
- return false;
- }
- $lp_item = Database :: get_course_table(TABLE_LP_ITEM);
- $sql = "SELECT * FROM $lp_item WHERE parent_item_id = $id";
- $res = Database::query($sql);
- while ($row = Database :: fetch_array($res)) {
- $num += $this->delete_children_items($row['id']);
- $sql_del = "DELETE FROM $lp_item WHERE id = " . $row['id'];
- $res_del = Database::query($sql_del);
- $num++;
- }
- return $num;
- }
-
- public function delete_item($id, $remove = 'keep') {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::delete_item()', 0);
- }
-
- if (empty ($id) || $id != strval(intval($id))) {
- return false;
- }
-
- $lp_item = Database :: get_course_table(TABLE_LP_ITEM);
- $sql_sel = "SELECT * FROM $lp_item WHERE id = $id";
- $res_sel = Database::query($sql_sel);
- if (Database :: num_rows($res_sel) < 1) {
- return false;
- }
- $row = Database :: fetch_array($res_sel);
- $previous = $row['previous_item_id'];
- $next = $row['next_item_id'];
- $display = $row['display_order'];
- $parent = $row['parent_item_id'];
- $lp = $row['lp_id'];
-
- $num = $this->delete_children_items($id);
- if ($this->debug > 2) {
- error_log('New LP - learnpath::delete_item() - deleted ' . $num . ' children of element ' . $id, 0);
- }
-
- $sql_del = "DELETE FROM $lp_item WHERE id = $id";
- if ($this->debug > 2) {
- error_log('New LP - Deleting item: ' . $sql_del, 0);
- }
- $res_del = Database::query($sql_del);
-
- $sql_upd = "UPDATE $lp_item SET next_item_id = $next WHERE id = $previous";
- $res_upd = Database::query($sql_upd);
- $sql_upd = "UPDATE $lp_item SET previous_item_id = $previous WHERE id = $next";
- $res_upd = Database::query($sql_upd);
-
- $sql_all = "UPDATE $lp_item SET display_order = display_order-1 WHERE lp_id = $lp AND parent_item_id = $parent AND display_order > $display";
- $res_all = Database::query($sql_all);
-
- $sql_all = "UPDATE $lp_item SET prerequisite = '' WHERE prerequisite = $id";
- $res_all = Database::query($sql_all);
-
- if (api_get_setting('search_enabled') == 'true') {
- $tbl_se_ref = Database :: get_main_table(TABLE_MAIN_SEARCH_ENGINE_REF);
- $sql = 'SELECT * FROM %s WHERE course_code=\'%s\' AND tool_id=\'%s\' AND ref_id_high_level=%s AND ref_id_second_level=%d LIMIT 1';
- $sql = sprintf($sql, $tbl_se_ref, $this->cc, TOOL_LEARNPATH, $lp, $id);
- $res = Database::query($sql);
- if (Database :: num_rows($res) > 0) {
- $row2 = Database :: fetch_array($res);
- require_once api_get_path(LIBRARY_PATH).'search/DokeosIndexer.class.php';
- $di = new DokeosIndexer();
- $di->remove_document((int) $row2['search_did']);
- }
- $sql = 'DELETE FROM %s WHERE course_code=\'%s\' AND tool_id=\'%s\' AND ref_id_high_level=%s AND ref_id_second_level=%d LIMIT 1';
- $sql = sprintf($sql, $tbl_se_ref, $this->cc, TOOL_LEARNPATH, $lp, $id);
- Database::query($sql);
- }
- }
-
- public function edit_item($id, $parent, $previous, $title, $description, $prerequisites = 0, $audio = null, $max_time_allowed = 0) {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::edit_item()', 0);
- }
- if (empty ($max_time_allowed)) {
- $max_time_allowed = 0;
- }
- if (empty ($id) || ($id != strval(intval($id))) || empty ($title)) {
- return false;
- }
- $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
- $sql_select = "SELECT * FROM " . $tbl_lp_item . " WHERE id = " . $id;
- $res_select = Database::query($sql_select);
- $row_select = Database :: fetch_array($res_select);
- $audio_update_sql = '';
- if (is_array($audio) && !empty ($audio['tmp_name']) && $audio['error'] === 0) {
-
- global $_course;
- $filepath = api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document/';
- if (!is_dir($filepath . 'audio')) {
- mkdir($filepath . 'audio', api_get_permissions_for_new_directories());
- $audio_id = add_document($_course, '/audio', 'folder', 0, 'audio');
- api_item_property_update($_course, TOOL_DOCUMENT, $audio_id, 'FolderCreated', api_get_user_id(), null, null, null, null, api_get_session_id());
- }
-
- $pi = pathinfo($audio['name']);
- if ($pi['extension'] == 'mp3') {
- $c_det = api_get_course_info($this->cc);
- $bp = api_get_path(SYS_COURSE_PATH) . $c_det['path'] . '/document';
- $path = handle_uploaded_document($c_det, $audio, $bp, '/audio', api_get_user_id(), 0, null, '', 0, 'rename', false, 0);
- $path = substr($path, 7);
-
- $audio_update_sql = ", audio = '" . Database :: escape_string($path) . "' ";
- }
- }
- $same_parent = ($row_select['parent_item_id'] == $parent) ? true : false;
- $same_previous = ($row_select['previous_item_id'] == $previous) ? true : false;
-
- if ($same_parent && $same_previous) {
-
- $sql_update = " UPDATE " . $tbl_lp_item . "
- SET title = '" . $this->escape_string($title) . "',
- prerequisite = '" . $prerequisites . "',
- description = '" . $this->escape_string($description) . "'
- " . $audio_update_sql . ",
- max_time_allowed = '" . $this->escape_string($max_time_allowed) . "'
- WHERE id = " . $id;
- $res_update = Database::query($sql_update);
- } else {
- $old_parent = $row_select['parent_item_id'];
- $old_previous = $row_select['previous_item_id'];
- $old_next = $row_select['next_item_id'];
- $old_order = $row_select['display_order'];
- $old_prerequisite = $row_select['prerequisite'];
- $old_max_time_allowed = $row_select['max_time_allowed'];
-
-
- if ($old_previous != 0) {
- $sql_update_next = "
- UPDATE " . $tbl_lp_item . "
- SET next_item_id = " . $old_next . "
- WHERE id = " . $old_previous;
- $res_update_next = Database::query($sql_update_next);
-
- }
- if ($old_next != 0) {
- $sql_update_previous = "
- UPDATE " . $tbl_lp_item . "
- SET previous_item_id = " . $old_previous . "
- WHERE id = " . $old_next;
- $res_update_previous = Database::query($sql_update_previous);
-
- }
-
- $sql_update_order = "
- UPDATE " . $tbl_lp_item . "
- SET display_order = display_order - 1
- WHERE
- display_order > " . $old_order . " AND lp_id = " . $this->lp_id . " AND
- parent_item_id = " . $old_parent;
- $res_update_order = Database::query($sql_update_order);
-
-
-
- if ($previous == 0) {
-
- $sql_select_old = "
- SELECT
- id,
- display_order
- FROM " . $tbl_lp_item . "
- WHERE
- lp_id = " . $this->lp_id . " AND
- parent_item_id = " . $parent . " AND
- previous_item_id = " . $previous;
- $res_select_old = Database::query($sql_select_old);
- $row_select_old = Database :: fetch_array($res_select_old);
-
-
- if (Database :: num_rows($res_select_old) == 0) {
- $new_next = 0;
- $new_order = 1;
- } else {
- $new_next = $row_select_old['id'];
- $new_order = $row_select_old['display_order'];
- }
-
-
-
- } else {
-
- $sql_select_old = "
- SELECT
- next_item_id,
- display_order
- FROM " . $tbl_lp_item . "
- WHERE id = " . $previous;
- $res_select_old = Database::query($sql_select_old);
- $row_select_old = Database :: fetch_array($res_select_old);
-
-
-
-
- $new_next = $row_select_old['next_item_id'];
- $new_order = $row_select_old['display_order'] + 1;
- }
-
-
- $sql_update = "
- UPDATE " . $tbl_lp_item . "
- SET
- title = '" . $this->escape_string($title) . "',
- description = '" . $this->escape_string($description) . "',
- parent_item_id = " . $parent . ",
- previous_item_id = " . $previous . ",
- next_item_id = " . $new_next . ",
- display_order = " . $new_order . "
- " . $audio_update_sql . "
- WHERE id = " . $id;
- $res_update_next = Database::query($sql_update);
-
- if ($previous != 0) {
-
- $sql_update_previous = "
- UPDATE " . $tbl_lp_item . "
- SET next_item_id = " . $id . "
- WHERE id = " . $previous;
- $res_update_next = Database::query($sql_update_previous);
-
- }
- if ($new_next != 0) {
-
- $sql_update_next = "
- UPDATE " . $tbl_lp_item . "
- SET previous_item_id = " . $id . "
- WHERE id = " . $new_next;
- $res_update_next = Database::query($sql_update_next);
-
- }
- if ($old_prerequisite != $prerequisites) {
- $sql_update_next = "
- UPDATE " . $tbl_lp_item . "
- SET prerequisite = " . $prerequisites . "
- WHERE id = " . $id;
- $res_update_next = Database::query($sql_update_next);
- }
- if ($old_max_time_allowed != $max_time_allowed) {
- $sql_update_max_time_allowed = "
- UPDATE " . $tbl_lp_item . "
- SET max_time_allowed = " . $max_time_allowed . "
- WHERE id = " . $id;
- $res_update_max_time_allowed = Database::query($sql_update_max_time_allowed);
- }
-
- $sql_update_order = "
- UPDATE " . $tbl_lp_item . "
- SET display_order = display_order + 1
- WHERE
- lp_id = " . $this->get_id() . " AND
- id <> " . $id . " AND
- parent_item_id = " . $parent . " AND
- display_order >= " . $new_order;
- $res_update_next = Database::query($sql_update_order);
- }
- }
-
- public function edit_item_prereq($id, $prerequisite_id, $mastery_score = 0, $max_score = 100) {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::edit_item_prereq(' . $id . ',' . $prerequisite_id . ',' . $mastery_score . ',' . $max_score . ')', 0);
- }
- if (empty ($id) or ($id != strval(intval($id))) or empty ($prerequisite_id)) {
- return false;
- }
- $prerequisite_id = $this->escape_string($prerequisite_id);
- $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
- if (!is_numeric($mastery_score) || $mastery_score < 0)
- $mastery_score = 0;
- if (!is_numeric($max_score) || $max_score < 0)
- $max_score = 100;
- if ($mastery_score > $max_score)
- $max_score = $mastery_score;
- if (!is_numeric($prerequisite_id))
- $prerequisite_id = 'NULL';
- $sql_upd = " UPDATE " . $tbl_lp_item . "
- SET prerequisite = " . $prerequisite_id . " WHERE id = " . $id;
- $res_upd = Database::query($sql_upd);
- if ($prerequisite_id != 'NULL' && $prerequisite_id != '') {
- $sql_upd = " UPDATE " . $tbl_lp_item . " SET
- mastery_score = " . $mastery_score .
-
- " WHERE ref = '" . $prerequisite_id . "'";
- $res_upd = Database::query($sql_upd);
- }
-
- return true;
- }
-
- public function escape_string($string) {
-
- return Database :: escape_string($string);
- }
-
- public function export_lp($type, $course, $id, $zipname) {
-
- if (empty($type) || empty($course) || empty($id) || empty($zipname)) {
- return false;
- }
- $url = '';
- switch ($type) {
- case 'scorm':
- break;
- case 'zip':
- break;
- case 'cdrom':
- break;
- }
- return $url;
- }
-
- public function get_brother_chapters($id) {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::get_brother_chapters()', 0);
- }
- if (empty ($id) OR $id != strval(intval($id))) {
- return array ();
- }
- $lp_item = Database :: get_course_table(TABLE_LP_ITEM);
- $sql_parent = "SELECT * FROM $lp_item WHERE id = $id AND item_type='dokeos_chapter'";
- $res_parent = Database::query($sql_parent);
- if (Database :: num_rows($res_parent) > 0) {
- $row_parent = Database :: fetch_array($res_parent);
- $parent = $row_parent['parent_item_id'];
- $sql_bros = "SELECT * FROM $lp_item WHERE parent_item_id = $parent AND id = $id AND item_type='dokeos_chapter' ORDER BY display_order";
- $res_bros = Database::query($sql_bros);
- $list = array ();
- while ($row_bro = Database :: fetch_array($res_bros)) {
- $list[] = $row_bro;
- }
- return $list;
- }
- return array ();
- }
-
- public function get_brother_items($id) {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::get_brother_items(' . $id . ')', 0);
- }
- if (empty ($id) OR $id != strval(intval($id))) {
- return array ();
- }
- $lp_item = Database :: get_course_table(TABLE_LP_ITEM);
- $sql_parent = "SELECT * FROM $lp_item WHERE id = $id";
- $res_parent = Database::query($sql_parent);
- if (Database :: num_rows($res_parent) > 0) {
- $row_parent = Database :: fetch_array($res_parent);
- $parent = $row_parent['parent_item_id'];
- $sql_bros = "SELECT * FROM $lp_item WHERE parent_item_id = $parent ORDER BY display_order";
- $res_bros = Database::query($sql_bros);
- $list = array ();
- while ($row_bro = Database :: fetch_array($res_bros)) {
- $list[] = $row_bro;
- }
- return $list;
- }
- return array ();
- }
-
- public function get_common_index_terms_by_prefix($prefix) {
- require_once api_get_path(LIBRARY_PATH).'specific_fields_manager.lib.php';
- $terms = get_specific_field_values_list_by_prefix($prefix, $this->cc, TOOL_LEARNPATH, $this->lp_id);
- $prefix_terms = array();
- if (!empty($terms)) {
- foreach ($terms as $term) {
- $prefix_terms[] = $term['value'];
- }
- }
- return $prefix_terms;
- }
-
- public function get_complete_items_count() {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::get_complete_items_count()', 0);
- }
- $i = 0;
- foreach ($this->items as $id => $dummy) {
-
- if ($this->items[$id]->status_is(array (
- 'completed',
- 'passed',
- 'succeeded',
- 'browsed',
- 'failed'
- )) && $this->items[$id]->get_type() != 'dokeos_chapter' && $this->items[$id]->get_type() != 'dir') {
- $i++;
- }
- }
- return $i;
- }
-
- public function get_current_item_id() {
- $current = 0;
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::get_current_item_id()', 0);
- }
- if (!empty ($this->current)) {
- $current = $this->current;
- }
- if ($this->debug > 2) {
- error_log('New LP - In learnpath::get_current_item_id() - Returning ' . $current, 0);
- }
- return $current;
- }
-
- public function get_first_item_id() {
- $current = 0;
- if (is_array($this->ordered_items)) {
- $current = $this->ordered_items[0];
- }
- return $current;
- }
-
- public function get_total_items_count() {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::get_total_items_count()', 0);
- }
- return count($this->items);
- }
-
- public function get_total_items_count_without_chapters() {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::get_total_items_count_without_chapters()', 0);
- }
- $total = 0;
- foreach ($this->items as $temp => $temp2) {
- if (!in_array($temp2->get_type(), array (
- 'dokeos_chapter',
- 'chapter',
- 'dir'
- )))
- $total++;
- }
- return $total;
- }
-
- public function first() {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::first()', 0);
- }
-
- if (count($this->ordered_items) == 0) {
- $this->index = 0;
- }
- if (!empty($this->last_item_seen) && !empty($this->items[$this->last_item_seen]) && $this->items[$this->last_item_seen]->get_type() != 'dir' && $this->items[$this->last_item_seen]->get_type() != 'dokeos_chapter' && !$this->items[$this->last_item_seen]->is_done()) {
- if ($this->debug > 2) {
- error_log('New LP - In learnpath::first() - Last item seen is ' . $this->last_item_seen . ' of type ' . $this->items[$this->last_item_seen]->get_type(), 0);
- }
- $index = -1;
- foreach ($this->ordered_items as $myindex => $item_id) {
- if ($item_id == $this->last_item_seen) {
- $index = $myindex;
- break;
- }
- }
- if ($index == -1) {
-
- if ($this->debug > 2) {
- error_log('New LP - Last item (' . $this->last_item_seen . ') was found in items but not in ordered_items, panic!', 0);
- }
- return false;
- } else {
- $this->last = $this->last_item_seen;
- $this->current = $this->last_item_seen;
- $this->index = $index;
- }
- } else {
- if ($this->debug > 2) {
- error_log('New LP - In learnpath::first() - No last item seen', 0);
- }
- $index = 0;
-
-
- while (!empty($this->ordered_items[$index]) AND is_a($this->items[$this->ordered_items[$index]], 'learnpathItem') AND ($this->items[$this->ordered_items[$index]]->get_type() == 'dir' OR $this->items[$this->ordered_items[$index]]->get_type() == 'dokeos_chapter' OR $this->items[$this->ordered_items[$index]]->is_done() === true) AND $index < $this->max_ordered_items) {
- $index++;
- }
- $this->last = $this->current;
-
- $this->current = $this->ordered_items[$index];
- $this->index = $index;
- if ($this->debug > 2) {
- error_log('New LP - In learnpath::first() - No last item seen. New last = ' . $this->last . '(' . $this->ordered_items[$index] . ')', 0);
- }
- }
- if ($this->debug > 2) {
- error_log('New LP - In learnpath::first() - First item is ' . $this->get_current_item_id());
- }
- }
-
- public function get_js_info($item_id = '') {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::get_js_info(' . $item_id . ')', 0);
- }
- $info = '';
- $item_id = $this->escape_string($item_id);
- if (!empty($item_id) && is_object($this->items[$item_id])) {
-
- $oItem = $this->items[$item_id];
- $info .= '<script language="javascript">';
- $info .= "top.set_score(" . $oItem->get_score() . ");\n";
- $info .= "top.set_max(" . $oItem->get_max() . ");\n";
- $info .= "top.set_min(" . $oItem->get_min() . ");\n";
- $info .= "top.set_lesson_status('" . $oItem->get_status() . "');";
- $info .= "top.set_session_time('" . $oItem->get_scorm_time('js') . "');";
- $info .= "top.set_suspend_data('" . $oItem->get_suspend_data() . "');";
- $info .= "top.set_saved_lesson_status('" . $oItem->get_status() . "');";
- $info .= "top.set_flag_synchronized();";
- $info .= '</script>';
- if ($this->debug > 2) {
- error_log('New LP - in learnpath::get_js_info(' . $item_id . ') - returning: ' . $info, 0);
- }
- return $info;
- } else {
-
- $info .= '<script language="javascript">';
- $info .= "top.set_score(" . learnpathItem :: get_score() . ");\n";
- $info .= "top.set_max(" . learnpathItem :: get_max() . ");\n";
- $info .= "top.set_min(" . learnpathItem :: get_min() . ");\n";
- $info .= "top.set_lesson_status('" . learnpathItem :: get_status() . "');";
- $info .= "top.set_session_time('" . learnpathItem :: get_scorm_time('js') . "');";
- $info .= "top.set_suspend_data('" . learnpathItem :: get_suspend_data() . "');";
- $info .= "top.set_saved_lesson_status('" . learnpathItem :: get_status() . "');";
- $info .= "top.set_flag_synchronized();";
- $info .= '</script>';
- if ($this->debug > 2) {
- error_log('New LP - in learnpath::get_js_info(' . $item_id . ') - returning: ' . $info, 0);
- }
- return $info;
- }
- }
-
- public function get_js_lib() {
- $lib = '';
- if (!empty ($this->js_lib)) {
- $lib = $this->js_lib;
- }
- return $lib;
- }
-
- public function get_id() {
-
- if (!empty ($this->lp_id)) {
- return $this->lp_id;
- } else {
- return 0;
- }
- }
-
- public function get_last() {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::get_last()', 0);
- }
- $this->index = count($this->ordered_items) - 1;
- return $this->ordered_items[$this->index];
- }
-
- public function get_navigation_bar() {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::get_navigation_bar()', 0);
- }
-
- $file = '';
- $openDir = '';
- $edoceo = '';
- $time = 0;
- $navbar = '';
- $RequestUri = '';
- $mycurrentitemid = $this->get_current_item_id();
- if ($this->mode == 'fullscreen') {
- $navbar = '<table cellpadding="0" cellspacing="0" align="left">' . "\n" .
- ' <tr> ' . "\n" .
- ' <td>' . "\n" .
- ' <div class="buttons">' . "\n" .
- ' <a href="lp_controller.php?action=stats" onClick="window.parent.API.save_asset();return true;" target="content_name_blank" title="stats" id="stats_link"><img border="0" src="../img/lp_stats.gif" title="' . get_lang('Reporting') . '"></a>' . "\n" .
- ' <a href="" onClick="switch_item(' . $mycurrentitemid . ',\'previous\');return false;" title="previous"><img border="0" src="../img/lp_leftarrow.gif" title="' . get_lang('ScormPrevious') . '"></a>' . "\n" .
- ' <a href="" onClick="switch_item(' . $mycurrentitemid . ',\'next\');return false;" title="next" ><img border="0" src="../img/lp_rightarrow.gif" title="' . get_lang('ScormNext') . '"></a>' . "\n" .
-
-
- ' </div>' . "\n" .
- ' </td>' . "\n" .
- ' </tr>' . "\n" .
- '</table>' . "\n";
- } else {
- $navbar = '<table cellpadding="0" cellspacing="0" align="left">' . "\n" .
- ' <tr> ' . "\n" .
- ' <td>' . "\n" .
- ' <div class="buttons">' . "\n" .
- ' <a href="lp_controller.php?action=stats" onClick="window.parent.API.save_asset();return true;" target="content_name" title="stats" id="stats_link"><img border="0" src="../img/lp_stats.gif" title="' . get_lang('Reporting') . '"></a>' . "\n" .
- ' <a href="" onClick="switch_item(' . $mycurrentitemid . ',\'previous\');return false;" title="previous"><img border="0" src="../img/lp_leftarrow.gif" title="' . get_lang('ScormPrevious') . '"></a>' . "\n" .
- ' <a href="" onClick="switch_item(' . $mycurrentitemid . ',\'next\');return false;" title="next" ><img border="0" src="../img/lp_rightarrow.gif" title="' . get_lang('ScormNext') . '"></a>' . "\n" .
-
- ' </div>' . "\n" .
- ' </td>' . "\n" .
- ' </tr>' . "\n" .
- '</table>' . "\n";
- }
- return $navbar;
- }
-
- public function get_next_index() {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::get_next_index()', 0);
- }
-
- $index = $this->index;
- $index++;
- if ($this->debug > 2) {
- error_log('New LP - Now looking at ordered_items[' . ($index) . '] - type is ' . $this->items[$this->ordered_items[$index]]->type, 0);
- }
- while (!empty ($this->ordered_items[$index]) AND ($this->items[$this->ordered_items[$index]]->get_type() == 'dir' || $this->items[$this->ordered_items[$index]]->get_type() == 'dokeos_chapter') AND $index < $this->max_ordered_items) {
- $index++;
- if ($index == $this->max_ordered_items){
- if ($this->items[$this->ordered_items[$index]]->get_type() == 'dir' || $this->items[$this->ordered_items[$index]]->get_type() == 'dokeos_chapter') {
- return $this->index;
- } else {
- return $index;
- }
- }
- }
- if (empty ($this->ordered_items[$index])) {
- return $this->index;
- }
- if ($this->debug > 2) {
- error_log('New LP - index is now ' . $index, 0);
- }
- return $index;
- }
-
- public function get_next_item_id() {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::get_next_item_id()', 0);
- }
- $new_index = $this->get_next_index();
- if (!empty ($new_index)) {
- if (isset ($this->ordered_items[$new_index])) {
- if ($this->debug > 2) {
- error_log('New LP - In learnpath::get_next_index() - Returning ' . $this->ordered_items[$new_index], 0);
- }
- return $this->ordered_items[$new_index];
- }
- }
- if ($this->debug > 2) {
- error_log('New LP - In learnpath::get_next_index() - Problem - Returning 0', 0);
- }
- return 0;
- }
-
- public function get_package_type($file_path, $file_name) {
-
- $file_info = pathinfo($file_name);
- $filename = $file_info['basename'];
- $extension = $file_info['extension'];
- if (!empty($_POST['ppt2lp']) && !in_array(strtolower($extension), array (
- 'dll',
- 'exe'
- ))) {
- return 'oogie';
- }
- if (!empty($_POST['woogie']) && !in_array(strtolower($extension), array (
- 'dll',
- 'exe'
- ))) {
- return 'woogie';
- }
- $file_base_name = str_replace('.' . $extension, '', $filename);
- $zipFile = new pclZip($file_path);
-
- $zipContentArray = $zipFile->listContent();
- $package_type = '';
- $at_root = false;
- $manifest = '';
-
- if (is_array($zipContentArray) && count($zipContentArray) > 0) {
- foreach ($zipContentArray as $thisContent) {
- if (preg_match('~.(php.*|phtml)$~i', $thisContent['filename'])) {
-
- }
- elseif (stristr($thisContent['filename'], 'imsmanifest.xml') !== false) {
- $manifest = $thisContent['filename'];
- $package_type = 'scorm';
- break;
- }
- elseif (preg_match('/aicc\//i', $thisContent['filename'])) {
-
- $package_type = 'aicc';
-
- } else {
- $package_type = '';
- }
- }
- }
- return $package_type;
- }
-
- public function get_previous_index() {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::get_previous_index()', 0);
- }
- $index = $this->index;
- if (isset ($this->ordered_items[$index -1])) {
- $index--;
- while (isset ($this->ordered_items[$index]) AND ($this->items[$this->ordered_items[$index]]->get_type() == 'dir' || $this->items[$this->ordered_items[$index]]->get_type() == 'dokeos_chapter')) {
- $index--;
- if ($index < 0) {
- return $this->index;
- }
- }
- } else {
- if ($this->debug > 2) {
- error_log('New LP - get_previous_index() - there was no previous index available, reusing ' . $index, 0);
- }
-
- }
- return $index;
- }
-
- public function get_previous_item_id() {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::get_previous_item_id()', 0);
- }
- $new_index = $this->get_previous_index();
- return $this->ordered_items[$new_index];
- }
-
- public function get_progress() {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::get_progress()', 0);
- }
- if (!empty ($this->progress_db)) {
- return $this->progress_db;
- }
- return 0;
- }
-
- public function get_db_progress($lp_id, $user_id, $mode = '%', $course_db = '', $sincere = false,$session_id = 0) {
-
- $session_id = intval($session_id);
- $session_condition = api_get_session_condition($session_id);
- $table = Database :: get_course_table(TABLE_LP_VIEW, $course_db);
- $sql = "SELECT * FROM $table WHERE lp_id = $lp_id AND user_id = $user_id $session_condition";
- $res = Database::query($sql);
- $view_id = 0;
- if (Database :: num_rows($res) > 0) {
- $row = Database :: fetch_array($res);
- $progress = $row['progress'];
- $view_id = $row['id'];
- } else {
- if ($sincere) {
- return null;
- }
- }
- if (empty ($progress)) {
- $progress = '0';
- }
- if ($mode == '%') {
- return $progress . '%';
- } else {
-
- $tbl = Database :: get_course_table(TABLE_LP_ITEM, $course_db);
- $sql = "SELECT count(*) FROM $tbl WHERE lp_id = " . $lp_id . "
- AND item_type NOT IN('dokeos_chapter','chapter','dir')";
- $res = Database::query($sql);
- $row = Database :: fetch_array($res);
- $total = $row[0];
- $tbl_item_view = Database :: get_course_table(TABLE_LP_ITEM_VIEW, $course_db);
- $tbl_item = Database :: get_course_table(TABLE_LP_ITEM, $course_db);
-
-
- $sql = "SELECT count(distinct(lp_item_id))
- FROM $tbl_item_view as item_view
- INNER JOIN $tbl_item as item
- ON item.id = item_view.lp_item_id
- AND item_type NOT IN('dokeos_chapter','chapter','dir')
- WHERE lp_view_id = " . $view_id . "
- AND status IN ('passed','completed','succeeded','browsed','failed')";
- $res = Database::query($sql);
- $row = Database :: fetch_array($res);
- $completed = $row[0];
- if ($mode == 'abs') {
- return $completed . '/' . $total;
- }
- elseif ($mode == 'both') {
- if ($progress < ($completed / ($total ? $total : 1))) {
- $progress = number_format(($completed / ($total ? $total : 1)) * 100, 0);
- }
- return $progress . '% (' . $completed . '/' . $total . ')';
- }
- }
- return $progress;
- }
-
- public function get_mediaplayer($autostart='true') {
- global $_course;
- $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
- $tbl_lp_item_view = Database :: get_course_table(TABLE_LP_ITEM_VIEW);
-
- $sql = "SELECT * FROM " . $tbl_lp_item . " as lp inner join " . $tbl_lp_item_view . " as lp_view on lp.id = lp_view.lp_item_id " .
- "WHERE lp.id = '" . $_SESSION['oLP']->current . "'";
- $result = Database::query($sql);
- $row = Database::fetch_assoc($result);
- $output = '';
- if (!empty ($row['audio'])) {
- $list = $_SESSION['oLP']->get_toc();
- $type_quiz = false;
- foreach($list as $toc) {
- if ($toc['id'] == $_SESSION['oLP']->current && ($toc['type']=='quiz') ) {
- $type_quiz = true;
- }
- }
- if ($type_quiz) {
- if ($_SESSION['oLP']->prevent_reinit == 1) {
- $row['status'] === 'completed' ? $autostart_audio = 'false' : $autostart_audio = 'true';
- } else {
- $autostart_audio = $autostart;
- }
- } else {
- $autostart_audio = 'true';
- }
-
- $output = '<div id="container">';
- $output .= '<script type="text/javascript" src="../inc/lib/mediaplayer/swfobject.js"></script>';
- $output .= '<script type="text/javascript">
- var s1 = new SWFObject("../inc/lib/mediaplayer/player.swf","ply","250","20","9","#FFFFFF");
- s1.addParam("allowscriptaccess","always");
- s1.addParam("flashvars","file=' . api_get_path(WEB_COURSE_PATH) . $_course['path'] . '/document/audio/' . $row['audio'] . '&autostart=' . $autostart_audio.'");
- s1.write("container");
- </script></div>';
- }
- return $output;
- }
-
- public function is_lp_visible_for_student($lp_id, $student_id, $course = null) {
- $lp_id = (int)$lp_id;
- $course = api_get_course_info($course);
- $tbl_learnpath = Database :: get_course_table(TABLE_LP_MAIN,$course['dbName']);
-
- $sql = "SELECT id, prerequisite, publicated_on, expired_on FROM $tbl_learnpath WHERE id = $lp_id";
- $rs = Database::query($sql);
- if (Database::num_rows($rs)>0) {
- $row = Database::fetch_array($rs);
- $prerequisite = $row['prerequisite'];
- $find = array(' ','-',':');
- $from = str_replace($find,'',api_get_local_time($row['publicated_on']));
- $to = str_replace($find,'',api_get_local_time($row['expired_on']));
- $is_visible = true;
- $progress = 0;
-
- if (!empty($prerequisite)) {
- $progress = self::get_db_progress($prerequisite,$student_id,'%', '', false, api_get_session_id());
- $progress = intval($progress);
- if ($progress < 100) {
- $is_visible = false;
- }
- }
-
- if ($is_visible) {
- $now = str_replace($find,'',api_get_local_time());
- if ((($row['publicated_on']!='0000-00-00 00:00:00') && ($now<$from)) or (($row['expired_on']!='0000-00-00 00:00:00') && ($now>$to))) {
- $is_visible = false;
- }
- }
- return $is_visible;
- }
- return false;
- }
-
- public function get_progress_bar($mode = '', $percentage = -1, $text_add = '', $from_lp = false) {
-
- global $lp_theme_css;
-
- if (!empty ($lp_theme_css)) {
- $css_path = api_get_path(WEB_CODE_PATH) . 'css/' . $lp_theme_css . '/images/';
- } else {
- $css_path = '../img/';
- }
-
- if (isset($this) && is_object($this) && ($percentage == '-1' OR $text_add == '')) {
- list($percentage, $text_add) = $this->get_progress_bar_text($mode);
- }
- $text = $percentage . $text_add;
-
-
- $factor = 1.2;
- if ($from_lp)
- $progress_height = '26';
- else
- $progress_height = '16';
- $size = str_replace('%', '', $percentage);
- $output ='<div style="width:135px">' .
- '<img id="progress_img_limit_left" src="' . $css_path . 'bar_1.gif" width="1" height="' . $progress_height . '">' .
- '<img id="progress_img_full" src="' . $css_path . 'bar_1u.gif" width="' . $size * $factor . 'px" height="' . $progress_height . '" id="full_portion">' .
- '<img id="progress_img_limit_middle" src="' . $css_path . 'bar_1m.gif" width="1" height="' . $progress_height . '">';
- if ($percentage <= 98) {
- $output .= '<img id="progress_img_empty" src="' . $css_path . 'bar_1r.gif" width="' . (100 - $size) * $factor . 'px" height="' . $progress_height . '" id="empty_portion">';
- } else {
- $output .= '<img id="progress_img_empty" src="' . $css_path . 'bar_1r.gif" width="0" height="' . $progress_height . '" id="empty_portion">';
- }
- $output .= '<img id="progress_bar_img_limit_right" src="' . $css_path . 'bar_1.gif" width="1" height="' . $progress_height . '"></div>' .
- '<div class="progresstext" id="progress_text">' . $text . '</div>';
- return $output;
- }
-
- public function get_progress_bar_text($mode = '', $add = 0) {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::get_progress_bar_text()', 0);
- }
- if (empty ($mode)) {
- $mode = $this->progress_bar_mode;
- }
- $total_items = $this->get_total_items_count_without_chapters();
- if ($this->debug > 2) {
- error_log('New LP - Total items available in this learnpath: ' . $total_items, 0);
- }
- $i = $this->get_complete_items_count();
- if ($this->debug > 2) {
- error_log('New LP - Items completed so far: ' . $i, 0);
- }
- if ($add != 0) {
- $i += $add;
- if ($this->debug > 2) {
- error_log('New LP - Items completed so far (+modifier): ' . $i, 0);
- }
- }
- $text = '';
- if ($i > $total_items) {
- $i = $total_items;
- }
- if ($mode == '%') {
- if ($total_items > 0) {
- $percentage = ((float) $i / (float) $total_items) * 100;
- } else {
- $percentage = 0;
- }
- $percentage = number_format($percentage, 0);
- $text = '%';
- }
- elseif ($mode == 'abs') {
- $percentage = $i;
- $text = '/' . $total_items;
- }
- return array (
- $percentage,
- $text
- );
- }
-
- public function get_progress_bar_mode() {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::get_progress_bar_mode()', 0);
- }
- if (!empty ($this->progress_bar_mode)) {
- return $this->progress_bar_mode;
- } else {
- return '%';
- }
- }
-
- public function get_proximity() {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::get_proximity()', 0);
- }
- if (!empty ($this->proximity)) {
- return $this->proximity;
- } else {
- return '';
- }
- }
-
- public function get_theme() {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::get_theme()', 0);
- }
- if (!empty ($this->theme)) {
- return $this->theme;
- } else {
- return '';
- }
- }
-
- public function get_lp_session_id() {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::get_lp_session_id()', 0);
- }
- if (!empty ($this->lp_session_id)) {
- return $this->lp_session_id;
- } else {
- return 0;
- }
- }
-
- public function get_preview_image() {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::get_preview_image()', 0);
- }
- if (!empty ($this->preview_image)) {
- return $this->preview_image;
- } else {
- return '';
- }
- }
-
- public function get_author() {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::get_author()', 0);
- }
- if (!empty ($this->author)) {
- return $this->author;
- } else {
- return '';
- }
- }
-
- public function get_scorm_prereq_string($item_id) {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::get_scorm_prereq_string()', 0);
- }
- if (!is_object($this->items[$item_id])) {
- return false;
- }
- $oItem = $this->items[$item_id];
- $prereq = $oItem->get_prereq_string();
- if (empty ($prereq)) {
- return '';
- }
- if (preg_match('/^\d+$/', $prereq) && is_object($this->items[$prereq])) {
-
- return 'ITEM_' . $prereq;
- } else {
- if (isset ($this->refs_list[$prereq])) {
-
-
- return 'ITEM_' . $this->refs_list[$prereq];
- } else {
-
-
-
-
- $find = array (
- '&',
- '|',
- '~',
- '=',
- '<>',
- '{',
- '}',
- '*',
- '(',
- ')'
- );
- $replace = array (
- ' ',
- ' ',
- ' ',
- ' ',
- ' ',
- ' ',
- ' ',
- ' ',
- ' ',
- ' '
- );
- $prereq_mod = str_replace($find, $replace, $prereq);
- $ids = split(' ', $prereq_mod);
- foreach ($ids as $id) {
- $id = trim($id);
- if (isset ($this->refs_list[$id])) {
- $prereq = preg_replace('/[^a-zA-Z_0-9](' . $id . ')[^a-zA-Z_0-9]/', 'ITEM_' . $this->refs_list[$id], $prereq);
- }
- }
- error_log('New LP - In learnpath::get_scorm_prereq_string(): returning modified string: ' . $prereq, 0);
- return $prereq;
- }
- }
- }
-
- public function get_scorm_xml_node(& $children, $id) {
- for ($i = 0; $i < $children->length; $i++) {
- $item_temp = $children->item($i);
- if ($item_temp->nodeName == 'item') {
- if ($item_temp->getAttribute('identifier') == $id) {
- return $item_temp;
- }
- }
- $subchildren = $item_temp->childNodes;
- if ($subchildren->length > 0) {
- $val = $this->get_scorm_xml_node($subchildren, $id);
- if (is_object($val)) {
- return $val;
- }
- }
- }
- return false;
- }
-
- public function get_stats() {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::get_stats()', 0);
- }
-
- }
-
- public function get_stats_course($course) {
-
-
- }
-
- public function get_stats_lp($course, $lp) {
-
-
- }
-
- public function get_stats_lp_user($course, $lp, $user) {
-
-
- }
-
- public function get_stats_user($course, $user) {
-
-
- }
-
- public function get_items_status_list() {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::get_items_status_list()', 0);
- }
- $list = array ();
- foreach ($this->ordered_items as $item_id) {
- $list[] = array (
- $item_id => $this->items[$item_id]->get_status()
- );
- }
- return $list;
- }
-
- public function get_interactions_count_from_db($lp_iv_id = 0) {
- if (empty ($lp_iv_id)) {
- return -1;
- }
- $table = Database :: get_course_table(TABLE_LP_IV_INTERACTION);
- $sql = "SELECT count(*) FROM $table WHERE lp_iv_id = $lp_iv_id";
- $res = Database::query($sql);
- $row = Database :: fetch_array($res);
- $num = $row[0];
- return $num;
- }
-
- public function get_iv_interactions_array($lp_iv_id = 0) {
- $list = array ();
- $table = Database :: get_course_table(TABLE_LP_IV_INTERACTION);
- $sql = "SELECT * FROM $table WHERE lp_iv_id = $lp_iv_id ORDER BY order_id ASC";
- $res = Database::query($sql);
- $num = Database :: num_rows($res);
- if ($num > 0) {
- $list[] = array (
- 'order_id' => api_htmlentities(get_lang('Order'), ENT_QUOTES),
- 'id' => api_htmlentities(get_lang('InteractionID'), ENT_QUOTES),
- 'type' => api_htmlentities(get_lang('Type'), ENT_QUOTES),
- 'time' => api_htmlentities(get_lang('TimeFinished'), ENT_QUOTES),
- 'correct_responses' => api_htmlentities(get_lang('CorrectAnswers'), ENT_QUOTES),
- 'student_response' => api_htmlentities(get_lang('StudentResponse'), ENT_QUOTES),
- 'result' => api_htmlentities(get_lang('Result'), ENT_QUOTES),
- 'latency' => api_htmlentities(get_lang('LatencyTimeSpent'), ENT_QUOTES)
- );
- while ($row = Database :: fetch_array($res)) {
- $list[] = array (
- 'order_id' => ($row['order_id'] + 1),
- 'id' => urldecode($row['interaction_id']),
- 'type' => $row['interaction_type'],
- 'time' => $row['completion_time'],
-
- 'correct_responses' => '',
- 'student_response' => $row['student_response'],
- 'result' => $row['result'],
- 'latency' => $row['latency']
- );
- }
- }
- return $list;
- }
-
- public function get_objectives_count_from_db($lp_iv_id = 0) {
- if (empty ($lp_iv_id)) {
- return -1;
- }
- $table = Database :: get_course_table(TABLE_LP_IV_OBJECTIVE);
- $sql = "SELECT count(*) FROM $table WHERE lp_iv_id = $lp_iv_id";
- $res = Database::query($sql);
- $row = Database :: fetch_array($res);
- $num = $row[0];
- return $num;
- }
-
- public function get_iv_objectives_array($lp_iv_id = 0) {
- $list = array();
- $table = Database :: get_course_table(TABLE_LP_IV_OBJECTIVE);
- $sql = "SELECT * FROM $table WHERE lp_iv_id = $lp_iv_id ORDER BY order_id ASC";
- $res = Database::query($sql);
- $num = Database :: num_rows($res);
- if ($num > 0) {
- $list[] = array (
- 'order_id' => api_htmlentities(get_lang('Order'), ENT_QUOTES),
- 'objective_id' => api_htmlentities(get_lang('ObjectiveID'), ENT_QUOTES),
- 'score_raw' => api_htmlentities(get_lang('ObjectiveRawScore'), ENT_QUOTES),
- 'score_max' => api_htmlentities(get_lang('ObjectiveMaxScore'), ENT_QUOTES),
- 'score_min' => api_htmlentities(get_lang('ObjectiveMinScore'), ENT_QUOTES),
- 'status' => api_htmlentities(get_lang('ObjectiveStatus'), ENT_QUOTES)
- );
- while ($row = Database :: fetch_array($res)) {
- $list[] = array (
- 'order_id' => ($row['order_id'] + 1),
- 'objective_id' => urldecode($row['objective_id']),
- 'score_raw' => $row['score_raw'],
- 'score_max' => $row['score_max'],
- 'score_min' => $row['score_min'],
- 'status' => $row['status']
- );
- }
- }
- return $list;
- }
-
- public function get_toc() {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::get_toc()', 0);
- }
- $toc = array ();
-
- foreach ($this->ordered_items as $item_id) {
- if ($this->debug > 2) {
- error_log('New LP - learnpath::get_toc(): getting info for item ' . $item_id, 0);
- }
-
- $toc[] = array (
- 'id' => $item_id,
- 'title' => $this->items[$item_id]->get_title(),
-
- 'status' => $this->items[$item_id]->get_status(),
- 'level' => $this->items[$item_id]->get_level(),
- 'type' => $this->items[$item_id]->get_type(),
- 'description' => $this->items[$item_id]->get_description(),
- 'path' => $this->items[$item_id]->get_path(),
- );
- }
- if ($this->debug > 2) {
- error_log('New LP - In learnpath::get_toc() - TOC array: ' . print_r($toc, true), 0);
- }
- return $toc;
- }
-
- public function get_items_details_as_js($varname = 'olms.lms_item_types') {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::get_items_details_as_js()', 0);
- }
- $toc = $varname.' = new Array();';
-
- foreach ($this->ordered_items as $item_id) {
- if ($this->debug > 2) {
- error_log('New LP - learnpath::get_items_details_as_js(): getting info for item ' . $item_id, 0);
- }
- $toc.= $varname."['i$item_id'] = '".$this->items[$item_id]->get_type()."';";
- }
- if ($this->debug > 2) {
- error_log('New LP - In learnpath::get_items_details_as_js() - TOC array: ' . print_r($toc, true), 0);
- }
- return $toc;
- }
-
- public function get_type($get_name = false) {
- $res = false;
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::get_type()', 0);
- }
- if (!empty ($this->type)) {
- if ($get_name) {
-
- } else {
- $res = $this->type;
- }
- }
- if ($this->debug > 2) {
- error_log('New LP - In learnpath::get_type() - Returning ' . ($res ? $res : 'false'), 0);
- }
- return $res;
- }
-
- public function get_type_static($lp_id = 0) {
- $tbl_lp = Database :: get_course_table(TABLE_LP_MAIN);
- $sql = "SELECT lp_type FROM $tbl_lp WHERE id = '" . $lp_id . "'";
- $res = Database::query($sql);
- if ($res === false) {
- return null;
- }
- if (Database :: num_rows($res) <= 0) {
- return null;
- }
- $row = Database :: fetch_array($res);
- return $row['lp_type'];
- }
-
- public function get_flat_ordered_items_list($lp, $parent = 0, $course_db = '') {
-
- $list = array();
- if (empty ($lp)) {
- return false;
- }
- $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM, $course_db);
- $sql = "SELECT * FROM $tbl_lp_item WHERE lp_id = $lp AND parent_item_id = $parent ORDER BY display_order";
- $res = Database::query($sql);
- while ($row = Database :: fetch_array($res)) {
- $sublist = learnpath :: get_flat_ordered_items_list($lp, $row['id'], $course_db);
- $list[] = $row['id'];
- foreach ($sublist as $item) {
- $list[] = $item;
- }
- }
- return $list;
- }
-
- public function get_html_toc() {
- $is_allowed_to_edit = api_is_allowed_to_edit(null, true);
- $charset = api_get_system_encoding();
- $display_action_links_with_icons = false;
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::get_html_toc()', 0);
- }
- $list = $this->get_toc();
-
-
-
- $html = '<div id="scorm_title" class="scorm_title"><div class="scorm_title_text">' . Security::remove_XSS($this->get_name()) . '</div></div>';
-
- if ($is_allowed_to_edit) {
- $gradebook = Security :: remove_XSS($_GET['gradebook']);
-
- if ($this->get_lp_session_id() == api_get_session_id()) {
- $html .= '<div id="actions_lp" class="actions_lp">';
- if ($display_action_links_with_icons) {
- $html .= '<div style = "text-align:center;">';
- $html .= "<a href='lp_controller.php?" . api_get_cidreq() . "&action=build&lp_id=" . $this->lp_id . "' target='_parent'>" . Display :: return_icon('build_learnpath.png', get_lang('Build'),'','32')."</a>";
- $html .= "<a href='lp_controller.php?" . api_get_cidreq() . "&action=admin_view&lp_id=" . $this->lp_id . "' target='_parent'>" . Display :: return_icon('move_learnpath.png', get_lang('BasicOverview'),'','32')."</a>";
- $html .= '<span>' . Display :: return_icon('view_remove_na.png', get_lang('Display'),'','32').'</span><br />';
- $html .= '<a href="lp_controller.php?' . api_get_cidreq() . '">'. get_lang('ReturnToLPList') . '</a>';
- $html .= '</div>';
- } else {
- $html .= '<div style = "text-align:center;">';
- $html .= "<a href='lp_controller.php?" . api_get_cidreq() . "&gradebook=$gradebook&action=build&lp_id=" . $this->lp_id . "' target='_parent'>" . get_lang('Build') . "</a>";
- $html .= "<a href='lp_controller.php?" . api_get_cidreq() . "&action=admin_view&lp_id=" . $this->lp_id . "' target='_parent'>" . get_lang('BasicOverview') . "</a>";
- $html .= '<span><b>' . get_lang('Display') . '</b></span><br />';
- $html .= '<a href="lp_controller.php?' . api_get_cidreq() . '">'. get_lang('ReturnToLPList') . '</a>';
- $html .= '</div>';
- }
- $html .= '</div>';
- }
- }
- $html .= '<div id="inner_lp_toc" class="inner_lp_toc">';
- require_once 'resourcelinker.inc.php';
-
- $mycurrentitemid = $this->get_current_item_id();
- $color_counter = 0;
- $i = 0;
- foreach ($list as $item) {
- if ($this->debug > 2) {
- error_log('New LP - learnpath::get_html_toc(): using item ' . $item['id'], 0);
- }
-
- $icon_name = array (
- 'not attempted' => '../img/notattempted.gif',
- 'incomplete' => '../img/incomplete.png',
- 'failed' => '../img/delete.png',
- 'completed' => '../img/completed.png',
- 'passed' => '../img/passed.gif',
- 'succeeded' => '../img/succeeded.gif',
- 'browsed' => '../img/completed.png',
- );
- $style = 'scorm_item';
- $scorm_color_background = 'scorm_item';
- $style_item = 'scorm_item';
- $current = false;
- if ($item['id'] == $this->current) {
- $style = 'scorm_item_highlight';
- $scorm_color_background = 'scorm_item_highlight';
- } else
- if ($color_counter % 2 == 0) {
- $scorm_color_background = 'scorm_item_1';
- } else {
- $scorm_color_background = 'scorm_item_2';
- }
- if ($scorm_color_background != '') {
- $html .= '<div id="toc_' . $item['id'] . '" class="' . $scorm_color_background . '">';
- }
-
- if ($item['type'] != 'dokeos_module' && $item['type'] != 'dokeos_chapter') {
- $html .= '<a name="atoc_' . $item['id'] . '" />';
- $html .= '<div class="' . $style_item . '" style="padding-left: ' . ($item['level'] * 1.5) . 'em; padding-right:' . ($item['level'] / 2) . 'em" title="' . $item['description'] . '" >';
- } else {
- $html .= '<div class="' . $style_item . '" style="padding-left: ' . ($item['level'] * 2) . 'em; padding-right:' . ($item['level'] * 1.5) . 'em" title="' . $item['description'] . '" >';
- }
- $title = $item['title'];
- if (empty ($title)) {
- $title = rl_get_resource_name(api_get_course_id(), $this->get_id(), $item['id']);
- }
- $title = Security::remove_XSS($title);
- if ($item['type'] != 'dokeos_chapter' && $item['type'] != 'dir' && $item['type'] != 'dokeos_module') {
-
- $url = $this->get_link('http', $item['id']);
-
-
-
- $html .= '<a href="" onClick="switch_item(' .$mycurrentitemid . ',' .$item['id'] . ');' .'return false;" >' . stripslashes($title) . '</a>';
- } elseif ($item['type'] == 'dokeos_module' || $item['type'] == 'dokeos_chapter') {
- $html .= "<img align='absbottom' width='13' height='13' src='../img/lp_dokeos_module.png'> " . stripslashes($title);
- } elseif ($item['type'] == 'dir') {
- $html .= stripslashes($title);
- }
- $tbl_track_e_exercises = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
- $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
- $user_id = api_get_user_id();
- $course_id = api_get_course_id();
- $sql = "SELECT path FROM $tbl_track_e_exercises, $tbl_lp_item
- WHERE path = '" . $item['path'] . "' AND exe_user_id = '$user_id' AND exe_cours_id = '$course_id' AND path = exe_exo_id AND status <> 'incomplete'";
- $result = Database::query($sql);
- $count = Database :: num_rows($result);
- if ($item['type'] == 'quiz') {
- if ($item['status'] == 'completed') {
- $html .= " <img id='toc_img_" . $item['id'] . "' src='" . $icon_name[$item['status']] . "' alt='" . substr($item['status'], 0, 1) . "' width='14' />";
- }
- } else {
- if ($item['type'] != 'dokeos_chapter' && $item['type'] != 'dokeos_module' && $item['type'] != 'dir') {
- $html .= " <img id='toc_img_" . $item['id'] . "' src='" . $icon_name[$item['status']] . "' alt='" . substr($item['status'], 0, 1) . "' width='14' />";
- }
- }
- $html .= "</div>";
- if ($scorm_color_background != '') {
- $html .= '</div>';
- }
- $color_counter++;
- }
- $html .= "</div>";
- return $html;
- }
-
- public function get_maker() {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::get_maker()', 0);
- }
- if (!empty ($this->maker)) {
- return $this->maker;
- } else {
- return '';
- }
- }
-
- public function get_message() {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::get_message()', 0);
- }
- return $this->message;
- }
-
- public function get_name() {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::get_name()', 0);
- }
- if (!empty ($this->name)) {
- return $this->name;
- } else {
- return 'N/A';
- }
- }
-
- public function get_link($type = 'http', $item_id = null) {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::get_link(' . $type . ',' . $item_id . ')', 0);
- }
- if (empty($item_id)) {
- if ($this->debug > 2) {
- error_log('New LP - In learnpath::get_link() - no item id given in learnpath::get_link(), using current: ' . $this->get_current_item_id(), 0);
- }
- $item_id = $this->get_current_item_id();
- }
- if (empty ($item_id)) {
- if ($this->debug > 2) {
- error_log('New LP - In learnpath::get_link() - no current item id found in learnpath object', 0);
- }
-
-
- $item_id = $this->first();
- return '';
- }
- $file = '';
- $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
- $lp_item_table = Database :: get_course_table(TABLE_LP_ITEM);
- $lp_item_view_table = Database :: get_course_table(TABLE_LP_ITEM_VIEW);
- $item_id = Database::escape_string($item_id);
- $sel = "SELECT l.lp_type as ltype, l.path as lpath, li.item_type as litype, li.path as lipath, li.parameters as liparams " .
- "FROM $lp_table l, $lp_item_table li WHERE li.id = $item_id AND li.lp_id = l.id";
- if ($this->debug > 2) {
- error_log('New LP - In learnpath::get_link() - selecting item ' . $sel, 0);
- }
- $res = Database::query($sel);
- if (Database :: num_rows($res) > 0) {
- $row = Database :: fetch_array($res);
-
- $lp_type = $row['ltype'];
- $lp_path = $row['lpath'];
- $lp_item_type = $row['litype'];
- $lp_item_path = $row['lipath'];
- $lp_item_params = $row['liparams'];
- if (empty ($lp_item_params) && strpos($lp_item_path, '?') !== false) {
- list ($lp_item_path, $lp_item_params) = explode('?', $lp_item_path);
- }
-
-
-
-
-
- $sys_course_path = api_get_path(SYS_COURSE_PATH) . api_get_course_path();
- if ($type == 'http') {
- $course_path = api_get_path(WEB_COURSE_PATH) . api_get_course_path();
- } else {
- $course_path = $sys_course_path;
- }
-
- if (in_array($lp_item_type, array('quiz', 'document', 'link', 'forum', 'thread', 'student_publication'))) {
- $lp_type = 1;
- }
-
-
-
- switch ($lp_type) {
- case 1 :
- if ($lp_item_type == 'dokeos_chapter') {
- $file = 'lp_content.php?type=dir';
- } else {
- require_once 'resourcelinker.inc.php';
- $file = rl_get_resource_link_for_learnpath(api_get_course_id(), $this->get_id(), $item_id);
-
-
- if ($lp_item_type == 'link') {
- require_once api_get_path(LIBRARY_PATH).'link.lib.php';
- if (is_youtube_link($file)) {
- $src = get_youtube_video_id($file);
- $file = 'embed.php?type=youtube&src='.$src;
- }
- } else {
-
- $lp_item_id = $this->get_current_item_id();
- $lp_view_id = $this->get_view_id();
- $prevent_reinit = $this->items[$this->current]->get_prevent_reinit();
- $list = $this->get_toc();
- $type_quiz = false;
-
- foreach ($list as $toc) {
- if ($toc['id'] == $lp_item_id && ($toc['type'] == 'quiz')) {
- $type_quiz = true;
- }
- }
-
- if ($type_quiz) {
- $lp_item_id = Database :: escape_string($lp_item_id);
- $lp_view_id = Database :: escape_string($lp_view_id);
- $sql = "SELECT count(*) FROM $lp_item_view_table WHERE lp_item_id='" . (int) $lp_item_id . "' AND lp_view_id ='" . (int) $lp_view_id . "' AND status='completed'";
- $result = Database::query($sql);
- $row_count = Database :: fetch_row($result);
- $count_item_view = (int) $row_count[0];
- $not_multiple_attempt = 0;
- if ($prevent_reinit === 1 && $count_item_view > 0) {
- $not_multiple_attempt = 1;
- }
- $file .= '¬_multiple_attempt=' . $not_multiple_attempt;
- }
-
- $tmp_array = explode('/', $file);
- $document_name = $tmp_array[count($tmp_array) - 1];
- if (strpos($document_name, '_DELETED_')) {
- $file = 'blank.php?error=document_deleted';
- }
- }
- }
- break;
- case 2 :
- if ($this->debug > 2) {
- error_log('New LP - In learnpath::get_link() ' . __LINE__ . ' - Item type: ' . $lp_item_type, 0);
- }
- if ($lp_item_type != 'dir') {
-
-
-
-
-
-
-
- if (preg_match('#^[a-zA-Z]{2,5}://#', $lp_item_path) != 0) {
- if ($this->debug > 2) {
- error_log('New LP - In learnpath::get_link() ' . __LINE__ . ' - Found match for protocol in ' . $lp_item_path, 0);
- }
-
- $file = $lp_item_path;
- } else {
- if ($this->debug > 2) {
- error_log('New LP - In learnpath::get_link() ' . __LINE__ . ' - No starting protocol in ' . $lp_item_path, 0);
- }
-
- $lp_item_path = preg_replace('/%2F/', '/', $lp_item_path);
- $lp_item_path = preg_replace('/%3A/', ':', $lp_item_path);
-
- $file = $course_path . '/scorm/' . $lp_path . '/' . $lp_item_path;
-
- $file = str_replace('//', '/', $file);
- $file = str_replace(':/', '://', $file);
- if (substr($lp_path, -1) == '/') {
- $lp_path = substr($lp_path, 0, -1);
- }
- if (!is_file(realpath($sys_course_path . '/scorm/' . $lp_path . '/' . $lp_item_path))) {
-
- $decoded = html_entity_decode($lp_item_path);
- list ($decoded) = explode('?', $decoded);
- if (!is_file(realpath($sys_course_path . '/scorm/' . $lp_path . '/' . $decoded))) {
- require_once 'resourcelinker.inc.php';
- $file = rl_get_resource_link_for_learnpath(api_get_course_id(), $this->get_id(), $item_id);
- if (empty($file)) {
- $file = 'blank.php?error=document_not_found';
- } else {
- $tmp_array = explode('/', $file);
- $document_name = $tmp_array[count($tmp_array) - 1];
- if (strpos($document_name, '_DELETED_')) {
- $file = 'blank.php?error=document_deleted';
- } else {
- $file = 'blank.php?error=document_not_found';
- }
- }
- } else {
- $file = $course_path . '/scorm/' . $lp_path . '/' . $decoded;
- }
- }
- }
-
-
-
-
-
- if ($file != 'blank.php') {
- $file .= (strstr($file, '?') === false ? '?' : '') . $lp_item_params;
- }
- } else {
- $file = 'lp_content.php?type=dir';
- }
- break;
- case 3 :
- if ($this->debug > 2) {
- error_log('New LP - In learnpath::get_link() ' . __LINE__ . ' - Item type: ' . $lp_item_type, 0);
- }
-
- $aicc_append = '?aicc_sid=' . urlencode(session_id()) . '&aicc_url=' . urlencode(api_get_path(WEB_CODE_PATH) . 'newscorm/aicc_hacp.php') . '&';
- if ($lp_item_type != 'dir') {
-
-
-
-
-
-
- if (preg_match('#^[a-zA-Z]{2,5}://#', $lp_item_path) != 0) {
- if ($this->debug > 2) {
- error_log('New LP - In learnpath::get_link() ' . __LINE__ . ' - Found match for protocol in ' . $lp_item_path, 0);
- }
-
- $file = $lp_item_path;
-
-
- if (stripos($file, '<servername>') !== false) {
-
- $web_course_path = str_replace('https://', '', str_replace('http://', '', $course_path));
- $file = str_replace('<servername>', $web_course_path . '/scorm/' . $lp_path, $lp_item_path);
- }
-
- $file .= $aicc_append;
- } else {
- if ($this->debug > 2) {
- error_log('New LP - In learnpath::get_link() ' . __LINE__ . ' - No starting protocol in ' . $lp_item_path, 0);
- }
-
- $lp_item_path = preg_replace('/%2F/', '/', $lp_item_path);
- $lp_item_path = preg_replace('/%3A/', ':', $lp_item_path);
-
- $file = $course_path . '/scorm/' . $lp_path . '/' . $lp_item_path;
-
- $file = str_replace('//', '/', $file);
- $file = str_replace(':/', '://', $file);
- $file .= $aicc_append;
- }
- } else {
- $file = 'lp_content.php?type=dir';
- }
- break;
- case 4 :
- break;
- default :
- break;
- }
- }
- if ($this->debug > 2) {
- error_log('New LP - In learnpath::get_link() - returning "' . $file . '" from get_link', 0);
- }
- return $file;
- }
-
- public function get_view($attempt_num = 0) {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::get_view()', 0);
- }
- $search = '';
-
- if ($attempt_num != 0 AND intval(strval($attempt_num)) == $attempt_num) {
- $search = 'AND view_count = ' . $attempt_num;
- }
-
- $lp_view_table = Database :: get_course_table(TABLE_LP_VIEW);
- $sql = "SELECT id, view_count FROM $lp_view_table " .
- "WHERE lp_id = " . $this->get_id() . " " .
- "AND user_id = " . $this->get_user_id() . " " .
- $search .
- " ORDER BY view_count DESC";
- $res = Database::query($sql);
- if (Database :: num_rows($res) > 0) {
- $row = Database :: fetch_array($res);
- $this->lp_view_id = $row['id'];
- } else {
-
- $sql = "INSERT INTO $lp_view_table(lp_id,user_id,view_count)" .
- "VALUES (" . $this->get_id() . "," . $this->get_user_id() . ",1)";
- $res = Database::query($sql);
- $id = Database :: insert_id();
- $this->lp_view_id = $id;
- }
- return $this->lp_view_id;
- }
-
- public function get_view_id() {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::get_view_id()', 0);
- }
- if (!empty ($this->lp_view_id)) {
- return $this->lp_view_id;
- } else {
- return 0;
- }
- }
-
- public function get_update_queue() {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::get_update_queue()', 0);
- }
- return $this->update_queue;
- }
-
- public function get_user_id() {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::get_user_id()', 0);
- }
- if (!empty ($this->user_id)) {
- return $this->user_id;
- } else {
- return false;
- }
- }
-
- public function has_audio() {
- if ($this->debug > 1) {
- error_log('New LP - In learnpath::has_audio()', 0);
- }
- $has = false;
- foreach ($this->items as $i => $item) {
- if (!empty ($this->items[$i]->audio)) {
- $has = true;
- break;
- }
- }
- return $has;
- }
-
- public function log($msg) {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::log()', 0);
- }
-
- $this->error .= $msg . "\n";
- return true;
- }
-
- public function move_item($id, $direction) {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::move_item(' . $id . ',' . $direction . ')', 0);
- }
- if (empty ($id) or empty ($direction)) {
- return false;
- }
- $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
- $sql_sel = "
- SELECT *
- FROM " . $tbl_lp_item . "
- WHERE id = " . $id;
- $res_sel = Database::query($sql_sel);
-
- if (Database :: num_rows($res_sel) < 1) {
- return false;
- }
-
- $row = Database :: fetch_array($res_sel);
- $previous = $row['previous_item_id'];
- $next = $row['next_item_id'];
- $display = $row['display_order'];
- $parent = $row['parent_item_id'];
- $lp = $row['lp_id'];
-
- switch ($direction) {
- case 'up' :
- if ($this->debug > 2) {
- error_log('Movement up detected', 0);
- }
- if ($display <= 1) {
- } else {
- $sql_sel2 = "SELECT *
- FROM $tbl_lp_item
- WHERE id = $previous";
- if ($this->debug > 2) {
- error_log('Selecting previous: ' . $sql_sel2, 0);
- }
- $res_sel2 = Database::query($sql_sel2);
- if (Database :: num_rows($res_sel2) < 1) {
- $previous_previous = 0;
- }
-
- $row2 = Database :: fetch_array($res_sel2);
- $previous_previous = $row2['previous_item_id'];
-
- if ($previous_previous != 0) {
- $sql_upd2 = "UPDATE $tbl_lp_item SET next_item_id = $id WHERE id = $previous_previous";
- if ($this->debug > 2) {
- error_log($sql_upd2, 0);
- }
- $res_upd2 = Database::query($sql_upd2);
- }
-
- if ($previous != 0) {
- $sql_upd2 = "UPDATE $tbl_lp_item SET next_item_id = $next, previous_item_id = $id, display_order = display_order +1 WHERE id = $previous";
- if ($this->debug > 2) {
- error_log($sql_upd2, 0);
- }
- $res_upd2 = Database::query($sql_upd2);
- }
-
- if ($id != 0) {
- $sql_upd2 = "UPDATE $tbl_lp_item SET next_item_id = $previous, previous_item_id = $previous_previous, display_order = display_order-1 WHERE id = $id";
- if ($this->debug > 2) {
- error_log($sql_upd2, 0);
- }
- $res_upd2 = Database::query($sql_upd2);
- }
-
- if ($next != 0) {
- $sql_upd2 = "UPDATE $tbl_lp_item SET previous_item_id = $previous WHERE id = $next";
- if ($this->debug > 2) {
- error_log($sql_upd2, 0);
- }
- $res_upd2 = Database::query($sql_upd2);
- }
- $display = $display -1;
- }
- break;
- case 'down' :
- if ($this->debug > 2) {
- error_log('Movement down detected', 0);
- }
- if ($next == 0) {
- } else {
- $sql_sel2 = "SELECT * FROM $tbl_lp_item WHERE id = $next";
- if ($this->debug > 2) {
- error_log('Selecting next: ' . $sql_sel2, 0);
- }
- $res_sel2 = Database::query($sql_sel2);
- if (Database :: num_rows($res_sel2) < 1) {
- $next_next = 0;
- }
-
- $row2 = Database :: fetch_array($res_sel2);
- $next_next = $row2['next_item_id'];
-
- if ($previous != 0) {
- $sql_upd2 = "UPDATE $tbl_lp_item SET next_item_id = $next WHERE id = $previous";
- $res_upd2 = Database::query($sql_upd2);
- }
-
- if ($id != 0) {
- $sql_upd2 = "UPDATE $tbl_lp_item SET previous_item_id = $next, next_item_id = $next_next, display_order = display_order+1 WHERE id = $id";
- $res_upd2 = Database::query($sql_upd2);
- }
-
- if ($next != 0) {
- $sql_upd2 = "UPDATE $tbl_lp_item SET previous_item_id = $previous, next_item_id = $id, display_order = display_order-1 WHERE id = $next";
- $res_upd2 = Database::query($sql_upd2);
- }
-
- if ($next_next != 0) {
- $sql_upd2 = "UPDATE $tbl_lp_item SET previous_item_id = $id WHERE id = $next_next";
- $res_upd2 = Database::query($sql_upd2);
- }
- $display = $display +1;
- }
- break;
- default :
- return false;
- }
- return $display;
- }
-
- public function move_up($lp_id) {
- $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
- $sql = "SELECT * FROM $lp_table ORDER BY display_order";
- $res = Database::query($sql);
- if ($res === false)
- return false;
- $lps = array ();
- $lp_order = array ();
- $num = Database :: num_rows($res);
-
-
- if ($num > 0) {
- $i = 1;
- while ($row = Database :: fetch_array($res)) {
- if ($row['display_order'] != $i) {
- $need_fix = true;
- $sql_u = "UPDATE $lp_table SET display_order = $i WHERE id = " . $row['id'];
- $res_u = Database::query($sql_u);
- }
- $row['display_order'] = $i;
- $lps[$row['id']] = $row;
- $lp_order[$i] = $row['id'];
- $i++;
- }
- }
- if ($num > 1) {
- $order = $lps[$lp_id]['display_order'];
- if ($order > 1) {
- $sql_u1 = "UPDATE $lp_table SET display_order = $order WHERE id = " . $lp_order[$order - 1];
- $res_u1 = Database::query($sql_u1);
- $sql_u2 = "UPDATE $lp_table SET display_order = " . ($order - 1) . " WHERE id = " . $lp_id;
- $res_u2 = Database::query($sql_u2);
- }
- }
- }
-
- public function move_down($lp_id) {
- $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
- $sql = "SELECT * FROM $lp_table ORDER BY display_order";
- $res = Database::query($sql);
- if ($res === false)
- return false;
- $lps = array ();
- $lp_order = array ();
- $num = Database :: num_rows($res);
- $max = 0;
-
-
- if ($num > 0) {
- $i = 1;
- while ($row = Database :: fetch_array($res)) {
- $max = $i;
- if ($row['display_order'] != $i) {
- $need_fix = true;
- $sql_u = "UPDATE $lp_table SET display_order = $i WHERE id = " . $row['id'];
- $res_u = Database::query($sql_u);
- }
- $row['display_order'] = $i;
- $lps[$row['id']] = $row;
- $lp_order[$i] = $row['id'];
- $i++;
- }
- }
- if ($num > 1) {
- $order = $lps[$lp_id]['display_order'];
- if ($order < $max) {
- $sql_u1 = "UPDATE $lp_table SET display_order = $order WHERE id = " . $lp_order[$order + 1];
- $res_u1 = Database::query($sql_u1);
- $sql_u2 = "UPDATE $lp_table SET display_order = " . ($order + 1) . " WHERE id = " . $lp_id;
- $res_u2 = Database::query($sql_u2);
- }
- }
- }
-
- public function next() {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::next()', 0);
- }
- $this->last = $this->get_current_item_id();
- $this->items[$this->last]->save(false, $this->prerequisites_match($this->last));
- $this->autocomplete_parents($this->last);
- $new_index = $this->get_next_index();
- if ($this->debug > 2) {
- error_log('New LP - New index: ' . $new_index, 0);
- }
- $this->index = $new_index;
- if ($this->debug > 2) {
- error_log('New LP - Now having orderedlist[' . $new_index . '] = ' . $this->ordered_items[$new_index], 0);
- }
- $this->current = $this->ordered_items[$new_index];
- if ($this->debug > 2) {
- error_log('New LP - new item id is ' . $this->current . '-' . $this->get_current_item_id(), 0);
- }
- }
-
- public function open($id) {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::open()', 0);
- }
-
-
-
-
-
-
- $this->index = 0;
- }
-
- public function prerequisites_match($item = null) {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::prerequisites_match()', 0);
- }
- if (empty ($item)) {
- $item = $this->current;
- }
- if (is_object($this->items[$item])) {
- $prereq_string = $this->items[$item]->get_prereq_string();
- if (empty ($prereq_string)) {
- return true;
- }
-
- $prereq_string = str_replace(' ', '', $prereq_string);
- if ($this->debug > 0) {
- error_log('Found prereq_string: ' . $prereq_string, 0);
- }
-
- $result = $this->items[$item]->parse_prereq($prereq_string, $this->items, $this->refs_list, $this->get_user_id());
- if ($result === false) {
- $this->set_error_msg($this->items[$item]->prereq_alert);
- }
- } else {
- $result = true;
- if ($this->debug > 1) {
- error_log('New LP - $this->items[' . $item . '] was not an object', 0);
- }
- }
- if ($this->debug > 1) {
- error_log('New LP - End of prerequisites_match(). Error message is now ' . $this->error, 0);
- }
- return $result;
- }
-
- public function previous() {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::previous()', 0);
- }
- $this->last = $this->get_current_item_id();
- $this->items[$this->last]->save(false, $this->prerequisites_match($this->last));
- $this->autocomplete_parents($this->last);
- $new_index = $this->get_previous_index();
- $this->index = $new_index;
- $this->current = $this->ordered_items[$new_index];
- }
-
- public function toggle_visibility($lp_id, $set_visibility = 1) {
-
- $action = 'visible';
- if ($set_visibility != 1) {
- $action = 'invisible';
- }
- return api_item_property_update(api_get_course_info(), TOOL_LEARNPATH, $lp_id, $action, api_get_user_id());
- }
-
- public function toggle_publish($lp_id, $set_visibility = 'v') {
-
- $tbl_lp = Database :: get_course_table(TABLE_LP_MAIN);
- $sql = "SELECT * FROM $tbl_lp where id=$lp_id";
- $result = Database::query($sql);
- $row = Database :: fetch_array($result);
- $name = domesticate($row['name']);
- if ($set_visibility == 'i') {
- $s = $name . " " . get_lang('_no_published');
- $dialogBox = $s;
- $v = 0;
- }
- if ($set_visibility == 'v') {
- $s = $name . " " . get_lang('_published');
- $dialogBox = $s;
- $v = 1;
- }
- $session_id = api_get_session_id();
- $session_condition = api_get_session_condition($session_id);
- $tbl_tool = Database :: get_course_table(TABLE_TOOL_LIST);
- $link = 'newscorm/lp_controller.php?action=view&lp_id=' . $lp_id.'&id_session='.$session_id;
- $sql = "SELECT * FROM $tbl_tool where name='$name' and image='scormbuilder.gif' and link LIKE '$link%' $session_condition";
- $result = Database::query($sql);
- $num = Database :: num_rows($result);
- $row2 = Database :: fetch_array($result);
-
- if (($set_visibility == 'i') && ($num > 0)) {
- $sql = "DELETE FROM $tbl_tool WHERE (name='$name' and image='scormbuilder.gif' and link LIKE '$link%' $session_condition)";
- } elseif (($set_visibility == 'v') && ($num == 0)) {
- $sql = "INSERT INTO $tbl_tool (name, link, image, visibility, admin, address, added_tool, session_id) VALUES ('$name','$link','scormbuilder.gif','$v','0','pastillegris.gif',0, $session_id)";
- } else {
-
- }
- $result = Database::query($sql);
-
- }
-
- public function restart() {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::restart()', 0);
- }
-
-
-
- $session_id = api_get_session_id();
- $lp_view_table = Database :: get_course_table(TABLE_LP_VIEW);
- $sql = "INSERT INTO $lp_view_table (lp_id, user_id, view_count, session_id) " .
- "VALUES (" . $this->lp_id . "," . $this->get_user_id() . "," . ($this->attempt + 1) . ", $session_id)";
- if ($this->debug > 2) {
- error_log('New LP - Inserting new lp_view for restart: ' . $sql, 0);
- }
- $res = Database::query($sql);
- if ($view_id = Database :: insert_id($res)) {
- $this->lp_view_id = $view_id;
- $this->attempt = $this->attempt + 1;
- } else {
- $this->error = 'Could not insert into item_view table...';
- return false;
- }
- $this->autocomplete_parents($this->current);
- foreach ($this->items as $index => $dummy) {
- $this->items[$index]->restart();
- $this->items[$index]->set_lp_view($this->lp_view_id);
- }
- $this->first();
- return true;
- }
-
- public function save_current() {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::save_current()', 0);
- }
-
-
- if ($this->debug > 2) {
- error_log('New LP - save_current() saving item ' . $this->current, 0);
- }
- if ($this->debug > 2) {
- error_log('' . print_r($this->items, true), 0);
- }
- if (is_object($this->items[$this->current])) {
-
- $res = $this->items[$this->current]->save(false, $this->prerequisites_match($this->current));
- $this->autocomplete_parents($this->current);
- $status = $this->items[$this->current]->get_status();
- $this->append_message('new_item_status: ' . $status);
- $this->update_queue[$this->current] = $status;
- return $res;
- }
- return false;
- }
-
- public function save_item($item_id = null, $from_outside = true) {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::save_item(' . $item_id . ',' . $from_outside . ')', 0);
- }
-
-
- if (empty ($item_id)) {
- $item_id = $this->escape_string($_REQUEST['id']);
- }
- if (empty ($item_id)) {
- $item_id = $this->get_current_item_id();
- }
- if ($this->debug > 2) {
- error_log('New LP - save_current() saving item ' . $item_id, 0);
- }
- if (is_object($this->items[$item_id])) {
- $res = $this->items[$item_id]->save($from_outside, $this->prerequisites_match($item_id));
-
- $this->autocomplete_parents($item_id);
- $status = $this->items[$item_id]->get_status();
- $this->append_message('new_item_status: ' . $status);
- $this->update_queue[$item_id] = $status;
- return $res;
- }
- return false;
- }
-
- public function save_last() {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::save_last()', 0);
- }
- $session_condition = api_get_session_condition(api_get_session_id(), true, false);
- $table = Database :: get_course_table(TABLE_LP_VIEW);
- if (isset ($this->current)) {
- if ($this->debug > 2) {
- error_log('New LP - Saving current item (' . $this->current . ') for later review', 0);
- }
- $sql = "UPDATE $table SET last_item = " . Database::escape_string($this->get_current_item_id()). " " .
- "WHERE lp_id = " . $this->get_id() . " AND user_id = " . $this->get_user_id().' '.$session_condition;
- if ($this->debug > 2) {
- error_log('New LP - Saving last item seen : ' . $sql, 0);
- }
- $res = Database::query($sql);
- }
-
- list($progress, $text) = $this->get_progress_bar_text('%');
- if ($progress >= 0 && $progress <= 100) {
- $progress = (int) $progress;
- $sql = "UPDATE $table SET progress = $progress " .
- "WHERE lp_id = " . $this->get_id() . " AND " .
- "user_id = " . $this->get_user_id().' '.$session_condition;
- $res = Database::query($sql);
- $this->progress_db = $progress;
- }
- }
-
- public function set_current_item($item_id = null) {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::set_current_item(' . $item_id . ')', 0);
- }
- if (empty ($item_id)) {
- if ($this->debug > 2) {
- error_log('New LP - No new current item given, ignore...', 0);
- }
-
- } else {
- if ($this->debug > 2) {
- error_log('New LP - New current item given is ' . $item_id . '...', 0);
- }
- if (is_numeric($item_id)) {
- $item_id = $this->escape_string($item_id);
-
- $this->last = $this->current;
- $this->current = $item_id;
-
- foreach ($this->ordered_items as $index => $item) {
- if ($item == $this->current) {
- $this->index = $index;
- break;
- }
- }
- if ($this->debug > 2) {
- error_log('New LP - set_current_item(' . $item_id . ') done. Index is now : ' . $this->index, 0);
- }
- } else {
- error_log('New LP - set_current_item(' . $item_id . ') failed. Not a numeric value: ', 0);
- }
- }
- }
-
- public function set_encoding($enc = 'UTF-8') {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::set_encoding()', 0);
- }
-
- $enc = api_refine_encoding_id($enc);
- if (empty($enc)) {
- $enc = api_get_system_encoding();
- }
- if (api_is_encoding_supported($enc)) {
- $lp = $this->get_id();
- if ($lp != 0) {
- $tbl_lp = Database :: get_course_table(TABLE_LP_MAIN);
- $sql = "UPDATE $tbl_lp SET default_encoding = '$enc' WHERE id = " . $lp;
- $res = Database::query($sql);
- return $res;
- }
- }
- return false;
- }
-
- public function set_jslib($lib = '') {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::set_jslib()', 0);
- }
- $lp = $this->get_id();
- if ($lp != 0) {
- $tbl_lp = Database :: get_course_table(TABLE_LP_MAIN);
- $sql = "UPDATE $tbl_lp SET js_lib = '$lib' WHERE id = " . $lp;
- $res = Database::query($sql);
- return $res;
- } else {
- return false;
- }
- }
-
- public function set_maker($name = '') {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::set_maker()', 0);
- }
- if (empty ($name))
- return false;
- $this->maker = $this->escape_string($name);
- $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
- $lp_id = $this->get_id();
- $sql = "UPDATE $lp_table SET content_maker = '" . $this->maker . "' WHERE id = '$lp_id'";
- if ($this->debug > 2) {
- error_log('New LP - lp updated with new content_maker : ' . $this->maker, 0);
- }
- $res = Database::query($sql);
- return true;
- }
-
- public function set_name($name = '') {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::set_name()', 0);
- }
- if (empty ($name))
- return false;
- $this->name = $this->escape_string($name);
- $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
- $lp_id = $this->get_id();
- $sql = "UPDATE $lp_table SET name = '" . $this->name . "' WHERE id = '$lp_id'";
- if ($this->debug > 2) {
- error_log('New LP - lp updated with new name : ' . $this->name, 0);
- }
- $res = Database::query($sql);
-
- if (Database::affected_rows()) {
- $table = Database :: get_course_table(TABLE_TOOL_LIST);
- $sql = 'UPDATE ' . $table . ' SET
- name = "' . $this->name . '"
- WHERE link = "newscorm/lp_controller.php?action=view&lp_id=' . $lp_id . '"';
- Database::query($sql);
- }
- return true;
- }
-
- public function set_terms_by_prefix($terms_string, $prefix) {
- if (api_get_setting('search_enabled') !== 'true')
- return false;
- $terms_string = trim($terms_string);
- $terms = explode(',', $terms_string);
- array_walk($terms, 'trim_value');
- $stored_terms = $this->get_common_index_terms_by_prefix($prefix);
-
-
-
- if ((count(array_diff($terms, $stored_terms)) == 0) && (count(array_diff($stored_terms, $terms)) == 0))
- return false;
- require_once 'xapian.php';
- require_once api_get_path(LIBRARY_PATH).'search/DokeosIndexer.class.php';
- require_once api_get_path(LIBRARY_PATH).'search/xapian/XapianQuery.php';
- require_once api_get_path(LIBRARY_PATH).'search/IndexableChunk.class.php';
- $items_table = Database :: get_course_table(TABLE_LP_ITEM);
-
- $lp_id = intval($_POST['lp_id']);
- $sql = "SELECT * FROM $items_table WHERE lp_id = $lp_id";
- $result = Database::query($sql);
- $di = new DokeosIndexer();
- while ($lp_item = Database :: fetch_array($result)) {
-
- $tbl_se_ref = Database :: get_main_table(TABLE_MAIN_SEARCH_ENGINE_REF);
- $sql = 'SELECT * FROM %s WHERE course_code=\'%s\' AND tool_id=\'%s\' AND ref_id_high_level=%s AND ref_id_second_level=%d LIMIT 1';
- $sql = sprintf($sql, $tbl_se_ref, $this->cc, TOOL_LEARNPATH, $lp_id, $lp_item['id']);
-
- $res = Database::query($sql);
- if (Database::num_rows($res) > 0) {
- $se_ref = Database :: fetch_array($res);
-
- $doc = $di->get_document($se_ref['search_did']);
- $xapian_terms = xapian_get_doc_terms($doc, $prefix);
-
- $xterms = array ();
- foreach ($xapian_terms as $xapian_term) {
- $xterms[] = substr($xapian_term['name'], 1);
- }
- $dterms = $terms;
- $missing_terms = array_diff($dterms, $xterms);
- $deprecated_terms = array_diff($xterms, $dterms);
-
- foreach ($missing_terms as $term) {
- $doc->add_term($prefix . $term, 1);
- }
- foreach ($deprecated_terms as $term) {
- $doc->remove_term($prefix . $term);
- }
- $di->getDb()->replace_document((int) $se_ref['search_did'], $doc);
- $di->getDb()->flush();
- } else {
-
- }
- }
- return true;
- }
-
- public function set_theme($name = '') {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::set_theme()', 0);
- }
- $this->theme = $this->escape_string($name);
- $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
- $lp_id = $this->get_id();
- $sql = "UPDATE $lp_table SET theme = '" . $this->theme . "' WHERE id = '$lp_id'";
- if ($this->debug > 2) {
- error_log('New LP - lp updated with new theme : ' . $this->theme, 0);
- }
-
- $res = Database::query($sql);
- return true;
- }
-
- public function set_preview_image($name = '') {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::set_preview_image()', 0);
- }
- $this->preview_image = $this->escape_string($name);
- $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
- $lp_id = $this->get_id();
- $sql = "UPDATE $lp_table SET preview_image = '" . $this->preview_image . "' WHERE id = '$lp_id'";
- if ($this->debug > 2) {
- error_log('New LP - lp updated with new preview image : ' . $this->preview_image, 0);
- }
- $res = Database::query($sql);
- return true;
- }
-
- public function set_author($name = '') {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::set_author()', 0);
- }
- $this->author = $this->escape_string($name);
- $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
- $lp_id = $this->get_id();
- $sql = "UPDATE $lp_table SET author = '" . $this->author . "' WHERE id = '$lp_id'";
- if ($this->debug > 2) {
- error_log('New LP - lp updated with new preview author : ' . $this->author, 0);
- }
- $res = Database::query($sql);
- return true;
- }
-
- public function set_prerequisite($prerequisite) {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::set_prerequisite()', 0);
- }
- $this->prerequisite = intval($prerequisite);
- $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
- $lp_id = $this->get_id();
- $sql = "UPDATE $lp_table SET prerequisite = '".$this->prerequisite."' WHERE id = '$lp_id'";
- if ($this->debug > 2) {
- error_log('New LP - lp updated with new preview requisite : ' . $this->requisite, 0);
- }
- $res = Database::query($sql);
- return true;
- }
-
- public function set_proximity($name = '') {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::set_proximity()', 0);
- }
- if (empty ($name))
- return false;
- $this->proximity = $this->escape_string($name);
- $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
- $lp_id = $this->get_id();
- $sql = "UPDATE $lp_table SET content_local = '" . $this->proximity . "' WHERE id = '$lp_id'";
- if ($this->debug > 2) {
- error_log('New LP - lp updated with new proximity : ' . $this->proximity, 0);
- }
- $res = Database::query($sql);
- return true;
- }
-
- public function set_previous_item($id) {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::set_previous_item()', 0);
- }
- $this->last = $id;
- }
-
- public function set_use_max_score($use_max_score = 1) {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::set_use_max_score()', 0);
- }
- $use_max_score = intval($use_max_score);
- $this->use_max_score = $use_max_score;
- $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
- $lp_id = $this->get_id();
- $sql = "UPDATE $lp_table SET use_max_score = '" . $this->use_max_score . "' WHERE id = '$lp_id'";
-
- if ($this->debug > 2) {
- error_log('New LP - lp updated with new use_max_score : ' . $this->use_max_score, 0);
- }
- $res = Database::query($sql);
- return true;
- }
-
- public function set_expired_on($expired_on) {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::set_expired_on()', 0);
- }
- if (!empty($expired_on)) {
- $this->expired_on = $this->escape_string(api_get_utc_datetime($expired_on));
- } else {
- $this->expired_on = '';
- }
- $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
- $lp_id = $this->get_id();
- $sql = "UPDATE $lp_table SET expired_on = '" . $this->expired_on . "' WHERE id = '$lp_id'";
- if ($this->debug > 2) {
- error_log('New LP - lp updated with new expired_on : ' . $this->expired_on, 0);
- }
- $res = Database::query($sql);
- return true;
- }
-
- public function set_publicated_on($publicated_on) {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::set_expired_on()', 0);
- }
- if (!empty($publicated_on)) {
- $this->publicated_on = $this->escape_string(api_get_utc_datetime($publicated_on));
- } else {
- $this->publicated_on = '';
- }
- $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
- $lp_id = $this->get_id();
- $sql = "UPDATE $lp_table SET publicated_on = '" . $this->publicated_on . "' WHERE id = '$lp_id'";
- if ($this->debug > 2) {
- error_log('New LP - lp updated with new publicated_on : ' . $this->publicated_on, 0);
- }
- $res = Database::query($sql);
- return true;
- }
-
- public function set_modified_on() {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::set_expired_on()', 0);
- }
- $this->modified_on = api_get_utc_datetime();
- $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
- $lp_id = $this->get_id();
- $sql = "UPDATE $lp_table SET modified_on = '" . $this->modified_on . "' WHERE id = '$lp_id'";
- if ($this->debug > 2) {
- error_log('New LP - lp updated with new expired_on : ' . $this->modified_on, 0);
- }
- $res = Database::query($sql);
- return true;
- }
-
- public function set_error_msg($error = '') {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::set_error_msg()', 0);
- }
- if (empty ($error)) {
- $this->error = '';
- } else {
- $this->error .= $error;
- }
- }
-
- public function start_current_item($allow_new_attempt = false) {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::start_current_item()', 0);
- }
- if ($this->current != 0 AND is_object($this->items[$this->current])) {
- $type = $this->get_type();
- $item_type = $this->items[$this->current]->get_type();
- if (($type == 2 && $item_type != 'sco') OR ($type == 3 && $item_type != 'au') OR ($type == 1 && $item_type != TOOL_QUIZ && $item_type != TOOL_HOTPOTATOES)) {
- $this->items[$this->current]->open($allow_new_attempt);
- $this->autocomplete_parents($this->current);
- $prereq_check = $this->prerequisites_match($this->current);
- $this->items[$this->current]->save(false, $prereq_check);
-
- } else {
-
- }
- if ($item_type == 'sco') {
- $this->items[$this->current]->restart();
- }
- }
- if ($this->debug > 0) {
- error_log('New LP - End of learnpath::start_current_item()', 0);
- }
- return true;
- }
-
- public function stop_previous_item() {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::stop_previous_item()', 0);
- }
- if ($this->last != 0 && $this->last != $this->current && is_object($this->items[$this->last])) {
- if ($this->debug > 2) {
- error_log('New LP - In learnpath::stop_previous_item() - ' . $this->last . ' is object', 0);
- }
- switch ($this->get_type()) {
- case '3' :
- if ($this->items[$this->last]->get_type() != 'au') {
- if ($this->debug > 2) {
- error_log('New LP - In learnpath::stop_previous_item() - ' . $this->last . ' in lp_type 3 is <> au', 0);
- }
- $this->items[$this->last]->close();
-
-
- } else {
- if ($this->debug > 2) {
- error_log('New LP - In learnpath::stop_previous_item() - Item is an AU, saving is managed by AICC signals', 0);
- }
- }
- case '2' :
- if ($this->items[$this->last]->get_type() != 'sco') {
- if ($this->debug > 2) {
- error_log('New LP - In learnpath::stop_previous_item() - ' . $this->last . ' in lp_type 2 is <> sco', 0);
- }
- $this->items[$this->last]->close();
-
-
- } else {
- if ($this->debug > 2) {
- error_log('New LP - In learnpath::stop_previous_item() - Item is a SCO, saving is managed by SCO signals', 0);
- }
- }
- break;
- case '1' :
- default :
- if ($this->debug > 2) {
- error_log('New LP - In learnpath::stop_previous_item() - ' . $this->last . ' in lp_type 1 is asset', 0);
- }
- $this->items[$this->last]->close();
- break;
- }
- } else {
- if ($this->debug > 2) {
- error_log('New LP - In learnpath::stop_previous_item() - No previous element found, ignoring...', 0);
- }
- return false;
- }
- return true;
- }
-
- public function update_default_view_mode() {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::update_default_view_mode()', 0);
- }
- $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
- $sql = "SELECT * FROM $lp_table WHERE id = " . $this->get_id();
- $res = Database::query($sql);
- if (Database :: num_rows($res) > 0) {
- $row = Database :: fetch_array($res);
- $view_mode = $row['default_view_mod'];
- if ($view_mode == 'fullscreen') {
- $view_mode = 'embedded';
- } elseif ($view_mode == 'embedded') {
- $view_mode = 'embedframe';
- } elseif ($view_mode == 'embedframe') {
- $view_mode = 'fullscreen';
- }
- $sql = "UPDATE $lp_table SET default_view_mod = '$view_mode' WHERE id = " . $this->get_id();
- $res = Database::query($sql);
- $this->mode = $view_mode;
- return $view_mode;
- } else {
- if ($this->debug > 2) {
- error_log('New LP - Problem in update_default_view() - could not find LP ' . $this->get_id() . ' in DB', 0);
- }
- }
- return -1;
- }
-
- public function update_default_scorm_commit() {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::update_default_scorm_commit()', 0);
- }
- $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
- $sql = "SELECT * FROM $lp_table WHERE id = " . $this->get_id();
- $res = Database::query($sql);
- if (Database :: num_rows($res) > 0) {
- $row = Database :: fetch_array($res);
- $force = $row['force_commit'];
- if ($force == 1) {
- $force = 0;
- $force_return = false;
- } elseif ($force == 0) {
- $force = 1;
- $force_return = true;
- }
- $sql = "UPDATE $lp_table SET force_commit = $force WHERE id = " . $this->get_id();
- $res = Database::query($sql);
- $this->force_commit = $force_return;
- return $force_return;
- } else {
- if ($this->debug > 2) {
- error_log('New LP - Problem in update_default_scorm_commit() - could not find LP ' . $this->get_id() . ' in DB', 0);
- }
- }
- return -1;
- }
-
- public function update_display_order() {
- $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
- $sql = "SELECT * FROM $lp_table ORDER BY display_order";
- $res = Database::query($sql);
- if ($res === false)
- return false;
- $lps = array ();
- $lp_order = array ();
- $num = Database :: num_rows($res);
-
-
- if ($num > 0) {
- $i = 1;
- while ($row = Database :: fetch_array($res)) {
- if ($row['display_order'] != $i) {
- $need_fix = true;
- $sql_u = "UPDATE $lp_table SET display_order = $i WHERE id = " . $row['id'];
- $res_u = Database::query($sql_u);
- }
- $i++;
- }
- }
- return true;
- }
-
- public function update_reinit() {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::update_reinit()', 0);
- }
- $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
- $sql = "SELECT * FROM $lp_table WHERE id = " . $this->get_id();
- $res = Database::query($sql);
- if (Database :: num_rows($res) > 0) {
- $row = Database :: fetch_array($res);
- $force = $row['prevent_reinit'];
- if ($force == 1) {
- $force = 0;
- } elseif ($force == 0) {
- $force = 1;
- }
- $sql = "UPDATE $lp_table SET prevent_reinit = $force WHERE id = " . $this->get_id();
- $res = Database::query($sql);
- $this->prevent_reinit = $force;
- return $force;
- } else {
- if ($this->debug > 2) {
- error_log('New LP - Problem in update_reinit() - could not find LP ' . $this->get_id() . ' in DB', 0);
- }
- }
- return -1;
- }
-
- public function update_scorm_debug() {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::update_scorm_debug()', 0);
- }
- $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
- $sql = "SELECT * FROM $lp_table WHERE id = " . $this->get_id();
- $res = Database::query($sql);
- if (Database :: num_rows($res) > 0) {
- $row = Database :: fetch_array($res);
- $force = $row['debug'];
- if ($force == 1) {
- $force = 0;
- } elseif ($force == 0) {
- $force = 1;
- }
- $sql = "UPDATE $lp_table SET debug = $force WHERE id = " . $this->get_id();
- $res = Database::query($sql);
- $this->scorm_debug = $force;
- return $force;
- } else {
- if ($this->debug > 2) {
- error_log('New LP - Problem in update_scorm_debug() - could not find LP ' . $this->get_id() . ' in DB', 0);
- }
- }
- return -1;
- }
-
- public function tree_array($array) {
- if ($this->debug > 1) {
- error_log('New LP - In learnpath::tree_array()', 0);
- }
- $array = $this->sort_tree_array($array);
- $this->create_tree_array($array);
- }
-
- public function create_tree_array($array, $parent = 0, $depth = -1, $tmp = array ()) {
- if ($this->debug > 1) {
- error_log('New LP - In learnpath::create_tree_array())', 0);
- }
- if (is_array($array)) {
- for ($i = 0; $i < count($array); $i++) {
- if ($array[$i]['parent_item_id'] == $parent) {
- if (!in_array($array[$i]['parent_item_id'], $tmp)) {
- $tmp[] = $array[$i]['parent_item_id'];
- $depth++;
- }
- $preq = (empty($array[$i]['prerequisite']) ? '' : $array[$i]['prerequisite']);
- $this->arrMenu[] = array (
- 'id' => $array[$i]['id'],
- 'item_type' => $array[$i]['item_type'],
- 'title' => $array[$i]['title'],
- 'path' => $array[$i]['path'],
- 'description' => $array[$i]['description'],
- 'parent_item_id' => $array[$i]['parent_item_id'],
- 'previous_item_id' => $array[$i]['previous_item_id'],
- 'next_item_id' => $array[$i]['next_item_id'],
- 'min_score' => $array[$i]['min_score'],
- 'max_score' => $array[$i]['max_score'],
- 'mastery_score' => $array[$i]['mastery_score'],
- 'display_order' => $array[$i]['display_order'],
- 'prerequisite' => $preq,
- 'depth' => $depth,
- 'audio' => $array[$i]['audio']
- );
- $this->create_tree_array($array, $array[$i]['id'], $depth, $tmp);
- }
- }
- }
- }
-
- public function sort_tree_array($array) {
- foreach ($array as $key => $row) {
- $parent[$key] = $row['parent_item_id'];
- $position[$key] = $row['display_order'];
- }
- if (count($array) > 0)
- array_multisort($parent, SORT_ASC, $position, SORT_ASC, $array);
- return $array;
- }
-
- public function overview() {
- $is_allowed_to_edit = api_is_allowed_to_edit(null,true);
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::overview()', 0);
- }
- global $charset, $_course;
- $_SESSION['gradebook'] = Security :: remove_XSS($_GET['gradebook']);
- $return = '';
- $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
- $sql = "SELECT * FROM " . $tbl_lp_item . "
- WHERE lp_id = " . $this->lp_id;
- $result = Database::query($sql);
- $arrLP = array ();
- while ($row = Database :: fetch_array($result)) {
- $row['title'] = Security :: remove_XSS($row['title']);
- $row['description'] = Security :: remove_XSS($row['description']);
- $arrLP[] = array (
- 'id' => $row['id'],
- 'item_type' => $row['item_type'],
- 'title' => $row['title'],
- 'path' => $row['path'],
- 'description' => $row['description'],
- 'parent_item_id' => $row['parent_item_id'],
- 'previous_item_id' => $row['previous_item_id'],
- 'next_item_id' => $row['next_item_id'],
- 'max_score' => $row['max_score'],
- 'min_score' => $row['min_score'],
- 'mastery_score' => $row['mastery_score'],
- 'prerequisite' => $row['prerequisite'],
- 'display_order' => $row['display_order'],
- 'audio' => $row['audio']
- );
- }
- $this->tree_array($arrLP);
- $arrLP = $this->arrMenu;
- unset ($this->arrMenu);
- if ($is_allowed_to_edit) {
- $token = Security::get_token();
- $gradebook = Security :: remove_XSS($_GET['gradebook']);
- $return .= '<div class="actions">';
- $return .= '<a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&gradebook=' . $gradebook . '&action=build&lp_id=' . $this->lp_id . '" title="' . get_lang('Build') . '">' . Display :: return_icon('build_learnpath.png', get_lang('Build'),'','32').'</a>';
- $return .= '<span>' . Display :: return_icon('move_learnpath_na.png', get_lang('BasicOverview'),'','32').'</span>';
- $return .= '<a href="lp_controller.php?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&action=view&lp_id=' . $this->lp_id . '">' . Display :: return_icon('view_left_right.png', get_lang('Display'),'','32').'</a>';
- $return .= ' '.Display :: return_icon('i.gif');
- $return .= '<a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&gradebook=' . $gradebook . '&action=add_item&type=step&lp_id=' . $_SESSION['oLP']->lp_id . '" title="' . get_lang('NewStep') . '">
- '. Display :: return_icon('new_learnigpath_object.png', get_lang('NewStep'),'','32').'</a>';
- $return .= '<a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&gradebook=' . $gradebook . '&action=add_item&type=chapter&lp_id=' . $_SESSION['oLP']->lp_id . '" title="' . get_lang('NewChapter') . '">
- '. Display :: return_icon('add_learnpath_section.png', get_lang('NewChapter'),'','32').'</a>';
- $return .= '<a href="lp_controller.php?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&action=edit&lp_id=' . Security :: remove_XSS($_GET['lp_id']) . '">' . Display :: return_icon('settings.png', get_lang('CourseSettings'),'','32').'</a>';
- $return .= '<a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&action=' . Security :: remove_XSS($_GET['action']) . '&lp_id=' . Security :: remove_XSS($_GET['lp_id']) . '&updateaudio=true">' . Display :: return_icon('upload_audio.png', get_lang('UpdateAllAudioFragments'),'','32').'</a>';
- $return .= '</div>';
- }
-
- if ($_GET['updateaudio'] == 'true' AND count($arrLP) <> 0) {
- $return .= '<form action="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&action=' . Security :: remove_XSS($_GET['action']) . '&lp_id=' . Security :: remove_XSS($_GET['lp_id']) . '" method="post" enctype="multipart/form-data" name="updatemp3" id="updatemp3">';
- $return .= Display :: display_warning_message(get_lang('LeaveEmptyToKeepCurrentFile'));
- }
- $return .= '<table class="data_table">' . "\n";
- $return .= "\t" . '<tr>' . "\n";
- $return .= "\t" . '<th width="60%">' . get_lang('Title') . '</th>' . "\n";
-
- $return .= "\t" . '<th>' . get_lang('Audio') . '</th>' . "\n";
- $return .= "\t" . '<th>' . get_lang('Move') . '</th>' . "\n";
- $return .= "\t" . '<th>' . get_lang('Actions') . '</th>' . "\n";
- $return .= "\t" . '</tr>' . "\n";
- for ($i = 0; $i < count($arrLP); $i++) {
- $title = $arrLP[$i]['title'];
- if ($arrLP[$i]['description'] == '')
- $arrLP[$i]['description'] = ' ';
- if (($i % 2) == 0) {
- $oddclass = 'row_odd';
- } else {
- $oddclass = 'row_even';
- }
- $return .= "\t" . '<tr class="' . $oddclass . '">' . "\n";
- $icon_name = str_replace(' ', '', $arrLP[$i]['item_type']);
- if (file_exists('../img/lp_' . $icon_name . '.png')) {
- $return .= "\t\t" . '<td style="padding-left:' . $arrLP[$i]['depth'] * 10 . 'px;"><img align="left" src="../img/lp_' . $icon_name . '.png" style="margin-right:3px;" />' . $title . '</td>' . "\n";
- } else {
- if (file_exists('../img/lp_' . $icon_name . '.gif')) {
- $return .= "\t\t" . '<td style="padding-left:' . $arrLP[$i]['depth'] * 10 . 'px;"><img align="left" src="../img/lp_' . $icon_name . '.gif" style="margin-right:3px;" />' . $title . '</td>' . "\n";
- } else {
-
- $return .= "\t\t" . '<td style="padding-left:' . $arrLP[$i]['depth'] * 10 . 'px;"><img align="left" src="../img/folder_document.gif" style="margin-right:3px;" />' . $title . '</td>' . "\n";
- }
- }
-
-
- $return .= "\t\t" . '<td align="center">';
- if (!$_GET['updateaudio'] OR $_GET['updateaudio'] <> 'true') {
- if (!empty ($arrLP[$i]['audio'])) {
- $return .= '<span id="container' . $i . '"><a href="http://www.macromedia.com/go/getflashplayer">Get the Flash Player</a> to see this player.</span>';
- $return .= '<script type="text/javascript" src="../inc/lib/mediaplayer/swfobject.js"></script>';
- $return .= '<script type="text/javascript">
- var s1 = new SWFObject("../inc/lib/mediaplayer/player.swf","ply","250","20","9","#FFFFFF");
- s1.addParam("allowscriptaccess","always");
- s1.addParam("flashvars","file=../../courses/' . $_course['path'] . '/document/audio/' . $arrLP[$i]['audio'] . '");
- s1.write("container' . $i . '");
- </script>';
- } else {
- $return .= ' - ';
- }
- } else {
- if ($arrLP[$i]['item_type'] != 'dokeos_chapter' && $arrLP[$i]['item_type'] != 'dokeos_module' && $arrLP[$i]['item_type'] != 'dir') {
- $return .= ' <input type="file" name="mp3file' . $arrLP[$i]['id'] . '" id="mp3file" />';
- if (!empty ($arrLP[$i]['audio'])) {
- $return .= '<br />'.Security::remove_XSS($arrLP[$i]['audio']).'<input type="checkbox" name="removemp3' . $arrLP[$i]['id'] . '" id="checkbox' . $arrLP[$i]['id'] . '" />' . get_lang('RemoveAudio');
- }
- }
- }
- $return .= '</td>';
- if ($is_allowed_to_edit) {
- $return .= '<td align="center">';
- if ($arrLP[$i]['previous_item_id'] != 0) {
- $return .= '<a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&action=move_item&direction=up&id=' . $arrLP[$i]['id'] . '&lp_id=' . $this->lp_id . '&sec_token='.$token.'">';
- $return .= '<img style="margin:1px;" alt="" src="../img/arrow_up_' . ($arrLP[$i]['depth'] % 3) . '.gif" title="' . get_lang('MoveUp') . '"/>';
- $return .= '</a>';
- } else
- $return .= '<img alt="" src="../img/blanco.png" title="" />';
- if ($arrLP[$i]['next_item_id'] != 0) {
- $return .= '<a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']). '&action=move_item&direction=down&id=' . $arrLP[$i]['id'] . '&lp_id=' . $this->lp_id . '&sec_token='.$token.'">';
- $return .= '<img style="margin:1px;" src="../img/arrow_down_' . ($arrLP[$i]['depth'] % 3) . '.gif" title="' . get_lang('MoveDown') . '" />';
- $return .= '</a>';
- } else
- $return .= '<img alt="" src="../img/blanco.png" title="" />';
- $return .= '</td>';
- $return .= '<td align="center">';
- if ($arrLP[$i]['item_type'] != 'dokeos_chapter' && $arrLP[$i]['item_type'] != 'dokeos_module') {
- $return .= "\t\t\t" . '<a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&action=edit_item&view=build&id=' . $arrLP[$i]['id'] . '&lp_id=' . $this->lp_id . '&path_item=' . $arrLP[$i]['path'] . '">';
- $return .= '<img style="margin:1px;" alt="" src="../img/edit.gif" title="' . get_lang('_edit_learnpath_module') . '" />';
- $return .= '</a>' . "\n";
- } else {
- $return .= "\t\t\t" . '<a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&action=edit_item&id=' . $arrLP[$i]['id'] . '&lp_id=' . $this->lp_id . '&path_item=' . $arrLP[$i]['path'] . '">';
- $return .= '<img style="margin:1px;" alt="" src="../img/edit.gif" title="' . get_lang('_edit_learnpath_module') . '" />';
- $return .= '</a>' . "\n";
- }
- $return .= "\t\t\t" . '<a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&action=delete_item&id=' . $arrLP[$i]['id'] . '&lp_id=' . $this->lp_id . '" onClick="return confirmation(\'' . addslashes($title) . '\');">';
- $return .= '<img style="margin:1px;" alt="" src="../img/delete.gif" title="' . get_lang('_delete_learnpath_module') . '" />';
- $return .= '</a>' . "\n";
- $return .= '</td>';
- }
- $return .= '</tr>';
- }
- if (count($arrLP) == 0) {
- $return .= "\t" . '<tr>' . "\n";
- $return .= "\t\t" . '<td colspan="4">' . get_lang('NoItemsInLp') . '</td>' . "\n";
- $return .= "\t" . '</tr>' . "\n";
- }
- $return .= '</table>' . "\n";
-
- if ($_GET['updateaudio'] == 'true') {
- $return .= '<div style="margin:40px 0; float:right;"><button class="save" type="submit" name="save_audio" id="save_audio">' . get_lang('SaveAudioAndOrganization') . '</button></div>';
- }
-
- if ($_GET['updateaudio'] == 'true' && count($arrLP) != 0) {
- $return .= '</form>';
- }
- return $return;
- }
-
- public function build_action_menu() {
- $gradebook = Security :: remove_XSS($_GET['gradebook']);
- echo '<div class="actions">';
-
- echo '<span>' . Display :: return_icon('build_learnpath_na.png', get_lang('Build'),'','32').'</span>';
- echo '<a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&gradebook=' . $gradebook . '&action=admin_view&lp_id=' . $_SESSION['oLP']->lp_id . '" title="' . get_lang('BasicOverview') . '">' . Display :: return_icon('move_learnpath.png', get_lang('BasicOverview'),'','32').'</a>';
- echo '<a href="lp_controller.php?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&gradebook=' . $gradebook . '&action=view&lp_id=' . $_SESSION['oLP']->lp_id . '">' . Display :: return_icon('view_left_right.png', get_lang('Display'),'','32').'</a> ';
- Display :: display_icon('i.gif');
- echo '<a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&gradebook=' . $gradebook . '&action=add_item&type=step&lp_id=' . $_SESSION['oLP']->lp_id . '" title="' . get_lang('NewStep') . '">' . Display :: return_icon('new_learnigpath_object.png', get_lang('NewStep'),'','32').'</a>';
-
- echo '<a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&gradebook=' . $gradebook . '&action=add_item&type=chapter&lp_id=' . $_SESSION['oLP']->lp_id . '" title="' . get_lang('NewChapter') . '">' . Display :: return_icon('add_learnpath_section.png', get_lang('NewChapter'),'','32').'</a>';
-
- echo '<a href="lp_controller.php?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&action=edit&lp_id=' . Security :: remove_XSS($_GET['lp_id']) . '">' . Display :: return_icon('settings.png', get_lang('CourseSettings'),'','32').'</a>';
- echo '<a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&action=admin_view&lp_id=' . Security :: remove_XSS($_GET['lp_id']) . '&updateaudio=true">' . Display :: return_icon('upload_audio.png', get_lang('UpdateAllAudioFragments'),'','32').'</a>';
- echo '</div>';
- }
-
- public function build_tree() {
- $return = "<script type=\"text/javascript\">\n";
- $return .= "\tm = new dTree('m');\n\n";
- $return .= "\tm.config.folderLinks = true;\n";
- $return .= "\tm.config.useCookies = true;\n";
- $return .= "\tm.config.useIcons = true;\n";
- $return .= "\tm.config.useLines = true;\n";
- $return .= "\tm.config.useSelection = true;\n";
- $return .= "\tm.config.useStatustext = false;\n\n";
- $menu = 0;
- $parent = '';
- $return .= "\tm.add(" . $menu . ", -1, '" . addslashes(Security::remove_XSS(($this->name))) . "');\n";
- $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
- $sql = " SELECT id, title, description, item_type, path, parent_item_id, previous_item_id, next_item_id, max_score, min_score, mastery_score, display_order
- FROM " . $tbl_lp_item . "
- WHERE lp_id = " . Database :: escape_string($this->lp_id);
- $result = Database::query($sql);
- $arrLP = array ();
- while ($row = Database :: fetch_array($result)) {
- $row['title'] = Security :: remove_XSS($row['title']);
- $row['description'] = Security :: remove_XSS($row['description']);
- $arrLP[] = array (
- 'id' => $row['id'],
- 'item_type' => $row['item_type'],
- 'title' => $row['title'],
- 'path' => $row['path'],
- 'description' => $row['description'],
- 'parent_item_id' => $row['parent_item_id'],
- 'previous_item_id' => $row['previous_item_id'],
- 'next_item_id' => $row['next_item_id'],
- 'max_score' => $row['max_score'],
- 'min_score' => $row['min_score'],
- 'mastery_score' => $row['mastery_score'],
- 'display_order' => $row['display_order']
- );
- }
- $this->tree_array($arrLP);
- $arrLP = $this->arrMenu;
- unset ($this->arrMenu);
- $title = '';
- for ($i = 0; $i < count($arrLP); $i++) {
- $title = addslashes($arrLP[$i]['title']);
- $menu_page = api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&action=view_item&id=' . $arrLP[$i]['id'] . '&lp_id=' . $_SESSION['oLP']->lp_id;
- $icon_name = str_replace(' ', '', $arrLP[$i]['item_type']);
- if (file_exists('../img/lp_' . $icon_name . '.png')) {
- $return .= "\tm.add(" . $arrLP[$i]['id'] . ", " . $arrLP[$i]['parent_item_id'] . ", '" . $title . "', '" . $menu_page . "', '', '', '../img/lp_" . $icon_name . ".png', '../img/lp_" . $icon_name . ".png');\n";
- } else
- if (file_exists('../img/lp_' . $icon_name . '.gif')) {
- $return .= "\tm.add(" . $arrLP[$i]['id'] . ", " . $arrLP[$i]['parent_item_id'] . ", '" . $title . "', '" . $menu_page . "', '', '', '../img/lp_" . $icon_name . ".gif', '../img/lp_" . $icon_name . ".gif');\n";
- } else {
- $return .= "\tm.add(" . $arrLP[$i]['id'] . ", " . $arrLP[$i]['parent_item_id'] . ", '" . $title . "', '" . $menu_page . "', '', '', '../img/folder_document.gif', '../img/folder_document.gif');\n";
- }
- if ($menu < $arrLP[$i]['id'])
- $menu = $arrLP[$i]['id'];
- }
- $return .= "\n\tdocument.write(m);\n";
- $return .= "\t if(!m.selectedNode) m.s(1);";
- $return .= "</script>\n";
- return $return;
- }
-
- public function create_document($_course) {
- global $charset;
- $dir = isset ($_GET['dir']) ? $_GET['dir'] : $_POST['dir'];
- if (strstr($dir, '..'))
- $dir = '/';
- if ($dir[0] == '.')
- $dir = substr($dir, 1);
- if ($dir[0] != '/')
- $dir = '/' . $dir;
- if ($dir[strlen($dir) - 1] != '/')
- $dir .= '/';
- $filepath = api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document' . $dir;
- if (!is_dir($filepath)) {
- $filepath = api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document/';
- $dir = '/';
- }
-
-
- $title = replace_dangerous_char(stripslashes($_POST['title']));
- $title = disable_dangerous_file($title);
- $filename = $title;
- $content = $_POST['content_lp'];
- $tmp_filename = $filename;
- $i = 0;
- while (file_exists($filepath . $tmp_filename . '.html'))
- $tmp_filename = $filename . '_' . ++ $i;
- $filename = $tmp_filename . '.html';
- $content = stripslashes(text_filter($content));
- $content = str_replace(api_get_path(WEB_COURSE_PATH), api_get_path(REL_PATH) . 'courses/', $content);
-
-
- $content = preg_replace("|(flashvars=\"file=)(\.+/)+|", "$1" . api_get_path(REL_COURSE_PATH) . $_course['path'] . '/document/', $content);
-
- $content = preg_replace("|(flashvars=\"file=)([^/]+)/|", "$1" . api_get_path(REL_COURSE_PATH) . $_course['path'] . '/document/$2/', $content);
-
- $content = str_replace('</body>', '<style type="text/css">body{}</style></body>', $content);
- if (!file_exists($filepath . $filename)) {
- if ($fp = @ fopen($filepath . $filename, 'w')) {
- fputs($fp, $content);
- fclose($fp);
- $file_size = filesize($filepath . $filename);
- $save_file_path = $dir . $filename;
- $document_id = add_document($_course, $save_file_path, 'file', $file_size, $filename . '.html');
- if ($document_id) {
- api_item_property_update($_course, TOOL_DOCUMENT, $document_id, 'DocumentAdded', api_get_user_id(), null, null, null, null, api_get_session_id());
-
-
- $new_comment = (isset($_POST['comment'])) ? trim($_POST['comment']) : '';
- $new_title = (isset($_POST['title'])) ? trim($_POST['title']) : '';
- if ($new_comment || $new_title) {
- $tbl_doc = Database :: get_course_table(TABLE_DOCUMENT);
- $ct = '';
- if ($new_comment)
- $ct .= ", comment='" . $new_comment . "'";
- if ($new_title)
- $ct .= ", title='" . Database :: escape_string(htmlspecialchars($new_title, ENT_QUOTES, $charset)) . ".html '";
- $sql_update = "
- UPDATE " . $tbl_doc . "
- SET " . substr($ct, 1) . "
- WHERE id = " . $document_id;
- Database::query($sql_update);
- }
- }
- return $document_id;
- }
- }
- }
-
- public function edit_document($_course) {
- global $_configuration;
- $dir = isset ($_GET['dir']) ? $_GET['dir'] : $_POST['dir'];
- if (strstr($dir, '..'))
- $dir = '/';
- if ($dir[0] == '.')
- $dir = substr($dir, 1);
- if ($dir[0] != '/')
- $dir = '/' . $dir;
- if ($dir[strlen($dir) - 1] != '/')
- $dir .= '/';
- $filepath = api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document' . $dir;
- if (!is_dir($filepath)) {
- $filepath = api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document/';
- $dir = '/';
- }
- $table_doc = Database :: get_course_table(TABLE_DOCUMENT);
- if (isset($_POST['path']) && !empty($_POST['path'])) {
- $sql = "SELECT path
- FROM " . $table_doc . "
- WHERE id = " . Database::escape_string($_POST['path']);
- $res = Database::query($sql);
- $row = Database :: fetch_array($res);
- $content = stripslashes($_POST['content_lp']);
- $file = $filepath . $row['path'];
- if ($fp = @ fopen($file, 'w')) {
- $content = text_filter($content);
- $content = str_replace(api_get_path(WEB_COURSE_PATH), $_configuration['url_append'] . '/courses/', $content);
-
-
- $content = preg_replace("|(flashvars=\"file=)(\.+/)+|", "$1" . api_get_path(REL_COURSE_PATH) . $_course['path'] . '/document/', $content);
-
- $content = preg_replace("|(flashvars=\"file=)([^/]+)/|", "$1" . api_get_path(REL_COURSE_PATH) . $_course['path'] . '/document/$2/', $content);
- fputs($fp, $content);
- fclose($fp);
- }
- }
- }
-
- public function display_item($item_id, $iframe = true, $msg = '') {
- global $_course;
- $return = '';
- if (is_numeric($item_id)) {
- $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
- $tbl_doc = Database :: get_course_table(TABLE_DOCUMENT);
- $sql = "SELECT lp.* FROM " . $tbl_lp_item . " as lp
- WHERE lp.id = " . Database :: escape_string($item_id);
- $result = Database::query($sql);
- while ($row = Database :: fetch_array($result)) {
- $_SESSION['parent_item_id'] = ($row['item_type'] == 'dokeos_chapter' || $row['item_type'] == 'dokeos_module' || $row['item_type'] == 'dir') ? $item_id : 0;
-
- if ($row['item_type'] != 'dokeos_chapter' || $row['item_type'] != 'dokeos_module') {
- $_SESSION['parent_item_id'] = $row['parent_item_id'];
- }
- $return .= $this->display_manipulate($item_id, $row['item_type']);
- $return .= '<div style="padding:10px;">';
- if ($msg != '')
- $return .= $msg;
- $return .= '<p class="lp_title">' . $row['title'] . '</p>';
-
-
- switch ($row['item_type']) {
- case TOOL_QUIZ:
- if (!empty($row['path'])) {
- require_once api_get_path(SYS_CODE_PATH).'exercice/exercise.class.php';
- $exercise = new Exercise();
- $exercise->read($row['path']);
-
- $return .=$exercise->description.'<br />';
-
- }
- break;
- case TOOL_DOCUMENT:
- $tbl_doc = Database :: get_course_table(TABLE_DOCUMENT);
- $sql_doc = "SELECT path FROM " . $tbl_doc . " WHERE id = " . Database :: escape_string($row['path']);
- $result = Database::query($sql_doc);
- $path_file = Database :: result($result, 0, 0);
- $path_parts = pathinfo($path_file);
-
- if (in_array($path_parts['extension'], array (
- 'html',
- 'txt',
- 'png',
- 'jpg',
- 'JPG',
- 'jpeg',
- 'JPEG',
- 'gif',
- 'swf'
- ))) {
- $return .= $this->display_document($row['path'], true, true);
- }
- break;
- }
- $return .= '</div>';
- }
- }
- return $return;
- }
-
- public function display_edit_item($item_id) {
- global $_course;
- $return = '';
- if (is_numeric($item_id)) {
- $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
- $sql = "SELECT *
- FROM " . $tbl_lp_item . "
- WHERE id = " . Database :: escape_string($item_id);
- $res = Database::query($sql);
- $row = Database :: fetch_array($res);
- switch ($row['item_type']) {
- case 'dokeos_chapter' :
- case 'dir' :
- case 'asset' :
- case 'sco' :
- if (isset ($_GET['view']) && $_GET['view'] == 'build') {
- $return .= $this->display_manipulate($item_id, $row['item_type']);
- $return .= $this->display_item_form($row['item_type'], get_lang('EditCurrentChapter') . ' :', 'edit', $item_id, $row);
- } else {
- $return .= $this->display_item_small_form($row['item_type'], get_lang('EditCurrentChapter') . ' :', $row);
- }
- break;
- case TOOL_DOCUMENT :
- $tbl_doc = Database :: get_course_table(TABLE_DOCUMENT);
- $sql_step = " SELECT lp.*, doc.path as dir
- FROM " . $tbl_lp_item . " as lp
- LEFT JOIN " . $tbl_doc . " as doc ON doc.id = lp.path
- WHERE lp.id = " . Database :: escape_string($item_id);
- $res_step = Database::query($sql_step);
- $row_step = Database :: fetch_array($res_step);
- $return .= $this->display_manipulate($item_id, $row['item_type']);
- $return .= $this->display_document_form('edit', $item_id, $row_step);
- break;
- case TOOL_LINK :
- $link_id = (string) $row['path'];
- if (ctype_digit($link_id)) {
- $tbl_link = Database :: get_course_table(TABLE_LINK);
- $sql_select = 'SELECT url FROM ' . $tbl_link . ' WHERE id = ' . Database :: escape_string($link_id);
- $res_link = Database::query($sql_select);
- $row_link = Database :: fetch_array($res_link);
- if (is_array($row_link)) {
- $row['url'] = $row_link['url'];
- }
- }
- $return .= $this->display_manipulate($item_id, $row['item_type']);
- $return .= $this->display_link_form('edit', $item_id, $row);
- break;
- case 'dokeos_module' :
- if (isset ($_GET['view']) && $_GET['view'] == 'build') {
- $return .= $this->display_manipulate($item_id, $row['item_type']);
- $return .= $this->display_item_form($row['item_type'], get_lang('EditCurrentModule') . ' :', 'edit', $item_id, $row);
- } else {
- $return .= $this->display_item_small_form($row['item_type'], get_lang('EditCurrentModule') . ' :', $row);
- }
- break;
- case TOOL_QUIZ :
- $return .= $this->display_manipulate($item_id, $row['item_type']);
- $return .= $this->display_quiz_form('edit', $item_id, $row);
- break;
- case TOOL_HOTPOTATOES :
- $return .= $this->display_manipulate($item_id, $row['item_type']);
- $return .= $this->display_hotpotatoes_form('edit', $item_id, $row);
- break;
- case TOOL_STUDENTPUBLICATION :
- $return .= $this->display_manipulate($item_id, $row['item_type']);
- $return .= $this->display_student_publication_form('edit', $item_id, $row);
- break;
- case TOOL_FORUM :
- $return .= $this->display_manipulate($item_id, $row['item_type']);
- $return .= $this->display_forum_form('edit', $item_id, $row);
- break;
- case TOOL_THREAD :
- $return .= $this->display_manipulate($item_id, $row['item_type']);
- $return .= $this->display_thread_form('edit', $item_id, $row);
- break;
- }
- }
- return $return;
- }
-
- public function display_resources() {
- global $_course;
- $return .= '<div class="sectiontitle">' . get_lang('CreateNewStep') . '</div>';
- $return .= '<div class="sectioncomment"><a href="' . api_get_self() . '?cidReq=' . $_GET['cidReq'] . '&action=add_item&type=' . TOOL_DOCUMENT . '&lp_id=' . $_SESSION['oLP']->lp_id . '">' . '<img title="Nuevo documento" src="../img/new_doc.gif" alt="Nuevo documento"/> ' . get_lang('NewDocument') . '</a></div>';
- $return .= '<div class="sectiontitle">' . get_lang('UseAnExistingResource') . '</div>';
- $return .= '<div class="sectioncomment">';
-
- $return .= $this->get_documents();
-
- $return .= $this->get_exercises();
-
- $return .= $this->get_links();
-
- $return .= $this->get_student_publications();
-
- $return .= $this->get_forums();
- $return .= '</div>';
- return $return;
- }
-
- public function get_extension($filename) {
- $explode = explode('.', $filename);
- return $explode[count($explode) - 1];
- }
-
- public function display_document($id, $show_title = false, $iframe = true, $edit_link = false) {
- global $_course;
- $return = '';
- $tbl_doc = Database :: get_course_table(TABLE_DOCUMENT);
- $sql_doc = "SELECT * FROM " . $tbl_doc . "
- WHERE id = " . $id;
- $res_doc = Database::query($sql_doc);
- $row_doc = Database :: fetch_array($res_doc);
-
-
-
- if ($iframe) {
- $return .= '<iframe id="learnpath_preview_frame" frameborder="0" height="400" width="100%" scrolling="auto" src="' . api_get_path(WEB_COURSE_PATH) . $_course['path'] . '/document' . str_replace('%2F', '/', urlencode($row_doc['path'])) . '?' . api_get_cidreq() . '"></iframe>';
- } else {
- $return .= file_get_contents(api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document' . $row_doc['path']);
- }
- return $return;
- }
-
- public function display_quiz_form($action = 'add', $id = 0, $extra_info = '') {
- global $charset;
- $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
- $tbl_quiz = Database :: get_course_table(TABLE_QUIZ_TEST);
- if ($id != 0 && is_array($extra_info)) {
- $item_title = stripslashes($extra_info['title']);
- $item_description = stripslashes($extra_info['description']);
- }
- elseif (is_numeric($extra_info)) {
- $sql_quiz = "
- SELECT
- title,
- description
- FROM " . $tbl_quiz . "
- WHERE id = " . $extra_info;
- $result = Database::query($sql_quiz);
- $row = Database :: fetch_array($result);
- $item_title = $row['title'];
- $item_description = $row['description'];
- } else {
- $item_title = '';
- $item_description = '';
- }
- $return = ' <div class="row">
- <div class="form_header">';
- if ($id != 0 && is_array($extra_info))
- $parent = $extra_info['parent_item_id'];
- else
- $parent = 0;
- $sql = "
- SELECT *
- FROM " . $tbl_lp_item . "
- WHERE
- lp_id = " . $this->lp_id;
- $result = Database::query($sql);
- $arrLP = array ();
- while ($row = Database :: fetch_array($result)) {
- $arrLP[] = array (
- 'id' => $row['id'],
- 'item_type' => $row['item_type'],
- 'title' => $row['title'],
- 'path' => $row['path'],
- 'description' => $row['description'],
- 'parent_item_id' => $row['parent_item_id'],
- 'previous_item_id' => $row['previous_item_id'],
- 'next_item_id' => $row['next_item_id'],
- 'display_order' => $row['display_order'],
- 'max_score' => $row['max_score'],
- 'min_score' => $row['min_score'],
- 'mastery_score' => $row['mastery_score'],
- 'prerequisite' => $row['prerequisite'],
- 'max_time_allowed' => $row['max_time_allowed']
- );
- }
- $this->tree_array($arrLP);
- $arrLP = $this->arrMenu;
- unset ($this->arrMenu);
- if ($action == 'add')
- $return .= get_lang('CreateTheExercise') . ' :' . "\n";
- elseif ($action == 'move') $return .= get_lang('MoveTheCurrentExercise') . ' :' . "\n";
- else
- $return .= get_lang('EditCurrentExecice') . ' :' . "\n";
- if (isset ($_GET['edit']) && $_GET['edit'] == 'true') {
- $return .= Display :: return_warning_message('<p class="lp_title">' . get_lang('Warning') . ' !</p>' . get_lang('WarningEditingDocument'));
- }
- $return .= ' </div>
- </div>';
- $return .= '<div class="sectioncomment">';
- $return .= '<form method="POST">' . "\n";
- $return .= "\t" . '<table class="lp_form">' . "\n";
- if ($action != 'move') {
- $return .= "\t\t" . '<tr>' . "\n";
- $return .= "\t\t\t" . '<td class="label"><label for="idTitle">' . get_lang('Title') . '</label></td>' . "\n";
- $return .= "\t\t\t" . '<td class="input"><input id="idTitle" name="title" size="44" type="text" class="learnpath_item_form" value="' . $item_title . '" /></td>' . "\n";
- $return .= "\t\t" . '</tr>' . "\n";
- }
- $return .= "\t\t" . '<tr>' . "\n";
- $return .= "\t\t\t" . '<td class="label"><label for="idParent">' . get_lang('Parent') . '</label></td>' . "\n";
- $return .= "\t\t\t" . '<td class="input">' . "\n";
- $return .= "\t\t\t\t" . '<select id="idParent" style="width:100%;" name="parent" onChange="javascript: load_cbo(this.value);" class="learnpath_item_form" size="1">';
- $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
- $arrHide = array (
- $id
- );
-
- for ($i = 0; $i < count($arrLP); $i++) {
- if ($action != 'add') {
- if (($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir') && !in_array($arrLP[$i]['id'], $arrHide) && !in_array($arrLP[$i]['parent_item_id'], $arrHide)) {
- $return .= "\t\t\t\t\t" . '<option ' . (($parent == $arrLP[$i]['id']) ? 'selected="selected" ' : '') . 'style="padding-left:' . ($arrLP[$i]['depth'] * 10) . 'px;" value="' . $arrLP[$i]['id'] . '">' . $arrLP[$i]['title'] . '</option>';
- } else {
- $arrHide[] = $arrLP[$i]['id'];
- }
- } else {
- if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
- $return .= "\t\t\t\t\t" . '<option ' . (($parent == $arrLP[$i]['id']) ? 'selected="selected" ' : '') . 'style="padding-left:' . ($arrLP[$i]['depth'] * 10) . 'px;" value="' . $arrLP[$i]['id'] . '">' . $arrLP[$i]['title'] . '</option>';
- }
- }
- if (is_array($arrLP)) {
- reset($arrLP);
- }
- $return .= '</select>';
- $return .= '</td>';
- $return .= '</tr>';
- $return .= '<tr>';
- $return .= "\t\t\t" . '<td class="label"><label for="idPosition">' . get_lang('Position') . '</label></td>' . "\n";
- $return .= "\t\t\t" . '<td class="input">' . "\n";
- $return .= "\t\t\t\t" . '<select class="learnpath_item_form" style="width:100%;" id="idPosition" name="previous" size="1">';
- $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . get_lang('FirstPosition') . '</option>';
- for ($i = 0; $i < count($arrLP); $i++) {
- if ($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) {
- if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
- $selected = 'selected="selected" ';
- elseif ($action == 'add') $selected = 'selected="selected" ';
- else
- $selected = '';
- $return .= "\t\t\t\t\t" . '<option ' . $selected . 'value="' . $arrLP[$i]['id'] . '">' . get_lang('After') . ' "' . $arrLP[$i]['title'] . '"</option>';
- }
- }
- $return .= "\t\t\t\t" . '</select>';
- $return .= "\t\t\t" . '</td>' . "\n";
- $return .= "\t\t" . '</tr>' . "\n";
- if ($action != 'move') {
- $id_prerequisite = 0;
- if (is_array($arrLP)) {
- foreach ($arrLP as $key => $value) {
- if ($value['id'] == $id) {
- $id_prerequisite = $value['prerequisite'];
- break;
- }
- }
- }
- $arrHide = array ();
- for ($i = 0; $i < count($arrLP); $i++) {
- if ($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter') {
- if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
- $s_selected_position = $arrLP[$i]['id'];
- elseif ($action == 'add') $s_selected_position = 0;
- $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
- }
- }
-
- $return .= "\t\t" . '</tr>' . "\n";
-
- }
- $return .= "\t\t" . '<tr>' . "\n";
- if ($action == 'add') {
- $return .= '<td> </td><td><button class="save" name="submit_button" type="submit">' . get_lang('AddExercise') . '</button></td>';
- } else {
- $return .= '<td> </td><td><button class="save" name="submit_button" type="submit">' . get_lang('EditCurrentExecice') . '</button></td>';
- }
- $return .= "\t\t" . '</tr>' . "\n";
- $return .= "\t" . '</table>' . "\n";
- if ($action == 'move') {
- $return .= "\t" . '<input name="title" type="hidden" value="' . $item_title . '" />' . "\n";
- $return .= "\t" . '<input name="description" type="hidden" value="' . $item_description . '" />' . "\n";
- }
- if (is_numeric($extra_info)) {
- $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info . '" />' . "\n";
- }
- elseif (is_array($extra_info)) {
- $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />' . "\n";
- }
- $return .= "\t" . '<input name="type" type="hidden" value="' . TOOL_QUIZ . '" />' . "\n";
- $return .= "\t" . '<input name="post_time" type="hidden" value="' . time() . '" />' . "\n";
- $return .= '</form>' . "\n";
- $return .= '</div>' . "\n";
- return $return;
- }
-
- public function display_hotpotatoes_form($action = 'add', $id = 0, $extra_info = '') {
- global $charset;
- $uploadPath = DIR_HOTPOTATOES;
- $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
- if ($id != 0 && is_array($extra_info)) {
- $item_title = stripslashes($extra_info['title']);
- $item_description = stripslashes($extra_info['description']);
- }
- elseif (is_numeric($extra_info)) {
- $TBL_DOCUMENT = Database :: get_course_table(TABLE_DOCUMENT);
- $sql_hot = "SELECT * FROM " . $TBL_DOCUMENT . "
- WHERE path LIKE '" . $uploadPath . "/%/%htm%'
- AND id = " . (int) $extra_info . " ORDER BY id ASC";
- $res_hot = Database::query($sql_hot);
- $row = Database :: fetch_array($res_hot);
- $item_title = $row['title'];
- $item_description = $row['description'];
- if (!empty ($row['comment'])) {
- $item_title = $row['comment'];
- }
- } else {
- $item_title = '';
- $item_description = '';
- }
- $return = '<div style="margin:3px 12px;">';
- if ($id != 0 && is_array($extra_info))
- $parent = $extra_info['parent_item_id'];
- else
- $parent = 0;
- $sql = "
- SELECT *
- FROM " . $tbl_lp_item . "
- WHERE
- lp_id = " . $this->lp_id;
- $result = Database::query($sql);
- $arrLP = array ();
- while ($row = Database :: fetch_array($result)) {
- $arrLP[] = array (
- 'id' => $row['id'],
- 'item_type' => $row['item_type'],
- 'title' => $row['title'],
- 'path' => $row['path'],
- 'description' => $row['description'],
- 'parent_item_id' => $row['parent_item_id'],
- 'previous_item_id' => $row['previous_item_id'],
- 'next_item_id' => $row['next_item_id'],
- 'display_order' => $row['display_order'],
- 'max_score' => $row['max_score'],
- 'min_score' => $row['min_score'],
- 'mastery_score' => $row['mastery_score'],
- 'prerequisite' => $row['prerequisite'],
- 'max_time_allowed' => $row['max_time_allowed']
- );
- }
- $this->tree_array($arrLP);
- $arrLP = $this->arrMenu;
- unset ($this->arrMenu);
- if ($action == 'add')
- $return .= '<p class="lp_title">' . get_lang('CreateTheExercise') . ' :</p>' . "\n";
- elseif ($action == 'move') $return .= '<p class="lp_title">' . get_lang('MoveTheCurrentExercise') . ' :</p>' . "\n";
- else
- $return .= '<p class="lp_title">' . get_lang('EditCurrentExecice') . ' :</p>' . "\n";
- if (isset ($_GET['edit']) && $_GET['edit'] == 'true') {
- $return .= Display :: return_warning_message('<p class="lp_title">' . get_lang('Warning') . ' !</p>' . get_lang('WarningEditingDocument'));
- }
- $return .= '<form method="POST">' . "\n";
- $return .= "\t" . '<table cellpadding="0" cellspacing="0" class="lp_form">' . "\n";
- $return .= "\t\t" . '<tr>' . "\n";
- $return .= "\t\t\t" . '<td class="label"><label for="idParent">' . get_lang('Parent') . ' :</label></td>' . "\n";
- $return .= "\t\t\t" . '<td class="input">' . "\n";
- $return .= "\t\t\t\t" . '<select id="idParent" name="parent" onChange="javascript: load_cbo(this.value);" size="1">';
- $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
- $arrHide = array (
- $id
- );
- if (count($arrLP) > 0) {
- for ($i = 0; $i < count($arrLP); $i++) {
- if ($action != 'add') {
- if (($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir') && !in_array($arrLP[$i]['id'], $arrHide) && !in_array($arrLP[$i]['parent_item_id'], $arrHide)) {
- $return .= "\t\t\t\t\t" . '<option ' . (($parent == $arrLP[$i]['id']) ? 'selected="selected" ' : '') . 'style="padding-left:' . ($arrLP[$i]['depth'] * 10) . 'px;" value="' . $arrLP[$i]['id'] . '">' . $arrLP[$i]['title'] . '</option>';
- } else {
- $arrHide[] = $arrLP[$i]['id'];
- }
- } else {
- if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
- $return .= "\t\t\t\t\t" . '<option ' . (($parent == $arrLP[$i]['id']) ? 'selected="selected" ' : '') . 'style="padding-left:' . ($arrLP[$i]['depth'] * 10) . 'px;" value="' . $arrLP[$i]['id'] . '">' . $arrLP[$i]['title'] . '</option>';
- }
- }
- reset($arrLP);
- }
- $return .= "\t\t\t\t" . '</select>';
- $return .= "\t\t\t" . '</td>' . "\n";
- $return .= "\t\t" . '</tr>' . "\n";
- $return .= "\t\t" . '<tr>' . "\n";
- $return .= "\t\t\t" . '<td class="label"><label for="idPosition">' . get_lang('Position') . ' :</label></td>' . "\n";
- $return .= "\t\t\t" . '<td class="input">' . "\n";
- $return .= "\t\t\t\t" . '<select id="idPosition" name="previous" size="1">';
- $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . get_lang('FirstPosition') . '</option>';
- for ($i = 0; $i < count($arrLP); $i++) {
- if ($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) {
- if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
- $selected = 'selected="selected" ';
- elseif ($action == 'add') $selected = 'selected="selected" ';
- else
- $selected = '';
- $return .= "\t\t\t\t\t" . '<option ' . $selected . 'value="' . $arrLP[$i]['id'] . '">' . get_lang('After') . ' "' . $arrLP[$i]['title'] . '"</option>';
- }
- }
- $return .= "\t\t\t\t" . '</select>';
- $return .= "\t\t\t" . '</td>' . "\n";
- $return .= "\t\t" . '</tr>' . "\n";
- if ($action != 'move') {
- $return .= "\t\t" . '<tr>' . "\n";
- $return .= "\t\t\t" . '<td class="label"><label for="idTitle">' . get_lang('Title') . ' :</label></td>' . "\n";
- $return .= "\t\t\t" . '<td class="input"><input id="idTitle" name="title" type="text" value="' . $item_title . '" /></td>' . "\n";
- $return .= "\t\t" . '</tr>' . "\n";
- $id_prerequisite = 0;
- if (is_array($arrLP) && count($arrLP) > 0) {
- foreach ($arrLP as $key => $value) {
- if ($value['id'] == $id) {
- $id_prerequisite = $value['prerequisite'];
- break;
- }
- }
- $arrHide = array ();
- for ($i = 0; $i < count($arrLP); $i++) {
- if ($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter') {
- if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
- $s_selected_position = $arrLP[$i]['id'];
- elseif ($action == 'add') $s_selected_position = 0;
- $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
- }
- }
- }
- $return .= "\t\t" . '<tr>' . "\n";
-
-
- foreach ($arrHide as $key => $value) {
- if ($key == $s_selected_position && $action == 'add') {
- $return .= '<option value="' . $key . '" selected="selected">' . $value['value'] . '</option>';
- }
- elseif ($key == $id_prerequisite && $action == 'edit') {
- $return .= '<option value="' . $key . '" selected="selected">' . $value['value'] . '</option>';
- } else {
- $return .= '<option value="' . $key . '">' . $value['value'] . '</option>';
- }
- }
- $return .= "</select></td>";
- $return .= "\t\t" . '</tr>' . "\n";
- $return .= "\t\t" . '<tr>' . "\n";
- $return .= "\t\t" . '</tr>' . "\n";
- }
- $return .= "\t\t" . '<tr>' . "\n";
- $return .= "\t\t\t" . '<td> </td><td><button class="save" name="submit_button" action="edit" type="submit">' . get_lang('SaveHotpotatoes') . '</button></td>' . "\n";
- $return .= "\t\t" . '</tr>' . "\n";
- $return .= "\t" . '</table>' . "\n";
- if ($action == 'move') {
- $return .= "\t" . '<input name="title" type="hidden" value="' . $item_title . '" />' . "\n";
- $return .= "\t" . '<input name="description" type="hidden" value="' . $item_description . '" />' . "\n";
- }
- if (is_numeric($extra_info)) {
- $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info . '" />' . "\n";
- }
- elseif (is_array($extra_info)) {
- $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />' . "\n";
- }
- $return .= "\t" . '<input name="type" type="hidden" value="' . TOOL_HOTPOTATOES . '" />' . "\n";
- $return .= "\t" . '<input name="post_time" type="hidden" value="' . time() . '" />' . "\n";
- $return .= '</form>' . "\n";
- $return .= '</div>' . "\n";
- return $return;
- }
-
- public function display_forum_form($action = 'add', $id = 0, $extra_info = '') {
- global $charset;
- $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
- $tbl_forum = Database :: get_course_table(TABLE_FORUM);
- if ($id != 0 && is_array($extra_info)) {
- $item_title = stripslashes($extra_info['title']);
- }
- elseif (is_numeric($extra_info)) {
- $sql_forum = "
- SELECT
- forum_title as title, forum_comment as comment
- FROM " . $tbl_forum . "
- WHERE forum_id = " . $extra_info;
- $result = Database::query($sql_forum);
- $row = Database :: fetch_array($result);
- $item_title = $row['title'];
- $item_description = $row['comment'];
- } else {
- $item_title = '';
- $item_description = '';
- }
- $return = ' <div class="row">
- <div class="form_header">';
- if ($id != 0 && is_array($extra_info))
- $parent = $extra_info['parent_item_id'];
- else
- $parent = 0;
- $sql = "
- SELECT *
- FROM " . $tbl_lp_item . "
- WHERE
- lp_id = " . $this->lp_id;
- $result = Database::query($sql);
- $arrLP = array ();
- while ($row = Database :: fetch_array($result)) {
- $arrLP[] = array (
- 'id' => $row['id'],
- 'item_type' => $row['item_type'],
- 'title' => $row['title'],
- 'path' => $row['path'],
- 'description' => $row['description'],
- 'parent_item_id' => $row['parent_item_id'],
- 'previous_item_id' => $row['previous_item_id'],
- 'next_item_id' => $row['next_item_id'],
- 'display_order' => $row['display_order'],
- 'max_score' => $row['max_score'],
- 'min_score' => $row['min_score'],
- 'mastery_score' => $row['mastery_score'],
- 'prerequisite' => $row['prerequisite']
- );
- }
- $this->tree_array($arrLP);
- $arrLP = $this->arrMenu;
- unset ($this->arrMenu);
- if ($action == 'add')
- $return .= get_lang('CreateTheForum') . ' :' . "\n";
- elseif ($action == 'move') $return .= get_lang('MoveTheCurrentForum') . ' :' . "\n";
- else
- $return .= get_lang('EditCurrentForum') . ' :' . "\n";
- $return .= ' </div>
- </div>';
- $return .= '<div class="sectioncomment">';
- $return .= '<form method="POST">' . "\n";
- $return .= "\t" . '<table class="lp_form">' . "\n";
- if ($action != 'move') {
- $return .= "\t\t" . '<tr>' . "\n";
- $return .= "\t\t\t" . '<td class="label"><label for="idTitle">' . get_lang('Title') . '</label></td>' . "\n";
- $return .= "\t\t\t" . '<td class="input"><input id="idTitle" size="44" name="title" type="text" value="' . $item_title . '" class="learnpath_item_form" /></td>' . "\n";
- $return .= "\t\t" . '</tr>' . "\n";
- }
- $return .= "\t\t" . '<tr>' . "\n";
- $return .= "\t\t\t" . '<td class="label"><label for="idParent">' . get_lang('Parent') . '</label></td>' . "\n";
- $return .= "\t\t\t" . '<td class="input">' . "\n";
- $return .= "\t\t\t\t" . '<select id="idParent" style="width:100%;" name="parent" onChange="javascript: load_cbo(this.value);" class="learnpath_item_form" size="1">';
- $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
- $arrHide = array (
- $id
- );
-
- for ($i = 0; $i < count($arrLP); $i++) {
- if ($action != 'add') {
- if (($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir') && !in_array($arrLP[$i]['id'], $arrHide) && !in_array($arrLP[$i]['parent_item_id'], $arrHide)) {
- $return .= "\t\t\t\t\t" . '<option ' . (($parent == $arrLP[$i]['id']) ? 'selected="selected" ' : '') . 'style="padding-left:' . ($arrLP[$i]['depth'] * 10) . 'px;" value="' . $arrLP[$i]['id'] . '">' . $arrLP[$i]['title'] . '</option>';
- } else {
- $arrHide[] = $arrLP[$i]['id'];
- }
- } else {
- if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
- $return .= "\t\t\t\t\t" . '<option ' . (($parent == $arrLP[$i]['id']) ? 'selected="selected" ' : '') . 'style="padding-left:' . ($arrLP[$i]['depth'] * 10) . 'px;" value="' . $arrLP[$i]['id'] . '">' . $arrLP[$i]['title'] . '</option>';
- }
- }
- if (is_array($arrLP)) {
- reset($arrLP);
- }
- $return .= "\t\t\t\t" . '</select>';
- $return .= "\t\t\t" . '</td>' . "\n";
- $return .= "\t\t" . '</tr>' . "\n";
- $return .= "\t\t" . '<tr>' . "\n";
- $return .= "\t\t\t" . '<td class="label"><label for="idPosition">' . get_lang('Position') . '</label></td>' . "\n";
- $return .= "\t\t\t" . '<td class="input">' . "\n";
- $return .= "\t\t\t\t" . '<select id="idPosition" name="previous" style="width:100%;" size="1" class="learnpath_item_form">';
- $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . get_lang('FirstPosition') . '</option>';
- for ($i = 0; $i < count($arrLP); $i++) {
- if ($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) {
- if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
- $selected = 'selected="selected" ';
- elseif ($action == 'add') $selected = 'selected="selected" ';
- else
- $selected = '';
- $return .= "\t\t\t\t\t" . '<option ' . $selected . 'value="' . $arrLP[$i]['id'] . '">' . get_lang('After') . ' "' . $arrLP[$i]['title'] . '"</option>';
- }
- }
- $return .= "\t\t\t\t" . '</select>';
- $return .= "\t\t\t" . '</td>' . "\n";
- $return .= "\t\t" . '</tr>' . "\n";
- if ($action != 'move') {
- $return .= "\t\t" . '<tr>' . "\n";
- $return .= "\t\t" . '</tr>' . "\n";
- $id_prerequisite = 0;
- if (is_array($arrLP)) {
- foreach ($arrLP as $key => $value) {
- if ($value['id'] == $id) {
- $id_prerequisite = $value['prerequisite'];
- break;
- }
- }
- }
- $arrHide = array ();
- for ($i = 0; $i < count($arrLP); $i++) {
- if ($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter') {
- if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
- $s_selected_position = $arrLP[$i]['id'];
- elseif ($action == 'add') $s_selected_position = 0;
- $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
- }
- }
- $return .= "\t\t" . '</tr>' . "\n";
- }
- $return .= "\t\t" . '<tr>' . "\n";
- if ($action == 'add') {
- $return .= '<td> </td><td><button class="save" name="submit_button" type="submit"> ' . get_lang('AddForumToCourse') . ' </button></td>';
- } else {
- $return .= '<td> </td><td><button class="save" name="submit_button" type="submit"> ' . get_lang('EditCurrentForum') . ' </button></td>';
- }
- $return .= "\t\t" . '</tr>' . "\n";
- $return .= "\t" . '</table>' . "\n";
- if ($action == 'move') {
- $return .= "\t" . '<input name="title" type="hidden" value="' . $item_title . '" />' . "\n";
- $return .= "\t" . '<input name="description" type="hidden" value="' . $item_description . '" />' . "\n";
- }
- if (is_numeric($extra_info)) {
- $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info . '" />' . "\n";
- }
- elseif (is_array($extra_info)) {
- $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />' . "\n";
- }
- $return .= "\t" . '<input name="type" type="hidden" value="' . TOOL_FORUM . '" />' . "\n";
- $return .= "\t" . '<input name="post_time" type="hidden" value="' . time() . '" />' . "\n";
- $return .= '</form>' . "\n";
- $return .= '</div>' . "\n";
- return $return;
- }
-
- public function display_thread_form($action = 'add', $id = 0, $extra_info = '') {
- global $charset;
- echo '
- <style>
- div.row div.label {
- width:110px;
- }
- div.row div.formw {
- width: 82%;
- }
- </style>';
- $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
- $tbl_forum = Database :: get_course_table(TABLE_FORUM_THREAD);
- if ($id != 0 && is_array($extra_info)) {
- $item_title = stripslashes($extra_info['title']);
- }
- elseif (is_numeric($extra_info)) {
- $sql_forum = "
- SELECT
- thread_title as title
- FROM " . $tbl_forum . "
- WHERE thread_id = " . $extra_info;
- $result = Database::query($sql_forum);
- $row = Database :: fetch_array($result);
- $item_title = $row['title'];
- $item_description = '';
- } else {
- $item_title = '';
- $item_description = '';
- }
- $return = '<div style="margin:3px 12px;">';
- if ($id != 0 && is_array($extra_info))
- $parent = $extra_info['parent_item_id'];
- else
- $parent = 0;
- $sql = "
- SELECT *
- FROM " . $tbl_lp_item . "
- WHERE
- lp_id = " . $this->lp_id;
- $result = Database::query($sql);
- $arrLP = array ();
- while ($row = Database :: fetch_array($result)) {
- $arrLP[] = array (
- 'id' => $row['id'],
- 'item_type' => $row['item_type'],
- 'title' => $row['title'],
- 'path' => $row['path'],
- 'description' => $row['description'],
- 'parent_item_id' => $row['parent_item_id'],
- 'previous_item_id' => $row['previous_item_id'],
- 'next_item_id' => $row['next_item_id'],
- 'display_order' => $row['display_order'],
- 'max_score' => $row['max_score'],
- 'min_score' => $row['min_score'],
- 'mastery_score' => $row['mastery_score'],
- 'prerequisite' => $row['prerequisite']
- );
- }
- $this->tree_array($arrLP);
- $arrLP = $this->arrMenu;
- unset ($this->arrMenu);
- if ($action == 'add')
- $return .= '<p class="lp_title">' . get_lang('CreateTheForum') . ' :</p>' . "\n";
- elseif ($action == 'move') $return .= '<p class="lp_title">' . get_lang('MoveTheCurrentForum') . ' :</p>' . "\n";
- else
- $return .= '<p class="lp_title">' . get_lang('EditCurrentForum') . ' :</p>' . "\n";
- $return .= '<form method="POST">' . "\n";
- $return .= "\t" . '<table cellpadding="0" cellspacing="0" class="lp_form">' . "\n";
- $return .= "\t\t" . '<tr>' . "\n";
- $return .= "\t\t\t" . '<td class="label"><label for="idParent">' . get_lang('Parent') . ' :</label></td>' . "\n";
- $return .= "\t\t\t" . '<td class="input">' . "\n";
- $return .= "\t\t\t\t" . '<select id="idParent" name="parent" onChange="javascript: load_cbo(this.value);" size="1">';
- $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
- $arrHide = array (
- $id
- );
- for ($i = 0; $i < count($arrLP); $i++) {
- if ($action != 'add') {
- if (($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir') && !in_array($arrLP[$i]['id'], $arrHide) && !in_array($arrLP[$i]['parent_item_id'], $arrHide)) {
- $return .= "\t\t\t\t\t" . '<option ' . (($parent == $arrLP[$i]['id']) ? 'selected="selected" ' : '') . 'style="padding-left:' . ($arrLP[$i]['depth'] * 10) . 'px;" value="' . $arrLP[$i]['id'] . '">' . $arrLP[$i]['title'] . '</option>';
- } else {
- $arrHide[] = $arrLP[$i]['id'];
- }
- } else {
- if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
- $return .= "\t\t\t\t\t" . '<option ' . (($parent == $arrLP[$i]['id']) ? 'selected="selected" ' : '') . 'style="padding-left:' . ($arrLP[$i]['depth'] * 10) . 'px;" value="' . $arrLP[$i]['id'] . '">' . $arrLP[$i]['title'] . '</option>';
- }
- }
- if ($arrLP != null) {
- reset($arrLP);
- }
- $return .= "\t\t\t\t" . '</select>';
- $return .= "\t\t\t" . '</td>' . "\n";
- $return .= "\t\t" . '</tr>' . "\n";
- $return .= "\t\t" . '<tr>' . "\n";
- $return .= "\t\t\t" . '<td class="label"><label for="idPosition">' . get_lang('Position') . ' :</label></td>' . "\n";
- $return .= "\t\t\t" . '<td class="input">' . "\n";
- $return .= "\t\t\t\t" . '<select id="idPosition" name="previous" size="1">';
- $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . get_lang('FirstPosition') . '</option>';
- for ($i = 0; $i < count($arrLP); $i++) {
- if ($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) {
- if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
- $selected = 'selected="selected" ';
- elseif ($action == 'add') $selected = 'selected="selected" ';
- else
- $selected = '';
- $return .= "\t\t\t\t\t" . '<option ' . $selected . 'value="' . $arrLP[$i]['id'] . '">' . get_lang('After') . ' "' . $arrLP[$i]['title'] . '"</option>';
- }
- }
- $return .= "\t\t\t\t" . '</select>';
- $return .= "\t\t\t" . '</td>' . "\n";
- $return .= "\t\t" . '</tr>' . "\n";
- if ($action != 'move') {
- $return .= "\t\t" . '<tr>' . "\n";
- $return .= "\t\t\t" . '<td class="label"><label for="idTitle">' . get_lang('Title') . ' :</label></td>' . "\n";
- $return .= "\t\t\t" . '<td class="input"><input id="idTitle" name="title" type="text" value="' . $item_title . '" /></td>' . "\n";
- $return .= "\t\t" . '</tr>' . "\n";
- $return .= "\t\t" . '<tr>' . "\n";
- $return .= "\t\t" . '</tr>' . "\n";
- $id_prerequisite = 0;
- if ($arrLP != null) {
- foreach ($arrLP as $key => $value) {
- if ($value['id'] == $id) {
- $id_prerequisite = $value['prerequisite'];
- break;
- }
- }
- }
- $arrHide = array();
- for ($i = 0; $i < count($arrLP); $i++) {
- if ($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter') {
- if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
- $s_selected_position = $arrLP[$i]['id'];
- elseif ($action == 'add') $s_selected_position = 0;
- $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
- }
- }
- $return .= "\t\t" . '<tr>' . "\n";
- $return .= "\t\t\t" . '<td class="label"><label for="idPrerequisites">' . get_lang('Prerequisites') . ' :</label></td>' . "\n";
- $return .= "\t\t\t" . '<td class="input"><select name="prerequisites" id="prerequisites"><option value="0">' . get_lang('NoPrerequisites') . '</option>';
- foreach ($arrHide as $key => $value) {
- if ($key == $s_selected_position && $action == 'add') {
- $return .= '<option value="' . $key . '" selected="selected">' . $value['value'] . '</option>';
- }
- elseif ($key == $id_prerequisite && $action == 'edit') {
- $return .= '<option value="' . $key . '" selected="selected">' . $value['value'] . '</option>';
- } else {
- $return .= '<option value="' . $key . '">' . $value['value'] . '</option>';
- }
- }
- $return .= "</select></td>";
- $return .= "\t\t" . '</tr>' . "\n";
- }
- $return .= "\t\t" . '<tr>' . "\n";
- $return .= "\t\t\t" . '<td colspan="2">
- <button class="save" name="submit_button" type="submit" value="'.get_lang('Ok').'" />'.get_lang('Ok').'</button></td>' . "\n";
- $return .= "\t\t" . '</tr>' . "\n";
- $return .= "\t" . '</table>' . "\n";
- if ($action == 'move') {
- $return .= "\t" . '<input name="title" type="hidden" value="' . $item_title . '" />' . "\n";
- $return .= "\t" . '<input name="description" type="hidden" value="' . $item_description . '" />' . "\n";
- }
- if (is_numeric($extra_info)) {
- $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info . '" />' . "\n";
- }
- elseif (is_array($extra_info)) {
- $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />' . "\n";
- }
- $return .= "\t" . '<input name="type" type="hidden" value="' . TOOL_THREAD . '" />' . "\n";
- $return .= "\t" . '<input name="post_time" type="hidden" value="' . time() . '" />' . "\n";
- $return .= '</form>' . "\n";
- $return .= '</div>' . "\n";
- return $return;
- }
-
- public function display_item_form($item_type, $title = '', $action = 'add', $id = 0, $extra_info = 'new') {
- global $_course;
- global $charset;
- $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
- if ($id != 0 && is_array($extra_info)) {
- $item_title = $extra_info['title'];
- $item_description = $extra_info['description'];
- $item_path = api_get_path(WEB_COURSE_PATH) . $_course['path'] . '/scorm/' . $this->path . '/' . stripslashes($extra_info['path']);
- } else {
- $item_title = '';
- $item_description = '';
- }
- $return = ' <div class="row">
- <div class="form_header">';
- if ($id != 0 && is_array($extra_info))
- $parent = $extra_info['parent_item_id'];
- else
- $parent = 0;
- $sql = "
- SELECT *
- FROM " . $tbl_lp_item . "
- WHERE lp_id = " . $this->lp_id . " AND id != " . $id . " ";
- if ($item_type == 'module')
- $sql .= " AND parent_item_id = 0";
- $result = Database::query($sql);
- $arrLP = array ();
- while ($row = Database :: fetch_array($result)) {
- $arrLP[] = array (
- 'id' => $row['id'],
- 'item_type' => $row['item_type'],
- 'title' => $row['title'],
- 'path' => $row['path'],
- 'description' => $row['description'],
- 'parent_item_id' => $row['parent_item_id'],
- 'previous_item_id' => $row['previous_item_id'],
- 'next_item_id' => $row['next_item_id'],
- 'max_score' => $row['max_score'],
- 'min_score' => $row['min_score'],
- 'mastery_score' => $row['mastery_score'],
- 'prerequisite' => $row['prerequisite'],
- 'display_order' => $row['display_order']
- );
- }
- $this->tree_array($arrLP);
- $arrLP = $this->arrMenu;
- unset ($this->arrMenu);
- $return .= $title . "\n";
- $return .= ' </div>
- </div>';
- require_once api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php';
- $form = new FormValidator('form', 'POST', api_get_self() . '?' . $_SERVER['QUERY_STRING']);
- $defaults['title'] = api_html_entity_decode($item_title, ENT_QUOTES, $charset);
- $defaults['description'] = $item_description;
- $form->addElement('html', $return);
-
- $arrHide[0]['value'] = Security :: remove_XSS($this->name);
- $arrHide[0]['padding'] = 3;
- $charset = api_get_system_encoding();
- if ($item_type != 'module' && $item_type != 'dokeos_module') {
- for ($i = 0; $i < count($arrLP); $i++) {
- if ($action != 'add') {
- if (($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir') && !in_array($arrLP[$i]['id'], $arrHide) && !in_array($arrLP[$i]['parent_item_id'], $arrHide)) {
- $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
- $arrHide[$arrLP[$i]['id']]['padding'] = 3 + $arrLP[$i]['depth'] * 10;
- if ($parent == $arrLP[$i]['id']) {
- $s_selected_parent = $arrHide[$arrLP[$i]['id']];
- }
- }
- } else {
- if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir') {
- $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
- $arrHide[$arrLP[$i]['id']]['padding'] = 3 + $arrLP[$i]['depth'] * 10;
- if ($parent == $arrLP[$i]['id']) {
- $s_selected_parent = $arrHide[$arrLP[$i]['id']];
- }
- }
- }
- }
- if ($action != 'move') {
- $form->addElement('text', 'title', get_lang('Title'), 'id="idTitle" class="learnpath_chapter_form" size="40%"');
- $form->applyFilter('title', 'html_filter');
- $form->addRule('title', '<div class="required">' . get_lang('ThisFieldIsRequired'), 'required');
-
- } else {
- $form->addElement('hidden', 'title');
- }
- $parent_select = & $form->addElement('select', 'parent', get_lang('Parent'), '', 'class="learnpath_chapter_form" style="width:37%;" id="idParent" onchange="javascript: load_cbo(this.value);"');
- foreach ($arrHide as $key => $value) {
- $parent_select->addOption($value['value'], $key, 'style="padding-left:' . $value['padding'] . 'px;"');
- }
- $parent_select->setSelected($s_selected_parent);
- }
- if (is_array($arrLP)) {
- reset($arrLP);
- }
- $arrHide = array ();
-
- for ($i = 0; $i < count($arrLP); $i++) {
- if ($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) {
- if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
- $s_selected_position = $arrLP[$i]['id'];
- elseif ($action == 'add') $s_selected_position = $arrLP[$i]['id'];
- $arrHide[$arrLP[$i]['id']]['value'] = get_lang('After') . ' "' . $arrLP[$i]['title'] . '"';
- }
- }
- $position = & $form->addElement('select', 'previous', get_lang('Position'), '', 'id="idPosition" class="learnpath_chapter_form" style="width:37%;"');
- $position->addOption(get_lang('FirstPosition'), 0, 'style="padding-left:' . $value['padding'] . 'px;"');
- foreach ($arrHide as $key => $value) {
- $position->addOption($value['value'] . '"', $key, 'style="padding-left:' . $value['padding'] . 'px;"');
- }
- if (!empty ($s_selected_position)) {
- $position->setSelected($s_selected_position);
- }
- if (is_array($arrLP)) {
- reset($arrLP);
- }
- $form->addElement('style_submit_button', 'submit_button', get_lang('SaveSection'), 'class="save"');
- if ($item_type == 'module' || $item_type == 'dokeos_module') {
- $form->addElement('hidden', 'parent', '0');
- }
- $extension = pathinfo($item_path, PATHINFO_EXTENSION);
- if (($item_type == 'asset' || $item_type == 'sco') && ($extension == 'html' || $extension == 'htm')) {
- if ($item_type == 'sco') {
- $form->addElement('html', '<script type="text/javascript">alert("' . get_lang('WarningWhenEditingScorm') . '")</script>');
- }
- $renderer = $form->defaultRenderer();
- $renderer->setElementTemplate('<br /> {label}<br />{element}', 'content_lp');
- $form->addElement('html_editor', 'content_lp', '', null, array('ToolbarSet' => 'LearningPathDocuments', 'Width' => '100%', 'Height' => '400', 'FullPage' => true));
- $defaults['content_lp'] = file_get_contents($item_path);
- }
- $form->addElement('hidden', 'type', 'dokeos_' . $item_type);
- $form->addElement('hidden', 'post_time', time());
- $form->setDefaults($defaults);
- return $form->return_form();
- }
-
- public function display_document_form($action = 'add', $id = 0, $extra_info = 'new') {
- global $charset;
- $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
- $tbl_doc = Database :: get_course_table(TABLE_DOCUMENT);
- $path_parts = pathinfo($extra_info['dir']);
- $no_display_edit_textarea = false;
-
-
- if ($action == "edit") {
- if (is_array($extra_info)) {
- if ($path_parts['extension'] != "txt" && $path_parts['extension'] != "html") {
- $no_display_edit_textarea = true;
- }
- }
- }
- $no_display_add = false;
-
-
- if ($action == "add") {
- if (is_numeric($extra_info)) {
- $sql_doc = "SELECT path FROM " . $tbl_doc . "WHERE id = " . Database :: escape_string($extra_info);
- $result = Database::query($sql_doc);
- $path_file = Database :: result($result, 0, 0);
- $path_parts = pathinfo($path_file);
- if ($path_parts['extension'] != "txt" && $path_parts['extension'] != "html") {
- $no_display_add = true;
- }
- }
- }
- if ($id != 0 && is_array($extra_info)) {
- $item_title = stripslashes($extra_info['title']);
- $item_description = stripslashes($extra_info['description']);
- $item_terms = stripslashes($extra_info['terms']);
- if (empty ($item_title)) {
- $path_parts = pathinfo($extra_info['path']);
- $item_title = stripslashes($path_parts['filename']);
- }
- } elseif (is_numeric($extra_info)) {
- $sql_doc = "SELECT path, title FROM " . $tbl_doc . "
- WHERE id = " . Database :: escape_string($extra_info);
- $result = Database::query($sql_doc);
- $row = Database :: fetch_array($result);
- $explode = explode('.', $row['title']);
- if (count($explode) > 1) {
- for ($i = 0; $i < count($explode) - 1; $i++)
- $item_title .= $explode[$i];
- } else {
- $item_title = $row['title'];
- }
- $item_title = str_replace('_', ' ', $item_title);
- if (empty ($item_title)) {
- $path_parts = pathinfo($row['path']);
- $item_title = stripslashes($path_parts['filename']);
- }
- } else {
- $item_title = '';
- $item_description = '';
- }
- $return = ' <div class="row">
- <div class="form_header">';
- if ($id != 0 && is_array($extra_info))
- $parent = $extra_info['parent_item_id'];
- else
- $parent = 0;
- $sql = "SELECT * FROM " . $tbl_lp_item . "
- WHERE lp_id = " . $this->lp_id;
- $result = Database::query($sql);
- $arrLP = array ();
- while ($row = Database :: fetch_array($result)) {
- $arrLP[] = array (
- 'id' => $row['id'],
- 'item_type' => $row['item_type'],
- 'title' => $row['title'],
- 'path' => $row['path'],
- 'description' => $row['description'],
- 'parent_item_id' => $row['parent_item_id'],
- 'previous_item_id' => $row['previous_item_id'],
- 'next_item_id' => $row['next_item_id'],
- 'display_order' => $row['display_order'],
- 'max_score' => $row['max_score'],
- 'min_score' => $row['min_score'],
- 'mastery_score' => $row['mastery_score'],
- 'prerequisite' => $row['prerequisite']
- );
- }
- $this->tree_array($arrLP);
- $arrLP = $this->arrMenu;
- unset ($this->arrMenu);
- if ($action == 'add') {
- $return .= get_lang('CreateTheDocument') . "\n";
- }
- elseif ($action == 'move') {
- $return .= get_lang('MoveTheCurrentDocument') . "\n";
- } else {
- $return .= get_lang('EditTheCurrentDocument') . "\n";
- }
- $return .= '</div>
- </div>';
- if (isset ($_GET['edit']) && $_GET['edit'] == 'true') {
- $return .= Display :: return_warning_message('<strong>' . get_lang('Warning') . ' !</strong><br />' . get_lang('WarningEditingDocument'), false);
- }
- require_once api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php';
- $form = new FormValidator('form', 'POST', api_get_self() . '?' . $_SERVER['QUERY_STRING'], '', 'enctype="multipart/form-data"');
- $defaults['title'] = Security :: remove_XSS($item_title);
- if (empty($item_title)) {
- $defaults['title'] = Security::remove_XSS($item_title);
- }
- $defaults['description'] = $item_description;
- $form->addElement('html', $return);
- if ($action != 'move') {
- $form->addElement('text', 'title', get_lang('Title'), 'id="idTitle" class="learnpath_item_form" size=44%');
- $form->applyFilter('title', 'html_filter');
- }
-
- $arrHide[0]['value'] = $this->name;
- $arrHide[0]['padding'] = 3;
- for ($i = 0; $i < count($arrLP); $i++) {
- if ($action != 'add') {
- if (($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir') && !in_array($arrLP[$i]['id'], $arrHide) && !in_array($arrLP[$i]['parent_item_id'], $arrHide)) {
- $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
- $arrHide[$arrLP[$i]['id']]['padding'] = 3 + $arrLP[$i]['depth'] * 10;
- if ($parent == $arrLP[$i]['id']) {
- $s_selected_parent = $arrHide[$arrLP[$i]['id']];
- }
- }
- } else {
- if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir') {
- $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
- $arrHide[$arrLP[$i]['id']]['padding'] = 3 + $arrLP[$i]['depth'] * 10;
- if ($parent == $arrLP[$i]['id']) {
- $s_selected_parent = $arrHide[$arrLP[$i]['id']];
- }
- }
- }
- }
- $parent_select = & $form->addElement('select', 'parent', get_lang('Parent'), '', 'class="learnpath_item_form" id="idParent" style="width:40%;" onchange="javascript: load_cbo(this.value);"');
- $my_count=0;
- foreach ($arrHide as $key => $value) {
- if ($my_count!=0) {
-
- $value['value'] = Security :: remove_XSS($value['value']);
- $parent_select->addOption($value['value'], $key, 'style="padding-left:' . $value['padding'] . 'px;"');
- } else {
- $value['value'] = Security :: remove_XSS($value['value']);
- $parent_select->addOption($value['value'], $key, 'style="padding-left:' . $value['padding'] . 'px;"');
- }
- $my_count++;
- }
- if (!empty ($id)) {
- $parent_select->setSelected($parent);
- } else {
- $parent_item_id = $_SESSION['parent_item_id'];
- $parent_select->setSelected($parent_item_id);
- }
- if (is_array($arrLP)) {
- reset($arrLP);
- }
- $arrHide = array ();
-
- for ($i = 0; $i < count($arrLP); $i++) {
- if ($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) {
- if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
- $s_selected_position = $arrLP[$i]['id'];
- elseif ($action == 'add') $s_selected_position = $arrLP[$i]['id'];
- $arrHide[$arrLP[$i]['id']]['value'] = get_lang('After') . ' "' . $arrLP[$i]['title'] . '"';
- }
- }
- $position = & $form->addElement('select', 'previous', get_lang('Position'), '', 'id="idPosition" class="learnpath_item_form" style="width:40%;"');
- $position->addOption(get_lang('FirstPosition'), 0);
- foreach ($arrHide as $key => $value) {
- $position->addOption($value['value'], $key, 'style="padding-left:' . $value['padding'] . 'px;"');
- }
- $position->setSelected($s_selected_position);
- if (is_array($arrLP)) {
- reset($arrLP);
- }
- if ($action != 'move') {
- $id_prerequisite = 0;
- if (is_array($arrLP)) {
- foreach ($arrLP as $key => $value) {
- if ($value['id'] == $id) {
- $id_prerequisite = $value['prerequisite'];
- break;
- }
- }
- }
-
-
-
-
-
-
-
- $arrHide = array ();
- for ($i = 0; $i < count($arrLP); $i++) {
- if ($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter') {
- if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
- $s_selected_position = $arrLP[$i]['id'];
- elseif ($action == 'add') $s_selected_position = $arrLP[$i]['id'];
- $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
- }
- }
-
- if (!$no_display_add) {
- if (($extra_info == 'new' || $extra_info['item_type'] == TOOL_DOCUMENT || $_GET['edit'] == 'true')) {
- if (isset ($_POST['content']))
- $content = stripslashes($_POST['content']);
- elseif (is_array($extra_info)) {
-
- if (!$no_display_edit_textarea) {
- $content = $this->display_document($extra_info['path'], false, false);
- }
- }
- elseif (is_numeric($extra_info)) $content = $this->display_document($extra_info, false, false);
- else
- $content = '';
- if (!$no_display_edit_textarea) {
-
-
-
-
-
- $relative_path = $extra_info['dir'];
- if ($relative_path == 'n/') {
-
- $relative_path = '';
- $relative_prefix = '';
- } else {
-
- $relative_path = explode('/', $relative_path);
- $cnt = count($relative_path) - 2;
- if ($cnt < 0) {
- $cnt = 0;
- }
- $relative_prefix = str_repeat('../', $cnt);
- $relative_path = array_slice($relative_path, 1, $cnt);
- $relative_path = implode('/', $relative_path);
- if (strlen($relative_path) > 0) {
- $relative_path = $relative_path . '/';
- }
- }
- $editor_config = array('ToolbarSet' => 'LearningPathDocuments', 'Width' => '100%', 'Height' => '700', 'FullPage' => true,
- 'CreateDocumentDir' => $relative_prefix,
- 'CreateDocumentWebDir' => api_get_path(WEB_COURSE_PATH) . api_get_course_path() . '/document/',
- 'BaseHref' => api_get_path(WEB_COURSE_PATH) . api_get_course_path() . '/document/' . $relative_path
- );
- if ($_GET['action'] == 'add_item') {
- $class = 'add';
- $text = get_lang('LPCreateDocument');
- } else
- if ($_GET['action'] == 'edit_item') {
- $class = 'save';
- $text = get_lang('SaveDocument');
- }
- $form->addElement('style_submit_button', 'submit_button', $text, 'class="' . $class . '"');
- $renderer = $form->defaultRenderer();
- $renderer->setElementTemplate('<br /> {label}<br />{element}', 'content_lp');
- $form->addElement('html', '<div style="margin:3px 12px">');
- $form->addElement('html_editor', 'content_lp', '', null, $editor_config);
- $form->addElement('html', '</div>');
- $defaults['content_lp'] = $content;
- }
- }
- elseif (is_numeric($extra_info)) {
- $form->addElement('style_submit_button', 'submit_button', get_lang('SaveDocument'), 'class="save"');
- $return = $this->display_document($extra_info, true, true, true);
- $form->addElement('html', $return);
- }
- }
- }
- if ($action == 'move') {
- $form->addElement('hidden', 'title', $item_title);
- $form->addElement('hidden', 'description', $item_description);
- }
- if (is_numeric($extra_info)) {
- $form->addElement('style_submit_button', 'submit_button', get_lang('SaveDocument'), 'value="submit_button", class="save"');
- $form->addElement('hidden', 'path', $extra_info);
- }
- elseif (is_array($extra_info)) {
- $form->addElement('style_submit_button', 'submit_button', get_lang('SaveDocument'), 'class="save"');
- $form->addElement('hidden', 'path', $extra_info['path']);
- }
- $form->addElement('hidden', 'type', TOOL_DOCUMENT);
- $form->addElement('hidden', 'post_time', time());
- $form->setDefaults($defaults);
- return $form->return_form();
- }
-
- public function display_link_form($action = 'add', $id = 0, $extra_info = '') {
- global $charset;
- $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
- $tbl_link = Database :: get_course_table(TABLE_LINK);
- if ($id != 0 && is_array($extra_info)) {
- $item_title = stripslashes($extra_info['title']);
- $item_description = stripslashes($extra_info['description']);
- $item_url = stripslashes($extra_info['url']);
- }
- elseif (is_numeric($extra_info)) {
- $sql_link = "
- SELECT
- title,
- description,
- url
- FROM " . $tbl_link . "
- WHERE id = " . $extra_info;
- $result = Database::query($sql_link);
- $row = Database :: fetch_array($result);
- $item_title = $row['title'];
- $item_description = $row['description'];
- $item_url = $row['url'];
- } else {
- $item_title = '';
- $item_description = '';
- $item_url = '';
- }
- $return = ' <div class="row">
- <div class="form_header">';
- if ($id != 0 && is_array($extra_info))
- $parent = $extra_info['parent_item_id'];
- else
- $parent = 0;
- $sql = "
- SELECT *
- FROM " . $tbl_lp_item . "
- WHERE
- lp_id = " . $this->lp_id;
- $result = Database::query($sql);
- $arrLP = array ();
- while ($row = Database :: fetch_array($result)) {
- $arrLP[] = array (
- 'id' => $row['id'],
- 'item_type' => $row['item_type'],
- 'title' => $row['title'],
- 'path' => $row['path'],
- 'description' => $row['description'],
- 'parent_item_id' => $row['parent_item_id'],
- 'previous_item_id' => $row['previous_item_id'],
- 'next_item_id' => $row['next_item_id'],
- 'display_order' => $row['display_order'],
- 'max_score' => $row['max_score'],
- 'min_score' => $row['min_score'],
- 'mastery_score' => $row['mastery_score'],
- 'prerequisite' => $row['prerequisite']
- );
- }
- $this->tree_array($arrLP);
- $arrLP = $this->arrMenu;
- unset ($this->arrMenu);
- if ($action == 'add')
- $return .= get_lang('CreateTheLink') . ' :' . "\n";
- elseif ($action == 'move') $return .= get_lang('MoveCurrentLink') . ' :' . "\n";
- else
- $return .= get_lang('EditCurrentLink') . ' :' . "\n";
- $return .= ' </div>
- </div>';
- $return .= '<div class="sectioncomment">';
- $return .= '<form method="POST">' . "\n";
- $return .= "\t" . '<table>' . "\n";
- if ($action != 'move') {
- $return .= "\t\t" . '<tr>' . "\n";
- $return .= "\t\t\t" . '<td class="label"><label for="idTitle">' . get_lang('Title') . '</label></td>' . "\n";
- $return .= "\t\t\t" . '<td class="input"><input id="idTitle" name="title" size="44" type="text" value="' . $item_title . '" class="learnpath_item_form"/></td>' . "\n";
- $return .= "\t\t" . '</tr>' . "\n";
- }
- $return .= "\t\t" . '<tr>' . "\n";
- $return .= "\t\t\t" . '<td class="label"><label for="idParent">' . get_lang('Parent') . '</label></td>' . "\n";
- $return .= "\t\t\t" . '<td class="input">' . "\n";
- $return .= "\t\t\t\t" . '<select id="idParent" style="width:100%;" name="parent" onChange="javascript: load_cbo(this.value);" class="learnpath_item_form" size="1">';
- $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
- $arrHide = array (
- $id
- );
- $parent_item_id = $_SESSION['parent_item_id'];
- for ($i = 0; $i < count($arrLP); $i++) {
- if ($action != 'add') {
- if (($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir') && !in_array($arrLP[$i]['id'], $arrHide) && !in_array($arrLP[$i]['parent_item_id'], $arrHide)) {
- $return .= "\t\t\t\t\t" . '<option ' . (($parent == $arrLP[$i]['id']) ? 'selected="selected" ' : '') . 'style="padding-left:' . ($arrLP[$i]['depth'] * 10) . 'px;" value="' . $arrLP[$i]['id'] . '">' . $arrLP[$i]['title'] . '</option>';
- } else {
- $arrHide[] = $arrLP[$i]['id'];
- }
- } else {
- if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
- $return .= "\t\t\t\t\t" . '<option ' . (($parent_item_id == $arrLP[$i]['id']) ? 'selected="selected" ' : '') . 'style="padding-left:' . ($arrLP[$i]['depth'] * 10) . 'px;" value="' . $arrLP[$i]['id'] . '">' . $arrLP[$i]['title'] . '</option>';
- }
- }
- if (is_array($arrLP)) {
- reset($arrLP);
- }
- $return .= "\t\t\t\t" . '</select>';
- $return .= "\t\t\t" . '</td>' . "\n";
- $return .= "\t\t" . '</tr>' . "\n";
- $return .= "\t\t" . '<tr>' . "\n";
- $return .= "\t\t\t" . '<td class="label"><label for="idPosition">' . get_lang('Position') . '</label></td>' . "\n";
- $return .= "\t\t\t" . '<td class="input">' . "\n";
- $return .= "\t\t\t\t" . '<select id="idPosition" name="previous" style="width:100%;" size="1" class="learnpath_item_form">';
- $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . get_lang('FirstPosition') . '</option>';
- for ($i = 0; $i < count($arrLP); $i++) {
- if ($arrLP[$i]['parent_item_id'] == $parent_item_id && $arrLP[$i]['id'] != $id) {
- if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
- $selected = 'selected="selected" ';
- elseif ($action == 'add') $selected = 'selected="selected" ';
- else
- $selected = '';
- $return .= "\t\t\t\t\t" . '<option ' . $selected . 'value="' . $arrLP[$i]['id'] . '">' . get_lang('After') . ' "' . $arrLP[$i]['title'] . '"</option>';
- }
- }
- $return .= "\t\t\t\t" . '</select>';
- $return .= "\t\t\t" . '</td>' . "\n";
- $return .= "\t\t" . '</tr>' . "\n";
- if ($action != 'move') {
- $return .= "\t\t" . '<tr>' . "\n";
- $return .= "\t\t\t" . '<td class="label"><label for="idURL">' . get_lang('Url') . '</label></td>' . "\n";
- $return .= "\t\t\t" . '<td class="input"><input' . (is_numeric($extra_info) ? ' disabled="disabled"' : '') . ' id="idURL" name="url" style="width:99%;" type="text" value="' . $item_url . '" class="learnpath_item_form" /></td>' . "\n";
- $return .= "\t\t" . '</tr>' . "\n";
- $id_prerequisite = 0;
- if (is_array($arrLP)) {
- foreach ($arrLP as $key => $value) {
- if ($value['id'] == $id) {
- $id_prerequisite = $value['prerequisite'];
- break;
- }
- }
- }
- $arrHide = array ();
- for ($i = 0; $i < count($arrLP); $i++) {
- if ($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter') {
- if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
- $s_selected_position = $arrLP[$i]['id'];
- elseif ($action == 'add') $s_selected_position = 0;
- $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
- }
- }
-
- $return .= "\t\t" . '</tr>' . "\n";
- }
- $return .= "\t\t" . '<tr>' . "\n";
- if ($action == 'add') {
- $return .= '<td> </td><td><button class="save" name="submit_button" type="submit">' . get_lang('AddLinkToCourse') . '</button></td>';
- } else {
- $return .= '<td> </td><td><button class="save" name="submit_button" type="submit">' . get_lang('EditCurrentLink') . '</button></td>';
- }
- $return .= "\t\t" . '</tr>' . "\n";
- $return .= "\t" . '</table>' . "\n";
- if ($action == 'move') {
- $return .= "\t" . '<input name="title" type="hidden" value="' . $item_title . '" />' . "\n";
- $return .= "\t" . '<input name="description" type="hidden" value="' . $item_description . '" />' . "\n";
- }
- if (is_numeric($extra_info)) {
- $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info . '" />' . "\n";
- }
- elseif (is_array($extra_info)) {
- $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />' . "\n";
- }
- $return .= "\t" . '<input name="type" type="hidden" value="' . TOOL_LINK . '" />' . "\n";
- $return .= "\t" . '<input name="post_time" type="hidden" value="' . time() . '" />' . "\n";
- $return .= '</form>' . "\n";
- $return .= '</div>' . "\n";
- return $return;
- }
-
- public function display_student_publication_form($action = 'add', $id = 0, $extra_info = '') {
- global $charset;
- $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
- $tbl_publication = Database :: get_course_table(TABLE_STUDENT_PUBLICATION);
- if ($id != 0 && is_array($extra_info)) {
- $item_title = stripslashes($extra_info['title']);
- $item_description = stripslashes($extra_info['description']);
- }
- elseif (is_numeric($extra_info)) {
- $sql_publication = "
- SELECT
- title,
- description
- FROM " . $tbl_publication . "
- WHERE id = " . $extra_info;
- $result = Database::query($sql_publication);
- $row = Database :: fetch_array($result);
- $item_title = $row['title'];
- } else {
- $item_title = get_lang('Student_publication');
- }
- $return = ' <div class="row">
- <div class="form_header">';
- if ($id != 0 && is_array($extra_info))
- $parent = $extra_info['parent_item_id'];
- else
- $parent = 0;
- $sql = "
- SELECT *
- FROM " . $tbl_lp_item . "
- WHERE
- lp_id = " . $this->lp_id;
- $result = Database::query($sql);
- $arrLP = array ();
- while ($row = Database :: fetch_array($result)) {
- $arrLP[] = array (
- 'id' => $row['id'],
- 'item_type' => $row['item_type'],
- 'title' => $row['title'],
- 'path' => $row['path'],
- 'description' => $row['description'],
- 'parent_item_id' => $row['parent_item_id'],
- 'previous_item_id' => $row['previous_item_id'],
- 'next_item_id' => $row['next_item_id'],
- 'display_order' => $row['display_order'],
- 'max_score' => $row['max_score'],
- 'min_score' => $row['min_score'],
- 'mastery_score' => $row['mastery_score'],
- 'prerequisite' => $row['prerequisite']
- );
- }
- $this->tree_array($arrLP);
- $arrLP = $this->arrMenu;
- unset ($this->arrMenu);
- if ($action == 'add')
- $return .= get_lang('Student_publication') . ' :' . "\n";
- elseif ($action == 'move') $return .= get_lang('MoveCurrentStudentPublication') . ' :' . "\n";
- else
- $return .= get_lang('EditCurrentStudentPublication') . ' :' . "\n";
- $return .= ' </div>
- </div>';
- $return .= '<div class="sectioncomment">';
- $return .= '<form method="POST">' . "\n";
- $return .= "\t" . '<table class="lp_form">' . "\n";
- if ($action != 'move') {
- $return .= "\t\t" . '<tr>' . "\n";
- $return .= "\t\t\t" . '<td class="label"><label for="idTitle">' . get_lang('Title') . '</label></td>' . "\n";
- $return .= "\t\t\t" . '<td class="input"><input id="idTitle" name="title" size="44" type="text" value="' . $item_title . '" class="learnpath_item_form" /></td>' . "\n";
- $return .= "\t\t" . '</tr>' . "\n";
- }
- $return .= "\t\t" . '<tr>' . "\n";
- $return .= "\t\t\t" . '<td class="label"><label for="idParent">' . get_lang('Parent') . '</label></td>' . "\n";
- $return .= "\t\t\t" . '<td class="input">' . "\n";
- $return .= "\t\t\t\t" . '<select id="idParent" name="parent" style="width:100%;" onChange="javascript: load_cbo(this.value);" class="learnpath_item_form" size="1">';
-
- $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
- $arrHide = array (
- $id
- );
- for ($i = 0; $i < count($arrLP); $i++) {
- if ($action != 'add') {
- if (($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir') && !in_array($arrLP[$i]['id'], $arrHide) && !in_array($arrLP[$i]['parent_item_id'], $arrHide)) {
- $return .= "\t\t\t\t\t" . '<option ' . (($parent == $arrLP[$i]['id']) ? 'selected="selected" ' : '') . 'style="padding-left:' . ($arrLP[$i]['depth'] * 10) . 'px;" value="' . $arrLP[$i]['id'] . '">' . $arrLP[$i]['title'] . '</option>';
- } else {
- $arrHide[] = $arrLP[$i]['id'];
- }
- } else {
- if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
- $return .= "\t\t\t\t\t" . '<option ' . (($parent == $arrLP[$i]['id']) ? 'selected="selected" ' : '') . 'style="padding-left:' . ($arrLP[$i]['depth'] * 10) . 'px;" value="' . $arrLP[$i]['id'] . '">' . $arrLP[$i]['title'] . '</option>';
- }
- }
- if (is_array($arrLP)) {
- reset($arrLP);
- }
- $return .= "\t\t\t\t" . '</select>';
- $return .= "\t\t\t" . '</td>' . "\n";
- $return .= "\t\t" . '</tr>' . "\n";
- $return .= "\t\t" . '<tr>' . "\n";
- $return .= "\t\t\t" . '<td class="label"><label for="idPosition">' . get_lang('Position') . '</label></td>' . "\n";
- $return .= "\t\t\t" . '<td class="input">' . "\n";
- $return .= "\t\t\t\t" . '<select id="idPosition" name="previous" style="width:100%;" size="1" class="learnpath_item_form">';
- $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . get_lang('FirstPosition') . '</option>';
- for ($i = 0; $i < count($arrLP); $i++) {
- if ($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) {
- if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
- $selected = 'selected="selected" ';
- elseif ($action == 'add') $selected = 'selected="selected" ';
- else
- $selected = '';
- $return .= "\t\t\t\t\t" . '<option ' . $selected . 'value="' . $arrLP[$i]['id'] . '">' . get_lang('After') . ' "' . $arrLP[$i]['title'] . '"</option>';
- }
- }
- $return .= "\t\t\t\t" . '</select>';
- $return .= "\t\t\t" . '</td>' . "\n";
- $return .= "\t\t" . '</tr>' . "\n";
- if ($action != 'move') {
- $id_prerequisite = 0;
- if (is_array($arrLP)) {
- foreach ($arrLP as $key => $value) {
- if ($value['id'] == $id) {
- $id_prerequisite = $value['prerequisite'];
- break;
- }
- }
- }
- $arrHide = array ();
- for ($i = 0; $i < count($arrLP); $i++) {
- if ($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter') {
- if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
- $s_selected_position = $arrLP[$i]['id'];
- elseif ($action == 'add') $s_selected_position = 0;
- $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
- }
- }
-
-
- $return .= "\t\t" . '</tr>' . "\n";
- }
- $return .= "\t\t" . '<tr>' . "\n";
- if ($action == 'add') {
- $return .= '<td> </td><td><button class="save" name="submit_button" type="submit">' . get_lang('AddAssignmentToCourse') . '</button></td>';
- } else {
- $return .= '<td> </td><td><button class="save" name="submit_button" type="submit">' . get_lang('EditCurrentStudentPublication') . '</button></td>';
- }
- $return .= "\t\t" . '</tr>' . "\n";
- $return .= "\t" . '</table>' . "\n";
- if ($action == 'move') {
- $return .= "\t" . '<input name="title" type="hidden" value="' . $item_title . '" />' . "\n";
- $return .= "\t" . '<input name="description" type="hidden" value="' . $item_description . '" />' . "\n";
- }
- if (is_numeric($extra_info)) {
- $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info . '" />' . "\n";
- } elseif (is_array($extra_info)) {
- $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />' . "\n";
- }
- $return .= "\t" . '<input name="type" type="hidden" value="' . TOOL_STUDENTPUBLICATION . '" />' . "\n";
- $return .= "\t" . '<input name="post_time" type="hidden" value="' . time() . '" />' . "\n";
- $return .= '</form>' . "\n";
- $return .= '</div>' . "\n";
- return $return;
- }
-
- public function display_manipulate($item_id, $item_type = TOOL_DOCUMENT) {
- global $charset, $_course;
- $return = '<div class="actions">';
- switch ($item_type) {
- case 'dokeos_chapter' :
- case 'chapter' :
-
-
- break;
- case 'dokeos_module' :
- case 'module' :
-
-
- break;
- case TOOL_DOCUMENT :
-
-
- break;
- case TOOL_LINK :
- case 'link' :
-
-
- break;
- case TOOL_QUIZ :
-
-
- break;
- case TOOL_STUDENTPUBLICATION :
-
-
- break;
- }
- $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
- $sql = "
- SELECT
- *
- FROM " . $tbl_lp_item . " as lp
- WHERE
- lp.id = " . $item_id;
- $result = Database::query($sql);
- $row = Database::fetch_assoc($result);
- $s_title = $row['title'];
-
- if (!empty ($row['audio'])) {
- $return .= '<div class="lp_mediaplayer" id="container"><a href="http://www.macromedia.com/go/getflashplayer">Get the Flash Player</a> to see this player.</div>';
- $return .= '<script type="text/javascript" src="../inc/lib/mediaplayer/swfobject.js"></script>';
- $return .= '<script type="text/javascript">
- var s1 = new SWFObject("../inc/lib/mediaplayer/player.swf","ply","250","20","9","#FFFFFF");
- s1.addParam("allowscriptaccess","always");
- s1.addParam("flashvars","file=../../courses/' . $_course['path'] . '/document/audio/' . $row['audio'] . '&autostart=true");
- s1.write("container");
- </script>';
- }
-
-
- $return .= '<a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&action=edit_item&view=build&id=' . $item_id . '&lp_id=' . $this->lp_id . '&path_item=' . $row['path'] . '" title="' . get_lang('Edit') . '"><img align="absbottom" alt="Edit the current item" src="../img/edit.gif" title="' . get_lang('Edit') . '" /> ' . get_lang('Edit') . '</a>';
- $return .= '<a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&action=move_item&view=build&id=' . $item_id . '&lp_id=' . $this->lp_id . '" title="Move the current item"><img align="absbottom" alt="Move the current item" src="../img/deplacer_fichier.gif" title="' . get_lang('Move') . '" /> ' . get_lang('Move') . '</a>';
-
- if ($item_type != 'dokeos_chapter' && $item_type != 'chapter') {
- $return .= '<a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&action=edit_item_prereq&view=build&id=' . $item_id . '&lp_id=' . $this->lp_id . '" title="' . get_lang('Prerequisites') . '"><img align="absbottom" alt="' . get_lang('Prerequisites') . '" src="../img/right.gif" title="' . get_lang('Prerequisites') . '" /> ' . get_lang('Prerequisites') . '</a>';
- }
- $return .= '<a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&action=delete_item&view=build&id=' . $item_id . '&lp_id=' . $this->lp_id . '" onClick="return confirmation(\'' . addslashes($s_title) . '\');" title="Delete the current item"><img alt="Delete the current item" align="absbottom" src="../img/delete.gif" title="' . get_lang('Delete') . '" /> ' . get_lang('Delete') . '</a>';
-
-
-
- ob_start();
- $audio_recorder_studentview = 'false';
- $audio_recorder_item_id = $item_id;
- if (api_get_setting('service_visio', 'active') == 'true') {
- include 'audiorecorder.inc.php';
- }
- $return .= ob_get_contents();
- ob_end_clean();
-
- $return .= '</div>';
- return $return;
- }
-
- public function get_js_dropdown_array() {
- $return = 'var child_name = new Array();' . "\n";
- $return .= 'var child_value = new Array();' . "\n\n";
- $return .= 'child_name[0] = new Array();' . "\n";
- $return .= 'child_value[0] = new Array();' . "\n\n";
- $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
- $sql_zero = "
- SELECT *
- FROM " . $tbl_lp_item . "
- WHERE
- lp_id = " . $this->lp_id . " AND
- parent_item_id = 0
- ORDER BY display_order ASC";
- $res_zero = Database::query($sql_zero);
- global $charset;
- $i = 0;
- while ($row_zero = Database :: fetch_array($res_zero)) {
- $return .= 'child_name[0][' . $i . '] = "' . get_lang('After') . ' \"' . $row_zero['title'] . '\"";' . "\n";
- $return .= 'child_value[0][' . $i++ . '] = "' . $row_zero['id'] . '";' . "\n";
- }
- $return .= "\n";
- $sql = "
- SELECT *
- FROM " . $tbl_lp_item . "
- WHERE
- lp_id = " . $this->lp_id;
- $res = Database::query($sql);
- while ($row = Database :: fetch_array($res)) {
- $sql_parent = "
- SELECT *
- FROM " . $tbl_lp_item . "
- WHERE parent_item_id = " . $row['id'] . "
- ORDER BY display_order ASC";
- $res_parent = Database::query($sql_parent);
- $i = 0;
- $return .= 'child_name[' . $row['id'] . '] = new Array();' . "\n";
- $return .= 'child_value[' . $row['id'] . '] = new Array();' . "\n\n";
- while ($row_parent = Database :: fetch_array($res_parent)) {
- $return .= 'child_name[' . $row['id'] . '][' . $i . '] = "' . get_lang('After') . ' \"' . api_html_entity_decode($row_parent['title'], ENT_QUOTES) . '\"";' . "\n";
- $return .= 'child_value[' . $row['id'] . '][' . $i++ . '] = "' . $row_parent['id'] . '";' . "\n";
- }
- $return .= "\n";
- }
- return $return;
- }
-
- public function display_move_item($item_id) {
- global $_course;
- global $charset;
- $return = '';
- if (is_numeric($item_id)) {
- $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
- $sql = "SELECT *
- FROM " . $tbl_lp_item . "
- WHERE id = " . $item_id;
- $res = Database::query($sql);
- $row = Database :: fetch_array($res);
- switch ($row['item_type']) {
- case 'dokeos_chapter' :
- case 'dir' :
- case 'asset' :
- $return .= $this->display_manipulate($item_id, $row['item_type']);
- $return .= $this->display_item_form($row['item_type'], get_lang('MoveCurrentChapter'), 'move', $item_id, $row);
- break;
- case 'dokeos_module' :
- $return .= $this->display_manipulate($item_id, $row['item_type']);
- $return .= $this->display_item_form($row['item_type'], 'Move th current module:', 'move', $item_id, $row);
- break;
- case TOOL_DOCUMENT :
- $return .= $this->display_manipulate($item_id, $row['item_type']);
- $return .= $this->display_document_form('move', $item_id, $row);
- break;
- case TOOL_LINK :
- $return .= $this->display_manipulate($item_id, $row['item_type']);
- $return .= $this->display_link_form('move', $item_id, $row);
- break;
- case TOOL_HOTPOTATOES :
- $return .= $this->display_manipulate($item_id, $row['item_type']);
- $return .= $this->display_link_form('move', $item_id, $row);
- break;
- case TOOL_QUIZ :
- $return .= $this->display_manipulate($item_id, $row['item_type']);
- $return .= $this->display_quiz_form('move', $item_id, $row);
- break;
- case TOOL_STUDENTPUBLICATION :
- $return .= $this->display_manipulate($item_id, $row['item_type']);
- $return .= $this->display_student_publication_form('move', $item_id, $row);
- break;
- case TOOL_FORUM :
- $return .= $this->display_manipulate($item_id, $row['item_type']);
- $return .= $this->display_forum_form('move', $item_id, $row);
- break;
- case TOOL_THREAD :
- $return .= $this->display_manipulate($item_id, $row['item_type']);
- $return .= $this->display_forum_form('move', $item_id, $row);
- break;
- }
- }
- return $return;
- }
-
- public function display_item_small_form($item_type, $title = '', $data) {
- global $charset;
- $return .= '<div class="lp_small_form">' . "\n";
- $return .= '<p class="lp_title">' . $title . '</p>';
- $return .= '<form method="post">' . "\n";
- $return .= '<table cellpadding="0" cellspacing="0" class="lp_form">';
- $return .= "\t\t" . '<tr>' . "\n";
- $return .= "\t\t\t" . '<td class="label"><label for="idTitle">Title :</label></td>' . "\n";
- $return .= "\t\t\t" . '<td class="input"><input class="small_form" id="idTitle" name="title" type="text" value="' . api_html_entity_decode($data['title'], ENT_QUOTES) . '" /></td>' . "\n";
- $return .= "\t\t" . '</tr>' . "\n";
-
-
-
-
-
- $return .= "\t\t" . '<tr>' . "\n";
- $return .= "\t\t\t" . '<td colspan="2"><button class="save" name="submit_button" type="submit">' . get_lang('Save') . '</button></td>' . "\n";
- $return .= "\t\t" . '</tr>' . "\n";
- $return .= "\t\t" . '</table>' . "\n";
- $return .= "\t" . '<input name="parent" type="hidden" value="' . $data['parent_item_id'] . '"/>' . "\n";
- $return .= "\t" . '<input name="previous" type="hidden" value="' . $data['previous_item_id'] . '"/>' . "\n";
- $return .= '</form>';
- $return .= '</div>';
- return $return;
- }
-
- public function display_item_prerequisites_form($item_id) {
- global $charset;
- $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
-
- $sql = "
- SELECT *
- FROM " . $tbl_lp_item . "
- WHERE id = " . $item_id;
- $result = Database::query($sql);
- $row = Database :: fetch_array($result);
- $preq_id = $row['prerequisite'];
-
-
- $return = $this->display_manipulate($item_id, TOOL_DOCUMENT);
- $return = ' <div class="row">
- <div class="form_header">';
- $return .= get_lang('AddEditPrerequisites');
- $return .= '</div> </div>';
- $return .= '<div class="sectioncomment">';
- $return .= '<form method="POST">';
- $return .= '<table class="lp_prerequisites" style="border-collapse:collapse;">';
- $return .= '<tr style="border-collapse:collapse;">';
- $return .= '<th height="24" style="border:1px solid gray; background-color:#F0F0F0;">' . get_lang('Prerequisites') . '</th>';
- $return .= '<th width="70" height="24" style="border:1px solid gray; background-color:#F0F0F0;">' . get_lang('Minimum') . '</th>';
- $return .= '<th width="70" height="24" style="border:1px solid gray; background-color:#F0F0F0;">' . get_lang('Maximum') . '</th>';
- $return .= '</tr>';
-
- $return .= '<tr >';
- $return .= '<td colspan="3" class="radio" style="border:1px solid gray;border-collapse:collapse;">';
- $return .= '<input checked="checked" id="idNone" name="prerequisites" style="margin-left:0; margin-right:10px;" type="radio" />';
- $return .= '<label for="idNone">' . get_lang('None') . '</label>';
- $return .= '</td><td />';
- $return .= '</tr>';
- $sql = "SELECT * FROM " . $tbl_lp_item . " WHERE lp_id = " . $this->lp_id;
- $result = Database::query($sql);
- $arrLP = array ();
- while ($row = Database :: fetch_array($result)) {
- $arrLP[] = array (
- 'id' => $row['id'],
- 'item_type' => $row['item_type'],
- 'title' => $row['title'],
- 'ref' => $row['ref'],
- 'description' => $row['description'],
- 'parent_item_id' => $row['parent_item_id'],
- 'previous_item_id' => $row['previous_item_id'],
- 'next_item_id' => $row['next_item_id'],
- 'max_score' => $row['max_score'],
- 'min_score' => $row['min_score'],
- 'mastery_score' => $row['mastery_score'],
- 'prerequisite' => $row['prerequisite'],
- 'next_item_id' => $row['next_item_id'],
- 'display_order' => $row['display_order']
- );
- if ($row['ref'] == $preq_id) {
- $preq_mastery = $row['mastery_score'];
- $preq_max = $row['max_score'];
- }
- }
- $this->tree_array($arrLP);
- $arrLP = $this->arrMenu;
- unset ($this->arrMenu);
- for ($i = 0; $i < count($arrLP); $i++) {
- if ($arrLP[$i]['id'] == $item_id)
- break;
- $return .= '<tr >';
- $return .= '<td style="border:1px solid #B0B0B0; border-collapse:collapse; height:25px; padding: 3px 5px 3px 3px;" class="radio"' . (($arrLP[$i]['item_type'] != TOOL_QUIZ && $arrLP[$i]['item_type'] != TOOL_HOTPOTATOES) ? ' colspan="3"' : '') . '>';
- $return .= '<input' . (($arrLP[$i]['id'] == $preq_id) ? ' checked="checked" ' : '') . (($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter') ? ' disabled="disabled" ' : ' ') . 'id="id' . $arrLP[$i]['id'] . '" name="prerequisites" style="margin-left:' . $arrLP[$i]['depth'] * 10 . 'px; margin-right:10px;" type="radio" value="' . $arrLP[$i]['id'] . '" />';
- $icon_name = str_replace(' ', '', $arrLP[$i]['item_type']);
- if (file_exists('../img/lp_' . $icon_name . '.png')) {
- $return .= '<img alt="" src="../img/lp_' . $icon_name . '.png" style="margin-right:5px;" title="" />';
- } else
- if (file_exists('../img/lp_' . $icon_name . '.gif')) {
- $return .= '<img alt="" src="../img/lp_' . $icon_name . '.gif" style="margin-right:5px;" title="" />';
- } else {
- $return .= Display::return_icon('folder_document.gif','',array('style'=>'margin-right:5px;'));
- }
- $return .= '<label for="id' . $arrLP[$i]['id'] . '">' . $arrLP[$i]['title'] . '</label>';
- $return .= '</td>';
-
- if ($arrLP[$i]['item_type'] == TOOL_QUIZ) {
- $return .= '<td class="exercise" style="border:1px solid #B0B0B0;">';
- $return .= '<center><input size="4" maxlength="3" name="min_' . $arrLP[$i]['id'] . '" type="text" value="' . (($arrLP[$i]['id'] == $preq_id) ? $preq_mastery : 0) . '" /></center>';
- $return .= '</td>';
- $return .= '<td class="exercise" style="border:1px solid #B0B0B0;">';
- $return .= '<center><input size="4" maxlength="3" name="max_' . $arrLP[$i]['id'] . '" type="text" value="' . $arrLP[$i]['max_score'] . '" disabled="true" /></center>';
- $return .= '</td>';
- }
- if ($arrLP[$i]['item_type'] == TOOL_HOTPOTATOES) {
- $return .= '<td class="exercise" style="border:1px solid #B0B0B0;">';
- $return .= '<center><input size="4" maxlength="3" name="min_' . $arrLP[$i]['id'] . '" type="text" value="' . (($arrLP[$i]['id'] == $preq_id) ? $preq_mastery : 0) . '" /></center>';
- $return .= '</td>';
- $return .= '<td class="exercise" style="border:1px solid #B0B0B0;">';
- $return .= '<center><input size="4" maxlength="3" name="max_' . $arrLP[$i]['id'] . '" type="text" value="' . $arrLP[$i]['max_score'] . '" disabled="true" /></center>';
- $return .= '</td>';
- }
- $return .= '</tr>';
- }
- $return .= '<tr>';
- $return .= '<td colspan="3">';
- $return .= '</td>';
- $return .= '</tr>';
- $return .= '</table>';
- $return .= '<div style="padding-top:3px;">';
- $return .= '<button class="save" name="submit_button" type="submit">' . get_lang('ModifyPrerequisites') . ' </button></td>' . "\n";
- $return .= '</div>';
- $return .= '</form>';
- $return .= '</div>';
- return $return;
- }
-
- public function display_lp_prerequisites_list() {
- global $charset;
- $lp_id = $this->lp_id;
- $tbl_lp = Database :: get_course_table(TABLE_LP_MAIN);
-
- $sql = "SELECT * FROM $tbl_lp WHERE id = $lp_id ";
- $result = Database::query($sql);
- $row = Database :: fetch_array($result);
- $preq_id = $row['prerequisite'];
- $session_id = api_get_session_id();
- $session_condition = api_get_session_condition($session_id, false);
- $sql = "SELECT * FROM $tbl_lp $session_condition ORDER BY display_order ";
- $rs = Database::query($sql);
- $return = '';
- $return .= '<select name="prerequisites" >';
- $return .= '<option value="0">'.get_lang('None').'</option>';
- if (Database::num_rows($rs) > 0) {
- while ($row = Database::fetch_array($rs)) {
- if ($row['id'] == $lp_id) {
- continue;
- }
- $return .= '<option value="'.$row['id'].'" '.(($row['id']==$preq_id)?' selected ' : '').'>'.$row['name'].'</option>';
- }
- }
- $return .= '</select>';
- return $return;
- }
-
- public function get_documents() {
- global $_course;
- $tbl_doc = Database :: get_course_table(TABLE_DOCUMENT);
- $tbl_item_prop = Database::get_course_table(TABLE_ITEM_PROPERTY);
- $tbl_course = Database::get_main_table(TABLE_MAIN_COURSE);
- $path = '/';
- $path = Database::escape_string(str_replace('_', '\_', $path));
- $added_slash = ($path == '/') ? '' : '/';
-
- $current_session_id = api_get_session_id();
- $condition_session = " AND (id_session = '$current_session_id' OR (id_session = '0' AND insert_date <= (SELECT creation_date FROM $tbl_course WHERE code = '{$_course[id]}')))";
- $sql_doc = "SELECT docs.*
- FROM $tbl_item_prop AS last, $tbl_doc AS docs
- WHERE docs.id = last.ref
- AND docs.path LIKE '".$path.$added_slash."%'
- AND docs.path NOT LIKE '%_DELETED_%'
- AND last.tool = '".TOOL_DOCUMENT."' $condition_session ORDER BY docs.path ASC";
-
- $res_doc = Database::query($sql_doc);
- $return = '<div class="lp_resource_header"' . " onclick=\"if(document.getElementById('resDoc').style.display == 'block') {document.getElementById('resDoc').style.display = 'none';} else {document.getElementById('resDoc').style.display = 'block';}\"" . '>'.Display::return_icon('folder_document.gif',get_lang('Documents'),array('style'=>'margin-right:5px;', 'height' => '16px')).' '. get_lang('Documents') . '</div>';
- $return .= '<div class="lp_resource_elements" id="resDoc">';
- $resources = Database::store_result($res_doc);
- $resources_sorted = array();
-
- foreach ($resources as $resource) {
- $resource_paths = explode('/', $resource['path']);
- array_shift($resource_paths);
- $path_to_eval = $last_path = '';
- $is_file = false;
- foreach ($resource_paths as $key => $resource_path) {
- if (strpos($resource_path, '.') === false && $key != count($resource_paths) - 1) {
- $path_to_eval .= '["' . $resource_path . '"]["files"]';
- } else
- if (strpos($resource_path, '.') !== false)
- $is_file = true;
- $last_path = $resource_path;
- }
- if ($is_file) {
-
-
- if (empty($resource['title'])) {
- $resource['title'] = basename($resource['path']);
- }
- eval ('$resources_sorted' . $path_to_eval . '[' . $resource['id'] . '] = "' .$resource['title']."/". $last_path. '";');
- } else {
- eval ('$resources_sorted' . $path_to_eval . '["' . $last_path . '"]["id"]=' . $resource['id'] . ';');
- }
- }
- $return .= $this->write_resources_tree($resources_sorted);
- if (Database :: num_rows($res_doc) == 0) {
- $return .= '<div class="lp_resource_element">' . get_lang('NoDocuments') . '</div>';
- }
- $return .= '</div>';
- return $return;
- }
-
- public function write_resources_tree($resources_sorted, $num = 0) {
- require_once api_get_path(LIBRARY_PATH).'fileDisplay.lib.php';
- if (count($resources_sorted) > 0) {
- foreach ($resources_sorted as $key => $resource) {
- if (is_int($resource['id'])) {
-
-
- if (in_array($key, array('shared_folder','chat_files', 'HotPotatoes_files', 'css', 'certificates'))){
- continue;
- }elseif(preg_match('/_groupdocs/', $key)){
- continue;
- }elseif(preg_match('/sf_user_/', $key)){
- continue;
- }elseif(preg_match('/shared_folder_session_/', $key)){
- continue;
- }
-
- if ($key=='images'){
- $key=get_lang('Images');
- }
- elseif($key=='gallery'){
- $key=get_lang('Gallery');
- }
- elseif($key=='flash'){
- $key=get_lang('Flash');
- }
- elseif($key=='audio'){
- $key=get_lang('Audio');
- }
- elseif($key=='video'){
- $key=get_lang('Video');
- }
- $return .= '<div><div style="margin-left:' . ($num * 15) . 'px;margin-right:5px;"><img style="cursor: pointer;" src="../img/nolines_plus.gif" align="absmiddle" id="img_' . $resource['id'] . '" onClick="javascript: testResources(\'' . $resource['id'] . '\',\'img_' . $resource['id'] . '\')"><img alt="" src="../img/lp_folder.gif" title="" align="absmiddle" /> <span onClick="javascript: testResources(\'' . $resource['id'] . '\',\'img_' . $resource['id'] . '\')" style="cursor: pointer;" >' . $key . '</span></div><div style="display: none;" id="' . $resource['id'] . '">';
- $return .= $this->write_resources_tree($resource['files'], $num +1);
- $return .= '</div></div>';
- } else {
- if (!is_array($resource)) {
-
- $icon = choose_image($resource);
- $position = strrpos($icon, '.');
- $icon = substr($icon, 0, $position) . '_small.gif';
- $file_info = explode('/', $resource);
- $my_file_title = $file_info[0];
- $my_file_name = $file_info[1];
-
-
- $return .= '<div><div style="margin-left:' . (($num +1) * 15) . 'px;margin-right:5px;"><a href="' . api_get_self() . '?cidReq=' . Security::remove_XSS($_GET['cidReq']) . '&action=add_item&type=' . TOOL_DOCUMENT . '&file=' . $key . '&lp_id=' . $this->lp_id . '"><img alt="" src="../img/' . $icon . '" title="" /> ' . $my_file_title . "</a></div></div>\r\n"; }
- }
- }
- }
- return $return;
- }
-
- public function get_exercises() {
-
- $uploadPath = DIR_HOTPOTATOES;
- $tbl_doc = Database :: get_course_table(TABLE_DOCUMENT);
- $tbl_quiz = Database :: get_course_table(TABLE_QUIZ_TEST);
- $session_id = api_get_session_id();
- $condition_session = api_get_session_condition($session_id);
- $sql_quiz = "
- SELECT *
- FROM " . $tbl_quiz . "
- WHERE active<>'-1' $condition_session
- ORDER BY title ASC";
- $sql_hot = "SELECT * FROM " . $tbl_doc . " " .
- " WHERE path LIKE '" . $uploadPath . "/%/%htm%' $condition_session " .
- " ORDER BY id ASC";
- $res_quiz = Database::query($sql_quiz);
- $res_hot = Database::query($sql_hot);
- $return .= '<div class="lp_resource_header"' . " onclick=\"javascript: if(document.getElementById('resExercise').style.display == 'block') {document.getElementById('resExercise').style.display = 'none';} else {document.getElementById('resExercise').style.display = 'block';}\"" . ' ><img align="left" alt="" src="../img/lp_' . TOOL_QUIZ . '.gif" style="margin-right:5px;" title="" />' . get_lang('Quiz') . '</div>';
- $return .= '<div class="lp_resource_elements" id="resExercise">';
- while ($row_hot = Database :: fetch_array($res_hot)) {
- $return .= '<div class="lp_resource_element">';
-
- $return .= '<img alt="hp" src="../img/hotpotatoes_s.png" style="margin-right:5px;" title="" width="18px" height="18px" />';
- $return .= '<a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&action=add_item&type=' . TOOL_HOTPOTATOES . '&file=' . $row_hot['id'] . '&lp_id=' . $this->lp_id . '">' . ((!empty ($row_hot['comment'])) ? $row_hot['comment'] : Security :: remove_XSS($row_hot['title'])) . '</a>';
-
- $return .= '</div>';
- }
- while ($row_quiz = Database :: fetch_array($res_quiz)) {
- $return .= '<div class="lp_resource_element">';
- $return .= '<img alt="" src="../img/quizz_small.gif" style="margin-right:5px;" title="" />';
- $return .= '<a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&action=add_item&type=' . TOOL_QUIZ . '&file=' . $row_quiz['id'] . '&lp_id=' . $this->lp_id . '">' . Security :: remove_XSS($row_quiz['title']) . '</a>';
-
- $return .= '</div>';
- }
- if (Database :: num_rows($res_quiz) == 0) {
- $return .= '<div class="lp_resource_element">' . get_lang('NoExercisesAvailable') . '</div>';
- }
- $return .= '<div class="lp_resource_element">';
- $return .= '<img alt="" src="../img/new_test_small.gif" style="margin-right:5px;" title="" />';
- $return .= '<a href="' . api_get_path(REL_CODE_PATH) . 'exercice/exercise_admin.php">' . get_lang('NewExercise') . '</a>';
- $return .= '</div>';
- $return .= '</div>';
- return $return;
- }
-
- public function get_links() {
- $tbl_link = Database :: get_course_table(TABLE_LINK);
- $session_id = api_get_session_id();
- $condition_session = api_get_session_condition($session_id,false);
- $sql_link = "SELECT * FROM $tbl_link $condition_session ORDER BY title ASC";
- $res_link = Database::query($sql_link);
- $return .= '<div class="lp_resource_header"' . " onclick=\"javascript: if(document.getElementById('resLink').style.display == 'block') {document.getElementById('resLink').style.display = 'none';} else {document.getElementById('resLink').style.display = 'block';}\"" . '><img alt="" src="../img/lp_' . TOOL_LINK . '.gif" style="margin-right:5px;" title="" />' . get_lang('Links') . '</div>';
- $return .= '<div class="lp_resource_elements" id="resLink">';
- while ($row_link = Database :: fetch_array($res_link)) {
- $return .= '<div class="lp_resource_element">';
- $return .= '<img alt="" src="../img/lp_link.gif" style="margin-right:5px;" title="" />';
- $return .= '<a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&action=add_item&type=' . TOOL_LINK . '&file=' . $row_link['id'] . '&lp_id=' . $this->lp_id . '">' . $row_link['title'] . '</a>';
- $return .= '</div>';
- }
- $return .= '<div class="lp_resource_element">';
- $return .= '<img alt="" src="../img/linksnew.gif" style="margin-right:5px;width:16px" title="" />';
- $return .= '<a href="' . api_get_path(REL_CODE_PATH) . 'link/link.php?' . api_get_cidreq() . '&action=addlink" title="' . get_lang('LinkAdd') . '">' . get_lang('LinkAdd') . '</a>';
- $return .= '</div>';
- if (Database :: num_rows($res_link) == 0)
- $return .= '<div class="lp_resource_element">' . get_lang('NoLinksAvailable') . '</div>';
- $return .= '</div>';
- return $return;
- }
-
- public function get_student_publications() {
- $tbl_student = Database :: get_course_table(TABLE_STUDENT_PUBLICATION);
- $session_id = api_get_session_id();
- $condition_session = api_get_session_condition($session_id, false);
- $sql_student = "SELECT * FROM $tbl_student $condition_session ORDER BY title ASC";
- $res_student = Database::query($sql_student);
- $return .= '<div class="lp_resource_header"' . " onclick=\"javascript: if(document.getElementById('resStudent').style.display == 'block') {document.getElementById('resStudent').style.display = 'none';} else {document.getElementById('resStudent').style.display = 'block';}\"" . '><img alt="" src="../img/lp_' . TOOL_STUDENTPUBLICATION . '.gif" style="margin-right:5px;" title="" />' . get_lang('Student_publication') . '</div>';
- $return .= '<div class="lp_resource_elements" id="resStudent">';
- $return .= '<div class="lp_resource_element">';
- $return .= '<img align="left" alt="" src="../img/works_small.gif" style="margin-right:5px;" title="" />';
- $return .= '<a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&action=add_item&type=' . TOOL_STUDENTPUBLICATION . '&lp_id=' . $this->lp_id . '">' . get_lang('AddAssignmentPage') . '</a>';
- $return .= '</div>';
- $return .= '</div>';
- return $return;
- }
-
- public function get_forums() {
- include '../forum/forumfunction.inc.php';
- include '../forum/forumconfig.inc.php';
- global $table_forums, $table_threads, $table_posts, $table_item_property, $table_users;
- $table_forums = Database :: get_course_table(TABLE_FORUM);
- $table_threads = Database :: get_course_table(TABLE_FORUM_THREAD);
- $table_posts = Database :: get_course_table(TABLE_FORUM_POST);
- $table_item_property = Database :: get_course_table(TABLE_ITEM_PROPERTY);
- $table_users = Database :: get_main_table(TABLE_MAIN_USER);
- $a_forums = get_forums();
- $return .= '<div class="lp_resource_header"' . " onclick=\"javascript: if(document.getElementById('forums').style.display == 'block') {document.getElementById('forums').style.display = 'none';} else {document.getElementById('forums').style.display = 'block';}\"" . '><img alt="" src="../img/lp_forum.gif" style="margin-right:5px;" title="" />' . get_lang('Forums') . '</div>';
- $return .= '<div class="lp_resource_elements" style="border:1px solid #999999;" id="forums">';
- foreach ($a_forums as $forum) {
- $return .= '<div class="lp_resource_element">';
- $return .= '<script type="text/javascript">
- function toggle_forum(forum_id){
- if(document.getElementById("forum_"+forum_id+"_content").style.display == "none"){
- document.getElementById("forum_"+forum_id+"_content").style.display = "block";
- document.getElementById("forum_"+forum_id+"_opener").src = "' . api_get_path(WEB_IMG_PATH) . 'remove.gif";
- }
- else {
- document.getElementById("forum_"+forum_id+"_content").style.display = "none";
- document.getElementById("forum_"+forum_id+"_opener").src = "' . api_get_path(WEB_IMG_PATH) . 'add.gif";
- }
- }
- </script>
- ';
- if (!empty($forum['forum_id'])) {
- $return .= '<img alt="" src="../img/lp_forum.gif" style="margin-right:5px;" title="" />';
- $return .= '<a style="cursor:hand" onclick="javascript: toggle_forum(' . $forum['forum_id'] . ')" style="vertical-align:middle"><img src="' . api_get_path(WEB_IMG_PATH) . 'add.gif" id="forum_' . $forum['forum_id'] . '_opener" align="absbottom" /></a>
- <a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&action=add_item&type=' . TOOL_FORUM . '&forum_id=' . $forum['forum_id'] . '&lp_id=' . $this->lp_id . '" style="vertical-align:middle">' . Security :: remove_XSS($forum['forum_title']) . '</a><ul style="display:none" id="forum_' . $forum['forum_id'] . '_content">';
- }
- $a_threads = get_threads($forum['forum_id']);
- if (is_array($a_threads)) {
- foreach ($a_threads as $thread) {
- $return .= '<li><a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&action=add_item&type=' . TOOL_THREAD . '&thread_id=' . $thread['thread_id'] . '&lp_id=' . $this->lp_id . '">' . Security :: remove_XSS($thread['thread_title']) . '</a></li>';
- }
- }
- $return .= '</ul></div>';
- }
- $return .= '<div class="lp_resource_element">';
- $return .= '<img alt="" src="../img/forum_new_small.gif" style="margin-right:5px;" title="" />';
- $return .= '<a href="' . api_get_path(REL_CODE_PATH) . 'forum/index.php?' . api_get_cidreq() . '&action=add&content=forum" title="' . get_lang('CreateANewForum') . '">' . get_lang('CreateANewForum') . '</a>';
- $return .= '</div>';
- return $return;
- }
-
- public function scorm_export() {
- global $_course;
-
- if (function_exists('ini_set')) {
- $mem = ini_get('memory_limit');
- if (substr($mem, -1, 1) == 'M') {
- $mem_num = substr($mem, 0, -1);
- if ($mem_num < 128) {
- ini_set('memory_limit', '128M');
- }
- } else {
- ini_set('memory_limit', '128M');
- }
- ini_set('max_execution_time', 600);
-
-
- }
-
- $archive_path = api_get_path(SYS_ARCHIVE_PATH);
- $sys_course_path = api_get_path(SYS_COURSE_PATH);
- $temp_dir_short = uniqid();
- $temp_zip_dir = $archive_path.'/'.$temp_dir_short;
- $temp_zip_file = $temp_zip_dir.'/'.md5(time()).'.zip';
- $zip_folder = new PclZip($temp_zip_file);
- $current_course_path = api_get_path(SYS_COURSE_PATH).api_get_course_path();
- $root_path = $main_path = api_get_path(SYS_PATH);
- $files_cleanup = array();
-
-
-
- if (!is_dir($temp_zip_dir)) {
- mkdir($temp_zip_dir, api_get_permissions_for_new_directories());
- } else {
-
- $handle = opendir($temp_zip_dir);
- while (false !== ($file = readdir($handle))) {
- if ($file != '.' && $file != '..') {
- unlink("$temp_zip_dir/$file");
- }
- }
- closedir($handle);
- }
- $zip_files = $zip_files_abs = $zip_files_dist = array();
- if (is_dir($current_course_path.'/scorm/'.$this->path) && is_file($current_course_path.'/scorm/'.$this->path.'/imsmanifest.xml')) {
-
- $dest_path_to_lp = substr($this->path, -1) == '.' ? substr($this->path, 0, -1) : $this->path;
- $dest_path_to_scorm_folder = str_replace('//','/',$temp_zip_dir.'/scorm/'.$dest_path_to_lp);
- mkdir($dest_path_to_scorm_folder, api_get_permissions_for_new_directories(), true);
- $zip_files_dist = copyr($current_course_path.'/scorm/'.$this->path, $dest_path_to_scorm_folder, array('imsmanifest'), $zip_files);
- }
-
-
-
- $xmldoc = new DOMDocument('1.0');
- $root = $xmldoc->createElement('manifest');
- $root->setAttribute('identifier', 'SingleCourseManifest');
- $root->setAttribute('version', '1.1');
- $root->setAttribute('xmlns', 'http://www.imsproject.org/xsd/imscp_rootv1p1p2');
- $root->setAttribute('xmlns:adlcp', 'http://www.adlnet.org/xsd/adlcp_rootv1p2');
- $root->setAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance');
- $root->setAttribute('xsi:schemaLocation', 'http://www.imsproject.org/xsd/imscp_rootv1p1p2 imscp_rootv1p1p2.xsd http://www.imsglobal.org/xsd/imsmd_rootv1p2p1 imsmd_rootv1p2p1.xsd http://www.adlnet.org/xsd/adlcp_rootv1p2 adlcp_rootv1p2.xsd');
-
- $metadata = $xmldoc->createElement('metadata');
- $md_schema = $xmldoc->createElement('schema', 'ADL SCORM');
- $metadata->appendChild($md_schema);
- $md_schemaversion = $xmldoc->createElement('schemaversion', '1.2');
- $metadata->appendChild($md_schemaversion);
- $root->appendChild($metadata);
- $organizations = $xmldoc->createElement('organizations');
- $resources = $xmldoc->createElement('resources');
-
- $organizations->setAttribute('default', 'chamilo_scorm_export');
- $organization = $xmldoc->createElement('organization');
- $organization->setAttribute('identifier', 'chamilo_scorm_export');
-
-
-
-
-
-
- $org_title = $xmldoc->createElement('title', api_utf8_encode($this->get_name()));
- $organization->appendChild($org_title);
-
-
- $link_updates = array();
- foreach ($this->items as $index => $item) {
- if (!in_array($item->type, array(TOOL_QUIZ, TOOL_FORUM, TOOL_THREAD, TOOL_LINK, TOOL_STUDENTPUBLICATION))) {
-
- if ($item->type == 'sco')
- $inc_docs = $item->get_resources_from_source(null, api_get_path(SYS_COURSE_PATH).api_get_course_path().'/'.'scorm/'.$this->path.'/'.$item->get_path());
- else
- $inc_docs = $item->get_resources_from_source();
-
- $my_item_id = $item->get_id();
- $my_item = $xmldoc->createElement('item');
- $my_item->setAttribute('identifier', 'ITEM_'.$my_item_id);
- $my_item->setAttribute('identifierref', 'RESOURCE_'.$my_item_id);
- $my_item->setAttribute('isvisible', 'true');
-
- $my_title = $xmldoc->createElement('title', htmlspecialchars(api_utf8_encode($item->get_title()), ENT_QUOTES, 'UTF-8'));
- $my_item->appendChild($my_title);
-
- $my_prereqs = $xmldoc->createElement('adlcp:prerequisites', $this->get_scorm_prereq_string($my_item_id));
- $my_prereqs->setAttribute('type', 'aicc_script');
- $my_item->appendChild($my_prereqs);
-
-
-
-
-
-
-
- $my_masteryscore = $xmldoc->createElement('adlcp:masteryscore', $item->get_mastery_score());
- $my_item->appendChild($my_masteryscore);
-
- if (!empty($item->parent) && $item->parent != 0) {
- $children = $organization->childNodes;
- $possible_parent = &$this->get_scorm_xml_node($children, 'ITEM_'.$item->parent);
- if (is_object($possible_parent)) {
- $possible_parent->appendChild($my_item);
- } else {
- if ($this->debug > 0) { error_log('Parent ITEM_'.$item->parent.' of item ITEM_'.$my_item_id.' not found'); }
- }
- } else {
- if ($this->debug > 0) { error_log('No parent'); }
- $organization->appendChild($my_item);
- }
-
- $my_file_path = $item->get_file_path('scorm/'.$this->path.'/');
-
- $my_xml_file_path = $my_file_path;
- $my_sub_dir = dirname($my_file_path);
- $my_sub_dir = str_replace('\\', '/', $my_sub_dir);
-
- $my_xml_sub_dir = $my_sub_dir;
-
- $my_resource = $xmldoc->createElement('resource');
- $my_resource->setAttribute('identifier', 'RESOURCE_'.$item->get_id());
- $my_resource->setAttribute('type', 'webcontent');
- $my_resource->setAttribute('href', $my_xml_file_path);
-
- if ($item->type == 'sco') {
- $my_resource->setAttribute('adlcp:scormtype', 'sco');
- } else {
- $my_resource->setAttribute('adlcp:scormtype', 'asset');
- }
-
- $my_resource->setAttribute('xml:base', '');
-
- $my_file = $xmldoc->createElement('file');
- $my_file->setAttribute('href', $my_xml_file_path);
- $my_resource->appendChild($my_file);
-
- $i = 1;
- foreach ($inc_docs as $doc_info) {
- if (count($doc_info) < 1 || empty($doc_info[0])) { continue; }
- $my_dep = $xmldoc->createElement('resource');
- $res_id = 'RESOURCE_'.$item->get_id().'_'.$i;
- $my_dep->setAttribute('identifier', $res_id);
- $my_dep->setAttribute('type', 'webcontent');
- $my_dep->setAttribute('adlcp:scormtype', 'asset');
- $my_dep_file = $xmldoc->createElement('file');
-
-
- if ($doc_info[1] == 'remote') {
-
- $my_dep_file->setAttribute('href', $doc_info[0]);
- $my_dep->setAttribute('xml:base', '');
- } elseif ($doc_info[1] == 'local') {
- switch ($doc_info[2]) {
- case 'url':
- $abs_path = api_get_path(SYS_PATH).str_replace(api_get_path(WEB_PATH), '', $doc_info[0]);
- $current_dir = dirname($abs_path);
- $current_dir = str_replace('\\', '/', $current_dir);
- $file_path = realpath($abs_path);
- $file_path = str_replace('\\', '/', $file_path);
- $my_dep_file->setAttribute('href', $file_path);
- $my_dep->setAttribute('xml:base', '');
- if (strstr($file_path, $main_path) !== false) {
-
-
- $file_path = substr($file_path, strlen($root_path) - 1);
-
-
- $zip_files_abs[] = $file_path;
- $link_updates[$my_file_path][] = array('orig' => $doc_info[0], 'dest' => $file_path);
- $my_dep_file->setAttribute('href', $file_path);
- $my_dep->setAttribute('xml:base', '');
- }
- elseif (empty($file_path)) {
-
- $file_path = $_SERVER['DOCUMENT_ROOT'].$abs_path;
- $file_path = str_replace('//', '/', $file_path);
- if (file_exists($file_path)) {
- $file_path = substr($file_path, strlen($current_dir));
- $zip_files[] = $my_sub_dir.'/'.$file_path;
- $link_updates[$my_file_path][] = array('orig' => $doc_info[0], 'dest' => $file_path);
- $my_dep_file->setAttribute('href', $file_path);
- $my_dep->setAttribute('xml:base', '');
- }
- }
- break;
- case 'abs':
- $my_dep_file->setAttribute('href', $doc_info[0]);
- $my_dep->setAttribute('xml:base', '');
-
-
-
- $abs_img_path_without_subdir = $doc_info[0];
- $relp = api_get_path(REL_PATH);
- $pos = strpos($abs_img_path_without_subdir, $relp);
- if ($pos === 0) {
- $abs_img_path_without_subdir = '/'.substr($abs_img_path_without_subdir, strlen($relp));
- }
-
- $file_path = realpath(api_get_path(SYS_PATH).$abs_img_path_without_subdir);
- $file_path = str_replace('\\', '/', $file_path);
- $file_path = str_replace('//', '/', $file_path);
-
-
- $cur_path = substr($current_course_path, -1) == '/' ? $current_course_path : $current_course_path.'/';
-
- if (strstr($file_path, $cur_path) !== false) {
-
-
- $orig_file_path = dirname($cur_path.$my_file_path).'/';
- $orig_file_path = str_replace('\\', '/', $orig_file_path);
- $relative_path = '';
- if (strstr($file_path, $cur_path) !== false) {
- $relative_path = substr($file_path, strlen($orig_file_path));
- $file_path = substr($file_path, strlen($cur_path));
- } else {
-
-
-
-
- $my_relative_path = dirname($file_path);
- $my_relative_path = str_replace('\\', '/', $my_relative_path);
- $my_relative_file = basename($file_path);
-
- $my_orig_file_path = substr($orig_file_path, 0, -1);
- $dotdot = '';
- $subdir = '';
- while (strstr($my_relative_path, $my_orig_file_path) === false && (strlen($my_orig_file_path) > 1) && (strlen($my_relative_path) > 1)) {
- $my_relative_path2 = dirname($my_relative_path);
- $my_relative_path2 = str_replace('\\', '/', $my_relative_path2);
- $my_orig_file_path = dirname($my_orig_file_path);
- $my_orig_file_path = str_replace('\\', '/', $my_orig_file_path);
- $subdir = substr($my_relative_path, strlen($my_relative_path2) + 1).'/'.$subdir;
- $dotdot += '../';
- $my_relative_path = $my_relative_path2;
- }
- $relative_path = $dotdot.$subdir.$my_relative_file;
- }
-
-
- $zip_files[] = $file_path;
-
- $link_updates[$my_file_path][] = array('orig' => $doc_info[0], 'dest' => $relative_path);
- $my_dep_file->setAttribute('href', $file_path);
- $my_dep->setAttribute('xml:base', '');
- }
- elseif (strstr($file_path,$main_path) !== false) {
-
-
- $file_path = substr($file_path, strlen($root_path));
-
-
- $zip_files_abs[] = $file_path;
- $link_updates[$my_file_path][] = array('orig' => $doc_info[0], 'dest' => $file_path);
- $my_dep_file->setAttribute('href', 'document/'.$file_path);
- $my_dep->setAttribute('xml:base', '');
- }
- elseif (empty($file_path)) {
-
- $file_path = $_SERVER['DOCUMENT_ROOT'].$doc_info[0];
- $file_path = str_replace('//', '/', $file_path);
- if (file_exists($file_path)) {
- $file_path = substr($file_path,strlen($current_dir));
- $zip_files[] = $my_sub_dir.'/'.$file_path;
- $link_updates[$my_file_path][] = array('orig' => $doc_info[0], 'dest' => $file_path);
- $my_dep_file->setAttribute('href','document/'.$file_path);
- $my_dep->setAttribute('xml:base', '');
- }
- }
- break;
- case 'rel':
- if (substr($doc_info[0], 0, 2) == '..') {
-
- $current_dir = dirname($current_course_path.'/'.$item->get_file_path()).'/';
- $current_dir = str_replace('\\', '/', $current_dir);
- $file_path = realpath($current_dir.$doc_info[0]);
- $file_path = str_replace('\\', '/', $file_path);
-
- if (strstr($file_path, $main_path) !== false) {
-
-
- $file_path = substr($file_path, strlen($root_path));
-
- $zip_files_abs[] = $file_path;
- $link_updates[$my_file_path][] = array('orig' => $doc_info[0], 'dest' => $file_path);
- $my_dep_file->setAttribute('href', 'document/'.$file_path);
- $my_dep->setAttribute('xml:base', '');
- }
- } else {
- $zip_files[] = $my_sub_dir.'/'.$doc_info[0];
- $my_dep_file->setAttribute('href', $doc_info[0]);
- $my_dep->setAttribute('xml:base', $my_xml_sub_dir);
- }
- break;
- default:
- $my_dep_file->setAttribute('href', $doc_info[0]);
- $my_dep->setAttribute('xml:base', '');
- break;
- }
- }
- $my_dep->appendChild($my_dep_file);
- $resources->appendChild($my_dep);
- $dependency = $xmldoc->createElement('dependency');
- $dependency->setAttribute('identifierref', $res_id);
- $my_resource->appendChild($dependency);
- $i++;
- }
-
-
- $resources->appendChild($my_resource);
- $zip_files[] = $my_file_path;
-
- } else {
-
- if ($item->type == TOOL_LINK) {
- $my_item = $xmldoc->createElement('item');
- $my_item->setAttribute('identifier', 'ITEM_'.$item->get_id());
- $my_item->setAttribute('identifierref', 'RESOURCE_'.$item->get_id());
- $my_item->setAttribute('isvisible', 'true');
-
- $my_title = $xmldoc->createElement('title', htmlspecialchars(api_utf8_encode($item->get_title()), ENT_QUOTES, 'UTF-8'));
- $my_item->appendChild($my_title);
-
- $my_prereqs = $xmldoc->createElement('adlcp:prerequisites', $item->get_prereq_string());
- $my_prereqs->setAttribute('type', 'aicc_script');
- $my_item->appendChild($my_prereqs);
-
-
-
-
-
-
-
- $my_masteryscore = $xmldoc->createElement('adlcp:masteryscore', $item->get_mastery_score());
- $my_item->appendChild($my_masteryscore);
-
- if (!empty($item->parent) && $item->parent != 0) {
- $children = $organization->childNodes;
- for ($i = 0; $i < $children->length; $i++) {
- $item_temp = $children->item($i);
- if ($item_temp -> nodeName == 'item') {
- if ($item_temp->getAttribute('identifier') == 'ITEM_'.$item->parent) {
- $item_temp -> appendChild($my_item);
- }
- }
- }
- } else {
- $organization->appendChild($my_item);
- }
- $my_file_path = 'link_'.$item->get_id().'.html';
- $sql = 'SELECT url, title FROM '.Database :: get_course_table(TABLE_LINK).' WHERE id='.$item->path;
- $rs = Database::query($sql);
- if ($link = Database :: fetch_array($rs)) {
- $url = $link['url'];
- $title = stripslashes($link['title']);
- $links_to_create[$my_file_path] = array('title' => $title, 'url' => $url);
-
- $my_xml_file_path = $my_file_path;
- $my_sub_dir = dirname($my_file_path);
- $my_sub_dir = str_replace('\\', '/', $my_sub_dir);
-
- $my_xml_sub_dir = $my_sub_dir;
-
- $my_resource = $xmldoc->createElement('resource');
- $my_resource->setAttribute('identifier', 'RESOURCE_'.$item->get_id());
- $my_resource->setAttribute('type', 'webcontent');
- $my_resource->setAttribute('href', $my_xml_file_path);
-
- $my_resource->setAttribute('adlcp:scormtype', 'asset');
-
- $my_resource->setAttribute('xml:base', '');
-
- $my_file = $xmldoc->createElement('file');
- $my_file->setAttribute('href', $my_xml_file_path);
- $my_resource->appendChild($my_file);
- $resources->appendChild($my_resource);
- }
- }
- elseif ($item->type == TOOL_QUIZ) {
- require_once api_get_path(SYS_CODE_PATH).'exercice/exercise.class.php';
- $exe_id = $item->path;
- $exe = new Exercise();
- $exe->read($exe_id);
- $my_item = $xmldoc->createElement('item');
- $my_item->setAttribute('identifier', 'ITEM_'.$item->get_id());
- $my_item->setAttribute('identifierref', 'RESOURCE_'.$item->get_id());
- $my_item->setAttribute('isvisible', 'true');
-
- $my_title = $xmldoc->createElement('title', htmlspecialchars(api_utf8_encode($item->get_title()), ENT_QUOTES, 'UTF-8'));
- $my_item->appendChild($my_title);
- $my_max_score = $xmldoc->createElement('max_score', $item->get_max());
-
-
- $my_prereqs = $xmldoc->createElement('adlcp:prerequisites', $item->get_prereq_string());
- $my_prereqs->setAttribute('type','aicc_script');
- $my_item->appendChild($my_prereqs);
-
- $my_masteryscore = $xmldoc->createElement('adlcp:masteryscore', $item->get_mastery_score());
- $my_item->appendChild($my_masteryscore);
-
- if (!empty($item->parent) && $item->parent != 0) {
- $children = $organization->childNodes;
- for ($i = 0; $i < $children->length; $i++) {
- $item_temp = $children->item($i);
- if ($item_temp -> nodeName == 'item') {
- if ($item_temp->getAttribute('identifier') == 'ITEM_'.$item->parent) {
- $item_temp -> appendChild($my_item);
- }
- }
- }
- } else {
- $organization->appendChild($my_item);
- }
-
- require_once api_get_path(SYS_CODE_PATH).'exercice/export/scorm/scorm_export.php';
-
-
- $my_file_path = 'quiz_'.$item->get_id().'.html';
-
-
- $contents = export_exercise($exe_id,true);
- $tmp_file_path = $archive_path.$temp_dir_short.'/'.$my_file_path;
- $res = file_put_contents($tmp_file_path, $contents);
- if ($res === false) { error_log('Could not write into file '.$tmp_file_path.' '.__FILE__.' '.__LINE__, 0); }
- $files_cleanup[] = $tmp_file_path;
-
-
- $my_xml_file_path = $my_file_path;
- $my_sub_dir = dirname($my_file_path);
- $my_sub_dir = str_replace('\\', '/', $my_sub_dir);
-
- $my_xml_sub_dir = $my_sub_dir;
-
- $my_resource = $xmldoc->createElement('resource');
- $my_resource->setAttribute('identifier', 'RESOURCE_'.$item->get_id());
- $my_resource->setAttribute('type', 'webcontent');
- $my_resource->setAttribute('href', $my_xml_file_path);
-
- $my_resource->setAttribute('adlcp:scormtype', 'sco');
-
- $my_resource->setAttribute('xml:base', '');
-
- $my_file = $xmldoc->createElement('file');
- $my_file->setAttribute('href', $my_xml_file_path);
- $my_resource->appendChild($my_file);
-
- $inc_docs = $item->get_resources_from_source(null,$tmp_file_path);
-
- $i = 1;
- foreach ($inc_docs as $doc_info) {
- if (count($doc_info) < 1 || empty($doc_info[0])) { continue; }
- $my_dep = $xmldoc->createElement('resource');
- $res_id = 'RESOURCE_'.$item->get_id().'_'.$i;
- $my_dep->setAttribute('identifier', $res_id);
- $my_dep->setAttribute('type', 'webcontent');
- $my_dep->setAttribute('adlcp:scormtype', 'asset');
- $my_dep_file = $xmldoc->createElement('file');
-
-
- if ($doc_info[1] == 'remote') {
-
- $my_dep_file->setAttribute('href', $doc_info[0]);
- $my_dep->setAttribute('xml:base', '');
- } elseif ($doc_info[1] == 'local') {
- switch ($doc_info[2]) {
- case 'url':
-
- $abs_path = api_get_path(SYS_PATH).str_replace(api_get_path(WEB_PATH), '', $doc_info[0]);
- $current_dir = dirname($abs_path);
- $current_dir = str_replace('\\', '/', $current_dir);
- $file_path = realpath($abs_path);
- $file_path = str_replace('\\', '/', $file_path);
- $my_dep_file->setAttribute('href', 'document/'.$file_path);
- $my_dep->setAttribute('xml:base', '');
- if (strstr($file_path, $main_path) !== false) {
-
-
- $file_path = substr($file_path, strlen($root_path));
-
-
- $zip_files_abs[] = $file_path;
- $link_updates[$my_file_path][] = array('orig' => $doc_info[0], 'dest' => 'document/'.$file_path);
- $my_dep_file->setAttribute('href', 'document/'.$file_path);
- $my_dep->setAttribute('xml:base', '');
- }
- elseif (empty($file_path)) {
-
- $file_path = $_SERVER['DOCUMENT_ROOT'].$abs_path;
- $file_path = str_replace('//', '/', $file_path);
- if (file_exists($file_path)) {
- $file_path = substr($file_path, strlen($current_dir));
- $zip_files[] = $my_sub_dir.'/'.$file_path;
- $link_updates[$my_file_path][] = array('orig' => $doc_info[0], 'dest' => 'document/'.$file_path);
- $my_dep_file->setAttribute('href', 'document/'.$file_path);
- $my_dep->setAttribute('xml:base', '');
- }
- }
- break;
- case 'abs':
- $current_dir = dirname($current_course_path.'/'.$item->get_file_path()).'/';
- $current_dir = str_replace('\\', '/', $current_dir);
- $file_path = realpath($doc_info[0]);
- $file_path = str_replace('\\', '/', $file_path);
- $my_dep_file->setAttribute('href', $file_path);
- $my_dep->setAttribute('xml:base', '');
- if (strstr($file_path,$main_path) !== false) {
-
-
- $file_path = substr($file_path, strlen($root_path));
-
-
- $zip_files_abs[] = $file_path;
- $link_updates[$my_file_path][] = array('orig' => $doc_info[0], 'dest' => $file_path);
- $my_dep_file->setAttribute('href', 'document/'.$file_path);
- $my_dep->setAttribute('xml:base', '');
- }
- elseif (empty($file_path)) {
-
- $file_path = $_SERVER['DOCUMENT_ROOT'].$doc_info[0];
- $file_path = str_replace('//', '/', $file_path);
- if (file_exists($file_path)) {
- $file_path = substr($file_path,strlen($current_dir));
- $zip_files[] = $my_sub_dir.'/'.$file_path;
- $link_updates[$my_file_path][] = array('orig' => $doc_info[0], 'dest' => $file_path);
- $my_dep_file->setAttribute('href', 'document/'.$file_path);
- $my_dep->setAttribute('xml:base', '');
- }
- }
- break;
- case 'rel':
- if (substr($doc_info[0], 0, 2) == '..') {
-
- $current_dir = dirname($current_course_path.'/'.$item->get_file_path()).'/';
- $current_dir = str_replace('\\', '/', $current_dir);
- $file_path = realpath($current_dir.$doc_info[0]);
- $file_path = str_replace('\\', '/', $file_path);
-
- if (strstr($file_path, $main_path) !== false) {
-
-
- $file_path = substr($file_path, strlen($root_path));
- $file_path_dest = $file_path;
-
- $info_file_path = explode('/', $file_path);
- if ($info_file_path[0] == 'courses') {
- $file_path_dest = 'document/'.$file_path;
- }
-
- $zip_files_abs[] = $file_path;
- $link_updates[$my_file_path][] = array('orig' => $doc_info[0], 'dest' => $file_path_dest);
- $my_dep_file->setAttribute('href', 'document/'.$file_path);
- $my_dep->setAttribute('xml:base', '');
- }
- } else {
- $zip_files[] = $my_sub_dir.'/'.$doc_info[0];
- $my_dep_file->setAttribute('href', $doc_info[0]);
- $my_dep->setAttribute('xml:base', $my_xml_sub_dir);
- }
- break;
- default:
- $my_dep_file->setAttribute('href', $doc_info[0]);
- $my_dep->setAttribute('xml:base', '');
- break;
- }
- }
- $my_dep->appendChild($my_dep_file);
- $resources->appendChild($my_dep);
- $dependency = $xmldoc->createElement('dependency');
- $dependency->setAttribute('identifierref', $res_id);
- $my_resource->appendChild($dependency);
- $i++;
- }
- $resources->appendChild($my_resource);
- $zip_files[] = $my_file_path;
- } else {
-
- $my_file_path = 'non_exportable.html';
-
- $my_xml_file_path = $my_file_path;
- $my_sub_dir = dirname($my_file_path);
- $my_sub_dir = str_replace('\\', '/', $my_sub_dir);
-
- $my_xml_sub_dir = $my_sub_dir;
-
- $my_resource = $xmldoc->createElement('resource');
- $my_resource->setAttribute('identifier', 'RESOURCE_'.$item->get_id());
- $my_resource->setAttribute('type', 'webcontent');
- $my_resource->setAttribute('href', 'document/'.$my_xml_file_path);
-
- $my_resource->setAttribute('adlcp:scormtype', 'asset');
-
- $my_resource->setAttribute('xml:base', '');
-
- $my_file = $xmldoc->createElement('file');
- $my_file->setAttribute('href', 'document/'.$my_xml_file_path);
- $my_resource->appendChild($my_file);
- $resources->appendChild($my_resource);
- }
- }
- }
- $organizations->appendChild($organization);
- $root->appendChild($organizations);
- $root->appendChild($resources);
- $xmldoc->appendChild($root);
-
-
-
-
- foreach ($zip_files as $file_path) {
- if (empty($file_path)) { continue; }
-
- $dest_file = $archive_path.$temp_dir_short.'/'.$file_path;
- $this->create_path($dest_file);
-
-
- @copy($sys_course_path.$_course['path'].'/'.$file_path, $dest_file);
-
- if (in_array($file_path, array_keys($link_updates))) {
- $string = file_get_contents($dest_file);
- unlink($dest_file);
- foreach ($link_updates[$file_path] as $old_new) {
-
-
-
-
-
- if (substr($old_new['dest'], -3) == 'flv' && substr($old_new['dest'], 0, 5) == 'main/') {
- $old_new['dest'] = str_replace('main/', '../../../', $old_new['dest']);
- }
- elseif (substr($old_new['dest'], -3) == 'flv' && substr($old_new['dest'], 0, 6) == 'video/') {
- $old_new['dest'] = str_replace('video/', '../../../../video/', $old_new['dest']);
- }
- $string = str_replace($old_new['orig'], $old_new['dest'], $string);
- }
- file_put_contents($dest_file, $string);
- }
- }
- foreach ($zip_files_abs as $file_path) {
- if (empty($file_path)) { continue; }
-
- if (!is_file($main_path.$file_path) || !is_readable($main_path.$file_path)) { continue; }
-
- $dest_file = $archive_path.$temp_dir_short.'/document/'.$file_path;
- $this->create_path($dest_file);
-
-
-
- copy($main_path.$file_path, $dest_file);
-
- if (in_array($file_path, array_keys($link_updates))) {
- $string = file_get_contents($dest_file);
- unlink($dest_file);
- foreach ($link_updates[$file_path] as $old_new) {
-
-
-
-
-
- if (substr($old_new['dest'], -3) == 'flv' && substr($old_new['dest'], 0, 5) == 'main/') {
- $old_new['dest'] = str_replace('main/', '../../../', $old_new['dest']);
- }
- $string = str_replace($old_new['orig'], $old_new['dest'], $string);
- }
- file_put_contents($dest_file, $string);
- }
- }
- if (is_array($links_to_create)) {
- foreach ($links_to_create as $file => $link) {
- $file_content = '<!DOCTYPE html
- PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="'.api_get_language_isocode().'" lang="'.api_get_language_isocode().'">
- <head>
- <title>'.$link['title'].'</title>
- <meta http-equiv="Content-Type" content="text/html; charset='.api_get_system_encoding().'" />
- </head>
- <body dir="'.api_get_text_direction().'">
- <div style="text-align:center"><a href="'.$link['url'].'">'.$link['title'].'</a></div>
- </body>
- </html>';
- file_put_contents($archive_path.$temp_dir_short.'/'.$file, $file_content);
- }
- }
-
- $lang_not_exportable = get_lang('ThisItemIsNotExportable');
- $file_content = '<!DOCTYPE html
- PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="'.api_get_language_isocode().'" lang="'.api_get_language_isocode().'">
- <head>
- <title>'.$lang_not_exportable.'</title>
- <meta http-equiv="Content-Type" content="text/html; charset='.api_get_system_encoding().'" />
- </head>
- <body dir="'.api_get_text_direction().'">
- ';
- $file_content .=
- <<<EOD
- <style>
- .error-message {
- font-family: arial, verdana, helvetica, sans-serif;
- border-width: 1px;
- border-style: solid;
- left: 50%;
- margin: 10px auto;
- min-height: 30px;
- padding: 5px;
- right: 50%;
- width: 500px;
- background-color: #FFD1D1;
- border-color: #FF0000;
- color: #000;
- }
- </style>
- <body>
- <div class="error-message">
- $lang_not_exportable
- </div>
- </body>
- </html>
- EOD;
- if (!is_dir($archive_path.$temp_dir_short.'/document')) {
- @mkdir($archive_path.$temp_dir_short.'/document', api_get_permissions_for_new_directories());
- }
- file_put_contents($archive_path.$temp_dir_short.'/document/non_exportable.html', $file_content);
-
- $main_code_path = api_get_path(SYS_CODE_PATH).'newscorm/packaging/';
- $extra_files = scandir($main_code_path);
- foreach ($extra_files as $extra_file) {
- if (strpos($extra_file, '.') === 0)
- continue;
- else {
- $dest_file = $archive_path . $temp_dir_short . '/' . $extra_file;
- $this->create_path($dest_file);
- copy($main_code_path.$extra_file, $dest_file);
- }
- }
-
- $manifest = @$xmldoc->saveXML();
- $manifest = api_utf8_decode_xml($manifest);
- file_put_contents($archive_path.'/'.$temp_dir_short.'/imsmanifest.xml', $manifest);
- $zip_folder->add($archive_path.'/'.$temp_dir_short, PCLZIP_OPT_REMOVE_PATH, $archive_path.'/'.$temp_dir_short.'/');
-
- foreach ($files_cleanup as $file) {
- $res = unlink($file);
- if ($res === false) { error_log('Could not delete temp file '.$file.' '.__FILE__.' '.__LINE__, 0); }
- }
-
-
- require_once api_get_path(LIBRARY_PATH).'fileUpload.lib.php';
- $name = replace_dangerous_char($this->get_name()).'.zip';
- DocumentManager::file_send_for_download($temp_zip_file, true, $name);
- }
- public function scorm_export_to_pdf($lp_id) {
- $lp_id = intval($lp_id);
- $files_to_export = array();
- $course_data = api_get_course_info($this->cc);
- if (!empty($course_data)) {
- $scorm_path = api_get_path(SYS_COURSE_PATH).$course_data['path'].'/scorm/'.$this->path;
- require_once api_get_path(LIBRARY_PATH).'document.lib.php';
- $list = $this->get_flat_ordered_items_list($lp_id);
-
- foreach($list as $item_id) {
- $item = $this->items[$item_id];
-
-
- switch ($item->type) {
- case 'document':
- $file_data = DocumentManager::get_document_data_by_id($item->path, $this->cc);
- $file_path = api_get_path(SYS_COURSE_PATH).$course_data['path'].'/document'.$file_data['path'];
- if (file_exists($file_path)) {
- $files_to_export[] = array('title'=>$item->get_title(),'path'=>$file_path);
- }
- break;
- case 'sco':
- $file_path = $scorm_path.'/'.$item->path;
- if (file_exists($file_path)) {
- $files_to_export[] = array('title'=>$item->get_title(),'path'=>$file_path);
- }
- break;
- case 'dokeos_chapter':
- case 'dir':
- case 'chapter':
- $files_to_export[] = array('title'=>$item->get_title(),'path'=>null);
- break;
- }
- }
- require_once api_get_path(LIBRARY_PATH).'pdf.lib.php';
- $pdf = new PDF();
- $result = $pdf->html_to_pdf($files_to_export, $this->name, $this->cc, true);
- return $result;
- }
- return false;
- }
-
- public function create_path($path) {
- $path_bits = split('/', dirname($path));
-
- $path_built = IS_WINDOWS_OS ? '' : '/';
- foreach ($path_bits as $bit) {
- if (!empty ($bit)) {
- $new_path = $path_built . $bit;
- if (is_dir($new_path)) {
- $path_built = $new_path . '/';
- } else {
- mkdir($new_path, api_get_permissions_for_new_directories());
- $path_built = $new_path . '/';
- }
- }
- }
- }
-
- public function delete_lp_image() {
- $img = $this->get_preview_image();
- if ($img != '') {
- $del_file = api_get_path(SYS_COURSE_PATH) . api_get_course_path() . '/upload/learning_path/images/' . $img;
- $this->set_preview_image('');
- return @ unlink($del_file);
- } else {
- return false;
- }
- }
-
- public function upload_image($image_array) {
- $image_moved = false;
- if (!empty ($image_array['name'])) {
- $upload_ok = process_uploaded_file($image_array);
- $has_attachment = true;
- } else {
- $image_moved = true;
- }
- if ($upload_ok) {
- if ($has_attachment) {
- $courseDir = api_get_course_path() . '/upload/learning_path/images';
- $sys_course_path = api_get_path(SYS_COURSE_PATH);
- $updir = $sys_course_path . $courseDir;
-
- $new_file_name = add_ext_on_mime(stripslashes($image_array['name']), $image_array['type']);
- if (!filter_extension($new_file_name)) {
-
- $image_moved = false;
- } else {
- $file_extension = explode('.', $image_array['name']);
- $file_extension = strtolower($file_extension[sizeof($file_extension) - 1]);
- $new_file_name = uniqid('') . '.' . $file_extension;
- $new_path = $updir . '/' . $new_file_name;
-
-
- include_once api_get_path(LIBRARY_PATH).'image.lib.php';
- $temp = new image($image_array['tmp_name']);
- $picture_infos = @getimagesize($image_array['tmp_name']);
- if ($picture_infos[0] > 104) {
- $thumbwidth = 104;
- } else {
- $thumbwidth = $picture_infos[0];
- }
- if ($picture_infos[1] > 96) {
- $new_height = 96;
- } else {
- $new_height = $picture_infos[1];
- }
-
- $temp->resize($thumbwidth,$new_height, 0);
- $type = $picture_infos[2];
- $result = false;
- switch ($type) {
- case 2 :
- $result = $temp->send_image('JPG', $new_path);
- break;
- case 3 :
- $result = $temp->send_image('PNG', $new_path);
- break;
- case 1 :
- $result = $temp->send_image('GIF', $new_path);
- break;
- }
- $temp->resize($thumbwidth, $new_height, 0);
- $type = $picture_infos[2];
- $result = false;
- switch ($type) {
- case 2 :
- $result = $temp->send_image('JPG', $new_path);
- break;
- case 3 :
- $result = $temp->send_image('PNG', $new_path);
- break;
- case 1 :
- $result = $temp->send_image('GIF', $new_path);
- break;
- }
-
- if ($result) {
- $image_moved = true;
- $this->set_preview_image($new_file_name);
- return true;
- }
- }
- }
- }
- return false;
- }
- public function set_autolunch($lp_id, $status) {
- $lp_id = intval($lp_id);
- $status = intval($status);
- $lp_table = Database::get_course_table(TABLE_LP_MAIN);
-
- $attributes['autolunch'] = 0;
- $where = array('session_id = ? '=> api_get_session_id());
- Database::update($lp_table, $attributes,$where);
- if ($status == 1) {
-
- $attributes['autolunch'] = 1;
- $where = array('id = ? AND session_id = ? '=> array($lp_id, api_get_session_id()));
- Database::update($lp_table, $attributes, $where );
- }
- }
- }
- if (!function_exists('trim_value')) {
- function trim_value(& $value) {
- $value = trim($value);
- }
- }
|