learnpath.class.php 299 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205
  1. <?php //$id:$
  2. /**
  3. * This (abstract?) class defines the parent attributes and methods for the dokeos learnpaths and scorm
  4. * learnpaths. It is used by the scorm class as well as the dokeos_lp class.
  5. * @package dokeos.learnpath
  6. * @author Yannick Warnier <ywarnier@beeznest.org>
  7. * @license GNU/GPL - See Dokeos license directory for details
  8. */
  9. /**
  10. * Defines the learnpath parent class
  11. * @package dokeos.learnpath
  12. */
  13. class learnpath {
  14. var $attempt = 0; //the number for the current ID view
  15. var $cc; //course (code) this learnpath is located in
  16. var $current; //id of the current item the user is viewing
  17. var $current_score; //the score of the current item
  18. var $current_time_start; //the time the user loaded this resource (this does not mean he can see it yet)
  19. var $current_time_stop; //the time the user closed this resource
  20. var $default_status = 'not attempted';
  21. var $encoding = 'ISO-8859-1';
  22. var $error = '';
  23. var $extra_information = ''; //this string can be used by proprietary SCORM contents to store data about the current learnpath
  24. var $force_commit = false; //for SCORM only - if set to true, will send a scorm LMSCommit() request on each LMSSetValue()
  25. var $index; //the index of the active learnpath_item in $ordered_items array
  26. var $items = array();
  27. var $last; //item_id of last item viewed in the learning path
  28. var $last_item_seen = 0; //in case we have already come in this learnpath, reuse the last item seen if authorized
  29. var $license; //which license this course has been given - not used yet on 20060522
  30. var $lp_id; //DB ID for this learnpath
  31. var $lp_view_id; //DB ID for lp_view
  32. var $log_file; //file where to log learnpath API msg
  33. var $maker; //which maker has conceived the content (ENI, Articulate, ...)
  34. var $message = '';
  35. var $mode='embedded'; //holds the video display mode (fullscreen or embedded)
  36. var $name; //learnpath name (they generally have one)
  37. var $ordered_items = array(); //list of the learnpath items in the order they are to be read
  38. var $path = ''; //path inside the scorm directory (if scorm)
  39. var $theme; // the current theme of the learning path
  40. // Tells if all the items of the learnpath can be tried again. Defaults to "no" (=1)
  41. var $prevent_reinit = 1;
  42. // Describes the mode of progress bar display
  43. var $progress_bar_mode = '%';
  44. // Percentage progress as saved in the db
  45. var $progress_db = '0';
  46. var $proximity; //wether the content is distant or local or unknown
  47. var $refs_list = array(); //list of items by ref => db_id. Used only for prerequisites match.
  48. //!!!This array (refs_list) is built differently depending on the nature of the LP.
  49. //If SCORM, uses ref, if Dokeos, uses id to keep a unique value
  50. var $type; //type of learnpath. Could be 'dokeos', 'scorm', 'scorm2004', 'aicc', ...
  51. //TODO check if this type variable is useful here (instead of just in the controller script)
  52. var $user_id; //ID of the user that is viewing/using the course
  53. var $update_queue = array();
  54. var $scorm_debug = 0;
  55. var $arrMenu = array(); //array for the menu items
  56. var $debug = 0; //logging level
  57. /**
  58. * Class constructor. Needs a database handler, a course code and a learnpath id from the database.
  59. * Also builds the list of items into $this->items.
  60. * @param string Course code
  61. * @param integer Learnpath ID
  62. * @param integer User ID
  63. * @return boolean True on success, false on error
  64. */
  65. function learnpath($course, $lp_id, $user_id) {
  66. //check params
  67. //check course code
  68. if($this->debug>0){error_log('New LP - In learnpath::learnpath('.$course.','.$lp_id.','.$user_id.')',0);}
  69. if(empty($course)){
  70. $this->error = 'Course code is empty';
  71. return false;
  72. }
  73. else
  74. {
  75. $main_table = Database::get_main_table(TABLE_MAIN_COURSE);
  76. //$course = Database::escape_string($course);
  77. $course = $this->escape_string($course);
  78. $sql = "SELECT * FROM $main_table WHERE code = '$course'";
  79. if($this->debug>2){error_log('New LP - learnpath::learnpath() '.__LINE__.' - Querying course: '.$sql,0);}
  80. //$res = Database::query($sql);
  81. $res = api_sql_query($sql, __FILE__, __LINE__);
  82. if(Database::num_rows($res)>0)
  83. {
  84. $this->cc = $course;
  85. }
  86. else
  87. {
  88. $this->error = 'Course code does not exist in database ('.$sql.')';
  89. return false;
  90. }
  91. }
  92. //check learnpath ID
  93. if(empty($lp_id))
  94. {
  95. $this->error = 'Learnpath ID is empty';
  96. return false;
  97. }
  98. else
  99. {
  100. //TODO make it flexible to use any course_code (still using env course code here)
  101. $lp_table = Database::get_course_table('lp');
  102. //$id = Database::escape_integer($id);
  103. $lp_id = $this->escape_string($lp_id);
  104. $sql = "SELECT * FROM $lp_table WHERE id = '$lp_id'";
  105. if($this->debug>2){error_log('New LP - learnpath::learnpath() '.__LINE__.' - Querying lp: '.$sql,0);}
  106. //$res = Database::query($sql);
  107. $res = api_sql_query($sql, __FILE__, __LINE__);
  108. if(Database::num_rows($res)>0)
  109. {
  110. $this->lp_id = $lp_id;
  111. $row = Database::fetch_array($res);
  112. $this->type = $row['lp_type'];
  113. $this->name = stripslashes($row['name']);
  114. $this->encoding = $row['default_encoding'];
  115. $this->proximity = $row['content_local'];
  116. $this->theme = $row['theme'];
  117. $this->maker = $row['content_maker'];
  118. $this->prevent_reinit = $row['prevent_reinit'];
  119. $this->license = $row['content_license'];
  120. $this->scorm_debug = $row['debug'];
  121. $this->js_lib = $row['js_lib'];
  122. $this->path = $row['path'];
  123. if($this->type == 2){
  124. if($row['force_commit'] == 1){
  125. $this->force_commit = true;
  126. }
  127. }
  128. $this->mode = $row['default_view_mod'];
  129. }
  130. else
  131. {
  132. $this->error = 'Learnpath ID does not exist in database ('.$sql.')';
  133. return false;
  134. }
  135. }
  136. //check user ID
  137. if(empty($user_id)){
  138. $this->error = 'User ID is empty';
  139. return false;
  140. }
  141. else
  142. {
  143. //$main_table = Database::get_main_user_table();
  144. $main_table = Database::get_main_table(TABLE_MAIN_USER);
  145. //$user_id = Database::escape_integer($user_id);
  146. $user_id = $this->escape_string($user_id);
  147. $sql = "SELECT * FROM $main_table WHERE user_id = '$user_id'";
  148. if($this->debug>2){error_log('New LP - learnpath::learnpath() '.__LINE__.' - Querying user: '.$sql,0);}
  149. //$res = Database::query($sql);
  150. $res = api_sql_query($sql);
  151. if(Database::num_rows($res)>0)
  152. {
  153. $this->user_id = $user_id;
  154. }
  155. else
  156. {
  157. $this->error = 'User ID does not exist in database ('.$sql.')';
  158. return false;
  159. }
  160. }
  161. //end of variables checking
  162. //now get the latest attempt from this user on this LP, if available, otherwise create a new one
  163. $lp_table = Database::get_course_table(TABLE_LP_VIEW);
  164. //selecting by view_count descending allows to get the highest view_count first
  165. $sql = "SELECT * FROM $lp_table WHERE lp_id = '$lp_id' AND user_id = '$user_id' ORDER BY view_count DESC";
  166. if($this->debug>2){error_log('New LP - learnpath::learnpath() '.__LINE__.' - querying lp_view: '.$sql,0);}
  167. //$res = Database::query($sql);
  168. $res = api_sql_query($sql);
  169. $view_id = 0; //used later to query lp_item_view
  170. if(Database::num_rows($res)>0)
  171. {
  172. if($this->debug>2){error_log('New LP - learnpath::learnpath() '.__LINE__.' - Found previous view',0);}
  173. $row = Database::fetch_array($res);
  174. $this->attempt = $row['view_count'];
  175. $this->lp_view_id = $row['id'];
  176. $this->last_item_seen = $row['last_item'];
  177. $this->progress_db = $row['progress'];
  178. }
  179. else
  180. {
  181. if($this->debug>2){error_log('New LP - learnpath::learnpath() '.__LINE__.' - NOT Found previous view',0);}
  182. $this->attempt = 1;
  183. $sql_ins = "INSERT INTO $lp_table (lp_id,user_id,view_count) VALUES ($lp_id,$user_id,1)";
  184. $res_ins = api_sql_query($sql_ins);
  185. $this->lp_view_id = Database::get_last_insert_id();
  186. if($this->debug>2){error_log('New LP - learnpath::learnpath() '.__LINE__.' - inserting new lp_view: '.$sql_ins,0);}
  187. }
  188. //initialise items
  189. $lp_item_table = Database::get_course_table(TABLE_LP_ITEM);
  190. $sql = "SELECT * FROM $lp_item_table WHERE lp_id = '".$this->lp_id."' ORDER BY parent_item_id, display_order";
  191. $res = api_sql_query($sql);
  192. while($row = Database::fetch_array($res))
  193. {
  194. $oItem = '';
  195. //$this->ordered_items[] = $row['id'];
  196. switch($this->type){
  197. case 3: //aicc
  198. $oItem = new aiccItem('db',$row['id']);
  199. if(is_object($oItem)){
  200. $my_item_id = $oItem->get_id();
  201. $oItem->set_lp_view($this->lp_view_id);
  202. $oItem->set_prevent_reinit($this->prevent_reinit);
  203. // Don't use reference here as the next loop will make the pointed object change
  204. $this->items[$my_item_id] = $oItem;
  205. $this->refs_list[$oItem->ref]=$my_item_id;
  206. if($this->debug>2){error_log('New LP - learnpath::learnpath() - aicc object with id '.$my_item_id.' set in items[]',0);}
  207. }
  208. break;
  209. case 2:
  210. require_once('scorm.class.php');
  211. require_once('scormItem.class.php');
  212. $oItem = new scormItem('db',$row['id']);
  213. if(is_object($oItem)){
  214. $my_item_id = $oItem->get_id();
  215. $oItem->set_lp_view($this->lp_view_id);
  216. $oItem->set_prevent_reinit($this->prevent_reinit);
  217. // Don't use reference here as the next loop will make the pointed object change
  218. $this->items[$my_item_id] = $oItem;
  219. $this->refs_list[$oItem->ref]=$my_item_id;
  220. if($this->debug>2){error_log('New LP - object with id '.$my_item_id.' set in items[]',0);}
  221. }
  222. break;
  223. case 1:
  224. default:
  225. require_once('learnpathItem.class.php');
  226. $oItem = new learnpathItem($row['id'],$user_id);
  227. if(is_object($oItem)){
  228. $my_item_id = $oItem->get_id();
  229. //$oItem->set_lp_view($this->lp_view_id); moved down to when we are sure the item_view exists
  230. $oItem->set_prevent_reinit($this->prevent_reinit);
  231. // Don't use reference here as the next loop will make the pointed object change
  232. $this->items[$my_item_id] = $oItem;
  233. $this->refs_list[$my_item_id]=$my_item_id;
  234. if($this->debug>2){error_log('New LP - learnpath::learnpath() '.__LINE__.' - object with id '.$my_item_id.' set in items[]',0);}
  235. }
  236. break;
  237. }
  238. //items is a list of pointers to all items, classified by DB ID, not SCO id
  239. if($row['parent_item_id'] == 0 OR empty($this->items[$row['parent_item_id']])){
  240. $this->items[$row['id']]->set_level(0);
  241. }else{
  242. $level = $this->items[$row['parent_item_id']]->get_level()+1;
  243. $this->items[$row['id']]->set_level($level);
  244. if(is_object($this->items[$row['parent_item_id']])){
  245. //items is a list of pointers from item DB ids to item objects
  246. $this->items[$row['parent_item_id']]->add_child($row['id']);
  247. }else{
  248. if($this->debug>2){error_log('New LP - learnpath::learnpath() '.__LINE__.' - The parent item ('.$row['parent_item_id'].') of item '.$row['id'].' could not be found',0);}
  249. }
  250. }
  251. //get last viewing vars
  252. $lp_item_view_table = Database::get_course_table(TABLE_LP_ITEM_VIEW);
  253. //this query should only return one or zero result
  254. $sql = "SELECT * " .
  255. "FROM $lp_item_view_table " .
  256. "WHERE lp_view_id = ".$this->lp_view_id." " .
  257. "AND lp_item_id = ".$row['id']." ORDER BY view_count DESC ";
  258. if($this->debug>2){error_log('New LP - learnpath::learnpath() - Selecting item_views: '.$sql,0);}
  259. //get the item status
  260. $res2 = api_sql_query($sql);
  261. if(Database::num_rows($res2)>0)
  262. {
  263. //if this learnpath has already been used by this user, get his last attempt count and
  264. //the last item seen back into this object
  265. //$max = 0;
  266. $row2 = Database::fetch_array($res2);
  267. if($this->debug>2){error_log('New LP - learnpath::learnpath() - Got item_view: '.print_r($row2,true),0);}
  268. $this->items[$row['id']]->set_status($row2['status']);
  269. if(empty($row2['status'])){
  270. $this->items[$row['id']]->set_status($this->default_status);
  271. }
  272. //$this->attempt = $row['view_count'];
  273. //$this->last_item = $row['id'];
  274. }
  275. else //no item found in lp_item_view for this view
  276. {
  277. //first attempt from this user. Set attempt to 1 and last_item to 0 (first item available)
  278. //TODO if the learnpath has not got attempts activated, always use attempt '1'
  279. //$this->attempt = 1;
  280. //$this->last_item = 0;
  281. $this->items[$row['id']]->set_status($this->default_status);
  282. //Add that row to the lp_item_view table so that we have something to show in the stats page
  283. $sql_ins = "INSERT INTO $lp_item_view_table " .
  284. "(lp_item_id, lp_view_id, view_count, status) VALUES " .
  285. "(".$row['id'].",".$this->lp_view_id.",1,'not attempted')";
  286. if($this->debug>2){error_log('New LP - learnpath::learnpath() '.__LINE__.' - Inserting blank item_view : '.$sql_ins,0);}
  287. $res_ins = api_sql_query($sql_ins);
  288. }
  289. //setting the view in the item object
  290. $this->items[$row['id']]->set_lp_view($this->lp_view_id);
  291. }
  292. $this->ordered_items = $this->get_flat_ordered_items_list($this->get_id(),0);
  293. $this->max_ordered_items = 0;
  294. foreach($this->ordered_items as $index=>$dummy){
  295. if($index > $this->max_ordered_items AND !empty($dummy)){
  296. $this->max_ordered_items = $index;
  297. }
  298. }
  299. //TODO define the current item better
  300. $this->first();
  301. if($this->debug>2){error_log('New LP - learnpath::learnpath() '.__LINE__.' - End of learnpath constructor for learnpath '.$this->get_id(),0);}
  302. }
  303. /**
  304. * Function rewritten based on old_add_item() from Yannick Warnier. Due the fact that users can decide where the item should come, I had to overlook this function and
  305. * I found it better to rewrite it. Old function is still available. Added also the possibility to add a description.
  306. *
  307. * @param int $parent
  308. * @param int $previous
  309. * @param string $type
  310. * @param int $id
  311. * @param string $title
  312. * @param string $description
  313. * @return int
  314. */
  315. function add_item($parent, $previous, $type = 'dokeos_chapter', $id, $title, $description, $prerequisites=0)
  316. {
  317. if($this->debug>0){error_log('New LP - In learnpath::add_item('.$parent.','.$previous.','.$type.','.$id.','.$title.')',0);}
  318. $tbl_lp_item = Database::get_course_table('lp_item');
  319. $parent = intval($parent);
  320. $previous = intval($previous);
  321. $type = $this->escape_string($type);
  322. $id = intval($id);
  323. $title = $this->escape_string(htmlentities($title));
  324. $description = $this->escape_string(htmlentities($description));
  325. $sql_count = "
  326. SELECT COUNT(id) AS num
  327. FROM " . $tbl_lp_item . "
  328. WHERE
  329. lp_id = " . $this->get_id() . " AND
  330. parent_item_id = " . $parent;
  331. $res_count = api_sql_query($sql_count, __FILE__, __LINE__);
  332. $row = Database::fetch_array($res_count);
  333. $num = $row['num'];
  334. if($num > 0)
  335. {
  336. if($previous == 0)
  337. {
  338. $sql = "
  339. SELECT
  340. id,
  341. next_item_id,
  342. display_order
  343. FROM " . $tbl_lp_item . "
  344. WHERE
  345. lp_id = " . $this->get_id() . " AND
  346. parent_item_id = " . $parent . " AND
  347. previous_item_id = 0 OR previous_item_id=".$parent;
  348. $result = api_sql_query($sql, __FILE__, __LINE__);
  349. $row = Database::fetch_array($result);
  350. $tmp_previous = 0;
  351. $next = $row['id'];
  352. $display_order = 0;
  353. }
  354. else
  355. {
  356. $previous = (int) $previous;
  357. $sql = "
  358. SELECT
  359. id,
  360. previous_item_id,
  361. next_item_id,
  362. display_order
  363. FROM " . $tbl_lp_item . "
  364. WHERE
  365. lp_id = " . $this->get_id() . " AND
  366. id = " . $previous;
  367. $result = api_sql_query($sql, __FILE__, __LINE__);
  368. $row = Database::fetch_array($result);
  369. $tmp_previous = $row['id'];
  370. $next = $row['next_item_id'];
  371. $display_order = $row['display_order'];
  372. }
  373. }
  374. else
  375. {
  376. $tmp_previous = 0;
  377. $next = 0;
  378. $display_order = 0;
  379. }
  380. $new_item_id = -1;
  381. $id = $this->escape_string($id);
  382. if($type == 'quiz')
  383. {
  384. $sql = 'SELECT SUM(ponderation)
  385. FROM '.Database :: get_course_table(TABLE_QUIZ_QUESTION).' as quiz_question
  386. INNER JOIN '.Database :: get_course_table(TABLE_QUIZ_TEST_QUESTION).' as quiz_rel_question
  387. ON quiz_question.id = quiz_rel_question.question_id
  388. AND quiz_rel_question.exercice_id = '.$id;
  389. $rsQuiz = api_sql_query($sql, __FILE__, __LINE__);
  390. $max_score = Database::result($rsQuiz, 0, 0);
  391. }
  392. else
  393. {
  394. $max_score = 100;
  395. }
  396. if($prerequisites!=0){
  397. $sql_ins = "
  398. INSERT INTO " . $tbl_lp_item . " (
  399. lp_id,
  400. item_type,
  401. ref,
  402. title,
  403. description,
  404. path,
  405. max_score,
  406. parent_item_id,
  407. previous_item_id,
  408. next_item_id,
  409. display_order,
  410. prerequisite
  411. ) VALUES (
  412. " . $this->get_id() . ",
  413. '" . $type . "',
  414. '',
  415. '" . $title . "',
  416. '" . $description . "',
  417. '" . $id . "',
  418. '" . $max_score. "',
  419. " . $parent . ",
  420. " . $previous . ",
  421. " . $next . ",
  422. " . ($display_order + 1) . ",
  423. " . $prerequisites . "
  424. )";
  425. }
  426. else{
  427. //insert new item
  428. $sql_ins = "
  429. INSERT INTO " . $tbl_lp_item . " (
  430. lp_id,
  431. item_type,
  432. ref,
  433. title,
  434. description,
  435. path,
  436. max_score,
  437. parent_item_id,
  438. previous_item_id,
  439. next_item_id,
  440. display_order
  441. ) VALUES (
  442. " . $this->get_id() . ",
  443. '" . $type . "',
  444. '',
  445. '" . $title . "',
  446. '" . $description . "',
  447. '" . $id . "',
  448. '" . $max_score. "',
  449. " . $parent . ",
  450. " . $previous . ",
  451. " . $next . ",
  452. " . ($display_order + 1) . "
  453. )";
  454. }
  455. if($this->debug>2){error_log('New LP - Inserting dokeos_chapter: '.$sql_ins,0);}
  456. $res_ins = api_sql_query($sql_ins, __FILE__, __LINE__);
  457. if($res_ins > 0)
  458. {
  459. $new_item_id = Database::get_last_insert_id($res_ins);
  460. //update the item that should come after the new item
  461. $sql_update_next = "
  462. UPDATE " . $tbl_lp_item . "
  463. SET previous_item_id = " . $new_item_id . "
  464. WHERE id = " . $next;
  465. $res_update_next = api_sql_query($sql_update_next, __FILE__, __LINE__);
  466. //update the item that should be before the new item
  467. $sql_update_previous = "
  468. UPDATE " . $tbl_lp_item . "
  469. SET next_item_id = " . $new_item_id . "
  470. WHERE id = " . $tmp_previous;
  471. $res_update_previous = api_sql_query($sql_update_previous, __FILE__, __LINE__);
  472. //update all the items after the new item
  473. $sql_update_order = "
  474. UPDATE " . $tbl_lp_item . "
  475. SET display_order = display_order + 1
  476. WHERE
  477. lp_id = " . $this->get_id() . " AND
  478. id <> " . $new_item_id . " AND
  479. parent_item_id = " . $parent . " AND
  480. display_order > " . $display_order;
  481. $res_update_previous = api_sql_query($sql_update_order, __FILE__, __LINE__);
  482. //update the item that should come after the new item
  483. $sql_update_ref = "
  484. UPDATE " . $tbl_lp_item . "
  485. SET ref = " . $new_item_id . "
  486. WHERE id = " . $new_item_id;
  487. api_sql_query($sql_update_ref, __FILE__, __LINE__);
  488. }
  489. return $new_item_id;
  490. }
  491. /**
  492. * Static admin function allowing addition of a learnpath to a course.
  493. * @param string Course code
  494. * @param string Learnpath name
  495. * @param string Learnpath description string, if provided
  496. * @param string Type of learnpath (default = 'guess', others = 'dokeos', 'aicc',...)
  497. * @param string Type of files origin (default = 'zip', others = 'dir','web_dir',...)
  498. * @param string Zip file containing the learnpath or directory containing the learnpath
  499. * @return integer The new learnpath ID on success, 0 on failure
  500. */
  501. function add_lp($course,$name,$description='',$learnpath='guess',$origin='zip',$zipname='')
  502. {
  503. //if($this->debug>0){error_log('New LP - In learnpath::add_lp()',0);}
  504. //TODO
  505. $tbl_lp = Database::get_course_table('lp');
  506. //check course code exists
  507. //check lp_name doesn't exist, otherwise append something
  508. $i = 0;
  509. $name = learnpath::escape_string(htmlentities($name)); //Kevin Van Den Haute: added htmlentities()
  510. $check_name = "SELECT * FROM $tbl_lp WHERE name = '$name'";
  511. //if($this->debug>2){error_log('New LP - Checking the name for new LP: '.$check_name,0);}
  512. $res_name = api_sql_query($check_name, __FILE__, __LINE__);
  513. while(Database::num_rows($res_name)){
  514. //there is already one such name, update the current one a bit
  515. $i++;
  516. $name = $name.' - '.$i;
  517. $check_name = "SELECT * FROM $tbl_lp WHERE name = '$name'";
  518. //if($this->debug>2){error_log('New LP - Checking the name for new LP: '.$check_name,0);}
  519. $res_name = api_sql_query($check_name, __FILE__, __LINE__);
  520. }
  521. //new name does not exist yet; keep it
  522. //escape description
  523. $description = learnpath::escape_string(htmlentities($description)); //Kevin: added htmlentities()
  524. $type = 1;
  525. switch($learnpath){
  526. case 'guess':
  527. break;
  528. case 'dokeos':
  529. $type = 1;
  530. break;
  531. case 'aicc':
  532. break;
  533. }
  534. switch($origin){
  535. case 'zip':
  536. //check zipname string. If empty, we are currently creating a new Dokeos learnpath
  537. break;
  538. case 'manual':
  539. default:
  540. $get_max = "SELECT MAX(display_order) FROM $tbl_lp";
  541. $res_max = api_sql_query($get_max, __FILE__, __LINE__);
  542. if(Database::num_rows($res_max)<1){
  543. $dsp = 1;
  544. }else{
  545. $row = Database::fetch_array($res_max);
  546. $dsp = $row[0]+1;
  547. }
  548. $sql_insert = "INSERT INTO $tbl_lp " .
  549. "(lp_type,name,description,path,default_view_mod," .
  550. "default_encoding,display_order,content_maker," .
  551. "content_local,js_lib) " .
  552. "VALUES ($type,'$name','$description','','embedded'," .
  553. "'UTF-8','$dsp','Dokeos'," .
  554. "'local','')";
  555. //if($this->debug>2){error_log('New LP - Inserting new lp '.$sql_insert,0);}
  556. $res_insert = api_sql_query($sql_insert, __FILE__, __LINE__);
  557. $id = Database::get_last_insert_id();
  558. if($id>0){
  559. //insert into item_property
  560. api_item_property_update(api_get_course_info(),TOOL_LEARNPATH,$id,'LearnpathAdded',api_get_user_id());
  561. return $id;
  562. }
  563. break;
  564. }
  565. }
  566. /**
  567. * Appends a message to the message attribute
  568. * @param string Message to append.
  569. */
  570. function append_message($string)
  571. {
  572. if($this->debug>0){error_log('New LP - In learnpath::append_message()',0);}
  573. $this->message .= $string;
  574. }
  575. /**
  576. * Autocompletes the parents of an item in case it's been completed or passed
  577. * @param integer Optional ID of the item from which to look for parents
  578. */
  579. function autocomplete_parents($item)
  580. {
  581. if($this->debug>0){error_log('New LP - In learnpath::autocomplete_parents()',0);}
  582. if(empty($item)){
  583. $item = $this->current;
  584. }
  585. $parent_id = $this->items[$item]->get_parent();
  586. if($this->debug>2){error_log('New LP - autocompleting parent of item '.$item.' (item '.$parent_id.')',0);}
  587. if(is_object($this->items[$item]) and !empty($parent_id))
  588. {//if $item points to an object and there is a parent
  589. if($this->debug>2){error_log('New LP - '.$item.' is an item, proceed',0);}
  590. $current_item =& $this->items[$item];
  591. $parent =& $this->items[$parent_id]; //get the parent
  592. //new experiment including failed and browsed in completed status
  593. $current_status = $current_item->get_status();
  594. if($current_item->is_done() || $current_status=='browsed' || $current_status=='failed')
  595. {
  596. //if the current item is completed or passes or succeeded
  597. $completed = true;
  598. if($this->debug>2){error_log('New LP - Status of current item is alright',0);}
  599. foreach($parent->get_children() as $child)
  600. {
  601. //check all his brothers (his parent's children) for completion status
  602. if($child!= $item)
  603. {
  604. if($this->debug>2){error_log('New LP - Looking at brother with ID '.$child.', status is '.$this->items[$child]->get_status(),0);}
  605. //if($this->items[$child]->status_is(array('completed','passed','succeeded')))
  606. //Trying completing parents of failed and browsed items as well
  607. if($this->items[$child]->status_is(array('completed','passed','succeeded','browsed','failed')))
  608. {
  609. //keep completion status to true
  610. }else{
  611. if($this->debug>2){error_log('New LP - Found one incomplete child of '.$parent_id.': '.$child.' is '.$this->items[$child]->get_status(),0);}
  612. $completed = false;
  613. }
  614. }
  615. }
  616. if($completed == true)
  617. { //if all the children were completed
  618. $parent->set_status('completed');
  619. $parent->save(false,$this->prerequisites_match($parent->get_id()));
  620. $this->update_queue[$parent->get_id()] = $parent->get_status();
  621. if($this->debug>2){error_log('New LP - Added parent to update queue '.print_r($this->update_queue,true),0);}
  622. $this->autocomplete_parents($parent->get_id()); //recursive call
  623. }
  624. }else{
  625. //error_log('New LP - status of current item is not enough to get bothered with it',0);
  626. }
  627. }
  628. }
  629. /**
  630. * Autosaves the current results into the database for the whole learnpath
  631. */
  632. function autosave()
  633. {
  634. if($this->debug>0){error_log('New LP - In learnpath::autosave()',0);}
  635. //TODO add aditionnal save operations for the learnpath itself
  636. }
  637. /**
  638. * Clears the message attribute
  639. */
  640. function clear_message()
  641. {
  642. if($this->debug>0){error_log('New LP - In learnpath::clear_message()',0);}
  643. $this->message = '';
  644. }
  645. /**
  646. * Closes the current resource
  647. *
  648. * Stops the timer
  649. * Saves into the database if required
  650. * Clears the current resource data from this object
  651. * @return boolean True on success, false on failure
  652. */
  653. function close()
  654. {
  655. if($this->debug>0){error_log('New LP - In learnpath::close()',0);}
  656. if(empty($this->lp_id))
  657. {
  658. $this->error = 'Trying to close this learnpath but no ID is set';
  659. return false;
  660. }
  661. $this->current_time_stop = time();
  662. if($this->save)
  663. {
  664. $learnpath_view_table = Database::get_course_table(TABLE_LP_VIEW);
  665. /*
  666. $sql = "UPDATE $learnpath_view_table " .
  667. "SET " .
  668. "stop_time = ".$this->current_time_stop.", " .
  669. "score = ".$this->current_score.", ".
  670. "WHERE learnpath_id = '".$this->lp_id."'";
  671. //$res = Database::query($sql);
  672. $res = api_sql_query($res);
  673. if(mysql_affected_rows($res)<1)
  674. {
  675. $this->error = 'Could not update learnpath_view table while closing learnpath';
  676. return false;
  677. }
  678. */
  679. }
  680. $this->ordered_items = array();
  681. $this->index=0;
  682. unset($this->lp_id);
  683. //unset other stuff
  684. return true;
  685. }
  686. /**
  687. * Static admin function allowing removal of a learnpath
  688. * @param string Course code
  689. * @param integer Learnpath ID
  690. * @param string Whether to delete data or keep it (default: 'keep', others: 'remove')
  691. * @return boolean True on success, false on failure (might change that to return number of elements deleted)
  692. */
  693. function delete($course=null,$id=null,$delete='keep')
  694. {
  695. //TODO implement a way of getting this to work when the current object is not set
  696. //In clear: implement this in the item class as well (abstract class) and use the given ID in queries
  697. //if(empty($course)){$course = api_get_course_id();}
  698. //if(empty($id)){$id = $this->get_id();}
  699. //If an ID is specifically given and the current LP is not the same,
  700. //prevent delete
  701. if(!empty($id) && ($id != $this->lp_id)){return false;}
  702. //if($this->debug>0){error_log('New LP - In learnpath::delete()',0);}
  703. foreach($this->items as $id => $dummy)
  704. {
  705. $this->items[$id]->delete();
  706. }
  707. $lp = Database::get_course_table('lp');
  708. $lp_view = Database::get_course_table('lp_view');
  709. $sql_del_view = "DELETE FROM $lp_view WHERE lp_id = ".$this->lp_id;
  710. //if($this->debug>2){error_log('New LP - Deleting views bound to lp '.$this->lp_id.': '.$sql_del_view,0);}
  711. $res_del_view = api_sql_query($sql_del_view, __FILE__, __LINE__);
  712. $this->toggle_publish($this->lp_id,'i');
  713. //if($this->debug>2){error_log('New LP - Deleting lp '.$this->lp_id.' of type '.$this->type,0);}
  714. if($this->type == 2 OR $this->type==3){
  715. //this is a scorm learning path, delete the files as well
  716. $sql = "SELECT path FROM $lp WHERE id = ".$this->lp_id;
  717. $res = api_sql_query($sql, __FILE__, __LINE__);
  718. if(Database::num_rows($res)>0){
  719. $row = Database::fetch_array($res);
  720. $path = $row['path'];
  721. $sql = "SELECT id FROM $lp WHERE path = '$path' AND id != ".$this->lp_id;
  722. $res = api_sql_query($sql, __FILE__, __LINE__);
  723. if(Database::num_rows($res)>0)
  724. { //another learning path uses this directory, so don't delete it
  725. if($this->debug>2){error_log('New LP - In learnpath::delete(), found other LP using path '.$path.', keeping directory',0);}
  726. }else{
  727. //no other LP uses that directory, delete it
  728. $course_rel_dir = api_get_course_path().'/scorm/'; //scorm dir web path starting from /courses
  729. $course_scorm_dir = api_get_path(SYS_COURSE_PATH).$course_rel_dir; //absolute system path for this course
  730. if($delete == 'remove' && is_dir($course_scorm_dir.$path) and !empty($course_scorm_dir)){
  731. if($this->debug>2){error_log('New LP - In learnpath::delete(), found SCORM, deleting directory: '.$course_scorm_dir.$path,0);}
  732. exec('rm -rf '.$course_scorm_dir.$path);
  733. }
  734. }
  735. }
  736. }
  737. $sql_del_lp = "DELETE FROM $lp WHERE id = ".$this->lp_id;
  738. //if($this->debug>2){error_log('New LP - Deleting lp '.$this->lp_id.': '.$sql_del_lp,0);}
  739. $res_del_lp = api_sql_query($sql_del_lp, __FILE__, __LINE__);
  740. $this->update_display_order();//updates the display order of all lps
  741. api_item_property_update(api_get_course_info(),TOOL_LEARNPATH,$this->lp_id,'delete',api_get_user_id());
  742. //TODO: also delete items and item-views
  743. }
  744. /**
  745. * Removes all the children of one item - dangerous!
  746. * @param integer Element ID of which children have to be removed
  747. * @return integer Total number of children removed
  748. */
  749. function delete_children_items($id){
  750. if($this->debug>0){error_log('New LP - In learnpath::delete_children_items('.$id.')',0);}
  751. $num = 0;
  752. if(empty($id) || $id != strval(intval($id))){return false;}
  753. $lp_item = Database::get_course_table('lp_item');
  754. $sql = "SELECT * FROM $lp_item WHERE parent_item_id = $id";
  755. $res = api_sql_query($sql, __FILE__, __LINE__);
  756. while($row = Database::fetch_array($res)){
  757. $num += $this->delete_children_items($row['id']);
  758. $sql_del = "DELETE FROM $lp_item WHERE id = ".$row['id'];
  759. $res_del = api_sql_query($sql_del, __FILE__, __LINE__);
  760. $num++;
  761. }
  762. return $num;
  763. }
  764. /**
  765. * Removes an item from the current learnpath
  766. * @param integer Elem ID (0 if first)
  767. * @param integer Whether to remove the resource/data from the system or leave it (default: 'keep', others 'remove')
  768. * @return integer Number of elements moved
  769. * @todo implement resource removal
  770. */
  771. function delete_item($id, $remove='keep')
  772. {
  773. if($this->debug>0){error_log('New LP - In learnpath::delete_item()',0);}
  774. //TODO - implement the resource removal
  775. if(empty($id) || $id != strval(intval($id))){return false;}
  776. //first select item to get previous, next, and display order
  777. $lp_item = Database::get_course_table('lp_item');
  778. $sql_sel = "SELECT * FROM $lp_item WHERE id = $id";
  779. $res_sel = api_sql_query($sql_sel,__FILE__,__LINE__);
  780. if(Database::num_rows($res_sel)<1){return false;}
  781. $row = Database::fetch_array($res_sel);
  782. $previous = $row['previous_item_id'];
  783. $next = $row['next_item_id'];
  784. $display = $row['display_order'];
  785. $parent = $row['parent_item_id'];
  786. $lp = $row['lp_id'];
  787. //delete children items
  788. $num = $this->delete_children_items($id);
  789. if($this->debug>2){error_log('New LP - learnpath::delete_item() - deleted '.$num.' children of element '.$id,0);}
  790. //now delete the item
  791. $sql_del = "DELETE FROM $lp_item WHERE id = $id";
  792. if($this->debug>2){error_log('New LP - Deleting item: '.$sql_del,0);}
  793. $res_del = api_sql_query($sql_del,__FILE__,__LINE__);
  794. //now update surrounding items
  795. $sql_upd = "UPDATE $lp_item SET next_item_id = $next WHERE id = $previous";
  796. $res_upd = api_sql_query($sql_upd,__FILE__,__LINE__);
  797. $sql_upd = "UPDATE $lp_item SET previous_item_id = $previous WHERE id = $next";
  798. $res_upd = api_sql_query($sql_upd,__FILE__,__LINE__);
  799. //now update all following items with new display order
  800. $sql_all = "UPDATE $lp_item SET display_order = display_order-1 WHERE lp_id = $lp AND parent_item_id = $parent AND display_order > $display";
  801. $res_all = api_sql_query($sql_all,__FILE__,__LINE__);
  802. }
  803. /**
  804. * Updates an item's content in place
  805. * @param integer Element ID
  806. * @param string New content
  807. * @return boolean True on success, false on error
  808. */
  809. function edit_item($id, $parent, $previous, $title, $description, $prerequisites=0)
  810. {
  811. if($this->debug > 0){error_log('New LP - In learnpath::edit_item()', 0);}
  812. if(empty($id) or ($id != strval(intval($id))) or empty($title)){ return false; }
  813. $tbl_lp_item = Database::get_course_table('lp_item');
  814. $sql_select = "
  815. SELECT *
  816. FROM " . $tbl_lp_item . "
  817. WHERE id = " . $id;
  818. $res_select = api_sql_query($sql_select, __FILE__, __LINE__);
  819. $row_select = Database::fetch_array($res_select);
  820. $same_parent = ($row_select['parent_item_id'] == $parent) ? true : false;
  821. $same_previous = ($row_select['previous_item_id'] == $previous) ? true : false;
  822. if($same_parent && $same_previous)
  823. {
  824. //only update title and description
  825. $sql_update = "
  826. UPDATE " . $tbl_lp_item . "
  827. SET
  828. title = '" . $this->escape_string(htmlentities($title)) . "',
  829. prerequisite = '".$prerequisites."',
  830. description = '" . $this->escape_string(htmlentities($description)) . "'
  831. WHERE id = " . $id;
  832. $res_update = api_sql_query($sql_update, __FILE__, __LINE__);
  833. }
  834. else
  835. {
  836. $old_parent = $row_select['parent_item_id'];
  837. $old_previous = $row_select['previous_item_id'];
  838. $old_next = $row_select['next_item_id'];
  839. $old_order = $row_select['display_order'];
  840. $old_prerequisite= $row_select['prerequisite'];
  841. /* BEGIN -- virtually remove the current item id */
  842. /* for the next and previous item it is like the current item doesn't exist anymore */
  843. if($old_previous != 0)
  844. {
  845. $sql_update_next = "
  846. UPDATE " . $tbl_lp_item . "
  847. SET next_item_id = " . $old_next . "
  848. WHERE id = " . $old_previous;
  849. $res_update_next = api_sql_query($sql_update_next, __FILE__, __LINE__);
  850. //echo '<p>' . $sql_update_next . '</p>';
  851. }
  852. if($old_next != 0)
  853. {
  854. $sql_update_previous = "
  855. UPDATE " . $tbl_lp_item . "
  856. SET previous_item_id = " . $old_previous . "
  857. WHERE id = " . $old_next;
  858. $res_update_previous = api_sql_query($sql_update_previous, __FILE__, __LINE__);
  859. //echo '<p>' . $sql_update_previous . '</p>';
  860. }
  861. //display_order - 1 for every item with a display_order bigger then the display_order of the current item
  862. $sql_update_order = "
  863. UPDATE " . $tbl_lp_item . "
  864. SET display_order = display_order - 1
  865. WHERE
  866. display_order > " . $old_order . " AND
  867. parent_item_id = " . $old_parent;
  868. $res_update_order = api_sql_query($sql_update_order, __FILE__, __LINE__);
  869. //echo '<p>' . $sql_update_order . '</p>';
  870. /* END -- virtually remove the current item id */
  871. /* BEGIN -- update the current item id to his new location */
  872. if($previous == 0)
  873. {
  874. //select the data of the item that should come after the current item
  875. $sql_select_old = "
  876. SELECT
  877. id,
  878. display_order
  879. FROM " . $tbl_lp_item . "
  880. WHERE
  881. lp_id = " . $this->lp_id . " AND
  882. parent_item_id = " . $parent . " AND
  883. previous_item_id = " . $previous;
  884. $res_select_old = api_sql_query($sql_select_old, __FILE__, __LINE__);
  885. $row_select_old = Database::fetch_array($res_select_old);
  886. //echo '<p>' . $sql_select_old . '</p>';
  887. //if the new parent didn't have children before
  888. if(Database::num_rows($res_select_old) == 0)
  889. {
  890. $new_next = 0;
  891. $new_order = 1;
  892. }
  893. else
  894. {
  895. $new_next = $row_select_old['id'];
  896. $new_order = $row_select_old['display_order'];
  897. }
  898. //echo 'New next_item_id of current item: ' . $new_next . '<br />';
  899. //echo 'New previous_item_id of current item: ' . $previous . '<br />';
  900. //echo 'New display_order of current item: ' . $new_order . '<br />';
  901. }
  902. else
  903. {
  904. //select the data of the item that should come before the current item
  905. $sql_select_old = "
  906. SELECT
  907. next_item_id,
  908. display_order
  909. FROM " . $tbl_lp_item . "
  910. WHERE id = " . $previous;
  911. $res_select_old = api_sql_query($sql_select_old, __FILE__, __LINE__);
  912. $row_select_old = Database::fetch_array($res_select_old);
  913. //echo '<p>' . $sql_select_old . '</p>';
  914. //echo 'New next_item_id of current item: ' . $row_select_old['next_item_id'] . '<br />';
  915. //echo 'New previous_item_id of current item: ' . $previous . '<br />';
  916. //echo 'New display_order of current item: ' . ($row_select_old['display_order'] + 1) . '<br />';
  917. $new_next = $row_select_old['next_item_id'];
  918. $new_order = $row_select_old['display_order'] + 1;
  919. }
  920. //update the current item with the new data
  921. $sql_update = "
  922. UPDATE " . $tbl_lp_item . "
  923. SET
  924. title = '" . $this->escape_string(htmlentities($title)) . "',
  925. description = '" . $this->escape_string(htmlentities($description)) . "',
  926. parent_item_id = " . $parent . ",
  927. previous_item_id = " . $previous . ",
  928. next_item_id = " . $new_next . ",
  929. display_order = " . $new_order . "
  930. WHERE id = " . $id;
  931. $res_update_next = api_sql_query($sql_update, __FILE__, __LINE__);
  932. //echo '<p>' . $sql_update . '</p>';
  933. if($previous != 0)
  934. {
  935. //update the previous item's next_item_id
  936. $sql_update_previous = "
  937. UPDATE " . $tbl_lp_item . "
  938. SET next_item_id = " . $id . "
  939. WHERE id = " . $previous;
  940. $res_update_next = api_sql_query($sql_update_previous, __FILE__, __LINE__);
  941. //echo '<p>' . $sql_update_previous . '</p>';
  942. }
  943. if($new_next != 0)
  944. {
  945. //update the next item's previous_item_id
  946. $sql_update_next = "
  947. UPDATE " . $tbl_lp_item . "
  948. SET previous_item_id = " . $id . "
  949. WHERE id = " . $new_next;
  950. $res_update_next = api_sql_query($sql_update_next, __FILE__, __LINE__);
  951. //echo '<p>' . $sql_update_next . '</p>';
  952. }
  953. if($old_prerequisite!=$prerequisites){
  954. $sql_update_next = "
  955. UPDATE " . $tbl_lp_item . "
  956. SET prerequisite = " . $prerequisites . "
  957. WHERE id = " . $id;
  958. $res_update_next = api_sql_query($sql_update_next, __FILE__, __LINE__);
  959. }
  960. //update all the items with the same or a bigger display_order than
  961. //the current item
  962. $sql_update_order = "
  963. UPDATE " . $tbl_lp_item . "
  964. SET display_order = display_order + 1
  965. WHERE
  966. lp_id = " . $this->get_id() . " AND
  967. id <> " . $id . " AND
  968. parent_item_id = " . $parent . " AND
  969. display_order >= " . $new_order;
  970. $res_update_next = api_sql_query($sql_update_order, __FILE__, __LINE__);
  971. //echo '<p>' . $sql_update_order . '</p>';
  972. /* END -- update the current item id to his new location */
  973. }
  974. }
  975. /**
  976. * Updates an item's prereq in place
  977. * @param integer Element ID
  978. * @param string Prerequisite Element ID
  979. *
  980. * @param string Prerequisite item type
  981. *
  982. * @param string Prerequisite min score
  983. *
  984. * @param string Prerequisite max score
  985. * @return boolean True on success, false on error
  986. */
  987. function edit_item_prereq($id, $prerequisite_id, $mastery_score = 0, $max_score = 100)
  988. {
  989. if($this->debug>0){error_log('New LP - In learnpath::edit_item_prereq('.$id.','.$prerequisite_id.','.$mastery_score.','.$max_score.')',0);}
  990. if(empty($id) or ($id != strval(intval($id))) or empty($prerequisite_id)){ return false; }
  991. $prerequisite_id = $this->escape_string($prerequisite_id);
  992. $tbl_lp_item = Database::get_course_table('lp_item');
  993. if(!is_numeric($mastery_score) || $mastery_score < 0)
  994. $mastery_score = 0;
  995. if(!is_numeric($max_score) || $max_score < 0)
  996. $max_score = 100;
  997. if($mastery_score > $max_score)
  998. $max_score = $mastery_score;
  999. if(!is_numeric($prerequisite_id))
  1000. $prerequisite_id = 'NULL';
  1001. $sql_upd = "
  1002. UPDATE " . $tbl_lp_item . "
  1003. SET prerequisite = ".$prerequisite_id." WHERE id = ".$id;
  1004. $res_upd = api_sql_query($sql_upd ,__FILE__, __LINE__);
  1005. if($prerequisite_id!='NULL' && $prerequisite_id!='')
  1006. {
  1007. $sql_upd = " UPDATE ".$tbl_lp_item." SET
  1008. mastery_score = " . $mastery_score .
  1009. //", max_score = " . $max_score . " " . //max score cannot be changed in the form anyway - see display_item_prerequisites_form()
  1010. " WHERE ref = '" . $prerequisite_id."'" ; //will this be enough to ensure unicity?
  1011. $res_upd = api_sql_query($sql_upd ,__FILE__, __LINE__);
  1012. }
  1013. //TODO update the item object (can be ignored for now because refreshed)
  1014. return true;
  1015. }
  1016. /**
  1017. * Escapes a string with the available database escape function
  1018. * @param string String to escape
  1019. * @return string String escaped
  1020. */
  1021. function escape_string($string){
  1022. //if($this->debug>0){error_log('New LP - In learnpath::escape_string('.$string.')',0);}
  1023. return Database::escape_string($string);
  1024. }
  1025. /**
  1026. * Static admin function exporting a learnpath into a zip file
  1027. * @param string Export type (scorm, zip, cd)
  1028. * @param string Course code
  1029. * @param integer Learnpath ID
  1030. * @param string Zip file name
  1031. * @return string Zip file path (or false on error)
  1032. */
  1033. function export_lp($type, $course, $id, $zipname)
  1034. {
  1035. //if($this->debug>0){error_log('New LP - In learnpath::export_lp()',0);}
  1036. //TODO
  1037. if(empty($type) OR empty($course) OR empty($id) OR empty($zipname)){return false;}
  1038. $url = '';
  1039. switch($type){
  1040. case 'scorm':
  1041. break;
  1042. case 'zip':
  1043. break;
  1044. case 'cdrom':
  1045. break;
  1046. }
  1047. return $url;
  1048. }
  1049. /**
  1050. * Gets all the chapters belonging to the same parent as the item/chapter given
  1051. * Can also be called as abstract method
  1052. * @param integer Item ID
  1053. * @return array A list of all the "brother items" (or an empty array on failure)
  1054. */
  1055. function get_brother_chapters($id){
  1056. if($this->debug>0){error_log('New LP - In learnpath::get_brother_chapters()',0);}
  1057. if(empty($id) OR $id != strval(intval($id))){ return array();}
  1058. $lp_item = Database::get_course_table('lp_item');
  1059. $sql_parent = "SELECT * FROM $lp_item WHERE id = $id AND item_type='dokeos_chapter'";
  1060. $res_parent = api_sql_query($sql_parent,__FILE__,__LINE__);
  1061. if(Database::num_rows($res_parent)>0){
  1062. $row_parent = Database::fetch_array($res_parent);
  1063. $parent = $row_parent['parent_item_id'];
  1064. $sql_bros = "SELECT * FROM $lp_item WHERE parent_item_id = $parent AND id = $id AND item_type='dokeos_chapter' ORDER BY display_order";
  1065. $res_bros = api_sql_query($sql_bros,__FILE__,__LINE__);
  1066. $list = array();
  1067. while ($row_bro = Database::fetch_array($res_bros)){
  1068. $list[] = $row_bro;
  1069. }
  1070. return $list;
  1071. }
  1072. return array();
  1073. }
  1074. /**
  1075. * Gets all the items belonging to the same parent as the item given
  1076. * Can also be called as abstract method
  1077. * @param integer Item ID
  1078. * @return array A list of all the "brother items" (or an empty array on failure)
  1079. */
  1080. function get_brother_items($id){
  1081. if($this->debug>0){error_log('New LP - In learnpath::get_brother_items('.$id.')',0);}
  1082. if(empty($id) OR $id != strval(intval($id))){ return array();}
  1083. $lp_item = Database::get_course_table('lp_item');
  1084. $sql_parent = "SELECT * FROM $lp_item WHERE id = $id";
  1085. $res_parent = api_sql_query($sql_parent,__FILE__,__LINE__);
  1086. if(Database::num_rows($res_parent)>0){
  1087. $row_parent = Database::fetch_array($res_parent);
  1088. $parent = $row_parent['parent_item_id'];
  1089. $sql_bros = "SELECT * FROM $lp_item WHERE parent_item_id = $parent ORDER BY display_order";
  1090. $res_bros = api_sql_query($sql_bros,__FILE__,__LINE__);
  1091. $list = array();
  1092. while ($row_bro = Database::fetch_array($res_bros)){
  1093. $list[] = $row_bro;
  1094. }
  1095. return $list;
  1096. }
  1097. return array();
  1098. }
  1099. /**
  1100. * Gets the number of items currently completed
  1101. * @return integer The number of items currently completed
  1102. */
  1103. function get_complete_items_count()
  1104. {
  1105. if($this->debug>0){error_log('New LP - In learnpath::get_complete_items_count()',0);}
  1106. $i = 0;
  1107. foreach($this->items as $id => $dummy){
  1108. //if($this->items[$id]->status_is(array('completed','passed','succeeded'))){
  1109. //Trying failed and browsed considered "progressed" as well
  1110. 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'){
  1111. $i++;
  1112. }
  1113. }
  1114. return $i;
  1115. }
  1116. /**
  1117. * Gets the current item ID
  1118. * @return integer The current learnpath item id
  1119. */
  1120. function get_current_item_id()
  1121. {
  1122. $current = 0;
  1123. if($this->debug>0){error_log('New LP - In learnpath::get_current_item_id()',0);}
  1124. if(!empty($this->current))
  1125. {
  1126. $current = $this->current;
  1127. }
  1128. if($this->debug>2){error_log('New LP - In learnpath::get_current_item_id() - Returning '.$current,0);}
  1129. return $current;
  1130. }
  1131. /**
  1132. * Gets the total number of items available for viewing in this SCORM
  1133. * @return integer The total number of items
  1134. */
  1135. function get_total_items_count()
  1136. {
  1137. if($this->debug>0){error_log('New LP - In learnpath::get_total_items_count()',0);}
  1138. return count($this->items);
  1139. }
  1140. /**
  1141. * Gets the total number of items available for viewing in this SCORM but without chapters
  1142. * @return integer The total no-chapters number of items
  1143. */
  1144. function get_total_items_count_without_chapters()
  1145. {
  1146. if($this->debug>0){error_log('New LP - In learnpath::get_total_items_count_without_chapters()',0);}
  1147. $total=0;
  1148. foreach($this->items as $temp=>$temp2){
  1149. if(!in_array($temp2->get_type(), array('dokeos_chapter','chapter','dir'))) $total++;
  1150. }
  1151. return $total;
  1152. }
  1153. /**
  1154. * Gets the first element URL.
  1155. * @return string URL to load into the viewer
  1156. */
  1157. function first()
  1158. {
  1159. if($this->debug>0){error_log('New LP - In learnpath::first()',0);}
  1160. //test if the last_item_seen exists and is not a dir
  1161. if(!empty($this->last_item_seen)
  1162. && !empty($this->items[$this->last_item_seen])
  1163. && $this->items[$this->last_item_seen]->get_type() != 'dir'
  1164. && $this->items[$this->last_item_seen]->get_type() != 'dokeos_chapter'
  1165. && $this->items[$this->last_item_seen]->is_done() != true
  1166. ){
  1167. 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);}
  1168. $index = -1;
  1169. foreach($this->ordered_items as $myindex => $item_id){
  1170. if($item_id == $this->last_item_seen){
  1171. $index = $myindex;
  1172. break;
  1173. }
  1174. }
  1175. if($index==-1){
  1176. //index hasn't changed, so item not found - panic (this shouldn't happen)
  1177. 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);}
  1178. return false;
  1179. }else{
  1180. $this->last = $this->last_item_seen;
  1181. $this->current = $this->last_item_seen;
  1182. $this->index = $index;
  1183. }
  1184. }else{
  1185. if($this->debug>2){error_log('New LP - In learnpath::first() - No last item seen',0);}
  1186. $index = 0;
  1187. //loop through all ordered items and stop at the first item that is
  1188. //not a directory *and* that has not been completed yet
  1189. while (!empty($this->ordered_items[$index])
  1190. AND
  1191. is_a($this->items[$this->ordered_items[$index]],'learnpathItem')
  1192. AND
  1193. (
  1194. $this->items[$this->ordered_items[$index]]->get_type() == 'dir'
  1195. OR $this->items[$this->ordered_items[$index]]->get_type() == 'dokeos_chapter'
  1196. OR $this->items[$this->ordered_items[$index]]->is_done() === true
  1197. )
  1198. AND $index < $this->max_ordered_items)
  1199. {
  1200. $index ++;
  1201. }
  1202. $this->last = $this->current;
  1203. //current is
  1204. $this->current = $this->ordered_items[$index];
  1205. $this->index = $index;
  1206. if($this->debug>2){error_log('New LP - In learnpath::first() - No last item seen. New last = '.$this->last.'('.$this->ordered_items[$index].')',0);}
  1207. }
  1208. if($this->debug>2){error_log('New LP - In learnpath::first() - First item is '.$this->get_current_item_id());}
  1209. }
  1210. /**
  1211. * Gets the information about an item in a format usable as JavaScript to update
  1212. * the JS API by just printing this content into the <head> section of the message frame
  1213. * @param integer Item ID
  1214. * @return string
  1215. */
  1216. function get_js_info($item_id=''){
  1217. if($this->debug>0){error_log('New LP - In learnpath::get_js_info('.$item_id.')',0);}
  1218. $info = '';
  1219. $item_id = $this->escape_string($item_id);
  1220. if(!empty($item_id) && is_object($this->items[$item_id])){
  1221. //if item is defined, return values from DB
  1222. $oItem = $this->items[$item_id];
  1223. $info .= '<script language="javascript">';
  1224. $info .= "top.set_score(".$oItem->get_score().");\n";
  1225. $info .= "top.set_max(".$oItem->get_max().");\n";
  1226. $info .= "top.set_min(".$oItem->get_min().");\n";
  1227. $info .= "top.set_lesson_status('".$oItem->get_status()."');";
  1228. $info .= "top.set_session_time('".$oItem->get_scorm_time('js')."');";
  1229. $info .= "top.set_suspend_data('".$oItem->get_suspend_data()."');";
  1230. $info .= "top.set_saved_lesson_status('".$oItem->get_status()."');";
  1231. $info .= "top.set_flag_synchronized();";
  1232. $info .= '</script>';
  1233. if($this->debug>2){error_log('New LP - in learnpath::get_js_info('.$item_id.') - returning: '.$info,0);}
  1234. return $info;
  1235. }else{
  1236. //if item_id is empty, just update to default SCORM data
  1237. $info .= '<script language="javascript">';
  1238. $info .= "top.set_score(".learnpathItem::get_score().");\n";
  1239. $info .= "top.set_max(".learnpathItem::get_max().");\n";
  1240. $info .= "top.set_min(".learnpathItem::get_min().");\n";
  1241. $info .= "top.set_lesson_status('".learnpathItem::get_status()."');";
  1242. $info .= "top.set_session_time('".learnpathItem::get_scorm_time('js')."');";
  1243. $info .= "top.set_suspend_data('".learnpathItem::get_suspend_data()."');";
  1244. $info .= "top.set_saved_lesson_status('".learnpathItem::get_status()."');";
  1245. $info .= "top.set_flag_synchronized();";
  1246. $info .= '</script>';
  1247. if($this->debug>2){error_log('New LP - in learnpath::get_js_info('.$item_id.') - returning: '.$info,0);}
  1248. return $info;
  1249. }
  1250. }
  1251. /**
  1252. * Gets the js library from the database
  1253. * @return string The name of the javascript library to be used
  1254. */
  1255. function get_js_lib(){
  1256. $lib = '';
  1257. if(!empty($this->js_lib)){
  1258. $lib = $this->js_lib;
  1259. }
  1260. return $lib;
  1261. }
  1262. /**
  1263. * Gets the learnpath database ID
  1264. * @return integer Learnpath ID in the lp table
  1265. */
  1266. function get_id()
  1267. {
  1268. if($this->debug>0){error_log('New LP - In learnpath::get_id()',0);}
  1269. if(!empty($this->lp_id))
  1270. {
  1271. return $this->lp_id;
  1272. }else{
  1273. return 0;
  1274. }
  1275. }
  1276. /**
  1277. * Gets the last element URL.
  1278. * @return string URL to load into the viewer
  1279. */
  1280. function get_last()
  1281. {
  1282. if($this->debug>0){error_log('New LP - In learnpath::get_last()',0);}
  1283. $this->index = count($this->ordered_items)-1;
  1284. return $this->ordered_items[$this->index];
  1285. }
  1286. /**
  1287. * Gets the navigation bar for the learnpath display screen
  1288. * @return string The HTML string to use as a navigation bar
  1289. */
  1290. function get_navigation_bar()
  1291. {
  1292. if($this->debug>0){error_log('New LP - In learnpath::get_navigation_bar()',0);}
  1293. //TODO find a good value for the following variables
  1294. $file = '';
  1295. $openDir = '';
  1296. $edoceo = '';
  1297. $time = 0;
  1298. $navbar = '';
  1299. $RequestUri = '';
  1300. $mycurrentitemid = $this->get_current_item_id();
  1301. if($this->mode == 'fullscreen'){
  1302. $navbar = '<table cellpadding="0" cellspacing="0" align="left">'."\n".
  1303. ' <tr> '."\n" .
  1304. ' <td>'."\n" .
  1305. ' <div class="buttons">'."\n" .
  1306. ' <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('ScormMystatus').'"></a>&nbsp;'."\n" .
  1307. ' <a href="" onclick="dokeos_xajax_handler.switch_item('.$mycurrentitemid.',\'previous\');return false;" title="previous"><img border="0" src="../img/lp_leftarrow.gif" title="'.get_lang('ScormPrevious').'"></a>&nbsp;'."\n" .
  1308. ' <a href="" onclick="dokeos_xajax_handler.switch_item('.$mycurrentitemid.',\'next\');return false;" title="next" ><img border="0" src="../img/lp_rightarrow.gif" title="'.get_lang('ScormNext').'"></a>&nbsp;'."\n" .
  1309. ' <a href="lp_controller.php?action=mode&mode=embedded" target="_top" title="embedded mode"><img border="0" src="../img/view_choose.gif" title="'.get_lang('ScormExitFullScreen').'"></a>'."\n" .
  1310. //' <a href="lp_controller.php?action=list" target="_top" title="learnpaths list"><img border="0" src="../img/exit.png" title="Exit"></a>'."\n" .
  1311. ' </div>'."\n" .
  1312. ' </td>'."\n" .
  1313. ' </tr>'."\n" .
  1314. '</table>'."\n" ;
  1315. }else{
  1316. $navbar = '<table cellpadding="0" cellspacing="0" align="left">'."\n".
  1317. ' <tr> '."\n" .
  1318. ' <td>'."\n" .
  1319. ' <div class="buttons">'."\n" .
  1320. ' <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('ScormMystatus').'"></a>&nbsp;'."\n" .
  1321. ' <a href="" onclick="dokeos_xajax_handler.switch_item('.$mycurrentitemid.',\'previous\');return false;" title="previous"><img border="0" src="../img/lp_leftarrow.gif" title="'.get_lang('ScormPrevious').'"></a>&nbsp;'."\n" .
  1322. ' <a href="" onclick="dokeos_xajax_handler.switch_item('.$mycurrentitemid.',\'next\');return false;" title="next" ><img border="0" src="../img/lp_rightarrow.gif" title="'.get_lang('ScormNext').'"></a>&nbsp;'."\n" .
  1323. ' <a href="lp_controller.php?action=mode&mode=fullscreen" target="_top" title="fullscreen"><img border="0" src="../img/view_fullscreen.gif" width="18" height="18" title="'.get_lang('ScormFullScreen').'"></a>'."\n" .
  1324. ' </div>'."\n" .
  1325. ' </td>'."\n" .
  1326. ' </tr>'."\n" .
  1327. '</table>'."\n" ;
  1328. }
  1329. return $navbar;
  1330. }
  1331. /**
  1332. * Gets the next resource in queue (url).
  1333. * @return string URL to load into the viewer
  1334. */
  1335. function get_next_index()
  1336. {
  1337. if($this->debug>0){error_log('New LP - In learnpath::get_next_index()',0);}
  1338. //TODO
  1339. $index = $this->index;
  1340. $index ++;
  1341. if($this->debug>2){error_log('New LP - Now looking at ordered_items['.($index).'] - type is '.$this->items[$this->ordered_items[$index]]->type,0);}
  1342. 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)
  1343. {
  1344. $index ++;
  1345. if($index == $this->max_ordered_items)
  1346. {
  1347. return $this->index;
  1348. }
  1349. }
  1350. if(empty($this->ordered_items[$index])){
  1351. return $this->index;
  1352. }
  1353. if($this->debug>2){error_log('New LP - index is now '.$index,0);}
  1354. return $index;
  1355. }
  1356. /**
  1357. * Gets item_id for the next element
  1358. * @return integer Next item (DB) ID
  1359. */
  1360. function get_next_item_id()
  1361. {
  1362. if($this->debug>0){error_log('New LP - In learnpath::get_next_item_id()',0);}
  1363. $new_index = $this->get_next_index();
  1364. if(!empty($new_index))
  1365. {
  1366. if(isset($this->ordered_items[$new_index]))
  1367. {
  1368. if($this->debug>2){error_log('New LP - In learnpath::get_next_index() - Returning '.$this->ordered_items[$new_index],0);}
  1369. return $this->ordered_items[$new_index];
  1370. }
  1371. }
  1372. if($this->debug>2){error_log('New LP - In learnpath::get_next_index() - Problem - Returning 0',0);}
  1373. return 0;
  1374. }
  1375. /**
  1376. * Returns the package type ('scorm','aicc','scorm2004','dokeos','ppt'...)
  1377. *
  1378. * Generally, the package provided is in the form of a zip file, so the function
  1379. * has been written to test a zip file. If not a zip, the function will return the
  1380. * default return value: ''
  1381. * @param string the path to the file
  1382. * @param string the original name of the file
  1383. * @return string 'scorm','aicc','scorm2004','dokeos' or '' if the package cannot be recognized
  1384. */
  1385. function get_package_type($file_path,$file_name){
  1386. //get name of the zip file without the extension
  1387. $file_info = pathinfo($file_name);
  1388. $filename = $file_info['basename'];//name including extension
  1389. $extension = $file_info['extension'];//extension only
  1390. if(!empty($_POST['ppt2lp']) && !in_array($extension,array('dll','exe')))
  1391. {
  1392. return 'oogie';
  1393. }
  1394. if(!empty($_POST['woogie']) && !in_array($extension,array('dll','exe')))
  1395. {
  1396. return 'woogie';
  1397. }
  1398. $file_base_name = str_replace('.'.$extension,'',$filename); //filename without its extension
  1399. $zipFile = new pclZip($file_path);
  1400. // Check the zip content (real size and file extension)
  1401. $zipContentArray = $zipFile->listContent();
  1402. $package_type='';
  1403. $at_root = false;
  1404. $manifest = '';
  1405. //the following loop should be stopped as soon as we found the right imsmanifest.xml (how to recognize it?)
  1406. foreach($zipContentArray as $thisContent)
  1407. {
  1408. if ( preg_match('~.(php.*|phtml)$~i', $thisContent['filename']) )
  1409. {
  1410. //New behaviour: Don't do anything. These files will be removed in scorm::import_package
  1411. }
  1412. elseif(stristr($thisContent['filename'],'imsmanifest.xml')!==FALSE)
  1413. {
  1414. $manifest = $thisContent['filename']; //just the relative directory inside scorm/
  1415. $package_type = 'scorm';
  1416. break;//exit the foreach loop
  1417. }
  1418. elseif(preg_match('/aicc\//i',$thisContent['filename'])!=false)
  1419. {//if found an aicc directory... (!= false means it cannot be false (error) or 0 (no match))
  1420. $package_type='aicc';
  1421. //break;//don't exit the loop, because if we find an imsmanifest afterwards, we want it, not the AICC
  1422. }
  1423. else
  1424. {
  1425. $package_type = '';
  1426. }
  1427. }
  1428. return $package_type;
  1429. }
  1430. /**
  1431. * Gets the previous resource in queue (url). Also initialises time values for this viewing
  1432. * @return string URL to load into the viewer
  1433. */
  1434. function get_previous_index()
  1435. {
  1436. if($this->debug>0){error_log('New LP - In learnpath::get_previous_index()',0);}
  1437. $index = $this->index;
  1438. if(isset($this->ordered_items[$index-1])){
  1439. $index --;
  1440. 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'))
  1441. {
  1442. $index --;
  1443. if($index < 0){
  1444. return $this->index;
  1445. }
  1446. }
  1447. }else{
  1448. if($this->debug>2){error_log('New LP - get_previous_index() - there was no previous index available, reusing '.$index,0);}
  1449. //no previous item
  1450. }
  1451. return $index;
  1452. }
  1453. /**
  1454. * Gets item_id for the next element
  1455. * @return integer Previous item (DB) ID
  1456. */
  1457. function get_previous_item_id()
  1458. {
  1459. $new_index = $this->get_previous_index();
  1460. return $this->ordered_items[$new_index];
  1461. }
  1462. /**
  1463. * Gets the progress value from the progress_db attribute
  1464. * @return integer Current progress value
  1465. */
  1466. function get_progress()
  1467. {
  1468. if($this->debug>0){error_log('New LP - In learnpath::get_progress()',0);}
  1469. if(!empty($this->progress_db))
  1470. {
  1471. return $this->progress_db;
  1472. }
  1473. return 0;
  1474. }
  1475. /**
  1476. * Gets the progress value from the progress field in the database (allows use as abstract method)
  1477. * @param integer Learnpath ID
  1478. * @param integer User ID
  1479. * @param string Mode of display ('%','abs' or 'both')
  1480. * @param string Course database name (optional, defaults to '')
  1481. * @param boolean Whether to return null if no record was found (true), or 0 (false) (optional, defaults to false)
  1482. * @return integer Current progress value as found in the database
  1483. */
  1484. function get_db_progress($lp_id,$user_id,$mode='%', $course_db='', $sincere=false)
  1485. {
  1486. //if($this->debug>0){error_log('New LP - In learnpath::get_db_progress()',0);}
  1487. $table = Database::get_course_table('lp_view', $course_db);
  1488. $sql = "SELECT * FROM $table WHERE lp_id = $lp_id AND user_id = $user_id";
  1489. $res = api_sql_query($sql,__FILE__,__LINE__);
  1490. $view_id = 0;
  1491. if(Database::num_rows($res)>0)
  1492. {
  1493. $row = Database::fetch_array($res);
  1494. $progress = $row['progress'];
  1495. $view_id = $row['id'];
  1496. }
  1497. else
  1498. {
  1499. if($sincere)
  1500. {
  1501. return null;
  1502. }
  1503. }
  1504. if(!$progress)
  1505. {
  1506. $progress = '0';
  1507. }
  1508. if($mode == '%')
  1509. {
  1510. return $progress.'%';
  1511. }
  1512. else
  1513. {
  1514. //get the number of items completed and the number of items total
  1515. $tbl = Database::get_course_table('lp_item', $course_db);
  1516. $sql = "SELECT count(*) FROM $tbl WHERE lp_id = ".$lp_id."
  1517. AND item_type NOT IN('dokeos_chapter','chapter','dir')";
  1518. $res = api_sql_query($sql, __FILE__, __LINE__);
  1519. $row = Database::fetch_array($res);
  1520. $total = $row[0];
  1521. $tbl_item_view = Database::get_course_table('lp_item_view', $course_db);
  1522. $tbl_item = Database::get_course_table('lp_item', $course_db);
  1523. //$sql = "SELECT count(distinct(lp_item_id)) FROM $tbl WHERE lp_view_id = ".$view_id." AND status IN ('passed','completed','succeeded')";
  1524. //trying as also counting browsed and failed items
  1525. $sql = "SELECT count(distinct(lp_item_id))
  1526. FROM $tbl_item_view as item_view
  1527. INNER JOIN $tbl_item as item
  1528. ON item.id = item_view.lp_item_id
  1529. AND item_type NOT IN('dokeos_chapter','chapter','dir')
  1530. WHERE lp_view_id = ".$view_id."
  1531. AND status IN ('passed','completed','succeeded','browsed','failed')";
  1532. $res = api_sql_query($sql, __FILE__, __LINE__);
  1533. $row = Database::fetch_array($res);
  1534. $completed = $row[0];
  1535. if($mode == 'abs')
  1536. {
  1537. return $completed.'/'.$total;
  1538. }
  1539. elseif($mode == 'both')
  1540. {
  1541. if($progress<($completed/($total?$total:1)))
  1542. {
  1543. $progress = number_format(($completed/($total?$total:1))*100,0);
  1544. }
  1545. return $progress.'% ('.$completed.'/'.$total.')';
  1546. }
  1547. }
  1548. return $progress;
  1549. }
  1550. /**
  1551. * Gets a progress bar for the learnpath by counting the number of items in it and the number of items
  1552. * completed so far.
  1553. * @param string Mode in which we want the values
  1554. * @param integer Progress value to display (optional but mandatory if used in abstract context)
  1555. * @param string Text to display near the progress value (optional but mandatory in abstract context)
  1556. * @return string HTML string containing the progress bar
  1557. */
  1558. function get_progress_bar($mode='',$percentage=-1,$text_add='')
  1559. {
  1560. global $lp_theme_css;
  1561. // Setting up the CSS path of the current style if exists
  1562. if (!empty($lp_theme_css))
  1563. {
  1564. $css_path=api_get_path(WEB_CODE_PATH).'css/'.$lp_theme_css.'/images/';
  1565. }
  1566. else
  1567. {
  1568. $css_path='../img/';
  1569. }
  1570. //if($this->debug>0){error_log('New LP - In learnpath::get_progress_bar()',0);}
  1571. if(is_object($this) && ($percentage=='-1' OR $text_add==''))
  1572. {
  1573. list ($percentage, $text_add) = $this->get_progress_bar_text($mode);
  1574. }
  1575. $text = $percentage.$text_add;
  1576. $size = str_replace('%','',$percentage);
  1577. $output = ''
  1578. //.htmlentities(get_lang('ScormCompstatus'),ENT_QUOTES,'ISO-8859-1')."<br />"
  1579. .'<table border="0" cellpadding="0" cellspacing="0"><tr><td>'
  1580. .'<img id="progress_img_limit_left" src="'.$css_path.'bar_1.gif" width="1" height="12">'
  1581. .'<img id="progress_img_full" src="'.$css_path.'bar_1u.gif" width="'.$size.'px" height="12" id="full_portion">'
  1582. .'<img id="progress_img_limit_middle" src="'.$css_path.'bar_1m.gif" width="1" height="12">';
  1583. if($percentage <= 98)
  1584. {
  1585. $output .= '<img id="progress_img_empty" src="'.$css_path.'bar_1r.gif" width="'.(100-$size).'px" height="12" id="empty_portion">';
  1586. }
  1587. else
  1588. {
  1589. $output .= '<img id="progress_img_empty" src="'.$css_path.'bar_1r.gif" width="0" height="12" id="empty_portion">';
  1590. }
  1591. $output .= '<img id="progress_bar_img_limit_right" src="'.$css_path.'bar_1.gif" width="1" height="12"></td></tr></table>'
  1592. .'<div class="progresstext" id="progress_text">'.$text.'</div>';
  1593. return $output;
  1594. }
  1595. /**
  1596. * Gets the progress bar info to display inside the progress bar. Also used by scorm_api.php
  1597. * @param string Mode of display (can be '%' or 'abs').abs means we display a number of completed elements per total elements
  1598. * //@param integer Additional steps to fake as completed
  1599. * @return list Percentage or number and symbol (% or /xx)
  1600. */
  1601. function get_progress_bar_text($mode='',$add=0)
  1602. {
  1603. if($this->debug>0){error_log('New LP - In learnpath::get_progress_bar_text()',0);}
  1604. if(empty($mode)){$mode = $this->progress_bar_mode;}
  1605. $total_items = $this->get_total_items_count_without_chapters();
  1606. if($this->debug>2){error_log('New LP - Total items available in this learnpath: '.$total_items,0);}
  1607. $i = $this->get_complete_items_count();
  1608. if($this->debug>2){error_log('New LP - Items completed so far: '.$i,0);}
  1609. if($add != 0){
  1610. $i += $add;
  1611. if($this->debug>2){error_log('New LP - Items completed so far (+modifier): '.$i,0);}
  1612. }
  1613. $text = '';
  1614. if($i>$total_items){
  1615. $i = $total_items;
  1616. }
  1617. if($mode == '%'){
  1618. if($total_items>0){
  1619. $percentage = ((float)$i/(float)$total_items)*100;
  1620. }
  1621. else
  1622. {
  1623. $percentage = 0;
  1624. }
  1625. $percentage = number_format($percentage,0);
  1626. $text = '%';
  1627. }elseif($mode == 'abs'){
  1628. $percentage = $i;
  1629. $text = '/'.$total_items;
  1630. }
  1631. return array($percentage,$text);
  1632. }
  1633. /**
  1634. * Gets the progress bar mode
  1635. * @return string The progress bar mode attribute
  1636. */
  1637. function get_progress_bar_mode()
  1638. {
  1639. if($this->debug>0){error_log('New LP - In learnpath::get_progress_bar_mode()',0);}
  1640. if(!empty($this->progress_bar_mode))
  1641. {
  1642. return $this->progress_bar_mode;
  1643. }else{
  1644. return '%';
  1645. }
  1646. }
  1647. /**
  1648. * Gets the learnpath proximity (remote or local)
  1649. * @return string Learnpath proximity
  1650. */
  1651. function get_proximity()
  1652. {
  1653. if($this->debug>0){error_log('New LP - In learnpath::get_proximity()',0);}
  1654. if(!empty($this->proximity)){return $this->proximity;}else{return '';}
  1655. }
  1656. /**
  1657. * Gets the learnpath theme (remote or local)
  1658. * @return string Learnpath theme
  1659. */
  1660. function get_theme()
  1661. {
  1662. if($this->debug>0){error_log('New LP - In learnpath::get_theme()',0);}
  1663. if(!empty($this->theme)){return $this->theme;}else{return '';}
  1664. }
  1665. /**
  1666. * Generate a new prerequisites string for a given item. If this item was a sco and
  1667. * its prerequisites were strings (instead of IDs), then transform those strings into
  1668. * IDs, knowing that SCORM IDs are kept in the "ref" field of the lp_item table.
  1669. * Prefix all item IDs that end-up in the prerequisites string by "ITEM_" to use the
  1670. * same rule as the scorm_export() method
  1671. * @param integer Item ID
  1672. * @return string Prerequisites string ready for the export as SCORM
  1673. */
  1674. function get_scorm_prereq_string($item_id)
  1675. {
  1676. if($this->debug>0){error_log('New LP - In learnpath::get_scorm_prereq_string()',0);}
  1677. if(!is_object($this->items[$item_id])){return false;}
  1678. $oItem = $this->items[$item_id];
  1679. $prereq = $oItem->get_prereq_string();
  1680. if(empty($prereq))
  1681. {
  1682. return '';
  1683. }
  1684. if(preg_match('/^\d+$/',$prereq) && is_object($this->items[$prereq]))
  1685. { //if the prerequisite is a simple integer ID and this ID exists as an item ID,
  1686. //then simply return it (with the ITEM_ prefix)
  1687. return 'ITEM_'.$prereq;
  1688. }
  1689. else
  1690. {
  1691. if(isset($this->refs_list[$prereq]))
  1692. {
  1693. //it's a simple string item from which the ID can be found in the refs list
  1694. //so we can transform it directly to an ID for export
  1695. return 'ITEM_'.$this->refs_list[$prereq];
  1696. }
  1697. else
  1698. {
  1699. //last case, if it's a complex form, then find all the IDs (SCORM strings)
  1700. //and replace them, one by one, by the internal IDs (dokeos db)
  1701. //TODO modify the '*' replacement to replace the multiplier in front of it
  1702. //by a space as well
  1703. $find = array('&','|','~','=','<>','{','}','*','(',')');
  1704. $replace = array(' ',' ',' ',' ',' ',' ',' ',' ',' ',' ');
  1705. $prereq_mod = str_replace($find,$replace,$prereq);
  1706. $ids = split(' ',$prereq_mod);
  1707. foreach($ids as $id)
  1708. {
  1709. $id = trim($id);
  1710. if(isset($this->refs_list[$id]))
  1711. {
  1712. $prereq = preg_replace('/[^a-zA-Z_0-9]('.$id.')[^a-zA-Z_0-9]/','ITEM_'.$this->refs_list[$id],$prereq);
  1713. }
  1714. }
  1715. error_log('New LP - In learnpath::get_scorm_prereq_string(): returning modified string: '.$prereq,0);
  1716. return $prereq;
  1717. }
  1718. }
  1719. }
  1720. /**
  1721. * Returns the XML DOM document's node
  1722. * @param resource Reference to a list of objects to search for the given ITEM_*
  1723. * @param string The identifier to look for
  1724. * @return mixed The reference to the element found with that identifier. False if not found
  1725. */
  1726. function get_scorm_xml_node(&$children,$id)
  1727. {
  1728. for($i=0;$i<$children->length;$i++){
  1729. $item_temp = $children->item($i);
  1730. if ($item_temp -> nodeName == 'item')
  1731. {
  1732. if($item_temp->getAttribute('identifier') == $id)
  1733. {
  1734. return $item_temp;
  1735. }
  1736. }
  1737. $subchildren = $item_temp->childNodes;
  1738. if($subchildren->length>0)
  1739. {
  1740. $val = $this->get_scorm_xml_node($subchildren,$id);
  1741. if(is_object($val))
  1742. {
  1743. return $val;
  1744. }
  1745. }
  1746. }
  1747. return false;
  1748. }
  1749. /**
  1750. * Returns a usable array of stats related to the current learnpath and user
  1751. * @return array Well-formatted array containing status for the current learnpath
  1752. */
  1753. function get_stats()
  1754. {
  1755. if($this->debug>0){error_log('New LP - In learnpath::get_stats()',0);}
  1756. //TODO
  1757. }
  1758. /**
  1759. * Static method. Can be re-implemented by children. Gives an array of statistics for
  1760. * the given course (for all learnpaths and all users)
  1761. * @param string Course code
  1762. * @return array Well-formatted array containing status for the course's learnpaths
  1763. */
  1764. function get_stats_course($course)
  1765. {
  1766. //if($this->debug>0){error_log('New LP - In learnpath::get_stats_course()',0);}
  1767. //TODO
  1768. }
  1769. /**
  1770. * Static method. Can be re-implemented by children. Gives an array of statistics for
  1771. * the given course and learnpath (for all users)
  1772. * @param string Course code
  1773. * @param integer Learnpath ID
  1774. * @return array Well-formatted array containing status for the specified learnpath
  1775. */
  1776. function get_stats_lp($course,$lp)
  1777. {
  1778. //if($this->debug>0){error_log('New LP - In learnpath::get_stats_lp()',0);}
  1779. //TODO
  1780. }
  1781. /**
  1782. * Static method. Can be re-implemented by children. Gives an array of statistics for
  1783. * the given course, learnpath and user.
  1784. * @param string Course code
  1785. * @param integer Learnpath ID
  1786. * @param integer User ID
  1787. * @return array Well-formatted array containing status for the specified learnpath and user
  1788. */
  1789. function get_stats_lp_user($course,$lp,$user)
  1790. {
  1791. //if($this->debug>0){error_log('New LP - In learnpath::get_stats_lp_user()',0);}
  1792. //TODO
  1793. }
  1794. /**
  1795. * Static method. Can be re-implemented by children. Gives an array of statistics for
  1796. * the given course and learnpath (for all users)
  1797. * @param string Course code
  1798. * @param integer User ID
  1799. * @return array Well-formatted array containing status for the user's learnpaths
  1800. */
  1801. function get_stats_user($course,$user)
  1802. {
  1803. //if($this->debug>0){error_log('New LP - In learnpath::get_stats_user()',0);}
  1804. //TODO
  1805. }
  1806. /**
  1807. * Gets the status list for all LP's items
  1808. * @return array Array of [index] => [item ID => current status]
  1809. */
  1810. function get_items_status_list(){
  1811. if($this->debug>0){error_log('New LP - In learnpath::get_items_status_list()',0);}
  1812. $list = array();
  1813. foreach($this->ordered_items as $item_id)
  1814. {
  1815. $list[]= array($item_id => $this->items[$item_id]->get_status());
  1816. }
  1817. return $list;
  1818. }
  1819. /**
  1820. * Return the number of interactions for the given learnpath Item View ID.
  1821. * This method can be used as static.
  1822. * @param integer Item View ID
  1823. * @return integer Number of interactions
  1824. */
  1825. function get_interactions_count_from_db($lp_iv_id=0){
  1826. if(empty($lp_iv_id)){return -1;}
  1827. $table = Database::get_course_table('lp_iv_interaction');
  1828. $sql = "SELECT count(*) FROM $table WHERE lp_iv_id = $lp_iv_id";
  1829. $res = api_sql_query($sql,__FILE__,__LINE__);
  1830. $row = Database::fetch_array($res);
  1831. $num = $row[0];
  1832. return $num;
  1833. }
  1834. /**
  1835. * Return the interactions as an array for the given lp_iv_id.
  1836. * This method can be used as static.
  1837. * @param integer Learnpath Item View ID
  1838. * @return array
  1839. * @todo Translate labels
  1840. */
  1841. function get_iv_interactions_array($lp_iv_id=0){
  1842. $list = array();
  1843. $table = Database::get_course_table('lp_iv_interaction');
  1844. $sql = "SELECT * FROM $table WHERE lp_iv_id = $lp_iv_id ORDER BY order_id ASC";
  1845. $res = api_sql_query($sql,__FILE__,__LINE__);
  1846. $num = Database::num_rows($res);
  1847. if($num>0){
  1848. $list[] = array(
  1849. "order_id"=>htmlentities(get_lang('Order')),
  1850. "id"=>htmlentities(get_lang('InteractionID')),
  1851. "type"=>htmlentities(get_lang('Type')),
  1852. "time"=>htmlentities(get_lang('TimeFinished')),
  1853. "correct_responses"=>htmlentities(get_lang('CorrectAnswers')),
  1854. "student_response"=>htmlentities(get_lang('StudentResponse')),
  1855. "result"=>htmlentities(get_lang('Result')),
  1856. "latency"=>htmlentities(get_lang('LatencyTimeSpent')));
  1857. while ($row = Database::fetch_array($res)){
  1858. $list[] = array(
  1859. "order_id"=>($row['order_id']+1),
  1860. "id"=>urldecode($row['interaction_id']),//urldecode because they often have %2F or stuff like that
  1861. "type"=>$row['interaction_type'],
  1862. "time"=>$row['completion_time'],
  1863. //"correct_responses"=>$row['correct_responses'],
  1864. //hide correct responses from students
  1865. "correct_responses"=>'',
  1866. "student_response"=>$row['student_response'],
  1867. "result"=>$row['result'],
  1868. "latency"=>$row['latency']);
  1869. }
  1870. }
  1871. return $list;
  1872. }
  1873. /**
  1874. * Return the number of objectives for the given learnpath Item View ID.
  1875. * This method can be used as static.
  1876. * @param integer Item View ID
  1877. * @return integer Number of objectives
  1878. */
  1879. function get_objectives_count_from_db($lp_iv_id=0){
  1880. if(empty($lp_iv_id)){return -1;}
  1881. $table = Database::get_course_table('lp_iv_objective');
  1882. $sql = "SELECT count(*) FROM $table WHERE lp_iv_id = $lp_iv_id";
  1883. $res = api_sql_query($sql,__FILE__,__LINE__);
  1884. $row = Database::fetch_array($res);
  1885. $num = $row[0];
  1886. return $num;
  1887. }
  1888. /**
  1889. * Return the objectives as an array for the given lp_iv_id.
  1890. * This method can be used as static.
  1891. * @param integer Learnpath Item View ID
  1892. * @return array
  1893. * @todo Translate labels
  1894. */
  1895. function get_iv_objectives_array($lp_iv_id=0){
  1896. $list = array();
  1897. $table = Database::get_course_table('lp_iv_objective');
  1898. $sql = "SELECT * FROM $table WHERE lp_iv_id = $lp_iv_id ORDER BY order_id ASC";
  1899. $res = api_sql_query($sql,__FILE__,__LINE__);
  1900. $num = Database::num_rows($res);
  1901. if($num>0){
  1902. $list[] = array(
  1903. "order_id"=>htmlentities(get_lang('Order')),
  1904. "objective_id"=>htmlentities(get_lang('ObjectiveID')),
  1905. "score_raw"=>htmlentities(get_lang('ObjectiveRawScore')),
  1906. "score_max"=>htmlentities(get_lang('ObjectiveMaxScore')),
  1907. "score_min"=>htmlentities(get_lang('ObjectiveMinScore')),
  1908. "status"=>htmlentities(get_lang('ObjectiveStatus')));
  1909. while ($row = Database::fetch_array($res)){
  1910. $list[] = array(
  1911. "order_id"=>($row['order_id']+1),
  1912. "objective_id"=>urldecode($row['objective_id']),//urldecode because they often have %2F or stuff like that
  1913. "score_raw"=>$row['score_raw'],
  1914. "score_max"=>$row['score_max'],
  1915. "score_min"=>$row['score_min'],
  1916. "status"=>$row['status']);
  1917. }
  1918. }
  1919. return $list;
  1920. }
  1921. /**
  1922. * Generate and return the table of contents for this learnpath. The (flat) table returned can be
  1923. * used by get_html_toc() to be ready to display
  1924. * @return array TOC as a table with 4 elements per row: title, link, status and level
  1925. */
  1926. function get_toc()
  1927. {
  1928. if($this->debug>0){error_log('New LP - In learnpath::get_toc()',0);}
  1929. $toc = array();
  1930. //echo "<pre>".print_r($this->items,true)."</pre>";
  1931. foreach($this->ordered_items as $item_id)
  1932. {
  1933. if($this->debug>2){error_log('New LP - learnpath::get_toc(): getting info for item '.$item_id,0);}
  1934. //TODO change this link generation and use new function instead
  1935. $toc[] = array(
  1936. 'id'=>$item_id,
  1937. 'title'=>$this->items[$item_id]->get_title(),
  1938. //'link'=>get_addedresource_link_in_learnpath('document',$item_id,1),
  1939. 'status'=>$this->items[$item_id]->get_status(),
  1940. 'level'=>$this->items[$item_id]->get_level(),
  1941. 'type' =>$this->items[$item_id]->get_type(),
  1942. 'description'=>$this->items[$item_id]->get_description(),
  1943. );
  1944. }
  1945. if($this->debug>2){error_log('New LP - In learnpath::get_toc() - TOC array: '.print_r($toc,true),0);}
  1946. return $toc;
  1947. }
  1948. /**
  1949. * Gets the learning path type
  1950. * @param boolean Return the name? If false, return the ID. Default is false.
  1951. * @return mixed Type ID or name, depending on the parameter
  1952. */
  1953. function get_type($get_name = false)
  1954. {
  1955. $res = false;
  1956. if($this->debug>0){error_log('New LP - In learnpath::get_type()',0);}
  1957. if(!empty($this->type))
  1958. {
  1959. if($get_name)
  1960. {
  1961. //get it from the lp_type table in main db
  1962. }else{
  1963. $res = $this->type;
  1964. }
  1965. }
  1966. if($this->debug>2){error_log('New LP - In learnpath::get_type() - Returning '.($res==false?'false':$res),0);}
  1967. return $res;
  1968. }
  1969. /**
  1970. * Gets the learning path type as static method
  1971. * @param boolean Return the name? If false, return the ID. Default is false.
  1972. * @return mixed Type ID or name, depending on the parameter
  1973. */
  1974. function get_type_static($lp_id=0)
  1975. {
  1976. $tbl_lp = Database::get_course_table('lp');
  1977. $sql = "SELECT lp_type FROM $tbl_lp WHERE id = '".$lp_id."'";
  1978. $res = api_sql_query($sql, __FILE__, __LINE__);
  1979. if($res===false){ return null;}
  1980. if(Database::num_rows($res)<=0){return null;}
  1981. $row = Database::fetch_array($res);
  1982. return $row['lp_type'];
  1983. }
  1984. /**
  1985. * Gets a flat list of item IDs ordered for display (level by level ordered by order_display)
  1986. * This method can be used as abstract and is recursive
  1987. * @param integer Learnpath ID
  1988. * @param integer Parent ID of the items to look for
  1989. * @return mixed Ordered list of item IDs or false on error
  1990. */
  1991. function get_flat_ordered_items_list($lp,$parent=0){
  1992. //if($this->debug>0){error_log('New LP - In learnpath::get_flat_ordered_items_list('.$lp.','.$parent.')',0);}
  1993. $list = array();
  1994. if(empty($lp)){return false;}
  1995. $tbl_lp_item = Database::get_course_table('lp_item');
  1996. $sql = "SELECT * FROM $tbl_lp_item WHERE lp_id = $lp AND parent_item_id = $parent ORDER BY display_order";
  1997. $res = api_sql_query($sql,__FILE__,__LINE__);
  1998. while($row = Database::fetch_array($res)){
  1999. $sublist = learnpath::get_flat_ordered_items_list($lp,$row['id']);
  2000. $list[] = $row['id'];
  2001. foreach($sublist as $item){
  2002. $list[] = $item;
  2003. }
  2004. }
  2005. return $list;
  2006. }
  2007. /**
  2008. * Uses the table generated by get_toc() and returns an HTML-formatted string ready to display
  2009. * @return string HTML TOC ready to display
  2010. */
  2011. /*function get_html_toc()
  2012. {
  2013. if($this->debug>0){error_log('New LP - In learnpath::get_html_toc()',0);}
  2014. $list = $this->get_toc();
  2015. //echo $this->current;
  2016. //$parent = $this->items[$this->current]->get_parent();
  2017. //if(empty($parent)){$parent = $this->ordered_items[$this->items[$this->current]->get_previous_index()];}
  2018. $html = '<div class="inner_lp_toc">'."\n" ;
  2019. // " onchange=\"javascript:document.getElementById('toc_$parent').focus();\">\n";
  2020. require_once('resourcelinker.inc.php');
  2021. //temp variables
  2022. $mycurrentitemid = $this->get_current_item_id();
  2023. foreach($list as $item)
  2024. {
  2025. if($this->debug>2){error_log('New LP - learnpath::get_html_toc(): using item '.$item['id'],0);}
  2026. //TODO complete this
  2027. $icon_name = array('not attempted' => 'notattempted.png',
  2028. 'incomplete' => 'incomplete.png',
  2029. 'failed' => 'failed.png',
  2030. 'completed' => 'completed.png',
  2031. 'passed' => 'passed.png',
  2032. 'succeeded' => 'succeeded.png',
  2033. 'browsed' => 'completed.png');
  2034. $style = 'scorm_item';
  2035. if($item['id'] == $this->current){
  2036. $style = 'scorm_item_highlight';
  2037. }
  2038. //the anchor will let us center the TOC on the currently viewed item &^D
  2039. $html .= '<a name="atoc_'.$item['id'].'" /><div class="'.$style.'" style="padding-left: '.($item['level']/2).'em; padding-right:'.($item['level']/2).'em" id="toc_'.$item['id'].'" >' .
  2040. '<img id="toc_img_'.$item['id'].'" class="scorm_status_img" src="'.$icon_name[$item['status']].'" alt="'.substr($item['status'],0,1).'" />';
  2041. //$title = htmlspecialchars($item['title'],ENT_QUOTES,$this->encoding);
  2042. $title = $item['title'];
  2043. if(empty($title)){
  2044. $title = rl_get_resource_name(api_get_course_id(),$this->get_id(),$item['id']);
  2045. $title = htmlspecialchars($title,ENT_QUOTES,$this->encoding);
  2046. }
  2047. if(empty($title))$title = '-';
  2048. if($item['type']!='dokeos_chapter' and $item['type']!='dir'){
  2049. //$html .= "<a href='lp_controller.php?".api_get_cidReq()."&action=content&lp_id=".$this->get_id()."&item_id=".$item['id']."' target='lp_content_frame_name'>".$title."</a>" ;
  2050. $url = $this->get_link('http',$item['id']);
  2051. //$html .= '<a href="'.$url.'" target="content_name" onclick="top.load_item('.$item['id'].',\''.$url.'\');">'.$title.'</a>' ;
  2052. //$html .= '<a href="" onclick="top.load_item('.$item['id'].',\''.$url.'\');return false;">'.$title.'</a>' ;
  2053. $html .= '<a href="" onclick="dokeos_xajax_handler.switch_item(' .
  2054. $mycurrentitemid.',' .
  2055. $item['id'].');' .
  2056. 'return false;" >'.$title.'</a>' ;
  2057. }else{
  2058. $html .= $title;
  2059. }
  2060. $html .= "</div>\n";
  2061. }
  2062. $html .= "</div>\n";
  2063. return $html;
  2064. }*/
  2065. /**
  2066. * Uses the table generated by get_toc() and returns an HTML-formatted string ready to display
  2067. * @return string HTML TOC ready to display
  2068. */
  2069. function get_html_toc()
  2070. {
  2071. if($this->debug>0){error_log('New LP - In learnpath::get_html_toc()',0);}
  2072. $list = $this->get_toc();
  2073. //echo $this->current;
  2074. //$parent = $this->items[$this->current]->get_parent();
  2075. //if(empty($parent)){$parent = $this->ordered_items[$this->items[$this->current]->get_previous_index()];}
  2076. $html .= '<div class="inner_lp_toc">'."\n" ;
  2077. if(api_is_allowed_to_edit()){
  2078. $mych = api_get_setting('platform_charset');
  2079. $html.="<p>&nbsp;&nbsp;&nbsp;&nbsp;<a target='_parent' href='lp_controller.php?".api_get_cidreq()."&action=build&lp_id=".$this->lp_id."' style= target='_parent'>".mb_convert_encoding(get_lang("Build"),$this->encoding,$mych)."</a>&nbsp;&#124;&nbsp;<a href='lp_controller.php?".api_get_cidreq()."&action=admin_view&lp_id=".$this->lp_id."' target='_parent'>".mb_convert_encoding(get_lang("BasicOverview"),$this->encoding,$mych)."</a>&nbsp;&#124;&nbsp;".mb_convert_encoding(get_lang("Display"),$this->encoding,$mych)."</p>";
  2080. unset($mych);
  2081. }
  2082. // " onchange=\"javascript:document.getElementById('toc_$parent').focus();\">\n";
  2083. require_once('resourcelinker.inc.php');
  2084. //temp variables
  2085. $mycurrentitemid = $this->get_current_item_id();
  2086. foreach($list as $item)
  2087. {
  2088. if($this->debug>2){error_log('New LP - learnpath::get_html_toc(): using item '.$item['id'],0);}
  2089. //TODO complete this
  2090. $icon_name = array('not attempted' => 'notattempted.png',
  2091. 'incomplete' => 'incomplete.png',
  2092. 'failed' => 'failed.png',
  2093. 'completed' => 'completed.png',
  2094. 'passed' => 'passed.png',
  2095. 'succeeded' => 'succeeded.png',
  2096. 'browsed' => 'completed.png');
  2097. $style = 'scorm_item';
  2098. if($item['id'] == $this->current)
  2099. {
  2100. $style = 'scorm_item_highlight';
  2101. }
  2102. //the anchor will let us center the TOC on the currently viewed item &^D
  2103. if($item['type']!='dokeos_module' AND $item['type']!='dokeos_chapter'){
  2104. $html .= '<a name="atoc_'.$item['id'].'" /><div class="'.$style.'" style="padding-left: '.($item['level']*1.5).'em; padding-right:'.($item['level']/2).'em" id="toc_'.$item['id'].'" title="'.$item['description'].'" >' .
  2105. '';
  2106. }
  2107. else{
  2108. $html .= '<div class="'.$style.'" style="padding-left: '.($item['level']*2).'em; padding-right:'.($item['level']*1.5).'em" id="toc_'.$item['id'].'" title="'.$item['description'].'" >' .
  2109. '';
  2110. }
  2111. $title=$item['title'];
  2112. if(empty($title))
  2113. {
  2114. $title = rl_get_resource_name(api_get_course_id(),$this->get_id(),$item['id']);
  2115. }
  2116. $title = html_entity_decode($title,ENT_QUOTES,$this->encoding);
  2117. if($item['type']!='dokeos_chapter' and $item['type']!='dir' AND $item['type']!='dokeos_module')
  2118. {
  2119. //$html .= "<a href='lp_controller.php?".api_get_cidreq()."&action=content&lp_id=".$this->get_id()."&item_id=".$item['id']."' target='lp_content_frame_name'>".$title."</a>" ;
  2120. $url = $this->get_link('http',$item['id']);
  2121. //$html .= '<a href="'.$url.'" target="content_name" onclick="top.load_item('.$item['id'].',\''.$url.'\');">'.$title.'</a>' ;
  2122. //$html .= '<a href="" onclick="top.load_item('.$item['id'].',\''.$url.'\');return false;">'.$title.'</a>' ;
  2123. //<img align="absbottom" width="13" height="13" src="../img/lp_document.png">&nbsp;
  2124. $html .= '<a href="" onclick="dokeos_xajax_handler.switch_item(' .
  2125. $mycurrentitemid.',' .
  2126. $item['id'].');' .
  2127. 'return false;" >'.stripslashes($title).'</a>' ;
  2128. }
  2129. elseif($item['type']=='dokeos_module' || $item['type']=='dokeos_chapter')
  2130. {
  2131. $html .= "<img align='absbottom' width='13' height='13' src='../img/lp_dokeos_module.png'>&nbsp;".stripslashes($title);
  2132. }
  2133. elseif($item['type']=='dir')
  2134. {
  2135. $html .= stripslashes($title);
  2136. }
  2137. $html .= "<img id='toc_img_".$item['id']."' src='".$icon_name[$item['status']]."' alt='".substr($item['status'],0,1)."' /></div>\n";
  2138. }
  2139. $html .= "</div>\n";
  2140. return $html;
  2141. }
  2142. /**
  2143. * Gets the learnpath maker name - generally the editor's name
  2144. * @return string Learnpath maker name
  2145. */
  2146. function get_maker()
  2147. {
  2148. if($this->debug>0){error_log('New LP - In learnpath::get_maker()',0);}
  2149. if(!empty($this->maker)){return $this->maker;}else{return '';}
  2150. }
  2151. /**
  2152. * Gets the user-friendly message stored in $this->message
  2153. * @return string Message
  2154. */
  2155. function get_message(){
  2156. if($this->debug>0){error_log('New LP - In learnpath::get_message()',0);}
  2157. return $this->message;
  2158. }
  2159. /**
  2160. * Gets the learnpath name/title
  2161. * @return string Learnpath name/title
  2162. */
  2163. function get_name()
  2164. {
  2165. if($this->debug>0){error_log('New LP - In learnpath::get_name()',0);}
  2166. if(!empty($this->name)){return $this->name;}else{return 'N/A';}
  2167. }
  2168. /**
  2169. * Gets a link to the resource from the present location, depending on item ID.
  2170. * @param string Type of link expected
  2171. * @param integer Learnpath item ID
  2172. * @return string Link to the lp_item resource
  2173. */
  2174. function get_link($type='http',$item_id=null)
  2175. {
  2176. if($this->debug>0){error_log('New LP - In learnpath::get_link('.$type.','.$item_id.')',0);}
  2177. if(empty($item_id))
  2178. {
  2179. 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);}
  2180. $item_id = $this->get_current_item_id();
  2181. }
  2182. if(empty($item_id)){
  2183. if($this->debug>2){error_log('New LP - In learnpath::get_link() - no current item id found in learnpath object',0);}
  2184. //still empty, this means there was no item_id given and we are not in an object context or
  2185. //the object property is empty, return empty link
  2186. $item_id = $this->first();
  2187. return '';
  2188. }
  2189. $file = '';
  2190. $lp_table = Database::get_course_table(TABLE_LP_MAIN);
  2191. $lp_item_table = Database::get_course_table(TABLE_LP_ITEM);
  2192. $sel = "SELECT l.lp_type as ltype, l.path as lpath, li.item_type as litype, li.path as lipath, li.parameters as liparams " .
  2193. "FROM $lp_table l, $lp_item_table li WHERE li.id = $item_id AND li.lp_id = l.id";
  2194. if($this->debug>2){error_log('New LP - In learnpath::get_link() - selecting item '.$sel,0);}
  2195. $res = api_sql_query($sel, __FILE__, __LINE__);
  2196. if(Database::num_rows($res)>0)
  2197. {
  2198. $row = Database::fetch_array($res);
  2199. //var_dump($row);
  2200. $lp_type = $row['ltype'];
  2201. $lp_path = $row['lpath'];
  2202. $lp_item_type = $row['litype'];
  2203. $lp_item_path = $row['lipath'];
  2204. $lp_item_params = $row['liparams'];
  2205. if(empty($lp_item_params))
  2206. {
  2207. list($lp_item_path,$lp_item_params) = explode('?',$lp_item_path);
  2208. }
  2209. //$lp_item_params = '?'.$lp_item_params;
  2210. //add ? if none - left commented to give freedom to scorm implementation
  2211. //if(substr($lp_item_params,0,1)!='?'){
  2212. // $lp_item_params = '?'.$lp_item_params;
  2213. //}
  2214. $sys_course_path = api_get_path(SYS_COURSE_PATH).api_get_course_path();
  2215. if($type == 'http'){
  2216. $course_path = api_get_path(WEB_COURSE_PATH).api_get_course_path(); //web path
  2217. }else{
  2218. $course_path = $sys_course_path; //system path
  2219. }
  2220. //now go through the specific cases to get the end of the path
  2221. switch($lp_type){
  2222. case 1:
  2223. if($lp_item_type == 'dokeos_chapter'){
  2224. $file = 'lp_content.php?type=dir';
  2225. }else{
  2226. require_once('resourcelinker.inc.php');
  2227. $file = rl_get_resource_link_for_learnpath(api_get_course_id(),$this->get_id(),$item_id);
  2228. $tmp_array=explode("/",$file);
  2229. $document_name=$tmp_array[count($tmp_array)-1];
  2230. if(strpos($document_name,'_DELETED_')){
  2231. $file = 'blank.php?error=document_deleted';
  2232. }
  2233. }
  2234. break;
  2235. case 2:
  2236. if($this->debug>2){error_log('New LP - In learnpath::get_link() '.__LINE__.' - Item type: '.$lp_item_type,0);}
  2237. if($lp_item_type!='dir'){
  2238. //Quite complex here:
  2239. //we want to make sure 'http://' (and similar) links can
  2240. //be loaded as is (withouth the Dokeos path in front) but
  2241. //some contents use this form: resource.htm?resource=http://blablabla
  2242. //which means we have to find a protocol at the path's start, otherwise
  2243. //it should not be considered as an external URL
  2244. //if($this->prerequisites_match($item_id)){
  2245. if(preg_match('#^[a-zA-Z]{2,5}://#',$lp_item_path)!=0){
  2246. if($this->debug>2){error_log('New LP - In learnpath::get_link() '.__LINE__.' - Found match for protocol in '.$lp_item_path,0);}
  2247. //distant url, return as is
  2248. $file = $lp_item_path;
  2249. }else{
  2250. if($this->debug>2){error_log('New LP - In learnpath::get_link() '.__LINE__.' - No starting protocol in '.$lp_item_path,0);}
  2251. //prevent getting untranslatable urls
  2252. $lp_item_path = preg_replace('/%2F/','/',$lp_item_path);
  2253. $lp_item_path = preg_replace('/%3A/',':',$lp_item_path);
  2254. //prepare the path
  2255. $file = $course_path.'/scorm/'.$lp_path.'/'.$lp_item_path;
  2256. //TODO fix this for urls with protocol header
  2257. $file = str_replace('//','/',$file);
  2258. $file = str_replace(':/','://',$file);
  2259. if(substr($lp_path,-1)=='/')
  2260. {
  2261. $lp_path = substr($lp_path,0,-1);
  2262. }
  2263. if(!is_file(realpath($sys_course_path.'/scorm/'.$lp_path.'/'.$lp_item_path)))
  2264. {//if file not found
  2265. $decoded = html_entity_decode($lp_item_path);
  2266. list($decoded) = explode('?',$decoded);
  2267. if(!is_file(realpath($sys_course_path.'/scorm/'.$lp_path.'/'.$decoded)))
  2268. {
  2269. require_once('resourcelinker.inc.php');
  2270. $file = rl_get_resource_link_for_learnpath(api_get_course_id(),$this->get_id(),$item_id);
  2271. $tmp_array=explode("/",$file);
  2272. $document_name=$tmp_array[count($tmp_array)-1];
  2273. if(strpos($document_name,'_DELETED_')){
  2274. $file = 'blank.php?error=document_deleted';
  2275. }
  2276. }
  2277. else
  2278. {
  2279. $file = $course_path.'/scorm/'.$lp_path.'/'.$decoded;
  2280. }
  2281. }
  2282. }
  2283. //}else{
  2284. //prerequisites did not match
  2285. //$file = 'blank.php';
  2286. //}
  2287. //We want to use parameters if they were defined in the imsmanifest
  2288. if($file!='blank.php')
  2289. {
  2290. $file.= $lp_item_params;
  2291. }
  2292. }else{
  2293. $file = 'lp_content.php?type=dir';
  2294. }
  2295. break;
  2296. case 3:
  2297. if($this->debug>2){error_log('New LP - In learnpath::get_link() '.__LINE__.' - Item type: '.$lp_item_type,0);}
  2298. //formatting AICC HACP append URL
  2299. $aicc_append = '?aicc_sid='.urlencode(session_id()).'&aicc_url='.urlencode(api_get_path(WEB_CODE_PATH).'newscorm/aicc_hacp.php').'&';
  2300. if($lp_item_type!='dir'){
  2301. //Quite complex here:
  2302. //we want to make sure 'http://' (and similar) links can
  2303. //be loaded as is (withouth the Dokeos path in front) but
  2304. //some contents use this form: resource.htm?resource=http://blablabla
  2305. //which means we have to find a protocol at the path's start, otherwise
  2306. //it should not be considered as an external URL
  2307. if(preg_match('#^[a-zA-Z]{2,5}://#',$lp_item_path)!=0){
  2308. if($this->debug>2){error_log('New LP - In learnpath::get_link() '.__LINE__.' - Found match for protocol in '.$lp_item_path,0);}
  2309. //distant url, return as is
  2310. $file = $lp_item_path;
  2311. /*
  2312. if(stristr($file,'<servername>')!==false){
  2313. $file = str_replace('<servername>',$course_path.'/scorm/'.$lp_path.'/',$lp_item_path);
  2314. }
  2315. */
  2316. $file .= $aicc_append;
  2317. }else{
  2318. if($this->debug>2){error_log('New LP - In learnpath::get_link() '.__LINE__.' - No starting protocol in '.$lp_item_path,0);}
  2319. //prevent getting untranslatable urls
  2320. $lp_item_path = preg_replace('/%2F/','/',$lp_item_path);
  2321. $lp_item_path = preg_replace('/%3A/',':',$lp_item_path);
  2322. //prepare the path - lp_path might be unusable because it includes the "aicc" subdir name
  2323. $file = $course_path.'/scorm/'.$lp_path.'/'.$lp_item_path;
  2324. //TODO fix this for urls with protocol header
  2325. $file = str_replace('//','/',$file);
  2326. $file = str_replace(':/','://',$file);
  2327. $file .= $aicc_append;
  2328. }
  2329. }else{
  2330. $file = 'lp_content.php?type=dir';
  2331. }
  2332. break;
  2333. case 4:
  2334. break;
  2335. default:
  2336. break;
  2337. }
  2338. }
  2339. if($this->debug>2){error_log('New LP - In learnpath::get_link() - returning "'.$file.'" from get_link',0);}
  2340. return $file;
  2341. }
  2342. /**
  2343. * Gets the latest usable view or generate a new one
  2344. * @param integer Optional attempt number. If none given, takes the highest from the lp_view table
  2345. * @return integer DB lp_view id
  2346. */
  2347. function get_view($attempt_num=0)
  2348. {
  2349. if($this->debug>0){error_log('New LP - In learnpath::get_view()',0);}
  2350. $search = '';
  2351. //use $attempt_num to enable multi-views management (disabled so far)
  2352. if($attempt_num != 0 AND intval(strval($attempt_num)) == $attempt_num)
  2353. {
  2354. $search = 'AND view_count = '.$attempt_num;
  2355. }
  2356. //when missing $attempt_num, search for a unique lp_view record for this lp and user
  2357. $lp_view_table = Database::get_course_table('lp_view');
  2358. $sql = "SELECT id, view_count FROM $lp_view_table " .
  2359. "WHERE lp_id = ".$this->get_id()." " .
  2360. "AND user_id = ".$this->get_user_id()." " .
  2361. $search .
  2362. " ORDER BY view_count DESC";
  2363. $res = api_sql_query($sql, __FILE__, __LINE__);
  2364. if(Database::num_rows($res)>0)
  2365. {
  2366. $row = Database::fetch_array($res);
  2367. $this->lp_view_id = $row['id'];
  2368. }else{
  2369. //no database record, create one
  2370. $sql = "INSERT INTO $lp_view_table(lp_id,user_id,view_count)" .
  2371. "VALUES (".$this->get_id().",".$this->get_user_id().",1)";
  2372. $res = api_sql_query($sql, __FILE__, __LINE__);
  2373. $id = Database::get_last_insert_id();
  2374. $this->lp_view_id = $id;
  2375. }
  2376. return $this->lp_view_id;
  2377. }
  2378. /**
  2379. * Gets the current view id
  2380. * @return integer View ID (from lp_view)
  2381. */
  2382. function get_view_id()
  2383. {
  2384. if($this->debug>0){error_log('New LP - In learnpath::get_view_id()',0);}
  2385. if(!empty($this->lp_view_id))
  2386. {
  2387. return $this->lp_view_id;
  2388. }else{
  2389. return 0;
  2390. }
  2391. }
  2392. /**
  2393. * Gets the update queue
  2394. * @return array Array containing IDs of items to be updated by JavaScript
  2395. */
  2396. function get_update_queue()
  2397. {
  2398. if($this->debug>0){error_log('New LP - In learnpath::get_update_queue()',0);}
  2399. return $this->update_queue;
  2400. }
  2401. /**
  2402. * Gets the user ID
  2403. * @return integer User ID
  2404. */
  2405. function get_user_id()
  2406. {
  2407. if($this->debug>0){error_log('New LP - In learnpath::get_user_id()',0);}
  2408. if(!empty($this->user_id))
  2409. {
  2410. return $this->user_id;
  2411. }else{
  2412. return false;
  2413. }
  2414. }
  2415. /**
  2416. * Logs a message into a file
  2417. * @param string Message to log
  2418. * @return boolean True on success, false on error or if msg empty
  2419. */
  2420. function log($msg)
  2421. {
  2422. if($this->debug>0){error_log('New LP - In learnpath::log()',0);}
  2423. //TODO
  2424. $this->error .= $msg."\n";
  2425. return true;
  2426. }
  2427. /**
  2428. * Moves an item up and down at its level
  2429. * @param integer Item to move up and down
  2430. * @param string Direction 'up' or 'down'
  2431. * @return integer New display order, or false on error
  2432. */
  2433. function move_item($id, $direction){
  2434. if($this->debug>0){error_log('New LP - In learnpath::move_item('.$id.','.$direction.')',0);}
  2435. if(empty($id) or empty($direction)){return false;}
  2436. $tbl_lp_item = Database::get_course_table('lp_item');
  2437. $sql_sel = "
  2438. SELECT *
  2439. FROM " . $tbl_lp_item . "
  2440. WHERE id = " . $id;
  2441. $res_sel = api_sql_query($sql_sel,__FILE__,__LINE__);
  2442. //check if elem exists
  2443. if(Database::num_rows($res_sel)<1){return false;}
  2444. //gather data
  2445. $row = Database::fetch_array($res_sel);
  2446. $previous = $row['previous_item_id'];
  2447. $next = $row['next_item_id'];
  2448. $display = $row['display_order'];
  2449. $parent = $row['parent_item_id'];
  2450. $lp = $row['lp_id'];
  2451. //update the item (switch with previous/next one)
  2452. switch($direction)
  2453. {
  2454. case 'up':
  2455. if($this->debug>2){error_log('Movement up detected',0);}
  2456. if($display <= 1){/*do nothing*/}
  2457. else{
  2458. $sql_sel2 = "SELECT *
  2459. FROM $tbl_lp_item
  2460. WHERE id = $previous";
  2461. if($this->debug>2){error_log('Selecting previous: '.$sql_sel2,0);}
  2462. $res_sel2 = api_sql_query($sql_sel2,__FILE__,__LINE__);
  2463. if(Database::num_rows($res_sel2)<1){$previous_previous = 0;}
  2464. //gather data
  2465. $row2 = Database::fetch_array($res_sel2);
  2466. $previous_previous = $row2['previous_item_id'];
  2467. //update previous_previous item (switch "next" with current)
  2468. if($previous_previous != 0)
  2469. {
  2470. $sql_upd2 = "UPDATE $tbl_lp_item SET next_item_id = $id WHERE id = $previous_previous";
  2471. if($this->debug>2){error_log($sql_upd2,0);}
  2472. $res_upd2 = api_sql_query($sql_upd2, __FILE__, __LINE__);
  2473. }
  2474. //update previous item (switch with current)
  2475. if($previous != 0)
  2476. {
  2477. $sql_upd2 = "UPDATE $tbl_lp_item SET next_item_id = $next, previous_item_id = $id, display_order = display_order +1 WHERE id = $previous";
  2478. if($this->debug>2){error_log($sql_upd2,0);}
  2479. $res_upd2 = api_sql_query($sql_upd2, __FILE__, __LINE__);
  2480. }
  2481. //update current item (switch with previous)
  2482. if($id != 0){
  2483. $sql_upd2 = "UPDATE $tbl_lp_item SET next_item_id = $previous, previous_item_id = $previous_previous, display_order = display_order-1 WHERE id = $id";
  2484. if($this->debug>2){error_log($sql_upd2,0);}
  2485. $res_upd2 = api_sql_query($sql_upd2, __FILE__, __LINE__);
  2486. }
  2487. //update next item (new previous item)
  2488. if($next != 0){
  2489. $sql_upd2 = "UPDATE $tbl_lp_item SET previous_item_id = $previous WHERE id = $next";
  2490. if($this->debug>2){error_log($sql_upd2,0);}
  2491. $res_upd2 = api_sql_query($sql_upd2, __FILE__, __LINE__);
  2492. }
  2493. $display = $display-1;
  2494. }
  2495. break;
  2496. case 'down':
  2497. if($this->debug>2){error_log('Movement down detected',0);}
  2498. if($next == 0){/*do nothing*/}
  2499. else{
  2500. $sql_sel2 = "SELECT * FROM $tbl_lp_item WHERE id = $next";
  2501. if($this->debug>2){error_log('Selecting next: '.$sql_sel2,0);}
  2502. $res_sel2 = api_sql_query($sql_sel2,__FILE__,__LINE__);
  2503. if(Database::num_rows($res_sel2)<1){$next_next = 0;}
  2504. //gather data
  2505. $row2 = Database::fetch_array($res_sel2);
  2506. $next_next = $row2['next_item_id'];
  2507. //update previous item (switch with current)
  2508. if($previous != 0)
  2509. {
  2510. $sql_upd2 = "UPDATE $tbl_lp_item SET next_item_id = $next WHERE id = $previous";
  2511. $res_upd2 = api_sql_query($sql_upd2, __FILE__, __LINE__);
  2512. }
  2513. //update current item (switch with previous)
  2514. if($id != 0)
  2515. {
  2516. $sql_upd2 = "UPDATE $tbl_lp_item SET previous_item_id = $next, next_item_id = $next_next, display_order = display_order+1 WHERE id = $id";
  2517. $res_upd2 = api_sql_query($sql_upd2, __FILE__, __LINE__);
  2518. }
  2519. //update next item (new previous item)
  2520. if($next != 0)
  2521. {
  2522. $sql_upd2 = "UPDATE $tbl_lp_item SET previous_item_id = $previous, next_item_id = $id, display_order = display_order-1 WHERE id = $next";
  2523. $res_upd2 = api_sql_query($sql_upd2, __FILE__, __LINE__);
  2524. }
  2525. //update next_next item (switch "previous" with current)
  2526. if($next_next != 0)
  2527. {
  2528. $sql_upd2 = "UPDATE $tbl_lp_item SET previous_item_id = $id WHERE id = $next_next";
  2529. $res_upd2 = api_sql_query($sql_upd2, __FILE__, __LINE__);
  2530. }
  2531. $display = $display+1;
  2532. }
  2533. break;
  2534. default:
  2535. return false;
  2536. }
  2537. return $display;
  2538. }
  2539. /**
  2540. * Move a learnpath up (display_order)
  2541. * @param integer Learnpath ID
  2542. */
  2543. function move_up($lp_id)
  2544. {
  2545. $lp_table = Database::get_course_table(TABLE_LP_MAIN);
  2546. $sql = "SELECT * FROM $lp_table ORDER BY display_order";
  2547. $res = api_sql_query($sql, __FILE__, __LINE__);
  2548. if($res === false) return false;
  2549. $lps = array();
  2550. $lp_order = array();
  2551. $num = Database::num_rows($res);
  2552. //first check the order is correct, globally (might be wrong because
  2553. //of versions < 1.8.4)
  2554. if($num>0)
  2555. {
  2556. $i = 1;
  2557. while($row = Database::fetch_array($res))
  2558. {
  2559. if($row['display_order'] != $i)
  2560. { //if we find a gap in the order, we need to fix it
  2561. $need_fix = true;
  2562. $sql_u = "UPDATE $lp_table SET display_order = $i WHERE id = ".$row['id'];
  2563. $res_u = api_sql_query($sql_u, __FILE__, __LINE__);
  2564. }
  2565. $row['display_order'] = $i;
  2566. $lps[$row['id']] = $row;
  2567. $lp_order[$i] = $row['id'];
  2568. $i++;
  2569. }
  2570. }
  2571. if($num>1) //if there's only one element, no need to sort
  2572. {
  2573. $order = $lps[$lp_id]['display_order'];
  2574. if($order>1) //if it's the first element, no need to move up
  2575. {
  2576. $sql_u1 = "UPDATE $lp_table SET display_order = $order WHERE id = ".$lp_order[$order-1];
  2577. $res_u1 = api_sql_query($sql_u1, __FILE__, __LINE__);
  2578. $sql_u2 = "UPDATE $lp_table SET display_order = ".($order-1)." WHERE id = ".$lp_id;
  2579. $res_u2 = api_sql_query($sql_u2, __FILE__, __LINE__);
  2580. }
  2581. }
  2582. }
  2583. /**
  2584. * Move a learnpath down (display_order)
  2585. * @param integer Learnpath ID
  2586. */
  2587. function move_down($lp_id)
  2588. {
  2589. $lp_table = Database::get_course_table(TABLE_LP_MAIN);
  2590. $sql = "SELECT * FROM $lp_table ORDER BY display_order";
  2591. $res = api_sql_query($sql, __FILE__, __LINE__);
  2592. if($res === false) return false;
  2593. $lps = array();
  2594. $lp_order = array();
  2595. $num = Database::num_rows($res);
  2596. $max = 0;
  2597. //first check the order is correct, globally (might be wrong because
  2598. //of versions < 1.8.4)
  2599. if($num>0)
  2600. {
  2601. $i = 1;
  2602. while($row = Database::fetch_array($res))
  2603. {
  2604. $max = $i;
  2605. if($row['display_order'] != $i)
  2606. { //if we find a gap in the order, we need to fix it
  2607. $need_fix = true;
  2608. $sql_u = "UPDATE $lp_table SET display_order = $i WHERE id = ".$row['id'];
  2609. $res_u = api_sql_query($sql_u, __FILE__, __LINE__);
  2610. }
  2611. $row['display_order'] = $i;
  2612. $lps[$row['id']] = $row;
  2613. $lp_order[$i] = $row['id'];
  2614. $i++;
  2615. }
  2616. }
  2617. if($num>1) //if there's only one element, no need to sort
  2618. {
  2619. $order = $lps[$lp_id]['display_order'];
  2620. if($order<$max) //if it's the first element, no need to move up
  2621. {
  2622. $sql_u1 = "UPDATE $lp_table SET display_order = $order WHERE id = ".$lp_order[$order+1];
  2623. $res_u1 = api_sql_query($sql_u1, __FILE__, __LINE__);
  2624. $sql_u2 = "UPDATE $lp_table SET display_order = ".($order+1)." WHERE id = ".$lp_id;
  2625. $res_u2 = api_sql_query($sql_u2, __FILE__, __LINE__);
  2626. }
  2627. }
  2628. }
  2629. /**
  2630. * Updates learnpath attributes to point to the next element
  2631. * The last part is similar to set_current_item but processing the other way around
  2632. */
  2633. function next()
  2634. {
  2635. if($this->debug>0){error_log('New LP - In learnpath::next()',0);}
  2636. $this->last = $this->get_current_item_id();
  2637. $this->items[$this->last]->save(false,$this->prerequisites_match($this->last));
  2638. $this->autocomplete_parents($this->last);
  2639. $new_index = $this->get_next_index();
  2640. if($this->debug>2){error_log('New LP - New index: '.$new_index,0);}
  2641. $this->index = $new_index;
  2642. if($this->debug>2){error_log('New LP - Now having orderedlist['.$new_index.'] = '. $this->ordered_items[$new_index],0);}
  2643. $this->current = $this->ordered_items[$new_index];
  2644. if($this->debug>2){error_log('New LP - new item id is '.$this->current.'-'.$this->get_current_item_id(),0);}
  2645. }
  2646. /**
  2647. * Open a resource = initialise all local variables relative to this resource. Depending on the child
  2648. * class, this might be redefined to allow several behaviours depending on the document type.
  2649. * @param integer Resource ID
  2650. * @return boolean True on success, false otherwise
  2651. */
  2652. function open($id)
  2653. {
  2654. if($this->debug>0){error_log('New LP - In learnpath::open()',0);}
  2655. //TODO
  2656. //set the current resource attribute to this resource
  2657. //switch on element type (redefine in child class?)
  2658. //set status for this item to "opened"
  2659. //start timer
  2660. //initialise score
  2661. $this->index = 0; //or = the last item seen (see $this->last)
  2662. }
  2663. /**
  2664. * Check that all prerequisites are fulfilled. Returns true and an empty string on succes, returns false
  2665. * and the prerequisite string on error.
  2666. * This function is based on the rules for aicc_script language as described in the SCORM 1.2 CAM documentation page 108.
  2667. * @param integer Optional item ID. If none given, uses the current open item.
  2668. * @return boolean True if prerequisites are matched, false otherwise
  2669. * @return string Empty string if true returned, prerequisites string otherwise.
  2670. */
  2671. function prerequisites_match($item = null)
  2672. {
  2673. if($this->debug>0){error_log('New LP - In learnpath::prerequisites_match()',0);}
  2674. if(empty($item)){$item = $this->current;}
  2675. if(is_object($this->items[$item]))
  2676. {
  2677. $prereq_string = $this->items[$item]->get_prereq_string();
  2678. if(empty($prereq_string)){return true;}
  2679. //clean spaces
  2680. $prereq_string = str_replace(' ','',$prereq_string);
  2681. if($this->debug>0){error_log('Found prereq_string: '.$prereq_string,0);}
  2682. //now send to the parse_prereq() function that will check this component's prerequisites
  2683. $result = $this->items[$item]->parse_prereq($prereq_string,$this->items,$this->refs_list,$this->get_user_id());
  2684. if($result === false)
  2685. {
  2686. $this->set_error_msg($this->items[$item]->prereq_alert);
  2687. }
  2688. }else{
  2689. $result = true;
  2690. if($this->debug>1){error_log('New LP - $this->items['.$item.'] was not an object',0);}
  2691. }
  2692. if($this->debug>1){error_log('New LP - End of prerequisites_match(). Error message is now '.$this->error,0);}
  2693. return $result;
  2694. }
  2695. /**
  2696. * Updates learnpath attributes to point to the previous element
  2697. * The last part is similar to set_current_item but processing the other way around
  2698. */
  2699. function previous()
  2700. {
  2701. if($this->debug>0){error_log('New LP - In learnpath::previous()',0);}
  2702. $this->last = $this->get_current_item_id();
  2703. $this->items[$this->last]->save(false,$this->prerequisites_match($this->last));
  2704. $this->autocomplete_parents($this->last);
  2705. $new_index = $this->get_previous_index();
  2706. $this->index = $new_index;
  2707. $this->current = $this->ordered_items[$new_index];
  2708. }
  2709. /**
  2710. * Publishes a learnpath. This basically means show or hide the learnpath
  2711. * to normal users.
  2712. * Can be used as abstract
  2713. * @param integer Learnpath ID
  2714. * @param string New visibility
  2715. */
  2716. function toggle_visibility($lp_id,$set_visibility=1)
  2717. {
  2718. //if($this->debug>0){error_log('New LP - In learnpath::toggle_visibility()',0);}
  2719. $action = 'visible';
  2720. if($set_visibility != 1)
  2721. {
  2722. $action = 'invisible';
  2723. }
  2724. return api_item_property_update(api_get_course_info(),TOOL_LEARNPATH,$lp_id,$action,api_get_user_id());
  2725. }
  2726. /**
  2727. * Publishes a learnpath. This basically means show or hide the learnpath
  2728. * on the course homepage
  2729. * Can be used as abstract
  2730. * @param integer Learnpath ID
  2731. * @param string New visibility
  2732. */
  2733. function toggle_publish($lp_id,$set_visibility='v')
  2734. {
  2735. //if($this->debug>0){error_log('New LP - In learnpath::toggle_publish()',0);}
  2736. $tbl_lp = Database::get_course_table('lp');
  2737. $sql="SELECT * FROM $tbl_lp where id=$lp_id";
  2738. $result=api_sql_query($sql,__FILE__,__LINE__);
  2739. $row=Database::fetch_array($result);
  2740. $name=domesticate($row['name']);
  2741. if($set_visibility == 'i') {
  2742. $s=$name." ".get_lang('_no_published');
  2743. $dialogBox=$s;
  2744. $v=0;
  2745. }
  2746. if($set_visibility == 'v')
  2747. {
  2748. $s=$name." ".get_lang('_published');
  2749. $dialogBox=$s;
  2750. $v=1;
  2751. }
  2752. $tbl_tool = Database::get_course_table(TABLE_TOOL_LIST);
  2753. $link = 'newscorm/lp_controller.php?action=view&lp_id='.$lp_id;
  2754. $sql="SELECT * FROM $tbl_tool where name='$name' and image='scormbuilder.gif' and link LIKE '$link%'";
  2755. $result=api_sql_query($sql,__FILE__,__LINE__);
  2756. $num=Database::num_rows($result);
  2757. $row2=Database::fetch_array($result);
  2758. //if($this->debug>2){error_log('New LP - '.$sql.' - '.$num,0);}
  2759. if(($set_visibility == 'i') && ($num>0))
  2760. {
  2761. $sql ="DELETE FROM $tbl_tool WHERE (name='$name' and image='scormbuilder.gif' and link LIKE '$link%')";
  2762. }
  2763. elseif(($set_visibility == 'v') && ($num==0))
  2764. {
  2765. $sql ="INSERT INTO $tbl_tool (name, link, image, visibility, admin, address, added_tool) VALUES ('$name','newscorm/lp_controller.php?action=view&lp_id=$lp_id','scormbuilder.gif','$v','0','pastillegris.gif',0)";
  2766. }
  2767. else
  2768. {
  2769. //parameter and database incompatible, do nothing
  2770. }
  2771. $result=api_sql_query($sql,__FILE__,__LINE__);
  2772. //if($this->debug>2){error_log('New LP - Leaving learnpath::toggle_visibility: '.$sql,0);}
  2773. }
  2774. /**
  2775. * Restart the whole learnpath. Return the URL of the first element.
  2776. * Make sure the results are saved with anoter method. This method should probably be
  2777. * redefined in children classes.
  2778. * @return string URL to load in the viewer
  2779. */
  2780. function restart()
  2781. {
  2782. if($this->debug>0){error_log('New LP - In learnpath::restart()',0);}
  2783. //TODO
  2784. //call autosave method to save the current progress
  2785. //$this->index = 0;
  2786. $lp_view_table = Database::get_course_table('lp_view');
  2787. $sql = "INSERT INTO $lp_view_table (lp_id, user_id, view_count) " .
  2788. "VALUES (".$this->lp_id.",".$this->get_user_id().",".($this->attempt+1).")";
  2789. if($this->debug>2){error_log('New LP - Inserting new lp_view for restart: '.$sql,0);}
  2790. $res = api_sql_query($sql, __FILE__, __LINE__);
  2791. if($view_id = Database::get_last_insert_id($res))
  2792. {
  2793. $this->lp_view_id = $view_id;
  2794. $this->attempt = $this->attempt+1;
  2795. }else{
  2796. $this->error = 'Could not insert into item_view table...';
  2797. return false;
  2798. }
  2799. $this->autocomplete_parents($this->current);
  2800. foreach($this->items as $index=>$dummy){
  2801. $this->items[$index]->restart();
  2802. $this->items[$index]->set_lp_view($this->lp_view_id);
  2803. }
  2804. $this->first();
  2805. return true;
  2806. }
  2807. /**
  2808. * Saves the current item
  2809. * @return boolean
  2810. */
  2811. function save_current(){
  2812. if($this->debug>0){error_log('New LP - In learnpath::save_current()',0);}
  2813. //TODO do a better check on the index pointing to the right item (it is supposed to be working
  2814. // on $ordered_items[] but not sure it's always safe to use with $items[])
  2815. if($this->debug>2){error_log('New LP - save_current() saving item '.$this->current,0);}
  2816. if($this->debug>2){error_log(''.print_r($this->items,true),0);}
  2817. if(is_object($this->items[$this->current])){
  2818. //$res = $this->items[$this->current]->save(false);
  2819. $res = $this->items[$this->current]->save(false,$this->prerequisites_match($this->current));
  2820. $this->autocomplete_parents($this->current);
  2821. $status = $this->items[$this->current]->get_status();
  2822. $this->append_message('new_item_status: '.$status);
  2823. $this->update_queue[$this->current] = $status;
  2824. return $res;
  2825. }
  2826. return false;
  2827. }
  2828. /**
  2829. * Saves the given item
  2830. * @param integer Item ID. Optional (will take from $_REQUEST if null)
  2831. * @param boolean Save from url params (true) or from current attributes (false). Optional. Defaults to true
  2832. * @return boolean
  2833. */
  2834. function save_item($item_id=null,$from_outside=true){
  2835. if($this->debug>0){error_log('New LP - In learnpath::save_item('.$item_id.','.$from_outside.')',0);}
  2836. //TODO do a better check on the index pointing to the right item (it is supposed to be working
  2837. // on $ordered_items[] but not sure it's always safe to use with $items[])
  2838. if(empty($item_id)){
  2839. $item_id = $this->escape_string($_REQUEST['id']);
  2840. }
  2841. if(empty($item_id))
  2842. {
  2843. $item_id = $this->get_current_item_id();
  2844. }
  2845. if($this->debug>2){error_log('New LP - save_current() saving item '.$item_id,0);}
  2846. if(is_object($this->items[$item_id])){
  2847. $res = $this->items[$item_id]->save($from_outside,$this->prerequisites_match($item_id));
  2848. //$res = $this->items[$item_id]->save($from_outside);
  2849. $this->autocomplete_parents($item_id);
  2850. $status = $this->items[$item_id]->get_status();
  2851. $this->append_message('new_item_status: '.$status);
  2852. $this->update_queue[$item_id] = $status;
  2853. return $res;
  2854. }
  2855. return false;
  2856. }
  2857. /**
  2858. * Saves the last item seen's ID only in case
  2859. */
  2860. function save_last(){
  2861. if($this->debug>0){error_log('New LP - In learnpath::save_last()',0);}
  2862. $table = Database::get_course_table('lp_view');
  2863. if(isset($this->current)){
  2864. if($this->debug>2){error_log('New LP - Saving current item ('.$this->current.') for later review',0);}
  2865. $sql = "UPDATE $table SET last_item = ".$this->get_current_item_id()." " .
  2866. "WHERE lp_id = ".$this->get_id()." AND user_id = ".$this->get_user_id();
  2867. if($this->debug>2){error_log('New LP - Saving last item seen : '.$sql,0);}
  2868. $res = api_sql_query($sql,__FILE__,__LINE__);
  2869. }
  2870. //save progress
  2871. list($progress,$text) = $this->get_progress_bar_text('%');
  2872. if($progress>=0 AND $progress<=100){
  2873. $progress= (int)$progress;
  2874. $sql = "UPDATE $table SET progress = $progress " .
  2875. "WHERE lp_id = ".$this->get_id()." AND " .
  2876. "user_id = ".$this->get_user_id();
  2877. $res = api_sql_query($sql,__FILE__, __LINE__); //ignore errors as some tables might not have the progress field just yet
  2878. $this->progress_db = $progress;
  2879. }
  2880. }
  2881. /**
  2882. * Sets the current item ID (checks if valid and authorized first)
  2883. * @param integer New item ID. If not given or not authorized, defaults to current
  2884. */
  2885. function set_current_item($item_id=null)
  2886. {
  2887. if($this->debug>0){error_log('New LP - In learnpath::set_current_item('.$item_id.')',0);}
  2888. if(empty($item_id)){
  2889. if($this->debug>2){error_log('New LP - No new current item given, ignore...',0);}
  2890. //do nothing
  2891. }else{
  2892. if($this->debug>2){error_log('New LP - New current item given is '.$item_id.'...',0);}
  2893. $item_id = $this->escape_string($item_id);
  2894. //TODO check in database here
  2895. $this->last = $this->current;
  2896. $this->current = $item_id;
  2897. //TODO update $this->index as well
  2898. foreach($this->ordered_items as $index => $item)
  2899. {
  2900. if($item == $this->current)
  2901. {
  2902. $this->index = $index;
  2903. break;
  2904. }
  2905. }
  2906. if($this->debug>2){error_log('New LP - set_current_item('.$item_id.') done. Index is now : '.$this->index,0);}
  2907. }
  2908. }
  2909. /**
  2910. * Sets the encoding
  2911. * @param string New encoding
  2912. */
  2913. function set_encoding($enc='ISO-8859-1'){
  2914. if($this->debug>0){error_log('New LP - In learnpath::set_encoding()',0);}
  2915. $enc = strtoupper($enc);
  2916. $encodings = array('UTF-8','ISO-8859-1','ISO-8859-15','SHIFT-JIS');
  2917. if(in_array($enc,$encodings)){
  2918. $lp = $this->get_id();
  2919. if($lp!=0){
  2920. $tbl_lp = Database::get_course_table('lp');
  2921. $sql = "UPDATE $tbl_lp SET default_encoding = '$enc' WHERE id = ".$lp;
  2922. $res = api_sql_query($sql, __FILE__, __LINE__);
  2923. return $res;
  2924. }
  2925. }
  2926. return false;
  2927. }
  2928. /**
  2929. * Sets the JS lib setting in the database directly.
  2930. * This is the JavaScript library file this lp needs to load on startup
  2931. * @param string Proximity setting
  2932. */
  2933. function set_jslib($lib=''){
  2934. if($this->debug>0){error_log('New LP - In learnpath::set_jslib()',0);}
  2935. $lp = $this->get_id();
  2936. if($lp!=0){
  2937. $tbl_lp = Database::get_course_table('lp');
  2938. $sql = "UPDATE $tbl_lp SET js_lib = '$lib' WHERE id = ".$lp;
  2939. $res = api_sql_query($sql, __FILE__, __LINE__);
  2940. return $res;
  2941. }else{
  2942. return false;
  2943. }
  2944. }
  2945. /**
  2946. * Sets the name of the LP maker (publisher) (and save)
  2947. * @param string Optional string giving the new content_maker of this learnpath
  2948. */
  2949. function set_maker($name=''){
  2950. if($this->debug>0){error_log('New LP - In learnpath::set_maker()',0);}
  2951. if(empty($name))return false;
  2952. $this->maker = $this->escape_string($name);
  2953. $lp_table = Database::get_course_table('lp');
  2954. $lp_id = $this->get_id();
  2955. $sql = "UPDATE $lp_table SET content_maker = '".$this->maker."' WHERE id = '$lp_id'";
  2956. if($this->debug>2){error_log('New LP - lp updated with new content_maker : '.$this->maker,0);}
  2957. //$res = Database::query($sql);
  2958. $res = api_sql_query($sql, __FILE__, __LINE__);
  2959. return true;
  2960. }
  2961. /**
  2962. * Sets the name of the current learnpath (and save)
  2963. * @param string Optional string giving the new name of this learnpath
  2964. */
  2965. function set_name($name=''){
  2966. if($this->debug>0){error_log('New LP - In learnpath::set_name()',0);}
  2967. if(empty($name))return false;
  2968. $this->name = $this->escape_string($name);
  2969. $lp_table = Database::get_course_table('lp');
  2970. $lp_id = $this->get_id();
  2971. $sql = "UPDATE $lp_table SET name = '".$this->name."' WHERE id = '$lp_id'";
  2972. if($this->debug>2){error_log('New LP - lp updated with new name : '.$this->name,0);}
  2973. //$res = Database::query($sql);
  2974. $res = api_sql_query($sql, __FILE__, __LINE__);
  2975. // if the lp is visible on the homepage, change his name there
  2976. if(mysql_affected_rows())
  2977. {
  2978. $table = Database :: get_course_table(TABLE_TOOL_LIST);
  2979. $sql = 'UPDATE '.$table.' SET
  2980. name = "'.$this->name.'"
  2981. WHERE link = "newscorm/lp_controller.php?action=view&lp_id='.$lp_id.'"';
  2982. api_sql_query($sql, __FILE__, __LINE__);
  2983. }
  2984. return true;
  2985. }
  2986. /**
  2987. * Sets the theme of the LP (local/remote) (and save)
  2988. * @param string Optional string giving the new theme of this learnpath
  2989. * @return bool returns true if theme name is not empty
  2990. */
  2991. function set_theme($name=''){
  2992. if($this->debug>0){error_log('New LP - In learnpath::set_theme()',0);}
  2993. if(empty($name))return false;
  2994. $this->theme = $this->escape_string($name);
  2995. $lp_table = Database::get_course_table('lp');
  2996. $lp_id = $this->get_id();
  2997. $sql = "UPDATE $lp_table SET theme = '".$this->theme."' WHERE id = '$lp_id'";
  2998. if($this->debug>2){error_log('New LP - lp updated with new theme : '.$this->theme,0);}
  2999. //$res = Database::query($sql);
  3000. $res = api_sql_query($sql, __FILE__, __LINE__);
  3001. return true;
  3002. }
  3003. /**
  3004. * Sets the location/proximity of the LP (local/remote) (and save)
  3005. * @param string Optional string giving the new location of this learnpath
  3006. */
  3007. function set_proximity($name=''){
  3008. if($this->debug>0){error_log('New LP - In learnpath::set_proximity()',0);}
  3009. if(empty($name))return false;
  3010. $this->proximity = $this->escape_string($name);
  3011. $lp_table = Database::get_course_table('lp');
  3012. $lp_id = $this->get_id();
  3013. $sql = "UPDATE $lp_table SET content_local = '".$this->proximity."' WHERE id = '$lp_id'";
  3014. if($this->debug>2){error_log('New LP - lp updated with new proximity : '.$this->proximity,0);}
  3015. //$res = Database::query($sql);
  3016. $res = api_sql_query($sql, __FILE__, __LINE__);
  3017. return true;
  3018. }
  3019. /**
  3020. * Sets the previous item ID to a given ID. Generally, this should be set to the previous 'current' item
  3021. * @param integer DB ID of the item
  3022. */
  3023. function set_previous_item($id)
  3024. {
  3025. if($this->debug>0){error_log('New LP - In learnpath::set_previous_item()',0);}
  3026. $this->last = $id;
  3027. }
  3028. /**
  3029. * Sets the object's error message
  3030. * @param string Error message. If empty, reinits the error string
  3031. * @return void
  3032. */
  3033. function set_error_msg($error='')
  3034. {
  3035. if($this->debug>0){error_log('New LP - In learnpath::set_error_msg()',0);}
  3036. if(empty($error)){
  3037. $this->error = '';
  3038. }else{
  3039. $this->error .= $error;
  3040. }
  3041. }
  3042. /**
  3043. * Launches the current item if not 'sco' (starts timer and make sure there is a record ready in the DB)
  3044. *
  3045. */
  3046. function start_current_item($allow_new_attempt=false){
  3047. if($this->debug>0){error_log('New LP - In learnpath::start_current_item()',0);}
  3048. if($this->current != 0 AND
  3049. is_object($this->items[$this->current]))
  3050. {
  3051. $type = $this->get_type();
  3052. $item_type = $this->items[$this->current]->get_type();
  3053. if(
  3054. ($type == 2 && $item_type!='sco')
  3055. OR
  3056. ($type == 3 && $item_type!='au')
  3057. OR
  3058. ($type == 1 && $item_type!=TOOL_QUIZ && $item_type!=TOOL_HOTPOTATOES)
  3059. )
  3060. {
  3061. $this->items[$this->current]->open($allow_new_attempt);
  3062. $this->autocomplete_parents($this->current);
  3063. $prereq_check = $this->prerequisites_match($this->current);
  3064. $this->items[$this->current]->save(false,$prereq_check);
  3065. //$this->update_queue[$this->last] = $this->items[$this->last]->get_status();
  3066. }else{
  3067. //if sco, then it is supposed to have been updated by some other call
  3068. }
  3069. }
  3070. if($this->debug>0){error_log('New LP - End of learnpath::start_current_item()',0);}
  3071. return true;
  3072. }
  3073. /**
  3074. * Stops the processing and counters for the old item (as held in $this->last)
  3075. * @param
  3076. */
  3077. function stop_previous_item(){
  3078. if($this->debug>0){error_log('New LP - In learnpath::stop_previous_item()',0);}
  3079. if($this->last != 0 AND $this->last!=$this->current AND is_object($this->items[$this->last]))
  3080. {
  3081. if($this->debug>2){error_log('New LP - In learnpath::stop_previous_item() - '.$this->last.' is object',0);}
  3082. switch($this->get_type()){
  3083. case '3':
  3084. if($this->items[$this->last]->get_type()!='au')
  3085. {
  3086. if($this->debug>2){error_log('New LP - In learnpath::stop_previous_item() - '.$this->last.' in lp_type 3 is <> au',0);}
  3087. $this->items[$this->last]->close();
  3088. //$this->autocomplete_parents($this->last);
  3089. //$this->update_queue[$this->last] = $this->items[$this->last]->get_status();
  3090. }else{
  3091. if($this->debug>2){error_log('New LP - In learnpath::stop_previous_item() - Item is an AU, saving is managed by AICC signals',0);}
  3092. }
  3093. case '2':
  3094. if($this->items[$this->last]->get_type()!='sco')
  3095. {
  3096. if($this->debug>2){error_log('New LP - In learnpath::stop_previous_item() - '.$this->last.' in lp_type 2 is <> sco',0);}
  3097. $this->items[$this->last]->close();
  3098. //$this->autocomplete_parents($this->last);
  3099. //$this->update_queue[$this->last] = $this->items[$this->last]->get_status();
  3100. }else{
  3101. if($this->debug>2){error_log('New LP - In learnpath::stop_previous_item() - Item is a SCO, saving is managed by SCO signals',0);}
  3102. }
  3103. break;
  3104. case '1':
  3105. default:
  3106. if($this->debug>2){error_log('New LP - In learnpath::stop_previous_item() - '.$this->last.' in lp_type 1 is asset',0);}
  3107. $this->items[$this->last]->close();
  3108. break;
  3109. }
  3110. }else{
  3111. if($this->debug>2){error_log('New LP - In learnpath::stop_previous_item() - No previous element found, ignoring...',0);}
  3112. return false;
  3113. }
  3114. return true;
  3115. }
  3116. /**
  3117. * Updates the default view mode from fullscreen to embedded and inversely
  3118. * @return string The current default view mode ('fullscreen' or 'embedded')
  3119. */
  3120. function update_default_view_mode()
  3121. {
  3122. if($this->debug>0){error_log('New LP - In learnpath::update_default_view_mode()',0);}
  3123. $lp_table = Database::get_course_table('lp');
  3124. $sql = "SELECT * FROM $lp_table WHERE id = ".$this->get_id();
  3125. $res = api_sql_query($sql, __FILE__, __LINE__);
  3126. if(Database::num_rows($res)>0){
  3127. $row = Database::fetch_array($res);
  3128. $view_mode = $row['default_view_mod'];
  3129. if($view_mode == 'fullscreen'){
  3130. $view_mode = 'embedded';
  3131. }elseif($view_mode == 'embedded'){
  3132. $view_mode = 'fullscreen';
  3133. }
  3134. $sql = "UPDATE $lp_table SET default_view_mod = '$view_mode' WHERE id = ".$this->get_id();
  3135. $res = api_sql_query($sql, __FILE__, __LINE__);
  3136. $this->mode = $view_mode;
  3137. return $view_mode;
  3138. }else{
  3139. if($this->debug>2){error_log('New LP - Problem in update_default_view() - could not find LP '.$this->get_id().' in DB',0);}
  3140. }
  3141. return -1;
  3142. }
  3143. /**
  3144. * Updates the default behaviour about auto-commiting SCORM updates
  3145. * @return boolean True if auto-commit has been set to 'on', false otherwise
  3146. */
  3147. function update_default_scorm_commit(){
  3148. if($this->debug>0){error_log('New LP - In learnpath::update_default_scorm_commit()',0);}
  3149. $lp_table = Database::get_course_table('lp');
  3150. $sql = "SELECT * FROM $lp_table WHERE id = ".$this->get_id();
  3151. $res = api_sql_query($sql, __FILE__, __LINE__);
  3152. if(Database::num_rows($res)>0){
  3153. $row = Database::fetch_array($res);
  3154. $force = $row['force_commit'];
  3155. if($force == 1){
  3156. $force = 0;
  3157. $force_return = false;
  3158. }elseif($force == 0){
  3159. $force = 1;
  3160. $force_return = true;
  3161. }
  3162. $sql = "UPDATE $lp_table SET force_commit = $force WHERE id = ".$this->get_id();
  3163. $res = api_sql_query($sql, __FILE__, __LINE__);
  3164. $this->force_commit = $force_return;
  3165. return $force_return;
  3166. }else{
  3167. if($this->debug>2){error_log('New LP - Problem in update_default_scorm_commit() - could not find LP '.$this->get_id().' in DB',0);}
  3168. }
  3169. return -1;
  3170. }
  3171. /**
  3172. * Updates the order of learning paths (goes through all of them by order and fills the gaps)
  3173. * @return bool True on success, false on failure
  3174. */
  3175. function update_display_order()
  3176. {
  3177. $lp_table = Database::get_course_table(TABLE_LP_MAIN);
  3178. $sql = "SELECT * FROM $lp_table ORDER BY display_order";
  3179. $res = api_sql_query($sql, __FILE__, __LINE__);
  3180. if($res === false) return false;
  3181. $lps = array();
  3182. $lp_order = array();
  3183. $num = Database::num_rows($res);
  3184. //first check the order is correct, globally (might be wrong because
  3185. //of versions < 1.8.4)
  3186. if($num>0)
  3187. {
  3188. $i = 1;
  3189. while($row = Database::fetch_array($res))
  3190. {
  3191. if($row['display_order'] != $i)
  3192. { //if we find a gap in the order, we need to fix it
  3193. $need_fix = true;
  3194. $sql_u = "UPDATE $lp_table SET display_order = $i WHERE id = ".$row['id'];
  3195. $res_u = api_sql_query($sql_u, __FILE__, __LINE__);
  3196. }
  3197. $i++;
  3198. }
  3199. }
  3200. return true;
  3201. }
  3202. /**
  3203. * Updates the "prevent_reinit" value that enables control on reinitialising items on second view
  3204. * @return boolean True if prevent_reinit has been set to 'on', false otherwise (or 1 or 0 in this case)
  3205. */
  3206. function update_reinit(){
  3207. if($this->debug>0){error_log('New LP - In learnpath::update_reinit()',0);}
  3208. $lp_table = Database::get_course_table('lp');
  3209. $sql = "SELECT * FROM $lp_table WHERE id = ".$this->get_id();
  3210. $res = api_sql_query($sql, __FILE__, __LINE__);
  3211. if(Database::num_rows($res)>0){
  3212. $row = Database::fetch_array($res);
  3213. $force = $row['prevent_reinit'];
  3214. if($force == 1){
  3215. $force = 0;
  3216. }elseif($force == 0){
  3217. $force = 1;
  3218. }
  3219. $sql = "UPDATE $lp_table SET prevent_reinit = $force WHERE id = ".$this->get_id();
  3220. $res = api_sql_query($sql,__FILE__,__LINE__);
  3221. $this->prevent_reinit = $force;
  3222. return $force;
  3223. }else{
  3224. if($this->debug>2){error_log('New LP - Problem in update_reinit() - could not find LP '.$this->get_id().' in DB',0);}
  3225. }
  3226. return -1;
  3227. }
  3228. /**
  3229. * Updates the "scorm_debug" value that shows or hide the debug window
  3230. * @return boolean True if scorm_debug has been set to 'on', false otherwise (or 1 or 0 in this case)
  3231. */
  3232. function update_scorm_debug(){
  3233. if($this->debug>0){error_log('New LP - In learnpath::update_scorm_debug()',0);}
  3234. $lp_table = Database::get_course_table('lp');
  3235. $sql = "SELECT * FROM $lp_table WHERE id = ".$this->get_id();
  3236. $res = api_sql_query($sql, __FILE__, __LINE__);
  3237. if(Database::num_rows($res)>0){
  3238. $row = Database::fetch_array($res);
  3239. $force = $row['debug'];
  3240. if($force == 1){
  3241. $force = 0;
  3242. }elseif($force == 0){
  3243. $force = 1;
  3244. }
  3245. $sql = "UPDATE $lp_table SET debug = $force WHERE id = ".$this->get_id();
  3246. $res = api_sql_query($sql,__FILE__,__LINE__);
  3247. $this->scorm_debug = $force;
  3248. return $force;
  3249. }else{
  3250. if($this->debug>2){error_log('New LP - Problem in update_scorm_debug() - could not find LP '.$this->get_id().' in DB',0);}
  3251. }
  3252. return -1;
  3253. }
  3254. /**
  3255. * Function that makes a call to the function sort_tree_array and create_tree_array
  3256. *
  3257. * @author Kevin Van Den Haute
  3258. *
  3259. * @param unknown_type $array
  3260. */
  3261. function tree_array($array)
  3262. {
  3263. $array = $this->sort_tree_array($array);
  3264. $this->create_tree_array($array);
  3265. }
  3266. /**
  3267. * Creates an array with the elements of the learning path tree in it
  3268. *
  3269. * @author Kevin Van Den Haute
  3270. *
  3271. * @param array $array
  3272. * @param int $parent
  3273. * @param int $depth
  3274. * @param array $tmp
  3275. */
  3276. function create_tree_array($array, $parent = 0, $depth = -1, $tmp = array())
  3277. {
  3278. if(is_array($array))
  3279. {
  3280. for($i = 0; $i < count($array); $i++)
  3281. {
  3282. if($array[$i]['parent_item_id'] == $parent)
  3283. {
  3284. if(!in_array($array[$i]['parent_item_id'], $tmp))
  3285. {
  3286. $tmp[] = $array[$i]['parent_item_id'];
  3287. $depth++;
  3288. }
  3289. $this->arrMenu[] = array(
  3290. 'id' => $array[$i]['id'],
  3291. 'item_type' => $array[$i]['item_type'],
  3292. 'title' => $array[$i]['title'],
  3293. 'path' => $array[$i]['path'],
  3294. 'description' => $array[$i]['description'],
  3295. 'parent_item_id' => $array[$i]['parent_item_id'],
  3296. 'previous_item_id' => $array[$i]['previous_item_id'],
  3297. 'next_item_id' => $array[$i]['next_item_id'],
  3298. 'min_score' => $array[$i]['min_score'],
  3299. 'max_score' => $array[$i]['max_score'],
  3300. 'mastery_score' => $array[$i]['mastery_score'],
  3301. 'display_order' => $array[$i]['display_order'],
  3302. 'prerequisite' => $array[$i]['prerequisite'],
  3303. 'depth' => $depth
  3304. );
  3305. $this->create_tree_array($array, $array[$i]['id'], $depth, $tmp);
  3306. }
  3307. }
  3308. }
  3309. }
  3310. /**
  3311. * Sorts a multi dimensional array by parent id and display order
  3312. * @author Kevin Van Den Haute
  3313. *
  3314. * @param array $array (array with al the learning path items in it)
  3315. *
  3316. * @return array
  3317. */
  3318. function sort_tree_array($array)
  3319. {
  3320. foreach($array as $key => $row)
  3321. {
  3322. $parent[$key] = $row['parent_item_id'];
  3323. $position[$key] = $row['display_order'];
  3324. }
  3325. if(count($array) > 0)
  3326. array_multisort($parent, SORT_ASC, $position, SORT_ASC, $array);
  3327. return $array;
  3328. }
  3329. /**
  3330. * Function that creates a table structure with a learning path his modules, chapters and documents.
  3331. * Also the actions for the modules, chapters and documents are in this table.
  3332. *
  3333. * @author Kevin Van Den Haute
  3334. *
  3335. * @param int $lp_id
  3336. *
  3337. * @return string
  3338. */
  3339. function overview()
  3340. {
  3341. $return = '';
  3342. $tbl_lp_item = Database::get_course_table('lp_item');
  3343. $sql = "
  3344. SELECT *
  3345. FROM " . $tbl_lp_item . "
  3346. WHERE
  3347. lp_id = " . $this->lp_id;
  3348. $result = api_sql_query($sql, __FILE__, __LINE__);
  3349. $arrLP = array();
  3350. while($row = Database::fetch_array($result))
  3351. {
  3352. $arrLP[] = array(
  3353. 'id' => $row['id'],
  3354. 'item_type' => $row['item_type'],
  3355. 'title' => stripslashes(html_entity_decode($row['title'])),
  3356. 'description' => $row['description'],
  3357. 'parent_item_id' => $row['parent_item_id'],
  3358. 'previous_item_id' => $row['previous_item_id'],
  3359. 'next_item_id' => $row['next_item_id'],
  3360. 'display_order' => $row['display_order']);
  3361. }
  3362. $this->tree_array($arrLP);
  3363. $arrLP = $this->arrMenu;
  3364. unset($this->arrMenu);
  3365. if(api_is_allowed_to_edit())
  3366. $return .= '<p><a href="' .api_get_self(). '?cidReq=' . $_GET['cidReq'] . '&amp;action=build&amp;lp_id=' . $this->lp_id . '">'.get_lang("Advanced").'</a>&nbsp;&#124;&nbsp;'.get_lang("BasicOverview").'&nbsp;&#124;&nbsp;<a href="lp_controller.php?cidReq='.$_GET['cidReq'].'&action=view&lp_id='.$this->lp_id.'">'.get_lang("Display").'</a></p>';
  3367. $return .= '<table class="data_table">' . "\n";
  3368. $return .= "\t" . '<tr>' . "\n";
  3369. $return .= "\t" . '<th width="75%">'.get_lang("Title").'</th>' . "\n";
  3370. //$return .= "\t" . '<th>'.get_lang("Description").'</th>' . "\n";
  3371. $return .= "\t" . '<th>'.get_lang("Move").'</th>' . "\n";
  3372. $return .= "\t" . '<th>'.get_lang("Actions").'</th>' . "\n";
  3373. $return .= "\t" . '</tr>' . "\n";
  3374. for($i = 0; $i < count($arrLP); $i++)
  3375. {
  3376. if($arrLP[$i]['description'] == '')
  3377. $arrLP[$i]['description'] = '&nbsp;';
  3378. if (($i % 2)==0) { $oddclass="row_odd"; } else { $oddclass="row_even"; }
  3379. $return .= "\t" . '<tr class="'.$oddclass.'">' . "\n";
  3380. $return .= "\t\t" . '<td style="padding-left:' . $arrLP[$i]['depth'] * 10 . 'px;"><img align="left" src="../img/lp_' . $arrLP[$i]['item_type'] . '.png" style="margin-right:3px;" />' . stripslashes($arrLP[$i]['title']) . '</td>' . "\n";
  3381. //$return .= "\t\t" . '<td>' . stripslashes($arrLP[$i]['description']) . '</td>' . "\n";
  3382. if(api_is_allowed_to_edit())
  3383. {
  3384. $return .= "\t\t" . '<td>' . "\n";
  3385. if($arrLP[$i]['previous_item_id'] != 0)
  3386. {
  3387. $return .= "\t\t\t" . '<a href="' .api_get_self(). '?cidReq=' . $_GET['cidReq'] . '&amp;action=move_item&amp;direction=up&amp;id=' . $arrLP[$i]['id'] . '&amp;lp_id=' . $this->lp_id . '">';
  3388. $return .= '<img alt="" src="../img/arrow_up_' . ($arrLP[$i]['depth'] % 3) . '.gif" />';
  3389. $return .= '</a>' . "\n";
  3390. }
  3391. else
  3392. $return .= "\t\t\t" . '<img alt="" src="../img/blanco.png" title="" />' . "\n";
  3393. if($arrLP[$i]['next_item_id'] != 0)
  3394. {
  3395. $return .= "\t\t\t" . '<a href="' .api_get_self(). '?cidReq=' . $_GET['cidReq'] . '&amp;action=move_item&amp;direction=down&amp;id=' . $arrLP[$i]['id'] . '&amp;lp_id=' . $this->lp_id . '">';
  3396. $return .= '<img src="../img/arrow_down_' . ($arrLP[$i]['depth'] % 3) . '.gif" />';
  3397. $return .= '</a>' . "\n";
  3398. }
  3399. else
  3400. $return .= "\t\t\t" . '<img alt="" src="../img/blanco.png" title="" />' . "\n";
  3401. $return .= "\t\t" . '</td>' . "\n";
  3402. $return .= "\t\t" . '<td>' . "\n";
  3403. if($arrLP[$i]['item_type'] != 'dokeos_chapter' && $arrLP[$i]['item_type'] != 'dokeos_module')
  3404. {
  3405. $return .= "\t\t\t" . '<a href="' .api_get_self(). '?cidReq=' . $_GET['cidReq'] . '&amp;action=edit_item&amp;view=build&amp;id=' . $arrLP[$i]['id'] . '&amp;lp_id=' . $this->lp_id . '">';
  3406. $return .= '<img alt="" src="../img/edit.gif" title="' . get_lang('_edit_learnpath_module') . '" />';
  3407. $return .= '</a>' . "\n";
  3408. }
  3409. else
  3410. {
  3411. $return .= "\t\t\t" . '<a href="' .api_get_self(). '?cidReq=' . $_GET['cidReq'] . '&amp;action=edit_item&amp;id=' . $arrLP[$i]['id'] . '&amp;lp_id=' . $this->lp_id . '">';
  3412. $return .= '<img alt="" src="../img/edit.gif" title="' . get_lang('_edit_learnpath_module') . '" />';
  3413. $return .= '</a>' . "\n";
  3414. }
  3415. $return .= "\t\t\t" . '<a href="' .api_get_self(). '?cidReq=' . $_GET['cidReq'] . '&amp;action=delete_item&amp;id=' . $arrLP[$i]['id'] . '&amp;lp_id=' . $this->lp_id . '" onclick="return confirmation(\'' . $arrLP[$i]['title'] . '\');">';
  3416. $return .= '<img alt="" src="../img/delete.gif" title="' . get_lang('_delete_learnpath_module') . '" />';
  3417. $return .= '</a>' . "\n";
  3418. $return .= "\t\t" . '</td>' . "\n";
  3419. }
  3420. $return .= "\t" . '</tr>' . "\n";
  3421. }
  3422. if(count($arrLP) == 0)
  3423. {
  3424. $return .= "\t" . '<tr>' . "\n";
  3425. $return .= "\t\t" . '<td colspan="4">'.get_lang("NoItemsInLp").'</td>' . "\n";
  3426. $return .= "\t" . '</tr>' . "\n";
  3427. }
  3428. $return .= '</table>' . "\n";
  3429. return $return;
  3430. }
  3431. /**
  3432. * This functions builds the LP tree based on data from the database.
  3433. *
  3434. * @return string
  3435. * @uses dtree.js :: necessary javascript for building this tree
  3436. */
  3437. function build_tree()
  3438. {
  3439. $return = "<script type=\"text/javascript\">\n";
  3440. $return .= "\tm = new dTree('m');\n\n";
  3441. $return .= "\tm.config.folderLinks = true;\n";
  3442. $return .= "\tm.config.useCookies = true;\n";
  3443. $return .= "\tm.config.useIcons = true;\n";
  3444. $return .= "\tm.config.useLines = true;\n";
  3445. $return .= "\tm.config.useSelection = true;\n";
  3446. $return .= "\tm.config.useStatustext = false;\n\n";
  3447. $menu = 0;
  3448. $parent = '';
  3449. $return .= "\tm.add(" . $menu . ", -1, '" . addslashes($this->name) . "');\n";
  3450. $tbl_lp_item = Database::get_course_table('lp_item');
  3451. $sql = "
  3452. SELECT *
  3453. FROM " . $tbl_lp_item . "
  3454. WHERE
  3455. lp_id = " . $this->lp_id;
  3456. $result = api_sql_query($sql, __FILE__, __LINE__);
  3457. $arrLP = array();
  3458. while($row = Database::fetch_array($result))
  3459. {
  3460. if($this->encoding=='UTF-8')
  3461. {
  3462. $row['title'] = utf8_decode($row['title']);
  3463. }
  3464. $arrLP[] = array(
  3465. 'id' => $row['id'],
  3466. 'item_type' => $row['item_type'],
  3467. 'title' => $row['title'],
  3468. 'path' => $row['path'],
  3469. 'description' => $row['description'],
  3470. 'parent_item_id' => $row['parent_item_id'],
  3471. 'previous_item_id' => $row['previous_item_id'],
  3472. 'next_item_id' => $row['next_item_id'],
  3473. 'display_order' => $row['display_order']);
  3474. }
  3475. $this->tree_array($arrLP);
  3476. $arrLP = $this->arrMenu;
  3477. unset($this->arrMenu);
  3478. $title='';
  3479. for($i = 0; $i < count($arrLP); $i++)
  3480. {
  3481. $title=html_entity_decode($arrLP[$i]['title']);
  3482. $menu_page = api_get_self() . '?cidReq=' . $_GET['cidReq'] . '&amp;action=view_item&amp;id=' . $arrLP[$i]['id'] . '&amp;lp_id=' . $_SESSION['oLP']->lp_id;
  3483. if(file_exists("../img/lp_" . $arrLP[$i]['item_type'] . ".png"))
  3484. {
  3485. $return .= "\tm.add(" . $arrLP[$i]['id'] . ", " . $arrLP[$i]['parent_item_id'] . ", '" . $title . "', '" . $menu_page . "', '', '', '../img/lp_" . $arrLP[$i]['item_type'] . ".png', '../img/lp_" . $arrLP[$i]['item_type'] . ".png');\n";
  3486. }
  3487. else if(file_exists("../img/lp_" . $arrLP[$i]['item_type'] . ".gif"))
  3488. {
  3489. $return .= "\tm.add(" . $arrLP[$i]['id'] . ", " . $arrLP[$i]['parent_item_id'] . ", '" . $title . "', '" . $menu_page . "', '', '', '../img/lp_" . $arrLP[$i]['item_type'] . ".gif', '../img/lp_" . $arrLP[$i]['item_type'] . ".gif');\n";
  3490. }
  3491. else
  3492. {
  3493. $return .= "\tm.add(" . $arrLP[$i]['id'] . ", " . $arrLP[$i]['parent_item_id'] . ", '" . $title . "', '" . $menu_page . "', '', '', '../img/lp_document.png', '../img/lp_document.png');\n";
  3494. }
  3495. if($menu < $arrLP[$i]['id'])
  3496. $menu = $arrLP[$i]['id'];
  3497. }
  3498. $return .= "\n\tdocument.write(m);\n";
  3499. $return .= "\t if(!m.selectedNode) m.s(1);";
  3500. $return .= "</script>\n";
  3501. return $return;
  3502. }
  3503. /**
  3504. * Create a new document //still needs some finetuning
  3505. *
  3506. * @param array $_course
  3507. * @return string
  3508. */
  3509. function create_document($_course)
  3510. {
  3511. $dir = isset($_GET['dir']) ? $_GET['dir'] : $_POST['dir']; // please do not modify this dirname formatting
  3512. if(strstr($dir, '..'))
  3513. $dir = '/';
  3514. if($dir[0] == '.')
  3515. $dir = substr($dir, 1);
  3516. if($dir[0] != '/')
  3517. $dir = '/'.$dir;
  3518. if($dir[strlen($dir) - 1] != '/')
  3519. $dir .= '/';
  3520. $filepath = api_get_path('SYS_COURSE_PATH') . $_course['path'] . '/document' . $dir;
  3521. if(!is_dir($filepath))
  3522. {
  3523. $filepath = api_get_path('SYS_COURSE_PATH') . $_course['path'] . '/document/';
  3524. $dir = '/';
  3525. }
  3526. //stripslashes before calling replace_dangerous_char() because $_POST['title']
  3527. //is already escaped twice when it gets here
  3528. $title = replace_dangerous_char(stripslashes($_POST['title']));
  3529. $filename = $title;
  3530. $content = $_POST['content_lp'];
  3531. $tmp_filename = $filename;
  3532. $i=0;
  3533. while(file_exists($filepath . $tmp_filename . '.html'))
  3534. $tmp_filename = $filename . '_' . ++$i;
  3535. $filename = $tmp_filename . '.html';
  3536. $content = stripslashes(text_filter($content));
  3537. //if flv player, change absolute paht temporarely to prevent from erasing it in the following lines
  3538. $content = str_replace('flv=h','flv=h|',$content);
  3539. $content = str_replace('flv=/','flv=/|',$content);
  3540. $content = str_replace(api_get_path('WEB_COURSE_PATH'), api_get_path(REL_PATH).'courses/', $content);
  3541. // for flv player : change back the url to absolute
  3542. $content = str_replace('flv=h|','flv=h',$content);
  3543. $content = str_replace('flv=/|','flv=/',$content);
  3544. // for flv player : to prevent edition problem with firefox, we have to use a strange tip (don't blame me please)
  3545. $content = str_replace('</body>','<style type="text/css">body{}</style></body>',$content);
  3546. if(!file_exists($filepath . $filename))
  3547. {
  3548. if($fp = @fopen($filepath . $filename, 'w'))
  3549. {
  3550. fputs($fp, $content);
  3551. fclose($fp);
  3552. $file_size = filesize($filepath . $filename);
  3553. $save_file_path = $dir . $filename;
  3554. $document_id = add_document($_course, $save_file_path, 'file', $file_size, $filename . '.html');
  3555. if($document_id)
  3556. {
  3557. api_item_property_update($_course, TOOL_DOCUMENT, $document_id, 'DocumentAdded', api_get_user_id());
  3558. //update parent folders
  3559. //item_property_update_on_folder($_course, $_GET['dir'], $_user['user_id']);
  3560. $new_comment = (isset($_POST['comment'])) ? trim($_POST['comment']) : '';
  3561. $new_title = (isset($_POST['title'])) ? trim($_POST['title']) : '';
  3562. if($new_comment || $new_title)
  3563. {
  3564. $tbl_doc = Database::get_course_table(TABLE_DOCUMENT);
  3565. $ct = '';
  3566. if($new_comment)
  3567. $ct .= ", comment='" . $new_comment . "'";
  3568. if($new_title)
  3569. $ct .= ", title='" . $new_title . ".html '";
  3570. $sql_update = "
  3571. UPDATE " . $tbl_doc . "
  3572. SET " . substr($ct, 1) . "
  3573. WHERE id = " . $document_id;
  3574. api_sql_query($sql_update, __FILE__, __LINE__);
  3575. }
  3576. }
  3577. return $document_id;
  3578. }
  3579. }
  3580. }
  3581. /**
  3582. * Enter description here...
  3583. *
  3584. * @param array $_course
  3585. */
  3586. function edit_document($_course)
  3587. {
  3588. global $_configuration;
  3589. $dir = isset($_GET['dir']) ? $_GET['dir'] : $_POST['dir']; // please do not modify this dirname formatting
  3590. if(strstr($dir, '..'))
  3591. $dir = '/';
  3592. if($dir[0] == '.')
  3593. $dir = substr($dir, 1);
  3594. if($dir[0] != '/')
  3595. $dir = '/'.$dir;
  3596. if($dir[strlen($dir) - 1] != '/')
  3597. $dir .= '/';
  3598. $filepath = api_get_path('SYS_COURSE_PATH') . $_course['path'] . '/document'.$dir;
  3599. if(!is_dir($filepath))
  3600. {
  3601. $filepath = api_get_path('SYS_COURSE_PATH') . $_course['path'] . '/document/';
  3602. $dir = '/';
  3603. }
  3604. $table_doc = Database::get_course_table(TABLE_DOCUMENT);
  3605. $sql = "
  3606. SELECT path
  3607. FROM " . $table_doc . "
  3608. WHERE id = " . $_POST['path'];
  3609. $res = api_sql_query($sql, __FILE__, __LINE__);
  3610. $row = Database::fetch_array($res);
  3611. $content = stripslashes($_POST['content_lp']);
  3612. $file = $filepath . $row['path'];
  3613. if($fp = @fopen($file, 'w'))
  3614. {
  3615. $content = text_filter($content);
  3616. $content = str_replace(api_get_path('WEB_COURSE_PATH'), $_configuration['url_append'].'/courses/', $content);
  3617. fputs($fp, $content);
  3618. fclose($fp);
  3619. }
  3620. }
  3621. /**
  3622. * Displays the selected item, with a panel for manipulating the item
  3623. *
  3624. * @param int $item_id
  3625. * @param string $msg
  3626. * @return string
  3627. */
  3628. function display_item($item_id, $iframe = true, $msg = '')
  3629. {
  3630. global $_course; //will disappear
  3631. $return = '';
  3632. if(is_numeric($item_id))
  3633. {
  3634. $tbl_lp_item = Database::get_course_table('lp_item');
  3635. $tbl_doc = Database::get_course_table(TABLE_DOCUMENT);
  3636. $sql = "
  3637. SELECT
  3638. lp.*
  3639. FROM " . $tbl_lp_item . " as lp
  3640. WHERE
  3641. lp.id = " . $item_id;
  3642. $result = api_sql_query($sql, __FILE__, __LINE__);
  3643. while($row = Database::fetch_array($result))
  3644. {
  3645. $return .= $this->display_manipulate($item_id, $row['item_type']);
  3646. $return .= '<div style="padding:10px;">';
  3647. if($msg != '')
  3648. $return .= $msg;
  3649. if($this->encoding=='UTF-8')
  3650. {
  3651. $row['title'] = utf8_decode($row['title']);
  3652. }
  3653. $return .= '<p class="lp_title">' . stripslashes($row['title']) . '</p>';
  3654. //$return .= '<p class="lp_text">' . ((trim($row['description']) == '') ? 'no description' : stripslashes($row['description'])) . '</p>';
  3655. //$return .= '<hr />';
  3656. if($row['item_type'] == TOOL_DOCUMENT)
  3657. {
  3658. $tbl_doc = Database :: get_course_table(TABLE_DOCUMENT);
  3659. $sql_doc = "SELECT path FROM " . $tbl_doc . " WHERE id = " . $row['path'];
  3660. $result=api_sql_query($sql_doc, __FILE__, __LINE__);
  3661. $path_file=mysql_result($result,0,0);
  3662. $path_parts = pathinfo($path_file);
  3663. if(in_array($path_parts['extension'],array('html','txt','png', 'jpg', 'JPG', 'jpeg', 'JPEG', 'gif', 'swf')))
  3664. {
  3665. $return .= $this->display_document($row['path'], true, true);
  3666. }
  3667. }
  3668. $return .= '</div>';
  3669. }
  3670. }
  3671. return $return;
  3672. }
  3673. /**
  3674. * Shows the needed forms for editing a specific item
  3675. *
  3676. * @param int $item_id
  3677. * @return string
  3678. */
  3679. function display_edit_item($item_id)
  3680. {
  3681. global $_course; //will disappear
  3682. $return = '';
  3683. if(is_numeric($item_id))
  3684. {
  3685. $tbl_lp_item = Database::get_course_table('lp_item');
  3686. $sql = "
  3687. SELECT *
  3688. FROM " . $tbl_lp_item . "
  3689. WHERE id = " . $item_id;
  3690. $res = api_sql_query($sql, __FILE__, __LINE__);
  3691. $row = Database::fetch_array($res);
  3692. switch($row['item_type'])
  3693. {
  3694. case 'dokeos_chapter': case 'dir' : case 'asset' : case 'sco' :
  3695. if(isset($_GET['view']) && $_GET['view'] == 'build')
  3696. {
  3697. $return .= $this->display_manipulate($item_id, $row['item_type']);
  3698. $return .= $this->display_item_form($row['item_type'], get_lang("EditCurrentChapter").' :', 'edit', $item_id, $row);
  3699. }
  3700. else
  3701. {
  3702. $return .= $this->display_item_small_form($row['item_type'], get_lang("EditCurrentChapter").' :', $row);
  3703. }
  3704. break;
  3705. case TOOL_DOCUMENT:
  3706. $tbl_doc = Database::get_course_table(TABLE_DOCUMENT);
  3707. $sql_step = "
  3708. SELECT
  3709. lp.*,
  3710. doc.path as dir
  3711. FROM " . $tbl_lp_item . " as lp
  3712. LEFT JOIN " . $tbl_doc . " as doc ON doc.id = lp.path
  3713. WHERE
  3714. lp.id = " . $item_id;
  3715. $res_step = api_sql_query($sql_step, __FILE__, __LINE__);
  3716. $row_step = Database::fetch_array($res_step);
  3717. $return .= $this->display_manipulate($item_id, $row['item_type']);
  3718. $return .= $this->display_document_form('edit', $item_id, $row_step);
  3719. break;
  3720. case TOOL_LINK:
  3721. $return .= $this->display_manipulate($item_id, $row['item_type']);
  3722. $return .= $this->display_link_form('edit', $item_id, $row);
  3723. break;
  3724. case 'dokeos_module':
  3725. if(isset($_GET['view']) && $_GET['view'] == 'build')
  3726. {
  3727. $return .= $this->display_manipulate($item_id, $row['item_type']);
  3728. $return .= $this->display_item_form($row['item_type'], get_lang("EditCurrentModule").' :', 'edit', $item_id, $row);
  3729. }
  3730. else
  3731. {
  3732. $return .= $this->display_item_small_form($row['item_type'], get_lang("EditCurrentModule").' :', $row);
  3733. }
  3734. break;
  3735. case TOOL_QUIZ:
  3736. $return .= $this->display_manipulate($item_id, $row['item_type']);
  3737. $return .= $this->display_quiz_form('edit', $item_id, $row);
  3738. break;
  3739. case TOOL_HOTPOTATOES:
  3740. $return .= $this->display_manipulate($item_id, $row['item_type']);
  3741. $return .= $this->display_hotpotatoes_form('edit', $item_id, $row);
  3742. break;
  3743. case TOOL_STUDENTPUBLICATION:
  3744. $return .= $this->display_manipulate($item_id, $row['item_type']);
  3745. $return .= $this->display_student_publication_form('edit', $item_id, $row);
  3746. break;
  3747. case TOOL_FORUM:
  3748. $return .= $this->display_manipulate($item_id, $row['item_type']);
  3749. $return .= $this->display_forum_form('edit', $item_id, $row);
  3750. break;
  3751. case TOOL_THREAD:
  3752. $return .= $this->display_manipulate($item_id, $row['item_type']);
  3753. $return .= $this->display_thread_form('edit', $item_id, $row);
  3754. break;
  3755. }
  3756. }
  3757. return $return;
  3758. }
  3759. /**
  3760. * Function that displays a list with al the resources that could be added to the learning path
  3761. *
  3762. * @return string
  3763. */
  3764. function display_resources()
  3765. {
  3766. global $_course; //TODO: don't use globals
  3767. $return = '<div style="margin:3px 10px;">' . "\n";
  3768. $return .= '<p class="lp_title" style="margin-top:0;">'.get_lang("CreateNewStep").'</p>';
  3769. $return .= '<div><a href="' .api_get_self(). '?cidReq=' . $_GET['cidReq'] . '&amp;action=add_item&amp;type=' . TOOL_DOCUMENT . '&amp;lp_id=' . $_SESSION['oLP']->lp_id . '">'.get_lang("NewDocument").'</a></div>';
  3770. $return .= '<p class="lp_title" style="margin-top:10px;">'.get_lang("UseAnExistingResource").'</p>';
  3771. /* get all the docs */
  3772. $return .= $this->get_documents();
  3773. /* get all the exercises */
  3774. $return .= $this->get_exercises();
  3775. /* get all the links */
  3776. $return .= $this->get_links();
  3777. /* get al the student publications */
  3778. $return .= $this->get_student_publications();
  3779. /* get al the forums */
  3780. $return .= $this->get_forums();
  3781. $return .= '</div>' . "\n";
  3782. return $return;
  3783. }
  3784. /**
  3785. * Returns the extension of a document
  3786. *
  3787. * @param unknown_type $filename
  3788. * @return unknown
  3789. */
  3790. function get_extension($filename)
  3791. {
  3792. $explode = explode('.', $filename);
  3793. return $explode[count($explode) - 1];
  3794. }
  3795. /**
  3796. * Displays a document by id
  3797. *
  3798. * @param unknown_type $id
  3799. * @return unknown
  3800. */
  3801. function display_document($id, $show_title = false, $iframe = true, $edit_link = false)
  3802. {
  3803. global $_course; //temporary
  3804. $return = '';
  3805. $tbl_doc = Database::get_course_table(TABLE_DOCUMENT);
  3806. $sql_doc = "
  3807. SELECT *
  3808. FROM " . $tbl_doc . "
  3809. WHERE id = " . $id;
  3810. $res_doc = api_sql_query($sql_doc, __FILE__, __LINE__);
  3811. $row_doc = Database::fetch_array($res_doc);
  3812. //if($show_title)
  3813. //$return .= '<p class="lp_title">' . $row_doc['title'] . ($edit_link ? ' [ <a href="' .api_get_self(). '?cidReq=' . $_GET['cidReq'] . '&amp;action=add_item&amp;type=' . TOOL_DOCUMENT . '&amp;file=' . $_GET['file'] . '&amp;edit=true&amp;lp_id=' . $_GET['lp_id'] . '">Edit this document</a> ]' : '') . '</p>';
  3814. //TODO: add a path filter
  3815. if($iframe){
  3816. $return .= '<iframe frameborder="0" src="' . api_get_path(WEB_COURSE_PATH) . $_course['path'] . '/document' . str_replace('%2F','/',urlencode($row_doc['path'])) . '?'.api_get_cidreq().'" style="background:#FFFFFF; border:1px solid #CCCCCC; height:490px; width:100%; margin-top: 20px;"></iframe>';
  3817. }
  3818. else{
  3819. $return .= file_get_contents(api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document' . $row_doc['path']);
  3820. }
  3821. return $return;
  3822. }
  3823. /**
  3824. * Enter description here...
  3825. *
  3826. * @param unknown_type $action
  3827. * @param unknown_type $id
  3828. * @param unknown_type $extra_info
  3829. * @return unknown
  3830. */
  3831. function display_quiz_form($action = 'add', $id = 0, $extra_info = '')
  3832. {
  3833. $tbl_lp_item = Database::get_course_table(TABLE_LP_ITEM);
  3834. $tbl_quiz = Database::get_course_table(TABLE_QUIZ_TEST);
  3835. if($id != 0 && is_array($extra_info))
  3836. {
  3837. $item_title = stripslashes($extra_info['title']);
  3838. $item_description = stripslashes($extra_info['description']);
  3839. }
  3840. elseif(is_numeric($extra_info))
  3841. {
  3842. $sql_quiz = "
  3843. SELECT
  3844. title,
  3845. description
  3846. FROM " . $tbl_quiz . "
  3847. WHERE id = " . $extra_info;
  3848. $result = api_sql_query($sql_quiz, __FILE__, __LINE__);
  3849. $row = Database::fetch_array($result);
  3850. $item_title = $row['title'];
  3851. $item_description = $row['description'];
  3852. }
  3853. else
  3854. {
  3855. $item_title = '';
  3856. $item_description = '';
  3857. }
  3858. $return = '<div style="margin:3px 10px;">';
  3859. if($id != 0 && is_array($extra_info))
  3860. $parent = $extra_info['parent_item_id'];
  3861. else
  3862. $parent = 0;
  3863. $sql = "
  3864. SELECT *
  3865. FROM " . $tbl_lp_item . "
  3866. WHERE
  3867. lp_id = " . $this->lp_id;
  3868. $result = api_sql_query($sql, __FILE__, __LINE__);
  3869. $arrLP = array();
  3870. while($row = Database::fetch_array($result))
  3871. {
  3872. $arrLP[] = array(
  3873. 'id' => $row['id'],
  3874. 'item_type' => $row['item_type'],
  3875. 'title' => $row['title'],
  3876. 'path' => $row['path'],
  3877. 'description' => $row['description'],
  3878. 'parent_item_id' => $row['parent_item_id'],
  3879. 'previous_item_id' => $row['previous_item_id'],
  3880. 'next_item_id' => $row['next_item_id'],
  3881. 'display_order' => $row['display_order'],
  3882. 'prerequisite' => $row['prerequisite']);
  3883. }
  3884. $this->tree_array($arrLP);
  3885. $arrLP = $this->arrMenu;
  3886. unset($this->arrMenu);
  3887. if($action == 'add')
  3888. $return .= '<p class="lp_title">'.get_lang("CreateTheExercise").' :</p>' . "\n";
  3889. elseif($action == 'move')
  3890. $return .= '<p class="lp_title">'.get_lang("MoveTheCurrentExercise").' :</p>' . "\n";
  3891. else
  3892. $return .= '<p class="lp_title">'.get_lang("EditCurrentExecice").' :</p>' . "\n";
  3893. if(isset($_GET['edit']) && $_GET['edit'] == 'true')
  3894. {
  3895. $return .= '<div class="lp_message" style="margin-bottom:15px;">';
  3896. $return .= '<p class="lp_title">'.get_lang("Warning").' !</p>';
  3897. $return .= get_lang("WarningEditingDocument");
  3898. $return .= '</div>';
  3899. }
  3900. $return .= '<form method="POST">' . "\n";
  3901. $return .= "\t" . '<table cellpadding="0" cellspacing="0" class="lp_form">' . "\n";
  3902. $return .= "\t\t" . '<tr>' . "\n";
  3903. $return .= "\t\t\t" . '<td class="label"><label for="idParent">'.get_lang("Parent").' :</label></td>' . "\n";
  3904. $return .= "\t\t\t" . '<td class="input">' . "\n";
  3905. $return .= "\t\t\t\t" . '<select id="idParent" name="parent" onchange="load_cbo(this.value);" size="1">';
  3906. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
  3907. $arrHide = array($id);
  3908. for($i = 0; $i < count($arrLP); $i++)
  3909. {
  3910. if($action != 'add')
  3911. {
  3912. 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))
  3913. {
  3914. $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'] . '">' . html_entity_decode(stripslashes($arrLP[$i]['title'])) . '</option>';
  3915. }
  3916. else
  3917. {
  3918. $arrHide[] = $arrLP[$i]['id'];
  3919. }
  3920. }
  3921. else
  3922. {
  3923. if($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
  3924. $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'] . '">' . html_entity_decode(stripslashes($arrLP[$i]['title'])) . '</option>';
  3925. }
  3926. }
  3927. reset($arrLP);
  3928. $return .= "\t\t\t\t" . '</select>';
  3929. $return .= "\t\t\t" . '</td>' . "\n";
  3930. $return .= "\t\t" . '</tr>' . "\n";
  3931. $return .= "\t\t" . '<tr>' . "\n";
  3932. $return .= "\t\t\t" . '<td class="label"><label for="idPosition">'.get_lang("Position").' :</label></td>' . "\n";
  3933. $return .= "\t\t\t" . '<td class="input">' . "\n";
  3934. $return .= "\t\t\t\t" . '<select id="idPosition" name="previous" size="1">';
  3935. $return .= "\t\t\t\t\t" . '<option class="top" value="0">First position</option>';
  3936. for($i = 0; $i < count($arrLP); $i++)
  3937. {
  3938. if($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id)
  3939. {
  3940. if($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  3941. $selected = 'selected="selected" ';
  3942. elseif($action == 'add')
  3943. $selected = 'selected="selected" ';
  3944. else
  3945. $selected = '';
  3946. $return .= "\t\t\t\t\t" . '<option ' . $selected . 'value="' . $arrLP[$i]['id'] . '">'.get_lang("After").' "' . html_entity_decode(stripslashes($arrLP[$i]['title'])) . '"</option>';
  3947. }
  3948. }
  3949. $return .= "\t\t\t\t" . '</select>';
  3950. $return .= "\t\t\t" . '</td>' . "\n";
  3951. $return .= "\t\t" . '</tr>' . "\n";
  3952. if($action != 'move')
  3953. {
  3954. $return .= "\t\t" . '<tr>' . "\n";
  3955. $return .= "\t\t\t" . '<td class="label"><label for="idTitle">'.get_lang("Title").' :</label></td>' . "\n";
  3956. $return .= "\t\t\t" . '<td class="input"><input id="idTitle" name="title" type="text" value="' . $item_title . '" /></td>' . "\n";
  3957. $return .= "\t\t" . '</tr>' . "\n";
  3958. $id_prerequisite=0;
  3959. foreach($arrLP as $key=>$value){
  3960. if($value['id']==$id){
  3961. $id_prerequisite=$value['prerequisite'];
  3962. break;
  3963. }
  3964. }
  3965. $arrHide=array();
  3966. for($i = 0; $i < count($arrLP); $i++)
  3967. {
  3968. if($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter')
  3969. {
  3970. if($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  3971. $s_selected_position=$arrLP[$i]['id'];
  3972. elseif($action == 'add')
  3973. $s_selected_position=0;
  3974. $arrHide[$arrLP[$i]['id']]['value']=html_entity_decode(stripslashes($arrLP[$i]['title']));
  3975. }
  3976. }
  3977. $return .= "\t\t" . '<tr>' . "\n";
  3978. $return .= "\t\t\t" . '<td class="label"><label for="idPrerequisites">'.get_lang("Prerequisites").' :</label></td>' . "\n";
  3979. $return .= "\t\t\t" . '<td class="input"><select name="prerequisites" id="prerequisites" style="background:#F8F8F8; border:1px solid #999999; font-family:Arial, Verdana, Helvetica, sans-serif; font-size:12px; width:300px;"><option value="0">'.get_lang("NoPrerequisites").'</option>';
  3980. foreach($arrHide as $key => $value){
  3981. if($key==$s_selected_position && $action == 'add'){
  3982. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  3983. }
  3984. elseif($key==$id_prerequisite && $action == 'edit'){
  3985. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  3986. }
  3987. else{
  3988. $return .= '<option value="'.$key.'">'.$value['value'].'</option>';
  3989. }
  3990. }
  3991. $return .= "</select></td>";
  3992. $return .= "\t\t" . '</tr>' . "\n";
  3993. $return .= "\t\t" . '<tr>' . "\n";
  3994. //Remove temporaly the test description
  3995. //$return .= "\t\t\t" . '<td class="label"><label for="idDescription">'.get_lang("Description").' :</label></td>' . "\n";
  3996. //$return .= "\t\t\t" . '<td class="input"><textarea id="idDescription" name="description" rows="4">' . $item_description . '</textarea></td>' . "\n";
  3997. $return .= "\t\t" . '</tr>' . "\n";
  3998. }
  3999. $return .= "\t\t" . '<tr>' . "\n";
  4000. $return .= "\t\t\t" . '<td colspan="2"><input class="button" name="submit_button" type="submit" value="OK" /></td>' . "\n";
  4001. $return .= "\t\t" . '</tr>' . "\n";
  4002. $return .= "\t" . '</table>' . "\n";
  4003. if($action == 'move')
  4004. {
  4005. $return .= "\t" . '<input name="title" type="hidden" value="' . $item_title . '" />' . "\n";
  4006. $return .= "\t" . '<input name="description" type="hidden" value="' . $item_description . '" />' . "\n";
  4007. }
  4008. if(is_numeric($extra_info))
  4009. {
  4010. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info . '" />' . "\n";
  4011. }
  4012. elseif(is_array($extra_info))
  4013. {
  4014. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />' . "\n";
  4015. }
  4016. $return .= "\t" . '<input name="type" type="hidden" value="'.TOOL_QUIZ.'" />' . "\n";
  4017. $return .= "\t" . '<input name="post_time" type="hidden" value="' . time() . '" />' . "\n";
  4018. $return .= '</form>' . "\n";
  4019. $return .= '</div>' . "\n";
  4020. return $return;
  4021. }
  4022. /**
  4023. * Addition of Hotpotatoes tests
  4024. * @param string Action
  4025. * @param integer Internal ID of the item
  4026. * @param mixed Extra information - can be an array with title and description indexes
  4027. * @return string HTML structure to display the hotpotatoes addition formular
  4028. */
  4029. function display_hotpotatoes_form($action = 'add', $id = 0, $extra_info = '')
  4030. {
  4031. $uploadPath = DIR_HOTPOTATOES; //defined in main_api
  4032. $tbl_lp_item = Database::get_course_table('lp_item');
  4033. if($id != 0 && is_array($extra_info))
  4034. {
  4035. $item_title = stripslashes($extra_info['title']);
  4036. $item_description = stripslashes($extra_info['description']);
  4037. }
  4038. elseif(is_numeric($extra_info))
  4039. {
  4040. $TBL_DOCUMENT = Database::get_course_table(TABLE_DOCUMENT);
  4041. $sql_hot = "SELECT * FROM ".$TBL_DOCUMENT."
  4042. WHERE path LIKE '".$uploadPath."/%/%htm%'
  4043. ORDER BY id ASC";
  4044. $res_hot = api_sql_query($sql_hot, __FILE__, __LINE__);
  4045. $row = Database::fetch_array($res_hot);
  4046. $item_title = $row['title'];
  4047. $item_description = $row['description'];
  4048. }
  4049. else
  4050. {
  4051. $item_title = '';
  4052. $item_description = '';
  4053. }
  4054. $return = '<div style="margin:3px 10px;">';
  4055. if($id != 0 && is_array($extra_info))
  4056. $parent = $extra_info['parent_item_id'];
  4057. else
  4058. $parent = 0;
  4059. $sql = "
  4060. SELECT *
  4061. FROM " . $tbl_lp_item . "
  4062. WHERE
  4063. lp_id = " . $this->lp_id;
  4064. $result = api_sql_query($sql, __FILE__, __LINE__);
  4065. $arrLP = array();
  4066. while($row = Database::fetch_array($result))
  4067. {
  4068. $arrLP[] = array(
  4069. 'id' => $row['id'],
  4070. 'item_type' => $row['item_type'],
  4071. 'title' => $row['title'],
  4072. 'path' => $row['path'],
  4073. 'description' => $row['description'],
  4074. 'parent_item_id' => $row['parent_item_id'],
  4075. 'previous_item_id' => $row['previous_item_id'],
  4076. 'next_item_id' => $row['next_item_id'],
  4077. 'display_order' => $row['display_order'],
  4078. 'prerequisite' => $row['prerequisite']);
  4079. }
  4080. $this->tree_array($arrLP);
  4081. $arrLP = $this->arrMenu;
  4082. unset($this->arrMenu);
  4083. if($action == 'add')
  4084. $return .= '<p class="lp_title">'.get_lang("CreateTheExercise").' :</p>' . "\n";
  4085. elseif($action == 'move')
  4086. $return .= '<p class="lp_title">'.get_lang("MoveTheCurrentExercise").' :</p>' . "\n";
  4087. else
  4088. $return .= '<p class="lp_title">'.get_lang("EditCurrentExecice").' :</p>' . "\n";
  4089. if(isset($_GET['edit']) && $_GET['edit'] == 'true')
  4090. {
  4091. $return .= '<div class="lp_message" style="margin-bottom:15px;">';
  4092. $return .= '<p class="lp_title">'.get_lang("Warning").' !</p>';
  4093. $return .= get_lang("WarningEditingDocument");
  4094. $return .= '</div>';
  4095. }
  4096. $return .= '<form method="POST">' . "\n";
  4097. $return .= "\t" . '<table cellpadding="0" cellspacing="0" class="lp_form">' . "\n";
  4098. $return .= "\t\t" . '<tr>' . "\n";
  4099. $return .= "\t\t\t" . '<td class="label"><label for="idParent">'.get_lang("Parent").' :</label></td>' . "\n";
  4100. $return .= "\t\t\t" . '<td class="input">' . "\n";
  4101. $return .= "\t\t\t\t" . '<select id="idParent" name="parent" onchange="load_cbo(this.value);" size="1">';
  4102. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
  4103. $arrHide = array($id);
  4104. for($i = 0; $i < count($arrLP); $i++)
  4105. {
  4106. if($action != 'add')
  4107. {
  4108. 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))
  4109. {
  4110. $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'] . '">' . html_entity_decode(stripslashes($arrLP[$i]['title'])) . '</option>';
  4111. }
  4112. else
  4113. {
  4114. $arrHide[] = $arrLP[$i]['id'];
  4115. }
  4116. }
  4117. else
  4118. {
  4119. if($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
  4120. $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'] . '">' . html_entity_decode(stripslashes($arrLP[$i]['title'])) . '</option>';
  4121. }
  4122. }
  4123. reset($arrLP);
  4124. $return .= "\t\t\t\t" . '</select>';
  4125. $return .= "\t\t\t" . '</td>' . "\n";
  4126. $return .= "\t\t" . '</tr>' . "\n";
  4127. $return .= "\t\t" . '<tr>' . "\n";
  4128. $return .= "\t\t\t" . '<td class="label"><label for="idPosition">'.get_lang("Position").' :</label></td>' . "\n";
  4129. $return .= "\t\t\t" . '<td class="input">' . "\n";
  4130. $return .= "\t\t\t\t" . '<select id="idPosition" name="previous" size="1">';
  4131. $return .= "\t\t\t\t\t" . '<option class="top" value="0">First position</option>';
  4132. for($i = 0; $i < count($arrLP); $i++)
  4133. {
  4134. if($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id)
  4135. {
  4136. if($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  4137. $selected = 'selected="selected" ';
  4138. elseif($action == 'add')
  4139. $selected = 'selected="selected" ';
  4140. else
  4141. $selected = '';
  4142. $return .= "\t\t\t\t\t" . '<option ' . $selected . 'value="' . $arrLP[$i]['id'] . '">'.get_lang("After").' "' . html_entity_decode(stripslashes($arrLP[$i]['title'])) . '"</option>';
  4143. }
  4144. }
  4145. $return .= "\t\t\t\t" . '</select>';
  4146. $return .= "\t\t\t" . '</td>' . "\n";
  4147. $return .= "\t\t" . '</tr>' . "\n";
  4148. if($action != 'move')
  4149. {
  4150. $return .= "\t\t" . '<tr>' . "\n";
  4151. $return .= "\t\t\t" . '<td class="label"><label for="idTitle">'.get_lang("Title").' :</label></td>' . "\n";
  4152. $return .= "\t\t\t" . '<td class="input"><input id="idTitle" name="title" type="text" value="' . $item_title . '" /></td>' . "\n";
  4153. $return .= "\t\t" . '</tr>' . "\n";
  4154. $id_prerequisite=0;
  4155. foreach($arrLP as $key=>$value){
  4156. if($value['id']==$id){
  4157. $id_prerequisite=$value['prerequisite'];
  4158. break;
  4159. }
  4160. }
  4161. $arrHide=array();
  4162. for($i = 0; $i < count($arrLP); $i++)
  4163. {
  4164. if($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter')
  4165. {
  4166. if($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  4167. $s_selected_position=$arrLP[$i]['id'];
  4168. elseif($action == 'add')
  4169. $s_selected_position=0;
  4170. $arrHide[$arrLP[$i]['id']]['value']=html_entity_decode(stripslashes($arrLP[$i]['title']));
  4171. }
  4172. }
  4173. $return .= "\t\t" . '<tr>' . "\n";
  4174. $return .= "\t\t\t" . '<td class="label"><label for="idPrerequisites">'.get_lang("Prerequisites").' :</label></td>' . "\n";
  4175. $return .= "\t\t\t" . '<td class="input"><select name="prerequisites" id="prerequisites" style="background:#F8F8F8; border:1px solid #999999; font-family:Arial, Verdana, Helvetica, sans-serif; font-size:12px; width:300px;"><option value="0">'.get_lang("NoPrerequisites").'</option>';
  4176. foreach($arrHide as $key => $value){
  4177. if($key==$s_selected_position && $action == 'add'){
  4178. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  4179. }
  4180. elseif($key==$id_prerequisite && $action == 'edit'){
  4181. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  4182. }
  4183. else{
  4184. $return .= '<option value="'.$key.'">'.$value['value'].'</option>';
  4185. }
  4186. }
  4187. $return .= "</select></td>";
  4188. $return .= "\t\t" . '</tr>' . "\n";
  4189. $return .= "\t\t" . '<tr>' . "\n";
  4190. //Remove temporaly the test description
  4191. //$return .= "\t\t\t" . '<td class="label"><label for="idDescription">'.get_lang("Description").' :</label></td>' . "\n";
  4192. //$return .= "\t\t\t" . '<td class="input"><textarea id="idDescription" name="description" rows="4">' . $item_description . '</textarea></td>' . "\n";
  4193. $return .= "\t\t" . '</tr>' . "\n";
  4194. }
  4195. $return .= "\t\t" . '<tr>' . "\n";
  4196. $return .= "\t\t\t" . '<td colspan="2"><input class="button" name="submit_button" type="submit" value="OK" /></td>' . "\n";
  4197. $return .= "\t\t" . '</tr>' . "\n";
  4198. $return .= "\t" . '</table>' . "\n";
  4199. if($action == 'move')
  4200. {
  4201. $return .= "\t" . '<input name="title" type="hidden" value="' . $item_title . '" />' . "\n";
  4202. $return .= "\t" . '<input name="description" type="hidden" value="' . $item_description . '" />' . "\n";
  4203. }
  4204. if(is_numeric($extra_info))
  4205. {
  4206. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info . '" />' . "\n";
  4207. }
  4208. elseif(is_array($extra_info))
  4209. {
  4210. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />' . "\n";
  4211. }
  4212. $return .= "\t" . '<input name="type" type="hidden" value="'.TOOL_HOTPOTATOES.'" />' . "\n";
  4213. $return .= "\t" . '<input name="post_time" type="hidden" value="' . time() . '" />' . "\n";
  4214. $return .= '</form>' . "\n";
  4215. $return .= '</div>' . "\n";
  4216. return $return;
  4217. }
  4218. //fin du hotpot form
  4219. /**
  4220. * Enter description here...
  4221. *
  4222. * @param unknown_type $action
  4223. * @param unknown_type $id
  4224. * @param unknown_type $extra_info
  4225. * @return unknown
  4226. */
  4227. function display_forum_form($action = 'add', $id = 0, $extra_info = '')
  4228. {
  4229. $tbl_lp_item = Database::get_course_table('lp_item');
  4230. $tbl_forum = Database::get_course_table(TABLE_FORUM);
  4231. if($id != 0 && is_array($extra_info))
  4232. {
  4233. $item_title = stripslashes($extra_info['title']);
  4234. }
  4235. elseif(is_numeric($extra_info))
  4236. {
  4237. $sql_forum = "
  4238. SELECT
  4239. forum_title as title, forum_comment as comment
  4240. FROM " . $tbl_forum . "
  4241. WHERE forum_id = " . $extra_info;
  4242. $result = api_sql_query($sql_forum, __FILE__, __LINE__);
  4243. $row = Database::fetch_array($result);
  4244. $item_title = $row['title'];
  4245. $item_description = $row['comment'];
  4246. }
  4247. else
  4248. {
  4249. $item_title = '';
  4250. $item_description = '';
  4251. }
  4252. $return = '<div style="margin:3px 10px;">';
  4253. if($id != 0 && is_array($extra_info))
  4254. $parent = $extra_info['parent_item_id'];
  4255. else
  4256. $parent = 0;
  4257. $sql = "
  4258. SELECT *
  4259. FROM " . $tbl_lp_item . "
  4260. WHERE
  4261. lp_id = " . $this->lp_id;
  4262. $result = api_sql_query($sql, __FILE__, __LINE__);
  4263. $arrLP = array();
  4264. while($row = Database::fetch_array($result))
  4265. {
  4266. $arrLP[] = array(
  4267. 'id' => $row['id'],
  4268. 'item_type' => $row['item_type'],
  4269. 'title' => $row['title'],
  4270. 'path' => $row['path'],
  4271. 'description' => $row['description'],
  4272. 'parent_item_id' => $row['parent_item_id'],
  4273. 'previous_item_id' => $row['previous_item_id'],
  4274. 'next_item_id' => $row['next_item_id'],
  4275. 'display_order' => $row['display_order'],
  4276. 'prerequisite' => $row['prerequisite']);
  4277. }
  4278. $this->tree_array($arrLP);
  4279. $arrLP = $this->arrMenu;
  4280. unset($this->arrMenu);
  4281. if($action == 'add')
  4282. $return .= '<p class="lp_title">'.get_lang("CreateTheForum").' :</p>' . "\n";
  4283. elseif($action == 'move')
  4284. $return .= '<p class="lp_title">'.get_lang("MoveTheCurrentForum").' :</p>' . "\n";
  4285. else
  4286. $return .= '<p class="lp_title">'.get_lang("EditCurrentForum").' :</p>' . "\n";
  4287. $return .= '<form method="POST">' . "\n";
  4288. $return .= "\t" . '<table cellpadding="0" cellspacing="0" class="lp_form">' . "\n";
  4289. $return .= "\t\t" . '<tr>' . "\n";
  4290. $return .= "\t\t\t" . '<td class="label"><label for="idParent">'.get_lang("Parent").' :</label></td>' . "\n";
  4291. $return .= "\t\t\t" . '<td class="input">' . "\n";
  4292. $return .= "\t\t\t\t" . '<select id="idParent" name="parent" onchange="load_cbo(this.value);" size="1">';
  4293. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
  4294. $arrHide = array($id);
  4295. for($i = 0; $i < count($arrLP); $i++)
  4296. {
  4297. if($action != 'add')
  4298. {
  4299. 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))
  4300. {
  4301. $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'] . '">' . html_entity_decode(stripslashes($arrLP[$i]['title'])) . '</option>';
  4302. }
  4303. else
  4304. {
  4305. $arrHide[] = $arrLP[$i]['id'];
  4306. }
  4307. }
  4308. else
  4309. {
  4310. if($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
  4311. $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'] . '">' . html_entity_decode(stripslashes($arrLP[$i]['title'])) . '</option>';
  4312. }
  4313. }
  4314. reset($arrLP);
  4315. $return .= "\t\t\t\t" . '</select>';
  4316. $return .= "\t\t\t" . '</td>' . "\n";
  4317. $return .= "\t\t" . '</tr>' . "\n";
  4318. $return .= "\t\t" . '<tr>' . "\n";
  4319. $return .= "\t\t\t" . '<td class="label"><label for="idPosition">'.get_lang("Position").' :</label></td>' . "\n";
  4320. $return .= "\t\t\t" . '<td class="input">' . "\n";
  4321. $return .= "\t\t\t\t" . '<select id="idPosition" name="previous" size="1">';
  4322. $return .= "\t\t\t\t\t" . '<option class="top" value="0">First position</option>';
  4323. for($i = 0; $i < count($arrLP); $i++)
  4324. {
  4325. if($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id)
  4326. {
  4327. if($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  4328. $selected = 'selected="selected" ';
  4329. elseif($action == 'add')
  4330. $selected = 'selected="selected" ';
  4331. else
  4332. $selected = '';
  4333. $return .= "\t\t\t\t\t" . '<option ' . $selected . 'value="' . $arrLP[$i]['id'] . '">'.get_lang("After").' "' . html_entity_decode(stripslashes($arrLP[$i]['title'])) . '"</option>';
  4334. }
  4335. }
  4336. $return .= "\t\t\t\t" . '</select>';
  4337. $return .= "\t\t\t" . '</td>' . "\n";
  4338. $return .= "\t\t" . '</tr>' . "\n";
  4339. if($action != 'move')
  4340. {
  4341. $return .= "\t\t" . '<tr>' . "\n";
  4342. $return .= "\t\t\t" . '<td class="label"><label for="idTitle">'.get_lang("Title").' :</label></td>' . "\n";
  4343. $return .= "\t\t\t" . '<td class="input"><input id="idTitle" name="title" type="text" value="' . $item_title . '" /></td>' . "\n";
  4344. $return .= "\t\t" . '</tr>' . "\n";
  4345. $return .= "\t\t" . '<tr>' . "\n";
  4346. //Remove temporaly the test description
  4347. //$return .= "\t\t\t" . '<td class="label"><label for="idDescription">'.get_lang("Description").' :</label></td>' . "\n";
  4348. //$return .= "\t\t\t" . '<td class="input"><textarea id="idDescription" name="description" rows="4">' . $item_description . '</textarea></td>' . "\n";
  4349. $return .= "\t\t" . '</tr>' . "\n";
  4350. $id_prerequisite=0;
  4351. foreach($arrLP as $key=>$value){
  4352. if($value['id']==$id){
  4353. $id_prerequisite=$value['prerequisite'];
  4354. break;
  4355. }
  4356. }
  4357. $arrHide=array();
  4358. for($i = 0; $i < count($arrLP); $i++)
  4359. {
  4360. if($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter')
  4361. {
  4362. if($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  4363. $s_selected_position=$arrLP[$i]['id'];
  4364. elseif($action == 'add')
  4365. $s_selected_position=0;
  4366. $arrHide[$arrLP[$i]['id']]['value']=html_entity_decode(stripslashes($arrLP[$i]['title']));
  4367. }
  4368. }
  4369. $return .= "\t\t" . '<tr>' . "\n";
  4370. $return .= "\t\t\t" . '<td class="label"><label for="idPrerequisites">'.get_lang("Prerequisites").' :</label></td>' . "\n";
  4371. $return .= "\t\t\t" . '<td class="input"><select name="prerequisites" id="prerequisites" style="background:#F8F8F8; border:1px solid #999999; font-family:Arial, Verdana, Helvetica, sans-serif; font-size:12px; width:300px;"><option value="0">'.get_lang("NoPrerequisites").'</option>';
  4372. foreach($arrHide as $key => $value){
  4373. if($key==$s_selected_position && $action == 'add'){
  4374. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  4375. }
  4376. elseif($key==$id_prerequisite && $action == 'edit'){
  4377. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  4378. }
  4379. else{
  4380. $return .= '<option value="'.$key.'">'.$value['value'].'</option>';
  4381. }
  4382. }
  4383. $return .= "</select></td>";
  4384. $return .= "\t\t" . '</tr>' . "\n";
  4385. }
  4386. $return .= "\t\t" . '<tr>' . "\n";
  4387. $return .= "\t\t\t" . '<td colspan="2"><input class="button" name="submit_button" type="submit" value="OK" /></td>' . "\n";
  4388. $return .= "\t\t" . '</tr>' . "\n";
  4389. $return .= "\t" . '</table>' . "\n";
  4390. if($action == 'move')
  4391. {
  4392. $return .= "\t" . '<input name="title" type="hidden" value="' . $item_title . '" />' . "\n";
  4393. $return .= "\t" . '<input name="description" type="hidden" value="' . $item_description . '" />' . "\n";
  4394. }
  4395. if(is_numeric($extra_info))
  4396. {
  4397. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info . '" />' . "\n";
  4398. }
  4399. elseif(is_array($extra_info))
  4400. {
  4401. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />' . "\n";
  4402. }
  4403. $return .= "\t" . '<input name="type" type="hidden" value="'.TOOL_FORUM.'" />' . "\n";
  4404. $return .= "\t" . '<input name="post_time" type="hidden" value="' . time() . '" />' . "\n";
  4405. $return .= '</form>' . "\n";
  4406. $return .= '</div>' . "\n";
  4407. return $return;
  4408. }
  4409. function display_thread_form($action = 'add', $id = 0, $extra_info = '')
  4410. {
  4411. $tbl_lp_item = Database::get_course_table('lp_item');
  4412. $tbl_forum = Database::get_course_table(TABLE_FORUM_THREAD);
  4413. if($id != 0 && is_array($extra_info))
  4414. {
  4415. $item_title = stripslashes($extra_info['title']);
  4416. }
  4417. elseif(is_numeric($extra_info))
  4418. {
  4419. $sql_forum = "
  4420. SELECT
  4421. thread_title as title
  4422. FROM " . $tbl_forum . "
  4423. WHERE thread_id = " . $extra_info;
  4424. $result = api_sql_query($sql_forum, __FILE__, __LINE__);
  4425. $row = Database::fetch_array($result);
  4426. $item_title = $row['title'];
  4427. $item_description = '';
  4428. }
  4429. else
  4430. {
  4431. $item_title = '';
  4432. $item_description = '';
  4433. }
  4434. $return = '<div style="margin:3px 10px;">';
  4435. if($id != 0 && is_array($extra_info))
  4436. $parent = $extra_info['parent_item_id'];
  4437. else
  4438. $parent = 0;
  4439. $sql = "
  4440. SELECT *
  4441. FROM " . $tbl_lp_item . "
  4442. WHERE
  4443. lp_id = " . $this->lp_id;
  4444. $result = api_sql_query($sql, __FILE__, __LINE__);
  4445. $arrLP = array();
  4446. while($row = Database::fetch_array($result))
  4447. {
  4448. $arrLP[] = array(
  4449. 'id' => $row['id'],
  4450. 'item_type' => $row['item_type'],
  4451. 'title' => $row['title'],
  4452. 'path' => $row['path'],
  4453. 'description' => $row['description'],
  4454. 'parent_item_id' => $row['parent_item_id'],
  4455. 'previous_item_id' => $row['previous_item_id'],
  4456. 'next_item_id' => $row['next_item_id'],
  4457. 'display_order' => $row['display_order'],
  4458. 'prerequisite' => $row['prerequisite']);
  4459. }
  4460. $this->tree_array($arrLP);
  4461. $arrLP = $this->arrMenu;
  4462. unset($this->arrMenu);
  4463. if($action == 'add')
  4464. $return .= '<p class="lp_title">'.get_lang("CreateTheForum").' :</p>' . "\n";
  4465. elseif($action == 'move')
  4466. $return .= '<p class="lp_title">'.get_lang("MoveTheCurrentForum").' :</p>' . "\n";
  4467. else
  4468. $return .= '<p class="lp_title">'.get_lang("EditCurrentForum").' :</p>' . "\n";
  4469. $return .= '<form method="POST">' . "\n";
  4470. $return .= "\t" . '<table cellpadding="0" cellspacing="0" class="lp_form">' . "\n";
  4471. $return .= "\t\t" . '<tr>' . "\n";
  4472. $return .= "\t\t\t" . '<td class="label"><label for="idParent">'.get_lang("Parent").' :</label></td>' . "\n";
  4473. $return .= "\t\t\t" . '<td class="input">' . "\n";
  4474. $return .= "\t\t\t\t" . '<select id="idParent" name="parent" onchange="load_cbo(this.value);" size="1">';
  4475. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
  4476. $arrHide = array($id);
  4477. for($i = 0; $i < count($arrLP); $i++)
  4478. {
  4479. if($action != 'add')
  4480. {
  4481. 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))
  4482. {
  4483. $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'] . '">' . html_entity_decode(stripslashes($arrLP[$i]['title'])) . '</option>';
  4484. }
  4485. else
  4486. {
  4487. $arrHide[] = $arrLP[$i]['id'];
  4488. }
  4489. }
  4490. else
  4491. {
  4492. if($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
  4493. $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'] . '">' . html_entity_decode(stripslashes($arrLP[$i]['title'])) . '</option>';
  4494. }
  4495. }
  4496. reset($arrLP);
  4497. $return .= "\t\t\t\t" . '</select>';
  4498. $return .= "\t\t\t" . '</td>' . "\n";
  4499. $return .= "\t\t" . '</tr>' . "\n";
  4500. $return .= "\t\t" . '<tr>' . "\n";
  4501. $return .= "\t\t\t" . '<td class="label"><label for="idPosition">'.get_lang("Position").' :</label></td>' . "\n";
  4502. $return .= "\t\t\t" . '<td class="input">' . "\n";
  4503. $return .= "\t\t\t\t" . '<select id="idPosition" name="previous" size="1">';
  4504. $return .= "\t\t\t\t\t" . '<option class="top" value="0">First position</option>';
  4505. for($i = 0; $i < count($arrLP); $i++)
  4506. {
  4507. if($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id)
  4508. {
  4509. if($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  4510. $selected = 'selected="selected" ';
  4511. elseif($action == 'add')
  4512. $selected = 'selected="selected" ';
  4513. else
  4514. $selected = '';
  4515. $return .= "\t\t\t\t\t" . '<option ' . $selected . 'value="' . $arrLP[$i]['id'] . '">'.get_lang("After").' "' . html_entity_decode(stripslashes($arrLP[$i]['title'])) . '"</option>';
  4516. }
  4517. }
  4518. $return .= "\t\t\t\t" . '</select>';
  4519. $return .= "\t\t\t" . '</td>' . "\n";
  4520. $return .= "\t\t" . '</tr>' . "\n";
  4521. if($action != 'move')
  4522. {
  4523. $return .= "\t\t" . '<tr>' . "\n";
  4524. $return .= "\t\t\t" . '<td class="label"><label for="idTitle">'.get_lang("Title").' :</label></td>' . "\n";
  4525. $return .= "\t\t\t" . '<td class="input"><input id="idTitle" name="title" type="text" value="' . $item_title . '" /></td>' . "\n";
  4526. $return .= "\t\t" . '</tr>' . "\n";
  4527. $return .= "\t\t" . '<tr>' . "\n";
  4528. //Remove temporaly the test description
  4529. //$return .= "\t\t\t" . '<td class="label"><label for="idDescription">'.get_lang("Description").' :</label></td>' . "\n";
  4530. //$return .= "\t\t\t" . '<td class="input"><textarea id="idDescription" name="description" rows="4">' . $item_description . '</textarea></td>' . "\n";
  4531. $return .= "\t\t" . '</tr>' . "\n";
  4532. $id_prerequisite=0;
  4533. foreach($arrLP as $key=>$value){
  4534. if($value['id']==$id){
  4535. $id_prerequisite=$value['prerequisite'];
  4536. break;
  4537. }
  4538. }
  4539. $arrHide=array();
  4540. for($i = 0; $i < count($arrLP); $i++)
  4541. {
  4542. if($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter')
  4543. {
  4544. if($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  4545. $s_selected_position=$arrLP[$i]['id'];
  4546. elseif($action == 'add')
  4547. $s_selected_position=0;
  4548. $arrHide[$arrLP[$i]['id']]['value']=html_entity_decode(stripslashes($arrLP[$i]['title']));
  4549. }
  4550. }
  4551. $return .= "\t\t" . '<tr>' . "\n";
  4552. $return .= "\t\t\t" . '<td class="label"><label for="idPrerequisites">'.get_lang("Prerequisites").' :</label></td>' . "\n";
  4553. $return .= "\t\t\t" . '<td class="input"><select name="prerequisites" id="prerequisites" style="background:#F8F8F8; border:1px solid #999999; font-family:Arial, Verdana, Helvetica, sans-serif; font-size:12px; width:300px;"><option value="0">'.get_lang("NoPrerequisites").'</option>';
  4554. foreach($arrHide as $key => $value){
  4555. if($key==$s_selected_position && $action == 'add'){
  4556. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  4557. }
  4558. elseif($key==$id_prerequisite && $action == 'edit'){
  4559. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  4560. }
  4561. else{
  4562. $return .= '<option value="'.$key.'">'.$value['value'].'</option>';
  4563. }
  4564. }
  4565. $return .= "</select></td>";
  4566. $return .= "\t\t" . '</tr>' . "\n";
  4567. }
  4568. $return .= "\t\t" . '<tr>' . "\n";
  4569. $return .= "\t\t\t" . '<td colspan="2"><input class="button" name="submit_button" type="submit" value="OK" /></td>' . "\n";
  4570. $return .= "\t\t" . '</tr>' . "\n";
  4571. $return .= "\t" . '</table>' . "\n";
  4572. if($action == 'move')
  4573. {
  4574. $return .= "\t" . '<input name="title" type="hidden" value="' . $item_title . '" />' . "\n";
  4575. $return .= "\t" . '<input name="description" type="hidden" value="' . $item_description . '" />' . "\n";
  4576. }
  4577. if(is_numeric($extra_info))
  4578. {
  4579. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info . '" />' . "\n";
  4580. }
  4581. elseif(is_array($extra_info))
  4582. {
  4583. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />' . "\n";
  4584. }
  4585. $return .= "\t" . '<input name="type" type="hidden" value="'.TOOL_THREAD.'" />' . "\n";
  4586. $return .= "\t" . '<input name="post_time" type="hidden" value="' . time() . '" />' . "\n";
  4587. $return .= '</form>' . "\n";
  4588. $return .= '</div>' . "\n";
  4589. return $return;
  4590. }
  4591. /**
  4592. * Enter description here...
  4593. *
  4594. * @param unknown_type $item_type
  4595. * @param unknown_type $title
  4596. * @param unknown_type $action
  4597. * @param unknown_type $id
  4598. * @param unknown_type $extra_info
  4599. * @return unknown
  4600. */
  4601. function display_item_form($item_type, $title = '', $action = 'add', $id = 0, $extra_info = 'new')
  4602. {
  4603. global $_course;
  4604. $tbl_lp_item = Database::get_course_table('lp_item');
  4605. if($id != 0 && is_array($extra_info))
  4606. {
  4607. $item_title = stripslashes($extra_info['title']);
  4608. $item_description = stripslashes($extra_info['description']);
  4609. $item_path = api_get_path(WEB_COURSE_PATH) . $_course['path'].'/scorm/'.$this->path.'/'.stripslashes($extra_info['path']);
  4610. }
  4611. else
  4612. {
  4613. $item_title = '';
  4614. $item_description = '';
  4615. }
  4616. $return = '<div style="margin:3px 10px;">';
  4617. if($id != 0 && is_array($extra_info))
  4618. $parent = $extra_info['parent_item_id'];
  4619. else
  4620. $parent = 0;
  4621. $sql = "
  4622. SELECT *
  4623. FROM " . $tbl_lp_item . "
  4624. WHERE lp_id = " . $this->lp_id. " AND id != " . $id. " ";
  4625. if($item_type == 'module')
  4626. $sql .= " AND parent_item_id = 0";
  4627. $result = api_sql_query($sql, __FILE__, __LINE__);
  4628. $arrLP = array();
  4629. while($row = Database::fetch_array($result))
  4630. {
  4631. $arrLP[] = array(
  4632. 'id' => $row['id'],
  4633. 'item_type' => $row['item_type'],
  4634. 'title' => $row['title'],
  4635. 'path' => $row['path'],
  4636. 'description' => $row['description'],
  4637. 'parent_item_id' => $row['parent_item_id'],
  4638. 'previous_item_id' => $row['previous_item_id'],
  4639. 'next_item_id' => $row['next_item_id'],
  4640. 'display_order' => $row['display_order']);
  4641. }
  4642. $this->tree_array($arrLP);
  4643. $arrLP = $this->arrMenu;
  4644. unset($this->arrMenu);
  4645. $return .= '<p class="lp_title">' . $title . '</p>' . "\n";
  4646. require_once (api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php');
  4647. $form = new FormValidator('form','POST',api_get_self()."?".$_SERVER["QUERY_STRING"]);
  4648. $defaults["title"]=html_entity_decode($item_title);
  4649. $defaults["description"]=html_entity_decode($item_description);
  4650. $form->addElement('html',$return);
  4651. //$arrHide = array($id);
  4652. $arrHide[0]['value']=$this->name;
  4653. $arrHide[0]['padding']=3;
  4654. if($item_type != 'module' && $item_type != 'dokeos_module')
  4655. {
  4656. for($i = 0; $i < count($arrLP); $i++)
  4657. {
  4658. if($action != 'add'){
  4659. 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)){
  4660. $arrHide[$arrLP[$i]['id']]['value']=html_entity_decode(stripslashes($arrLP[$i]['title']));
  4661. $arrHide[$arrLP[$i]['id']]['padding']=3+ $arrLP[$i]['depth'] * 10;
  4662. if($parent == $arrLP[$i]['id']){
  4663. $s_selected_parent=$arrHide[$arrLP[$i]['id']];
  4664. }
  4665. }
  4666. }
  4667. else{
  4668. if($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir'){
  4669. $arrHide[$arrLP[$i]['id']]['value']=html_entity_decode(stripslashes($arrLP[$i]['title']));
  4670. $arrHide[$arrLP[$i]['id']]['padding']=3+ $arrLP[$i]['depth'] * 10;
  4671. if($parent == $arrLP[$i]['id']){
  4672. $s_selected_parent=$arrHide[$arrLP[$i]['id']];
  4673. }
  4674. }
  4675. }
  4676. }
  4677. $parent_select = &$form->addElement('select', 'parent', get_lang("Parent")." :", '', 'style="background:#F8F8F8; border:1px solid #999999; font-family:Arial, Verdana, Helvetica, sans-serif; font-size:12px; width:300px;" onchange="load_cbo(this.value);"');
  4678. foreach($arrHide as $key => $value){
  4679. $parent_select->addOption($value['value'],$key,'style="padding-left:'.$value['padding'].'px;"');
  4680. }
  4681. $parent_select -> setSelected($s_selected_parent);
  4682. }
  4683. if(is_array($arrLP)) { reset($arrLP); }
  4684. $arrHide=array();
  4685. //POSITION
  4686. for($i = 0; $i < count($arrLP); $i++)
  4687. {
  4688. if($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id)
  4689. {
  4690. if($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  4691. $s_selected_position=$arrLP[$i]['id'];
  4692. elseif($action == 'add')
  4693. $s_selected_position=$arrLP[$i]['id'];
  4694. $arrHide[$arrLP[$i]['id']]['value']=get_lang("After").' "' . html_entity_decode(stripslashes($arrLP[$i]['title']));
  4695. }
  4696. }
  4697. $position = &$form->addElement('select', 'previous', get_lang("Position")." :", '', 'id="idPosition" style="background:#F8F8F8; border:1px solid #999999; font-family:Arial, Verdana, Helvetica, sans-serif; font-size:12px; width:300px;"');
  4698. $position->addOption(get_lang('FirstPosition'),0,'style="padding-left:'.$value['padding'].'px;"');
  4699. foreach($arrHide as $key => $value){
  4700. $position->addOption($value['value'],$key,'style="padding-left:'.$value['padding'].'px;"');
  4701. }
  4702. if(!empty($s_selected_position)) { $position->setSelected($s_selected_position); }
  4703. if(is_array($arrLP)) { reset($arrLP); }
  4704. if($action != 'move'){
  4705. $form->addElement('text','title', get_lang('Title').' :','id="idTitle" style="background:#F8F8F8; border:1px solid #999999; font-family:Arial, Verdana, Helvetica, sans-serif; font-size:12px; padding:1px 2px; width:300px;"');
  4706. //$form->addElement('textarea','description',get_lang("Description").' :', 'id="idDescription" style="background:#F8F8F8; border:1px solid #999999; font-family:Arial, Verdana, Helvetica, sans-serif; font-size:12px; padding:1px 2px; width:300px;"');
  4707. }
  4708. else
  4709. {
  4710. $form->addElement('hidden','title');
  4711. }
  4712. $form->addElement('submit', 'submit_button', get_lang('Ok'), 'style="background:#F8F8F8; border:1px solid #999999; font-family:Arial, Verdana, Helvetica, sans-serif; font-size:12px; padding:1px 2px; width:75px;"');
  4713. if($item_type == 'module' || $item_type == 'dokeos_module')
  4714. {
  4715. $form->addElement('hidden', 'parent', '0');
  4716. }
  4717. $extension = pathinfo($item_path, PATHINFO_EXTENSION);
  4718. if(($item_type=='asset' || $item_type=='sco') && ($extension == 'html' || $extension == 'htm'))
  4719. {
  4720. if($item_type=='sco')
  4721. {
  4722. $form->addElement('html','<script type="text/javascript">alert("'.get_lang('WarningWhenEditingScorm').'")</script>');
  4723. }
  4724. $renderer = $form->defaultRenderer();
  4725. $renderer->setElementTemplate('<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{label}<br />{element}','content_lp');
  4726. $form->addElement('html_editor','content_lp','<a style="cursor:pointer" onclick="launch_templates()"><img src="'.api_get_path(WEB_IMG_PATH).'templates.gif" /></a>');
  4727. $defaults["content_lp"]=file_get_contents($item_path);
  4728. }
  4729. $form->addElement('hidden', 'type', 'dokeos_'.$item_type);
  4730. $form->addElement('hidden', 'post_time', time());
  4731. $form->addElement('html','</div>');
  4732. $form->setDefaults($defaults);
  4733. return $form->return_form();
  4734. }
  4735. /**
  4736. * Enter description here...
  4737. *
  4738. * @param unknown_type $action
  4739. * @param unknown_type $id
  4740. * @param unknown_type $extra_info
  4741. * @return unknown
  4742. */
  4743. function display_document_form($action = 'add', $id = 0, $extra_info = 'new')
  4744. {
  4745. echo '
  4746. <style>
  4747. .row{
  4748. width:100%;
  4749. }
  4750. div.row div.label {
  4751. width: 75px;
  4752. }
  4753. div.row div.formw {
  4754. width: 88%;
  4755. }
  4756. </style>';
  4757. $tbl_lp_item = Database::get_course_table('lp_item');
  4758. $tbl_doc = Database::get_course_table(TABLE_DOCUMENT);
  4759. $path_parts = pathinfo($extra_info['dir']);
  4760. $no_display_edit_textarea=false;
  4761. //If action==edit document
  4762. //We don't display the document form if it's not an editable document (html or txt file)
  4763. if($action=="edit"){
  4764. if(is_array($extra_info)){
  4765. if($path_parts['extension']!="txt" && $path_parts['extension']!="html"){
  4766. $no_display_edit_textarea=true;
  4767. }
  4768. }
  4769. }
  4770. $no_display_add=false;
  4771. //If action==add an existing document
  4772. //We don't display the document form if it's not an editable document (html or txt file)
  4773. if($action=="add"){
  4774. if(is_numeric($extra_info)){
  4775. $sql_doc = "SELECT path FROM " . $tbl_doc . "WHERE id = " . $extra_info;
  4776. $result=api_sql_query($sql_doc, __FILE__, __LINE__);
  4777. $path_file=mysql_result($result,0,0);
  4778. $path_parts = pathinfo($path_file);
  4779. if($path_parts['extension']!="txt" && $path_parts['extension']!="html"){
  4780. $no_display_add=true;
  4781. }
  4782. }
  4783. }
  4784. if($id != 0 && is_array($extra_info))
  4785. {
  4786. $item_title = stripslashes($extra_info['title']);
  4787. $item_description = stripslashes($extra_info['description']);
  4788. if(empty($item_title))
  4789. {
  4790. $path_parts = pathinfo($extra_info['path']);
  4791. $item_title = stripslashes($path_parts['filename']);
  4792. }
  4793. }
  4794. elseif(is_numeric($extra_info))
  4795. {
  4796. $sql_doc = "
  4797. SELECT path, title
  4798. FROM " . $tbl_doc . "
  4799. WHERE id = " . $extra_info;
  4800. $result = api_sql_query($sql_doc, __FILE__, __LINE__);
  4801. $row = Database::fetch_array($result);
  4802. $explode = explode('.', $row['title']);
  4803. if(count($explode)>1){
  4804. for($i = 0; $i < count($explode) - 1; $i++)
  4805. $item_title .= $explode[$i];
  4806. }
  4807. else{
  4808. $item_title=$row['title'];
  4809. }
  4810. $item_title = str_replace('_', ' ', $item_title);
  4811. if(empty($item_title))
  4812. {
  4813. $path_parts = pathinfo($row['path']);
  4814. $item_title = stripslashes($path_parts['filename']);
  4815. }
  4816. }
  4817. else
  4818. {
  4819. $item_title = '';
  4820. $item_description = '';
  4821. }
  4822. $return = '<div style="margin:3px 0px;">';
  4823. if($id != 0 && is_array($extra_info))
  4824. $parent = $extra_info['parent_item_id'];
  4825. else
  4826. $parent = 0;
  4827. $sql = "
  4828. SELECT *
  4829. FROM " . $tbl_lp_item . "
  4830. WHERE
  4831. lp_id = " . $this->lp_id;
  4832. $result = api_sql_query($sql, __FILE__, __LINE__);
  4833. $arrLP = array();
  4834. while($row = Database::fetch_array($result))
  4835. {
  4836. $arrLP[] = array(
  4837. 'id' => $row['id'],
  4838. 'item_type' => $row['item_type'],
  4839. 'title' => $row['title'],
  4840. 'path' => $row['path'],
  4841. 'description' => $row['description'],
  4842. 'parent_item_id' => $row['parent_item_id'],
  4843. 'previous_item_id' => $row['previous_item_id'],
  4844. 'next_item_id' => $row['next_item_id'],
  4845. 'display_order' => $row['display_order'],
  4846. 'prerequisite' => $row['prerequisite']);
  4847. }
  4848. $this->tree_array($arrLP);
  4849. $arrLP = $this->arrMenu;
  4850. unset($this->arrMenu);
  4851. if($action == 'add')
  4852. $return .= '<p class="lp_title">'.get_lang("CreateTheDocument").' :</p>' . "\n";
  4853. elseif($action == 'move')
  4854. $return .= '<p class="lp_title">'.get_lang("MoveTheCurrentDocument").' :</p>' . "\n";
  4855. else
  4856. $return .= '<p class="lp_title">'.get_lang("EditTheCurrentDocument").' :</p>' . "\n";
  4857. if(isset($_GET['edit']) && $_GET['edit'] == 'true')
  4858. {
  4859. $return .= '<div class="lp_message" style="margin-bottom:15px;">';
  4860. $return .= '<p class="lp_title">'.get_lang("Warning").' !</p>';
  4861. $return .= get_lang("WarningEditingDocument");
  4862. $return .= '</div>';
  4863. }
  4864. /*
  4865. if($no_display_add==true){
  4866. $return .= '<div class="lp_message" style="margin-bottom:15px;">';
  4867. $return .= get_lang("CantEditDocument");
  4868. $return .= '</div>';
  4869. return $return;
  4870. }
  4871. */
  4872. require_once (api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php');
  4873. $form = new FormValidator('form','POST',api_get_self()."?".$_SERVER["QUERY_STRING"]);
  4874. $defaults["title"]=html_entity_decode($item_title);
  4875. $defaults["description"]=html_entity_decode($item_description);
  4876. $form->addElement('html',$return);
  4877. //$arrHide = array($id);
  4878. $arrHide[0]['value']=$this->name;
  4879. $arrHide[0]['padding']=3;
  4880. for($i = 0; $i < count($arrLP); $i++)
  4881. {
  4882. if($action != 'add'){
  4883. 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)){
  4884. $arrHide[$arrLP[$i]['id']]['value']=html_entity_decode(stripslashes($arrLP[$i]['title']));
  4885. $arrHide[$arrLP[$i]['id']]['padding']=3+ $arrLP[$i]['depth'] * 10;
  4886. if($parent == $arrLP[$i]['id']){
  4887. $s_selected_parent=$arrHide[$arrLP[$i]['id']];
  4888. }
  4889. }
  4890. }
  4891. else{
  4892. if($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir'){
  4893. $arrHide[$arrLP[$i]['id']]['value']=html_entity_decode(stripslashes($arrLP[$i]['title']));
  4894. $arrHide[$arrLP[$i]['id']]['padding']=3+ $arrLP[$i]['depth'] * 10;
  4895. if($parent == $arrLP[$i]['id']){
  4896. $s_selected_parent=$arrHide[$arrLP[$i]['id']];
  4897. }
  4898. }
  4899. }
  4900. }
  4901. $parent_select = &$form->addElement('select', 'parent', get_lang("Parent")." :", '', 'style="background:#F8F8F8; border:1px solid #999999; font-family:Arial, Verdana, Helvetica, sans-serif; font-size:12px; width:300px;" onchange="load_cbo(this.value);"');
  4902. foreach($arrHide as $key => $value){
  4903. $parent_select->addOption($value['value'],$key,'style="padding-left:'.$value['padding'].'px;"');
  4904. }
  4905. $parent_select -> setSelected($parent);
  4906. if(is_array($arrLP))
  4907. {
  4908. reset($arrLP);
  4909. }
  4910. $arrHide=array();
  4911. //POSITION
  4912. for($i = 0; $i < count($arrLP); $i++)
  4913. {
  4914. if($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id)
  4915. {
  4916. if($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  4917. $s_selected_position=$arrLP[$i]['id'];
  4918. elseif($action == 'add')
  4919. $s_selected_position=$arrLP[$i]['id'];
  4920. $arrHide[$arrLP[$i]['id']]['value']=get_lang("After").' "' . html_entity_decode(stripslashes($arrLP[$i]['title'])).'"';
  4921. }
  4922. }
  4923. $position = &$form->addElement('select', 'previous', get_lang("Position")." :", '', 'id="idPosition" style="background:#F8F8F8; border:1px solid #999999; font-family:Arial, Verdana, Helvetica, sans-serif; font-size:12px; width:300px;"');
  4924. $position->addOption(get_lang("FirstPosition"),0,'style="padding-left:3px;"');
  4925. foreach($arrHide as $key => $value){
  4926. $position->addOption($value['value'],$key,'style="padding-left:'.$value['padding'].'px;"');
  4927. }
  4928. $position -> setSelected($s_selected_position);
  4929. if(is_array($arrLP))
  4930. {
  4931. reset($arrLP);
  4932. }
  4933. if($action != 'move'){
  4934. $form->addElement('text','title', get_lang('Title').' :','id="idTitle" style="background:#F8F8F8; border:1px solid #999999; font-family:Arial, Verdana, Helvetica, sans-serif; font-size:12px; padding:1px 2px; width:300px;"');
  4935. //$form->addElement('textarea','description',get_lang("Description").' :', 'id="idDescription" style="background:#F8F8F8; border:1px solid #999999; font-family:Arial, Verdana, Helvetica, sans-serif; font-size:12px; padding:1px 2px; width:300px;"');
  4936. $id_prerequisite=0;
  4937. if(is_array($arrLP))
  4938. {
  4939. foreach($arrLP as $key=>$value){
  4940. if($value['id']==$id){
  4941. $id_prerequisite=$value['prerequisite'];
  4942. break;
  4943. }
  4944. }
  4945. }
  4946. $select_prerequisites=$form->addElement('select', 'prerequisites', get_lang('Prerequisites'), '', 'id="prerequisites" style="background:#F8F8F8; border:1px solid #999999; font-family:Arial, Verdana, Helvetica, sans-serif; font-size:12px; width:300px;"');
  4947. $select_prerequisites->addOption(get_lang("NoPrerequisites"),0,'style="padding-left:3px;"');
  4948. $arrHide=array();
  4949. for($i = 0; $i < count($arrLP); $i++)
  4950. {
  4951. if($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter')
  4952. {
  4953. if($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  4954. $s_selected_position=$arrLP[$i]['id'];
  4955. elseif($action == 'add')
  4956. $s_selected_position=$arrLP[$i]['id'];
  4957. $arrHide[$arrLP[$i]['id']]['value']=html_entity_decode(stripslashes($arrLP[$i]['title']));
  4958. }
  4959. }
  4960. foreach($arrHide as $key => $value){
  4961. $select_prerequisites->addOption($value['value'],$key,'style="padding-left:'.$value['padding'].'px;"');
  4962. if($key==$s_selected_position && $action == 'add'){
  4963. $select_prerequisites -> setSelected(0);
  4964. }
  4965. elseif($key==$id_prerequisite && $action == 'edit'){
  4966. $select_prerequisites -> setSelected($id_prerequisite);
  4967. }
  4968. }
  4969. if(!$no_display_add)
  4970. {
  4971. if(($extra_info == 'new' || $extra_info['item_type'] == TOOL_DOCUMENT || $_GET['edit'] == 'true'))
  4972. {
  4973. if(isset($_POST['content']))
  4974. $content = stripslashes($_POST['content']);
  4975. elseif(is_array($extra_info)){
  4976. //If it's an html document or a text file
  4977. if(!$no_display_edit_textarea){
  4978. $content = $this->display_document($extra_info['path'], false, false);
  4979. }
  4980. }
  4981. elseif(is_numeric($extra_info))
  4982. $content = $this->display_document($extra_info, false, false);
  4983. else
  4984. $content = '';
  4985. $form->addElement('submit', 'submit_button', get_lang('Ok'), 'style="background:#F8F8F8; border:1px solid #999999; font-family:Arial, Verdana, Helvetica, sans-serif; font-size:12px; padding:1px 2px; width:75px;"');
  4986. if(!$no_display_edit_textarea){
  4987. $renderer = $form->defaultRenderer();
  4988. $renderer->setElementTemplate('<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{label}<br />{element}','content_lp');
  4989. $form->addElement('html_editor','content_lp','<a style="cursor:pointer" onclick="launch_templates()"><img src="'.api_get_path(WEB_IMG_PATH).'templates.gif" /></a>');
  4990. $defaults["content_lp"]=$content;
  4991. }
  4992. }
  4993. elseif(is_numeric($extra_info))
  4994. {
  4995. $form->addElement('submit', 'submit_button', get_lang('Ok'), 'style="background:#F8F8F8; border:1px solid #999999; font-family:Arial, Verdana, Helvetica, sans-serif; font-size:12px; padding:1px 2px; width:75px;"');
  4996. $return = $this->display_document($extra_info, true, true, true);
  4997. $form->addElement('html',$return);
  4998. }
  4999. }
  5000. }
  5001. if($action == 'move')
  5002. {
  5003. $form->addElement('hidden', 'title', $item_title);
  5004. $form->addElement('hidden', 'description', $item_description);
  5005. }
  5006. if(is_numeric($extra_info))
  5007. {
  5008. $form->addElement('submit', 'submit_button', get_lang('Ok'), 'style="background:#F8F8F8; border:1px solid #999999; font-family:Arial, Verdana, Helvetica, sans-serif; font-size:12px; padding:1px 2px; width:75px;"');
  5009. $form->addElement('hidden', 'path', $extra_info);
  5010. }
  5011. elseif(is_array($extra_info))
  5012. {
  5013. $form->addElement('submit', 'submit_button', get_lang('Ok'), 'style="background:#F8F8F8; border:1px solid #999999; font-family:Arial, Verdana, Helvetica, sans-serif; font-size:12px; padding:1px 2px; width:75px;"');
  5014. $form->addElement('hidden', 'path', $extra_info['path']);
  5015. }
  5016. $form->addElement('hidden', 'type', TOOL_DOCUMENT);
  5017. $form->addElement('hidden', 'post_time', time());
  5018. $form->addElement('html','</div>');
  5019. $form->setDefaults($defaults);
  5020. return $form->return_form();
  5021. }
  5022. /**
  5023. * Enter description here...
  5024. *
  5025. * @param unknown_type $action
  5026. * @param unknown_type $id
  5027. * @param unknown_type $extra_info
  5028. */
  5029. function display_link_form($action = 'add', $id = 0, $extra_info = '')
  5030. {
  5031. $tbl_lp_item = Database::get_course_table('lp_item');
  5032. $tbl_link = Database::get_course_table(TABLE_LINK);
  5033. if($id != 0 && is_array($extra_info))
  5034. {
  5035. $item_title = stripslashes($extra_info['title']);
  5036. $item_description = stripslashes($extra_info['description']);
  5037. }
  5038. elseif(is_numeric($extra_info))
  5039. {
  5040. $sql_link = "
  5041. SELECT
  5042. title,
  5043. description,
  5044. url
  5045. FROM " . $tbl_link . "
  5046. WHERE id = " . $extra_info;
  5047. $result = api_sql_query($sql_link, __FILE__, __LINE__);
  5048. $row = Database::fetch_array($result);
  5049. $item_title = $row['title'];
  5050. $item_description = $row['description'];
  5051. $item_url = $row['url'];
  5052. }
  5053. else
  5054. {
  5055. $item_title = '';
  5056. $item_description = '';
  5057. }
  5058. $return = '<div style="margin:3px 10px;">';
  5059. if($id != 0 && is_array($extra_info))
  5060. $parent = $extra_info['parent_item_id'];
  5061. else
  5062. $parent = 0;
  5063. $sql = "
  5064. SELECT *
  5065. FROM " . $tbl_lp_item . "
  5066. WHERE
  5067. lp_id = " . $this->lp_id;
  5068. $result = api_sql_query($sql, __FILE__, __LINE__);
  5069. $arrLP = array();
  5070. while($row = Database::fetch_array($result))
  5071. {
  5072. $arrLP[] = array(
  5073. 'id' => $row['id'],
  5074. 'item_type' => $row['item_type'],
  5075. 'title' => $row['title'],
  5076. 'path' => $row['path'],
  5077. 'description' => $row['description'],
  5078. 'parent_item_id' => $row['parent_item_id'],
  5079. 'previous_item_id' => $row['previous_item_id'],
  5080. 'next_item_id' => $row['next_item_id'],
  5081. 'display_order' => $row['display_order'],
  5082. 'prerequisite' => $row['prerequisite']);
  5083. }
  5084. $this->tree_array($arrLP);
  5085. $arrLP = $this->arrMenu;
  5086. unset($this->arrMenu);
  5087. if($action == 'add')
  5088. $return .= '<p class="lp_title">'.get_lang("CreateTheLink").' :</p>' . "\n";
  5089. elseif($action == 'move')
  5090. $return .= '<p class="lp_title">'.get_lang("MoveCurrentLink").' :</p>' . "\n";
  5091. else
  5092. $return .= '<p class="lp_title">'.get_lang("EditCurrentLink").' :</p>' . "\n";
  5093. $return .= '<form method="POST">' . "\n";
  5094. $return .= "\t" . '<table cellpadding="0" cellspacing="0" class="lp_form">' . "\n";
  5095. $return .= "\t\t" . '<tr>' . "\n";
  5096. $return .= "\t\t\t" . '<td class="label"><label for="idParent">'.get_lang("Parent").' :</label></td>' . "\n";
  5097. $return .= "\t\t\t" . '<td class="input">' . "\n";
  5098. $return .= "\t\t\t\t" . '<select id="idParent" name="parent" onchange="load_cbo(this.value);" size="1">';
  5099. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
  5100. $arrHide = array($id);
  5101. for($i = 0; $i < count($arrLP); $i++)
  5102. {
  5103. if($action != 'add')
  5104. {
  5105. 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))
  5106. {
  5107. $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'] . '">' . html_entity_decode(stripslashes($arrLP[$i]['title'])) . '</option>';
  5108. }
  5109. else
  5110. {
  5111. $arrHide[] = $arrLP[$i]['id'];
  5112. }
  5113. }
  5114. else
  5115. {
  5116. if($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
  5117. $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'] . '">' . html_entity_decode(stripslashes($arrLP[$i]['title'])) . '</option>';
  5118. }
  5119. }
  5120. reset($arrLP);
  5121. $return .= "\t\t\t\t" . '</select>';
  5122. $return .= "\t\t\t" . '</td>' . "\n";
  5123. $return .= "\t\t" . '</tr>' . "\n";
  5124. $return .= "\t\t" . '<tr>' . "\n";
  5125. $return .= "\t\t\t" . '<td class="label"><label for="idPosition">'.get_lang("Position").' :</label></td>' . "\n";
  5126. $return .= "\t\t\t" . '<td class="input">' . "\n";
  5127. $return .= "\t\t\t\t" . '<select id="idPosition" name="previous" size="1">';
  5128. $return .= "\t\t\t\t\t" . '<option class="top" value="0">'.get_lang("FirstPosition").'</option>';
  5129. for($i = 0; $i < count($arrLP); $i++)
  5130. {
  5131. if($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id)
  5132. {
  5133. if($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5134. $selected = 'selected="selected" ';
  5135. elseif($action == 'add')
  5136. $selected = 'selected="selected" ';
  5137. else
  5138. $selected = '';
  5139. $return .= "\t\t\t\t\t" . '<option ' . $selected . 'value="' . $arrLP[$i]['id'] . '">'.get_lang("After").' "' . html_entity_decode(stripslashes($arrLP[$i]['title'])) . '"</option>';
  5140. }
  5141. }
  5142. $return .= "\t\t\t\t" . '</select>';
  5143. $return .= "\t\t\t" . '</td>' . "\n";
  5144. $return .= "\t\t" . '</tr>' . "\n";
  5145. if($action != 'move')
  5146. {
  5147. $return .= "\t\t" . '<tr>' . "\n";
  5148. $return .= "\t\t\t" . '<td class="label"><label for="idTitle">'.get_lang("Title").' :</label></td>' . "\n";
  5149. $return .= "\t\t\t" . '<td class="input"><input id="idTitle" name="title" type="text" value="' . $item_title . '" /></td>' . "\n";
  5150. $return .= "\t\t" . '</tr>' . "\n";
  5151. $return .= "\t\t" . '<tr>' . "\n";
  5152. $return .= "\t\t\t" . '<td class="label"><label for="idDescription">'.get_lang("Description").' :</label></td>' . "\n";
  5153. $return .= "\t\t\t" . '<td class="input"><textarea id="idDescription" name="description" rows="4">' . $item_description . '</textarea></td>' . "\n";
  5154. $return .= "\t\t" . '</tr>' . "\n";
  5155. $return .= "\t\t" . '<tr>' . "\n";
  5156. $return .= "\t\t\t" . '<td class="label"><label for="idURL">'.get_lang("Url").' :</label></td>' . "\n";
  5157. $return .= "\t\t\t" . '<td class="input"><input' . (is_numeric($extra_info) ? ' disabled="disabled"' : '') . ' id="idURL" name="url" type="text" value="' . $item_url . '" /></td>' . "\n";
  5158. $return .= "\t\t" . '</tr>' . "\n";
  5159. $id_prerequisite=0;
  5160. foreach($arrLP as $key=>$value){
  5161. if($value['id']==$id){
  5162. $id_prerequisite=$value['prerequisite'];
  5163. break;
  5164. }
  5165. }
  5166. $arrHide=array();
  5167. for($i = 0; $i < count($arrLP); $i++)
  5168. {
  5169. if($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter')
  5170. {
  5171. if($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5172. $s_selected_position=$arrLP[$i]['id'];
  5173. elseif($action == 'add')
  5174. $s_selected_position=0;
  5175. $arrHide[$arrLP[$i]['id']]['value']=html_entity_decode(stripslashes($arrLP[$i]['title']));
  5176. }
  5177. }
  5178. $return .= "\t\t" . '<tr>' . "\n";
  5179. $return .= "\t\t\t" . '<td class="label"><label for="idPrerequisites">'.get_lang("Prerequisites").' :</label></td>' . "\n";
  5180. $return .= "\t\t\t" . '<td class="input"><select name="prerequisites" id="prerequisites" style="background:#F8F8F8; border:1px solid #999999; font-family:Arial, Verdana, Helvetica, sans-serif; font-size:12px; width:300px;"><option value="0">'.get_lang("NoPrerequisites").'</option>';
  5181. foreach($arrHide as $key => $value){
  5182. if($key==$s_selected_position && $action == 'add'){
  5183. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  5184. }
  5185. elseif($key==$id_prerequisite && $action == 'edit'){
  5186. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  5187. }
  5188. else{
  5189. $return .= '<option value="'.$key.'">'.$value['value'].'</option>';
  5190. }
  5191. }
  5192. $return .= "</select></td>";
  5193. $return .= "\t\t" . '</tr>' . "\n";
  5194. }
  5195. $return .= "\t\t" . '<tr>' . "\n";
  5196. $return .= "\t\t\t" . '<td colspan="2"><input class="button" name="submit_button" type="submit" value="'.get_lang("Ok").'" /></td>' . "\n";
  5197. $return .= "\t\t" . '</tr>' . "\n";
  5198. $return .= "\t" . '</table>' . "\n";
  5199. if($action == 'move')
  5200. {
  5201. $return .= "\t" . '<input name="title" type="hidden" value="' . $item_title . '" />' . "\n";
  5202. $return .= "\t" . '<input name="description" type="hidden" value="' . $item_description . '" />' . "\n";
  5203. }
  5204. if(is_numeric($extra_info))
  5205. {
  5206. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info . '" />' . "\n";
  5207. }
  5208. elseif(is_array($extra_info))
  5209. {
  5210. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />' . "\n";
  5211. }
  5212. $return .= "\t" . '<input name="type" type="hidden" value="'.TOOL_LINK.'" />' . "\n";
  5213. $return .= "\t" . '<input name="post_time" type="hidden" value="' . time() . '" />' . "\n";
  5214. $return .= '</form>' . "\n";
  5215. $return .= '</div>' . "\n";
  5216. return $return;
  5217. }
  5218. /**
  5219. * Enter description here...
  5220. *
  5221. * @param unknown_type $action
  5222. * @param unknown_type $id
  5223. * @param unknown_type $extra_info
  5224. * @return unknown
  5225. */
  5226. function display_student_publication_form($action = 'add', $id = 0, $extra_info = '')
  5227. {
  5228. $tbl_lp_item = Database::get_course_table('lp_item');
  5229. $tbl_publication = Database::get_course_table(TABLE_STUDENT_PUBLICATION);
  5230. if($id != 0 && is_array($extra_info))
  5231. {
  5232. $item_title = stripslashes($extra_info['title']);
  5233. $item_description = stripslashes($extra_info['description']);
  5234. }
  5235. elseif(is_numeric($extra_info))
  5236. {
  5237. $sql_publication = "
  5238. SELECT
  5239. title,
  5240. description
  5241. FROM " . $tbl_publication . "
  5242. WHERE id = " . $extra_info;
  5243. $result = api_sql_query($sql_publication, __FILE__, __LINE__);
  5244. $row = Database::fetch_array($result);
  5245. $item_title = $row['title'];
  5246. }
  5247. else
  5248. {
  5249. $item_title = '';
  5250. }
  5251. $return = '<div style="margin:3px 10px;">';
  5252. if($id != 0 && is_array($extra_info))
  5253. $parent = $extra_info['parent_item_id'];
  5254. else
  5255. $parent = 0;
  5256. $sql = "
  5257. SELECT *
  5258. FROM " . $tbl_lp_item . "
  5259. WHERE
  5260. lp_id = " . $this->lp_id;
  5261. $result = api_sql_query($sql, __FILE__, __LINE__);
  5262. $arrLP = array();
  5263. while($row = Database::fetch_array($result))
  5264. {
  5265. $arrLP[] = array(
  5266. 'id' => $row['id'],
  5267. 'item_type' => $row['item_type'],
  5268. 'title' => $row['title'],
  5269. 'path' => $row['path'],
  5270. 'description' => $row['description'],
  5271. 'parent_item_id' => $row['parent_item_id'],
  5272. 'previous_item_id' => $row['previous_item_id'],
  5273. 'next_item_id' => $row['next_item_id'],
  5274. 'display_order' => $row['display_order'],
  5275. 'prerequisite' => $row['prerequisite']);
  5276. }
  5277. $this->tree_array($arrLP);
  5278. $arrLP = $this->arrMenu;
  5279. unset($this->arrMenu);
  5280. if($action == 'add')
  5281. $return .= '<p class="lp_title">'.get_lang("Student_publication").' :</p>' . "\n";
  5282. elseif($action == 'move')
  5283. $return .= '<p class="lp_title">'.get_lang("MoveCurrentStudentPublication").' :</p>' . "\n";
  5284. else
  5285. $return .= '<p class="lp_title">'.get_lang("EditCurrentStudentPublication").' :</p>' . "\n";
  5286. $return .= '<form method="POST">' . "\n";
  5287. $return .= "\t" . '<table cellpadding="0" cellspacing="0" class="lp_form">' . "\n";
  5288. $return .= "\t\t" . '<tr>' . "\n";
  5289. $return .= "\t\t\t" . '<td class="label"><label for="idParent">'.get_lang("Parent").' :</label></td>' . "\n";
  5290. $return .= "\t\t\t" . '<td class="input">' . "\n";
  5291. $return .= "\t\t\t\t" . '<select id="idParent" name="parent" onchange="load_cbo(this.value);" size="1">';
  5292. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
  5293. $arrHide = array($id);
  5294. for($i = 0; $i < count($arrLP); $i++)
  5295. {
  5296. if($action != 'add')
  5297. {
  5298. 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))
  5299. {
  5300. $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'] . '">' . html_entity_decode(stripslashes($arrLP[$i]['title'])) . '</option>';
  5301. }
  5302. else
  5303. {
  5304. $arrHide[] = $arrLP[$i]['id'];
  5305. }
  5306. }
  5307. else
  5308. {
  5309. if($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
  5310. $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'] . '">' . html_entity_decode(stripslashes($arrLP[$i]['title'])) . '</option>';
  5311. }
  5312. }
  5313. reset($arrLP);
  5314. $return .= "\t\t\t\t" . '</select>';
  5315. $return .= "\t\t\t" . '</td>' . "\n";
  5316. $return .= "\t\t" . '</tr>' . "\n";
  5317. $return .= "\t\t" . '<tr>' . "\n";
  5318. $return .= "\t\t\t" . '<td class="label"><label for="idPosition">'.get_lang("Position").' :</label></td>' . "\n";
  5319. $return .= "\t\t\t" . '<td class="input">' . "\n";
  5320. $return .= "\t\t\t\t" . '<select id="idPosition" name="previous" size="1">';
  5321. $return .= "\t\t\t\t\t" . '<option class="top" value="0">'.get_lang("FirstPosition").'</option>';
  5322. for($i = 0; $i < count($arrLP); $i++)
  5323. {
  5324. if($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id)
  5325. {
  5326. if($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5327. $selected = 'selected="selected" ';
  5328. elseif($action == 'add')
  5329. $selected = 'selected="selected" ';
  5330. else
  5331. $selected = '';
  5332. $return .= "\t\t\t\t\t" . '<option ' . $selected . 'value="' . $arrLP[$i]['id'] . '">'.get_lang("After").' "' . html_entity_decode(stripslashes($arrLP[$i]['title'])) . '"</option>';
  5333. }
  5334. }
  5335. $return .= "\t\t\t\t" . '</select>';
  5336. $return .= "\t\t\t" . '</td>' . "\n";
  5337. $return .= "\t\t" . '</tr>' . "\n";
  5338. if($action != 'move')
  5339. {
  5340. $return .= "\t\t" . '<tr>' . "\n";
  5341. $return .= "\t\t\t" . '<td class="label"><label for="idTitle">'.get_lang("Title").' :</label></td>' . "\n";
  5342. $return .= "\t\t\t" . '<td class="input"><input id="idTitle" name="title" type="text" value="' . $item_title . '" /></td>' . "\n";
  5343. $return .= "\t\t" . '</tr>' . "\n";
  5344. $id_prerequisite=0;
  5345. foreach($arrLP as $key=>$value){
  5346. if($value['id']==$id){
  5347. $id_prerequisite=$value['prerequisite'];
  5348. break;
  5349. }
  5350. }
  5351. $arrHide=array();
  5352. for($i = 0; $i < count($arrLP); $i++)
  5353. {
  5354. if($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter')
  5355. {
  5356. if($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5357. $s_selected_position=$arrLP[$i]['id'];
  5358. elseif($action == 'add')
  5359. $s_selected_position=0;
  5360. $arrHide[$arrLP[$i]['id']]['value']=html_entity_decode(stripslashes($arrLP[$i]['title']));
  5361. }
  5362. }
  5363. $return .= "\t\t" . '<tr>' . "\n";
  5364. $return .= "\t\t\t" . '<td class="label"><label for="idPrerequisites">'.get_lang("Prerequisites").' :</label></td>' . "\n";
  5365. $return .= "\t\t\t" . '<td class="input"><select name="prerequisites" id="prerequisites" style="background:#F8F8F8; border:1px solid #999999; font-family:Arial, Verdana, Helvetica, sans-serif; font-size:12px; width:300px;"><option value="0">'.get_lang("NoPrerequisites").'</option>';
  5366. foreach($arrHide as $key => $value){
  5367. if($key==$s_selected_position && $action == 'add'){
  5368. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  5369. }
  5370. elseif($key==$id_prerequisite && $action == 'edit'){
  5371. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  5372. }
  5373. else{
  5374. $return .= '<option value="'.$key.'">'.$value['value'].'</option>';
  5375. }
  5376. }
  5377. $return .= "</select></td>";
  5378. $return .= "\t\t" . '</tr>' . "\n";
  5379. }
  5380. $return .= "\t\t" . '<tr>' . "\n";
  5381. $return .= "\t\t\t" . '<td colspan="2"><input class="button" name="submit_button" type="submit" value="'.get_lang("Ok").'" /></td>' . "\n";
  5382. $return .= "\t\t" . '</tr>' . "\n";
  5383. $return .= "\t" . '</table>' . "\n";
  5384. if($action == 'move')
  5385. {
  5386. $return .= "\t" . '<input name="title" type="hidden" value="' . $item_title . '" />' . "\n";
  5387. $return .= "\t" . '<input name="description" type="hidden" value="' . $item_description . '" />' . "\n";
  5388. }
  5389. if(is_numeric($extra_info))
  5390. {
  5391. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info . '" />' . "\n";
  5392. }
  5393. elseif(is_array($extra_info))
  5394. {
  5395. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />' . "\n";
  5396. }
  5397. $return .= "\t" . '<input name="type" type="hidden" value="'.TOOL_STUDENTPUBLICATION.'" />' . "\n";
  5398. $return .= "\t" . '<input name="post_time" type="hidden" value="' . time() . '" />' . "\n";
  5399. $return .= '</form>' . "\n";
  5400. $return .= '</div>' . "\n";
  5401. return $return;
  5402. }
  5403. /**
  5404. * Displays the menu for manipulating a step
  5405. *
  5406. * @return unknown
  5407. */
  5408. function display_manipulate($item_id, $item_type = TOOL_DOCUMENT)
  5409. {
  5410. $return = '<div class="lp_manipulate"><table border="0" width="100%"><tr><td valign="top" width="400">';
  5411. switch($item_type)
  5412. {
  5413. case 'dokeos_chapter':
  5414. case 'chapter':
  5415. $lang = get_lang('TitleManipulateChapter');
  5416. break;
  5417. case 'dokeos_module':
  5418. case 'module':
  5419. $lang = get_lang('TitleManipulateModule');
  5420. break;
  5421. case TOOL_DOCUMENT:
  5422. $lang = get_lang('TitleManipulateDocument');
  5423. break;
  5424. case TOOL_LINK:
  5425. case 'link':
  5426. $lang = get_lang('TitleManipulateLink');
  5427. break;
  5428. case TOOL_QUIZ:
  5429. $lang = get_lang('TitleManipulateQuiz');
  5430. break;
  5431. case TOOL_STUDENTPUBLICATION:
  5432. $lang = get_lang('TitleManipulateStudentPublication');
  5433. break;
  5434. }
  5435. $tbl_lp_item = Database::get_course_table('lp_item');
  5436. $sql = "
  5437. SELECT
  5438. description
  5439. FROM " . $tbl_lp_item . " as lp
  5440. WHERE
  5441. lp.id = " . $item_id;
  5442. $result = api_sql_query($sql, __FILE__, __LINE__);
  5443. $s_description=mysql_result($result,0,0);
  5444. $return .= '<p class="lp_title">' . $lang . '</p>';
  5445. $return .= '<a href="' .api_get_self(). '?cidReq=' . $_GET['cidReq'] . '&amp;action=edit_item&amp;view=build&amp;id=' . $item_id . '&amp;lp_id=' . $this->lp_id . '" title="Edit the current item"><img align="absbottom" alt="Edit the current item" src="../img/edit.gif" title="Edit the current item" /> '.get_lang("Edit").'</a>';
  5446. $return .= '<a href="' .api_get_self(). '?cidReq=' . $_GET['cidReq'] . '&amp;action=move_item&amp;view=build&amp;id=' . $item_id . '&amp;lp_id=' . $this->lp_id . '" title="Move the current item"><img align="absbottom" alt="Move the current item" src="../img/deplacer_fichier.gif" title="Move the current item" /> '.get_lang("Move").'</a>';
  5447. // commented for now as prerequisites cannot be added to chapters
  5448. if($item_type != 'dokeos_chapter' && $item_type != 'chapter')
  5449. {
  5450. $return .= '<a href="' .api_get_self(). '?cidReq=' . $_GET['cidReq'] . '&amp;action=edit_item_prereq&amp;view=build&amp;id=' . $item_id . '&amp;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>';
  5451. }
  5452. $return .= '<a href="' .api_get_self(). '?cidReq=' . $_GET['cidReq'] . '&amp;action=delete_item&amp;view=build&amp;id=' . $item_id . '&amp;lp_id=' . $this->lp_id . '" onclick="return confirmation(\'' . htmlentities($s_description) . '\');" title="Delete the current item"><img alt="Delete the current item" align="absbottom" src="../img/delete.gif" title="Delete the current item" /> '.get_lang("Delete").'</a>';
  5453. //$return .= '<br><br><p class="lp_text">' . ((trim($s_description) == '') ? ''.get_lang("NoDescription").'' : stripslashes(nl2br($s_description))) . '</p>';
  5454. $return.="</td><td valign='top'>";
  5455. // get the audiorecorder. Use of ob_* functions since there are echos in the file
  5456. ob_start();
  5457. $audio_recorder_studentview = 'false';
  5458. $audio_recorder_item_id = $item_id;
  5459. if(api_get_setting('service_ppt2lp','active')=='true' && api_get_setting('service_ppt2lp','path_to_lzx')!=''){
  5460. include('audiorecorder.inc.php');
  5461. }
  5462. $return .= ob_get_contents();
  5463. ob_end_clean();
  5464. // end of audiorecorder include
  5465. $return.="</td></tr></table>";
  5466. $return .= '</div>';
  5467. return $return;
  5468. }
  5469. /**
  5470. * Creates the javascript needed for filling up the checkboxes without page reload
  5471. *
  5472. * @return string
  5473. */
  5474. function create_js()
  5475. {
  5476. $return = '<script language="javascript" type="text/javascript">' . "\n";
  5477. $return .= 'function load_cbo(id){' . "\n";
  5478. $return .= "var cbo = document.getElementById('idPosition');\n";
  5479. $return .= 'for(var i = cbo.length - 1; i > 0; i--)';
  5480. $return .= 'cbo.options[i] = null;'."\n";
  5481. $return .= 'var k=0;'."\n";
  5482. $return .= 'for(var i = 1; i <= child_name[id].length; i++){'."\n";
  5483. $return .= ' cbo.options[i] = new Option(child_name[id][i-1], child_value[id][i-1]);'."\n";
  5484. $return .= 'k=i;';
  5485. $return .= '}' . "\n\n";
  5486. $return .= 'if( typeof cbo != "undefined" ) {cbo.options[k].selected = true;}';
  5487. $return .='}';
  5488. $return .= 'var child_name = new Array();' . "\n";
  5489. $return .= 'var child_value = new Array();' . "\n\n";
  5490. $return .= 'child_name[0] = new Array();' . "\n";
  5491. $return .= 'child_value[0] = new Array();' . "\n\n";
  5492. $tbl_lp_item = Database::get_course_table('lp_item');
  5493. $sql_zero = "
  5494. SELECT *
  5495. FROM " . $tbl_lp_item . "
  5496. WHERE
  5497. lp_id = " . $this->lp_id . " AND
  5498. parent_item_id = 0
  5499. ORDER BY display_order ASC";
  5500. $res_zero = api_sql_query($sql_zero, __FILE__, __LINE__);
  5501. $i = 0;
  5502. while($row_zero = Database::fetch_array($res_zero))
  5503. {
  5504. $return .= 'child_name[0][' . $i . '] = "'.get_lang("After").' \"' . $row_zero['title'] . '\"";' . "\n";
  5505. $return .= 'child_value[0][' . $i++ . '] = "' . $row_zero['id'] . '";' . "\n";
  5506. }
  5507. $return .= "\n";
  5508. $sql = "
  5509. SELECT *
  5510. FROM " . $tbl_lp_item . "
  5511. WHERE
  5512. lp_id = " . $this->lp_id;
  5513. $res = api_sql_query($sql, __FILE__, __LINE__);
  5514. while($row = Database::fetch_array($res))
  5515. {
  5516. $sql_parent = "
  5517. SELECT *
  5518. FROM " . $tbl_lp_item . "
  5519. WHERE parent_item_id = " . $row['id'] . "
  5520. ORDER BY display_order ASC";
  5521. $res_parent = api_sql_query($sql_parent, __FILE__, __LINE__);
  5522. $i = 0;
  5523. $return .= 'child_name[' . $row['id'] . '] = new Array();' . "\n";
  5524. $return .= 'child_value[' . $row['id'] . '] = new Array();' . "\n\n";
  5525. while($row_parent = Database::fetch_array($res_parent))
  5526. {
  5527. $return .= 'child_name[' . $row['id'] . '][' . $i . '] = "'.get_lang("After").' \"' . $row_parent['title'] . '\"";' . "\n";
  5528. $return .= 'child_value[' . $row['id'] . '][' . $i++ . '] = "' . $row_parent['id'] . '";' . "\n";
  5529. }
  5530. $return .= "\n";
  5531. }
  5532. $return .= '</script>' . "\n";
  5533. return $return;
  5534. }
  5535. /**
  5536. * Enter description here...
  5537. *
  5538. * @param unknown_type $item_id
  5539. * @return unknown
  5540. */
  5541. function display_move_item($item_id)
  5542. {
  5543. global $_course; //will disappear
  5544. $return = '';
  5545. if(is_numeric($item_id))
  5546. {
  5547. $tbl_lp_item = Database::get_course_table('lp_item');
  5548. $sql = "
  5549. SELECT *
  5550. FROM " . $tbl_lp_item . "
  5551. WHERE id = " . $item_id;
  5552. $res = api_sql_query($sql, __FILE__, __LINE__);
  5553. $row = Database::fetch_array($res);
  5554. switch($row['item_type'])
  5555. {
  5556. case 'dokeos_chapter': case 'dir' : case 'asset' :
  5557. $return .= $this->display_manipulate($item_id, $row['item_type']);
  5558. $return .= $this->display_item_form($row['item_type'], get_lang('MoveCurrentChapter'), 'move', $item_id, $row);
  5559. break;
  5560. case 'dokeos_module':
  5561. $return .= $this->display_manipulate($item_id, $row['item_type']);
  5562. $return .= $this->display_item_form($row['item_type'], 'Move th current module:', 'move', $item_id, $row);
  5563. break;
  5564. case TOOL_DOCUMENT:
  5565. $return .= $this->display_manipulate($item_id, $row['item_type']);
  5566. $return .= $this->display_document_form('move', $item_id, $row);
  5567. break;
  5568. case TOOL_LINK:
  5569. $return .= $this->display_manipulate($item_id, $row['item_type']);
  5570. $return .= $this->display_link_form('move', $item_id, $row);
  5571. break;
  5572. case TOOL_HOTPOTATOES:
  5573. $return .= $this->display_manipulate($item_id, $row['item_type']);
  5574. $return .= $this->display_link_form('move', $item_id, $row);
  5575. break;
  5576. case TOOL_QUIZ:
  5577. $return .= $this->display_manipulate($item_id, $row['item_type']);
  5578. $return .= $this->display_quiz_form('move', $item_id, $row);
  5579. break;
  5580. case TOOL_STUDENTPUBLICATION:
  5581. $return .= $this->display_manipulate($item_id, $row['item_type']);
  5582. $return .= $this->display_student_publication_form('move', $item_id, $row);
  5583. break;
  5584. case TOOL_FORUM :
  5585. $return .= $this->display_manipulate($item_id, $row['item_type']);
  5586. $return .= $this->display_forum_form('move', $item_id, $row);
  5587. }
  5588. }
  5589. return $return;
  5590. }
  5591. /**
  5592. * Displays a basic form on the overview page for changing the item title and the item description.
  5593. *
  5594. * @param string $item_type
  5595. * @param string $title
  5596. * @param array $data
  5597. * @return string
  5598. */
  5599. function display_item_small_form($item_type, $title = '', $data)
  5600. {
  5601. $return .= '<div class="lp_small_form">' . "\n";
  5602. $return .= '<p class="lp_title">' . $title . '</p>';
  5603. $return .= '<form method="post">' . "\n";
  5604. $return .= '<table cellpadding="0" cellspacing="0" class="lp_form">';
  5605. $return .= "\t\t" . '<tr>' . "\n";
  5606. $return .= "\t\t\t" . '<td class="label"><label for="idTitle">Title:</label></td>' . "\n";
  5607. $return .= "\t\t\t" . '<td class="input"><input class="small_form" id="idTitle" name="title" type="text" value="' . $data['title'] . '" /></td>' . "\n";
  5608. $return .= "\t\t" . '</tr>' . "\n";
  5609. $return .= "\t\t" . '<tr>' . "\n";
  5610. $return .= "\t\t\t" . '<td class="label"><label for="idDescription">Description:</label></td>' . "\n";
  5611. $return .= "\t\t\t" . '<td class="input"><textarea class="small_form" id="idDescription" name="description" rows="4">' . $data['description'] . '</textarea></td>' . "\n";
  5612. $return .= "\t\t" . '</tr>' . "\n";
  5613. $return .= "\t\t" . '<tr>' . "\n";
  5614. $return .= "\t\t\t" . '<td colspan="2"><input class="button small_form" name="submit_button" type="submit" value="OK" /></td>' . "\n";
  5615. $return .= "\t\t" . '</tr>' . "\n";
  5616. $return .= "\t\t" . '</table>' . "\n";
  5617. $return .= "\t" . '<input name="parent" type="hidden" value="' . $data['parent_item_id'] . '"/>' . "\n";
  5618. $return .= "\t" . '<input name="previous" type="hidden" value="' . $data['previous_item_id'] . '"/>' . "\n";
  5619. $return .= '</form>';
  5620. $return .= '</div>';
  5621. return $return;
  5622. }
  5623. /**
  5624. * Enter description here...
  5625. *
  5626. * @param unknown_type $item_id
  5627. * @return unknown
  5628. */
  5629. function display_item_prerequisites_form($item_id)
  5630. {
  5631. $tbl_lp_item = Database::get_course_table('lp_item');
  5632. /* current prerequisite */
  5633. $sql = "
  5634. SELECT *
  5635. FROM " . $tbl_lp_item . "
  5636. WHERE id = " . $item_id;
  5637. $result = api_sql_query($sql, __FILE__, __LINE__);
  5638. $row = Database::fetch_array($result);
  5639. $preq_id = $row['prerequisite'];
  5640. //$preq_mastery = $row['mastery_score'];
  5641. //$preq_max = $row['max_score'];
  5642. $return = $this->display_manipulate($item_id, TOOL_DOCUMENT);
  5643. $return .= '<div style="margin:3px 10px;">';
  5644. $return .= '<p class="lp_title">'.get_lang("AddEditPrerequisites").'</p>';
  5645. $return .= '<form method="POST">';
  5646. $return .= '<table class="lp_form">';
  5647. $return .= '<tr>';
  5648. $return .= '<th></th>';
  5649. $return .= '<th class="exercise">'.get_lang("Minimum").'</th>';
  5650. $return .= '<th class="exercise">'.get_lang("Maximum").'</th>';
  5651. $return .= '</tr>';
  5652. $return .= '<tr>';
  5653. $return .= '<td class="radio" colspan="3">';
  5654. $return .= '<input checked="checked" id="idNone" name="prerequisites" style="margin-left:0; margin-right:10px;" type="radio" />';
  5655. $return .= '<label for="idNone">'.get_lang("None").'</label>';
  5656. $return .= '</td>';
  5657. $return .= '</tr>';
  5658. $sql = "
  5659. SELECT *
  5660. FROM " . $tbl_lp_item . "
  5661. WHERE
  5662. lp_id = " . $this->lp_id;
  5663. $result = api_sql_query($sql, __FILE__, __LINE__);
  5664. $arrLP = array();
  5665. while($row = Database::fetch_array($result))
  5666. {
  5667. $arrLP[] = array(
  5668. 'id' => $row['id'],
  5669. 'item_type' => $row['item_type'],
  5670. 'title' => $row['title'],
  5671. 'ref' => $row['ref'],
  5672. 'description' => $row['description'],
  5673. 'parent_item_id' => $row['parent_item_id'],
  5674. 'previous_item_id' => $row['previous_item_id'],
  5675. 'next_item_id' => $row['next_item_id'],
  5676. 'max_score' => $row['max_score'],
  5677. 'min_score' => $row['min_score'],
  5678. 'mastery_score' => $row['mastery_score'],
  5679. 'next_item_id' => $row['next_item_id'],
  5680. 'display_order' => $row['display_order']);
  5681. if($row['ref'] == $preq_id)
  5682. {
  5683. $preq_mastery = $row['mastery_score'];
  5684. $preq_max = $row['max_score'];
  5685. }
  5686. }
  5687. $this->tree_array($arrLP);
  5688. $arrLP = $this->arrMenu;
  5689. unset($this->arrMenu);
  5690. for($i = 0; $i < count($arrLP); $i++)
  5691. {
  5692. if($arrLP[$i]['id'] == $item_id)
  5693. break;
  5694. $return .= '<tr>';
  5695. $return .= '<td class="radio"' . (($arrLP[$i]['item_type'] != TOOL_QUIZ && $arrLP[$i]['item_type'] != TOOL_HOTPOTATOES) ? ' colspan="3"' : '') . '>';
  5696. $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'] . '" />';
  5697. $return .= '<img alt="" src="../img/lp_' . $arrLP[$i]['item_type'] . '.png" style="margin-right:5px;" title="" />';
  5698. $return .= '<label for="id' . $arrLP[$i]['id'] . '">' . stripslashes($arrLP[$i]['title']) . '</label>';
  5699. $return .= '</td>';
  5700. //$return .= '<td class="radio"' . (($arrLP[$i]['item_type'] != TOOL_HOTPOTATOES) ? ' colspan="3"' : '') . ' />';
  5701. if($arrLP[$i]['item_type'] == TOOL_QUIZ)
  5702. {
  5703. $return .= '<td class="exercise">';
  5704. $return .= '<input maxlength="3" name="min_' . $arrLP[$i]['id'] . '" type="text" value="' . (($arrLP[$i]['id'] == $preq_id) ? $preq_mastery : 0) . '" />';
  5705. $return .= '</td>';
  5706. $return .= '<td class="exercise">';
  5707. $return .= '<input maxlength="3" name="max_' . $arrLP[$i]['id'] . '" type="text" value="' . $arrLP[$i]['max_score'] . '" disabled="true" />';
  5708. $return .= '</td>';
  5709. }
  5710. if($arrLP[$i]['item_type'] == TOOL_HOTPOTATOES)
  5711. {
  5712. $return .= '<td class="exercise">';
  5713. $return .= '<input maxlength="3" name="min_' . $arrLP[$i]['id'] . '" type="text" value="' . (($arrLP[$i]['id'] == $preq_id) ? $preq_mastery : 0) . '" />';
  5714. $return .= '</td>';
  5715. $return .= '<td class="exercise">';
  5716. $return .= '<input maxlength="3" name="max_' . $arrLP[$i]['id'] . '" type="text" value="' . $arrLP[$i]['max_score'] . '" disabled="true" />';
  5717. $return .= '</td>';
  5718. }
  5719. $return .='</tr>';
  5720. }
  5721. $return .= '<tr>';
  5722. $return .= '<td colspan="3">';
  5723. $return .= '<input class="button" name="submit_button" type="submit" value="'.get_lang("Ok").'" /></td>' . "\n";
  5724. $return .= '</td>';
  5725. $return .= '</tr>';
  5726. $return .= '</table>';
  5727. $return .= '</form>';
  5728. $return .= '</div>';
  5729. return $return;
  5730. }
  5731. /**
  5732. * Creates a list with all the documents in it
  5733. *
  5734. * @return string
  5735. */
  5736. function get_documents()
  5737. {
  5738. global $_course;
  5739. $tbl_doc = Database::get_course_table(TABLE_DOCUMENT);
  5740. $sql_doc = "
  5741. SELECT *
  5742. FROM " . $tbl_doc . "
  5743. WHERE
  5744. path NOT LIKE '%_DELETED_%'
  5745. ORDER BY path ASC";
  5746. $res_doc = api_sql_query($sql_doc, __FILE__, __LINE__);
  5747. $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';}\"" . ' style="cursor:pointer;"><img align="left" alt="" src="../img/lp_' . TOOL_DOCUMENT . '.gif" style="margin-right:5px;" title="" />'.get_lang("Document").'</div>';
  5748. $return .= '<div class="lp_resource_elements" id="resDoc">';
  5749. $resources=api_store_result($res_doc);
  5750. $resources_sorted = array();
  5751. // if you want to debug it, I advise you to do "echo" on the eval statements
  5752. foreach($resources as $resource)
  5753. {
  5754. $resource_paths = explode('/',$resource['path']);
  5755. array_shift($resource_paths);
  5756. $path_to_eval = $last_path = '';
  5757. $is_file = false;
  5758. foreach($resource_paths as $key => $resource_path)
  5759. {
  5760. if(strpos($resource_path,'.')===false && $key != count($resource_paths)-1)
  5761. { // it's a folder
  5762. $path_to_eval .= '["'.$resource_path.'"]["files"]';
  5763. }
  5764. else if(strpos($resource_path,'.')!==false)
  5765. $is_file = true;
  5766. $last_path = $resource_path;
  5767. }
  5768. if($is_file)
  5769. {
  5770. eval('$resources_sorted'.$path_to_eval.'['.$resource['id'].'] = "'.$last_path.'";');
  5771. }
  5772. else
  5773. {
  5774. eval('$resources_sorted'.$path_to_eval.'["'.$last_path.'"]["id"]='.$resource['id'].';');
  5775. }
  5776. }
  5777. $return .=$this->write_resources_tree('', $resources_sorted);
  5778. $return .='</div>';
  5779. if(Database::num_rows($res_doc) == 0)
  5780. $return .= '<div class="lp_resource_element">'.get_lang("NoDocuments").'</div>';
  5781. return $return;
  5782. }
  5783. function write_resources_tree($return, $resources_sorted, $num=0){
  5784. include_once(api_get_path(LIBRARY_PATH).'fileDisplay.lib.php');
  5785. if(count($resources_sorted)>0)
  5786. {
  5787. foreach($resources_sorted as $key=>$resource)
  5788. {
  5789. if(is_int($resource['id']))
  5790. { // it's a folder
  5791. $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="testResources(\''.$resource["id"].'\',\'img_'.$resource["id"].'\')"><img alt="" src="../img/lp_folder.gif" title="" align="absmiddle" />&nbsp;<span onclick="testResources(\''.$resource["id"].'\',\'img_'.$resource["id"].'\')" style="cursor: pointer;" >'.$key.'</span></div><div style="display: none;" id="'.$resource['id'].'">';
  5792. $return = $this->write_resources_tree($return, $resource['files'], $num+1);
  5793. $return .= "</div></div>\r\n";
  5794. }
  5795. else
  5796. {
  5797. // it's a file
  5798. $icon = choose_image($resource);
  5799. $position = strrpos($icon,'.');
  5800. $icon=substr($icon,0,$position).'_small.gif';
  5801. $return .= '<div><div style="margin-left:' . (($num+1) * 15) . 'px;margin-right:5px;"><a href="' . api_get_self() . '?cidReq=' . $_GET['cidReq'] . '&amp;action=add_item&amp;type=' . TOOL_DOCUMENT . '&amp;file=' . $key . '&amp;lp_id=' . $this->lp_id . '"><img align="left" alt="" src="../img/'.$icon.'" title="" />&nbsp;'.$resource."</a></div></div>\r\n";
  5802. }
  5803. }
  5804. }
  5805. return $return;
  5806. }
  5807. /**
  5808. * Creates a list with all the exercises (quiz) in it
  5809. *
  5810. * @return string
  5811. */
  5812. function get_exercises()
  5813. {
  5814. // new for hotpotatoes
  5815. $uploadPath = DIR_HOTPOTATOES; //defined in main_api
  5816. $tbl_doc = Database::get_course_table(TABLE_DOCUMENT);
  5817. $tbl_quiz = Database::get_course_table(TABLE_QUIZ_TEST);
  5818. $sql_quiz = "
  5819. SELECT *
  5820. FROM " . $tbl_quiz . "
  5821. WHERE active<>'-1'
  5822. ORDER BY title ASC";
  5823. $sql_hot = "SELECT * FROM ".$tbl_doc." " .
  5824. " WHERE path LIKE '".$uploadPath."/%/%htm%'" .
  5825. " ORDER BY id ASC";
  5826. $res_quiz = api_sql_query($sql_quiz, __FILE__, __LINE__);
  5827. $res_hot = api_sql_query($sql_hot, __FILE__, __LINE__);
  5828. $return .= '<div class="lp_resource_header_end"' . " onclick=\"if(document.getElementById('resExercise').style.display == 'block') {document.getElementById('resExercise').style.display = 'none';} else {document.getElementById('resExercise').style.display = 'block';}\"" . ' style="cursor:pointer;"><img align="left" alt="" src="../img/lp_' . TOOL_QUIZ . '.gif" style="margin-right:5px;" title="" />'.get_lang('Quiz').'</div>';
  5829. $return .= '<div class="lp_resource_elements_end" id="resExercise">';
  5830. while ($row_hot = mysql_fetch_array($res_hot))
  5831. {
  5832. $return .= '<div class="lp_resource_element">';
  5833. //display quizhotpotatoes
  5834. $return .= '<img alt="" src="../img/jqz.jpg" style="margin-right:5px;" title="" />';
  5835. $return .= '<a href="' .api_get_self(). '?cidReq=' . $_GET['cidReq'] . '&amp;action=add_item&amp;type=' . TOOL_HOTPOTATOES . '&amp;file=' . $row_hot['id'] . '&amp;lp_id=' . $this->lp_id . '">' . $row_hot['title'] . '</a>';
  5836. //$return .= $row_quiz['title'];
  5837. $return .= '</div>';
  5838. }
  5839. while($row_quiz = Database::fetch_array($res_quiz))
  5840. {
  5841. $return .= '<div class="lp_resource_element">';
  5842. $return .= '<img alt="" src="../img/quizz_small.gif" style="margin-right:5px;" title="" />';
  5843. $return .= '<a href="' .api_get_self(). '?cidReq=' . $_GET['cidReq'] . '&amp;action=add_item&amp;type=' . TOOL_QUIZ . '&amp;file=' . $row_quiz['id'] . '&amp;lp_id=' . $this->lp_id . '">' . $row_quiz['title'] . '</a>';
  5844. //$return .= $row_quiz['title'];
  5845. $return .= '</div>';
  5846. }
  5847. if(Database::num_rows($res_quiz) == 0)
  5848. $return .= '<div class="lp_resource_element">'.get_lang("NoExercisesAvailable").'</div>';
  5849. $return .= '<div class="lp_resource_element">';
  5850. $return .= '<img alt="" src="../img/new_test_small.gif" style="margin-right:5px;" title="" />';
  5851. $return .= '<a href="'.api_get_path(REL_CODE_PATH).'exercice/exercise_admin.php">' . get_lang('NewExercise') . '</a>';
  5852. $return .= '</div>';
  5853. $return .= '</div>';
  5854. return $return;
  5855. }
  5856. /**
  5857. * Creates a list with all the links in it
  5858. *
  5859. * @return string
  5860. */
  5861. function get_links()
  5862. {
  5863. $tbl_link = Database::get_course_table(TABLE_LINK);
  5864. $sql_link = "
  5865. SELECT *
  5866. FROM " . $tbl_link . "
  5867. ORDER BY title ASC";
  5868. $res_link = api_sql_query($sql_link, __FILE__, __LINE__);
  5869. $return .= '<div class="lp_resource_header"' . " onclick=\"if(document.getElementById('resLink').style.display == 'block') {document.getElementById('resLink').style.display = 'none';} else {document.getElementById('resLink').style.display = 'block';}\"" . ' style="cursor:pointer;"><img align="left" alt="" src="../img/lp_' . TOOL_LINK . '.gif" style="margin-right:5px;" title="" />'.get_lang("Links").'</div>';
  5870. $return .= '<div class="lp_resource_elements" id="resLink">';
  5871. while($row_link = Database::fetch_array($res_link))
  5872. {
  5873. $return .= '<div class="lp_resource_element">';
  5874. $return .= '<img align="left" alt="" src="../img/file_html_small.gif" style="margin-right:5px;" title="" />';
  5875. $return .= '<a href="' .api_get_self(). '?cidReq=' . $_GET['cidReq'] . '&amp;action=add_item&amp;type=' . TOOL_LINK . '&amp;file=' . $row_link['id'] . '&amp;lp_id=' . $this->lp_id . '">' . $row_link['title'] . '</a>';
  5876. $return .= '</div>';
  5877. }
  5878. $return .= '<div class="lp_resource_element">';
  5879. $return .= '<img align="left" alt="" src="../img/file_html_new_small.gif" style="margin-right:5px;" title="" />';
  5880. $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>';
  5881. $return .= '</div>';
  5882. if(Database::num_rows($res_link) == 0)
  5883. $return .= '<div class="lp_resource_element">'.get_lang("NoLinksAvailable").'</div>';
  5884. $return .= '</div>';
  5885. return $return;
  5886. }
  5887. /**
  5888. * Creates a list with all the student publications in it
  5889. *
  5890. * @return unknown
  5891. */
  5892. function get_student_publications()
  5893. {
  5894. $tbl_student = Database::get_course_table(TABLE_STUDENT_PUBLICATION);
  5895. $sql_student = "
  5896. SELECT *
  5897. FROM " . $tbl_student . "
  5898. ORDER BY title ASC";
  5899. $res_student = api_sql_query($sql_student, __FILE__, __LINE__);
  5900. $return .= '<div class="lp_resource_header"' . " onclick=\"if(document.getElementById('resStudent').style.display == 'block') {document.getElementById('resStudent').style.display = 'none';} else {document.getElementById('resStudent').style.display = 'block';}\"" . ' style="border-bottom:1px solid #999999; cursor:pointer;"><img align="left" alt="" src="../img/lp_' . TOOL_STUDENTPUBLICATION . '.gif" style="margin-right:5px;" title="" />'.get_lang('Student_publication').'</div>';
  5901. $return .= '<div class="lp_resource_elements" id="resStudent" style="border-bottom:1px solid #999999; border-top:0;">';
  5902. $return .= '<div class="lp_resource_element">';
  5903. $return .= '<img align="left" alt="" src="../img/works_small.gif" style="margin-right:5px;" title="" />';
  5904. $return .= '<a href="' .api_get_self(). '?cidReq=' . $_GET['cidReq'] . '&amp;action=add_item&amp;type=' . TOOL_STUDENTPUBLICATION . '&amp;lp_id=' . $this->lp_id . '">' . get_lang('AddAssignmentPage') . '</a>';
  5905. $return .= '</div>';
  5906. $return .= '</div>';
  5907. return $return;
  5908. }
  5909. function get_forums()
  5910. {
  5911. include ('../forum/forumfunction.inc.php');
  5912. include ('../forum/forumconfig.inc.php');
  5913. global $table_forums, $table_threads,$table_posts, $table_item_property, $table_users;
  5914. $table_forums = Database :: get_course_table(TABLE_FORUM);
  5915. $table_threads = Database :: get_course_table(TABLE_FORUM_THREAD);
  5916. $table_posts = Database :: get_course_table(TABLE_FORUM_POST);
  5917. $table_item_property = Database :: get_course_table(TABLE_ITEM_PROPERTY);
  5918. $table_users = Database :: get_main_table(TABLE_MAIN_USER);
  5919. $a_forums = get_forums();
  5920. $return .= '<div class="lp_resource_header"' . " onclick=\"if(document.getElementById('forums').style.display == 'block') {document.getElementById('forums').style.display = 'none';} else {document.getElementById('forums').style.display = 'block';}\"" . ' style="border-bottom:1px solid #999999; cursor:pointer;"><img align="left" alt="" src="../img/lp_forum.gif" style="margin-right:5px;" title="" />'.get_lang('Forums').'</div>';
  5921. $return .= '<div class="lp_resource_elements" id="forums" style="border-bottom:1px solid #999999; border-top:0;">';
  5922. foreach($a_forums as $forum)
  5923. {
  5924. $return .= '<div class="lp_resource_element">';
  5925. $return .= '<script type="text/javascript">
  5926. function toggle_forum(forum_id){
  5927. if(document.getElementById("forum_"+forum_id+"_content").style.display == "none"){
  5928. document.getElementById("forum_"+forum_id+"_content").style.display = "block";
  5929. document.getElementById("forum_"+forum_id+"_opener").src = "'.api_get_path(WEB_IMG_PATH).'remove.gif";
  5930. }
  5931. else {
  5932. document.getElementById("forum_"+forum_id+"_content").style.display = "none";
  5933. document.getElementById("forum_"+forum_id+"_opener").src = "'.api_get_path(WEB_IMG_PATH).'add.gif";
  5934. }
  5935. }
  5936. </script>
  5937. ';
  5938. $return .= '<img align="left" alt="" src="../img/lp_forum.gif" style="margin-right:5px;" title="" />';
  5939. $return .= '<a style="cursor:hand" onclick="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>
  5940. <a href="' .api_get_self(). '?cidReq=' . $_GET['cidReq'] . '&amp;action=add_item&amp;type=' . TOOL_FORUM . '&amp;forum_id=' . $forum['forum_id'] . '&amp;lp_id=' . $this->lp_id . '" style="vertical-align:middle">' . $forum['forum_title'] . '</a><ul style="display:none" id="forum_'.$forum['forum_id'].'_content">';
  5941. $a_threads = get_threads($forum['forum_id']);
  5942. if(is_array($a_threads)){
  5943. foreach($a_threads as $thread)
  5944. {
  5945. $return .= '<li><a href="' .api_get_self(). '?cidReq=' . $_GET['cidReq'] . '&amp;action=add_item&amp;type=' . TOOL_THREAD . '&amp;thread_id=' . $thread['thread_id'] . '&amp;lp_id=' . $this->lp_id . '">' . $thread['thread_title'] . '</a></li>';
  5946. }
  5947. }
  5948. $return .= '</ul></div>';
  5949. }
  5950. $return .= '<div class="lp_resource_element">';
  5951. $return .= '<img align="left" alt="" src="../img/forum_new_small.gif" style="margin-right:5px;" title="" />';
  5952. $return .= '<a href="'.api_get_path(REL_CODE_PATH).'forum/index.php?'.api_get_cidreq().'&action=add&amp;content=forum" title="'.get_lang('CreateANewForum').'">'.get_lang('CreateANewForum').'</a>';
  5953. $return .= '</div>';
  5954. return $return;
  5955. }
  5956. /**
  5957. * Exports the learning path as a SCORM package. This is the main function that
  5958. * gathers the content, transforms it, writes the imsmanifest.xml file, zips the
  5959. * whole thing and returns the zip.
  5960. *
  5961. * This method needs to be called in PHP5, as it will fail with non-adequate
  5962. * XML package (like the ones for PHP4), and it is *not* a static method, so
  5963. * you need to call it on a learnpath object.
  5964. * @TODO The method might be redefined later on in the scorm class itself to avoid
  5965. * creating a SCORM structure if there is one already. However, if the initial SCORM
  5966. * path has been modified, it should use the generic method here below.
  5967. * @TODO link this function with the export_lp() function in the same class
  5968. * @param string Optional name of zip file. If none, title of learnpath is
  5969. * domesticated and trailed with ".zip"
  5970. * @return string Returns the zip package string, or null if error
  5971. */
  5972. function scorm_export()
  5973. {
  5974. global $_course;
  5975. if (!class_exists('DomDocument'))
  5976. {
  5977. error_log('DOM functions not supported for PHP version below 5.0',0);
  5978. $this->error = 'PHP DOM functions not supported for PHP versions below 5.0';
  5979. return null;
  5980. }
  5981. //remove memory and time limits as much as possible as this might be a long process...
  5982. if(function_exists('ini_set'))
  5983. {
  5984. $mem = ini_get('memory_limit');
  5985. if(substr($mem,-1,1)=='M')
  5986. {
  5987. $mem_num = substr($mem,0,-1);
  5988. if($mem_num<128)
  5989. {
  5990. ini_set('memory_limit','128M');
  5991. }
  5992. }
  5993. else
  5994. {
  5995. ini_set('memory_limit','128M');
  5996. }
  5997. ini_set('max_execution_time',600);
  5998. //}else{
  5999. //error_log('Scorm export: could not change memory and time limits',0);
  6000. }
  6001. //Create the zip handler (this will remain available throughout the method)
  6002. $garbage_path = api_get_path(GARBAGE_PATH);
  6003. $sys_course_path = api_get_path(SYS_COURSE_PATH);
  6004. $temp_dir_short = uniqid();
  6005. $temp_zip_dir = $garbage_path."/".$temp_dir_short;
  6006. $temp_zip_file = $temp_zip_dir."/".md5(time()).".zip";
  6007. $zip_folder=new PclZip($temp_zip_file);
  6008. $current_course_path = api_get_path(SYS_COURSE_PATH).api_get_course_path();
  6009. $root_path = $main_path = api_get_path(SYS_PATH);
  6010. $files_cleanup = array();
  6011. //place to temporarily stash the zipfiles
  6012. //create the temp dir if it doesn't exist
  6013. //or do a cleanup befor creating the zipfile
  6014. if(!is_dir($temp_zip_dir))
  6015. {
  6016. mkdir($temp_zip_dir);
  6017. }
  6018. else
  6019. {//cleanup: check the temp dir for old files and delete them
  6020. $handle=opendir($temp_zip_dir);
  6021. while (false!==($file = readdir($handle)))
  6022. {
  6023. if ($file != "." && $file != "..")
  6024. {
  6025. unlink("$temp_zip_dir/$file");
  6026. }
  6027. }
  6028. closedir($handle);
  6029. }
  6030. $zip_files = $zip_files_abs = $zip_files_dist = array();
  6031. if(is_dir($current_course_path.'/scorm/'.$this->path) && is_file($current_course_path.'/scorm/'.$this->path.'/imsmanifest.xml'))
  6032. {
  6033. // remove the possible . at the end of the path
  6034. $dest_path_to_lp = substr($this->path, -1) == '.' ? substr($this->path, 0, -1) : $this->path;
  6035. $dest_path_to_scorm_folder = str_replace('//','/',$temp_zip_dir.'/scorm/'.$dest_path_to_lp);
  6036. $perm = api_get_setting('permissions_for_new_directories');
  6037. $perm = octdec(!empty($perm)?$perm:'0770');
  6038. mkdir ($dest_path_to_scorm_folder, $perm, true);
  6039. $zip_files_dist = copyr($current_course_path.'/scorm/'.$this->path, $dest_path_to_scorm_folder, array('imsmanifest'), $zip_files);
  6040. }
  6041. //Build a dummy imsmanifest structure. Do not add to the zip yet (we still need it)
  6042. //This structure is developed following regulations for SCORM 1.2 packaging in the SCORM 1.2 Content
  6043. //Aggregation Model official document, secion "2.3 Content Packaging"
  6044. $xmldoc = new DOMDocument('1.0',$this->encoding);
  6045. $root = $xmldoc->createElement('manifest');
  6046. $root->setAttribute('identifier','SingleCourseManifest');
  6047. $root->setAttribute('version','1.1');
  6048. $root->setAttribute('xmlns','http://www.imsproject.org/xsd/imscp_rootv1p1p2');
  6049. $root->setAttribute('xmlns:adlcp','http://www.adlnet.org/xsd/adlcp_rootv1p2');
  6050. $root->setAttribute('xmlns:xsi','http://www.w3.org/2001/XMLSchema-instance');
  6051. $root->setAttribute('xsi:schemaLocation','http://www.imsproject.org/xsd/imscp_rootv1p1p2 imscp_rootv1p1p2.xsd
  6052. http://www.imsglobal.org/xsd/imsmd_rootv1p2p1 imsmd_rootv1p2p1.xsd
  6053. http://www.adlnet.org/xsd/adlcp_rootv1p2 adlcp_rootv1p2.xsd');
  6054. //Build mandatory sub-root container elements
  6055. $metadata = $xmldoc->createElement('metadata');
  6056. $md_schema = $xmldoc->createElement('schema','ADL SCORM');
  6057. $metadata->appendChild($md_schema);
  6058. $md_schemaversion = $xmldoc->createElement('schemaversion','1.2');
  6059. $metadata->appendChild($md_schemaversion);
  6060. $root->appendChild($metadata);
  6061. $organizations = $xmldoc->createElement('organizations');
  6062. $resources = $xmldoc->createElement('resources');
  6063. //Build the only organization we will use in building our learnpaths
  6064. $organizations->setAttribute('default','dokeos_scorm_export');
  6065. $organization = $xmldoc->createElement('organization');
  6066. $organization->setAttribute('identifier','dokeos_scorm_export');
  6067. //to set the title of the SCORM entity (=organization), we take the name given
  6068. //in Dokeos and convert it to HTML entities using the Dokeos charset (not the
  6069. //learning path charset) as it is the encoding that defines how it is stored
  6070. //in the database. Then we convert it to HTML entities again as the "&" character
  6071. //alone is not authorized in XML (must be &amp;)
  6072. //The title is then decoded twice when extracting (see scorm::parse_manifest)
  6073. global $charset;
  6074. $org_title = $xmldoc->createElement('title',htmlentities(htmlentities($this->get_name(),ENT_QUOTES,$charset)));
  6075. $organization->appendChild($org_title);
  6076. //For each element, add it to the imsmanifest structure, then add it to the zip.
  6077. //Always call the learnpathItem->scorm_export() method to change it to the SCORM
  6078. //format
  6079. $link_updates = array();
  6080. foreach($this->items as $index => $item){
  6081. if(!in_array($item->type , array(TOOL_QUIZ, TOOL_FORUM, TOOL_THREAD, TOOL_LINK, TOOL_STUDENTPUBLICATION)))
  6082. {
  6083. //get included documents from this item
  6084. if($item->type=='sco')
  6085. $inc_docs = $item->get_resources_from_source(null,api_get_path(SYS_COURSE_PATH).api_get_course_path().'/'.'scorm/'.$this->path.'/'.$item->get_path());
  6086. else
  6087. $inc_docs = $item->get_resources_from_source();
  6088. //give a child element <item> to the <organization> element
  6089. $my_item_id = $item->get_id();
  6090. $my_item = $xmldoc->createElement('item');
  6091. $my_item->setAttribute('identifier','ITEM_'.$my_item_id);
  6092. $my_item->setAttribute('identifierref','RESOURCE_'.$my_item_id);
  6093. $my_item->setAttribute('isvisible','true');
  6094. //give a child element <title> to the <item> element
  6095. $my_title = $xmldoc->createElement('title',htmlspecialchars($item->get_title(),ENT_QUOTES));
  6096. $my_item->appendChild($my_title);
  6097. //give a child element <adlcp:prerequisites> to the <item> element
  6098. $my_prereqs = $xmldoc->createElement('adlcp:prerequisites',$this->get_scorm_prereq_string($my_item_id));
  6099. $my_prereqs->setAttribute('type','aicc_script');
  6100. $my_item->appendChild($my_prereqs);
  6101. //give a child element <adlcp:maxtimeallowed> to the <item> element - not yet supported
  6102. //$xmldoc->createElement('adlcp:maxtimeallowed','');
  6103. //give a child element <adlcp:timelimitaction> to the <item> element - not yet supported
  6104. //$xmldoc->createElement('adlcp:timelimitaction','');
  6105. //give a child element <adlcp:datafromlms> to the <item> element - not yet supported
  6106. //$xmldoc->createElement('adlcp:datafromlms','');
  6107. //give a child element <adlcp:masteryscore> to the <item> element
  6108. $my_masteryscore = $xmldoc->createElement('adlcp:masteryscore',$item->masteryscore);
  6109. $my_item->appendChild($my_masteryscore);
  6110. //attach this item to the organization element or hits parent if there is one
  6111. if(!empty($item->parent) && $item->parent!=0)
  6112. {
  6113. $children = $organization->childNodes;
  6114. $possible_parent = &$this->get_scorm_xml_node($children,'ITEM_'.$item->parent);
  6115. if(is_object($possible_parent))
  6116. {
  6117. $possible_parent->appendChild($my_item);
  6118. }
  6119. else
  6120. {
  6121. if($this->debug>0){error_log('Parent ITEM_'.$item->parent.' of item ITEM_'.$my_item_id.' not found');}
  6122. }
  6123. }
  6124. else
  6125. {
  6126. if($this->debug>0){error_log('No parent');}
  6127. $organization->appendChild($my_item);
  6128. }
  6129. //get the path of the file(s) from the course directory root
  6130. $my_file_path = $item->get_file_path('scorm/'.$this->path.'/');
  6131. $my_xml_file_path = htmlentities($my_file_path);
  6132. $my_sub_dir = dirname($my_file_path);
  6133. $my_xml_sub_dir = htmlentities($my_sub_dir);
  6134. //give a <resource> child to the <resources> element
  6135. $my_resource = $xmldoc->createElement('resource');
  6136. $my_resource->setAttribute('identifier','RESOURCE_'.$item->get_id());
  6137. $my_resource->setAttribute('type','webcontent');
  6138. $my_resource->setAttribute('href',$my_xml_file_path);
  6139. //adlcp:scormtype can be either 'sco' or 'asset'
  6140. if($item->type=='sco')
  6141. {
  6142. $my_resource->setAttribute('adlcp:scormtype','sco');
  6143. }
  6144. else
  6145. {
  6146. $my_resource->setAttribute('adlcp:scormtype','asset');
  6147. }
  6148. //xml:base is the base directory to find the files declared in this resource
  6149. $my_resource->setAttribute('xml:base','');
  6150. //give a <file> child to the <resource> element
  6151. $my_file = $xmldoc->createElement('file');
  6152. $my_file->setAttribute('href',$my_xml_file_path);
  6153. $my_resource->appendChild($my_file);
  6154. //dependency to other files - not yet supported
  6155. $i = 1;
  6156. foreach($inc_docs as $doc_info)
  6157. {
  6158. if(count($doc_info)<1 or empty($doc_info[0])){continue;}
  6159. $my_dep = $xmldoc->createElement('resource');
  6160. $res_id = 'RESOURCE_'.$item->get_id().'_'.$i;
  6161. $my_dep->setAttribute('identifier',$res_id);
  6162. $my_dep->setAttribute('type','webcontent');
  6163. $my_dep->setAttribute('adlcp:scormtype','asset');
  6164. $my_dep_file = $xmldoc->createElement('file');
  6165. //check type of URL
  6166. //error_log('Now dealing with '.$doc_info[0].' of type '.$doc_info[1].'-'.$doc_info[2],0);
  6167. if($doc_info[1] == 'remote')
  6168. { //remote file. Save url as is
  6169. $my_dep_file->setAttribute('href',$doc_info[0]);
  6170. $my_dep->setAttribute('xml:base','');
  6171. }elseif($doc_info[1] == 'local'){
  6172. switch($doc_info[2])
  6173. {
  6174. case 'url': //local URL - save path as url for now, don't zip file
  6175. $abs_path = api_get_path(SYS_PATH).str_replace(api_get_path(WEB_PATH),'',$doc_info[0]);
  6176. $current_dir = dirname($abs_path);
  6177. $file_path = realpath($abs_path);
  6178. $my_dep_file->setAttribute('href',$file_path);
  6179. $my_dep->setAttribute('xml:base','');
  6180. if(strstr($file_path,$main_path) !== false)
  6181. {//the calculated real path is really inside the dokeos root path
  6182. //reduce file path to what's under the DocumentRoot
  6183. $file_path = substr($file_path,strlen($root_path));
  6184. //echo $file_path;echo '<br><br>';
  6185. //error_log('Reduced path: '.$file_path,0);
  6186. $zip_files_abs[] = $file_path;
  6187. $link_updates[$my_file_path][] = array('orig'=>$doc_info[0],'dest'=>$file_path);
  6188. $my_dep_file->setAttribute('href',$file_path);
  6189. $my_dep->setAttribute('xml:base','');
  6190. }
  6191. else if (empty($file_path))
  6192. {
  6193. /*$document_root = substr(api_get_path(SYS_PATH), 0, strpos(api_get_path(SYS_PATH),api_get_path(REL_PATH)));
  6194. if(strpos($document_root,-1)=='/')
  6195. {
  6196. $document_root = substr(0, -1, $document_root);
  6197. }*/
  6198. $file_path = $_SERVER['DOCUMENT_ROOT'].$abs_path;
  6199. $file_path = str_replace('//','/',$file_path);
  6200. if(file_exists($file_path))
  6201. {
  6202. $file_path = substr($file_path,strlen($current_dir)); // we get the relative path
  6203. $zip_files[] = $my_sub_dir.'/'.$file_path;
  6204. $link_updates[$my_file_path][] = array('orig'=>$doc_info[0],'dest'=>$file_path);
  6205. $my_dep_file->setAttribute('href',$file_path);
  6206. $my_dep->setAttribute('xml:base','');
  6207. }
  6208. }
  6209. break;
  6210. case 'abs': //absolute path from DocumentRoot. Save file and leave path as is in the zip
  6211. $my_dep_file->setAttribute('href',$doc_info[0]);
  6212. $my_dep->setAttribute('xml:base','');
  6213. //$current_dir = dirname($current_course_path.'/'.$item->get_file_path()).'/';
  6214. $file_path = realpath(api_get_path(SYS_PATH).$doc_info[0]);
  6215. $file_path = str_replace('//','/',$file_path);
  6216. //prepare the current directory path (until just under 'document') with a trailing slash
  6217. $cur_path = substr($current_course_path,-1)=='/'?$current_course_path:$current_course_path.'/';
  6218. //check if the current document is in that path
  6219. if(strstr($file_path,$cur_path) !== false)
  6220. {
  6221. //the document is in that path, now get the relative path
  6222. //to the containing document
  6223. $orig_file_path = dirname($cur_path.$my_file_path).'/';
  6224. $relative_path ='';
  6225. if(strstr($file_path,$cur_path)!==false)
  6226. {
  6227. $relative_path = substr($file_path,strlen($orig_file_path));
  6228. $file_path = substr($file_path,strlen($cur_path));
  6229. }
  6230. else
  6231. {
  6232. //this case is still a problem as it's difficult to calculate a relative path easily
  6233. //might still generate wrong links
  6234. //$file_path = substr($file_path,strlen($cur_path));
  6235. //calculate the directory path to the current file (without trailing slash)
  6236. $my_relative_path = dirname($file_path);
  6237. $my_relative_file = basename($file_path);
  6238. //calculate the directory path to the containing file (without trailing slash)
  6239. $my_orig_file_path = substr($orig_file_path,0,-1);
  6240. $dotdot = '';
  6241. $subdir = '';
  6242. while(strstr($my_relative_path,$my_orig_file_path)===false && (strlen($my_orig_file_path)>1) && (strlen($my_relative_path)>1))
  6243. {
  6244. $my_relative_path2 = dirname($my_relative_path);
  6245. $my_orig_file_path = dirname($my_orig_file_path);
  6246. $subdir = substr($my_relative_path,strlen($my_relative_path2)+1)."/".$subdir;
  6247. $dotdot += '../';
  6248. $my_relative_path = $my_relative_path2;
  6249. }
  6250. $relative_path = $dotdot.$subdir.$my_relative_file;
  6251. }
  6252. //put the current document in the zip (this array is the array
  6253. //that will manage documents already in the course folder - relative)
  6254. $zip_files[] = $file_path;
  6255. //update the links to the current document in the containing document (make them relative)
  6256. $link_updates[$my_file_path][] = array('orig'=>$doc_info[0],'dest'=>$relative_path);
  6257. $my_dep_file->setAttribute('href',$file_path);
  6258. $my_dep->setAttribute('xml:base','');
  6259. }
  6260. elseif(strstr($file_path,$main_path) !== false)
  6261. {//the calculated real path is really inside the dokeos root path
  6262. //reduce file path to what's under the DocumentRoot
  6263. $file_path = substr($file_path,strlen($root_path));
  6264. //echo $file_path;echo '<br><br>';
  6265. //error_log('Reduced path: '.$file_path,0);
  6266. $zip_files_abs[] = $file_path;
  6267. $link_updates[$my_file_path][] = array('orig'=>$doc_info[0],'dest'=>$file_path);
  6268. $my_dep_file->setAttribute('href','document/'.$file_path);
  6269. $my_dep->setAttribute('xml:base','');
  6270. }
  6271. else if (empty($file_path))
  6272. {
  6273. /*$document_root = substr(api_get_path(SYS_PATH), 0, strpos(api_get_path(SYS_PATH),api_get_path(REL_PATH)));
  6274. if(strpos($document_root,-1)=='/')
  6275. {
  6276. $document_root = substr(0, -1, $document_root);
  6277. }*/
  6278. $file_path = $_SERVER['DOCUMENT_ROOT'].$doc_info[0];
  6279. $file_path = str_replace('//','/',$file_path);
  6280. if(file_exists($file_path))
  6281. {
  6282. $file_path = substr($file_path,strlen($current_dir)); // we get the relative path
  6283. $zip_files[] = $my_sub_dir.'/'.$file_path;
  6284. $link_updates[$my_file_path][] = array('orig'=>$doc_info[0],'dest'=>$file_path);
  6285. $my_dep_file->setAttribute('href','document/'.$file_path);
  6286. $my_dep->setAttribute('xml:base','');
  6287. }
  6288. }
  6289. break;
  6290. case 'rel': //path relative to the current document. Save xml:base as current document's directory and save file in zip as subdir.file_path
  6291. if(substr($doc_info[0],0,2)=='..')
  6292. { //relative path going up
  6293. $current_dir = dirname($current_course_path.'/'.$item->get_file_path()).'/';
  6294. $file_path = realpath($current_dir.$doc_info[0]);
  6295. //error_log($file_path.' <-> '.$main_path,0);
  6296. if(strstr($file_path,$main_path) !== false)
  6297. {//the calculated real path is really inside the dokeos root path
  6298. //reduce file path to what's under the DocumentRoot
  6299. $file_path = substr($file_path,strlen($root_path));
  6300. //error_log('Reduced path: '.$file_path,0);
  6301. $zip_files_abs[] = $file_path;
  6302. $link_updates[$my_file_path][] = array('orig'=>$doc_info[0],'dest'=>$file_path);
  6303. $my_dep_file->setAttribute('href','document/'.$file_path);
  6304. $my_dep->setAttribute('xml:base','');
  6305. }
  6306. }else{
  6307. $zip_files[] = $my_sub_dir.'/'.$doc_info[0];
  6308. $my_dep_file->setAttribute('href',$doc_info[0]);
  6309. $my_dep->setAttribute('xml:base',$my_xml_sub_dir);
  6310. }
  6311. break;
  6312. default:
  6313. $my_dep_file->setAttribute('href',$doc_info[0]);
  6314. $my_dep->setAttribute('xml:base','');
  6315. break;
  6316. }
  6317. }
  6318. $my_dep->appendChild($my_dep_file);
  6319. $resources->appendChild($my_dep);
  6320. $dependency = $xmldoc->createElement('dependency');
  6321. $dependency->setAttribute('identifierref',$res_id);
  6322. $my_resource->appendChild($dependency);
  6323. $i++;
  6324. }
  6325. //$my_dependency = $xmldoc->createElement('dependency');
  6326. //$my_dependency->setAttribute('identifierref','');
  6327. $resources->appendChild($my_resource);
  6328. $zip_files[] = $my_file_path;
  6329. //error_log('File '.$my_file_path. ' added to $zip_files',0);
  6330. }
  6331. else
  6332. { // if the item is a quiz or a link or whatever non-exportable, we include a step indicating it
  6333. if($item->type == TOOL_LINK)
  6334. {
  6335. $my_item = $xmldoc->createElement('item');
  6336. $my_item->setAttribute('identifier','ITEM_'.$item->get_id());
  6337. $my_item->setAttribute('identifierref','RESOURCE_'.$item->get_id());
  6338. $my_item->setAttribute('isvisible','true');
  6339. //give a child element <title> to the <item> element
  6340. $my_title = $xmldoc->createElement('title',htmlspecialchars($item->get_title(),ENT_QUOTES));
  6341. $my_item->appendChild($my_title);
  6342. //give a child element <adlcp:prerequisites> to the <item> element
  6343. $my_prereqs = $xmldoc->createElement('adlcp:prerequisites',$item->get_prereq_string());
  6344. $my_prereqs->setAttribute('type','aicc_script');
  6345. $my_item->appendChild($my_prereqs);
  6346. //give a child element <adlcp:maxtimeallowed> to the <item> element - not yet supported
  6347. //$xmldoc->createElement('adlcp:maxtimeallowed','');
  6348. //give a child element <adlcp:timelimitaction> to the <item> element - not yet supported
  6349. //$xmldoc->createElement('adlcp:timelimitaction','');
  6350. //give a child element <adlcp:datafromlms> to the <item> element - not yet supported
  6351. //$xmldoc->createElement('adlcp:datafromlms','');
  6352. //give a child element <adlcp:masteryscore> to the <item> element
  6353. $my_masteryscore = $xmldoc->createElement('adlcp:masteryscore',$item->masteryscore);
  6354. $my_item->appendChild($my_masteryscore);
  6355. //attach this item to the organization element or its parent if there is one
  6356. if(!empty($item->parent) && $item->parent!=0)
  6357. {
  6358. $children = $organization->childNodes;
  6359. for($i=0;$i<$children->length;$i++){
  6360. $item_temp = $children->item($i);
  6361. if ($item_temp -> nodeName == 'item')
  6362. {
  6363. if($item_temp->getAttribute('identifier') == 'ITEM_'.$item->parent)
  6364. {
  6365. $item_temp -> appendChild($my_item);
  6366. }
  6367. }
  6368. }
  6369. }
  6370. else
  6371. {
  6372. $organization->appendChild($my_item);
  6373. }
  6374. $my_file_path = 'link_'.$item->get_id().'.html';
  6375. $sql = 'SELECT url, title FROM '.Database :: get_course_table(TABLE_LINK).' WHERE id='.$item->path;
  6376. $rs = api_sql_query($sql, __FILE__, __LINE__);
  6377. if($link = Database :: fetch_array($rs))
  6378. {
  6379. $url = $link['url'];
  6380. $title = stripslashes($link['title']);
  6381. $links_to_create[$my_file_path] = array('title'=>$title,'url'=>$url);
  6382. $my_xml_file_path = htmlentities($my_file_path);
  6383. $my_sub_dir = dirname($my_file_path);
  6384. $my_xml_sub_dir = htmlentities($my_sub_dir);
  6385. //give a <resource> child to the <resources> element
  6386. $my_resource = $xmldoc->createElement('resource');
  6387. $my_resource->setAttribute('identifier','RESOURCE_'.$item->get_id());
  6388. $my_resource->setAttribute('type','webcontent');
  6389. $my_resource->setAttribute('href',$my_xml_file_path);
  6390. //adlcp:scormtype can be either 'sco' or 'asset'
  6391. $my_resource->setAttribute('adlcp:scormtype','asset');
  6392. //xml:base is the base directory to find the files declared in this resource
  6393. $my_resource->setAttribute('xml:base','');
  6394. //give a <file> child to the <resource> element
  6395. $my_file = $xmldoc->createElement('file');
  6396. $my_file->setAttribute('href',$my_xml_file_path);
  6397. $my_resource->appendChild($my_file);
  6398. $resources->appendChild($my_resource);
  6399. }
  6400. }
  6401. elseif($item->type == TOOL_QUIZ)
  6402. {
  6403. require_once(api_get_path(SYS_CODE_PATH).'exercice/exercise.class.php');
  6404. $exe_id = $item->path; //should be using ref when everything will be cleaned up in this regard
  6405. $exe = new Exercise();
  6406. $exe->read($exe_id);
  6407. $my_item = $xmldoc->createElement('item');
  6408. $my_item->setAttribute('identifier','ITEM_'.$item->get_id());
  6409. $my_item->setAttribute('identifierref','RESOURCE_'.$item->get_id());
  6410. $my_item->setAttribute('isvisible','true');
  6411. //give a child element <title> to the <item> element
  6412. $my_title = $xmldoc->createElement('title',htmlspecialchars($item->get_title(),ENT_QUOTES));
  6413. $my_item->appendChild($my_title);
  6414. //give a child element <adlcp:prerequisites> to the <item> element
  6415. $my_prereqs = $xmldoc->createElement('adlcp:prerequisites',$item->get_prereq_string());
  6416. $my_prereqs->setAttribute('type','aicc_script');
  6417. $my_item->appendChild($my_prereqs);
  6418. //give a child element <adlcp:masteryscore> to the <item> element
  6419. $my_masteryscore = $xmldoc->createElement('adlcp:masteryscore',$item->masteryscore);
  6420. $my_item->appendChild($my_masteryscore);
  6421. //attach this item to the organization element or hits parent if there is one
  6422. if(!empty($item->parent) && $item->parent!=0)
  6423. {
  6424. $children = $organization->childNodes;
  6425. for($i=0;$i<$children->length;$i++){
  6426. $item_temp = $children->item($i);
  6427. if ($item_temp -> nodeName == 'item')
  6428. {
  6429. if($item_temp->getAttribute('identifier') == 'ITEM_'.$item->parent)
  6430. {
  6431. $item_temp -> appendChild($my_item);
  6432. }
  6433. }
  6434. }
  6435. }
  6436. else
  6437. {
  6438. $organization->appendChild($my_item);
  6439. }
  6440. //include export scripts
  6441. require_once(api_get_path(SYS_CODE_PATH).'exercice/export/scorm/scorm_export.php');
  6442. //get the path of the file(s) from the course directory root
  6443. //$my_file_path = $item->get_file_path('scorm/'.$this->path.'/');
  6444. $my_file_path = 'quiz_'.$item->get_id().'.html';
  6445. //write the contents of the exported exercise into a (big) html file
  6446. //to later pack it into the exported SCORM. The file will be removed afterwards
  6447. $contents = export_exercise($exe_id,true);
  6448. $tmp_file_path = $garbage_path.$temp_dir_short.'/'.$my_file_path;
  6449. $res = file_put_contents($tmp_file_path,$contents);
  6450. if($res === false){error_log('Could not write into file '.$tmp_file_path.' '.__FILE__.' '.__LINE__,0);}
  6451. $files_cleanup[] = $tmp_file_path;
  6452. //error_log($tmp_path);die();
  6453. $my_xml_file_path = htmlentities($my_file_path);
  6454. $my_sub_dir = dirname($my_file_path);
  6455. $my_xml_sub_dir = htmlentities($my_sub_dir);
  6456. //give a <resource> child to the <resources> element
  6457. $my_resource = $xmldoc->createElement('resource');
  6458. $my_resource->setAttribute('identifier','RESOURCE_'.$item->get_id());
  6459. $my_resource->setAttribute('type','webcontent');
  6460. $my_resource->setAttribute('href',$my_xml_file_path);
  6461. //adlcp:scormtype can be either 'sco' or 'asset'
  6462. $my_resource->setAttribute('adlcp:scormtype','sco');
  6463. //xml:base is the base directory to find the files declared in this resource
  6464. $my_resource->setAttribute('xml:base','');
  6465. //give a <file> child to the <resource> element
  6466. $my_file = $xmldoc->createElement('file');
  6467. $my_file->setAttribute('href',$my_xml_file_path);
  6468. $my_resource->appendChild($my_file);
  6469. //get included docs
  6470. $inc_docs = $item->get_resources_from_source(null,$tmp_file_path);
  6471. //dependency to other files - not yet supported
  6472. $i = 1;
  6473. foreach($inc_docs as $doc_info)
  6474. {
  6475. if(count($doc_info)<1 or empty($doc_info[0])){continue;}
  6476. $my_dep = $xmldoc->createElement('resource');
  6477. $res_id = 'RESOURCE_'.$item->get_id().'_'.$i;
  6478. $my_dep->setAttribute('identifier',$res_id);
  6479. $my_dep->setAttribute('type','webcontent');
  6480. $my_dep->setAttribute('adlcp:scormtype','asset');
  6481. $my_dep_file = $xmldoc->createElement('file');
  6482. //check type of URL
  6483. //error_log('Now dealing with '.$doc_info[0].' of type '.$doc_info[1].'-'.$doc_info[2],0);
  6484. if($doc_info[1] == 'remote')
  6485. { //remote file. Save url as is
  6486. $my_dep_file->setAttribute('href',$doc_info[0]);
  6487. $my_dep->setAttribute('xml:base','');
  6488. }elseif($doc_info[1] == 'local'){
  6489. switch($doc_info[2])
  6490. {
  6491. case 'url': //local URL - save path as url for now, don't zip file
  6492. //save file but as local file (retrieve from URL)
  6493. $abs_path = api_get_path(SYS_PATH).str_replace(api_get_path(WEB_PATH),'',$doc_info[0]);
  6494. $current_dir = dirname($abs_path);
  6495. $file_path = realpath($abs_path);
  6496. $my_dep_file->setAttribute('href','document/'.$file_path);
  6497. $my_dep->setAttribute('xml:base','');
  6498. if(strstr($file_path,$main_path) !== false)
  6499. {//the calculated real path is really inside the dokeos root path
  6500. //reduce file path to what's under the DocumentRoot
  6501. $file_path = substr($file_path,strlen($root_path));
  6502. //echo $file_path;echo '<br><br>';
  6503. //error_log('Reduced path: '.$file_path,0);
  6504. $zip_files_abs[] = $file_path;
  6505. $link_updates[$my_file_path][] = array('orig'=>$doc_info[0],'dest'=>'document/'.$file_path);
  6506. $my_dep_file->setAttribute('href','document/'.$file_path);
  6507. $my_dep->setAttribute('xml:base','');
  6508. }
  6509. else if (empty($file_path))
  6510. {
  6511. /*$document_root = substr(api_get_path(SYS_PATH), 0, strpos(api_get_path(SYS_PATH),api_get_path(REL_PATH)));
  6512. if(strpos($document_root,-1)=='/')
  6513. {
  6514. $document_root = substr(0, -1, $document_root);
  6515. }*/
  6516. $file_path = $_SERVER['DOCUMENT_ROOT'].$abs_path;
  6517. $file_path = str_replace('//','/',$file_path);
  6518. if(file_exists($file_path))
  6519. {
  6520. $file_path = substr($file_path,strlen($current_dir)); // we get the relative path
  6521. $zip_files[] = $my_sub_dir.'/'.$file_path;
  6522. $link_updates[$my_file_path][] = array('orig'=>$doc_info[0],'dest'=>'document/'.$file_path);
  6523. $my_dep_file->setAttribute('href','document/'.$file_path);
  6524. $my_dep->setAttribute('xml:base','');
  6525. }
  6526. }
  6527. break;
  6528. case 'abs': //absolute path from DocumentRoot. Save file and leave path as is in the zip
  6529. $current_dir = dirname($current_course_path.'/'.$item->get_file_path()).'/';
  6530. $file_path = realpath($doc_info[0]);
  6531. $my_dep_file->setAttribute('href',$file_path);
  6532. $my_dep->setAttribute('xml:base','');
  6533. if(strstr($file_path,$main_path) !== false)
  6534. {//the calculated real path is really inside the dokeos root path
  6535. //reduce file path to what's under the DocumentRoot
  6536. $file_path = substr($file_path,strlen($root_path));
  6537. //echo $file_path;echo '<br><br>';
  6538. //error_log('Reduced path: '.$file_path,0);
  6539. $zip_files_abs[] = $file_path;
  6540. $link_updates[$my_file_path][] = array('orig'=>$doc_info[0],'dest'=>$file_path);
  6541. $my_dep_file->setAttribute('href','document/'.$file_path);
  6542. $my_dep->setAttribute('xml:base','');
  6543. }
  6544. else if (empty($file_path))
  6545. {
  6546. /*$document_root = substr(api_get_path(SYS_PATH), 0, strpos(api_get_path(SYS_PATH),api_get_path(REL_PATH)));
  6547. if(strpos($document_root,-1)=='/')
  6548. {
  6549. $document_root = substr(0, -1, $document_root);
  6550. }*/
  6551. $file_path = $_SERVER['DOCUMENT_ROOT'].$doc_info[0];
  6552. $file_path = str_replace('//','/',$file_path);
  6553. if(file_exists($file_path))
  6554. {
  6555. $file_path = substr($file_path,strlen($current_dir)); // we get the relative path
  6556. $zip_files[] = $my_sub_dir.'/'.$file_path;
  6557. $link_updates[$my_file_path][] = array('orig'=>$doc_info[0],'dest'=>$file_path);
  6558. $my_dep_file->setAttribute('href','document/'.$file_path);
  6559. $my_dep->setAttribute('xml:base','');
  6560. }
  6561. }
  6562. break;
  6563. case 'rel': //path relative to the current document. Save xml:base as current document's directory and save file in zip as subdir.file_path
  6564. if(substr($doc_info[0],0,2)=='..')
  6565. { //relative path going up
  6566. $current_dir = dirname($current_course_path.'/'.$item->get_file_path()).'/';
  6567. $file_path = realpath($current_dir.$doc_info[0]);
  6568. //error_log($file_path.' <-> '.$main_path,0);
  6569. if(strstr($file_path,$main_path) !== false)
  6570. {//the calculated real path is really inside the dokeos root path
  6571. //reduce file path to what's under the DocumentRoot
  6572. $file_path = substr($file_path,strlen($root_path));
  6573. //error_log('Reduced path: '.$file_path,0);
  6574. $zip_files_abs[] = $file_path;
  6575. $link_updates[$my_file_path][] = array('orig'=>$doc_info[0],'dest'=>$file_path);
  6576. $my_dep_file->setAttribute('href','document/'.$file_path);
  6577. $my_dep->setAttribute('xml:base','');
  6578. }
  6579. }else{
  6580. $zip_files[] = $my_sub_dir.'/'.$doc_info[0];
  6581. $my_dep_file->setAttribute('href',$doc_info[0]);
  6582. $my_dep->setAttribute('xml:base',$my_xml_sub_dir);
  6583. }
  6584. break;
  6585. default:
  6586. $my_dep_file->setAttribute('href',$doc_info[0]);
  6587. $my_dep->setAttribute('xml:base','');
  6588. break;
  6589. }
  6590. }
  6591. $my_dep->appendChild($my_dep_file);
  6592. $resources->appendChild($my_dep);
  6593. $dependency = $xmldoc->createElement('dependency');
  6594. $dependency->setAttribute('identifierref',$res_id);
  6595. $my_resource->appendChild($dependency);
  6596. $i++;
  6597. }
  6598. $resources->appendChild($my_resource);
  6599. $zip_files[] = $my_file_path;
  6600. }
  6601. else
  6602. {
  6603. //get the path of the file(s) from the course directory root
  6604. $my_file_path = 'non_exportable.html';
  6605. $my_xml_file_path = htmlentities($my_file_path);
  6606. $my_sub_dir = dirname($my_file_path);
  6607. $my_xml_sub_dir = htmlentities($my_sub_dir);
  6608. //give a <resource> child to the <resources> element
  6609. $my_resource = $xmldoc->createElement('resource');
  6610. $my_resource->setAttribute('identifier','RESOURCE_'.$item->get_id());
  6611. $my_resource->setAttribute('type','webcontent');
  6612. $my_resource->setAttribute('href','document/'.$my_xml_file_path);
  6613. //adlcp:scormtype can be either 'sco' or 'asset'
  6614. $my_resource->setAttribute('adlcp:scormtype','asset');
  6615. //xml:base is the base directory to find the files declared in this resource
  6616. $my_resource->setAttribute('xml:base','');
  6617. //give a <file> child to the <resource> element
  6618. $my_file = $xmldoc->createElement('file');
  6619. $my_file->setAttribute('href','document/'.$my_xml_file_path);
  6620. $my_resource->appendChild($my_file);
  6621. $resources->appendChild($my_resource);
  6622. }
  6623. }
  6624. }
  6625. $organizations->appendChild($organization);
  6626. $root->appendChild($organizations);
  6627. $root->appendChild($resources);
  6628. $xmldoc->appendChild($root);
  6629. //todo: add a readme file here, with a short description and a link to the Reload player
  6630. //then add the file to the zip, then destroy the file (this is done automatically)
  6631. // http://www.reload.ac.uk/scormplayer.html - once done, don't forget to close FS#138
  6632. //error_log(print_r($zip_files,true),0);
  6633. foreach($zip_files as $file_path)
  6634. {
  6635. if(empty($file_path)){continue;}
  6636. //error_log('getting document from '.api_get_path('SYS_COURSE_PATH').$_course['path'].'/'.$file_path.' removing '.api_get_path('SYS_COURSE_PATH').$_course['path'].'/',0);
  6637. $dest_file = $garbage_path.$temp_dir_short.'/'.$file_path;
  6638. $this->create_path($dest_file);
  6639. //error_log('copy '.api_get_path('SYS_COURSE_PATH').$_course['path'].'/'.$file_path.' to '.api_get_path('GARBAGE_PATH').$temp_dir_short.'/'.$file_path,0);
  6640. //echo $main_path.$file_path.'<br>';
  6641. @copy($sys_course_path.$_course['path'].'/'.$file_path,$dest_file);
  6642. //check if the file needs a link update
  6643. if(in_array($file_path,array_keys($link_updates))){
  6644. $string = file_get_contents($dest_file);
  6645. unlink($dest_file);
  6646. foreach($link_updates[$file_path] as $old_new)
  6647. {
  6648. //error_log('Replacing '.$old_new['orig'].' by '.$old_new['dest'].' in '.$file_path,0);
  6649. $string = str_replace($old_new['orig'],$old_new['dest'],$string);
  6650. }
  6651. file_put_contents($dest_file,$string);
  6652. }
  6653. }
  6654. foreach($zip_files_abs as $file_path)
  6655. {
  6656. if(empty($file_path)){continue;}
  6657. //error_log('getting document from '.api_get_path('SYS_COURSE_PATH').$_course['path'].'/'.$file_path.' removing '.api_get_path('SYS_COURSE_PATH').$_course['path'].'/',0);
  6658. $dest_file = $garbage_path.$temp_dir_short.'/document/'.$file_path;
  6659. $this->create_path($dest_file);
  6660. //error_log('Created path '.api_get_path('GARBAGE_PATH').$temp_dir_short.'/document/'.$file_path,0);
  6661. //error_log('copy '.api_get_path('SYS_COURSE_PATH').$_course['path'].'/'.$file_path.' to '.api_get_path('GARBAGE_PATH').$temp_dir_short.'/'.$file_path,0);
  6662. //echo $main_path.$file_path.' - '.$dest_file.'<br>';
  6663. copy($main_path.$file_path,$dest_file);
  6664. //check if the file needs a link update
  6665. if(in_array($file_path,array_keys($link_updates))){
  6666. $string = file_get_contents($dest_file);
  6667. unlink($dest_file);
  6668. foreach($link_updates[$file_path] as $old_new)
  6669. {
  6670. //error_log('Replacing '.$old_new['orig'].' by '.$old_new['dest'].' in '.$file_path,0);
  6671. $string = str_replace($old_new['orig'],$old_new['dest'],$string);
  6672. }
  6673. file_put_contents($dest_file,$string);
  6674. }
  6675. }
  6676. if(is_array($links_to_create))
  6677. {
  6678. foreach($links_to_create as $file=>$link)
  6679. {
  6680. $file_content = '<html><body><div style="text-align:center"><a href="'.$link['url'].'">'.$link['title'].'</a></div></body></html>';
  6681. file_put_contents($garbage_path.$temp_dir_short.'/'.$file, $file_content);
  6682. }
  6683. }
  6684. // add non exportable message explanation
  6685. $lang_not_exportable = get_lang('ThisItemIsNotExportable');
  6686. $file_content =
  6687. <<<EOD
  6688. <html>
  6689. <head>
  6690. <style>
  6691. .error-message {
  6692. font-family: arial, verdana, helvetica, sans-serif;
  6693. border-width: 1px;
  6694. border-style: solid;
  6695. left: 50%;
  6696. margin: 10px auto;
  6697. min-height: 30px;
  6698. padding: 5px;
  6699. right: 50%;
  6700. width: 500px;
  6701. background-color: #FFD1D1;
  6702. border-color: #FF0000;
  6703. color: #000;
  6704. }
  6705. </style>
  6706. <body>
  6707. <div class="error-message">
  6708. $lang_not_exportable
  6709. </div>
  6710. </body>
  6711. </html>
  6712. EOD;
  6713. if(!is_dir($garbage_path.$temp_dir_short.'/document'))
  6714. {
  6715. @mkdir($garbage_path.$temp_dir_short.'/document');
  6716. }
  6717. file_put_contents($garbage_path.$temp_dir_short.'/document/non_exportable.html', $file_content);
  6718. //Add the extra files that go along with a SCORM package
  6719. $main_code_path = api_get_path(SYS_CODE_PATH).'newscorm/packaging/';
  6720. $extra_files = scandir($main_code_path);
  6721. foreach($extra_files as $extra_file)
  6722. {
  6723. if(strpos($extra_file,'.')===0) continue;
  6724. else
  6725. {
  6726. $dest_file = $garbage_path.$temp_dir_short.'/'.$extra_file;
  6727. $this->create_path($dest_file);
  6728. copy($main_code_path.$extra_file,$dest_file);
  6729. }
  6730. }
  6731. //Finalize the imsmanifest structure, add to the zip, then return the zip
  6732. $xmldoc->save($garbage_path.'/'.$temp_dir_short.'/imsmanifest.xml');
  6733. $zip_folder->add($garbage_path.'/'.$temp_dir_short, PCLZIP_OPT_REMOVE_PATH, $garbage_path.'/'.$temp_dir_short.'/');
  6734. //clean possible temporary files
  6735. foreach($files_cleanup as $file)
  6736. {
  6737. $res = unlink($file);
  6738. if($res === false){error_log('Could not delete temp file '.$file.' '.__FILE__.' '.__LINE__,0);}
  6739. }
  6740. //Send file to client
  6741. //$name = 'scorm_export_'.$this->lp_id.'.zip';
  6742. require_once(api_get_path(LIBRARY_PATH).'fileUpload.lib.php');
  6743. $name = preg_replace('([^a-zA-Z0-9_\.])','-',html_entity_decode($this->get_name(),ENT_QUOTES)).'.zip';
  6744. DocumentManager::file_send_for_download($temp_zip_file,true,$name);
  6745. }
  6746. /**
  6747. * Temp function to be moved in main_api or the best place around for this. Creates a file path
  6748. * if it doesn't exist
  6749. */
  6750. function create_path($path){
  6751. $path_bits = split('/',dirname($path));
  6752. $path_built = '/';
  6753. foreach($path_bits as $bit){
  6754. if(!empty($bit)){
  6755. $new_path = $path_built.$bit;
  6756. if(is_dir($new_path)){
  6757. $path_built = $new_path.'/';
  6758. }
  6759. else
  6760. {
  6761. mkdir($new_path);
  6762. $path_built = $new_path.'/';
  6763. }
  6764. }
  6765. }
  6766. }
  6767. }
  6768. ?>