learnpath.class.php 184 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291
  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(MAIN_COURSE_TABLE);
  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(MAIN_USER_TABLE);
  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)
  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 = (int) $parent;
  323. $sql_count = "
  324. SELECT COUNT(id) AS num
  325. FROM " . $tbl_lp_item . "
  326. WHERE
  327. lp_id = " . $this->get_id() . " AND
  328. parent_item_id = " . $parent;
  329. $res_count = api_sql_query($sql_count, __FILE__, __LINE__);
  330. $row = Database::fetch_array($res_count);
  331. $num = $row['num'];
  332. if($num > 0)
  333. {
  334. if($previous == 0)
  335. {
  336. $sql = "
  337. SELECT
  338. id,
  339. next_item_id,
  340. display_order
  341. FROM " . $tbl_lp_item . "
  342. WHERE
  343. lp_id = " . $this->get_id() . " AND
  344. parent_item_id = " . $parent . " AND
  345. previous_item_id = 0";
  346. $result = api_sql_query($sql, __FILE__, __LINE__);
  347. $row = Database::fetch_array($result);
  348. $tmp_previous = 0;
  349. $next = $row['id'];
  350. $display_order = 0;
  351. }
  352. else
  353. {
  354. $previous = (int) $previous;
  355. $sql = "
  356. SELECT
  357. id,
  358. previous_item_id,
  359. next_item_id,
  360. display_order
  361. FROM " . $tbl_lp_item . "
  362. WHERE
  363. lp_id = " . $this->get_id() . " AND
  364. id = " . $previous;
  365. $result = api_sql_query($sql, __FILE__, __LINE__);
  366. $row = Database::fetch_array($result);
  367. $tmp_previous = $row['id'];
  368. $next = $row['next_item_id'];
  369. $display_order = $row['display_order'];
  370. }
  371. }
  372. else
  373. {
  374. $tmp_previous = 0;
  375. $next = 0;
  376. $display_order = 0;
  377. }
  378. $new_item_id = -1;
  379. $id = $this->escape_string($id);
  380. //insert new item
  381. $sql_ins = "
  382. INSERT INTO " . $tbl_lp_item . " (
  383. lp_id,
  384. item_type,
  385. ref,
  386. title,
  387. description,
  388. path,
  389. parent_item_id,
  390. previous_item_id,
  391. next_item_id,
  392. display_order
  393. ) VALUES (
  394. " . $this->get_id() . ",
  395. '" . $type . "',
  396. '',
  397. '" . $this->escape_string(htmlentities($title)) . "',
  398. '" . $this->escape_string(htmlentities($description)) . "',
  399. '" . $id . "',
  400. " . $parent . ",
  401. " . $previous . ",
  402. " . $next . ",
  403. " . ($display_order + 1) . "
  404. )";
  405. //echo $sql_ins; // for debug
  406. if($this->debug>2){error_log('New LP - Inserting dokeos_chapter: '.$sql_ins,0);}
  407. $res_ins = api_sql_query($sql_ins, __FILE__, __LINE__);
  408. if($res_ins > 0)
  409. {
  410. $new_item_id = Database::get_last_insert_id($res_ins);
  411. //update the item that should come after the new item
  412. $sql_update_next = "
  413. UPDATE " . $tbl_lp_item . "
  414. SET previous_item_id = " . $new_item_id . "
  415. WHERE id = " . $next;
  416. $res_update_next = api_sql_query($sql_update_next, __FILE__, __LINE__);
  417. //update the item that should be before the new item
  418. $sql_update_previous = "
  419. UPDATE " . $tbl_lp_item . "
  420. SET next_item_id = " . $new_item_id . "
  421. WHERE id = " . $tmp_previous;
  422. $res_update_previous = api_sql_query($sql_update_previous, __FILE__, __LINE__);
  423. //update all the items after the new item
  424. $sql_update_order = "
  425. UPDATE " . $tbl_lp_item . "
  426. SET display_order = display_order + 1
  427. WHERE
  428. lp_id = " . $this->get_id() . " AND
  429. id <> " . $new_item_id . " AND
  430. parent_item_id = " . $parent . " AND
  431. display_order > " . $display_order;
  432. $res_update_previous = api_sql_query($sql_update_order, __FILE__, __LINE__);
  433. }
  434. return $new_item_id;
  435. }
  436. /**
  437. * Adds an item to the current learnpath
  438. * @param integer Parent ID
  439. * @param integer Previous elem ID (0 if first)
  440. * @param string Resource type to add ('file','dokeos_item')
  441. * @param string Resource ID or path if 'file' or name if 'dokeos_chapter'
  442. * @return integer New element ID
  443. */
  444. function old_add_item($parent, $previous, $type = 'dokeos_chapter', $id, $title)
  445. {
  446. //TODO
  447. if($this->debug>0){error_log('New LP - In learnpath::add_item('.$parent.','.$previous.','.$type.','.$id.','.$title.')',0);}
  448. $tbl_lp_item = Database::get_course_table('lp_item');
  449. $parent = (int) $parent;
  450. $display_order = 1;
  451. if($previous == -1){
  452. //insert in latest position available
  453. $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;
  454. if($this->debug>1){error_log('New LP - checking for latest item at this level: '.$sql_check,0);}
  455. $res = mysql_query($sql_check) or die(mysql_error());
  456. $res_check = api_sql_query($sql_check, __FILE__, __LINE__);
  457. $num = Database::num_rows($res_check);
  458. if($num>0){
  459. $row = Database::fetch_array($res_check);
  460. $previous = $row['id'];
  461. }else{
  462. $previous = 0;
  463. }
  464. }else{
  465. $previous = (int) $previous;
  466. }
  467. $new_item_id = -1;
  468. //check type
  469. switch ($type){
  470. case 'dokeos_step':
  471. $id = $this->escape_string($id);
  472. //check the next item
  473. $sql_check = "SELECT * FROM $tbl_lp_item " .
  474. "WHERE lp_id = ".$this->get_id()." " .
  475. "AND previous_item_id = $previous " .
  476. "AND parent_item_id = $parent";
  477. if($this->debug>2){error_log('New LP - Getting info from the next element: '.$sql_check,0);}
  478. $res_check = api_sql_query($sql_check);
  479. if(Database::num_rows($res_check)){
  480. $row = Database::fetch_array($res_check);
  481. $next = $row['id'];
  482. //TODO check display_order
  483. $display_order = $row['display_order']+1;
  484. }else{
  485. $next = 0;
  486. $display_order = 1;
  487. }
  488. //insert new item
  489. $sql_ins = "INSERT INTO $tbl_lp_item " .
  490. "(lp_id,item_type,ref,title," .
  491. "path,parent_item_id," .
  492. "previous_item_id,next_item_id,display_order)" .
  493. "VALUES" .
  494. "(".$this->get_id().",'$type','','$title','$id'," .
  495. "$parent," .
  496. "$previous,$next,$display_order)";
  497. if($this->debug>2){error_log('New LP - Inserting dokeos_chapter: '.$sql_ins,0);}
  498. $res_ins = api_sql_query($sql_ins);
  499. if($res_ins>0){
  500. $new_item_id = Database::get_last_insert_id($res_ins);
  501. //now update previous item
  502. $sql_upd = "UPDATE $tbl_lp_item " .
  503. "SET next_item_id = $new_item_id " .
  504. "WHERE lp_id = ".$this->get_id()." " .
  505. "AND id = $previous AND parent_item_id = $parent";
  506. if($this->debug>2){error_log('New LP - Updating previous item: '.$sql_upd,0);}
  507. $res_upd = api_sql_query($sql_upd);
  508. //now update next item
  509. $sql_upd = "UPDATE $tbl_lp_item " .
  510. "SET previous_item_id = $new_item_id " .
  511. "WHERE lp_id = ".$this->get_id()." " .
  512. "AND id = $next AND parent_item_id = $parent";
  513. if($this->debug>2){error_log('New LP - Updating next item: '.$sql_upd,0);}
  514. $res_upd = api_sql_query($sql_upd);
  515. }
  516. break;
  517. default:
  518. break;
  519. }
  520. return $new_item_id;
  521. }
  522. /**
  523. * Static admin function allowing addition of a learnpath to a course.
  524. * @param string Course code
  525. * @param string Learnpath name
  526. * @param string Learnpath description string, if provided
  527. * @param string Type of learnpath (default = 'guess', others = 'dokeos', 'aicc',...)
  528. * @param string Type of files origin (default = 'zip', others = 'dir','web_dir',...)
  529. * @param string Zip file containing the learnpath or directory containing the learnpath
  530. * @return integer The new learnpath ID on success, 0 on failure
  531. */
  532. function add_lp($course,$name,$description='',$learnpath='guess',$origin='zip',$zipname='')
  533. {
  534. //if($this->debug>0){error_log('New LP - In learnpath::add_lp()',0);}
  535. //TODO
  536. $tbl_lp = Database::get_course_table('lp');
  537. //check course code exists
  538. //check lp_name doesn't exist, otherwise append something
  539. $i = 0;
  540. $name = learnpath::escape_string(htmlentities($name)); //Kevin Van Den Haute: added htmlentities()
  541. $check_name = "SELECT * FROM $tbl_lp WHERE name = '$name'";
  542. //if($this->debug>2){error_log('New LP - Checking the name for new LP: '.$check_name,0);}
  543. $res_name = api_sql_query($check_name);
  544. while(Database::num_rows($res_name)){
  545. //there is already one such name, update the current one a bit
  546. $i++;
  547. $name = $name.' - '.$i;
  548. $check_name = "SELECT * FROM $tbl_lp WHERE name = '$name'";
  549. //if($this->debug>2){error_log('New LP - Checking the name for new LP: '.$check_name,0);}
  550. $res_name = api_sql_query($check_name);
  551. }
  552. //new name does not exist yet; keep it
  553. //escape description
  554. $description = learnpath::escape_string(htmlentities($description)); //Kevin: added htmlentities()
  555. $type = 1;
  556. switch($learnpath){
  557. case 'guess':
  558. break;
  559. case 'dokeos':
  560. $type = 1;
  561. break;
  562. case 'aicc':
  563. break;
  564. }
  565. switch($origin){
  566. case 'zip':
  567. //check zipname string. If empty, we are currently creating a new Dokeos learnpath
  568. break;
  569. case 'manual':
  570. $get_max = "SELECT MAX(display_order) FROM $tbl_lp";
  571. $res_max = api_sql_query($get_max);
  572. if(Database::num_rows($res_max)<1){
  573. $dsp = 1;
  574. }else{
  575. $row = Database::fetch_array($res_max);
  576. $dsp = $row[0]+1;
  577. }
  578. $sql_insert = "INSERT INTO $tbl_lp " .
  579. "(lp_type,name,description,path,default_view_mod," .
  580. "default_encoding,display_order,content_maker," .
  581. "content_local,js_lib) " .
  582. "VALUES ($type,'$name','$description','','embedded'," .
  583. "'ISO-8859-1','$dsp','Dokeos'," .
  584. "'local','')";
  585. //if($this->debug>2){error_log('New LP - Inserting new lp '.$sql_insert,0);}
  586. $res_insert = api_sql_query($sql_insert);
  587. $id = Database::get_last_insert_id();
  588. if($id>0){
  589. return $id;
  590. }
  591. break;
  592. }
  593. }
  594. /**
  595. * Appends a message to the message attribute
  596. * @param string Message to append.
  597. */
  598. function append_message($string)
  599. {
  600. if($this->debug>0){error_log('New LP - In learnpath::append_message()',0);}
  601. $this->message .= $string;
  602. }
  603. /**
  604. * Autocompletes the parents of an item in case it's been completed or passed
  605. * @param integer Optional ID of the item from which to look for parents
  606. */
  607. function autocomplete_parents($item)
  608. {
  609. if($this->debug>0){error_log('New LP - In learnpath::autocomplete_parents()',0);}
  610. if(empty($item)){
  611. $item = $this->current;
  612. }
  613. $parent_id = $this->items[$item]->get_parent();
  614. if($this->debug>2){error_log('New LP - autocompleting parent of item '.$item.' (item '.$parent_id.')',0);}
  615. if(is_object($this->items[$item]) and !empty($parent_id))
  616. {//if $item points to an object and there is a parent
  617. if($this->debug>2){error_log('New LP - '.$item.' is an item, proceed',0);}
  618. $current_item =& $this->items[$item];
  619. $parent =& $this->items[$parent_id]; //get the parent
  620. //new experiment including failed and browsed in completed status
  621. $current_status = $current_item->get_status();
  622. if($current_item->is_done() || $current_status=='browsed' || $current_status=='failed'){
  623. //if the current item is completed or passes or succeeded
  624. $completed = true;
  625. if($this->debug>2){error_log('New LP - Status of current item is alright',0);}
  626. foreach($parent->get_children() as $child){
  627. //check all his brothers (his parent's children) for completion status
  628. if($child!= $item){
  629. if($this->debug>2){error_log('New LP - Looking at brother with ID '.$child.', status is '.$this->items[$child]->get_status(),0);}
  630. //if($this->items[$child]->status_is(array('completed','passed','succeeded')))
  631. //Trying completing parents of failed and browsed items as well
  632. if($this->items[$child]->status_is(array('completed','passed','succeeded','browsed','failed')))
  633. {
  634. //keep completion status to true
  635. }else{
  636. if($this->debug>2){error_log('New LP - Found one incomplete child of '.$parent_id.': '.$child.' is '.$this->items[$child]->get_status(),0);}
  637. $completed = false;
  638. }
  639. }
  640. }
  641. if($completed == true){ //if all the children were completed
  642. $parent->set_status('completed');
  643. $parent->save(false);
  644. $this->update_queue[$parent->get_id()] = $parent->get_status();
  645. if($this->debug>2){error_log('New LP - Added parent to update queue '.print_r($this->update_queue,true),0);}
  646. $this->autocomplete_parents($parent->get_id()); //recursive call
  647. }
  648. }else{
  649. //error_log('New LP - status of current item is not enough to get bothered',0);
  650. }
  651. }
  652. }
  653. /**
  654. * Autosaves the current results into the database for the whole learnpath
  655. */
  656. function autosave()
  657. {
  658. if($this->debug>0){error_log('New LP - In learnpath::autosave()',0);}
  659. //TODO add aditionnal save operations for the learnpath itself
  660. }
  661. /**
  662. * Clears the message attribute
  663. */
  664. function clear_message()
  665. {
  666. if($this->debug>0){error_log('New LP - In learnpath::clear_message()',0);}
  667. $this->message = '';
  668. }
  669. /**
  670. * Closes the current resource
  671. *
  672. * Stops the timer
  673. * Saves into the database if required
  674. * Clears the current resource data from this object
  675. * @return boolean True on success, false on failure
  676. */
  677. function close()
  678. {
  679. if($this->debug>0){error_log('New LP - In learnpath::close()',0);}
  680. if(empty($this->lp_id))
  681. {
  682. $this->error = 'Trying to close this learnpath but no ID is set';
  683. return false;
  684. }
  685. $this->current_time_stop = time();
  686. if($this->save)
  687. {
  688. $learnpath_view_table = Database::get_course_table(LEARNPATH_VIEW_TABLE);
  689. /*
  690. $sql = "UPDATE $learnpath_view_table " .
  691. "SET " .
  692. "stop_time = ".$this->current_time_stop.", " .
  693. "score = ".$this->current_score.", ".
  694. "WHERE learnpath_id = '".$this->lp_id."'";
  695. //$res = Database::query($sql);
  696. $res = api_sql_query($res);
  697. if(mysql_affected_rows($res)<1)
  698. {
  699. $this->error = 'Could not update learnpath_view table while closing learnpath';
  700. return false;
  701. }
  702. */
  703. }
  704. $this->ordered_items = array();
  705. $this->index=0;
  706. unset($this->lp_id);
  707. //unset other stuff
  708. return true;
  709. }
  710. /**
  711. * Static admin function allowing removal of a learnpath
  712. * @param string Course code
  713. * @param integer Learnpath ID
  714. * @param string Whether to delete data or keep it (default: 'keep', others: 'remove')
  715. * @return boolean True on success, false on failure (might change that to return number of elements deleted)
  716. */
  717. function delete($course=null,$id=null,$delete='keep')
  718. {
  719. //TODO implement a way of getting this to work when the current object is not set
  720. //In clear: implement this in the item class as well (abstract class) and use the given ID in queries
  721. //if(empty($course)){$course = api_get_course_id();}
  722. //if(empty($id)){$id = $this->get_id();}
  723. //if($this->debug>0){error_log('New LP - In learnpath::delete()',0);}
  724. foreach($this->items as $id => $dummy)
  725. {
  726. $this->items[$id]->delete();
  727. }
  728. $lp = Database::get_course_table('lp');
  729. $lp_view = Database::get_course_table('lp_view');
  730. $sql_del_view = "DELETE FROM $lp_view WHERE lp_id = ".$this->lp_id;
  731. //if($this->debug>2){error_log('New LP - Deleting views bound to lp '.$this->lp_id.': '.$sql_del_view,0);}
  732. $res_del_view = api_sql_query($sql_del_view);
  733. //if($this->debug>2){error_log('New LP - Deleting lp '.$this->lp_id.' of type '.$this->type,0);}
  734. if($this->type == 2 OR $this->type==3){
  735. //this is a scorm learning path, delete the files as well
  736. $sql = "SELECT path FROM $lp WHERE id = ".$this->lp_id;
  737. $res = api_sql_query($sql);
  738. if(Database::num_rows($res)>0){
  739. $row = Database::fetch_array($res);
  740. $path = $row['path'];
  741. $sql = "SELECT id FROM $lp WHERE path = '$path' AND id != ".$this->lp_id;
  742. $res = api_sql_query($sql);
  743. if(Database::num_rows($res)>0)
  744. { //another learning path uses this directory, so don't delete it
  745. if($this->debug>2){error_log('New LP - In learnpath::delete(), found other LP using path '.$path.', keeping directory',0);}
  746. }else{
  747. //no other LP uses that directory, delete it
  748. $course_rel_dir = api_get_course_path().'/scorm/'; //scorm dir web path starting from /courses
  749. $course_scorm_dir = api_get_path(SYS_COURSE_PATH).$course_rel_dir; //absolute system path for this course
  750. if($delete == 'remove' && is_dir($course_scorm_dir.$path) and !empty($course_scorm_dir)){
  751. if($this->debug>2){error_log('New LP - In learnpath::delete(), found SCORM, deleting directory: '.$course_scorm_dir.$path,0);}
  752. exec('rm -rf '.$course_scorm_dir.$path);
  753. }
  754. }
  755. }
  756. }
  757. $sql_del_lp = "DELETE FROM $lp WHERE id = ".$this->lp_id;
  758. //if($this->debug>2){error_log('New LP - Deleting lp '.$this->lp_id.': '.$sql_del_lp,0);}
  759. $res_del_lp = api_sql_query($sql_del_lp);
  760. //TODO: also delete items and item-views
  761. }
  762. /**
  763. * Removes all the children of one item - dangerous!
  764. * @param integer Element ID of which children have to be removed
  765. * @return integer Total number of children removed
  766. */
  767. function delete_children_items($id){
  768. if($this->debug>0){error_log('New LP - In learnpath::delete_children_items('.$id.')',0);}
  769. $num = 0;
  770. if(empty($id) || $id != strval(intval($id))){return false;}
  771. $lp_item = Database::get_course_table('lp_item');
  772. $sql = "SELECT * FROM $lp_item WHERE parent_item_id = $id";
  773. $res = api_sql_query($sql);
  774. while($row = Database::fetch_array($res)){
  775. $num += $this->delete_children_items($row['id']);
  776. $sql_del = "DELETE FROM $lp_item WHERE id = ".$row['id'];
  777. $res_del = api_sql_query($sql_del);
  778. $num++;
  779. }
  780. return $num;
  781. }
  782. /**
  783. * Removes an item from the current learnpath
  784. * @param integer Elem ID (0 if first)
  785. * @param integer Whether to remove the resource/data from the system or leave it (default: 'keep', others 'remove')
  786. * @return integer Number of elements moved
  787. * @todo implement resource removal
  788. */
  789. function delete_item($id, $remove='keep')
  790. {
  791. if($this->debug>0){error_log('New LP - In learnpath::delete_item()',0);}
  792. //TODO - implement the resource removal
  793. if(empty($id) || $id != strval(intval($id))){return false;}
  794. //first select item to get previous, next, and display order
  795. $lp_item = Database::get_course_table('lp_item');
  796. $sql_sel = "SELECT * FROM $lp_item WHERE id = $id";
  797. $res_sel = api_sql_query($sql_sel,__FILE__,__LINE__);
  798. if(Database::num_rows($res_sel)<1){return false;}
  799. $row = Database::fetch_array($res_sel);
  800. $previous = $row['previous_item_id'];
  801. $next = $row['next_item_id'];
  802. $display = $row['display_order'];
  803. $parent = $row['parent_item_id'];
  804. $lp = $row['lp_id'];
  805. //delete children items
  806. $num = $this->delete_children_items($id);
  807. if($this->debug>2){error_log('New LP - learnpath::delete_item() - deleted '.$num.' children of element '.$id,0);}
  808. //now delete the item
  809. $sql_del = "DELETE FROM $lp_item WHERE id = $id";
  810. if($this->debug>2){error_log('New LP - Deleting item: '.$sql_del,0);}
  811. $res_del = api_sql_query($sql_del,__FILE__,__LINE__);
  812. //now update surrounding items
  813. $sql_upd = "UPDATE $lp_item SET next_item_id = $next WHERE id = $previous";
  814. $res_upd = api_sql_query($sql_upd,__FILE__,__LINE__);
  815. $sql_upd = "UPDATE $lp_item SET previous_item_id = $previous WHERE id = $next";
  816. $res_upd = api_sql_query($sql_upd,__FILE__,__LINE__);
  817. //now update all following items with new display order
  818. $sql_all = "UPDATE $lp_item SET display_order = display_order-1 WHERE lp_id = $lp AND parent_item_id = $parent AND display_order > $display";
  819. $res_all = api_sql_query($sql_all,__FILE__,__LINE__);
  820. }
  821. /**
  822. * Updates an item's content in place
  823. * @param integer Element ID
  824. * @param string New content
  825. * @return boolean True on success, false on error
  826. */
  827. function old_edit_item($id,$content)
  828. {
  829. if($this->debug>0){error_log('New LP - In learnpath::edit_item()',0);}
  830. if(empty($id) or ($id != strval(intval($id))) or empty($content)){ return false; }
  831. $content = $this->escape_string($content);
  832. $lp_item = Database::get_course_table('lp_item');
  833. $sql_upd = "UPDATE $lp_item SET title = '$content' WHERE id = $id";
  834. $res_upd = api_sql_query($sql_upd,__FILE__,__LINE__);
  835. //TODO update the item object (can be ignored for now because refreshed)
  836. return true;
  837. }
  838. function edit_item($id, $parent, $previous, $title, $description)
  839. {
  840. if($this->debug > 0){error_log('New LP - In learnpath::edit_item()', 0);}
  841. if(empty($id) or ($id != strval(intval($id))) or empty($title)){ return false; }
  842. $tbl_lp_item = Database::get_course_table('lp_item');
  843. $sql_select = "
  844. SELECT *
  845. FROM " . $tbl_lp_item . "
  846. WHERE id = " . $id;
  847. $res_select = api_sql_query($sql_select, __FILE__, __LINE__);
  848. $row_select = Database::fetch_array($res_select);
  849. $same_parent = ($row_select['parent_item_id'] == $parent) ? true : false;
  850. $same_previous = ($row_select['previous_item_id'] == $previous) ? true : false;
  851. if($same_parent && $same_previous)
  852. {
  853. //only update title and description
  854. $sql_update = "
  855. UPDATE " . $tbl_lp_item . "
  856. SET
  857. title = '" . $this->escape_string(htmlentities($title)) . "',
  858. description = '" . $this->escape_string(htmlentities($description)) . "'
  859. WHERE id = " . $id;
  860. $res_update = api_sql_query($sql_update, __FILE__, __LINE__);
  861. }
  862. else
  863. {
  864. $old_parent = $row_select['parent_item_id'];
  865. $old_previous = $row_select['previous_item_id'];
  866. $old_next = $row_select['next_item_id'];
  867. $old_order = $row_select['display_order'];
  868. /* BEGIN -- virtually remove the current item id */
  869. /* for the next and previous item it is like the current item doesn't exist anymore */
  870. if($old_previous != 0)
  871. {
  872. $sql_update_next = "
  873. UPDATE " . $tbl_lp_item . "
  874. SET next_item_id = " . $old_next . "
  875. WHERE id = " . $old_previous;
  876. $res_update_next = api_sql_query($sql_update_next, __FILE__, __LINE__);
  877. //echo '<p>' . $sql_update_next . '</p>';
  878. }
  879. if($old_next != 0)
  880. {
  881. $sql_update_previous = "
  882. UPDATE " . $tbl_lp_item . "
  883. SET previous_item_id = " . $old_previous . "
  884. WHERE id = " . $old_next;
  885. $res_update_previous = api_sql_query($sql_update_previous, __FILE__, __LINE__);
  886. //echo '<p>' . $sql_update_previous . '</p>';
  887. }
  888. //display_order - 1 for every item with a display_order bigger then the display_order of the current item
  889. $sql_update_order = "
  890. UPDATE " . $tbl_lp_item . "
  891. SET display_order = display_order - 1
  892. WHERE
  893. display_order > " . $old_order . " AND
  894. parent_item_id = " . $old_parent;
  895. $res_update_order = api_sql_query($sql_update_order, __FILE__, __LINE__);
  896. //echo '<p>' . $sql_update_order . '</p>';
  897. /* END -- virtually remove the current item id */
  898. /* BEGIN -- update the current item id to his new location */
  899. if($previous == 0)
  900. {
  901. //select the data of the item that should come after the current item
  902. $sql_select_old = "
  903. SELECT
  904. id,
  905. display_order
  906. FROM " . $tbl_lp_item . "
  907. WHERE
  908. lp_id = " . $this->lp_id . " AND
  909. parent_item_id = " . $parent . " AND
  910. previous_item_id = " . $previous;
  911. $res_select_old = api_sql_query($sql_select_old, __FILE__, __LINE__);
  912. $row_select_old = Database::fetch_array($res_select_old);
  913. //echo '<p>' . $sql_select_old . '</p>';
  914. //if the new parent doesn't had children before
  915. if(Database::num_rows($res_select_old) == 0)
  916. {
  917. $new_next = 0;
  918. $new_order = 1;
  919. }
  920. else
  921. {
  922. $new_next = $row_select_old['id'];
  923. $new_order = $row_select_old['display_order'];
  924. }
  925. //echo 'New next_item_id of current item: ' . $new_next . '<br />';
  926. //echo 'New previous_item_id of current item: ' . $previous . '<br />';
  927. //echo 'New display_order of current item: ' . $new_order . '<br />';
  928. }
  929. else
  930. {
  931. //select the data of the item that should come before the current item
  932. $sql_select_old = "
  933. SELECT
  934. next_item_id,
  935. display_order
  936. FROM " . $tbl_lp_item . "
  937. WHERE id = " . $previous;
  938. $res_select_old = api_sql_query($sql_select_old, __FILE__, __LINE__);
  939. $row_select_old = Database::fetch_array($res_select_old);
  940. //echo '<p>' . $sql_select_old . '</p>';
  941. //echo 'New next_item_id of current item: ' . $row_select_old['next_item_id'] . '<br />';
  942. //echo 'New previous_item_id of current item: ' . $previous . '<br />';
  943. //echo 'New display_order of current item: ' . ($row_select_old['display_order'] + 1) . '<br />';
  944. $new_next = $row_select_old['next_item_id'];
  945. $new_order = $row_select_old['display_order'] + 1;
  946. }
  947. //update the current item with the new data
  948. $sql_update = "
  949. UPDATE " . $tbl_lp_item . "
  950. SET
  951. title = '" . $this->escape_string(htmlentities($title)) . "',
  952. description = '" . $this->escape_string(htmlentities($description)) . "',
  953. parent_item_id = " . $parent . ",
  954. previous_item_id = " . $previous . ",
  955. next_item_id = " . $new_next . ",
  956. display_order = " . $new_order . "
  957. WHERE id = " . $id;
  958. $res_update_next = api_sql_query($sql_update, __FILE__, __LINE__);
  959. //echo '<p>' . $sql_update . '</p>';
  960. if($previous != 0)
  961. {
  962. //update the previous item his next_item_id
  963. $sql_update_previous = "
  964. UPDATE " . $tbl_lp_item . "
  965. SET next_item_id = " . $id . "
  966. WHERE id = " . $previous;
  967. $res_update_next = api_sql_query($sql_update_previous, __FILE__, __LINE__);
  968. //echo '<p>' . $sql_update_previous . '</p>';
  969. }
  970. if($new_next != 0)
  971. {
  972. //update the next item his previous_item_id
  973. $sql_update_next = "
  974. UPDATE " . $tbl_lp_item . "
  975. SET previous_item_id = " . $id . "
  976. WHERE id = " . $new_next;
  977. $res_update_next = api_sql_query($sql_update_next, __FILE__, __LINE__);
  978. //echo '<p>' . $sql_update_next . '</p>';
  979. }
  980. //update all the items with the same or a bigger display_order then the current item
  981. $sql_update_order = "
  982. UPDATE " . $tbl_lp_item . "
  983. SET display_order = display_order + 1
  984. WHERE
  985. lp_id = " . $this->get_id() . " AND
  986. id <> " . $id . " AND
  987. parent_item_id = " . $parent . " AND
  988. display_order >= " . $new_order;
  989. $res_update_next = api_sql_query($sql_update_order, __FILE__, __LINE__);
  990. //echo '<p>' . $sql_update_order . '</p>';
  991. /* END -- update the current item id to his new location */
  992. }
  993. }
  994. /**
  995. * Updates an item's prereq in place
  996. * @param integer Element ID
  997. * @param string Prerequisite Element ID
  998. *
  999. * @param string Prerequisite item type
  1000. *
  1001. * @param string Prerequisite min score
  1002. *
  1003. * @param string Prerequisite max score
  1004. * @return boolean True on success, false on error
  1005. */
  1006. function edit_item_prereq($id, $prerequisite_id, $min_score = 0, $max_score = 100)
  1007. {
  1008. if($this->debug>0){error_log('New LP - In learnpath::edit_item_prereq()',0);}
  1009. if(empty($id) or ($id != strval(intval($id))) or empty($prerequisite_id)){ return false; }
  1010. $prerequisite_id = $this->escape_string($prerequisite_id);
  1011. $tbl_lp_item = Database::get_course_table('lp_item');
  1012. if(!is_numeric($min_score) || $min_score < 0 || $min_score > 100)
  1013. $min_score = 0;
  1014. if(!is_numeric($max_score) || $max_score < 0 || $max_score > 100)
  1015. $max_score = 100;
  1016. if($min_score > $max_score)
  1017. $max_score = $min_score;
  1018. if(!is_numeric($prerequisite_id))
  1019. $prerequisite_id = 'NULL';
  1020. $sql_upd = "
  1021. UPDATE " . $tbl_lp_item . "
  1022. SET
  1023. min_score = " . $min_score . ",
  1024. max_score = " . $max_score . ",
  1025. prerequisite = " . $prerequisite_id . "
  1026. WHERE id = " . $id;
  1027. $res_upd = api_sql_query($sql_upd ,__FILE__, __LINE__);
  1028. //TODO update the item object (can be ignored for now because refreshed)
  1029. return true;
  1030. }
  1031. /**
  1032. * Escapes a string with the available database escape function
  1033. * @param string String to escape
  1034. * @return string String escaped
  1035. */
  1036. function escape_string($string){
  1037. //if($this->debug>0){error_log('New LP - In learnpath::escape_string('.$string.')',0);}
  1038. return mysql_real_escape_string($string);
  1039. }
  1040. /**
  1041. * Static admin function exporting a learnpath into a zip file
  1042. * @param string Export type (scorm, zip, cd)
  1043. * @param string Course code
  1044. * @param integer Learnpath ID
  1045. * @param string Zip file name
  1046. * @return string Zip file path (or false on error)
  1047. */
  1048. function export_lp($type, $course, $id, $zipname)
  1049. {
  1050. //if($this->debug>0){error_log('New LP - In learnpath::export_lp()',0);}
  1051. //TODO
  1052. if(empty($type) OR empty($course) OR empty($id) OR empty($zipname)){return false;}
  1053. $url = '';
  1054. switch($type){
  1055. case 'scorm':
  1056. break;
  1057. case 'zip':
  1058. break;
  1059. case 'cdrom':
  1060. break;
  1061. }
  1062. return $url;
  1063. }
  1064. /**
  1065. * Gets all the chapters belonging to the same parent as the item/chapter given
  1066. * Can also be called as abstract method
  1067. * @param integer Item ID
  1068. * @return array A list of all the "brother items" (or an empty array on failure)
  1069. */
  1070. function get_brother_chapters($id){
  1071. if($this->debug>0){error_log('New LP - In learnpath::get_brother_chapters()',0);}
  1072. if(empty($id) OR $id != strval(intval($id))){ return array();}
  1073. $lp_item = Database::get_course_table('lp_item');
  1074. $sql_parent = "SELECT * FROM $lp_item WHERE id = $id AND item_type='dokeos_chapter'";
  1075. $res_parent = api_sql_query($sql_parent,__FILE__,__LINE__);
  1076. if(Database::num_rows($res_parent)>0){
  1077. $row_parent = Database::fetch_array($res_parent);
  1078. $parent = $row_parent['parent_item_id'];
  1079. $sql_bros = "SELECT * FROM $lp_item WHERE parent_item_id = $parent AND id = $id AND item_type='dokeos_chapter' ORDER BY display_order";
  1080. $res_bros = api_sql_query($sql_bros,__FILE__,__LINE__);
  1081. $list = array();
  1082. while ($row_bro = Database::fetch_array($res_bros)){
  1083. $list[] = $row_bro;
  1084. }
  1085. return $list;
  1086. }
  1087. return array();
  1088. }
  1089. /**
  1090. * Gets all the items belonging to the same parent as the item given
  1091. * Can also be called as abstract method
  1092. * @param integer Item ID
  1093. * @return array A list of all the "brother items" (or an empty array on failure)
  1094. */
  1095. function get_brother_items($id){
  1096. if($this->debug>0){error_log('New LP - In learnpath::get_brother_items('.$id.')',0);}
  1097. if(empty($id) OR $id != strval(intval($id))){ return array();}
  1098. $lp_item = Database::get_course_table('lp_item');
  1099. $sql_parent = "SELECT * FROM $lp_item WHERE id = $id";
  1100. $res_parent = api_sql_query($sql_parent,__FILE__,__LINE__);
  1101. if(Database::num_rows($res_parent)>0){
  1102. $row_parent = Database::fetch_array($res_parent);
  1103. $parent = $row_parent['parent_item_id'];
  1104. $sql_bros = "SELECT * FROM $lp_item WHERE parent_item_id = $parent ORDER BY display_order";
  1105. $res_bros = api_sql_query($sql_bros,__FILE__,__LINE__);
  1106. $list = array();
  1107. while ($row_bro = Database::fetch_array($res_bros)){
  1108. $list[] = $row_bro;
  1109. }
  1110. return $list;
  1111. }
  1112. return array();
  1113. }
  1114. /**
  1115. * Gets the number of items currently completed
  1116. * @return integer The number of items currently completed
  1117. */
  1118. function get_complete_items_count()
  1119. {
  1120. if($this->debug>0){error_log('New LP - In learnpath::get_complete_items_count()',0);}
  1121. $i = 0;
  1122. foreach($this->items as $id => $dummy){
  1123. //if($this->items[$id]->status_is(array('completed','passed','succeeded'))){
  1124. //Trying failed and browsed considered "progressed" as well
  1125. if($this->items[$id]->status_is(array('completed','passed','succeeded','browsed','failed'))){
  1126. $i++;
  1127. }
  1128. }
  1129. return $i;
  1130. }
  1131. /**
  1132. * Gets the current item ID
  1133. * @return integer The current learnpath item id
  1134. */
  1135. function get_current_item_id()
  1136. {
  1137. $current = 0;
  1138. if($this->debug>0){error_log('New LP - In learnpath::get_current_item_id()',0);}
  1139. if(!empty($this->current))
  1140. {
  1141. $current = $this->current;
  1142. }
  1143. if($this->debug>2){error_log('New LP - In learnpath::get_current_item_id() - Returning '.$current,0);}
  1144. return $current;
  1145. }
  1146. /**
  1147. * Gets the total number of items available for viewing in this SCORM
  1148. * @return integer The total number of items
  1149. */
  1150. function get_total_items_count()
  1151. {
  1152. if($this->debug>0){error_log('New LP - In learnpath::get_total_items_count()',0);}
  1153. return count($this->items);
  1154. }
  1155. /**
  1156. * Gets the first element URL.
  1157. * @return string URL to load into the viewer
  1158. */
  1159. function first()
  1160. {
  1161. if($this->debug>0){error_log('New LP - In learnpath::first()',0);}
  1162. //test if the last_item_seen exists and is not a dir
  1163. if(!empty($this->last_item_seen)
  1164. && !empty($this->items[$this->last_item_seen])
  1165. && $this->items[$this->last_item_seen]->get_type() != 'dir'
  1166. && $this->items[$this->last_item_seen]->get_type() != 'dokeos_chapter'
  1167. && $this->items[$this->last_item_seen]->is_done() != true
  1168. ){
  1169. 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);}
  1170. $index = -1;
  1171. foreach($this->ordered_items as $myindex => $item_id){
  1172. if($item_id == $this->last_item_seen){
  1173. $index = $myindex;
  1174. break;
  1175. }
  1176. }
  1177. if($index==-1){
  1178. //index hasn't changed, so item not found - panic (this shouldn't happen)
  1179. 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);}
  1180. return false;
  1181. }else{
  1182. $this->last = $this->last_item_seen;
  1183. $this->current = $this->last_item_seen;
  1184. $this->index = $index;
  1185. }
  1186. }else{
  1187. if($this->debug>2){error_log('New LP - In learnpath::first() - No last item seen',0);}
  1188. $index = 0;
  1189. while (!empty($this->ordered_items[$index])
  1190. AND
  1191. (
  1192. $this->items[$this->ordered_items[$index]]->get_type() == 'dir'
  1193. OR $this->items[$this->ordered_items[$index]]->get_type() == 'dokeos_chapter'
  1194. OR $this->items[$this->ordered_items[$index]]->is_done() === true
  1195. )
  1196. AND $index < $this->max_ordered_items)
  1197. {
  1198. $index ++;
  1199. }
  1200. $this->last = $this->current;
  1201. //current is
  1202. $this->current = $this->ordered_items[$index];
  1203. $this->index = $index;
  1204. if($this->debug>2){error_log('New LP - In learnpath::first() - No last item seen. New last = '.$this->last.'('.$this->ordered_items[$index].')',0);}
  1205. }
  1206. if($this->debug>2){error_log('New LP - In learnpath::first() - First item is '.$this->get_current_item_id());}
  1207. }
  1208. /**
  1209. * Gets the information about an item in a format usable as JavaScript to update
  1210. * the JS API by just printing this content into the <head> section of the message frame
  1211. * @param integer Item ID
  1212. * @return string
  1213. */
  1214. function get_js_info($item_id=''){
  1215. if($this->debug>0){error_log('New LP - In learnpath::get_js_info('.$item_id.')',0);}
  1216. $info = '';
  1217. $item_id = $this->escape_string($item_id);
  1218. if(!empty($item_id) && is_object($this->items[$item_id])){
  1219. //if item is defined, return values from DB
  1220. $oItem = $this->items[$item_id];
  1221. $info .= '<script language="javascript">';
  1222. $info .= "top.set_score(".$oItem->get_score().");\n";
  1223. $info .= "top.set_max(".$oItem->get_max().");\n";
  1224. $info .= "top.set_min(".$oItem->get_min().");\n";
  1225. $info .= "top.set_lesson_status('".$oItem->get_status()."');";
  1226. $info .= "top.set_session_time('".$oItem->get_scorm_time('js')."');";
  1227. $info .= "top.set_suspend_data('".$oItem->get_suspend_data()."');";
  1228. $info .= "top.set_saved_lesson_status('".$oItem->get_status()."');";
  1229. $info .= "top.set_flag_synchronized();";
  1230. $info .= '</script>';
  1231. if($this->debug>2){error_log('New LP - in learnpath::get_js_info('.$item_id.') - returning: '.$info,0);}
  1232. return $info;
  1233. }else{
  1234. //if item_id is empty, just update to default SCORM data
  1235. $info .= '<script language="javascript">';
  1236. $info .= "top.set_score(".learnpathItem::get_score().");\n";
  1237. $info .= "top.set_max(".learnpathItem::get_max().");\n";
  1238. $info .= "top.set_min(".learnpathItem::get_min().");\n";
  1239. $info .= "top.set_lesson_status('".learnpathItem::get_status()."');";
  1240. $info .= "top.set_session_time('".learnpathItem::get_scorm_time('js')."');";
  1241. $info .= "top.set_suspend_data('".learnpathItem::get_suspend_data()."');";
  1242. $info .= "top.set_saved_lesson_status('".learnpathItem::get_status()."');";
  1243. $info .= "top.set_flag_synchronized();";
  1244. $info .= '</script>';
  1245. if($this->debug>2){error_log('New LP - in learnpath::get_js_info('.$item_id.') - returning: '.$info,0);}
  1246. return $info;
  1247. }
  1248. }
  1249. /**
  1250. * Gets the js library from the database
  1251. * @return string The name of the javascript library to be used
  1252. */
  1253. function get_js_lib(){
  1254. $lib = '';
  1255. if(!empty($this->js_lib)){
  1256. $lib = $this->js_lib;
  1257. }
  1258. return $lib;
  1259. }
  1260. /**
  1261. * Gets the learnpath database ID
  1262. * @return integer Learnpath ID in the lp table
  1263. */
  1264. function get_id()
  1265. {
  1266. if($this->debug>0){error_log('New LP - In learnpath::get_id()',0);}
  1267. if(!empty($this->lp_id))
  1268. {
  1269. return $this->lp_id;
  1270. }else{
  1271. return 0;
  1272. }
  1273. }
  1274. /**
  1275. * Gets the last element URL.
  1276. * @return string URL to load into the viewer
  1277. */
  1278. function get_last()
  1279. {
  1280. if($this->debug>0){error_log('New LP - In learnpath::get_last()',0);}
  1281. $this->index = count($this->ordered_items)-1;
  1282. return $this->ordered_items[$this->index];
  1283. }
  1284. /**
  1285. * Gets the navigation bar for the learnpath display screen
  1286. * @return string The HTML string to use as a navigation bar
  1287. */
  1288. function get_navigation_bar()
  1289. {
  1290. if($this->debug>0){error_log('New LP - In learnpath::get_navigation_bar()',0);}
  1291. //TODO find a good value for the following variables
  1292. $file = '';
  1293. $openDir = '';
  1294. $edoceo = '';
  1295. $time = 0;
  1296. $navbar = '';
  1297. $RequestUri = '';
  1298. $mycurrentitemid = $this->get_current_item_id();
  1299. if($this->mode == 'fullscreen'){
  1300. $navbar = '<table cellpadding="0" cellspacing="0" align="left">'."\n".
  1301. ' <tr> '."\n" .
  1302. ' <td>'."\n" .
  1303. ' <div class="buttons">'."\n" .
  1304. ' <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" .
  1305. ' <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" .
  1306. ' <a href="lp_controller.php?action=switch_view_mode" target="_top" title="embedded mode"><img border="0" src="../img/scormexitfullscreen.jpg" title="'.get_lang('ScormExitFullScreen').'"></a>'."\n" .
  1307. ' <a href="lp_controller.php?action=list" target="_top" title="learnpaths list"><img border="0" src="../img/exit.png" title="Exit"></a>'."\n" .
  1308. ' </div>'."\n" .
  1309. ' </td>'."\n" .
  1310. ' </tr>'."\n" .
  1311. '</table>'."\n" ;
  1312. }else{
  1313. $navbar = '<table cellpadding="0" cellspacing="0" align="left">'."\n".
  1314. ' <tr> '."\n" .
  1315. ' <td>'."\n" .
  1316. ' <div class="buttons">'."\n" .
  1317. ' <a href="lp_controller.php?action=stats" target="content_name" title="stats"><img border="0" src="../img/scormstatus.gif" title="'.get_lang('ScormMystatus').'"></a>&nbsp;'."\n" .
  1318. ' <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" .
  1319. ' <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" .
  1320. ' <a href="lp_controller.php?action=switch_view_mode" target="_top" title="fullscreen"><img border="0" src="../img/scormfullscreen.jpg" title="'.get_lang('ScormFullScreen').'"></a>'."\n" .
  1321. ' </div>'."\n" .
  1322. ' </td>'."\n" .
  1323. ' </tr>'."\n" .
  1324. '</table>'."\n" ;
  1325. }
  1326. return $navbar;
  1327. }
  1328. /**
  1329. * Gets the next resource in queue (url).
  1330. * @return string URL to load into the viewer
  1331. */
  1332. function get_next_index()
  1333. {
  1334. if($this->debug>0){error_log('New LP - In learnpath::get_next_index()',0);}
  1335. //TODO
  1336. $index = $this->index;
  1337. $index ++;
  1338. if($this->debug>2){error_log('New LP - Now looking at ordered_items['.($index).'] - type is '.$this->items[$this->ordered_items[$index]]['type'],0);}
  1339. while(!empty($this->ordered_items[$index]) AND $this->items[$this->ordered_items[$index]]->get_type() == 'dir' AND $index < $this->max_ordered_items)
  1340. {
  1341. $index ++;
  1342. if($index == $this->max_ordered_items)
  1343. {
  1344. return $this->index;
  1345. }
  1346. }
  1347. if(empty($this->ordered_items[$index])){
  1348. return $this->index;
  1349. }
  1350. if($this->debug>2){error_log('New LP - index is now '.$index,0);}
  1351. return $index;
  1352. }
  1353. /**
  1354. * Gets item_id for the next element
  1355. * @return integer Next item (DB) ID
  1356. */
  1357. function get_next_item_id()
  1358. {
  1359. $new_index = $this->get_next_index();
  1360. return $this->ordered_items[$new_index];
  1361. }
  1362. /**
  1363. * Gets the previous resource in queue (url). Also initialises time values for this viewing
  1364. * @return string URL to load into the viewer
  1365. */
  1366. function get_previous_index()
  1367. {
  1368. if($this->debug>0){error_log('New LP - In learnpath::get_previous_index()',0);}
  1369. $index = $this->index;
  1370. if(isset($this->ordered_items[$index-1])){
  1371. $index --;
  1372. while(isset($this->ordered_items[$index]) AND $this->items[$this->ordered_items[$index]]->get_type() == 'dir')
  1373. {
  1374. $index --;
  1375. if($index < 0){
  1376. return $this->index;
  1377. }
  1378. }
  1379. }else{
  1380. if($this->debug>2){error_log('New LP - get_previous_index() - there was no previous index available, reusing '.$index,0);}
  1381. //no previous item
  1382. }
  1383. return $index;
  1384. }
  1385. /**
  1386. * Gets item_id for the next element
  1387. * @return integer Previous item (DB) ID
  1388. */
  1389. function get_previous_item_id()
  1390. {
  1391. $new_index = $this->get_previous_index();
  1392. return $this->ordered_items[$new_index];
  1393. }
  1394. /**
  1395. * Gets the progress value from the progress_db attribute
  1396. * @return integer Current progress value
  1397. */
  1398. function get_progress(){
  1399. if($this->debug>0){error_log('New LP - In learnpath::get_progress()',0);}
  1400. if(!empty($this->progress_db)){
  1401. return $this->progress_db;
  1402. }
  1403. return 0;
  1404. }
  1405. /**
  1406. * Gets the progress value from the progress field in the database (allows use as abstract method)
  1407. * @param integer Learnpath ID
  1408. * @param integer User ID
  1409. * @param string Mode of display ('%','abs' or 'both')
  1410. * @return integer Current progress value as found in the database
  1411. */
  1412. function get_db_progress($lp_id,$user_id,$mode='%'){
  1413. //if($this->debug>0){error_log('New LP - In learnpath::get_db_progress()',0);}
  1414. $table = Database::get_course_table('lp_view');
  1415. $sql = "SELECT * FROM $table WHERE lp_id = $lp_id AND user_id = $user_id";
  1416. $res = api_sql_query($sql,__FILE__,__LINE__);
  1417. $view_id = 0;
  1418. if(Database::num_rows($res)>0){
  1419. $row = Database::fetch_array($res);
  1420. $progress = $row['progress'];
  1421. $view_id = $row['id'];
  1422. }
  1423. if(!$progress){
  1424. $progress = '0';
  1425. }
  1426. if($mode == '%'){
  1427. return $progress.'%';
  1428. }else{
  1429. //get the number of items completed and the number of items total
  1430. $tbl = Database::get_course_table('lp_item');
  1431. $sql = "SELECT count(*) FROM $tbl WHERE lp_id = ".$lp_id;
  1432. $res = api_sql_query($sql);
  1433. $row = Database::fetch_array($res);
  1434. $total = $row[0];
  1435. $tbl = Database::get_course_table('lp_item_view');
  1436. //$sql = "SELECT count(distinct(lp_item_id)) FROM $tbl WHERE lp_view_id = ".$view_id." AND status IN ('passed','completed','succeeded')";
  1437. //trying as also counting browsed and failed items
  1438. $sql = "SELECT count(distinct(lp_item_id)) FROM $tbl WHERE lp_view_id = ".$view_id." AND status IN ('passed','completed','succeeded','browsed','failed')";
  1439. $res = api_sql_query($sql);
  1440. $row = Database::fetch_array($res);
  1441. $completed = $row[0];
  1442. if($mode == 'abs'){
  1443. return $completed.'/'.$total;
  1444. }
  1445. elseif($mode == 'both')
  1446. {
  1447. return $progress.'% ('.$completed.'/'.$total.')';
  1448. }
  1449. }
  1450. return $progress;
  1451. }
  1452. /**
  1453. * Gets a progress bar for the learnpath by counting the number of items in it and the number of items
  1454. * completed so far.
  1455. * @param string Mode in which we want the values
  1456. * @param integer Progress value to display (optional but mandatory if used in abstract context)
  1457. * @param string Text to display near the progress value (optional but mandatory in abstract context)
  1458. * @return string HTML string containing the progress bar
  1459. */
  1460. function get_progress_bar($mode='',$percentage=-1,$text_add='')
  1461. {
  1462. if($this->debug>0){error_log('New LP - In learnpath::get_progress_bar()',0);}
  1463. if($percentage=='-1' OR $text_add==''){
  1464. list ($percentage, $text_add) = $this->get_progress_bar_text($mode);
  1465. }
  1466. $text = $percentage.$text_add;
  1467. $output = ''
  1468. //.htmlentities(get_lang('ScormCompstatus'),ENT_QUOTES,'ISO-8859-1')."<br />"
  1469. .'<table border="0" cellpadding="0" cellspacing="0"><tr><td>'
  1470. .'<img id="progress_img_limit_left" src="../img/bar_1.gif" width="1" height="12">'
  1471. .'<img id="progress_img_full" src="../img/bar_1u.gif" width="'.$percentage.'" height="12" id="full_portion">'
  1472. .'<img id="progress_img_limit_middle" src="../img/bar_1m.gif" width="1" height="12">';
  1473. if($percentage <= 98){
  1474. $output .= '<img id="progress_img_empty" src="../img/bar_1r.gif" width="'.(100-$percentage).'" height="12" id="empty_portion">';
  1475. }else{
  1476. $output .= '<img id="progress_img_empty" src="../img/bar_1r.gif" width="0" height="12" id="empty_portion">';
  1477. }
  1478. $output .= '<img id="progress_bar_img_limit_right" src="../img/bar_1.gif" width="1" height="12"></td></tr></table>'
  1479. .'<div class="progresstext" id="progress_text">'.$text.'</div>';
  1480. return $output;
  1481. }
  1482. /**
  1483. * Gets the progress bar info to display inside the progress bar. Also used by scorm_api.php
  1484. * @param string Mode of display (can be '%' or 'abs').abs means we display a number of completed elements per total elements
  1485. * //@param integer Additional steps to fake as completed
  1486. * @return list Percentage or number and symbol (% or /xx)
  1487. */
  1488. function get_progress_bar_text($mode='',$add=0)
  1489. {
  1490. if($this->debug>0){error_log('New LP - In learnpath::get_progress_bar_text()',0);}
  1491. if(empty($mode)){$mode = $this->progress_bar_mode;}
  1492. $total_items = $this->get_total_items_count();
  1493. if($this->debug>2){error_log('New LP - Total items available in this learnpath: '.$total_items,0);}
  1494. $i = $this->get_complete_items_count();
  1495. if($this->debug>2){error_log('New LP - Items completed so far: '.$i,0);}
  1496. if($add != 0){
  1497. $i += $add;
  1498. if($this->debug>2){error_log('New LP - Items completed so far (+modifier): '.$i,0);}
  1499. }
  1500. $text = '';
  1501. if($i>$total_items){
  1502. $i = $total_items;
  1503. }
  1504. if($mode == '%'){
  1505. $percentage = ((float)$i/(float)$total_items)*100;
  1506. $percentage = number_format($percentage,0);
  1507. $text = '%';
  1508. }elseif($mode == 'abs'){
  1509. $percentage = $i;
  1510. $text = '/'.$total_items;
  1511. }
  1512. return array($percentage,$text);
  1513. }
  1514. /**
  1515. * Gets the progress bar mode
  1516. * @return string The progress bar mode attribute
  1517. */
  1518. function get_progress_bar_mode()
  1519. {
  1520. if($this->debug>0){error_log('New LP - In learnpath::get_progress_bar_mode()',0);}
  1521. if(!empty($this->progress_bar_mode))
  1522. {
  1523. return $this->progress_bar_mode;
  1524. }else{
  1525. return '%';
  1526. }
  1527. }
  1528. /**
  1529. * Returns a usable array of stats related to the current learnpath and user
  1530. * @return array Well-formatted array containing status for the current learnpath
  1531. */
  1532. function get_stats()
  1533. {
  1534. if($this->debug>0){error_log('New LP - In learnpath::get_stats()',0);}
  1535. //TODO
  1536. }
  1537. /**
  1538. * Static method. Can be re-implemented by children. Gives an array of statistics for
  1539. * the given course (for all learnpaths and all users)
  1540. * @param string Course code
  1541. * @return array Well-formatted array containing status for the course's learnpaths
  1542. */
  1543. function get_stats_course($course)
  1544. {
  1545. //if($this->debug>0){error_log('New LP - In learnpath::get_stats_course()',0);}
  1546. //TODO
  1547. }
  1548. /**
  1549. * Static method. Can be re-implemented by children. Gives an array of statistics for
  1550. * the given course and learnpath (for all users)
  1551. * @param string Course code
  1552. * @param integer Learnpath ID
  1553. * @return array Well-formatted array containing status for the specified learnpath
  1554. */
  1555. function get_stats_lp($course,$lp)
  1556. {
  1557. //if($this->debug>0){error_log('New LP - In learnpath::get_stats_lp()',0);}
  1558. //TODO
  1559. }
  1560. /**
  1561. * Static method. Can be re-implemented by children. Gives an array of statistics for
  1562. * the given course, learnpath and user.
  1563. * @param string Course code
  1564. * @param integer Learnpath ID
  1565. * @param integer User ID
  1566. * @return array Well-formatted array containing status for the specified learnpath and user
  1567. */
  1568. function get_stats_lp_user($course,$lp,$user)
  1569. {
  1570. //if($this->debug>0){error_log('New LP - In learnpath::get_stats_lp_user()',0);}
  1571. //TODO
  1572. }
  1573. /**
  1574. * Static method. Can be re-implemented by children. Gives an array of statistics for
  1575. * the given course and learnpath (for all users)
  1576. * @param string Course code
  1577. * @param integer User ID
  1578. * @return array Well-formatted array containing status for the user's learnpaths
  1579. */
  1580. function get_stats_user($course,$user)
  1581. {
  1582. //if($this->debug>0){error_log('New LP - In learnpath::get_stats_user()',0);}
  1583. //TODO
  1584. }
  1585. /**
  1586. * Gets the status list for all LP's items
  1587. * @return array Array of [index] => [item ID => current status]
  1588. */
  1589. function get_items_status_list(){
  1590. if($this->debug>0){error_log('New LP - In learnpath::get_items_status_list()',0);}
  1591. $list = array();
  1592. foreach($this->ordered_items as $item_id)
  1593. {
  1594. $list[]= array($item_id => $this->items[$item_id]->get_status());
  1595. }
  1596. return $list;
  1597. }
  1598. /**
  1599. * Generate and return the table of contents for this learnpath. The (flat) table returned can be
  1600. * used by get_html_toc() to be ready to display
  1601. * @return array TOC as a table with 4 elements per row: title, link, status and level
  1602. */
  1603. function get_toc()
  1604. {
  1605. if($this->debug>0){error_log('New LP - In learnpath::get_toc()',0);}
  1606. $toc = array();
  1607. //echo "<pre>".print_r($this->items,true)."</pre>";
  1608. foreach($this->ordered_items as $item_id)
  1609. {
  1610. if($this->debug>2){error_log('New LP - learnpath::get_toc(): getting info for item '.$item_id,0);}
  1611. //TODO change this link generation and use new function instead
  1612. $toc[] = array(
  1613. 'id'=>$item_id,
  1614. 'title'=>$this->items[$item_id]->get_title(),
  1615. //'link'=>get_addedresource_link_in_learnpath('document',$item_id,1),
  1616. 'status'=>$this->items[$item_id]->get_status(),
  1617. 'level'=>$this->items[$item_id]->get_level(),
  1618. 'type' =>$this->items[$item_id]->get_type(),
  1619. );
  1620. }
  1621. if($this->debug>2){error_log('New LP - In learnpath::get_toc() - TOC array: '.print_r($toc,true),0);}
  1622. return $toc;
  1623. }
  1624. /**
  1625. * Gets the learning path type
  1626. * @param boolean Return the name? If false, return the ID. Default is false.
  1627. * @return mixed Type ID or name, depending on the parameter
  1628. */
  1629. function get_type($get_name = false)
  1630. {
  1631. $res = false;
  1632. if($this->debug>0){error_log('New LP - In learnpath::get_type()',0);}
  1633. if(!empty($this->type))
  1634. {
  1635. if($get_name)
  1636. {
  1637. //get it from the lp_type table in main db
  1638. }else{
  1639. $res = $this->type;
  1640. }
  1641. }
  1642. if($this->debug>2){error_log('New LP - In learnpath::get_type() - Returning '.($res==false?'false':$res),0);}
  1643. return $res;
  1644. }
  1645. /**
  1646. * Gets a flat list of item IDs ordered for display (level by level ordered by order_display)
  1647. * This method can be used as abstract and is recursive
  1648. * @param integer Learnpath ID
  1649. * @param integer Parent ID of the items to look for
  1650. * @return mixed Ordered list of item IDs or false on error
  1651. */
  1652. function get_flat_ordered_items_list($lp,$parent=0){
  1653. if($this->debug>0){error_log('New LP - In learnpath::get_flat_ordered_items_list('.$lp.','.$parent.')',0);}
  1654. $list = array();
  1655. if(empty($lp)){return false;}
  1656. $tbl_lp_item = Database::get_course_table('lp_item');
  1657. $sql = "SELECT * FROM $tbl_lp_item WHERE lp_id = $lp AND parent_item_id = $parent ORDER BY display_order";
  1658. $res = api_sql_query($sql,__FILE__,__LINE__);
  1659. while($row = Database::fetch_array($res)){
  1660. $sublist = learnpath::get_flat_ordered_items_list($lp,$row['id']);
  1661. $list[] = $row['id'];
  1662. foreach($sublist as $item){
  1663. $list[] = $item;
  1664. }
  1665. }
  1666. return $list;
  1667. }
  1668. /**
  1669. * Uses the table generated by get_toc() and returns an HTML-formatted string ready to display
  1670. * @return string HTML TOC ready to display
  1671. */
  1672. function get_html_toc()
  1673. {
  1674. if($this->debug>0){error_log('New LP - In learnpath::get_html_toc()',0);}
  1675. $list = $this->get_toc();
  1676. //echo $this->current;
  1677. //$parent = $this->items[$this->current]->get_parent();
  1678. //if(empty($parent)){$parent = $this->ordered_items[$this->items[$this->current]->get_previous_index()];}
  1679. $html = '<div class="inner_lp_toc">'."\n" ;
  1680. // " onchange=\"javascript:document.getElementById('toc_$parent').focus();\">\n";
  1681. require_once('resourcelinker.inc.php');
  1682. //temp variables
  1683. $mycurrentitemid = $this->get_current_item_id();
  1684. foreach($list as $item)
  1685. {
  1686. if($this->debug>2){error_log('New LP - learnpath::get_html_toc(): using item '.$item['id'],0);}
  1687. //TODO complete this
  1688. $icon_name = array('not attempted' => 'notattempted.png',
  1689. 'incomplete' => 'incomplete.png',
  1690. 'failed' => 'failed.png',
  1691. 'completed' => 'completed.png',
  1692. 'passed' => 'passed.png',
  1693. 'succeeded' => 'succeeded.png',
  1694. 'browsed' => 'completed.png');
  1695. $style = 'scorm_item';
  1696. if($item['id'] == $this->current){
  1697. $style = 'scorm_item_highlight';
  1698. }
  1699. //the anchor will let us center the TOC on the currently viewed item &^D
  1700. $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'].'" >' .
  1701. '<img id="toc_img_'.$item['id'].'" class="scorm_status_img" src="'.$icon_name[$item['status']].'" alt="'.substr($item['status'],0,1).'" />';
  1702. //$title = htmlspecialchars($item['title'],ENT_QUOTES,$this->encoding);
  1703. $title = $item['title'];
  1704. if(empty($title)){
  1705. $title = rl_get_resource_name(api_get_course_id(),$this->get_id(),$item['id']);
  1706. $title = htmlspecialchars($title,ENT_QUOTES,$this->encoding);
  1707. }
  1708. if(empty($title))$title = '-';
  1709. if($item['type']!='dokeos_chapter' and $item['type']!='dir'){
  1710. //$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>" ;
  1711. $url = $this->get_link('http',$item['id']);
  1712. //$html .= '<a href="'.$url.'" target="content_name" onclick="top.load_item('.$item['id'].',\''.$url.'\');">'.$title.'</a>' ;
  1713. //$html .= '<a href="" onclick="top.load_item('.$item['id'].',\''.$url.'\');return false;">'.$title.'</a>' ;
  1714. $html .= '<a href="" onclick="dokeos_xajax_handler.switch_item(' .
  1715. $mycurrentitemid.',' .
  1716. $item['id'].');' .
  1717. 'return false;" >'.$title.'</a>' ;
  1718. }else{
  1719. $html .= $title;
  1720. }
  1721. $html .= "</div>\n";
  1722. }
  1723. $html .= "</div>\n";
  1724. return $html;
  1725. }
  1726. /**
  1727. * Gets the user-friendly message stored in $this->message
  1728. * @return string Message
  1729. */
  1730. function get_message(){
  1731. if($this->debug>0){error_log('New LP - In learnpath::get_message()',0);}
  1732. return $this->message;
  1733. }
  1734. /**
  1735. * Gets the learnpath name/title
  1736. * @return string Learnpath name/title
  1737. */
  1738. function get_name()
  1739. {
  1740. if($this->debug>0){error_log('New LP - In learnpath::get_name()',0);}
  1741. if(!empty($this->name)){return $this->name;}else{return 'N/A';}
  1742. }
  1743. /**
  1744. * Gets a link to the resource from the present location, depending on item ID.
  1745. * @param string Type of link expected
  1746. * @param integer Learnpath item ID
  1747. * @return string Link to the lp_item resource
  1748. */
  1749. function get_link($type='http',$item_id=null)
  1750. {
  1751. if($this->debug>0){error_log('New LP - In learnpath::get_link('.$type.','.$item_id.')',0);}
  1752. if(empty($item_id))
  1753. {
  1754. 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);}
  1755. $item_id = $this->get_current_item_id();
  1756. }
  1757. if(empty($item_id)){
  1758. if($this->debug>2){error_log('New LP - In learnpath::get_link() - no current item id found in learnpath object',0);}
  1759. //still empty, this means there was no item_id given and we are not in an object context or
  1760. //the object property is empty, return empty link
  1761. $item_id = $this->first();
  1762. return '';
  1763. }
  1764. $file = '';
  1765. $lp_db = Database::get_current_course_database();
  1766. $lp_pref = Database::get_course_table_prefix();
  1767. $lp_table = $lp_db.'.'.$lp_pref.'lp';
  1768. $lp_item_table = $lp_db.'.'.$lp_pref.'lp_item';
  1769. $sel = "SELECT l.lp_type as ltype, l.path as lpath, li.item_type as litype, li.path as lipath " .
  1770. "FROM $lp_table l, $lp_item_table li WHERE li.id = $item_id AND li.lp_id = l.id";
  1771. if($this->debug>2){error_log('New LP - In learnpath::get_link() - selecting item '.$sel,0);}
  1772. $res = api_sql_query($sel);
  1773. if(Database::num_rows($res)>0)
  1774. {
  1775. $row = Database::fetch_array($res);
  1776. //var_dump($row);
  1777. $lp_type = $row['ltype'];
  1778. $lp_path = $row['lpath'];
  1779. $lp_item_type = $row['litype'];
  1780. $lp_item_path = $row['lipath'];
  1781. if($type == 'http'){
  1782. $course_path = api_get_path(WEB_COURSE_PATH).api_get_course_path(); //web path
  1783. }else{
  1784. $course_path = api_get_path(SYS_COURSE_PATH).api_get_course_path(); //system path
  1785. }
  1786. //now go through the specific cases to get the end of the path
  1787. switch($lp_type){
  1788. case 1:
  1789. if($lp_item_type == 'dokeos_chapter'){
  1790. $file = 'lp_content.php?type=dir';
  1791. }else{
  1792. require_once('resourcelinker.inc.php');
  1793. $file = rl_get_resource_link_for_learnpath(api_get_course_id(),$this->get_id(),$item_id);
  1794. }
  1795. break;
  1796. case 2:
  1797. if($this->debug>2){error_log('New LP - In learnpath::get_link() '.__LINE__.' - Item type: '.$lp_item_type,0);}
  1798. if($lp_item_type!='dir'){
  1799. //Quite complex here:
  1800. //we want to make sure 'http://' (and similar) links can
  1801. //be loaded as is (withouth the Dokeos path in front) but
  1802. //some contents use this form: resource.htm?resource=http://blablabla
  1803. //which means we have to find a protocol at the path's start, otherwise
  1804. //it should not be considered as an external URL
  1805. //if($this->prerequisites_match($item_id)){
  1806. if(preg_match('#^[a-zA-Z]{2,5}://#',$lp_item_path)!=0){
  1807. if($this->debug>2){error_log('New LP - In learnpath::get_link() '.__LINE__.' - Found match for protocol in '.$lp_item_path,0);}
  1808. //distant url, return as is
  1809. $file = $lp_item_path;
  1810. }else{
  1811. if($this->debug>2){error_log('New LP - In learnpath::get_link() '.__LINE__.' - No starting protocol in '.$lp_item_path,0);}
  1812. //prevent getting untranslatable urls
  1813. $lp_item_path = preg_replace('/%2F/','/',$lp_item_path);
  1814. $lp_item_path = preg_replace('/%3A/',':',$lp_item_path);
  1815. //prepare the path
  1816. $file = $course_path.'/scorm/'.$lp_path.'/'.$lp_item_path;
  1817. //TODO fix this for urls with protocol header
  1818. $file = str_replace('//','/',$file);
  1819. $file = str_replace(':/','://',$file);
  1820. }
  1821. //}else{
  1822. //prerequisites did not match
  1823. //$file = 'blank.php';
  1824. //}
  1825. }else{
  1826. $file = 'lp_content.php?type=dir';
  1827. }
  1828. break;
  1829. case 3:
  1830. if($this->debug>2){error_log('New LP - In learnpath::get_link() '.__LINE__.' - Item type: '.$lp_item_type,0);}
  1831. //formatting AICC HACP append URL
  1832. $aicc_append = '?aicc_sid='.urlencode(session_id()).'&aicc_url='.urlencode(api_get_path(WEB_CODE_PATH).'newscorm/aicc.hacp.php').'&';
  1833. if($lp_item_type!='dir'){
  1834. //Quite complex here:
  1835. //we want to make sure 'http://' (and similar) links can
  1836. //be loaded as is (withouth the Dokeos path in front) but
  1837. //some contents use this form: resource.htm?resource=http://blablabla
  1838. //which means we have to find a protocol at the path's start, otherwise
  1839. //it should not be considered as an external URL
  1840. if(preg_match('#^[a-zA-Z]{2,5}://#',$lp_item_path)!=0){
  1841. if($this->debug>2){error_log('New LP - In learnpath::get_link() '.__LINE__.' - Found match for protocol in '.$lp_item_path,0);}
  1842. //distant url, return as is
  1843. $file = $lp_item_path;
  1844. $file .= $aicc_append;
  1845. }else{
  1846. if($this->debug>2){error_log('New LP - In learnpath::get_link() '.__LINE__.' - No starting protocol in '.$lp_item_path,0);}
  1847. //prevent getting untranslatable urls
  1848. $lp_item_path = preg_replace('/%2F/','/',$lp_item_path);
  1849. $lp_item_path = preg_replace('/%3A/',':',$lp_item_path);
  1850. //prepare the path
  1851. $file = $course_path.'/scorm/'.$lp_path.'/'.$lp_item_path;
  1852. //TODO fix this for urls with protocol header
  1853. $file = str_replace('//','/',$file);
  1854. $file = str_replace(':/','://',$file);
  1855. $file .= $aicc_append;
  1856. }
  1857. }else{
  1858. $file = 'lp_content.php?type=dir';
  1859. }
  1860. break;
  1861. case 4:
  1862. break;
  1863. default:
  1864. break;
  1865. }
  1866. }
  1867. if($this->debug>2){error_log('New LP - In learnpath::get_link() - returning "'.$file.'" from get_link',0);}
  1868. return $file;
  1869. }
  1870. /**
  1871. * Gets the latest usable view or generate a new one
  1872. * @param integer Optional attempt number. If none given, takes the highest from the lp_view table
  1873. * @return integer DB lp_view id
  1874. */
  1875. function get_view($attempt_num=0)
  1876. {
  1877. if($this->debug>0){error_log('New LP - In learnpath::get_view()',0);}
  1878. $search = '';
  1879. //use $attempt_num to enable multi-views management (disabled so far)
  1880. if($attempt_num != 0 AND intval(strval($attempt_num)) == $attempt_num)
  1881. {
  1882. $search = 'AND view_count = '.$attempt_num;
  1883. }
  1884. //when missing $attempt_num, search for a unique lp_view record for this lp and user
  1885. $lp_view_table = Database::get_course_table('lp_view');
  1886. $sql = "SELECT id, view_count FROM $lp_view_table " .
  1887. "WHERE lp_id = ".$this->get_id()." " .
  1888. "AND user_id = ".$this->get_user_id()." " .
  1889. $search .
  1890. " ORDER BY view_count DESC";
  1891. $res = api_sql_query($sql);
  1892. if(Database::num_rows($res)>0)
  1893. {
  1894. $row = Database::fetch_array($res);
  1895. $this->lp_view_id = $row['id'];
  1896. }else{
  1897. //no database record, create one
  1898. $sql = "INSERT INTO $lp_view_table(lp_id,user_id,view_count)" .
  1899. "VALUES (".$this->get_id().",".$this->get_user_id().",1)";
  1900. $res = api_sql_query($sql);
  1901. $id = Database::get_last_insert_id();
  1902. $this->lp_view_id = $id;
  1903. }
  1904. }
  1905. /**
  1906. * Gets the current view id
  1907. * @return integer View ID (from lp_view)
  1908. */
  1909. function get_view_id()
  1910. {
  1911. if($this->debug>0){error_log('New LP - In learnpath::get_view_id()',0);}
  1912. if(!empty($this->lp_view_id))
  1913. {
  1914. return $this->lp_view_id;
  1915. }else{
  1916. return 0;
  1917. }
  1918. }
  1919. /**
  1920. * Gets the update queue
  1921. * @return array Array containing IDs of items to be updated by JavaScript
  1922. */
  1923. function get_update_queue()
  1924. {
  1925. if($this->debug>0){error_log('New LP - In learnpath::get_update_queue()',0);}
  1926. return $this->update_queue;
  1927. }
  1928. /**
  1929. * Gets the user ID
  1930. * @return integer User ID
  1931. */
  1932. function get_user_id()
  1933. {
  1934. if($this->debug>0){error_log('New LP - In learnpath::get_user_id()',0);}
  1935. if(!empty($this->user_id))
  1936. {
  1937. return $this->user_id;
  1938. }else{
  1939. return false;
  1940. }
  1941. }
  1942. /**
  1943. * Logs a message into a file
  1944. * @param string Message to log
  1945. * @return boolean True on success, false on error or if msg empty
  1946. */
  1947. function log($msg)
  1948. {
  1949. if($this->debug>0){error_log('New LP - In learnpath::log()',0);}
  1950. //TODO
  1951. $this->error .= $msg."\n";
  1952. return true;
  1953. }
  1954. /**
  1955. * Moves an item up and down at its level
  1956. * @param integer Item to move up and down
  1957. * @param string Direction 'up' or 'down'
  1958. * @return integer New display order, or false on error
  1959. */
  1960. function move_item($id, $direction){
  1961. if($this->debug>0){error_log('New LP - In learnpath::move_item('.$id.','.$direction.')',0);}
  1962. if(empty($id) or empty($direction)){return false;}
  1963. $tbl_lp_item = Database::get_course_table('lp_item');
  1964. $sql_sel = "
  1965. SELECT *
  1966. FROM " . $tbl_lp_item . "
  1967. WHERE id = " . $id;
  1968. $res_sel = api_sql_query($sql_sel,__FILE__,__LINE__);
  1969. //check if elem exists
  1970. if(Database::num_rows($res_sel)<1){return false;}
  1971. //gather data
  1972. $row = Database::fetch_array($res_sel);
  1973. $previous = $row['previous_item_id'];
  1974. $next = $row['next_item_id'];
  1975. $display = $row['display_order'];
  1976. $parent = $row['parent_item_id'];
  1977. $lp = $row['lp_id'];
  1978. //update the item (switch with previous/next one)
  1979. switch($direction)
  1980. {
  1981. case 'up':
  1982. if($this->debug>2){error_log('Movement up detected',0);}
  1983. if($display <= 1){/*do nothing*/}
  1984. else{
  1985. $sql_sel2 = "SELECT *
  1986. FROM $tbl_lp_item
  1987. WHERE id = $previous";
  1988. if($this->debug>2){error_log('Selecting previous: '.$sql_sel2,0);}
  1989. $res_sel2 = api_sql_query($sql_sel2,__FILE__,__LINE__);
  1990. if(Database::num_rows($res_sel2)<1){$previous_previous = 0;}
  1991. //gather data
  1992. $row2 = Database::fetch_array($res_sel2);
  1993. $previous_previous = $row2['previous_item_id'];
  1994. //update previous_previous item (switch "next" with current)
  1995. if($previous_previous != 0){
  1996. $sql_upd2 = "UPDATE $tbl_lp_item SET next_item_id = $id WHERE id = $previous_$previous";
  1997. if($this->debug>2){error_log($sql_upd2,0);}
  1998. $res_upd2 = api_sql_query($sql_upd2);
  1999. }
  2000. //update previous item (switch with current)
  2001. if($previous != 0){
  2002. $sql_upd2 = "UPDATE $tbl_lp_item SET next_item_id = $next, previous_item_id = $id, display_order = display_order +1 WHERE id = $previous";
  2003. if($this->debug>2){error_log($sql_upd2,0);}
  2004. $res_upd2 = api_sql_query($sql_upd2);
  2005. }
  2006. //update current item (switch with previous)
  2007. if($id != 0){
  2008. $sql_upd2 = "UPDATE $tbl_lp_item SET next_item_id = $previous, previous_item_id = $previous_previous, display_order = display_order-1 WHERE id = $id";
  2009. if($this->debug>2){error_log($sql_upd2,0);}
  2010. $res_upd2 = api_sql_query($sql_upd2);
  2011. }
  2012. //update next item (new previous item)
  2013. if($next != 0){
  2014. $sql_upd2 = "UPDATE $tbl_lp_item SET previous_item_id = $previous WHERE id = $next";
  2015. if($this->debug>2){error_log($sql_upd2,0);}
  2016. $res_upd2 = api_sql_query($sql_upd2);
  2017. }
  2018. $display = $display-1;
  2019. }
  2020. break;
  2021. case 'down':
  2022. if($this->debug>2){error_log('Movement down detected',0);}
  2023. if($next == 0){/*do nothing*/}
  2024. else{
  2025. $sql_sel2 = "SELECT * FROM $tbl_lp_item WHERE id = $next";
  2026. if($this->debug>2){error_log('Selecting next: '.$sql_sel2,0);}
  2027. $res_sel2 = api_sql_query($sql_sel2,__FILE__,__LINE__);
  2028. if(Database::num_rows($res_sel2)<1){$next_next = 0;}
  2029. //gather data
  2030. $row2 = Database::fetch_array($res_sel2);
  2031. $next_next = $row2['next_item_id'];
  2032. //update previous item (switch with current)
  2033. if($previous != 0){
  2034. $sql_upd2 = "UPDATE $tbl_lp_item SET next_item_id = $next WHERE id = $previous";
  2035. $res_upd2 = api_sql_query($sql_upd2);
  2036. }
  2037. //update current item (switch with previous)
  2038. if($id != 0){
  2039. $sql_upd2 = "UPDATE $tbl_lp_item SET previous_item_id = $next, next_item_id = $next_next, display_order = display_order+1 WHERE id = $id";
  2040. $res_upd2 = api_sql_query($sql_upd2);
  2041. }
  2042. //update next item (new previous item)
  2043. if($next != 0){
  2044. $sql_upd2 = "UPDATE $tbl_lp_item SET previous_item_id = $previous, next_item_id = $id, display_order = display_order-1 WHERE id = $next";
  2045. $res_upd2 = api_sql_query($sql_upd2);
  2046. }
  2047. //update next_next item (switch "previous" with current)
  2048. if($next_next != 0){
  2049. $sql_upd2 = "UPDATE $tbl_lp_item SET previous_item_id = $id WHERE id = $next_next";
  2050. $res_upd2 = api_sql_query($sql_upd2);
  2051. }
  2052. $display = $display+1;
  2053. }
  2054. break;
  2055. default:
  2056. return false;
  2057. }
  2058. return $display;
  2059. }
  2060. /**
  2061. * Updates learnpath attributes to point to the next element
  2062. * The last part is similar to set_current_item but processing the other way around
  2063. */
  2064. function next(){
  2065. if($this->debug>0){error_log('New LP - In learnpath::next()',0);}
  2066. $this->last = $this->get_current_item_id();
  2067. $this->items[$this->last]->save(false);
  2068. $this->autocomplete_parents($this->last);
  2069. $new_index = $this->get_next_index();
  2070. if($this->debug>2){error_log('New LP - New index: '.$new_index,0);}
  2071. $this->index = $new_index;
  2072. if($this->debug>2){error_log('New LP - Now having orderedlist['.$new_index.'] = '. $this->ordered_items[$new_index],0);}
  2073. $this->current = $this->ordered_items[$new_index];
  2074. if($this->debug>2){error_log('New LP - new item id is '.$this->current.'-'.$this->get_current_item_id(),0);}
  2075. }
  2076. /**
  2077. * Open a resource = initialise all local variables relative to this resource. Depending on the child
  2078. * class, this might be redefined to allow several behaviours depending on the document type.
  2079. * @param integer Resource ID
  2080. * @return boolean True on success, false otherwise
  2081. */
  2082. function open($id)
  2083. {
  2084. if($this->debug>0){error_log('New LP - In learnpath::open()',0);}
  2085. //TODO
  2086. //set the current resource attribute to this resource
  2087. //switch on element type (redefine in child class?)
  2088. //set status for this item to "opened"
  2089. //start timer
  2090. //initialise score
  2091. $this->index = 0; //or = the last item seen (see $this->last)
  2092. }
  2093. /**
  2094. * Check that all prerequisites are fulfilled. Returns true and an empty string on succes, returns false
  2095. * and the prerequisite string on error.
  2096. * This function is based on the rules for aicc_script language as described in the SCORM 1.2 CAM documentation page 108.
  2097. * @param integer Optional item ID. If none given, uses the current open item.
  2098. * @return boolean True if prerequisites are matched, false otherwise
  2099. * @return string Empty string if true returned, prerequisites string otherwise.
  2100. */
  2101. function prerequisites_match($item = null){
  2102. if($this->debug>0){error_log('New LP - In learnpath::prerequisites_match()',0);}
  2103. if(empty($item)){$item = $this->current;}
  2104. if(is_object($this->items[$item])){
  2105. $prereq_string = $this->items[$item]->get_prereq_string();
  2106. if(empty($prereq_string)){return true;}
  2107. //clean spaces
  2108. $prereq_string = str_replace(' ','',$prereq_string);
  2109. if($this->debug>0){error_log('Found prereq_string: '.$prereq_string,0);}
  2110. //now send to the parse_prereq() function that will check this component's prerequisites
  2111. $result = $this->items[$item]->parse_prereq($prereq_string,$this);
  2112. if($result === false){
  2113. $this->set_error_msg($this->items[$item]->prereq_alert);
  2114. }
  2115. }else{
  2116. $result = true;
  2117. if($this->debug>1){error_log('New LP - $this->items['.$item.'] was not an object',0);}
  2118. }
  2119. if($this->debug>1){error_log('New LP - End of prerequisites_match(). Error message is now '.$this->error,0);}
  2120. return $result;
  2121. }
  2122. /**
  2123. * Updates learnpath attributes to point to the previous element
  2124. * The last part is similar to set_current_item but processing the other way around
  2125. */
  2126. function previous(){
  2127. if($this->debug>0){error_log('New LP - In learnpath::previous()',0);}
  2128. $this->last = $this->get_current_item_id();
  2129. $this->items[$this->last]->save(false);
  2130. $this->autocomplete_parents($this->last);
  2131. $new_index = $this->get_previous_index();
  2132. $this->index = $new_index;
  2133. $this->current = $this->ordered_items[$new_index];
  2134. }
  2135. /**
  2136. * Publishes a learnpath. This basically means show or hide the learnpath
  2137. * to normal users.
  2138. * Can be used as abstract
  2139. * @param integer Learnpath ID
  2140. * @param string New visibility
  2141. */
  2142. function toggle_visibility($lp_id,$set_visibility='v')
  2143. {
  2144. //if($this->debug>0){error_log('New LP - In learnpath::toggle_visibility()',0);}
  2145. $tbl_lp = Database::get_course_table('lp');
  2146. $sql="SELECT * FROM $tbl_lp where id=$lp_id";
  2147. $result=api_sql_query($sql,__FILE__,__LINE__);
  2148. $row=Database::fetch_array($result);
  2149. $name=domesticate($row['name']);
  2150. if($set_visibility == 'i') {
  2151. $s=$name." ".get_lang('_no_published');
  2152. $dialogBox=$s;
  2153. $v=0;
  2154. }
  2155. if($set_visibility == 'v') {
  2156. $s=$name." ".get_lang('_published');
  2157. $dialogBox=$s;
  2158. $v=1;
  2159. }
  2160. $tbl_tool = Database::get_course_table(TOOL_LIST_TABLE);
  2161. $sql="SELECT * FROM $tbl_tool where name='$name' and image='scormbuilder.gif'";
  2162. $result=api_sql_query($sql,__FILE__,__LINE__);
  2163. $num=Database::num_rows($result);
  2164. $row2=Database::fetch_array($result);
  2165. //if($this->debug>2){error_log('New LP - '.$sql.' - '.$num,0);}
  2166. if(($set_visibility == 'i') && ($num>0))
  2167. {
  2168. //it is visible or hidden but once was published
  2169. if(($row2['visibility'])==1)
  2170. {
  2171. $sql ="DELETE FROM $tbl_tool WHERE (name='$name' and image='scormbuilder.gif')";
  2172. }
  2173. else
  2174. {
  2175. $sql ="UPDATE $tbl_tool set visibility=1 WHERE (name='$name' and image='scormbuilder.gif')";
  2176. }
  2177. }
  2178. elseif(($set_visibility == 'v') && ($num==0))
  2179. {
  2180. $sql ="INSERT INTO $tbl_tool (name, link, image, visibility, admin, address, added_tool) VALUES ('$name','newscorm/lp_controller.php?mode=view&lp_id=$lp_id','scormbuilder.gif','$v','0','pastillegris.gif',0)";
  2181. }
  2182. else
  2183. {
  2184. //parameter and database incompatible, do nothing
  2185. }
  2186. $result=api_sql_query($sql,__FILE__,__LINE__);
  2187. //if($this->debug>2){error_log('New LP - Leaving learnpath::toggle_visibility: '.$sql,0);}
  2188. }
  2189. /**
  2190. * Restart the whole learnpath. Return the URL of the first element.
  2191. * Make sure the results are saved with anoter method. This method should probably be
  2192. * redefined in children classes.
  2193. * @return string URL to load in the viewer
  2194. */
  2195. function restart()
  2196. {
  2197. if($this->debug>0){error_log('New LP - In learnpath::restart()',0);}
  2198. //TODO
  2199. //call autosave method to save the current progress
  2200. //$this->index = 0;
  2201. $lp_view_table = Database::get_course_table('lp_view');
  2202. $sql = "INSERT INTO $lp_view_table (lp_id, user_id, view_count) " .
  2203. "VALUES (".$this->lp_id.",".$this->get_user_id().",".($this->attempt+1).")";
  2204. if($this->debug>2){error_log('New LP - Inserting new lp_view for restart: '.$sql,0);}
  2205. $res = api_sql_query($sql);
  2206. if($view_id = Database::get_last_insert_id($res))
  2207. {
  2208. $this->lp_view_id = $view_id;
  2209. $this->attempt = $this->attempt+1;
  2210. }else{
  2211. $this->error = 'Could not insert into item_view table...';
  2212. return false;
  2213. }
  2214. $this->autocomplete_parents($this->current);
  2215. foreach($this->items as $index=>$dummy){
  2216. $this->items[$index]->restart();
  2217. $this->items[$index]->set_lp_view($this->lp_view_id);
  2218. }
  2219. $this->first();
  2220. return true;
  2221. }
  2222. /**
  2223. * Saves the current item
  2224. * @return boolean
  2225. */
  2226. function save_current(){
  2227. if($this->debug>0){error_log('New LP - In learnpath::save_current()',0);}
  2228. //TODO do a better check on the index pointing to the right item (it is supposed to be working
  2229. // on $ordered_items[] but not sure it's always safe to use with $items[])
  2230. if($this->debug>2){error_log('New LP - save_current() saving item '.$this->current,0);}
  2231. if($this->debug>2){error_log(''.print_r($this->items,true),0);}
  2232. if(is_object($this->items[$this->current])){
  2233. $res = $this->items[$this->current]->save(false);
  2234. $this->autocomplete_parents($this->current);
  2235. $status = $this->items[$this->current]->get_status();
  2236. $this->append_message('new_item_status: '.$status);
  2237. $this->update_queue[$this->current] = $status;
  2238. return $res;
  2239. }
  2240. return false;
  2241. }
  2242. /**
  2243. * Saves the given item
  2244. * @param integer Item ID. Optional (will take from $_REQUEST if null)
  2245. * @param boolean Save from url params (true) or from current attributes (false). Optional. Defaults to true
  2246. * @return boolean
  2247. */
  2248. function save_item($item_id=null,$from_outside=true){
  2249. if($this->debug>0){error_log('New LP - In learnpath::save_item('.$item_id.','.$from_outside.')',0);}
  2250. //TODO do a better check on the index pointing to the right item (it is supposed to be working
  2251. // on $ordered_items[] but not sure it's always safe to use with $items[])
  2252. if(empty($item_id)){
  2253. $item_id = $this->escape_string($_REQUEST['id']);
  2254. }
  2255. if(empty($item_id))
  2256. {
  2257. $item_id = $this->get_current_item_id();
  2258. }
  2259. if($this->debug>2){error_log('New LP - save_current() saving item '.$item_id,0);}
  2260. if(is_object($this->items[$item_id])){
  2261. $res = $this->items[$item_id]->save($from_outside);
  2262. $this->autocomplete_parents($item_id);
  2263. $status = $this->items[$item_id]->get_status();
  2264. $this->append_message('new_item_status: '.$status);
  2265. $this->update_queue[$item_id] = $status;
  2266. return $res;
  2267. }
  2268. return false;
  2269. }
  2270. /**
  2271. * Saves the last item seen's ID only in case
  2272. */
  2273. function save_last(){
  2274. if($this->debug>0){error_log('New LP - In learnpath::save_last()',0);}
  2275. $table = Database::get_course_table('lp_view');
  2276. if(isset($this->current)){
  2277. if($this->debug>2){error_log('New LP - Saving current item ('.$this->current.') for later review',0);}
  2278. $sql = "UPDATE $table SET last_item = ".$this->get_current_item_id()." " .
  2279. "WHERE lp_id = ".$this->get_id()." AND user_id = ".$this->get_user_id();
  2280. if($this->debug>2){error_log('New LP - Saving last item seen : '.$sql,0);}
  2281. $res = api_sql_query($sql,__FILE__,__LINE__);
  2282. }
  2283. //save progress
  2284. list($progress,$text) = $this->get_progress_bar_text('%');
  2285. if($progress>=0 AND $progress<=100){
  2286. $progress= (int)$progress;
  2287. $sql = "UPDATE $table SET progress = $progress " .
  2288. "WHERE lp_id = ".$this->get_id()." AND " .
  2289. "user_id = ".$this->get_user_id();
  2290. $res = @mysql_query($sql); //ignore errors as some tables might not have the progress field just yet
  2291. $this->progress_db = $progress;
  2292. }
  2293. }
  2294. /**
  2295. * Sets the current item ID (checks if valid and authorized first)
  2296. * @param integer New item ID. If not given or not authorized, defaults to current
  2297. */
  2298. function set_current_item($item_id=null)
  2299. {
  2300. if($this->debug>0){error_log('New LP - In learnpath::set_current_item('.$item_id.')',0);}
  2301. if(empty($item_id)){
  2302. if($this->debug>2){error_log('New LP - No new current item given, ignore...',0);}
  2303. //do nothing
  2304. }else{
  2305. if($this->debug>2){error_log('New LP - New current item given is '.$item_id.'...',0);}
  2306. $item_id = $this->escape_string($item_id);
  2307. //TODO check in database here
  2308. $this->last = $this->current;
  2309. $this->current = $item_id;
  2310. //TODO update $this->index as well
  2311. foreach($this->ordered_items as $index => $item)
  2312. {
  2313. if($item == $this->current)
  2314. {
  2315. $this->index = $index;
  2316. break;
  2317. }
  2318. }
  2319. if($this->debug>2){error_log('New LP - set_current_item('.$item_id.') done. Index is now : '.$this->index,0);}
  2320. }
  2321. }
  2322. /**
  2323. * Sets the encoding
  2324. * @param string New encoding
  2325. */
  2326. function set_encoding($enc='ISO-8859-1'){
  2327. if($this->debug>0){error_log('New LP - In learnpath::set_encoding()',0);}
  2328. $enc = strtoupper($enc);
  2329. $encodings = array('UTF-8','ISO-8859-1','ISO-8859-15','SHIFT-JIS');
  2330. if(in_array($enc,$encodings)){
  2331. $lp = $this->get_id();
  2332. if($lp!=0){
  2333. $tbl_lp = Database::get_course_table('lp');
  2334. $sql = "UPDATE $tbl_lp SET default_encoding = '$enc' WHERE id = ".$lp;
  2335. $res = api_sql_query($sql);
  2336. return $res;
  2337. }
  2338. }
  2339. return false;
  2340. }
  2341. /**
  2342. * Sets the JS lib setting in the database directly.
  2343. * This is the JavaScript library file this lp needs to load on startup
  2344. * @param string Proximity setting
  2345. */
  2346. function set_jslib($lib=''){
  2347. if($this->debug>0){error_log('New LP - In learnpath::set_jslib()',0);}
  2348. $lp = $this->get_id();
  2349. if($lp!=0){
  2350. $tbl_lp = Database::get_course_table('lp');
  2351. $sql = "UPDATE $tbl_lp SET js_lib = '$lib' WHERE id = ".$lp;
  2352. $res = api_sql_query($sql);
  2353. return $res;
  2354. }else{
  2355. return false;
  2356. }
  2357. }
  2358. /**
  2359. * Sets the name of the LP maker (publisher) (and save)
  2360. * @param string Optional string giving the new content_maker of this learnpath
  2361. */
  2362. function set_maker($name=''){
  2363. if($this->debug>0){error_log('New LP - In learnpath::set_maker()',0);}
  2364. if(empty($name))return false;
  2365. $this->maker = $this->escape_string($name);
  2366. $lp_table = Database::get_course_table('lp');
  2367. $lp_id = $this->get_id();
  2368. $sql = "UPDATE $lp_table SET content_maker = '".$this->maker."' WHERE id = '$lp_id'";
  2369. if($this->debug>2){error_log('New LP - lp updated with new content_maker : '.$this->maker,0);}
  2370. //$res = Database::query($sql);
  2371. $res = api_sql_query($sql);
  2372. return true;
  2373. }
  2374. /**
  2375. * Sets the name of the current learnpath (and save)
  2376. * @param string Optional string giving the new name of this learnpath
  2377. */
  2378. function set_name($name=''){
  2379. if($this->debug>0){error_log('New LP - In learnpath::set_name()',0);}
  2380. if(empty($name))return false;
  2381. $this->name = $this->escape_string($name);
  2382. $lp_table = Database::get_course_table('lp');
  2383. $lp_id = $this->get_id();
  2384. $sql = "UPDATE $lp_table SET name = '".$this->name."' WHERE id = '$lp_id'";
  2385. if($this->debug>2){error_log('New LP - lp updated with new name : '.$this->name,0);}
  2386. //$res = Database::query($sql);
  2387. $res = api_sql_query($sql);
  2388. return true;
  2389. }
  2390. /**
  2391. * Sets the location/proximity of the LP (local/remote) (and save)
  2392. * @param string Optional string giving the new location of this learnpath
  2393. */
  2394. function set_proximity($name=''){
  2395. if($this->debug>0){error_log('New LP - In learnpath::set_proximity()',0);}
  2396. if(empty($name))return false;
  2397. $this->proximity = $this->escape_string($name);
  2398. $lp_table = Database::get_course_table('lp');
  2399. $lp_id = $this->get_id();
  2400. $sql = "UPDATE $lp_table SET content_local = '".$this->proximity."' WHERE id = '$lp_id'";
  2401. if($this->debug>2){error_log('New LP - lp updated with new proximity : '.$this->proximity,0);}
  2402. //$res = Database::query($sql);
  2403. $res = api_sql_query($sql);
  2404. return true;
  2405. }
  2406. /**
  2407. * Sets the previous item ID to a given ID. Generally, this should be set to the previous 'current' item
  2408. * @param integer DB ID of the item
  2409. */
  2410. function set_previous_item($id)
  2411. {
  2412. if($this->debug>0){error_log('New LP - In learnpath::set_previous_item()',0);}
  2413. $this->last = $id;
  2414. }
  2415. /**
  2416. * Sets the object's error message
  2417. * @param string Error message. If empty, reinits the error string
  2418. * @return void
  2419. */
  2420. function set_error_msg($error='')
  2421. {
  2422. if($this->debug>0){error_log('New LP - In learnpath::set_error_msg()',0);}
  2423. if(empty($error)){
  2424. $this->error = '';
  2425. }else{
  2426. $this->error .= $error;
  2427. }
  2428. }
  2429. /**
  2430. * Launches the current item if not 'sco' (starts timer and make sure there is a record ready in the DB)
  2431. *
  2432. */
  2433. function start_current_item(){
  2434. if($this->debug>0){error_log('New LP - In learnpath::start_current_item()',0);}
  2435. if($this->current != 0 AND
  2436. is_object($this->items[$this->current]))
  2437. {
  2438. $type = $this->get_type();
  2439. if(
  2440. ($type == 2 && $this->items[$this->current]->get_type()!='sco')
  2441. OR
  2442. ($type == 3 && $this->items[$this->current]->get_type()!='au')
  2443. OR
  2444. ($type==1)
  2445. )
  2446. {
  2447. $this->items[$this->current]->open();
  2448. $this->items[$this->current]->save(false);
  2449. $this->autocomplete_parents($this->current);
  2450. $this->prerequisites_match(); //launch the prerequisites check and set error if needed
  2451. //$this->update_queue[$this->last] = $this->items[$this->last]->get_status();
  2452. }else{
  2453. //if sco, then it is supposed to have been updated by some other call
  2454. }
  2455. }
  2456. return true;
  2457. }
  2458. /**
  2459. * Stops the processing and counters for the old item (as held in $this->last)
  2460. * @param
  2461. */
  2462. function stop_previous_item(){
  2463. if($this->debug>0){error_log('New LP - In learnpath::stop_previous_item()',0);}
  2464. if($this->last != 0 AND is_object($this->items[$this->last]))
  2465. {
  2466. if($this->debug>2){error_log('New LP - In learnpath::stop_previous_item() - '.$this->last.' is object',0);}
  2467. switch($this->get_type()){
  2468. case '3':
  2469. if($this->items[$this->last]->get_type()!='au')
  2470. {
  2471. if($this->debug>2){error_log('New LP - In learnpath::stop_previous_item() - '.$this->last.' in lp_type 3 is <> au',0);}
  2472. $this->items[$this->last]->close();
  2473. //$this->autocomplete_parents($this->last);
  2474. //$this->update_queue[$this->last] = $this->items[$this->last]->get_status();
  2475. }else{
  2476. if($this->debug>2){error_log('New LP - In learnpath::stop_previous_item() - Item is an AU, saving is managed by AICC signals',0);}
  2477. }
  2478. case '2':
  2479. if($this->items[$this->last]->get_type()!='sco')
  2480. {
  2481. if($this->debug>2){error_log('New LP - In learnpath::stop_previous_item() - '.$this->last.' in lp_type 2 is <> sco',0);}
  2482. $this->items[$this->last]->close();
  2483. //$this->autocomplete_parents($this->last);
  2484. //$this->update_queue[$this->last] = $this->items[$this->last]->get_status();
  2485. }else{
  2486. if($this->debug>2){error_log('New LP - In learnpath::stop_previous_item() - Item is a SCO, saving is managed by SCO signals',0);}
  2487. }
  2488. break;
  2489. case '1':
  2490. default:
  2491. if($this->debug>2){error_log('New LP - In learnpath::stop_previous_item() - '.$this->last.' in lp_type 1 is asset',0);}
  2492. $this->items[$this->last]->close();
  2493. break;
  2494. }
  2495. }else{
  2496. if($this->debug>2){error_log('New LP - In learnpath::stop_previous_item() - No previous element found, ignoring...',0);}
  2497. return false;
  2498. }
  2499. return true;
  2500. }
  2501. /**
  2502. * Updates the default view mode from fullscreen to embedded and inversely
  2503. * @return string The current default view mode ('fullscreen' or 'embedded')
  2504. */
  2505. function update_default_view_mode()
  2506. {
  2507. if($this->debug>0){error_log('New LP - In learnpath::update_default_view_mode()',0);}
  2508. $lp_table = Database::get_course_table('lp');
  2509. $sql = "SELECT * FROM $lp_table WHERE id = ".$this->get_id();
  2510. $res = api_sql_query($sql);
  2511. if(Database::num_rows($res)>0){
  2512. $row = Database::fetch_array($res);
  2513. $view_mode = $row['default_view_mod'];
  2514. if($view_mode == 'fullscreen'){
  2515. $view_mode = 'embedded';
  2516. }elseif($view_mode == 'embedded'){
  2517. $view_mode = 'fullscreen';
  2518. }
  2519. $sql = "UPDATE $lp_table SET default_view_mod = '$view_mode' WHERE id = ".$this->get_id();
  2520. $res = api_sql_query($sql);
  2521. $this->mode = $view_mode;
  2522. return $view_mode;
  2523. }else{
  2524. if($this->debug>2){error_log('New LP - Problem in update_default_view() - could not find LP '.$this->get_id().' in DB',0);}
  2525. }
  2526. return -1;
  2527. }
  2528. /**
  2529. * Updates the default behaviour about auto-commiting SCORM updates
  2530. * @return boolean True if auto-commit has been set to 'on', false otherwise
  2531. */
  2532. function update_default_scorm_commit(){
  2533. if($this->debug>0){error_log('New LP - In learnpath::update_default_scorm_commit()',0);}
  2534. $lp_table = Database::get_course_table('lp');
  2535. $sql = "SELECT * FROM $lp_table WHERE id = ".$this->get_id();
  2536. $res = api_sql_query($sql);
  2537. if(Database::num_rows($res)>0){
  2538. $row = Database::fetch_array($res);
  2539. $force = $row['force_commit'];
  2540. if($force == 1){
  2541. $force = 0;
  2542. $force_return = false;
  2543. }elseif($force == 0){
  2544. $force = 1;
  2545. $force_return = true;
  2546. }
  2547. $sql = "UPDATE $lp_table SET force_commit = $force WHERE id = ".$this->get_id();
  2548. $res = api_sql_query($sql);
  2549. $this->force_commit = $force_return;
  2550. return $force_return;
  2551. }else{
  2552. if($this->debug>2){error_log('New LP - Problem in update_default_scorm_commit() - could not find LP '.$this->get_id().' in DB',0);}
  2553. }
  2554. return -1;
  2555. }
  2556. /**
  2557. * Updates the "prevent_reinit" value that enables control on reinitialising items on second view
  2558. * @return boolean True if prevent_reinit has been set to 'on', false otherwise (or 1 or 0 in this case)
  2559. */
  2560. function update_reinit(){
  2561. if($this->debug>0){error_log('New LP - In learnpath::update_reinit()',0);}
  2562. $lp_table = Database::get_course_table('lp');
  2563. $sql = "SELECT * FROM $lp_table WHERE id = ".$this->get_id();
  2564. $res = api_sql_query($sql);
  2565. if(Database::num_rows($res)>0){
  2566. $row = Database::fetch_array($res);
  2567. $force = $row['prevent_reinit'];
  2568. if($force == 1){
  2569. $force = 0;
  2570. }elseif($force == 0){
  2571. $force = 1;
  2572. }
  2573. $sql = "UPDATE $lp_table SET prevent_reinit = $force WHERE id = ".$this->get_id();
  2574. $res = api_sql_query($sql,__FILE__,__LINE__);
  2575. $this->prevent_reinit = $force;
  2576. return $force;
  2577. }else{
  2578. if($this->debug>2){error_log('New LP - Problem in update_reinit() - could not find LP '.$this->get_id().' in DB',0);}
  2579. }
  2580. return -1;
  2581. }
  2582. /**
  2583. * Updates the "scorm_debug" value that shows or hide the debug window
  2584. * @return boolean True if scorm_debug has been set to 'on', false otherwise (or 1 or 0 in this case)
  2585. */
  2586. function update_scorm_debug(){
  2587. if($this->debug>0){error_log('New LP - In learnpath::update_scorm_debug()',0);}
  2588. $lp_table = Database::get_course_table('lp');
  2589. $sql = "SELECT * FROM $lp_table WHERE id = ".$this->get_id();
  2590. $res = api_sql_query($sql);
  2591. if(Database::num_rows($res)>0){
  2592. $row = Database::fetch_array($res);
  2593. $force = $row['debug'];
  2594. if($force == 1){
  2595. $force = 0;
  2596. }elseif($force == 0){
  2597. $force = 1;
  2598. }
  2599. $sql = "UPDATE $lp_table SET debug = $force WHERE id = ".$this->get_id();
  2600. $res = api_sql_query($sql,__FILE__,__LINE__);
  2601. $this->scorm_debug = $force;
  2602. return $force;
  2603. }else{
  2604. if($this->debug>2){error_log('New LP - Problem in update_scorm_debug() - could not find LP '.$this->get_id().' in DB',0);}
  2605. }
  2606. return -1;
  2607. }
  2608. /**
  2609. * Function that makes a call to the function sort_tree_array and create_tree_array
  2610. *
  2611. * @author Kevin Van Den Haute
  2612. *
  2613. * @param unknown_type $array
  2614. */
  2615. function tree_array($array)
  2616. {
  2617. $array = $this->sort_tree_array($array);
  2618. $this->create_tree_array($array);
  2619. }
  2620. /**
  2621. * Creates an array with the elements of the learning path tree in it
  2622. *
  2623. * @author Kevin Van Den Haute
  2624. *
  2625. * @param array $array
  2626. * @param int $parent
  2627. * @param int $depth
  2628. * @param array $tmp
  2629. */
  2630. function create_tree_array($array, $parent = 0, $depth = -1, $tmp = array())
  2631. {
  2632. if(is_array($array))
  2633. {
  2634. for($i = 0; $i < count($array); $i++)
  2635. {
  2636. if($array[$i]['parent_item_id'] == $parent)
  2637. {
  2638. if(!in_array($array[$i]['parent_item_id'], $tmp))
  2639. {
  2640. $tmp[] = $array[$i]['parent_item_id'];
  2641. $depth++;
  2642. }
  2643. $this->arrMenu[] = array(
  2644. 'id' => $array[$i]['id'],
  2645. 'item_type' => $array[$i]['item_type'],
  2646. 'title' => $array[$i]['title'],
  2647. 'path' => $array[$i]['path'],
  2648. 'description' => $array[$i]['description'],
  2649. 'parent_item_id' => $array[$i]['parent_item_id'],
  2650. 'previous_item_id' => $array[$i]['previous_item_id'],
  2651. 'next_item_id' => $array[$i]['next_item_id'],
  2652. 'display_order' => $array[$i]['display_order'],
  2653. 'depth' => $depth
  2654. );
  2655. $this->create_tree_array($array, $array[$i]['id'], $depth, $tmp);
  2656. }
  2657. }
  2658. }
  2659. }
  2660. /**
  2661. * Sorts a multi dimensional array by parent id and display order
  2662. * @author Kevin Van Den Haute
  2663. *
  2664. * @param array $array (array with al the learning path items in it)
  2665. *
  2666. * @return array
  2667. */
  2668. function sort_tree_array($array)
  2669. {
  2670. foreach($array as $key => $row)
  2671. {
  2672. $parent[$key] = $row['parent_item_id'];
  2673. $position[$key] = $row['display_order'];
  2674. }
  2675. if(count($array) > 0)
  2676. array_multisort($parent, SORT_ASC, $position, SORT_ASC, $array);
  2677. return $array;
  2678. }
  2679. /**
  2680. * Function that creates a table structure with a learning path his modules, chapters and documents.
  2681. * Also the actions for the modules, chapters and documents are in this table.
  2682. *
  2683. * @author Kevin Van Den Haute
  2684. *
  2685. * @param int $lp_id
  2686. *
  2687. * @return string
  2688. */
  2689. function overview()
  2690. {
  2691. $return = '';
  2692. $tbl_lp_item = Database::get_course_table('lp_item');
  2693. $sql = "
  2694. SELECT *
  2695. FROM " . $tbl_lp_item . "
  2696. WHERE
  2697. lp_id = " . $this->lp_id;
  2698. $result = api_sql_query($sql, __FILE__, __LINE__);
  2699. $arrLP = array();
  2700. while($row = Database::fetch_array($result))
  2701. {
  2702. $arrLP[] = array(
  2703. 'id' => $row['id'],
  2704. 'item_type' => $row['item_type'],
  2705. 'title' => $row['title'],
  2706. 'description' => $row['description'],
  2707. 'parent_item_id' => $row['parent_item_id'],
  2708. 'previous_item_id' => $row['previous_item_id'],
  2709. 'next_item_id' => $row['next_item_id'],
  2710. 'display_order' => $row['display_order']);
  2711. }
  2712. $this->tree_array($arrLP);
  2713. $arrLP = $this->arrMenu;
  2714. unset($this->arrMenu);
  2715. if(api_is_allowed_to_edit())
  2716. $return .= '<p><a href="' . $_SERVER['PHP_SELF'] . '?cidReq=' . $_GET['cidReq'] . '&amp;action=build&amp;lp_id=' . $this->lp_id . '">Advanced</a></p>';
  2717. $return .= '<table cellpadding="0" cellspacing="2" class="lp_overview">' . "\n";
  2718. $return .= "\t" . '<tr class="header">' . "\n";
  2719. $return .= "\t" . '<th>Title</th>' . "\n";
  2720. $return .= "\t" . '<th>Description</th>' . "\n";
  2721. $return .= "\t" . '<th>Move</th>' . "\n";
  2722. $return .= "\t" . '<th>Actions</th>' . "\n";
  2723. $return .= "\t" . '</tr>' . "\n";
  2724. for($i = 0; $i < count($arrLP); $i++)
  2725. {
  2726. if($arrLP[$i]['description'] == '')
  2727. $arrLP[$i]['description'] = '&nbsp;';
  2728. $return .= "\t" . '<tr>' . "\n";
  2729. $return .= "\t\t" . '<td class="title" 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";
  2730. $return .= "\t\t" . '<td>' . stripslashes($arrLP[$i]['description']) . '</td>' . "\n";
  2731. if(api_is_allowed_to_edit())
  2732. {
  2733. $return .= "\t\t" . '<td class="move">' . "\n";
  2734. if($arrLP[$i]['previous_item_id'] != 0)
  2735. {
  2736. $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 . '">';
  2737. $return .= '<img alt="" src="img/arrow_up_' . ($arrLP[$i]['depth'] % 3) . '.png" />';
  2738. $return .= '</a>' . "\n";
  2739. }
  2740. else
  2741. $return .= "\t\t\t" . '<img alt="" src="img/blanco.png" title="" />' . "\n";
  2742. if($arrLP[$i]['next_item_id'] != 0)
  2743. {
  2744. $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 . '">';
  2745. $return .= '<img src="img/arrow_down_' . ($arrLP[$i]['depth'] % 3) . '.png" />';
  2746. $return .= '</a>' . "\n";
  2747. }
  2748. else
  2749. $return .= "\t\t\t" . '<img alt="" src="img/blanco.png" title="" />' . "\n";
  2750. $return .= "\t\t" . '</td>' . "\n";
  2751. $return .= "\t\t" . '<td class="actions">' . "\n";
  2752. if($arrLP[$i]['item_type'] != 'dokeos_chapter' && $arrLP[$i]['item_type'] != 'dokeos_module')
  2753. {
  2754. $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 . '">';
  2755. $return .= '<img alt="" src="../img/edit.gif" title="' . get_lang('_edit_learnpath_module') . '" />';
  2756. $return .= '</a>' . "\n";
  2757. }
  2758. else
  2759. {
  2760. $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 . '">';
  2761. $return .= '<img alt="" src="../img/edit.gif" title="' . get_lang('_edit_learnpath_module') . '" />';
  2762. $return .= '</a>' . "\n";
  2763. }
  2764. $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'] . '\');">';
  2765. $return .= '<img alt="" src="../img/delete.gif" title="' . get_lang('_delete_learnpath_module') . '" />';
  2766. $return .= '</a>' . "\n";
  2767. $return .= "\t\t" . '</td>' . "\n";
  2768. }
  2769. $return .= "\t" . '</tr>' . "\n";
  2770. }
  2771. if(count($arrLP) == 0)
  2772. {
  2773. $return .= "\t" . '<tr>' . "\n";
  2774. $return .= "\t\t" . '<td colspan="4">There are no items in the learning path for this moment. Click on "Advanced" for creating your learning path items.</td>' . "\n";
  2775. $return .= "\t" . '</tr>' . "\n";
  2776. }
  2777. $return .= '</table>' . "\n";
  2778. return $return;
  2779. }
  2780. /**
  2781. * This functions builds the LP tree based on data from the database.
  2782. *
  2783. * @return string
  2784. * @uses dtree.js :: necessary javascript for building this tree
  2785. */
  2786. function build_tree()
  2787. {
  2788. $return = "<script type=\"text/javascript\">\n";
  2789. $return .= "\tm = new dTree('m');\n\n";
  2790. $return .= "\tm.config.folderLinks = true;\n";
  2791. $return .= "\tm.config.useCookies = true;\n";
  2792. $return .= "\tm.config.useIcons = true;\n";
  2793. $return .= "\tm.config.useLines = true;\n";
  2794. $return .= "\tm.config.useSelection = true;\n";
  2795. $return .= "\tm.config.useStatustext = false;\n\n";
  2796. $menu = 0;
  2797. $parent = '';
  2798. $return .= "\tm.add(" . $menu . ", -1, '" . addslashes($this->name) . "');\n";
  2799. $tbl_lp_item = Database::get_course_table('lp_item');
  2800. $sql = "
  2801. SELECT *
  2802. FROM " . $tbl_lp_item . "
  2803. WHERE
  2804. lp_id = " . $this->lp_id;
  2805. $result = api_sql_query($sql, __FILE__, __LINE__);
  2806. $arrLP = array();
  2807. while($row = Database::fetch_array($result))
  2808. {
  2809. $arrLP[] = array(
  2810. 'id' => $row['id'],
  2811. 'item_type' => $row['item_type'],
  2812. 'title' => $row['title'],
  2813. 'path' => $row['path'],
  2814. 'description' => $row['description'],
  2815. 'parent_item_id' => $row['parent_item_id'],
  2816. 'previous_item_id' => $row['previous_item_id'],
  2817. 'next_item_id' => $row['next_item_id'],
  2818. 'display_order' => $row['display_order']);
  2819. }
  2820. $this->tree_array($arrLP);
  2821. $arrLP = $this->arrMenu;
  2822. unset($this->arrMenu);
  2823. for($i = 0; $i < count($arrLP); $i++)
  2824. {
  2825. $menu_page = $_SERVER['PHP_SELF'] . '?cidReq=' . $_GET['cidReq'] . '&amp;action=view_item&amp;id=' . $arrLP[$i]['id'] . '&amp;lp_id=' . $_SESSION['oLP']->lp_id;
  2826. $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";
  2827. if($menu < $arrLP[$i]['id'])
  2828. $menu = $arrLP[$i]['id'];
  2829. }
  2830. $return .= "\n\tdocument.write(m);\n";
  2831. $return .= "</script>\n";
  2832. return $return;
  2833. }
  2834. /**
  2835. * Create a new document //still needs some finetuning
  2836. *
  2837. * @param array $_course
  2838. * @return string
  2839. */
  2840. function create_document($_course)
  2841. {
  2842. $dir = isset($_GET['dir']) ? $_GET['dir'] : $_POST['dir']; // please do not modify this dirname formatting
  2843. if(strstr($dir, '..'))
  2844. $dir = '/';
  2845. if($dir[0] == '.')
  2846. $dir = substr($dir, 1);
  2847. if($dir[0] != '/')
  2848. $dir = '/'.$dir;
  2849. if($dir[strlen($dir) - 1] != '/')
  2850. $dir .= '/';
  2851. $filepath = api_get_path('SYS_COURSE_PATH') . $_course['path'] . '/document' . $dir;
  2852. if(!is_dir($filepath))
  2853. {
  2854. $filepath = api_get_path('SYS_COURSE_PATH') . $_course['path'] . '/document/';
  2855. $dir = '/';
  2856. }
  2857. $title = replace_dangerous_char($_POST['title']);
  2858. $filename = $title;
  2859. $content = $_POST['content'];
  2860. $tmp_filename = $filename;
  2861. while(file_exists($filepath . $tmp_filename . '.html'))
  2862. $tmp_filename = $filename . '_' . ++$i;
  2863. $filename = $tmp_filename . '.html';
  2864. $content = stripslashes(text_filter($content));
  2865. $path_to_remove = api_get_path('WEB_COURSE_PATH') . $_course['path'] . '/document' . $dir;
  2866. $content = str_replace($path_to_remove, './', $content);
  2867. if(!file_exists($filepath . $filename))
  2868. {
  2869. if($fp = @fopen($filepath . $filename, 'w'))
  2870. {
  2871. fputs($fp, $content);
  2872. fclose($fp);
  2873. $file_size = filesize($filepath . $filename);
  2874. $save_file_path = $dir . $filename;
  2875. $document_id = add_document($_course, $save_file_path, 'file', $file_size, $filename . '.html');
  2876. if($document_id)
  2877. {
  2878. api_item_property_update($_course, TOOL_DOCUMENT, $document_id, 'DocumentAdded', $_uid, $to_group_id);
  2879. //update parent folders
  2880. //item_property_update_on_folder($_course, $_GET['dir'], $_uid);
  2881. $new_comment = (isset($_POST['comment'])) ? trim($_POST['comment']) : '';
  2882. $new_title = (isset($_POST['title'])) ? trim($_POST['title']) : '';
  2883. if($new_comment || $new_title)
  2884. {
  2885. $tbl_doc = Database::get_course_table(DOCUMENT_TABLE);
  2886. $ct = '';
  2887. if($new_comment)
  2888. $ct .= ", comment='" . $new_comment . "'";
  2889. if($new_title)
  2890. $ct .= ", title='" . $new_title . ".html '";
  2891. $sql_update = "
  2892. UPDATE " . $tbl_doc . "
  2893. SET " . substr($ct, 1) . "
  2894. WHERE id = " . $document_id;
  2895. api_sql_query($sql_update, __FILE__, __LINE__);
  2896. }
  2897. }
  2898. return $document_id;
  2899. }
  2900. }
  2901. }
  2902. /**
  2903. * Enter description here...
  2904. *
  2905. * @param array $_course
  2906. */
  2907. function edit_document($_course)
  2908. {
  2909. $dir = isset($_GET['dir']) ? $_GET['dir'] : $_POST['dir']; // please do not modify this dirname formatting
  2910. if(strstr($dir, '..'))
  2911. $dir = '/';
  2912. if($dir[0] == '.')
  2913. $dir = substr($dir, 1);
  2914. if($dir[0] != '/')
  2915. $dir = '/'.$dir;
  2916. if($dir[strlen($dir) - 1] != '/')
  2917. $dir .= '/';
  2918. $filepath = api_get_path('SYS_COURSE_PATH') . $_course['path'] . '/document'.$dir;
  2919. if(!is_dir($filepath))
  2920. {
  2921. $filepath = api_get_path('SYS_COURSE_PATH') . $_course['path'] . '/document/';
  2922. $dir = '/';
  2923. }
  2924. $table_doc = Database::get_course_table(DOCUMENT_TABLE);
  2925. $sql = "
  2926. SELECT path
  2927. FROM " . $table_doc . "
  2928. WHERE id = " . $_POST['path'];
  2929. $res = api_sql_query($sql, __FILE__, __LINE__);
  2930. $row = Database::fetch_array($res);
  2931. $content = stripslashes($_POST['content']);
  2932. $file = $filepath . $row['path'];
  2933. if($fp = @fopen($file, 'w'))
  2934. {
  2935. $content = text_filter($content);
  2936. $path_to_remove = api_get_path('WEB_COURSE_PATH') . $_course['path'] . '/document' . $dir;
  2937. $content = str_replace($path_to_remove, './', $content);
  2938. fputs($fp, $content);
  2939. fclose($fp);
  2940. }
  2941. }
  2942. /**
  2943. * Displays the selected item, with a panel for manipulating the item
  2944. *
  2945. * @param int $item_id
  2946. * @param string $msg
  2947. * @return string
  2948. */
  2949. function display_item($item_id, $iframe = true, $msg = '')
  2950. {
  2951. global $_course; //will disappear
  2952. $return = '';
  2953. if(is_numeric($item_id))
  2954. {
  2955. $tbl_lp_item = Database::get_course_table('lp_item');
  2956. $tbl_doc = Database::get_course_table(DOCUMENT_TABLE);
  2957. $sql = "
  2958. SELECT
  2959. lp.*
  2960. FROM " . $tbl_lp_item . " as lp
  2961. WHERE
  2962. lp.id = " . $item_id;
  2963. $result = api_sql_query($sql, __FILE__, __LINE__);
  2964. while($row = Database::fetch_array($result))
  2965. {
  2966. $return .= $this->display_manipulate($item_id, $row['item_type']);
  2967. $return .= '<div style="padding:10px;">';
  2968. if($msg != '')
  2969. $return .= $msg;
  2970. $return .= '<p class="lp_title">' . stripslashes($row['title']) . '</p>';
  2971. $return .= '<p class="lp_text">' . ((trim($row['description']) == '') ? 'no description' : stripslashes($row['description'])) . '</p>';
  2972. $return .= '<hr />';
  2973. if($row['item_type'] == TOOL_DOCUMENT)
  2974. $return .= $this->display_document($row['path'], true, true);
  2975. $return .= '</div>';
  2976. }
  2977. }
  2978. return $return;
  2979. }
  2980. /**
  2981. * Shows the needed forms for editing a specific item
  2982. *
  2983. * @param int $item_id
  2984. * @return string
  2985. */
  2986. function display_edit_item($item_id)
  2987. {
  2988. global $_course; //will disappear
  2989. $return = '';
  2990. if(is_numeric($item_id))
  2991. {
  2992. $tbl_lp_item = Database::get_course_table('lp_item');
  2993. $sql = "
  2994. SELECT *
  2995. FROM " . $tbl_lp_item . "
  2996. WHERE id = " . $item_id;
  2997. $res = api_sql_query($sql, __FILE__, __LINE__);
  2998. $row = Database::fetch_array($res);
  2999. switch($row['item_type'])
  3000. {
  3001. case 'dokeos_chapter':
  3002. if(isset($_GET['view']) && $_GET['view'] == 'build')
  3003. {
  3004. $return .= $this->display_manipulate($item_id, $row['item_type']);
  3005. $return .= $this->display_item_form($row['item_type'], 'Edit the current chapter:', 'edit', $item_id, $row);
  3006. }
  3007. else
  3008. {
  3009. $return .= $this->display_item_small_form($row['item_type'], 'Edit the current chapter:', $row);
  3010. }
  3011. break;
  3012. case TOOL_DOCUMENT:
  3013. $tbl_doc = Database::get_course_table(DOCUMENT_TABLE);
  3014. $sql_step = "
  3015. SELECT
  3016. lp.*,
  3017. doc.path as dir
  3018. FROM " . $tbl_lp_item . " as lp
  3019. LEFT JOIN " . $tbl_doc . " as doc ON doc.id = lp.path
  3020. WHERE
  3021. lp.id = " . $item_id;
  3022. $res_step = api_sql_query($sql_step, __FILE__, __LINE__);
  3023. $row_step = Database::fetch_array($res_step);
  3024. $return .= $this->display_manipulate($item_id, $row['item_type']);
  3025. $return .= $this->display_document_form('edit', $item_id, $row_step);
  3026. break;
  3027. case TOOL_LINK:
  3028. $return .= $this->display_manipulate($item_id, $row['item_type']);
  3029. $return .= $this->display_link_form('edit', $item_id, $row);
  3030. break;
  3031. case 'dokeos_module':
  3032. if(isset($_GET['view']) && $_GET['view'] == 'build')
  3033. {
  3034. $return .= $this->display_manipulate($item_id, $row['item_type']);
  3035. $return .= $this->display_item_form($row['item_type'], 'Edit the current module:', 'edit', $item_id, $row);
  3036. }
  3037. else
  3038. {
  3039. $return .= $this->display_item_small_form($row['item_type'], 'Edit the current module:', $row);
  3040. }
  3041. break;
  3042. case TOOL_QUIZ:
  3043. $return .= $this->display_manipulate($item_id, $row['item_type']);
  3044. $return .= $this->display_quiz_form('edit', $item_id, $row);
  3045. break;
  3046. case TOOL_STUDENTPUBLICATION:
  3047. $return .= $this->display_manipulate($item_id, $row['item_type']);
  3048. $return .= $this->display_student_publication_form('edit', $item_id, $row);
  3049. break;
  3050. }
  3051. }
  3052. return $return;
  3053. }
  3054. /**
  3055. * Function that displays a list with al the resources that could be added to the learning path
  3056. *
  3057. * @return string
  3058. */
  3059. function display_resources()
  3060. {
  3061. global $_course; //TODO: don't use globals
  3062. $return = '<div style="margin:3px 10px;">' . "\n";
  3063. $return .= '<p class="lp_title" style="margin-top:0;">Create a new step:</p>';
  3064. $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 . '">New document</a></div>';
  3065. $return .= '<p class="lp_title" style="margin-top:10px;">Or use an existing resource:</p>';
  3066. /* get al the docs */
  3067. $return .= $this->get_documents();
  3068. /* get al the exercises */
  3069. $return .= $this->get_exercises();
  3070. /* get al links */
  3071. $return .= $this->get_links();
  3072. /* get al the student publications */
  3073. $return .= $this->get_student_publications();
  3074. $return .= '</div>' . "\n";
  3075. return $return;
  3076. }
  3077. /**
  3078. * Returns the extension of a document
  3079. *
  3080. * @param unknown_type $filename
  3081. * @return unknown
  3082. */
  3083. function get_extension($filename)
  3084. {
  3085. $explode = explode('.', $filename);
  3086. return $explode[count($explode) - 1];
  3087. }
  3088. /**
  3089. * Displays a document by id
  3090. *
  3091. * @param unknown_type $id
  3092. * @return unknown
  3093. */
  3094. function display_document($id, $show_title = false, $iframe = true, $edit_link = false)
  3095. {
  3096. global $_course; //temporary
  3097. $return = '';
  3098. $tbl_doc = Database::get_course_table(DOCUMENT_TABLE);
  3099. $sql_doc = "
  3100. SELECT *
  3101. FROM " . $tbl_doc . "
  3102. WHERE id = " . $id;
  3103. $res_doc = api_sql_query($sql_doc, __FILE__, __LINE__);
  3104. $row_doc = Database::fetch_array($res_doc);
  3105. if($show_title)
  3106. $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>';
  3107. //TODO: add a path filter
  3108. if($iframe)
  3109. $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:400px; width:100%;"></iframe>';
  3110. else
  3111. $return .= file_get_contents(api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document' . $row_doc['path']);
  3112. return $return;
  3113. }
  3114. /**
  3115. * Enter description here...
  3116. *
  3117. * @param unknown_type $action
  3118. * @param unknown_type $id
  3119. * @param unknown_type $extra_info
  3120. * @return unknown
  3121. */
  3122. function display_quiz_form($action = 'add', $id = 0, $extra_info = '')
  3123. {
  3124. $tbl_lp_item = Database::get_course_table('lp_item');
  3125. $tbl_quiz = Database::get_course_table(QUIZ_TEST_TABLE);
  3126. if($id != 0 && is_array($extra_info))
  3127. {
  3128. $item_title = stripslashes($extra_info['title']);
  3129. $item_description = stripslashes($extra_info['description']);
  3130. }
  3131. elseif(is_numeric($extra_info))
  3132. {
  3133. $sql_quiz = "
  3134. SELECT
  3135. title,
  3136. description
  3137. FROM " . $tbl_quiz . "
  3138. WHERE id = " . $extra_info;
  3139. $result = api_sql_query($sql_quiz, __FILE__, __LINE__);
  3140. $row = Database::fetch_array($result);
  3141. $item_title = $row['title'];
  3142. $item_description = $row['description'];
  3143. }
  3144. else
  3145. {
  3146. $item_title = '';
  3147. $item_description = '';
  3148. }
  3149. $return = '<div style="margin:3px 10px;">';
  3150. if($id != 0 && is_array($extra_info))
  3151. $parent = $extra_info['parent_item_id'];
  3152. else
  3153. $parent = 0;
  3154. $sql = "
  3155. SELECT *
  3156. FROM " . $tbl_lp_item . "
  3157. WHERE
  3158. lp_id = " . $this->lp_id;
  3159. $result = api_sql_query($sql, __FILE__, __LINE__);
  3160. $arrLP = array();
  3161. while($row = Database::fetch_array($result))
  3162. {
  3163. $arrLP[] = array(
  3164. 'id' => $row['id'],
  3165. 'item_type' => $row['item_type'],
  3166. 'title' => $row['title'],
  3167. 'path' => $row['path'],
  3168. 'description' => $row['description'],
  3169. 'parent_item_id' => $row['parent_item_id'],
  3170. 'previous_item_id' => $row['previous_item_id'],
  3171. 'next_item_id' => $row['next_item_id'],
  3172. 'display_order' => $row['display_order']);
  3173. }
  3174. $this->tree_array($arrLP);
  3175. $arrLP = $this->arrMenu;
  3176. unset($this->arrMenu);
  3177. if($action == 'add')
  3178. $return .= '<p class="lp_title">Create the exercise:</p>' . "\n";
  3179. elseif($action == 'move')
  3180. $return .= '<p class="lp_title">Move the current exercise:</p>' . "\n";
  3181. else
  3182. $return .= '<p class="lp_title">Edit the current exercise:</p>' . "\n";
  3183. if(isset($_GET['edit']) && $_GET['edit'] == 'true')
  3184. {
  3185. $return .= '<div class="lp_message" style="margin-bottom:15px;">';
  3186. $return .= '<p class="lp_title">Warning !</p>';
  3187. $return .= 'When you edit an existing document in the Learning Path, the new version of the document will not overwrite the old version but will be saved as a new document. If you want to edit a document definitively, you can do that with the document tool.';
  3188. $return .= '</div>';
  3189. }
  3190. $return .= '<form method="POST">' . "\n";
  3191. $return .= "\t" . '<table cellpadding="0" cellspacing="0" class="lp_form">' . "\n";
  3192. $return .= "\t\t" . '<tr>' . "\n";
  3193. $return .= "\t\t\t" . '<td class="label"><label for="idParent">Parent:</label></td>' . "\n";
  3194. $return .= "\t\t\t" . '<td class="input">' . "\n";
  3195. $return .= "\t\t\t\t" . '<select id="idParent" name="parent" onchange="load_cbo(this.value);" size="1">';
  3196. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
  3197. $arrHide = array($id);
  3198. for($i = 0; $i < count($arrLP); $i++)
  3199. {
  3200. if($action != 'add')
  3201. {
  3202. 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))
  3203. {
  3204. $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>';
  3205. }
  3206. else
  3207. {
  3208. $arrHide[] = $arrLP[$i]['id'];
  3209. }
  3210. }
  3211. else
  3212. {
  3213. if($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter')
  3214. $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>';
  3215. }
  3216. }
  3217. reset($arrLP);
  3218. $return .= "\t\t\t\t" . '</select>';
  3219. $return .= "\t\t\t" . '</td>' . "\n";
  3220. $return .= "\t\t" . '</tr>' . "\n";
  3221. $return .= "\t\t" . '<tr>' . "\n";
  3222. $return .= "\t\t\t" . '<td class="label"><label for="idPosition">Position:</label></td>' . "\n";
  3223. $return .= "\t\t\t" . '<td class="input">' . "\n";
  3224. $return .= "\t\t\t\t" . '<select id="idPosition" name="previous" size="1">';
  3225. $return .= "\t\t\t\t\t" . '<option class="top" value="0">First position</option>';
  3226. for($i = 0; $i < count($arrLP); $i++)
  3227. {
  3228. if($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id)
  3229. {
  3230. if($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  3231. $selected = 'selected="selected" ';
  3232. elseif($action == 'add')
  3233. $selected = 'selected="selected" ';
  3234. else
  3235. $selected = '';
  3236. $return .= "\t\t\t\t\t" . '<option ' . $selected . 'value="' . $arrLP[$i]['id'] . '">After "' . html_entity_decode(stripslashes($arrLP[$i]['title'])) . '"</option>';
  3237. }
  3238. }
  3239. $return .= "\t\t\t\t" . '</select>';
  3240. $return .= "\t\t\t" . '</td>' . "\n";
  3241. $return .= "\t\t" . '</tr>' . "\n";
  3242. if($action != 'move')
  3243. {
  3244. $return .= "\t\t" . '<tr>' . "\n";
  3245. $return .= "\t\t\t" . '<td class="label"><label for="idTitle">Title:</label></td>' . "\n";
  3246. $return .= "\t\t\t" . '<td class="input"><input id="idTitle" name="title" type="text" value="' . $item_title . '" /></td>' . "\n";
  3247. $return .= "\t\t" . '</tr>' . "\n";
  3248. $return .= "\t\t" . '<tr>' . "\n";
  3249. $return .= "\t\t\t" . '<td class="label"><label for="idDescription">Description:</label></td>' . "\n";
  3250. $return .= "\t\t\t" . '<td class="input"><textarea id="idDescription" name="description" rows="4">' . $item_description . '</textarea></td>' . "\n";
  3251. $return .= "\t\t" . '</tr>' . "\n";
  3252. }
  3253. $return .= "\t\t" . '<tr>' . "\n";
  3254. $return .= "\t\t\t" . '<td colspan="2"><input class="button" name="submit_button" type="submit" value="OK" /></td>' . "\n";
  3255. $return .= "\t\t" . '</tr>' . "\n";
  3256. $return .= "\t" . '</table>' . "\n";
  3257. if($action == 'move')
  3258. {
  3259. $return .= "\t" . '<input name="title" type="hidden" value="' . $item_title . '" />' . "\n";
  3260. $return .= "\t" . '<input name="description" type="hidden" value="' . $item_description . '" />' . "\n";
  3261. }
  3262. if(is_numeric($extra_info))
  3263. {
  3264. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info . '" />' . "\n";
  3265. }
  3266. elseif(is_array($extra_info))
  3267. {
  3268. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />' . "\n";
  3269. }
  3270. $return .= "\t" . '<input name="type" type="hidden" value="'.TOOL_QUIZ.'" />' . "\n";
  3271. $return .= "\t" . '<input name="post_time" type="hidden" value="' . time() . '" />' . "\n";
  3272. $return .= '</form>' . "\n";
  3273. $return .= '</div>' . "\n";
  3274. return $return;
  3275. }
  3276. /**
  3277. * Enter description here...
  3278. *
  3279. * @param unknown_type $item_type
  3280. * @param unknown_type $title
  3281. * @param unknown_type $action
  3282. * @param unknown_type $id
  3283. * @param unknown_type $extra_info
  3284. * @return unknown
  3285. */
  3286. function display_item_form($item_type, $title = '', $action = 'add', $id = 0, $extra_info = 'new')
  3287. {
  3288. $tbl_lp_item = Database::get_course_table('lp_item');
  3289. if($id != 0 && is_array($extra_info))
  3290. {
  3291. $item_title = stripslashes($extra_info['title']);
  3292. $item_description = stripslashes($extra_info['description']);
  3293. }
  3294. else
  3295. {
  3296. $item_title = '';
  3297. $item_description = '';
  3298. }
  3299. $return = '<div style="margin:3px 10px;">';
  3300. if($id != 0 && is_array($extra_info))
  3301. $parent = $extra_info['parent_item_id'];
  3302. else
  3303. $parent = 0;
  3304. $sql = "
  3305. SELECT *
  3306. FROM " . $tbl_lp_item . "
  3307. WHERE
  3308. lp_id = " . $this->lp_id;
  3309. if($item_type == 'module')
  3310. $sql .= " AND parent_item_id = 0";
  3311. $result = api_sql_query($sql, __FILE__, __LINE__);
  3312. $arrLP = array();
  3313. while($row = Database::fetch_array($result))
  3314. {
  3315. $arrLP[] = array(
  3316. 'id' => $row['id'],
  3317. 'item_type' => $row['item_type'],
  3318. 'title' => $row['title'],
  3319. 'path' => $row['path'],
  3320. 'description' => $row['description'],
  3321. 'parent_item_id' => $row['parent_item_id'],
  3322. 'previous_item_id' => $row['previous_item_id'],
  3323. 'next_item_id' => $row['next_item_id'],
  3324. 'display_order' => $row['display_order']);
  3325. }
  3326. $this->tree_array($arrLP);
  3327. $arrLP = $this->arrMenu;
  3328. unset($this->arrMenu);
  3329. $return .= '<p class="lp_title">' . $title . '</p>' . "\n";
  3330. $return .= '<form method="POST">' . "\n";
  3331. $return .= "\t" . '<table cellpadding="0" cellspacing="0" class="lp_form">' . "\n";
  3332. if($item_type != 'module' && $item_type != 'dokeos_module')
  3333. {
  3334. $return .= "\t\t" . '<tr>' . "\n";
  3335. $return .= "\t\t\t" . '<td class="label"><label for="idParent">Parent:</label></td>' . "\n";
  3336. $return .= "\t\t\t" . '<td class="input">' . "\n";
  3337. $return .= "\t\t\t\t" . '<select id="idParent" name="parent" onchange="load_cbo(this.value);" size="1">';
  3338. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
  3339. $arrHide = array($id);
  3340. for($i = 0; $i < count($arrLP); $i++)
  3341. {
  3342. if($action != 'add')
  3343. {
  3344. 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))
  3345. {
  3346. $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>';
  3347. }
  3348. else
  3349. {
  3350. $arrHide[] = $arrLP[$i]['id'];
  3351. }
  3352. }
  3353. else
  3354. {
  3355. if($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter')
  3356. $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>';
  3357. }
  3358. }
  3359. reset($arrLP);
  3360. $return .= "\t\t\t\t" . '</select>';
  3361. $return .= "\t\t\t" . '</td>' . "\n";
  3362. $return .= "\t\t" . '</tr>' . "\n";
  3363. }
  3364. $return .= "\t\t" . '<tr>' . "\n";
  3365. $return .= "\t\t\t" . '<td class="label"><label for="idPosition">Position:</label></td>' . "\n";
  3366. $return .= "\t\t\t" . '<td class="input">' . "\n";
  3367. $return .= "\t\t\t\t" . '<select id="idPosition" name="previous" size="1">';
  3368. $return .= "\t\t\t\t\t" . '<option class="top" value="0">First position</option>';
  3369. for($i = 0; $i < count($arrLP); $i++)
  3370. {
  3371. if($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id)
  3372. {
  3373. if($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  3374. $selected = 'selected="selected" ';
  3375. elseif($action == 'add')
  3376. $selected = 'selected="selected" ';
  3377. else
  3378. $selected = '';
  3379. $return .= "\t\t\t\t\t" . '<option ' . $selected . 'value="' . $arrLP[$i]['id'] . '">After "' . html_entity_decode(stripslashes($arrLP[$i]['title'])) . '"</option>';
  3380. }
  3381. }
  3382. $return .= "\t\t\t\t" . '</select>';
  3383. $return .= "\t\t\t" . '</td>' . "\n";
  3384. $return .= "\t\t" . '</tr>' . "\n";
  3385. if($action != 'move')
  3386. {
  3387. $return .= "\t\t" . '<tr>' . "\n";
  3388. $return .= "\t\t\t" . '<td class="label"><label for="idTitle">Title:</label></td>' . "\n";
  3389. $return .= "\t\t\t" . '<td class="input"><input id="idTitle" name="title" type="text" value="' . $item_title . '" /></td>' . "\n";
  3390. $return .= "\t\t" . '</tr>' . "\n";
  3391. $return .= "\t\t" . '<tr>' . "\n";
  3392. $return .= "\t\t\t" . '<td class="label"><label for="idDescription">Description:</label></td>' . "\n";
  3393. $return .= "\t\t\t" . '<td class="input"><textarea id="idDescription" name="description" rows="4">' . $item_description . '</textarea></td>' . "\n";
  3394. $return .= "\t\t" . '</tr>' . "\n";
  3395. }
  3396. $return .= "\t\t" . '<tr>' . "\n";
  3397. $return .= "\t\t\t" . '<td colspan="2"><input class="button" name="submit_button" type="submit" value="OK" /></td>' . "\n";
  3398. $return .= "\t\t" . '</tr>' . "\n";
  3399. $return .= "\t" . '</table>' . "\n";
  3400. if($item_type == 'module' || $item_type == 'dokeos_module')
  3401. $return .= "\t" . '<input name="parent" type="hidden" value="0" />' . "\n";
  3402. if($action == 'move')
  3403. {
  3404. $return .= "\t" . '<input name="title" type="hidden" value="' . $item_title . '" />' . "\n";
  3405. $return .= "\t" . '<input name="description" type="hidden" value="' . $item_description . '" />' . "\n";
  3406. }
  3407. /*if($id != 0 && is_array($extra_info))
  3408. {
  3409. $return .= "\t" . '<input name="old_previous" type="hidden" value="' . $extra_info['parent_item_id'] . '" />' . "\n";
  3410. $return .= "\t" . '<input name="old_next" type="hidden" value="' . $extra_info['previous_item_id'] . '" />' . "\n";
  3411. }*/
  3412. $return .= "\t" . '<input name="type" type="hidden" value="dokeos_' . $item_type . '" />' . "\n";
  3413. $return .= "\t" . '<input name="post_time" type="hidden" value="' . time() . '" />' . "\n";
  3414. $return .= '</form>' . "\n";
  3415. $return .= '</div>' . "\n";
  3416. return $return;
  3417. }
  3418. /**
  3419. * Enter description here...
  3420. *
  3421. * @param unknown_type $action
  3422. * @param unknown_type $id
  3423. * @param unknown_type $extra_info
  3424. * @return unknown
  3425. */
  3426. function display_document_form($action = 'add', $id = 0, $extra_info = 'new')
  3427. {
  3428. $tbl_lp_item = Database::get_course_table('lp_item');
  3429. $tbl_doc = Database::get_course_table(DOCUMENT_TABLE);
  3430. if($id != 0 && is_array($extra_info))
  3431. {
  3432. $item_title = stripslashes($extra_info['title']);
  3433. $item_description = stripslashes($extra_info['description']);
  3434. }
  3435. elseif(is_numeric($extra_info))
  3436. {
  3437. $sql_doc = "
  3438. SELECT title
  3439. FROM " . $tbl_doc . "
  3440. WHERE id = " . $extra_info;
  3441. $result = api_sql_query($sql_doc, __FILE__, __LINE__);
  3442. $row = Database::fetch_array($result);
  3443. $explode = explode('.', $row['title']);
  3444. for($i = 0; $i < count($explode) - 1; $i++)
  3445. $item_title .= $explode[$i];
  3446. $item_title = str_replace('_', ' ', $item_title);
  3447. }
  3448. else
  3449. {
  3450. $item_title = '';
  3451. $item_description = '';
  3452. }
  3453. $return = '<div style="margin:3px 10px;">';
  3454. if($id != 0 && is_array($extra_info))
  3455. $parent = $extra_info['parent_item_id'];
  3456. else
  3457. $parent = 0;
  3458. $sql = "
  3459. SELECT *
  3460. FROM " . $tbl_lp_item . "
  3461. WHERE
  3462. lp_id = " . $this->lp_id;
  3463. $result = api_sql_query($sql, __FILE__, __LINE__);
  3464. $arrLP = array();
  3465. while($row = Database::fetch_array($result))
  3466. {
  3467. $arrLP[] = array(
  3468. 'id' => $row['id'],
  3469. 'item_type' => $row['item_type'],
  3470. 'title' => $row['title'],
  3471. 'path' => $row['path'],
  3472. 'description' => $row['description'],
  3473. 'parent_item_id' => $row['parent_item_id'],
  3474. 'previous_item_id' => $row['previous_item_id'],
  3475. 'next_item_id' => $row['next_item_id'],
  3476. 'display_order' => $row['display_order']);
  3477. }
  3478. $this->tree_array($arrLP);
  3479. $arrLP = $this->arrMenu;
  3480. unset($this->arrMenu);
  3481. if($action == 'add')
  3482. $return .= '<p class="lp_title">Create the document:</p>' . "\n";
  3483. elseif($action == 'move')
  3484. $return .= '<p class="lp_title">Move the current document:</p>' . "\n";
  3485. else
  3486. $return .= '<p class="lp_title">Edit the current document:</p>' . "\n";
  3487. if(isset($_GET['edit']) && $_GET['edit'] == 'true')
  3488. {
  3489. $return .= '<div class="lp_message" style="margin-bottom:15px;">';
  3490. $return .= '<p class="lp_title">Warning !</p>';
  3491. $return .= 'When you edit an existing document in the Learning Path, the new version of the document will not overwrite the old version but will be saved as a new document. If you want to edit a document definitively, you can do that with the document tool.';
  3492. $return .= '</div>';
  3493. }
  3494. $return .= '<form method="POST">' . "\n";
  3495. $return .= "\t" . '<table cellpadding="0" cellspacing="0" class="lp_form">' . "\n";
  3496. $return .= "\t\t" . '<tr>' . "\n";
  3497. $return .= "\t\t\t" . '<td class="label"><label for="idParent">Parent:</label></td>' . "\n";
  3498. $return .= "\t\t\t" . '<td class="input">' . "\n";
  3499. $return .= "\t\t\t\t" . '<select id="idParent" name="parent" onchange="load_cbo(this.value);" size="1">';
  3500. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
  3501. $arrHide = array($id);
  3502. for($i = 0; $i < count($arrLP); $i++)
  3503. {
  3504. if($action != 'add')
  3505. {
  3506. 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))
  3507. {
  3508. $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>';
  3509. }
  3510. else
  3511. {
  3512. $arrHide[] = $arrLP[$i]['id'];
  3513. }
  3514. }
  3515. else
  3516. {
  3517. if($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter')
  3518. $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>';
  3519. }
  3520. }
  3521. reset($arrLP);
  3522. $return .= "\t\t\t\t" . '</select>';
  3523. $return .= "\t\t\t" . '</td>' . "\n";
  3524. $return .= "\t\t" . '</tr>' . "\n";
  3525. $return .= "\t\t" . '<tr>' . "\n";
  3526. $return .= "\t\t\t" . '<td class="label"><label for="idPosition">Position:</label></td>' . "\n";
  3527. $return .= "\t\t\t" . '<td class="input">' . "\n";
  3528. $return .= "\t\t\t\t" . '<select id="idPosition" name="previous" size="1">';
  3529. $return .= "\t\t\t\t\t" . '<option class="top" value="0">First position</option>';
  3530. for($i = 0; $i < count($arrLP); $i++)
  3531. {
  3532. if($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id)
  3533. {
  3534. if($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  3535. $selected = 'selected="selected" ';
  3536. elseif($action == 'add')
  3537. $selected = 'selected="selected" ';
  3538. else
  3539. $selected = '';
  3540. $return .= "\t\t\t\t\t" . '<option ' . $selected . 'value="' . $arrLP[$i]['id'] . '">After "' . html_entity_decode(stripslashes($arrLP[$i]['title'])) . '"</option>';
  3541. }
  3542. }
  3543. $return .= "\t\t\t\t" . '</select>';
  3544. $return .= "\t\t\t" . '</td>' . "\n";
  3545. $return .= "\t\t" . '</tr>' . "\n";
  3546. if($action != 'move')
  3547. {
  3548. $return .= "\t\t" . '<tr>' . "\n";
  3549. $return .= "\t\t\t" . '<td class="label"><label for="idTitle">Title:</label></td>' . "\n";
  3550. $return .= "\t\t\t" . '<td class="input"><input id="idTitle" name="title" type="text" value="' . $item_title . '" /></td>' . "\n";
  3551. $return .= "\t\t" . '</tr>' . "\n";
  3552. $return .= "\t\t" . '<tr>' . "\n";
  3553. $return .= "\t\t\t" . '<td class="label"><label for="idDescription">Description:</label></td>' . "\n";
  3554. $return .= "\t\t\t" . '<td class="input"><textarea id="idDescription" name="description" rows="4">' . $item_description . '</textarea></td>' . "\n";
  3555. $return .= "\t\t" . '</tr>' . "\n";
  3556. if(($extra_info == 'new' || $extra_info['item_type'] == TOOL_DOCUMENT || $_GET['edit'] == 'true'))
  3557. {
  3558. if($action == 'add' || $_GET['edit'] == 'true')
  3559. {
  3560. $return .= "\t\t" . '<tr>' . "\n";
  3561. $return .= "\t\t\t" . '<td class="label"><label for="idDir">Directory:</label></td>' . "\n";
  3562. $return .= "\t\t\t" . '<td class="input">';
  3563. $sql_doc = "
  3564. SELECT *
  3565. FROM " . $tbl_doc . "
  3566. WHERE
  3567. filetype = 'folder'
  3568. ORDER BY path ASC";
  3569. $result = api_sql_query($sql_doc, __FILE__, __LINE__);
  3570. $return .= "\t\t\t\t" . '<select id="idDir" name="dir" size="1">' . "\n";
  3571. $return .= "\t\t\t\t\t" . '<option value="/">/ ( root )</option>' . "\n";
  3572. while($row_doc = Database::fetch_array($result))
  3573. {
  3574. $return .= "\t\t\t\t\t" . '<option value="' . $row_doc['path'] . '">' . $row_doc['path'] . '</option>' . "\n";
  3575. }
  3576. $return .= "\t\t\t\t" . '</select>' . "\n";
  3577. $return .= "\t\t\t" . '</td>' . "\n";
  3578. $return .= "\t\t" . '</tr>' . "\n";
  3579. }
  3580. $return .= "\t\t" . '<tr>' . "\n";
  3581. $return .= "\t\t\t" . '<td colspan="2">' . "\n";
  3582. if(isset($_POST['content']))
  3583. $content = stripslashes($_POST['content']);
  3584. elseif(is_array($extra_info))
  3585. $content = $this->display_document($extra_info['path'], false, false);
  3586. elseif(is_numeric($extra_info))
  3587. $content = $this->display_document($extra_info, false, false);
  3588. else
  3589. $content = '';
  3590. $oFCKeditor = new FCKeditor('content') ;
  3591. $oFCKeditor->BasePath = api_get_path(WEB_PATH) . 'main/inc/lib/fckeditor/' ;
  3592. $oFCKeditor->Height = '400';
  3593. $oFCKeditor->Width = '100%';
  3594. $oFCKeditor->Value = $content;
  3595. $return .= $oFCKeditor->CreateHtml();
  3596. $return .= "\t\t\t" . '</td>' . "\n";
  3597. $return .= "\t\t" . '</tr>' . "\n";
  3598. }
  3599. elseif(is_numeric($extra_info))
  3600. {
  3601. $return .= "\t\t" . '<tr>' . "\n";
  3602. $return .= "\t\t\t" . '<td colspan="2" style="background:#F8F8F8; border:1px solid #999999;">' . "\n";
  3603. $return .= $this->display_document($extra_info, true, true, true);
  3604. $return .= "\t\t\t" . '</td>' . "\n";
  3605. $return .= "\t\t" . '</tr>' . "\n";
  3606. }
  3607. }
  3608. $return .= "\t\t" . '<tr>' . "\n";
  3609. $return .= "\t\t\t" . '<td colspan="2"><input class="button" name="submit_button" type="submit" value="OK" /></td>' . "\n";
  3610. $return .= "\t\t" . '</tr>' . "\n";
  3611. $return .= "\t" . '</table>' . "\n";
  3612. if($action == 'move')
  3613. {
  3614. $return .= "\t" . '<input name="title" type="hidden" value="' . $item_title . '" />' . "\n";
  3615. $return .= "\t" . '<input name="description" type="hidden" value="' . $item_description . '" />' . "\n";
  3616. }
  3617. if(is_numeric($extra_info))
  3618. {
  3619. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info . '" />' . "\n";
  3620. }
  3621. elseif(is_array($extra_info))
  3622. {
  3623. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />' . "\n";
  3624. }
  3625. $return .= "\t" . '<input name="type" type="hidden" value="'.TOOL_DOCUMENT.'" />' . "\n";
  3626. $return .= "\t" . '<input name="post_time" type="hidden" value="' . time() . '" />' . "\n";
  3627. $return .= '</form>' . "\n";
  3628. $return .= '</div>' . "\n";
  3629. return $return;
  3630. }
  3631. /**
  3632. * Enter description here...
  3633. *
  3634. * @param unknown_type $action
  3635. * @param unknown_type $id
  3636. * @param unknown_type $extra_info
  3637. */
  3638. function display_link_form($action = 'add', $id = 0, $extra_info = '')
  3639. {
  3640. $tbl_lp_item = Database::get_course_table('lp_item');
  3641. $tbl_link = Database::get_course_table(LINK_TABLE);
  3642. if($id != 0 && is_array($extra_info))
  3643. {
  3644. $item_title = stripslashes($extra_info['title']);
  3645. $item_description = stripslashes($extra_info['description']);
  3646. }
  3647. elseif(is_numeric($extra_info))
  3648. {
  3649. $sql_link = "
  3650. SELECT
  3651. title,
  3652. description,
  3653. url
  3654. FROM " . $tbl_link . "
  3655. WHERE id = " . $extra_info;
  3656. $result = api_sql_query($sql_link, __FILE__, __LINE__);
  3657. $row = Database::fetch_array($result);
  3658. $item_title = $row['title'];
  3659. $item_description = $row['description'];
  3660. $item_url = $row['url'];
  3661. }
  3662. else
  3663. {
  3664. $item_title = '';
  3665. $item_description = '';
  3666. }
  3667. $return = '<div style="margin:3px 10px;">';
  3668. if($id != 0 && is_array($extra_info))
  3669. $parent = $extra_info['parent_item_id'];
  3670. else
  3671. $parent = 0;
  3672. $sql = "
  3673. SELECT *
  3674. FROM " . $tbl_lp_item . "
  3675. WHERE
  3676. lp_id = " . $this->lp_id;
  3677. $result = api_sql_query($sql, __FILE__, __LINE__);
  3678. $arrLP = array();
  3679. while($row = Database::fetch_array($result))
  3680. {
  3681. $arrLP[] = array(
  3682. 'id' => $row['id'],
  3683. 'item_type' => $row['item_type'],
  3684. 'title' => $row['title'],
  3685. 'path' => $row['path'],
  3686. 'description' => $row['description'],
  3687. 'parent_item_id' => $row['parent_item_id'],
  3688. 'previous_item_id' => $row['previous_item_id'],
  3689. 'next_item_id' => $row['next_item_id'],
  3690. 'display_order' => $row['display_order']);
  3691. }
  3692. $this->tree_array($arrLP);
  3693. $arrLP = $this->arrMenu;
  3694. unset($this->arrMenu);
  3695. if($action == 'add')
  3696. $return .= '<p class="lp_title">Create the link:</p>' . "\n";
  3697. elseif($action == 'move')
  3698. $return .= '<p class="lp_title">Move the current link:</p>' . "\n";
  3699. else
  3700. $return .= '<p class="lp_title">Edit the current link:</p>' . "\n";
  3701. $return .= '<form method="POST">' . "\n";
  3702. $return .= "\t" . '<table cellpadding="0" cellspacing="0" class="lp_form">' . "\n";
  3703. $return .= "\t\t" . '<tr>' . "\n";
  3704. $return .= "\t\t\t" . '<td class="label"><label for="idParent">Parent:</label></td>' . "\n";
  3705. $return .= "\t\t\t" . '<td class="input">' . "\n";
  3706. $return .= "\t\t\t\t" . '<select id="idParent" name="parent" onchange="load_cbo(this.value);" size="1">';
  3707. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
  3708. $arrHide = array($id);
  3709. for($i = 0; $i < count($arrLP); $i++)
  3710. {
  3711. if($action != 'add')
  3712. {
  3713. 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))
  3714. {
  3715. $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>';
  3716. }
  3717. else
  3718. {
  3719. $arrHide[] = $arrLP[$i]['id'];
  3720. }
  3721. }
  3722. else
  3723. {
  3724. if($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter')
  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. }
  3728. reset($arrLP);
  3729. $return .= "\t\t\t\t" . '</select>';
  3730. $return .= "\t\t\t" . '</td>' . "\n";
  3731. $return .= "\t\t" . '</tr>' . "\n";
  3732. $return .= "\t\t" . '<tr>' . "\n";
  3733. $return .= "\t\t\t" . '<td class="label"><label for="idPosition">Position:</label></td>' . "\n";
  3734. $return .= "\t\t\t" . '<td class="input">' . "\n";
  3735. $return .= "\t\t\t\t" . '<select id="idPosition" name="previous" size="1">';
  3736. $return .= "\t\t\t\t\t" . '<option class="top" value="0">First position</option>';
  3737. for($i = 0; $i < count($arrLP); $i++)
  3738. {
  3739. if($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id)
  3740. {
  3741. if($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  3742. $selected = 'selected="selected" ';
  3743. elseif($action == 'add')
  3744. $selected = 'selected="selected" ';
  3745. else
  3746. $selected = '';
  3747. $return .= "\t\t\t\t\t" . '<option ' . $selected . 'value="' . $arrLP[$i]['id'] . '">After "' . html_entity_decode(stripslashes($arrLP[$i]['title'])) . '"</option>';
  3748. }
  3749. }
  3750. $return .= "\t\t\t\t" . '</select>';
  3751. $return .= "\t\t\t" . '</td>' . "\n";
  3752. $return .= "\t\t" . '</tr>' . "\n";
  3753. if($action != 'move')
  3754. {
  3755. $return .= "\t\t" . '<tr>' . "\n";
  3756. $return .= "\t\t\t" . '<td class="label"><label for="idTitle">Title:</label></td>' . "\n";
  3757. $return .= "\t\t\t" . '<td class="input"><input id="idTitle" name="title" type="text" value="' . $item_title . '" /></td>' . "\n";
  3758. $return .= "\t\t" . '</tr>' . "\n";
  3759. $return .= "\t\t" . '<tr>' . "\n";
  3760. $return .= "\t\t\t" . '<td class="label"><label for="idDescription">Description:</label></td>' . "\n";
  3761. $return .= "\t\t\t" . '<td class="input"><textarea id="idDescription" name="description" rows="4">' . $item_description . '</textarea></td>' . "\n";
  3762. $return .= "\t\t" . '</tr>' . "\n";
  3763. $return .= "\t\t" . '<tr>' . "\n";
  3764. $return .= "\t\t\t" . '<td class="label"><label for="idURL">URL:</label></td>' . "\n";
  3765. $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";
  3766. $return .= "\t\t" . '</tr>' . "\n";
  3767. }
  3768. $return .= "\t\t" . '<tr>' . "\n";
  3769. $return .= "\t\t\t" . '<td colspan="2"><input class="button" name="submit_button" type="submit" value="OK" /></td>' . "\n";
  3770. $return .= "\t\t" . '</tr>' . "\n";
  3771. $return .= "\t" . '</table>' . "\n";
  3772. if($action == 'move')
  3773. {
  3774. $return .= "\t" . '<input name="title" type="hidden" value="' . $item_title . '" />' . "\n";
  3775. $return .= "\t" . '<input name="description" type="hidden" value="' . $item_description . '" />' . "\n";
  3776. }
  3777. if(is_numeric($extra_info))
  3778. {
  3779. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info . '" />' . "\n";
  3780. }
  3781. elseif(is_array($extra_info))
  3782. {
  3783. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />' . "\n";
  3784. }
  3785. $return .= "\t" . '<input name="type" type="hidden" value="'.TOOL_LINK.'" />' . "\n";
  3786. $return .= "\t" . '<input name="post_time" type="hidden" value="' . time() . '" />' . "\n";
  3787. $return .= '</form>' . "\n";
  3788. $return .= '</div>' . "\n";
  3789. return $return;
  3790. }
  3791. /**
  3792. * Enter description here...
  3793. *
  3794. * @param unknown_type $action
  3795. * @param unknown_type $id
  3796. * @param unknown_type $extra_info
  3797. * @return unknown
  3798. */
  3799. function display_student_publication_form($action = 'add', $id = 0, $extra_info = '')
  3800. {
  3801. $tbl_lp_item = Database::get_course_table('lp_item');
  3802. $tbl_publication = Database::get_course_table(STUDENT_PUBLICATION_TABLE);
  3803. if($id != 0 && is_array($extra_info))
  3804. {
  3805. $item_title = stripslashes($extra_info['title']);
  3806. $item_description = stripslashes($extra_info['description']);
  3807. }
  3808. elseif(is_numeric($extra_info))
  3809. {
  3810. $sql_publication = "
  3811. SELECT
  3812. title,
  3813. description
  3814. FROM " . $tbl_publication . "
  3815. WHERE id = " . $extra_info;
  3816. $result = api_sql_query($sql_publication, __FILE__, __LINE__);
  3817. $row = Database::fetch_array($result);
  3818. $item_title = $row['title'];
  3819. $item_description = $row['description'];
  3820. }
  3821. else
  3822. {
  3823. $item_title = '';
  3824. $item_description = '';
  3825. }
  3826. $return = '<div style="margin:3px 10px;">';
  3827. if($id != 0 && is_array($extra_info))
  3828. $parent = $extra_info['parent_item_id'];
  3829. else
  3830. $parent = 0;
  3831. $sql = "
  3832. SELECT *
  3833. FROM " . $tbl_lp_item . "
  3834. WHERE
  3835. lp_id = " . $this->lp_id;
  3836. $result = api_sql_query($sql, __FILE__, __LINE__);
  3837. $arrLP = array();
  3838. while($row = Database::fetch_array($result))
  3839. {
  3840. $arrLP[] = array(
  3841. 'id' => $row['id'],
  3842. 'item_type' => $row['item_type'],
  3843. 'title' => $row['title'],
  3844. 'path' => $row['path'],
  3845. 'description' => $row['description'],
  3846. 'parent_item_id' => $row['parent_item_id'],
  3847. 'previous_item_id' => $row['previous_item_id'],
  3848. 'next_item_id' => $row['next_item_id'],
  3849. 'display_order' => $row['display_order']);
  3850. }
  3851. $this->tree_array($arrLP);
  3852. $arrLP = $this->arrMenu;
  3853. unset($this->arrMenu);
  3854. if($action == 'add')
  3855. $return .= '<p class="lp_title">Create the student publication:</p>' . "\n";
  3856. elseif($action == 'move')
  3857. $return .= '<p class="lp_title">Move the current student publication:</p>' . "\n";
  3858. else
  3859. $return .= '<p class="lp_title">Edit the current student publication:</p>' . "\n";
  3860. $return .= '<form method="POST">' . "\n";
  3861. $return .= "\t" . '<table cellpadding="0" cellspacing="0" class="lp_form">' . "\n";
  3862. $return .= "\t\t" . '<tr>' . "\n";
  3863. $return .= "\t\t\t" . '<td class="label"><label for="idParent">Parent:</label></td>' . "\n";
  3864. $return .= "\t\t\t" . '<td class="input">' . "\n";
  3865. $return .= "\t\t\t\t" . '<select id="idParent" name="parent" onchange="load_cbo(this.value);" size="1">';
  3866. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
  3867. $arrHide = array($id);
  3868. for($i = 0; $i < count($arrLP); $i++)
  3869. {
  3870. if($action != 'add')
  3871. {
  3872. 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))
  3873. {
  3874. $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>';
  3875. }
  3876. else
  3877. {
  3878. $arrHide[] = $arrLP[$i]['id'];
  3879. }
  3880. }
  3881. else
  3882. {
  3883. if($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter')
  3884. $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>';
  3885. }
  3886. }
  3887. reset($arrLP);
  3888. $return .= "\t\t\t\t" . '</select>';
  3889. $return .= "\t\t\t" . '</td>' . "\n";
  3890. $return .= "\t\t" . '</tr>' . "\n";
  3891. $return .= "\t\t" . '<tr>' . "\n";
  3892. $return .= "\t\t\t" . '<td class="label"><label for="idPosition">Position:</label></td>' . "\n";
  3893. $return .= "\t\t\t" . '<td class="input">' . "\n";
  3894. $return .= "\t\t\t\t" . '<select id="idPosition" name="previous" size="1">';
  3895. $return .= "\t\t\t\t\t" . '<option class="top" value="0">First position</option>';
  3896. for($i = 0; $i < count($arrLP); $i++)
  3897. {
  3898. if($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id)
  3899. {
  3900. if($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  3901. $selected = 'selected="selected" ';
  3902. elseif($action == 'add')
  3903. $selected = 'selected="selected" ';
  3904. else
  3905. $selected = '';
  3906. $return .= "\t\t\t\t\t" . '<option ' . $selected . 'value="' . $arrLP[$i]['id'] . '">After "' . html_entity_decode(stripslashes($arrLP[$i]['title'])) . '"</option>';
  3907. }
  3908. }
  3909. $return .= "\t\t\t\t" . '</select>';
  3910. $return .= "\t\t\t" . '</td>' . "\n";
  3911. $return .= "\t\t" . '</tr>' . "\n";
  3912. if($action != 'move')
  3913. {
  3914. $return .= "\t\t" . '<tr>' . "\n";
  3915. $return .= "\t\t\t" . '<td class="label"><label for="idTitle">Title:</label></td>' . "\n";
  3916. $return .= "\t\t\t" . '<td class="input"><input id="idTitle" name="title" type="text" value="' . $item_title . '" /></td>' . "\n";
  3917. $return .= "\t\t" . '</tr>' . "\n";
  3918. $return .= "\t\t" . '<tr>' . "\n";
  3919. $return .= "\t\t\t" . '<td class="label"><label for="idDescription">Description:</label></td>' . "\n";
  3920. $return .= "\t\t\t" . '<td class="input"><textarea id="idDescription" name="description" rows="4">' . $item_description . '</textarea></td>' . "\n";
  3921. $return .= "\t\t" . '</tr>' . "\n";
  3922. }
  3923. $return .= "\t\t" . '<tr>' . "\n";
  3924. $return .= "\t\t\t" . '<td colspan="2"><input class="button" name="submit_button" type="submit" value="OK" /></td>' . "\n";
  3925. $return .= "\t\t" . '</tr>' . "\n";
  3926. $return .= "\t" . '</table>' . "\n";
  3927. if($action == 'move')
  3928. {
  3929. $return .= "\t" . '<input name="title" type="hidden" value="' . $item_title . '" />' . "\n";
  3930. $return .= "\t" . '<input name="description" type="hidden" value="' . $item_description . '" />' . "\n";
  3931. }
  3932. if(is_numeric($extra_info))
  3933. {
  3934. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info . '" />' . "\n";
  3935. }
  3936. elseif(is_array($extra_info))
  3937. {
  3938. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />' . "\n";
  3939. }
  3940. $return .= "\t" . '<input name="type" type="hidden" value="'.TOOL_STUDENTPUBLICATION.'" />' . "\n";
  3941. $return .= "\t" . '<input name="post_time" type="hidden" value="' . time() . '" />' . "\n";
  3942. $return .= '</form>' . "\n";
  3943. $return .= '</div>' . "\n";
  3944. return $return;
  3945. }
  3946. /**
  3947. * Displays the menu for manipulating a step
  3948. *
  3949. * @return unknown
  3950. */
  3951. function display_manipulate($item_id, $item_type = TOOL_DOCUMENT)
  3952. {
  3953. $return = '<div class="lp_manipulate">';
  3954. switch($item_type)
  3955. {
  3956. case 'dokeos_chapter':
  3957. case 'chapter':
  3958. $lang = get_lang('TitleManipulateChapter');
  3959. /* temp */ $lang = 'Manipulate the current chapter';
  3960. break;
  3961. case 'dokeos_module':
  3962. case 'module':
  3963. $lang = get_lang('TitleManipulateModule');
  3964. /* temp */ $lang = 'Manipulate the current module';
  3965. break;
  3966. case TOOL_DOCUMENT:
  3967. $lang = get_lang('TitleManipulateDocument');
  3968. /* temp */ $lang = 'Manipulate the current document';
  3969. break;
  3970. case TOOL_LINK:
  3971. case 'link':
  3972. $lang = get_lang('TitleManipulateLink');
  3973. /* temp */ $lang = 'Manipulate the current link';
  3974. break;
  3975. case TOOL_QUIZ:
  3976. $lang = get_lang('TitleManipulateQuiz');
  3977. /* temp */ $lang = 'Manipulate the current exercise';
  3978. break;
  3979. case TOOL_STUDENTPUBLICATION:
  3980. $lang = get_lang('TitleManipulateStudentPublication');
  3981. /* temp */ $lang = 'Manipulate the current student publication';
  3982. break;
  3983. }
  3984. $return .= '<p class="lp_title">' . $lang . '</p>';
  3985. $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 alt="Edit the current item" src="../img/edit.gif" title="Edit the current item" /> Edit</a>';
  3986. $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 alt="Move the current item" src="../img/move.gif" title="Move the current item" /> Move</a>';
  3987. if($item_type != 'chapter' && $item_type != 'dokeos_chapter' && $item_type != 'module' && $item_type != 'dokeos_module')
  3988. $return .= '<a href="' . $_SERVER['PHP_SELF'] . '?cidReq=' . $_GET['cidReq'] . '&amp;action=edit_item_prereq&amp;view=build&amp;id=' . $item_id . '&amp;lp_id=' . $this->lp_id . '" title="Edit the prerequisites of the current item"><img alt="Edit the prerequisites of the current item" src="../img/edit.gif" title="Edit the prerequisites of the current item" /> Prerequisites</a>';
  3989. $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" src="../img/delete.gif" title="Delete the current item" /> Delete</a>';
  3990. $return .= '</div>';
  3991. return $return;
  3992. }
  3993. /**
  3994. * Creates the javascript needed for filling up the checkboxes without page reload
  3995. *
  3996. * @return string
  3997. */
  3998. function create_js()
  3999. {
  4000. $return = '<script language="javascript" type="text/javascript">' . "\n";
  4001. $return .= 'function load_cbo(id){' . "\n";
  4002. $return .= "var cbo = document.getElementById('idPosition');";
  4003. $return .= 'for(var i = cbo.length - 1; i > 0; i--)';
  4004. $return .= 'cbo.options[i] = null;';
  4005. $return .= 'for(var i = 1; i <= child_name[id].length; i++)';
  4006. $return .= 'cbo.options[i] = new Option(child_name[id][i-1], child_value[id][i-1]);';
  4007. $return .= '}' . "\n\n";
  4008. $return .= 'var child_name = new Array();' . "\n";
  4009. $return .= 'var child_value = new Array();' . "\n\n";
  4010. $return .= 'child_name[0] = new Array();' . "\n";
  4011. $return .= 'child_value[0] = new Array();' . "\n\n";
  4012. $tbl_lp_item = Database::get_course_table('lp_item');
  4013. $sql_zero = "
  4014. SELECT *
  4015. FROM " . $tbl_lp_item . "
  4016. WHERE
  4017. lp_id = " . $this->lp_id . " AND
  4018. parent_item_id = 0
  4019. ORDER BY display_order ASC";
  4020. $res_zero = api_sql_query($sql_zero, __FILE__, __LINE__);
  4021. $i = 0;
  4022. while($row_zero = Database::fetch_array($res_zero))
  4023. {
  4024. $return .= 'child_name[0][' . $i . '] = "After \"' . $row_zero['title'] . '\"";' . "\n";
  4025. $return .= 'child_value[0][' . $i++ . '] = "' . $row_zero['id'] . '";' . "\n";
  4026. }
  4027. $return .= "\n";
  4028. $sql = "
  4029. SELECT *
  4030. FROM " . $tbl_lp_item . "
  4031. WHERE
  4032. lp_id = " . $this->lp_id;
  4033. $res = api_sql_query($sql, __FILE__, __LINE__);
  4034. while($row = Database::fetch_array($res))
  4035. {
  4036. $sql_parent = "
  4037. SELECT *
  4038. FROM " . $tbl_lp_item . "
  4039. WHERE parent_item_id = " . $row['id'] . "
  4040. ORDER BY display_order ASC";
  4041. $res_parent = api_sql_query($sql_parent, __FILE__, __LINE__);
  4042. $i = 0;
  4043. $return .= 'child_name[' . $row['id'] . '] = new Array();' . "\n";
  4044. $return .= 'child_value[' . $row['id'] . '] = new Array();' . "\n\n";
  4045. while($row_parent = Database::fetch_array($res_parent))
  4046. {
  4047. $return .= 'child_name[' . $row['id'] . '][' . $i . '] = "After \"' . $row_parent['title'] . '\"";' . "\n";
  4048. $return .= 'child_value[' . $row['id'] . '][' . $i++ . '] = "' . $row_parent['id'] . '";' . "\n";
  4049. }
  4050. $return .= "\n";
  4051. }
  4052. $return .= '</script>' . "\n";
  4053. return $return;
  4054. }
  4055. /**
  4056. * Enter description here...
  4057. *
  4058. * @param unknown_type $item_id
  4059. * @return unknown
  4060. */
  4061. function display_move_item($item_id)
  4062. {
  4063. global $_course; //will disappear
  4064. $return = '';
  4065. if(is_numeric($item_id))
  4066. {
  4067. $tbl_lp_item = Database::get_course_table('lp_item');
  4068. $sql = "
  4069. SELECT *
  4070. FROM " . $tbl_lp_item . "
  4071. WHERE id = " . $item_id;
  4072. $res = api_sql_query($sql, __FILE__, __LINE__);
  4073. $row = Database::fetch_array($res);
  4074. switch($row['item_type'])
  4075. {
  4076. case 'dokeos_chapter':
  4077. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4078. $return .= $this->display_item_form($row['item_type'], 'Move the current chapter:', 'move', $item_id, $row);
  4079. break;
  4080. case 'dokeos_module':
  4081. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4082. $return .= $this->display_item_form($row['item_type'], 'Move th current module:', 'move', $item_id, $row);
  4083. break;
  4084. case TOOL_DOCUMENT:
  4085. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4086. $return .= $this->display_document_form('move', $item_id, $row);
  4087. break;
  4088. case TOOL_LINK:
  4089. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4090. $return .= $this->display_link_form('move', $item_id, $row);
  4091. break;
  4092. case TOOL_QUIZ:
  4093. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4094. $return .= $this->display_quiz_form('move', $item_id, $row);
  4095. break;
  4096. case TOOL_STUDENTPUBLICATION:
  4097. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4098. $return .= $this->display_student_publication_form('move', $item_id, $row);
  4099. break;
  4100. }
  4101. }
  4102. return $return;
  4103. }
  4104. /**
  4105. * Displays a basic form on the overview page for changing the item title and the item description.
  4106. *
  4107. * @param string $item_type
  4108. * @param string $title
  4109. * @param array $data
  4110. * @return string
  4111. */
  4112. function display_item_small_form($item_type, $title = '', $data)
  4113. {
  4114. $return .= '<div class="lp_small_form">' . "\n";
  4115. $return .= '<p class="lp_title">' . $title . '</p>';
  4116. $return .= '<form method="post">' . "\n";
  4117. $return .= '<table cellpadding="0" cellspacing="0" class="lp_form">';
  4118. $return .= "\t\t" . '<tr>' . "\n";
  4119. $return .= "\t\t\t" . '<td class="label"><label for="idTitle">Title:</label></td>' . "\n";
  4120. $return .= "\t\t\t" . '<td class="input"><input class="small_form" id="idTitle" name="title" type="text" value="' . $data['title'] . '" /></td>' . "\n";
  4121. $return .= "\t\t" . '</tr>' . "\n";
  4122. $return .= "\t\t" . '<tr>' . "\n";
  4123. $return .= "\t\t\t" . '<td class="label"><label for="idDescription">Description:</label></td>' . "\n";
  4124. $return .= "\t\t\t" . '<td class="input"><textarea class="small_form" id="idDescription" name="description" rows="4">' . $data['description'] . '</textarea></td>' . "\n";
  4125. $return .= "\t\t" . '</tr>' . "\n";
  4126. $return .= "\t\t" . '<tr>' . "\n";
  4127. $return .= "\t\t\t" . '<td colspan="2"><input class="button small_form" name="submit_button" type="submit" value="OK" /></td>' . "\n";
  4128. $return .= "\t\t" . '</tr>' . "\n";
  4129. $return .= "\t\t" . '</table>' . "\n";
  4130. $return .= "\t" . '<input name="parent" type="hidden" value="' . $data['parent_item_id'] . '"/>' . "\n";
  4131. $return .= "\t" . '<input name="previous" type="hidden" value="' . $data['previous_item_id'] . '"/>' . "\n";
  4132. $return .= '</form>';
  4133. $return .= '</div>';
  4134. return $return;
  4135. }
  4136. /**
  4137. * Enter description here...
  4138. *
  4139. * @param unknown_type $item_id
  4140. * @return unknown
  4141. */
  4142. function display_item_prerequisites_form($item_id)
  4143. {
  4144. $tbl_lp_item = Database::get_course_table('lp_item');
  4145. /* current prerequisite */
  4146. $sql = "
  4147. SELECT *
  4148. FROM " . $tbl_lp_item . "
  4149. WHERE id = " . $item_id;
  4150. $result = api_sql_query($sql, __FILE__, __LINE__);
  4151. $row = Database::fetch_array($result);
  4152. $preq_id = $row['prerequisite'];
  4153. $preq_min = $row['min_score'];
  4154. $preq_max = $row['max_score'];
  4155. $return = $this->display_manipulate($item_id, TOOL_DOCUMENT);
  4156. $return .= '<div style="margin:3px 10px;">';
  4157. $return .= '<p class="lp_title">Add/edit prerequisites</p>';
  4158. $return .= '<form method="POST">';
  4159. $return .= '<table class="lp_form">';
  4160. $return .= '<tr>';
  4161. $return .= '<th></th>';
  4162. $return .= '<th class="exercise">Minimum</th>';
  4163. $return .= '<th class="exercise">Maximum</th>';
  4164. $return .= '</tr>';
  4165. $return .= '<tr>';
  4166. $return .= '<td class="radio" colspan="3">';
  4167. $return .= '<input checked="checked" id="idNone" name="prerequisites" style="margin-left:0; margin-right:10px;" type="radio" />';
  4168. $return .= '<label for="idNone">None</label>';
  4169. $return .= '</td>';
  4170. $return .= '</tr>';
  4171. $sql = "
  4172. SELECT *
  4173. FROM " . $tbl_lp_item . "
  4174. WHERE
  4175. lp_id = " . $this->lp_id;
  4176. $result = api_sql_query($sql, __FILE__, __LINE__);
  4177. $arrLP = array();
  4178. while($row = Database::fetch_array($result))
  4179. {
  4180. $arrLP[] = array(
  4181. 'id' => $row['id'],
  4182. 'item_type' => $row['item_type'],
  4183. 'title' => $row['title'],
  4184. 'description' => $row['description'],
  4185. 'parent_item_id' => $row['parent_item_id'],
  4186. 'previous_item_id' => $row['previous_item_id'],
  4187. 'next_item_id' => $row['next_item_id'],
  4188. 'display_order' => $row['display_order']);
  4189. }
  4190. $this->tree_array($arrLP);
  4191. $arrLP = $this->arrMenu;
  4192. unset($this->arrMenu);
  4193. for($i = 0; $i < count($arrLP); $i++)
  4194. {
  4195. if($arrLP[$i]['id'] == $item_id)
  4196. break;
  4197. $return .= '<tr>';
  4198. $return .= '<td class="radio"' . (($arrLP[$i]['item_type'] != TOOL_QUIZ) ? ' colspan="3"' : '') . '>';
  4199. $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'] . '" />';
  4200. $return .= '<img alt="" src="img/lp_' . $arrLP[$i]['item_type'] . '.png" style="margin-right:5px;" title="" />';
  4201. $return .= '<label for="id' . $arrLP[$i]['id'] . '">' . stripslashes($arrLP[$i]['title']) . '</label>';
  4202. $return .= '</td>';
  4203. if($arrLP[$i]['item_type'] == TOOL_QUIZ)
  4204. {
  4205. $return .= '<td class="exercise">';
  4206. $return .= '<input maxlength="3" name="min_' . $arrLP[$i]['id'] . '" type="text" value="' . (($arrLP[$i]['id'] == $preq_id) ? $preq_min : 0) . '" />';
  4207. $return .= '</td>';
  4208. $return .= '<td class="exercise">';
  4209. $return .= '<input maxlength="3" name="max_' . $arrLP[$i]['id'] . '" type="text" value="' . (($arrLP[$i]['id'] == $preq_id) ? $preq_max : 100) . '" />';
  4210. $return .= '</td>';
  4211. }
  4212. $return .= '</tr>';
  4213. }
  4214. $return .= '<tr>';
  4215. $return .= '<td colspan="3">';
  4216. $return .= '<input class="button" name="submit_button" type="submit" value="OK" /></td>' . "\n";
  4217. $return .= '</td>';
  4218. $return .= '</tr>';
  4219. $return .= '</table>';
  4220. $return .= '</form>';
  4221. $return .= '</div>';
  4222. return $return;
  4223. }
  4224. /**
  4225. * Creates a list with all the documents in it
  4226. *
  4227. * @return string
  4228. */
  4229. function get_documents()
  4230. {
  4231. global $_course;
  4232. $tbl_doc = Database::get_course_table(DOCUMENT_TABLE);
  4233. $sql_doc = "
  4234. SELECT *
  4235. FROM " . $tbl_doc . "
  4236. WHERE
  4237. path NOT LIKE '%_DELETED_%'
  4238. ORDER BY path ASC";
  4239. $res_doc = api_sql_query($sql_doc, __FILE__, __LINE__);
  4240. $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 . '.png" style="margin-right:5px;" title="" />Document</div>';
  4241. $return .= '<div class="lp_resource_elements" id="resDoc">';
  4242. while($row_doc = Database::fetch_array($res_doc))
  4243. {
  4244. $explode = explode('/', $row_doc['path']);
  4245. $num = count($explode) - 2;
  4246. $return .= '<div class="lp_resource_element">';
  4247. $return .= '<img align="left" alt="" src="img/lp_' . (($row_doc['filetype'] == 'file') ? TOOL_DOCUMENT : 'folder') . '.png" style="margin-left:' . ($num * 20) . 'px;margin-right:5px;" title="" />';
  4248. if($row_doc['filetype'] == 'file')
  4249. $return .= '<a href="' . $_SERVER['PHP_SELF'] . '?cidReq=' . $_GET['cidReq'] . '&amp;action=add_item&amp;type=' . TOOL_DOCUMENT . '&amp;file=' . $row_doc['id'] . '&amp;lp_id=' . $this->lp_id . '">' . $row_doc['title'] . '</a>';
  4250. else
  4251. $return .= $row_doc['title'];
  4252. $return .= '</div>';
  4253. }
  4254. if(Database::num_rows($res_doc) == 0)
  4255. $return .= '<div class="lp_resource_element">No documents</div>';
  4256. $return .= '</div>';
  4257. return $return;
  4258. }
  4259. /**
  4260. * Creates a list with all the exercises (quiz) in it
  4261. *
  4262. * @return string
  4263. */
  4264. function get_exercises()
  4265. {
  4266. $tbl_quiz = Database::get_course_table(QUIZ_TEST_TABLE);
  4267. $sql_quiz = "
  4268. SELECT *
  4269. FROM " . $tbl_quiz . "
  4270. ORDER BY title ASC";
  4271. $res_quiz = api_sql_query($sql_quiz, __FILE__, __LINE__);
  4272. $return .= '<div class="lp_resource_header"' . " 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 . '.png" style="margin-right:5px;" title="" />Exercises</div>';
  4273. $return .= '<div class="lp_resource_elements" id="resExercise">';
  4274. while($row_quiz = Database::fetch_array($res_quiz))
  4275. {
  4276. $return .= '<div class="lp_resource_element">';
  4277. $return .= '<img align="left" alt="" src="img/lp_' . TOOL_QUIZ . '.png" style="margin-right:5px;" title="" />';
  4278. $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>';
  4279. //$return .= $row_quiz['title'];
  4280. $return .= '</div>';
  4281. }
  4282. if(Database::num_rows($res_quiz) == 0)
  4283. $return .= '<div class="lp_resource_element">No exercises available</div>';
  4284. $return .= '</div>';
  4285. return $return;
  4286. }
  4287. /**
  4288. * Creates a list with all the links in it
  4289. *
  4290. * @return string
  4291. */
  4292. function get_links()
  4293. {
  4294. $tbl_link = Database::get_course_table(LINK_TABLE);
  4295. $sql_link = "
  4296. SELECT *
  4297. FROM " . $tbl_link . "
  4298. ORDER BY title ASC";
  4299. $res_link = api_sql_query($sql_link, __FILE__, __LINE__);
  4300. $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 . '.png" style="margin-right:5px;" title="" />Links</div>';
  4301. $return .= '<div class="lp_resource_elements" id="resLink">';
  4302. while($row_link = Database::fetch_array($res_link))
  4303. {
  4304. $return .= '<div class="lp_resource_element">';
  4305. $return .= '<img align="left" alt="" src="img/lp_' . TOOL_LINK . '.png" style="margin-right:5px;" title="" />';
  4306. $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>';
  4307. $return .= '</div>';
  4308. }
  4309. if(Database::num_rows($res_link) == 0)
  4310. $return .= '<div class="lp_resource_element">No links available</div>';
  4311. $return .= '</div>';
  4312. return $return;
  4313. }
  4314. /**
  4315. * Creates a list with all the student publications in it
  4316. *
  4317. * @return unknown
  4318. */
  4319. function get_student_publications()
  4320. {
  4321. $tbl_student = Database::get_course_table(STUDENT_PUBLICATION_TABLE);
  4322. $sql_student = "
  4323. SELECT *
  4324. FROM " . $tbl_student . "
  4325. ORDER BY title ASC";
  4326. $res_student = api_sql_query($sql_student, __FILE__, __LINE__);
  4327. $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 . '.png" style="margin-right:5px;" title="" />Student Publications</div>';
  4328. $return .= '<div class="lp_resource_elements" id="resStudent" style="border-bottom:1px solid #999999; border-top:0;">';
  4329. while($row_student = Database::fetch_array($res_student))
  4330. {
  4331. $return .= '<div class="lp_resource_element">';
  4332. $return .= '<img align="left" alt="" src="img/lp_' . TOOL_STUDENTPUBLICATION . '.png" style="margin-right:5px;" title="" />';
  4333. $return .= '<a href="' . $_SERVER['PHP_SELF'] . '?cidReq=' . $_GET['cidReq'] . '&amp;action=add_item&amp;type=' . TOOL_STUDENTPUBLICATION . '&amp;file=' . $row_student['id'] . '&amp;lp_id=' . $this->lp_id . '">' . $row_student['title'] . '</a>';
  4334. $return .= '</div>';
  4335. }
  4336. if(Database::num_rows($res_student) == 0)
  4337. $return .= '<div class="lp_resource_element">No student publications available</div>';
  4338. $return .= '</div>';
  4339. return $return;
  4340. }
  4341. }
  4342. ?>