123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291 |
- <?php //$id:$
- /**
- * This (abstract?) class defines the parent attributes and methods for the dokeos learnpaths and scorm
- * learnpaths. It is used by the scorm class as well as the dokeos_lp class.
- * @package dokeos.learnpath
- * @author Yannick Warnier <ywarnier@beeznest.org>
- * @license GNU/GPL - See Dokeos license directory for details
- */
- /**
- * Defines the learnpath parent class
- * @package dokeos.learnpath
- */
- class learnpath {
- var $attempt = 0; //the number for the current ID view
- var $cc; //course (code) this learnpath is located in
- var $current; //id of the current item the user is viewing
- var $current_score; //the score of the current item
- var $current_time_start; //the time the user loaded this resource (this does not mean he can see it yet)
- var $current_time_stop; //the time the user closed this resource
- var $default_status = 'not attempted';
- var $encoding = 'ISO-8859-1';
- var $error = '';
- var $extra_information = ''; //this string can be used by proprietary SCORM contents to store data about the current learnpath
- var $force_commit = false; //for SCORM only - if set to true, will send a scorm LMSCommit() request on each LMSSetValue()
- var $index; //the index of the active learnpath_item in $ordered_items array
- var $items = array();
- var $last; //item_id of last item viewed in the learning path
- var $last_item_seen = 0; //in case we have already come in this learnpath, reuse the last item seen if authorized
- var $license; //which license this course has been given - not used yet on 20060522
- var $lp_id; //DB ID for this learnpath
- var $lp_view_id; //DB ID for lp_view
- var $log_file; //file where to log learnpath API msg
- var $maker; //which maker has conceived the content (ENI, Articulate, ...)
- var $message = '';
- var $mode='embedded'; //holds the video display mode (fullscreen or embedded)
- var $name; //learnpath name (they generally have one)
- var $ordered_items = array(); //list of the learnpath items in the order they are to be read
- var $path = ''; //path inside the scorm directory (if scorm)
-
- // Tells if all the items of the learnpath can be tried again. Defaults to "no" (=1)
- var $prevent_reinit = 1;
-
- // Describes the mode of progress bar display
- var $progress_bar_mode = '%';
-
- // Percentage progress as saved in the db
- var $progress_db = '0';
- var $proximity; //wether the content is distant or local or unknown
- var $refs_list = array(); //list of items by ref => db_id. Used only for prerequisites match.
- //!!!This array (refs_list) is built differently depending on the nature of the LP.
- //If SCORM, uses ref, if Dokeos, uses id to keep a unique value
- var $type; //type of learnpath. Could be 'dokeos', 'scorm', 'scorm2004', 'aicc', ...
- //TODO check if this type variable is useful here (instead of just in the controller script)
- var $user_id; //ID of the user that is viewing/using the course
- var $update_queue = array();
- var $scorm_debug = 0;
-
- var $arrMenu = array(); //array for the menu items
- var $debug = 0; //logging level
- /**
- * Class constructor. Needs a database handler, a course code and a learnpath id from the database.
- * Also builds the list of items into $this->items.
- * @param string Course code
- * @param integer Learnpath ID
- * @param integer User ID
- * @return boolean True on success, false on error
- */
- function learnpath($course, $lp_id, $user_id) {
- //check params
- //check course code
- if($this->debug>0){error_log('New LP - In learnpath::learnpath('.$course.','.$lp_id.','.$user_id.')',0);}
- if(empty($course)){
- $this->error = 'Course code is empty';
- return false;
- }
- else
- {
- $main_table = Database::get_main_table(MAIN_COURSE_TABLE);
- //$course = Database::escape_string($course);
- $course = $this->escape_string($course);
- $sql = "SELECT * FROM $main_table WHERE code = '$course'";
- if($this->debug>2){error_log('New LP - learnpath::learnpath() '.__LINE__.' - Querying course: '.$sql,0);}
- //$res = Database::query($sql);
- $res = api_sql_query($sql);
- if(Database::num_rows($res)>0)
- {
- $this->cc = $course;
- }
- else
- {
- $this->error = 'Course code does not exist in database ('.$sql.')';
- return false;
- }
- }
- //check learnpath ID
- if(empty($lp_id))
- {
- $this->error = 'Learnpath ID is empty';
- return false;
- }
- else
- {
- //TODO make it flexible to use any course_code (still using env course code here)
- //$lp_table = Database::get_course_table(LEARNPATH_TABLE);
- $lp_db = Database::get_current_course_database();
- $lp_pref = Database::get_course_table_prefix();
- $lp_table = $lp_db.'.'.$lp_pref.'lp';
- //$id = Database::escape_integer($id);
- $lp_id = $this->escape_string($lp_id);
- $sql = "SELECT * FROM $lp_table WHERE id = '$lp_id'";
- if($this->debug>2){error_log('New LP - learnpath::learnpath() '.__LINE__.' - Querying lp: '.$sql,0);}
- //$res = Database::query($sql);
- $res = api_sql_query($sql);
- if(Database::num_rows($res)>0)
- {
- $this->lp_id = $lp_id;
- $row = Database::fetch_array($res);
- $this->type = $row['lp_type'];
- $this->name = stripslashes($row['name']);
- $this->encoding = $row['default_encoding'];
- $this->proximity = $row['content_local'];
- $this->maker = $row['content_maker'];
- $this->prevent_reinit = $row['prevent_reinit'];
- $this->license = $row['content_license'];
- $this->scorm_debug = $row['debug'];
- $this->js_lib = $row['js_lib'];
- $this->path = $row['path'];
- if($this->type == 2){
- if($row['force_commit'] == 1){
- $this->force_commit = true;
- }
- }
- $this->mode = $row['default_view_mod'];
- }
- else
- {
- $this->error = 'Learnpath ID does not exist in database ('.$sql.')';
- return false;
- }
- }
- //check user ID
- if(empty($user_id)){
- $this->error = 'User ID is empty';
- return false;
- }
- else
- {
- //$main_table = Database::get_main_user_table();
- $main_table = Database::get_main_table(MAIN_USER_TABLE);
- //$user_id = Database::escape_integer($user_id);
- $user_id = $this->escape_string($user_id);
- $sql = "SELECT * FROM $main_table WHERE user_id = '$user_id'";
- if($this->debug>2){error_log('New LP - learnpath::learnpath() '.__LINE__.' - Querying user: '.$sql,0);}
- //$res = Database::query($sql);
- $res = api_sql_query($sql);
- if(Database::num_rows($res)>0)
- {
- $this->user_id = $user_id;
- }
- else
- {
- $this->error = 'User ID does not exist in database ('.$sql.')';
- return false;
- }
- }
- //end of variables checking
-
- //now get the latest attempt from this user on this LP, if available, otherwise create a new one
- //$lp_table = Database::get_course_table(LEARNPATH_VIEW_TABLE);
- $lp_db = Database::get_current_course_database();
- $lp_pref = Database::get_course_table_prefix();
- $lp_table = $lp_db.'.'.$lp_pref.'lp_view';
- //selecting by view_count descending allows to get the highest view_count first
- $sql = "SELECT * FROM $lp_table WHERE lp_id = '$lp_id' AND user_id = '$user_id' ORDER BY view_count DESC";
- if($this->debug>2){error_log('New LP - learnpath::learnpath() '.__LINE__.' - querying lp_view: '.$sql,0);}
- //$res = Database::query($sql);
- $res = api_sql_query($sql);
- $view_id = 0; //used later to query lp_item_view
- if(Database::num_rows($res)>0)
- {
- if($this->debug>2){error_log('New LP - learnpath::learnpath() '.__LINE__.' - Found previous view',0);}
- $row = Database::fetch_array($res);
- $this->attempt = $row['view_count'];
- $this->lp_view_id = $row['id'];
- $this->last_item_seen = $row['last_item'];
- $this->progress_db = $row['progress'];
- }
- else
- {
- if($this->debug>2){error_log('New LP - learnpath::learnpath() '.__LINE__.' - NOT Found previous view',0);}
- $this->attempt = 1;
- $sql_ins = "INSERT INTO $lp_table (lp_id,user_id,view_count) VALUES ($lp_id,$user_id,1)";
- $res_ins = api_sql_query($sql_ins);
- $this->lp_view_id = Database::get_last_insert_id();
- if($this->debug>2){error_log('New LP - learnpath::learnpath() '.__LINE__.' - inserting new lp_view: '.$sql_ins,0);}
- }
- //initialise items
- $lp_item_table = $lp_db.'.'.$lp_pref.'lp_item';
- $sql = "SELECT * FROM $lp_item_table WHERE lp_id = '".$this->lp_id."' ORDER BY parent_item_id, display_order";
- $res = api_sql_query($sql);
-
- while($row = Database::fetch_array($res))
- {
- $oItem = '';
- //$this->ordered_items[] = $row['id'];
- switch($this->type){
-
- case 3: //aicc
- $oItem = new aiccItem('db',$row['id']);
- if(is_object($oItem)){
- $oItem->set_lp_view($this->lp_view_id);
- $oItem->set_prevent_reinit($this->prevent_reinit);
- $id = $oItem->get_id();
- // Don't use reference here as the next loop will make the pointed object change
- $this->items[$id] = $oItem;
- $this->refs_list[$oItem->ref]=$id;
- if($this->debug>2){error_log('New LP - learnpath::learnpath() - aicc object with id '.$id.' set in items[]',0);}
- }
- break;
- case 2:
- require_once('scorm.class.php');
- require_once('scormItem.class.php');
- $oItem = new scormItem('db',$row['id']);
- if(is_object($oItem)){
- $oItem->set_lp_view($this->lp_view_id);
- $oItem->set_prevent_reinit($this->prevent_reinit);
- // Don't use reference here as the next loop will make the pointed object change
- $this->items[$oItem->get_id()] = $oItem;
- $this->refs_list[$oItem->ref]=$oItem->get_id();
- if($this->debug>2){error_log('New LP - object with id '.$oItem->get_id().' set in items[]',0);}
- }
- break;
- case 1:
- default:
- require_once('learnpathItem.class.php');
- $oItem = new learnpathItem($row['id'],$user_id);
- if(is_object($oItem)){
- //$oItem->set_lp_view($this->lp_view_id); moved down to when we are sure the item_view exists
- $oItem->set_prevent_reinit($this->prevent_reinit);
- // Don't use reference here as the next loop will make the pointed object change
- $this->items[$oItem->get_id()] = $oItem;
- $this->refs_list[$oItem->get_id()]=$oItem->get_id();
- if($this->debug>2){error_log('New LP - learnpath::learnpath() '.__LINE__.' - object with id '.$oItem->get_id().' set in items[]',0);}
- }
- break;
- }
- //items is a list of pointers to all items, classified by DB ID, not SCO id
- if($row['parent_item_id'] == 0 OR empty($this->items[$row['parent_item_id']])){
- $this->items[$row['id']]->set_level(0);
- }else{
- $level = $this->items[$row['parent_item_id']]->get_level()+1;
- $this->items[$row['id']]->set_level($level);
- if(is_object($this->items[$row['parent_item_id']])){
- //items is a list of pointers from item DB ids to item objects
- $this->items[$row['parent_item_id']]->add_child($row['id']);
- }else{
- 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);}
- }
- }
- //get last viewing vars
- //$learnpath_items_view_table = Database::get_course_table(LEARNPATH_ITEM_VIEW_TABLE);
- $lp_item_view_table = $lp_db.'.'.$lp_pref.'lp_item_view';
- //this query should only return one or zero result
- $sql = "SELECT * " .
- "FROM $lp_item_view_table " .
- "WHERE lp_view_id = ".$this->lp_view_id." " .
- "AND lp_item_id = ".$row['id']." ORDER BY view_count DESC ";
- if($this->debug>2){error_log('New LP - learnpath::learnpath() - Selecting item_views: '.$sql,0);}
- //get the item status
- $res2 = api_sql_query($sql);
- if(Database::num_rows($res2)>0)
- {
- //if this learnpath has already been used by this user, get his last attempt count and
- //the last item seen back into this object
- //$max = 0;
- $row2 = Database::fetch_array($res2);
- if($this->debug>2){error_log('New LP - learnpath::learnpath() - Got item_view: '.print_r($row2,true),0);}
- $this->items[$row['id']]->set_status($row2['status']);
- if(empty($row2['status'])){
- $this->items[$row['id']]->set_status($this->default_status);
- }
- //$this->attempt = $row['view_count'];
- //$this->last_item = $row['id'];
- }
- else //no item found in lp_item_view for this view
- {
- //first attempt from this user. Set attempt to 1 and last_item to 0 (first item available)
- //TODO if the learnpath has not got attempts activated, always use attempt '1'
- //$this->attempt = 1;
- //$this->last_item = 0;
- $this->items[$row['id']]->set_status($this->default_status);
- //Add that row to the lp_item_view table so that we have something to show in the stats page
- $sql_ins = "INSERT INTO $lp_item_view_table " .
- "(lp_item_id, lp_view_id, view_count, status) VALUES " .
- "(".$row['id'].",".$this->lp_view_id.",1,'not attempted')";
- if($this->debug>2){error_log('New LP - learnpath::learnpath() '.__LINE__.' - Inserting blank item_view : '.$sql_ins,0);}
- $res_ins = api_sql_query($sql_ins);
- }
- //setting the view in the item object
- $this->items[$row['id']]->set_lp_view($this->lp_view_id);
- }
- $this->ordered_items = $this->get_flat_ordered_items_list($this->get_id(),0);
- $this->max_ordered_items = 0;
- foreach($this->ordered_items as $index=>$dummy){
- if($index > $this->max_ordered_items AND !empty($dummy)){
- $this->max_ordered_items = $index;
- }
- }
- //TODO define the current item better
- $this->first();
- if($this->debug>2){error_log('New LP - learnpath::learnpath() '.__LINE__.' - End of learnpath constructor for learnpath '.$this->get_id(),0);}
- }
-
- /**
- * 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
- * I found it better to rewrite it. Old function is still available. Added also the possibility to add a description.
- *
- * @param int $parent
- * @param int $previous
- * @param string $type
- * @param int $id
- * @param string $title
- * @param string $description
- * @return int
- */
- function add_item($parent, $previous, $type = 'dokeos_chapter', $id, $title, $description)
- {
- if($this->debug>0){error_log('New LP - In learnpath::add_item('.$parent.','.$previous.','.$type.','.$id.','.$title.')',0);}
-
- $tbl_lp_item = Database::get_course_table('lp_item');
- $parent = (int) $parent;
-
- $sql_count = "
- SELECT COUNT(id) AS num
- FROM " . $tbl_lp_item . "
- WHERE
- lp_id = " . $this->get_id() . " AND
- parent_item_id = " . $parent;
-
- $res_count = api_sql_query($sql_count, __FILE__, __LINE__);
- $row = Database::fetch_array($res_count);
-
- $num = $row['num'];
-
- if($num > 0)
- {
- if($previous == 0)
- {
- $sql = "
- SELECT
- id,
- next_item_id,
- display_order
- FROM " . $tbl_lp_item . "
- WHERE
- lp_id = " . $this->get_id() . " AND
- parent_item_id = " . $parent . " AND
- previous_item_id = 0";
-
- $result = api_sql_query($sql, __FILE__, __LINE__);
- $row = Database::fetch_array($result);
-
- $tmp_previous = 0;
- $next = $row['id'];
- $display_order = 0;
- }
- else
- {
- $previous = (int) $previous;
-
- $sql = "
- SELECT
- id,
- previous_item_id,
- next_item_id,
- display_order
- FROM " . $tbl_lp_item . "
- WHERE
- lp_id = " . $this->get_id() . " AND
- id = " . $previous;
-
- $result = api_sql_query($sql, __FILE__, __LINE__);
- $row = Database::fetch_array($result);
-
- $tmp_previous = $row['id'];
- $next = $row['next_item_id'];
-
- $display_order = $row['display_order'];
- }
- }
- else
- {
- $tmp_previous = 0;
- $next = 0;
- $display_order = 0;
- }
-
- $new_item_id = -1;
- $id = $this->escape_string($id);
-
- //insert new item
- $sql_ins = "
- INSERT INTO " . $tbl_lp_item . " (
- lp_id,
- item_type,
- ref,
- title,
- description,
- path,
- parent_item_id,
- previous_item_id,
- next_item_id,
- display_order
- ) VALUES (
- " . $this->get_id() . ",
- '" . $type . "',
- '',
- '" . $this->escape_string(htmlentities($title)) . "',
- '" . $this->escape_string(htmlentities($description)) . "',
- '" . $id . "',
- " . $parent . ",
- " . $previous . ",
- " . $next . ",
- " . ($display_order + 1) . "
- )";
-
- //echo $sql_ins; // for debug
-
- if($this->debug>2){error_log('New LP - Inserting dokeos_chapter: '.$sql_ins,0);}
-
- $res_ins = api_sql_query($sql_ins, __FILE__, __LINE__);
-
- if($res_ins > 0)
- {
- $new_item_id = Database::get_last_insert_id($res_ins);
-
- //update the item that should come after the new item
- $sql_update_next = "
- UPDATE " . $tbl_lp_item . "
- SET previous_item_id = " . $new_item_id . "
- WHERE id = " . $next;
-
- $res_update_next = api_sql_query($sql_update_next, __FILE__, __LINE__);
-
- //update the item that should be before the new item
- $sql_update_previous = "
- UPDATE " . $tbl_lp_item . "
- SET next_item_id = " . $new_item_id . "
- WHERE id = " . $tmp_previous;
-
- $res_update_previous = api_sql_query($sql_update_previous, __FILE__, __LINE__);
-
- //update all the items after the new item
- $sql_update_order = "
- UPDATE " . $tbl_lp_item . "
- SET display_order = display_order + 1
- WHERE
- lp_id = " . $this->get_id() . " AND
- id <> " . $new_item_id . " AND
- parent_item_id = " . $parent . " AND
- display_order > " . $display_order;
-
- $res_update_previous = api_sql_query($sql_update_order, __FILE__, __LINE__);
- }
-
- return $new_item_id;
- }
-
-
- /**
- * Adds an item to the current learnpath
- * @param integer Parent ID
- * @param integer Previous elem ID (0 if first)
- * @param string Resource type to add ('file','dokeos_item')
- * @param string Resource ID or path if 'file' or name if 'dokeos_chapter'
- * @return integer New element ID
- */
- function old_add_item($parent, $previous, $type = 'dokeos_chapter', $id, $title)
- {
- //TODO
- if($this->debug>0){error_log('New LP - In learnpath::add_item('.$parent.','.$previous.','.$type.','.$id.','.$title.')',0);}
-
- $tbl_lp_item = Database::get_course_table('lp_item');
- $parent = (int) $parent;
- $display_order = 1;
-
- if($previous == -1){
- //insert in latest position available
- $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;
-
- if($this->debug>1){error_log('New LP - checking for latest item at this level: '.$sql_check,0);}
-
- $res = mysql_query($sql_check) or die(mysql_error());
-
- $res_check = api_sql_query($sql_check, __FILE__, __LINE__);
- $num = Database::num_rows($res_check);
-
- if($num>0){
- $row = Database::fetch_array($res_check);
- $previous = $row['id'];
- }else{
- $previous = 0;
- }
- }else{
- $previous = (int) $previous;
- }
-
- $new_item_id = -1;
- //check type
- switch ($type){
- case 'dokeos_step':
- $id = $this->escape_string($id);
- //check the next item
- $sql_check = "SELECT * FROM $tbl_lp_item " .
- "WHERE lp_id = ".$this->get_id()." " .
- "AND previous_item_id = $previous " .
- "AND parent_item_id = $parent";
- if($this->debug>2){error_log('New LP - Getting info from the next element: '.$sql_check,0);}
- $res_check = api_sql_query($sql_check);
- if(Database::num_rows($res_check)){
- $row = Database::fetch_array($res_check);
- $next = $row['id'];
- //TODO check display_order
- $display_order = $row['display_order']+1;
- }else{
- $next = 0;
- $display_order = 1;
- }
-
- //insert new item
- $sql_ins = "INSERT INTO $tbl_lp_item " .
- "(lp_id,item_type,ref,title," .
- "path,parent_item_id," .
- "previous_item_id,next_item_id,display_order)" .
- "VALUES" .
- "(".$this->get_id().",'$type','','$title','$id'," .
- "$parent," .
- "$previous,$next,$display_order)";
- if($this->debug>2){error_log('New LP - Inserting dokeos_chapter: '.$sql_ins,0);}
- $res_ins = api_sql_query($sql_ins);
- if($res_ins>0){
- $new_item_id = Database::get_last_insert_id($res_ins);
- //now update previous item
- $sql_upd = "UPDATE $tbl_lp_item " .
- "SET next_item_id = $new_item_id " .
- "WHERE lp_id = ".$this->get_id()." " .
- "AND id = $previous AND parent_item_id = $parent";
- if($this->debug>2){error_log('New LP - Updating previous item: '.$sql_upd,0);}
- $res_upd = api_sql_query($sql_upd);
- //now update next item
- $sql_upd = "UPDATE $tbl_lp_item " .
- "SET previous_item_id = $new_item_id " .
- "WHERE lp_id = ".$this->get_id()." " .
- "AND id = $next AND parent_item_id = $parent";
- if($this->debug>2){error_log('New LP - Updating next item: '.$sql_upd,0);}
- $res_upd = api_sql_query($sql_upd);
-
- }
- break;
- default:
- break;
- }
- return $new_item_id;
- }
- /**
- * Static admin function allowing addition of a learnpath to a course.
- * @param string Course code
- * @param string Learnpath name
- * @param string Learnpath description string, if provided
- * @param string Type of learnpath (default = 'guess', others = 'dokeos', 'aicc',...)
- * @param string Type of files origin (default = 'zip', others = 'dir','web_dir',...)
- * @param string Zip file containing the learnpath or directory containing the learnpath
- * @return integer The new learnpath ID on success, 0 on failure
- */
- function add_lp($course,$name,$description='',$learnpath='guess',$origin='zip',$zipname='')
- {
- //if($this->debug>0){error_log('New LP - In learnpath::add_lp()',0);}
- //TODO
- $tbl_lp = Database::get_course_table('lp');
- //check course code exists
- //check lp_name doesn't exist, otherwise append something
- $i = 0;
- $name = learnpath::escape_string(htmlentities($name)); //Kevin Van Den Haute: added htmlentities()
- $check_name = "SELECT * FROM $tbl_lp WHERE name = '$name'";
- //if($this->debug>2){error_log('New LP - Checking the name for new LP: '.$check_name,0);}
- $res_name = api_sql_query($check_name);
- while(Database::num_rows($res_name)){
- //there is already one such name, update the current one a bit
- $i++;
- $name = $name.' - '.$i;
- $check_name = "SELECT * FROM $tbl_lp WHERE name = '$name'";
- //if($this->debug>2){error_log('New LP - Checking the name for new LP: '.$check_name,0);}
- $res_name = api_sql_query($check_name);
- }
- //new name does not exist yet; keep it
- //escape description
- $description = learnpath::escape_string(htmlentities($description)); //Kevin: added htmlentities()
- $type = 1;
- switch($learnpath){
- case 'guess':
- break;
- case 'dokeos':
- $type = 1;
- break;
- case 'aicc':
- break;
- }
- switch($origin){
- case 'zip':
- //check zipname string. If empty, we are currently creating a new Dokeos learnpath
- break;
- case 'manual':
- $get_max = "SELECT MAX(display_order) FROM $tbl_lp";
- $res_max = api_sql_query($get_max);
- if(Database::num_rows($res_max)<1){
- $dsp = 1;
- }else{
- $row = Database::fetch_array($res_max);
- $dsp = $row[0]+1;
- }
- $sql_insert = "INSERT INTO $tbl_lp " .
- "(lp_type,name,description,path,default_view_mod," .
- "default_encoding,display_order,content_maker," .
- "content_local,js_lib) " .
- "VALUES ($type,'$name','$description','','embedded'," .
- "'ISO-8859-1','$dsp','Dokeos'," .
- "'local','')";
- //if($this->debug>2){error_log('New LP - Inserting new lp '.$sql_insert,0);}
- $res_insert = api_sql_query($sql_insert);
- $id = Database::get_last_insert_id();
- if($id>0){
- return $id;
- }
- break;
- }
- }
- /**
- * Appends a message to the message attribute
- * @param string Message to append.
- */
- function append_message($string)
- {
- if($this->debug>0){error_log('New LP - In learnpath::append_message()',0);}
- $this->message .= $string;
- }
- /**
- * Autocompletes the parents of an item in case it's been completed or passed
- * @param integer Optional ID of the item from which to look for parents
- */
- function autocomplete_parents($item)
- {
- if($this->debug>0){error_log('New LP - In learnpath::autocomplete_parents()',0);}
- if(empty($item)){
- $item = $this->current;
- }
- $parent_id = $this->items[$item]->get_parent();
- if($this->debug>2){error_log('New LP - autocompleting parent of item '.$item.' (item '.$parent_id.')',0);}
- if(is_object($this->items[$item]) and !empty($parent_id))
- {//if $item points to an object and there is a parent
- if($this->debug>2){error_log('New LP - '.$item.' is an item, proceed',0);}
- $current_item =& $this->items[$item];
- $parent =& $this->items[$parent_id]; //get the parent
- //new experiment including failed and browsed in completed status
- $current_status = $current_item->get_status();
- if($current_item->is_done() || $current_status=='browsed' || $current_status=='failed'){
- //if the current item is completed or passes or succeeded
- $completed = true;
- if($this->debug>2){error_log('New LP - Status of current item is alright',0);}
- foreach($parent->get_children() as $child){
- //check all his brothers (his parent's children) for completion status
- if($child!= $item){
- if($this->debug>2){error_log('New LP - Looking at brother with ID '.$child.', status is '.$this->items[$child]->get_status(),0);}
- //if($this->items[$child]->status_is(array('completed','passed','succeeded')))
- //Trying completing parents of failed and browsed items as well
- if($this->items[$child]->status_is(array('completed','passed','succeeded','browsed','failed')))
- {
- //keep completion status to true
- }else{
- if($this->debug>2){error_log('New LP - Found one incomplete child of '.$parent_id.': '.$child.' is '.$this->items[$child]->get_status(),0);}
- $completed = false;
- }
- }
- }
- if($completed == true){ //if all the children were completed
- $parent->set_status('completed');
- $parent->save(false);
- $this->update_queue[$parent->get_id()] = $parent->get_status();
- if($this->debug>2){error_log('New LP - Added parent to update queue '.print_r($this->update_queue,true),0);}
- $this->autocomplete_parents($parent->get_id()); //recursive call
- }
- }else{
- //error_log('New LP - status of current item is not enough to get bothered',0);
- }
- }
- }
- /**
- * Autosaves the current results into the database for the whole learnpath
- */
- function autosave()
- {
- if($this->debug>0){error_log('New LP - In learnpath::autosave()',0);}
- //TODO add aditionnal save operations for the learnpath itself
- }
- /**
- * Clears the message attribute
- */
- function clear_message()
- {
- if($this->debug>0){error_log('New LP - In learnpath::clear_message()',0);}
- $this->message = '';
- }
- /**
- * Closes the current resource
- *
- * Stops the timer
- * Saves into the database if required
- * Clears the current resource data from this object
- * @return boolean True on success, false on failure
- */
- function close()
- {
- if($this->debug>0){error_log('New LP - In learnpath::close()',0);}
- if(empty($this->lp_id))
- {
- $this->error = 'Trying to close this learnpath but no ID is set';
- return false;
- }
- $this->current_time_stop = time();
- if($this->save)
- {
- $learnpath_view_table = Database::get_course_table(LEARNPATH_VIEW_TABLE);
- /*
- $sql = "UPDATE $learnpath_view_table " .
- "SET " .
- "stop_time = ".$this->current_time_stop.", " .
- "score = ".$this->current_score.", ".
- "WHERE learnpath_id = '".$this->lp_id."'";
- //$res = Database::query($sql);
- $res = api_sql_query($res);
- if(mysql_affected_rows($res)<1)
- {
- $this->error = 'Could not update learnpath_view table while closing learnpath';
- return false;
- }
- */
- }
- $this->ordered_items = array();
- $this->index=0;
- unset($this->lp_id);
- //unset other stuff
- return true;
- }
- /**
- * Static admin function allowing removal of a learnpath
- * @param string Course code
- * @param integer Learnpath ID
- * @param string Whether to delete data or keep it (default: 'keep', others: 'remove')
- * @return boolean True on success, false on failure (might change that to return number of elements deleted)
- */
- function delete($course=null,$id=null,$delete='keep')
- {
- //TODO implement a way of getting this to work when the current object is not set
- //In clear: implement this in the item class as well (abstract class) and use the given ID in queries
- //if(empty($course)){$course = api_get_course_id();}
- //if(empty($id)){$id = $this->get_id();}
-
- //if($this->debug>0){error_log('New LP - In learnpath::delete()',0);}
- foreach($this->items as $id => $dummy)
- {
- $this->items[$id]->delete();
- }
- $lp = Database::get_course_table('lp');
- $lp_view = Database::get_course_table('lp_view');
- $sql_del_view = "DELETE FROM $lp_view WHERE lp_id = ".$this->lp_id;
- //if($this->debug>2){error_log('New LP - Deleting views bound to lp '.$this->lp_id.': '.$sql_del_view,0);}
- $res_del_view = api_sql_query($sql_del_view);
- //if($this->debug>2){error_log('New LP - Deleting lp '.$this->lp_id.' of type '.$this->type,0);}
- if($this->type == 2 OR $this->type==3){
- //this is a scorm learning path, delete the files as well
- $sql = "SELECT path FROM $lp WHERE id = ".$this->lp_id;
- $res = api_sql_query($sql);
- if(Database::num_rows($res)>0){
- $row = Database::fetch_array($res);
- $path = $row['path'];
- $sql = "SELECT id FROM $lp WHERE path = '$path' AND id != ".$this->lp_id;
- $res = api_sql_query($sql);
- if(Database::num_rows($res)>0)
- { //another learning path uses this directory, so don't delete it
- if($this->debug>2){error_log('New LP - In learnpath::delete(), found other LP using path '.$path.', keeping directory',0);}
- }else{
- //no other LP uses that directory, delete it
- $course_rel_dir = api_get_course_path().'/scorm/'; //scorm dir web path starting from /courses
- $course_scorm_dir = api_get_path(SYS_COURSE_PATH).$course_rel_dir; //absolute system path for this course
- if($delete == 'remove' && is_dir($course_scorm_dir.$path) and !empty($course_scorm_dir)){
- if($this->debug>2){error_log('New LP - In learnpath::delete(), found SCORM, deleting directory: '.$course_scorm_dir.$path,0);}
- exec('rm -rf '.$course_scorm_dir.$path);
- }
- }
- }
- }
- $sql_del_lp = "DELETE FROM $lp WHERE id = ".$this->lp_id;
- //if($this->debug>2){error_log('New LP - Deleting lp '.$this->lp_id.': '.$sql_del_lp,0);}
- $res_del_lp = api_sql_query($sql_del_lp);
- //TODO: also delete items and item-views
- }
- /**
- * Removes all the children of one item - dangerous!
- * @param integer Element ID of which children have to be removed
- * @return integer Total number of children removed
- */
- function delete_children_items($id){
- if($this->debug>0){error_log('New LP - In learnpath::delete_children_items('.$id.')',0);}
- $num = 0;
- if(empty($id) || $id != strval(intval($id))){return false;}
- $lp_item = Database::get_course_table('lp_item');
- $sql = "SELECT * FROM $lp_item WHERE parent_item_id = $id";
- $res = api_sql_query($sql);
- while($row = Database::fetch_array($res)){
- $num += $this->delete_children_items($row['id']);
- $sql_del = "DELETE FROM $lp_item WHERE id = ".$row['id'];
- $res_del = api_sql_query($sql_del);
- $num++;
- }
- return $num;
- }
- /**
- * Removes an item from the current learnpath
- * @param integer Elem ID (0 if first)
- * @param integer Whether to remove the resource/data from the system or leave it (default: 'keep', others 'remove')
- * @return integer Number of elements moved
- * @todo implement resource removal
- */
- function delete_item($id, $remove='keep')
- {
- if($this->debug>0){error_log('New LP - In learnpath::delete_item()',0);}
- //TODO - implement the resource removal
- if(empty($id) || $id != strval(intval($id))){return false;}
- //first select item to get previous, next, and display order
- $lp_item = Database::get_course_table('lp_item');
- $sql_sel = "SELECT * FROM $lp_item WHERE id = $id";
- $res_sel = api_sql_query($sql_sel,__FILE__,__LINE__);
- if(Database::num_rows($res_sel)<1){return false;}
- $row = Database::fetch_array($res_sel);
- $previous = $row['previous_item_id'];
- $next = $row['next_item_id'];
- $display = $row['display_order'];
- $parent = $row['parent_item_id'];
- $lp = $row['lp_id'];
- //delete children items
- $num = $this->delete_children_items($id);
- if($this->debug>2){error_log('New LP - learnpath::delete_item() - deleted '.$num.' children of element '.$id,0);}
- //now delete the item
- $sql_del = "DELETE FROM $lp_item WHERE id = $id";
- if($this->debug>2){error_log('New LP - Deleting item: '.$sql_del,0);}
- $res_del = api_sql_query($sql_del,__FILE__,__LINE__);
- //now update surrounding items
- $sql_upd = "UPDATE $lp_item SET next_item_id = $next WHERE id = $previous";
- $res_upd = api_sql_query($sql_upd,__FILE__,__LINE__);
- $sql_upd = "UPDATE $lp_item SET previous_item_id = $previous WHERE id = $next";
- $res_upd = api_sql_query($sql_upd,__FILE__,__LINE__);
- //now update all following items with new display order
- $sql_all = "UPDATE $lp_item SET display_order = display_order-1 WHERE lp_id = $lp AND parent_item_id = $parent AND display_order > $display";
- $res_all = api_sql_query($sql_all,__FILE__,__LINE__);
- }
- /**
- * Updates an item's content in place
- * @param integer Element ID
- * @param string New content
- * @return boolean True on success, false on error
- */
- function old_edit_item($id,$content)
- {
- if($this->debug>0){error_log('New LP - In learnpath::edit_item()',0);}
- if(empty($id) or ($id != strval(intval($id))) or empty($content)){ return false; }
- $content = $this->escape_string($content);
- $lp_item = Database::get_course_table('lp_item');
- $sql_upd = "UPDATE $lp_item SET title = '$content' WHERE id = $id";
- $res_upd = api_sql_query($sql_upd,__FILE__,__LINE__);
- //TODO update the item object (can be ignored for now because refreshed)
- return true;
- }
-
- function edit_item($id, $parent, $previous, $title, $description)
- {
- if($this->debug > 0){error_log('New LP - In learnpath::edit_item()', 0);}
- if(empty($id) or ($id != strval(intval($id))) or empty($title)){ return false; }
-
- $tbl_lp_item = Database::get_course_table('lp_item');
-
- $sql_select = "
- SELECT *
- FROM " . $tbl_lp_item . "
- WHERE id = " . $id;
- $res_select = api_sql_query($sql_select, __FILE__, __LINE__);
- $row_select = Database::fetch_array($res_select);
-
- $same_parent = ($row_select['parent_item_id'] == $parent) ? true : false;
- $same_previous = ($row_select['previous_item_id'] == $previous) ? true : false;
-
- if($same_parent && $same_previous)
- {
- //only update title and description
- $sql_update = "
- UPDATE " . $tbl_lp_item . "
- SET
- title = '" . $this->escape_string(htmlentities($title)) . "',
- description = '" . $this->escape_string(htmlentities($description)) . "'
- WHERE id = " . $id;
- $res_update = api_sql_query($sql_update, __FILE__, __LINE__);
- }
- else
- {
- $old_parent = $row_select['parent_item_id'];
- $old_previous = $row_select['previous_item_id'];
- $old_next = $row_select['next_item_id'];
- $old_order = $row_select['display_order'];
-
- /* BEGIN -- virtually remove the current item id */
- /* for the next and previous item it is like the current item doesn't exist anymore */
-
- if($old_previous != 0)
- {
- $sql_update_next = "
- UPDATE " . $tbl_lp_item . "
- SET next_item_id = " . $old_next . "
- WHERE id = " . $old_previous;
- $res_update_next = api_sql_query($sql_update_next, __FILE__, __LINE__);
-
- //echo '<p>' . $sql_update_next . '</p>';
- }
-
- if($old_next != 0)
- {
- $sql_update_previous = "
- UPDATE " . $tbl_lp_item . "
- SET previous_item_id = " . $old_previous . "
- WHERE id = " . $old_next;
- $res_update_previous = api_sql_query($sql_update_previous, __FILE__, __LINE__);
-
- //echo '<p>' . $sql_update_previous . '</p>';
- }
-
- //display_order - 1 for every item with a display_order bigger then the display_order of the current item
- $sql_update_order = "
- UPDATE " . $tbl_lp_item . "
- SET display_order = display_order - 1
- WHERE
- display_order > " . $old_order . " AND
- parent_item_id = " . $old_parent;
- $res_update_order = api_sql_query($sql_update_order, __FILE__, __LINE__);
-
- //echo '<p>' . $sql_update_order . '</p>';
-
- /* END -- virtually remove the current item id */
-
- /* BEGIN -- update the current item id to his new location */
-
- if($previous == 0)
- {
- //select the data of the item that should come after the current item
- $sql_select_old = "
- SELECT
- id,
- display_order
- FROM " . $tbl_lp_item . "
- WHERE
- lp_id = " . $this->lp_id . " AND
- parent_item_id = " . $parent . " AND
- previous_item_id = " . $previous;
- $res_select_old = api_sql_query($sql_select_old, __FILE__, __LINE__);
- $row_select_old = Database::fetch_array($res_select_old);
-
- //echo '<p>' . $sql_select_old . '</p>';
-
- //if the new parent doesn't had children before
- if(Database::num_rows($res_select_old) == 0)
- {
- $new_next = 0;
- $new_order = 1;
- }
- else
- {
- $new_next = $row_select_old['id'];
- $new_order = $row_select_old['display_order'];
- }
-
- //echo 'New next_item_id of current item: ' . $new_next . '<br />';
- //echo 'New previous_item_id of current item: ' . $previous . '<br />';
- //echo 'New display_order of current item: ' . $new_order . '<br />';
-
-
- }
- else
- {
- //select the data of the item that should come before the current item
- $sql_select_old = "
- SELECT
- next_item_id,
- display_order
- FROM " . $tbl_lp_item . "
- WHERE id = " . $previous;
- $res_select_old = api_sql_query($sql_select_old, __FILE__, __LINE__);
- $row_select_old = Database::fetch_array($res_select_old);
-
- //echo '<p>' . $sql_select_old . '</p>';
-
- //echo 'New next_item_id of current item: ' . $row_select_old['next_item_id'] . '<br />';
- //echo 'New previous_item_id of current item: ' . $previous . '<br />';
- //echo 'New display_order of current item: ' . ($row_select_old['display_order'] + 1) . '<br />';
-
- $new_next = $row_select_old['next_item_id'];
- $new_order = $row_select_old['display_order'] + 1;
- }
-
- //update the current item with the new data
- $sql_update = "
- UPDATE " . $tbl_lp_item . "
- SET
- title = '" . $this->escape_string(htmlentities($title)) . "',
- description = '" . $this->escape_string(htmlentities($description)) . "',
- parent_item_id = " . $parent . ",
- previous_item_id = " . $previous . ",
- next_item_id = " . $new_next . ",
- display_order = " . $new_order . "
- WHERE id = " . $id;
- $res_update_next = api_sql_query($sql_update, __FILE__, __LINE__);
- //echo '<p>' . $sql_update . '</p>';
-
- if($previous != 0)
- {
- //update the previous item his next_item_id
- $sql_update_previous = "
- UPDATE " . $tbl_lp_item . "
- SET next_item_id = " . $id . "
- WHERE id = " . $previous;
- $res_update_next = api_sql_query($sql_update_previous, __FILE__, __LINE__);
- //echo '<p>' . $sql_update_previous . '</p>';
- }
-
- if($new_next != 0)
- {
- //update the next item his previous_item_id
- $sql_update_next = "
- UPDATE " . $tbl_lp_item . "
- SET previous_item_id = " . $id . "
- WHERE id = " . $new_next;
- $res_update_next = api_sql_query($sql_update_next, __FILE__, __LINE__);
- //echo '<p>' . $sql_update_next . '</p>';
- }
-
- //update all the items with the same or a bigger display_order then the current item
- $sql_update_order = "
- UPDATE " . $tbl_lp_item . "
- SET display_order = display_order + 1
- WHERE
- lp_id = " . $this->get_id() . " AND
- id <> " . $id . " AND
- parent_item_id = " . $parent . " AND
- display_order >= " . $new_order;
-
- $res_update_next = api_sql_query($sql_update_order, __FILE__, __LINE__);
- //echo '<p>' . $sql_update_order . '</p>';
-
- /* END -- update the current item id to his new location */
- }
- }
-
- /**
- * Updates an item's prereq in place
- * @param integer Element ID
- * @param string Prerequisite Element ID
- *
- * @param string Prerequisite item type
- *
- * @param string Prerequisite min score
- *
- * @param string Prerequisite max score
- * @return boolean True on success, false on error
- */
- function edit_item_prereq($id, $prerequisite_id, $min_score = 0, $max_score = 100)
- {
- if($this->debug>0){error_log('New LP - In learnpath::edit_item_prereq()',0);}
- if(empty($id) or ($id != strval(intval($id))) or empty($prerequisite_id)){ return false; }
- $prerequisite_id = $this->escape_string($prerequisite_id);
- $tbl_lp_item = Database::get_course_table('lp_item');
-
- if(!is_numeric($min_score) || $min_score < 0 || $min_score > 100)
- $min_score = 0;
-
- if(!is_numeric($max_score) || $max_score < 0 || $max_score > 100)
- $max_score = 100;
-
- if($min_score > $max_score)
- $max_score = $min_score;
-
- if(!is_numeric($prerequisite_id))
- $prerequisite_id = 'NULL';
-
- $sql_upd = "
- UPDATE " . $tbl_lp_item . "
- SET
- min_score = " . $min_score . ",
- max_score = " . $max_score . ",
- prerequisite = " . $prerequisite_id . "
- WHERE id = " . $id;
-
- $res_upd = api_sql_query($sql_upd ,__FILE__, __LINE__);
- //TODO update the item object (can be ignored for now because refreshed)
- return true;
- }
- /**
- * Escapes a string with the available database escape function
- * @param string String to escape
- * @return string String escaped
- */
- function escape_string($string){
- //if($this->debug>0){error_log('New LP - In learnpath::escape_string('.$string.')',0);}
- return mysql_real_escape_string($string);
- }
- /**
- * Static admin function exporting a learnpath into a zip file
- * @param string Export type (scorm, zip, cd)
- * @param string Course code
- * @param integer Learnpath ID
- * @param string Zip file name
- * @return string Zip file path (or false on error)
- */
- function export_lp($type, $course, $id, $zipname)
- {
- //if($this->debug>0){error_log('New LP - In learnpath::export_lp()',0);}
- //TODO
- if(empty($type) OR empty($course) OR empty($id) OR empty($zipname)){return false;}
- $url = '';
- switch($type){
- case 'scorm':
- break;
- case 'zip':
- break;
- case 'cdrom':
- break;
- }
- return $url;
- }
- /**
- * Gets all the chapters belonging to the same parent as the item/chapter given
- * Can also be called as abstract method
- * @param integer Item ID
- * @return array A list of all the "brother items" (or an empty array on failure)
- */
- function get_brother_chapters($id){
- if($this->debug>0){error_log('New LP - In learnpath::get_brother_chapters()',0);}
- if(empty($id) OR $id != strval(intval($id))){ return array();}
- $lp_item = Database::get_course_table('lp_item');
- $sql_parent = "SELECT * FROM $lp_item WHERE id = $id AND item_type='dokeos_chapter'";
- $res_parent = api_sql_query($sql_parent,__FILE__,__LINE__);
- if(Database::num_rows($res_parent)>0){
- $row_parent = Database::fetch_array($res_parent);
- $parent = $row_parent['parent_item_id'];
- $sql_bros = "SELECT * FROM $lp_item WHERE parent_item_id = $parent AND id = $id AND item_type='dokeos_chapter' ORDER BY display_order";
- $res_bros = api_sql_query($sql_bros,__FILE__,__LINE__);
- $list = array();
- while ($row_bro = Database::fetch_array($res_bros)){
- $list[] = $row_bro;
- }
- return $list;
- }
- return array();
- }
- /**
- * Gets all the items belonging to the same parent as the item given
- * Can also be called as abstract method
- * @param integer Item ID
- * @return array A list of all the "brother items" (or an empty array on failure)
- */
- function get_brother_items($id){
- if($this->debug>0){error_log('New LP - In learnpath::get_brother_items('.$id.')',0);}
- if(empty($id) OR $id != strval(intval($id))){ return array();}
- $lp_item = Database::get_course_table('lp_item');
- $sql_parent = "SELECT * FROM $lp_item WHERE id = $id";
- $res_parent = api_sql_query($sql_parent,__FILE__,__LINE__);
- if(Database::num_rows($res_parent)>0){
- $row_parent = Database::fetch_array($res_parent);
- $parent = $row_parent['parent_item_id'];
- $sql_bros = "SELECT * FROM $lp_item WHERE parent_item_id = $parent ORDER BY display_order";
- $res_bros = api_sql_query($sql_bros,__FILE__,__LINE__);
- $list = array();
- while ($row_bro = Database::fetch_array($res_bros)){
- $list[] = $row_bro;
- }
- return $list;
- }
- return array();
- }
- /**
- * Gets the number of items currently completed
- * @return integer The number of items currently completed
- */
- function get_complete_items_count()
- {
- if($this->debug>0){error_log('New LP - In learnpath::get_complete_items_count()',0);}
- $i = 0;
- foreach($this->items as $id => $dummy){
- //if($this->items[$id]->status_is(array('completed','passed','succeeded'))){
- //Trying failed and browsed considered "progressed" as well
- if($this->items[$id]->status_is(array('completed','passed','succeeded','browsed','failed'))){
- $i++;
- }
- }
- return $i;
- }
- /**
- * Gets the current item ID
- * @return integer The current learnpath item id
- */
- function get_current_item_id()
- {
- $current = 0;
- if($this->debug>0){error_log('New LP - In learnpath::get_current_item_id()',0);}
- if(!empty($this->current))
- {
- $current = $this->current;
- }
- if($this->debug>2){error_log('New LP - In learnpath::get_current_item_id() - Returning '.$current,0);}
- return $current;
- }
- /**
- * Gets the total number of items available for viewing in this SCORM
- * @return integer The total number of items
- */
- function get_total_items_count()
- {
- if($this->debug>0){error_log('New LP - In learnpath::get_total_items_count()',0);}
- return count($this->items);
- }
- /**
- * Gets the first element URL.
- * @return string URL to load into the viewer
- */
- function first()
- {
- if($this->debug>0){error_log('New LP - In learnpath::first()',0);}
- //test if the last_item_seen exists and is not a dir
- if(!empty($this->last_item_seen)
- && !empty($this->items[$this->last_item_seen])
- && $this->items[$this->last_item_seen]->get_type() != 'dir'
- && $this->items[$this->last_item_seen]->get_type() != 'dokeos_chapter'
- && $this->items[$this->last_item_seen]->is_done() != true
- ){
- if($this->debug>2){error_log('New LP - In learnpath::first() - Last item seen is '.$this->last_item_seen.' of type '.$this->items[$this->last_item_seen]->get_type(),0);}
- $index = -1;
- foreach($this->ordered_items as $myindex => $item_id){
- if($item_id == $this->last_item_seen){
- $index = $myindex;
- break;
- }
- }
- if($index==-1){
- //index hasn't changed, so item not found - panic (this shouldn't happen)
- if($this->debug>2){error_log('New LP - Last item ('.$this->last_item_seen.') was found in items but not in ordered_items, panic!',0);}
- return false;
- }else{
- $this->last = $this->last_item_seen;
- $this->current = $this->last_item_seen;
- $this->index = $index;
- }
- }else{
- if($this->debug>2){error_log('New LP - In learnpath::first() - No last item seen',0);}
- $index = 0;
- while (!empty($this->ordered_items[$index])
- AND
- (
- $this->items[$this->ordered_items[$index]]->get_type() == 'dir'
- OR $this->items[$this->ordered_items[$index]]->get_type() == 'dokeos_chapter'
- OR $this->items[$this->ordered_items[$index]]->is_done() === true
- )
- AND $index < $this->max_ordered_items)
- {
- $index ++;
- }
- $this->last = $this->current;
- //current is
- $this->current = $this->ordered_items[$index];
- $this->index = $index;
- if($this->debug>2){error_log('New LP - In learnpath::first() - No last item seen. New last = '.$this->last.'('.$this->ordered_items[$index].')',0);}
- }
- if($this->debug>2){error_log('New LP - In learnpath::first() - First item is '.$this->get_current_item_id());}
- }
- /**
- * Gets the information about an item in a format usable as JavaScript to update
- * the JS API by just printing this content into the <head> section of the message frame
- * @param integer Item ID
- * @return string
- */
- function get_js_info($item_id=''){
- if($this->debug>0){error_log('New LP - In learnpath::get_js_info('.$item_id.')',0);}
- $info = '';
- $item_id = $this->escape_string($item_id);
- if(!empty($item_id) && is_object($this->items[$item_id])){
- //if item is defined, return values from DB
- $oItem = $this->items[$item_id];
- $info .= '<script language="javascript">';
- $info .= "top.set_score(".$oItem->get_score().");\n";
- $info .= "top.set_max(".$oItem->get_max().");\n";
- $info .= "top.set_min(".$oItem->get_min().");\n";
- $info .= "top.set_lesson_status('".$oItem->get_status()."');";
- $info .= "top.set_session_time('".$oItem->get_scorm_time('js')."');";
- $info .= "top.set_suspend_data('".$oItem->get_suspend_data()."');";
- $info .= "top.set_saved_lesson_status('".$oItem->get_status()."');";
- $info .= "top.set_flag_synchronized();";
- $info .= '</script>';
- if($this->debug>2){error_log('New LP - in learnpath::get_js_info('.$item_id.') - returning: '.$info,0);}
- return $info;
- }else{
- //if item_id is empty, just update to default SCORM data
- $info .= '<script language="javascript">';
- $info .= "top.set_score(".learnpathItem::get_score().");\n";
- $info .= "top.set_max(".learnpathItem::get_max().");\n";
- $info .= "top.set_min(".learnpathItem::get_min().");\n";
- $info .= "top.set_lesson_status('".learnpathItem::get_status()."');";
- $info .= "top.set_session_time('".learnpathItem::get_scorm_time('js')."');";
- $info .= "top.set_suspend_data('".learnpathItem::get_suspend_data()."');";
- $info .= "top.set_saved_lesson_status('".learnpathItem::get_status()."');";
- $info .= "top.set_flag_synchronized();";
- $info .= '</script>';
- if($this->debug>2){error_log('New LP - in learnpath::get_js_info('.$item_id.') - returning: '.$info,0);}
- return $info;
- }
- }
- /**
- * Gets the js library from the database
- * @return string The name of the javascript library to be used
- */
- function get_js_lib(){
- $lib = '';
- if(!empty($this->js_lib)){
- $lib = $this->js_lib;
- }
- return $lib;
- }
- /**
- * Gets the learnpath database ID
- * @return integer Learnpath ID in the lp table
- */
- function get_id()
- {
- if($this->debug>0){error_log('New LP - In learnpath::get_id()',0);}
- if(!empty($this->lp_id))
- {
- return $this->lp_id;
- }else{
- return 0;
- }
- }
- /**
- * Gets the last element URL.
- * @return string URL to load into the viewer
- */
- function get_last()
- {
- if($this->debug>0){error_log('New LP - In learnpath::get_last()',0);}
- $this->index = count($this->ordered_items)-1;
- return $this->ordered_items[$this->index];
- }
- /**
- * Gets the navigation bar for the learnpath display screen
- * @return string The HTML string to use as a navigation bar
- */
- function get_navigation_bar()
- {
- if($this->debug>0){error_log('New LP - In learnpath::get_navigation_bar()',0);}
- //TODO find a good value for the following variables
- $file = '';
- $openDir = '';
- $edoceo = '';
- $time = 0;
- $navbar = '';
- $RequestUri = '';
- $mycurrentitemid = $this->get_current_item_id();
- if($this->mode == 'fullscreen'){
- $navbar = '<table cellpadding="0" cellspacing="0" align="left">'."\n".
- ' <tr> '."\n" .
- ' <td>'."\n" .
- ' <div class="buttons">'."\n" .
- ' <a href="" onclick="dokeos_xajax_handler.switch_item('.$mycurrentitemid.',\'previous\');return false;" title="previous"><img border="0" src="../img/previous.gif" title="'.get_lang('ScormPrevious').'"></a> '."\n" .
- ' <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> '."\n" .
- ' <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" .
- ' <a href="lp_controller.php?action=list" target="_top" title="learnpaths list"><img border="0" src="../img/exit.png" title="Exit"></a>'."\n" .
- ' </div>'."\n" .
- ' </td>'."\n" .
- ' </tr>'."\n" .
- '</table>'."\n" ;
-
- }else{
- $navbar = '<table cellpadding="0" cellspacing="0" align="left">'."\n".
- ' <tr> '."\n" .
- ' <td>'."\n" .
- ' <div class="buttons">'."\n" .
- ' <a href="lp_controller.php?action=stats" target="content_name" title="stats"><img border="0" src="../img/scormstatus.gif" title="'.get_lang('ScormMystatus').'"></a> '."\n" .
- ' <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> '."\n" .
- ' <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> '."\n" .
- ' <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" .
- ' </div>'."\n" .
- ' </td>'."\n" .
- ' </tr>'."\n" .
- '</table>'."\n" ;
- }
- return $navbar;
- }
- /**
- * Gets the next resource in queue (url).
- * @return string URL to load into the viewer
- */
- function get_next_index()
- {
- if($this->debug>0){error_log('New LP - In learnpath::get_next_index()',0);}
- //TODO
- $index = $this->index;
- $index ++;
- if($this->debug>2){error_log('New LP - Now looking at ordered_items['.($index).'] - type is '.$this->items[$this->ordered_items[$index]]['type'],0);}
- while(!empty($this->ordered_items[$index]) AND $this->items[$this->ordered_items[$index]]->get_type() == 'dir' AND $index < $this->max_ordered_items)
- {
- $index ++;
- if($index == $this->max_ordered_items)
- {
- return $this->index;
- }
- }
- if(empty($this->ordered_items[$index])){
- return $this->index;
- }
- if($this->debug>2){error_log('New LP - index is now '.$index,0);}
- return $index;
- }
- /**
- * Gets item_id for the next element
- * @return integer Next item (DB) ID
- */
- function get_next_item_id()
- {
- $new_index = $this->get_next_index();
- return $this->ordered_items[$new_index];
- }
- /**
- * Gets the previous resource in queue (url). Also initialises time values for this viewing
- * @return string URL to load into the viewer
- */
- function get_previous_index()
- {
- if($this->debug>0){error_log('New LP - In learnpath::get_previous_index()',0);}
- $index = $this->index;
- if(isset($this->ordered_items[$index-1])){
- $index --;
- while(isset($this->ordered_items[$index]) AND $this->items[$this->ordered_items[$index]]->get_type() == 'dir')
- {
- $index --;
- if($index < 0){
- return $this->index;
- }
- }
- }else{
- if($this->debug>2){error_log('New LP - get_previous_index() - there was no previous index available, reusing '.$index,0);}
- //no previous item
- }
- return $index;
- }
- /**
- * Gets item_id for the next element
- * @return integer Previous item (DB) ID
- */
- function get_previous_item_id()
- {
- $new_index = $this->get_previous_index();
- return $this->ordered_items[$new_index];
- }
- /**
- * Gets the progress value from the progress_db attribute
- * @return integer Current progress value
- */
- function get_progress(){
- if($this->debug>0){error_log('New LP - In learnpath::get_progress()',0);}
- if(!empty($this->progress_db)){
- return $this->progress_db;
- }
- return 0;
- }
- /**
- * Gets the progress value from the progress field in the database (allows use as abstract method)
- * @param integer Learnpath ID
- * @param integer User ID
- * @param string Mode of display ('%','abs' or 'both')
- * @return integer Current progress value as found in the database
- */
- function get_db_progress($lp_id,$user_id,$mode='%'){
- //if($this->debug>0){error_log('New LP - In learnpath::get_db_progress()',0);}
- $table = Database::get_course_table('lp_view');
- $sql = "SELECT * FROM $table WHERE lp_id = $lp_id AND user_id = $user_id";
- $res = api_sql_query($sql,__FILE__,__LINE__);
- $view_id = 0;
- if(Database::num_rows($res)>0){
- $row = Database::fetch_array($res);
- $progress = $row['progress'];
- $view_id = $row['id'];
- }
- if(!$progress){
- $progress = '0';
- }
- if($mode == '%'){
- return $progress.'%';
- }else{
- //get the number of items completed and the number of items total
- $tbl = Database::get_course_table('lp_item');
- $sql = "SELECT count(*) FROM $tbl WHERE lp_id = ".$lp_id;
- $res = api_sql_query($sql);
- $row = Database::fetch_array($res);
- $total = $row[0];
- $tbl = Database::get_course_table('lp_item_view');
- //$sql = "SELECT count(distinct(lp_item_id)) FROM $tbl WHERE lp_view_id = ".$view_id." AND status IN ('passed','completed','succeeded')";
- //trying as also counting browsed and failed items
- $sql = "SELECT count(distinct(lp_item_id)) FROM $tbl WHERE lp_view_id = ".$view_id." AND status IN ('passed','completed','succeeded','browsed','failed')";
- $res = api_sql_query($sql);
- $row = Database::fetch_array($res);
- $completed = $row[0];
- if($mode == 'abs'){
- return $completed.'/'.$total;
- }
- elseif($mode == 'both')
- {
- return $progress.'% ('.$completed.'/'.$total.')';
- }
- }
- return $progress;
- }
- /**
- * Gets a progress bar for the learnpath by counting the number of items in it and the number of items
- * completed so far.
- * @param string Mode in which we want the values
- * @param integer Progress value to display (optional but mandatory if used in abstract context)
- * @param string Text to display near the progress value (optional but mandatory in abstract context)
- * @return string HTML string containing the progress bar
- */
- function get_progress_bar($mode='',$percentage=-1,$text_add='')
- {
- if($this->debug>0){error_log('New LP - In learnpath::get_progress_bar()',0);}
- if($percentage=='-1' OR $text_add==''){
- list ($percentage, $text_add) = $this->get_progress_bar_text($mode);
- }
- $text = $percentage.$text_add;
- $output = ''
- //.htmlentities(get_lang('ScormCompstatus'),ENT_QUOTES,'ISO-8859-1')."<br />"
- .'<table border="0" cellpadding="0" cellspacing="0"><tr><td>'
- .'<img id="progress_img_limit_left" src="../img/bar_1.gif" width="1" height="12">'
- .'<img id="progress_img_full" src="../img/bar_1u.gif" width="'.$percentage.'" height="12" id="full_portion">'
- .'<img id="progress_img_limit_middle" src="../img/bar_1m.gif" width="1" height="12">';
- if($percentage <= 98){
- $output .= '<img id="progress_img_empty" src="../img/bar_1r.gif" width="'.(100-$percentage).'" height="12" id="empty_portion">';
- }else{
- $output .= '<img id="progress_img_empty" src="../img/bar_1r.gif" width="0" height="12" id="empty_portion">';
- }
- $output .= '<img id="progress_bar_img_limit_right" src="../img/bar_1.gif" width="1" height="12"></td></tr></table>'
- .'<div class="progresstext" id="progress_text">'.$text.'</div>';
- return $output;
- }
- /**
- * Gets the progress bar info to display inside the progress bar. Also used by scorm_api.php
- * @param string Mode of display (can be '%' or 'abs').abs means we display a number of completed elements per total elements
- * //@param integer Additional steps to fake as completed
- * @return list Percentage or number and symbol (% or /xx)
- */
- function get_progress_bar_text($mode='',$add=0)
- {
- if($this->debug>0){error_log('New LP - In learnpath::get_progress_bar_text()',0);}
- if(empty($mode)){$mode = $this->progress_bar_mode;}
- $total_items = $this->get_total_items_count();
- if($this->debug>2){error_log('New LP - Total items available in this learnpath: '.$total_items,0);}
- $i = $this->get_complete_items_count();
- if($this->debug>2){error_log('New LP - Items completed so far: '.$i,0);}
- if($add != 0){
- $i += $add;
- if($this->debug>2){error_log('New LP - Items completed so far (+modifier): '.$i,0);}
- }
- $text = '';
- if($i>$total_items){
- $i = $total_items;
- }
- if($mode == '%'){
- $percentage = ((float)$i/(float)$total_items)*100;
- $percentage = number_format($percentage,0);
- $text = '%';
- }elseif($mode == 'abs'){
- $percentage = $i;
- $text = '/'.$total_items;
- }
- return array($percentage,$text);
- }
- /**
- * Gets the progress bar mode
- * @return string The progress bar mode attribute
- */
- function get_progress_bar_mode()
- {
- if($this->debug>0){error_log('New LP - In learnpath::get_progress_bar_mode()',0);}
- if(!empty($this->progress_bar_mode))
- {
- return $this->progress_bar_mode;
- }else{
- return '%';
- }
- }
-
- /**
- * Returns a usable array of stats related to the current learnpath and user
- * @return array Well-formatted array containing status for the current learnpath
- */
- function get_stats()
- {
- if($this->debug>0){error_log('New LP - In learnpath::get_stats()',0);}
- //TODO
- }
- /**
- * Static method. Can be re-implemented by children. Gives an array of statistics for
- * the given course (for all learnpaths and all users)
- * @param string Course code
- * @return array Well-formatted array containing status for the course's learnpaths
- */
- function get_stats_course($course)
- {
- //if($this->debug>0){error_log('New LP - In learnpath::get_stats_course()',0);}
- //TODO
- }
- /**
- * Static method. Can be re-implemented by children. Gives an array of statistics for
- * the given course and learnpath (for all users)
- * @param string Course code
- * @param integer Learnpath ID
- * @return array Well-formatted array containing status for the specified learnpath
- */
- function get_stats_lp($course,$lp)
- {
- //if($this->debug>0){error_log('New LP - In learnpath::get_stats_lp()',0);}
- //TODO
- }
- /**
- * Static method. Can be re-implemented by children. Gives an array of statistics for
- * the given course, learnpath and user.
- * @param string Course code
- * @param integer Learnpath ID
- * @param integer User ID
- * @return array Well-formatted array containing status for the specified learnpath and user
- */
- function get_stats_lp_user($course,$lp,$user)
- {
- //if($this->debug>0){error_log('New LP - In learnpath::get_stats_lp_user()',0);}
- //TODO
- }
- /**
- * Static method. Can be re-implemented by children. Gives an array of statistics for
- * the given course and learnpath (for all users)
- * @param string Course code
- * @param integer User ID
- * @return array Well-formatted array containing status for the user's learnpaths
- */
- function get_stats_user($course,$user)
- {
- //if($this->debug>0){error_log('New LP - In learnpath::get_stats_user()',0);}
- //TODO
- }
- /**
- * Gets the status list for all LP's items
- * @return array Array of [index] => [item ID => current status]
- */
- function get_items_status_list(){
- if($this->debug>0){error_log('New LP - In learnpath::get_items_status_list()',0);}
- $list = array();
- foreach($this->ordered_items as $item_id)
- {
- $list[]= array($item_id => $this->items[$item_id]->get_status());
- }
- return $list;
- }
- /**
- * Generate and return the table of contents for this learnpath. The (flat) table returned can be
- * used by get_html_toc() to be ready to display
- * @return array TOC as a table with 4 elements per row: title, link, status and level
- */
- function get_toc()
- {
- if($this->debug>0){error_log('New LP - In learnpath::get_toc()',0);}
- $toc = array();
- //echo "<pre>".print_r($this->items,true)."</pre>";
- foreach($this->ordered_items as $item_id)
- {
- if($this->debug>2){error_log('New LP - learnpath::get_toc(): getting info for item '.$item_id,0);}
- //TODO change this link generation and use new function instead
- $toc[] = array(
- 'id'=>$item_id,
- 'title'=>$this->items[$item_id]->get_title(),
- //'link'=>get_addedresource_link_in_learnpath('document',$item_id,1),
- 'status'=>$this->items[$item_id]->get_status(),
- 'level'=>$this->items[$item_id]->get_level(),
- 'type' =>$this->items[$item_id]->get_type(),
- );
- }
- if($this->debug>2){error_log('New LP - In learnpath::get_toc() - TOC array: '.print_r($toc,true),0);}
- return $toc;
- }
- /**
- * Gets the learning path type
- * @param boolean Return the name? If false, return the ID. Default is false.
- * @return mixed Type ID or name, depending on the parameter
- */
- function get_type($get_name = false)
- {
- $res = false;
- if($this->debug>0){error_log('New LP - In learnpath::get_type()',0);}
- if(!empty($this->type))
- {
- if($get_name)
- {
- //get it from the lp_type table in main db
- }else{
- $res = $this->type;
- }
- }
- if($this->debug>2){error_log('New LP - In learnpath::get_type() - Returning '.($res==false?'false':$res),0);}
- return $res;
- }
- /**
- * Gets a flat list of item IDs ordered for display (level by level ordered by order_display)
- * This method can be used as abstract and is recursive
- * @param integer Learnpath ID
- * @param integer Parent ID of the items to look for
- * @return mixed Ordered list of item IDs or false on error
- */
- function get_flat_ordered_items_list($lp,$parent=0){
- if($this->debug>0){error_log('New LP - In learnpath::get_flat_ordered_items_list('.$lp.','.$parent.')',0);}
- $list = array();
- if(empty($lp)){return false;}
- $tbl_lp_item = Database::get_course_table('lp_item');
- $sql = "SELECT * FROM $tbl_lp_item WHERE lp_id = $lp AND parent_item_id = $parent ORDER BY display_order";
- $res = api_sql_query($sql,__FILE__,__LINE__);
- while($row = Database::fetch_array($res)){
- $sublist = learnpath::get_flat_ordered_items_list($lp,$row['id']);
- $list[] = $row['id'];
- foreach($sublist as $item){
- $list[] = $item;
- }
- }
- return $list;
- }
- /**
- * Uses the table generated by get_toc() and returns an HTML-formatted string ready to display
- * @return string HTML TOC ready to display
- */
- function get_html_toc()
- {
- if($this->debug>0){error_log('New LP - In learnpath::get_html_toc()',0);}
- $list = $this->get_toc();
- //echo $this->current;
- //$parent = $this->items[$this->current]->get_parent();
- //if(empty($parent)){$parent = $this->ordered_items[$this->items[$this->current]->get_previous_index()];}
- $html = '<div class="inner_lp_toc">'."\n" ;
- // " onchange=\"javascript:document.getElementById('toc_$parent').focus();\">\n";
- require_once('resourcelinker.inc.php');
-
- //temp variables
- $mycurrentitemid = $this->get_current_item_id();
-
- foreach($list as $item)
- {
- if($this->debug>2){error_log('New LP - learnpath::get_html_toc(): using item '.$item['id'],0);}
- //TODO complete this
- $icon_name = array('not attempted' => 'notattempted.png',
- 'incomplete' => 'incomplete.png',
- 'failed' => 'failed.png',
- 'completed' => 'completed.png',
- 'passed' => 'passed.png',
- 'succeeded' => 'succeeded.png',
- 'browsed' => 'completed.png');
-
- $style = 'scorm_item';
- if($item['id'] == $this->current){
- $style = 'scorm_item_highlight';
- }
- //the anchor will let us center the TOC on the currently viewed item &^D
- $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'].'" >' .
- '<img id="toc_img_'.$item['id'].'" class="scorm_status_img" src="'.$icon_name[$item['status']].'" alt="'.substr($item['status'],0,1).'" />';
-
- //$title = htmlspecialchars($item['title'],ENT_QUOTES,$this->encoding);
- $title = $item['title'];
- if(empty($title)){
- $title = rl_get_resource_name(api_get_course_id(),$this->get_id(),$item['id']);
- $title = htmlspecialchars($title,ENT_QUOTES,$this->encoding);
- }
- if(empty($title))$title = '-';
-
- if($item['type']!='dokeos_chapter' and $item['type']!='dir'){
- //$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>" ;
- $url = $this->get_link('http',$item['id']);
- //$html .= '<a href="'.$url.'" target="content_name" onclick="top.load_item('.$item['id'].',\''.$url.'\');">'.$title.'</a>' ;
- //$html .= '<a href="" onclick="top.load_item('.$item['id'].',\''.$url.'\');return false;">'.$title.'</a>' ;
- $html .= '<a href="" onclick="dokeos_xajax_handler.switch_item(' .
- $mycurrentitemid.',' .
- $item['id'].');' .
- 'return false;" >'.$title.'</a>' ;
- }else{
- $html .= $title;
- }
- $html .= "</div>\n";
- }
- $html .= "</div>\n";
- return $html;
- }
- /**
- * Gets the user-friendly message stored in $this->message
- * @return string Message
- */
- function get_message(){
- if($this->debug>0){error_log('New LP - In learnpath::get_message()',0);}
- return $this->message;
- }
- /**
- * Gets the learnpath name/title
- * @return string Learnpath name/title
- */
- function get_name()
- {
- if($this->debug>0){error_log('New LP - In learnpath::get_name()',0);}
- if(!empty($this->name)){return $this->name;}else{return 'N/A';}
- }
- /**
- * Gets a link to the resource from the present location, depending on item ID.
- * @param string Type of link expected
- * @param integer Learnpath item ID
- * @return string Link to the lp_item resource
- */
- function get_link($type='http',$item_id=null)
- {
- if($this->debug>0){error_log('New LP - In learnpath::get_link('.$type.','.$item_id.')',0);}
- if(empty($item_id))
- {
- if($this->debug>2){error_log('New LP - In learnpath::get_link() - no item id given in learnpath::get_link(), using current: '.$this->get_current_item_id(),0);}
- $item_id = $this->get_current_item_id();
- }
- if(empty($item_id)){
- if($this->debug>2){error_log('New LP - In learnpath::get_link() - no current item id found in learnpath object',0);}
- //still empty, this means there was no item_id given and we are not in an object context or
- //the object property is empty, return empty link
- $item_id = $this->first();
- return '';
- }
- $file = '';
- $lp_db = Database::get_current_course_database();
- $lp_pref = Database::get_course_table_prefix();
- $lp_table = $lp_db.'.'.$lp_pref.'lp';
- $lp_item_table = $lp_db.'.'.$lp_pref.'lp_item';
- $sel = "SELECT l.lp_type as ltype, l.path as lpath, li.item_type as litype, li.path as lipath " .
- "FROM $lp_table l, $lp_item_table li WHERE li.id = $item_id AND li.lp_id = l.id";
- if($this->debug>2){error_log('New LP - In learnpath::get_link() - selecting item '.$sel,0);}
- $res = api_sql_query($sel);
- if(Database::num_rows($res)>0)
- {
- $row = Database::fetch_array($res);
- //var_dump($row);
- $lp_type = $row['ltype'];
- $lp_path = $row['lpath'];
- $lp_item_type = $row['litype'];
- $lp_item_path = $row['lipath'];
- if($type == 'http'){
- $course_path = api_get_path(WEB_COURSE_PATH).api_get_course_path(); //web path
- }else{
- $course_path = api_get_path(SYS_COURSE_PATH).api_get_course_path(); //system path
- }
- //now go through the specific cases to get the end of the path
- switch($lp_type){
- case 1:
- if($lp_item_type == 'dokeos_chapter'){
- $file = 'lp_content.php?type=dir';
- }else{
- require_once('resourcelinker.inc.php');
- $file = rl_get_resource_link_for_learnpath(api_get_course_id(),$this->get_id(),$item_id);
- }
- break;
- case 2:
- if($this->debug>2){error_log('New LP - In learnpath::get_link() '.__LINE__.' - Item type: '.$lp_item_type,0);}
- if($lp_item_type!='dir'){
- //Quite complex here:
- //we want to make sure 'http://' (and similar) links can
- //be loaded as is (withouth the Dokeos path in front) but
- //some contents use this form: resource.htm?resource=http://blablabla
- //which means we have to find a protocol at the path's start, otherwise
- //it should not be considered as an external URL
-
- //if($this->prerequisites_match($item_id)){
- if(preg_match('#^[a-zA-Z]{2,5}://#',$lp_item_path)!=0){
- if($this->debug>2){error_log('New LP - In learnpath::get_link() '.__LINE__.' - Found match for protocol in '.$lp_item_path,0);}
- //distant url, return as is
- $file = $lp_item_path;
- }else{
- if($this->debug>2){error_log('New LP - In learnpath::get_link() '.__LINE__.' - No starting protocol in '.$lp_item_path,0);}
- //prevent getting untranslatable urls
- $lp_item_path = preg_replace('/%2F/','/',$lp_item_path);
- $lp_item_path = preg_replace('/%3A/',':',$lp_item_path);
- //prepare the path
- $file = $course_path.'/scorm/'.$lp_path.'/'.$lp_item_path;
- //TODO fix this for urls with protocol header
- $file = str_replace('//','/',$file);
- $file = str_replace(':/','://',$file);
- }
- //}else{
- //prerequisites did not match
- //$file = 'blank.php';
- //}
- }else{
- $file = 'lp_content.php?type=dir';
- }
- break;
- case 3:
- if($this->debug>2){error_log('New LP - In learnpath::get_link() '.__LINE__.' - Item type: '.$lp_item_type,0);}
- //formatting AICC HACP append URL
- $aicc_append = '?aicc_sid='.urlencode(session_id()).'&aicc_url='.urlencode(api_get_path(WEB_CODE_PATH).'newscorm/aicc.hacp.php').'&';
- if($lp_item_type!='dir'){
- //Quite complex here:
- //we want to make sure 'http://' (and similar) links can
- //be loaded as is (withouth the Dokeos path in front) but
- //some contents use this form: resource.htm?resource=http://blablabla
- //which means we have to find a protocol at the path's start, otherwise
- //it should not be considered as an external URL
-
- if(preg_match('#^[a-zA-Z]{2,5}://#',$lp_item_path)!=0){
- if($this->debug>2){error_log('New LP - In learnpath::get_link() '.__LINE__.' - Found match for protocol in '.$lp_item_path,0);}
- //distant url, return as is
- $file = $lp_item_path;
- $file .= $aicc_append;
- }else{
- if($this->debug>2){error_log('New LP - In learnpath::get_link() '.__LINE__.' - No starting protocol in '.$lp_item_path,0);}
- //prevent getting untranslatable urls
- $lp_item_path = preg_replace('/%2F/','/',$lp_item_path);
- $lp_item_path = preg_replace('/%3A/',':',$lp_item_path);
- //prepare the path
- $file = $course_path.'/scorm/'.$lp_path.'/'.$lp_item_path;
- //TODO fix this for urls with protocol header
- $file = str_replace('//','/',$file);
- $file = str_replace(':/','://',$file);
- $file .= $aicc_append;
- }
- }else{
- $file = 'lp_content.php?type=dir';
- }
- break;
- case 4:
- break;
- default:
- break;
- }
- }
- if($this->debug>2){error_log('New LP - In learnpath::get_link() - returning "'.$file.'" from get_link',0);}
- return $file;
- }
- /**
- * Gets the latest usable view or generate a new one
- * @param integer Optional attempt number. If none given, takes the highest from the lp_view table
- * @return integer DB lp_view id
- */
- function get_view($attempt_num=0)
- {
- if($this->debug>0){error_log('New LP - In learnpath::get_view()',0);}
- $search = '';
- //use $attempt_num to enable multi-views management (disabled so far)
- if($attempt_num != 0 AND intval(strval($attempt_num)) == $attempt_num)
- {
- $search = 'AND view_count = '.$attempt_num;
- }
- //when missing $attempt_num, search for a unique lp_view record for this lp and user
- $lp_view_table = Database::get_course_table('lp_view');
- $sql = "SELECT id, view_count FROM $lp_view_table " .
- "WHERE lp_id = ".$this->get_id()." " .
- "AND user_id = ".$this->get_user_id()." " .
- $search .
- " ORDER BY view_count DESC";
- $res = api_sql_query($sql);
- if(Database::num_rows($res)>0)
- {
- $row = Database::fetch_array($res);
- $this->lp_view_id = $row['id'];
- }else{
- //no database record, create one
- $sql = "INSERT INTO $lp_view_table(lp_id,user_id,view_count)" .
- "VALUES (".$this->get_id().",".$this->get_user_id().",1)";
- $res = api_sql_query($sql);
- $id = Database::get_last_insert_id();
- $this->lp_view_id = $id;
- }
- }
- /**
- * Gets the current view id
- * @return integer View ID (from lp_view)
- */
- function get_view_id()
- {
- if($this->debug>0){error_log('New LP - In learnpath::get_view_id()',0);}
- if(!empty($this->lp_view_id))
- {
- return $this->lp_view_id;
- }else{
- return 0;
- }
- }
- /**
- * Gets the update queue
- * @return array Array containing IDs of items to be updated by JavaScript
- */
- function get_update_queue()
- {
- if($this->debug>0){error_log('New LP - In learnpath::get_update_queue()',0);}
- return $this->update_queue;
- }
- /**
- * Gets the user ID
- * @return integer User ID
- */
- function get_user_id()
- {
- if($this->debug>0){error_log('New LP - In learnpath::get_user_id()',0);}
- if(!empty($this->user_id))
- {
- return $this->user_id;
- }else{
- return false;
- }
- }
- /**
- * Logs a message into a file
- * @param string Message to log
- * @return boolean True on success, false on error or if msg empty
- */
- function log($msg)
- {
- if($this->debug>0){error_log('New LP - In learnpath::log()',0);}
- //TODO
- $this->error .= $msg."\n";
- return true;
- }
- /**
- * Moves an item up and down at its level
- * @param integer Item to move up and down
- * @param string Direction 'up' or 'down'
- * @return integer New display order, or false on error
- */
- function move_item($id, $direction){
- if($this->debug>0){error_log('New LP - In learnpath::move_item('.$id.','.$direction.')',0);}
- if(empty($id) or empty($direction)){return false;}
- $tbl_lp_item = Database::get_course_table('lp_item');
- $sql_sel = "
- SELECT *
- FROM " . $tbl_lp_item . "
- WHERE id = " . $id;
- $res_sel = api_sql_query($sql_sel,__FILE__,__LINE__);
- //check if elem exists
- if(Database::num_rows($res_sel)<1){return false;}
- //gather data
- $row = Database::fetch_array($res_sel);
- $previous = $row['previous_item_id'];
- $next = $row['next_item_id'];
- $display = $row['display_order'];
- $parent = $row['parent_item_id'];
- $lp = $row['lp_id'];
- //update the item (switch with previous/next one)
- switch($direction)
- {
- case 'up':
- if($this->debug>2){error_log('Movement up detected',0);}
- if($display <= 1){/*do nothing*/}
- else{
- $sql_sel2 = "SELECT *
- FROM $tbl_lp_item
- WHERE id = $previous";
- if($this->debug>2){error_log('Selecting previous: '.$sql_sel2,0);}
- $res_sel2 = api_sql_query($sql_sel2,__FILE__,__LINE__);
- if(Database::num_rows($res_sel2)<1){$previous_previous = 0;}
- //gather data
- $row2 = Database::fetch_array($res_sel2);
- $previous_previous = $row2['previous_item_id'];
- //update previous_previous item (switch "next" with current)
- if($previous_previous != 0){
- $sql_upd2 = "UPDATE $tbl_lp_item SET next_item_id = $id WHERE id = $previous_$previous";
- if($this->debug>2){error_log($sql_upd2,0);}
- $res_upd2 = api_sql_query($sql_upd2);
- }
- //update previous item (switch with current)
- if($previous != 0){
- $sql_upd2 = "UPDATE $tbl_lp_item SET next_item_id = $next, previous_item_id = $id, display_order = display_order +1 WHERE id = $previous";
- if($this->debug>2){error_log($sql_upd2,0);}
- $res_upd2 = api_sql_query($sql_upd2);
- }
- //update current item (switch with previous)
- if($id != 0){
- $sql_upd2 = "UPDATE $tbl_lp_item SET next_item_id = $previous, previous_item_id = $previous_previous, display_order = display_order-1 WHERE id = $id";
- if($this->debug>2){error_log($sql_upd2,0);}
- $res_upd2 = api_sql_query($sql_upd2);
- }
- //update next item (new previous item)
- if($next != 0){
- $sql_upd2 = "UPDATE $tbl_lp_item SET previous_item_id = $previous WHERE id = $next";
- if($this->debug>2){error_log($sql_upd2,0);}
- $res_upd2 = api_sql_query($sql_upd2);
- }
- $display = $display-1;
- }
- break;
- case 'down':
- if($this->debug>2){error_log('Movement down detected',0);}
- if($next == 0){/*do nothing*/}
- else{
- $sql_sel2 = "SELECT * FROM $tbl_lp_item WHERE id = $next";
- if($this->debug>2){error_log('Selecting next: '.$sql_sel2,0);}
- $res_sel2 = api_sql_query($sql_sel2,__FILE__,__LINE__);
- if(Database::num_rows($res_sel2)<1){$next_next = 0;}
- //gather data
- $row2 = Database::fetch_array($res_sel2);
- $next_next = $row2['next_item_id'];
- //update previous item (switch with current)
- if($previous != 0){
- $sql_upd2 = "UPDATE $tbl_lp_item SET next_item_id = $next WHERE id = $previous";
- $res_upd2 = api_sql_query($sql_upd2);
- }
- //update current item (switch with previous)
- if($id != 0){
- $sql_upd2 = "UPDATE $tbl_lp_item SET previous_item_id = $next, next_item_id = $next_next, display_order = display_order+1 WHERE id = $id";
- $res_upd2 = api_sql_query($sql_upd2);
- }
- //update next item (new previous item)
- if($next != 0){
- $sql_upd2 = "UPDATE $tbl_lp_item SET previous_item_id = $previous, next_item_id = $id, display_order = display_order-1 WHERE id = $next";
- $res_upd2 = api_sql_query($sql_upd2);
- }
- //update next_next item (switch "previous" with current)
- if($next_next != 0){
- $sql_upd2 = "UPDATE $tbl_lp_item SET previous_item_id = $id WHERE id = $next_next";
- $res_upd2 = api_sql_query($sql_upd2);
- }
- $display = $display+1;
- }
- break;
- default:
- return false;
- }
- return $display;
- }
- /**
- * Updates learnpath attributes to point to the next element
- * The last part is similar to set_current_item but processing the other way around
- */
- function next(){
- if($this->debug>0){error_log('New LP - In learnpath::next()',0);}
- $this->last = $this->get_current_item_id();
- $this->items[$this->last]->save(false);
- $this->autocomplete_parents($this->last);
- $new_index = $this->get_next_index();
- if($this->debug>2){error_log('New LP - New index: '.$new_index,0);}
- $this->index = $new_index;
- if($this->debug>2){error_log('New LP - Now having orderedlist['.$new_index.'] = '. $this->ordered_items[$new_index],0);}
- $this->current = $this->ordered_items[$new_index];
- if($this->debug>2){error_log('New LP - new item id is '.$this->current.'-'.$this->get_current_item_id(),0);}
- }
- /**
- * Open a resource = initialise all local variables relative to this resource. Depending on the child
- * class, this might be redefined to allow several behaviours depending on the document type.
- * @param integer Resource ID
- * @return boolean True on success, false otherwise
- */
- function open($id)
- {
- if($this->debug>0){error_log('New LP - In learnpath::open()',0);}
- //TODO
- //set the current resource attribute to this resource
- //switch on element type (redefine in child class?)
- //set status for this item to "opened"
- //start timer
- //initialise score
- $this->index = 0; //or = the last item seen (see $this->last)
- }
- /**
- * Check that all prerequisites are fulfilled. Returns true and an empty string on succes, returns false
- * and the prerequisite string on error.
- * This function is based on the rules for aicc_script language as described in the SCORM 1.2 CAM documentation page 108.
- * @param integer Optional item ID. If none given, uses the current open item.
- * @return boolean True if prerequisites are matched, false otherwise
- * @return string Empty string if true returned, prerequisites string otherwise.
- */
- function prerequisites_match($item = null){
- if($this->debug>0){error_log('New LP - In learnpath::prerequisites_match()',0);}
- if(empty($item)){$item = $this->current;}
- if(is_object($this->items[$item])){
- $prereq_string = $this->items[$item]->get_prereq_string();
- if(empty($prereq_string)){return true;}
- //clean spaces
- $prereq_string = str_replace(' ','',$prereq_string);
- if($this->debug>0){error_log('Found prereq_string: '.$prereq_string,0);}
- //now send to the parse_prereq() function that will check this component's prerequisites
- $result = $this->items[$item]->parse_prereq($prereq_string,$this);
- if($result === false){
- $this->set_error_msg($this->items[$item]->prereq_alert);
- }
- }else{
- $result = true;
- if($this->debug>1){error_log('New LP - $this->items['.$item.'] was not an object',0);}
- }
- if($this->debug>1){error_log('New LP - End of prerequisites_match(). Error message is now '.$this->error,0);}
- return $result;
- }
- /**
- * Updates learnpath attributes to point to the previous element
- * The last part is similar to set_current_item but processing the other way around
- */
- function previous(){
- if($this->debug>0){error_log('New LP - In learnpath::previous()',0);}
- $this->last = $this->get_current_item_id();
- $this->items[$this->last]->save(false);
- $this->autocomplete_parents($this->last);
- $new_index = $this->get_previous_index();
- $this->index = $new_index;
- $this->current = $this->ordered_items[$new_index];
- }
- /**
- * Publishes a learnpath. This basically means show or hide the learnpath
- * to normal users.
- * Can be used as abstract
- * @param integer Learnpath ID
- * @param string New visibility
- */
- function toggle_visibility($lp_id,$set_visibility='v')
- {
- //if($this->debug>0){error_log('New LP - In learnpath::toggle_visibility()',0);}
- $tbl_lp = Database::get_course_table('lp');
- $sql="SELECT * FROM $tbl_lp where id=$lp_id";
- $result=api_sql_query($sql,__FILE__,__LINE__);
- $row=Database::fetch_array($result);
- $name=domesticate($row['name']);
- if($set_visibility == 'i') {
- $s=$name." ".get_lang('_no_published');
- $dialogBox=$s;
- $v=0;
- }
- if($set_visibility == 'v') {
- $s=$name." ".get_lang('_published');
- $dialogBox=$s;
- $v=1;
- }
- $tbl_tool = Database::get_course_table(TOOL_LIST_TABLE);
- $sql="SELECT * FROM $tbl_tool where name='$name' and image='scormbuilder.gif'";
- $result=api_sql_query($sql,__FILE__,__LINE__);
- $num=Database::num_rows($result);
- $row2=Database::fetch_array($result);
- //if($this->debug>2){error_log('New LP - '.$sql.' - '.$num,0);}
- if(($set_visibility == 'i') && ($num>0))
- {
- //it is visible or hidden but once was published
- if(($row2['visibility'])==1)
- {
- $sql ="DELETE FROM $tbl_tool WHERE (name='$name' and image='scormbuilder.gif')";
- }
- else
- {
- $sql ="UPDATE $tbl_tool set visibility=1 WHERE (name='$name' and image='scormbuilder.gif')";
- }
- }
- elseif(($set_visibility == 'v') && ($num==0))
- {
- $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)";
- }
- else
- {
- //parameter and database incompatible, do nothing
- }
- $result=api_sql_query($sql,__FILE__,__LINE__);
- //if($this->debug>2){error_log('New LP - Leaving learnpath::toggle_visibility: '.$sql,0);}
- }
- /**
- * Restart the whole learnpath. Return the URL of the first element.
- * Make sure the results are saved with anoter method. This method should probably be
- * redefined in children classes.
- * @return string URL to load in the viewer
- */
- function restart()
- {
- if($this->debug>0){error_log('New LP - In learnpath::restart()',0);}
- //TODO
- //call autosave method to save the current progress
- //$this->index = 0;
- $lp_view_table = Database::get_course_table('lp_view');
- $sql = "INSERT INTO $lp_view_table (lp_id, user_id, view_count) " .
- "VALUES (".$this->lp_id.",".$this->get_user_id().",".($this->attempt+1).")";
- if($this->debug>2){error_log('New LP - Inserting new lp_view for restart: '.$sql,0);}
- $res = api_sql_query($sql);
- if($view_id = Database::get_last_insert_id($res))
- {
- $this->lp_view_id = $view_id;
- $this->attempt = $this->attempt+1;
- }else{
- $this->error = 'Could not insert into item_view table...';
- return false;
- }
- $this->autocomplete_parents($this->current);
- foreach($this->items as $index=>$dummy){
- $this->items[$index]->restart();
- $this->items[$index]->set_lp_view($this->lp_view_id);
- }
- $this->first();
- return true;
- }
- /**
- * Saves the current item
- * @return boolean
- */
- function save_current(){
- if($this->debug>0){error_log('New LP - In learnpath::save_current()',0);}
- //TODO do a better check on the index pointing to the right item (it is supposed to be working
- // on $ordered_items[] but not sure it's always safe to use with $items[])
- if($this->debug>2){error_log('New LP - save_current() saving item '.$this->current,0);}
- if($this->debug>2){error_log(''.print_r($this->items,true),0);}
- if(is_object($this->items[$this->current])){
- $res = $this->items[$this->current]->save(false);
- $this->autocomplete_parents($this->current);
- $status = $this->items[$this->current]->get_status();
- $this->append_message('new_item_status: '.$status);
- $this->update_queue[$this->current] = $status;
- return $res;
- }
- return false;
- }
- /**
- * Saves the given item
- * @param integer Item ID. Optional (will take from $_REQUEST if null)
- * @param boolean Save from url params (true) or from current attributes (false). Optional. Defaults to true
- * @return boolean
- */
- function save_item($item_id=null,$from_outside=true){
- if($this->debug>0){error_log('New LP - In learnpath::save_item('.$item_id.','.$from_outside.')',0);}
- //TODO do a better check on the index pointing to the right item (it is supposed to be working
- // on $ordered_items[] but not sure it's always safe to use with $items[])
- if(empty($item_id)){
- $item_id = $this->escape_string($_REQUEST['id']);
- }
- if(empty($item_id))
- {
- $item_id = $this->get_current_item_id();
- }
- if($this->debug>2){error_log('New LP - save_current() saving item '.$item_id,0);}
- if(is_object($this->items[$item_id])){
- $res = $this->items[$item_id]->save($from_outside);
- $this->autocomplete_parents($item_id);
- $status = $this->items[$item_id]->get_status();
- $this->append_message('new_item_status: '.$status);
- $this->update_queue[$item_id] = $status;
- return $res;
- }
- return false;
- }
- /**
- * Saves the last item seen's ID only in case
- */
- function save_last(){
- if($this->debug>0){error_log('New LP - In learnpath::save_last()',0);}
- $table = Database::get_course_table('lp_view');
- if(isset($this->current)){
- if($this->debug>2){error_log('New LP - Saving current item ('.$this->current.') for later review',0);}
- $sql = "UPDATE $table SET last_item = ".$this->get_current_item_id()." " .
- "WHERE lp_id = ".$this->get_id()." AND user_id = ".$this->get_user_id();
- if($this->debug>2){error_log('New LP - Saving last item seen : '.$sql,0);}
- $res = api_sql_query($sql,__FILE__,__LINE__);
- }
- //save progress
- list($progress,$text) = $this->get_progress_bar_text('%');
- if($progress>=0 AND $progress<=100){
- $progress= (int)$progress;
- $sql = "UPDATE $table SET progress = $progress " .
- "WHERE lp_id = ".$this->get_id()." AND " .
- "user_id = ".$this->get_user_id();
- $res = @mysql_query($sql); //ignore errors as some tables might not have the progress field just yet
- $this->progress_db = $progress;
- }
- }
- /**
- * Sets the current item ID (checks if valid and authorized first)
- * @param integer New item ID. If not given or not authorized, defaults to current
- */
- function set_current_item($item_id=null)
- {
- if($this->debug>0){error_log('New LP - In learnpath::set_current_item('.$item_id.')',0);}
- if(empty($item_id)){
- if($this->debug>2){error_log('New LP - No new current item given, ignore...',0);}
- //do nothing
- }else{
- if($this->debug>2){error_log('New LP - New current item given is '.$item_id.'...',0);}
- $item_id = $this->escape_string($item_id);
- //TODO check in database here
- $this->last = $this->current;
- $this->current = $item_id;
- //TODO update $this->index as well
- foreach($this->ordered_items as $index => $item)
- {
- if($item == $this->current)
- {
- $this->index = $index;
- break;
- }
- }
- if($this->debug>2){error_log('New LP - set_current_item('.$item_id.') done. Index is now : '.$this->index,0);}
- }
- }
- /**
- * Sets the encoding
- * @param string New encoding
- */
- function set_encoding($enc='ISO-8859-1'){
- if($this->debug>0){error_log('New LP - In learnpath::set_encoding()',0);}
- $enc = strtoupper($enc);
- $encodings = array('UTF-8','ISO-8859-1','ISO-8859-15','SHIFT-JIS');
- if(in_array($enc,$encodings)){
- $lp = $this->get_id();
- if($lp!=0){
- $tbl_lp = Database::get_course_table('lp');
- $sql = "UPDATE $tbl_lp SET default_encoding = '$enc' WHERE id = ".$lp;
- $res = api_sql_query($sql);
- return $res;
- }
- }
- return false;
- }
- /**
- * Sets the JS lib setting in the database directly.
- * This is the JavaScript library file this lp needs to load on startup
- * @param string Proximity setting
- */
- function set_jslib($lib=''){
- if($this->debug>0){error_log('New LP - In learnpath::set_jslib()',0);}
- $lp = $this->get_id();
- if($lp!=0){
- $tbl_lp = Database::get_course_table('lp');
- $sql = "UPDATE $tbl_lp SET js_lib = '$lib' WHERE id = ".$lp;
- $res = api_sql_query($sql);
- return $res;
- }else{
- return false;
- }
- }
- /**
- * Sets the name of the LP maker (publisher) (and save)
- * @param string Optional string giving the new content_maker of this learnpath
- */
- function set_maker($name=''){
- if($this->debug>0){error_log('New LP - In learnpath::set_maker()',0);}
- if(empty($name))return false;
-
- $this->maker = $this->escape_string($name);
- $lp_table = Database::get_course_table('lp');
- $lp_id = $this->get_id();
- $sql = "UPDATE $lp_table SET content_maker = '".$this->maker."' WHERE id = '$lp_id'";
- if($this->debug>2){error_log('New LP - lp updated with new content_maker : '.$this->maker,0);}
- //$res = Database::query($sql);
- $res = api_sql_query($sql);
- return true;
- }
- /**
- * Sets the name of the current learnpath (and save)
- * @param string Optional string giving the new name of this learnpath
- */
- function set_name($name=''){
- if($this->debug>0){error_log('New LP - In learnpath::set_name()',0);}
- if(empty($name))return false;
-
- $this->name = $this->escape_string($name);
- $lp_table = Database::get_course_table('lp');
- $lp_id = $this->get_id();
- $sql = "UPDATE $lp_table SET name = '".$this->name."' WHERE id = '$lp_id'";
- if($this->debug>2){error_log('New LP - lp updated with new name : '.$this->name,0);}
- //$res = Database::query($sql);
- $res = api_sql_query($sql);
- return true;
- }
- /**
- * Sets the location/proximity of the LP (local/remote) (and save)
- * @param string Optional string giving the new location of this learnpath
- */
- function set_proximity($name=''){
- if($this->debug>0){error_log('New LP - In learnpath::set_proximity()',0);}
- if(empty($name))return false;
-
- $this->proximity = $this->escape_string($name);
- $lp_table = Database::get_course_table('lp');
- $lp_id = $this->get_id();
- $sql = "UPDATE $lp_table SET content_local = '".$this->proximity."' WHERE id = '$lp_id'";
- if($this->debug>2){error_log('New LP - lp updated with new proximity : '.$this->proximity,0);}
- //$res = Database::query($sql);
- $res = api_sql_query($sql);
- return true;
- }
- /**
- * Sets the previous item ID to a given ID. Generally, this should be set to the previous 'current' item
- * @param integer DB ID of the item
- */
- function set_previous_item($id)
- {
- if($this->debug>0){error_log('New LP - In learnpath::set_previous_item()',0);}
- $this->last = $id;
- }
- /**
- * Sets the object's error message
- * @param string Error message. If empty, reinits the error string
- * @return void
- */
- function set_error_msg($error='')
- {
- if($this->debug>0){error_log('New LP - In learnpath::set_error_msg()',0);}
- if(empty($error)){
- $this->error = '';
- }else{
- $this->error .= $error;
- }
- }
- /**
- * Launches the current item if not 'sco' (starts timer and make sure there is a record ready in the DB)
- *
- */
- function start_current_item(){
- if($this->debug>0){error_log('New LP - In learnpath::start_current_item()',0);}
- if($this->current != 0 AND
- is_object($this->items[$this->current]))
- {
- $type = $this->get_type();
- if(
- ($type == 2 && $this->items[$this->current]->get_type()!='sco')
- OR
- ($type == 3 && $this->items[$this->current]->get_type()!='au')
- OR
- ($type==1)
- )
- {
- $this->items[$this->current]->open();
- $this->items[$this->current]->save(false);
- $this->autocomplete_parents($this->current);
- $this->prerequisites_match(); //launch the prerequisites check and set error if needed
- //$this->update_queue[$this->last] = $this->items[$this->last]->get_status();
- }else{
- //if sco, then it is supposed to have been updated by some other call
- }
- }
- return true;
- }
- /**
- * Stops the processing and counters for the old item (as held in $this->last)
- * @param
- */
- function stop_previous_item(){
- if($this->debug>0){error_log('New LP - In learnpath::stop_previous_item()',0);}
- if($this->last != 0 AND is_object($this->items[$this->last]))
- {
- if($this->debug>2){error_log('New LP - In learnpath::stop_previous_item() - '.$this->last.' is object',0);}
- switch($this->get_type()){
- case '3':
- if($this->items[$this->last]->get_type()!='au')
- {
- if($this->debug>2){error_log('New LP - In learnpath::stop_previous_item() - '.$this->last.' in lp_type 3 is <> au',0);}
- $this->items[$this->last]->close();
- //$this->autocomplete_parents($this->last);
- //$this->update_queue[$this->last] = $this->items[$this->last]->get_status();
- }else{
- if($this->debug>2){error_log('New LP - In learnpath::stop_previous_item() - Item is an AU, saving is managed by AICC signals',0);}
- }
- case '2':
- if($this->items[$this->last]->get_type()!='sco')
- {
- if($this->debug>2){error_log('New LP - In learnpath::stop_previous_item() - '.$this->last.' in lp_type 2 is <> sco',0);}
- $this->items[$this->last]->close();
- //$this->autocomplete_parents($this->last);
- //$this->update_queue[$this->last] = $this->items[$this->last]->get_status();
- }else{
- if($this->debug>2){error_log('New LP - In learnpath::stop_previous_item() - Item is a SCO, saving is managed by SCO signals',0);}
- }
- break;
- case '1':
- default:
- if($this->debug>2){error_log('New LP - In learnpath::stop_previous_item() - '.$this->last.' in lp_type 1 is asset',0);}
- $this->items[$this->last]->close();
- break;
- }
- }else{
- if($this->debug>2){error_log('New LP - In learnpath::stop_previous_item() - No previous element found, ignoring...',0);}
- return false;
- }
- return true;
- }
- /**
- * Updates the default view mode from fullscreen to embedded and inversely
- * @return string The current default view mode ('fullscreen' or 'embedded')
- */
- function update_default_view_mode()
- {
- if($this->debug>0){error_log('New LP - In learnpath::update_default_view_mode()',0);}
- $lp_table = Database::get_course_table('lp');
- $sql = "SELECT * FROM $lp_table WHERE id = ".$this->get_id();
- $res = api_sql_query($sql);
- if(Database::num_rows($res)>0){
- $row = Database::fetch_array($res);
- $view_mode = $row['default_view_mod'];
- if($view_mode == 'fullscreen'){
- $view_mode = 'embedded';
- }elseif($view_mode == 'embedded'){
- $view_mode = 'fullscreen';
- }
- $sql = "UPDATE $lp_table SET default_view_mod = '$view_mode' WHERE id = ".$this->get_id();
- $res = api_sql_query($sql);
- $this->mode = $view_mode;
- return $view_mode;
- }else{
- if($this->debug>2){error_log('New LP - Problem in update_default_view() - could not find LP '.$this->get_id().' in DB',0);}
- }
- return -1;
- }
- /**
- * Updates the default behaviour about auto-commiting SCORM updates
- * @return boolean True if auto-commit has been set to 'on', false otherwise
- */
- function update_default_scorm_commit(){
- if($this->debug>0){error_log('New LP - In learnpath::update_default_scorm_commit()',0);}
- $lp_table = Database::get_course_table('lp');
- $sql = "SELECT * FROM $lp_table WHERE id = ".$this->get_id();
- $res = api_sql_query($sql);
- if(Database::num_rows($res)>0){
- $row = Database::fetch_array($res);
- $force = $row['force_commit'];
- if($force == 1){
- $force = 0;
- $force_return = false;
- }elseif($force == 0){
- $force = 1;
- $force_return = true;
- }
- $sql = "UPDATE $lp_table SET force_commit = $force WHERE id = ".$this->get_id();
- $res = api_sql_query($sql);
- $this->force_commit = $force_return;
- return $force_return;
- }else{
- if($this->debug>2){error_log('New LP - Problem in update_default_scorm_commit() - could not find LP '.$this->get_id().' in DB',0);}
- }
- return -1;
- }
- /**
- * Updates the "prevent_reinit" value that enables control on reinitialising items on second view
- * @return boolean True if prevent_reinit has been set to 'on', false otherwise (or 1 or 0 in this case)
- */
- function update_reinit(){
- if($this->debug>0){error_log('New LP - In learnpath::update_reinit()',0);}
- $lp_table = Database::get_course_table('lp');
- $sql = "SELECT * FROM $lp_table WHERE id = ".$this->get_id();
- $res = api_sql_query($sql);
- if(Database::num_rows($res)>0){
- $row = Database::fetch_array($res);
- $force = $row['prevent_reinit'];
- if($force == 1){
- $force = 0;
- }elseif($force == 0){
- $force = 1;
- }
- $sql = "UPDATE $lp_table SET prevent_reinit = $force WHERE id = ".$this->get_id();
- $res = api_sql_query($sql,__FILE__,__LINE__);
- $this->prevent_reinit = $force;
- return $force;
- }else{
- if($this->debug>2){error_log('New LP - Problem in update_reinit() - could not find LP '.$this->get_id().' in DB',0);}
- }
- return -1;
- }
- /**
- * Updates the "scorm_debug" value that shows or hide the debug window
- * @return boolean True if scorm_debug has been set to 'on', false otherwise (or 1 or 0 in this case)
- */
- function update_scorm_debug(){
- if($this->debug>0){error_log('New LP - In learnpath::update_scorm_debug()',0);}
- $lp_table = Database::get_course_table('lp');
- $sql = "SELECT * FROM $lp_table WHERE id = ".$this->get_id();
- $res = api_sql_query($sql);
- if(Database::num_rows($res)>0){
- $row = Database::fetch_array($res);
- $force = $row['debug'];
- if($force == 1){
- $force = 0;
- }elseif($force == 0){
- $force = 1;
- }
- $sql = "UPDATE $lp_table SET debug = $force WHERE id = ".$this->get_id();
- $res = api_sql_query($sql,__FILE__,__LINE__);
- $this->scorm_debug = $force;
- return $force;
- }else{
- if($this->debug>2){error_log('New LP - Problem in update_scorm_debug() - could not find LP '.$this->get_id().' in DB',0);}
- }
- return -1;
- }
-
- /**
- * Function that makes a call to the function sort_tree_array and create_tree_array
- *
- * @author Kevin Van Den Haute
- *
- * @param unknown_type $array
- */
- function tree_array($array)
- {
- $array = $this->sort_tree_array($array);
- $this->create_tree_array($array);
- }
- /**
- * Creates an array with the elements of the learning path tree in it
- *
- * @author Kevin Van Den Haute
- *
- * @param array $array
- * @param int $parent
- * @param int $depth
- * @param array $tmp
- */
- function create_tree_array($array, $parent = 0, $depth = -1, $tmp = array())
- {
- if(is_array($array))
- {
- for($i = 0; $i < count($array); $i++)
- {
- if($array[$i]['parent_item_id'] == $parent)
- {
- if(!in_array($array[$i]['parent_item_id'], $tmp))
- {
- $tmp[] = $array[$i]['parent_item_id'];
- $depth++;
- }
-
- $this->arrMenu[] = array(
- 'id' => $array[$i]['id'],
- 'item_type' => $array[$i]['item_type'],
- 'title' => $array[$i]['title'],
- 'path' => $array[$i]['path'],
- 'description' => $array[$i]['description'],
- 'parent_item_id' => $array[$i]['parent_item_id'],
- 'previous_item_id' => $array[$i]['previous_item_id'],
- 'next_item_id' => $array[$i]['next_item_id'],
- 'display_order' => $array[$i]['display_order'],
- 'depth' => $depth
- );
-
- $this->create_tree_array($array, $array[$i]['id'], $depth, $tmp);
- }
- }
- }
- }
-
- /**
- * Sorts a multi dimensional array by parent id and display order
- * @author Kevin Van Den Haute
- *
- * @param array $array (array with al the learning path items in it)
- *
- * @return array
- */
- function sort_tree_array($array)
- {
- foreach($array as $key => $row)
- {
- $parent[$key] = $row['parent_item_id'];
- $position[$key] = $row['display_order'];
- }
-
- if(count($array) > 0)
- array_multisort($parent, SORT_ASC, $position, SORT_ASC, $array);
-
- return $array;
- }
-
-
-
- /**
- * Function that creates a table structure with a learning path his modules, chapters and documents.
- * Also the actions for the modules, chapters and documents are in this table.
- *
- * @author Kevin Van Den Haute
- *
- * @param int $lp_id
- *
- * @return string
- */
- function overview()
- {
- $return = '';
-
- $tbl_lp_item = Database::get_course_table('lp_item');
-
- $sql = "
- SELECT *
- FROM " . $tbl_lp_item . "
- WHERE
- lp_id = " . $this->lp_id;
-
- $result = api_sql_query($sql, __FILE__, __LINE__);
-
- $arrLP = array();
-
- while($row = Database::fetch_array($result))
- {
- $arrLP[] = array(
- 'id' => $row['id'],
- 'item_type' => $row['item_type'],
- 'title' => $row['title'],
- 'description' => $row['description'],
- 'parent_item_id' => $row['parent_item_id'],
- 'previous_item_id' => $row['previous_item_id'],
- 'next_item_id' => $row['next_item_id'],
- 'display_order' => $row['display_order']);
- }
-
- $this->tree_array($arrLP);
-
- $arrLP = $this->arrMenu;
-
- unset($this->arrMenu);
-
- if(api_is_allowed_to_edit())
- $return .= '<p><a href="' . $_SERVER['PHP_SELF'] . '?cidReq=' . $_GET['cidReq'] . '&action=build&lp_id=' . $this->lp_id . '">Advanced</a></p>';
-
- $return .= '<table cellpadding="0" cellspacing="2" class="lp_overview">' . "\n";
-
- $return .= "\t" . '<tr class="header">' . "\n";
-
- $return .= "\t" . '<th>Title</th>' . "\n";
- $return .= "\t" . '<th>Description</th>' . "\n";
- $return .= "\t" . '<th>Move</th>' . "\n";
- $return .= "\t" . '<th>Actions</th>' . "\n";
-
- $return .= "\t" . '</tr>' . "\n";
-
- for($i = 0; $i < count($arrLP); $i++)
- {
- if($arrLP[$i]['description'] == '')
- $arrLP[$i]['description'] = ' ';
-
- $return .= "\t" . '<tr>' . "\n";
-
- $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";
- $return .= "\t\t" . '<td>' . stripslashes($arrLP[$i]['description']) . '</td>' . "\n";
-
- if(api_is_allowed_to_edit())
- {
- $return .= "\t\t" . '<td class="move">' . "\n";
-
- if($arrLP[$i]['previous_item_id'] != 0)
- {
- $return .= "\t\t\t" . '<a href="' . $_SERVER['PHP_SELF'] . '?cidReq=' . $_GET['cidReq'] . '&action=move_item&direction=up&id=' . $arrLP[$i]['id'] . '&lp_id=' . $this->lp_id . '">';
- $return .= '<img alt="" src="img/arrow_up_' . ($arrLP[$i]['depth'] % 3) . '.png" />';
- $return .= '</a>' . "\n";
- }
- else
- $return .= "\t\t\t" . '<img alt="" src="img/blanco.png" title="" />' . "\n";
-
- if($arrLP[$i]['next_item_id'] != 0)
- {
- $return .= "\t\t\t" . '<a href="' . $_SERVER['PHP_SELF'] . '?cidReq=' . $_GET['cidReq'] . '&action=move_item&direction=down&id=' . $arrLP[$i]['id'] . '&lp_id=' . $this->lp_id . '">';
- $return .= '<img src="img/arrow_down_' . ($arrLP[$i]['depth'] % 3) . '.png" />';
- $return .= '</a>' . "\n";
- }
- else
- $return .= "\t\t\t" . '<img alt="" src="img/blanco.png" title="" />' . "\n";
-
- $return .= "\t\t" . '</td>' . "\n";
-
- $return .= "\t\t" . '<td class="actions">' . "\n";
-
- if($arrLP[$i]['item_type'] != 'dokeos_chapter' && $arrLP[$i]['item_type'] != 'dokeos_module')
- {
- $return .= "\t\t\t" . '<a href="' . $_SERVER['PHP_SELF'] . '?cidReq=' . $_GET['cidReq'] . '&action=edit_item&view=build&id=' . $arrLP[$i]['id'] . '&lp_id=' . $this->lp_id . '">';
- $return .= '<img alt="" src="../img/edit.gif" title="' . get_lang('_edit_learnpath_module') . '" />';
- $return .= '</a>' . "\n";
- }
- else
- {
- $return .= "\t\t\t" . '<a href="' . $_SERVER['PHP_SELF'] . '?cidReq=' . $_GET['cidReq'] . '&action=edit_item&id=' . $arrLP[$i]['id'] . '&lp_id=' . $this->lp_id . '">';
- $return .= '<img alt="" src="../img/edit.gif" title="' . get_lang('_edit_learnpath_module') . '" />';
- $return .= '</a>' . "\n";
- }
-
- $return .= "\t\t\t" . '<a href="' . $_SERVER['PHP_SELF'] . '?cidReq=' . $_GET['cidReq'] . '&action=delete_item&id=' . $arrLP[$i]['id'] . '&lp_id=' . $this->lp_id . '" onclick="return confirmation(\'' . $arrLP[$i]['title'] . '\');">';
- $return .= '<img alt="" src="../img/delete.gif" title="' . get_lang('_delete_learnpath_module') . '" />';
- $return .= '</a>' . "\n";
-
- $return .= "\t\t" . '</td>' . "\n";
- }
-
- $return .= "\t" . '</tr>' . "\n";
- }
-
- if(count($arrLP) == 0)
- {
- $return .= "\t" . '<tr>' . "\n";
- $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";
- $return .= "\t" . '</tr>' . "\n";
- }
-
- $return .= '</table>' . "\n";
-
- return $return;
- }
-
- /**
- * This functions builds the LP tree based on data from the database.
- *
- * @return string
- * @uses dtree.js :: necessary javascript for building this tree
- */
- function build_tree()
- {
- $return = "<script type=\"text/javascript\">\n";
-
- $return .= "\tm = new dTree('m');\n\n";
-
- $return .= "\tm.config.folderLinks = true;\n";
- $return .= "\tm.config.useCookies = true;\n";
- $return .= "\tm.config.useIcons = true;\n";
- $return .= "\tm.config.useLines = true;\n";
- $return .= "\tm.config.useSelection = true;\n";
- $return .= "\tm.config.useStatustext = false;\n\n";
-
- $menu = 0;
- $parent = '';
-
- $return .= "\tm.add(" . $menu . ", -1, '" . addslashes($this->name) . "');\n";
-
- $tbl_lp_item = Database::get_course_table('lp_item');
-
- $sql = "
- SELECT *
- FROM " . $tbl_lp_item . "
- WHERE
- lp_id = " . $this->lp_id;
-
- $result = api_sql_query($sql, __FILE__, __LINE__);
-
- $arrLP = array();
-
- while($row = Database::fetch_array($result))
- {
- $arrLP[] = array(
- 'id' => $row['id'],
- 'item_type' => $row['item_type'],
- 'title' => $row['title'],
- 'path' => $row['path'],
- 'description' => $row['description'],
- 'parent_item_id' => $row['parent_item_id'],
- 'previous_item_id' => $row['previous_item_id'],
- 'next_item_id' => $row['next_item_id'],
- 'display_order' => $row['display_order']);
- }
-
- $this->tree_array($arrLP);
-
- $arrLP = $this->arrMenu;
-
- unset($this->arrMenu);
-
- for($i = 0; $i < count($arrLP); $i++)
- {
- $menu_page = $_SERVER['PHP_SELF'] . '?cidReq=' . $_GET['cidReq'] . '&action=view_item&id=' . $arrLP[$i]['id'] . '&lp_id=' . $_SESSION['oLP']->lp_id;
-
- $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";
-
- if($menu < $arrLP[$i]['id'])
- $menu = $arrLP[$i]['id'];
- }
-
- $return .= "\n\tdocument.write(m);\n";
-
- $return .= "</script>\n";
-
- return $return;
- }
-
- /**
- * Create a new document //still needs some finetuning
- *
- * @param array $_course
- * @return string
- */
- function create_document($_course)
- {
- $dir = isset($_GET['dir']) ? $_GET['dir'] : $_POST['dir']; // please do not modify this dirname formatting
-
- if(strstr($dir, '..'))
- $dir = '/';
-
- if($dir[0] == '.')
- $dir = substr($dir, 1);
-
- if($dir[0] != '/')
- $dir = '/'.$dir;
-
- if($dir[strlen($dir) - 1] != '/')
- $dir .= '/';
-
- $filepath = api_get_path('SYS_COURSE_PATH') . $_course['path'] . '/document' . $dir;
-
- if(!is_dir($filepath))
- {
- $filepath = api_get_path('SYS_COURSE_PATH') . $_course['path'] . '/document/';
-
- $dir = '/';
- }
-
- $title = replace_dangerous_char($_POST['title']);
- $filename = $title;
- $content = $_POST['content'];
-
- $tmp_filename = $filename;
-
- while(file_exists($filepath . $tmp_filename . '.html'))
- $tmp_filename = $filename . '_' . ++$i;
-
- $filename = $tmp_filename . '.html';
-
- $content = stripslashes(text_filter($content));
-
- $path_to_remove = api_get_path('WEB_COURSE_PATH') . $_course['path'] . '/document' . $dir;
- $content = str_replace($path_to_remove, './', $content);
-
- if(!file_exists($filepath . $filename))
- {
- if($fp = @fopen($filepath . $filename, 'w'))
- {
- fputs($fp, $content);
- fclose($fp);
-
- $file_size = filesize($filepath . $filename);
- $save_file_path = $dir . $filename;
-
- $document_id = add_document($_course, $save_file_path, 'file', $file_size, $filename . '.html');
-
- if($document_id)
- {
- api_item_property_update($_course, TOOL_DOCUMENT, $document_id, 'DocumentAdded', $_uid, $to_group_id);
-
- //update parent folders
- //item_property_update_on_folder($_course, $_GET['dir'], $_uid);
-
- $new_comment = (isset($_POST['comment'])) ? trim($_POST['comment']) : '';
- $new_title = (isset($_POST['title'])) ? trim($_POST['title']) : '';
-
- if($new_comment || $new_title)
- {
- $tbl_doc = Database::get_course_table(DOCUMENT_TABLE);
- $ct = '';
-
- if($new_comment)
- $ct .= ", comment='" . $new_comment . "'";
-
- if($new_title)
- $ct .= ", title='" . $new_title . ".html '";
-
- $sql_update = "
- UPDATE " . $tbl_doc . "
- SET " . substr($ct, 1) . "
- WHERE id = " . $document_id;
- api_sql_query($sql_update, __FILE__, __LINE__);
- }
- }
-
- return $document_id;
- }
- }
- }
-
- /**
- * Enter description here...
- *
- * @param array $_course
- */
- function edit_document($_course)
- {
- $dir = isset($_GET['dir']) ? $_GET['dir'] : $_POST['dir']; // please do not modify this dirname formatting
-
- if(strstr($dir, '..'))
- $dir = '/';
-
- if($dir[0] == '.')
- $dir = substr($dir, 1);
-
- if($dir[0] != '/')
- $dir = '/'.$dir;
-
- if($dir[strlen($dir) - 1] != '/')
- $dir .= '/';
-
- $filepath = api_get_path('SYS_COURSE_PATH') . $_course['path'] . '/document'.$dir;
-
- if(!is_dir($filepath))
- {
- $filepath = api_get_path('SYS_COURSE_PATH') . $_course['path'] . '/document/';
-
- $dir = '/';
- }
-
- $table_doc = Database::get_course_table(DOCUMENT_TABLE);
-
- $sql = "
- SELECT path
- FROM " . $table_doc . "
- WHERE id = " . $_POST['path'];
- $res = api_sql_query($sql, __FILE__, __LINE__);
- $row = Database::fetch_array($res);
-
- $content = stripslashes($_POST['content']);
- $file = $filepath . $row['path'];
-
-
- if($fp = @fopen($file, 'w'))
- {
- $content = text_filter($content);
- $path_to_remove = api_get_path('WEB_COURSE_PATH') . $_course['path'] . '/document' . $dir;
- $content = str_replace($path_to_remove, './', $content);
-
- fputs($fp, $content);
- fclose($fp);
- }
- }
-
- /**
- * Displays the selected item, with a panel for manipulating the item
- *
- * @param int $item_id
- * @param string $msg
- * @return string
- */
- function display_item($item_id, $iframe = true, $msg = '')
- {
- global $_course; //will disappear
-
- $return = '';
-
- if(is_numeric($item_id))
- {
- $tbl_lp_item = Database::get_course_table('lp_item');
- $tbl_doc = Database::get_course_table(DOCUMENT_TABLE);
-
- $sql = "
- SELECT
- lp.*
- FROM " . $tbl_lp_item . " as lp
- WHERE
- lp.id = " . $item_id;
-
- $result = api_sql_query($sql, __FILE__, __LINE__);
-
- while($row = Database::fetch_array($result))
- {
- $return .= $this->display_manipulate($item_id, $row['item_type']);
-
- $return .= '<div style="padding:10px;">';
-
- if($msg != '')
- $return .= $msg;
-
- $return .= '<p class="lp_title">' . stripslashes($row['title']) . '</p>';
- $return .= '<p class="lp_text">' . ((trim($row['description']) == '') ? 'no description' : stripslashes($row['description'])) . '</p>';
-
- $return .= '<hr />';
-
- if($row['item_type'] == TOOL_DOCUMENT)
- $return .= $this->display_document($row['path'], true, true);
-
- $return .= '</div>';
- }
- }
-
- return $return;
- }
-
- /**
- * Shows the needed forms for editing a specific item
- *
- * @param int $item_id
- * @return string
- */
- function display_edit_item($item_id)
- {
- global $_course; //will disappear
-
- $return = '';
-
- if(is_numeric($item_id))
- {
- $tbl_lp_item = Database::get_course_table('lp_item');
-
- $sql = "
- SELECT *
- FROM " . $tbl_lp_item . "
- WHERE id = " . $item_id;
-
- $res = api_sql_query($sql, __FILE__, __LINE__);
- $row = Database::fetch_array($res);
-
- switch($row['item_type'])
- {
- case 'dokeos_chapter':
-
- if(isset($_GET['view']) && $_GET['view'] == 'build')
- {
- $return .= $this->display_manipulate($item_id, $row['item_type']);
- $return .= $this->display_item_form($row['item_type'], 'Edit the current chapter:', 'edit', $item_id, $row);
- }
- else
- {
- $return .= $this->display_item_small_form($row['item_type'], 'Edit the current chapter:', $row);
- }
-
- break;
-
- case TOOL_DOCUMENT:
-
- $tbl_doc = Database::get_course_table(DOCUMENT_TABLE);
-
- $sql_step = "
- SELECT
- lp.*,
- doc.path as dir
- FROM " . $tbl_lp_item . " as lp
- LEFT JOIN " . $tbl_doc . " as doc ON doc.id = lp.path
- WHERE
- lp.id = " . $item_id;
- $res_step = api_sql_query($sql_step, __FILE__, __LINE__);
- $row_step = Database::fetch_array($res_step);
-
- $return .= $this->display_manipulate($item_id, $row['item_type']);
- $return .= $this->display_document_form('edit', $item_id, $row_step);
-
- break;
-
- case TOOL_LINK:
-
- $return .= $this->display_manipulate($item_id, $row['item_type']);
- $return .= $this->display_link_form('edit', $item_id, $row);
-
- break;
-
- case 'dokeos_module':
-
- if(isset($_GET['view']) && $_GET['view'] == 'build')
- {
- $return .= $this->display_manipulate($item_id, $row['item_type']);
- $return .= $this->display_item_form($row['item_type'], 'Edit the current module:', 'edit', $item_id, $row);
- }
- else
- {
- $return .= $this->display_item_small_form($row['item_type'], 'Edit the current module:', $row);
- }
-
- break;
-
- case TOOL_QUIZ:
-
- $return .= $this->display_manipulate($item_id, $row['item_type']);
- $return .= $this->display_quiz_form('edit', $item_id, $row);
-
- break;
-
- case TOOL_STUDENTPUBLICATION:
-
- $return .= $this->display_manipulate($item_id, $row['item_type']);
- $return .= $this->display_student_publication_form('edit', $item_id, $row);
-
- break;
- }
- }
-
- return $return;
- }
-
- /**
- * Function that displays a list with al the resources that could be added to the learning path
- *
- * @return string
- */
- function display_resources()
- {
- global $_course; //TODO: don't use globals
-
- $return = '<div style="margin:3px 10px;">' . "\n";
-
- $return .= '<p class="lp_title" style="margin-top:0;">Create a new step:</p>';
-
- $return .= '<div><a href="' . $_SERVER['PHP_SELF'] . '?cidReq=' . $_GET['cidReq'] . '&action=add_item&type=' . TOOL_DOCUMENT . '&lp_id=' . $_SESSION['oLP']->lp_id . '">New document</a></div>';
-
- $return .= '<p class="lp_title" style="margin-top:10px;">Or use an existing resource:</p>';
-
- /* get al the docs */
- $return .= $this->get_documents();
-
- /* get al the exercises */
- $return .= $this->get_exercises();
-
- /* get al links */
- $return .= $this->get_links();
-
- /* get al the student publications */
- $return .= $this->get_student_publications();
-
- $return .= '</div>' . "\n";
-
- return $return;
- }
-
- /**
- * Returns the extension of a document
- *
- * @param unknown_type $filename
- * @return unknown
- */
- function get_extension($filename)
- {
- $explode = explode('.', $filename);
-
- return $explode[count($explode) - 1];
- }
-
- /**
- * Displays a document by id
- *
- * @param unknown_type $id
- * @return unknown
- */
- function display_document($id, $show_title = false, $iframe = true, $edit_link = false)
- {
- global $_course; //temporary
-
- $return = '';
-
- $tbl_doc = Database::get_course_table(DOCUMENT_TABLE);
-
- $sql_doc = "
- SELECT *
- FROM " . $tbl_doc . "
- WHERE id = " . $id;
- $res_doc = api_sql_query($sql_doc, __FILE__, __LINE__);
- $row_doc = Database::fetch_array($res_doc);
-
- if($show_title)
- $return .= '<p class="lp_title">' . $row_doc['title'] . ($edit_link ? ' [ <a href="' . $_SERVER['PHP_SELF'] . '?cidReq=' . $_GET['cidReq'] . '&action=add_item&type=' . TOOL_DOCUMENT . '&file=' . $_GET['file'] . '&edit=true&lp_id=' . $_GET['lp_id'] . '">Edit this document</a> ]' : '') . '</p>';
-
- //TODO: add a path filter
- if($iframe)
- $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>';
- else
- $return .= file_get_contents(api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document' . $row_doc['path']);
-
- return $return;
- }
-
- /**
- * Enter description here...
- *
- * @param unknown_type $action
- * @param unknown_type $id
- * @param unknown_type $extra_info
- * @return unknown
- */
- function display_quiz_form($action = 'add', $id = 0, $extra_info = '')
- {
- $tbl_lp_item = Database::get_course_table('lp_item');
- $tbl_quiz = Database::get_course_table(QUIZ_TEST_TABLE);
-
- if($id != 0 && is_array($extra_info))
- {
- $item_title = stripslashes($extra_info['title']);
- $item_description = stripslashes($extra_info['description']);
- }
- elseif(is_numeric($extra_info))
- {
- $sql_quiz = "
- SELECT
- title,
- description
- FROM " . $tbl_quiz . "
- WHERE id = " . $extra_info;
-
- $result = api_sql_query($sql_quiz, __FILE__, __LINE__);
- $row = Database::fetch_array($result);
-
- $item_title = $row['title'];
- $item_description = $row['description'];
- }
- else
- {
- $item_title = '';
- $item_description = '';
- }
-
- $return = '<div style="margin:3px 10px;">';
-
- if($id != 0 && is_array($extra_info))
- $parent = $extra_info['parent_item_id'];
- else
- $parent = 0;
-
- $sql = "
- SELECT *
- FROM " . $tbl_lp_item . "
- WHERE
- lp_id = " . $this->lp_id;
-
- $result = api_sql_query($sql, __FILE__, __LINE__);
-
- $arrLP = array();
-
- while($row = Database::fetch_array($result))
- {
- $arrLP[] = array(
- 'id' => $row['id'],
- 'item_type' => $row['item_type'],
- 'title' => $row['title'],
- 'path' => $row['path'],
- 'description' => $row['description'],
- 'parent_item_id' => $row['parent_item_id'],
- 'previous_item_id' => $row['previous_item_id'],
- 'next_item_id' => $row['next_item_id'],
- 'display_order' => $row['display_order']);
- }
-
- $this->tree_array($arrLP);
-
- $arrLP = $this->arrMenu;
-
- unset($this->arrMenu);
-
- if($action == 'add')
- $return .= '<p class="lp_title">Create the exercise:</p>' . "\n";
- elseif($action == 'move')
- $return .= '<p class="lp_title">Move the current exercise:</p>' . "\n";
- else
- $return .= '<p class="lp_title">Edit the current exercise:</p>' . "\n";
-
- if(isset($_GET['edit']) && $_GET['edit'] == 'true')
- {
- $return .= '<div class="lp_message" style="margin-bottom:15px;">';
-
- $return .= '<p class="lp_title">Warning !</p>';
- $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.';
-
- $return .= '</div>';
- }
-
- $return .= '<form method="POST">' . "\n";
-
- $return .= "\t" . '<table cellpadding="0" cellspacing="0" class="lp_form">' . "\n";
-
- $return .= "\t\t" . '<tr>' . "\n";
-
- $return .= "\t\t\t" . '<td class="label"><label for="idParent">Parent:</label></td>' . "\n";
- $return .= "\t\t\t" . '<td class="input">' . "\n";
-
- $return .= "\t\t\t\t" . '<select id="idParent" name="parent" onchange="load_cbo(this.value);" size="1">';
-
- $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
-
- $arrHide = array($id);
-
- for($i = 0; $i < count($arrLP); $i++)
- {
- if($action != 'add')
- {
- if(($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter') && !in_array($arrLP[$i]['id'], $arrHide) && !in_array($arrLP[$i]['parent_item_id'], $arrHide))
- {
- $return .= "\t\t\t\t\t" . '<option ' . (($parent == $arrLP[$i]['id']) ? 'selected="selected" ' : '') . 'style="padding-left:' . ($arrLP[$i]['depth'] * 10) . 'px;" value="' . $arrLP[$i]['id'] . '">' . html_entity_decode(stripslashes($arrLP[$i]['title'])) . '</option>';
- }
- else
- {
- $arrHide[] = $arrLP[$i]['id'];
- }
- }
- else
- {
- if($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter')
- $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>';
- }
- }
-
- reset($arrLP);
-
- $return .= "\t\t\t\t" . '</select>';
-
- $return .= "\t\t\t" . '</td>' . "\n";
-
- $return .= "\t\t" . '</tr>' . "\n";
-
- $return .= "\t\t" . '<tr>' . "\n";
-
- $return .= "\t\t\t" . '<td class="label"><label for="idPosition">Position:</label></td>' . "\n";
- $return .= "\t\t\t" . '<td class="input">' . "\n";
-
- $return .= "\t\t\t\t" . '<select id="idPosition" name="previous" size="1">';
-
- $return .= "\t\t\t\t\t" . '<option class="top" value="0">First position</option>';
-
- for($i = 0; $i < count($arrLP); $i++)
- {
- if($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id)
- {
- if($extra_info['previous_item_id'] == $arrLP[$i]['id'])
- $selected = 'selected="selected" ';
- elseif($action == 'add')
- $selected = 'selected="selected" ';
- else
- $selected = '';
-
- $return .= "\t\t\t\t\t" . '<option ' . $selected . 'value="' . $arrLP[$i]['id'] . '">After "' . html_entity_decode(stripslashes($arrLP[$i]['title'])) . '"</option>';
- }
- }
-
- $return .= "\t\t\t\t" . '</select>';
-
- $return .= "\t\t\t" . '</td>' . "\n";
-
- $return .= "\t\t" . '</tr>' . "\n";
-
- if($action != 'move')
- {
- $return .= "\t\t" . '<tr>' . "\n";
-
- $return .= "\t\t\t" . '<td class="label"><label for="idTitle">Title:</label></td>' . "\n";
- $return .= "\t\t\t" . '<td class="input"><input id="idTitle" name="title" type="text" value="' . $item_title . '" /></td>' . "\n";
-
- $return .= "\t\t" . '</tr>' . "\n";
-
- $return .= "\t\t" . '<tr>' . "\n";
-
- $return .= "\t\t\t" . '<td class="label"><label for="idDescription">Description:</label></td>' . "\n";
- $return .= "\t\t\t" . '<td class="input"><textarea id="idDescription" name="description" rows="4">' . $item_description . '</textarea></td>' . "\n";
-
- $return .= "\t\t" . '</tr>' . "\n";
- }
-
- $return .= "\t\t" . '<tr>' . "\n";
-
- $return .= "\t\t\t" . '<td colspan="2"><input class="button" name="submit_button" type="submit" value="OK" /></td>' . "\n";
-
- $return .= "\t\t" . '</tr>' . "\n";
-
- $return .= "\t" . '</table>' . "\n";
-
- if($action == 'move')
- {
- $return .= "\t" . '<input name="title" type="hidden" value="' . $item_title . '" />' . "\n";
- $return .= "\t" . '<input name="description" type="hidden" value="' . $item_description . '" />' . "\n";
- }
-
- if(is_numeric($extra_info))
- {
- $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info . '" />' . "\n";
- }
- elseif(is_array($extra_info))
- {
- $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />' . "\n";
- }
-
- $return .= "\t" . '<input name="type" type="hidden" value="'.TOOL_QUIZ.'" />' . "\n";
- $return .= "\t" . '<input name="post_time" type="hidden" value="' . time() . '" />' . "\n";
-
- $return .= '</form>' . "\n";
-
- $return .= '</div>' . "\n";
-
- return $return;
- }
-
- /**
- * Enter description here...
- *
- * @param unknown_type $item_type
- * @param unknown_type $title
- * @param unknown_type $action
- * @param unknown_type $id
- * @param unknown_type $extra_info
- * @return unknown
- */
- function display_item_form($item_type, $title = '', $action = 'add', $id = 0, $extra_info = 'new')
- {
- $tbl_lp_item = Database::get_course_table('lp_item');
-
- if($id != 0 && is_array($extra_info))
- {
- $item_title = stripslashes($extra_info['title']);
- $item_description = stripslashes($extra_info['description']);
- }
- else
- {
- $item_title = '';
- $item_description = '';
- }
-
- $return = '<div style="margin:3px 10px;">';
-
- if($id != 0 && is_array($extra_info))
- $parent = $extra_info['parent_item_id'];
- else
- $parent = 0;
-
- $sql = "
- SELECT *
- FROM " . $tbl_lp_item . "
- WHERE
- lp_id = " . $this->lp_id;
-
- if($item_type == 'module')
- $sql .= " AND parent_item_id = 0";
-
- $result = api_sql_query($sql, __FILE__, __LINE__);
-
- $arrLP = array();
-
- while($row = Database::fetch_array($result))
- {
- $arrLP[] = array(
- 'id' => $row['id'],
- 'item_type' => $row['item_type'],
- 'title' => $row['title'],
- 'path' => $row['path'],
- 'description' => $row['description'],
- 'parent_item_id' => $row['parent_item_id'],
- 'previous_item_id' => $row['previous_item_id'],
- 'next_item_id' => $row['next_item_id'],
- 'display_order' => $row['display_order']);
- }
-
- $this->tree_array($arrLP);
-
- $arrLP = $this->arrMenu;
-
- unset($this->arrMenu);
-
- $return .= '<p class="lp_title">' . $title . '</p>' . "\n";
-
- $return .= '<form method="POST">' . "\n";
-
- $return .= "\t" . '<table cellpadding="0" cellspacing="0" class="lp_form">' . "\n";
-
- if($item_type != 'module' && $item_type != 'dokeos_module')
- {
- $return .= "\t\t" . '<tr>' . "\n";
-
- $return .= "\t\t\t" . '<td class="label"><label for="idParent">Parent:</label></td>' . "\n";
- $return .= "\t\t\t" . '<td class="input">' . "\n";
-
- $return .= "\t\t\t\t" . '<select id="idParent" name="parent" onchange="load_cbo(this.value);" size="1">';
-
- $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
-
- $arrHide = array($id);
-
- for($i = 0; $i < count($arrLP); $i++)
- {
- if($action != 'add')
- {
- if($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] != 'dokeos_chapter' && !in_array($arrLP[$i]['id'], $arrHide) && !in_array($arrLP[$i]['parent_item_id'], $arrHide))
- {
- $return .= "\t\t\t\t\t" . '<option ' . (($parent == $arrLP[$i]['id']) ? 'selected="selected" ' : '') . 'style="padding-left:' . ($arrLP[$i]['depth'] * 10) . 'px;" value="' . $arrLP[$i]['id'] . '">' . html_entity_decode(stripslashes($arrLP[$i]['title'])) . '</option>';
- }
- else
- {
- $arrHide[] = $arrLP[$i]['id'];
- }
- }
- else
- {
- if($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter')
- $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>';
- }
- }
-
- reset($arrLP);
-
- $return .= "\t\t\t\t" . '</select>';
-
- $return .= "\t\t\t" . '</td>' . "\n";
-
- $return .= "\t\t" . '</tr>' . "\n";
- }
-
- $return .= "\t\t" . '<tr>' . "\n";
-
- $return .= "\t\t\t" . '<td class="label"><label for="idPosition">Position:</label></td>' . "\n";
- $return .= "\t\t\t" . '<td class="input">' . "\n";
-
- $return .= "\t\t\t\t" . '<select id="idPosition" name="previous" size="1">';
-
- $return .= "\t\t\t\t\t" . '<option class="top" value="0">First position</option>';
-
- for($i = 0; $i < count($arrLP); $i++)
- {
- if($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id)
- {
- if($extra_info['previous_item_id'] == $arrLP[$i]['id'])
- $selected = 'selected="selected" ';
- elseif($action == 'add')
- $selected = 'selected="selected" ';
- else
- $selected = '';
-
- $return .= "\t\t\t\t\t" . '<option ' . $selected . 'value="' . $arrLP[$i]['id'] . '">After "' . html_entity_decode(stripslashes($arrLP[$i]['title'])) . '"</option>';
- }
- }
-
- $return .= "\t\t\t\t" . '</select>';
-
- $return .= "\t\t\t" . '</td>' . "\n";
-
- $return .= "\t\t" . '</tr>' . "\n";
-
- if($action != 'move')
- {
- $return .= "\t\t" . '<tr>' . "\n";
-
- $return .= "\t\t\t" . '<td class="label"><label for="idTitle">Title:</label></td>' . "\n";
- $return .= "\t\t\t" . '<td class="input"><input id="idTitle" name="title" type="text" value="' . $item_title . '" /></td>' . "\n";
-
- $return .= "\t\t" . '</tr>' . "\n";
-
- $return .= "\t\t" . '<tr>' . "\n";
-
- $return .= "\t\t\t" . '<td class="label"><label for="idDescription">Description:</label></td>' . "\n";
- $return .= "\t\t\t" . '<td class="input"><textarea id="idDescription" name="description" rows="4">' . $item_description . '</textarea></td>' . "\n";
-
- $return .= "\t\t" . '</tr>' . "\n";
- }
-
- $return .= "\t\t" . '<tr>' . "\n";
-
- $return .= "\t\t\t" . '<td colspan="2"><input class="button" name="submit_button" type="submit" value="OK" /></td>' . "\n";
-
- $return .= "\t\t" . '</tr>' . "\n";
-
- $return .= "\t" . '</table>' . "\n";
-
- if($item_type == 'module' || $item_type == 'dokeos_module')
- $return .= "\t" . '<input name="parent" type="hidden" value="0" />' . "\n";
-
- if($action == 'move')
- {
- $return .= "\t" . '<input name="title" type="hidden" value="' . $item_title . '" />' . "\n";
- $return .= "\t" . '<input name="description" type="hidden" value="' . $item_description . '" />' . "\n";
- }
- /*if($id != 0 && is_array($extra_info))
- {
- $return .= "\t" . '<input name="old_previous" type="hidden" value="' . $extra_info['parent_item_id'] . '" />' . "\n";
- $return .= "\t" . '<input name="old_next" type="hidden" value="' . $extra_info['previous_item_id'] . '" />' . "\n";
- }*/
-
- $return .= "\t" . '<input name="type" type="hidden" value="dokeos_' . $item_type . '" />' . "\n";
- $return .= "\t" . '<input name="post_time" type="hidden" value="' . time() . '" />' . "\n";
-
- $return .= '</form>' . "\n";
- $return .= '</div>' . "\n";
-
- return $return;
- }
-
- /**
- * Enter description here...
- *
- * @param unknown_type $action
- * @param unknown_type $id
- * @param unknown_type $extra_info
- * @return unknown
- */
- function display_document_form($action = 'add', $id = 0, $extra_info = 'new')
- {
- $tbl_lp_item = Database::get_course_table('lp_item');
- $tbl_doc = Database::get_course_table(DOCUMENT_TABLE);
-
- if($id != 0 && is_array($extra_info))
- {
- $item_title = stripslashes($extra_info['title']);
- $item_description = stripslashes($extra_info['description']);
- }
- elseif(is_numeric($extra_info))
- {
- $sql_doc = "
- SELECT title
- FROM " . $tbl_doc . "
- WHERE id = " . $extra_info;
-
- $result = api_sql_query($sql_doc, __FILE__, __LINE__);
- $row = Database::fetch_array($result);
-
- $explode = explode('.', $row['title']);
-
- for($i = 0; $i < count($explode) - 1; $i++)
- $item_title .= $explode[$i];
-
- $item_title = str_replace('_', ' ', $item_title);
- }
- else
- {
- $item_title = '';
- $item_description = '';
- }
-
- $return = '<div style="margin:3px 10px;">';
-
- if($id != 0 && is_array($extra_info))
- $parent = $extra_info['parent_item_id'];
- else
- $parent = 0;
-
- $sql = "
- SELECT *
- FROM " . $tbl_lp_item . "
- WHERE
- lp_id = " . $this->lp_id;
-
- $result = api_sql_query($sql, __FILE__, __LINE__);
-
- $arrLP = array();
-
- while($row = Database::fetch_array($result))
- {
- $arrLP[] = array(
- 'id' => $row['id'],
- 'item_type' => $row['item_type'],
- 'title' => $row['title'],
- 'path' => $row['path'],
- 'description' => $row['description'],
- 'parent_item_id' => $row['parent_item_id'],
- 'previous_item_id' => $row['previous_item_id'],
- 'next_item_id' => $row['next_item_id'],
- 'display_order' => $row['display_order']);
- }
-
- $this->tree_array($arrLP);
-
- $arrLP = $this->arrMenu;
-
- unset($this->arrMenu);
-
- if($action == 'add')
- $return .= '<p class="lp_title">Create the document:</p>' . "\n";
- elseif($action == 'move')
- $return .= '<p class="lp_title">Move the current document:</p>' . "\n";
- else
- $return .= '<p class="lp_title">Edit the current document:</p>' . "\n";
-
- if(isset($_GET['edit']) && $_GET['edit'] == 'true')
- {
- $return .= '<div class="lp_message" style="margin-bottom:15px;">';
-
- $return .= '<p class="lp_title">Warning !</p>';
- $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.';
-
- $return .= '</div>';
- }
-
- $return .= '<form method="POST">' . "\n";
-
- $return .= "\t" . '<table cellpadding="0" cellspacing="0" class="lp_form">' . "\n";
-
- $return .= "\t\t" . '<tr>' . "\n";
-
- $return .= "\t\t\t" . '<td class="label"><label for="idParent">Parent:</label></td>' . "\n";
- $return .= "\t\t\t" . '<td class="input">' . "\n";
-
- $return .= "\t\t\t\t" . '<select id="idParent" name="parent" onchange="load_cbo(this.value);" size="1">';
-
- $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
-
- $arrHide = array($id);
-
- for($i = 0; $i < count($arrLP); $i++)
- {
- if($action != 'add')
- {
- if(($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter') && !in_array($arrLP[$i]['id'], $arrHide) && !in_array($arrLP[$i]['parent_item_id'], $arrHide))
- {
- $return .= "\t\t\t\t\t" . '<option ' . (($parent == $arrLP[$i]['id']) ? 'selected="selected" ' : '') . 'style="padding-left:' . ($arrLP[$i]['depth'] * 10) . 'px;" value="' . $arrLP[$i]['id'] . '">' . html_entity_decode(stripslashes($arrLP[$i]['title'])) . '</option>';
- }
- else
- {
- $arrHide[] = $arrLP[$i]['id'];
- }
- }
- else
- {
- if($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter')
- $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>';
- }
- }
-
- reset($arrLP);
-
- $return .= "\t\t\t\t" . '</select>';
-
- $return .= "\t\t\t" . '</td>' . "\n";
-
- $return .= "\t\t" . '</tr>' . "\n";
-
- $return .= "\t\t" . '<tr>' . "\n";
-
- $return .= "\t\t\t" . '<td class="label"><label for="idPosition">Position:</label></td>' . "\n";
- $return .= "\t\t\t" . '<td class="input">' . "\n";
-
- $return .= "\t\t\t\t" . '<select id="idPosition" name="previous" size="1">';
-
- $return .= "\t\t\t\t\t" . '<option class="top" value="0">First position</option>';
-
- for($i = 0; $i < count($arrLP); $i++)
- {
- if($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id)
- {
- if($extra_info['previous_item_id'] == $arrLP[$i]['id'])
- $selected = 'selected="selected" ';
- elseif($action == 'add')
- $selected = 'selected="selected" ';
- else
- $selected = '';
-
- $return .= "\t\t\t\t\t" . '<option ' . $selected . 'value="' . $arrLP[$i]['id'] . '">After "' . html_entity_decode(stripslashes($arrLP[$i]['title'])) . '"</option>';
- }
- }
-
- $return .= "\t\t\t\t" . '</select>';
-
- $return .= "\t\t\t" . '</td>' . "\n";
-
- $return .= "\t\t" . '</tr>' . "\n";
-
- if($action != 'move')
- {
- $return .= "\t\t" . '<tr>' . "\n";
-
- $return .= "\t\t\t" . '<td class="label"><label for="idTitle">Title:</label></td>' . "\n";
- $return .= "\t\t\t" . '<td class="input"><input id="idTitle" name="title" type="text" value="' . $item_title . '" /></td>' . "\n";
-
- $return .= "\t\t" . '</tr>' . "\n";
-
- $return .= "\t\t" . '<tr>' . "\n";
-
- $return .= "\t\t\t" . '<td class="label"><label for="idDescription">Description:</label></td>' . "\n";
- $return .= "\t\t\t" . '<td class="input"><textarea id="idDescription" name="description" rows="4">' . $item_description . '</textarea></td>' . "\n";
-
- $return .= "\t\t" . '</tr>' . "\n";
-
- if(($extra_info == 'new' || $extra_info['item_type'] == TOOL_DOCUMENT || $_GET['edit'] == 'true'))
- {
- if($action == 'add' || $_GET['edit'] == 'true')
- {
- $return .= "\t\t" . '<tr>' . "\n";
-
- $return .= "\t\t\t" . '<td class="label"><label for="idDir">Directory:</label></td>' . "\n";
- $return .= "\t\t\t" . '<td class="input">';
-
- $sql_doc = "
- SELECT *
- FROM " . $tbl_doc . "
- WHERE
- filetype = 'folder'
- ORDER BY path ASC";
-
- $result = api_sql_query($sql_doc, __FILE__, __LINE__);
-
- $return .= "\t\t\t\t" . '<select id="idDir" name="dir" size="1">' . "\n";
-
- $return .= "\t\t\t\t\t" . '<option value="/">/ ( root )</option>' . "\n";
-
- while($row_doc = Database::fetch_array($result))
- {
- $return .= "\t\t\t\t\t" . '<option value="' . $row_doc['path'] . '">' . $row_doc['path'] . '</option>' . "\n";
- }
-
- $return .= "\t\t\t\t" . '</select>' . "\n";
-
- $return .= "\t\t\t" . '</td>' . "\n";
-
- $return .= "\t\t" . '</tr>' . "\n";
- }
-
- $return .= "\t\t" . '<tr>' . "\n";
-
- $return .= "\t\t\t" . '<td colspan="2">' . "\n";
-
- if(isset($_POST['content']))
- $content = stripslashes($_POST['content']);
- elseif(is_array($extra_info))
- $content = $this->display_document($extra_info['path'], false, false);
- elseif(is_numeric($extra_info))
- $content = $this->display_document($extra_info, false, false);
- else
- $content = '';
-
- $oFCKeditor = new FCKeditor('content') ;
- $oFCKeditor->BasePath = api_get_path(WEB_PATH) . 'main/inc/lib/fckeditor/' ;
- $oFCKeditor->Height = '400';
- $oFCKeditor->Width = '100%';
- $oFCKeditor->Value = $content;
-
- $return .= $oFCKeditor->CreateHtml();
-
- $return .= "\t\t\t" . '</td>' . "\n";
-
- $return .= "\t\t" . '</tr>' . "\n";
- }
- elseif(is_numeric($extra_info))
- {
- $return .= "\t\t" . '<tr>' . "\n";
-
- $return .= "\t\t\t" . '<td colspan="2" style="background:#F8F8F8; border:1px solid #999999;">' . "\n";
-
- $return .= $this->display_document($extra_info, true, true, true);
-
- $return .= "\t\t\t" . '</td>' . "\n";
-
- $return .= "\t\t" . '</tr>' . "\n";
- }
- }
-
- $return .= "\t\t" . '<tr>' . "\n";
-
- $return .= "\t\t\t" . '<td colspan="2"><input class="button" name="submit_button" type="submit" value="OK" /></td>' . "\n";
-
- $return .= "\t\t" . '</tr>' . "\n";
-
- $return .= "\t" . '</table>' . "\n";
-
- if($action == 'move')
- {
- $return .= "\t" . '<input name="title" type="hidden" value="' . $item_title . '" />' . "\n";
- $return .= "\t" . '<input name="description" type="hidden" value="' . $item_description . '" />' . "\n";
- }
-
- if(is_numeric($extra_info))
- {
- $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info . '" />' . "\n";
- }
- elseif(is_array($extra_info))
- {
- $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />' . "\n";
- }
-
- $return .= "\t" . '<input name="type" type="hidden" value="'.TOOL_DOCUMENT.'" />' . "\n";
- $return .= "\t" . '<input name="post_time" type="hidden" value="' . time() . '" />' . "\n";
-
- $return .= '</form>' . "\n";
- $return .= '</div>' . "\n";
-
- return $return;
- }
-
- /**
- * Enter description here...
- *
- * @param unknown_type $action
- * @param unknown_type $id
- * @param unknown_type $extra_info
- */
- function display_link_form($action = 'add', $id = 0, $extra_info = '')
- {
- $tbl_lp_item = Database::get_course_table('lp_item');
- $tbl_link = Database::get_course_table(LINK_TABLE);
-
- if($id != 0 && is_array($extra_info))
- {
- $item_title = stripslashes($extra_info['title']);
- $item_description = stripslashes($extra_info['description']);
- }
- elseif(is_numeric($extra_info))
- {
- $sql_link = "
- SELECT
- title,
- description,
- url
- FROM " . $tbl_link . "
- WHERE id = " . $extra_info;
-
- $result = api_sql_query($sql_link, __FILE__, __LINE__);
- $row = Database::fetch_array($result);
-
- $item_title = $row['title'];
- $item_description = $row['description'];
- $item_url = $row['url'];
- }
- else
- {
- $item_title = '';
- $item_description = '';
- }
-
- $return = '<div style="margin:3px 10px;">';
-
- if($id != 0 && is_array($extra_info))
- $parent = $extra_info['parent_item_id'];
- else
- $parent = 0;
-
- $sql = "
- SELECT *
- FROM " . $tbl_lp_item . "
- WHERE
- lp_id = " . $this->lp_id;
-
- $result = api_sql_query($sql, __FILE__, __LINE__);
-
- $arrLP = array();
-
- while($row = Database::fetch_array($result))
- {
- $arrLP[] = array(
- 'id' => $row['id'],
- 'item_type' => $row['item_type'],
- 'title' => $row['title'],
- 'path' => $row['path'],
- 'description' => $row['description'],
- 'parent_item_id' => $row['parent_item_id'],
- 'previous_item_id' => $row['previous_item_id'],
- 'next_item_id' => $row['next_item_id'],
- 'display_order' => $row['display_order']);
- }
-
- $this->tree_array($arrLP);
-
- $arrLP = $this->arrMenu;
-
- unset($this->arrMenu);
-
- if($action == 'add')
- $return .= '<p class="lp_title">Create the link:</p>' . "\n";
- elseif($action == 'move')
- $return .= '<p class="lp_title">Move the current link:</p>' . "\n";
- else
- $return .= '<p class="lp_title">Edit the current link:</p>' . "\n";
-
- $return .= '<form method="POST">' . "\n";
-
- $return .= "\t" . '<table cellpadding="0" cellspacing="0" class="lp_form">' . "\n";
-
- $return .= "\t\t" . '<tr>' . "\n";
-
- $return .= "\t\t\t" . '<td class="label"><label for="idParent">Parent:</label></td>' . "\n";
- $return .= "\t\t\t" . '<td class="input">' . "\n";
-
- $return .= "\t\t\t\t" . '<select id="idParent" name="parent" onchange="load_cbo(this.value);" size="1">';
-
- $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
-
- $arrHide = array($id);
-
- for($i = 0; $i < count($arrLP); $i++)
- {
- if($action != 'add')
- {
- if(($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter') && !in_array($arrLP[$i]['id'], $arrHide) && !in_array($arrLP[$i]['parent_item_id'], $arrHide))
- {
- $return .= "\t\t\t\t\t" . '<option ' . (($parent == $arrLP[$i]['id']) ? 'selected="selected" ' : '') . 'style="padding-left:' . ($arrLP[$i]['depth'] * 10) . 'px;" value="' . $arrLP[$i]['id'] . '">' . html_entity_decode(stripslashes($arrLP[$i]['title'])) . '</option>';
- }
- else
- {
- $arrHide[] = $arrLP[$i]['id'];
- }
- }
- else
- {
- if($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter')
- $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>';
- }
- }
-
- reset($arrLP);
-
- $return .= "\t\t\t\t" . '</select>';
-
- $return .= "\t\t\t" . '</td>' . "\n";
-
- $return .= "\t\t" . '</tr>' . "\n";
-
- $return .= "\t\t" . '<tr>' . "\n";
-
- $return .= "\t\t\t" . '<td class="label"><label for="idPosition">Position:</label></td>' . "\n";
- $return .= "\t\t\t" . '<td class="input">' . "\n";
-
- $return .= "\t\t\t\t" . '<select id="idPosition" name="previous" size="1">';
-
- $return .= "\t\t\t\t\t" . '<option class="top" value="0">First position</option>';
-
- for($i = 0; $i < count($arrLP); $i++)
- {
- if($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id)
- {
- if($extra_info['previous_item_id'] == $arrLP[$i]['id'])
- $selected = 'selected="selected" ';
- elseif($action == 'add')
- $selected = 'selected="selected" ';
- else
- $selected = '';
-
- $return .= "\t\t\t\t\t" . '<option ' . $selected . 'value="' . $arrLP[$i]['id'] . '">After "' . html_entity_decode(stripslashes($arrLP[$i]['title'])) . '"</option>';
- }
- }
-
- $return .= "\t\t\t\t" . '</select>';
-
- $return .= "\t\t\t" . '</td>' . "\n";
-
- $return .= "\t\t" . '</tr>' . "\n";
-
- if($action != 'move')
- {
- $return .= "\t\t" . '<tr>' . "\n";
-
- $return .= "\t\t\t" . '<td class="label"><label for="idTitle">Title:</label></td>' . "\n";
- $return .= "\t\t\t" . '<td class="input"><input id="idTitle" name="title" type="text" value="' . $item_title . '" /></td>' . "\n";
-
- $return .= "\t\t" . '</tr>' . "\n";
-
- $return .= "\t\t" . '<tr>' . "\n";
-
- $return .= "\t\t\t" . '<td class="label"><label for="idDescription">Description:</label></td>' . "\n";
- $return .= "\t\t\t" . '<td class="input"><textarea id="idDescription" name="description" rows="4">' . $item_description . '</textarea></td>' . "\n";
-
- $return .= "\t\t" . '</tr>' . "\n";
-
- $return .= "\t\t" . '<tr>' . "\n";
-
- $return .= "\t\t\t" . '<td class="label"><label for="idURL">URL:</label></td>' . "\n";
- $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";
-
- $return .= "\t\t" . '</tr>' . "\n";
- }
-
- $return .= "\t\t" . '<tr>' . "\n";
-
- $return .= "\t\t\t" . '<td colspan="2"><input class="button" name="submit_button" type="submit" value="OK" /></td>' . "\n";
-
- $return .= "\t\t" . '</tr>' . "\n";
-
- $return .= "\t" . '</table>' . "\n";
-
- if($action == 'move')
- {
- $return .= "\t" . '<input name="title" type="hidden" value="' . $item_title . '" />' . "\n";
- $return .= "\t" . '<input name="description" type="hidden" value="' . $item_description . '" />' . "\n";
- }
-
- if(is_numeric($extra_info))
- {
- $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info . '" />' . "\n";
- }
- elseif(is_array($extra_info))
- {
- $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />' . "\n";
- }
-
- $return .= "\t" . '<input name="type" type="hidden" value="'.TOOL_LINK.'" />' . "\n";
- $return .= "\t" . '<input name="post_time" type="hidden" value="' . time() . '" />' . "\n";
-
- $return .= '</form>' . "\n";
-
- $return .= '</div>' . "\n";
-
- return $return;
- }
-
- /**
- * Enter description here...
- *
- * @param unknown_type $action
- * @param unknown_type $id
- * @param unknown_type $extra_info
- * @return unknown
- */
- function display_student_publication_form($action = 'add', $id = 0, $extra_info = '')
- {
- $tbl_lp_item = Database::get_course_table('lp_item');
- $tbl_publication = Database::get_course_table(STUDENT_PUBLICATION_TABLE);
-
- if($id != 0 && is_array($extra_info))
- {
- $item_title = stripslashes($extra_info['title']);
- $item_description = stripslashes($extra_info['description']);
- }
- elseif(is_numeric($extra_info))
- {
- $sql_publication = "
- SELECT
- title,
- description
- FROM " . $tbl_publication . "
- WHERE id = " . $extra_info;
-
- $result = api_sql_query($sql_publication, __FILE__, __LINE__);
- $row = Database::fetch_array($result);
-
- $item_title = $row['title'];
- $item_description = $row['description'];
- }
- else
- {
- $item_title = '';
- $item_description = '';
- }
-
- $return = '<div style="margin:3px 10px;">';
-
- if($id != 0 && is_array($extra_info))
- $parent = $extra_info['parent_item_id'];
- else
- $parent = 0;
-
- $sql = "
- SELECT *
- FROM " . $tbl_lp_item . "
- WHERE
- lp_id = " . $this->lp_id;
-
- $result = api_sql_query($sql, __FILE__, __LINE__);
-
- $arrLP = array();
-
- while($row = Database::fetch_array($result))
- {
- $arrLP[] = array(
- 'id' => $row['id'],
- 'item_type' => $row['item_type'],
- 'title' => $row['title'],
- 'path' => $row['path'],
- 'description' => $row['description'],
- 'parent_item_id' => $row['parent_item_id'],
- 'previous_item_id' => $row['previous_item_id'],
- 'next_item_id' => $row['next_item_id'],
- 'display_order' => $row['display_order']);
- }
-
- $this->tree_array($arrLP);
-
- $arrLP = $this->arrMenu;
-
- unset($this->arrMenu);
-
- if($action == 'add')
- $return .= '<p class="lp_title">Create the student publication:</p>' . "\n";
- elseif($action == 'move')
- $return .= '<p class="lp_title">Move the current student publication:</p>' . "\n";
- else
- $return .= '<p class="lp_title">Edit the current student publication:</p>' . "\n";
-
- $return .= '<form method="POST">' . "\n";
-
- $return .= "\t" . '<table cellpadding="0" cellspacing="0" class="lp_form">' . "\n";
-
- $return .= "\t\t" . '<tr>' . "\n";
-
- $return .= "\t\t\t" . '<td class="label"><label for="idParent">Parent:</label></td>' . "\n";
- $return .= "\t\t\t" . '<td class="input">' . "\n";
-
- $return .= "\t\t\t\t" . '<select id="idParent" name="parent" onchange="load_cbo(this.value);" size="1">';
-
- $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
-
- $arrHide = array($id);
-
- for($i = 0; $i < count($arrLP); $i++)
- {
- if($action != 'add')
- {
- if(($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter') && !in_array($arrLP[$i]['id'], $arrHide) && !in_array($arrLP[$i]['parent_item_id'], $arrHide))
- {
- $return .= "\t\t\t\t\t" . '<option ' . (($parent == $arrLP[$i]['id']) ? 'selected="selected" ' : '') . 'style="padding-left:' . ($arrLP[$i]['depth'] * 10) . 'px;" value="' . $arrLP[$i]['id'] . '">' . html_entity_decode(stripslashes($arrLP[$i]['title'])) . '</option>';
- }
- else
- {
- $arrHide[] = $arrLP[$i]['id'];
- }
- }
- else
- {
- if($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter')
- $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>';
- }
- }
-
- reset($arrLP);
-
- $return .= "\t\t\t\t" . '</select>';
-
- $return .= "\t\t\t" . '</td>' . "\n";
-
- $return .= "\t\t" . '</tr>' . "\n";
-
- $return .= "\t\t" . '<tr>' . "\n";
-
- $return .= "\t\t\t" . '<td class="label"><label for="idPosition">Position:</label></td>' . "\n";
- $return .= "\t\t\t" . '<td class="input">' . "\n";
-
- $return .= "\t\t\t\t" . '<select id="idPosition" name="previous" size="1">';
-
- $return .= "\t\t\t\t\t" . '<option class="top" value="0">First position</option>';
-
- for($i = 0; $i < count($arrLP); $i++)
- {
- if($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id)
- {
- if($extra_info['previous_item_id'] == $arrLP[$i]['id'])
- $selected = 'selected="selected" ';
- elseif($action == 'add')
- $selected = 'selected="selected" ';
- else
- $selected = '';
-
- $return .= "\t\t\t\t\t" . '<option ' . $selected . 'value="' . $arrLP[$i]['id'] . '">After "' . html_entity_decode(stripslashes($arrLP[$i]['title'])) . '"</option>';
- }
- }
-
- $return .= "\t\t\t\t" . '</select>';
-
- $return .= "\t\t\t" . '</td>' . "\n";
-
- $return .= "\t\t" . '</tr>' . "\n";
-
- if($action != 'move')
- {
- $return .= "\t\t" . '<tr>' . "\n";
-
- $return .= "\t\t\t" . '<td class="label"><label for="idTitle">Title:</label></td>' . "\n";
- $return .= "\t\t\t" . '<td class="input"><input id="idTitle" name="title" type="text" value="' . $item_title . '" /></td>' . "\n";
-
- $return .= "\t\t" . '</tr>' . "\n";
-
- $return .= "\t\t" . '<tr>' . "\n";
-
- $return .= "\t\t\t" . '<td class="label"><label for="idDescription">Description:</label></td>' . "\n";
- $return .= "\t\t\t" . '<td class="input"><textarea id="idDescription" name="description" rows="4">' . $item_description . '</textarea></td>' . "\n";
-
- $return .= "\t\t" . '</tr>' . "\n";
- }
-
- $return .= "\t\t" . '<tr>' . "\n";
-
- $return .= "\t\t\t" . '<td colspan="2"><input class="button" name="submit_button" type="submit" value="OK" /></td>' . "\n";
-
- $return .= "\t\t" . '</tr>' . "\n";
-
- $return .= "\t" . '</table>' . "\n";
-
- if($action == 'move')
- {
- $return .= "\t" . '<input name="title" type="hidden" value="' . $item_title . '" />' . "\n";
- $return .= "\t" . '<input name="description" type="hidden" value="' . $item_description . '" />' . "\n";
- }
-
- if(is_numeric($extra_info))
- {
- $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info . '" />' . "\n";
- }
- elseif(is_array($extra_info))
- {
- $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />' . "\n";
- }
-
- $return .= "\t" . '<input name="type" type="hidden" value="'.TOOL_STUDENTPUBLICATION.'" />' . "\n";
- $return .= "\t" . '<input name="post_time" type="hidden" value="' . time() . '" />' . "\n";
-
- $return .= '</form>' . "\n";
-
- $return .= '</div>' . "\n";
-
- return $return;
- }
-
- /**
- * Displays the menu for manipulating a step
- *
- * @return unknown
- */
- function display_manipulate($item_id, $item_type = TOOL_DOCUMENT)
- {
- $return = '<div class="lp_manipulate">';
-
- switch($item_type)
- {
- case 'dokeos_chapter':
- case 'chapter':
-
- $lang = get_lang('TitleManipulateChapter');
- /* temp */ $lang = 'Manipulate the current chapter';
- break;
-
- case 'dokeos_module':
- case 'module':
-
- $lang = get_lang('TitleManipulateModule');
- /* temp */ $lang = 'Manipulate the current module';
-
- break;
-
- case TOOL_DOCUMENT:
-
- $lang = get_lang('TitleManipulateDocument');
- /* temp */ $lang = 'Manipulate the current document';
-
- break;
-
- case TOOL_LINK:
- case 'link':
-
- $lang = get_lang('TitleManipulateLink');
- /* temp */ $lang = 'Manipulate the current link';
-
- break;
-
- case TOOL_QUIZ:
-
- $lang = get_lang('TitleManipulateQuiz');
- /* temp */ $lang = 'Manipulate the current exercise';
-
- break;
-
- case TOOL_STUDENTPUBLICATION:
-
- $lang = get_lang('TitleManipulateStudentPublication');
- /* temp */ $lang = 'Manipulate the current student publication';
-
- break;
- }
-
- $return .= '<p class="lp_title">' . $lang . '</p>';
-
- $return .= '<a href="' . $_SERVER['PHP_SELF'] . '?cidReq=' . $_GET['cidReq'] . '&action=edit_item&view=build&id=' . $item_id . '&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>';
- $return .= '<a href="' . $_SERVER['PHP_SELF'] . '?cidReq=' . $_GET['cidReq'] . '&action=move_item&view=build&id=' . $item_id . '&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>';
-
- if($item_type != 'chapter' && $item_type != 'dokeos_chapter' && $item_type != 'module' && $item_type != 'dokeos_module')
- $return .= '<a href="' . $_SERVER['PHP_SELF'] . '?cidReq=' . $_GET['cidReq'] . '&action=edit_item_prereq&view=build&id=' . $item_id . '&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>';
-
- $return .= '<a href="' . $_SERVER['PHP_SELF'] . '?cidReq=' . $_GET['cidReq'] . '&action=delete_item&view=build&id=' . $item_id . '&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>';
-
- $return .= '</div>';
- return $return;
- }
-
- /**
- * Creates the javascript needed for filling up the checkboxes without page reload
- *
- * @return string
- */
- function create_js()
- {
- $return = '<script language="javascript" type="text/javascript">' . "\n";
-
- $return .= 'function load_cbo(id){' . "\n";
-
- $return .= "var cbo = document.getElementById('idPosition');";
-
- $return .= 'for(var i = cbo.length - 1; i > 0; i--)';
- $return .= 'cbo.options[i] = null;';
-
- $return .= 'for(var i = 1; i <= child_name[id].length; i++)';
- $return .= 'cbo.options[i] = new Option(child_name[id][i-1], child_value[id][i-1]);';
-
- $return .= '}' . "\n\n";
-
- $return .= 'var child_name = new Array();' . "\n";
- $return .= 'var child_value = new Array();' . "\n\n";
-
- $return .= 'child_name[0] = new Array();' . "\n";
- $return .= 'child_value[0] = new Array();' . "\n\n";
-
- $tbl_lp_item = Database::get_course_table('lp_item');
-
- $sql_zero = "
- SELECT *
- FROM " . $tbl_lp_item . "
- WHERE
- lp_id = " . $this->lp_id . " AND
- parent_item_id = 0
- ORDER BY display_order ASC";
- $res_zero = api_sql_query($sql_zero, __FILE__, __LINE__);
-
- $i = 0;
-
- while($row_zero = Database::fetch_array($res_zero))
- {
- $return .= 'child_name[0][' . $i . '] = "After \"' . $row_zero['title'] . '\"";' . "\n";
- $return .= 'child_value[0][' . $i++ . '] = "' . $row_zero['id'] . '";' . "\n";
- }
-
- $return .= "\n";
-
- $sql = "
- SELECT *
- FROM " . $tbl_lp_item . "
- WHERE
- lp_id = " . $this->lp_id;
- $res = api_sql_query($sql, __FILE__, __LINE__);
-
- while($row = Database::fetch_array($res))
- {
- $sql_parent = "
- SELECT *
- FROM " . $tbl_lp_item . "
- WHERE parent_item_id = " . $row['id'] . "
- ORDER BY display_order ASC";
- $res_parent = api_sql_query($sql_parent, __FILE__, __LINE__);
-
- $i = 0;
-
- $return .= 'child_name[' . $row['id'] . '] = new Array();' . "\n";
- $return .= 'child_value[' . $row['id'] . '] = new Array();' . "\n\n";
-
- while($row_parent = Database::fetch_array($res_parent))
- {
- $return .= 'child_name[' . $row['id'] . '][' . $i . '] = "After \"' . $row_parent['title'] . '\"";' . "\n";
- $return .= 'child_value[' . $row['id'] . '][' . $i++ . '] = "' . $row_parent['id'] . '";' . "\n";
- }
-
- $return .= "\n";
- }
-
- $return .= '</script>' . "\n";
-
- return $return;
- }
-
- /**
- * Enter description here...
- *
- * @param unknown_type $item_id
- * @return unknown
- */
- function display_move_item($item_id)
- {
- global $_course; //will disappear
-
- $return = '';
-
- if(is_numeric($item_id))
- {
- $tbl_lp_item = Database::get_course_table('lp_item');
-
- $sql = "
- SELECT *
- FROM " . $tbl_lp_item . "
- WHERE id = " . $item_id;
-
- $res = api_sql_query($sql, __FILE__, __LINE__);
- $row = Database::fetch_array($res);
-
- switch($row['item_type'])
- {
- case 'dokeos_chapter':
-
- $return .= $this->display_manipulate($item_id, $row['item_type']);
- $return .= $this->display_item_form($row['item_type'], 'Move the current chapter:', 'move', $item_id, $row);
-
- break;
-
- case 'dokeos_module':
-
- $return .= $this->display_manipulate($item_id, $row['item_type']);
- $return .= $this->display_item_form($row['item_type'], 'Move th current module:', 'move', $item_id, $row);
-
- break;
-
- case TOOL_DOCUMENT:
-
- $return .= $this->display_manipulate($item_id, $row['item_type']);
- $return .= $this->display_document_form('move', $item_id, $row);
-
- break;
-
- case TOOL_LINK:
-
- $return .= $this->display_manipulate($item_id, $row['item_type']);
- $return .= $this->display_link_form('move', $item_id, $row);
-
- break;
-
- case TOOL_QUIZ:
-
- $return .= $this->display_manipulate($item_id, $row['item_type']);
- $return .= $this->display_quiz_form('move', $item_id, $row);
-
- break;
-
- case TOOL_STUDENTPUBLICATION:
-
- $return .= $this->display_manipulate($item_id, $row['item_type']);
- $return .= $this->display_student_publication_form('move', $item_id, $row);
-
- break;
- }
- }
-
- return $return;
- }
-
- /**
- * Displays a basic form on the overview page for changing the item title and the item description.
- *
- * @param string $item_type
- * @param string $title
- * @param array $data
- * @return string
- */
- function display_item_small_form($item_type, $title = '', $data)
- {
- $return .= '<div class="lp_small_form">' . "\n";
-
- $return .= '<p class="lp_title">' . $title . '</p>';
-
- $return .= '<form method="post">' . "\n";
-
- $return .= '<table cellpadding="0" cellspacing="0" class="lp_form">';
-
- $return .= "\t\t" . '<tr>' . "\n";
-
- $return .= "\t\t\t" . '<td class="label"><label for="idTitle">Title:</label></td>' . "\n";
- $return .= "\t\t\t" . '<td class="input"><input class="small_form" id="idTitle" name="title" type="text" value="' . $data['title'] . '" /></td>' . "\n";
-
- $return .= "\t\t" . '</tr>' . "\n";
-
- $return .= "\t\t" . '<tr>' . "\n";
-
- $return .= "\t\t\t" . '<td class="label"><label for="idDescription">Description:</label></td>' . "\n";
- $return .= "\t\t\t" . '<td class="input"><textarea class="small_form" id="idDescription" name="description" rows="4">' . $data['description'] . '</textarea></td>' . "\n";
-
- $return .= "\t\t" . '</tr>' . "\n";
-
- $return .= "\t\t" . '<tr>' . "\n";
-
- $return .= "\t\t\t" . '<td colspan="2"><input class="button small_form" name="submit_button" type="submit" value="OK" /></td>' . "\n";
-
- $return .= "\t\t" . '</tr>' . "\n";
-
- $return .= "\t\t" . '</table>' . "\n";
-
- $return .= "\t" . '<input name="parent" type="hidden" value="' . $data['parent_item_id'] . '"/>' . "\n";
- $return .= "\t" . '<input name="previous" type="hidden" value="' . $data['previous_item_id'] . '"/>' . "\n";
-
- $return .= '</form>';
-
- $return .= '</div>';
-
- return $return;
- }
-
- /**
- * Enter description here...
- *
- * @param unknown_type $item_id
- * @return unknown
- */
- function display_item_prerequisites_form($item_id)
- {
- $tbl_lp_item = Database::get_course_table('lp_item');
-
- /* current prerequisite */
- $sql = "
- SELECT *
- FROM " . $tbl_lp_item . "
- WHERE id = " . $item_id;
- $result = api_sql_query($sql, __FILE__, __LINE__);
- $row = Database::fetch_array($result);
-
- $preq_id = $row['prerequisite'];
- $preq_min = $row['min_score'];
- $preq_max = $row['max_score'];
-
- $return = $this->display_manipulate($item_id, TOOL_DOCUMENT);
-
- $return .= '<div style="margin:3px 10px;">';
-
- $return .= '<p class="lp_title">Add/edit prerequisites</p>';
-
- $return .= '<form method="POST">';
-
- $return .= '<table class="lp_form">';
-
- $return .= '<tr>';
-
- $return .= '<th></th>';
- $return .= '<th class="exercise">Minimum</th>';
- $return .= '<th class="exercise">Maximum</th>';
-
- $return .= '</tr>';
-
- $return .= '<tr>';
-
- $return .= '<td class="radio" colspan="3">';
-
- $return .= '<input checked="checked" id="idNone" name="prerequisites" style="margin-left:0; margin-right:10px;" type="radio" />';
- $return .= '<label for="idNone">None</label>';
-
- $return .= '</td>';
-
- $return .= '</tr>';
-
- $sql = "
- SELECT *
- FROM " . $tbl_lp_item . "
- WHERE
- lp_id = " . $this->lp_id;
-
- $result = api_sql_query($sql, __FILE__, __LINE__);
-
- $arrLP = array();
-
- while($row = Database::fetch_array($result))
- {
- $arrLP[] = array(
- 'id' => $row['id'],
- 'item_type' => $row['item_type'],
- 'title' => $row['title'],
- 'description' => $row['description'],
- 'parent_item_id' => $row['parent_item_id'],
- 'previous_item_id' => $row['previous_item_id'],
- 'next_item_id' => $row['next_item_id'],
- 'display_order' => $row['display_order']);
- }
-
- $this->tree_array($arrLP);
-
- $arrLP = $this->arrMenu;
-
- unset($this->arrMenu);
-
- for($i = 0; $i < count($arrLP); $i++)
- {
- if($arrLP[$i]['id'] == $item_id)
- break;
-
- $return .= '<tr>';
-
- $return .= '<td class="radio"' . (($arrLP[$i]['item_type'] != TOOL_QUIZ) ? ' colspan="3"' : '') . '>';
-
- $return .= '<input' . (($arrLP[$i]['id'] == $preq_id) ? ' checked="checked" ' : '') . (($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter') ? ' disabled="disabled" ' : ' ') . 'id="id' . $arrLP[$i]['id'] . '" name="prerequisites" style="margin-left:' . $arrLP[$i]['depth'] * 10 . 'px; margin-right:10px;" type="radio" value="' . $arrLP[$i]['id'] . '" />';
- $return .= '<img alt="" src="img/lp_' . $arrLP[$i]['item_type'] . '.png" style="margin-right:5px;" title="" />';
- $return .= '<label for="id' . $arrLP[$i]['id'] . '">' . stripslashes($arrLP[$i]['title']) . '</label>';
-
- $return .= '</td>';
-
- if($arrLP[$i]['item_type'] == TOOL_QUIZ)
- {
- $return .= '<td class="exercise">';
-
- $return .= '<input maxlength="3" name="min_' . $arrLP[$i]['id'] . '" type="text" value="' . (($arrLP[$i]['id'] == $preq_id) ? $preq_min : 0) . '" />';
-
- $return .= '</td>';
-
- $return .= '<td class="exercise">';
-
- $return .= '<input maxlength="3" name="max_' . $arrLP[$i]['id'] . '" type="text" value="' . (($arrLP[$i]['id'] == $preq_id) ? $preq_max : 100) . '" />';
-
- $return .= '</td>';
- }
-
- $return .= '</tr>';
- }
-
- $return .= '<tr>';
-
- $return .= '<td colspan="3">';
-
- $return .= '<input class="button" name="submit_button" type="submit" value="OK" /></td>' . "\n";
-
- $return .= '</td>';
-
- $return .= '</tr>';
-
- $return .= '</table>';
-
- $return .= '</form>';
-
- $return .= '</div>';
-
- return $return;
- }
-
- /**
- * Creates a list with all the documents in it
- *
- * @return string
- */
- function get_documents()
- {
- global $_course;
-
- $tbl_doc = Database::get_course_table(DOCUMENT_TABLE);
-
- $sql_doc = "
- SELECT *
- FROM " . $tbl_doc . "
- WHERE
- path NOT LIKE '%_DELETED_%'
- ORDER BY path ASC";
- $res_doc = api_sql_query($sql_doc, __FILE__, __LINE__);
-
- $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>';
- $return .= '<div class="lp_resource_elements" id="resDoc">';
-
- while($row_doc = Database::fetch_array($res_doc))
- {
- $explode = explode('/', $row_doc['path']);
- $num = count($explode) - 2;
-
- $return .= '<div class="lp_resource_element">';
-
- $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="" />';
-
- if($row_doc['filetype'] == 'file')
- $return .= '<a href="' . $_SERVER['PHP_SELF'] . '?cidReq=' . $_GET['cidReq'] . '&action=add_item&type=' . TOOL_DOCUMENT . '&file=' . $row_doc['id'] . '&lp_id=' . $this->lp_id . '">' . $row_doc['title'] . '</a>';
- else
- $return .= $row_doc['title'];
-
- $return .= '</div>';
- }
- if(Database::num_rows($res_doc) == 0)
- $return .= '<div class="lp_resource_element">No documents</div>';
-
- $return .= '</div>';
-
- return $return;
- }
-
- /**
- * Creates a list with all the exercises (quiz) in it
- *
- * @return string
- */
- function get_exercises()
- {
- $tbl_quiz = Database::get_course_table(QUIZ_TEST_TABLE);
-
- $sql_quiz = "
- SELECT *
- FROM " . $tbl_quiz . "
- ORDER BY title ASC";
- $res_quiz = api_sql_query($sql_quiz, __FILE__, __LINE__);
-
- $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>';
- $return .= '<div class="lp_resource_elements" id="resExercise">';
-
- while($row_quiz = Database::fetch_array($res_quiz))
- {
- $return .= '<div class="lp_resource_element">';
-
- $return .= '<img align="left" alt="" src="img/lp_' . TOOL_QUIZ . '.png" style="margin-right:5px;" title="" />';
- $return .= '<a href="' . $_SERVER['PHP_SELF'] . '?cidReq=' . $_GET['cidReq'] . '&action=add_item&type=' . TOOL_QUIZ . '&file=' . $row_quiz['id'] . '&lp_id=' . $this->lp_id . '">' . $row_quiz['title'] . '</a>';
- //$return .= $row_quiz['title'];
-
- $return .= '</div>';
- }
-
- if(Database::num_rows($res_quiz) == 0)
- $return .= '<div class="lp_resource_element">No exercises available</div>';
-
- $return .= '</div>';
-
- return $return;
- }
-
- /**
- * Creates a list with all the links in it
- *
- * @return string
- */
- function get_links()
- {
- $tbl_link = Database::get_course_table(LINK_TABLE);
-
- $sql_link = "
- SELECT *
- FROM " . $tbl_link . "
- ORDER BY title ASC";
- $res_link = api_sql_query($sql_link, __FILE__, __LINE__);
-
- $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>';
- $return .= '<div class="lp_resource_elements" id="resLink">';
-
- while($row_link = Database::fetch_array($res_link))
- {
- $return .= '<div class="lp_resource_element">';
-
- $return .= '<img align="left" alt="" src="img/lp_' . TOOL_LINK . '.png" style="margin-right:5px;" title="" />';
- $return .= '<a href="' . $_SERVER['PHP_SELF'] . '?cidReq=' . $_GET['cidReq'] . '&action=add_item&type=' . TOOL_LINK . '&file=' . $row_link['id'] . '&lp_id=' . $this->lp_id . '">' . $row_link['title'] . '</a>';
-
- $return .= '</div>';
- }
-
- if(Database::num_rows($res_link) == 0)
- $return .= '<div class="lp_resource_element">No links available</div>';
-
- $return .= '</div>';
-
- return $return;
- }
-
- /**
- * Creates a list with all the student publications in it
- *
- * @return unknown
- */
- function get_student_publications()
- {
- $tbl_student = Database::get_course_table(STUDENT_PUBLICATION_TABLE);
-
- $sql_student = "
- SELECT *
- FROM " . $tbl_student . "
- ORDER BY title ASC";
- $res_student = api_sql_query($sql_student, __FILE__, __LINE__);
-
- $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>';
- $return .= '<div class="lp_resource_elements" id="resStudent" style="border-bottom:1px solid #999999; border-top:0;">';
-
- while($row_student = Database::fetch_array($res_student))
- {
- $return .= '<div class="lp_resource_element">';
-
- $return .= '<img align="left" alt="" src="img/lp_' . TOOL_STUDENTPUBLICATION . '.png" style="margin-right:5px;" title="" />';
- $return .= '<a href="' . $_SERVER['PHP_SELF'] . '?cidReq=' . $_GET['cidReq'] . '&action=add_item&type=' . TOOL_STUDENTPUBLICATION . '&file=' . $row_student['id'] . '&lp_id=' . $this->lp_id . '">' . $row_student['title'] . '</a>';
-
- $return .= '</div>';
- }
-
- if(Database::num_rows($res_student) == 0)
- $return .= '<div class="lp_resource_element">No student publications available</div>';
-
- $return .= '</div>';
-
- return $return;
- }
- }
- ?>
|