learnpath.class.php 245 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539
  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. // Tells if all the items of the learnpath can be tried again. Defaults to "no" (=1)
  40. var $prevent_reinit = 1;
  41. // Describes the mode of progress bar display
  42. var $progress_bar_mode = '%';
  43. // Percentage progress as saved in the db
  44. var $progress_db = '0';
  45. var $proximity; //wether the content is distant or local or unknown
  46. var $refs_list = array(); //list of items by ref => db_id. Used only for prerequisites match.
  47. //!!!This array (refs_list) is built differently depending on the nature of the LP.
  48. //If SCORM, uses ref, if Dokeos, uses id to keep a unique value
  49. var $type; //type of learnpath. Could be 'dokeos', 'scorm', 'scorm2004', 'aicc', ...
  50. //TODO check if this type variable is useful here (instead of just in the controller script)
  51. var $user_id; //ID of the user that is viewing/using the course
  52. var $update_queue = array();
  53. var $scorm_debug = 0;
  54. var $arrMenu = array(); //array for the menu items
  55. var $debug = 0; //logging level
  56. /**
  57. * Class constructor. Needs a database handler, a course code and a learnpath id from the database.
  58. * Also builds the list of items into $this->items.
  59. * @param string Course code
  60. * @param integer Learnpath ID
  61. * @param integer User ID
  62. * @return boolean True on success, false on error
  63. */
  64. function learnpath($course, $lp_id, $user_id) {
  65. //check params
  66. //check course code
  67. if($this->debug>0){error_log('New LP - In learnpath::learnpath('.$course.','.$lp_id.','.$user_id.')',0);}
  68. if(empty($course)){
  69. $this->error = 'Course code is empty';
  70. return false;
  71. }
  72. else
  73. {
  74. $main_table = Database::get_main_table(TABLE_MAIN_COURSE);
  75. //$course = Database::escape_string($course);
  76. $course = $this->escape_string($course);
  77. $sql = "SELECT * FROM $main_table WHERE code = '$course'";
  78. if($this->debug>2){error_log('New LP - learnpath::learnpath() '.__LINE__.' - Querying course: '.$sql,0);}
  79. //$res = Database::query($sql);
  80. $res = api_sql_query($sql);
  81. if(Database::num_rows($res)>0)
  82. {
  83. $this->cc = $course;
  84. }
  85. else
  86. {
  87. $this->error = 'Course code does not exist in database ('.$sql.')';
  88. return false;
  89. }
  90. }
  91. //check learnpath ID
  92. if(empty($lp_id))
  93. {
  94. $this->error = 'Learnpath ID is empty';
  95. return false;
  96. }
  97. else
  98. {
  99. //TODO make it flexible to use any course_code (still using env course code here)
  100. //$lp_table = Database::get_course_table(LEARNPATH_TABLE);
  101. $lp_db = Database::get_current_course_database();
  102. $lp_pref = Database::get_course_table_prefix();
  103. $lp_table = $lp_db.'.'.$lp_pref.'lp';
  104. //$id = Database::escape_integer($id);
  105. $lp_id = $this->escape_string($lp_id);
  106. $sql = "SELECT * FROM $lp_table WHERE id = '$lp_id'";
  107. if($this->debug>2){error_log('New LP - learnpath::learnpath() '.__LINE__.' - Querying lp: '.$sql,0);}
  108. //$res = Database::query($sql);
  109. $res = api_sql_query($sql);
  110. if(Database::num_rows($res)>0)
  111. {
  112. $this->lp_id = $lp_id;
  113. $row = Database::fetch_array($res);
  114. $this->type = $row['lp_type'];
  115. $this->name = stripslashes($row['name']);
  116. $this->encoding = $row['default_encoding'];
  117. $this->proximity = $row['content_local'];
  118. $this->maker = $row['content_maker'];
  119. $this->prevent_reinit = $row['prevent_reinit'];
  120. $this->license = $row['content_license'];
  121. $this->scorm_debug = $row['debug'];
  122. $this->js_lib = $row['js_lib'];
  123. $this->path = $row['path'];
  124. if($this->type == 2){
  125. if($row['force_commit'] == 1){
  126. $this->force_commit = true;
  127. }
  128. }
  129. $this->mode = $row['default_view_mod'];
  130. }
  131. else
  132. {
  133. $this->error = 'Learnpath ID does not exist in database ('.$sql.')';
  134. return false;
  135. }
  136. }
  137. //check user ID
  138. if(empty($user_id)){
  139. $this->error = 'User ID is empty';
  140. return false;
  141. }
  142. else
  143. {
  144. //$main_table = Database::get_main_user_table();
  145. $main_table = Database::get_main_table(TABLE_MAIN_USER);
  146. //$user_id = Database::escape_integer($user_id);
  147. $user_id = $this->escape_string($user_id);
  148. $sql = "SELECT * FROM $main_table WHERE user_id = '$user_id'";
  149. if($this->debug>2){error_log('New LP - learnpath::learnpath() '.__LINE__.' - Querying user: '.$sql,0);}
  150. //$res = Database::query($sql);
  151. $res = api_sql_query($sql);
  152. if(Database::num_rows($res)>0)
  153. {
  154. $this->user_id = $user_id;
  155. }
  156. else
  157. {
  158. $this->error = 'User ID does not exist in database ('.$sql.')';
  159. return false;
  160. }
  161. }
  162. //end of variables checking
  163. //now get the latest attempt from this user on this LP, if available, otherwise create a new one
  164. //$lp_table = Database::get_course_table(LEARNPATH_VIEW_TABLE);
  165. $lp_db = Database::get_current_course_database();
  166. $lp_pref = Database::get_course_table_prefix();
  167. $lp_table = $lp_db.'.'.$lp_pref.'lp_view';
  168. //selecting by view_count descending allows to get the highest view_count first
  169. $sql = "SELECT * FROM $lp_table WHERE lp_id = '$lp_id' AND user_id = '$user_id' ORDER BY view_count DESC";
  170. if($this->debug>2){error_log('New LP - learnpath::learnpath() '.__LINE__.' - querying lp_view: '.$sql,0);}
  171. //$res = Database::query($sql);
  172. $res = api_sql_query($sql);
  173. $view_id = 0; //used later to query lp_item_view
  174. if(Database::num_rows($res)>0)
  175. {
  176. if($this->debug>2){error_log('New LP - learnpath::learnpath() '.__LINE__.' - Found previous view',0);}
  177. $row = Database::fetch_array($res);
  178. $this->attempt = $row['view_count'];
  179. $this->lp_view_id = $row['id'];
  180. $this->last_item_seen = $row['last_item'];
  181. $this->progress_db = $row['progress'];
  182. }
  183. else
  184. {
  185. if($this->debug>2){error_log('New LP - learnpath::learnpath() '.__LINE__.' - NOT Found previous view',0);}
  186. $this->attempt = 1;
  187. $sql_ins = "INSERT INTO $lp_table (lp_id,user_id,view_count) VALUES ($lp_id,$user_id,1)";
  188. $res_ins = api_sql_query($sql_ins);
  189. $this->lp_view_id = Database::get_last_insert_id();
  190. if($this->debug>2){error_log('New LP - learnpath::learnpath() '.__LINE__.' - inserting new lp_view: '.$sql_ins,0);}
  191. }
  192. //initialise items
  193. $lp_item_table = $lp_db.'.'.$lp_pref.'lp_item';
  194. $sql = "SELECT * FROM $lp_item_table WHERE lp_id = '".$this->lp_id."' ORDER BY parent_item_id, display_order";
  195. $res = api_sql_query($sql);
  196. while($row = Database::fetch_array($res))
  197. {
  198. $oItem = '';
  199. //$this->ordered_items[] = $row['id'];
  200. switch($this->type){
  201. case 3: //aicc
  202. $oItem = new aiccItem('db',$row['id']);
  203. if(is_object($oItem)){
  204. $oItem->set_lp_view($this->lp_view_id);
  205. $oItem->set_prevent_reinit($this->prevent_reinit);
  206. $id = $oItem->get_id();
  207. // Don't use reference here as the next loop will make the pointed object change
  208. $this->items[$id] = $oItem;
  209. $this->refs_list[$oItem->ref]=$id;
  210. if($this->debug>2){error_log('New LP - learnpath::learnpath() - aicc object with id '.$id.' set in items[]',0);}
  211. }
  212. break;
  213. case 2:
  214. require_once('scorm.class.php');
  215. require_once('scormItem.class.php');
  216. $oItem = new scormItem('db',$row['id']);
  217. if(is_object($oItem)){
  218. $oItem->set_lp_view($this->lp_view_id);
  219. $oItem->set_prevent_reinit($this->prevent_reinit);
  220. // Don't use reference here as the next loop will make the pointed object change
  221. $this->items[$oItem->get_id()] = $oItem;
  222. $this->refs_list[$oItem->ref]=$oItem->get_id();
  223. if($this->debug>2){error_log('New LP - object with id '.$oItem->get_id().' set in items[]',0);}
  224. }
  225. break;
  226. case 1:
  227. default:
  228. require_once('learnpathItem.class.php');
  229. $oItem = new learnpathItem($row['id'],$user_id);
  230. if(is_object($oItem)){
  231. //$oItem->set_lp_view($this->lp_view_id); moved down to when we are sure the item_view exists
  232. $oItem->set_prevent_reinit($this->prevent_reinit);
  233. // Don't use reference here as the next loop will make the pointed object change
  234. $this->items[$oItem->get_id()] = $oItem;
  235. $this->refs_list[$oItem->get_id()]=$oItem->get_id();
  236. if($this->debug>2){error_log('New LP - learnpath::learnpath() '.__LINE__.' - object with id '.$oItem->get_id().' set in items[]',0);}
  237. }
  238. break;
  239. }
  240. //items is a list of pointers to all items, classified by DB ID, not SCO id
  241. if($row['parent_item_id'] == 0 OR empty($this->items[$row['parent_item_id']])){
  242. $this->items[$row['id']]->set_level(0);
  243. }else{
  244. $level = $this->items[$row['parent_item_id']]->get_level()+1;
  245. $this->items[$row['id']]->set_level($level);
  246. if(is_object($this->items[$row['parent_item_id']])){
  247. //items is a list of pointers from item DB ids to item objects
  248. $this->items[$row['parent_item_id']]->add_child($row['id']);
  249. }else{
  250. 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);}
  251. }
  252. }
  253. //get last viewing vars
  254. //$learnpath_items_view_table = Database::get_course_table(LEARNPATH_ITEM_VIEW_TABLE);
  255. $lp_item_view_table = $lp_db.'.'.$lp_pref.'lp_item_view';
  256. //this query should only return one or zero result
  257. $sql = "SELECT * " .
  258. "FROM $lp_item_view_table " .
  259. "WHERE lp_view_id = ".$this->lp_view_id." " .
  260. "AND lp_item_id = ".$row['id']." ORDER BY view_count DESC ";
  261. if($this->debug>2){error_log('New LP - learnpath::learnpath() - Selecting item_views: '.$sql,0);}
  262. //get the item status
  263. $res2 = api_sql_query($sql);
  264. if(Database::num_rows($res2)>0)
  265. {
  266. //if this learnpath has already been used by this user, get his last attempt count and
  267. //the last item seen back into this object
  268. //$max = 0;
  269. $row2 = Database::fetch_array($res2);
  270. if($this->debug>2){error_log('New LP - learnpath::learnpath() - Got item_view: '.print_r($row2,true),0);}
  271. $this->items[$row['id']]->set_status($row2['status']);
  272. if(empty($row2['status'])){
  273. $this->items[$row['id']]->set_status($this->default_status);
  274. }
  275. //$this->attempt = $row['view_count'];
  276. //$this->last_item = $row['id'];
  277. }
  278. else //no item found in lp_item_view for this view
  279. {
  280. //first attempt from this user. Set attempt to 1 and last_item to 0 (first item available)
  281. //TODO if the learnpath has not got attempts activated, always use attempt '1'
  282. //$this->attempt = 1;
  283. //$this->last_item = 0;
  284. $this->items[$row['id']]->set_status($this->default_status);
  285. //Add that row to the lp_item_view table so that we have something to show in the stats page
  286. $sql_ins = "INSERT INTO $lp_item_view_table " .
  287. "(lp_item_id, lp_view_id, view_count, status) VALUES " .
  288. "(".$row['id'].",".$this->lp_view_id.",1,'not attempted')";
  289. if($this->debug>2){error_log('New LP - learnpath::learnpath() '.__LINE__.' - Inserting blank item_view : '.$sql_ins,0);}
  290. $res_ins = api_sql_query($sql_ins);
  291. }
  292. //setting the view in the item object
  293. $this->items[$row['id']]->set_lp_view($this->lp_view_id);
  294. }
  295. $this->ordered_items = $this->get_flat_ordered_items_list($this->get_id(),0);
  296. $this->max_ordered_items = 0;
  297. foreach($this->ordered_items as $index=>$dummy){
  298. if($index > $this->max_ordered_items AND !empty($dummy)){
  299. $this->max_ordered_items = $index;
  300. }
  301. }
  302. //TODO define the current item better
  303. $this->first();
  304. if($this->debug>2){error_log('New LP - learnpath::learnpath() '.__LINE__.' - End of learnpath constructor for learnpath '.$this->get_id(),0);}
  305. }
  306. /**
  307. * 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
  308. * I found it better to rewrite it. Old function is still available. Added also the possibility to add a description.
  309. *
  310. * @param int $parent
  311. * @param int $previous
  312. * @param string $type
  313. * @param int $id
  314. * @param string $title
  315. * @param string $description
  316. * @return int
  317. */
  318. function add_item($parent, $previous, $type = 'dokeos_chapter', $id, $title, $description, $prerequisites=0)
  319. {
  320. if($this->debug>0){error_log('New LP - In learnpath::add_item('.$parent.','.$previous.','.$type.','.$id.','.$title.')',0);}
  321. $tbl_lp_item = Database::get_course_table('lp_item');
  322. $parent = intval($parent);
  323. $previous = intval($previous);
  324. $type = $this->escape_string($type);
  325. $id = intval($id);
  326. $title = $this->escape_string(htmlentities($title));
  327. $description = $this->escape_string(htmlentities($description));
  328. $sql_count = "
  329. SELECT COUNT(id) AS num
  330. FROM " . $tbl_lp_item . "
  331. WHERE
  332. lp_id = " . $this->get_id() . " AND
  333. parent_item_id = " . $parent;
  334. $res_count = api_sql_query($sql_count, __FILE__, __LINE__);
  335. $row = Database::fetch_array($res_count);
  336. $num = $row['num'];
  337. if($num > 0)
  338. {
  339. if($previous == 0)
  340. {
  341. $sql = "
  342. SELECT
  343. id,
  344. next_item_id,
  345. display_order
  346. FROM " . $tbl_lp_item . "
  347. WHERE
  348. lp_id = " . $this->get_id() . " AND
  349. parent_item_id = " . $parent . " AND
  350. previous_item_id = 0";
  351. $result = api_sql_query($sql, __FILE__, __LINE__);
  352. $row = Database::fetch_array($result);
  353. $tmp_previous = 0;
  354. $next = $row['id'];
  355. $display_order = 0;
  356. }
  357. else
  358. {
  359. $previous = (int) $previous;
  360. $sql = "
  361. SELECT
  362. id,
  363. previous_item_id,
  364. next_item_id,
  365. display_order
  366. FROM " . $tbl_lp_item . "
  367. WHERE
  368. lp_id = " . $this->get_id() . " AND
  369. id = " . $previous;
  370. $result = api_sql_query($sql, __FILE__, __LINE__);
  371. $row = Database::fetch_array($result);
  372. $tmp_previous = $row['id'];
  373. $next = $row['next_item_id'];
  374. $display_order = $row['display_order'];
  375. }
  376. }
  377. else
  378. {
  379. $tmp_previous = 0;
  380. $next = 0;
  381. $display_order = 0;
  382. }
  383. $new_item_id = -1;
  384. $id = $this->escape_string($id);
  385. if($prerequisites!=0){
  386. $sql_ins = "
  387. INSERT INTO " . $tbl_lp_item . " (
  388. lp_id,
  389. item_type,
  390. ref,
  391. title,
  392. description,
  393. path,
  394. parent_item_id,
  395. previous_item_id,
  396. next_item_id,
  397. display_order,
  398. prerequisite
  399. ) VALUES (
  400. " . $this->get_id() . ",
  401. '" . $type . "',
  402. '',
  403. '" . $title . "',
  404. '" . $description . "',
  405. '" . $id . "',
  406. " . $parent . ",
  407. " . $previous . ",
  408. " . $next . ",
  409. " . ($display_order + 1) . ",
  410. " . $prerequisites . "
  411. )";
  412. }
  413. else{
  414. //insert new item
  415. $sql_ins = "
  416. INSERT INTO " . $tbl_lp_item . " (
  417. lp_id,
  418. item_type,
  419. ref,
  420. title,
  421. description,
  422. path,
  423. parent_item_id,
  424. previous_item_id,
  425. next_item_id,
  426. display_order
  427. ) VALUES (
  428. " . $this->get_id() . ",
  429. '" . $type . "',
  430. '',
  431. '" . $title . "',
  432. '" . $description . "',
  433. '" . $id . "',
  434. " . $parent . ",
  435. " . $previous . ",
  436. " . $next . ",
  437. " . ($display_order + 1) . "
  438. )";
  439. }
  440. if($this->debug>2){error_log('New LP - Inserting dokeos_chapter: '.$sql_ins,0);}
  441. $res_ins = api_sql_query($sql_ins, __FILE__, __LINE__);
  442. if($res_ins > 0)
  443. {
  444. $new_item_id = Database::get_last_insert_id($res_ins);
  445. //update the item that should come after the new item
  446. $sql_update_next = "
  447. UPDATE " . $tbl_lp_item . "
  448. SET previous_item_id = " . $new_item_id . "
  449. WHERE id = " . $next;
  450. $res_update_next = api_sql_query($sql_update_next, __FILE__, __LINE__);
  451. //update the item that should be before the new item
  452. $sql_update_previous = "
  453. UPDATE " . $tbl_lp_item . "
  454. SET next_item_id = " . $new_item_id . "
  455. WHERE id = " . $tmp_previous;
  456. $res_update_previous = api_sql_query($sql_update_previous, __FILE__, __LINE__);
  457. //update all the items after the new item
  458. $sql_update_order = "
  459. UPDATE " . $tbl_lp_item . "
  460. SET display_order = display_order + 1
  461. WHERE
  462. lp_id = " . $this->get_id() . " AND
  463. id <> " . $new_item_id . " AND
  464. parent_item_id = " . $parent . " AND
  465. display_order > " . $display_order;
  466. $res_update_previous = api_sql_query($sql_update_order, __FILE__, __LINE__);
  467. //update the item that should come after the new item
  468. $sql_update_ref = "
  469. UPDATE " . $tbl_lp_item . "
  470. SET ref = " . $new_item_id . "
  471. WHERE id = " . $new_item_id;
  472. api_sql_query($sql_update_ref, __FILE__, __LINE__);
  473. }
  474. return $new_item_id;
  475. }
  476. /**
  477. * Adds an item to the current learnpath
  478. * @param integer Parent ID
  479. * @param integer Previous elem ID (0 if first)
  480. * @param string Resource type to add ('file','dokeos_item')
  481. * @param string Resource ID or path if 'file' or name if 'dokeos_chapter'
  482. * @return integer New element ID
  483. */
  484. function old_add_item($parent, $previous, $type = 'dokeos_chapter', $id, $title)
  485. {
  486. //TODO
  487. if($this->debug>0){error_log('New LP - In learnpath::add_item('.$parent.','.$previous.','.$type.','.$id.','.$title.')',0);}
  488. $tbl_lp_item = Database::get_course_table('lp_item');
  489. $parent = (int) $parent;
  490. $display_order = 1;
  491. if($previous == -1){
  492. //insert in latest position available
  493. $sql_check = "SELECT MAX(previous_item_id) as prev, id FROM $tbl_lp_item WHERE lp_id = " . $this->get_id() . " AND parent_item_id = " . $parent;
  494. if($this->debug>1){error_log('New LP - checking for latest item at this level: '.$sql_check,0);}
  495. $res = mysql_query($sql_check) or die(mysql_error());
  496. $res_check = api_sql_query($sql_check, __FILE__, __LINE__);
  497. $num = Database::num_rows($res_check);
  498. if($num>0){
  499. $row = Database::fetch_array($res_check);
  500. $previous = $row['id'];
  501. }else{
  502. $previous = 0;
  503. }
  504. }else{
  505. $previous = (int) $previous;
  506. }
  507. $new_item_id = -1;
  508. //check type
  509. switch ($type){
  510. case 'dokeos_step':
  511. $id = $this->escape_string($id);
  512. //check the next item
  513. $sql_check = "SELECT * FROM $tbl_lp_item " .
  514. "WHERE lp_id = ".$this->get_id()." " .
  515. "AND previous_item_id = $previous " .
  516. "AND parent_item_id = $parent";
  517. if($this->debug>2){error_log('New LP - Getting info from the next element: '.$sql_check,0);}
  518. $res_check = api_sql_query($sql_check);
  519. if(Database::num_rows($res_check)){
  520. $row = Database::fetch_array($res_check);
  521. $next = $row['id'];
  522. //TODO check display_order
  523. $display_order = $row['display_order']+1;
  524. }else{
  525. $next = 0;
  526. $display_order = 1;
  527. }
  528. //insert new item
  529. $sql_ins = "INSERT INTO $tbl_lp_item " .
  530. "(lp_id,item_type,ref,title," .
  531. "path,parent_item_id," .
  532. "previous_item_id,next_item_id,display_order)" .
  533. "VALUES" .
  534. "(".$this->get_id().",'$type','','$title','$id'," .
  535. "$parent," .
  536. "$previous,$next,$display_order)";
  537. if($this->debug>2){error_log('New LP - Inserting dokeos_chapter: '.$sql_ins,0);}
  538. $res_ins = api_sql_query($sql_ins);
  539. if($res_ins>0){
  540. $new_item_id = Database::get_last_insert_id($res_ins);
  541. //now update previous item
  542. $sql_upd = "UPDATE $tbl_lp_item " .
  543. "SET next_item_id = $new_item_id " .
  544. "WHERE lp_id = ".$this->get_id()." " .
  545. "AND id = $previous AND parent_item_id = $parent";
  546. if($this->debug>2){error_log('New LP - Updating previous item: '.$sql_upd,0);}
  547. $res_upd = api_sql_query($sql_upd);
  548. //now update next item
  549. $sql_upd = "UPDATE $tbl_lp_item " .
  550. "SET previous_item_id = $new_item_id " .
  551. "WHERE lp_id = ".$this->get_id()." " .
  552. "AND id = $next AND parent_item_id = $parent";
  553. if($this->debug>2){error_log('New LP - Updating next item: '.$sql_upd,0);}
  554. $res_upd = api_sql_query($sql_upd);
  555. }
  556. break;
  557. default:
  558. break;
  559. }
  560. return $new_item_id;
  561. }
  562. /**
  563. * Static admin function allowing addition of a learnpath to a course.
  564. * @param string Course code
  565. * @param string Learnpath name
  566. * @param string Learnpath description string, if provided
  567. * @param string Type of learnpath (default = 'guess', others = 'dokeos', 'aicc',...)
  568. * @param string Type of files origin (default = 'zip', others = 'dir','web_dir',...)
  569. * @param string Zip file containing the learnpath or directory containing the learnpath
  570. * @return integer The new learnpath ID on success, 0 on failure
  571. */
  572. function add_lp($course,$name,$description='',$learnpath='guess',$origin='zip',$zipname='')
  573. {
  574. //if($this->debug>0){error_log('New LP - In learnpath::add_lp()',0);}
  575. //TODO
  576. $tbl_lp = Database::get_course_table('lp');
  577. //check course code exists
  578. //check lp_name doesn't exist, otherwise append something
  579. $i = 0;
  580. $name = learnpath::escape_string(htmlentities($name)); //Kevin Van Den Haute: added htmlentities()
  581. $check_name = "SELECT * FROM $tbl_lp WHERE name = '$name'";
  582. //if($this->debug>2){error_log('New LP - Checking the name for new LP: '.$check_name,0);}
  583. $res_name = api_sql_query($check_name);
  584. while(Database::num_rows($res_name)){
  585. //there is already one such name, update the current one a bit
  586. $i++;
  587. $name = $name.' - '.$i;
  588. $check_name = "SELECT * FROM $tbl_lp WHERE name = '$name'";
  589. //if($this->debug>2){error_log('New LP - Checking the name for new LP: '.$check_name,0);}
  590. $res_name = api_sql_query($check_name);
  591. }
  592. //new name does not exist yet; keep it
  593. //escape description
  594. $description = learnpath::escape_string(htmlentities($description)); //Kevin: added htmlentities()
  595. $type = 1;
  596. switch($learnpath){
  597. case 'guess':
  598. break;
  599. case 'dokeos':
  600. $type = 1;
  601. break;
  602. case 'aicc':
  603. break;
  604. }
  605. switch($origin){
  606. case 'zip':
  607. //check zipname string. If empty, we are currently creating a new Dokeos learnpath
  608. break;
  609. case 'manual':
  610. $get_max = "SELECT MAX(display_order) FROM $tbl_lp";
  611. $res_max = api_sql_query($get_max);
  612. if(Database::num_rows($res_max)<1){
  613. $dsp = 1;
  614. }else{
  615. $row = Database::fetch_array($res_max);
  616. $dsp = $row[0]+1;
  617. }
  618. $sql_insert = "INSERT INTO $tbl_lp " .
  619. "(lp_type,name,description,path,default_view_mod," .
  620. "default_encoding,display_order,content_maker," .
  621. "content_local,js_lib) " .
  622. "VALUES ($type,'$name','$description','','embedded'," .
  623. "'ISO-8859-1','$dsp','Dokeos'," .
  624. "'local','')";
  625. //if($this->debug>2){error_log('New LP - Inserting new lp '.$sql_insert,0);}
  626. $res_insert = api_sql_query($sql_insert);
  627. $id = Database::get_last_insert_id();
  628. if($id>0){
  629. return $id;
  630. }
  631. break;
  632. }
  633. }
  634. /**
  635. * Appends a message to the message attribute
  636. * @param string Message to append.
  637. */
  638. function append_message($string)
  639. {
  640. if($this->debug>0){error_log('New LP - In learnpath::append_message()',0);}
  641. $this->message .= $string;
  642. }
  643. /**
  644. * Autocompletes the parents of an item in case it's been completed or passed
  645. * @param integer Optional ID of the item from which to look for parents
  646. */
  647. function autocomplete_parents($item)
  648. {
  649. if($this->debug>0){error_log('New LP - In learnpath::autocomplete_parents()',0);}
  650. if(empty($item)){
  651. $item = $this->current;
  652. }
  653. $parent_id = $this->items[$item]->get_parent();
  654. if($this->debug>2){error_log('New LP - autocompleting parent of item '.$item.' (item '.$parent_id.')',0);}
  655. if(is_object($this->items[$item]) and !empty($parent_id))
  656. {//if $item points to an object and there is a parent
  657. if($this->debug>2){error_log('New LP - '.$item.' is an item, proceed',0);}
  658. $current_item =& $this->items[$item];
  659. $parent =& $this->items[$parent_id]; //get the parent
  660. //new experiment including failed and browsed in completed status
  661. $current_status = $current_item->get_status();
  662. if($current_item->is_done() || $current_status=='browsed' || $current_status=='failed'){
  663. //if the current item is completed or passes or succeeded
  664. $completed = true;
  665. if($this->debug>2){error_log('New LP - Status of current item is alright',0);}
  666. foreach($parent->get_children() as $child){
  667. //check all his brothers (his parent's children) for completion status
  668. if($child!= $item){
  669. if($this->debug>2){error_log('New LP - Looking at brother with ID '.$child.', status is '.$this->items[$child]->get_status(),0);}
  670. //if($this->items[$child]->status_is(array('completed','passed','succeeded')))
  671. //Trying completing parents of failed and browsed items as well
  672. if($this->items[$child]->status_is(array('completed','passed','succeeded','browsed','failed')))
  673. {
  674. //keep completion status to true
  675. }else{
  676. if($this->debug>2){error_log('New LP - Found one incomplete child of '.$parent_id.': '.$child.' is '.$this->items[$child]->get_status(),0);}
  677. $completed = false;
  678. }
  679. }
  680. }
  681. if($completed == true){ //if all the children were completed
  682. $parent->set_status('completed');
  683. $parent->save(false);
  684. $this->update_queue[$parent->get_id()] = $parent->get_status();
  685. if($this->debug>2){error_log('New LP - Added parent to update queue '.print_r($this->update_queue,true),0);}
  686. $this->autocomplete_parents($parent->get_id()); //recursive call
  687. }
  688. }else{
  689. //error_log('New LP - status of current item is not enough to get bothered',0);
  690. }
  691. }
  692. }
  693. /**
  694. * Autosaves the current results into the database for the whole learnpath
  695. */
  696. function autosave()
  697. {
  698. if($this->debug>0){error_log('New LP - In learnpath::autosave()',0);}
  699. //TODO add aditionnal save operations for the learnpath itself
  700. }
  701. /**
  702. * Clears the message attribute
  703. */
  704. function clear_message()
  705. {
  706. if($this->debug>0){error_log('New LP - In learnpath::clear_message()',0);}
  707. $this->message = '';
  708. }
  709. /**
  710. * Closes the current resource
  711. *
  712. * Stops the timer
  713. * Saves into the database if required
  714. * Clears the current resource data from this object
  715. * @return boolean True on success, false on failure
  716. */
  717. function close()
  718. {
  719. if($this->debug>0){error_log('New LP - In learnpath::close()',0);}
  720. if(empty($this->lp_id))
  721. {
  722. $this->error = 'Trying to close this learnpath but no ID is set';
  723. return false;
  724. }
  725. $this->current_time_stop = time();
  726. if($this->save)
  727. {
  728. $learnpath_view_table = Database::get_course_table(LEARNPATH_VIEW_TABLE);
  729. /*
  730. $sql = "UPDATE $learnpath_view_table " .
  731. "SET " .
  732. "stop_time = ".$this->current_time_stop.", " .
  733. "score = ".$this->current_score.", ".
  734. "WHERE learnpath_id = '".$this->lp_id."'";
  735. //$res = Database::query($sql);
  736. $res = api_sql_query($res);
  737. if(mysql_affected_rows($res)<1)
  738. {
  739. $this->error = 'Could not update learnpath_view table while closing learnpath';
  740. return false;
  741. }
  742. */
  743. }
  744. $this->ordered_items = array();
  745. $this->index=0;
  746. unset($this->lp_id);
  747. //unset other stuff
  748. return true;
  749. }
  750. /**
  751. * Static admin function allowing removal of a learnpath
  752. * @param string Course code
  753. * @param integer Learnpath ID
  754. * @param string Whether to delete data or keep it (default: 'keep', others: 'remove')
  755. * @return boolean True on success, false on failure (might change that to return number of elements deleted)
  756. */
  757. function delete($course=null,$id=null,$delete='keep')
  758. {
  759. //TODO implement a way of getting this to work when the current object is not set
  760. //In clear: implement this in the item class as well (abstract class) and use the given ID in queries
  761. //if(empty($course)){$course = api_get_course_id();}
  762. //if(empty($id)){$id = $this->get_id();}
  763. //if($this->debug>0){error_log('New LP - In learnpath::delete()',0);}
  764. foreach($this->items as $id => $dummy)
  765. {
  766. $this->items[$id]->delete();
  767. }
  768. $lp = Database::get_course_table('lp');
  769. $lp_view = Database::get_course_table('lp_view');
  770. $sql_del_view = "DELETE FROM $lp_view WHERE lp_id = ".$this->lp_id;
  771. //if($this->debug>2){error_log('New LP - Deleting views bound to lp '.$this->lp_id.': '.$sql_del_view,0);}
  772. $res_del_view = api_sql_query($sql_del_view);
  773. //if($this->debug>2){error_log('New LP - Deleting lp '.$this->lp_id.' of type '.$this->type,0);}
  774. if($this->type == 2 OR $this->type==3){
  775. //this is a scorm learning path, delete the files as well
  776. $sql = "SELECT path FROM $lp WHERE id = ".$this->lp_id;
  777. $res = api_sql_query($sql);
  778. if(Database::num_rows($res)>0){
  779. $row = Database::fetch_array($res);
  780. $path = $row['path'];
  781. $sql = "SELECT id FROM $lp WHERE path = '$path' AND id != ".$this->lp_id;
  782. $res = api_sql_query($sql);
  783. if(Database::num_rows($res)>0)
  784. { //another learning path uses this directory, so don't delete it
  785. if($this->debug>2){error_log('New LP - In learnpath::delete(), found other LP using path '.$path.', keeping directory',0);}
  786. }else{
  787. //no other LP uses that directory, delete it
  788. $course_rel_dir = api_get_course_path().'/scorm/'; //scorm dir web path starting from /courses
  789. $course_scorm_dir = api_get_path(SYS_COURSE_PATH).$course_rel_dir; //absolute system path for this course
  790. if($delete == 'remove' && is_dir($course_scorm_dir.$path) and !empty($course_scorm_dir)){
  791. if($this->debug>2){error_log('New LP - In learnpath::delete(), found SCORM, deleting directory: '.$course_scorm_dir.$path,0);}
  792. exec('rm -rf '.$course_scorm_dir.$path);
  793. }
  794. }
  795. }
  796. }
  797. $sql_del_lp = "DELETE FROM $lp WHERE id = ".$this->lp_id;
  798. //if($this->debug>2){error_log('New LP - Deleting lp '.$this->lp_id.': '.$sql_del_lp,0);}
  799. $res_del_lp = api_sql_query($sql_del_lp);
  800. //TODO: also delete items and item-views
  801. }
  802. /**
  803. * Removes all the children of one item - dangerous!
  804. * @param integer Element ID of which children have to be removed
  805. * @return integer Total number of children removed
  806. */
  807. function delete_children_items($id){
  808. if($this->debug>0){error_log('New LP - In learnpath::delete_children_items('.$id.')',0);}
  809. $num = 0;
  810. if(empty($id) || $id != strval(intval($id))){return false;}
  811. $lp_item = Database::get_course_table('lp_item');
  812. $sql = "SELECT * FROM $lp_item WHERE parent_item_id = $id";
  813. $res = api_sql_query($sql);
  814. while($row = Database::fetch_array($res)){
  815. $num += $this->delete_children_items($row['id']);
  816. $sql_del = "DELETE FROM $lp_item WHERE id = ".$row['id'];
  817. $res_del = api_sql_query($sql_del);
  818. $num++;
  819. }
  820. return $num;
  821. }
  822. /**
  823. * Removes an item from the current learnpath
  824. * @param integer Elem ID (0 if first)
  825. * @param integer Whether to remove the resource/data from the system or leave it (default: 'keep', others 'remove')
  826. * @return integer Number of elements moved
  827. * @todo implement resource removal
  828. */
  829. function delete_item($id, $remove='keep')
  830. {
  831. if($this->debug>0){error_log('New LP - In learnpath::delete_item()',0);}
  832. //TODO - implement the resource removal
  833. if(empty($id) || $id != strval(intval($id))){return false;}
  834. //first select item to get previous, next, and display order
  835. $lp_item = Database::get_course_table('lp_item');
  836. $sql_sel = "SELECT * FROM $lp_item WHERE id = $id";
  837. $res_sel = api_sql_query($sql_sel,__FILE__,__LINE__);
  838. if(Database::num_rows($res_sel)<1){return false;}
  839. $row = Database::fetch_array($res_sel);
  840. $previous = $row['previous_item_id'];
  841. $next = $row['next_item_id'];
  842. $display = $row['display_order'];
  843. $parent = $row['parent_item_id'];
  844. $lp = $row['lp_id'];
  845. //delete children items
  846. $num = $this->delete_children_items($id);
  847. if($this->debug>2){error_log('New LP - learnpath::delete_item() - deleted '.$num.' children of element '.$id,0);}
  848. //now delete the item
  849. $sql_del = "DELETE FROM $lp_item WHERE id = $id";
  850. if($this->debug>2){error_log('New LP - Deleting item: '.$sql_del,0);}
  851. $res_del = api_sql_query($sql_del,__FILE__,__LINE__);
  852. //now update surrounding items
  853. $sql_upd = "UPDATE $lp_item SET next_item_id = $next WHERE id = $previous";
  854. $res_upd = api_sql_query($sql_upd,__FILE__,__LINE__);
  855. $sql_upd = "UPDATE $lp_item SET previous_item_id = $previous WHERE id = $next";
  856. $res_upd = api_sql_query($sql_upd,__FILE__,__LINE__);
  857. //now update all following items with new display order
  858. $sql_all = "UPDATE $lp_item SET display_order = display_order-1 WHERE lp_id = $lp AND parent_item_id = $parent AND display_order > $display";
  859. $res_all = api_sql_query($sql_all,__FILE__,__LINE__);
  860. }
  861. /**
  862. * Updates an item's content in place
  863. * @param integer Element ID
  864. * @param string New content
  865. * @return boolean True on success, false on error
  866. */
  867. function old_edit_item($id,$content)
  868. {
  869. if($this->debug>0){error_log('New LP - In learnpath::edit_item()',0);}
  870. if(empty($id) or ($id != strval(intval($id))) or empty($content)){ return false; }
  871. $content = $this->escape_string($content);
  872. $lp_item = Database::get_course_table('lp_item');
  873. $sql_upd = "UPDATE $lp_item SET title = '$content' WHERE id = $id";
  874. $res_upd = api_sql_query($sql_upd,__FILE__,__LINE__);
  875. //TODO update the item object (can be ignored for now because refreshed)
  876. return true;
  877. }
  878. function edit_item($id, $parent, $previous, $title, $description, $prerequisites=0)
  879. {
  880. if($this->debug > 0){error_log('New LP - In learnpath::edit_item()', 0);}
  881. if(empty($id) or ($id != strval(intval($id))) or empty($title)){ return false; }
  882. $tbl_lp_item = Database::get_course_table('lp_item');
  883. $sql_select = "
  884. SELECT *
  885. FROM " . $tbl_lp_item . "
  886. WHERE id = " . $id;
  887. $res_select = api_sql_query($sql_select, __FILE__, __LINE__);
  888. $row_select = Database::fetch_array($res_select);
  889. $same_parent = ($row_select['parent_item_id'] == $parent) ? true : false;
  890. $same_previous = ($row_select['previous_item_id'] == $previous) ? true : false;
  891. if($same_parent && $same_previous)
  892. {
  893. //only update title and description
  894. $sql_update = "
  895. UPDATE " . $tbl_lp_item . "
  896. SET
  897. title = '" . $this->escape_string(htmlentities($title)) . "',
  898. prerequisite = '".$prerequisites."',
  899. description = '" . $this->escape_string(htmlentities($description)) . "'
  900. WHERE id = " . $id;
  901. $res_update = api_sql_query($sql_update, __FILE__, __LINE__);
  902. }
  903. else
  904. {
  905. $old_parent = $row_select['parent_item_id'];
  906. $old_previous = $row_select['previous_item_id'];
  907. $old_next = $row_select['next_item_id'];
  908. $old_order = $row_select['display_order'];
  909. $old_prerequisite= $row_select['prerequisite'];
  910. /* BEGIN -- virtually remove the current item id */
  911. /* for the next and previous item it is like the current item doesn't exist anymore */
  912. if($old_previous != 0)
  913. {
  914. $sql_update_next = "
  915. UPDATE " . $tbl_lp_item . "
  916. SET next_item_id = " . $old_next . "
  917. WHERE id = " . $old_previous;
  918. $res_update_next = api_sql_query($sql_update_next, __FILE__, __LINE__);
  919. //echo '<p>' . $sql_update_next . '</p>';
  920. }
  921. if($old_next != 0)
  922. {
  923. $sql_update_previous = "
  924. UPDATE " . $tbl_lp_item . "
  925. SET previous_item_id = " . $old_previous . "
  926. WHERE id = " . $old_next;
  927. $res_update_previous = api_sql_query($sql_update_previous, __FILE__, __LINE__);
  928. //echo '<p>' . $sql_update_previous . '</p>';
  929. }
  930. //display_order - 1 for every item with a display_order bigger then the display_order of the current item
  931. $sql_update_order = "
  932. UPDATE " . $tbl_lp_item . "
  933. SET display_order = display_order - 1
  934. WHERE
  935. display_order > " . $old_order . " AND
  936. parent_item_id = " . $old_parent;
  937. $res_update_order = api_sql_query($sql_update_order, __FILE__, __LINE__);
  938. //echo '<p>' . $sql_update_order . '</p>';
  939. /* END -- virtually remove the current item id */
  940. /* BEGIN -- update the current item id to his new location */
  941. if($previous == 0)
  942. {
  943. //select the data of the item that should come after the current item
  944. $sql_select_old = "
  945. SELECT
  946. id,
  947. display_order
  948. FROM " . $tbl_lp_item . "
  949. WHERE
  950. lp_id = " . $this->lp_id . " AND
  951. parent_item_id = " . $parent . " AND
  952. previous_item_id = " . $previous;
  953. $res_select_old = api_sql_query($sql_select_old, __FILE__, __LINE__);
  954. $row_select_old = Database::fetch_array($res_select_old);
  955. //echo '<p>' . $sql_select_old . '</p>';
  956. //if the new parent doesn't had children before
  957. if(Database::num_rows($res_select_old) == 0)
  958. {
  959. $new_next = 0;
  960. $new_order = 1;
  961. }
  962. else
  963. {
  964. $new_next = $row_select_old['id'];
  965. $new_order = $row_select_old['display_order'];
  966. }
  967. //echo 'New next_item_id of current item: ' . $new_next . '<br />';
  968. //echo 'New previous_item_id of current item: ' . $previous . '<br />';
  969. //echo 'New display_order of current item: ' . $new_order . '<br />';
  970. }
  971. else
  972. {
  973. //select the data of the item that should come before the current item
  974. $sql_select_old = "
  975. SELECT
  976. next_item_id,
  977. display_order
  978. FROM " . $tbl_lp_item . "
  979. WHERE id = " . $previous;
  980. $res_select_old = api_sql_query($sql_select_old, __FILE__, __LINE__);
  981. $row_select_old = Database::fetch_array($res_select_old);
  982. //echo '<p>' . $sql_select_old . '</p>';
  983. //echo 'New next_item_id of current item: ' . $row_select_old['next_item_id'] . '<br />';
  984. //echo 'New previous_item_id of current item: ' . $previous . '<br />';
  985. //echo 'New display_order of current item: ' . ($row_select_old['display_order'] + 1) . '<br />';
  986. $new_next = $row_select_old['next_item_id'];
  987. $new_order = $row_select_old['display_order'] + 1;
  988. }
  989. //update the current item with the new data
  990. $sql_update = "
  991. UPDATE " . $tbl_lp_item . "
  992. SET
  993. title = '" . $this->escape_string(htmlentities($title)) . "',
  994. description = '" . $this->escape_string(htmlentities($description)) . "',
  995. parent_item_id = " . $parent . ",
  996. previous_item_id = " . $previous . ",
  997. next_item_id = " . $new_next . ",
  998. display_order = " . $new_order . "
  999. WHERE id = " . $id;
  1000. $res_update_next = api_sql_query($sql_update, __FILE__, __LINE__);
  1001. //echo '<p>' . $sql_update . '</p>';
  1002. if($previous != 0)
  1003. {
  1004. //update the previous item his next_item_id
  1005. $sql_update_previous = "
  1006. UPDATE " . $tbl_lp_item . "
  1007. SET next_item_id = " . $id . "
  1008. WHERE id = " . $previous;
  1009. $res_update_next = api_sql_query($sql_update_previous, __FILE__, __LINE__);
  1010. //echo '<p>' . $sql_update_previous . '</p>';
  1011. }
  1012. if($new_next != 0)
  1013. {
  1014. //update the next item his previous_item_id
  1015. $sql_update_next = "
  1016. UPDATE " . $tbl_lp_item . "
  1017. SET previous_item_id = " . $id . "
  1018. WHERE id = " . $new_next;
  1019. $res_update_next = api_sql_query($sql_update_next, __FILE__, __LINE__);
  1020. //echo '<p>' . $sql_update_next . '</p>';
  1021. }
  1022. if($old_prerequisite!=$prerequisites){
  1023. $sql_update_next = "
  1024. UPDATE " . $tbl_lp_item . "
  1025. SET prerequisite = " . $prerequisites . "
  1026. WHERE id = " . $id;
  1027. $res_update_next = api_sql_query($sql_update_next, __FILE__, __LINE__);
  1028. }
  1029. //update all the items with the same or a bigger display_order then the current item
  1030. $sql_update_order = "
  1031. UPDATE " . $tbl_lp_item . "
  1032. SET display_order = display_order + 1
  1033. WHERE
  1034. lp_id = " . $this->get_id() . " AND
  1035. id <> " . $id . " AND
  1036. parent_item_id = " . $parent . " AND
  1037. display_order >= " . $new_order;
  1038. $res_update_next = api_sql_query($sql_update_order, __FILE__, __LINE__);
  1039. //echo '<p>' . $sql_update_order . '</p>';
  1040. /* END -- update the current item id to his new location */
  1041. }
  1042. }
  1043. /**
  1044. * Updates an item's prereq in place
  1045. * @param integer Element ID
  1046. * @param string Prerequisite Element ID
  1047. *
  1048. * @param string Prerequisite item type
  1049. *
  1050. * @param string Prerequisite min score
  1051. *
  1052. * @param string Prerequisite max score
  1053. * @return boolean True on success, false on error
  1054. */
  1055. function edit_item_prereq($id, $prerequisite_id, $min_score = 0, $max_score = 100)
  1056. {
  1057. if($this->debug>0){error_log('New LP - In learnpath::edit_item_prereq()',0);}
  1058. if(empty($id) or ($id != strval(intval($id))) or empty($prerequisite_id)){ return false; }
  1059. $prerequisite_id = $this->escape_string($prerequisite_id);
  1060. $tbl_lp_item = Database::get_course_table('lp_item');
  1061. if(!is_numeric($min_score) || $min_score < 0 || $min_score > 100)
  1062. $min_score = 0;
  1063. if(!is_numeric($max_score) || $max_score < 0 || $max_score > 100)
  1064. $max_score = 100;
  1065. if($min_score > $max_score)
  1066. $max_score = $min_score;
  1067. if(!is_numeric($prerequisite_id))
  1068. $prerequisite_id = 'NULL';
  1069. $sql_upd = "
  1070. UPDATE " . $tbl_lp_item . "
  1071. SET
  1072. min_score = " . $min_score . ",
  1073. max_score = " . $max_score . ",
  1074. prerequisite = " . $prerequisite_id . "
  1075. WHERE id = " . $id;
  1076. $res_upd = api_sql_query($sql_upd ,__FILE__, __LINE__);
  1077. //TODO update the item object (can be ignored for now because refreshed)
  1078. return true;
  1079. }
  1080. /**
  1081. * Escapes a string with the available database escape function
  1082. * @param string String to escape
  1083. * @return string String escaped
  1084. */
  1085. function escape_string($string){
  1086. //if($this->debug>0){error_log('New LP - In learnpath::escape_string('.$string.')',0);}
  1087. return mysql_real_escape_string($string);
  1088. }
  1089. /**
  1090. * Static admin function exporting a learnpath into a zip file
  1091. * @param string Export type (scorm, zip, cd)
  1092. * @param string Course code
  1093. * @param integer Learnpath ID
  1094. * @param string Zip file name
  1095. * @return string Zip file path (or false on error)
  1096. */
  1097. function export_lp($type, $course, $id, $zipname)
  1098. {
  1099. //if($this->debug>0){error_log('New LP - In learnpath::export_lp()',0);}
  1100. //TODO
  1101. if(empty($type) OR empty($course) OR empty($id) OR empty($zipname)){return false;}
  1102. $url = '';
  1103. switch($type){
  1104. case 'scorm':
  1105. break;
  1106. case 'zip':
  1107. break;
  1108. case 'cdrom':
  1109. break;
  1110. }
  1111. return $url;
  1112. }
  1113. /**
  1114. * Gets all the chapters belonging to the same parent as the item/chapter given
  1115. * Can also be called as abstract method
  1116. * @param integer Item ID
  1117. * @return array A list of all the "brother items" (or an empty array on failure)
  1118. */
  1119. function get_brother_chapters($id){
  1120. if($this->debug>0){error_log('New LP - In learnpath::get_brother_chapters()',0);}
  1121. if(empty($id) OR $id != strval(intval($id))){ return array();}
  1122. $lp_item = Database::get_course_table('lp_item');
  1123. $sql_parent = "SELECT * FROM $lp_item WHERE id = $id AND item_type='dokeos_chapter'";
  1124. $res_parent = api_sql_query($sql_parent,__FILE__,__LINE__);
  1125. if(Database::num_rows($res_parent)>0){
  1126. $row_parent = Database::fetch_array($res_parent);
  1127. $parent = $row_parent['parent_item_id'];
  1128. $sql_bros = "SELECT * FROM $lp_item WHERE parent_item_id = $parent AND id = $id AND item_type='dokeos_chapter' ORDER BY display_order";
  1129. $res_bros = api_sql_query($sql_bros,__FILE__,__LINE__);
  1130. $list = array();
  1131. while ($row_bro = Database::fetch_array($res_bros)){
  1132. $list[] = $row_bro;
  1133. }
  1134. return $list;
  1135. }
  1136. return array();
  1137. }
  1138. /**
  1139. * Gets all the items belonging to the same parent as the item given
  1140. * Can also be called as abstract method
  1141. * @param integer Item ID
  1142. * @return array A list of all the "brother items" (or an empty array on failure)
  1143. */
  1144. function get_brother_items($id){
  1145. if($this->debug>0){error_log('New LP - In learnpath::get_brother_items('.$id.')',0);}
  1146. if(empty($id) OR $id != strval(intval($id))){ return array();}
  1147. $lp_item = Database::get_course_table('lp_item');
  1148. $sql_parent = "SELECT * FROM $lp_item WHERE id = $id";
  1149. $res_parent = api_sql_query($sql_parent,__FILE__,__LINE__);
  1150. if(Database::num_rows($res_parent)>0){
  1151. $row_parent = Database::fetch_array($res_parent);
  1152. $parent = $row_parent['parent_item_id'];
  1153. $sql_bros = "SELECT * FROM $lp_item WHERE parent_item_id = $parent ORDER BY display_order";
  1154. $res_bros = api_sql_query($sql_bros,__FILE__,__LINE__);
  1155. $list = array();
  1156. while ($row_bro = Database::fetch_array($res_bros)){
  1157. $list[] = $row_bro;
  1158. }
  1159. return $list;
  1160. }
  1161. return array();
  1162. }
  1163. /**
  1164. * Gets the number of items currently completed
  1165. * @return integer The number of items currently completed
  1166. */
  1167. function get_complete_items_count()
  1168. {
  1169. if($this->debug>0){error_log('New LP - In learnpath::get_complete_items_count()',0);}
  1170. $i = 0;
  1171. foreach($this->items as $id => $dummy){
  1172. //if($this->items[$id]->status_is(array('completed','passed','succeeded'))){
  1173. //Trying failed and browsed considered "progressed" as well
  1174. 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'){
  1175. $i++;
  1176. }
  1177. }
  1178. return $i;
  1179. }
  1180. /**
  1181. * Gets the current item ID
  1182. * @return integer The current learnpath item id
  1183. */
  1184. function get_current_item_id()
  1185. {
  1186. $current = 0;
  1187. if($this->debug>0){error_log('New LP - In learnpath::get_current_item_id()',0);}
  1188. if(!empty($this->current))
  1189. {
  1190. $current = $this->current;
  1191. }
  1192. if($this->debug>2){error_log('New LP - In learnpath::get_current_item_id() - Returning '.$current,0);}
  1193. return $current;
  1194. }
  1195. /**
  1196. * Gets the total number of items available for viewing in this SCORM
  1197. * @return integer The total number of items
  1198. */
  1199. function get_total_items_count()
  1200. {
  1201. if($this->debug>0){error_log('New LP - In learnpath::get_total_items_count()',0);}
  1202. return count($this->items);
  1203. }
  1204. /**
  1205. * Gets the total number of items available for viewing in this SCORM but without chapters
  1206. * @return integer The total no-chapters number of items
  1207. */
  1208. function get_total_items_count_without_chapters()
  1209. {
  1210. if($this->debug>0){error_log('New LP - In learnpath::get_total_items_count_without_chapters()',0);}
  1211. $total=0;
  1212. foreach($this->items as $temp=>$temp2){
  1213. if(!in_array($temp2->get_type(), array('dokeos_chapter','chapter','dir'))) $total++;
  1214. }
  1215. return $total;
  1216. }
  1217. /**
  1218. * Gets the first element URL.
  1219. * @return string URL to load into the viewer
  1220. */
  1221. function first()
  1222. {
  1223. if($this->debug>0){error_log('New LP - In learnpath::first()',0);}
  1224. //test if the last_item_seen exists and is not a dir
  1225. if(!empty($this->last_item_seen)
  1226. && !empty($this->items[$this->last_item_seen])
  1227. && $this->items[$this->last_item_seen]->get_type() != 'dir'
  1228. && $this->items[$this->last_item_seen]->get_type() != 'dokeos_chapter'
  1229. && $this->items[$this->last_item_seen]->is_done() != true
  1230. ){
  1231. 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);}
  1232. $index = -1;
  1233. foreach($this->ordered_items as $myindex => $item_id){
  1234. if($item_id == $this->last_item_seen){
  1235. $index = $myindex;
  1236. break;
  1237. }
  1238. }
  1239. if($index==-1){
  1240. //index hasn't changed, so item not found - panic (this shouldn't happen)
  1241. 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);}
  1242. return false;
  1243. }else{
  1244. $this->last = $this->last_item_seen;
  1245. $this->current = $this->last_item_seen;
  1246. $this->index = $index;
  1247. }
  1248. }else{
  1249. if($this->debug>2){error_log('New LP - In learnpath::first() - No last item seen',0);}
  1250. $index = 0;
  1251. while (!empty($this->ordered_items[$index])
  1252. AND
  1253. (
  1254. $this->items[$this->ordered_items[$index]]->get_type() == 'dir'
  1255. OR $this->items[$this->ordered_items[$index]]->get_type() == 'dokeos_chapter'
  1256. OR $this->items[$this->ordered_items[$index]]->is_done() === true
  1257. )
  1258. AND $index < $this->max_ordered_items)
  1259. {
  1260. $index ++;
  1261. }
  1262. $this->last = $this->current;
  1263. //current is
  1264. $this->current = $this->ordered_items[$index];
  1265. $this->index = $index;
  1266. if($this->debug>2){error_log('New LP - In learnpath::first() - No last item seen. New last = '.$this->last.'('.$this->ordered_items[$index].')',0);}
  1267. }
  1268. if($this->debug>2){error_log('New LP - In learnpath::first() - First item is '.$this->get_current_item_id());}
  1269. }
  1270. /**
  1271. * Gets the information about an item in a format usable as JavaScript to update
  1272. * the JS API by just printing this content into the <head> section of the message frame
  1273. * @param integer Item ID
  1274. * @return string
  1275. */
  1276. function get_js_info($item_id=''){
  1277. if($this->debug>0){error_log('New LP - In learnpath::get_js_info('.$item_id.')',0);}
  1278. $info = '';
  1279. $item_id = $this->escape_string($item_id);
  1280. if(!empty($item_id) && is_object($this->items[$item_id])){
  1281. //if item is defined, return values from DB
  1282. $oItem = $this->items[$item_id];
  1283. $info .= '<script language="javascript">';
  1284. $info .= "top.set_score(".$oItem->get_score().");\n";
  1285. $info .= "top.set_max(".$oItem->get_max().");\n";
  1286. $info .= "top.set_min(".$oItem->get_min().");\n";
  1287. $info .= "top.set_lesson_status('".$oItem->get_status()."');";
  1288. $info .= "top.set_session_time('".$oItem->get_scorm_time('js')."');";
  1289. $info .= "top.set_suspend_data('".$oItem->get_suspend_data()."');";
  1290. $info .= "top.set_saved_lesson_status('".$oItem->get_status()."');";
  1291. $info .= "top.set_flag_synchronized();";
  1292. $info .= '</script>';
  1293. if($this->debug>2){error_log('New LP - in learnpath::get_js_info('.$item_id.') - returning: '.$info,0);}
  1294. return $info;
  1295. }else{
  1296. //if item_id is empty, just update to default SCORM data
  1297. $info .= '<script language="javascript">';
  1298. $info .= "top.set_score(".learnpathItem::get_score().");\n";
  1299. $info .= "top.set_max(".learnpathItem::get_max().");\n";
  1300. $info .= "top.set_min(".learnpathItem::get_min().");\n";
  1301. $info .= "top.set_lesson_status('".learnpathItem::get_status()."');";
  1302. $info .= "top.set_session_time('".learnpathItem::get_scorm_time('js')."');";
  1303. $info .= "top.set_suspend_data('".learnpathItem::get_suspend_data()."');";
  1304. $info .= "top.set_saved_lesson_status('".learnpathItem::get_status()."');";
  1305. $info .= "top.set_flag_synchronized();";
  1306. $info .= '</script>';
  1307. if($this->debug>2){error_log('New LP - in learnpath::get_js_info('.$item_id.') - returning: '.$info,0);}
  1308. return $info;
  1309. }
  1310. }
  1311. /**
  1312. * Gets the js library from the database
  1313. * @return string The name of the javascript library to be used
  1314. */
  1315. function get_js_lib(){
  1316. $lib = '';
  1317. if(!empty($this->js_lib)){
  1318. $lib = $this->js_lib;
  1319. }
  1320. return $lib;
  1321. }
  1322. /**
  1323. * Gets the learnpath database ID
  1324. * @return integer Learnpath ID in the lp table
  1325. */
  1326. function get_id()
  1327. {
  1328. if($this->debug>0){error_log('New LP - In learnpath::get_id()',0);}
  1329. if(!empty($this->lp_id))
  1330. {
  1331. return $this->lp_id;
  1332. }else{
  1333. return 0;
  1334. }
  1335. }
  1336. /**
  1337. * Gets the last element URL.
  1338. * @return string URL to load into the viewer
  1339. */
  1340. function get_last()
  1341. {
  1342. if($this->debug>0){error_log('New LP - In learnpath::get_last()',0);}
  1343. $this->index = count($this->ordered_items)-1;
  1344. return $this->ordered_items[$this->index];
  1345. }
  1346. /**
  1347. * Gets the navigation bar for the learnpath display screen
  1348. * @return string The HTML string to use as a navigation bar
  1349. */
  1350. function get_navigation_bar()
  1351. {
  1352. if($this->debug>0){error_log('New LP - In learnpath::get_navigation_bar()',0);}
  1353. //TODO find a good value for the following variables
  1354. $file = '';
  1355. $openDir = '';
  1356. $edoceo = '';
  1357. $time = 0;
  1358. $navbar = '';
  1359. $RequestUri = '';
  1360. $mycurrentitemid = $this->get_current_item_id();
  1361. if($this->mode == 'fullscreen'){
  1362. $navbar = '<table cellpadding="0" cellspacing="0" align="left">'."\n".
  1363. ' <tr> '."\n" .
  1364. ' <td>'."\n" .
  1365. ' <div class="buttons">'."\n" .
  1366. ' <a href="" onclick="dokeos_xajax_handler.switch_item('.$mycurrentitemid.',\'previous\');return false;" title="previous"><img border="0" src="../img/previous.gif" title="'.get_lang('ScormPrevious').'"></a>&nbsp;'."\n" .
  1367. ' <a href="" onclick="dokeos_xajax_handler.switch_item('.$mycurrentitemid.',\'next\');return false;" title="next" ><img border="0" src="../img/next.gif" title="'.get_lang('ScormNext').'"></a>&nbsp;'."\n" .
  1368. ' <a href="lp_controller.php?action=mode&mode=embedded" target="_top" title="embedded mode"><img border="0" src="../img/scormexitfullscreen.jpg" title="'.get_lang('ScormExitFullScreen').'"></a>'."\n" .
  1369. ' <a href="lp_controller.php?action=list" target="_top" title="learnpaths list"><img border="0" src="../img/exit.png" title="Exit"></a>'."\n" .
  1370. ' </div>'."\n" .
  1371. ' </td>'."\n" .
  1372. ' </tr>'."\n" .
  1373. '</table>'."\n" ;
  1374. }else{
  1375. $navbar = '<table cellpadding="0" cellspacing="0" align="left">'."\n".
  1376. ' <tr> '."\n" .
  1377. ' <td>'."\n" .
  1378. ' <div class="buttons">'."\n" .
  1379. ' <a href="lp_controller.php?action=stats" target="content_name" title="stats"><img border="0" src="../img/lp_stats.gif" title="'.get_lang('ScormMystatus').'"></a>&nbsp;'."\n" .
  1380. ' <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" .
  1381. ' <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" .
  1382. //' <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" .
  1383. ' </div>'."\n" .
  1384. ' </td>'."\n" .
  1385. ' </tr>'."\n" .
  1386. '</table>'."\n" ;
  1387. }
  1388. return $navbar;
  1389. }
  1390. /**
  1391. * Gets the next resource in queue (url).
  1392. * @return string URL to load into the viewer
  1393. */
  1394. function get_next_index()
  1395. {
  1396. if($this->debug>0){error_log('New LP - In learnpath::get_next_index()',0);}
  1397. //TODO
  1398. $index = $this->index;
  1399. $index ++;
  1400. if($this->debug>2){error_log('New LP - Now looking at ordered_items['.($index).'] - type is '.$this->items[$this->ordered_items[$index]]['type'],0);}
  1401. 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)
  1402. {
  1403. $index ++;
  1404. if($index == $this->max_ordered_items)
  1405. {
  1406. return $this->index;
  1407. }
  1408. }
  1409. if(empty($this->ordered_items[$index])){
  1410. return $this->index;
  1411. }
  1412. if($this->debug>2){error_log('New LP - index is now '.$index,0);}
  1413. return $index;
  1414. }
  1415. /**
  1416. * Gets item_id for the next element
  1417. * @return integer Next item (DB) ID
  1418. */
  1419. function get_next_item_id()
  1420. {
  1421. $new_index = $this->get_next_index();
  1422. return $this->ordered_items[$new_index];
  1423. }
  1424. /**
  1425. * Returns the package type ('scorm','aicc','scorm2004','dokeos','ppt'...)
  1426. *
  1427. * Generally, the package provided is in the form of a zip file, so the function
  1428. * has been written to test a zip file. If not a zip, the function will return the
  1429. * default return value: ''
  1430. * @param string the path to the file
  1431. * @param string the original name of the file
  1432. * @return string 'scorm','aicc','scorm2004','dokeos' or '' if the package cannot be recognized
  1433. */
  1434. function get_package_type($file_path,$file_name){
  1435. //get name of the zip file without the extension
  1436. $file_info = pathinfo($file_name);
  1437. $filename = $file_info['basename'];//name including extension
  1438. $extension = $file_info['extension'];//extension only
  1439. if(!empty($_POST['ppt2lp']) && !in_array($extension,array('dll','exe')))
  1440. {
  1441. return 'ppt';
  1442. }
  1443. $file_base_name = str_replace('.'.$extension,'',$filename); //filename without its extension
  1444. $zipFile = new pclZip($file_path);
  1445. // Check the zip content (real size and file extension)
  1446. $zipContentArray = $zipFile->listContent();
  1447. $package_type='';
  1448. $at_root = false;
  1449. $manifest = '';
  1450. //the following loop should be stopped as soon as we found the right imsmanifest.xml (how to recognize it?)
  1451. foreach($zipContentArray as $thisContent)
  1452. {
  1453. if ( preg_match('~.(php.*|phtml)$~i', $thisContent['filename']) )
  1454. {
  1455. return '';
  1456. }
  1457. elseif(stristr($thisContent['filename'],'imsmanifest.xml')!==FALSE)
  1458. {
  1459. $manifest = $thisContent['filename']; //just the relative directory inside scorm/
  1460. $package_type = 'scorm';
  1461. break;//exit the foreach loop
  1462. }
  1463. elseif(preg_match('/aicc\//i',$thisContent['filename'])!==FALSE)
  1464. {//if found an aicc directory...
  1465. $package_type='aicc';
  1466. //break;//don't exit the loop, because if we find an imsmanifest afterwards, we want it, not the AICC
  1467. }
  1468. else
  1469. {
  1470. $package_type = '';
  1471. }
  1472. }
  1473. return $package_type;
  1474. }
  1475. /**
  1476. * Gets the previous resource in queue (url). Also initialises time values for this viewing
  1477. * @return string URL to load into the viewer
  1478. */
  1479. function get_previous_index()
  1480. {
  1481. if($this->debug>0){error_log('New LP - In learnpath::get_previous_index()',0);}
  1482. $index = $this->index;
  1483. if(isset($this->ordered_items[$index-1])){
  1484. $index --;
  1485. 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'))
  1486. {
  1487. $index --;
  1488. if($index < 0){
  1489. return $this->index;
  1490. }
  1491. }
  1492. }else{
  1493. if($this->debug>2){error_log('New LP - get_previous_index() - there was no previous index available, reusing '.$index,0);}
  1494. //no previous item
  1495. }
  1496. return $index;
  1497. }
  1498. /**
  1499. * Gets item_id for the next element
  1500. * @return integer Previous item (DB) ID
  1501. */
  1502. function get_previous_item_id()
  1503. {
  1504. $new_index = $this->get_previous_index();
  1505. return $this->ordered_items[$new_index];
  1506. }
  1507. /**
  1508. * Gets the progress value from the progress_db attribute
  1509. * @return integer Current progress value
  1510. */
  1511. function get_progress(){
  1512. if($this->debug>0){error_log('New LP - In learnpath::get_progress()',0);}
  1513. if(!empty($this->progress_db)){
  1514. return $this->progress_db;
  1515. }
  1516. return 0;
  1517. }
  1518. /**
  1519. * Gets the progress value from the progress field in the database (allows use as abstract method)
  1520. * @param integer Learnpath ID
  1521. * @param integer User ID
  1522. * @param string Mode of display ('%','abs' or 'both')
  1523. * @return integer Current progress value as found in the database
  1524. */
  1525. function get_db_progress($lp_id,$user_id,$mode='%', $course_db=''){
  1526. //if($this->debug>0){error_log('New LP - In learnpath::get_db_progress()',0);}
  1527. $table = Database::get_course_table('lp_view', $course_db);
  1528. $sql = "SELECT * FROM $table WHERE lp_id = $lp_id AND user_id = $user_id";
  1529. $res = api_sql_query($sql,__FILE__,__LINE__);
  1530. $view_id = 0;
  1531. if(Database::num_rows($res)>0){
  1532. $row = Database::fetch_array($res);
  1533. $progress = $row['progress'];
  1534. $view_id = $row['id'];
  1535. }
  1536. if(!$progress){
  1537. $progress = '0';
  1538. }
  1539. if($mode == '%'){
  1540. return $progress.'%';
  1541. }else{
  1542. //get the number of items completed and the number of items total
  1543. $tbl = Database::get_course_table('lp_item', $course_db);
  1544. $sql = "SELECT count(*) FROM $tbl WHERE lp_id = ".$lp_id."
  1545. AND item_type NOT IN('dokeos_chapter','chapter','dir')";
  1546. $res = api_sql_query($sql);
  1547. $row = Database::fetch_array($res);
  1548. $total = $row[0];
  1549. $tbl = Database::get_course_table('lp_item_view', $course_db);
  1550. //$sql = "SELECT count(distinct(lp_item_id)) FROM $tbl WHERE lp_view_id = ".$view_id." AND status IN ('passed','completed','succeeded')";
  1551. //trying as also counting browsed and failed items
  1552. $sql = "SELECT count(distinct(lp_item_id)) FROM $tbl WHERE lp_view_id = ".$view_id." AND status IN ('passed','completed','succeeded','browsed','failed')";
  1553. $res = api_sql_query($sql);
  1554. $row = Database::fetch_array($res);
  1555. $completed = $row[0];
  1556. if($mode == 'abs'){
  1557. return $completed.'/'.$total;
  1558. }
  1559. elseif($mode == 'both')
  1560. {
  1561. if($progress<($completed/($total?$total:1))){
  1562. $progress = number_format(($completed/($total?$total:1))*100,0);
  1563. }
  1564. return $progress.'% ('.$completed.'/'.$total.')';
  1565. }
  1566. }
  1567. return $progress;
  1568. }
  1569. /**
  1570. * Gets a progress bar for the learnpath by counting the number of items in it and the number of items
  1571. * completed so far.
  1572. * @param string Mode in which we want the values
  1573. * @param integer Progress value to display (optional but mandatory if used in abstract context)
  1574. * @param string Text to display near the progress value (optional but mandatory in abstract context)
  1575. * @return string HTML string containing the progress bar
  1576. */
  1577. function get_progress_bar($mode='',$percentage=-1,$text_add='')
  1578. {
  1579. if($this->debug>0){error_log('New LP - In learnpath::get_progress_bar()',0);}
  1580. if($percentage=='-1' OR $text_add==''){
  1581. list ($percentage, $text_add) = $this->get_progress_bar_text($mode);
  1582. }
  1583. $text = $percentage.$text_add;
  1584. $output = ''
  1585. //.htmlentities(get_lang('ScormCompstatus'),ENT_QUOTES,'ISO-8859-1')."<br />"
  1586. .'<table border="0" cellpadding="0" cellspacing="0"><tr><td>'
  1587. .'<img id="progress_img_limit_left" src="../img/bar_1.gif" width="1" height="12">'
  1588. .'<img id="progress_img_full" src="../img/bar_1u.gif" width="'.$percentage.'" height="12" id="full_portion">'
  1589. .'<img id="progress_img_limit_middle" src="../img/bar_1m.gif" width="1" height="12">';
  1590. if($percentage <= 98){
  1591. $output .= '<img id="progress_img_empty" src="../img/bar_1r.gif" width="'.(100-$percentage).'" height="12" id="empty_portion">';
  1592. }else{
  1593. $output .= '<img id="progress_img_empty" src="../img/bar_1r.gif" width="0" height="12" id="empty_portion">';
  1594. }
  1595. $output .= '<img id="progress_bar_img_limit_right" src="../img/bar_1.gif" width="1" height="12"></td></tr></table>'
  1596. .'<div class="progresstext" id="progress_text">'.$text.'</div>';
  1597. return $output;
  1598. }
  1599. /**
  1600. * Gets the progress bar info to display inside the progress bar. Also used by scorm_api.php
  1601. * @param string Mode of display (can be '%' or 'abs').abs means we display a number of completed elements per total elements
  1602. * //@param integer Additional steps to fake as completed
  1603. * @return list Percentage or number and symbol (% or /xx)
  1604. */
  1605. function get_progress_bar_text($mode='',$add=0)
  1606. {
  1607. if($this->debug>0){error_log('New LP - In learnpath::get_progress_bar_text()',0);}
  1608. if(empty($mode)){$mode = $this->progress_bar_mode;}
  1609. $total_items = $this->get_total_items_count_without_chapters();
  1610. if($this->debug>2){error_log('New LP - Total items available in this learnpath: '.$total_items,0);}
  1611. $i = $this->get_complete_items_count();
  1612. if($this->debug>2){error_log('New LP - Items completed so far: '.$i,0);}
  1613. if($add != 0){
  1614. $i += $add;
  1615. if($this->debug>2){error_log('New LP - Items completed so far (+modifier): '.$i,0);}
  1616. }
  1617. $text = '';
  1618. if($i>$total_items){
  1619. $i = $total_items;
  1620. }
  1621. if($mode == '%'){
  1622. $percentage = ((float)$i/(float)$total_items)*100;
  1623. $percentage = number_format($percentage,0);
  1624. $text = '%';
  1625. }elseif($mode == 'abs'){
  1626. $percentage = $i;
  1627. $text = '/'.$total_items;
  1628. }
  1629. return array($percentage,$text);
  1630. }
  1631. /**
  1632. * Gets the progress bar mode
  1633. * @return string The progress bar mode attribute
  1634. */
  1635. function get_progress_bar_mode()
  1636. {
  1637. if($this->debug>0){error_log('New LP - In learnpath::get_progress_bar_mode()',0);}
  1638. if(!empty($this->progress_bar_mode))
  1639. {
  1640. return $this->progress_bar_mode;
  1641. }else{
  1642. return '%';
  1643. }
  1644. }
  1645. /**
  1646. * Gets the learnpath proximity (remote or local)
  1647. * @return string Learnpath proximity
  1648. */
  1649. function get_proximity()
  1650. {
  1651. if($this->debug>0){error_log('New LP - In learnpath::get_proximity()',0);}
  1652. if(!empty($this->proximity)){return $this->proximity;}else{return '';}
  1653. }
  1654. /**
  1655. * Returns a usable array of stats related to the current learnpath and user
  1656. * @return array Well-formatted array containing status for the current learnpath
  1657. */
  1658. function get_stats()
  1659. {
  1660. if($this->debug>0){error_log('New LP - In learnpath::get_stats()',0);}
  1661. //TODO
  1662. }
  1663. /**
  1664. * Static method. Can be re-implemented by children. Gives an array of statistics for
  1665. * the given course (for all learnpaths and all users)
  1666. * @param string Course code
  1667. * @return array Well-formatted array containing status for the course's learnpaths
  1668. */
  1669. function get_stats_course($course)
  1670. {
  1671. //if($this->debug>0){error_log('New LP - In learnpath::get_stats_course()',0);}
  1672. //TODO
  1673. }
  1674. /**
  1675. * Static method. Can be re-implemented by children. Gives an array of statistics for
  1676. * the given course and learnpath (for all users)
  1677. * @param string Course code
  1678. * @param integer Learnpath ID
  1679. * @return array Well-formatted array containing status for the specified learnpath
  1680. */
  1681. function get_stats_lp($course,$lp)
  1682. {
  1683. //if($this->debug>0){error_log('New LP - In learnpath::get_stats_lp()',0);}
  1684. //TODO
  1685. }
  1686. /**
  1687. * Static method. Can be re-implemented by children. Gives an array of statistics for
  1688. * the given course, learnpath and user.
  1689. * @param string Course code
  1690. * @param integer Learnpath ID
  1691. * @param integer User ID
  1692. * @return array Well-formatted array containing status for the specified learnpath and user
  1693. */
  1694. function get_stats_lp_user($course,$lp,$user)
  1695. {
  1696. //if($this->debug>0){error_log('New LP - In learnpath::get_stats_lp_user()',0);}
  1697. //TODO
  1698. }
  1699. /**
  1700. * Static method. Can be re-implemented by children. Gives an array of statistics for
  1701. * the given course and learnpath (for all users)
  1702. * @param string Course code
  1703. * @param integer User ID
  1704. * @return array Well-formatted array containing status for the user's learnpaths
  1705. */
  1706. function get_stats_user($course,$user)
  1707. {
  1708. //if($this->debug>0){error_log('New LP - In learnpath::get_stats_user()',0);}
  1709. //TODO
  1710. }
  1711. /**
  1712. * Gets the status list for all LP's items
  1713. * @return array Array of [index] => [item ID => current status]
  1714. */
  1715. function get_items_status_list(){
  1716. if($this->debug>0){error_log('New LP - In learnpath::get_items_status_list()',0);}
  1717. $list = array();
  1718. foreach($this->ordered_items as $item_id)
  1719. {
  1720. $list[]= array($item_id => $this->items[$item_id]->get_status());
  1721. }
  1722. return $list;
  1723. }
  1724. /**
  1725. * Return the number of interactions for the given learnpath Item View ID.
  1726. * This method can be used as static.
  1727. * @param integer Item View ID
  1728. * @return integer Number of interactions
  1729. */
  1730. function get_interactions_count_from_db($lp_iv_id=0){
  1731. $table = Database::get_course_table('lp_iv_interaction');
  1732. $sql = "SELECT count(*) FROM $table WHERE lp_iv_id = $lp_iv_id";
  1733. $res = api_sql_query($sql,__FILE__,__LINE__);
  1734. $row = Database::fetch_array($res);
  1735. $num = $row[0];
  1736. return $num;
  1737. }
  1738. /**
  1739. * Return the interactions as an array for the given lp_iv_id.
  1740. * This method can be used as static.
  1741. * @param integer Learnpath Item View ID
  1742. * @return array
  1743. * @todo Translate labels
  1744. */
  1745. function get_iv_interactions_array($lp_iv_id=0){
  1746. $list = array();
  1747. $table = Database::get_course_table('lp_iv_interaction');
  1748. $sql = "SELECT * FROM $table WHERE lp_iv_id = $lp_iv_id ORDER BY order_id ASC";
  1749. $res = api_sql_query($sql,__FILE__,__LINE__);
  1750. $num = Database::num_rows($res);
  1751. if($num>0){
  1752. $list[] = array(
  1753. "order_id"=>'Order',
  1754. "id"=>'Interaction ID',
  1755. "type"=>'Type',
  1756. "time"=>'Time (finished at ...)',
  1757. "correct_responses"=>'Correct responses',
  1758. "student_response"=>'Student response',
  1759. "result"=>'Result',
  1760. "latency"=>'Latency (time spent)');
  1761. while ($row = Database::fetch_array($res)){
  1762. $list[] = array(
  1763. "order_id"=>($row['order_id']+1),
  1764. "id"=>urldecode($row['interaction_id']),//urldecode because they often have %2F or stuff like that
  1765. "type"=>$row['interaction_type'],
  1766. "time"=>$row['completion_time'],
  1767. //"correct_responses"=>$row['correct_responses'],
  1768. //hide correct responses from students
  1769. "correct_responses"=>'',
  1770. "student_response"=>$row['student_response'],
  1771. "result"=>$row['result'],
  1772. "latency"=>$row['latency']);
  1773. }
  1774. }
  1775. return $list;
  1776. }
  1777. /**
  1778. * Generate and return the table of contents for this learnpath. The (flat) table returned can be
  1779. * used by get_html_toc() to be ready to display
  1780. * @return array TOC as a table with 4 elements per row: title, link, status and level
  1781. */
  1782. function get_toc()
  1783. {
  1784. if($this->debug>0){error_log('New LP - In learnpath::get_toc()',0);}
  1785. $toc = array();
  1786. //echo "<pre>".print_r($this->items,true)."</pre>";
  1787. foreach($this->ordered_items as $item_id)
  1788. {
  1789. if($this->debug>2){error_log('New LP - learnpath::get_toc(): getting info for item '.$item_id,0);}
  1790. //TODO change this link generation and use new function instead
  1791. $toc[] = array(
  1792. 'id'=>$item_id,
  1793. 'title'=>$this->items[$item_id]->get_title(),
  1794. //'link'=>get_addedresource_link_in_learnpath('document',$item_id,1),
  1795. 'status'=>$this->items[$item_id]->get_status(),
  1796. 'level'=>$this->items[$item_id]->get_level(),
  1797. 'type' =>$this->items[$item_id]->get_type(),
  1798. );
  1799. }
  1800. if($this->debug>2){error_log('New LP - In learnpath::get_toc() - TOC array: '.print_r($toc,true),0);}
  1801. return $toc;
  1802. }
  1803. /**
  1804. * Gets the learning path type
  1805. * @param boolean Return the name? If false, return the ID. Default is false.
  1806. * @return mixed Type ID or name, depending on the parameter
  1807. */
  1808. function get_type($get_name = false)
  1809. {
  1810. $res = false;
  1811. if($this->debug>0){error_log('New LP - In learnpath::get_type()',0);}
  1812. if(!empty($this->type))
  1813. {
  1814. if($get_name)
  1815. {
  1816. //get it from the lp_type table in main db
  1817. }else{
  1818. $res = $this->type;
  1819. }
  1820. }
  1821. if($this->debug>2){error_log('New LP - In learnpath::get_type() - Returning '.($res==false?'false':$res),0);}
  1822. return $res;
  1823. }
  1824. /**
  1825. * Gets a flat list of item IDs ordered for display (level by level ordered by order_display)
  1826. * This method can be used as abstract and is recursive
  1827. * @param integer Learnpath ID
  1828. * @param integer Parent ID of the items to look for
  1829. * @return mixed Ordered list of item IDs or false on error
  1830. */
  1831. function get_flat_ordered_items_list($lp,$parent=0){
  1832. //if($this->debug>0){error_log('New LP - In learnpath::get_flat_ordered_items_list('.$lp.','.$parent.')',0);}
  1833. $list = array();
  1834. if(empty($lp)){return false;}
  1835. $tbl_lp_item = Database::get_course_table('lp_item');
  1836. $sql = "SELECT * FROM $tbl_lp_item WHERE lp_id = $lp AND parent_item_id = $parent ORDER BY display_order";
  1837. $res = api_sql_query($sql,__FILE__,__LINE__);
  1838. while($row = Database::fetch_array($res)){
  1839. $sublist = learnpath::get_flat_ordered_items_list($lp,$row['id']);
  1840. $list[] = $row['id'];
  1841. foreach($sublist as $item){
  1842. $list[] = $item;
  1843. }
  1844. }
  1845. return $list;
  1846. }
  1847. /**
  1848. * Uses the table generated by get_toc() and returns an HTML-formatted string ready to display
  1849. * @return string HTML TOC ready to display
  1850. */
  1851. /*function get_html_toc()
  1852. {
  1853. if($this->debug>0){error_log('New LP - In learnpath::get_html_toc()',0);}
  1854. $list = $this->get_toc();
  1855. //echo $this->current;
  1856. //$parent = $this->items[$this->current]->get_parent();
  1857. //if(empty($parent)){$parent = $this->ordered_items[$this->items[$this->current]->get_previous_index()];}
  1858. $html = '<div class="inner_lp_toc">'."\n" ;
  1859. // " onchange=\"javascript:document.getElementById('toc_$parent').focus();\">\n";
  1860. require_once('resourcelinker.inc.php');
  1861. //temp variables
  1862. $mycurrentitemid = $this->get_current_item_id();
  1863. foreach($list as $item)
  1864. {
  1865. if($this->debug>2){error_log('New LP - learnpath::get_html_toc(): using item '.$item['id'],0);}
  1866. //TODO complete this
  1867. $icon_name = array('not attempted' => 'notattempted.png',
  1868. 'incomplete' => 'incomplete.png',
  1869. 'failed' => 'failed.png',
  1870. 'completed' => 'completed.png',
  1871. 'passed' => 'passed.png',
  1872. 'succeeded' => 'succeeded.png',
  1873. 'browsed' => 'completed.png');
  1874. $style = 'scorm_item';
  1875. if($item['id'] == $this->current){
  1876. $style = 'scorm_item_highlight';
  1877. }
  1878. //the anchor will let us center the TOC on the currently viewed item &^D
  1879. $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'].'" >' .
  1880. '<img id="toc_img_'.$item['id'].'" class="scorm_status_img" src="'.$icon_name[$item['status']].'" alt="'.substr($item['status'],0,1).'" />';
  1881. //$title = htmlspecialchars($item['title'],ENT_QUOTES,$this->encoding);
  1882. $title = $item['title'];
  1883. if(empty($title)){
  1884. $title = rl_get_resource_name(api_get_course_id(),$this->get_id(),$item['id']);
  1885. $title = htmlspecialchars($title,ENT_QUOTES,$this->encoding);
  1886. }
  1887. if(empty($title))$title = '-';
  1888. if($item['type']!='dokeos_chapter' and $item['type']!='dir'){
  1889. //$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>" ;
  1890. $url = $this->get_link('http',$item['id']);
  1891. //$html .= '<a href="'.$url.'" target="content_name" onclick="top.load_item('.$item['id'].',\''.$url.'\');">'.$title.'</a>' ;
  1892. //$html .= '<a href="" onclick="top.load_item('.$item['id'].',\''.$url.'\');return false;">'.$title.'</a>' ;
  1893. $html .= '<a href="" onclick="dokeos_xajax_handler.switch_item(' .
  1894. $mycurrentitemid.',' .
  1895. $item['id'].');' .
  1896. 'return false;" >'.$title.'</a>' ;
  1897. }else{
  1898. $html .= $title;
  1899. }
  1900. $html .= "</div>\n";
  1901. }
  1902. $html .= "</div>\n";
  1903. return $html;
  1904. }*/
  1905. /**
  1906. * Uses the table generated by get_toc() and returns an HTML-formatted string ready to display
  1907. * @return string HTML TOC ready to display
  1908. */
  1909. function get_html_toc()
  1910. {
  1911. if($this->debug>0){error_log('New LP - In learnpath::get_html_toc()',0);}
  1912. $list = $this->get_toc();
  1913. //echo $this->current;
  1914. //$parent = $this->items[$this->current]->get_parent();
  1915. //if(empty($parent)){$parent = $this->ordered_items[$this->items[$this->current]->get_previous_index()];}
  1916. $html .= '<div class="inner_lp_toc">'."\n" ;
  1917. if($_SESSION["is_courseAdmin"]==1){
  1918. $html.="<a href='lp_controller.php?cidReq=".$_SESSION['_cid']."&action=build&lp_id=".$this->lp_id."' style='font-size: 11px' target='_parent'>".mb_convert_encoding(get_lang("Build"),$this->encoding)."</a>&nbsp;<a style='font-size: 11px' href='lp_controller.php?cidReq=".$_SESSION['_cid']."&action=admin_view&lp_id=".$this->lp_id."' target='_parent'>".mb_convert_encoding(get_lang("BasicOverview"),$this->encoding)."</a>&nbsp;".mb_convert_encoding(get_lang("Display"),$this->encoding)."<br><br>";
  1919. }
  1920. // " onchange=\"javascript:document.getElementById('toc_$parent').focus();\">\n";
  1921. require_once('resourcelinker.inc.php');
  1922. //temp variables
  1923. $mycurrentitemid = $this->get_current_item_id();
  1924. foreach($list as $item)
  1925. {
  1926. if($this->debug>2){error_log('New LP - learnpath::get_html_toc(): using item '.$item['id'],0);}
  1927. //TODO complete this
  1928. $icon_name = array('not attempted' => 'notattempted.png',
  1929. 'incomplete' => 'incomplete.png',
  1930. 'failed' => 'failed.png',
  1931. 'completed' => 'completed.png',
  1932. 'passed' => 'passed.png',
  1933. 'succeeded' => 'succeeded.png',
  1934. 'browsed' => 'completed.png');
  1935. $style = 'scorm_item';
  1936. if($item['id'] == $this->current){
  1937. $style = 'scorm_item_highlight';
  1938. }
  1939. //the anchor will let us center the TOC on the currently viewed item &^D
  1940. if($item['type']!='dokeos_module' AND $item['type']!='dokeos_chapter'){
  1941. $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'].'" >' .
  1942. '';
  1943. }
  1944. else{
  1945. $html .= '<div class="'.$style.'" style="padding-left: '.($item['level']*2).'em; padding-right:'.($item['level']*1.5).'em" id="toc_'.$item['id'].'" >' .
  1946. '';
  1947. }
  1948. //$title = htmlspecialchars($item['title'],ENT_QUOTES,$this->encoding);
  1949. $title = $item['title'];
  1950. if(empty($title)){
  1951. $title = rl_get_resource_name(api_get_course_id(),$this->get_id(),$item['id']);
  1952. $title = htmlspecialchars($title,ENT_QUOTES,$this->encoding);
  1953. }
  1954. if(empty($title))$title = '-';
  1955. if($item['type']!='dokeos_chapter' and $item['type']!='dir' AND $item['type']!='dokeos_module'){
  1956. //$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>" ;
  1957. $url = $this->get_link('http',$item['id']);
  1958. //$html .= '<a href="'.$url.'" target="content_name" onclick="top.load_item('.$item['id'].',\''.$url.'\');">'.$title.'</a>' ;
  1959. //$html .= '<a href="" onclick="top.load_item('.$item['id'].',\''.$url.'\');return false;">'.$title.'</a>' ;
  1960. $html .= '<a href="" onclick="dokeos_xajax_handler.switch_item(' .
  1961. $mycurrentitemid.',' .
  1962. $item['id'].');' .
  1963. 'return false;" ><img align="absbottom" width="13" height="13" src="../img/lp_document.png">&nbsp;'.stripslashes($title).'</a>' ;
  1964. }
  1965. elseif($item['type']=='dokeos_module' || $item['type']=='dokeos_chapter'){
  1966. $html .= "<img align='absbottom' width='13' height='13' src='../img/lp_dokeos_module.png'>&nbsp;".stripslashes($title);
  1967. }
  1968. elseif($item['type']=='dir'){
  1969. $html .= stripslashes($title);
  1970. }
  1971. $html .= "<img id='toc_img_".$item['id']."' src='".$icon_name[$item['status']]."' alt='".substr($item['status'],0,1)."' /></div>\n";
  1972. }
  1973. $html .= "</div>\n";
  1974. return $html;
  1975. }
  1976. /**
  1977. * Gets the learnpath maker name - generally the editor's name
  1978. * @return string Learnpath maker name
  1979. */
  1980. function get_maker()
  1981. {
  1982. if($this->debug>0){error_log('New LP - In learnpath::get_maker()',0);}
  1983. if(!empty($this->maker)){return $this->maker;}else{return '';}
  1984. }
  1985. /**
  1986. * Gets the user-friendly message stored in $this->message
  1987. * @return string Message
  1988. */
  1989. function get_message(){
  1990. if($this->debug>0){error_log('New LP - In learnpath::get_message()',0);}
  1991. return $this->message;
  1992. }
  1993. /**
  1994. * Gets the learnpath name/title
  1995. * @return string Learnpath name/title
  1996. */
  1997. function get_name()
  1998. {
  1999. if($this->debug>0){error_log('New LP - In learnpath::get_name()',0);}
  2000. if(!empty($this->name)){return $this->name;}else{return 'N/A';}
  2001. }
  2002. /**
  2003. * Gets a link to the resource from the present location, depending on item ID.
  2004. * @param string Type of link expected
  2005. * @param integer Learnpath item ID
  2006. * @return string Link to the lp_item resource
  2007. */
  2008. function get_link($type='http',$item_id=null)
  2009. {
  2010. if($this->debug>0){error_log('New LP - In learnpath::get_link('.$type.','.$item_id.')',0);}
  2011. if(empty($item_id))
  2012. {
  2013. 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);}
  2014. $item_id = $this->get_current_item_id();
  2015. }
  2016. if(empty($item_id)){
  2017. if($this->debug>2){error_log('New LP - In learnpath::get_link() - no current item id found in learnpath object',0);}
  2018. //still empty, this means there was no item_id given and we are not in an object context or
  2019. //the object property is empty, return empty link
  2020. $item_id = $this->first();
  2021. return '';
  2022. }
  2023. $file = '';
  2024. $lp_db = Database::get_current_course_database();
  2025. $lp_pref = Database::get_course_table_prefix();
  2026. $lp_table = $lp_db.'.'.$lp_pref.'lp';
  2027. $lp_item_table = $lp_db.'.'.$lp_pref.'lp_item';
  2028. $sel = "SELECT l.lp_type as ltype, l.path as lpath, li.item_type as litype, li.path as lipath, li.parameters as liparams " .
  2029. "FROM $lp_table l, $lp_item_table li WHERE li.id = $item_id AND li.lp_id = l.id";
  2030. if($this->debug>2){error_log('New LP - In learnpath::get_link() - selecting item '.$sel,0);}
  2031. $res = api_sql_query($sel);
  2032. if(Database::num_rows($res)>0)
  2033. {
  2034. $row = Database::fetch_array($res);
  2035. //var_dump($row);
  2036. $lp_type = $row['ltype'];
  2037. $lp_path = $row['lpath'];
  2038. $lp_item_type = $row['litype'];
  2039. $lp_item_path = $row['lipath'];
  2040. $lp_item_params = $row['liparams'];
  2041. //add ? if none - left commented to give freedom to scorm implementation
  2042. //if(substr($lp_item_params,0,1)!='?'){
  2043. // $lp_item_params = '?'.$lp_item_params;
  2044. //}
  2045. $sys_course_path = api_get_path(SYS_COURSE_PATH).api_get_course_path();
  2046. if($type == 'http'){
  2047. $course_path = api_get_path(WEB_COURSE_PATH).api_get_course_path(); //web path
  2048. }else{
  2049. $course_path = $sys_course_path; //system path
  2050. }
  2051. //now go through the specific cases to get the end of the path
  2052. switch($lp_type){
  2053. case 1:
  2054. if($lp_item_type == 'dokeos_chapter'){
  2055. $file = 'lp_content.php?type=dir';
  2056. }else{
  2057. require_once('resourcelinker.inc.php');
  2058. $file = rl_get_resource_link_for_learnpath(api_get_course_id(),$this->get_id(),$item_id);
  2059. $tmp_array=explode("/",$file);
  2060. $document_name=$tmp_array[count($tmp_array)-1];
  2061. if(strpos($document_name,'_DELETED_')){
  2062. $file = 'blank.php?error=document_deleted';
  2063. }
  2064. }
  2065. break;
  2066. case 2:
  2067. if($this->debug>2){error_log('New LP - In learnpath::get_link() '.__LINE__.' - Item type: '.$lp_item_type,0);}
  2068. if($lp_item_type!='dir'){
  2069. //Quite complex here:
  2070. //we want to make sure 'http://' (and similar) links can
  2071. //be loaded as is (withouth the Dokeos path in front) but
  2072. //some contents use this form: resource.htm?resource=http://blablabla
  2073. //which means we have to find a protocol at the path's start, otherwise
  2074. //it should not be considered as an external URL
  2075. //if($this->prerequisites_match($item_id)){
  2076. if(preg_match('#^[a-zA-Z]{2,5}://#',$lp_item_path)!=0){
  2077. if($this->debug>2){error_log('New LP - In learnpath::get_link() '.__LINE__.' - Found match for protocol in '.$lp_item_path,0);}
  2078. //distant url, return as is
  2079. $file = $lp_item_path;
  2080. }else{
  2081. if($this->debug>2){error_log('New LP - In learnpath::get_link() '.__LINE__.' - No starting protocol in '.$lp_item_path,0);}
  2082. //prevent getting untranslatable urls
  2083. $lp_item_path = preg_replace('/%2F/','/',$lp_item_path);
  2084. $lp_item_path = preg_replace('/%3A/',':',$lp_item_path);
  2085. //prepare the path
  2086. $file = $course_path.'/scorm/'.$lp_path.'/'.$lp_item_path;
  2087. //TODO fix this for urls with protocol header
  2088. $file = str_replace('//','/',$file);
  2089. $file = str_replace(':/','://',$file);
  2090. if(!is_file($sys_course_path.'/scorm/'.$lp_path.'/'.$lp_item_path))
  2091. {//if file not found
  2092. $decoded = html_entity_decode($lp_item_path);
  2093. if(!is_file($sys_course_path.'/scorm/'.$lp_path.'/'.$decoded))
  2094. {
  2095. $file = 'blank.php';
  2096. }
  2097. else
  2098. {
  2099. $file = $course_path.'/scorm/'.$lp_path.'/'.$decoded;
  2100. }
  2101. }
  2102. }
  2103. //}else{
  2104. //prerequisites did not match
  2105. //$file = 'blank.php';
  2106. //}
  2107. //We want to use parameters if they were defined in the imsmanifest
  2108. if($file!='blank.php')
  2109. {
  2110. $file.= $lp_item_params;
  2111. }
  2112. }else{
  2113. $file = 'lp_content.php?type=dir';
  2114. }
  2115. break;
  2116. case 3:
  2117. if($this->debug>2){error_log('New LP - In learnpath::get_link() '.__LINE__.' - Item type: '.$lp_item_type,0);}
  2118. //formatting AICC HACP append URL
  2119. $aicc_append = '?aicc_sid='.urlencode(session_id()).'&aicc_url='.urlencode(api_get_path(WEB_CODE_PATH).'newscorm/aicc_hacp.php').'&';
  2120. if($lp_item_type!='dir'){
  2121. //Quite complex here:
  2122. //we want to make sure 'http://' (and similar) links can
  2123. //be loaded as is (withouth the Dokeos path in front) but
  2124. //some contents use this form: resource.htm?resource=http://blablabla
  2125. //which means we have to find a protocol at the path's start, otherwise
  2126. //it should not be considered as an external URL
  2127. if(preg_match('#^[a-zA-Z]{2,5}://#',$lp_item_path)!=0){
  2128. if($this->debug>2){error_log('New LP - In learnpath::get_link() '.__LINE__.' - Found match for protocol in '.$lp_item_path,0);}
  2129. //distant url, return as is
  2130. $file = $lp_item_path;
  2131. /*
  2132. if(stristr($file,'<servername>')!==false){
  2133. $file = str_replace('<servername>',$course_path.'/scorm/'.$lp_path.'/',$lp_item_path);
  2134. }
  2135. */
  2136. $file .= $aicc_append;
  2137. }else{
  2138. if($this->debug>2){error_log('New LP - In learnpath::get_link() '.__LINE__.' - No starting protocol in '.$lp_item_path,0);}
  2139. //prevent getting untranslatable urls
  2140. $lp_item_path = preg_replace('/%2F/','/',$lp_item_path);
  2141. $lp_item_path = preg_replace('/%3A/',':',$lp_item_path);
  2142. //prepare the path - lp_path might be unusable because it includes the "aicc" subdir name
  2143. $file = $course_path.'/scorm/'.$lp_path.'/'.$lp_item_path;
  2144. //TODO fix this for urls with protocol header
  2145. $file = str_replace('//','/',$file);
  2146. $file = str_replace(':/','://',$file);
  2147. $file .= $aicc_append;
  2148. }
  2149. }else{
  2150. $file = 'lp_content.php?type=dir';
  2151. }
  2152. break;
  2153. case 4:
  2154. break;
  2155. default:
  2156. break;
  2157. }
  2158. }
  2159. if($this->debug>2){error_log('New LP - In learnpath::get_link() - returning "'.$file.'" from get_link',0);}
  2160. return $file;
  2161. }
  2162. /**
  2163. * Gets the latest usable view or generate a new one
  2164. * @param integer Optional attempt number. If none given, takes the highest from the lp_view table
  2165. * @return integer DB lp_view id
  2166. */
  2167. function get_view($attempt_num=0)
  2168. {
  2169. if($this->debug>0){error_log('New LP - In learnpath::get_view()',0);}
  2170. $search = '';
  2171. //use $attempt_num to enable multi-views management (disabled so far)
  2172. if($attempt_num != 0 AND intval(strval($attempt_num)) == $attempt_num)
  2173. {
  2174. $search = 'AND view_count = '.$attempt_num;
  2175. }
  2176. //when missing $attempt_num, search for a unique lp_view record for this lp and user
  2177. $lp_view_table = Database::get_course_table('lp_view');
  2178. $sql = "SELECT id, view_count FROM $lp_view_table " .
  2179. "WHERE lp_id = ".$this->get_id()." " .
  2180. "AND user_id = ".$this->get_user_id()." " .
  2181. $search .
  2182. " ORDER BY view_count DESC";
  2183. $res = api_sql_query($sql);
  2184. if(Database::num_rows($res)>0)
  2185. {
  2186. $row = Database::fetch_array($res);
  2187. $this->lp_view_id = $row['id'];
  2188. }else{
  2189. //no database record, create one
  2190. $sql = "INSERT INTO $lp_view_table(lp_id,user_id,view_count)" .
  2191. "VALUES (".$this->get_id().",".$this->get_user_id().",1)";
  2192. $res = api_sql_query($sql);
  2193. $id = Database::get_last_insert_id();
  2194. $this->lp_view_id = $id;
  2195. }
  2196. }
  2197. /**
  2198. * Gets the current view id
  2199. * @return integer View ID (from lp_view)
  2200. */
  2201. function get_view_id()
  2202. {
  2203. if($this->debug>0){error_log('New LP - In learnpath::get_view_id()',0);}
  2204. if(!empty($this->lp_view_id))
  2205. {
  2206. return $this->lp_view_id;
  2207. }else{
  2208. return 0;
  2209. }
  2210. }
  2211. /**
  2212. * Gets the update queue
  2213. * @return array Array containing IDs of items to be updated by JavaScript
  2214. */
  2215. function get_update_queue()
  2216. {
  2217. if($this->debug>0){error_log('New LP - In learnpath::get_update_queue()',0);}
  2218. return $this->update_queue;
  2219. }
  2220. /**
  2221. * Gets the user ID
  2222. * @return integer User ID
  2223. */
  2224. function get_user_id()
  2225. {
  2226. if($this->debug>0){error_log('New LP - In learnpath::get_user_id()',0);}
  2227. if(!empty($this->user_id))
  2228. {
  2229. return $this->user_id;
  2230. }else{
  2231. return false;
  2232. }
  2233. }
  2234. /**
  2235. * Logs a message into a file
  2236. * @param string Message to log
  2237. * @return boolean True on success, false on error or if msg empty
  2238. */
  2239. function log($msg)
  2240. {
  2241. if($this->debug>0){error_log('New LP - In learnpath::log()',0);}
  2242. //TODO
  2243. $this->error .= $msg."\n";
  2244. return true;
  2245. }
  2246. /**
  2247. * Moves an item up and down at its level
  2248. * @param integer Item to move up and down
  2249. * @param string Direction 'up' or 'down'
  2250. * @return integer New display order, or false on error
  2251. */
  2252. function move_item($id, $direction){
  2253. if($this->debug>0){error_log('New LP - In learnpath::move_item('.$id.','.$direction.')',0);}
  2254. if(empty($id) or empty($direction)){return false;}
  2255. $tbl_lp_item = Database::get_course_table('lp_item');
  2256. $sql_sel = "
  2257. SELECT *
  2258. FROM " . $tbl_lp_item . "
  2259. WHERE id = " . $id;
  2260. $res_sel = api_sql_query($sql_sel,__FILE__,__LINE__);
  2261. //check if elem exists
  2262. if(Database::num_rows($res_sel)<1){return false;}
  2263. //gather data
  2264. $row = Database::fetch_array($res_sel);
  2265. $previous = $row['previous_item_id'];
  2266. $next = $row['next_item_id'];
  2267. $display = $row['display_order'];
  2268. $parent = $row['parent_item_id'];
  2269. $lp = $row['lp_id'];
  2270. //update the item (switch with previous/next one)
  2271. switch($direction)
  2272. {
  2273. case 'up':
  2274. if($this->debug>2){error_log('Movement up detected',0);}
  2275. if($display <= 1){/*do nothing*/}
  2276. else{
  2277. $sql_sel2 = "SELECT *
  2278. FROM $tbl_lp_item
  2279. WHERE id = $previous";
  2280. if($this->debug>2){error_log('Selecting previous: '.$sql_sel2,0);}
  2281. $res_sel2 = api_sql_query($sql_sel2,__FILE__,__LINE__);
  2282. if(Database::num_rows($res_sel2)<1){$previous_previous = 0;}
  2283. //gather data
  2284. $row2 = Database::fetch_array($res_sel2);
  2285. $previous_previous = $row2['previous_item_id'];
  2286. //update previous_previous item (switch "next" with current)
  2287. if($previous_previous != 0){
  2288. $sql_upd2 = "UPDATE $tbl_lp_item SET next_item_id = $id WHERE id = $previous_$previous";
  2289. if($this->debug>2){error_log($sql_upd2,0);}
  2290. $res_upd2 = api_sql_query($sql_upd2);
  2291. }
  2292. //update previous item (switch with current)
  2293. if($previous != 0){
  2294. $sql_upd2 = "UPDATE $tbl_lp_item SET next_item_id = $next, previous_item_id = $id, display_order = display_order +1 WHERE id = $previous";
  2295. if($this->debug>2){error_log($sql_upd2,0);}
  2296. $res_upd2 = api_sql_query($sql_upd2);
  2297. }
  2298. //update current item (switch with previous)
  2299. if($id != 0){
  2300. $sql_upd2 = "UPDATE $tbl_lp_item SET next_item_id = $previous, previous_item_id = $previous_previous, display_order = display_order-1 WHERE id = $id";
  2301. if($this->debug>2){error_log($sql_upd2,0);}
  2302. $res_upd2 = api_sql_query($sql_upd2);
  2303. }
  2304. //update next item (new previous item)
  2305. if($next != 0){
  2306. $sql_upd2 = "UPDATE $tbl_lp_item SET previous_item_id = $previous WHERE id = $next";
  2307. if($this->debug>2){error_log($sql_upd2,0);}
  2308. $res_upd2 = api_sql_query($sql_upd2);
  2309. }
  2310. $display = $display-1;
  2311. }
  2312. break;
  2313. case 'down':
  2314. if($this->debug>2){error_log('Movement down detected',0);}
  2315. if($next == 0){/*do nothing*/}
  2316. else{
  2317. $sql_sel2 = "SELECT * FROM $tbl_lp_item WHERE id = $next";
  2318. if($this->debug>2){error_log('Selecting next: '.$sql_sel2,0);}
  2319. $res_sel2 = api_sql_query($sql_sel2,__FILE__,__LINE__);
  2320. if(Database::num_rows($res_sel2)<1){$next_next = 0;}
  2321. //gather data
  2322. $row2 = Database::fetch_array($res_sel2);
  2323. $next_next = $row2['next_item_id'];
  2324. //update previous item (switch with current)
  2325. if($previous != 0){
  2326. $sql_upd2 = "UPDATE $tbl_lp_item SET next_item_id = $next WHERE id = $previous";
  2327. $res_upd2 = api_sql_query($sql_upd2);
  2328. }
  2329. //update current item (switch with previous)
  2330. if($id != 0){
  2331. $sql_upd2 = "UPDATE $tbl_lp_item SET previous_item_id = $next, next_item_id = $next_next, display_order = display_order+1 WHERE id = $id";
  2332. $res_upd2 = api_sql_query($sql_upd2);
  2333. }
  2334. //update next item (new previous item)
  2335. if($next != 0){
  2336. $sql_upd2 = "UPDATE $tbl_lp_item SET previous_item_id = $previous, next_item_id = $id, display_order = display_order-1 WHERE id = $next";
  2337. $res_upd2 = api_sql_query($sql_upd2);
  2338. }
  2339. //update next_next item (switch "previous" with current)
  2340. if($next_next != 0){
  2341. $sql_upd2 = "UPDATE $tbl_lp_item SET previous_item_id = $id WHERE id = $next_next";
  2342. $res_upd2 = api_sql_query($sql_upd2);
  2343. }
  2344. $display = $display+1;
  2345. }
  2346. break;
  2347. default:
  2348. return false;
  2349. }
  2350. return $display;
  2351. }
  2352. /**
  2353. * Updates learnpath attributes to point to the next element
  2354. * The last part is similar to set_current_item but processing the other way around
  2355. */
  2356. function next(){
  2357. if($this->debug>0){error_log('New LP - In learnpath::next()',0);}
  2358. $this->last = $this->get_current_item_id();
  2359. $this->items[$this->last]->save(false);
  2360. $this->autocomplete_parents($this->last);
  2361. $new_index = $this->get_next_index();
  2362. if($this->debug>2){error_log('New LP - New index: '.$new_index,0);}
  2363. $this->index = $new_index;
  2364. if($this->debug>2){error_log('New LP - Now having orderedlist['.$new_index.'] = '. $this->ordered_items[$new_index],0);}
  2365. $this->current = $this->ordered_items[$new_index];
  2366. if($this->debug>2){error_log('New LP - new item id is '.$this->current.'-'.$this->get_current_item_id(),0);}
  2367. }
  2368. /**
  2369. * Open a resource = initialise all local variables relative to this resource. Depending on the child
  2370. * class, this might be redefined to allow several behaviours depending on the document type.
  2371. * @param integer Resource ID
  2372. * @return boolean True on success, false otherwise
  2373. */
  2374. function open($id)
  2375. {
  2376. if($this->debug>0){error_log('New LP - In learnpath::open()',0);}
  2377. //TODO
  2378. //set the current resource attribute to this resource
  2379. //switch on element type (redefine in child class?)
  2380. //set status for this item to "opened"
  2381. //start timer
  2382. //initialise score
  2383. $this->index = 0; //or = the last item seen (see $this->last)
  2384. }
  2385. /**
  2386. * Check that all prerequisites are fulfilled. Returns true and an empty string on succes, returns false
  2387. * and the prerequisite string on error.
  2388. * This function is based on the rules for aicc_script language as described in the SCORM 1.2 CAM documentation page 108.
  2389. * @param integer Optional item ID. If none given, uses the current open item.
  2390. * @return boolean True if prerequisites are matched, false otherwise
  2391. * @return string Empty string if true returned, prerequisites string otherwise.
  2392. */
  2393. function prerequisites_match($item = null){
  2394. if($this->debug>0){error_log('New LP - In learnpath::prerequisites_match()',0);}
  2395. if(empty($item)){$item = $this->current;}
  2396. if(is_object($this->items[$item])){
  2397. $prereq_string = $this->items[$item]->get_prereq_string();
  2398. if(empty($prereq_string)){return true;}
  2399. //clean spaces
  2400. $prereq_string = str_replace(' ','',$prereq_string);
  2401. if($this->debug>0){error_log('Found prereq_string: '.$prereq_string,0);}
  2402. //now send to the parse_prereq() function that will check this component's prerequisites
  2403. $result = $this->items[$item]->parse_prereq($prereq_string,$this);
  2404. if($result === false){
  2405. $this->set_error_msg($this->items[$item]->prereq_alert);
  2406. }
  2407. }else{
  2408. $result = true;
  2409. if($this->debug>1){error_log('New LP - $this->items['.$item.'] was not an object',0);}
  2410. }
  2411. if($this->debug>1){error_log('New LP - End of prerequisites_match(). Error message is now '.$this->error,0);}
  2412. return $result;
  2413. }
  2414. /**
  2415. * Updates learnpath attributes to point to the previous element
  2416. * The last part is similar to set_current_item but processing the other way around
  2417. */
  2418. function previous(){
  2419. if($this->debug>0){error_log('New LP - In learnpath::previous()',0);}
  2420. $this->last = $this->get_current_item_id();
  2421. $this->items[$this->last]->save(false);
  2422. $this->autocomplete_parents($this->last);
  2423. $new_index = $this->get_previous_index();
  2424. $this->index = $new_index;
  2425. $this->current = $this->ordered_items[$new_index];
  2426. }
  2427. /**
  2428. * Publishes a learnpath. This basically means show or hide the learnpath
  2429. * to normal users.
  2430. * Can be used as abstract
  2431. * @param integer Learnpath ID
  2432. * @param string New visibility
  2433. */
  2434. function toggle_visibility($lp_id,$set_visibility='v')
  2435. {
  2436. //if($this->debug>0){error_log('New LP - In learnpath::toggle_visibility()',0);}
  2437. $tbl_lp = Database::get_course_table('lp');
  2438. $sql="SELECT * FROM $tbl_lp where id=$lp_id";
  2439. $result=api_sql_query($sql,__FILE__,__LINE__);
  2440. $row=Database::fetch_array($result);
  2441. $name=domesticate($row['name']);
  2442. if($set_visibility == 'i') {
  2443. $s=$name." ".get_lang('_no_published');
  2444. $dialogBox=$s;
  2445. $v=0;
  2446. }
  2447. if($set_visibility == 'v') {
  2448. $s=$name." ".get_lang('_published');
  2449. $dialogBox=$s;
  2450. $v=1;
  2451. }
  2452. $tbl_tool = Database::get_course_table(TABLE_TOOL_LIST);
  2453. $link = 'newscorm/lp_controller.php?action=view&lp_id='.$lp_id;
  2454. $sql="SELECT * FROM $tbl_tool where name='$name' and image='scormbuilder.gif' and link LIKE '$link%'";
  2455. $result=api_sql_query($sql,__FILE__,__LINE__);
  2456. $num=Database::num_rows($result);
  2457. $row2=Database::fetch_array($result);
  2458. //if($this->debug>2){error_log('New LP - '.$sql.' - '.$num,0);}
  2459. if(($set_visibility == 'i') && ($num>0))
  2460. {
  2461. //it is visible or hidden but once was published
  2462. if(($row2['visibility'])==1)
  2463. {
  2464. $sql ="DELETE FROM $tbl_tool WHERE (name='$name' and image='scormbuilder.gif' and link LIKE '$link%')";
  2465. }
  2466. else
  2467. {
  2468. $sql ="UPDATE $tbl_tool set visibility=1 WHERE (name='$name' and image='scormbuilder.gif' and link LIKE '$link%')";
  2469. }
  2470. }
  2471. elseif(($set_visibility == 'v') && ($num==0))
  2472. {
  2473. $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)";
  2474. }
  2475. else
  2476. {
  2477. //parameter and database incompatible, do nothing
  2478. }
  2479. $result=api_sql_query($sql,__FILE__,__LINE__);
  2480. //if($this->debug>2){error_log('New LP - Leaving learnpath::toggle_visibility: '.$sql,0);}
  2481. }
  2482. /**
  2483. * Restart the whole learnpath. Return the URL of the first element.
  2484. * Make sure the results are saved with anoter method. This method should probably be
  2485. * redefined in children classes.
  2486. * @return string URL to load in the viewer
  2487. */
  2488. function restart()
  2489. {
  2490. if($this->debug>0){error_log('New LP - In learnpath::restart()',0);}
  2491. //TODO
  2492. //call autosave method to save the current progress
  2493. //$this->index = 0;
  2494. $lp_view_table = Database::get_course_table('lp_view');
  2495. $sql = "INSERT INTO $lp_view_table (lp_id, user_id, view_count) " .
  2496. "VALUES (".$this->lp_id.",".$this->get_user_id().",".($this->attempt+1).")";
  2497. if($this->debug>2){error_log('New LP - Inserting new lp_view for restart: '.$sql,0);}
  2498. $res = api_sql_query($sql);
  2499. if($view_id = Database::get_last_insert_id($res))
  2500. {
  2501. $this->lp_view_id = $view_id;
  2502. $this->attempt = $this->attempt+1;
  2503. }else{
  2504. $this->error = 'Could not insert into item_view table...';
  2505. return false;
  2506. }
  2507. $this->autocomplete_parents($this->current);
  2508. foreach($this->items as $index=>$dummy){
  2509. $this->items[$index]->restart();
  2510. $this->items[$index]->set_lp_view($this->lp_view_id);
  2511. }
  2512. $this->first();
  2513. return true;
  2514. }
  2515. /**
  2516. * Saves the current item
  2517. * @return boolean
  2518. */
  2519. function save_current(){
  2520. if($this->debug>0){error_log('New LP - In learnpath::save_current()',0);}
  2521. //TODO do a better check on the index pointing to the right item (it is supposed to be working
  2522. // on $ordered_items[] but not sure it's always safe to use with $items[])
  2523. if($this->debug>2){error_log('New LP - save_current() saving item '.$this->current,0);}
  2524. if($this->debug>2){error_log(''.print_r($this->items,true),0);}
  2525. if(is_object($this->items[$this->current])){
  2526. $res = $this->items[$this->current]->save(false);
  2527. $this->autocomplete_parents($this->current);
  2528. $status = $this->items[$this->current]->get_status();
  2529. $this->append_message('new_item_status: '.$status);
  2530. $this->update_queue[$this->current] = $status;
  2531. return $res;
  2532. }
  2533. return false;
  2534. }
  2535. /**
  2536. * Saves the given item
  2537. * @param integer Item ID. Optional (will take from $_REQUEST if null)
  2538. * @param boolean Save from url params (true) or from current attributes (false). Optional. Defaults to true
  2539. * @return boolean
  2540. */
  2541. function save_item($item_id=null,$from_outside=true){
  2542. if($this->debug>0){error_log('New LP - In learnpath::save_item('.$item_id.','.$from_outside.')',0);}
  2543. //TODO do a better check on the index pointing to the right item (it is supposed to be working
  2544. // on $ordered_items[] but not sure it's always safe to use with $items[])
  2545. if(empty($item_id)){
  2546. $item_id = $this->escape_string($_REQUEST['id']);
  2547. }
  2548. if(empty($item_id))
  2549. {
  2550. $item_id = $this->get_current_item_id();
  2551. }
  2552. if($this->debug>2){error_log('New LP - save_current() saving item '.$item_id,0);}
  2553. if(is_object($this->items[$item_id])){
  2554. $res = $this->items[$item_id]->save($from_outside);
  2555. $this->autocomplete_parents($item_id);
  2556. $status = $this->items[$item_id]->get_status();
  2557. $this->append_message('new_item_status: '.$status);
  2558. $this->update_queue[$item_id] = $status;
  2559. return $res;
  2560. }
  2561. return false;
  2562. }
  2563. /**
  2564. * Saves the last item seen's ID only in case
  2565. */
  2566. function save_last(){
  2567. if($this->debug>0){error_log('New LP - In learnpath::save_last()',0);}
  2568. $table = Database::get_course_table('lp_view');
  2569. if(isset($this->current)){
  2570. if($this->debug>2){error_log('New LP - Saving current item ('.$this->current.') for later review',0);}
  2571. $sql = "UPDATE $table SET last_item = ".$this->get_current_item_id()." " .
  2572. "WHERE lp_id = ".$this->get_id()." AND user_id = ".$this->get_user_id();
  2573. if($this->debug>2){error_log('New LP - Saving last item seen : '.$sql,0);}
  2574. $res = api_sql_query($sql,__FILE__,__LINE__);
  2575. }
  2576. //save progress
  2577. list($progress,$text) = $this->get_progress_bar_text('%');
  2578. if($progress>=0 AND $progress<=100){
  2579. $progress= (int)$progress;
  2580. $sql = "UPDATE $table SET progress = $progress " .
  2581. "WHERE lp_id = ".$this->get_id()." AND " .
  2582. "user_id = ".$this->get_user_id();
  2583. $res = @mysql_query($sql); //ignore errors as some tables might not have the progress field just yet
  2584. $this->progress_db = $progress;
  2585. }
  2586. }
  2587. /**
  2588. * Sets the current item ID (checks if valid and authorized first)
  2589. * @param integer New item ID. If not given or not authorized, defaults to current
  2590. */
  2591. function set_current_item($item_id=null)
  2592. {
  2593. if($this->debug>0){error_log('New LP - In learnpath::set_current_item('.$item_id.')',0);}
  2594. if(empty($item_id)){
  2595. if($this->debug>2){error_log('New LP - No new current item given, ignore...',0);}
  2596. //do nothing
  2597. }else{
  2598. if($this->debug>2){error_log('New LP - New current item given is '.$item_id.'...',0);}
  2599. $item_id = $this->escape_string($item_id);
  2600. //TODO check in database here
  2601. $this->last = $this->current;
  2602. $this->current = $item_id;
  2603. //TODO update $this->index as well
  2604. foreach($this->ordered_items as $index => $item)
  2605. {
  2606. if($item == $this->current)
  2607. {
  2608. $this->index = $index;
  2609. break;
  2610. }
  2611. }
  2612. if($this->debug>2){error_log('New LP - set_current_item('.$item_id.') done. Index is now : '.$this->index,0);}
  2613. }
  2614. }
  2615. /**
  2616. * Sets the encoding
  2617. * @param string New encoding
  2618. */
  2619. function set_encoding($enc='ISO-8859-1'){
  2620. if($this->debug>0){error_log('New LP - In learnpath::set_encoding()',0);}
  2621. $enc = strtoupper($enc);
  2622. $encodings = array('UTF-8','ISO-8859-1','ISO-8859-15','SHIFT-JIS');
  2623. if(in_array($enc,$encodings)){
  2624. $lp = $this->get_id();
  2625. if($lp!=0){
  2626. $tbl_lp = Database::get_course_table('lp');
  2627. $sql = "UPDATE $tbl_lp SET default_encoding = '$enc' WHERE id = ".$lp;
  2628. $res = api_sql_query($sql);
  2629. return $res;
  2630. }
  2631. }
  2632. return false;
  2633. }
  2634. /**
  2635. * Sets the JS lib setting in the database directly.
  2636. * This is the JavaScript library file this lp needs to load on startup
  2637. * @param string Proximity setting
  2638. */
  2639. function set_jslib($lib=''){
  2640. if($this->debug>0){error_log('New LP - In learnpath::set_jslib()',0);}
  2641. $lp = $this->get_id();
  2642. if($lp!=0){
  2643. $tbl_lp = Database::get_course_table('lp');
  2644. $sql = "UPDATE $tbl_lp SET js_lib = '$lib' WHERE id = ".$lp;
  2645. $res = api_sql_query($sql);
  2646. return $res;
  2647. }else{
  2648. return false;
  2649. }
  2650. }
  2651. /**
  2652. * Sets the name of the LP maker (publisher) (and save)
  2653. * @param string Optional string giving the new content_maker of this learnpath
  2654. */
  2655. function set_maker($name=''){
  2656. if($this->debug>0){error_log('New LP - In learnpath::set_maker()',0);}
  2657. if(empty($name))return false;
  2658. $this->maker = $this->escape_string($name);
  2659. $lp_table = Database::get_course_table('lp');
  2660. $lp_id = $this->get_id();
  2661. $sql = "UPDATE $lp_table SET content_maker = '".$this->maker."' WHERE id = '$lp_id'";
  2662. if($this->debug>2){error_log('New LP - lp updated with new content_maker : '.$this->maker,0);}
  2663. //$res = Database::query($sql);
  2664. $res = api_sql_query($sql);
  2665. return true;
  2666. }
  2667. /**
  2668. * Sets the name of the current learnpath (and save)
  2669. * @param string Optional string giving the new name of this learnpath
  2670. */
  2671. function set_name($name=''){
  2672. if($this->debug>0){error_log('New LP - In learnpath::set_name()',0);}
  2673. if(empty($name))return false;
  2674. $this->name = $this->escape_string($name);
  2675. $lp_table = Database::get_course_table('lp');
  2676. $lp_id = $this->get_id();
  2677. $sql = "UPDATE $lp_table SET name = '".$this->name."' WHERE id = '$lp_id'";
  2678. if($this->debug>2){error_log('New LP - lp updated with new name : '.$this->name,0);}
  2679. //$res = Database::query($sql);
  2680. $res = api_sql_query($sql);
  2681. return true;
  2682. }
  2683. /**
  2684. * Sets the location/proximity of the LP (local/remote) (and save)
  2685. * @param string Optional string giving the new location of this learnpath
  2686. */
  2687. function set_proximity($name=''){
  2688. if($this->debug>0){error_log('New LP - In learnpath::set_proximity()',0);}
  2689. if(empty($name))return false;
  2690. $this->proximity = $this->escape_string($name);
  2691. $lp_table = Database::get_course_table('lp');
  2692. $lp_id = $this->get_id();
  2693. $sql = "UPDATE $lp_table SET content_local = '".$this->proximity."' WHERE id = '$lp_id'";
  2694. if($this->debug>2){error_log('New LP - lp updated with new proximity : '.$this->proximity,0);}
  2695. //$res = Database::query($sql);
  2696. $res = api_sql_query($sql);
  2697. return true;
  2698. }
  2699. /**
  2700. * Sets the previous item ID to a given ID. Generally, this should be set to the previous 'current' item
  2701. * @param integer DB ID of the item
  2702. */
  2703. function set_previous_item($id)
  2704. {
  2705. if($this->debug>0){error_log('New LP - In learnpath::set_previous_item()',0);}
  2706. $this->last = $id;
  2707. }
  2708. /**
  2709. * Sets the object's error message
  2710. * @param string Error message. If empty, reinits the error string
  2711. * @return void
  2712. */
  2713. function set_error_msg($error='')
  2714. {
  2715. if($this->debug>0){error_log('New LP - In learnpath::set_error_msg()',0);}
  2716. if(empty($error)){
  2717. $this->error = '';
  2718. }else{
  2719. $this->error .= $error;
  2720. }
  2721. }
  2722. /**
  2723. * Launches the current item if not 'sco' (starts timer and make sure there is a record ready in the DB)
  2724. *
  2725. */
  2726. function start_current_item(){
  2727. if($this->debug>0){error_log('New LP - In learnpath::start_current_item()',0);}
  2728. if($this->current != 0 AND
  2729. is_object($this->items[$this->current]))
  2730. {
  2731. $type = $this->get_type();
  2732. if(
  2733. ($type == 2 && $this->items[$this->current]->get_type()!='sco')
  2734. OR
  2735. ($type == 3 && $this->items[$this->current]->get_type()!='au')
  2736. OR
  2737. ($type==1)
  2738. )
  2739. {
  2740. $this->items[$this->current]->open();
  2741. $this->autocomplete_parents($this->current);
  2742. $prereq_check = $this->prerequisites_match($this->current);
  2743. if($prereq_check === true) //launch the prerequisites check and set error if needed
  2744. {
  2745. $this->items[$this->current]->save(false);
  2746. }
  2747. //$this->update_queue[$this->last] = $this->items[$this->last]->get_status();
  2748. }else{
  2749. //if sco, then it is supposed to have been updated by some other call
  2750. }
  2751. }
  2752. return true;
  2753. }
  2754. /**
  2755. * Stops the processing and counters for the old item (as held in $this->last)
  2756. * @param
  2757. */
  2758. function stop_previous_item(){
  2759. if($this->debug>0){error_log('New LP - In learnpath::stop_previous_item()',0);}
  2760. if($this->last != 0 AND $this->last!=$this->current AND is_object($this->items[$this->last]))
  2761. {
  2762. if($this->debug>2){error_log('New LP - In learnpath::stop_previous_item() - '.$this->last.' is object',0);}
  2763. switch($this->get_type()){
  2764. case '3':
  2765. if($this->items[$this->last]->get_type()!='au')
  2766. {
  2767. if($this->debug>2){error_log('New LP - In learnpath::stop_previous_item() - '.$this->last.' in lp_type 3 is <> au',0);}
  2768. $this->items[$this->last]->close();
  2769. //$this->autocomplete_parents($this->last);
  2770. //$this->update_queue[$this->last] = $this->items[$this->last]->get_status();
  2771. }else{
  2772. if($this->debug>2){error_log('New LP - In learnpath::stop_previous_item() - Item is an AU, saving is managed by AICC signals',0);}
  2773. }
  2774. case '2':
  2775. if($this->items[$this->last]->get_type()!='sco')
  2776. {
  2777. if($this->debug>2){error_log('New LP - In learnpath::stop_previous_item() - '.$this->last.' in lp_type 2 is <> sco',0);}
  2778. $this->items[$this->last]->close();
  2779. //$this->autocomplete_parents($this->last);
  2780. //$this->update_queue[$this->last] = $this->items[$this->last]->get_status();
  2781. }else{
  2782. if($this->debug>2){error_log('New LP - In learnpath::stop_previous_item() - Item is a SCO, saving is managed by SCO signals',0);}
  2783. }
  2784. break;
  2785. case '1':
  2786. default:
  2787. if($this->debug>2){error_log('New LP - In learnpath::stop_previous_item() - '.$this->last.' in lp_type 1 is asset',0);}
  2788. $this->items[$this->last]->close();
  2789. break;
  2790. }
  2791. }else{
  2792. if($this->debug>2){error_log('New LP - In learnpath::stop_previous_item() - No previous element found, ignoring...',0);}
  2793. return false;
  2794. }
  2795. return true;
  2796. }
  2797. /**
  2798. * Updates the default view mode from fullscreen to embedded and inversely
  2799. * @return string The current default view mode ('fullscreen' or 'embedded')
  2800. */
  2801. function update_default_view_mode()
  2802. {
  2803. if($this->debug>0){error_log('New LP - In learnpath::update_default_view_mode()',0);}
  2804. $lp_table = Database::get_course_table('lp');
  2805. $sql = "SELECT * FROM $lp_table WHERE id = ".$this->get_id();
  2806. $res = api_sql_query($sql);
  2807. if(Database::num_rows($res)>0){
  2808. $row = Database::fetch_array($res);
  2809. $view_mode = $row['default_view_mod'];
  2810. if($view_mode == 'fullscreen'){
  2811. $view_mode = 'embedded';
  2812. }elseif($view_mode == 'embedded'){
  2813. $view_mode = 'fullscreen';
  2814. }
  2815. $sql = "UPDATE $lp_table SET default_view_mod = '$view_mode' WHERE id = ".$this->get_id();
  2816. $res = api_sql_query($sql);
  2817. $this->mode = $view_mode;
  2818. return $view_mode;
  2819. }else{
  2820. if($this->debug>2){error_log('New LP - Problem in update_default_view() - could not find LP '.$this->get_id().' in DB',0);}
  2821. }
  2822. return -1;
  2823. }
  2824. /**
  2825. * Updates the default behaviour about auto-commiting SCORM updates
  2826. * @return boolean True if auto-commit has been set to 'on', false otherwise
  2827. */
  2828. function update_default_scorm_commit(){
  2829. if($this->debug>0){error_log('New LP - In learnpath::update_default_scorm_commit()',0);}
  2830. $lp_table = Database::get_course_table('lp');
  2831. $sql = "SELECT * FROM $lp_table WHERE id = ".$this->get_id();
  2832. $res = api_sql_query($sql);
  2833. if(Database::num_rows($res)>0){
  2834. $row = Database::fetch_array($res);
  2835. $force = $row['force_commit'];
  2836. if($force == 1){
  2837. $force = 0;
  2838. $force_return = false;
  2839. }elseif($force == 0){
  2840. $force = 1;
  2841. $force_return = true;
  2842. }
  2843. $sql = "UPDATE $lp_table SET force_commit = $force WHERE id = ".$this->get_id();
  2844. $res = api_sql_query($sql);
  2845. $this->force_commit = $force_return;
  2846. return $force_return;
  2847. }else{
  2848. if($this->debug>2){error_log('New LP - Problem in update_default_scorm_commit() - could not find LP '.$this->get_id().' in DB',0);}
  2849. }
  2850. return -1;
  2851. }
  2852. /**
  2853. * Updates the "prevent_reinit" value that enables control on reinitialising items on second view
  2854. * @return boolean True if prevent_reinit has been set to 'on', false otherwise (or 1 or 0 in this case)
  2855. */
  2856. function update_reinit(){
  2857. if($this->debug>0){error_log('New LP - In learnpath::update_reinit()',0);}
  2858. $lp_table = Database::get_course_table('lp');
  2859. $sql = "SELECT * FROM $lp_table WHERE id = ".$this->get_id();
  2860. $res = api_sql_query($sql);
  2861. if(Database::num_rows($res)>0){
  2862. $row = Database::fetch_array($res);
  2863. $force = $row['prevent_reinit'];
  2864. if($force == 1){
  2865. $force = 0;
  2866. }elseif($force == 0){
  2867. $force = 1;
  2868. }
  2869. $sql = "UPDATE $lp_table SET prevent_reinit = $force WHERE id = ".$this->get_id();
  2870. $res = api_sql_query($sql,__FILE__,__LINE__);
  2871. $this->prevent_reinit = $force;
  2872. return $force;
  2873. }else{
  2874. if($this->debug>2){error_log('New LP - Problem in update_reinit() - could not find LP '.$this->get_id().' in DB',0);}
  2875. }
  2876. return -1;
  2877. }
  2878. /**
  2879. * Updates the "scorm_debug" value that shows or hide the debug window
  2880. * @return boolean True if scorm_debug has been set to 'on', false otherwise (or 1 or 0 in this case)
  2881. */
  2882. function update_scorm_debug(){
  2883. if($this->debug>0){error_log('New LP - In learnpath::update_scorm_debug()',0);}
  2884. $lp_table = Database::get_course_table('lp');
  2885. $sql = "SELECT * FROM $lp_table WHERE id = ".$this->get_id();
  2886. $res = api_sql_query($sql);
  2887. if(Database::num_rows($res)>0){
  2888. $row = Database::fetch_array($res);
  2889. $force = $row['debug'];
  2890. if($force == 1){
  2891. $force = 0;
  2892. }elseif($force == 0){
  2893. $force = 1;
  2894. }
  2895. $sql = "UPDATE $lp_table SET debug = $force WHERE id = ".$this->get_id();
  2896. $res = api_sql_query($sql,__FILE__,__LINE__);
  2897. $this->scorm_debug = $force;
  2898. return $force;
  2899. }else{
  2900. if($this->debug>2){error_log('New LP - Problem in update_scorm_debug() - could not find LP '.$this->get_id().' in DB',0);}
  2901. }
  2902. return -1;
  2903. }
  2904. /**
  2905. * Function that makes a call to the function sort_tree_array and create_tree_array
  2906. *
  2907. * @author Kevin Van Den Haute
  2908. *
  2909. * @param unknown_type $array
  2910. */
  2911. function tree_array($array)
  2912. {
  2913. $array = $this->sort_tree_array($array);
  2914. $this->create_tree_array($array);
  2915. }
  2916. /**
  2917. * Creates an array with the elements of the learning path tree in it
  2918. *
  2919. * @author Kevin Van Den Haute
  2920. *
  2921. * @param array $array
  2922. * @param int $parent
  2923. * @param int $depth
  2924. * @param array $tmp
  2925. */
  2926. function create_tree_array($array, $parent = 0, $depth = -1, $tmp = array())
  2927. {
  2928. if(is_array($array))
  2929. {
  2930. for($i = 0; $i < count($array); $i++)
  2931. {
  2932. if($array[$i]['parent_item_id'] == $parent)
  2933. {
  2934. if(!in_array($array[$i]['parent_item_id'], $tmp))
  2935. {
  2936. $tmp[] = $array[$i]['parent_item_id'];
  2937. $depth++;
  2938. }
  2939. $this->arrMenu[] = array(
  2940. 'id' => $array[$i]['id'],
  2941. 'item_type' => $array[$i]['item_type'],
  2942. 'title' => $array[$i]['title'],
  2943. 'path' => $array[$i]['path'],
  2944. 'description' => $array[$i]['description'],
  2945. 'parent_item_id' => $array[$i]['parent_item_id'],
  2946. 'previous_item_id' => $array[$i]['previous_item_id'],
  2947. 'next_item_id' => $array[$i]['next_item_id'],
  2948. 'display_order' => $array[$i]['display_order'],
  2949. 'prerequisite' => $array[$i]['prerequisite'],
  2950. 'depth' => $depth
  2951. );
  2952. $this->create_tree_array($array, $array[$i]['id'], $depth, $tmp);
  2953. }
  2954. }
  2955. }
  2956. }
  2957. /**
  2958. * Sorts a multi dimensional array by parent id and display order
  2959. * @author Kevin Van Den Haute
  2960. *
  2961. * @param array $array (array with al the learning path items in it)
  2962. *
  2963. * @return array
  2964. */
  2965. function sort_tree_array($array)
  2966. {
  2967. foreach($array as $key => $row)
  2968. {
  2969. $parent[$key] = $row['parent_item_id'];
  2970. $position[$key] = $row['display_order'];
  2971. }
  2972. if(count($array) > 0)
  2973. array_multisort($parent, SORT_ASC, $position, SORT_ASC, $array);
  2974. return $array;
  2975. }
  2976. /**
  2977. * Function that creates a table structure with a learning path his modules, chapters and documents.
  2978. * Also the actions for the modules, chapters and documents are in this table.
  2979. *
  2980. * @author Kevin Van Den Haute
  2981. *
  2982. * @param int $lp_id
  2983. *
  2984. * @return string
  2985. */
  2986. function overview()
  2987. {
  2988. $return = '';
  2989. $tbl_lp_item = Database::get_course_table('lp_item');
  2990. $sql = "
  2991. SELECT *
  2992. FROM " . $tbl_lp_item . "
  2993. WHERE
  2994. lp_id = " . $this->lp_id;
  2995. $result = api_sql_query($sql, __FILE__, __LINE__);
  2996. $arrLP = array();
  2997. while($row = Database::fetch_array($result))
  2998. {
  2999. $arrLP[] = array(
  3000. 'id' => $row['id'],
  3001. 'item_type' => $row['item_type'],
  3002. 'title' => $row['title'],
  3003. 'description' => $row['description'],
  3004. 'parent_item_id' => $row['parent_item_id'],
  3005. 'previous_item_id' => $row['previous_item_id'],
  3006. 'next_item_id' => $row['next_item_id'],
  3007. 'display_order' => $row['display_order']);
  3008. }
  3009. $this->tree_array($arrLP);
  3010. $arrLP = $this->arrMenu;
  3011. unset($this->arrMenu);
  3012. if(api_is_allowed_to_edit())
  3013. $return .= '<p><a href="' . $_SERVER['PHP_SELF'] . '?cidReq=' . $_GET['cidReq'] . '&amp;action=build&amp;lp_id=' . $this->lp_id . '">'.get_lang("Advanced").'</a>&nbsp;'.get_lang("BasicOverview").'&nbsp;<a href="lp_controller.php?cidReq='.$_GET['cidReq'].'&action=view&lp_id='.$this->lp_id.'">'.get_lang("Display").'</a></p>';
  3014. $return .= '<table class="data_table">' . "\n";
  3015. $return .= "\t" . '<tr>' . "\n";
  3016. $return .= "\t" . '<th width="75%">'.get_lang("Title").'</th>' . "\n";
  3017. //$return .= "\t" . '<th>'.get_lang("Description").'</th>' . "\n";
  3018. $return .= "\t" . '<th>'.get_lang("Move").'</th>' . "\n";
  3019. $return .= "\t" . '<th>'.get_lang("Actions").'</th>' . "\n";
  3020. $return .= "\t" . '</tr>' . "\n";
  3021. for($i = 0; $i < count($arrLP); $i++)
  3022. {
  3023. if($arrLP[$i]['description'] == '')
  3024. $arrLP[$i]['description'] = '&nbsp;';
  3025. if (($i % 2)==0) { $oddclass="row_odd"; } else { $oddclass="row_even"; }
  3026. $return .= "\t" . '<tr class="'.$oddclass.'">' . "\n";
  3027. $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";
  3028. //$return .= "\t\t" . '<td>' . stripslashes($arrLP[$i]['description']) . '</td>' . "\n";
  3029. if(api_is_allowed_to_edit())
  3030. {
  3031. $return .= "\t\t" . '<td>' . "\n";
  3032. if($arrLP[$i]['previous_item_id'] != 0)
  3033. {
  3034. $return .= "\t\t\t" . '<a href="' . $_SERVER['PHP_SELF'] . '?cidReq=' . $_GET['cidReq'] . '&amp;action=move_item&amp;direction=up&amp;id=' . $arrLP[$i]['id'] . '&amp;lp_id=' . $this->lp_id . '">';
  3035. $return .= '<img alt="" src="../img/arrow_up_' . ($arrLP[$i]['depth'] % 3) . '.gif" />';
  3036. $return .= '</a>' . "\n";
  3037. }
  3038. else
  3039. $return .= "\t\t\t" . '<img alt="" src="../img/blanco.png" title="" />' . "\n";
  3040. if($arrLP[$i]['next_item_id'] != 0)
  3041. {
  3042. $return .= "\t\t\t" . '<a href="' . $_SERVER['PHP_SELF'] . '?cidReq=' . $_GET['cidReq'] . '&amp;action=move_item&amp;direction=down&amp;id=' . $arrLP[$i]['id'] . '&amp;lp_id=' . $this->lp_id . '">';
  3043. $return .= '<img src="../img/arrow_down_' . ($arrLP[$i]['depth'] % 3) . '.gif" />';
  3044. $return .= '</a>' . "\n";
  3045. }
  3046. else
  3047. $return .= "\t\t\t" . '<img alt="" src="../img/blanco.png" title="" />' . "\n";
  3048. $return .= "\t\t" . '</td>' . "\n";
  3049. $return .= "\t\t" . '<td>' . "\n";
  3050. if($arrLP[$i]['item_type'] != 'dokeos_chapter' && $arrLP[$i]['item_type'] != 'dokeos_module')
  3051. {
  3052. $return .= "\t\t\t" . '<a href="' . $_SERVER['PHP_SELF'] . '?cidReq=' . $_GET['cidReq'] . '&amp;action=edit_item&amp;view=build&amp;id=' . $arrLP[$i]['id'] . '&amp;lp_id=' . $this->lp_id . '">';
  3053. $return .= '<img alt="" src="../img/edit.gif" title="' . get_lang('_edit_learnpath_module') . '" />';
  3054. $return .= '</a>' . "\n";
  3055. }
  3056. else
  3057. {
  3058. $return .= "\t\t\t" . '<a href="' . $_SERVER['PHP_SELF'] . '?cidReq=' . $_GET['cidReq'] . '&amp;action=edit_item&amp;id=' . $arrLP[$i]['id'] . '&amp;lp_id=' . $this->lp_id . '">';
  3059. $return .= '<img alt="" src="../img/edit.gif" title="' . get_lang('_edit_learnpath_module') . '" />';
  3060. $return .= '</a>' . "\n";
  3061. }
  3062. $return .= "\t\t\t" . '<a href="' . $_SERVER['PHP_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'] . '\');">';
  3063. $return .= '<img alt="" src="../img/delete.gif" title="' . get_lang('_delete_learnpath_module') . '" />';
  3064. $return .= '</a>' . "\n";
  3065. $return .= "\t\t" . '</td>' . "\n";
  3066. }
  3067. $return .= "\t" . '</tr>' . "\n";
  3068. }
  3069. if(count($arrLP) == 0)
  3070. {
  3071. $return .= "\t" . '<tr>' . "\n";
  3072. $return .= "\t\t" . '<td colspan="4">'.get_lang("NoItemsInLp").'</td>' . "\n";
  3073. $return .= "\t" . '</tr>' . "\n";
  3074. }
  3075. $return .= '</table>' . "\n";
  3076. return $return;
  3077. }
  3078. /**
  3079. * This functions builds the LP tree based on data from the database.
  3080. *
  3081. * @return string
  3082. * @uses dtree.js :: necessary javascript for building this tree
  3083. */
  3084. function build_tree()
  3085. {
  3086. $return = "<script type=\"text/javascript\">\n";
  3087. $return .= "\tm = new dTree('m');\n\n";
  3088. $return .= "\tm.config.folderLinks = true;\n";
  3089. $return .= "\tm.config.useCookies = true;\n";
  3090. $return .= "\tm.config.useIcons = true;\n";
  3091. $return .= "\tm.config.useLines = true;\n";
  3092. $return .= "\tm.config.useSelection = true;\n";
  3093. $return .= "\tm.config.useStatustext = false;\n\n";
  3094. $menu = 0;
  3095. $parent = '';
  3096. $return .= "\tm.add(" . $menu . ", -1, '" . addslashes($this->name) . "');\n";
  3097. $tbl_lp_item = Database::get_course_table('lp_item');
  3098. $sql = "
  3099. SELECT *
  3100. FROM " . $tbl_lp_item . "
  3101. WHERE
  3102. lp_id = " . $this->lp_id;
  3103. $result = api_sql_query($sql, __FILE__, __LINE__);
  3104. $arrLP = array();
  3105. while($row = Database::fetch_array($result))
  3106. {
  3107. $arrLP[] = array(
  3108. 'id' => $row['id'],
  3109. 'item_type' => $row['item_type'],
  3110. 'title' => $row['title'],
  3111. 'path' => $row['path'],
  3112. 'description' => $row['description'],
  3113. 'parent_item_id' => $row['parent_item_id'],
  3114. 'previous_item_id' => $row['previous_item_id'],
  3115. 'next_item_id' => $row['next_item_id'],
  3116. 'display_order' => $row['display_order']);
  3117. }
  3118. $this->tree_array($arrLP);
  3119. $arrLP = $this->arrMenu;
  3120. unset($this->arrMenu);
  3121. for($i = 0; $i < count($arrLP); $i++)
  3122. {
  3123. $menu_page = $_SERVER['PHP_SELF'] . '?cidReq=' . $_GET['cidReq'] . '&amp;action=view_item&amp;id=' . $arrLP[$i]['id'] . '&amp;lp_id=' . $_SESSION['oLP']->lp_id;
  3124. if(file_exists("../img/lp_" . $arrLP[$i]['item_type'] . ".png"))
  3125. {
  3126. $return .= "\tm.add(" . $arrLP[$i]['id'] . ", " . $arrLP[$i]['parent_item_id'] . ", '" . $arrLP[$i]['title'] . "', '" . $menu_page . "', '', '', '../img/lp_" . $arrLP[$i]['item_type'] . ".png', '../img/lp_" . $arrLP[$i]['item_type'] . ".png');\n";
  3127. }
  3128. else if(file_exists("../img/lp_" . $arrLP[$i]['item_type'] . ".gif"))
  3129. {
  3130. $return .= "\tm.add(" . $arrLP[$i]['id'] . ", " . $arrLP[$i]['parent_item_id'] . ", '" . $arrLP[$i]['title'] . "', '" . $menu_page . "', '', '', '../img/lp_" . $arrLP[$i]['item_type'] . ".gif', '../img/lp_" . $arrLP[$i]['item_type'] . ".gif');\n";
  3131. }
  3132. else
  3133. {
  3134. $return .= "\tm.add(" . $arrLP[$i]['id'] . ", " . $arrLP[$i]['parent_item_id'] . ", '" . $arrLP[$i]['title'] . "', '" . $menu_page . "', '', '', '../img/lp_document.png', '../img/lp_document.png');\n";
  3135. }
  3136. if($menu < $arrLP[$i]['id'])
  3137. $menu = $arrLP[$i]['id'];
  3138. }
  3139. $return .= "\n\tdocument.write(m);\n";
  3140. $return .= "\t if(!m.selectedNode) m.s(1);";
  3141. $return .= "</script>\n";
  3142. return $return;
  3143. }
  3144. /**
  3145. * Create a new document //still needs some finetuning
  3146. *
  3147. * @param array $_course
  3148. * @return string
  3149. */
  3150. function create_document($_course)
  3151. {
  3152. $dir = isset($_GET['dir']) ? $_GET['dir'] : $_POST['dir']; // please do not modify this dirname formatting
  3153. if(strstr($dir, '..'))
  3154. $dir = '/';
  3155. if($dir[0] == '.')
  3156. $dir = substr($dir, 1);
  3157. if($dir[0] != '/')
  3158. $dir = '/'.$dir;
  3159. if($dir[strlen($dir) - 1] != '/')
  3160. $dir .= '/';
  3161. $filepath = api_get_path('SYS_COURSE_PATH') . $_course['path'] . '/document' . $dir;
  3162. if(!is_dir($filepath))
  3163. {
  3164. $filepath = api_get_path('SYS_COURSE_PATH') . $_course['path'] . '/document/';
  3165. $dir = '/';
  3166. }
  3167. $title = replace_dangerous_char($_POST['title']);
  3168. $filename = $title;
  3169. $content = $_POST['content_lp'];
  3170. $tmp_filename = $filename;
  3171. while(file_exists($filepath . $tmp_filename . '.html'))
  3172. $tmp_filename = $filename . '_' . ++$i;
  3173. $filename = $tmp_filename . '.html';
  3174. $content = stripslashes(text_filter($content));
  3175. $path_to_remove = api_get_path('WEB_COURSE_PATH') . $_course['path'] . '/document' . $dir;
  3176. $content = str_replace($path_to_remove, './', $content);
  3177. if(!file_exists($filepath . $filename))
  3178. {
  3179. if($fp = @fopen($filepath . $filename, 'w'))
  3180. {
  3181. fputs($fp, $content);
  3182. fclose($fp);
  3183. $file_size = filesize($filepath . $filename);
  3184. $save_file_path = $dir . $filename;
  3185. $document_id = add_document($_course, $save_file_path, 'file', $file_size, $filename . '.html');
  3186. if($document_id)
  3187. {
  3188. api_item_property_update($_course, TOOL_DOCUMENT, $document_id, 'DocumentAdded', $_user['user_id'], $to_group_id);
  3189. //update parent folders
  3190. //item_property_update_on_folder($_course, $_GET['dir'], $_user['user_id']);
  3191. $new_comment = (isset($_POST['comment'])) ? trim($_POST['comment']) : '';
  3192. $new_title = (isset($_POST['title'])) ? trim($_POST['title']) : '';
  3193. if($new_comment || $new_title)
  3194. {
  3195. $tbl_doc = Database::get_course_table(TABLE_DOCUMENT);
  3196. $ct = '';
  3197. if($new_comment)
  3198. $ct .= ", comment='" . $new_comment . "'";
  3199. if($new_title)
  3200. $ct .= ", title='" . $new_title . ".html '";
  3201. $sql_update = "
  3202. UPDATE " . $tbl_doc . "
  3203. SET " . substr($ct, 1) . "
  3204. WHERE id = " . $document_id;
  3205. api_sql_query($sql_update, __FILE__, __LINE__);
  3206. }
  3207. }
  3208. return $document_id;
  3209. }
  3210. }
  3211. }
  3212. /**
  3213. * Enter description here...
  3214. *
  3215. * @param array $_course
  3216. */
  3217. function edit_document($_course)
  3218. {
  3219. global $_configuration;
  3220. $dir = isset($_GET['dir']) ? $_GET['dir'] : $_POST['dir']; // please do not modify this dirname formatting
  3221. if(strstr($dir, '..'))
  3222. $dir = '/';
  3223. if($dir[0] == '.')
  3224. $dir = substr($dir, 1);
  3225. if($dir[0] != '/')
  3226. $dir = '/'.$dir;
  3227. if($dir[strlen($dir) - 1] != '/')
  3228. $dir .= '/';
  3229. $filepath = api_get_path('SYS_COURSE_PATH') . $_course['path'] . '/document'.$dir;
  3230. if(!is_dir($filepath))
  3231. {
  3232. $filepath = api_get_path('SYS_COURSE_PATH') . $_course['path'] . '/document/';
  3233. $dir = '/';
  3234. }
  3235. $table_doc = Database::get_course_table(TABLE_DOCUMENT);
  3236. $sql = "
  3237. SELECT path
  3238. FROM " . $table_doc . "
  3239. WHERE id = " . $_POST['path'];
  3240. $res = api_sql_query($sql, __FILE__, __LINE__);
  3241. $row = Database::fetch_array($res);
  3242. $content = stripslashes($_POST['content_lp']);
  3243. $file = $filepath . $row['path'];
  3244. if($fp = @fopen($file, 'w'))
  3245. {
  3246. $content = text_filter($content);
  3247. $content = str_replace(api_get_path('WEB_COURSE_PATH'), $_configuration['url_append'].'/courses/', $content);
  3248. fputs($fp, $content);
  3249. fclose($fp);
  3250. }
  3251. }
  3252. /**
  3253. * Displays the selected item, with a panel for manipulating the item
  3254. *
  3255. * @param int $item_id
  3256. * @param string $msg
  3257. * @return string
  3258. */
  3259. function display_item($item_id, $iframe = true, $msg = '')
  3260. {
  3261. global $_course; //will disappear
  3262. $return = '';
  3263. if(is_numeric($item_id))
  3264. {
  3265. $tbl_lp_item = Database::get_course_table('lp_item');
  3266. $tbl_doc = Database::get_course_table(TABLE_DOCUMENT);
  3267. $sql = "
  3268. SELECT
  3269. lp.*
  3270. FROM " . $tbl_lp_item . " as lp
  3271. WHERE
  3272. lp.id = " . $item_id;
  3273. $result = api_sql_query($sql, __FILE__, __LINE__);
  3274. while($row = Database::fetch_array($result))
  3275. {
  3276. $return .= $this->display_manipulate($item_id, $row['item_type']);
  3277. $return .= '<div style="padding:10px;">';
  3278. if($msg != '')
  3279. $return .= $msg;
  3280. $return .= '<p class="lp_title">' . stripslashes($row['title']) . '</p>';
  3281. //$return .= '<p class="lp_text">' . ((trim($row['description']) == '') ? 'no description' : stripslashes($row['description'])) . '</p>';
  3282. //$return .= '<hr />';
  3283. if($row['item_type'] == TOOL_DOCUMENT)
  3284. {
  3285. $tbl_doc = Database :: get_course_table(TABLE_DOCUMENT);
  3286. $sql_doc = "SELECT path FROM " . $tbl_doc . " WHERE id = " . $row['path'];
  3287. $result=api_sql_query($sql_doc);
  3288. $path_file=mysql_result($result,0,0);
  3289. $path_parts = pathinfo($path_file);
  3290. if(in_array($path_parts['extension'],array('html','txt','png', 'jpg', 'JPG', 'jpeg', 'JPEG', 'gif', 'swf')))
  3291. {
  3292. $return .= $this->display_document($row['path'], true, true);
  3293. }
  3294. }
  3295. $return .= '</div>';
  3296. }
  3297. }
  3298. return $return;
  3299. }
  3300. /**
  3301. * Shows the needed forms for editing a specific item
  3302. *
  3303. * @param int $item_id
  3304. * @return string
  3305. */
  3306. function display_edit_item($item_id)
  3307. {
  3308. global $_course; //will disappear
  3309. $return = '';
  3310. if(is_numeric($item_id))
  3311. {
  3312. $tbl_lp_item = Database::get_course_table('lp_item');
  3313. $sql = "
  3314. SELECT *
  3315. FROM " . $tbl_lp_item . "
  3316. WHERE id = " . $item_id;
  3317. $res = api_sql_query($sql, __FILE__, __LINE__);
  3318. $row = Database::fetch_array($res);
  3319. switch($row['item_type'])
  3320. {
  3321. case 'dokeos_chapter':
  3322. if(isset($_GET['view']) && $_GET['view'] == 'build')
  3323. {
  3324. $return .= $this->display_manipulate($item_id, $row['item_type']);
  3325. $return .= $this->display_item_form($row['item_type'], get_lang("EditCurrentChapter").' :', 'edit', $item_id, $row);
  3326. }
  3327. else
  3328. {
  3329. $return .= $this->display_item_small_form($row['item_type'], get_lang("EditCurrentChapter").' :', $row);
  3330. }
  3331. break;
  3332. case TOOL_DOCUMENT:
  3333. $tbl_doc = Database::get_course_table(TABLE_DOCUMENT);
  3334. $sql_step = "
  3335. SELECT
  3336. lp.*,
  3337. doc.path as dir
  3338. FROM " . $tbl_lp_item . " as lp
  3339. LEFT JOIN " . $tbl_doc . " as doc ON doc.id = lp.path
  3340. WHERE
  3341. lp.id = " . $item_id;
  3342. $res_step = api_sql_query($sql_step, __FILE__, __LINE__);
  3343. $row_step = Database::fetch_array($res_step);
  3344. $return .= $this->display_manipulate($item_id, $row['item_type']);
  3345. $return .= $this->display_document_form('edit', $item_id, $row_step);
  3346. break;
  3347. case TOOL_LINK:
  3348. $return .= $this->display_manipulate($item_id, $row['item_type']);
  3349. $return .= $this->display_link_form('edit', $item_id, $row);
  3350. break;
  3351. case 'dokeos_module':
  3352. if(isset($_GET['view']) && $_GET['view'] == 'build')
  3353. {
  3354. $return .= $this->display_manipulate($item_id, $row['item_type']);
  3355. $return .= $this->display_item_form($row['item_type'], get_lang("EditCurrentModule").' :', 'edit', $item_id, $row);
  3356. }
  3357. else
  3358. {
  3359. $return .= $this->display_item_small_form($row['item_type'], get_lang("EditCurrentModule").' :', $row);
  3360. }
  3361. break;
  3362. case TOOL_QUIZ:
  3363. $return .= $this->display_manipulate($item_id, $row['item_type']);
  3364. $return .= $this->display_quiz_form('edit', $item_id, $row);
  3365. break;
  3366. case TOOL_STUDENTPUBLICATION:
  3367. $return .= $this->display_manipulate($item_id, $row['item_type']);
  3368. $return .= $this->display_student_publication_form('edit', $item_id, $row);
  3369. break;
  3370. case TOOL_FORUM:
  3371. $return .= $this->display_manipulate($item_id, $row['item_type']);
  3372. $return .= $this->display_forum_form('edit', $item_id, $row);
  3373. break;
  3374. case TOOL_THREAD:
  3375. $return .= $this->display_manipulate($item_id, $row['item_type']);
  3376. $return .= $this->display_thread_form('edit', $item_id, $row);
  3377. break;
  3378. }
  3379. }
  3380. return $return;
  3381. }
  3382. /**
  3383. * Function that displays a list with al the resources that could be added to the learning path
  3384. *
  3385. * @return string
  3386. */
  3387. function display_resources()
  3388. {
  3389. global $_course; //TODO: don't use globals
  3390. $return = '<div style="margin:3px 10px;">' . "\n";
  3391. $return .= '<p class="lp_title" style="margin-top:0;">'.get_lang("CreateNewStep").'</p>';
  3392. $return .= '<div><a href="' . $_SERVER['PHP_SELF'] . '?cidReq=' . $_GET['cidReq'] . '&amp;action=add_item&amp;type=' . TOOL_DOCUMENT . '&amp;lp_id=' . $_SESSION['oLP']->lp_id . '">'.get_lang("NewDocument").'</a></div>';
  3393. $return .= '<p class="lp_title" style="margin-top:10px;">'.get_lang("UseAnExistingResource").'</p>';
  3394. /* get all the docs */
  3395. $return .= $this->get_documents();
  3396. /* get all the exercises */
  3397. $return .= $this->get_exercises();
  3398. /* get all the links */
  3399. $return .= $this->get_links();
  3400. /* get al the student publications */
  3401. $return .= $this->get_student_publications();
  3402. /* get al the forums */
  3403. $return .= $this->get_forums();
  3404. $return .= '</div>' . "\n";
  3405. return $return;
  3406. }
  3407. /**
  3408. * Returns the extension of a document
  3409. *
  3410. * @param unknown_type $filename
  3411. * @return unknown
  3412. */
  3413. function get_extension($filename)
  3414. {
  3415. $explode = explode('.', $filename);
  3416. return $explode[count($explode) - 1];
  3417. }
  3418. /**
  3419. * Displays a document by id
  3420. *
  3421. * @param unknown_type $id
  3422. * @return unknown
  3423. */
  3424. function display_document($id, $show_title = false, $iframe = true, $edit_link = false)
  3425. {
  3426. global $_course; //temporary
  3427. $return = '';
  3428. $tbl_doc = Database::get_course_table(TABLE_DOCUMENT);
  3429. $sql_doc = "
  3430. SELECT *
  3431. FROM " . $tbl_doc . "
  3432. WHERE id = " . $id;
  3433. $res_doc = api_sql_query($sql_doc, __FILE__, __LINE__);
  3434. $row_doc = Database::fetch_array($res_doc);
  3435. //if($show_title)
  3436. //$return .= '<p class="lp_title">' . $row_doc['title'] . ($edit_link ? ' [ <a href="' . $_SERVER['PHP_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>';
  3437. //TODO: add a path filter
  3438. if($iframe){
  3439. $return .= '<iframe frameborder="0" src="' . api_get_path(WEB_COURSE_PATH) . $_course['path'] . '/document' . $row_doc['path'] . '" style="background:#FFFFFF; border:1px solid #CCCCCC; height:490px; width:100%; margin-top: 20px;"></iframe>';
  3440. }
  3441. else{
  3442. $return .= file_get_contents(api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document' . $row_doc['path']);
  3443. }
  3444. return $return;
  3445. }
  3446. /**
  3447. * Enter description here...
  3448. *
  3449. * @param unknown_type $action
  3450. * @param unknown_type $id
  3451. * @param unknown_type $extra_info
  3452. * @return unknown
  3453. */
  3454. function display_quiz_form($action = 'add', $id = 0, $extra_info = '')
  3455. {
  3456. $tbl_lp_item = Database::get_course_table('lp_item');
  3457. $tbl_quiz = Database::get_course_table(TABLE_QUIZ_TEST);
  3458. if($id != 0 && is_array($extra_info))
  3459. {
  3460. $item_title = stripslashes($extra_info['title']);
  3461. $item_description = stripslashes($extra_info['description']);
  3462. }
  3463. elseif(is_numeric($extra_info))
  3464. {
  3465. $sql_quiz = "
  3466. SELECT
  3467. title,
  3468. description
  3469. FROM " . $tbl_quiz . "
  3470. WHERE id = " . $extra_info;
  3471. $result = api_sql_query($sql_quiz, __FILE__, __LINE__);
  3472. $row = Database::fetch_array($result);
  3473. $item_title = $row['title'];
  3474. $item_description = $row['description'];
  3475. }
  3476. else
  3477. {
  3478. $item_title = '';
  3479. $item_description = '';
  3480. }
  3481. $return = '<div style="margin:3px 10px;">';
  3482. if($id != 0 && is_array($extra_info))
  3483. $parent = $extra_info['parent_item_id'];
  3484. else
  3485. $parent = 0;
  3486. $sql = "
  3487. SELECT *
  3488. FROM " . $tbl_lp_item . "
  3489. WHERE
  3490. lp_id = " . $this->lp_id;
  3491. $result = api_sql_query($sql, __FILE__, __LINE__);
  3492. $arrLP = array();
  3493. while($row = Database::fetch_array($result))
  3494. {
  3495. $arrLP[] = array(
  3496. 'id' => $row['id'],
  3497. 'item_type' => $row['item_type'],
  3498. 'title' => $row['title'],
  3499. 'path' => $row['path'],
  3500. 'description' => $row['description'],
  3501. 'parent_item_id' => $row['parent_item_id'],
  3502. 'previous_item_id' => $row['previous_item_id'],
  3503. 'next_item_id' => $row['next_item_id'],
  3504. 'display_order' => $row['display_order'],
  3505. 'prerequisite' => $row['prerequisite']);
  3506. }
  3507. $this->tree_array($arrLP);
  3508. $arrLP = $this->arrMenu;
  3509. unset($this->arrMenu);
  3510. if($action == 'add')
  3511. $return .= '<p class="lp_title">'.get_lang("CreateTheExercise").' :</p>' . "\n";
  3512. elseif($action == 'move')
  3513. $return .= '<p class="lp_title">'.get_lang("MoveTheCurrentExercise").' :</p>' . "\n";
  3514. else
  3515. $return .= '<p class="lp_title">'.get_lang("EditCurrentExecice").' :</p>' . "\n";
  3516. if(isset($_GET['edit']) && $_GET['edit'] == 'true')
  3517. {
  3518. $return .= '<div class="lp_message" style="margin-bottom:15px;">';
  3519. $return .= '<p class="lp_title">'.get_lang("Warning").' !</p>';
  3520. $return .= get_lang("WarningEditingDocument");
  3521. $return .= '</div>';
  3522. }
  3523. $return .= '<form method="POST">' . "\n";
  3524. $return .= "\t" . '<table cellpadding="0" cellspacing="0" class="lp_form">' . "\n";
  3525. $return .= "\t\t" . '<tr>' . "\n";
  3526. $return .= "\t\t\t" . '<td class="label"><label for="idParent">'.get_lang("Parent").' :</label></td>' . "\n";
  3527. $return .= "\t\t\t" . '<td class="input">' . "\n";
  3528. $return .= "\t\t\t\t" . '<select id="idParent" name="parent" onchange="load_cbo(this.value);" size="1">';
  3529. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
  3530. $arrHide = array($id);
  3531. for($i = 0; $i < count($arrLP); $i++)
  3532. {
  3533. if($action != 'add')
  3534. {
  3535. if(($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter') && !in_array($arrLP[$i]['id'], $arrHide) && !in_array($arrLP[$i]['parent_item_id'], $arrHide))
  3536. {
  3537. $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>';
  3538. }
  3539. else
  3540. {
  3541. $arrHide[] = $arrLP[$i]['id'];
  3542. }
  3543. }
  3544. else
  3545. {
  3546. if($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter')
  3547. $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>';
  3548. }
  3549. }
  3550. reset($arrLP);
  3551. $return .= "\t\t\t\t" . '</select>';
  3552. $return .= "\t\t\t" . '</td>' . "\n";
  3553. $return .= "\t\t" . '</tr>' . "\n";
  3554. $return .= "\t\t" . '<tr>' . "\n";
  3555. $return .= "\t\t\t" . '<td class="label"><label for="idPosition">'.get_lang("Position").' :</label></td>' . "\n";
  3556. $return .= "\t\t\t" . '<td class="input">' . "\n";
  3557. $return .= "\t\t\t\t" . '<select id="idPosition" name="previous" size="1">';
  3558. $return .= "\t\t\t\t\t" . '<option class="top" value="0">First position</option>';
  3559. for($i = 0; $i < count($arrLP); $i++)
  3560. {
  3561. if($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id)
  3562. {
  3563. if($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  3564. $selected = 'selected="selected" ';
  3565. elseif($action == 'add')
  3566. $selected = 'selected="selected" ';
  3567. else
  3568. $selected = '';
  3569. $return .= "\t\t\t\t\t" . '<option ' . $selected . 'value="' . $arrLP[$i]['id'] . '">'.get_lang("After").' "' . html_entity_decode(stripslashes($arrLP[$i]['title'])) . '"</option>';
  3570. }
  3571. }
  3572. $return .= "\t\t\t\t" . '</select>';
  3573. $return .= "\t\t\t" . '</td>' . "\n";
  3574. $return .= "\t\t" . '</tr>' . "\n";
  3575. if($action != 'move')
  3576. {
  3577. $return .= "\t\t" . '<tr>' . "\n";
  3578. $return .= "\t\t\t" . '<td class="label"><label for="idTitle">'.get_lang("Title").' :</label></td>' . "\n";
  3579. $return .= "\t\t\t" . '<td class="input"><input id="idTitle" name="title" type="text" value="' . $item_title . '" /></td>' . "\n";
  3580. $return .= "\t\t" . '</tr>' . "\n";
  3581. $id_prerequisite=0;
  3582. foreach($arrLP as $key=>$value){
  3583. if($value['id']==$id){
  3584. $id_prerequisite=$value['prerequisite'];
  3585. break;
  3586. }
  3587. }
  3588. $arrHide=array();
  3589. for($i = 0; $i < count($arrLP); $i++)
  3590. {
  3591. if($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter')
  3592. {
  3593. if($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  3594. $s_selected_position=$arrLP[$i]['id'];
  3595. elseif($action == 'add')
  3596. $s_selected_position=0;
  3597. $arrHide[$arrLP[$i]['id']]['value']=html_entity_decode(stripslashes($arrLP[$i]['title']));
  3598. }
  3599. }
  3600. $return .= "\t\t" . '<tr>' . "\n";
  3601. $return .= "\t\t\t" . '<td class="label"><label for="idPrerequisites">'.get_lang("Prerequisites").' :</label></td>' . "\n";
  3602. $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>';
  3603. foreach($arrHide as $key => $value){
  3604. if($key==$s_selected_position && $action == 'add'){
  3605. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  3606. }
  3607. elseif($key==$id_prerequisite && $action == 'edit'){
  3608. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  3609. }
  3610. else{
  3611. $return .= '<option value="'.$key.'">'.$value['value'].'</option>';
  3612. }
  3613. }
  3614. $return .= "</select></td>";
  3615. $return .= "\t\t" . '</tr>' . "\n";
  3616. $return .= "\t\t" . '<tr>' . "\n";
  3617. //Remove temporaly the test description
  3618. //$return .= "\t\t\t" . '<td class="label"><label for="idDescription">'.get_lang("Description").' :</label></td>' . "\n";
  3619. //$return .= "\t\t\t" . '<td class="input"><textarea id="idDescription" name="description" rows="4">' . $item_description . '</textarea></td>' . "\n";
  3620. $return .= "\t\t" . '</tr>' . "\n";
  3621. }
  3622. $return .= "\t\t" . '<tr>' . "\n";
  3623. $return .= "\t\t\t" . '<td colspan="2"><input class="button" name="submit_button" type="submit" value="OK" /></td>' . "\n";
  3624. $return .= "\t\t" . '</tr>' . "\n";
  3625. $return .= "\t" . '</table>' . "\n";
  3626. if($action == 'move')
  3627. {
  3628. $return .= "\t" . '<input name="title" type="hidden" value="' . $item_title . '" />' . "\n";
  3629. $return .= "\t" . '<input name="description" type="hidden" value="' . $item_description . '" />' . "\n";
  3630. }
  3631. if(is_numeric($extra_info))
  3632. {
  3633. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info . '" />' . "\n";
  3634. }
  3635. elseif(is_array($extra_info))
  3636. {
  3637. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />' . "\n";
  3638. }
  3639. $return .= "\t" . '<input name="type" type="hidden" value="'.TOOL_QUIZ.'" />' . "\n";
  3640. $return .= "\t" . '<input name="post_time" type="hidden" value="' . time() . '" />' . "\n";
  3641. $return .= '</form>' . "\n";
  3642. $return .= '</div>' . "\n";
  3643. return $return;
  3644. }
  3645. /**
  3646. * Enter description here...
  3647. *
  3648. * @param unknown_type $action
  3649. * @param unknown_type $id
  3650. * @param unknown_type $extra_info
  3651. * @return unknown
  3652. */
  3653. function display_forum_form($action = 'add', $id = 0, $extra_info = '')
  3654. {
  3655. $tbl_lp_item = Database::get_course_table('lp_item');
  3656. $tbl_forum = Database::get_course_table(TABLE_FORUM);
  3657. if($id != 0 && is_array($extra_info))
  3658. {
  3659. $item_title = stripslashes($extra_info['title']);
  3660. }
  3661. elseif(is_numeric($extra_info))
  3662. {
  3663. $sql_forum = "
  3664. SELECT
  3665. forum_title as title
  3666. FROM " . $tbl_forum . "
  3667. WHERE forum_id = " . $extra_info;
  3668. $result = api_sql_query($sql_forum, __FILE__, __LINE__);
  3669. $row = Database::fetch_array($result);
  3670. $item_title = $row['title'];
  3671. }
  3672. else
  3673. {
  3674. $item_title = '';
  3675. }
  3676. $return = '<div style="margin:3px 10px;">';
  3677. if($id != 0 && is_array($extra_info))
  3678. $parent = $extra_info['parent_item_id'];
  3679. else
  3680. $parent = 0;
  3681. $sql = "
  3682. SELECT *
  3683. FROM " . $tbl_lp_item . "
  3684. WHERE
  3685. lp_id = " . $this->lp_id;
  3686. $result = api_sql_query($sql, __FILE__, __LINE__);
  3687. $arrLP = array();
  3688. while($row = Database::fetch_array($result))
  3689. {
  3690. $arrLP[] = array(
  3691. 'id' => $row['id'],
  3692. 'item_type' => $row['item_type'],
  3693. 'title' => $row['title'],
  3694. 'path' => $row['path'],
  3695. 'description' => $row['description'],
  3696. 'parent_item_id' => $row['parent_item_id'],
  3697. 'previous_item_id' => $row['previous_item_id'],
  3698. 'next_item_id' => $row['next_item_id'],
  3699. 'display_order' => $row['display_order'],
  3700. 'prerequisite' => $row['prerequisite']);
  3701. }
  3702. $this->tree_array($arrLP);
  3703. $arrLP = $this->arrMenu;
  3704. unset($this->arrMenu);
  3705. if($action == 'add')
  3706. $return .= '<p class="lp_title">'.get_lang("CreateTheForum").' :</p>' . "\n";
  3707. elseif($action == 'move')
  3708. $return .= '<p class="lp_title">'.get_lang("MoveTheCurrentForum").' :</p>' . "\n";
  3709. else
  3710. $return .= '<p class="lp_title">'.get_lang("EditCurrentForum").' :</p>' . "\n";
  3711. $return .= '<form method="POST">' . "\n";
  3712. $return .= "\t" . '<table cellpadding="0" cellspacing="0" class="lp_form">' . "\n";
  3713. $return .= "\t\t" . '<tr>' . "\n";
  3714. $return .= "\t\t\t" . '<td class="label"><label for="idParent">'.get_lang("Parent").' :</label></td>' . "\n";
  3715. $return .= "\t\t\t" . '<td class="input">' . "\n";
  3716. $return .= "\t\t\t\t" . '<select id="idParent" name="parent" onchange="load_cbo(this.value);" size="1">';
  3717. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
  3718. $arrHide = array($id);
  3719. for($i = 0; $i < count($arrLP); $i++)
  3720. {
  3721. if($action != 'add')
  3722. {
  3723. if(($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter') && !in_array($arrLP[$i]['id'], $arrHide) && !in_array($arrLP[$i]['parent_item_id'], $arrHide))
  3724. {
  3725. $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>';
  3726. }
  3727. else
  3728. {
  3729. $arrHide[] = $arrLP[$i]['id'];
  3730. }
  3731. }
  3732. else
  3733. {
  3734. if($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter')
  3735. $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>';
  3736. }
  3737. }
  3738. reset($arrLP);
  3739. $return .= "\t\t\t\t" . '</select>';
  3740. $return .= "\t\t\t" . '</td>' . "\n";
  3741. $return .= "\t\t" . '</tr>' . "\n";
  3742. $return .= "\t\t" . '<tr>' . "\n";
  3743. $return .= "\t\t\t" . '<td class="label"><label for="idPosition">'.get_lang("Position").' :</label></td>' . "\n";
  3744. $return .= "\t\t\t" . '<td class="input">' . "\n";
  3745. $return .= "\t\t\t\t" . '<select id="idPosition" name="previous" size="1">';
  3746. $return .= "\t\t\t\t\t" . '<option class="top" value="0">First position</option>';
  3747. for($i = 0; $i < count($arrLP); $i++)
  3748. {
  3749. if($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id)
  3750. {
  3751. if($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  3752. $selected = 'selected="selected" ';
  3753. elseif($action == 'add')
  3754. $selected = 'selected="selected" ';
  3755. else
  3756. $selected = '';
  3757. $return .= "\t\t\t\t\t" . '<option ' . $selected . 'value="' . $arrLP[$i]['id'] . '">'.get_lang("After").' "' . html_entity_decode(stripslashes($arrLP[$i]['title'])) . '"</option>';
  3758. }
  3759. }
  3760. $return .= "\t\t\t\t" . '</select>';
  3761. $return .= "\t\t\t" . '</td>' . "\n";
  3762. $return .= "\t\t" . '</tr>' . "\n";
  3763. if($action != 'move')
  3764. {
  3765. $return .= "\t\t" . '<tr>' . "\n";
  3766. $return .= "\t\t\t" . '<td class="label"><label for="idTitle">'.get_lang("Title").' :</label></td>' . "\n";
  3767. $return .= "\t\t\t" . '<td class="input"><input id="idTitle" name="title" type="text" value="' . $item_title . '" /></td>' . "\n";
  3768. $return .= "\t\t" . '</tr>' . "\n";
  3769. $return .= "\t\t" . '<tr>' . "\n";
  3770. //Remove temporaly the test description
  3771. //$return .= "\t\t\t" . '<td class="label"><label for="idDescription">'.get_lang("Description").' :</label></td>' . "\n";
  3772. //$return .= "\t\t\t" . '<td class="input"><textarea id="idDescription" name="description" rows="4">' . $item_description . '</textarea></td>' . "\n";
  3773. $return .= "\t\t" . '</tr>' . "\n";
  3774. $id_prerequisite=0;
  3775. foreach($arrLP as $key=>$value){
  3776. if($value['id']==$id){
  3777. $id_prerequisite=$value['prerequisite'];
  3778. break;
  3779. }
  3780. }
  3781. $arrHide=array();
  3782. for($i = 0; $i < count($arrLP); $i++)
  3783. {
  3784. if($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter')
  3785. {
  3786. if($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  3787. $s_selected_position=$arrLP[$i]['id'];
  3788. elseif($action == 'add')
  3789. $s_selected_position=0;
  3790. $arrHide[$arrLP[$i]['id']]['value']=html_entity_decode(stripslashes($arrLP[$i]['title']));
  3791. }
  3792. }
  3793. $return .= "\t\t" . '<tr>' . "\n";
  3794. $return .= "\t\t\t" . '<td class="label"><label for="idPrerequisites">'.get_lang("Prerequisites").' :</label></td>' . "\n";
  3795. $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>';
  3796. foreach($arrHide as $key => $value){
  3797. if($key==$s_selected_position && $action == 'add'){
  3798. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  3799. }
  3800. elseif($key==$id_prerequisite && $action == 'edit'){
  3801. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  3802. }
  3803. else{
  3804. $return .= '<option value="'.$key.'">'.$value['value'].'</option>';
  3805. }
  3806. }
  3807. $return .= "</select></td>";
  3808. $return .= "\t\t" . '</tr>' . "\n";
  3809. }
  3810. $return .= "\t\t" . '<tr>' . "\n";
  3811. $return .= "\t\t\t" . '<td colspan="2"><input class="button" name="submit_button" type="submit" value="OK" /></td>' . "\n";
  3812. $return .= "\t\t" . '</tr>' . "\n";
  3813. $return .= "\t" . '</table>' . "\n";
  3814. if($action == 'move')
  3815. {
  3816. $return .= "\t" . '<input name="title" type="hidden" value="' . $item_title . '" />' . "\n";
  3817. $return .= "\t" . '<input name="description" type="hidden" value="' . $item_description . '" />' . "\n";
  3818. }
  3819. if(is_numeric($extra_info))
  3820. {
  3821. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info . '" />' . "\n";
  3822. }
  3823. elseif(is_array($extra_info))
  3824. {
  3825. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />' . "\n";
  3826. }
  3827. $return .= "\t" . '<input name="type" type="hidden" value="'.TOOL_FORUM.'" />' . "\n";
  3828. $return .= "\t" . '<input name="post_time" type="hidden" value="' . time() . '" />' . "\n";
  3829. $return .= '</form>' . "\n";
  3830. $return .= '</div>' . "\n";
  3831. return $return;
  3832. }
  3833. function display_thread_form($action = 'add', $id = 0, $extra_info = '')
  3834. {
  3835. $tbl_lp_item = Database::get_course_table('lp_item');
  3836. $tbl_forum = Database::get_course_table(TABLE_FORUM_THREAD);
  3837. if($id != 0 && is_array($extra_info))
  3838. {
  3839. $item_title = stripslashes($extra_info['title']);
  3840. }
  3841. elseif(is_numeric($extra_info))
  3842. {
  3843. $sql_forum = "
  3844. SELECT
  3845. thread_title as title
  3846. FROM " . $tbl_forum . "
  3847. WHERE thread_id = " . $extra_info;
  3848. $result = api_sql_query($sql_forum, __FILE__, __LINE__);
  3849. $row = Database::fetch_array($result);
  3850. $item_title = $row['title'];
  3851. }
  3852. else
  3853. {
  3854. $item_title = '';
  3855. }
  3856. $return = '<div style="margin:3px 10px;">';
  3857. if($id != 0 && is_array($extra_info))
  3858. $parent = $extra_info['parent_item_id'];
  3859. else
  3860. $parent = 0;
  3861. $sql = "
  3862. SELECT *
  3863. FROM " . $tbl_lp_item . "
  3864. WHERE
  3865. lp_id = " . $this->lp_id;
  3866. $result = api_sql_query($sql, __FILE__, __LINE__);
  3867. $arrLP = array();
  3868. while($row = Database::fetch_array($result))
  3869. {
  3870. $arrLP[] = array(
  3871. 'id' => $row['id'],
  3872. 'item_type' => $row['item_type'],
  3873. 'title' => $row['title'],
  3874. 'path' => $row['path'],
  3875. 'description' => $row['description'],
  3876. 'parent_item_id' => $row['parent_item_id'],
  3877. 'previous_item_id' => $row['previous_item_id'],
  3878. 'next_item_id' => $row['next_item_id'],
  3879. 'display_order' => $row['display_order'],
  3880. 'prerequisite' => $row['prerequisite']);
  3881. }
  3882. $this->tree_array($arrLP);
  3883. $arrLP = $this->arrMenu;
  3884. unset($this->arrMenu);
  3885. if($action == 'add')
  3886. $return .= '<p class="lp_title">'.get_lang("CreateTheForum").' :</p>' . "\n";
  3887. elseif($action == 'move')
  3888. $return .= '<p class="lp_title">'.get_lang("MoveTheCurrentForum").' :</p>' . "\n";
  3889. else
  3890. $return .= '<p class="lp_title">'.get_lang("EditCurrentForum").' :</p>' . "\n";
  3891. $return .= '<form method="POST">' . "\n";
  3892. $return .= "\t" . '<table cellpadding="0" cellspacing="0" class="lp_form">' . "\n";
  3893. $return .= "\t\t" . '<tr>' . "\n";
  3894. $return .= "\t\t\t" . '<td class="label"><label for="idParent">'.get_lang("Parent").' :</label></td>' . "\n";
  3895. $return .= "\t\t\t" . '<td class="input">' . "\n";
  3896. $return .= "\t\t\t\t" . '<select id="idParent" name="parent" onchange="load_cbo(this.value);" size="1">';
  3897. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
  3898. $arrHide = array($id);
  3899. for($i = 0; $i < count($arrLP); $i++)
  3900. {
  3901. if($action != 'add')
  3902. {
  3903. if(($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter') && !in_array($arrLP[$i]['id'], $arrHide) && !in_array($arrLP[$i]['parent_item_id'], $arrHide))
  3904. {
  3905. $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>';
  3906. }
  3907. else
  3908. {
  3909. $arrHide[] = $arrLP[$i]['id'];
  3910. }
  3911. }
  3912. else
  3913. {
  3914. if($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter')
  3915. $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>';
  3916. }
  3917. }
  3918. reset($arrLP);
  3919. $return .= "\t\t\t\t" . '</select>';
  3920. $return .= "\t\t\t" . '</td>' . "\n";
  3921. $return .= "\t\t" . '</tr>' . "\n";
  3922. $return .= "\t\t" . '<tr>' . "\n";
  3923. $return .= "\t\t\t" . '<td class="label"><label for="idPosition">'.get_lang("Position").' :</label></td>' . "\n";
  3924. $return .= "\t\t\t" . '<td class="input">' . "\n";
  3925. $return .= "\t\t\t\t" . '<select id="idPosition" name="previous" size="1">';
  3926. $return .= "\t\t\t\t\t" . '<option class="top" value="0">First position</option>';
  3927. for($i = 0; $i < count($arrLP); $i++)
  3928. {
  3929. if($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id)
  3930. {
  3931. if($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  3932. $selected = 'selected="selected" ';
  3933. elseif($action == 'add')
  3934. $selected = 'selected="selected" ';
  3935. else
  3936. $selected = '';
  3937. $return .= "\t\t\t\t\t" . '<option ' . $selected . 'value="' . $arrLP[$i]['id'] . '">'.get_lang("After").' "' . html_entity_decode(stripslashes($arrLP[$i]['title'])) . '"</option>';
  3938. }
  3939. }
  3940. $return .= "\t\t\t\t" . '</select>';
  3941. $return .= "\t\t\t" . '</td>' . "\n";
  3942. $return .= "\t\t" . '</tr>' . "\n";
  3943. if($action != 'move')
  3944. {
  3945. $return .= "\t\t" . '<tr>' . "\n";
  3946. $return .= "\t\t\t" . '<td class="label"><label for="idTitle">'.get_lang("Title").' :</label></td>' . "\n";
  3947. $return .= "\t\t\t" . '<td class="input"><input id="idTitle" name="title" type="text" value="' . $item_title . '" /></td>' . "\n";
  3948. $return .= "\t\t" . '</tr>' . "\n";
  3949. $return .= "\t\t" . '<tr>' . "\n";
  3950. //Remove temporaly the test description
  3951. //$return .= "\t\t\t" . '<td class="label"><label for="idDescription">'.get_lang("Description").' :</label></td>' . "\n";
  3952. //$return .= "\t\t\t" . '<td class="input"><textarea id="idDescription" name="description" rows="4">' . $item_description . '</textarea></td>' . "\n";
  3953. $return .= "\t\t" . '</tr>' . "\n";
  3954. $id_prerequisite=0;
  3955. foreach($arrLP as $key=>$value){
  3956. if($value['id']==$id){
  3957. $id_prerequisite=$value['prerequisite'];
  3958. break;
  3959. }
  3960. }
  3961. $arrHide=array();
  3962. for($i = 0; $i < count($arrLP); $i++)
  3963. {
  3964. if($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter')
  3965. {
  3966. if($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  3967. $s_selected_position=$arrLP[$i]['id'];
  3968. elseif($action == 'add')
  3969. $s_selected_position=0;
  3970. $arrHide[$arrLP[$i]['id']]['value']=html_entity_decode(stripslashes($arrLP[$i]['title']));
  3971. }
  3972. }
  3973. $return .= "\t\t" . '<tr>' . "\n";
  3974. $return .= "\t\t\t" . '<td class="label"><label for="idPrerequisites">'.get_lang("Prerequisites").' :</label></td>' . "\n";
  3975. $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>';
  3976. foreach($arrHide as $key => $value){
  3977. if($key==$s_selected_position && $action == 'add'){
  3978. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  3979. }
  3980. elseif($key==$id_prerequisite && $action == 'edit'){
  3981. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  3982. }
  3983. else{
  3984. $return .= '<option value="'.$key.'">'.$value['value'].'</option>';
  3985. }
  3986. }
  3987. $return .= "</select></td>";
  3988. $return .= "\t\t" . '</tr>' . "\n";
  3989. }
  3990. $return .= "\t\t" . '<tr>' . "\n";
  3991. $return .= "\t\t\t" . '<td colspan="2"><input class="button" name="submit_button" type="submit" value="OK" /></td>' . "\n";
  3992. $return .= "\t\t" . '</tr>' . "\n";
  3993. $return .= "\t" . '</table>' . "\n";
  3994. if($action == 'move')
  3995. {
  3996. $return .= "\t" . '<input name="title" type="hidden" value="' . $item_title . '" />' . "\n";
  3997. $return .= "\t" . '<input name="description" type="hidden" value="' . $item_description . '" />' . "\n";
  3998. }
  3999. if(is_numeric($extra_info))
  4000. {
  4001. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info . '" />' . "\n";
  4002. }
  4003. elseif(is_array($extra_info))
  4004. {
  4005. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />' . "\n";
  4006. }
  4007. $return .= "\t" . '<input name="type" type="hidden" value="'.TOOL_THREAD.'" />' . "\n";
  4008. $return .= "\t" . '<input name="post_time" type="hidden" value="' . time() . '" />' . "\n";
  4009. $return .= '</form>' . "\n";
  4010. $return .= '</div>' . "\n";
  4011. return $return;
  4012. }
  4013. /**
  4014. * Enter description here...
  4015. *
  4016. * @param unknown_type $item_type
  4017. * @param unknown_type $title
  4018. * @param unknown_type $action
  4019. * @param unknown_type $id
  4020. * @param unknown_type $extra_info
  4021. * @return unknown
  4022. */
  4023. function display_item_form($item_type, $title = '', $action = 'add', $id = 0, $extra_info = 'new')
  4024. {
  4025. $tbl_lp_item = Database::get_course_table('lp_item');
  4026. if($id != 0 && is_array($extra_info))
  4027. {
  4028. $item_title = stripslashes($extra_info['title']);
  4029. $item_description = stripslashes($extra_info['description']);
  4030. }
  4031. else
  4032. {
  4033. $item_title = '';
  4034. $item_description = '';
  4035. }
  4036. $return = '<div style="margin:3px 10px;">';
  4037. if($id != 0 && is_array($extra_info))
  4038. $parent = $extra_info['parent_item_id'];
  4039. else
  4040. $parent = 0;
  4041. $sql = "
  4042. SELECT *
  4043. FROM " . $tbl_lp_item . "
  4044. WHERE
  4045. lp_id = " . $this->lp_id;
  4046. if($item_type == 'module')
  4047. $sql .= " AND parent_item_id = 0";
  4048. $result = api_sql_query($sql, __FILE__, __LINE__);
  4049. $arrLP = array();
  4050. while($row = Database::fetch_array($result))
  4051. {
  4052. $arrLP[] = array(
  4053. 'id' => $row['id'],
  4054. 'item_type' => $row['item_type'],
  4055. 'title' => $row['title'],
  4056. 'path' => $row['path'],
  4057. 'description' => $row['description'],
  4058. 'parent_item_id' => $row['parent_item_id'],
  4059. 'previous_item_id' => $row['previous_item_id'],
  4060. 'next_item_id' => $row['next_item_id'],
  4061. 'display_order' => $row['display_order']);
  4062. }
  4063. $this->tree_array($arrLP);
  4064. $arrLP = $this->arrMenu;
  4065. unset($this->arrMenu);
  4066. $return .= '<p class="lp_title">' . $title . '</p>' . "\n";
  4067. require_once (api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php');
  4068. $form = new FormValidator('form','POST',$_SERVER["PHP_SELF"]."?".$_SERVER["QUERY_STRING"]);
  4069. $defaults["title"]=$item_title;
  4070. $defaults["description"]=$item_description;
  4071. $form->addElement('html',$return);
  4072. //$arrHide = array($id);
  4073. $arrHide[0]['value']=$this->name;
  4074. $arrHide[0]['padding']=3;
  4075. if($item_type != 'module' && $item_type != 'dokeos_module')
  4076. {
  4077. for($i = 0; $i < count($arrLP); $i++)
  4078. {
  4079. if($action != 'add'){
  4080. if(($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter') && !in_array($arrLP[$i]['id'], $arrHide) && !in_array($arrLP[$i]['parent_item_id'], $arrHide)){
  4081. $arrHide[$arrLP[$i]['id']]['value']=html_entity_decode(stripslashes($arrLP[$i]['title']));
  4082. $arrHide[$arrLP[$i]['id']]['padding']=3+ $arrLP[$i]['depth'] * 10;
  4083. if($parent == $arrLP[$i]['id']){
  4084. $s_selected_parent=$arrHide[$arrLP[$i]['id']];
  4085. }
  4086. }
  4087. }
  4088. else{
  4089. if($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter'){
  4090. $arrHide[$arrLP[$i]['id']]['value']=html_entity_decode(stripslashes($arrLP[$i]['title']));
  4091. $arrHide[$arrLP[$i]['id']]['padding']=3+ $arrLP[$i]['depth'] * 10;
  4092. if($parent == $arrLP[$i]['id']){
  4093. $s_selected_parent=$arrHide[$arrLP[$i]['id']];
  4094. }
  4095. }
  4096. }
  4097. }
  4098. $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);"');
  4099. foreach($arrHide as $key => $value){
  4100. $parent_select->addOption($value['value'],$key,'style="padding-left:'.$value['padding'].'px;"');
  4101. }
  4102. $parent_select -> setSelected($s_selected_parent);
  4103. }
  4104. reset($arrLP);
  4105. $arrHide=array();
  4106. //POSITION
  4107. for($i = 0; $i < count($arrLP); $i++)
  4108. {
  4109. if($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id)
  4110. {
  4111. if($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  4112. $s_selected_position=$arrLP[$i]['id'];
  4113. elseif($action == 'add')
  4114. $s_selected_position=$arrLP[$i]['id'];
  4115. $arrHide[$arrLP[$i]['id']]['value']=get_lang("After").' "' . html_entity_decode(stripslashes($arrLP[$i]['title']));
  4116. }
  4117. }
  4118. $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;"');
  4119. $position->addOption(get_lang('FirstPosition'),$key,'style="padding-left:'.$value['padding'].'px;"');
  4120. foreach($arrHide as $key => $value){
  4121. $position->addOption($value['value'],$key,'style="padding-left:'.$value['padding'].'px;"');
  4122. }
  4123. if(empty($s_selected_position))
  4124. $position -> setSelected($s_selected_position);
  4125. reset($arrLP);
  4126. if($action != 'move'){
  4127. $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;"');
  4128. //$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;"');
  4129. }
  4130. $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;"');
  4131. if($item_type == 'module' || $item_type == 'dokeos_module')
  4132. {
  4133. $form->addElement('hidden', 'parent', '0');
  4134. }
  4135. $form->addElement('hidden', 'type', 'dokeos_'.$item_type);
  4136. $form->addElement('hidden', 'post_time', time());
  4137. $form->addElement('html','</div>');
  4138. $form->setDefaults($defaults);
  4139. return $form->return_form();
  4140. }
  4141. /**
  4142. * Enter description here...
  4143. *
  4144. * @param unknown_type $action
  4145. * @param unknown_type $id
  4146. * @param unknown_type $extra_info
  4147. * @return unknown
  4148. */
  4149. function display_document_form($action = 'add', $id = 0, $extra_info = 'new')
  4150. {
  4151. echo '
  4152. <style>
  4153. .row{
  4154. width:100%;
  4155. }
  4156. div.row div.label {
  4157. width: 75px;
  4158. }
  4159. div.row div.formw {
  4160. width: 85%;
  4161. }
  4162. </style>';
  4163. $tbl_lp_item = Database::get_course_table('lp_item');
  4164. $tbl_doc = Database::get_course_table(TABLE_DOCUMENT);
  4165. $path_parts = pathinfo($extra_info['dir']);
  4166. $no_display_edit_textarea=false;
  4167. //If action==edit document
  4168. //We don't display the document form if it's not an editable document (html or txt file)
  4169. if($action=="edit"){
  4170. if(is_array($extra_info)){
  4171. if($path_parts['extension']!="txt" && $path_parts['extension']!="html"){
  4172. $no_display_edit_textarea=true;
  4173. }
  4174. }
  4175. }
  4176. $no_display_add=false;
  4177. //If action==add an existing document
  4178. //We don't display the document form if it's not an editable document (html or txt file)
  4179. if($action=="add"){
  4180. if(is_numeric($extra_info)){
  4181. $sql_doc = "SELECT path FROM " . $tbl_doc . "WHERE id = " . $extra_info;
  4182. $result=api_sql_query($sql_doc);
  4183. $path_file=mysql_result($result,0,0);
  4184. $path_parts = pathinfo($path_file);
  4185. if($path_parts['extension']!="txt" && $path_parts['extension']!="html"){
  4186. $no_display_add=true;
  4187. }
  4188. }
  4189. }
  4190. if($id != 0 && is_array($extra_info))
  4191. {
  4192. $item_title = stripslashes($extra_info['title']);
  4193. $item_description = stripslashes($extra_info['description']);
  4194. if(empty($item_title))
  4195. {
  4196. $path_parts = pathinfo($extra_info['path']);
  4197. $item_title = stripslashes($path_parts['filename']);
  4198. }
  4199. }
  4200. elseif(is_numeric($extra_info))
  4201. {
  4202. $sql_doc = "
  4203. SELECT path, title
  4204. FROM " . $tbl_doc . "
  4205. WHERE id = " . $extra_info;
  4206. $result = api_sql_query($sql_doc, __FILE__, __LINE__);
  4207. $row = Database::fetch_array($result);
  4208. $explode = explode('.', $row['title']);
  4209. if(count($explode)>1){
  4210. for($i = 0; $i < count($explode) - 1; $i++)
  4211. $item_title .= $explode[$i];
  4212. }
  4213. else{
  4214. $item_title=$row['title'];
  4215. }
  4216. $item_title = str_replace('_', ' ', $item_title);
  4217. if(empty($item_title))
  4218. {
  4219. $path_parts = pathinfo($row['path']);
  4220. $item_title = stripslashes($path_parts['filename']);
  4221. }
  4222. }
  4223. else
  4224. {
  4225. $item_title = '';
  4226. $item_description = '';
  4227. }
  4228. $return = '<div style="margin:3px 10px;">';
  4229. if($id != 0 && is_array($extra_info))
  4230. $parent = $extra_info['parent_item_id'];
  4231. else
  4232. $parent = 0;
  4233. $sql = "
  4234. SELECT *
  4235. FROM " . $tbl_lp_item . "
  4236. WHERE
  4237. lp_id = " . $this->lp_id;
  4238. $result = api_sql_query($sql, __FILE__, __LINE__);
  4239. $arrLP = array();
  4240. while($row = Database::fetch_array($result))
  4241. {
  4242. $arrLP[] = array(
  4243. 'id' => $row['id'],
  4244. 'item_type' => $row['item_type'],
  4245. 'title' => $row['title'],
  4246. 'path' => $row['path'],
  4247. 'description' => $row['description'],
  4248. 'parent_item_id' => $row['parent_item_id'],
  4249. 'previous_item_id' => $row['previous_item_id'],
  4250. 'next_item_id' => $row['next_item_id'],
  4251. 'display_order' => $row['display_order'],
  4252. 'prerequisite' => $row['prerequisite']);
  4253. }
  4254. $this->tree_array($arrLP);
  4255. $arrLP = $this->arrMenu;
  4256. unset($this->arrMenu);
  4257. if($action == 'add')
  4258. $return .= '<p class="lp_title">'.get_lang("CreateTheDocument").' :</p>' . "\n";
  4259. elseif($action == 'move')
  4260. $return .= '<p class="lp_title">'.get_lang("MoveTheCurrentDocument").' :</p>' . "\n";
  4261. else
  4262. $return .= '<p class="lp_title">'.get_lang("EditTheCurrentDocument").' :</p>' . "\n";
  4263. if(isset($_GET['edit']) && $_GET['edit'] == 'true')
  4264. {
  4265. $return .= '<div class="lp_message" style="margin-bottom:15px;">';
  4266. $return .= '<p class="lp_title">'.get_lang("Warning").' !</p>';
  4267. $return .= get_lang("WarningEditingDocument");
  4268. $return .= '</div>';
  4269. }
  4270. /*
  4271. if($no_display_add==true){
  4272. $return .= '<div class="lp_message" style="margin-bottom:15px;">';
  4273. $return .= get_lang("CantEditDocument");
  4274. $return .= '</div>';
  4275. return $return;
  4276. }
  4277. */
  4278. require_once (api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php');
  4279. $form = new FormValidator('form','POST',$_SERVER["PHP_SELF"]."?".$_SERVER["QUERY_STRING"]);
  4280. $defaults["title"]=$item_title;
  4281. $defaults["description"]=$item_description;
  4282. $form->addElement('html',$return);
  4283. //$arrHide = array($id);
  4284. $arrHide[0]['value']=$this->name;
  4285. $arrHide[0]['padding']=3;
  4286. for($i = 0; $i < count($arrLP); $i++)
  4287. {
  4288. if($action != 'add'){
  4289. if(($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter') && !in_array($arrLP[$i]['id'], $arrHide) && !in_array($arrLP[$i]['parent_item_id'], $arrHide)){
  4290. $arrHide[$arrLP[$i]['id']]['value']=html_entity_decode(stripslashes($arrLP[$i]['title']));
  4291. $arrHide[$arrLP[$i]['id']]['padding']=3+ $arrLP[$i]['depth'] * 10;
  4292. if($parent == $arrLP[$i]['id']){
  4293. $s_selected_parent=$arrHide[$arrLP[$i]['id']];
  4294. }
  4295. }
  4296. }
  4297. else{
  4298. if($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter'){
  4299. $arrHide[$arrLP[$i]['id']]['value']=html_entity_decode(stripslashes($arrLP[$i]['title']));
  4300. $arrHide[$arrLP[$i]['id']]['padding']=3+ $arrLP[$i]['depth'] * 10;
  4301. if($parent == $arrLP[$i]['id']){
  4302. $s_selected_parent=$arrHide[$arrLP[$i]['id']];
  4303. }
  4304. }
  4305. }
  4306. }
  4307. $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);"');
  4308. foreach($arrHide as $key => $value){
  4309. $parent_select->addOption($value['value'],$key,'style="padding-left:'.$value['padding'].'px;"');
  4310. }
  4311. $parent_select -> setSelected($parent);
  4312. reset($arrLP);
  4313. $arrHide=array();
  4314. //POSITION
  4315. for($i = 0; $i < count($arrLP); $i++)
  4316. {
  4317. if($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id)
  4318. {
  4319. if($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  4320. $s_selected_position=$arrLP[$i]['id'];
  4321. elseif($action == 'add')
  4322. $s_selected_position=$arrLP[$i]['id'];
  4323. $arrHide[$arrLP[$i]['id']]['value']=get_lang("After").' "' . html_entity_decode(stripslashes($arrLP[$i]['title'])).'"';
  4324. }
  4325. }
  4326. $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;"');
  4327. $position->addOption(get_lang("FirstPosition"),0,'style="padding-left:3px;"');
  4328. foreach($arrHide as $key => $value){
  4329. $position->addOption($value['value'],$key,'style="padding-left:'.$value['padding'].'px;"');
  4330. }
  4331. $position -> setSelected($s_selected_position);
  4332. reset($arrLP);
  4333. if($action != 'move'){
  4334. $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;"');
  4335. //$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;"');
  4336. $id_prerequisite=0;
  4337. foreach($arrLP as $key=>$value){
  4338. if($value['id']==$id){
  4339. $id_prerequisite=$value['prerequisite'];
  4340. break;
  4341. }
  4342. }
  4343. $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;"');
  4344. $select_prerequisites->addOption(get_lang("NoPrerequisites"),0,'style="padding-left:3px;"');
  4345. $arrHide=array();
  4346. for($i = 0; $i < count($arrLP); $i++)
  4347. {
  4348. if($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter')
  4349. {
  4350. if($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  4351. $s_selected_position=$arrLP[$i]['id'];
  4352. elseif($action == 'add')
  4353. $s_selected_position=$arrLP[$i]['id'];
  4354. $arrHide[$arrLP[$i]['id']]['value']=html_entity_decode(stripslashes($arrLP[$i]['title']));
  4355. }
  4356. }
  4357. foreach($arrHide as $key => $value){
  4358. $select_prerequisites->addOption($value['value'],$key,'style="padding-left:'.$value['padding'].'px;"');
  4359. if($key==$s_selected_position && $action == 'add'){
  4360. $select_prerequisites -> setSelected(0);
  4361. }
  4362. elseif($key==$id_prerequisite && $action == 'edit'){
  4363. $select_prerequisites -> setSelected($id_prerequisite);
  4364. }
  4365. }
  4366. if(!$no_display_add)
  4367. {
  4368. if(($extra_info == 'new' || $extra_info['item_type'] == TOOL_DOCUMENT || $_GET['edit'] == 'true'))
  4369. {
  4370. if(isset($_POST['content']))
  4371. $content = stripslashes($_POST['content']);
  4372. elseif(is_array($extra_info)){
  4373. //If it's an html document or a text file
  4374. if(!$no_display_edit_textarea){
  4375. $content = $this->display_document($extra_info['path'], false, false);
  4376. }
  4377. }
  4378. elseif(is_numeric($extra_info))
  4379. $content = $this->display_document($extra_info, false, false);
  4380. else
  4381. $content = '';
  4382. if(!$no_display_edit_textarea){
  4383. $form->addElement('html_editor','content_lp',get_lang("Content")." :");
  4384. $defaults["content_lp"]=$content;
  4385. }
  4386. }
  4387. elseif(is_numeric($extra_info))
  4388. {
  4389. $return = $this->display_document($extra_info, true, true, true);
  4390. $form->addElement('html',$return);
  4391. }
  4392. }
  4393. }
  4394. $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;"');
  4395. if($action == 'move')
  4396. {
  4397. $form->addElement('hidden', 'title', $item_title);
  4398. $form->addElement('hidden', 'description', $item_description);
  4399. }
  4400. if(is_numeric($extra_info))
  4401. {
  4402. $form->addElement('hidden', 'path', $extra_info);
  4403. }
  4404. elseif(is_array($extra_info))
  4405. {
  4406. $form->addElement('hidden', 'path', $extra_info['path']);
  4407. }
  4408. $form->addElement('hidden', 'type', TOOL_DOCUMENT);
  4409. $form->addElement('hidden', 'post_time', time());
  4410. $form->addElement('html','</div>');
  4411. $form->setDefaults($defaults);
  4412. return $form->return_form();
  4413. }
  4414. /**
  4415. * Enter description here...
  4416. *
  4417. * @param unknown_type $action
  4418. * @param unknown_type $id
  4419. * @param unknown_type $extra_info
  4420. */
  4421. function display_link_form($action = 'add', $id = 0, $extra_info = '')
  4422. {
  4423. $tbl_lp_item = Database::get_course_table('lp_item');
  4424. $tbl_link = Database::get_course_table(TABLE_LINK);
  4425. if($id != 0 && is_array($extra_info))
  4426. {
  4427. $item_title = stripslashes($extra_info['title']);
  4428. $item_description = stripslashes($extra_info['description']);
  4429. }
  4430. elseif(is_numeric($extra_info))
  4431. {
  4432. $sql_link = "
  4433. SELECT
  4434. title,
  4435. description,
  4436. url
  4437. FROM " . $tbl_link . "
  4438. WHERE id = " . $extra_info;
  4439. $result = api_sql_query($sql_link, __FILE__, __LINE__);
  4440. $row = Database::fetch_array($result);
  4441. $item_title = $row['title'];
  4442. $item_description = $row['description'];
  4443. $item_url = $row['url'];
  4444. }
  4445. else
  4446. {
  4447. $item_title = '';
  4448. $item_description = '';
  4449. }
  4450. $return = '<div style="margin:3px 10px;">';
  4451. if($id != 0 && is_array($extra_info))
  4452. $parent = $extra_info['parent_item_id'];
  4453. else
  4454. $parent = 0;
  4455. $sql = "
  4456. SELECT *
  4457. FROM " . $tbl_lp_item . "
  4458. WHERE
  4459. lp_id = " . $this->lp_id;
  4460. $result = api_sql_query($sql, __FILE__, __LINE__);
  4461. $arrLP = array();
  4462. while($row = Database::fetch_array($result))
  4463. {
  4464. $arrLP[] = array(
  4465. 'id' => $row['id'],
  4466. 'item_type' => $row['item_type'],
  4467. 'title' => $row['title'],
  4468. 'path' => $row['path'],
  4469. 'description' => $row['description'],
  4470. 'parent_item_id' => $row['parent_item_id'],
  4471. 'previous_item_id' => $row['previous_item_id'],
  4472. 'next_item_id' => $row['next_item_id'],
  4473. 'display_order' => $row['display_order'],
  4474. 'prerequisite' => $row['prerequisite']);
  4475. }
  4476. $this->tree_array($arrLP);
  4477. $arrLP = $this->arrMenu;
  4478. unset($this->arrMenu);
  4479. if($action == 'add')
  4480. $return .= '<p class="lp_title">'.get_lang("CreateTheLink").' :</p>' . "\n";
  4481. elseif($action == 'move')
  4482. $return .= '<p class="lp_title">'.get_lang("MoveCurrentLink").' :</p>' . "\n";
  4483. else
  4484. $return .= '<p class="lp_title">'.get_lang("EditCurrentLink").' :</p>' . "\n";
  4485. $return .= '<form method="POST">' . "\n";
  4486. $return .= "\t" . '<table cellpadding="0" cellspacing="0" class="lp_form">' . "\n";
  4487. $return .= "\t\t" . '<tr>' . "\n";
  4488. $return .= "\t\t\t" . '<td class="label"><label for="idParent">'.get_lang("Parent").' :</label></td>' . "\n";
  4489. $return .= "\t\t\t" . '<td class="input">' . "\n";
  4490. $return .= "\t\t\t\t" . '<select id="idParent" name="parent" onchange="load_cbo(this.value);" size="1">';
  4491. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
  4492. $arrHide = array($id);
  4493. for($i = 0; $i < count($arrLP); $i++)
  4494. {
  4495. if($action != 'add')
  4496. {
  4497. if(($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter') && !in_array($arrLP[$i]['id'], $arrHide) && !in_array($arrLP[$i]['parent_item_id'], $arrHide))
  4498. {
  4499. $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>';
  4500. }
  4501. else
  4502. {
  4503. $arrHide[] = $arrLP[$i]['id'];
  4504. }
  4505. }
  4506. else
  4507. {
  4508. if($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter')
  4509. $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>';
  4510. }
  4511. }
  4512. reset($arrLP);
  4513. $return .= "\t\t\t\t" . '</select>';
  4514. $return .= "\t\t\t" . '</td>' . "\n";
  4515. $return .= "\t\t" . '</tr>' . "\n";
  4516. $return .= "\t\t" . '<tr>' . "\n";
  4517. $return .= "\t\t\t" . '<td class="label"><label for="idPosition">'.get_lang("Position").' :</label></td>' . "\n";
  4518. $return .= "\t\t\t" . '<td class="input">' . "\n";
  4519. $return .= "\t\t\t\t" . '<select id="idPosition" name="previous" size="1">';
  4520. $return .= "\t\t\t\t\t" . '<option class="top" value="0">'.get_lang("FirstPosition").'</option>';
  4521. for($i = 0; $i < count($arrLP); $i++)
  4522. {
  4523. if($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id)
  4524. {
  4525. if($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  4526. $selected = 'selected="selected" ';
  4527. elseif($action == 'add')
  4528. $selected = 'selected="selected" ';
  4529. else
  4530. $selected = '';
  4531. $return .= "\t\t\t\t\t" . '<option ' . $selected . 'value="' . $arrLP[$i]['id'] . '">'.get_lang("After").' "' . html_entity_decode(stripslashes($arrLP[$i]['title'])) . '"</option>';
  4532. }
  4533. }
  4534. $return .= "\t\t\t\t" . '</select>';
  4535. $return .= "\t\t\t" . '</td>' . "\n";
  4536. $return .= "\t\t" . '</tr>' . "\n";
  4537. if($action != 'move')
  4538. {
  4539. $return .= "\t\t" . '<tr>' . "\n";
  4540. $return .= "\t\t\t" . '<td class="label"><label for="idTitle">'.get_lang("Title").' :</label></td>' . "\n";
  4541. $return .= "\t\t\t" . '<td class="input"><input id="idTitle" name="title" type="text" value="' . $item_title . '" /></td>' . "\n";
  4542. $return .= "\t\t" . '</tr>' . "\n";
  4543. $return .= "\t\t" . '<tr>' . "\n";
  4544. $return .= "\t\t\t" . '<td class="label"><label for="idDescription">'.get_lang("Description").' :</label></td>' . "\n";
  4545. $return .= "\t\t\t" . '<td class="input"><textarea id="idDescription" name="description" rows="4">' . $item_description . '</textarea></td>' . "\n";
  4546. $return .= "\t\t" . '</tr>' . "\n";
  4547. $return .= "\t\t" . '<tr>' . "\n";
  4548. $return .= "\t\t\t" . '<td class="label"><label for="idURL">'.get_lang("Url").' :</label></td>' . "\n";
  4549. $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";
  4550. $return .= "\t\t" . '</tr>' . "\n";
  4551. $id_prerequisite=0;
  4552. foreach($arrLP as $key=>$value){
  4553. if($value['id']==$id){
  4554. $id_prerequisite=$value['prerequisite'];
  4555. break;
  4556. }
  4557. }
  4558. $arrHide=array();
  4559. for($i = 0; $i < count($arrLP); $i++)
  4560. {
  4561. if($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter')
  4562. {
  4563. if($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  4564. $s_selected_position=$arrLP[$i]['id'];
  4565. elseif($action == 'add')
  4566. $s_selected_position=$arrLP[$i]['id'];
  4567. $arrHide[$arrLP[$i]['id']]['value']=html_entity_decode(stripslashes($arrLP[$i]['title']));
  4568. }
  4569. }
  4570. $return .= "\t\t" . '<tr>' . "\n";
  4571. $return .= "\t\t\t" . '<td class="label"><label for="idPrerequisites">'.get_lang("Prerequisites").' :</label></td>' . "\n";
  4572. $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>';
  4573. foreach($arrHide as $key => $value){
  4574. if($key==$s_selected_position && $action == 'add'){
  4575. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  4576. }
  4577. elseif($key==$id_prerequisite && $action == 'edit'){
  4578. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  4579. }
  4580. else{
  4581. $return .= '<option value="'.$key.'">'.$value['value'].'</option>';
  4582. }
  4583. }
  4584. $return .= "</select></td>";
  4585. $return .= "\t\t" . '</tr>' . "\n";
  4586. }
  4587. $return .= "\t\t" . '<tr>' . "\n";
  4588. $return .= "\t\t\t" . '<td colspan="2"><input class="button" name="submit_button" type="submit" value="'.get_lang("Ok").'" /></td>' . "\n";
  4589. $return .= "\t\t" . '</tr>' . "\n";
  4590. $return .= "\t" . '</table>' . "\n";
  4591. if($action == 'move')
  4592. {
  4593. $return .= "\t" . '<input name="title" type="hidden" value="' . $item_title . '" />' . "\n";
  4594. $return .= "\t" . '<input name="description" type="hidden" value="' . $item_description . '" />' . "\n";
  4595. }
  4596. if(is_numeric($extra_info))
  4597. {
  4598. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info . '" />' . "\n";
  4599. }
  4600. elseif(is_array($extra_info))
  4601. {
  4602. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />' . "\n";
  4603. }
  4604. $return .= "\t" . '<input name="type" type="hidden" value="'.TOOL_LINK.'" />' . "\n";
  4605. $return .= "\t" . '<input name="post_time" type="hidden" value="' . time() . '" />' . "\n";
  4606. $return .= '</form>' . "\n";
  4607. $return .= '</div>' . "\n";
  4608. return $return;
  4609. }
  4610. /**
  4611. * Enter description here...
  4612. *
  4613. * @param unknown_type $action
  4614. * @param unknown_type $id
  4615. * @param unknown_type $extra_info
  4616. * @return unknown
  4617. */
  4618. function display_student_publication_form($action = 'add', $id = 0, $extra_info = '')
  4619. {
  4620. $tbl_lp_item = Database::get_course_table('lp_item');
  4621. $tbl_publication = Database::get_course_table(TABLE_STUDENT_PUBLICATION);
  4622. if($id != 0 && is_array($extra_info))
  4623. {
  4624. $item_title = stripslashes($extra_info['title']);
  4625. $item_description = stripslashes($extra_info['description']);
  4626. }
  4627. elseif(is_numeric($extra_info))
  4628. {
  4629. $sql_publication = "
  4630. SELECT
  4631. title,
  4632. description
  4633. FROM " . $tbl_publication . "
  4634. WHERE id = " . $extra_info;
  4635. $result = api_sql_query($sql_publication, __FILE__, __LINE__);
  4636. $row = Database::fetch_array($result);
  4637. $item_title = $row['title'];
  4638. }
  4639. else
  4640. {
  4641. $item_title = '';
  4642. }
  4643. $return = '<div style="margin:3px 10px;">';
  4644. if($id != 0 && is_array($extra_info))
  4645. $parent = $extra_info['parent_item_id'];
  4646. else
  4647. $parent = 0;
  4648. $sql = "
  4649. SELECT *
  4650. FROM " . $tbl_lp_item . "
  4651. WHERE
  4652. lp_id = " . $this->lp_id;
  4653. $result = api_sql_query($sql, __FILE__, __LINE__);
  4654. $arrLP = array();
  4655. while($row = Database::fetch_array($result))
  4656. {
  4657. $arrLP[] = array(
  4658. 'id' => $row['id'],
  4659. 'item_type' => $row['item_type'],
  4660. 'title' => $row['title'],
  4661. 'path' => $row['path'],
  4662. 'description' => $row['description'],
  4663. 'parent_item_id' => $row['parent_item_id'],
  4664. 'previous_item_id' => $row['previous_item_id'],
  4665. 'next_item_id' => $row['next_item_id'],
  4666. 'display_order' => $row['display_order'],
  4667. 'prerequisite' => $row['prerequisite']);
  4668. }
  4669. $this->tree_array($arrLP);
  4670. $arrLP = $this->arrMenu;
  4671. unset($this->arrMenu);
  4672. if($action == 'add')
  4673. $return .= '<p class="lp_title">'.get_lang("Student_publication").' :</p>' . "\n";
  4674. elseif($action == 'move')
  4675. $return .= '<p class="lp_title">'.get_lang("MoveCurrentStudentPublication").' :</p>' . "\n";
  4676. else
  4677. $return .= '<p class="lp_title">'.get_lang("EditCurrentStudentPublication").' :</p>' . "\n";
  4678. $return .= '<form method="POST">' . "\n";
  4679. $return .= "\t" . '<table cellpadding="0" cellspacing="0" class="lp_form">' . "\n";
  4680. $return .= "\t\t" . '<tr>' . "\n";
  4681. $return .= "\t\t\t" . '<td class="label"><label for="idParent">'.get_lang("Parent").' :</label></td>' . "\n";
  4682. $return .= "\t\t\t" . '<td class="input">' . "\n";
  4683. $return .= "\t\t\t\t" . '<select id="idParent" name="parent" onchange="load_cbo(this.value);" size="1">';
  4684. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
  4685. $arrHide = array($id);
  4686. for($i = 0; $i < count($arrLP); $i++)
  4687. {
  4688. if($action != 'add')
  4689. {
  4690. if(($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter') && !in_array($arrLP[$i]['id'], $arrHide) && !in_array($arrLP[$i]['parent_item_id'], $arrHide))
  4691. {
  4692. $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>';
  4693. }
  4694. else
  4695. {
  4696. $arrHide[] = $arrLP[$i]['id'];
  4697. }
  4698. }
  4699. else
  4700. {
  4701. if($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter')
  4702. $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>';
  4703. }
  4704. }
  4705. reset($arrLP);
  4706. $return .= "\t\t\t\t" . '</select>';
  4707. $return .= "\t\t\t" . '</td>' . "\n";
  4708. $return .= "\t\t" . '</tr>' . "\n";
  4709. $return .= "\t\t" . '<tr>' . "\n";
  4710. $return .= "\t\t\t" . '<td class="label"><label for="idPosition">'.get_lang("Position").' :</label></td>' . "\n";
  4711. $return .= "\t\t\t" . '<td class="input">' . "\n";
  4712. $return .= "\t\t\t\t" . '<select id="idPosition" name="previous" size="1">';
  4713. $return .= "\t\t\t\t\t" . '<option class="top" value="0">'.get_lang("FirstPosition").'</option>';
  4714. for($i = 0; $i < count($arrLP); $i++)
  4715. {
  4716. if($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id)
  4717. {
  4718. if($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  4719. $selected = 'selected="selected" ';
  4720. elseif($action == 'add')
  4721. $selected = 'selected="selected" ';
  4722. else
  4723. $selected = '';
  4724. $return .= "\t\t\t\t\t" . '<option ' . $selected . 'value="' . $arrLP[$i]['id'] . '">'.get_lang("After").' "' . html_entity_decode(stripslashes($arrLP[$i]['title'])) . '"</option>';
  4725. }
  4726. }
  4727. $return .= "\t\t\t\t" . '</select>';
  4728. $return .= "\t\t\t" . '</td>' . "\n";
  4729. $return .= "\t\t" . '</tr>' . "\n";
  4730. if($action != 'move')
  4731. {
  4732. $return .= "\t\t" . '<tr>' . "\n";
  4733. $return .= "\t\t\t" . '<td class="label"><label for="idTitle">'.get_lang("Title").' :</label></td>' . "\n";
  4734. $return .= "\t\t\t" . '<td class="input"><input id="idTitle" name="title" type="text" value="' . $item_title . '" /></td>' . "\n";
  4735. $return .= "\t\t" . '</tr>' . "\n";
  4736. $id_prerequisite=0;
  4737. foreach($arrLP as $key=>$value){
  4738. if($value['id']==$id){
  4739. $id_prerequisite=$value['prerequisite'];
  4740. break;
  4741. }
  4742. }
  4743. $arrHide=array();
  4744. for($i = 0; $i < count($arrLP); $i++)
  4745. {
  4746. if($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter')
  4747. {
  4748. if($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  4749. $s_selected_position=$arrLP[$i]['id'];
  4750. elseif($action == 'add')
  4751. $s_selected_position=0;
  4752. $arrHide[$arrLP[$i]['id']]['value']=html_entity_decode(stripslashes($arrLP[$i]['title']));
  4753. }
  4754. }
  4755. $return .= "\t\t" . '<tr>' . "\n";
  4756. $return .= "\t\t\t" . '<td class="label"><label for="idPrerequisites">'.get_lang("Prerequisites").' :</label></td>' . "\n";
  4757. $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>';
  4758. foreach($arrHide as $key => $value){
  4759. if($key==$s_selected_position && $action == 'add'){
  4760. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  4761. }
  4762. elseif($key==$id_prerequisite && $action == 'edit'){
  4763. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  4764. }
  4765. else{
  4766. $return .= '<option value="'.$key.'">'.$value['value'].'</option>';
  4767. }
  4768. }
  4769. $return .= "</select></td>";
  4770. $return .= "\t\t" . '</tr>' . "\n";
  4771. }
  4772. $return .= "\t\t" . '<tr>' . "\n";
  4773. $return .= "\t\t\t" . '<td colspan="2"><input class="button" name="submit_button" type="submit" value="'.get_lang("Ok").'" /></td>' . "\n";
  4774. $return .= "\t\t" . '</tr>' . "\n";
  4775. $return .= "\t" . '</table>' . "\n";
  4776. if($action == 'move')
  4777. {
  4778. $return .= "\t" . '<input name="title" type="hidden" value="' . $item_title . '" />' . "\n";
  4779. $return .= "\t" . '<input name="description" type="hidden" value="' . $item_description . '" />' . "\n";
  4780. }
  4781. if(is_numeric($extra_info))
  4782. {
  4783. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info . '" />' . "\n";
  4784. }
  4785. elseif(is_array($extra_info))
  4786. {
  4787. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />' . "\n";
  4788. }
  4789. $return .= "\t" . '<input name="type" type="hidden" value="'.TOOL_STUDENTPUBLICATION.'" />' . "\n";
  4790. $return .= "\t" . '<input name="post_time" type="hidden" value="' . time() . '" />' . "\n";
  4791. $return .= '</form>' . "\n";
  4792. $return .= '</div>' . "\n";
  4793. return $return;
  4794. }
  4795. /**
  4796. * Displays the menu for manipulating a step
  4797. *
  4798. * @return unknown
  4799. */
  4800. function display_manipulate($item_id, $item_type = TOOL_DOCUMENT)
  4801. {
  4802. $return = '<div class="lp_manipulate"><table border="0" width="100%"><tr><td valign="top" width="400">';
  4803. switch($item_type)
  4804. {
  4805. case 'dokeos_chapter':
  4806. case 'chapter':
  4807. $lang = get_lang('TitleManipulateChapter');
  4808. break;
  4809. case 'dokeos_module':
  4810. case 'module':
  4811. $lang = get_lang('TitleManipulateModule');
  4812. break;
  4813. case TOOL_DOCUMENT:
  4814. $lang = get_lang('TitleManipulateDocument');
  4815. break;
  4816. case TOOL_LINK:
  4817. case 'link':
  4818. $lang = get_lang('TitleManipulateLink');
  4819. break;
  4820. case TOOL_QUIZ:
  4821. $lang = get_lang('TitleManipulateQuiz');
  4822. break;
  4823. case TOOL_STUDENTPUBLICATION:
  4824. $lang = get_lang('TitleManipulateStudentPublication');
  4825. break;
  4826. }
  4827. $tbl_lp_item = Database::get_course_table('lp_item');
  4828. $sql = "
  4829. SELECT
  4830. description
  4831. FROM " . $tbl_lp_item . " as lp
  4832. WHERE
  4833. lp.id = " . $item_id;
  4834. $result = api_sql_query($sql, __FILE__, __LINE__);
  4835. $s_description=mysql_result($result,0,0);
  4836. $return .= '<p class="lp_title">' . $lang . '</p>';
  4837. $return .= '<a href="' . $_SERVER['PHP_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>';
  4838. $return .= '<a href="' . $_SERVER['PHP_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>';
  4839. $return .= '<a href="' . $_SERVER['PHP_SELF'] . '?cidReq=' . $_GET['cidReq'] . '&amp;action=delete_item&amp;view=build&amp;id=' . $item_id . '&amp;lp_id=' . $this->lp_id . '" onclick="return confirmation(\'' . $row['title'] . '\');" 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>';
  4840. //$return .= '<br><br><p class="lp_text">' . ((trim($s_description) == '') ? ''.get_lang("NoDescription").'' : stripslashes(nl2br($s_description))) . '</p>';
  4841. $return.="</td><td valign='top'>";
  4842. // get the audiorecorder. Use of ob_* functions since there are echos in the file
  4843. ob_start();
  4844. $audio_recorder_studentview = 'false';
  4845. $audio_recorder_item_id = $item_id;
  4846. if(api_get_setting('service_ppt2lp','active')=='true' && api_get_setting('service_ppt2lp','path_to_lzx')!=''){
  4847. include('audiorecorder.inc.php');
  4848. }
  4849. $return .= ob_get_contents();
  4850. ob_end_clean();
  4851. // end of audiorecorder include
  4852. $return.="</td></tr></table>";
  4853. $return .= '</div>';
  4854. return $return;
  4855. }
  4856. /**
  4857. * Creates the javascript needed for filling up the checkboxes without page reload
  4858. *
  4859. * @return string
  4860. */
  4861. function create_js()
  4862. {
  4863. $return = '<script language="javascript" type="text/javascript">' . "\n";
  4864. $return .= 'function load_cbo(id){' . "\n";
  4865. $return .= "var cbo = document.getElementById('idPosition');";
  4866. $return .= 'for(var i = cbo.length - 1; i > 0; i--)';
  4867. $return .= 'cbo.options[i] = null;';
  4868. $return .= 'for(var i = 1; i <= child_name[id].length; i++)';
  4869. $return .= 'cbo.options[i] = new Option(child_name[id][i-1], child_value[id][i-1]);';
  4870. $return .= '}' . "\n\n";
  4871. $return .= 'var child_name = new Array();' . "\n";
  4872. $return .= 'var child_value = new Array();' . "\n\n";
  4873. $return .= 'child_name[0] = new Array();' . "\n";
  4874. $return .= 'child_value[0] = new Array();' . "\n\n";
  4875. $tbl_lp_item = Database::get_course_table('lp_item');
  4876. $sql_zero = "
  4877. SELECT *
  4878. FROM " . $tbl_lp_item . "
  4879. WHERE
  4880. lp_id = " . $this->lp_id . " AND
  4881. parent_item_id = 0
  4882. ORDER BY display_order ASC";
  4883. $res_zero = api_sql_query($sql_zero, __FILE__, __LINE__);
  4884. $i = 0;
  4885. while($row_zero = Database::fetch_array($res_zero))
  4886. {
  4887. $return .= 'child_name[0][' . $i . '] = "'.get_lang("After").' \"' . $row_zero['title'] . '\"";' . "\n";
  4888. $return .= 'child_value[0][' . $i++ . '] = "' . $row_zero['id'] . '";' . "\n";
  4889. }
  4890. $return .= "\n";
  4891. $sql = "
  4892. SELECT *
  4893. FROM " . $tbl_lp_item . "
  4894. WHERE
  4895. lp_id = " . $this->lp_id;
  4896. $res = api_sql_query($sql, __FILE__, __LINE__);
  4897. while($row = Database::fetch_array($res))
  4898. {
  4899. $sql_parent = "
  4900. SELECT *
  4901. FROM " . $tbl_lp_item . "
  4902. WHERE parent_item_id = " . $row['id'] . "
  4903. ORDER BY display_order ASC";
  4904. $res_parent = api_sql_query($sql_parent, __FILE__, __LINE__);
  4905. $i = 0;
  4906. $return .= 'child_name[' . $row['id'] . '] = new Array();' . "\n";
  4907. $return .= 'child_value[' . $row['id'] . '] = new Array();' . "\n\n";
  4908. while($row_parent = Database::fetch_array($res_parent))
  4909. {
  4910. $return .= 'child_name[' . $row['id'] . '][' . $i . '] = "'.get_lang("After").' \"' . $row_parent['title'] . '\"";' . "\n";
  4911. $return .= 'child_value[' . $row['id'] . '][' . $i++ . '] = "' . $row_parent['id'] . '";' . "\n";
  4912. }
  4913. $return .= "\n";
  4914. }
  4915. $return .= '</script>' . "\n";
  4916. return $return;
  4917. }
  4918. /**
  4919. * Enter description here...
  4920. *
  4921. * @param unknown_type $item_id
  4922. * @return unknown
  4923. */
  4924. function display_move_item($item_id)
  4925. {
  4926. global $_course; //will disappear
  4927. $return = '';
  4928. if(is_numeric($item_id))
  4929. {
  4930. $tbl_lp_item = Database::get_course_table('lp_item');
  4931. $sql = "
  4932. SELECT *
  4933. FROM " . $tbl_lp_item . "
  4934. WHERE id = " . $item_id;
  4935. $res = api_sql_query($sql, __FILE__, __LINE__);
  4936. $row = Database::fetch_array($res);
  4937. switch($row['item_type'])
  4938. {
  4939. case 'dokeos_chapter':
  4940. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4941. $return .= $this->display_item_form($row['item_type'], 'Move the current chapter:', 'move', $item_id, $row);
  4942. break;
  4943. case 'dokeos_module':
  4944. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4945. $return .= $this->display_item_form($row['item_type'], 'Move th current module:', 'move', $item_id, $row);
  4946. break;
  4947. case TOOL_DOCUMENT:
  4948. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4949. $return .= $this->display_document_form('move', $item_id, $row);
  4950. break;
  4951. case TOOL_LINK:
  4952. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4953. $return .= $this->display_link_form('move', $item_id, $row);
  4954. break;
  4955. case TOOL_QUIZ:
  4956. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4957. $return .= $this->display_quiz_form('move', $item_id, $row);
  4958. break;
  4959. case TOOL_STUDENTPUBLICATION:
  4960. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4961. $return .= $this->display_student_publication_form('move', $item_id, $row);
  4962. break;
  4963. }
  4964. }
  4965. return $return;
  4966. }
  4967. /**
  4968. * Displays a basic form on the overview page for changing the item title and the item description.
  4969. *
  4970. * @param string $item_type
  4971. * @param string $title
  4972. * @param array $data
  4973. * @return string
  4974. */
  4975. function display_item_small_form($item_type, $title = '', $data)
  4976. {
  4977. $return .= '<div class="lp_small_form">' . "\n";
  4978. $return .= '<p class="lp_title">' . $title . '</p>';
  4979. $return .= '<form method="post">' . "\n";
  4980. $return .= '<table cellpadding="0" cellspacing="0" class="lp_form">';
  4981. $return .= "\t\t" . '<tr>' . "\n";
  4982. $return .= "\t\t\t" . '<td class="label"><label for="idTitle">Title:</label></td>' . "\n";
  4983. $return .= "\t\t\t" . '<td class="input"><input class="small_form" id="idTitle" name="title" type="text" value="' . $data['title'] . '" /></td>' . "\n";
  4984. $return .= "\t\t" . '</tr>' . "\n";
  4985. $return .= "\t\t" . '<tr>' . "\n";
  4986. $return .= "\t\t\t" . '<td class="label"><label for="idDescription">Description:</label></td>' . "\n";
  4987. $return .= "\t\t\t" . '<td class="input"><textarea class="small_form" id="idDescription" name="description" rows="4">' . $data['description'] . '</textarea></td>' . "\n";
  4988. $return .= "\t\t" . '</tr>' . "\n";
  4989. $return .= "\t\t" . '<tr>' . "\n";
  4990. $return .= "\t\t\t" . '<td colspan="2"><input class="button small_form" name="submit_button" type="submit" value="OK" /></td>' . "\n";
  4991. $return .= "\t\t" . '</tr>' . "\n";
  4992. $return .= "\t\t" . '</table>' . "\n";
  4993. $return .= "\t" . '<input name="parent" type="hidden" value="' . $data['parent_item_id'] . '"/>' . "\n";
  4994. $return .= "\t" . '<input name="previous" type="hidden" value="' . $data['previous_item_id'] . '"/>' . "\n";
  4995. $return .= '</form>';
  4996. $return .= '</div>';
  4997. return $return;
  4998. }
  4999. /**
  5000. * Enter description here...
  5001. *
  5002. * @param unknown_type $item_id
  5003. * @return unknown
  5004. */
  5005. function display_item_prerequisites_form($item_id)
  5006. {
  5007. $tbl_lp_item = Database::get_course_table('lp_item');
  5008. /* current prerequisite */
  5009. $sql = "
  5010. SELECT *
  5011. FROM " . $tbl_lp_item . "
  5012. WHERE id = " . $item_id;
  5013. $result = api_sql_query($sql, __FILE__, __LINE__);
  5014. $row = Database::fetch_array($result);
  5015. $preq_id = $row['prerequisite'];
  5016. $preq_min = $row['min_score'];
  5017. $preq_max = $row['max_score'];
  5018. $return = $this->display_manipulate($item_id, TOOL_DOCUMENT);
  5019. $return .= '<div style="margin:3px 10px;">';
  5020. $return .= '<p class="lp_title">'.get_lang("AddEditPrerequisites").'</p>';
  5021. $return .= '<form method="POST">';
  5022. $return .= '<table class="lp_form">';
  5023. $return .= '<tr>';
  5024. $return .= '<th></th>';
  5025. $return .= '<th class="exercise">'.get_lang("Minimum").'</th>';
  5026. $return .= '<th class="exercise">'.get_lang("Maximum").'</th>';
  5027. $return .= '</tr>';
  5028. $return .= '<tr>';
  5029. $return .= '<td class="radio" colspan="3">';
  5030. $return .= '<input checked="checked" id="idNone" name="prerequisites" style="margin-left:0; margin-right:10px;" type="radio" />';
  5031. $return .= '<label for="idNone">'.get_lang("None").'</label>';
  5032. $return .= '</td>';
  5033. $return .= '</tr>';
  5034. $sql = "
  5035. SELECT *
  5036. FROM " . $tbl_lp_item . "
  5037. WHERE
  5038. lp_id = " . $this->lp_id;
  5039. $result = api_sql_query($sql, __FILE__, __LINE__);
  5040. $arrLP = array();
  5041. while($row = Database::fetch_array($result))
  5042. {
  5043. $arrLP[] = array(
  5044. 'id' => $row['id'],
  5045. 'item_type' => $row['item_type'],
  5046. 'title' => $row['title'],
  5047. 'description' => $row['description'],
  5048. 'parent_item_id' => $row['parent_item_id'],
  5049. 'previous_item_id' => $row['previous_item_id'],
  5050. 'next_item_id' => $row['next_item_id'],
  5051. 'display_order' => $row['display_order']);
  5052. }
  5053. $this->tree_array($arrLP);
  5054. $arrLP = $this->arrMenu;
  5055. unset($this->arrMenu);
  5056. for($i = 0; $i < count($arrLP); $i++)
  5057. {
  5058. if($arrLP[$i]['id'] == $item_id)
  5059. break;
  5060. $return .= '<tr>';
  5061. $return .= '<td class="radio"' . (($arrLP[$i]['item_type'] != TOOL_QUIZ) ? ' colspan="3"' : '') . '>';
  5062. $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'] . '" />';
  5063. $return .= '<img alt="" src="../img/lp_' . $arrLP[$i]['item_type'] . '.png" style="margin-right:5px;" title="" />';
  5064. $return .= '<label for="id' . $arrLP[$i]['id'] . '">' . stripslashes($arrLP[$i]['title']) . '</label>';
  5065. $return .= '</td>';
  5066. if($arrLP[$i]['item_type'] == TOOL_QUIZ)
  5067. {
  5068. $return .= '<td class="exercise">';
  5069. $return .= '<input maxlength="3" name="min_' . $arrLP[$i]['id'] . '" type="text" value="' . (($arrLP[$i]['id'] == $preq_id) ? $preq_min : 0) . '" />';
  5070. $return .= '</td>';
  5071. $return .= '<td class="exercise">';
  5072. $return .= '<input maxlength="3" name="max_' . $arrLP[$i]['id'] . '" type="text" value="' . (($arrLP[$i]['id'] == $preq_id) ? $preq_max : 100) . '" />';
  5073. $return .= '</td>';
  5074. }
  5075. $return .= '</tr>';
  5076. }
  5077. $return .= '<tr>';
  5078. $return .= '<td colspan="3">';
  5079. $return .= '<input class="button" name="submit_button" type="submit" value="'.get_lang("Ok").'" /></td>' . "\n";
  5080. $return .= '</td>';
  5081. $return .= '</tr>';
  5082. $return .= '</table>';
  5083. $return .= '</form>';
  5084. $return .= '</div>';
  5085. return $return;
  5086. }
  5087. /**
  5088. * Creates a list with all the documents in it
  5089. *
  5090. * @return string
  5091. */
  5092. function get_documents()
  5093. {
  5094. global $_course;
  5095. $tbl_doc = Database::get_course_table(TABLE_DOCUMENT);
  5096. $sql_doc = "
  5097. SELECT *
  5098. FROM " . $tbl_doc . "
  5099. WHERE
  5100. path NOT LIKE '%_DELETED_%'
  5101. ORDER BY path ASC";
  5102. $res_doc = api_sql_query($sql_doc, __FILE__, __LINE__);
  5103. $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>';
  5104. $return .= '<div class="lp_resource_elements" id="resDoc">';
  5105. $resources=api_store_result($res_doc);
  5106. $return .=$this->write_resources_tree('', $resources);
  5107. $return .='</div>';
  5108. if(Database::num_rows($res_doc) == 0)
  5109. $return .= '<div class="lp_resource_element">'.get_lang("NoDocuments").'</div>';
  5110. return $return;
  5111. }
  5112. function write_resources_tree($parent, $resources_array_first = false){
  5113. static $resources_array;
  5114. if($resources_array_first !== false)
  5115. $resources_array = $resources_array_first;
  5116. while($value = current($resources_array))
  5117. {
  5118. if(strpos($value['path'], $parent)!==false || $parent=='')
  5119. {
  5120. $explode = explode('/', $value['path']);
  5121. $num = count($explode) - 2;
  5122. //It's a file
  5123. if ($value['filetype'] == 'file') {
  5124. if($num==0) $num=1;
  5125. $return .= '<div><div style="margin-left:' . ($num * 15) . 'px;margin-right:5px;"><a href="' . $_SERVER['PHP_SELF'] . '?cidReq=' . $_GET['cidReq'] . '&amp;action=add_item&amp;type=' . TOOL_DOCUMENT . '&amp;file=' . $value['id'] . '&amp;lp_id=' . $this->lp_id . '"><img align="left" alt="" src="../img/lp_' . (($value['filetype'] == 'file') ? TOOL_DOCUMENT.'_file' : 'folder') . '.gif" title="" />'.$value['title']."</a></div></div>\r\n";
  5126. array_shift($resources_array);
  5127. }
  5128. //It's a folder
  5129. else {
  5130. $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_'.$value["id"].'" onclick="testResources(\''.$value["id"].'\',\'img_'.$value["id"].'\')"><img alt="" src="../img/lp_' . (($value['filetype'] == 'file') ? TOOL_DOCUMENT.'_file' : 'folder') . '.gif" title="" align="absmiddle" /><span onclick="testResources(\''.$value["id"].'\',\'img_'.$value["id"].'\')" style="cursor: pointer;" >'.$value['title'].'</span></div><div style="display: none;" id="'.$value['id'].'">';
  5131. array_shift($resources_array);
  5132. $return .= $this->write_resources_tree($value['path']);
  5133. $return .= "</div></div>\r\n";
  5134. }
  5135. }
  5136. else
  5137. return $return;
  5138. }
  5139. return $return;
  5140. }
  5141. /**
  5142. * Creates a list with all the exercises (quiz) in it
  5143. *
  5144. * @return string
  5145. */
  5146. function get_exercises()
  5147. {
  5148. $tbl_quiz = Database::get_course_table(TABLE_QUIZ_TEST);
  5149. $sql_quiz = "
  5150. SELECT *
  5151. FROM " . $tbl_quiz . "
  5152. ORDER BY title ASC";
  5153. $res_quiz = api_sql_query($sql_quiz, __FILE__, __LINE__);
  5154. $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("Exercise").'</div>';
  5155. $return .= '<div class="lp_resource_elements_end" id="resExercise">';
  5156. while($row_quiz = Database::fetch_array($res_quiz))
  5157. {
  5158. $return .= '<div class="lp_resource_element">';
  5159. $return .= '<img alt="" src="../img/lp_' . TOOL_QUIZ . '.png" style="margin-right:5px;" title="" />';
  5160. $return .= '<a href="' . $_SERVER['PHP_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>';
  5161. //$return .= $row_quiz['title'];
  5162. $return .= '</div>';
  5163. }
  5164. if(Database::num_rows($res_quiz) == 0)
  5165. $return .= '<div class="lp_resource_element">'.get_lang("NoExercisesAvailable").'</div>';
  5166. $return .= '</div>';
  5167. return $return;
  5168. }
  5169. /**
  5170. * Creates a list with all the links in it
  5171. *
  5172. * @return string
  5173. */
  5174. function get_links()
  5175. {
  5176. $tbl_link = Database::get_course_table(TABLE_LINK);
  5177. $sql_link = "
  5178. SELECT *
  5179. FROM " . $tbl_link . "
  5180. ORDER BY title ASC";
  5181. $res_link = api_sql_query($sql_link, __FILE__, __LINE__);
  5182. $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>';
  5183. $return .= '<div class="lp_resource_elements" id="resLink">';
  5184. while($row_link = Database::fetch_array($res_link))
  5185. {
  5186. $return .= '<div class="lp_resource_element">';
  5187. $return .= '<img align="left" alt="" src="../img/lp_' . TOOL_LINK . '.png" style="margin-right:5px;" title="" />';
  5188. $return .= '<a href="' . $_SERVER['PHP_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>';
  5189. $return .= '</div>';
  5190. }
  5191. if(Database::num_rows($res_link) == 0)
  5192. $return .= '<div class="lp_resource_element">'.get_lang("NoLinksAvailable").'</div>';
  5193. $return .= '</div>';
  5194. return $return;
  5195. }
  5196. /**
  5197. * Creates a list with all the student publications in it
  5198. *
  5199. * @return unknown
  5200. */
  5201. function get_student_publications()
  5202. {
  5203. $tbl_student = Database::get_course_table(TABLE_STUDENT_PUBLICATION);
  5204. $sql_student = "
  5205. SELECT *
  5206. FROM " . $tbl_student . "
  5207. ORDER BY title ASC";
  5208. $res_student = api_sql_query($sql_student, __FILE__, __LINE__);
  5209. $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('Assignments').'</div>';
  5210. $return .= '<div class="lp_resource_elements" id="resStudent" style="border-bottom:1px solid #999999; border-top:0;">';
  5211. $return .= '<div class="lp_resource_element">';
  5212. $return .= '<img align="left" alt="" src="../img/lp_' . TOOL_STUDENTPUBLICATION . '.png" style="margin-right:5px;" title="" />';
  5213. $return .= '<a href="' . $_SERVER['PHP_SELF'] . '?cidReq=' . $_GET['cidReq'] . '&amp;action=add_item&amp;type=' . TOOL_STUDENTPUBLICATION . '&amp;lp_id=' . $this->lp_id . '">' . get_lang('AddAssignmentPage') . '</a>';
  5214. $return .= '</div>';
  5215. $return .= '</div>';
  5216. return $return;
  5217. }
  5218. function get_forums()
  5219. {
  5220. include ('../forum/forumfunction.inc.php');
  5221. include ('../forum/forumconfig.inc.php');
  5222. global $table_forums, $table_threads,$table_posts, $table_item_property, $table_users;
  5223. $table_forums = Database :: get_course_table(TABLE_FORUM);
  5224. $table_threads = Database :: get_course_table(TABLE_FORUM_THREAD);
  5225. $table_posts = Database :: get_course_table(TABLE_FORUM_POST);
  5226. $table_item_property = Database :: get_course_table(TABLE_ITEM_PROPERTY);
  5227. $table_users = Database :: get_main_table(TABLE_MAIN_USER);
  5228. $a_forums = get_forums();
  5229. $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>';
  5230. $return .= '<div class="lp_resource_elements" id="forums" style="border-bottom:1px solid #999999; border-top:0;">';
  5231. foreach($a_forums as $forum)
  5232. {
  5233. $return .= '<div class="lp_resource_element">';
  5234. $return .= '<script type="text/javascript">
  5235. function toggle_forum(forum_id){
  5236. if(document.getElementById("forum_"+forum_id+"_content").style.display == "none"){
  5237. document.getElementById("forum_"+forum_id+"_content").style.display = "block";
  5238. document.getElementById("forum_"+forum_id+"_opener").src = "'.api_get_path(WEB_IMG_PATH).'remove.gif";
  5239. }
  5240. else {
  5241. document.getElementById("forum_"+forum_id+"_content").style.display = "none";
  5242. document.getElementById("forum_"+forum_id+"_opener").src = "'.api_get_path(WEB_IMG_PATH).'add.gif";
  5243. }
  5244. }
  5245. </script>
  5246. ';
  5247. $return .= '<img align="left" alt="" src="../img/lp_forum.gif" style="margin-right:5px;" title="" />';
  5248. $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>
  5249. <a href="' . $_SERVER['PHP_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">';
  5250. $a_threads = get_threads($forum['forum_id']);
  5251. foreach($a_threads as $thread)
  5252. {
  5253. $return .= '<li><a href="' . $_SERVER['PHP_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>';
  5254. }
  5255. $return .= '</ul></div>';
  5256. }
  5257. return $return;
  5258. }
  5259. /**
  5260. * Exports the learning path as a SCORM package. This is the main function that
  5261. * gathers the content, transforms it, writes the imsmanifest.xml file, zips the
  5262. * whole thing and returns the zip.
  5263. *
  5264. * This method needs to be called in PHP5, as it will fail with non-adequate
  5265. * XML package (like the ones for PHP4), and it is *not* a static method, so
  5266. * you need to call it on a learnpath object.
  5267. * @TODO The method might be redefined later on in the scorm class itself to avoid
  5268. * creating a SCORM structure if there is one already. However, if the initial SCORM
  5269. * path has been modified, it should use the generic method here below.
  5270. * @TODO link this function with the export_lp() function in the same class
  5271. * @param string Optional name of zip file. If none, title of learnpath is
  5272. * domesticated and trailed with ".zip"
  5273. * @return string Returns the zip package string, or null if error
  5274. */
  5275. function scorm_export()
  5276. {
  5277. global $_course;
  5278. if (!class_exists('DomDocument'))
  5279. {
  5280. error_log('DOM functions not supported for PHP version below 5.0',0);
  5281. $this->error = 'PHP DOM functions not supported for PHP versions below 5.0';
  5282. return null;
  5283. }
  5284. //Create the zip handler (this will remain available throughout the method)
  5285. $temp_dir_short = uniqid();
  5286. $temp_zip_dir = api_get_path(GARBAGE_PATH)."/".$temp_dir_short;
  5287. $temp_zip_file = $temp_zip_dir."/".md5(time()).".zip";
  5288. $zip_folder=new PclZip($temp_zip_file);
  5289. $current_course_path = api_get_path(SYS_COURSE_PATH).api_get_course_path();
  5290. $root_path = api_get_path(SYS_PATH);
  5291. $rel_path = api_get_path(REL_PATH);
  5292. if($rel_path === '/')
  5293. {
  5294. $rel_path = '';
  5295. }
  5296. $main_path = $root_path.$rel_path;
  5297. //place to temporarily stash the zipfiles
  5298. //create the temp dir if it doesn't exist
  5299. //or do a cleanup befor creating the zipfile
  5300. if(!is_dir($temp_zip_dir))
  5301. {
  5302. mkdir($temp_zip_dir);
  5303. }
  5304. else
  5305. {//cleanup: check the temp dir for old files and delete them
  5306. $handle=opendir($temp_zip_dir);
  5307. while (false!==($file = readdir($handle)))
  5308. {
  5309. if ($file != "." && $file != "..")
  5310. {
  5311. unlink("$temp_zip_dir/$file");
  5312. }
  5313. }
  5314. closedir($handle);
  5315. }
  5316. //Build a dummy imsmanifest structure. Do not add to the zip yet (we still need it)
  5317. //This structure is developed following regulations for SCORM 1.2 packaging in the SCORM 1.2 Content
  5318. //Aggregation Model official document, secion "2.3 Content Packaging"
  5319. $xmldoc = new DOMDocument('1.0',$this->encoding);
  5320. $root = $xmldoc->createElement('manifest');
  5321. $root->setAttribute('identifier','SingleCourseManifest');
  5322. $root->setAttribute('version','1.1');
  5323. $root->setAttribute('xmlns','http://www.imsproject.org/xsd/imscp_rootv1p1p2');
  5324. $root->setAttribute('xmlns:adlcp','http://www.adlnet.org/xsd/adlcp_rootv1p2');
  5325. $root->setAttribute('xmlns:xsi','http://www.w3.org/2001/XMLSchema-instance');
  5326. $root->setAttribute('xsi:schemaLocation','http://www.omsproject.org/xsd/imscp_rootv1p1p2 imscp_rootv1p1p2.xsd
  5327. http://www.imsglobal.org/xsd/imsmd_rootv1p2p1 imsmd_rootv1p2p1.xsd
  5328. http://www.adlnet.org/xsd/adlcp_rootv1p2 adlcp_rootv1p2.xsd');
  5329. //Build mandatory sub-root container elements
  5330. $metadata = $xmldoc->createElement('metadata');
  5331. $md_schema = $xmldoc->createElement('schema','ADL SCORM');
  5332. $metadata->appendChild($md_schema);
  5333. $md_schemaversion = $xmldoc->createElement('schemaversion','1.2');
  5334. $metadata->appendChild($md_schemaversion);
  5335. $root->appendChild($metadata);
  5336. $organizations = $xmldoc->createElement('organizations');
  5337. $resources = $xmldoc->createElement('resources');
  5338. //Build the only organization we will use in building our learnpaths
  5339. $organizations->setAttribute('default','dokeos_scorm_export');
  5340. $organization = $xmldoc->createElement('organization');
  5341. $organization->setAttribute('identifier','dokeos_scorm_export');
  5342. $org_title = $xmldoc->createElement('title',htmlspecialchars($this->get_name(),ENT_QUOTES)); //filter data for XML?
  5343. $organization->appendChild($org_title);
  5344. //For each element, add it to the imsmanifest structure, then add it to the zip.
  5345. //Always call the learnpathItem->scorm_export() method to change it to the SCORM
  5346. //format
  5347. $zip_files = array();
  5348. $zip_files_abs = array();
  5349. $link_updates = array();
  5350. foreach($this->items as $index => $item){
  5351. //get included documents from this item
  5352. $inc_docs = $item->get_resources_from_source();
  5353. //error_log('Dealing with document '.$item->get_file_path().', found included documents: '.print_r($inc_docs,true),0);
  5354. //give a child element <item> to the <organization> element
  5355. $my_item = $xmldoc->createElement('item');
  5356. $my_item->setAttribute('identifier','ITEM_'.$item->get_id());
  5357. $my_item->setAttribute('identifierref','RESOURCE_'.$item->get_id());
  5358. $my_item->setAttribute('isvisible','true');
  5359. //give a child element <title> to the <item> element
  5360. $my_title = $xmldoc->createElement('title',htmlspecialchars($item->get_title(),ENT_QUOTES));
  5361. $my_item->appendChild($my_title);
  5362. //give a child element <adlcp:prerequisite> to the <item> element
  5363. $my_prereqs = $xmldoc->createElement('adlcp:prerequisite',$item->get_prereq_string());
  5364. $my_prereqs->setAttribute('type','aicc_script');
  5365. $my_item->appendChild($my_prereqs);
  5366. //give a child element <adlcp:maxtimeallowed> to the <item> element - not yet supported
  5367. //$xmldoc->createElement('adlcp:maxtimeallowed','');
  5368. //give a child element <adlcp:timelimitaction> to the <item> element - not yet supported
  5369. //$xmldoc->createElement('adlcp:timelimitaction','');
  5370. //give a child element <adlcp:datafromlms> to the <item> element - not yet supported
  5371. //$xmldoc->createElement('adlcp:datafromlms','');
  5372. //give a child element <adlcp:masteryscore> to the <item> element
  5373. $my_masteryscore = $xmldoc->createElement('adlcp:masteryscore',$item->masteryscore);
  5374. $my_item->appendChild($my_masteryscore);
  5375. //attache this item to the organization element
  5376. $organization->appendChild($my_item);
  5377. //get the path of the file(s) from the course directory root
  5378. $my_file_path = $item->get_file_path();
  5379. $my_xml_file_path = htmlentities($my_file_path);
  5380. $my_sub_dir = dirname($my_file_path);
  5381. $my_xml_sub_dir = htmlentities($my_sub_dir);
  5382. //give a <resource> child to the <resources> element
  5383. $my_resource = $xmldoc->createElement('resource');
  5384. $my_resource->setAttribute('identifier','RESOURCE_'.$item->get_id());
  5385. $my_resource->setAttribute('type','webcontent');
  5386. $my_resource->setAttribute('href',$my_xml_file_path);
  5387. //adlcp:scormtype can be either 'sco' or 'asset'
  5388. $my_resource->setAttribute('adlcp:scormtype','asset');
  5389. //xml:base is the base directory to find the files declared in this resource
  5390. $my_resource->setAttribute('xml:base','');
  5391. //give a <file> child to the <resource> element
  5392. $my_file = $xmldoc->createElement('file');
  5393. $my_file->setAttribute('href',$my_xml_file_path);
  5394. $my_resource->appendChild($my_file);
  5395. //dependency to other files - not yet supported
  5396. $i = 1;
  5397. foreach($inc_docs as $doc_info)
  5398. {
  5399. if(count($doc_info)<1 or empty($doc_info[0])){continue;}
  5400. $my_dep = $xmldoc->createElement('resource');
  5401. $res_id = 'RESOURCE_'.$item->get_id().'_'.$i;
  5402. $my_dep->setAttribute('identifier',$res_id);
  5403. $my_dep->setAttribute('type','webcontent');
  5404. $my_dep->setAttribute('adlc:scormtype','asset');
  5405. $my_dep_file = $xmldoc->createElement('file');
  5406. //check type of URL
  5407. //error_log('Now dealing with '.$doc_info[0].' of type '.$doc_info[1].'-'.$doc_info[2],0);
  5408. if($doc_info[1] == 'remote')
  5409. { //remote file. Save url as is
  5410. $my_dep_file->setAttribute('href',$doc_info[0]);
  5411. $my_dep->setAttribute('xml:base','');
  5412. }elseif($doc_info[1] == 'local'){
  5413. switch($doc_info[2])
  5414. {
  5415. case 'url': //local URL - save path as url for now, don't zip file
  5416. $my_dep_file->setAttribute('href',$doc_info[0]);
  5417. $my_dep->setAttribute('xml:base','');
  5418. break;
  5419. case 'abs': //absolute path from DocumentRoot. Save file and leave path as is in the zip
  5420. $my_dep_file->setAttribute('href',$doc_info[0]);
  5421. $my_dep->setAttribute('xml:base','');
  5422. $zip_files_abs[] = $doc_info[0];
  5423. $current_dir = dirname($current_course_path.'/'.$item->get_file_path()).'/';
  5424. $file_path = realpath($doc_info[0]);
  5425. if(strstr($file_path,$main_path) !== false)
  5426. {//the calculated real path is really inside the dokeos root path
  5427. //reduce file path to what's under the DocumentRoot
  5428. $file_path = substr($file_path,strlen($root_path));
  5429. //error_log('Reduced path: '.$file_path,0);
  5430. $zip_files_abs[] = $file_path;
  5431. $link_updates[$my_file_path][] = array('orig'=>$doc_info[0],'dest'=>$file_path);
  5432. $my_dep_file->setAttribute('href','document/'.$file_path);
  5433. $my_dep->setAttribute('xml:base','');
  5434. }
  5435. break;
  5436. 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
  5437. if(substr($doc_info[0],0,2)=='..')
  5438. { //relative path going up
  5439. $current_dir = dirname($current_course_path.'/'.$item->get_file_path()).'/';
  5440. $file_path = realpath($current_dir.$doc_info[0]);
  5441. //error_log($file_path.' <-> '.$main_path,0);
  5442. if(strstr($file_path,$main_path) !== false)
  5443. {//the calculated real path is really inside the dokeos root path
  5444. //reduce file path to what's under the DocumentRoot
  5445. $file_path = substr($file_path,strlen($root_path));
  5446. //error_log('Reduced path: '.$file_path,0);
  5447. $zip_files_abs[] = $file_path;
  5448. $link_updates[$my_file_path][] = array('orig'=>$doc_info[0],'dest'=>$file_path);
  5449. $my_dep_file->setAttribute('href','document/'.$file_path);
  5450. $my_dep->setAttribute('xml:base','');
  5451. }
  5452. }else{
  5453. $zip_files[] = $my_sub_dir.'/'.$doc_info[0];
  5454. $my_dep_file->setAttribute('href',$doc_info[0]);
  5455. $my_dep->setAttribute('xml:base',$my_xml_sub_dir);
  5456. }
  5457. break;
  5458. default:
  5459. $my_dep_file->setAttribute('href',$doc_info[0]);
  5460. $my_dep->setAttribute('xml:base','');
  5461. break;
  5462. }
  5463. }
  5464. $my_dep->appendChild($my_dep_file);
  5465. $resources->appendChild($my_dep);
  5466. $dependency = $xmldoc->createElement('dependency');
  5467. $dependency->setAttribute('identifierref',$res_id);
  5468. $my_resource->appendChild($dependency);
  5469. $i++;
  5470. }
  5471. //$my_dependency = $xmldoc->createElement('dependency');
  5472. //$my_dependency->setAttribute('identifierref','');
  5473. $resources->appendChild($my_resource);
  5474. $zip_files[] = $my_file_path;
  5475. //error_log('File '.$my_file_path. ' added to $zip_files',0);
  5476. }
  5477. $organizations->appendChild($organization);
  5478. $root->appendChild($organizations);
  5479. $root->appendChild($resources);
  5480. $xmldoc->appendChild($root);
  5481. //error_log(print_r($zip_files,true),0);
  5482. $garbage_path = api_get_path(GARBAGE_PATH);
  5483. $sys_course_path = api_get_path(SYS_COURSE_PATH);
  5484. foreach($zip_files as $file_path)
  5485. {
  5486. if(empty($file_path)){continue;}
  5487. //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);
  5488. $dest_file = $garbage_path.$temp_dir_short.'/'.$file_path;
  5489. $this->create_path($dest_file);
  5490. //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);
  5491. copy($sys_course_path.$_course['path'].'/'.$file_path,$dest_file);
  5492. //check if the file needs a link update
  5493. if(in_array($file_path,array_keys($link_updates))){
  5494. $string = file_get_contents($dest_file);
  5495. unlink($dest_file);
  5496. foreach($link_updates[$file_path] as $old_new)
  5497. {
  5498. //error_log('Replacing '.$old_new['orig'].' by '.$old_new['dest'].' in '.$file_path,0);
  5499. $string = str_replace($old_new['orig'],$old_new['dest'],$string);
  5500. }
  5501. file_put_contents($dest_file,$string);
  5502. }
  5503. $zip_folder->add($dest_file,PCLZIP_OPT_REMOVE_PATH, $garbage_path);
  5504. }
  5505. foreach($zip_files_abs as $file_path)
  5506. {
  5507. if(empty($file_path)){continue;}
  5508. //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);
  5509. $dest_file = $garbage_path.$temp_dir_short.'/document/'.$file_path;
  5510. $this->create_path($dest_file);
  5511. //error_log('Created path '.api_get_path('GARBAGE_PATH').$temp_dir_short.'/document/'.$file_path,0);
  5512. //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);
  5513. copy($main_path.$file_path,$dest_file);
  5514. //check if the file needs a link update
  5515. if(in_array($file_path,array_keys($link_updates))){
  5516. $string = file_get_contents($dest_file);
  5517. unlink($dest_file);
  5518. foreach($link_updates[$file_path] as $old_new)
  5519. {
  5520. //error_log('Replacing '.$old_new['orig'].' by '.$old_new['dest'].' in '.$file_path,0);
  5521. $string = str_replace($old_new['orig'],$old_new['dest'],$string);
  5522. }
  5523. file_put_contents($dest_file,$string);
  5524. }
  5525. $zip_folder->add($dest_file,PCLZIP_OPT_REMOVE_PATH, $garbage_path);
  5526. }
  5527. //Finalize the imsmanifest structure, add to the zip, then return the zip
  5528. $xmldoc->save($garbage_path.'/'.$temp_dir_short.'/imsmanifest.xml');
  5529. $zip_folder->add($garbage_path.'/'.$temp_dir_short.'/imsmanifest.xml',PCLZIP_OPT_REMOVE_PATH, $garbage_path.'/');
  5530. //Send file to client
  5531. $name = 'scorm_export_'.$this->lp_id.'.zip';
  5532. DocumentManager::file_send_for_download($temp_zip_file,true,$name);
  5533. }
  5534. /**
  5535. * Temp function to be moved in main_api or the best place around for this. Creates a file path
  5536. * if it doesn't exist
  5537. */
  5538. function create_path($path){
  5539. $path_bits = split('/',dirname($path));
  5540. $path_built = '/';
  5541. foreach($path_bits as $bit){
  5542. if(!empty($bit)){
  5543. $new_path = $path_built.$bit;
  5544. if(is_dir($new_path)){
  5545. $path_built = $new_path.'/';
  5546. }
  5547. else
  5548. {
  5549. mkdir($new_path);
  5550. $path_built = $new_path.'/';
  5551. }
  5552. }
  5553. }
  5554. }
  5555. }
  5556. ?>