learnpath.class.php 299 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244
  1. <?php //$id:$
  2. /**
  3. * This (abstract?) class defines the parent attributes and methods for the dokeos learnpaths and scorm
  4. * learnpaths. It is used by the scorm class as well as the dokeos_lp class.
  5. * @package dokeos.learnpath
  6. * @author Yannick Warnier <ywarnier@beeznest.org>
  7. * @license GNU/GPL - See Dokeos license directory for details
  8. */
  9. /**
  10. * Defines the learnpath parent class
  11. * @package dokeos.learnpath
  12. */
  13. class learnpath {
  14. var $attempt = 0; //the number for the current ID view
  15. var $cc; //course (code) this learnpath is located in
  16. var $current; //id of the current item the user is viewing
  17. var $current_score; //the score of the current item
  18. var $current_time_start; //the time the user loaded this resource (this does not mean he can see it yet)
  19. var $current_time_stop; //the time the user closed this resource
  20. var $default_status = 'not attempted';
  21. var $encoding = 'ISO-8859-1';
  22. var $error = '';
  23. var $extra_information = ''; //this string can be used by proprietary SCORM contents to store data about the current learnpath
  24. var $force_commit = false; //for SCORM only - if set to true, will send a scorm LMSCommit() request on each LMSSetValue()
  25. var $index; //the index of the active learnpath_item in $ordered_items array
  26. var $items = array();
  27. var $last; //item_id of last item viewed in the learning path
  28. var $last_item_seen = 0; //in case we have already come in this learnpath, reuse the last item seen if authorized
  29. var $license; //which license this course has been given - not used yet on 20060522
  30. var $lp_id; //DB ID for this learnpath
  31. var $lp_view_id; //DB ID for lp_view
  32. var $log_file; //file where to log learnpath API msg
  33. var $maker; //which maker has conceived the content (ENI, Articulate, ...)
  34. var $message = '';
  35. var $mode='embedded'; //holds the video display mode (fullscreen or embedded)
  36. var $name; //learnpath name (they generally have one)
  37. var $ordered_items = array(); //list of the learnpath items in the order they are to be read
  38. var $path = ''; //path inside the scorm directory (if scorm)
  39. var $theme; // the current theme of the learning path
  40. // Tells if all the items of the learnpath can be tried again. Defaults to "no" (=1)
  41. var $prevent_reinit = 1;
  42. // Describes the mode of progress bar display
  43. var $progress_bar_mode = '%';
  44. // Percentage progress as saved in the db
  45. var $progress_db = '0';
  46. var $proximity; //wether the content is distant or local or unknown
  47. var $refs_list = array(); //list of items by ref => db_id. Used only for prerequisites match.
  48. //!!!This array (refs_list) is built differently depending on the nature of the LP.
  49. //If SCORM, uses ref, if Dokeos, uses id to keep a unique value
  50. var $type; //type of learnpath. Could be 'dokeos', 'scorm', 'scorm2004', 'aicc', ...
  51. //TODO check if this type variable is useful here (instead of just in the controller script)
  52. var $user_id; //ID of the user that is viewing/using the course
  53. var $update_queue = array();
  54. var $scorm_debug = 0;
  55. var $arrMenu = array(); //array for the menu items
  56. var $debug = 0; //logging level
  57. /**
  58. * Class constructor. Needs a database handler, a course code and a learnpath id from the database.
  59. * Also builds the list of items into $this->items.
  60. * @param string Course code
  61. * @param integer Learnpath ID
  62. * @param integer User ID
  63. * @return boolean True on success, false on error
  64. */
  65. function learnpath($course, $lp_id, $user_id) {
  66. //check params
  67. //check course code
  68. if($this->debug>0){error_log('New LP - In learnpath::learnpath('.$course.','.$lp_id.','.$user_id.')',0);}
  69. if(empty($course)){
  70. $this->error = 'Course code is empty';
  71. return false;
  72. }
  73. else
  74. {
  75. $main_table = Database::get_main_table(TABLE_MAIN_COURSE);
  76. //$course = Database::escape_string($course);
  77. $course = $this->escape_string($course);
  78. $sql = "SELECT * FROM $main_table WHERE code = '$course'";
  79. if($this->debug>2){error_log('New LP - learnpath::learnpath() '.__LINE__.' - Querying course: '.$sql,0);}
  80. //$res = Database::query($sql);
  81. $res = api_sql_query($sql, __FILE__, __LINE__);
  82. if(Database::num_rows($res)>0)
  83. {
  84. $this->cc = $course;
  85. }
  86. else
  87. {
  88. $this->error = 'Course code does not exist in database ('.$sql.')';
  89. return false;
  90. }
  91. }
  92. //check learnpath ID
  93. if(empty($lp_id))
  94. {
  95. $this->error = 'Learnpath ID is empty';
  96. return false;
  97. }
  98. else
  99. {
  100. //TODO make it flexible to use any course_code (still using env course code here)
  101. $lp_table = Database::get_course_table('lp');
  102. //$id = Database::escape_integer($id);
  103. $lp_id = $this->escape_string($lp_id);
  104. $sql = "SELECT * FROM $lp_table WHERE id = '$lp_id'";
  105. if($this->debug>2){error_log('New LP - learnpath::learnpath() '.__LINE__.' - Querying lp: '.$sql,0);}
  106. //$res = Database::query($sql);
  107. $res = api_sql_query($sql, __FILE__, __LINE__);
  108. if(Database::num_rows($res)>0)
  109. {
  110. $this->lp_id = $lp_id;
  111. $row = Database::fetch_array($res);
  112. $this->type = $row['lp_type'];
  113. $this->name = stripslashes($row['name']);
  114. $this->encoding = $row['default_encoding'];
  115. $this->proximity = $row['content_local'];
  116. $this->theme = $row['theme'];
  117. $this->maker = $row['content_maker'];
  118. $this->prevent_reinit = $row['prevent_reinit'];
  119. $this->license = $row['content_license'];
  120. $this->scorm_debug = $row['debug'];
  121. $this->js_lib = $row['js_lib'];
  122. $this->path = $row['path'];
  123. if($this->type == 2){
  124. if($row['force_commit'] == 1){
  125. $this->force_commit = true;
  126. }
  127. }
  128. $this->mode = $row['default_view_mod'];
  129. }
  130. else
  131. {
  132. $this->error = 'Learnpath ID does not exist in database ('.$sql.')';
  133. return false;
  134. }
  135. }
  136. //check user ID
  137. if(empty($user_id)){
  138. $this->error = 'User ID is empty';
  139. return false;
  140. }
  141. else
  142. {
  143. //$main_table = Database::get_main_user_table();
  144. $main_table = Database::get_main_table(TABLE_MAIN_USER);
  145. //$user_id = Database::escape_integer($user_id);
  146. $user_id = $this->escape_string($user_id);
  147. $sql = "SELECT * FROM $main_table WHERE user_id = '$user_id'";
  148. if($this->debug>2){error_log('New LP - learnpath::learnpath() '.__LINE__.' - Querying user: '.$sql,0);}
  149. //$res = Database::query($sql);
  150. $res = api_sql_query($sql);
  151. if(Database::num_rows($res)>0)
  152. {
  153. $this->user_id = $user_id;
  154. }
  155. else
  156. {
  157. $this->error = 'User ID does not exist in database ('.$sql.')';
  158. return false;
  159. }
  160. }
  161. //end of variables checking
  162. //now get the latest attempt from this user on this LP, if available, otherwise create a new one
  163. $lp_table = Database::get_course_table(TABLE_LP_VIEW);
  164. //selecting by view_count descending allows to get the highest view_count first
  165. $sql = "SELECT * FROM $lp_table WHERE lp_id = '$lp_id' AND user_id = '$user_id' ORDER BY view_count DESC";
  166. if($this->debug>2){error_log('New LP - learnpath::learnpath() '.__LINE__.' - querying lp_view: '.$sql,0);}
  167. //$res = Database::query($sql);
  168. $res = api_sql_query($sql);
  169. $view_id = 0; //used later to query lp_item_view
  170. if(Database::num_rows($res)>0)
  171. {
  172. if($this->debug>2){error_log('New LP - learnpath::learnpath() '.__LINE__.' - Found previous view',0);}
  173. $row = Database::fetch_array($res);
  174. $this->attempt = $row['view_count'];
  175. $this->lp_view_id = $row['id'];
  176. $this->last_item_seen = $row['last_item'];
  177. $this->progress_db = $row['progress'];
  178. }
  179. else
  180. {
  181. if($this->debug>2){error_log('New LP - learnpath::learnpath() '.__LINE__.' - NOT Found previous view',0);}
  182. $this->attempt = 1;
  183. $sql_ins = "INSERT INTO $lp_table (lp_id,user_id,view_count) VALUES ($lp_id,$user_id,1)";
  184. $res_ins = api_sql_query($sql_ins);
  185. $this->lp_view_id = Database::get_last_insert_id();
  186. if($this->debug>2){error_log('New LP - learnpath::learnpath() '.__LINE__.' - inserting new lp_view: '.$sql_ins,0);}
  187. }
  188. //initialise items
  189. $lp_item_table = Database::get_course_table(TABLE_LP_ITEM);
  190. $sql = "SELECT * FROM $lp_item_table WHERE lp_id = '".$this->lp_id."' ORDER BY parent_item_id, display_order";
  191. $res = api_sql_query($sql);
  192. while($row = Database::fetch_array($res))
  193. {
  194. $oItem = '';
  195. //$this->ordered_items[] = $row['id'];
  196. switch($this->type){
  197. case 3: //aicc
  198. $oItem = new aiccItem('db',$row['id']);
  199. if(is_object($oItem)){
  200. $my_item_id = $oItem->get_id();
  201. $oItem->set_lp_view($this->lp_view_id);
  202. $oItem->set_prevent_reinit($this->prevent_reinit);
  203. // Don't use reference here as the next loop will make the pointed object change
  204. $this->items[$my_item_id] = $oItem;
  205. $this->refs_list[$oItem->ref]=$my_item_id;
  206. if($this->debug>2){error_log('New LP - learnpath::learnpath() - aicc object with id '.$my_item_id.' set in items[]',0);}
  207. }
  208. break;
  209. case 2:
  210. require_once('scorm.class.php');
  211. require_once('scormItem.class.php');
  212. $oItem = new scormItem('db',$row['id']);
  213. if(is_object($oItem)){
  214. $my_item_id = $oItem->get_id();
  215. $oItem->set_lp_view($this->lp_view_id);
  216. $oItem->set_prevent_reinit($this->prevent_reinit);
  217. // Don't use reference here as the next loop will make the pointed object change
  218. $this->items[$my_item_id] = $oItem;
  219. $this->refs_list[$oItem->ref]=$my_item_id;
  220. if($this->debug>2){error_log('New LP - object with id '.$my_item_id.' set in items[]',0);}
  221. }
  222. break;
  223. case 1:
  224. default:
  225. require_once('learnpathItem.class.php');
  226. $oItem = new learnpathItem($row['id'],$user_id);
  227. if(is_object($oItem)){
  228. $my_item_id = $oItem->get_id();
  229. //$oItem->set_lp_view($this->lp_view_id); moved down to when we are sure the item_view exists
  230. $oItem->set_prevent_reinit($this->prevent_reinit);
  231. // Don't use reference here as the next loop will make the pointed object change
  232. $this->items[$my_item_id] = $oItem;
  233. $this->refs_list[$my_item_id]=$my_item_id;
  234. if($this->debug>2){error_log('New LP - learnpath::learnpath() '.__LINE__.' - object with id '.$my_item_id.' set in items[]',0);}
  235. }
  236. break;
  237. }
  238. //items is a list of pointers to all items, classified by DB ID, not SCO id
  239. if($row['parent_item_id'] == 0 OR empty($this->items[$row['parent_item_id']])){
  240. $this->items[$row['id']]->set_level(0);
  241. }else{
  242. $level = $this->items[$row['parent_item_id']]->get_level()+1;
  243. $this->items[$row['id']]->set_level($level);
  244. if(is_object($this->items[$row['parent_item_id']])){
  245. //items is a list of pointers from item DB ids to item objects
  246. $this->items[$row['parent_item_id']]->add_child($row['id']);
  247. }else{
  248. if($this->debug>2){error_log('New LP - learnpath::learnpath() '.__LINE__.' - The parent item ('.$row['parent_item_id'].') of item '.$row['id'].' could not be found',0);}
  249. }
  250. }
  251. //get last viewing vars
  252. $lp_item_view_table = Database::get_course_table(TABLE_LP_ITEM_VIEW);
  253. //this query should only return one or zero result
  254. $sql = "SELECT * " .
  255. "FROM $lp_item_view_table " .
  256. "WHERE lp_view_id = ".$this->lp_view_id." " .
  257. "AND lp_item_id = ".$row['id']." ORDER BY view_count DESC ";
  258. if($this->debug>2){error_log('New LP - learnpath::learnpath() - Selecting item_views: '.$sql,0);}
  259. //get the item status
  260. $res2 = api_sql_query($sql);
  261. if(Database::num_rows($res2)>0)
  262. {
  263. //if this learnpath has already been used by this user, get his last attempt count and
  264. //the last item seen back into this object
  265. //$max = 0;
  266. $row2 = Database::fetch_array($res2);
  267. if($this->debug>2){error_log('New LP - learnpath::learnpath() - Got item_view: '.print_r($row2,true),0);}
  268. $this->items[$row['id']]->set_status($row2['status']);
  269. if(empty($row2['status'])){
  270. $this->items[$row['id']]->set_status($this->default_status);
  271. }
  272. //$this->attempt = $row['view_count'];
  273. //$this->last_item = $row['id'];
  274. }
  275. else //no item found in lp_item_view for this view
  276. {
  277. //first attempt from this user. Set attempt to 1 and last_item to 0 (first item available)
  278. //TODO if the learnpath has not got attempts activated, always use attempt '1'
  279. //$this->attempt = 1;
  280. //$this->last_item = 0;
  281. $this->items[$row['id']]->set_status($this->default_status);
  282. //Add that row to the lp_item_view table so that we have something to show in the stats page
  283. $sql_ins = "INSERT INTO $lp_item_view_table " .
  284. "(lp_item_id, lp_view_id, view_count, status) VALUES " .
  285. "(".$row['id'].",".$this->lp_view_id.",1,'not attempted')";
  286. if($this->debug>2){error_log('New LP - learnpath::learnpath() '.__LINE__.' - Inserting blank item_view : '.$sql_ins,0);}
  287. $res_ins = api_sql_query($sql_ins);
  288. }
  289. //setting the view in the item object
  290. $this->items[$row['id']]->set_lp_view($this->lp_view_id);
  291. }
  292. $this->ordered_items = $this->get_flat_ordered_items_list($this->get_id(),0);
  293. $this->max_ordered_items = 0;
  294. foreach($this->ordered_items as $index=>$dummy){
  295. if($index > $this->max_ordered_items AND !empty($dummy)){
  296. $this->max_ordered_items = $index;
  297. }
  298. }
  299. //TODO define the current item better
  300. $this->first();
  301. if($this->debug>2){error_log('New LP - learnpath::learnpath() '.__LINE__.' - End of learnpath constructor for learnpath '.$this->get_id(),0);}
  302. }
  303. /**
  304. * Function rewritten based on old_add_item() from Yannick Warnier. Due the fact that users can decide where the item should come, I had to overlook this function and
  305. * I found it better to rewrite it. Old function is still available. Added also the possibility to add a description.
  306. *
  307. * @param int $parent
  308. * @param int $previous
  309. * @param string $type
  310. * @param int $id
  311. * @param string $title
  312. * @param string $description
  313. * @return int
  314. */
  315. function add_item($parent, $previous, $type = 'dokeos_chapter', $id, $title, $description, $prerequisites=0)
  316. {
  317. if($this->debug>0){error_log('New LP - In learnpath::add_item('.$parent.','.$previous.','.$type.','.$id.','.$title.')',0);}
  318. $tbl_lp_item = Database::get_course_table('lp_item');
  319. $parent = intval($parent);
  320. $previous = intval($previous);
  321. $type = $this->escape_string($type);
  322. $id = intval($id);
  323. $title = $this->escape_string(htmlentities($title));
  324. $description = $this->escape_string(htmlentities($description));
  325. $sql_count = "
  326. SELECT COUNT(id) AS num
  327. FROM " . $tbl_lp_item . "
  328. WHERE
  329. lp_id = " . $this->get_id() . " AND
  330. parent_item_id = " . $parent;
  331. $res_count = api_sql_query($sql_count, __FILE__, __LINE__);
  332. $row = Database::fetch_array($res_count);
  333. $num = $row['num'];
  334. if($num > 0)
  335. {
  336. if($previous == 0)
  337. {
  338. $sql = "
  339. SELECT
  340. id,
  341. next_item_id,
  342. display_order
  343. FROM " . $tbl_lp_item . "
  344. WHERE
  345. lp_id = " . $this->get_id() . " AND
  346. parent_item_id = " . $parent . " AND
  347. previous_item_id = 0 OR previous_item_id=".$parent;
  348. $result = api_sql_query($sql, __FILE__, __LINE__);
  349. $row = Database::fetch_array($result);
  350. $tmp_previous = 0;
  351. $next = $row['id'];
  352. $display_order = 0;
  353. }
  354. else
  355. {
  356. $previous = (int) $previous;
  357. $sql = "
  358. SELECT
  359. id,
  360. previous_item_id,
  361. next_item_id,
  362. display_order
  363. FROM " . $tbl_lp_item . "
  364. WHERE
  365. lp_id = " . $this->get_id() . " AND
  366. id = " . $previous;
  367. $result = api_sql_query($sql, __FILE__, __LINE__);
  368. $row = Database::fetch_array($result);
  369. $tmp_previous = $row['id'];
  370. $next = $row['next_item_id'];
  371. $display_order = $row['display_order'];
  372. }
  373. }
  374. else
  375. {
  376. $tmp_previous = 0;
  377. $next = 0;
  378. $display_order = 0;
  379. }
  380. $new_item_id = -1;
  381. $id = $this->escape_string($id);
  382. if($type == 'quiz')
  383. {
  384. $sql = 'SELECT SUM(ponderation)
  385. FROM '.Database :: get_course_table(TABLE_QUIZ_QUESTION).' as quiz_question
  386. INNER JOIN '.Database :: get_course_table(TABLE_QUIZ_TEST_QUESTION).' as quiz_rel_question
  387. ON quiz_question.id = quiz_rel_question.question_id
  388. AND quiz_rel_question.exercice_id = '.$id;
  389. $rsQuiz = api_sql_query($sql, __FILE__, __LINE__);
  390. $max_score = Database::result($rsQuiz, 0, 0);
  391. }
  392. else
  393. {
  394. $max_score = 100;
  395. }
  396. if($prerequisites!=0){
  397. $sql_ins = "
  398. INSERT INTO " . $tbl_lp_item . " (
  399. lp_id,
  400. item_type,
  401. ref,
  402. title,
  403. description,
  404. path,
  405. max_score,
  406. parent_item_id,
  407. previous_item_id,
  408. next_item_id,
  409. display_order,
  410. prerequisite
  411. ) VALUES (
  412. " . $this->get_id() . ",
  413. '" . $type . "',
  414. '',
  415. '" . $title . "',
  416. '" . $description . "',
  417. '" . $id . "',
  418. '" . $max_score. "',
  419. " . $parent . ",
  420. " . $previous . ",
  421. " . $next . ",
  422. " . ($display_order + 1) . ",
  423. " . $prerequisites . "
  424. )";
  425. }
  426. else{
  427. //insert new item
  428. $sql_ins = "
  429. INSERT INTO " . $tbl_lp_item . " (
  430. lp_id,
  431. item_type,
  432. ref,
  433. title,
  434. description,
  435. path,
  436. max_score,
  437. parent_item_id,
  438. previous_item_id,
  439. next_item_id,
  440. display_order
  441. ) VALUES (
  442. " . $this->get_id() . ",
  443. '" . $type . "',
  444. '',
  445. '" . $title . "',
  446. '" . $description . "',
  447. '" . $id . "',
  448. '" . $max_score. "',
  449. " . $parent . ",
  450. " . $previous . ",
  451. " . $next . ",
  452. " . ($display_order + 1) . "
  453. )";
  454. }
  455. if($this->debug>2){error_log('New LP - Inserting dokeos_chapter: '.$sql_ins,0);}
  456. $res_ins = api_sql_query($sql_ins, __FILE__, __LINE__);
  457. if($res_ins > 0)
  458. {
  459. $new_item_id = Database::get_last_insert_id($res_ins);
  460. //update the item that should come after the new item
  461. $sql_update_next = "
  462. UPDATE " . $tbl_lp_item . "
  463. SET previous_item_id = " . $new_item_id . "
  464. WHERE id = " . $next;
  465. $res_update_next = api_sql_query($sql_update_next, __FILE__, __LINE__);
  466. //update the item that should be before the new item
  467. $sql_update_previous = "
  468. UPDATE " . $tbl_lp_item . "
  469. SET next_item_id = " . $new_item_id . "
  470. WHERE id = " . $tmp_previous;
  471. $res_update_previous = api_sql_query($sql_update_previous, __FILE__, __LINE__);
  472. //update all the items after the new item
  473. $sql_update_order = "
  474. UPDATE " . $tbl_lp_item . "
  475. SET display_order = display_order + 1
  476. WHERE
  477. lp_id = " . $this->get_id() . " AND
  478. id <> " . $new_item_id . " AND
  479. parent_item_id = " . $parent . " AND
  480. display_order > " . $display_order;
  481. $res_update_previous = api_sql_query($sql_update_order, __FILE__, __LINE__);
  482. //update the item that should come after the new item
  483. $sql_update_ref = "
  484. UPDATE " . $tbl_lp_item . "
  485. SET ref = " . $new_item_id . "
  486. WHERE id = " . $new_item_id;
  487. api_sql_query($sql_update_ref, __FILE__, __LINE__);
  488. }
  489. return $new_item_id;
  490. }
  491. /**
  492. * Static admin function allowing addition of a learnpath to a course.
  493. * @param string Course code
  494. * @param string Learnpath name
  495. * @param string Learnpath description string, if provided
  496. * @param string Type of learnpath (default = 'guess', others = 'dokeos', 'aicc',...)
  497. * @param string Type of files origin (default = 'zip', others = 'dir','web_dir',...)
  498. * @param string Zip file containing the learnpath or directory containing the learnpath
  499. * @return integer The new learnpath ID on success, 0 on failure
  500. */
  501. function add_lp($course,$name,$description='',$learnpath='guess',$origin='zip',$zipname='')
  502. {
  503. //if($this->debug>0){error_log('New LP - In learnpath::add_lp()',0);}
  504. //TODO
  505. $tbl_lp = Database::get_course_table('lp');
  506. //check course code exists
  507. //check lp_name doesn't exist, otherwise append something
  508. $i = 0;
  509. $name = learnpath::escape_string(htmlentities($name)); //Kevin Van Den Haute: added htmlentities()
  510. $check_name = "SELECT * FROM $tbl_lp WHERE name = '$name'";
  511. //if($this->debug>2){error_log('New LP - Checking the name for new LP: '.$check_name,0);}
  512. $res_name = api_sql_query($check_name, __FILE__, __LINE__);
  513. while(Database::num_rows($res_name)){
  514. //there is already one such name, update the current one a bit
  515. $i++;
  516. $name = $name.' - '.$i;
  517. $check_name = "SELECT * FROM $tbl_lp WHERE name = '$name'";
  518. //if($this->debug>2){error_log('New LP - Checking the name for new LP: '.$check_name,0);}
  519. $res_name = api_sql_query($check_name, __FILE__, __LINE__);
  520. }
  521. //new name does not exist yet; keep it
  522. //escape description
  523. $description = learnpath::escape_string(htmlentities($description)); //Kevin: added htmlentities()
  524. $type = 1;
  525. switch($learnpath){
  526. case 'guess':
  527. break;
  528. case 'dokeos':
  529. $type = 1;
  530. break;
  531. case 'aicc':
  532. break;
  533. }
  534. switch($origin){
  535. case 'zip':
  536. //check zipname string. If empty, we are currently creating a new Dokeos learnpath
  537. break;
  538. case 'manual':
  539. default:
  540. $get_max = "SELECT MAX(display_order) FROM $tbl_lp";
  541. $res_max = api_sql_query($get_max, __FILE__, __LINE__);
  542. if(Database::num_rows($res_max)<1){
  543. $dsp = 1;
  544. }else{
  545. $row = Database::fetch_array($res_max);
  546. $dsp = $row[0]+1;
  547. }
  548. $sql_insert = "INSERT INTO $tbl_lp " .
  549. "(lp_type,name,description,path,default_view_mod," .
  550. "default_encoding,display_order,content_maker," .
  551. "content_local,js_lib) " .
  552. "VALUES ($type,'$name','$description','','embedded'," .
  553. "'UTF-8','$dsp','Dokeos'," .
  554. "'local','')";
  555. //if($this->debug>2){error_log('New LP - Inserting new lp '.$sql_insert,0);}
  556. $res_insert = api_sql_query($sql_insert, __FILE__, __LINE__);
  557. $id = Database::get_last_insert_id();
  558. if($id>0){
  559. //insert into item_property
  560. api_item_property_update(api_get_course_info(),TOOL_LEARNPATH,$id,'LearnpathAdded',api_get_user_id());
  561. return $id;
  562. }
  563. break;
  564. }
  565. }
  566. /**
  567. * Appends a message to the message attribute
  568. * @param string Message to append.
  569. */
  570. function append_message($string)
  571. {
  572. if($this->debug>0){error_log('New LP - In learnpath::append_message()',0);}
  573. $this->message .= $string;
  574. }
  575. /**
  576. * Autocompletes the parents of an item in case it's been completed or passed
  577. * @param integer Optional ID of the item from which to look for parents
  578. */
  579. function autocomplete_parents($item)
  580. {
  581. if($this->debug>0){error_log('New LP - In learnpath::autocomplete_parents()',0);}
  582. if(empty($item)){
  583. $item = $this->current;
  584. }
  585. $parent_id = $this->items[$item]->get_parent();
  586. if($this->debug>2){error_log('New LP - autocompleting parent of item '.$item.' (item '.$parent_id.')',0);}
  587. if(is_object($this->items[$item]) and !empty($parent_id))
  588. {//if $item points to an object and there is a parent
  589. if($this->debug>2){error_log('New LP - '.$item.' is an item, proceed',0);}
  590. $current_item =& $this->items[$item];
  591. $parent =& $this->items[$parent_id]; //get the parent
  592. //new experiment including failed and browsed in completed status
  593. $current_status = $current_item->get_status();
  594. if($current_item->is_done() || $current_status=='browsed' || $current_status=='failed')
  595. {
  596. //if the current item is completed or passes or succeeded
  597. $completed = true;
  598. if($this->debug>2){error_log('New LP - Status of current item is alright',0);}
  599. foreach($parent->get_children() as $child)
  600. {
  601. //check all his brothers (his parent's children) for completion status
  602. if($child!= $item)
  603. {
  604. if($this->debug>2){error_log('New LP - Looking at brother with ID '.$child.', status is '.$this->items[$child]->get_status(),0);}
  605. //if($this->items[$child]->status_is(array('completed','passed','succeeded')))
  606. //Trying completing parents of failed and browsed items as well
  607. if($this->items[$child]->status_is(array('completed','passed','succeeded','browsed','failed')))
  608. {
  609. //keep completion status to true
  610. }else{
  611. if($this->debug>2){error_log('New LP - Found one incomplete child of '.$parent_id.': '.$child.' is '.$this->items[$child]->get_status(),0);}
  612. $completed = false;
  613. }
  614. }
  615. }
  616. if($completed == true)
  617. { //if all the children were completed
  618. $parent->set_status('completed');
  619. $parent->save(false,$this->prerequisites_match($parent->get_id()));
  620. $this->update_queue[$parent->get_id()] = $parent->get_status();
  621. if($this->debug>2){error_log('New LP - Added parent to update queue '.print_r($this->update_queue,true),0);}
  622. $this->autocomplete_parents($parent->get_id()); //recursive call
  623. }
  624. }else{
  625. //error_log('New LP - status of current item is not enough to get bothered with it',0);
  626. }
  627. }
  628. }
  629. /**
  630. * Autosaves the current results into the database for the whole learnpath
  631. */
  632. function autosave()
  633. {
  634. if($this->debug>0){error_log('New LP - In learnpath::autosave()',0);}
  635. //TODO add aditionnal save operations for the learnpath itself
  636. }
  637. /**
  638. * Clears the message attribute
  639. */
  640. function clear_message()
  641. {
  642. if($this->debug>0){error_log('New LP - In learnpath::clear_message()',0);}
  643. $this->message = '';
  644. }
  645. /**
  646. * Closes the current resource
  647. *
  648. * Stops the timer
  649. * Saves into the database if required
  650. * Clears the current resource data from this object
  651. * @return boolean True on success, false on failure
  652. */
  653. function close()
  654. {
  655. if($this->debug>0){error_log('New LP - In learnpath::close()',0);}
  656. if(empty($this->lp_id))
  657. {
  658. $this->error = 'Trying to close this learnpath but no ID is set';
  659. return false;
  660. }
  661. $this->current_time_stop = time();
  662. if($this->save)
  663. {
  664. $learnpath_view_table = Database::get_course_table(TABLE_LP_VIEW);
  665. /*
  666. $sql = "UPDATE $learnpath_view_table " .
  667. "SET " .
  668. "stop_time = ".$this->current_time_stop.", " .
  669. "score = ".$this->current_score.", ".
  670. "WHERE learnpath_id = '".$this->lp_id."'";
  671. //$res = Database::query($sql);
  672. $res = api_sql_query($res);
  673. if(mysql_affected_rows($res)<1)
  674. {
  675. $this->error = 'Could not update learnpath_view table while closing learnpath';
  676. return false;
  677. }
  678. */
  679. }
  680. $this->ordered_items = array();
  681. $this->index=0;
  682. unset($this->lp_id);
  683. //unset other stuff
  684. return true;
  685. }
  686. /**
  687. * Static admin function allowing removal of a learnpath
  688. * @param string Course code
  689. * @param integer Learnpath ID
  690. * @param string Whether to delete data or keep it (default: 'keep', others: 'remove')
  691. * @return boolean True on success, false on failure (might change that to return number of elements deleted)
  692. */
  693. function delete($course=null,$id=null,$delete='keep')
  694. {
  695. //TODO implement a way of getting this to work when the current object is not set
  696. //In clear: implement this in the item class as well (abstract class) and use the given ID in queries
  697. //if(empty($course)){$course = api_get_course_id();}
  698. //if(empty($id)){$id = $this->get_id();}
  699. //If an ID is specifically given and the current LP is not the same,
  700. //prevent delete
  701. if(!empty($id) && ($id != $this->lp_id)){return false;}
  702. //if($this->debug>0){error_log('New LP - In learnpath::delete()',0);}
  703. foreach($this->items as $id => $dummy)
  704. {
  705. $this->items[$id]->delete();
  706. }
  707. $lp = Database::get_course_table('lp');
  708. $lp_view = Database::get_course_table('lp_view');
  709. $sql_del_view = "DELETE FROM $lp_view WHERE lp_id = ".$this->lp_id;
  710. //if($this->debug>2){error_log('New LP - Deleting views bound to lp '.$this->lp_id.': '.$sql_del_view,0);}
  711. $res_del_view = api_sql_query($sql_del_view, __FILE__, __LINE__);
  712. $this->toggle_publish($this->lp_id,'i');
  713. //if($this->debug>2){error_log('New LP - Deleting lp '.$this->lp_id.' of type '.$this->type,0);}
  714. if($this->type == 2 OR $this->type==3){
  715. //this is a scorm learning path, delete the files as well
  716. $sql = "SELECT path FROM $lp WHERE id = ".$this->lp_id;
  717. $res = api_sql_query($sql, __FILE__, __LINE__);
  718. if(Database::num_rows($res)>0){
  719. $row = Database::fetch_array($res);
  720. $path = $row['path'];
  721. $sql = "SELECT id FROM $lp WHERE path = '$path' AND id != ".$this->lp_id;
  722. $res = api_sql_query($sql, __FILE__, __LINE__);
  723. if(Database::num_rows($res)>0)
  724. { //another learning path uses this directory, so don't delete it
  725. if($this->debug>2){error_log('New LP - In learnpath::delete(), found other LP using path '.$path.', keeping directory',0);}
  726. }else{
  727. //no other LP uses that directory, delete it
  728. $course_rel_dir = api_get_course_path().'/scorm/'; //scorm dir web path starting from /courses
  729. $course_scorm_dir = api_get_path(SYS_COURSE_PATH).$course_rel_dir; //absolute system path for this course
  730. if($delete == 'remove' && is_dir($course_scorm_dir.$path) and !empty($course_scorm_dir)){
  731. if($this->debug>2){error_log('New LP - In learnpath::delete(), found SCORM, deleting directory: '.$course_scorm_dir.$path,0);}
  732. exec('rm -rf '.$course_scorm_dir.$path);
  733. }
  734. }
  735. }
  736. }
  737. $sql_del_lp = "DELETE FROM $lp WHERE id = ".$this->lp_id;
  738. //if($this->debug>2){error_log('New LP - Deleting lp '.$this->lp_id.': '.$sql_del_lp,0);}
  739. $res_del_lp = api_sql_query($sql_del_lp, __FILE__, __LINE__);
  740. $this->update_display_order();//updates the display order of all lps
  741. api_item_property_update(api_get_course_info(),TOOL_LEARNPATH,$this->lp_id,'delete',api_get_user_id());
  742. //TODO: also delete items and item-views
  743. }
  744. /**
  745. * Removes all the children of one item - dangerous!
  746. * @param integer Element ID of which children have to be removed
  747. * @return integer Total number of children removed
  748. */
  749. function delete_children_items($id){
  750. if($this->debug>0){error_log('New LP - In learnpath::delete_children_items('.$id.')',0);}
  751. $num = 0;
  752. if(empty($id) || $id != strval(intval($id))){return false;}
  753. $lp_item = Database::get_course_table('lp_item');
  754. $sql = "SELECT * FROM $lp_item WHERE parent_item_id = $id";
  755. $res = api_sql_query($sql, __FILE__, __LINE__);
  756. while($row = Database::fetch_array($res)){
  757. $num += $this->delete_children_items($row['id']);
  758. $sql_del = "DELETE FROM $lp_item WHERE id = ".$row['id'];
  759. $res_del = api_sql_query($sql_del, __FILE__, __LINE__);
  760. $num++;
  761. }
  762. return $num;
  763. }
  764. /**
  765. * Removes an item from the current learnpath
  766. * @param integer Elem ID (0 if first)
  767. * @param integer Whether to remove the resource/data from the system or leave it (default: 'keep', others 'remove')
  768. * @return integer Number of elements moved
  769. * @todo implement resource removal
  770. */
  771. function delete_item($id, $remove='keep')
  772. {
  773. if($this->debug>0){error_log('New LP - In learnpath::delete_item()',0);}
  774. //TODO - implement the resource removal
  775. if(empty($id) || $id != strval(intval($id))){return false;}
  776. //first select item to get previous, next, and display order
  777. $lp_item = Database::get_course_table('lp_item');
  778. $sql_sel = "SELECT * FROM $lp_item WHERE id = $id";
  779. $res_sel = api_sql_query($sql_sel,__FILE__,__LINE__);
  780. if(Database::num_rows($res_sel)<1){return false;}
  781. $row = Database::fetch_array($res_sel);
  782. $previous = $row['previous_item_id'];
  783. $next = $row['next_item_id'];
  784. $display = $row['display_order'];
  785. $parent = $row['parent_item_id'];
  786. $lp = $row['lp_id'];
  787. //delete children items
  788. $num = $this->delete_children_items($id);
  789. if($this->debug>2){error_log('New LP - learnpath::delete_item() - deleted '.$num.' children of element '.$id,0);}
  790. //now delete the item
  791. $sql_del = "DELETE FROM $lp_item WHERE id = $id";
  792. if($this->debug>2){error_log('New LP - Deleting item: '.$sql_del,0);}
  793. $res_del = api_sql_query($sql_del,__FILE__,__LINE__);
  794. //now update surrounding items
  795. $sql_upd = "UPDATE $lp_item SET next_item_id = $next WHERE id = $previous";
  796. $res_upd = api_sql_query($sql_upd,__FILE__,__LINE__);
  797. $sql_upd = "UPDATE $lp_item SET previous_item_id = $previous WHERE id = $next";
  798. $res_upd = api_sql_query($sql_upd,__FILE__,__LINE__);
  799. //now update all following items with new display order
  800. $sql_all = "UPDATE $lp_item SET display_order = display_order-1 WHERE lp_id = $lp AND parent_item_id = $parent AND display_order > $display";
  801. $res_all = api_sql_query($sql_all,__FILE__,__LINE__);
  802. }
  803. /**
  804. * Updates an item's content in place
  805. * @param integer Element ID
  806. * @param string New content
  807. * @return boolean True on success, false on error
  808. */
  809. function edit_item($id, $parent, $previous, $title, $description, $prerequisites=0)
  810. {
  811. if($this->debug > 0){error_log('New LP - In learnpath::edit_item()', 0);}
  812. if(empty($id) or ($id != strval(intval($id))) or empty($title)){ return false; }
  813. $tbl_lp_item = Database::get_course_table('lp_item');
  814. $sql_select = "
  815. SELECT *
  816. FROM " . $tbl_lp_item . "
  817. WHERE id = " . $id;
  818. $res_select = api_sql_query($sql_select, __FILE__, __LINE__);
  819. $row_select = Database::fetch_array($res_select);
  820. $same_parent = ($row_select['parent_item_id'] == $parent) ? true : false;
  821. $same_previous = ($row_select['previous_item_id'] == $previous) ? true : false;
  822. if($same_parent && $same_previous)
  823. {
  824. //only update title and description
  825. $sql_update = "
  826. UPDATE " . $tbl_lp_item . "
  827. SET
  828. title = '" . $this->escape_string(htmlentities($title)) . "',
  829. prerequisite = '".$prerequisites."',
  830. description = '" . $this->escape_string(htmlentities($description)) . "'
  831. WHERE id = " . $id;
  832. $res_update = api_sql_query($sql_update, __FILE__, __LINE__);
  833. }
  834. else
  835. {
  836. $old_parent = $row_select['parent_item_id'];
  837. $old_previous = $row_select['previous_item_id'];
  838. $old_next = $row_select['next_item_id'];
  839. $old_order = $row_select['display_order'];
  840. $old_prerequisite= $row_select['prerequisite'];
  841. /* BEGIN -- virtually remove the current item id */
  842. /* for the next and previous item it is like the current item doesn't exist anymore */
  843. if($old_previous != 0)
  844. {
  845. $sql_update_next = "
  846. UPDATE " . $tbl_lp_item . "
  847. SET next_item_id = " . $old_next . "
  848. WHERE id = " . $old_previous;
  849. $res_update_next = api_sql_query($sql_update_next, __FILE__, __LINE__);
  850. //echo '<p>' . $sql_update_next . '</p>';
  851. }
  852. if($old_next != 0)
  853. {
  854. $sql_update_previous = "
  855. UPDATE " . $tbl_lp_item . "
  856. SET previous_item_id = " . $old_previous . "
  857. WHERE id = " . $old_next;
  858. $res_update_previous = api_sql_query($sql_update_previous, __FILE__, __LINE__);
  859. //echo '<p>' . $sql_update_previous . '</p>';
  860. }
  861. //display_order - 1 for every item with a display_order bigger then the display_order of the current item
  862. $sql_update_order = "
  863. UPDATE " . $tbl_lp_item . "
  864. SET display_order = display_order - 1
  865. WHERE
  866. display_order > " . $old_order . " AND
  867. parent_item_id = " . $old_parent;
  868. $res_update_order = api_sql_query($sql_update_order, __FILE__, __LINE__);
  869. //echo '<p>' . $sql_update_order . '</p>';
  870. /* END -- virtually remove the current item id */
  871. /* BEGIN -- update the current item id to his new location */
  872. if($previous == 0)
  873. {
  874. //select the data of the item that should come after the current item
  875. $sql_select_old = "
  876. SELECT
  877. id,
  878. display_order
  879. FROM " . $tbl_lp_item . "
  880. WHERE
  881. lp_id = " . $this->lp_id . " AND
  882. parent_item_id = " . $parent . " AND
  883. previous_item_id = " . $previous;
  884. $res_select_old = api_sql_query($sql_select_old, __FILE__, __LINE__);
  885. $row_select_old = Database::fetch_array($res_select_old);
  886. //echo '<p>' . $sql_select_old . '</p>';
  887. //if the new parent didn't have children before
  888. if(Database::num_rows($res_select_old) == 0)
  889. {
  890. $new_next = 0;
  891. $new_order = 1;
  892. }
  893. else
  894. {
  895. $new_next = $row_select_old['id'];
  896. $new_order = $row_select_old['display_order'];
  897. }
  898. //echo 'New next_item_id of current item: ' . $new_next . '<br />';
  899. //echo 'New previous_item_id of current item: ' . $previous . '<br />';
  900. //echo 'New display_order of current item: ' . $new_order . '<br />';
  901. }
  902. else
  903. {
  904. //select the data of the item that should come before the current item
  905. $sql_select_old = "
  906. SELECT
  907. next_item_id,
  908. display_order
  909. FROM " . $tbl_lp_item . "
  910. WHERE id = " . $previous;
  911. $res_select_old = api_sql_query($sql_select_old, __FILE__, __LINE__);
  912. $row_select_old = Database::fetch_array($res_select_old);
  913. //echo '<p>' . $sql_select_old . '</p>';
  914. //echo 'New next_item_id of current item: ' . $row_select_old['next_item_id'] . '<br />';
  915. //echo 'New previous_item_id of current item: ' . $previous . '<br />';
  916. //echo 'New display_order of current item: ' . ($row_select_old['display_order'] + 1) . '<br />';
  917. $new_next = $row_select_old['next_item_id'];
  918. $new_order = $row_select_old['display_order'] + 1;
  919. }
  920. //update the current item with the new data
  921. $sql_update = "
  922. UPDATE " . $tbl_lp_item . "
  923. SET
  924. title = '" . $this->escape_string(htmlentities($title)) . "',
  925. description = '" . $this->escape_string(htmlentities($description)) . "',
  926. parent_item_id = " . $parent . ",
  927. previous_item_id = " . $previous . ",
  928. next_item_id = " . $new_next . ",
  929. display_order = " . $new_order . "
  930. WHERE id = " . $id;
  931. $res_update_next = api_sql_query($sql_update, __FILE__, __LINE__);
  932. //echo '<p>' . $sql_update . '</p>';
  933. if($previous != 0)
  934. {
  935. //update the previous item's next_item_id
  936. $sql_update_previous = "
  937. UPDATE " . $tbl_lp_item . "
  938. SET next_item_id = " . $id . "
  939. WHERE id = " . $previous;
  940. $res_update_next = api_sql_query($sql_update_previous, __FILE__, __LINE__);
  941. //echo '<p>' . $sql_update_previous . '</p>';
  942. }
  943. if($new_next != 0)
  944. {
  945. //update the next item's previous_item_id
  946. $sql_update_next = "
  947. UPDATE " . $tbl_lp_item . "
  948. SET previous_item_id = " . $id . "
  949. WHERE id = " . $new_next;
  950. $res_update_next = api_sql_query($sql_update_next, __FILE__, __LINE__);
  951. //echo '<p>' . $sql_update_next . '</p>';
  952. }
  953. if($old_prerequisite!=$prerequisites){
  954. $sql_update_next = "
  955. UPDATE " . $tbl_lp_item . "
  956. SET prerequisite = " . $prerequisites . "
  957. WHERE id = " . $id;
  958. $res_update_next = api_sql_query($sql_update_next, __FILE__, __LINE__);
  959. }
  960. //update all the items with the same or a bigger display_order than
  961. //the current item
  962. $sql_update_order = "
  963. UPDATE " . $tbl_lp_item . "
  964. SET display_order = display_order + 1
  965. WHERE
  966. lp_id = " . $this->get_id() . " AND
  967. id <> " . $id . " AND
  968. parent_item_id = " . $parent . " AND
  969. display_order >= " . $new_order;
  970. $res_update_next = api_sql_query($sql_update_order, __FILE__, __LINE__);
  971. //echo '<p>' . $sql_update_order . '</p>';
  972. /* END -- update the current item id to his new location */
  973. }
  974. }
  975. /**
  976. * Updates an item's prereq in place
  977. * @param integer Element ID
  978. * @param string Prerequisite Element ID
  979. *
  980. * @param string Prerequisite item type
  981. *
  982. * @param string Prerequisite min score
  983. *
  984. * @param string Prerequisite max score
  985. * @return boolean True on success, false on error
  986. */
  987. function edit_item_prereq($id, $prerequisite_id, $mastery_score = 0, $max_score = 100)
  988. {
  989. if($this->debug>0){error_log('New LP - In learnpath::edit_item_prereq('.$id.','.$prerequisite_id.','.$mastery_score.','.$max_score.')',0);}
  990. if(empty($id) or ($id != strval(intval($id))) or empty($prerequisite_id)){ return false; }
  991. $prerequisite_id = $this->escape_string($prerequisite_id);
  992. $tbl_lp_item = Database::get_course_table('lp_item');
  993. if(!is_numeric($mastery_score) || $mastery_score < 0)
  994. $mastery_score = 0;
  995. if(!is_numeric($max_score) || $max_score < 0)
  996. $max_score = 100;
  997. if($mastery_score > $max_score)
  998. $max_score = $mastery_score;
  999. if(!is_numeric($prerequisite_id))
  1000. $prerequisite_id = 'NULL';
  1001. $sql_upd = "
  1002. UPDATE " . $tbl_lp_item . "
  1003. SET prerequisite = ".$prerequisite_id." WHERE id = ".$id;
  1004. $res_upd = api_sql_query($sql_upd ,__FILE__, __LINE__);
  1005. if($prerequisite_id!='NULL' && $prerequisite_id!='')
  1006. {
  1007. $sql_upd = " UPDATE ".$tbl_lp_item." SET
  1008. mastery_score = " . $mastery_score .
  1009. //", max_score = " . $max_score . " " . //max score cannot be changed in the form anyway - see display_item_prerequisites_form()
  1010. " WHERE ref = '" . $prerequisite_id."'" ; //will this be enough to ensure unicity?
  1011. $res_upd = api_sql_query($sql_upd ,__FILE__, __LINE__);
  1012. }
  1013. //TODO update the item object (can be ignored for now because refreshed)
  1014. return true;
  1015. }
  1016. /**
  1017. * Escapes a string with the available database escape function
  1018. * @param string String to escape
  1019. * @return string String escaped
  1020. */
  1021. function escape_string($string){
  1022. //if($this->debug>0){error_log('New LP - In learnpath::escape_string('.$string.')',0);}
  1023. return Database::escape_string($string);
  1024. }
  1025. /**
  1026. * Static admin function exporting a learnpath into a zip file
  1027. * @param string Export type (scorm, zip, cd)
  1028. * @param string Course code
  1029. * @param integer Learnpath ID
  1030. * @param string Zip file name
  1031. * @return string Zip file path (or false on error)
  1032. */
  1033. function export_lp($type, $course, $id, $zipname)
  1034. {
  1035. //if($this->debug>0){error_log('New LP - In learnpath::export_lp()',0);}
  1036. //TODO
  1037. if(empty($type) OR empty($course) OR empty($id) OR empty($zipname)){return false;}
  1038. $url = '';
  1039. switch($type){
  1040. case 'scorm':
  1041. break;
  1042. case 'zip':
  1043. break;
  1044. case 'cdrom':
  1045. break;
  1046. }
  1047. return $url;
  1048. }
  1049. /**
  1050. * Gets all the chapters belonging to the same parent as the item/chapter given
  1051. * Can also be called as abstract method
  1052. * @param integer Item ID
  1053. * @return array A list of all the "brother items" (or an empty array on failure)
  1054. */
  1055. function get_brother_chapters($id){
  1056. if($this->debug>0){error_log('New LP - In learnpath::get_brother_chapters()',0);}
  1057. if(empty($id) OR $id != strval(intval($id))){ return array();}
  1058. $lp_item = Database::get_course_table('lp_item');
  1059. $sql_parent = "SELECT * FROM $lp_item WHERE id = $id AND item_type='dokeos_chapter'";
  1060. $res_parent = api_sql_query($sql_parent,__FILE__,__LINE__);
  1061. if(Database::num_rows($res_parent)>0){
  1062. $row_parent = Database::fetch_array($res_parent);
  1063. $parent = $row_parent['parent_item_id'];
  1064. $sql_bros = "SELECT * FROM $lp_item WHERE parent_item_id = $parent AND id = $id AND item_type='dokeos_chapter' ORDER BY display_order";
  1065. $res_bros = api_sql_query($sql_bros,__FILE__,__LINE__);
  1066. $list = array();
  1067. while ($row_bro = Database::fetch_array($res_bros)){
  1068. $list[] = $row_bro;
  1069. }
  1070. return $list;
  1071. }
  1072. return array();
  1073. }
  1074. /**
  1075. * Gets all the items belonging to the same parent as the item given
  1076. * Can also be called as abstract method
  1077. * @param integer Item ID
  1078. * @return array A list of all the "brother items" (or an empty array on failure)
  1079. */
  1080. function get_brother_items($id){
  1081. if($this->debug>0){error_log('New LP - In learnpath::get_brother_items('.$id.')',0);}
  1082. if(empty($id) OR $id != strval(intval($id))){ return array();}
  1083. $lp_item = Database::get_course_table('lp_item');
  1084. $sql_parent = "SELECT * FROM $lp_item WHERE id = $id";
  1085. $res_parent = api_sql_query($sql_parent,__FILE__,__LINE__);
  1086. if(Database::num_rows($res_parent)>0){
  1087. $row_parent = Database::fetch_array($res_parent);
  1088. $parent = $row_parent['parent_item_id'];
  1089. $sql_bros = "SELECT * FROM $lp_item WHERE parent_item_id = $parent ORDER BY display_order";
  1090. $res_bros = api_sql_query($sql_bros,__FILE__,__LINE__);
  1091. $list = array();
  1092. while ($row_bro = Database::fetch_array($res_bros)){
  1093. $list[] = $row_bro;
  1094. }
  1095. return $list;
  1096. }
  1097. return array();
  1098. }
  1099. /**
  1100. * Gets the number of items currently completed
  1101. * @return integer The number of items currently completed
  1102. */
  1103. function get_complete_items_count()
  1104. {
  1105. if($this->debug>0){error_log('New LP - In learnpath::get_complete_items_count()',0);}
  1106. $i = 0;
  1107. foreach($this->items as $id => $dummy){
  1108. //if($this->items[$id]->status_is(array('completed','passed','succeeded'))){
  1109. //Trying failed and browsed considered "progressed" as well
  1110. if($this->items[$id]->status_is(array('completed','passed','succeeded','browsed','failed'))&&$this->items[$id]->get_type()!='dokeos_chapter'&&$this->items[$id]->get_type()!='dir'){
  1111. $i++;
  1112. }
  1113. }
  1114. return $i;
  1115. }
  1116. /**
  1117. * Gets the current item ID
  1118. * @return integer The current learnpath item id
  1119. */
  1120. function get_current_item_id()
  1121. {
  1122. $current = 0;
  1123. if($this->debug>0){error_log('New LP - In learnpath::get_current_item_id()',0);}
  1124. if(!empty($this->current))
  1125. {
  1126. $current = $this->current;
  1127. }
  1128. if($this->debug>2){error_log('New LP - In learnpath::get_current_item_id() - Returning '.$current,0);}
  1129. return $current;
  1130. }
  1131. /**
  1132. * Gets the total number of items available for viewing in this SCORM
  1133. * @return integer The total number of items
  1134. */
  1135. function get_total_items_count()
  1136. {
  1137. if($this->debug>0){error_log('New LP - In learnpath::get_total_items_count()',0);}
  1138. return count($this->items);
  1139. }
  1140. /**
  1141. * Gets the total number of items available for viewing in this SCORM but without chapters
  1142. * @return integer The total no-chapters number of items
  1143. */
  1144. function get_total_items_count_without_chapters()
  1145. {
  1146. if($this->debug>0){error_log('New LP - In learnpath::get_total_items_count_without_chapters()',0);}
  1147. $total=0;
  1148. foreach($this->items as $temp=>$temp2){
  1149. if(!in_array($temp2->get_type(), array('dokeos_chapter','chapter','dir'))) $total++;
  1150. }
  1151. return $total;
  1152. }
  1153. /**
  1154. * Gets the first element URL.
  1155. * @return string URL to load into the viewer
  1156. */
  1157. function first()
  1158. {
  1159. if($this->debug>0){error_log('New LP - In learnpath::first()',0);}
  1160. //test if the last_item_seen exists and is not a dir
  1161. if(!empty($this->last_item_seen)
  1162. && !empty($this->items[$this->last_item_seen])
  1163. && $this->items[$this->last_item_seen]->get_type() != 'dir'
  1164. && $this->items[$this->last_item_seen]->get_type() != 'dokeos_chapter'
  1165. && $this->items[$this->last_item_seen]->is_done() != true
  1166. ){
  1167. if($this->debug>2){error_log('New LP - In learnpath::first() - Last item seen is '.$this->last_item_seen.' of type '.$this->items[$this->last_item_seen]->get_type(),0);}
  1168. $index = -1;
  1169. foreach($this->ordered_items as $myindex => $item_id){
  1170. if($item_id == $this->last_item_seen){
  1171. $index = $myindex;
  1172. break;
  1173. }
  1174. }
  1175. if($index==-1){
  1176. //index hasn't changed, so item not found - panic (this shouldn't happen)
  1177. if($this->debug>2){error_log('New LP - Last item ('.$this->last_item_seen.') was found in items but not in ordered_items, panic!',0);}
  1178. return false;
  1179. }else{
  1180. $this->last = $this->last_item_seen;
  1181. $this->current = $this->last_item_seen;
  1182. $this->index = $index;
  1183. }
  1184. }else{
  1185. if($this->debug>2){error_log('New LP - In learnpath::first() - No last item seen',0);}
  1186. $index = 0;
  1187. //loop through all ordered items and stop at the first item that is
  1188. //not a directory *and* that has not been completed yet
  1189. while (!empty($this->ordered_items[$index])
  1190. AND
  1191. is_a($this->items[$this->ordered_items[$index]],'learnpathItem')
  1192. AND
  1193. (
  1194. $this->items[$this->ordered_items[$index]]->get_type() == 'dir'
  1195. OR $this->items[$this->ordered_items[$index]]->get_type() == 'dokeos_chapter'
  1196. OR $this->items[$this->ordered_items[$index]]->is_done() === true
  1197. )
  1198. AND $index < $this->max_ordered_items)
  1199. {
  1200. $index ++;
  1201. }
  1202. $this->last = $this->current;
  1203. //current is
  1204. $this->current = $this->ordered_items[$index];
  1205. $this->index = $index;
  1206. if($this->debug>2){error_log('New LP - In learnpath::first() - No last item seen. New last = '.$this->last.'('.$this->ordered_items[$index].')',0);}
  1207. }
  1208. if($this->debug>2){error_log('New LP - In learnpath::first() - First item is '.$this->get_current_item_id());}
  1209. }
  1210. /**
  1211. * Gets the information about an item in a format usable as JavaScript to update
  1212. * the JS API by just printing this content into the <head> section of the message frame
  1213. * @param integer Item ID
  1214. * @return string
  1215. */
  1216. function get_js_info($item_id=''){
  1217. if($this->debug>0){error_log('New LP - In learnpath::get_js_info('.$item_id.')',0);}
  1218. $info = '';
  1219. $item_id = $this->escape_string($item_id);
  1220. if(!empty($item_id) && is_object($this->items[$item_id])){
  1221. //if item is defined, return values from DB
  1222. $oItem = $this->items[$item_id];
  1223. $info .= '<script language="javascript">';
  1224. $info .= "top.set_score(".$oItem->get_score().");\n";
  1225. $info .= "top.set_max(".$oItem->get_max().");\n";
  1226. $info .= "top.set_min(".$oItem->get_min().");\n";
  1227. $info .= "top.set_lesson_status('".$oItem->get_status()."');";
  1228. $info .= "top.set_session_time('".$oItem->get_scorm_time('js')."');";
  1229. $info .= "top.set_suspend_data('".$oItem->get_suspend_data()."');";
  1230. $info .= "top.set_saved_lesson_status('".$oItem->get_status()."');";
  1231. $info .= "top.set_flag_synchronized();";
  1232. $info .= '</script>';
  1233. if($this->debug>2){error_log('New LP - in learnpath::get_js_info('.$item_id.') - returning: '.$info,0);}
  1234. return $info;
  1235. }else{
  1236. //if item_id is empty, just update to default SCORM data
  1237. $info .= '<script language="javascript">';
  1238. $info .= "top.set_score(".learnpathItem::get_score().");\n";
  1239. $info .= "top.set_max(".learnpathItem::get_max().");\n";
  1240. $info .= "top.set_min(".learnpathItem::get_min().");\n";
  1241. $info .= "top.set_lesson_status('".learnpathItem::get_status()."');";
  1242. $info .= "top.set_session_time('".learnpathItem::get_scorm_time('js')."');";
  1243. $info .= "top.set_suspend_data('".learnpathItem::get_suspend_data()."');";
  1244. $info .= "top.set_saved_lesson_status('".learnpathItem::get_status()."');";
  1245. $info .= "top.set_flag_synchronized();";
  1246. $info .= '</script>';
  1247. if($this->debug>2){error_log('New LP - in learnpath::get_js_info('.$item_id.') - returning: '.$info,0);}
  1248. return $info;
  1249. }
  1250. }
  1251. /**
  1252. * Gets the js library from the database
  1253. * @return string The name of the javascript library to be used
  1254. */
  1255. function get_js_lib(){
  1256. $lib = '';
  1257. if(!empty($this->js_lib)){
  1258. $lib = $this->js_lib;
  1259. }
  1260. return $lib;
  1261. }
  1262. /**
  1263. * Gets the learnpath database ID
  1264. * @return integer Learnpath ID in the lp table
  1265. */
  1266. function get_id()
  1267. {
  1268. if($this->debug>0){error_log('New LP - In learnpath::get_id()',0);}
  1269. if(!empty($this->lp_id))
  1270. {
  1271. return $this->lp_id;
  1272. }else{
  1273. return 0;
  1274. }
  1275. }
  1276. /**
  1277. * Gets the last element URL.
  1278. * @return string URL to load into the viewer
  1279. */
  1280. function get_last()
  1281. {
  1282. if($this->debug>0){error_log('New LP - In learnpath::get_last()',0);}
  1283. $this->index = count($this->ordered_items)-1;
  1284. return $this->ordered_items[$this->index];
  1285. }
  1286. /**
  1287. * Gets the navigation bar for the learnpath display screen
  1288. * @return string The HTML string to use as a navigation bar
  1289. */
  1290. function get_navigation_bar()
  1291. {
  1292. if($this->debug>0){error_log('New LP - In learnpath::get_navigation_bar()',0);}
  1293. //TODO find a good value for the following variables
  1294. $file = '';
  1295. $openDir = '';
  1296. $edoceo = '';
  1297. $time = 0;
  1298. $navbar = '';
  1299. $RequestUri = '';
  1300. $mycurrentitemid = $this->get_current_item_id();
  1301. if($this->mode == 'fullscreen'){
  1302. $navbar = '<table cellpadding="0" cellspacing="0" align="left">'."\n".
  1303. ' <tr> '."\n" .
  1304. ' <td>'."\n" .
  1305. ' <div class="buttons">'."\n" .
  1306. ' <a href="lp_controller.php?action=stats" onclick="window.parent.API.save_asset();return true;" target="content_name_blank" title="stats" id="stats_link"><img border="0" src="../img/lp_stats.gif" title="'.get_lang('ScormMystatus').'"></a>&nbsp;'."\n" .
  1307. ' <a href="" onclick="dokeos_xajax_handler.switch_item('.$mycurrentitemid.',\'previous\');return false;" title="previous"><img border="0" src="../img/lp_leftarrow.gif" title="'.get_lang('ScormPrevious').'"></a>&nbsp;'."\n" .
  1308. ' <a href="" onclick="dokeos_xajax_handler.switch_item('.$mycurrentitemid.',\'next\');return false;" title="next" ><img border="0" src="../img/lp_rightarrow.gif" title="'.get_lang('ScormNext').'"></a>&nbsp;'."\n" .
  1309. ' <a href="lp_controller.php?action=mode&mode=embedded" target="_top" title="embedded mode"><img border="0" src="../img/view_choose.gif" title="'.get_lang('ScormExitFullScreen').'"></a>'."\n" .
  1310. //' <a href="lp_controller.php?action=list" target="_top" title="learnpaths list"><img border="0" src="../img/exit.png" title="Exit"></a>'."\n" .
  1311. ' </div>'."\n" .
  1312. ' </td>'."\n" .
  1313. ' </tr>'."\n" .
  1314. '</table>'."\n" ;
  1315. }else{
  1316. $navbar = '<table cellpadding="0" cellspacing="0" align="left">'."\n".
  1317. ' <tr> '."\n" .
  1318. ' <td>'."\n" .
  1319. ' <div class="buttons">'."\n" .
  1320. ' <a href="lp_controller.php?action=stats" onclick="window.parent.API.save_asset();return true;" target="content_name" title="stats" id="stats_link"><img border="0" src="../img/lp_stats.gif" title="'.get_lang('ScormMystatus').'"></a>&nbsp;'."\n" .
  1321. ' <a href="" onclick="dokeos_xajax_handler.switch_item('.$mycurrentitemid.',\'previous\');return false;" title="previous"><img border="0" src="../img/lp_leftarrow.gif" title="'.get_lang('ScormPrevious').'"></a>&nbsp;'."\n" .
  1322. ' <a href="" onclick="dokeos_xajax_handler.switch_item('.$mycurrentitemid.',\'next\');return false;" title="next" ><img border="0" src="../img/lp_rightarrow.gif" title="'.get_lang('ScormNext').'"></a>&nbsp;'."\n" .
  1323. ' <a href="lp_controller.php?action=mode&mode=fullscreen" target="_top" title="fullscreen"><img border="0" src="../img/view_fullscreen.gif" width="18" height="18" title="'.get_lang('ScormFullScreen').'"></a>'."\n" .
  1324. ' </div>'."\n" .
  1325. ' </td>'."\n" .
  1326. ' </tr>'."\n" .
  1327. '</table>'."\n" ;
  1328. }
  1329. return $navbar;
  1330. }
  1331. /**
  1332. * Gets the next resource in queue (url).
  1333. * @return string URL to load into the viewer
  1334. */
  1335. function get_next_index()
  1336. {
  1337. if($this->debug>0){error_log('New LP - In learnpath::get_next_index()',0);}
  1338. //TODO
  1339. $index = $this->index;
  1340. $index ++;
  1341. if($this->debug>2){error_log('New LP - Now looking at ordered_items['.($index).'] - type is '.$this->items[$this->ordered_items[$index]]->type,0);}
  1342. while(!empty($this->ordered_items[$index]) AND ($this->items[$this->ordered_items[$index]]->get_type() == 'dir' || $this->items[$this->ordered_items[$index]]->get_type() == 'dokeos_chapter') AND $index < $this->max_ordered_items)
  1343. {
  1344. $index ++;
  1345. if($index == $this->max_ordered_items)
  1346. {
  1347. return $this->index;
  1348. }
  1349. }
  1350. if(empty($this->ordered_items[$index])){
  1351. return $this->index;
  1352. }
  1353. if($this->debug>2){error_log('New LP - index is now '.$index,0);}
  1354. return $index;
  1355. }
  1356. /**
  1357. * Gets item_id for the next element
  1358. * @return integer Next item (DB) ID
  1359. */
  1360. function get_next_item_id()
  1361. {
  1362. if($this->debug>0){error_log('New LP - In learnpath::get_next_item_id()',0);}
  1363. $new_index = $this->get_next_index();
  1364. if(!empty($new_index))
  1365. {
  1366. if(isset($this->ordered_items[$new_index]))
  1367. {
  1368. if($this->debug>2){error_log('New LP - In learnpath::get_next_index() - Returning '.$this->ordered_items[$new_index],0);}
  1369. return $this->ordered_items[$new_index];
  1370. }
  1371. }
  1372. if($this->debug>2){error_log('New LP - In learnpath::get_next_index() - Problem - Returning 0',0);}
  1373. return 0;
  1374. }
  1375. /**
  1376. * Returns the package type ('scorm','aicc','scorm2004','dokeos','ppt'...)
  1377. *
  1378. * Generally, the package provided is in the form of a zip file, so the function
  1379. * has been written to test a zip file. If not a zip, the function will return the
  1380. * default return value: ''
  1381. * @param string the path to the file
  1382. * @param string the original name of the file
  1383. * @return string 'scorm','aicc','scorm2004','dokeos' or '' if the package cannot be recognized
  1384. */
  1385. function get_package_type($file_path,$file_name){
  1386. //get name of the zip file without the extension
  1387. $file_info = pathinfo($file_name);
  1388. $filename = $file_info['basename'];//name including extension
  1389. $extension = $file_info['extension'];//extension only
  1390. if(!empty($_POST['ppt2lp']) && !in_array($extension,array('dll','exe')))
  1391. {
  1392. return 'oogie';
  1393. }
  1394. if(!empty($_POST['woogie']) && !in_array($extension,array('dll','exe')))
  1395. {
  1396. return 'woogie';
  1397. }
  1398. $file_base_name = str_replace('.'.$extension,'',$filename); //filename without its extension
  1399. $zipFile = new pclZip($file_path);
  1400. // Check the zip content (real size and file extension)
  1401. $zipContentArray = $zipFile->listContent();
  1402. $package_type='';
  1403. $at_root = false;
  1404. $manifest = '';
  1405. //the following loop should be stopped as soon as we found the right imsmanifest.xml (how to recognize it?)
  1406. foreach($zipContentArray as $thisContent)
  1407. {
  1408. if ( preg_match('~.(php.*|phtml)$~i', $thisContent['filename']) )
  1409. {
  1410. //New behaviour: Don't do anything. These files will be removed in scorm::import_package
  1411. }
  1412. elseif(stristr($thisContent['filename'],'imsmanifest.xml')!==FALSE)
  1413. {
  1414. $manifest = $thisContent['filename']; //just the relative directory inside scorm/
  1415. $package_type = 'scorm';
  1416. break;//exit the foreach loop
  1417. }
  1418. elseif(preg_match('/aicc\//i',$thisContent['filename'])!=false)
  1419. {//if found an aicc directory... (!= false means it cannot be false (error) or 0 (no match))
  1420. $package_type='aicc';
  1421. //break;//don't exit the loop, because if we find an imsmanifest afterwards, we want it, not the AICC
  1422. }
  1423. else
  1424. {
  1425. $package_type = '';
  1426. }
  1427. }
  1428. return $package_type;
  1429. }
  1430. /**
  1431. * Gets the previous resource in queue (url). Also initialises time values for this viewing
  1432. * @return string URL to load into the viewer
  1433. */
  1434. function get_previous_index()
  1435. {
  1436. if($this->debug>0){error_log('New LP - In learnpath::get_previous_index()',0);}
  1437. $index = $this->index;
  1438. if(isset($this->ordered_items[$index-1])){
  1439. $index --;
  1440. while(isset($this->ordered_items[$index]) AND ($this->items[$this->ordered_items[$index]]->get_type() == 'dir' || $this->items[$this->ordered_items[$index]]->get_type() == 'dokeos_chapter'))
  1441. {
  1442. $index --;
  1443. if($index < 0){
  1444. return $this->index;
  1445. }
  1446. }
  1447. }else{
  1448. if($this->debug>2){error_log('New LP - get_previous_index() - there was no previous index available, reusing '.$index,0);}
  1449. //no previous item
  1450. }
  1451. return $index;
  1452. }
  1453. /**
  1454. * Gets item_id for the next element
  1455. * @return integer Previous item (DB) ID
  1456. */
  1457. function get_previous_item_id()
  1458. {
  1459. $new_index = $this->get_previous_index();
  1460. return $this->ordered_items[$new_index];
  1461. }
  1462. /**
  1463. * Gets the progress value from the progress_db attribute
  1464. * @return integer Current progress value
  1465. */
  1466. function get_progress()
  1467. {
  1468. if($this->debug>0){error_log('New LP - In learnpath::get_progress()',0);}
  1469. if(!empty($this->progress_db))
  1470. {
  1471. return $this->progress_db;
  1472. }
  1473. return 0;
  1474. }
  1475. /**
  1476. * Gets the progress value from the progress field in the database (allows use as abstract method)
  1477. * @param integer Learnpath ID
  1478. * @param integer User ID
  1479. * @param string Mode of display ('%','abs' or 'both')
  1480. * @param string Course database name (optional, defaults to '')
  1481. * @param boolean Whether to return null if no record was found (true), or 0 (false) (optional, defaults to false)
  1482. * @return integer Current progress value as found in the database
  1483. */
  1484. function get_db_progress($lp_id,$user_id,$mode='%', $course_db='', $sincere=false)
  1485. {
  1486. //if($this->debug>0){error_log('New LP - In learnpath::get_db_progress()',0);}
  1487. $table = Database::get_course_table('lp_view', $course_db);
  1488. $sql = "SELECT * FROM $table WHERE lp_id = $lp_id AND user_id = $user_id";
  1489. $res = api_sql_query($sql,__FILE__,__LINE__);
  1490. $view_id = 0;
  1491. if(Database::num_rows($res)>0)
  1492. {
  1493. $row = Database::fetch_array($res);
  1494. $progress = $row['progress'];
  1495. $view_id = $row['id'];
  1496. }
  1497. else
  1498. {
  1499. if($sincere)
  1500. {
  1501. return null;
  1502. }
  1503. }
  1504. if(!$progress)
  1505. {
  1506. $progress = '0';
  1507. }
  1508. if($mode == '%')
  1509. {
  1510. return $progress.'%';
  1511. }
  1512. else
  1513. {
  1514. //get the number of items completed and the number of items total
  1515. $tbl = Database::get_course_table('lp_item', $course_db);
  1516. $sql = "SELECT count(*) FROM $tbl WHERE lp_id = ".$lp_id."
  1517. AND item_type NOT IN('dokeos_chapter','chapter','dir')";
  1518. $res = api_sql_query($sql, __FILE__, __LINE__);
  1519. $row = Database::fetch_array($res);
  1520. $total = $row[0];
  1521. $tbl_item_view = Database::get_course_table('lp_item_view', $course_db);
  1522. $tbl_item = Database::get_course_table('lp_item', $course_db);
  1523. //$sql = "SELECT count(distinct(lp_item_id)) FROM $tbl WHERE lp_view_id = ".$view_id." AND status IN ('passed','completed','succeeded')";
  1524. //trying as also counting browsed and failed items
  1525. $sql = "SELECT count(distinct(lp_item_id))
  1526. FROM $tbl_item_view as item_view
  1527. INNER JOIN $tbl_item as item
  1528. ON item.id = item_view.lp_item_id
  1529. AND item_type NOT IN('dokeos_chapter','chapter','dir')
  1530. WHERE lp_view_id = ".$view_id."
  1531. AND status IN ('passed','completed','succeeded','browsed','failed')";
  1532. $res = api_sql_query($sql, __FILE__, __LINE__);
  1533. $row = Database::fetch_array($res);
  1534. $completed = $row[0];
  1535. if($mode == 'abs')
  1536. {
  1537. return $completed.'/'.$total;
  1538. }
  1539. elseif($mode == 'both')
  1540. {
  1541. if($progress<($completed/($total?$total:1)))
  1542. {
  1543. $progress = number_format(($completed/($total?$total:1))*100,0);
  1544. }
  1545. return $progress.'% ('.$completed.'/'.$total.')';
  1546. }
  1547. }
  1548. return $progress;
  1549. }
  1550. /**
  1551. * Gets a progress bar for the learnpath by counting the number of items in it and the number of items
  1552. * completed so far.
  1553. * @param string Mode in which we want the values
  1554. * @param integer Progress value to display (optional but mandatory if used in abstract context)
  1555. * @param string Text to display near the progress value (optional but mandatory in abstract context)
  1556. * @return string HTML string containing the progress bar
  1557. */
  1558. function get_progress_bar($mode='',$percentage=-1,$text_add='')
  1559. {
  1560. global $lp_theme_css;
  1561. // Setting up the CSS path of the current style if exists
  1562. if (!empty($lp_theme_css))
  1563. {
  1564. $css_path=api_get_path(WEB_CODE_PATH).'css/'.$lp_theme_css.'/images/';
  1565. }
  1566. else
  1567. {
  1568. $css_path='../img/';
  1569. }
  1570. //if($this->debug>0){error_log('New LP - In learnpath::get_progress_bar()',0);}
  1571. if(is_object($this) && ($percentage=='-1' OR $text_add==''))
  1572. {
  1573. list ($percentage, $text_add) = $this->get_progress_bar_text($mode);
  1574. }
  1575. $text = $percentage.$text_add;
  1576. $size = str_replace('%','',$percentage);
  1577. $output = ''
  1578. //.htmlentities(get_lang('ScormCompstatus'),ENT_QUOTES,'ISO-8859-1')."<br />"
  1579. .'<table border="0" cellpadding="0" cellspacing="0"><tr><td>'
  1580. .'<img id="progress_img_limit_left" src="'.$css_path.'bar_1.gif" width="1" height="12">'
  1581. .'<img id="progress_img_full" src="'.$css_path.'bar_1u.gif" width="'.$size.'px" height="12" id="full_portion">'
  1582. .'<img id="progress_img_limit_middle" src="'.$css_path.'bar_1m.gif" width="1" height="12">';
  1583. if($percentage <= 98)
  1584. {
  1585. $output .= '<img id="progress_img_empty" src="'.$css_path.'bar_1r.gif" width="'.(100-$size).'px" height="12" id="empty_portion">';
  1586. }
  1587. else
  1588. {
  1589. $output .= '<img id="progress_img_empty" src="'.$css_path.'bar_1r.gif" width="0" height="12" id="empty_portion">';
  1590. }
  1591. $output .= '<img id="progress_bar_img_limit_right" src="'.$css_path.'bar_1.gif" width="1" height="12"></td></tr></table>'
  1592. .'<div class="progresstext" id="progress_text">'.$text.'</div>';
  1593. return $output;
  1594. }
  1595. /**
  1596. * Gets the progress bar info to display inside the progress bar. Also used by scorm_api.php
  1597. * @param string Mode of display (can be '%' or 'abs').abs means we display a number of completed elements per total elements
  1598. * //@param integer Additional steps to fake as completed
  1599. * @return list Percentage or number and symbol (% or /xx)
  1600. */
  1601. function get_progress_bar_text($mode='',$add=0)
  1602. {
  1603. if($this->debug>0){error_log('New LP - In learnpath::get_progress_bar_text()',0);}
  1604. if(empty($mode)){$mode = $this->progress_bar_mode;}
  1605. $total_items = $this->get_total_items_count_without_chapters();
  1606. if($this->debug>2){error_log('New LP - Total items available in this learnpath: '.$total_items,0);}
  1607. $i = $this->get_complete_items_count();
  1608. if($this->debug>2){error_log('New LP - Items completed so far: '.$i,0);}
  1609. if($add != 0){
  1610. $i += $add;
  1611. if($this->debug>2){error_log('New LP - Items completed so far (+modifier): '.$i,0);}
  1612. }
  1613. $text = '';
  1614. if($i>$total_items){
  1615. $i = $total_items;
  1616. }
  1617. if($mode == '%'){
  1618. if($total_items>0){
  1619. $percentage = ((float)$i/(float)$total_items)*100;
  1620. }
  1621. else
  1622. {
  1623. $percentage = 0;
  1624. }
  1625. $percentage = number_format($percentage,0);
  1626. $text = '%';
  1627. }elseif($mode == 'abs'){
  1628. $percentage = $i;
  1629. $text = '/'.$total_items;
  1630. }
  1631. return array($percentage,$text);
  1632. }
  1633. /**
  1634. * Gets the progress bar mode
  1635. * @return string The progress bar mode attribute
  1636. */
  1637. function get_progress_bar_mode()
  1638. {
  1639. if($this->debug>0){error_log('New LP - In learnpath::get_progress_bar_mode()',0);}
  1640. if(!empty($this->progress_bar_mode))
  1641. {
  1642. return $this->progress_bar_mode;
  1643. }else{
  1644. return '%';
  1645. }
  1646. }
  1647. /**
  1648. * Gets the learnpath proximity (remote or local)
  1649. * @return string Learnpath proximity
  1650. */
  1651. function get_proximity()
  1652. {
  1653. if($this->debug>0){error_log('New LP - In learnpath::get_proximity()',0);}
  1654. if(!empty($this->proximity)){return $this->proximity;}else{return '';}
  1655. }
  1656. /**
  1657. * Gets the learnpath theme (remote or local)
  1658. * @return string Learnpath theme
  1659. */
  1660. function get_theme()
  1661. {
  1662. if($this->debug>0){error_log('New LP - In learnpath::get_theme()',0);}
  1663. if(!empty($this->theme)){return $this->theme;}else{return '';}
  1664. }
  1665. /**
  1666. * Generate a new prerequisites string for a given item. If this item was a sco and
  1667. * its prerequisites were strings (instead of IDs), then transform those strings into
  1668. * IDs, knowing that SCORM IDs are kept in the "ref" field of the lp_item table.
  1669. * Prefix all item IDs that end-up in the prerequisites string by "ITEM_" to use the
  1670. * same rule as the scorm_export() method
  1671. * @param integer Item ID
  1672. * @return string Prerequisites string ready for the export as SCORM
  1673. */
  1674. function get_scorm_prereq_string($item_id)
  1675. {
  1676. if($this->debug>0){error_log('New LP - In learnpath::get_scorm_prereq_string()',0);}
  1677. if(!is_object($this->items[$item_id])){return false;}
  1678. $oItem = $this->items[$item_id];
  1679. $prereq = $oItem->get_prereq_string();
  1680. if(empty($prereq))
  1681. {
  1682. return '';
  1683. }
  1684. if(preg_match('/^\d+$/',$prereq) && is_object($this->items[$prereq]))
  1685. { //if the prerequisite is a simple integer ID and this ID exists as an item ID,
  1686. //then simply return it (with the ITEM_ prefix)
  1687. return 'ITEM_'.$prereq;
  1688. }
  1689. else
  1690. {
  1691. if(isset($this->refs_list[$prereq]))
  1692. {
  1693. //it's a simple string item from which the ID can be found in the refs list
  1694. //so we can transform it directly to an ID for export
  1695. return 'ITEM_'.$this->refs_list[$prereq];
  1696. }
  1697. else
  1698. {
  1699. //last case, if it's a complex form, then find all the IDs (SCORM strings)
  1700. //and replace them, one by one, by the internal IDs (dokeos db)
  1701. //TODO modify the '*' replacement to replace the multiplier in front of it
  1702. //by a space as well
  1703. $find = array('&','|','~','=','<>','{','}','*','(',')');
  1704. $replace = array(' ',' ',' ',' ',' ',' ',' ',' ',' ',' ');
  1705. $prereq_mod = str_replace($find,$replace,$prereq);
  1706. $ids = split(' ',$prereq_mod);
  1707. foreach($ids as $id)
  1708. {
  1709. $id = trim($id);
  1710. if(isset($this->refs_list[$id]))
  1711. {
  1712. $prereq = preg_replace('/[^a-zA-Z_0-9]('.$id.')[^a-zA-Z_0-9]/','ITEM_'.$this->refs_list[$id],$prereq);
  1713. }
  1714. }
  1715. error_log('New LP - In learnpath::get_scorm_prereq_string(): returning modified string: '.$prereq,0);
  1716. return $prereq;
  1717. }
  1718. }
  1719. }
  1720. /**
  1721. * Returns the XML DOM document's node
  1722. * @param resource Reference to a list of objects to search for the given ITEM_*
  1723. * @param string The identifier to look for
  1724. * @return mixed The reference to the element found with that identifier. False if not found
  1725. */
  1726. function get_scorm_xml_node(&$children,$id)
  1727. {
  1728. for($i=0;$i<$children->length;$i++){
  1729. $item_temp = $children->item($i);
  1730. if ($item_temp -> nodeName == 'item')
  1731. {
  1732. if($item_temp->getAttribute('identifier') == $id)
  1733. {
  1734. return $item_temp;
  1735. }
  1736. }
  1737. $subchildren = $item_temp->childNodes;
  1738. if($subchildren->length>0)
  1739. {
  1740. $val = $this->get_scorm_xml_node($subchildren,$id);
  1741. if(is_object($val))
  1742. {
  1743. return $val;
  1744. }
  1745. }
  1746. }
  1747. return false;
  1748. }
  1749. /**
  1750. * Returns a usable array of stats related to the current learnpath and user
  1751. * @return array Well-formatted array containing status for the current learnpath
  1752. */
  1753. function get_stats()
  1754. {
  1755. if($this->debug>0){error_log('New LP - In learnpath::get_stats()',0);}
  1756. //TODO
  1757. }
  1758. /**
  1759. * Static method. Can be re-implemented by children. Gives an array of statistics for
  1760. * the given course (for all learnpaths and all users)
  1761. * @param string Course code
  1762. * @return array Well-formatted array containing status for the course's learnpaths
  1763. */
  1764. function get_stats_course($course)
  1765. {
  1766. //if($this->debug>0){error_log('New LP - In learnpath::get_stats_course()',0);}
  1767. //TODO
  1768. }
  1769. /**
  1770. * Static method. Can be re-implemented by children. Gives an array of statistics for
  1771. * the given course and learnpath (for all users)
  1772. * @param string Course code
  1773. * @param integer Learnpath ID
  1774. * @return array Well-formatted array containing status for the specified learnpath
  1775. */
  1776. function get_stats_lp($course,$lp)
  1777. {
  1778. //if($this->debug>0){error_log('New LP - In learnpath::get_stats_lp()',0);}
  1779. //TODO
  1780. }
  1781. /**
  1782. * Static method. Can be re-implemented by children. Gives an array of statistics for
  1783. * the given course, learnpath and user.
  1784. * @param string Course code
  1785. * @param integer Learnpath ID
  1786. * @param integer User ID
  1787. * @return array Well-formatted array containing status for the specified learnpath and user
  1788. */
  1789. function get_stats_lp_user($course,$lp,$user)
  1790. {
  1791. //if($this->debug>0){error_log('New LP - In learnpath::get_stats_lp_user()',0);}
  1792. //TODO
  1793. }
  1794. /**
  1795. * Static method. Can be re-implemented by children. Gives an array of statistics for
  1796. * the given course and learnpath (for all users)
  1797. * @param string Course code
  1798. * @param integer User ID
  1799. * @return array Well-formatted array containing status for the user's learnpaths
  1800. */
  1801. function get_stats_user($course,$user)
  1802. {
  1803. //if($this->debug>0){error_log('New LP - In learnpath::get_stats_user()',0);}
  1804. //TODO
  1805. }
  1806. /**
  1807. * Gets the status list for all LP's items
  1808. * @return array Array of [index] => [item ID => current status]
  1809. */
  1810. function get_items_status_list(){
  1811. if($this->debug>0){error_log('New LP - In learnpath::get_items_status_list()',0);}
  1812. $list = array();
  1813. foreach($this->ordered_items as $item_id)
  1814. {
  1815. $list[]= array($item_id => $this->items[$item_id]->get_status());
  1816. }
  1817. return $list;
  1818. }
  1819. /**
  1820. * Return the number of interactions for the given learnpath Item View ID.
  1821. * This method can be used as static.
  1822. * @param integer Item View ID
  1823. * @return integer Number of interactions
  1824. */
  1825. function get_interactions_count_from_db($lp_iv_id=0){
  1826. if(empty($lp_iv_id)){return -1;}
  1827. $table = Database::get_course_table('lp_iv_interaction');
  1828. $sql = "SELECT count(*) FROM $table WHERE lp_iv_id = $lp_iv_id";
  1829. $res = api_sql_query($sql,__FILE__,__LINE__);
  1830. $row = Database::fetch_array($res);
  1831. $num = $row[0];
  1832. return $num;
  1833. }
  1834. /**
  1835. * Return the interactions as an array for the given lp_iv_id.
  1836. * This method can be used as static.
  1837. * @param integer Learnpath Item View ID
  1838. * @return array
  1839. * @todo Translate labels
  1840. */
  1841. function get_iv_interactions_array($lp_iv_id=0){
  1842. $list = array();
  1843. $table = Database::get_course_table('lp_iv_interaction');
  1844. $sql = "SELECT * FROM $table WHERE lp_iv_id = $lp_iv_id ORDER BY order_id ASC";
  1845. $res = api_sql_query($sql,__FILE__,__LINE__);
  1846. $num = Database::num_rows($res);
  1847. if($num>0){
  1848. $list[] = array(
  1849. "order_id"=>htmlentities(get_lang('Order')),
  1850. "id"=>htmlentities(get_lang('InteractionID')),
  1851. "type"=>htmlentities(get_lang('Type')),
  1852. "time"=>htmlentities(get_lang('TimeFinished')),
  1853. "correct_responses"=>htmlentities(get_lang('CorrectAnswers')),
  1854. "student_response"=>htmlentities(get_lang('StudentResponse')),
  1855. "result"=>htmlentities(get_lang('Result')),
  1856. "latency"=>htmlentities(get_lang('LatencyTimeSpent')));
  1857. while ($row = Database::fetch_array($res)){
  1858. $list[] = array(
  1859. "order_id"=>($row['order_id']+1),
  1860. "id"=>urldecode($row['interaction_id']),//urldecode because they often have %2F or stuff like that
  1861. "type"=>$row['interaction_type'],
  1862. "time"=>$row['completion_time'],
  1863. //"correct_responses"=>$row['correct_responses'],
  1864. //hide correct responses from students
  1865. "correct_responses"=>'',
  1866. "student_response"=>$row['student_response'],
  1867. "result"=>$row['result'],
  1868. "latency"=>$row['latency']);
  1869. }
  1870. }
  1871. return $list;
  1872. }
  1873. /**
  1874. * Return the number of objectives for the given learnpath Item View ID.
  1875. * This method can be used as static.
  1876. * @param integer Item View ID
  1877. * @return integer Number of objectives
  1878. */
  1879. function get_objectives_count_from_db($lp_iv_id=0){
  1880. if(empty($lp_iv_id)){return -1;}
  1881. $table = Database::get_course_table('lp_iv_objective');
  1882. $sql = "SELECT count(*) FROM $table WHERE lp_iv_id = $lp_iv_id";
  1883. $res = api_sql_query($sql,__FILE__,__LINE__);
  1884. $row = Database::fetch_array($res);
  1885. $num = $row[0];
  1886. return $num;
  1887. }
  1888. /**
  1889. * Return the objectives as an array for the given lp_iv_id.
  1890. * This method can be used as static.
  1891. * @param integer Learnpath Item View ID
  1892. * @return array
  1893. * @todo Translate labels
  1894. */
  1895. function get_iv_objectives_array($lp_iv_id=0){
  1896. $list = array();
  1897. $table = Database::get_course_table('lp_iv_objective');
  1898. $sql = "SELECT * FROM $table WHERE lp_iv_id = $lp_iv_id ORDER BY order_id ASC";
  1899. $res = api_sql_query($sql,__FILE__,__LINE__);
  1900. $num = Database::num_rows($res);
  1901. if($num>0){
  1902. $list[] = array(
  1903. "order_id"=>htmlentities(get_lang('Order')),
  1904. "objective_id"=>htmlentities(get_lang('ObjectiveID')),
  1905. "score_raw"=>htmlentities(get_lang('ObjectiveRawScore')),
  1906. "score_max"=>htmlentities(get_lang('ObjectiveMaxScore')),
  1907. "score_min"=>htmlentities(get_lang('ObjectiveMinScore')),
  1908. "status"=>htmlentities(get_lang('ObjectiveStatus')));
  1909. while ($row = Database::fetch_array($res)){
  1910. $list[] = array(
  1911. "order_id"=>($row['order_id']+1),
  1912. "objective_id"=>urldecode($row['objective_id']),//urldecode because they often have %2F or stuff like that
  1913. "score_raw"=>$row['score_raw'],
  1914. "score_max"=>$row['score_max'],
  1915. "score_min"=>$row['score_min'],
  1916. "status"=>$row['status']);
  1917. }
  1918. }
  1919. return $list;
  1920. }
  1921. /**
  1922. * Generate and return the table of contents for this learnpath. The (flat) table returned can be
  1923. * used by get_html_toc() to be ready to display
  1924. * @return array TOC as a table with 4 elements per row: title, link, status and level
  1925. */
  1926. function get_toc()
  1927. {
  1928. if($this->debug>0){error_log('New LP - In learnpath::get_toc()',0);}
  1929. $toc = array();
  1930. //echo "<pre>".print_r($this->items,true)."</pre>";
  1931. foreach($this->ordered_items as $item_id)
  1932. {
  1933. if($this->debug>2){error_log('New LP - learnpath::get_toc(): getting info for item '.$item_id,0);}
  1934. //TODO change this link generation and use new function instead
  1935. $toc[] = array(
  1936. 'id'=>$item_id,
  1937. 'title'=>$this->items[$item_id]->get_title(),
  1938. //'link'=>get_addedresource_link_in_learnpath('document',$item_id,1),
  1939. 'status'=>$this->items[$item_id]->get_status(),
  1940. 'level'=>$this->items[$item_id]->get_level(),
  1941. 'type' =>$this->items[$item_id]->get_type(),
  1942. 'description'=>$this->items[$item_id]->get_description(),
  1943. );
  1944. }
  1945. if($this->debug>2){error_log('New LP - In learnpath::get_toc() - TOC array: '.print_r($toc,true),0);}
  1946. return $toc;
  1947. }
  1948. /**
  1949. * Gets the learning path type
  1950. * @param boolean Return the name? If false, return the ID. Default is false.
  1951. * @return mixed Type ID or name, depending on the parameter
  1952. */
  1953. function get_type($get_name = false)
  1954. {
  1955. $res = false;
  1956. if($this->debug>0){error_log('New LP - In learnpath::get_type()',0);}
  1957. if(!empty($this->type))
  1958. {
  1959. if($get_name)
  1960. {
  1961. //get it from the lp_type table in main db
  1962. }else{
  1963. $res = $this->type;
  1964. }
  1965. }
  1966. if($this->debug>2){error_log('New LP - In learnpath::get_type() - Returning '.($res==false?'false':$res),0);}
  1967. return $res;
  1968. }
  1969. /**
  1970. * Gets the learning path type as static method
  1971. * @param boolean Return the name? If false, return the ID. Default is false.
  1972. * @return mixed Type ID or name, depending on the parameter
  1973. */
  1974. function get_type_static($lp_id=0)
  1975. {
  1976. $tbl_lp = Database::get_course_table('lp');
  1977. $sql = "SELECT lp_type FROM $tbl_lp WHERE id = '".$lp_id."'";
  1978. $res = api_sql_query($sql, __FILE__, __LINE__);
  1979. if($res===false){ return null;}
  1980. if(Database::num_rows($res)<=0){return null;}
  1981. $row = Database::fetch_array($res);
  1982. return $row['lp_type'];
  1983. }
  1984. /**
  1985. * Gets a flat list of item IDs ordered for display (level by level ordered by order_display)
  1986. * This method can be used as abstract and is recursive
  1987. * @param integer Learnpath ID
  1988. * @param integer Parent ID of the items to look for
  1989. * @return mixed Ordered list of item IDs or false on error
  1990. */
  1991. function get_flat_ordered_items_list($lp,$parent=0){
  1992. //if($this->debug>0){error_log('New LP - In learnpath::get_flat_ordered_items_list('.$lp.','.$parent.')',0);}
  1993. $list = array();
  1994. if(empty($lp)){return false;}
  1995. $tbl_lp_item = Database::get_course_table('lp_item');
  1996. $sql = "SELECT * FROM $tbl_lp_item WHERE lp_id = $lp AND parent_item_id = $parent ORDER BY display_order";
  1997. $res = api_sql_query($sql,__FILE__,__LINE__);
  1998. while($row = Database::fetch_array($res)){
  1999. $sublist = learnpath::get_flat_ordered_items_list($lp,$row['id']);
  2000. $list[] = $row['id'];
  2001. foreach($sublist as $item){
  2002. $list[] = $item;
  2003. }
  2004. }
  2005. return $list;
  2006. }
  2007. /**
  2008. * Uses the table generated by get_toc() and returns an HTML-formatted string ready to display
  2009. * @return string HTML TOC ready to display
  2010. */
  2011. /*function get_html_toc()
  2012. {
  2013. if($this->debug>0){error_log('New LP - In learnpath::get_html_toc()',0);}
  2014. $list = $this->get_toc();
  2015. //echo $this->current;
  2016. //$parent = $this->items[$this->current]->get_parent();
  2017. //if(empty($parent)){$parent = $this->ordered_items[$this->items[$this->current]->get_previous_index()];}
  2018. $html = '<div class="inner_lp_toc">'."\n" ;
  2019. // " onchange=\"javascript:document.getElementById('toc_$parent').focus();\">\n";
  2020. require_once('resourcelinker.inc.php');
  2021. //temp variables
  2022. $mycurrentitemid = $this->get_current_item_id();
  2023. foreach($list as $item)
  2024. {
  2025. if($this->debug>2){error_log('New LP - learnpath::get_html_toc(): using item '.$item['id'],0);}
  2026. //TODO complete this
  2027. $icon_name = array('not attempted' => 'notattempted.png',
  2028. 'incomplete' => 'incomplete.png',
  2029. 'failed' => 'failed.png',
  2030. 'completed' => 'completed.png',
  2031. 'passed' => 'passed.png',
  2032. 'succeeded' => 'succeeded.png',
  2033. 'browsed' => 'completed.png');
  2034. $style = 'scorm_item';
  2035. if($item['id'] == $this->current){
  2036. $style = 'scorm_item_highlight';
  2037. }
  2038. //the anchor will let us center the TOC on the currently viewed item &^D
  2039. $html .= '<a name="atoc_'.$item['id'].'" /><div class="'.$style.'" style="padding-left: '.($item['level']/2).'em; padding-right:'.($item['level']/2).'em" id="toc_'.$item['id'].'" >' .
  2040. '<img id="toc_img_'.$item['id'].'" class="scorm_status_img" src="'.$icon_name[$item['status']].'" alt="'.substr($item['status'],0,1).'" />';
  2041. //$title = htmlspecialchars($item['title'],ENT_QUOTES,$this->encoding);
  2042. $title = $item['title'];
  2043. if(empty($title)){
  2044. $title = rl_get_resource_name(api_get_course_id(),$this->get_id(),$item['id']);
  2045. $title = htmlspecialchars($title,ENT_QUOTES,$this->encoding);
  2046. }
  2047. if(empty($title))$title = '-';
  2048. if($item['type']!='dokeos_chapter' and $item['type']!='dir'){
  2049. //$html .= "<a href='lp_controller.php?".api_get_cidReq()."&action=content&lp_id=".$this->get_id()."&item_id=".$item['id']."' target='lp_content_frame_name'>".$title."</a>" ;
  2050. $url = $this->get_link('http',$item['id']);
  2051. //$html .= '<a href="'.$url.'" target="content_name" onclick="top.load_item('.$item['id'].',\''.$url.'\');">'.$title.'</a>' ;
  2052. //$html .= '<a href="" onclick="top.load_item('.$item['id'].',\''.$url.'\');return false;">'.$title.'</a>' ;
  2053. $html .= '<a href="" onclick="dokeos_xajax_handler.switch_item(' .
  2054. $mycurrentitemid.',' .
  2055. $item['id'].');' .
  2056. 'return false;" >'.$title.'</a>' ;
  2057. }else{
  2058. $html .= $title;
  2059. }
  2060. $html .= "</div>\n";
  2061. }
  2062. $html .= "</div>\n";
  2063. return $html;
  2064. }*/
  2065. /**
  2066. * Uses the table generated by get_toc() and returns an HTML-formatted string ready to display
  2067. * @return string HTML TOC ready to display
  2068. */
  2069. function get_html_toc()
  2070. {
  2071. if($this->debug>0){error_log('New LP - In learnpath::get_html_toc()',0);}
  2072. $list = $this->get_toc();
  2073. //echo $this->current;
  2074. //$parent = $this->items[$this->current]->get_parent();
  2075. //if(empty($parent)){$parent = $this->ordered_items[$this->items[$this->current]->get_previous_index()];}
  2076. $html.= '<div class="inner_lp_toc">'."\n" ;
  2077. $html.= '<div class="scorm_title">&nbsp;&nbsp;&nbsp;&nbsp;'.$this->get_name().'</div>';
  2078. // build, display
  2079. if(api_is_allowed_to_edit())
  2080. {
  2081. $mych = api_get_setting('platform_charset');
  2082. $html.="<p>&nbsp;&nbsp;&nbsp;&nbsp;<a target='_parent' href='lp_controller.php?".api_get_cidreq()."&action=build&lp_id=".$this->lp_id."' style= target='_parent'>".mb_convert_encoding(get_lang("Build"),$this->encoding,$mych)."</a>&nbsp;&#124;&nbsp;<a href='lp_controller.php?".api_get_cidreq()."&action=admin_view&lp_id=".$this->lp_id."' target='_parent'>".mb_convert_encoding(get_lang("BasicOverview"),$this->encoding,$mych)."</a>&nbsp;&#124;&nbsp;".mb_convert_encoding(get_lang("Display"),$this->encoding,$mych)."</p>";
  2083. unset($mych);
  2084. }
  2085. // " onchange=\"javascript:document.getElementById('toc_$parent').focus();\">\n";
  2086. require_once('resourcelinker.inc.php');
  2087. //temp variables
  2088. $mycurrentitemid = $this->get_current_item_id();
  2089. $color_counter=0;
  2090. $i=0;
  2091. foreach($list as $item)
  2092. {
  2093. if($this->debug>2){error_log('New LP - learnpath::get_html_toc(): using item '.$item['id'],0);}
  2094. //TODO complete this
  2095. $icon_name = array('not attempted' => 'notattempted.png',
  2096. 'incomplete' => 'incomplete.png',
  2097. 'failed' => 'failed.png',
  2098. 'completed' => 'completed.png',
  2099. 'passed' => 'passed.png',
  2100. 'succeeded' => 'succeeded.png',
  2101. 'browsed' => 'completed.png');
  2102. $style = 'scorm_item';
  2103. $scorm_color_background='scorm_item';
  2104. $style_item ='scorm_item';
  2105. $current=false;
  2106. if($item['id'] == $this->current)
  2107. {
  2108. $style = 'scorm_item_highlight';
  2109. $scorm_color_background ='scorm_item_highlight';
  2110. }
  2111. else
  2112. if ($color_counter%2==0)
  2113. {
  2114. $scorm_color_background='scorm_item_1';
  2115. }
  2116. else
  2117. {
  2118. $scorm_color_background='scorm_item_2';
  2119. }
  2120. if ($scorm_color_background!='')
  2121. {
  2122. $html .= '<div id="toc_'.$item['id'].'" class="'.$scorm_color_background.'">';
  2123. }
  2124. //the anchor will let us center the TOC on the currently viewed item &^D
  2125. if($item['type']!='dokeos_module' AND $item['type']!='dokeos_chapter')
  2126. {
  2127. $html .= '<a name="atoc_'.$item['id'].'" />';
  2128. $html .= '<div class="'.$style_item.'" style="padding-left: '.($item['level']*1.5).'em; padding-right:'.($item['level']/2).'em" title="'.$item['description'].'" >';
  2129. }
  2130. else
  2131. {
  2132. $html .= '<div class="'.$style_item.'" style="padding-left: '.($item['level']*2).'em; padding-right:'.($item['level']*1.5).'em" title="'.$item['description'].'" >';
  2133. }
  2134. $title=$item['title'];
  2135. if(empty($title))
  2136. {
  2137. $title = rl_get_resource_name(api_get_course_id(),$this->get_id(),$item['id']);
  2138. }
  2139. $title = html_entity_decode($title,ENT_QUOTES,$this->encoding);
  2140. if($item['type']!='dokeos_chapter' and $item['type']!='dir' AND $item['type']!='dokeos_module')
  2141. {
  2142. //$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>" ;
  2143. $url = $this->get_link('http',$item['id']);
  2144. //$html .= '<a href="'.$url.'" target="content_name" onclick="top.load_item('.$item['id'].',\''.$url.'\');">'.$title.'</a>' ;
  2145. //$html .= '<a href="" onclick="top.load_item('.$item['id'].',\''.$url.'\');return false;">'.$title.'</a>' ;
  2146. //<img align="absbottom" width="13" height="13" src="../img/lp_document.png">&nbsp;
  2147. $html .= '<a href="" onclick="dokeos_xajax_handler.switch_item(' .
  2148. $mycurrentitemid.',' .
  2149. $item['id'].');' .
  2150. 'return false;" >'.stripslashes($title).'</a>' ;
  2151. }
  2152. elseif($item['type']=='dokeos_module' || $item['type']=='dokeos_chapter')
  2153. {
  2154. $html .= "<img align='absbottom' width='13' height='13' src='../img/lp_dokeos_module.png'>&nbsp;".stripslashes($title);
  2155. }
  2156. elseif($item['type']=='dir')
  2157. {
  2158. $html .= stripslashes($title);
  2159. }
  2160. $html .= "<img id='toc_img_".$item['id']."' src='".$icon_name[$item['status']]."' alt='".substr($item['status'],0,1)."' />";
  2161. $html .= "</div>";
  2162. if ($scorm_color_background!='')
  2163. {
  2164. $html .= '</div>';
  2165. }
  2166. $color_counter++;
  2167. }
  2168. $html .= "</div>\n";
  2169. return $html;
  2170. }
  2171. /**
  2172. * Gets the learnpath maker name - generally the editor's name
  2173. * @return string Learnpath maker name
  2174. */
  2175. function get_maker()
  2176. {
  2177. if($this->debug>0){error_log('New LP - In learnpath::get_maker()',0);}
  2178. if(!empty($this->maker)){return $this->maker;}else{return '';}
  2179. }
  2180. /**
  2181. * Gets the user-friendly message stored in $this->message
  2182. * @return string Message
  2183. */
  2184. function get_message(){
  2185. if($this->debug>0){error_log('New LP - In learnpath::get_message()',0);}
  2186. return $this->message;
  2187. }
  2188. /**
  2189. * Gets the learnpath name/title
  2190. * @return string Learnpath name/title
  2191. */
  2192. function get_name()
  2193. {
  2194. if($this->debug>0){error_log('New LP - In learnpath::get_name()',0);}
  2195. if(!empty($this->name)){return $this->name;}else{return 'N/A';}
  2196. }
  2197. /**
  2198. * Gets a link to the resource from the present location, depending on item ID.
  2199. * @param string Type of link expected
  2200. * @param integer Learnpath item ID
  2201. * @return string Link to the lp_item resource
  2202. */
  2203. function get_link($type='http',$item_id=null)
  2204. {
  2205. if($this->debug>0){error_log('New LP - In learnpath::get_link('.$type.','.$item_id.')',0);}
  2206. if(empty($item_id))
  2207. {
  2208. 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);}
  2209. $item_id = $this->get_current_item_id();
  2210. }
  2211. if(empty($item_id)){
  2212. if($this->debug>2){error_log('New LP - In learnpath::get_link() - no current item id found in learnpath object',0);}
  2213. //still empty, this means there was no item_id given and we are not in an object context or
  2214. //the object property is empty, return empty link
  2215. $item_id = $this->first();
  2216. return '';
  2217. }
  2218. $file = '';
  2219. $lp_table = Database::get_course_table(TABLE_LP_MAIN);
  2220. $lp_item_table = Database::get_course_table(TABLE_LP_ITEM);
  2221. $sel = "SELECT l.lp_type as ltype, l.path as lpath, li.item_type as litype, li.path as lipath, li.parameters as liparams " .
  2222. "FROM $lp_table l, $lp_item_table li WHERE li.id = $item_id AND li.lp_id = l.id";
  2223. if($this->debug>2){error_log('New LP - In learnpath::get_link() - selecting item '.$sel,0);}
  2224. $res = api_sql_query($sel, __FILE__, __LINE__);
  2225. if(Database::num_rows($res)>0)
  2226. {
  2227. $row = Database::fetch_array($res);
  2228. //var_dump($row);
  2229. $lp_type = $row['ltype'];
  2230. $lp_path = $row['lpath'];
  2231. $lp_item_type = $row['litype'];
  2232. $lp_item_path = $row['lipath'];
  2233. $lp_item_params = $row['liparams'];
  2234. if(empty($lp_item_params))
  2235. {
  2236. list($lp_item_path,$lp_item_params) = explode('?',$lp_item_path);
  2237. }
  2238. //$lp_item_params = '?'.$lp_item_params;
  2239. //add ? if none - left commented to give freedom to scorm implementation
  2240. //if(substr($lp_item_params,0,1)!='?'){
  2241. // $lp_item_params = '?'.$lp_item_params;
  2242. //}
  2243. $sys_course_path = api_get_path(SYS_COURSE_PATH).api_get_course_path();
  2244. if($type == 'http'){
  2245. $course_path = api_get_path(WEB_COURSE_PATH).api_get_course_path(); //web path
  2246. }else{
  2247. $course_path = $sys_course_path; //system path
  2248. }
  2249. //now go through the specific cases to get the end of the path
  2250. switch($lp_type){
  2251. case 1:
  2252. if($lp_item_type == 'dokeos_chapter'){
  2253. $file = 'lp_content.php?type=dir';
  2254. }else{
  2255. require_once('resourcelinker.inc.php');
  2256. $file = rl_get_resource_link_for_learnpath(api_get_course_id(),$this->get_id(),$item_id);
  2257. $tmp_array=explode("/",$file);
  2258. $document_name=$tmp_array[count($tmp_array)-1];
  2259. if(strpos($document_name,'_DELETED_')){
  2260. $file = 'blank.php?error=document_deleted';
  2261. }
  2262. }
  2263. break;
  2264. case 2:
  2265. if($this->debug>2){error_log('New LP - In learnpath::get_link() '.__LINE__.' - Item type: '.$lp_item_type,0);}
  2266. if($lp_item_type!='dir'){
  2267. //Quite complex here:
  2268. //we want to make sure 'http://' (and similar) links can
  2269. //be loaded as is (withouth the Dokeos path in front) but
  2270. //some contents use this form: resource.htm?resource=http://blablabla
  2271. //which means we have to find a protocol at the path's start, otherwise
  2272. //it should not be considered as an external URL
  2273. //if($this->prerequisites_match($item_id)){
  2274. if(preg_match('#^[a-zA-Z]{2,5}://#',$lp_item_path)!=0){
  2275. if($this->debug>2){error_log('New LP - In learnpath::get_link() '.__LINE__.' - Found match for protocol in '.$lp_item_path,0);}
  2276. //distant url, return as is
  2277. $file = $lp_item_path;
  2278. }else{
  2279. if($this->debug>2){error_log('New LP - In learnpath::get_link() '.__LINE__.' - No starting protocol in '.$lp_item_path,0);}
  2280. //prevent getting untranslatable urls
  2281. $lp_item_path = preg_replace('/%2F/','/',$lp_item_path);
  2282. $lp_item_path = preg_replace('/%3A/',':',$lp_item_path);
  2283. //prepare the path
  2284. $file = $course_path.'/scorm/'.$lp_path.'/'.$lp_item_path;
  2285. //TODO fix this for urls with protocol header
  2286. $file = str_replace('//','/',$file);
  2287. $file = str_replace(':/','://',$file);
  2288. if(substr($lp_path,-1)=='/')
  2289. {
  2290. $lp_path = substr($lp_path,0,-1);
  2291. }
  2292. if(!is_file(realpath($sys_course_path.'/scorm/'.$lp_path.'/'.$lp_item_path)))
  2293. {//if file not found
  2294. $decoded = html_entity_decode($lp_item_path);
  2295. list($decoded) = explode('?',$decoded);
  2296. if(!is_file(realpath($sys_course_path.'/scorm/'.$lp_path.'/'.$decoded)))
  2297. {
  2298. require_once('resourcelinker.inc.php');
  2299. $file = rl_get_resource_link_for_learnpath(api_get_course_id(),$this->get_id(),$item_id);
  2300. $tmp_array=explode("/",$file);
  2301. $document_name=$tmp_array[count($tmp_array)-1];
  2302. if(strpos($document_name,'_DELETED_')){
  2303. $file = 'blank.php?error=document_deleted';
  2304. }
  2305. }
  2306. else
  2307. {
  2308. $file = $course_path.'/scorm/'.$lp_path.'/'.$decoded;
  2309. }
  2310. }
  2311. }
  2312. //}else{
  2313. //prerequisites did not match
  2314. //$file = 'blank.php';
  2315. //}
  2316. //We want to use parameters if they were defined in the imsmanifest
  2317. if($file!='blank.php')
  2318. {
  2319. $file.= $lp_item_params;
  2320. }
  2321. }else{
  2322. $file = 'lp_content.php?type=dir';
  2323. }
  2324. break;
  2325. case 3:
  2326. if($this->debug>2){error_log('New LP - In learnpath::get_link() '.__LINE__.' - Item type: '.$lp_item_type,0);}
  2327. //formatting AICC HACP append URL
  2328. $aicc_append = '?aicc_sid='.urlencode(session_id()).'&aicc_url='.urlencode(api_get_path(WEB_CODE_PATH).'newscorm/aicc_hacp.php').'&';
  2329. if($lp_item_type!='dir'){
  2330. //Quite complex here:
  2331. //we want to make sure 'http://' (and similar) links can
  2332. //be loaded as is (withouth the Dokeos path in front) but
  2333. //some contents use this form: resource.htm?resource=http://blablabla
  2334. //which means we have to find a protocol at the path's start, otherwise
  2335. //it should not be considered as an external URL
  2336. if(preg_match('#^[a-zA-Z]{2,5}://#',$lp_item_path)!=0){
  2337. if($this->debug>2){error_log('New LP - In learnpath::get_link() '.__LINE__.' - Found match for protocol in '.$lp_item_path,0);}
  2338. //distant url, return as is
  2339. $file = $lp_item_path;
  2340. /*
  2341. if(stristr($file,'<servername>')!==false){
  2342. $file = str_replace('<servername>',$course_path.'/scorm/'.$lp_path.'/',$lp_item_path);
  2343. }
  2344. */
  2345. $file .= $aicc_append;
  2346. }else{
  2347. if($this->debug>2){error_log('New LP - In learnpath::get_link() '.__LINE__.' - No starting protocol in '.$lp_item_path,0);}
  2348. //prevent getting untranslatable urls
  2349. $lp_item_path = preg_replace('/%2F/','/',$lp_item_path);
  2350. $lp_item_path = preg_replace('/%3A/',':',$lp_item_path);
  2351. //prepare the path - lp_path might be unusable because it includes the "aicc" subdir name
  2352. $file = $course_path.'/scorm/'.$lp_path.'/'.$lp_item_path;
  2353. //TODO fix this for urls with protocol header
  2354. $file = str_replace('//','/',$file);
  2355. $file = str_replace(':/','://',$file);
  2356. $file .= $aicc_append;
  2357. }
  2358. }else{
  2359. $file = 'lp_content.php?type=dir';
  2360. }
  2361. break;
  2362. case 4:
  2363. break;
  2364. default:
  2365. break;
  2366. }
  2367. }
  2368. if($this->debug>2){error_log('New LP - In learnpath::get_link() - returning "'.$file.'" from get_link',0);}
  2369. return $file;
  2370. }
  2371. /**
  2372. * Gets the latest usable view or generate a new one
  2373. * @param integer Optional attempt number. If none given, takes the highest from the lp_view table
  2374. * @return integer DB lp_view id
  2375. */
  2376. function get_view($attempt_num=0)
  2377. {
  2378. if($this->debug>0){error_log('New LP - In learnpath::get_view()',0);}
  2379. $search = '';
  2380. //use $attempt_num to enable multi-views management (disabled so far)
  2381. if($attempt_num != 0 AND intval(strval($attempt_num)) == $attempt_num)
  2382. {
  2383. $search = 'AND view_count = '.$attempt_num;
  2384. }
  2385. //when missing $attempt_num, search for a unique lp_view record for this lp and user
  2386. $lp_view_table = Database::get_course_table('lp_view');
  2387. $sql = "SELECT id, view_count FROM $lp_view_table " .
  2388. "WHERE lp_id = ".$this->get_id()." " .
  2389. "AND user_id = ".$this->get_user_id()." " .
  2390. $search .
  2391. " ORDER BY view_count DESC";
  2392. $res = api_sql_query($sql, __FILE__, __LINE__);
  2393. if(Database::num_rows($res)>0)
  2394. {
  2395. $row = Database::fetch_array($res);
  2396. $this->lp_view_id = $row['id'];
  2397. }else{
  2398. //no database record, create one
  2399. $sql = "INSERT INTO $lp_view_table(lp_id,user_id,view_count)" .
  2400. "VALUES (".$this->get_id().",".$this->get_user_id().",1)";
  2401. $res = api_sql_query($sql, __FILE__, __LINE__);
  2402. $id = Database::get_last_insert_id();
  2403. $this->lp_view_id = $id;
  2404. }
  2405. return $this->lp_view_id;
  2406. }
  2407. /**
  2408. * Gets the current view id
  2409. * @return integer View ID (from lp_view)
  2410. */
  2411. function get_view_id()
  2412. {
  2413. if($this->debug>0){error_log('New LP - In learnpath::get_view_id()',0);}
  2414. if(!empty($this->lp_view_id))
  2415. {
  2416. return $this->lp_view_id;
  2417. }else{
  2418. return 0;
  2419. }
  2420. }
  2421. /**
  2422. * Gets the update queue
  2423. * @return array Array containing IDs of items to be updated by JavaScript
  2424. */
  2425. function get_update_queue()
  2426. {
  2427. if($this->debug>0){error_log('New LP - In learnpath::get_update_queue()',0);}
  2428. return $this->update_queue;
  2429. }
  2430. /**
  2431. * Gets the user ID
  2432. * @return integer User ID
  2433. */
  2434. function get_user_id()
  2435. {
  2436. if($this->debug>0){error_log('New LP - In learnpath::get_user_id()',0);}
  2437. if(!empty($this->user_id))
  2438. {
  2439. return $this->user_id;
  2440. }else{
  2441. return false;
  2442. }
  2443. }
  2444. /**
  2445. * Logs a message into a file
  2446. * @param string Message to log
  2447. * @return boolean True on success, false on error or if msg empty
  2448. */
  2449. function log($msg)
  2450. {
  2451. if($this->debug>0){error_log('New LP - In learnpath::log()',0);}
  2452. //TODO
  2453. $this->error .= $msg."\n";
  2454. return true;
  2455. }
  2456. /**
  2457. * Moves an item up and down at its level
  2458. * @param integer Item to move up and down
  2459. * @param string Direction 'up' or 'down'
  2460. * @return integer New display order, or false on error
  2461. */
  2462. function move_item($id, $direction){
  2463. if($this->debug>0){error_log('New LP - In learnpath::move_item('.$id.','.$direction.')',0);}
  2464. if(empty($id) or empty($direction)){return false;}
  2465. $tbl_lp_item = Database::get_course_table('lp_item');
  2466. $sql_sel = "
  2467. SELECT *
  2468. FROM " . $tbl_lp_item . "
  2469. WHERE id = " . $id;
  2470. $res_sel = api_sql_query($sql_sel,__FILE__,__LINE__);
  2471. //check if elem exists
  2472. if(Database::num_rows($res_sel)<1){return false;}
  2473. //gather data
  2474. $row = Database::fetch_array($res_sel);
  2475. $previous = $row['previous_item_id'];
  2476. $next = $row['next_item_id'];
  2477. $display = $row['display_order'];
  2478. $parent = $row['parent_item_id'];
  2479. $lp = $row['lp_id'];
  2480. //update the item (switch with previous/next one)
  2481. switch($direction)
  2482. {
  2483. case 'up':
  2484. if($this->debug>2){error_log('Movement up detected',0);}
  2485. if($display <= 1){/*do nothing*/}
  2486. else{
  2487. $sql_sel2 = "SELECT *
  2488. FROM $tbl_lp_item
  2489. WHERE id = $previous";
  2490. if($this->debug>2){error_log('Selecting previous: '.$sql_sel2,0);}
  2491. $res_sel2 = api_sql_query($sql_sel2,__FILE__,__LINE__);
  2492. if(Database::num_rows($res_sel2)<1){$previous_previous = 0;}
  2493. //gather data
  2494. $row2 = Database::fetch_array($res_sel2);
  2495. $previous_previous = $row2['previous_item_id'];
  2496. //update previous_previous item (switch "next" with current)
  2497. if($previous_previous != 0)
  2498. {
  2499. $sql_upd2 = "UPDATE $tbl_lp_item SET next_item_id = $id WHERE id = $previous_previous";
  2500. if($this->debug>2){error_log($sql_upd2,0);}
  2501. $res_upd2 = api_sql_query($sql_upd2, __FILE__, __LINE__);
  2502. }
  2503. //update previous item (switch with current)
  2504. if($previous != 0)
  2505. {
  2506. $sql_upd2 = "UPDATE $tbl_lp_item SET next_item_id = $next, previous_item_id = $id, display_order = display_order +1 WHERE id = $previous";
  2507. if($this->debug>2){error_log($sql_upd2,0);}
  2508. $res_upd2 = api_sql_query($sql_upd2, __FILE__, __LINE__);
  2509. }
  2510. //update current item (switch with previous)
  2511. if($id != 0){
  2512. $sql_upd2 = "UPDATE $tbl_lp_item SET next_item_id = $previous, previous_item_id = $previous_previous, display_order = display_order-1 WHERE id = $id";
  2513. if($this->debug>2){error_log($sql_upd2,0);}
  2514. $res_upd2 = api_sql_query($sql_upd2, __FILE__, __LINE__);
  2515. }
  2516. //update next item (new previous item)
  2517. if($next != 0){
  2518. $sql_upd2 = "UPDATE $tbl_lp_item SET previous_item_id = $previous WHERE id = $next";
  2519. if($this->debug>2){error_log($sql_upd2,0);}
  2520. $res_upd2 = api_sql_query($sql_upd2, __FILE__, __LINE__);
  2521. }
  2522. $display = $display-1;
  2523. }
  2524. break;
  2525. case 'down':
  2526. if($this->debug>2){error_log('Movement down detected',0);}
  2527. if($next == 0){/*do nothing*/}
  2528. else{
  2529. $sql_sel2 = "SELECT * FROM $tbl_lp_item WHERE id = $next";
  2530. if($this->debug>2){error_log('Selecting next: '.$sql_sel2,0);}
  2531. $res_sel2 = api_sql_query($sql_sel2,__FILE__,__LINE__);
  2532. if(Database::num_rows($res_sel2)<1){$next_next = 0;}
  2533. //gather data
  2534. $row2 = Database::fetch_array($res_sel2);
  2535. $next_next = $row2['next_item_id'];
  2536. //update previous item (switch with current)
  2537. if($previous != 0)
  2538. {
  2539. $sql_upd2 = "UPDATE $tbl_lp_item SET next_item_id = $next WHERE id = $previous";
  2540. $res_upd2 = api_sql_query($sql_upd2, __FILE__, __LINE__);
  2541. }
  2542. //update current item (switch with previous)
  2543. if($id != 0)
  2544. {
  2545. $sql_upd2 = "UPDATE $tbl_lp_item SET previous_item_id = $next, next_item_id = $next_next, display_order = display_order+1 WHERE id = $id";
  2546. $res_upd2 = api_sql_query($sql_upd2, __FILE__, __LINE__);
  2547. }
  2548. //update next item (new previous item)
  2549. if($next != 0)
  2550. {
  2551. $sql_upd2 = "UPDATE $tbl_lp_item SET previous_item_id = $previous, next_item_id = $id, display_order = display_order-1 WHERE id = $next";
  2552. $res_upd2 = api_sql_query($sql_upd2, __FILE__, __LINE__);
  2553. }
  2554. //update next_next item (switch "previous" with current)
  2555. if($next_next != 0)
  2556. {
  2557. $sql_upd2 = "UPDATE $tbl_lp_item SET previous_item_id = $id WHERE id = $next_next";
  2558. $res_upd2 = api_sql_query($sql_upd2, __FILE__, __LINE__);
  2559. }
  2560. $display = $display+1;
  2561. }
  2562. break;
  2563. default:
  2564. return false;
  2565. }
  2566. return $display;
  2567. }
  2568. /**
  2569. * Move a learnpath up (display_order)
  2570. * @param integer Learnpath ID
  2571. */
  2572. function move_up($lp_id)
  2573. {
  2574. $lp_table = Database::get_course_table(TABLE_LP_MAIN);
  2575. $sql = "SELECT * FROM $lp_table ORDER BY display_order";
  2576. $res = api_sql_query($sql, __FILE__, __LINE__);
  2577. if($res === false) return false;
  2578. $lps = array();
  2579. $lp_order = array();
  2580. $num = Database::num_rows($res);
  2581. //first check the order is correct, globally (might be wrong because
  2582. //of versions < 1.8.4)
  2583. if($num>0)
  2584. {
  2585. $i = 1;
  2586. while($row = Database::fetch_array($res))
  2587. {
  2588. if($row['display_order'] != $i)
  2589. { //if we find a gap in the order, we need to fix it
  2590. $need_fix = true;
  2591. $sql_u = "UPDATE $lp_table SET display_order = $i WHERE id = ".$row['id'];
  2592. $res_u = api_sql_query($sql_u, __FILE__, __LINE__);
  2593. }
  2594. $row['display_order'] = $i;
  2595. $lps[$row['id']] = $row;
  2596. $lp_order[$i] = $row['id'];
  2597. $i++;
  2598. }
  2599. }
  2600. if($num>1) //if there's only one element, no need to sort
  2601. {
  2602. $order = $lps[$lp_id]['display_order'];
  2603. if($order>1) //if it's the first element, no need to move up
  2604. {
  2605. $sql_u1 = "UPDATE $lp_table SET display_order = $order WHERE id = ".$lp_order[$order-1];
  2606. $res_u1 = api_sql_query($sql_u1, __FILE__, __LINE__);
  2607. $sql_u2 = "UPDATE $lp_table SET display_order = ".($order-1)." WHERE id = ".$lp_id;
  2608. $res_u2 = api_sql_query($sql_u2, __FILE__, __LINE__);
  2609. }
  2610. }
  2611. }
  2612. /**
  2613. * Move a learnpath down (display_order)
  2614. * @param integer Learnpath ID
  2615. */
  2616. function move_down($lp_id)
  2617. {
  2618. $lp_table = Database::get_course_table(TABLE_LP_MAIN);
  2619. $sql = "SELECT * FROM $lp_table ORDER BY display_order";
  2620. $res = api_sql_query($sql, __FILE__, __LINE__);
  2621. if($res === false) return false;
  2622. $lps = array();
  2623. $lp_order = array();
  2624. $num = Database::num_rows($res);
  2625. $max = 0;
  2626. //first check the order is correct, globally (might be wrong because
  2627. //of versions < 1.8.4)
  2628. if($num>0)
  2629. {
  2630. $i = 1;
  2631. while($row = Database::fetch_array($res))
  2632. {
  2633. $max = $i;
  2634. if($row['display_order'] != $i)
  2635. { //if we find a gap in the order, we need to fix it
  2636. $need_fix = true;
  2637. $sql_u = "UPDATE $lp_table SET display_order = $i WHERE id = ".$row['id'];
  2638. $res_u = api_sql_query($sql_u, __FILE__, __LINE__);
  2639. }
  2640. $row['display_order'] = $i;
  2641. $lps[$row['id']] = $row;
  2642. $lp_order[$i] = $row['id'];
  2643. $i++;
  2644. }
  2645. }
  2646. if($num>1) //if there's only one element, no need to sort
  2647. {
  2648. $order = $lps[$lp_id]['display_order'];
  2649. if($order<$max) //if it's the first element, no need to move up
  2650. {
  2651. $sql_u1 = "UPDATE $lp_table SET display_order = $order WHERE id = ".$lp_order[$order+1];
  2652. $res_u1 = api_sql_query($sql_u1, __FILE__, __LINE__);
  2653. $sql_u2 = "UPDATE $lp_table SET display_order = ".($order+1)." WHERE id = ".$lp_id;
  2654. $res_u2 = api_sql_query($sql_u2, __FILE__, __LINE__);
  2655. }
  2656. }
  2657. }
  2658. /**
  2659. * Updates learnpath attributes to point to the next element
  2660. * The last part is similar to set_current_item but processing the other way around
  2661. */
  2662. function next()
  2663. {
  2664. if($this->debug>0){error_log('New LP - In learnpath::next()',0);}
  2665. $this->last = $this->get_current_item_id();
  2666. $this->items[$this->last]->save(false,$this->prerequisites_match($this->last));
  2667. $this->autocomplete_parents($this->last);
  2668. $new_index = $this->get_next_index();
  2669. if($this->debug>2){error_log('New LP - New index: '.$new_index,0);}
  2670. $this->index = $new_index;
  2671. if($this->debug>2){error_log('New LP - Now having orderedlist['.$new_index.'] = '. $this->ordered_items[$new_index],0);}
  2672. $this->current = $this->ordered_items[$new_index];
  2673. if($this->debug>2){error_log('New LP - new item id is '.$this->current.'-'.$this->get_current_item_id(),0);}
  2674. }
  2675. /**
  2676. * Open a resource = initialise all local variables relative to this resource. Depending on the child
  2677. * class, this might be redefined to allow several behaviours depending on the document type.
  2678. * @param integer Resource ID
  2679. * @return boolean True on success, false otherwise
  2680. */
  2681. function open($id)
  2682. {
  2683. if($this->debug>0){error_log('New LP - In learnpath::open()',0);}
  2684. //TODO
  2685. //set the current resource attribute to this resource
  2686. //switch on element type (redefine in child class?)
  2687. //set status for this item to "opened"
  2688. //start timer
  2689. //initialise score
  2690. $this->index = 0; //or = the last item seen (see $this->last)
  2691. }
  2692. /**
  2693. * Check that all prerequisites are fulfilled. Returns true and an empty string on succes, returns false
  2694. * and the prerequisite string on error.
  2695. * This function is based on the rules for aicc_script language as described in the SCORM 1.2 CAM documentation page 108.
  2696. * @param integer Optional item ID. If none given, uses the current open item.
  2697. * @return boolean True if prerequisites are matched, false otherwise
  2698. * @return string Empty string if true returned, prerequisites string otherwise.
  2699. */
  2700. function prerequisites_match($item = null)
  2701. {
  2702. if($this->debug>0){error_log('New LP - In learnpath::prerequisites_match()',0);}
  2703. if(empty($item)){$item = $this->current;}
  2704. if(is_object($this->items[$item]))
  2705. {
  2706. $prereq_string = $this->items[$item]->get_prereq_string();
  2707. if(empty($prereq_string)){return true;}
  2708. //clean spaces
  2709. $prereq_string = str_replace(' ','',$prereq_string);
  2710. if($this->debug>0){error_log('Found prereq_string: '.$prereq_string,0);}
  2711. //now send to the parse_prereq() function that will check this component's prerequisites
  2712. $result = $this->items[$item]->parse_prereq($prereq_string,$this->items,$this->refs_list,$this->get_user_id());
  2713. if($result === false)
  2714. {
  2715. $this->set_error_msg($this->items[$item]->prereq_alert);
  2716. }
  2717. }else{
  2718. $result = true;
  2719. if($this->debug>1){error_log('New LP - $this->items['.$item.'] was not an object',0);}
  2720. }
  2721. if($this->debug>1){error_log('New LP - End of prerequisites_match(). Error message is now '.$this->error,0);}
  2722. return $result;
  2723. }
  2724. /**
  2725. * Updates learnpath attributes to point to the previous element
  2726. * The last part is similar to set_current_item but processing the other way around
  2727. */
  2728. function previous()
  2729. {
  2730. if($this->debug>0){error_log('New LP - In learnpath::previous()',0);}
  2731. $this->last = $this->get_current_item_id();
  2732. $this->items[$this->last]->save(false,$this->prerequisites_match($this->last));
  2733. $this->autocomplete_parents($this->last);
  2734. $new_index = $this->get_previous_index();
  2735. $this->index = $new_index;
  2736. $this->current = $this->ordered_items[$new_index];
  2737. }
  2738. /**
  2739. * Publishes a learnpath. This basically means show or hide the learnpath
  2740. * to normal users.
  2741. * Can be used as abstract
  2742. * @param integer Learnpath ID
  2743. * @param string New visibility
  2744. */
  2745. function toggle_visibility($lp_id,$set_visibility=1)
  2746. {
  2747. //if($this->debug>0){error_log('New LP - In learnpath::toggle_visibility()',0);}
  2748. $action = 'visible';
  2749. if($set_visibility != 1)
  2750. {
  2751. $action = 'invisible';
  2752. }
  2753. return api_item_property_update(api_get_course_info(),TOOL_LEARNPATH,$lp_id,$action,api_get_user_id());
  2754. }
  2755. /**
  2756. * Publishes a learnpath. This basically means show or hide the learnpath
  2757. * on the course homepage
  2758. * Can be used as abstract
  2759. * @param integer Learnpath ID
  2760. * @param string New visibility
  2761. */
  2762. function toggle_publish($lp_id,$set_visibility='v')
  2763. {
  2764. //if($this->debug>0){error_log('New LP - In learnpath::toggle_publish()',0);}
  2765. $tbl_lp = Database::get_course_table('lp');
  2766. $sql="SELECT * FROM $tbl_lp where id=$lp_id";
  2767. $result=api_sql_query($sql,__FILE__,__LINE__);
  2768. $row=Database::fetch_array($result);
  2769. $name=domesticate($row['name']);
  2770. if($set_visibility == 'i') {
  2771. $s=$name." ".get_lang('_no_published');
  2772. $dialogBox=$s;
  2773. $v=0;
  2774. }
  2775. if($set_visibility == 'v')
  2776. {
  2777. $s=$name." ".get_lang('_published');
  2778. $dialogBox=$s;
  2779. $v=1;
  2780. }
  2781. $tbl_tool = Database::get_course_table(TABLE_TOOL_LIST);
  2782. $link = 'newscorm/lp_controller.php?action=view&lp_id='.$lp_id;
  2783. $sql="SELECT * FROM $tbl_tool where name='$name' and image='scormbuilder.gif' and link LIKE '$link%'";
  2784. $result=api_sql_query($sql,__FILE__,__LINE__);
  2785. $num=Database::num_rows($result);
  2786. $row2=Database::fetch_array($result);
  2787. //if($this->debug>2){error_log('New LP - '.$sql.' - '.$num,0);}
  2788. if(($set_visibility == 'i') && ($num>0))
  2789. {
  2790. $sql ="DELETE FROM $tbl_tool WHERE (name='$name' and image='scormbuilder.gif' and link LIKE '$link%')";
  2791. }
  2792. elseif(($set_visibility == 'v') && ($num==0))
  2793. {
  2794. $sql ="INSERT INTO $tbl_tool (name, link, image, visibility, admin, address, added_tool) VALUES ('$name','newscorm/lp_controller.php?action=view&lp_id=$lp_id','scormbuilder.gif','$v','0','pastillegris.gif',0)";
  2795. }
  2796. else
  2797. {
  2798. //parameter and database incompatible, do nothing
  2799. }
  2800. $result=api_sql_query($sql,__FILE__,__LINE__);
  2801. //if($this->debug>2){error_log('New LP - Leaving learnpath::toggle_visibility: '.$sql,0);}
  2802. }
  2803. /**
  2804. * Restart the whole learnpath. Return the URL of the first element.
  2805. * Make sure the results are saved with anoter method. This method should probably be
  2806. * redefined in children classes.
  2807. * @return string URL to load in the viewer
  2808. */
  2809. function restart()
  2810. {
  2811. if($this->debug>0){error_log('New LP - In learnpath::restart()',0);}
  2812. //TODO
  2813. //call autosave method to save the current progress
  2814. //$this->index = 0;
  2815. $lp_view_table = Database::get_course_table('lp_view');
  2816. $sql = "INSERT INTO $lp_view_table (lp_id, user_id, view_count) " .
  2817. "VALUES (".$this->lp_id.",".$this->get_user_id().",".($this->attempt+1).")";
  2818. if($this->debug>2){error_log('New LP - Inserting new lp_view for restart: '.$sql,0);}
  2819. $res = api_sql_query($sql, __FILE__, __LINE__);
  2820. if($view_id = Database::get_last_insert_id($res))
  2821. {
  2822. $this->lp_view_id = $view_id;
  2823. $this->attempt = $this->attempt+1;
  2824. }else{
  2825. $this->error = 'Could not insert into item_view table...';
  2826. return false;
  2827. }
  2828. $this->autocomplete_parents($this->current);
  2829. foreach($this->items as $index=>$dummy){
  2830. $this->items[$index]->restart();
  2831. $this->items[$index]->set_lp_view($this->lp_view_id);
  2832. }
  2833. $this->first();
  2834. return true;
  2835. }
  2836. /**
  2837. * Saves the current item
  2838. * @return boolean
  2839. */
  2840. function save_current(){
  2841. if($this->debug>0){error_log('New LP - In learnpath::save_current()',0);}
  2842. //TODO do a better check on the index pointing to the right item (it is supposed to be working
  2843. // on $ordered_items[] but not sure it's always safe to use with $items[])
  2844. if($this->debug>2){error_log('New LP - save_current() saving item '.$this->current,0);}
  2845. if($this->debug>2){error_log(''.print_r($this->items,true),0);}
  2846. if(is_object($this->items[$this->current])){
  2847. //$res = $this->items[$this->current]->save(false);
  2848. $res = $this->items[$this->current]->save(false,$this->prerequisites_match($this->current));
  2849. $this->autocomplete_parents($this->current);
  2850. $status = $this->items[$this->current]->get_status();
  2851. $this->append_message('new_item_status: '.$status);
  2852. $this->update_queue[$this->current] = $status;
  2853. return $res;
  2854. }
  2855. return false;
  2856. }
  2857. /**
  2858. * Saves the given item
  2859. * @param integer Item ID. Optional (will take from $_REQUEST if null)
  2860. * @param boolean Save from url params (true) or from current attributes (false). Optional. Defaults to true
  2861. * @return boolean
  2862. */
  2863. function save_item($item_id=null,$from_outside=true){
  2864. if($this->debug>0){error_log('New LP - In learnpath::save_item('.$item_id.','.$from_outside.')',0);}
  2865. //TODO do a better check on the index pointing to the right item (it is supposed to be working
  2866. // on $ordered_items[] but not sure it's always safe to use with $items[])
  2867. if(empty($item_id)){
  2868. $item_id = $this->escape_string($_REQUEST['id']);
  2869. }
  2870. if(empty($item_id))
  2871. {
  2872. $item_id = $this->get_current_item_id();
  2873. }
  2874. if($this->debug>2){error_log('New LP - save_current() saving item '.$item_id,0);}
  2875. if(is_object($this->items[$item_id])){
  2876. $res = $this->items[$item_id]->save($from_outside,$this->prerequisites_match($item_id));
  2877. //$res = $this->items[$item_id]->save($from_outside);
  2878. $this->autocomplete_parents($item_id);
  2879. $status = $this->items[$item_id]->get_status();
  2880. $this->append_message('new_item_status: '.$status);
  2881. $this->update_queue[$item_id] = $status;
  2882. return $res;
  2883. }
  2884. return false;
  2885. }
  2886. /**
  2887. * Saves the last item seen's ID only in case
  2888. */
  2889. function save_last(){
  2890. if($this->debug>0){error_log('New LP - In learnpath::save_last()',0);}
  2891. $table = Database::get_course_table('lp_view');
  2892. if(isset($this->current)){
  2893. if($this->debug>2){error_log('New LP - Saving current item ('.$this->current.') for later review',0);}
  2894. $sql = "UPDATE $table SET last_item = ".$this->get_current_item_id()." " .
  2895. "WHERE lp_id = ".$this->get_id()." AND user_id = ".$this->get_user_id();
  2896. if($this->debug>2){error_log('New LP - Saving last item seen : '.$sql,0);}
  2897. $res = api_sql_query($sql,__FILE__,__LINE__);
  2898. }
  2899. //save progress
  2900. list($progress,$text) = $this->get_progress_bar_text('%');
  2901. if($progress>=0 AND $progress<=100){
  2902. $progress= (int)$progress;
  2903. $sql = "UPDATE $table SET progress = $progress " .
  2904. "WHERE lp_id = ".$this->get_id()." AND " .
  2905. "user_id = ".$this->get_user_id();
  2906. $res = api_sql_query($sql,__FILE__, __LINE__); //ignore errors as some tables might not have the progress field just yet
  2907. $this->progress_db = $progress;
  2908. }
  2909. }
  2910. /**
  2911. * Sets the current item ID (checks if valid and authorized first)
  2912. * @param integer New item ID. If not given or not authorized, defaults to current
  2913. */
  2914. function set_current_item($item_id=null)
  2915. {
  2916. if($this->debug>0){error_log('New LP - In learnpath::set_current_item('.$item_id.')',0);}
  2917. if(empty($item_id)){
  2918. if($this->debug>2){error_log('New LP - No new current item given, ignore...',0);}
  2919. //do nothing
  2920. }else{
  2921. if($this->debug>2){error_log('New LP - New current item given is '.$item_id.'...',0);}
  2922. $item_id = $this->escape_string($item_id);
  2923. //TODO check in database here
  2924. $this->last = $this->current;
  2925. $this->current = $item_id;
  2926. //TODO update $this->index as well
  2927. foreach($this->ordered_items as $index => $item)
  2928. {
  2929. if($item == $this->current)
  2930. {
  2931. $this->index = $index;
  2932. break;
  2933. }
  2934. }
  2935. if($this->debug>2){error_log('New LP - set_current_item('.$item_id.') done. Index is now : '.$this->index,0);}
  2936. }
  2937. }
  2938. /**
  2939. * Sets the encoding
  2940. * @param string New encoding
  2941. */
  2942. function set_encoding($enc='ISO-8859-1'){
  2943. if($this->debug>0){error_log('New LP - In learnpath::set_encoding()',0);}
  2944. $enc = strtoupper($enc);
  2945. $encodings = array('UTF-8','ISO-8859-1','ISO-8859-15','SHIFT-JIS');
  2946. if(in_array($enc,$encodings)){
  2947. $lp = $this->get_id();
  2948. if($lp!=0){
  2949. $tbl_lp = Database::get_course_table('lp');
  2950. $sql = "UPDATE $tbl_lp SET default_encoding = '$enc' WHERE id = ".$lp;
  2951. $res = api_sql_query($sql, __FILE__, __LINE__);
  2952. return $res;
  2953. }
  2954. }
  2955. return false;
  2956. }
  2957. /**
  2958. * Sets the JS lib setting in the database directly.
  2959. * This is the JavaScript library file this lp needs to load on startup
  2960. * @param string Proximity setting
  2961. */
  2962. function set_jslib($lib=''){
  2963. if($this->debug>0){error_log('New LP - In learnpath::set_jslib()',0);}
  2964. $lp = $this->get_id();
  2965. if($lp!=0){
  2966. $tbl_lp = Database::get_course_table('lp');
  2967. $sql = "UPDATE $tbl_lp SET js_lib = '$lib' WHERE id = ".$lp;
  2968. $res = api_sql_query($sql, __FILE__, __LINE__);
  2969. return $res;
  2970. }else{
  2971. return false;
  2972. }
  2973. }
  2974. /**
  2975. * Sets the name of the LP maker (publisher) (and save)
  2976. * @param string Optional string giving the new content_maker of this learnpath
  2977. */
  2978. function set_maker($name=''){
  2979. if($this->debug>0){error_log('New LP - In learnpath::set_maker()',0);}
  2980. if(empty($name))return false;
  2981. $this->maker = $this->escape_string($name);
  2982. $lp_table = Database::get_course_table('lp');
  2983. $lp_id = $this->get_id();
  2984. $sql = "UPDATE $lp_table SET content_maker = '".$this->maker."' WHERE id = '$lp_id'";
  2985. if($this->debug>2){error_log('New LP - lp updated with new content_maker : '.$this->maker,0);}
  2986. //$res = Database::query($sql);
  2987. $res = api_sql_query($sql, __FILE__, __LINE__);
  2988. return true;
  2989. }
  2990. /**
  2991. * Sets the name of the current learnpath (and save)
  2992. * @param string Optional string giving the new name of this learnpath
  2993. */
  2994. function set_name($name=''){
  2995. if($this->debug>0){error_log('New LP - In learnpath::set_name()',0);}
  2996. if(empty($name))return false;
  2997. $this->name = $this->escape_string($name);
  2998. $lp_table = Database::get_course_table('lp');
  2999. $lp_id = $this->get_id();
  3000. $sql = "UPDATE $lp_table SET name = '".$this->name."' WHERE id = '$lp_id'";
  3001. if($this->debug>2){error_log('New LP - lp updated with new name : '.$this->name,0);}
  3002. //$res = Database::query($sql);
  3003. $res = api_sql_query($sql, __FILE__, __LINE__);
  3004. // if the lp is visible on the homepage, change his name there
  3005. if(mysql_affected_rows())
  3006. {
  3007. $table = Database :: get_course_table(TABLE_TOOL_LIST);
  3008. $sql = 'UPDATE '.$table.' SET
  3009. name = "'.$this->name.'"
  3010. WHERE link = "newscorm/lp_controller.php?action=view&lp_id='.$lp_id.'"';
  3011. api_sql_query($sql, __FILE__, __LINE__);
  3012. }
  3013. return true;
  3014. }
  3015. /**
  3016. * Sets the theme of the LP (local/remote) (and save)
  3017. * @param string Optional string giving the new theme of this learnpath
  3018. * @return bool returns true if theme name is not empty
  3019. */
  3020. function set_theme($name=''){
  3021. if($this->debug>0){error_log('New LP - In learnpath::set_theme()',0);}
  3022. if(empty($name))return false;
  3023. $this->theme = $this->escape_string($name);
  3024. $lp_table = Database::get_course_table('lp');
  3025. $lp_id = $this->get_id();
  3026. $sql = "UPDATE $lp_table SET theme = '".$this->theme."' WHERE id = '$lp_id'";
  3027. if($this->debug>2){error_log('New LP - lp updated with new theme : '.$this->theme,0);}
  3028. //$res = Database::query($sql);
  3029. $res = api_sql_query($sql, __FILE__, __LINE__);
  3030. return true;
  3031. }
  3032. /**
  3033. * Sets the location/proximity of the LP (local/remote) (and save)
  3034. * @param string Optional string giving the new location of this learnpath
  3035. */
  3036. function set_proximity($name=''){
  3037. if($this->debug>0){error_log('New LP - In learnpath::set_proximity()',0);}
  3038. if(empty($name))return false;
  3039. $this->proximity = $this->escape_string($name);
  3040. $lp_table = Database::get_course_table('lp');
  3041. $lp_id = $this->get_id();
  3042. $sql = "UPDATE $lp_table SET content_local = '".$this->proximity."' WHERE id = '$lp_id'";
  3043. if($this->debug>2){error_log('New LP - lp updated with new proximity : '.$this->proximity,0);}
  3044. //$res = Database::query($sql);
  3045. $res = api_sql_query($sql, __FILE__, __LINE__);
  3046. return true;
  3047. }
  3048. /**
  3049. * Sets the previous item ID to a given ID. Generally, this should be set to the previous 'current' item
  3050. * @param integer DB ID of the item
  3051. */
  3052. function set_previous_item($id)
  3053. {
  3054. if($this->debug>0){error_log('New LP - In learnpath::set_previous_item()',0);}
  3055. $this->last = $id;
  3056. }
  3057. /**
  3058. * Sets the object's error message
  3059. * @param string Error message. If empty, reinits the error string
  3060. * @return void
  3061. */
  3062. function set_error_msg($error='')
  3063. {
  3064. if($this->debug>0){error_log('New LP - In learnpath::set_error_msg()',0);}
  3065. if(empty($error)){
  3066. $this->error = '';
  3067. }else{
  3068. $this->error .= $error;
  3069. }
  3070. }
  3071. /**
  3072. * Launches the current item if not 'sco' (starts timer and make sure there is a record ready in the DB)
  3073. *
  3074. */
  3075. function start_current_item($allow_new_attempt=false){
  3076. if($this->debug>0){error_log('New LP - In learnpath::start_current_item()',0);}
  3077. if($this->current != 0 AND
  3078. is_object($this->items[$this->current]))
  3079. {
  3080. $type = $this->get_type();
  3081. $item_type = $this->items[$this->current]->get_type();
  3082. if(
  3083. ($type == 2 && $item_type!='sco')
  3084. OR
  3085. ($type == 3 && $item_type!='au')
  3086. OR
  3087. ($type == 1 && $item_type!=TOOL_QUIZ && $item_type!=TOOL_HOTPOTATOES)
  3088. )
  3089. {
  3090. $this->items[$this->current]->open($allow_new_attempt);
  3091. $this->autocomplete_parents($this->current);
  3092. $prereq_check = $this->prerequisites_match($this->current);
  3093. $this->items[$this->current]->save(false,$prereq_check);
  3094. //$this->update_queue[$this->last] = $this->items[$this->last]->get_status();
  3095. }else{
  3096. //if sco, then it is supposed to have been updated by some other call
  3097. }
  3098. }
  3099. if($this->debug>0){error_log('New LP - End of learnpath::start_current_item()',0);}
  3100. return true;
  3101. }
  3102. /**
  3103. * Stops the processing and counters for the old item (as held in $this->last)
  3104. * @param
  3105. */
  3106. function stop_previous_item(){
  3107. if($this->debug>0){error_log('New LP - In learnpath::stop_previous_item()',0);}
  3108. if($this->last != 0 AND $this->last!=$this->current AND is_object($this->items[$this->last]))
  3109. {
  3110. if($this->debug>2){error_log('New LP - In learnpath::stop_previous_item() - '.$this->last.' is object',0);}
  3111. switch($this->get_type()){
  3112. case '3':
  3113. if($this->items[$this->last]->get_type()!='au')
  3114. {
  3115. if($this->debug>2){error_log('New LP - In learnpath::stop_previous_item() - '.$this->last.' in lp_type 3 is <> au',0);}
  3116. $this->items[$this->last]->close();
  3117. //$this->autocomplete_parents($this->last);
  3118. //$this->update_queue[$this->last] = $this->items[$this->last]->get_status();
  3119. }else{
  3120. if($this->debug>2){error_log('New LP - In learnpath::stop_previous_item() - Item is an AU, saving is managed by AICC signals',0);}
  3121. }
  3122. case '2':
  3123. if($this->items[$this->last]->get_type()!='sco')
  3124. {
  3125. if($this->debug>2){error_log('New LP - In learnpath::stop_previous_item() - '.$this->last.' in lp_type 2 is <> sco',0);}
  3126. $this->items[$this->last]->close();
  3127. //$this->autocomplete_parents($this->last);
  3128. //$this->update_queue[$this->last] = $this->items[$this->last]->get_status();
  3129. }else{
  3130. if($this->debug>2){error_log('New LP - In learnpath::stop_previous_item() - Item is a SCO, saving is managed by SCO signals',0);}
  3131. }
  3132. break;
  3133. case '1':
  3134. default:
  3135. if($this->debug>2){error_log('New LP - In learnpath::stop_previous_item() - '.$this->last.' in lp_type 1 is asset',0);}
  3136. $this->items[$this->last]->close();
  3137. break;
  3138. }
  3139. }else{
  3140. if($this->debug>2){error_log('New LP - In learnpath::stop_previous_item() - No previous element found, ignoring...',0);}
  3141. return false;
  3142. }
  3143. return true;
  3144. }
  3145. /**
  3146. * Updates the default view mode from fullscreen to embedded and inversely
  3147. * @return string The current default view mode ('fullscreen' or 'embedded')
  3148. */
  3149. function update_default_view_mode()
  3150. {
  3151. if($this->debug>0){error_log('New LP - In learnpath::update_default_view_mode()',0);}
  3152. $lp_table = Database::get_course_table('lp');
  3153. $sql = "SELECT * FROM $lp_table WHERE id = ".$this->get_id();
  3154. $res = api_sql_query($sql, __FILE__, __LINE__);
  3155. if(Database::num_rows($res)>0){
  3156. $row = Database::fetch_array($res);
  3157. $view_mode = $row['default_view_mod'];
  3158. if($view_mode == 'fullscreen'){
  3159. $view_mode = 'embedded';
  3160. }elseif($view_mode == 'embedded'){
  3161. $view_mode = 'fullscreen';
  3162. }
  3163. $sql = "UPDATE $lp_table SET default_view_mod = '$view_mode' WHERE id = ".$this->get_id();
  3164. $res = api_sql_query($sql, __FILE__, __LINE__);
  3165. $this->mode = $view_mode;
  3166. return $view_mode;
  3167. }else{
  3168. if($this->debug>2){error_log('New LP - Problem in update_default_view() - could not find LP '.$this->get_id().' in DB',0);}
  3169. }
  3170. return -1;
  3171. }
  3172. /**
  3173. * Updates the default behaviour about auto-commiting SCORM updates
  3174. * @return boolean True if auto-commit has been set to 'on', false otherwise
  3175. */
  3176. function update_default_scorm_commit(){
  3177. if($this->debug>0){error_log('New LP - In learnpath::update_default_scorm_commit()',0);}
  3178. $lp_table = Database::get_course_table('lp');
  3179. $sql = "SELECT * FROM $lp_table WHERE id = ".$this->get_id();
  3180. $res = api_sql_query($sql, __FILE__, __LINE__);
  3181. if(Database::num_rows($res)>0){
  3182. $row = Database::fetch_array($res);
  3183. $force = $row['force_commit'];
  3184. if($force == 1){
  3185. $force = 0;
  3186. $force_return = false;
  3187. }elseif($force == 0){
  3188. $force = 1;
  3189. $force_return = true;
  3190. }
  3191. $sql = "UPDATE $lp_table SET force_commit = $force WHERE id = ".$this->get_id();
  3192. $res = api_sql_query($sql, __FILE__, __LINE__);
  3193. $this->force_commit = $force_return;
  3194. return $force_return;
  3195. }else{
  3196. if($this->debug>2){error_log('New LP - Problem in update_default_scorm_commit() - could not find LP '.$this->get_id().' in DB',0);}
  3197. }
  3198. return -1;
  3199. }
  3200. /**
  3201. * Updates the order of learning paths (goes through all of them by order and fills the gaps)
  3202. * @return bool True on success, false on failure
  3203. */
  3204. function update_display_order()
  3205. {
  3206. $lp_table = Database::get_course_table(TABLE_LP_MAIN);
  3207. $sql = "SELECT * FROM $lp_table ORDER BY display_order";
  3208. $res = api_sql_query($sql, __FILE__, __LINE__);
  3209. if($res === false) return false;
  3210. $lps = array();
  3211. $lp_order = array();
  3212. $num = Database::num_rows($res);
  3213. //first check the order is correct, globally (might be wrong because
  3214. //of versions < 1.8.4)
  3215. if($num>0)
  3216. {
  3217. $i = 1;
  3218. while($row = Database::fetch_array($res))
  3219. {
  3220. if($row['display_order'] != $i)
  3221. { //if we find a gap in the order, we need to fix it
  3222. $need_fix = true;
  3223. $sql_u = "UPDATE $lp_table SET display_order = $i WHERE id = ".$row['id'];
  3224. $res_u = api_sql_query($sql_u, __FILE__, __LINE__);
  3225. }
  3226. $i++;
  3227. }
  3228. }
  3229. return true;
  3230. }
  3231. /**
  3232. * Updates the "prevent_reinit" value that enables control on reinitialising items on second view
  3233. * @return boolean True if prevent_reinit has been set to 'on', false otherwise (or 1 or 0 in this case)
  3234. */
  3235. function update_reinit(){
  3236. if($this->debug>0){error_log('New LP - In learnpath::update_reinit()',0);}
  3237. $lp_table = Database::get_course_table('lp');
  3238. $sql = "SELECT * FROM $lp_table WHERE id = ".$this->get_id();
  3239. $res = api_sql_query($sql, __FILE__, __LINE__);
  3240. if(Database::num_rows($res)>0){
  3241. $row = Database::fetch_array($res);
  3242. $force = $row['prevent_reinit'];
  3243. if($force == 1){
  3244. $force = 0;
  3245. }elseif($force == 0){
  3246. $force = 1;
  3247. }
  3248. $sql = "UPDATE $lp_table SET prevent_reinit = $force WHERE id = ".$this->get_id();
  3249. $res = api_sql_query($sql,__FILE__,__LINE__);
  3250. $this->prevent_reinit = $force;
  3251. return $force;
  3252. }else{
  3253. if($this->debug>2){error_log('New LP - Problem in update_reinit() - could not find LP '.$this->get_id().' in DB',0);}
  3254. }
  3255. return -1;
  3256. }
  3257. /**
  3258. * Updates the "scorm_debug" value that shows or hide the debug window
  3259. * @return boolean True if scorm_debug has been set to 'on', false otherwise (or 1 or 0 in this case)
  3260. */
  3261. function update_scorm_debug(){
  3262. if($this->debug>0){error_log('New LP - In learnpath::update_scorm_debug()',0);}
  3263. $lp_table = Database::get_course_table('lp');
  3264. $sql = "SELECT * FROM $lp_table WHERE id = ".$this->get_id();
  3265. $res = api_sql_query($sql, __FILE__, __LINE__);
  3266. if(Database::num_rows($res)>0){
  3267. $row = Database::fetch_array($res);
  3268. $force = $row['debug'];
  3269. if($force == 1){
  3270. $force = 0;
  3271. }elseif($force == 0){
  3272. $force = 1;
  3273. }
  3274. $sql = "UPDATE $lp_table SET debug = $force WHERE id = ".$this->get_id();
  3275. $res = api_sql_query($sql,__FILE__,__LINE__);
  3276. $this->scorm_debug = $force;
  3277. return $force;
  3278. }else{
  3279. if($this->debug>2){error_log('New LP - Problem in update_scorm_debug() - could not find LP '.$this->get_id().' in DB',0);}
  3280. }
  3281. return -1;
  3282. }
  3283. /**
  3284. * Function that makes a call to the function sort_tree_array and create_tree_array
  3285. *
  3286. * @author Kevin Van Den Haute
  3287. *
  3288. * @param unknown_type $array
  3289. */
  3290. function tree_array($array)
  3291. {
  3292. $array = $this->sort_tree_array($array);
  3293. $this->create_tree_array($array);
  3294. }
  3295. /**
  3296. * Creates an array with the elements of the learning path tree in it
  3297. *
  3298. * @author Kevin Van Den Haute
  3299. *
  3300. * @param array $array
  3301. * @param int $parent
  3302. * @param int $depth
  3303. * @param array $tmp
  3304. */
  3305. function create_tree_array($array, $parent = 0, $depth = -1, $tmp = array())
  3306. {
  3307. if(is_array($array))
  3308. {
  3309. for($i = 0; $i < count($array); $i++)
  3310. {
  3311. if($array[$i]['parent_item_id'] == $parent)
  3312. {
  3313. if(!in_array($array[$i]['parent_item_id'], $tmp))
  3314. {
  3315. $tmp[] = $array[$i]['parent_item_id'];
  3316. $depth++;
  3317. }
  3318. $this->arrMenu[] = array(
  3319. 'id' => $array[$i]['id'],
  3320. 'item_type' => $array[$i]['item_type'],
  3321. 'title' => $array[$i]['title'],
  3322. 'path' => $array[$i]['path'],
  3323. 'description' => $array[$i]['description'],
  3324. 'parent_item_id' => $array[$i]['parent_item_id'],
  3325. 'previous_item_id' => $array[$i]['previous_item_id'],
  3326. 'next_item_id' => $array[$i]['next_item_id'],
  3327. 'min_score' => $array[$i]['min_score'],
  3328. 'max_score' => $array[$i]['max_score'],
  3329. 'mastery_score' => $array[$i]['mastery_score'],
  3330. 'display_order' => $array[$i]['display_order'],
  3331. 'prerequisite' => $array[$i]['prerequisite'],
  3332. 'depth' => $depth
  3333. );
  3334. $this->create_tree_array($array, $array[$i]['id'], $depth, $tmp);
  3335. }
  3336. }
  3337. }
  3338. }
  3339. /**
  3340. * Sorts a multi dimensional array by parent id and display order
  3341. * @author Kevin Van Den Haute
  3342. *
  3343. * @param array $array (array with al the learning path items in it)
  3344. *
  3345. * @return array
  3346. */
  3347. function sort_tree_array($array)
  3348. {
  3349. foreach($array as $key => $row)
  3350. {
  3351. $parent[$key] = $row['parent_item_id'];
  3352. $position[$key] = $row['display_order'];
  3353. }
  3354. if(count($array) > 0)
  3355. array_multisort($parent, SORT_ASC, $position, SORT_ASC, $array);
  3356. return $array;
  3357. }
  3358. /**
  3359. * Function that creates a table structure with a learning path his modules, chapters and documents.
  3360. * Also the actions for the modules, chapters and documents are in this table.
  3361. *
  3362. * @author Kevin Van Den Haute
  3363. *
  3364. * @param int $lp_id
  3365. *
  3366. * @return string
  3367. */
  3368. function overview()
  3369. {
  3370. $return = '';
  3371. $tbl_lp_item = Database::get_course_table('lp_item');
  3372. $sql = "
  3373. SELECT *
  3374. FROM " . $tbl_lp_item . "
  3375. WHERE
  3376. lp_id = " . $this->lp_id;
  3377. $result = api_sql_query($sql, __FILE__, __LINE__);
  3378. $arrLP = array();
  3379. while($row = Database::fetch_array($result))
  3380. {
  3381. $arrLP[] = array(
  3382. 'id' => $row['id'],
  3383. 'item_type' => $row['item_type'],
  3384. 'title' => stripslashes(html_entity_decode($row['title'])),
  3385. 'description' => $row['description'],
  3386. 'parent_item_id' => $row['parent_item_id'],
  3387. 'previous_item_id' => $row['previous_item_id'],
  3388. 'next_item_id' => $row['next_item_id'],
  3389. 'display_order' => $row['display_order']);
  3390. }
  3391. $this->tree_array($arrLP);
  3392. $arrLP = $this->arrMenu;
  3393. unset($this->arrMenu);
  3394. if(api_is_allowed_to_edit())
  3395. $return .= '<p><a href="' .api_get_self(). '?cidReq=' . $_GET['cidReq'] . '&amp;action=build&amp;lp_id=' . $this->lp_id . '">'.get_lang("Advanced").'</a>&nbsp;&#124;&nbsp;'.get_lang("BasicOverview").'&nbsp;&#124;&nbsp;<a href="lp_controller.php?cidReq='.$_GET['cidReq'].'&action=view&lp_id='.$this->lp_id.'">'.get_lang("Display").'</a></p>';
  3396. $return .= '<table class="data_table">' . "\n";
  3397. $return .= "\t" . '<tr>' . "\n";
  3398. $return .= "\t" . '<th width="75%">'.get_lang("Title").'</th>' . "\n";
  3399. //$return .= "\t" . '<th>'.get_lang("Description").'</th>' . "\n";
  3400. $return .= "\t" . '<th>'.get_lang("Move").'</th>' . "\n";
  3401. $return .= "\t" . '<th>'.get_lang("Actions").'</th>' . "\n";
  3402. $return .= "\t" . '</tr>' . "\n";
  3403. for($i = 0; $i < count($arrLP); $i++)
  3404. {
  3405. if($arrLP[$i]['description'] == '')
  3406. $arrLP[$i]['description'] = '&nbsp;';
  3407. if (($i % 2)==0) { $oddclass="row_odd"; } else { $oddclass="row_even"; }
  3408. $return .= "\t" . '<tr class="'.$oddclass.'">' . "\n";
  3409. $return .= "\t\t" . '<td style="padding-left:' . $arrLP[$i]['depth'] * 10 . 'px;"><img align="left" src="../img/lp_' . $arrLP[$i]['item_type'] . '.png" style="margin-right:3px;" />' . stripslashes($arrLP[$i]['title']) . '</td>' . "\n";
  3410. //$return .= "\t\t" . '<td>' . stripslashes($arrLP[$i]['description']) . '</td>' . "\n";
  3411. if(api_is_allowed_to_edit())
  3412. {
  3413. $return .= "\t\t" . '<td>' . "\n";
  3414. if($arrLP[$i]['previous_item_id'] != 0)
  3415. {
  3416. $return .= "\t\t\t" . '<a href="' .api_get_self(). '?cidReq=' . $_GET['cidReq'] . '&amp;action=move_item&amp;direction=up&amp;id=' . $arrLP[$i]['id'] . '&amp;lp_id=' . $this->lp_id . '">';
  3417. $return .= '<img alt="" src="../img/arrow_up_' . ($arrLP[$i]['depth'] % 3) . '.gif" />';
  3418. $return .= '</a>' . "\n";
  3419. }
  3420. else
  3421. $return .= "\t\t\t" . '<img alt="" src="../img/blanco.png" title="" />' . "\n";
  3422. if($arrLP[$i]['next_item_id'] != 0)
  3423. {
  3424. $return .= "\t\t\t" . '<a href="' .api_get_self(). '?cidReq=' . $_GET['cidReq'] . '&amp;action=move_item&amp;direction=down&amp;id=' . $arrLP[$i]['id'] . '&amp;lp_id=' . $this->lp_id . '">';
  3425. $return .= '<img src="../img/arrow_down_' . ($arrLP[$i]['depth'] % 3) . '.gif" />';
  3426. $return .= '</a>' . "\n";
  3427. }
  3428. else
  3429. $return .= "\t\t\t" . '<img alt="" src="../img/blanco.png" title="" />' . "\n";
  3430. $return .= "\t\t" . '</td>' . "\n";
  3431. $return .= "\t\t" . '<td>' . "\n";
  3432. if($arrLP[$i]['item_type'] != 'dokeos_chapter' && $arrLP[$i]['item_type'] != 'dokeos_module')
  3433. {
  3434. $return .= "\t\t\t" . '<a href="' .api_get_self(). '?cidReq=' . $_GET['cidReq'] . '&amp;action=edit_item&amp;view=build&amp;id=' . $arrLP[$i]['id'] . '&amp;lp_id=' . $this->lp_id . '">';
  3435. $return .= '<img alt="" src="../img/edit.gif" title="' . get_lang('_edit_learnpath_module') . '" />';
  3436. $return .= '</a>' . "\n";
  3437. }
  3438. else
  3439. {
  3440. $return .= "\t\t\t" . '<a href="' .api_get_self(). '?cidReq=' . $_GET['cidReq'] . '&amp;action=edit_item&amp;id=' . $arrLP[$i]['id'] . '&amp;lp_id=' . $this->lp_id . '">';
  3441. $return .= '<img alt="" src="../img/edit.gif" title="' . get_lang('_edit_learnpath_module') . '" />';
  3442. $return .= '</a>' . "\n";
  3443. }
  3444. $return .= "\t\t\t" . '<a href="' .api_get_self(). '?cidReq=' . $_GET['cidReq'] . '&amp;action=delete_item&amp;id=' . $arrLP[$i]['id'] . '&amp;lp_id=' . $this->lp_id . '" onclick="return confirmation(\'' . $arrLP[$i]['title'] . '\');">';
  3445. $return .= '<img alt="" src="../img/delete.gif" title="' . get_lang('_delete_learnpath_module') . '" />';
  3446. $return .= '</a>' . "\n";
  3447. $return .= "\t\t" . '</td>' . "\n";
  3448. }
  3449. $return .= "\t" . '</tr>' . "\n";
  3450. }
  3451. if(count($arrLP) == 0)
  3452. {
  3453. $return .= "\t" . '<tr>' . "\n";
  3454. $return .= "\t\t" . '<td colspan="4">'.get_lang("NoItemsInLp").'</td>' . "\n";
  3455. $return .= "\t" . '</tr>' . "\n";
  3456. }
  3457. $return .= '</table>' . "\n";
  3458. return $return;
  3459. }
  3460. /**
  3461. * This functions builds the LP tree based on data from the database.
  3462. *
  3463. * @return string
  3464. * @uses dtree.js :: necessary javascript for building this tree
  3465. */
  3466. function build_tree()
  3467. {
  3468. $return = "<script type=\"text/javascript\">\n";
  3469. $return .= "\tm = new dTree('m');\n\n";
  3470. $return .= "\tm.config.folderLinks = true;\n";
  3471. $return .= "\tm.config.useCookies = true;\n";
  3472. $return .= "\tm.config.useIcons = true;\n";
  3473. $return .= "\tm.config.useLines = true;\n";
  3474. $return .= "\tm.config.useSelection = true;\n";
  3475. $return .= "\tm.config.useStatustext = false;\n\n";
  3476. $menu = 0;
  3477. $parent = '';
  3478. $return .= "\tm.add(" . $menu . ", -1, '" . addslashes($this->name) . "');\n";
  3479. $tbl_lp_item = Database::get_course_table('lp_item');
  3480. $sql = "
  3481. SELECT *
  3482. FROM " . $tbl_lp_item . "
  3483. WHERE
  3484. lp_id = " . $this->lp_id;
  3485. $result = api_sql_query($sql, __FILE__, __LINE__);
  3486. $arrLP = array();
  3487. while($row = Database::fetch_array($result))
  3488. {
  3489. if($this->encoding=='UTF-8')
  3490. {
  3491. $row['title'] = utf8_decode($row['title']);
  3492. }
  3493. $arrLP[] = array(
  3494. 'id' => $row['id'],
  3495. 'item_type' => $row['item_type'],
  3496. 'title' => $row['title'],
  3497. 'path' => $row['path'],
  3498. 'description' => $row['description'],
  3499. 'parent_item_id' => $row['parent_item_id'],
  3500. 'previous_item_id' => $row['previous_item_id'],
  3501. 'next_item_id' => $row['next_item_id'],
  3502. 'display_order' => $row['display_order']);
  3503. }
  3504. $this->tree_array($arrLP);
  3505. $arrLP = $this->arrMenu;
  3506. unset($this->arrMenu);
  3507. $title='';
  3508. for($i = 0; $i < count($arrLP); $i++)
  3509. {
  3510. $title = addslashes($arrLP[$i]['title']);
  3511. $menu_page = api_get_self() . '?cidReq=' . $_GET['cidReq'] . '&amp;action=view_item&amp;id=' . $arrLP[$i]['id'] . '&amp;lp_id=' . $_SESSION['oLP']->lp_id;
  3512. if(file_exists("../img/lp_" . $arrLP[$i]['item_type'] . ".png"))
  3513. {
  3514. $return .= "\tm.add(" . $arrLP[$i]['id'] . ", " . $arrLP[$i]['parent_item_id'] . ", '" . $title . "', '" . $menu_page . "', '', '', '../img/lp_" . $arrLP[$i]['item_type'] . ".png', '../img/lp_" . $arrLP[$i]['item_type'] . ".png');\n";
  3515. }
  3516. else if(file_exists("../img/lp_" . $arrLP[$i]['item_type'] . ".gif"))
  3517. {
  3518. $return .= "\tm.add(" . $arrLP[$i]['id'] . ", " . $arrLP[$i]['parent_item_id'] . ", '" . $title . "', '" . $menu_page . "', '', '', '../img/lp_" . $arrLP[$i]['item_type'] . ".gif', '../img/lp_" . $arrLP[$i]['item_type'] . ".gif');\n";
  3519. }
  3520. else
  3521. {
  3522. $return .= "\tm.add(" . $arrLP[$i]['id'] . ", " . $arrLP[$i]['parent_item_id'] . ", '" . $title . "', '" . $menu_page . "', '', '', '../img/lp_document.png', '../img/lp_document.png');\n";
  3523. }
  3524. if($menu < $arrLP[$i]['id'])
  3525. $menu = $arrLP[$i]['id'];
  3526. }
  3527. $return .= "\n\tdocument.write(m);\n";
  3528. $return .= "\t if(!m.selectedNode) m.s(1);";
  3529. $return .= "</script>\n";
  3530. return $return;
  3531. }
  3532. /**
  3533. * Create a new document //still needs some finetuning
  3534. *
  3535. * @param array $_course
  3536. * @return string
  3537. */
  3538. function create_document($_course)
  3539. {
  3540. $dir = isset($_GET['dir']) ? $_GET['dir'] : $_POST['dir']; // please do not modify this dirname formatting
  3541. if(strstr($dir, '..'))
  3542. $dir = '/';
  3543. if($dir[0] == '.')
  3544. $dir = substr($dir, 1);
  3545. if($dir[0] != '/')
  3546. $dir = '/'.$dir;
  3547. if($dir[strlen($dir) - 1] != '/')
  3548. $dir .= '/';
  3549. $filepath = api_get_path('SYS_COURSE_PATH') . $_course['path'] . '/document' . $dir;
  3550. if(!is_dir($filepath))
  3551. {
  3552. $filepath = api_get_path('SYS_COURSE_PATH') . $_course['path'] . '/document/';
  3553. $dir = '/';
  3554. }
  3555. //stripslashes before calling replace_dangerous_char() because $_POST['title']
  3556. //is already escaped twice when it gets here
  3557. $title = replace_dangerous_char(stripslashes($_POST['title']));
  3558. $filename = $title;
  3559. $content = $_POST['content_lp'];
  3560. $tmp_filename = $filename;
  3561. $i=0;
  3562. while(file_exists($filepath . $tmp_filename . '.html'))
  3563. $tmp_filename = $filename . '_' . ++$i;
  3564. $filename = $tmp_filename . '.html';
  3565. $content = stripslashes(text_filter($content));
  3566. //if flv player, change absolute paht temporarely to prevent from erasing it in the following lines
  3567. $content = str_replace('flv=h','flv=h|',$content);
  3568. $content = str_replace('flv=/','flv=/|',$content);
  3569. $content = str_replace(api_get_path('WEB_COURSE_PATH'), api_get_path(REL_PATH).'courses/', $content);
  3570. // for flv player : change back the url to absolute
  3571. $content = str_replace('flv=h|','flv=h',$content);
  3572. $content = str_replace('flv=/|','flv=/',$content);
  3573. // for flv player : to prevent edition problem with firefox, we have to use a strange tip (don't blame me please)
  3574. $content = str_replace('</body>','<style type="text/css">body{}</style></body>',$content);
  3575. if(!file_exists($filepath . $filename))
  3576. {
  3577. if($fp = @fopen($filepath . $filename, 'w'))
  3578. {
  3579. fputs($fp, $content);
  3580. fclose($fp);
  3581. $file_size = filesize($filepath . $filename);
  3582. $save_file_path = $dir . $filename;
  3583. $document_id = add_document($_course, $save_file_path, 'file', $file_size, $filename . '.html');
  3584. if($document_id)
  3585. {
  3586. api_item_property_update($_course, TOOL_DOCUMENT, $document_id, 'DocumentAdded', api_get_user_id());
  3587. //update parent folders
  3588. //item_property_update_on_folder($_course, $_GET['dir'], $_user['user_id']);
  3589. $new_comment = (isset($_POST['comment'])) ? trim($_POST['comment']) : '';
  3590. $new_title = (isset($_POST['title'])) ? trim($_POST['title']) : '';
  3591. if($new_comment || $new_title)
  3592. {
  3593. $tbl_doc = Database::get_course_table(TABLE_DOCUMENT);
  3594. $ct = '';
  3595. if($new_comment)
  3596. $ct .= ", comment='" . $new_comment . "'";
  3597. if($new_title)
  3598. $ct .= ", title='" . $new_title . ".html '";
  3599. $sql_update = "
  3600. UPDATE " . $tbl_doc . "
  3601. SET " . substr($ct, 1) . "
  3602. WHERE id = " . $document_id;
  3603. api_sql_query($sql_update, __FILE__, __LINE__);
  3604. }
  3605. }
  3606. return $document_id;
  3607. }
  3608. }
  3609. }
  3610. /**
  3611. * Enter description here...
  3612. *
  3613. * @param array $_course
  3614. */
  3615. function edit_document($_course)
  3616. {
  3617. global $_configuration;
  3618. $dir = isset($_GET['dir']) ? $_GET['dir'] : $_POST['dir']; // please do not modify this dirname formatting
  3619. if(strstr($dir, '..'))
  3620. $dir = '/';
  3621. if($dir[0] == '.')
  3622. $dir = substr($dir, 1);
  3623. if($dir[0] != '/')
  3624. $dir = '/'.$dir;
  3625. if($dir[strlen($dir) - 1] != '/')
  3626. $dir .= '/';
  3627. $filepath = api_get_path('SYS_COURSE_PATH') . $_course['path'] . '/document'.$dir;
  3628. if(!is_dir($filepath))
  3629. {
  3630. $filepath = api_get_path('SYS_COURSE_PATH') . $_course['path'] . '/document/';
  3631. $dir = '/';
  3632. }
  3633. $table_doc = Database::get_course_table(TABLE_DOCUMENT);
  3634. $sql = "
  3635. SELECT path
  3636. FROM " . $table_doc . "
  3637. WHERE id = " . $_POST['path'];
  3638. $res = api_sql_query($sql, __FILE__, __LINE__);
  3639. $row = Database::fetch_array($res);
  3640. $content = stripslashes($_POST['content_lp']);
  3641. $file = $filepath . $row['path'];
  3642. if($fp = @fopen($file, 'w'))
  3643. {
  3644. $content = text_filter($content);
  3645. $content = str_replace(api_get_path('WEB_COURSE_PATH'), $_configuration['url_append'].'/courses/', $content);
  3646. fputs($fp, $content);
  3647. fclose($fp);
  3648. }
  3649. }
  3650. /**
  3651. * Displays the selected item, with a panel for manipulating the item
  3652. *
  3653. * @param int $item_id
  3654. * @param string $msg
  3655. * @return string
  3656. */
  3657. function display_item($item_id, $iframe = true, $msg = '')
  3658. {
  3659. global $_course; //will disappear
  3660. $return = '';
  3661. if(is_numeric($item_id))
  3662. {
  3663. $tbl_lp_item = Database::get_course_table('lp_item');
  3664. $tbl_doc = Database::get_course_table(TABLE_DOCUMENT);
  3665. $sql = "
  3666. SELECT
  3667. lp.*
  3668. FROM " . $tbl_lp_item . " as lp
  3669. WHERE
  3670. lp.id = " . $item_id;
  3671. $result = api_sql_query($sql, __FILE__, __LINE__);
  3672. while($row = Database::fetch_array($result))
  3673. {
  3674. $return .= $this->display_manipulate($item_id, $row['item_type']);
  3675. $return .= '<div style="padding:10px;">';
  3676. if($msg != '')
  3677. $return .= $msg;
  3678. if($this->encoding=='UTF-8')
  3679. {
  3680. $row['title'] = utf8_decode($row['title']);
  3681. }
  3682. $return .= '<p class="lp_title">' . stripslashes($row['title']) . '</p>';
  3683. //$return .= '<p class="lp_text">' . ((trim($row['description']) == '') ? 'no description' : stripslashes($row['description'])) . '</p>';
  3684. //$return .= '<hr />';
  3685. if($row['item_type'] == TOOL_DOCUMENT)
  3686. {
  3687. $tbl_doc = Database :: get_course_table(TABLE_DOCUMENT);
  3688. $sql_doc = "SELECT path FROM " . $tbl_doc . " WHERE id = " . $row['path'];
  3689. $result=api_sql_query($sql_doc, __FILE__, __LINE__);
  3690. $path_file=mysql_result($result,0,0);
  3691. $path_parts = pathinfo($path_file);
  3692. if(in_array($path_parts['extension'],array('html','txt','png', 'jpg', 'JPG', 'jpeg', 'JPEG', 'gif', 'swf')))
  3693. {
  3694. $return .= $this->display_document($row['path'], true, true);
  3695. }
  3696. }
  3697. $return .= '</div>';
  3698. }
  3699. }
  3700. return $return;
  3701. }
  3702. /**
  3703. * Shows the needed forms for editing a specific item
  3704. *
  3705. * @param int $item_id
  3706. * @return string
  3707. */
  3708. function display_edit_item($item_id)
  3709. {
  3710. global $_course; //will disappear
  3711. $return = '';
  3712. if(is_numeric($item_id))
  3713. {
  3714. $tbl_lp_item = Database::get_course_table('lp_item');
  3715. $sql = "
  3716. SELECT *
  3717. FROM " . $tbl_lp_item . "
  3718. WHERE id = " . $item_id;
  3719. $res = api_sql_query($sql, __FILE__, __LINE__);
  3720. $row = Database::fetch_array($res);
  3721. switch($row['item_type'])
  3722. {
  3723. case 'dokeos_chapter': case 'dir' : case 'asset' : case 'sco' :
  3724. if(isset($_GET['view']) && $_GET['view'] == 'build')
  3725. {
  3726. $return .= $this->display_manipulate($item_id, $row['item_type']);
  3727. $return .= $this->display_item_form($row['item_type'], get_lang("EditCurrentChapter").' :', 'edit', $item_id, $row);
  3728. }
  3729. else
  3730. {
  3731. $return .= $this->display_item_small_form($row['item_type'], get_lang("EditCurrentChapter").' :', $row);
  3732. }
  3733. break;
  3734. case TOOL_DOCUMENT:
  3735. $tbl_doc = Database::get_course_table(TABLE_DOCUMENT);
  3736. $sql_step = "
  3737. SELECT
  3738. lp.*,
  3739. doc.path as dir
  3740. FROM " . $tbl_lp_item . " as lp
  3741. LEFT JOIN " . $tbl_doc . " as doc ON doc.id = lp.path
  3742. WHERE
  3743. lp.id = " . $item_id;
  3744. $res_step = api_sql_query($sql_step, __FILE__, __LINE__);
  3745. $row_step = Database::fetch_array($res_step);
  3746. $return .= $this->display_manipulate($item_id, $row['item_type']);
  3747. $return .= $this->display_document_form('edit', $item_id, $row_step);
  3748. break;
  3749. case TOOL_LINK:
  3750. $return .= $this->display_manipulate($item_id, $row['item_type']);
  3751. $return .= $this->display_link_form('edit', $item_id, $row);
  3752. break;
  3753. case 'dokeos_module':
  3754. if(isset($_GET['view']) && $_GET['view'] == 'build')
  3755. {
  3756. $return .= $this->display_manipulate($item_id, $row['item_type']);
  3757. $return .= $this->display_item_form($row['item_type'], get_lang("EditCurrentModule").' :', 'edit', $item_id, $row);
  3758. }
  3759. else
  3760. {
  3761. $return .= $this->display_item_small_form($row['item_type'], get_lang("EditCurrentModule").' :', $row);
  3762. }
  3763. break;
  3764. case TOOL_QUIZ:
  3765. $return .= $this->display_manipulate($item_id, $row['item_type']);
  3766. $return .= $this->display_quiz_form('edit', $item_id, $row);
  3767. break;
  3768. case TOOL_HOTPOTATOES:
  3769. $return .= $this->display_manipulate($item_id, $row['item_type']);
  3770. $return .= $this->display_hotpotatoes_form('edit', $item_id, $row);
  3771. break;
  3772. case TOOL_STUDENTPUBLICATION:
  3773. $return .= $this->display_manipulate($item_id, $row['item_type']);
  3774. $return .= $this->display_student_publication_form('edit', $item_id, $row);
  3775. break;
  3776. case TOOL_FORUM:
  3777. $return .= $this->display_manipulate($item_id, $row['item_type']);
  3778. $return .= $this->display_forum_form('edit', $item_id, $row);
  3779. break;
  3780. case TOOL_THREAD:
  3781. $return .= $this->display_manipulate($item_id, $row['item_type']);
  3782. $return .= $this->display_thread_form('edit', $item_id, $row);
  3783. break;
  3784. }
  3785. }
  3786. return $return;
  3787. }
  3788. /**
  3789. * Function that displays a list with al the resources that could be added to the learning path
  3790. *
  3791. * @return string
  3792. */
  3793. function display_resources()
  3794. {
  3795. global $_course; //TODO: don't use globals
  3796. $return = '<div style="margin:3px 10px;">' . "\n";
  3797. $return .= '<p class="lp_title" style="margin-top:0;">'.get_lang("CreateNewStep").'</p>';
  3798. $return .= '<div><a href="' .api_get_self(). '?cidReq=' . $_GET['cidReq'] . '&amp;action=add_item&amp;type=' . TOOL_DOCUMENT . '&amp;lp_id=' . $_SESSION['oLP']->lp_id . '">'.get_lang("NewDocument").'</a></div>';
  3799. $return .= '<p class="lp_title" style="margin-top:10px;">'.get_lang("UseAnExistingResource").'</p>';
  3800. /* get all the docs */
  3801. $return .= $this->get_documents();
  3802. /* get all the exercises */
  3803. $return .= $this->get_exercises();
  3804. /* get all the links */
  3805. $return .= $this->get_links();
  3806. /* get al the student publications */
  3807. $return .= $this->get_student_publications();
  3808. /* get al the forums */
  3809. $return .= $this->get_forums();
  3810. $return .= '</div>' . "\n";
  3811. return $return;
  3812. }
  3813. /**
  3814. * Returns the extension of a document
  3815. *
  3816. * @param unknown_type $filename
  3817. * @return unknown
  3818. */
  3819. function get_extension($filename)
  3820. {
  3821. $explode = explode('.', $filename);
  3822. return $explode[count($explode) - 1];
  3823. }
  3824. /**
  3825. * Displays a document by id
  3826. *
  3827. * @param unknown_type $id
  3828. * @return unknown
  3829. */
  3830. function display_document($id, $show_title = false, $iframe = true, $edit_link = false)
  3831. {
  3832. global $_course; //temporary
  3833. $return = '';
  3834. $tbl_doc = Database::get_course_table(TABLE_DOCUMENT);
  3835. $sql_doc = "
  3836. SELECT *
  3837. FROM " . $tbl_doc . "
  3838. WHERE id = " . $id;
  3839. $res_doc = api_sql_query($sql_doc, __FILE__, __LINE__);
  3840. $row_doc = Database::fetch_array($res_doc);
  3841. //if($show_title)
  3842. //$return .= '<p class="lp_title">' . $row_doc['title'] . ($edit_link ? ' [ <a href="' .api_get_self(). '?cidReq=' . $_GET['cidReq'] . '&amp;action=add_item&amp;type=' . TOOL_DOCUMENT . '&amp;file=' . $_GET['file'] . '&amp;edit=true&amp;lp_id=' . $_GET['lp_id'] . '">Edit this document</a> ]' : '') . '</p>';
  3843. //TODO: add a path filter
  3844. if($iframe){
  3845. $return .= '<iframe frameborder="0" src="' . api_get_path(WEB_COURSE_PATH) . $_course['path'] . '/document' . str_replace('%2F','/',urlencode($row_doc['path'])) . '?'.api_get_cidreq().'" style="background:#FFFFFF; border:1px solid #CCCCCC; height:490px; width:100%; margin-top: 20px;"></iframe>';
  3846. }
  3847. else{
  3848. $return .= file_get_contents(api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document' . $row_doc['path']);
  3849. }
  3850. return $return;
  3851. }
  3852. /**
  3853. * Enter description here...
  3854. *
  3855. * @param unknown_type $action
  3856. * @param unknown_type $id
  3857. * @param unknown_type $extra_info
  3858. * @return unknown
  3859. */
  3860. function display_quiz_form($action = 'add', $id = 0, $extra_info = '')
  3861. {
  3862. $tbl_lp_item = Database::get_course_table(TABLE_LP_ITEM);
  3863. $tbl_quiz = Database::get_course_table(TABLE_QUIZ_TEST);
  3864. if($id != 0 && is_array($extra_info))
  3865. {
  3866. $item_title = stripslashes($extra_info['title']);
  3867. $item_description = stripslashes($extra_info['description']);
  3868. }
  3869. elseif(is_numeric($extra_info))
  3870. {
  3871. $sql_quiz = "
  3872. SELECT
  3873. title,
  3874. description
  3875. FROM " . $tbl_quiz . "
  3876. WHERE id = " . $extra_info;
  3877. $result = api_sql_query($sql_quiz, __FILE__, __LINE__);
  3878. $row = Database::fetch_array($result);
  3879. $item_title = $row['title'];
  3880. $item_description = $row['description'];
  3881. }
  3882. else
  3883. {
  3884. $item_title = '';
  3885. $item_description = '';
  3886. }
  3887. $return = '<div style="margin:3px 10px;">';
  3888. if($id != 0 && is_array($extra_info))
  3889. $parent = $extra_info['parent_item_id'];
  3890. else
  3891. $parent = 0;
  3892. $sql = "
  3893. SELECT *
  3894. FROM " . $tbl_lp_item . "
  3895. WHERE
  3896. lp_id = " . $this->lp_id;
  3897. $result = api_sql_query($sql, __FILE__, __LINE__);
  3898. $arrLP = array();
  3899. while($row = Database::fetch_array($result))
  3900. {
  3901. $arrLP[] = array(
  3902. 'id' => $row['id'],
  3903. 'item_type' => $row['item_type'],
  3904. 'title' => $row['title'],
  3905. 'path' => $row['path'],
  3906. 'description' => $row['description'],
  3907. 'parent_item_id' => $row['parent_item_id'],
  3908. 'previous_item_id' => $row['previous_item_id'],
  3909. 'next_item_id' => $row['next_item_id'],
  3910. 'display_order' => $row['display_order'],
  3911. 'prerequisite' => $row['prerequisite']);
  3912. }
  3913. $this->tree_array($arrLP);
  3914. $arrLP = $this->arrMenu;
  3915. unset($this->arrMenu);
  3916. if($action == 'add')
  3917. $return .= '<p class="lp_title">'.get_lang("CreateTheExercise").' :</p>' . "\n";
  3918. elseif($action == 'move')
  3919. $return .= '<p class="lp_title">'.get_lang("MoveTheCurrentExercise").' :</p>' . "\n";
  3920. else
  3921. $return .= '<p class="lp_title">'.get_lang("EditCurrentExecice").' :</p>' . "\n";
  3922. if(isset($_GET['edit']) && $_GET['edit'] == 'true')
  3923. {
  3924. $return .= '<div class="lp_message" style="margin-bottom:15px;">';
  3925. $return .= '<p class="lp_title">'.get_lang("Warning").' !</p>';
  3926. $return .= get_lang("WarningEditingDocument");
  3927. $return .= '</div>';
  3928. }
  3929. $return .= '<form method="POST">' . "\n";
  3930. $return .= "\t" . '<table cellpadding="0" cellspacing="0" class="lp_form">' . "\n";
  3931. $return .= "\t\t" . '<tr>' . "\n";
  3932. $return .= "\t\t\t" . '<td class="label"><label for="idParent">'.get_lang("Parent").' :</label></td>' . "\n";
  3933. $return .= "\t\t\t" . '<td class="input">' . "\n";
  3934. $return .= "\t\t\t\t" . '<select id="idParent" name="parent" onchange="load_cbo(this.value);" size="1">';
  3935. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
  3936. $arrHide = array($id);
  3937. for($i = 0; $i < count($arrLP); $i++)
  3938. {
  3939. if($action != 'add')
  3940. {
  3941. if(($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir') && !in_array($arrLP[$i]['id'], $arrHide) && !in_array($arrLP[$i]['parent_item_id'], $arrHide))
  3942. {
  3943. $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>';
  3944. }
  3945. else
  3946. {
  3947. $arrHide[] = $arrLP[$i]['id'];
  3948. }
  3949. }
  3950. else
  3951. {
  3952. if($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
  3953. $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>';
  3954. }
  3955. }
  3956. if (is_array($arrLP))
  3957. {
  3958. reset($arrLP);
  3959. }
  3960. $return .= "\t\t\t\t" . '</select>';
  3961. $return .= "\t\t\t" . '</td>' . "\n";
  3962. $return .= "\t\t" . '</tr>' . "\n";
  3963. $return .= "\t\t" . '<tr>' . "\n";
  3964. $return .= "\t\t\t" . '<td class="label"><label for="idPosition">'.get_lang("Position").' :</label></td>' . "\n";
  3965. $return .= "\t\t\t" . '<td class="input">' . "\n";
  3966. $return .= "\t\t\t\t" . '<select id="idPosition" name="previous" size="1">';
  3967. $return .= "\t\t\t\t\t" . '<option class="top" value="0">First position</option>';
  3968. for($i = 0; $i < count($arrLP); $i++)
  3969. {
  3970. if($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id)
  3971. {
  3972. if($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  3973. $selected = 'selected="selected" ';
  3974. elseif($action == 'add')
  3975. $selected = 'selected="selected" ';
  3976. else
  3977. $selected = '';
  3978. $return .= "\t\t\t\t\t" . '<option ' . $selected . 'value="' . $arrLP[$i]['id'] . '">'.get_lang("After").' "' . html_entity_decode(stripslashes($arrLP[$i]['title'])) . '"</option>';
  3979. }
  3980. }
  3981. $return .= "\t\t\t\t" . '</select>';
  3982. $return .= "\t\t\t" . '</td>' . "\n";
  3983. $return .= "\t\t" . '</tr>' . "\n";
  3984. if($action != 'move')
  3985. {
  3986. $return .= "\t\t" . '<tr>' . "\n";
  3987. $return .= "\t\t\t" . '<td class="label"><label for="idTitle">'.get_lang("Title").' :</label></td>' . "\n";
  3988. $return .= "\t\t\t" . '<td class="input"><input id="idTitle" name="title" type="text" value="' . $item_title . '" /></td>' . "\n";
  3989. $return .= "\t\t" . '</tr>' . "\n";
  3990. $id_prerequisite=0;
  3991. if (is_array($arrLP ))
  3992. {
  3993. foreach($arrLP as $key=>$value){
  3994. if($value['id']==$id){
  3995. $id_prerequisite=$value['prerequisite'];
  3996. break;
  3997. }
  3998. }
  3999. }
  4000. $arrHide=array();
  4001. for($i = 0; $i < count($arrLP); $i++)
  4002. {
  4003. if($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter')
  4004. {
  4005. if($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  4006. $s_selected_position=$arrLP[$i]['id'];
  4007. elseif($action == 'add')
  4008. $s_selected_position=0;
  4009. $arrHide[$arrLP[$i]['id']]['value']=html_entity_decode(stripslashes($arrLP[$i]['title']));
  4010. }
  4011. }
  4012. $return .= "\t\t" . '<tr>' . "\n";
  4013. $return .= "\t\t\t" . '<td class="label"><label for="idPrerequisites">'.get_lang("Prerequisites").' :</label></td>' . "\n";
  4014. $return .= "\t\t\t" . '<td class="input"><select name="prerequisites" id="prerequisites" style="background:#F8F8F8; border:1px solid #999999; font-family:Arial, Verdana, Helvetica, sans-serif; font-size:12px; width:300px;"><option value="0">'.get_lang("NoPrerequisites").'</option>';
  4015. foreach($arrHide as $key => $value){
  4016. if($key==$s_selected_position && $action == 'add'){
  4017. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  4018. }
  4019. elseif($key==$id_prerequisite && $action == 'edit'){
  4020. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  4021. }
  4022. else{
  4023. $return .= '<option value="'.$key.'">'.$value['value'].'</option>';
  4024. }
  4025. }
  4026. $return .= "</select></td>";
  4027. $return .= "\t\t" . '</tr>' . "\n";
  4028. $return .= "\t\t" . '<tr>' . "\n";
  4029. //Remove temporaly the test description
  4030. //$return .= "\t\t\t" . '<td class="label"><label for="idDescription">'.get_lang("Description").' :</label></td>' . "\n";
  4031. //$return .= "\t\t\t" . '<td class="input"><textarea id="idDescription" name="description" rows="4">' . $item_description . '</textarea></td>' . "\n";
  4032. $return .= "\t\t" . '</tr>' . "\n";
  4033. }
  4034. $return .= "\t\t" . '<tr>' . "\n";
  4035. $return .= "\t\t\t" . '<td colspan="2"><input class="button" name="submit_button" type="submit" value="OK" /></td>' . "\n";
  4036. $return .= "\t\t" . '</tr>' . "\n";
  4037. $return .= "\t" . '</table>' . "\n";
  4038. if($action == 'move')
  4039. {
  4040. $return .= "\t" . '<input name="title" type="hidden" value="' . $item_title . '" />' . "\n";
  4041. $return .= "\t" . '<input name="description" type="hidden" value="' . $item_description . '" />' . "\n";
  4042. }
  4043. if(is_numeric($extra_info))
  4044. {
  4045. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info . '" />' . "\n";
  4046. }
  4047. elseif(is_array($extra_info))
  4048. {
  4049. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />' . "\n";
  4050. }
  4051. $return .= "\t" . '<input name="type" type="hidden" value="'.TOOL_QUIZ.'" />' . "\n";
  4052. $return .= "\t" . '<input name="post_time" type="hidden" value="' . time() . '" />' . "\n";
  4053. $return .= '</form>' . "\n";
  4054. $return .= '</div>' . "\n";
  4055. return $return;
  4056. }
  4057. /**
  4058. * Addition of Hotpotatoes tests
  4059. * @param string Action
  4060. * @param integer Internal ID of the item
  4061. * @param mixed Extra information - can be an array with title and description indexes
  4062. * @return string HTML structure to display the hotpotatoes addition formular
  4063. */
  4064. function display_hotpotatoes_form($action = 'add', $id = 0, $extra_info = '')
  4065. {
  4066. $uploadPath = DIR_HOTPOTATOES; //defined in main_api
  4067. $tbl_lp_item = Database::get_course_table('lp_item');
  4068. if($id != 0 && is_array($extra_info))
  4069. {
  4070. $item_title = stripslashes($extra_info['title']);
  4071. $item_description = stripslashes($extra_info['description']);
  4072. }
  4073. elseif(is_numeric($extra_info))
  4074. {
  4075. $TBL_DOCUMENT = Database::get_course_table(TABLE_DOCUMENT);
  4076. $sql_hot = "SELECT * FROM ".$TBL_DOCUMENT."
  4077. WHERE path LIKE '".$uploadPath."/%/%htm%'
  4078. ORDER BY id ASC";
  4079. $res_hot = api_sql_query($sql_hot, __FILE__, __LINE__);
  4080. $row = Database::fetch_array($res_hot);
  4081. $item_title = $row['title'];
  4082. $item_description = $row['description'];
  4083. }
  4084. else
  4085. {
  4086. $item_title = '';
  4087. $item_description = '';
  4088. }
  4089. $return = '<div style="margin:3px 10px;">';
  4090. if($id != 0 && is_array($extra_info))
  4091. $parent = $extra_info['parent_item_id'];
  4092. else
  4093. $parent = 0;
  4094. $sql = "
  4095. SELECT *
  4096. FROM " . $tbl_lp_item . "
  4097. WHERE
  4098. lp_id = " . $this->lp_id;
  4099. $result = api_sql_query($sql, __FILE__, __LINE__);
  4100. $arrLP = array();
  4101. while($row = Database::fetch_array($result))
  4102. {
  4103. $arrLP[] = array(
  4104. 'id' => $row['id'],
  4105. 'item_type' => $row['item_type'],
  4106. 'title' => $row['title'],
  4107. 'path' => $row['path'],
  4108. 'description' => $row['description'],
  4109. 'parent_item_id' => $row['parent_item_id'],
  4110. 'previous_item_id' => $row['previous_item_id'],
  4111. 'next_item_id' => $row['next_item_id'],
  4112. 'display_order' => $row['display_order'],
  4113. 'prerequisite' => $row['prerequisite']);
  4114. }
  4115. $this->tree_array($arrLP);
  4116. $arrLP = $this->arrMenu;
  4117. unset($this->arrMenu);
  4118. if($action == 'add')
  4119. $return .= '<p class="lp_title">'.get_lang("CreateTheExercise").' :</p>' . "\n";
  4120. elseif($action == 'move')
  4121. $return .= '<p class="lp_title">'.get_lang("MoveTheCurrentExercise").' :</p>' . "\n";
  4122. else
  4123. $return .= '<p class="lp_title">'.get_lang("EditCurrentExecice").' :</p>' . "\n";
  4124. if(isset($_GET['edit']) && $_GET['edit'] == 'true')
  4125. {
  4126. $return .= '<div class="lp_message" style="margin-bottom:15px;">';
  4127. $return .= '<p class="lp_title">'.get_lang("Warning").' !</p>';
  4128. $return .= get_lang("WarningEditingDocument");
  4129. $return .= '</div>';
  4130. }
  4131. $return .= '<form method="POST">' . "\n";
  4132. $return .= "\t" . '<table cellpadding="0" cellspacing="0" class="lp_form">' . "\n";
  4133. $return .= "\t\t" . '<tr>' . "\n";
  4134. $return .= "\t\t\t" . '<td class="label"><label for="idParent">'.get_lang("Parent").' :</label></td>' . "\n";
  4135. $return .= "\t\t\t" . '<td class="input">' . "\n";
  4136. $return .= "\t\t\t\t" . '<select id="idParent" name="parent" onchange="load_cbo(this.value);" size="1">';
  4137. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
  4138. $arrHide = array($id);
  4139. for($i = 0; $i < count($arrLP); $i++)
  4140. {
  4141. if($action != 'add')
  4142. {
  4143. if(($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir') && !in_array($arrLP[$i]['id'], $arrHide) && !in_array($arrLP[$i]['parent_item_id'], $arrHide))
  4144. {
  4145. $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>';
  4146. }
  4147. else
  4148. {
  4149. $arrHide[] = $arrLP[$i]['id'];
  4150. }
  4151. }
  4152. else
  4153. {
  4154. if($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
  4155. $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>';
  4156. }
  4157. }
  4158. reset($arrLP);
  4159. $return .= "\t\t\t\t" . '</select>';
  4160. $return .= "\t\t\t" . '</td>' . "\n";
  4161. $return .= "\t\t" . '</tr>' . "\n";
  4162. $return .= "\t\t" . '<tr>' . "\n";
  4163. $return .= "\t\t\t" . '<td class="label"><label for="idPosition">'.get_lang("Position").' :</label></td>' . "\n";
  4164. $return .= "\t\t\t" . '<td class="input">' . "\n";
  4165. $return .= "\t\t\t\t" . '<select id="idPosition" name="previous" size="1">';
  4166. $return .= "\t\t\t\t\t" . '<option class="top" value="0">First position</option>';
  4167. for($i = 0; $i < count($arrLP); $i++)
  4168. {
  4169. if($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id)
  4170. {
  4171. if($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  4172. $selected = 'selected="selected" ';
  4173. elseif($action == 'add')
  4174. $selected = 'selected="selected" ';
  4175. else
  4176. $selected = '';
  4177. $return .= "\t\t\t\t\t" . '<option ' . $selected . 'value="' . $arrLP[$i]['id'] . '">'.get_lang("After").' "' . html_entity_decode(stripslashes($arrLP[$i]['title'])) . '"</option>';
  4178. }
  4179. }
  4180. $return .= "\t\t\t\t" . '</select>';
  4181. $return .= "\t\t\t" . '</td>' . "\n";
  4182. $return .= "\t\t" . '</tr>' . "\n";
  4183. if($action != 'move')
  4184. {
  4185. $return .= "\t\t" . '<tr>' . "\n";
  4186. $return .= "\t\t\t" . '<td class="label"><label for="idTitle">'.get_lang("Title").' :</label></td>' . "\n";
  4187. $return .= "\t\t\t" . '<td class="input"><input id="idTitle" name="title" type="text" value="' . $item_title . '" /></td>' . "\n";
  4188. $return .= "\t\t" . '</tr>' . "\n";
  4189. $id_prerequisite=0;
  4190. foreach($arrLP as $key=>$value){
  4191. if($value['id']==$id){
  4192. $id_prerequisite=$value['prerequisite'];
  4193. break;
  4194. }
  4195. }
  4196. $arrHide=array();
  4197. for($i = 0; $i < count($arrLP); $i++)
  4198. {
  4199. if($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter')
  4200. {
  4201. if($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  4202. $s_selected_position=$arrLP[$i]['id'];
  4203. elseif($action == 'add')
  4204. $s_selected_position=0;
  4205. $arrHide[$arrLP[$i]['id']]['value']=html_entity_decode(stripslashes($arrLP[$i]['title']));
  4206. }
  4207. }
  4208. $return .= "\t\t" . '<tr>' . "\n";
  4209. $return .= "\t\t\t" . '<td class="label"><label for="idPrerequisites">'.get_lang("Prerequisites").' :</label></td>' . "\n";
  4210. $return .= "\t\t\t" . '<td class="input"><select name="prerequisites" id="prerequisites" style="background:#F8F8F8; border:1px solid #999999; font-family:Arial, Verdana, Helvetica, sans-serif; font-size:12px; width:300px;"><option value="0">'.get_lang("NoPrerequisites").'</option>';
  4211. foreach($arrHide as $key => $value){
  4212. if($key==$s_selected_position && $action == 'add'){
  4213. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  4214. }
  4215. elseif($key==$id_prerequisite && $action == 'edit'){
  4216. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  4217. }
  4218. else{
  4219. $return .= '<option value="'.$key.'">'.$value['value'].'</option>';
  4220. }
  4221. }
  4222. $return .= "</select></td>";
  4223. $return .= "\t\t" . '</tr>' . "\n";
  4224. $return .= "\t\t" . '<tr>' . "\n";
  4225. //Remove temporaly the test description
  4226. //$return .= "\t\t\t" . '<td class="label"><label for="idDescription">'.get_lang("Description").' :</label></td>' . "\n";
  4227. //$return .= "\t\t\t" . '<td class="input"><textarea id="idDescription" name="description" rows="4">' . $item_description . '</textarea></td>' . "\n";
  4228. $return .= "\t\t" . '</tr>' . "\n";
  4229. }
  4230. $return .= "\t\t" . '<tr>' . "\n";
  4231. $return .= "\t\t\t" . '<td colspan="2"><input class="button" name="submit_button" type="submit" value="OK" /></td>' . "\n";
  4232. $return .= "\t\t" . '</tr>' . "\n";
  4233. $return .= "\t" . '</table>' . "\n";
  4234. if($action == 'move')
  4235. {
  4236. $return .= "\t" . '<input name="title" type="hidden" value="' . $item_title . '" />' . "\n";
  4237. $return .= "\t" . '<input name="description" type="hidden" value="' . $item_description . '" />' . "\n";
  4238. }
  4239. if(is_numeric($extra_info))
  4240. {
  4241. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info . '" />' . "\n";
  4242. }
  4243. elseif(is_array($extra_info))
  4244. {
  4245. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />' . "\n";
  4246. }
  4247. $return .= "\t" . '<input name="type" type="hidden" value="'.TOOL_HOTPOTATOES.'" />' . "\n";
  4248. $return .= "\t" . '<input name="post_time" type="hidden" value="' . time() . '" />' . "\n";
  4249. $return .= '</form>' . "\n";
  4250. $return .= '</div>' . "\n";
  4251. return $return;
  4252. }
  4253. //fin du hotpot form
  4254. /**
  4255. * Enter description here...
  4256. *
  4257. * @param unknown_type $action
  4258. * @param unknown_type $id
  4259. * @param unknown_type $extra_info
  4260. * @return unknown
  4261. */
  4262. function display_forum_form($action = 'add', $id = 0, $extra_info = '')
  4263. {
  4264. $tbl_lp_item = Database::get_course_table('lp_item');
  4265. $tbl_forum = Database::get_course_table(TABLE_FORUM);
  4266. if($id != 0 && is_array($extra_info))
  4267. {
  4268. $item_title = stripslashes($extra_info['title']);
  4269. }
  4270. elseif(is_numeric($extra_info))
  4271. {
  4272. $sql_forum = "
  4273. SELECT
  4274. forum_title as title, forum_comment as comment
  4275. FROM " . $tbl_forum . "
  4276. WHERE forum_id = " . $extra_info;
  4277. $result = api_sql_query($sql_forum, __FILE__, __LINE__);
  4278. $row = Database::fetch_array($result);
  4279. $item_title = $row['title'];
  4280. $item_description = $row['comment'];
  4281. }
  4282. else
  4283. {
  4284. $item_title = '';
  4285. $item_description = '';
  4286. }
  4287. $return = '<div style="margin:3px 10px;">';
  4288. if($id != 0 && is_array($extra_info))
  4289. $parent = $extra_info['parent_item_id'];
  4290. else
  4291. $parent = 0;
  4292. $sql = "
  4293. SELECT *
  4294. FROM " . $tbl_lp_item . "
  4295. WHERE
  4296. lp_id = " . $this->lp_id;
  4297. $result = api_sql_query($sql, __FILE__, __LINE__);
  4298. $arrLP = array();
  4299. while($row = Database::fetch_array($result))
  4300. {
  4301. $arrLP[] = array(
  4302. 'id' => $row['id'],
  4303. 'item_type' => $row['item_type'],
  4304. 'title' => $row['title'],
  4305. 'path' => $row['path'],
  4306. 'description' => $row['description'],
  4307. 'parent_item_id' => $row['parent_item_id'],
  4308. 'previous_item_id' => $row['previous_item_id'],
  4309. 'next_item_id' => $row['next_item_id'],
  4310. 'display_order' => $row['display_order'],
  4311. 'prerequisite' => $row['prerequisite']);
  4312. }
  4313. $this->tree_array($arrLP);
  4314. $arrLP = $this->arrMenu;
  4315. unset($this->arrMenu);
  4316. if($action == 'add')
  4317. $return .= '<p class="lp_title">'.get_lang("CreateTheForum").' :</p>' . "\n";
  4318. elseif($action == 'move')
  4319. $return .= '<p class="lp_title">'.get_lang("MoveTheCurrentForum").' :</p>' . "\n";
  4320. else
  4321. $return .= '<p class="lp_title">'.get_lang("EditCurrentForum").' :</p>' . "\n";
  4322. $return .= '<form method="POST">' . "\n";
  4323. $return .= "\t" . '<table cellpadding="0" cellspacing="0" class="lp_form">' . "\n";
  4324. $return .= "\t\t" . '<tr>' . "\n";
  4325. $return .= "\t\t\t" . '<td class="label"><label for="idParent">'.get_lang("Parent").' :</label></td>' . "\n";
  4326. $return .= "\t\t\t" . '<td class="input">' . "\n";
  4327. $return .= "\t\t\t\t" . '<select id="idParent" name="parent" onchange="load_cbo(this.value);" size="1">';
  4328. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
  4329. $arrHide = array($id);
  4330. for($i = 0; $i < count($arrLP); $i++)
  4331. {
  4332. if($action != 'add')
  4333. {
  4334. if(($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir') && !in_array($arrLP[$i]['id'], $arrHide) && !in_array($arrLP[$i]['parent_item_id'], $arrHide))
  4335. {
  4336. $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>';
  4337. }
  4338. else
  4339. {
  4340. $arrHide[] = $arrLP[$i]['id'];
  4341. }
  4342. }
  4343. else
  4344. {
  4345. if($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
  4346. $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>';
  4347. }
  4348. }
  4349. reset($arrLP);
  4350. $return .= "\t\t\t\t" . '</select>';
  4351. $return .= "\t\t\t" . '</td>' . "\n";
  4352. $return .= "\t\t" . '</tr>' . "\n";
  4353. $return .= "\t\t" . '<tr>' . "\n";
  4354. $return .= "\t\t\t" . '<td class="label"><label for="idPosition">'.get_lang("Position").' :</label></td>' . "\n";
  4355. $return .= "\t\t\t" . '<td class="input">' . "\n";
  4356. $return .= "\t\t\t\t" . '<select id="idPosition" name="previous" size="1">';
  4357. $return .= "\t\t\t\t\t" . '<option class="top" value="0">First position</option>';
  4358. for($i = 0; $i < count($arrLP); $i++)
  4359. {
  4360. if($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id)
  4361. {
  4362. if($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  4363. $selected = 'selected="selected" ';
  4364. elseif($action == 'add')
  4365. $selected = 'selected="selected" ';
  4366. else
  4367. $selected = '';
  4368. $return .= "\t\t\t\t\t" . '<option ' . $selected . 'value="' . $arrLP[$i]['id'] . '">'.get_lang("After").' "' . html_entity_decode(stripslashes($arrLP[$i]['title'])) . '"</option>';
  4369. }
  4370. }
  4371. $return .= "\t\t\t\t" . '</select>';
  4372. $return .= "\t\t\t" . '</td>' . "\n";
  4373. $return .= "\t\t" . '</tr>' . "\n";
  4374. if($action != 'move')
  4375. {
  4376. $return .= "\t\t" . '<tr>' . "\n";
  4377. $return .= "\t\t\t" . '<td class="label"><label for="idTitle">'.get_lang("Title").' :</label></td>' . "\n";
  4378. $return .= "\t\t\t" . '<td class="input"><input id="idTitle" name="title" type="text" value="' . $item_title . '" /></td>' . "\n";
  4379. $return .= "\t\t" . '</tr>' . "\n";
  4380. $return .= "\t\t" . '<tr>' . "\n";
  4381. //Remove temporaly the test description
  4382. //$return .= "\t\t\t" . '<td class="label"><label for="idDescription">'.get_lang("Description").' :</label></td>' . "\n";
  4383. //$return .= "\t\t\t" . '<td class="input"><textarea id="idDescription" name="description" rows="4">' . $item_description . '</textarea></td>' . "\n";
  4384. $return .= "\t\t" . '</tr>' . "\n";
  4385. $id_prerequisite=0;
  4386. foreach($arrLP as $key=>$value){
  4387. if($value['id']==$id){
  4388. $id_prerequisite=$value['prerequisite'];
  4389. break;
  4390. }
  4391. }
  4392. $arrHide=array();
  4393. for($i = 0; $i < count($arrLP); $i++)
  4394. {
  4395. if($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter')
  4396. {
  4397. if($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  4398. $s_selected_position=$arrLP[$i]['id'];
  4399. elseif($action == 'add')
  4400. $s_selected_position=0;
  4401. $arrHide[$arrLP[$i]['id']]['value']=html_entity_decode(stripslashes($arrLP[$i]['title']));
  4402. }
  4403. }
  4404. $return .= "\t\t" . '<tr>' . "\n";
  4405. $return .= "\t\t\t" . '<td class="label"><label for="idPrerequisites">'.get_lang("Prerequisites").' :</label></td>' . "\n";
  4406. $return .= "\t\t\t" . '<td class="input"><select name="prerequisites" id="prerequisites" style="background:#F8F8F8; border:1px solid #999999; font-family:Arial, Verdana, Helvetica, sans-serif; font-size:12px; width:300px;"><option value="0">'.get_lang("NoPrerequisites").'</option>';
  4407. foreach($arrHide as $key => $value){
  4408. if($key==$s_selected_position && $action == 'add'){
  4409. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  4410. }
  4411. elseif($key==$id_prerequisite && $action == 'edit'){
  4412. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  4413. }
  4414. else{
  4415. $return .= '<option value="'.$key.'">'.$value['value'].'</option>';
  4416. }
  4417. }
  4418. $return .= "</select></td>";
  4419. $return .= "\t\t" . '</tr>' . "\n";
  4420. }
  4421. $return .= "\t\t" . '<tr>' . "\n";
  4422. $return .= "\t\t\t" . '<td colspan="2"><input class="button" name="submit_button" type="submit" value="OK" /></td>' . "\n";
  4423. $return .= "\t\t" . '</tr>' . "\n";
  4424. $return .= "\t" . '</table>' . "\n";
  4425. if($action == 'move')
  4426. {
  4427. $return .= "\t" . '<input name="title" type="hidden" value="' . $item_title . '" />' . "\n";
  4428. $return .= "\t" . '<input name="description" type="hidden" value="' . $item_description . '" />' . "\n";
  4429. }
  4430. if(is_numeric($extra_info))
  4431. {
  4432. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info . '" />' . "\n";
  4433. }
  4434. elseif(is_array($extra_info))
  4435. {
  4436. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />' . "\n";
  4437. }
  4438. $return .= "\t" . '<input name="type" type="hidden" value="'.TOOL_FORUM.'" />' . "\n";
  4439. $return .= "\t" . '<input name="post_time" type="hidden" value="' . time() . '" />' . "\n";
  4440. $return .= '</form>' . "\n";
  4441. $return .= '</div>' . "\n";
  4442. return $return;
  4443. }
  4444. function display_thread_form($action = 'add', $id = 0, $extra_info = '')
  4445. {
  4446. $tbl_lp_item = Database::get_course_table('lp_item');
  4447. $tbl_forum = Database::get_course_table(TABLE_FORUM_THREAD);
  4448. if($id != 0 && is_array($extra_info))
  4449. {
  4450. $item_title = stripslashes($extra_info['title']);
  4451. }
  4452. elseif(is_numeric($extra_info))
  4453. {
  4454. $sql_forum = "
  4455. SELECT
  4456. thread_title as title
  4457. FROM " . $tbl_forum . "
  4458. WHERE thread_id = " . $extra_info;
  4459. $result = api_sql_query($sql_forum, __FILE__, __LINE__);
  4460. $row = Database::fetch_array($result);
  4461. $item_title = $row['title'];
  4462. $item_description = '';
  4463. }
  4464. else
  4465. {
  4466. $item_title = '';
  4467. $item_description = '';
  4468. }
  4469. $return = '<div style="margin:3px 10px;">';
  4470. if($id != 0 && is_array($extra_info))
  4471. $parent = $extra_info['parent_item_id'];
  4472. else
  4473. $parent = 0;
  4474. $sql = "
  4475. SELECT *
  4476. FROM " . $tbl_lp_item . "
  4477. WHERE
  4478. lp_id = " . $this->lp_id;
  4479. $result = api_sql_query($sql, __FILE__, __LINE__);
  4480. $arrLP = array();
  4481. while($row = Database::fetch_array($result))
  4482. {
  4483. $arrLP[] = array(
  4484. 'id' => $row['id'],
  4485. 'item_type' => $row['item_type'],
  4486. 'title' => $row['title'],
  4487. 'path' => $row['path'],
  4488. 'description' => $row['description'],
  4489. 'parent_item_id' => $row['parent_item_id'],
  4490. 'previous_item_id' => $row['previous_item_id'],
  4491. 'next_item_id' => $row['next_item_id'],
  4492. 'display_order' => $row['display_order'],
  4493. 'prerequisite' => $row['prerequisite']);
  4494. }
  4495. $this->tree_array($arrLP);
  4496. $arrLP = $this->arrMenu;
  4497. unset($this->arrMenu);
  4498. if($action == 'add')
  4499. $return .= '<p class="lp_title">'.get_lang("CreateTheForum").' :</p>' . "\n";
  4500. elseif($action == 'move')
  4501. $return .= '<p class="lp_title">'.get_lang("MoveTheCurrentForum").' :</p>' . "\n";
  4502. else
  4503. $return .= '<p class="lp_title">'.get_lang("EditCurrentForum").' :</p>' . "\n";
  4504. $return .= '<form method="POST">' . "\n";
  4505. $return .= "\t" . '<table cellpadding="0" cellspacing="0" class="lp_form">' . "\n";
  4506. $return .= "\t\t" . '<tr>' . "\n";
  4507. $return .= "\t\t\t" . '<td class="label"><label for="idParent">'.get_lang("Parent").' :</label></td>' . "\n";
  4508. $return .= "\t\t\t" . '<td class="input">' . "\n";
  4509. $return .= "\t\t\t\t" . '<select id="idParent" name="parent" onchange="load_cbo(this.value);" size="1">';
  4510. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
  4511. $arrHide = array($id);
  4512. for($i = 0; $i < count($arrLP); $i++)
  4513. {
  4514. if($action != 'add')
  4515. {
  4516. if(($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir') && !in_array($arrLP[$i]['id'], $arrHide) && !in_array($arrLP[$i]['parent_item_id'], $arrHide))
  4517. {
  4518. $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>';
  4519. }
  4520. else
  4521. {
  4522. $arrHide[] = $arrLP[$i]['id'];
  4523. }
  4524. }
  4525. else
  4526. {
  4527. if($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
  4528. $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>';
  4529. }
  4530. }
  4531. reset($arrLP);
  4532. $return .= "\t\t\t\t" . '</select>';
  4533. $return .= "\t\t\t" . '</td>' . "\n";
  4534. $return .= "\t\t" . '</tr>' . "\n";
  4535. $return .= "\t\t" . '<tr>' . "\n";
  4536. $return .= "\t\t\t" . '<td class="label"><label for="idPosition">'.get_lang("Position").' :</label></td>' . "\n";
  4537. $return .= "\t\t\t" . '<td class="input">' . "\n";
  4538. $return .= "\t\t\t\t" . '<select id="idPosition" name="previous" size="1">';
  4539. $return .= "\t\t\t\t\t" . '<option class="top" value="0">First position</option>';
  4540. for($i = 0; $i < count($arrLP); $i++)
  4541. {
  4542. if($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id)
  4543. {
  4544. if($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  4545. $selected = 'selected="selected" ';
  4546. elseif($action == 'add')
  4547. $selected = 'selected="selected" ';
  4548. else
  4549. $selected = '';
  4550. $return .= "\t\t\t\t\t" . '<option ' . $selected . 'value="' . $arrLP[$i]['id'] . '">'.get_lang("After").' "' . html_entity_decode(stripslashes($arrLP[$i]['title'])) . '"</option>';
  4551. }
  4552. }
  4553. $return .= "\t\t\t\t" . '</select>';
  4554. $return .= "\t\t\t" . '</td>' . "\n";
  4555. $return .= "\t\t" . '</tr>' . "\n";
  4556. if($action != 'move')
  4557. {
  4558. $return .= "\t\t" . '<tr>' . "\n";
  4559. $return .= "\t\t\t" . '<td class="label"><label for="idTitle">'.get_lang("Title").' :</label></td>' . "\n";
  4560. $return .= "\t\t\t" . '<td class="input"><input id="idTitle" name="title" type="text" value="' . $item_title . '" /></td>' . "\n";
  4561. $return .= "\t\t" . '</tr>' . "\n";
  4562. $return .= "\t\t" . '<tr>' . "\n";
  4563. //Remove temporaly the test description
  4564. //$return .= "\t\t\t" . '<td class="label"><label for="idDescription">'.get_lang("Description").' :</label></td>' . "\n";
  4565. //$return .= "\t\t\t" . '<td class="input"><textarea id="idDescription" name="description" rows="4">' . $item_description . '</textarea></td>' . "\n";
  4566. $return .= "\t\t" . '</tr>' . "\n";
  4567. $id_prerequisite=0;
  4568. foreach($arrLP as $key=>$value){
  4569. if($value['id']==$id){
  4570. $id_prerequisite=$value['prerequisite'];
  4571. break;
  4572. }
  4573. }
  4574. $arrHide=array();
  4575. for($i = 0; $i < count($arrLP); $i++)
  4576. {
  4577. if($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter')
  4578. {
  4579. if($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  4580. $s_selected_position=$arrLP[$i]['id'];
  4581. elseif($action == 'add')
  4582. $s_selected_position=0;
  4583. $arrHide[$arrLP[$i]['id']]['value']=html_entity_decode(stripslashes($arrLP[$i]['title']));
  4584. }
  4585. }
  4586. $return .= "\t\t" . '<tr>' . "\n";
  4587. $return .= "\t\t\t" . '<td class="label"><label for="idPrerequisites">'.get_lang("Prerequisites").' :</label></td>' . "\n";
  4588. $return .= "\t\t\t" . '<td class="input"><select name="prerequisites" id="prerequisites" style="background:#F8F8F8; border:1px solid #999999; font-family:Arial, Verdana, Helvetica, sans-serif; font-size:12px; width:300px;"><option value="0">'.get_lang("NoPrerequisites").'</option>';
  4589. foreach($arrHide as $key => $value){
  4590. if($key==$s_selected_position && $action == 'add'){
  4591. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  4592. }
  4593. elseif($key==$id_prerequisite && $action == 'edit'){
  4594. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  4595. }
  4596. else{
  4597. $return .= '<option value="'.$key.'">'.$value['value'].'</option>';
  4598. }
  4599. }
  4600. $return .= "</select></td>";
  4601. $return .= "\t\t" . '</tr>' . "\n";
  4602. }
  4603. $return .= "\t\t" . '<tr>' . "\n";
  4604. $return .= "\t\t\t" . '<td colspan="2"><input class="button" name="submit_button" type="submit" value="OK" /></td>' . "\n";
  4605. $return .= "\t\t" . '</tr>' . "\n";
  4606. $return .= "\t" . '</table>' . "\n";
  4607. if($action == 'move')
  4608. {
  4609. $return .= "\t" . '<input name="title" type="hidden" value="' . $item_title . '" />' . "\n";
  4610. $return .= "\t" . '<input name="description" type="hidden" value="' . $item_description . '" />' . "\n";
  4611. }
  4612. if(is_numeric($extra_info))
  4613. {
  4614. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info . '" />' . "\n";
  4615. }
  4616. elseif(is_array($extra_info))
  4617. {
  4618. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />' . "\n";
  4619. }
  4620. $return .= "\t" . '<input name="type" type="hidden" value="'.TOOL_THREAD.'" />' . "\n";
  4621. $return .= "\t" . '<input name="post_time" type="hidden" value="' . time() . '" />' . "\n";
  4622. $return .= '</form>' . "\n";
  4623. $return .= '</div>' . "\n";
  4624. return $return;
  4625. }
  4626. /**
  4627. * Enter description here...
  4628. *
  4629. * @param unknown_type $item_type
  4630. * @param unknown_type $title
  4631. * @param unknown_type $action
  4632. * @param unknown_type $id
  4633. * @param unknown_type $extra_info
  4634. * @return unknown
  4635. */
  4636. function display_item_form($item_type, $title = '', $action = 'add', $id = 0, $extra_info = 'new')
  4637. {
  4638. global $_course;
  4639. $tbl_lp_item = Database::get_course_table('lp_item');
  4640. if($id != 0 && is_array($extra_info))
  4641. {
  4642. $item_title = stripslashes($extra_info['title']);
  4643. $item_description = stripslashes($extra_info['description']);
  4644. $item_path = api_get_path(WEB_COURSE_PATH) . $_course['path'].'/scorm/'.$this->path.'/'.stripslashes($extra_info['path']);
  4645. }
  4646. else
  4647. {
  4648. $item_title = '';
  4649. $item_description = '';
  4650. }
  4651. $return = '<div style="margin:3px 10px;">';
  4652. if($id != 0 && is_array($extra_info))
  4653. $parent = $extra_info['parent_item_id'];
  4654. else
  4655. $parent = 0;
  4656. $sql = "
  4657. SELECT *
  4658. FROM " . $tbl_lp_item . "
  4659. WHERE lp_id = " . $this->lp_id. " AND id != " . $id. " ";
  4660. if($item_type == 'module')
  4661. $sql .= " AND parent_item_id = 0";
  4662. $result = api_sql_query($sql, __FILE__, __LINE__);
  4663. $arrLP = array();
  4664. while($row = Database::fetch_array($result))
  4665. {
  4666. $arrLP[] = array(
  4667. 'id' => $row['id'],
  4668. 'item_type' => $row['item_type'],
  4669. 'title' => $row['title'],
  4670. 'path' => $row['path'],
  4671. 'description' => $row['description'],
  4672. 'parent_item_id' => $row['parent_item_id'],
  4673. 'previous_item_id' => $row['previous_item_id'],
  4674. 'next_item_id' => $row['next_item_id'],
  4675. 'display_order' => $row['display_order']);
  4676. }
  4677. $this->tree_array($arrLP);
  4678. $arrLP = $this->arrMenu;
  4679. unset($this->arrMenu);
  4680. $return .= '<p class="lp_title">' . $title . '</p>' . "\n";
  4681. require_once (api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php');
  4682. $form = new FormValidator('form','POST',api_get_self()."?".$_SERVER["QUERY_STRING"]);
  4683. $defaults["title"]=html_entity_decode($item_title);
  4684. $defaults["description"]=html_entity_decode($item_description);
  4685. $form->addElement('html',$return);
  4686. //$arrHide = array($id);
  4687. $arrHide[0]['value']=$this->name;
  4688. $arrHide[0]['padding']=3;
  4689. if($item_type != 'module' && $item_type != 'dokeos_module')
  4690. {
  4691. for($i = 0; $i < count($arrLP); $i++)
  4692. {
  4693. if($action != 'add'){
  4694. if(($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir') && !in_array($arrLP[$i]['id'], $arrHide) && !in_array($arrLP[$i]['parent_item_id'], $arrHide)){
  4695. $arrHide[$arrLP[$i]['id']]['value']=html_entity_decode(stripslashes($arrLP[$i]['title']));
  4696. $arrHide[$arrLP[$i]['id']]['padding']=3+ $arrLP[$i]['depth'] * 10;
  4697. if($parent == $arrLP[$i]['id']){
  4698. $s_selected_parent=$arrHide[$arrLP[$i]['id']];
  4699. }
  4700. }
  4701. }
  4702. else{
  4703. if($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir'){
  4704. $arrHide[$arrLP[$i]['id']]['value']=html_entity_decode(stripslashes($arrLP[$i]['title']));
  4705. $arrHide[$arrLP[$i]['id']]['padding']=3+ $arrLP[$i]['depth'] * 10;
  4706. if($parent == $arrLP[$i]['id']){
  4707. $s_selected_parent=$arrHide[$arrLP[$i]['id']];
  4708. }
  4709. }
  4710. }
  4711. }
  4712. $parent_select = &$form->addElement('select', 'parent', get_lang("Parent")." :", '', 'style="background:#F8F8F8; border:1px solid #999999; font-family:Arial, Verdana, Helvetica, sans-serif; font-size:12px; width:300px;" onchange="load_cbo(this.value);"');
  4713. foreach($arrHide as $key => $value){
  4714. $parent_select->addOption($value['value'],$key,'style="padding-left:'.$value['padding'].'px;"');
  4715. }
  4716. $parent_select -> setSelected($s_selected_parent);
  4717. }
  4718. if(is_array($arrLP)) { reset($arrLP); }
  4719. $arrHide=array();
  4720. //POSITION
  4721. for($i = 0; $i < count($arrLP); $i++)
  4722. {
  4723. if($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id)
  4724. {
  4725. if($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  4726. $s_selected_position=$arrLP[$i]['id'];
  4727. elseif($action == 'add')
  4728. $s_selected_position=$arrLP[$i]['id'];
  4729. $arrHide[$arrLP[$i]['id']]['value']=get_lang("After").' "' . html_entity_decode(stripslashes($arrLP[$i]['title']));
  4730. }
  4731. }
  4732. $position = &$form->addElement('select', 'previous', get_lang("Position")." :", '', 'id="idPosition" style="background:#F8F8F8; border:1px solid #999999; font-family:Arial, Verdana, Helvetica, sans-serif; font-size:12px; width:300px;"');
  4733. $position->addOption(get_lang('FirstPosition'),0,'style="padding-left:'.$value['padding'].'px;"');
  4734. foreach($arrHide as $key => $value){
  4735. $position->addOption($value['value'],$key,'style="padding-left:'.$value['padding'].'px;"');
  4736. }
  4737. if(!empty($s_selected_position)) { $position->setSelected($s_selected_position); }
  4738. if(is_array($arrLP)) { reset($arrLP); }
  4739. if($action != 'move'){
  4740. $form->addElement('text','title', get_lang('Title').' :','id="idTitle" style="background:#F8F8F8; border:1px solid #999999; font-family:Arial, Verdana, Helvetica, sans-serif; font-size:12px; padding:1px 2px; width:300px;"');
  4741. //$form->addElement('textarea','description',get_lang("Description").' :', 'id="idDescription" style="background:#F8F8F8; border:1px solid #999999; font-family:Arial, Verdana, Helvetica, sans-serif; font-size:12px; padding:1px 2px; width:300px;"');
  4742. }
  4743. else
  4744. {
  4745. $form->addElement('hidden','title');
  4746. }
  4747. $form->addElement('submit', 'submit_button', get_lang('Ok'), 'style="padding:1px 2px; width:75px;"');
  4748. if($item_type == 'module' || $item_type == 'dokeos_module')
  4749. {
  4750. $form->addElement('hidden', 'parent', '0');
  4751. }
  4752. $extension = pathinfo($item_path, PATHINFO_EXTENSION);
  4753. if(($item_type=='asset' || $item_type=='sco') && ($extension == 'html' || $extension == 'htm'))
  4754. {
  4755. if($item_type=='sco')
  4756. {
  4757. $form->addElement('html','<script type="text/javascript">alert("'.get_lang('WarningWhenEditingScorm').'")</script>');
  4758. }
  4759. $renderer = $form->defaultRenderer();
  4760. $renderer->setElementTemplate('<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{label}<br />{element}','content_lp');
  4761. $form->addElement('html_editor','content_lp','<a style="cursor:pointer" onclick="launch_templates()"><img src="'.api_get_path(WEB_IMG_PATH).'templates.gif" /></a>');
  4762. $defaults["content_lp"]=file_get_contents($item_path);
  4763. }
  4764. $form->addElement('hidden', 'type', 'dokeos_'.$item_type);
  4765. $form->addElement('hidden', 'post_time', time());
  4766. $form->addElement('html','</div>');
  4767. $form->setDefaults($defaults);
  4768. return $form->return_form();
  4769. }
  4770. /**
  4771. * Enter description here...
  4772. *
  4773. * @param unknown_type $action
  4774. * @param unknown_type $id
  4775. * @param unknown_type $extra_info
  4776. * @return unknown
  4777. */
  4778. function display_document_form($action = 'add', $id = 0, $extra_info = 'new')
  4779. {
  4780. echo '
  4781. <style>
  4782. .row{
  4783. width:100%;
  4784. }
  4785. div.row div.label {
  4786. width: 75px;
  4787. }
  4788. div.row div.formw {
  4789. width: 88%;
  4790. }
  4791. </style>';
  4792. $tbl_lp_item = Database::get_course_table('lp_item');
  4793. $tbl_doc = Database::get_course_table(TABLE_DOCUMENT);
  4794. $path_parts = pathinfo($extra_info['dir']);
  4795. $no_display_edit_textarea=false;
  4796. //If action==edit document
  4797. //We don't display the document form if it's not an editable document (html or txt file)
  4798. if($action=="edit"){
  4799. if(is_array($extra_info)){
  4800. if($path_parts['extension']!="txt" && $path_parts['extension']!="html"){
  4801. $no_display_edit_textarea=true;
  4802. }
  4803. }
  4804. }
  4805. $no_display_add=false;
  4806. //If action==add an existing document
  4807. //We don't display the document form if it's not an editable document (html or txt file)
  4808. if($action=="add"){
  4809. if(is_numeric($extra_info)){
  4810. $sql_doc = "SELECT path FROM " . $tbl_doc . "WHERE id = " . $extra_info;
  4811. $result=api_sql_query($sql_doc, __FILE__, __LINE__);
  4812. $path_file=mysql_result($result,0,0);
  4813. $path_parts = pathinfo($path_file);
  4814. if($path_parts['extension']!="txt" && $path_parts['extension']!="html"){
  4815. $no_display_add=true;
  4816. }
  4817. }
  4818. }
  4819. if($id != 0 && is_array($extra_info))
  4820. {
  4821. $item_title = stripslashes($extra_info['title']);
  4822. $item_description = stripslashes($extra_info['description']);
  4823. if(empty($item_title))
  4824. {
  4825. $path_parts = pathinfo($extra_info['path']);
  4826. $item_title = stripslashes($path_parts['filename']);
  4827. }
  4828. }
  4829. elseif(is_numeric($extra_info))
  4830. {
  4831. $sql_doc = "
  4832. SELECT path, title
  4833. FROM " . $tbl_doc . "
  4834. WHERE id = " . $extra_info;
  4835. $result = api_sql_query($sql_doc, __FILE__, __LINE__);
  4836. $row = Database::fetch_array($result);
  4837. $explode = explode('.', $row['title']);
  4838. if(count($explode)>1){
  4839. for($i = 0; $i < count($explode) - 1; $i++)
  4840. $item_title .= $explode[$i];
  4841. }
  4842. else{
  4843. $item_title=$row['title'];
  4844. }
  4845. $item_title = str_replace('_', ' ', $item_title);
  4846. if(empty($item_title))
  4847. {
  4848. $path_parts = pathinfo($row['path']);
  4849. $item_title = stripslashes($path_parts['filename']);
  4850. }
  4851. }
  4852. else
  4853. {
  4854. $item_title = '';
  4855. $item_description = '';
  4856. }
  4857. $return = '<div style="margin:3px 0px;">';
  4858. if($id != 0 && is_array($extra_info))
  4859. $parent = $extra_info['parent_item_id'];
  4860. else
  4861. $parent = 0;
  4862. $sql = "
  4863. SELECT *
  4864. FROM " . $tbl_lp_item . "
  4865. WHERE
  4866. lp_id = " . $this->lp_id;
  4867. $result = api_sql_query($sql, __FILE__, __LINE__);
  4868. $arrLP = array();
  4869. while($row = Database::fetch_array($result))
  4870. {
  4871. $arrLP[] = array(
  4872. 'id' => $row['id'],
  4873. 'item_type' => $row['item_type'],
  4874. 'title' => $row['title'],
  4875. 'path' => $row['path'],
  4876. 'description' => $row['description'],
  4877. 'parent_item_id' => $row['parent_item_id'],
  4878. 'previous_item_id' => $row['previous_item_id'],
  4879. 'next_item_id' => $row['next_item_id'],
  4880. 'display_order' => $row['display_order'],
  4881. 'prerequisite' => $row['prerequisite']);
  4882. }
  4883. $this->tree_array($arrLP);
  4884. $arrLP = $this->arrMenu;
  4885. unset($this->arrMenu);
  4886. if($action == 'add')
  4887. $return .= '<p class="lp_title">'.get_lang("CreateTheDocument").' :</p>' . "\n";
  4888. elseif($action == 'move')
  4889. $return .= '<p class="lp_title">'.get_lang("MoveTheCurrentDocument").' :</p>' . "\n";
  4890. else
  4891. $return .= '<p class="lp_title">'.get_lang("EditTheCurrentDocument").' :</p>' . "\n";
  4892. if(isset($_GET['edit']) && $_GET['edit'] == 'true')
  4893. {
  4894. $return .= '<div class="lp_message" style="margin-bottom:15px;">';
  4895. $return .= '<p class="lp_title">'.get_lang("Warning").' !</p>';
  4896. $return .= get_lang("WarningEditingDocument");
  4897. $return .= '</div>';
  4898. }
  4899. /*
  4900. if($no_display_add==true){
  4901. $return .= '<div class="lp_message" style="margin-bottom:15px;">';
  4902. $return .= get_lang("CantEditDocument");
  4903. $return .= '</div>';
  4904. return $return;
  4905. }
  4906. */
  4907. require_once (api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php');
  4908. $form = new FormValidator('form','POST',api_get_self()."?".$_SERVER["QUERY_STRING"]);
  4909. $defaults["title"]=html_entity_decode($item_title);
  4910. $defaults["description"]=html_entity_decode($item_description);
  4911. $form->addElement('html',$return);
  4912. //$arrHide = array($id);
  4913. $arrHide[0]['value']=$this->name;
  4914. $arrHide[0]['padding']=3;
  4915. for($i = 0; $i < count($arrLP); $i++)
  4916. {
  4917. if($action != 'add'){
  4918. if(($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir') && !in_array($arrLP[$i]['id'], $arrHide) && !in_array($arrLP[$i]['parent_item_id'], $arrHide)){
  4919. $arrHide[$arrLP[$i]['id']]['value']=html_entity_decode(stripslashes($arrLP[$i]['title']));
  4920. $arrHide[$arrLP[$i]['id']]['padding']=3+ $arrLP[$i]['depth'] * 10;
  4921. if($parent == $arrLP[$i]['id']){
  4922. $s_selected_parent=$arrHide[$arrLP[$i]['id']];
  4923. }
  4924. }
  4925. }
  4926. else{
  4927. if($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir'){
  4928. $arrHide[$arrLP[$i]['id']]['value']=html_entity_decode(stripslashes($arrLP[$i]['title']));
  4929. $arrHide[$arrLP[$i]['id']]['padding']=3+ $arrLP[$i]['depth'] * 10;
  4930. if($parent == $arrLP[$i]['id']){
  4931. $s_selected_parent=$arrHide[$arrLP[$i]['id']];
  4932. }
  4933. }
  4934. }
  4935. }
  4936. $parent_select = &$form->addElement('select', 'parent', get_lang("Parent")." :", '', 'style="background:#F8F8F8; border:1px solid #999999; font-family:Arial, Verdana, Helvetica, sans-serif; font-size:12px; width:300px;" onchange="load_cbo(this.value);"');
  4937. foreach($arrHide as $key => $value){
  4938. $parent_select->addOption($value['value'],$key,'style="padding-left:'.$value['padding'].'px;"');
  4939. }
  4940. $parent_select -> setSelected($parent);
  4941. if(is_array($arrLP))
  4942. {
  4943. reset($arrLP);
  4944. }
  4945. $arrHide=array();
  4946. //POSITION
  4947. for($i = 0; $i < count($arrLP); $i++)
  4948. {
  4949. if($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id)
  4950. {
  4951. if($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  4952. $s_selected_position=$arrLP[$i]['id'];
  4953. elseif($action == 'add')
  4954. $s_selected_position=$arrLP[$i]['id'];
  4955. $arrHide[$arrLP[$i]['id']]['value']=get_lang("After").' "' . html_entity_decode(stripslashes($arrLP[$i]['title'])).'"';
  4956. }
  4957. }
  4958. $position = &$form->addElement('select', 'previous', get_lang("Position")." :", '', 'id="idPosition" style="background:#F8F8F8; border:1px solid #999999; font-family:Arial, Verdana, Helvetica, sans-serif; font-size:12px; width:300px;"');
  4959. $position->addOption(get_lang("FirstPosition"),0,'style="padding-left:3px;"');
  4960. foreach($arrHide as $key => $value){
  4961. $position->addOption($value['value'],$key,'style="padding-left:'.$value['padding'].'px;"');
  4962. }
  4963. $position -> setSelected($s_selected_position);
  4964. if(is_array($arrLP))
  4965. {
  4966. reset($arrLP);
  4967. }
  4968. if($action != 'move'){
  4969. $form->addElement('text','title', get_lang('Title').' :','id="idTitle" style="background:#F8F8F8; border:1px solid #999999; font-family:Arial, Verdana, Helvetica, sans-serif; font-size:12px; padding:1px 2px; width:300px;"');
  4970. //$form->addElement('textarea','description',get_lang("Description").' :', 'id="idDescription" style="background:#F8F8F8; border:1px solid #999999; font-family:Arial, Verdana, Helvetica, sans-serif; font-size:12px; padding:1px 2px; width:300px;"');
  4971. $id_prerequisite=0;
  4972. if(is_array($arrLP))
  4973. {
  4974. foreach($arrLP as $key=>$value){
  4975. if($value['id']==$id){
  4976. $id_prerequisite=$value['prerequisite'];
  4977. break;
  4978. }
  4979. }
  4980. }
  4981. $select_prerequisites=$form->addElement('select', 'prerequisites', get_lang('Prerequisites'), '', 'id="prerequisites" style="background:#F8F8F8; border:1px solid #999999; font-family:Arial, Verdana, Helvetica, sans-serif; font-size:12px; width:300px;"');
  4982. $select_prerequisites->addOption(get_lang("NoPrerequisites"),0,'style="padding-left:3px;"');
  4983. $arrHide=array();
  4984. for($i = 0; $i < count($arrLP); $i++)
  4985. {
  4986. if($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter')
  4987. {
  4988. if($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  4989. $s_selected_position=$arrLP[$i]['id'];
  4990. elseif($action == 'add')
  4991. $s_selected_position=$arrLP[$i]['id'];
  4992. $arrHide[$arrLP[$i]['id']]['value']=html_entity_decode(stripslashes($arrLP[$i]['title']));
  4993. }
  4994. }
  4995. foreach($arrHide as $key => $value){
  4996. $select_prerequisites->addOption($value['value'],$key,'style="padding-left:'.$value['padding'].'px;"');
  4997. if($key==$s_selected_position && $action == 'add'){
  4998. $select_prerequisites -> setSelected(0);
  4999. }
  5000. elseif($key==$id_prerequisite && $action == 'edit'){
  5001. $select_prerequisites -> setSelected($id_prerequisite);
  5002. }
  5003. }
  5004. if(!$no_display_add)
  5005. {
  5006. if(($extra_info == 'new' || $extra_info['item_type'] == TOOL_DOCUMENT || $_GET['edit'] == 'true'))
  5007. {
  5008. if(isset($_POST['content']))
  5009. $content = stripslashes($_POST['content']);
  5010. elseif(is_array($extra_info)){
  5011. //If it's an html document or a text file
  5012. if(!$no_display_edit_textarea){
  5013. $content = $this->display_document($extra_info['path'], false, false);
  5014. }
  5015. }
  5016. elseif(is_numeric($extra_info))
  5017. $content = $this->display_document($extra_info, false, false);
  5018. else
  5019. $content = '';
  5020. $form->addElement('submit', 'submit_button', get_lang('Ok'), 'style="padding:1px 2px; width:75px;"');
  5021. if(!$no_display_edit_textarea){
  5022. $renderer = $form->defaultRenderer();
  5023. $renderer->setElementTemplate('<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{label}<br />{element}','content_lp');
  5024. $form->addElement('html_editor','content_lp','<a style="cursor:pointer" onclick="launch_templates()"><img src="'.api_get_path(WEB_IMG_PATH).'templates.gif" /></a>');
  5025. $defaults["content_lp"]=$content;
  5026. }
  5027. }
  5028. elseif(is_numeric($extra_info))
  5029. {
  5030. $form->addElement('submit', 'submit_button', get_lang('Ok'), 'style="padding:1px 2px; width:75px;"');
  5031. $return = $this->display_document($extra_info, true, true, true);
  5032. $form->addElement('html',$return);
  5033. }
  5034. }
  5035. }
  5036. if($action == 'move')
  5037. {
  5038. $form->addElement('hidden', 'title', $item_title);
  5039. $form->addElement('hidden', 'description', $item_description);
  5040. }
  5041. if(is_numeric($extra_info))
  5042. {
  5043. $form->addElement('submit', 'submit_button', get_lang('Ok'), 'style="padding:1px 2px; width:75px;"');
  5044. $form->addElement('hidden', 'path', $extra_info);
  5045. }
  5046. elseif(is_array($extra_info))
  5047. {
  5048. $form->addElement('submit', 'submit_button', get_lang('Ok'), 'style="padding:1px 2px; width:75px;"');
  5049. $form->addElement('hidden', 'path', $extra_info['path']);
  5050. }
  5051. $form->addElement('hidden', 'type', TOOL_DOCUMENT);
  5052. $form->addElement('hidden', 'post_time', time());
  5053. $form->addElement('html','</div>');
  5054. $form->setDefaults($defaults);
  5055. return $form->return_form();
  5056. }
  5057. /**
  5058. * Enter description here...
  5059. *
  5060. * @param unknown_type $action
  5061. * @param unknown_type $id
  5062. * @param unknown_type $extra_info
  5063. */
  5064. function display_link_form($action = 'add', $id = 0, $extra_info = '')
  5065. {
  5066. $tbl_lp_item = Database::get_course_table('lp_item');
  5067. $tbl_link = Database::get_course_table(TABLE_LINK);
  5068. if($id != 0 && is_array($extra_info))
  5069. {
  5070. $item_title = stripslashes($extra_info['title']);
  5071. $item_description = stripslashes($extra_info['description']);
  5072. }
  5073. elseif(is_numeric($extra_info))
  5074. {
  5075. $sql_link = "
  5076. SELECT
  5077. title,
  5078. description,
  5079. url
  5080. FROM " . $tbl_link . "
  5081. WHERE id = " . $extra_info;
  5082. $result = api_sql_query($sql_link, __FILE__, __LINE__);
  5083. $row = Database::fetch_array($result);
  5084. $item_title = $row['title'];
  5085. $item_description = $row['description'];
  5086. $item_url = $row['url'];
  5087. }
  5088. else
  5089. {
  5090. $item_title = '';
  5091. $item_description = '';
  5092. }
  5093. $return = '<div style="margin:3px 10px;">';
  5094. if($id != 0 && is_array($extra_info))
  5095. $parent = $extra_info['parent_item_id'];
  5096. else
  5097. $parent = 0;
  5098. $sql = "
  5099. SELECT *
  5100. FROM " . $tbl_lp_item . "
  5101. WHERE
  5102. lp_id = " . $this->lp_id;
  5103. $result = api_sql_query($sql, __FILE__, __LINE__);
  5104. $arrLP = array();
  5105. while($row = Database::fetch_array($result))
  5106. {
  5107. $arrLP[] = array(
  5108. 'id' => $row['id'],
  5109. 'item_type' => $row['item_type'],
  5110. 'title' => $row['title'],
  5111. 'path' => $row['path'],
  5112. 'description' => $row['description'],
  5113. 'parent_item_id' => $row['parent_item_id'],
  5114. 'previous_item_id' => $row['previous_item_id'],
  5115. 'next_item_id' => $row['next_item_id'],
  5116. 'display_order' => $row['display_order'],
  5117. 'prerequisite' => $row['prerequisite']);
  5118. }
  5119. $this->tree_array($arrLP);
  5120. $arrLP = $this->arrMenu;
  5121. unset($this->arrMenu);
  5122. if($action == 'add')
  5123. $return .= '<p class="lp_title">'.get_lang("CreateTheLink").' :</p>' . "\n";
  5124. elseif($action == 'move')
  5125. $return .= '<p class="lp_title">'.get_lang("MoveCurrentLink").' :</p>' . "\n";
  5126. else
  5127. $return .= '<p class="lp_title">'.get_lang("EditCurrentLink").' :</p>' . "\n";
  5128. $return .= '<form method="POST">' . "\n";
  5129. $return .= "\t" . '<table cellpadding="0" cellspacing="0" class="lp_form">' . "\n";
  5130. $return .= "\t\t" . '<tr>' . "\n";
  5131. $return .= "\t\t\t" . '<td class="label"><label for="idParent">'.get_lang("Parent").' :</label></td>' . "\n";
  5132. $return .= "\t\t\t" . '<td class="input">' . "\n";
  5133. $return .= "\t\t\t\t" . '<select id="idParent" name="parent" onchange="load_cbo(this.value);" size="1">';
  5134. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
  5135. $arrHide = array($id);
  5136. for($i = 0; $i < count($arrLP); $i++)
  5137. {
  5138. if($action != 'add')
  5139. {
  5140. if(($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir') && !in_array($arrLP[$i]['id'], $arrHide) && !in_array($arrLP[$i]['parent_item_id'], $arrHide))
  5141. {
  5142. $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>';
  5143. }
  5144. else
  5145. {
  5146. $arrHide[] = $arrLP[$i]['id'];
  5147. }
  5148. }
  5149. else
  5150. {
  5151. if($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
  5152. $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>';
  5153. }
  5154. }
  5155. reset($arrLP);
  5156. $return .= "\t\t\t\t" . '</select>';
  5157. $return .= "\t\t\t" . '</td>' . "\n";
  5158. $return .= "\t\t" . '</tr>' . "\n";
  5159. $return .= "\t\t" . '<tr>' . "\n";
  5160. $return .= "\t\t\t" . '<td class="label"><label for="idPosition">'.get_lang("Position").' :</label></td>' . "\n";
  5161. $return .= "\t\t\t" . '<td class="input">' . "\n";
  5162. $return .= "\t\t\t\t" . '<select id="idPosition" name="previous" size="1">';
  5163. $return .= "\t\t\t\t\t" . '<option class="top" value="0">'.get_lang("FirstPosition").'</option>';
  5164. for($i = 0; $i < count($arrLP); $i++)
  5165. {
  5166. if($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id)
  5167. {
  5168. if($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5169. $selected = 'selected="selected" ';
  5170. elseif($action == 'add')
  5171. $selected = 'selected="selected" ';
  5172. else
  5173. $selected = '';
  5174. $return .= "\t\t\t\t\t" . '<option ' . $selected . 'value="' . $arrLP[$i]['id'] . '">'.get_lang("After").' "' . html_entity_decode(stripslashes($arrLP[$i]['title'])) . '"</option>';
  5175. }
  5176. }
  5177. $return .= "\t\t\t\t" . '</select>';
  5178. $return .= "\t\t\t" . '</td>' . "\n";
  5179. $return .= "\t\t" . '</tr>' . "\n";
  5180. if($action != 'move')
  5181. {
  5182. $return .= "\t\t" . '<tr>' . "\n";
  5183. $return .= "\t\t\t" . '<td class="label"><label for="idTitle">'.get_lang("Title").' :</label></td>' . "\n";
  5184. $return .= "\t\t\t" . '<td class="input"><input id="idTitle" name="title" type="text" value="' . $item_title . '" /></td>' . "\n";
  5185. $return .= "\t\t" . '</tr>' . "\n";
  5186. $return .= "\t\t" . '<tr>' . "\n";
  5187. $return .= "\t\t\t" . '<td class="label"><label for="idDescription">'.get_lang("Description").' :</label></td>' . "\n";
  5188. $return .= "\t\t\t" . '<td class="input"><textarea id="idDescription" name="description" rows="4">' . $item_description . '</textarea></td>' . "\n";
  5189. $return .= "\t\t" . '</tr>' . "\n";
  5190. $return .= "\t\t" . '<tr>' . "\n";
  5191. $return .= "\t\t\t" . '<td class="label"><label for="idURL">'.get_lang("Url").' :</label></td>' . "\n";
  5192. $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";
  5193. $return .= "\t\t" . '</tr>' . "\n";
  5194. $id_prerequisite=0;
  5195. foreach($arrLP as $key=>$value){
  5196. if($value['id']==$id){
  5197. $id_prerequisite=$value['prerequisite'];
  5198. break;
  5199. }
  5200. }
  5201. $arrHide=array();
  5202. for($i = 0; $i < count($arrLP); $i++)
  5203. {
  5204. if($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter')
  5205. {
  5206. if($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5207. $s_selected_position=$arrLP[$i]['id'];
  5208. elseif($action == 'add')
  5209. $s_selected_position=0;
  5210. $arrHide[$arrLP[$i]['id']]['value']=html_entity_decode(stripslashes($arrLP[$i]['title']));
  5211. }
  5212. }
  5213. $return .= "\t\t" . '<tr>' . "\n";
  5214. $return .= "\t\t\t" . '<td class="label"><label for="idPrerequisites">'.get_lang("Prerequisites").' :</label></td>' . "\n";
  5215. $return .= "\t\t\t" . '<td class="input"><select name="prerequisites" id="prerequisites" style="background:#F8F8F8; border:1px solid #999999; font-family:Arial, Verdana, Helvetica, sans-serif; font-size:12px; width:300px;"><option value="0">'.get_lang("NoPrerequisites").'</option>';
  5216. foreach($arrHide as $key => $value){
  5217. if($key==$s_selected_position && $action == 'add'){
  5218. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  5219. }
  5220. elseif($key==$id_prerequisite && $action == 'edit'){
  5221. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  5222. }
  5223. else{
  5224. $return .= '<option value="'.$key.'">'.$value['value'].'</option>';
  5225. }
  5226. }
  5227. $return .= "</select></td>";
  5228. $return .= "\t\t" . '</tr>' . "\n";
  5229. }
  5230. $return .= "\t\t" . '<tr>' . "\n";
  5231. $return .= "\t\t\t" . '<td colspan="2"><input class="button" name="submit_button" type="submit" value="'.get_lang("Ok").'" /></td>' . "\n";
  5232. $return .= "\t\t" . '</tr>' . "\n";
  5233. $return .= "\t" . '</table>' . "\n";
  5234. if($action == 'move')
  5235. {
  5236. $return .= "\t" . '<input name="title" type="hidden" value="' . $item_title . '" />' . "\n";
  5237. $return .= "\t" . '<input name="description" type="hidden" value="' . $item_description . '" />' . "\n";
  5238. }
  5239. if(is_numeric($extra_info))
  5240. {
  5241. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info . '" />' . "\n";
  5242. }
  5243. elseif(is_array($extra_info))
  5244. {
  5245. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />' . "\n";
  5246. }
  5247. $return .= "\t" . '<input name="type" type="hidden" value="'.TOOL_LINK.'" />' . "\n";
  5248. $return .= "\t" . '<input name="post_time" type="hidden" value="' . time() . '" />' . "\n";
  5249. $return .= '</form>' . "\n";
  5250. $return .= '</div>' . "\n";
  5251. return $return;
  5252. }
  5253. /**
  5254. * Enter description here...
  5255. *
  5256. * @param unknown_type $action
  5257. * @param unknown_type $id
  5258. * @param unknown_type $extra_info
  5259. * @return unknown
  5260. */
  5261. function display_student_publication_form($action = 'add', $id = 0, $extra_info = '')
  5262. {
  5263. $tbl_lp_item = Database::get_course_table('lp_item');
  5264. $tbl_publication = Database::get_course_table(TABLE_STUDENT_PUBLICATION);
  5265. if($id != 0 && is_array($extra_info))
  5266. {
  5267. $item_title = stripslashes($extra_info['title']);
  5268. $item_description = stripslashes($extra_info['description']);
  5269. }
  5270. elseif(is_numeric($extra_info))
  5271. {
  5272. $sql_publication = "
  5273. SELECT
  5274. title,
  5275. description
  5276. FROM " . $tbl_publication . "
  5277. WHERE id = " . $extra_info;
  5278. $result = api_sql_query($sql_publication, __FILE__, __LINE__);
  5279. $row = Database::fetch_array($result);
  5280. $item_title = $row['title'];
  5281. }
  5282. else
  5283. {
  5284. $item_title = '';
  5285. }
  5286. $return = '<div style="margin:3px 10px;">';
  5287. if($id != 0 && is_array($extra_info))
  5288. $parent = $extra_info['parent_item_id'];
  5289. else
  5290. $parent = 0;
  5291. $sql = "
  5292. SELECT *
  5293. FROM " . $tbl_lp_item . "
  5294. WHERE
  5295. lp_id = " . $this->lp_id;
  5296. $result = api_sql_query($sql, __FILE__, __LINE__);
  5297. $arrLP = array();
  5298. while($row = Database::fetch_array($result))
  5299. {
  5300. $arrLP[] = array(
  5301. 'id' => $row['id'],
  5302. 'item_type' => $row['item_type'],
  5303. 'title' => $row['title'],
  5304. 'path' => $row['path'],
  5305. 'description' => $row['description'],
  5306. 'parent_item_id' => $row['parent_item_id'],
  5307. 'previous_item_id' => $row['previous_item_id'],
  5308. 'next_item_id' => $row['next_item_id'],
  5309. 'display_order' => $row['display_order'],
  5310. 'prerequisite' => $row['prerequisite']);
  5311. }
  5312. $this->tree_array($arrLP);
  5313. $arrLP = $this->arrMenu;
  5314. unset($this->arrMenu);
  5315. if($action == 'add')
  5316. $return .= '<p class="lp_title">'.get_lang("Student_publication").' :</p>' . "\n";
  5317. elseif($action == 'move')
  5318. $return .= '<p class="lp_title">'.get_lang("MoveCurrentStudentPublication").' :</p>' . "\n";
  5319. else
  5320. $return .= '<p class="lp_title">'.get_lang("EditCurrentStudentPublication").' :</p>' . "\n";
  5321. $return .= '<form method="POST">' . "\n";
  5322. $return .= "\t" . '<table cellpadding="0" cellspacing="0" class="lp_form">' . "\n";
  5323. $return .= "\t\t" . '<tr>' . "\n";
  5324. $return .= "\t\t\t" . '<td class="label"><label for="idParent">'.get_lang("Parent").' :</label></td>' . "\n";
  5325. $return .= "\t\t\t" . '<td class="input">' . "\n";
  5326. $return .= "\t\t\t\t" . '<select id="idParent" name="parent" onchange="load_cbo(this.value);" size="1">';
  5327. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
  5328. $arrHide = array($id);
  5329. for($i = 0; $i < count($arrLP); $i++)
  5330. {
  5331. if($action != 'add')
  5332. {
  5333. if(($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir') && !in_array($arrLP[$i]['id'], $arrHide) && !in_array($arrLP[$i]['parent_item_id'], $arrHide))
  5334. {
  5335. $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>';
  5336. }
  5337. else
  5338. {
  5339. $arrHide[] = $arrLP[$i]['id'];
  5340. }
  5341. }
  5342. else
  5343. {
  5344. if($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
  5345. $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>';
  5346. }
  5347. }
  5348. reset($arrLP);
  5349. $return .= "\t\t\t\t" . '</select>';
  5350. $return .= "\t\t\t" . '</td>' . "\n";
  5351. $return .= "\t\t" . '</tr>' . "\n";
  5352. $return .= "\t\t" . '<tr>' . "\n";
  5353. $return .= "\t\t\t" . '<td class="label"><label for="idPosition">'.get_lang("Position").' :</label></td>' . "\n";
  5354. $return .= "\t\t\t" . '<td class="input">' . "\n";
  5355. $return .= "\t\t\t\t" . '<select id="idPosition" name="previous" size="1">';
  5356. $return .= "\t\t\t\t\t" . '<option class="top" value="0">'.get_lang("FirstPosition").'</option>';
  5357. for($i = 0; $i < count($arrLP); $i++)
  5358. {
  5359. if($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id)
  5360. {
  5361. if($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5362. $selected = 'selected="selected" ';
  5363. elseif($action == 'add')
  5364. $selected = 'selected="selected" ';
  5365. else
  5366. $selected = '';
  5367. $return .= "\t\t\t\t\t" . '<option ' . $selected . 'value="' . $arrLP[$i]['id'] . '">'.get_lang("After").' "' . html_entity_decode(stripslashes($arrLP[$i]['title'])) . '"</option>';
  5368. }
  5369. }
  5370. $return .= "\t\t\t\t" . '</select>';
  5371. $return .= "\t\t\t" . '</td>' . "\n";
  5372. $return .= "\t\t" . '</tr>' . "\n";
  5373. if($action != 'move')
  5374. {
  5375. $return .= "\t\t" . '<tr>' . "\n";
  5376. $return .= "\t\t\t" . '<td class="label"><label for="idTitle">'.get_lang("Title").' :</label></td>' . "\n";
  5377. $return .= "\t\t\t" . '<td class="input"><input id="idTitle" name="title" type="text" value="' . $item_title . '" /></td>' . "\n";
  5378. $return .= "\t\t" . '</tr>' . "\n";
  5379. $id_prerequisite=0;
  5380. foreach($arrLP as $key=>$value){
  5381. if($value['id']==$id){
  5382. $id_prerequisite=$value['prerequisite'];
  5383. break;
  5384. }
  5385. }
  5386. $arrHide=array();
  5387. for($i = 0; $i < count($arrLP); $i++)
  5388. {
  5389. if($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter')
  5390. {
  5391. if($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5392. $s_selected_position=$arrLP[$i]['id'];
  5393. elseif($action == 'add')
  5394. $s_selected_position=0;
  5395. $arrHide[$arrLP[$i]['id']]['value']=html_entity_decode(stripslashes($arrLP[$i]['title']));
  5396. }
  5397. }
  5398. $return .= "\t\t" . '<tr>' . "\n";
  5399. $return .= "\t\t\t" . '<td class="label"><label for="idPrerequisites">'.get_lang("Prerequisites").' :</label></td>' . "\n";
  5400. $return .= "\t\t\t" . '<td class="input"><select name="prerequisites" id="prerequisites" style="background:#F8F8F8; border:1px solid #999999; font-family:Arial, Verdana, Helvetica, sans-serif; font-size:12px; width:300px;"><option value="0">'.get_lang("NoPrerequisites").'</option>';
  5401. foreach($arrHide as $key => $value){
  5402. if($key==$s_selected_position && $action == 'add'){
  5403. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  5404. }
  5405. elseif($key==$id_prerequisite && $action == 'edit'){
  5406. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  5407. }
  5408. else{
  5409. $return .= '<option value="'.$key.'">'.$value['value'].'</option>';
  5410. }
  5411. }
  5412. $return .= "</select></td>";
  5413. $return .= "\t\t" . '</tr>' . "\n";
  5414. }
  5415. $return .= "\t\t" . '<tr>' . "\n";
  5416. $return .= "\t\t\t" . '<td colspan="2"><input class="button" name="submit_button" type="submit" value="'.get_lang("Ok").'" /></td>' . "\n";
  5417. $return .= "\t\t" . '</tr>' . "\n";
  5418. $return .= "\t" . '</table>' . "\n";
  5419. if($action == 'move')
  5420. {
  5421. $return .= "\t" . '<input name="title" type="hidden" value="' . $item_title . '" />' . "\n";
  5422. $return .= "\t" . '<input name="description" type="hidden" value="' . $item_description . '" />' . "\n";
  5423. }
  5424. if(is_numeric($extra_info))
  5425. {
  5426. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info . '" />' . "\n";
  5427. }
  5428. elseif(is_array($extra_info))
  5429. {
  5430. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />' . "\n";
  5431. }
  5432. $return .= "\t" . '<input name="type" type="hidden" value="'.TOOL_STUDENTPUBLICATION.'" />' . "\n";
  5433. $return .= "\t" . '<input name="post_time" type="hidden" value="' . time() . '" />' . "\n";
  5434. $return .= '</form>' . "\n";
  5435. $return .= '</div>' . "\n";
  5436. return $return;
  5437. }
  5438. /**
  5439. * Displays the menu for manipulating a step
  5440. *
  5441. * @return unknown
  5442. */
  5443. function display_manipulate($item_id, $item_type = TOOL_DOCUMENT)
  5444. {
  5445. $return = '<div class="lp_manipulate"><table border="0" width="100%"><tr><td valign="top" width="400">';
  5446. switch($item_type)
  5447. {
  5448. case 'dokeos_chapter':
  5449. case 'chapter':
  5450. $lang = get_lang('TitleManipulateChapter');
  5451. break;
  5452. case 'dokeos_module':
  5453. case 'module':
  5454. $lang = get_lang('TitleManipulateModule');
  5455. break;
  5456. case TOOL_DOCUMENT:
  5457. $lang = get_lang('TitleManipulateDocument');
  5458. break;
  5459. case TOOL_LINK:
  5460. case 'link':
  5461. $lang = get_lang('TitleManipulateLink');
  5462. break;
  5463. case TOOL_QUIZ:
  5464. $lang = get_lang('TitleManipulateQuiz');
  5465. break;
  5466. case TOOL_STUDENTPUBLICATION:
  5467. $lang = get_lang('TitleManipulateStudentPublication');
  5468. break;
  5469. }
  5470. $tbl_lp_item = Database::get_course_table('lp_item');
  5471. $sql = "
  5472. SELECT
  5473. description
  5474. FROM " . $tbl_lp_item . " as lp
  5475. WHERE
  5476. lp.id = " . $item_id;
  5477. $result = api_sql_query($sql, __FILE__, __LINE__);
  5478. $s_description=mysql_result($result,0,0);
  5479. $return .= '<p class="lp_title">' . $lang . '</p>';
  5480. $return .= '<a href="' .api_get_self(). '?cidReq=' . $_GET['cidReq'] . '&amp;action=edit_item&amp;view=build&amp;id=' . $item_id . '&amp;lp_id=' . $this->lp_id . '" title="Edit the current item"><img align="absbottom" alt="Edit the current item" src="../img/edit.gif" title="Edit the current item" /> '.get_lang("Edit").'</a>';
  5481. $return .= '<a href="' .api_get_self(). '?cidReq=' . $_GET['cidReq'] . '&amp;action=move_item&amp;view=build&amp;id=' . $item_id . '&amp;lp_id=' . $this->lp_id . '" title="Move the current item"><img align="absbottom" alt="Move the current item" src="../img/deplacer_fichier.gif" title="Move the current item" /> '.get_lang("Move").'</a>';
  5482. // commented for now as prerequisites cannot be added to chapters
  5483. if($item_type != 'dokeos_chapter' && $item_type != 'chapter')
  5484. {
  5485. $return .= '<a href="' .api_get_self(). '?cidReq=' . $_GET['cidReq'] . '&amp;action=edit_item_prereq&amp;view=build&amp;id=' . $item_id . '&amp;lp_id=' . $this->lp_id . '" title="'.get_lang('Prerequisites').'"><img align="absbottom" alt="'.get_lang('Prerequisites').'" src="../img/right.gif" title="'.get_lang('Prerequisites').'" /> '.get_lang('Prerequisites').'</a>';
  5486. }
  5487. $return .= '<a href="' .api_get_self(). '?cidReq=' . $_GET['cidReq'] . '&amp;action=delete_item&amp;view=build&amp;id=' . $item_id . '&amp;lp_id=' . $this->lp_id . '" onclick="return confirmation(\'' . htmlentities($s_description) . '\');" title="Delete the current item"><img alt="Delete the current item" align="absbottom" src="../img/delete.gif" title="Delete the current item" /> '.get_lang("Delete").'</a>';
  5488. //$return .= '<br><br><p class="lp_text">' . ((trim($s_description) == '') ? ''.get_lang("NoDescription").'' : stripslashes(nl2br($s_description))) . '</p>';
  5489. $return.="</td><td valign='top'>";
  5490. // get the audiorecorder. Use of ob_* functions since there are echos in the file
  5491. ob_start();
  5492. $audio_recorder_studentview = 'false';
  5493. $audio_recorder_item_id = $item_id;
  5494. if(api_get_setting('service_visio','active')=='true'){
  5495. include('audiorecorder.inc.php');
  5496. }
  5497. $return .= ob_get_contents();
  5498. ob_end_clean();
  5499. // end of audiorecorder include
  5500. $return.="</td></tr></table>";
  5501. $return .= '</div>';
  5502. return $return;
  5503. }
  5504. /**
  5505. * Creates the javascript needed for filling up the checkboxes without page reload
  5506. *
  5507. * @return string
  5508. */
  5509. function create_js()
  5510. {
  5511. $return = '<script language="javascript" type="text/javascript">' . "\n";
  5512. $return .= 'function load_cbo(id){' . "\n";
  5513. $return .= "var cbo = document.getElementById('idPosition');\n";
  5514. $return .= 'for(var i = cbo.length - 1; i > 0; i--)';
  5515. $return .= 'cbo.options[i] = null;'."\n";
  5516. $return .= 'var k=0;'."\n";
  5517. $return .= 'for(var i = 1; i <= child_name[id].length; i++){'."\n";
  5518. $return .= ' cbo.options[i] = new Option(child_name[id][i-1], child_value[id][i-1]);'."\n";
  5519. $return .= 'k=i;';
  5520. $return .= '}' . "\n\n";
  5521. $return .= 'if( typeof cbo != "undefined" ) {cbo.options[k].selected = true;}';
  5522. $return .='}';
  5523. $return .= 'var child_name = new Array();' . "\n";
  5524. $return .= 'var child_value = new Array();' . "\n\n";
  5525. $return .= 'child_name[0] = new Array();' . "\n";
  5526. $return .= 'child_value[0] = new Array();' . "\n\n";
  5527. $tbl_lp_item = Database::get_course_table('lp_item');
  5528. $sql_zero = "
  5529. SELECT *
  5530. FROM " . $tbl_lp_item . "
  5531. WHERE
  5532. lp_id = " . $this->lp_id . " AND
  5533. parent_item_id = 0
  5534. ORDER BY display_order ASC";
  5535. $res_zero = api_sql_query($sql_zero, __FILE__, __LINE__);
  5536. $i = 0;
  5537. while($row_zero = Database::fetch_array($res_zero))
  5538. {
  5539. $return .= 'child_name[0][' . $i . '] = "'.get_lang("After").' \"' . $row_zero['title'] . '\"";' . "\n";
  5540. $return .= 'child_value[0][' . $i++ . '] = "' . $row_zero['id'] . '";' . "\n";
  5541. }
  5542. $return .= "\n";
  5543. $sql = "
  5544. SELECT *
  5545. FROM " . $tbl_lp_item . "
  5546. WHERE
  5547. lp_id = " . $this->lp_id;
  5548. $res = api_sql_query($sql, __FILE__, __LINE__);
  5549. while($row = Database::fetch_array($res))
  5550. {
  5551. $sql_parent = "
  5552. SELECT *
  5553. FROM " . $tbl_lp_item . "
  5554. WHERE parent_item_id = " . $row['id'] . "
  5555. ORDER BY display_order ASC";
  5556. $res_parent = api_sql_query($sql_parent, __FILE__, __LINE__);
  5557. $i = 0;
  5558. $return .= 'child_name[' . $row['id'] . '] = new Array();' . "\n";
  5559. $return .= 'child_value[' . $row['id'] . '] = new Array();' . "\n\n";
  5560. while($row_parent = Database::fetch_array($res_parent))
  5561. {
  5562. $return .= 'child_name[' . $row['id'] . '][' . $i . '] = "'.get_lang("After").' \"' . $row_parent['title'] . '\"";' . "\n";
  5563. $return .= 'child_value[' . $row['id'] . '][' . $i++ . '] = "' . $row_parent['id'] . '";' . "\n";
  5564. }
  5565. $return .= "\n";
  5566. }
  5567. $return .= '</script>' . "\n";
  5568. return $return;
  5569. }
  5570. /**
  5571. * Enter description here...
  5572. *
  5573. * @param unknown_type $item_id
  5574. * @return unknown
  5575. */
  5576. function display_move_item($item_id)
  5577. {
  5578. global $_course; //will disappear
  5579. $return = '';
  5580. if(is_numeric($item_id))
  5581. {
  5582. $tbl_lp_item = Database::get_course_table('lp_item');
  5583. $sql = "
  5584. SELECT *
  5585. FROM " . $tbl_lp_item . "
  5586. WHERE id = " . $item_id;
  5587. $res = api_sql_query($sql, __FILE__, __LINE__);
  5588. $row = Database::fetch_array($res);
  5589. switch($row['item_type'])
  5590. {
  5591. case 'dokeos_chapter': case 'dir' : case 'asset' :
  5592. $return .= $this->display_manipulate($item_id, $row['item_type']);
  5593. $return .= $this->display_item_form($row['item_type'], get_lang('MoveCurrentChapter'), 'move', $item_id, $row);
  5594. break;
  5595. case 'dokeos_module':
  5596. $return .= $this->display_manipulate($item_id, $row['item_type']);
  5597. $return .= $this->display_item_form($row['item_type'], 'Move th current module:', 'move', $item_id, $row);
  5598. break;
  5599. case TOOL_DOCUMENT:
  5600. $return .= $this->display_manipulate($item_id, $row['item_type']);
  5601. $return .= $this->display_document_form('move', $item_id, $row);
  5602. break;
  5603. case TOOL_LINK:
  5604. $return .= $this->display_manipulate($item_id, $row['item_type']);
  5605. $return .= $this->display_link_form('move', $item_id, $row);
  5606. break;
  5607. case TOOL_HOTPOTATOES:
  5608. $return .= $this->display_manipulate($item_id, $row['item_type']);
  5609. $return .= $this->display_link_form('move', $item_id, $row);
  5610. break;
  5611. case TOOL_QUIZ:
  5612. $return .= $this->display_manipulate($item_id, $row['item_type']);
  5613. $return .= $this->display_quiz_form('move', $item_id, $row);
  5614. break;
  5615. case TOOL_STUDENTPUBLICATION:
  5616. $return .= $this->display_manipulate($item_id, $row['item_type']);
  5617. $return .= $this->display_student_publication_form('move', $item_id, $row);
  5618. break;
  5619. case TOOL_FORUM :
  5620. $return .= $this->display_manipulate($item_id, $row['item_type']);
  5621. $return .= $this->display_forum_form('move', $item_id, $row);
  5622. }
  5623. }
  5624. return $return;
  5625. }
  5626. /**
  5627. * Displays a basic form on the overview page for changing the item title and the item description.
  5628. *
  5629. * @param string $item_type
  5630. * @param string $title
  5631. * @param array $data
  5632. * @return string
  5633. */
  5634. function display_item_small_form($item_type, $title = '', $data)
  5635. {
  5636. $return .= '<div class="lp_small_form">' . "\n";
  5637. $return .= '<p class="lp_title">' . $title . '</p>';
  5638. $return .= '<form method="post">' . "\n";
  5639. $return .= '<table cellpadding="0" cellspacing="0" class="lp_form">';
  5640. $return .= "\t\t" . '<tr>' . "\n";
  5641. $return .= "\t\t\t" . '<td class="label"><label for="idTitle">Title:</label></td>' . "\n";
  5642. $return .= "\t\t\t" . '<td class="input"><input class="small_form" id="idTitle" name="title" type="text" value="' . $data['title'] . '" /></td>' . "\n";
  5643. $return .= "\t\t" . '</tr>' . "\n";
  5644. $return .= "\t\t" . '<tr>' . "\n";
  5645. $return .= "\t\t\t" . '<td class="label"><label for="idDescription">Description:</label></td>' . "\n";
  5646. $return .= "\t\t\t" . '<td class="input"><textarea class="small_form" id="idDescription" name="description" rows="4">' . $data['description'] . '</textarea></td>' . "\n";
  5647. $return .= "\t\t" . '</tr>' . "\n";
  5648. $return .= "\t\t" . '<tr>' . "\n";
  5649. $return .= "\t\t\t" . '<td colspan="2"><input class="button small_form" name="submit_button" type="submit" value="OK" /></td>' . "\n";
  5650. $return .= "\t\t" . '</tr>' . "\n";
  5651. $return .= "\t\t" . '</table>' . "\n";
  5652. $return .= "\t" . '<input name="parent" type="hidden" value="' . $data['parent_item_id'] . '"/>' . "\n";
  5653. $return .= "\t" . '<input name="previous" type="hidden" value="' . $data['previous_item_id'] . '"/>' . "\n";
  5654. $return .= '</form>';
  5655. $return .= '</div>';
  5656. return $return;
  5657. }
  5658. /**
  5659. * Enter description here...
  5660. *
  5661. * @param unknown_type $item_id
  5662. * @return unknown
  5663. */
  5664. function display_item_prerequisites_form($item_id)
  5665. {
  5666. $tbl_lp_item = Database::get_course_table('lp_item');
  5667. /* current prerequisite */
  5668. $sql = "
  5669. SELECT *
  5670. FROM " . $tbl_lp_item . "
  5671. WHERE id = " . $item_id;
  5672. $result = api_sql_query($sql, __FILE__, __LINE__);
  5673. $row = Database::fetch_array($result);
  5674. $preq_id = $row['prerequisite'];
  5675. //$preq_mastery = $row['mastery_score'];
  5676. //$preq_max = $row['max_score'];
  5677. $return = $this->display_manipulate($item_id, TOOL_DOCUMENT);
  5678. $return .= '<div style="margin:3px 10px;">';
  5679. $return .= '<p class="lp_title">'.get_lang("AddEditPrerequisites").'</p>';
  5680. $return .= '<form method="POST">';
  5681. $return .= '<table class="lp_form">';
  5682. $return .= '<tr>';
  5683. $return .= '<th></th>';
  5684. $return .= '<th class="exercise">'.get_lang("Minimum").'</th>';
  5685. $return .= '<th class="exercise">'.get_lang("Maximum").'</th>';
  5686. $return .= '</tr>';
  5687. $return .= '<tr>';
  5688. $return .= '<td class="radio" colspan="3">';
  5689. $return .= '<input checked="checked" id="idNone" name="prerequisites" style="margin-left:0; margin-right:10px;" type="radio" />';
  5690. $return .= '<label for="idNone">'.get_lang("None").'</label>';
  5691. $return .= '</td>';
  5692. $return .= '</tr>';
  5693. $sql = "
  5694. SELECT *
  5695. FROM " . $tbl_lp_item . "
  5696. WHERE
  5697. lp_id = " . $this->lp_id;
  5698. $result = api_sql_query($sql, __FILE__, __LINE__);
  5699. $arrLP = array();
  5700. while($row = Database::fetch_array($result))
  5701. {
  5702. $arrLP[] = array(
  5703. 'id' => $row['id'],
  5704. 'item_type' => $row['item_type'],
  5705. 'title' => $row['title'],
  5706. 'ref' => $row['ref'],
  5707. 'description' => $row['description'],
  5708. 'parent_item_id' => $row['parent_item_id'],
  5709. 'previous_item_id' => $row['previous_item_id'],
  5710. 'next_item_id' => $row['next_item_id'],
  5711. 'max_score' => $row['max_score'],
  5712. 'min_score' => $row['min_score'],
  5713. 'mastery_score' => $row['mastery_score'],
  5714. 'next_item_id' => $row['next_item_id'],
  5715. 'display_order' => $row['display_order']);
  5716. if($row['ref'] == $preq_id)
  5717. {
  5718. $preq_mastery = $row['mastery_score'];
  5719. $preq_max = $row['max_score'];
  5720. }
  5721. }
  5722. $this->tree_array($arrLP);
  5723. $arrLP = $this->arrMenu;
  5724. unset($this->arrMenu);
  5725. for($i = 0; $i < count($arrLP); $i++)
  5726. {
  5727. if($arrLP[$i]['id'] == $item_id)
  5728. break;
  5729. $return .= '<tr>';
  5730. $return .= '<td class="radio"' . (($arrLP[$i]['item_type'] != TOOL_QUIZ && $arrLP[$i]['item_type'] != TOOL_HOTPOTATOES) ? ' colspan="3"' : '') . '>';
  5731. $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'] . '" />';
  5732. $return .= '<img alt="" src="../img/lp_' . $arrLP[$i]['item_type'] . '.png" style="margin-right:5px;" title="" />';
  5733. $return .= '<label for="id' . $arrLP[$i]['id'] . '">' . stripslashes($arrLP[$i]['title']) . '</label>';
  5734. $return .= '</td>';
  5735. //$return .= '<td class="radio"' . (($arrLP[$i]['item_type'] != TOOL_HOTPOTATOES) ? ' colspan="3"' : '') . ' />';
  5736. if($arrLP[$i]['item_type'] == TOOL_QUIZ)
  5737. {
  5738. $return .= '<td class="exercise">';
  5739. $return .= '<input maxlength="3" name="min_' . $arrLP[$i]['id'] . '" type="text" value="' . (($arrLP[$i]['id'] == $preq_id) ? $preq_mastery : 0) . '" />';
  5740. $return .= '</td>';
  5741. $return .= '<td class="exercise">';
  5742. $return .= '<input maxlength="3" name="max_' . $arrLP[$i]['id'] . '" type="text" value="' . $arrLP[$i]['max_score'] . '" disabled="true" />';
  5743. $return .= '</td>';
  5744. }
  5745. if($arrLP[$i]['item_type'] == TOOL_HOTPOTATOES)
  5746. {
  5747. $return .= '<td class="exercise">';
  5748. $return .= '<input maxlength="3" name="min_' . $arrLP[$i]['id'] . '" type="text" value="' . (($arrLP[$i]['id'] == $preq_id) ? $preq_mastery : 0) . '" />';
  5749. $return .= '</td>';
  5750. $return .= '<td class="exercise">';
  5751. $return .= '<input maxlength="3" name="max_' . $arrLP[$i]['id'] . '" type="text" value="' . $arrLP[$i]['max_score'] . '" disabled="true" />';
  5752. $return .= '</td>';
  5753. }
  5754. $return .='</tr>';
  5755. }
  5756. $return .= '<tr>';
  5757. $return .= '<td colspan="3">';
  5758. $return .= '<input class="button" name="submit_button" type="submit" value="'.get_lang("Ok").'" /></td>' . "\n";
  5759. $return .= '</td>';
  5760. $return .= '</tr>';
  5761. $return .= '</table>';
  5762. $return .= '</form>';
  5763. $return .= '</div>';
  5764. return $return;
  5765. }
  5766. /**
  5767. * Creates a list with all the documents in it
  5768. *
  5769. * @return string
  5770. */
  5771. function get_documents()
  5772. {
  5773. global $_course;
  5774. $tbl_doc = Database::get_course_table(TABLE_DOCUMENT);
  5775. $sql_doc = "
  5776. SELECT *
  5777. FROM " . $tbl_doc . "
  5778. WHERE
  5779. path NOT LIKE '%_DELETED_%'
  5780. ORDER BY path ASC";
  5781. $res_doc = api_sql_query($sql_doc, __FILE__, __LINE__);
  5782. $return = '<div class="lp_resource_header"' . " onclick=\"if(document.getElementById('resDoc').style.display == 'block') {document.getElementById('resDoc').style.display = 'none';} else {document.getElementById('resDoc').style.display = 'block';}\"" . ' style="cursor:pointer;"><img align="left" alt="" src="../img/lp_' . TOOL_DOCUMENT . '.gif" style="margin-right:5px;" title="" />'.get_lang("Document").'</div>';
  5783. $return .= '<div class="lp_resource_elements" id="resDoc">';
  5784. $resources=api_store_result($res_doc);
  5785. $resources_sorted = array();
  5786. // if you want to debug it, I advise you to do "echo" on the eval statements
  5787. foreach($resources as $resource)
  5788. {
  5789. $resource_paths = explode('/',$resource['path']);
  5790. array_shift($resource_paths);
  5791. $path_to_eval = $last_path = '';
  5792. $is_file = false;
  5793. foreach($resource_paths as $key => $resource_path)
  5794. {
  5795. if(strpos($resource_path,'.')===false && $key != count($resource_paths)-1)
  5796. { // it's a folder
  5797. $path_to_eval .= '["'.$resource_path.'"]["files"]';
  5798. }
  5799. else if(strpos($resource_path,'.')!==false)
  5800. $is_file = true;
  5801. $last_path = $resource_path;
  5802. }
  5803. if($is_file)
  5804. {
  5805. eval('$resources_sorted'.$path_to_eval.'['.$resource['id'].'] = "'.$last_path.'";');
  5806. }
  5807. else
  5808. {
  5809. eval('$resources_sorted'.$path_to_eval.'["'.$last_path.'"]["id"]='.$resource['id'].';');
  5810. }
  5811. }
  5812. $return .=$this->write_resources_tree('', $resources_sorted);
  5813. $return .='</div>';
  5814. if(Database::num_rows($res_doc) == 0)
  5815. $return .= '<div class="lp_resource_element">'.get_lang("NoDocuments").'</div>';
  5816. return $return;
  5817. }
  5818. function write_resources_tree($return, $resources_sorted, $num=0){
  5819. include_once(api_get_path(LIBRARY_PATH).'fileDisplay.lib.php');
  5820. if(count($resources_sorted)>0)
  5821. {
  5822. foreach($resources_sorted as $key=>$resource)
  5823. {
  5824. if(is_int($resource['id']))
  5825. { // it's a folder
  5826. $return .= '<div><div style="margin-left:' . ($num * 15) . 'px;margin-right:5px;"><img style="cursor: pointer;" src="../img/nolines_plus.gif" align="absmiddle" id="img_'.$resource["id"].'" onclick="testResources(\''.$resource["id"].'\',\'img_'.$resource["id"].'\')"><img alt="" src="../img/lp_folder.gif" title="" align="absmiddle" />&nbsp;<span onclick="testResources(\''.$resource["id"].'\',\'img_'.$resource["id"].'\')" style="cursor: pointer;" >'.$key.'</span></div><div style="display: none;" id="'.$resource['id'].'">';
  5827. $return = $this->write_resources_tree($return, $resource['files'], $num+1);
  5828. $return .= "</div></div>\r\n";
  5829. }
  5830. else
  5831. {
  5832. // it's a file
  5833. $icon = choose_image($resource);
  5834. $position = strrpos($icon,'.');
  5835. $icon=substr($icon,0,$position).'_small.gif';
  5836. $return .= '<div><div style="margin-left:' . (($num+1) * 15) . 'px;margin-right:5px;"><a href="' . api_get_self() . '?cidReq=' . $_GET['cidReq'] . '&amp;action=add_item&amp;type=' . TOOL_DOCUMENT . '&amp;file=' . $key . '&amp;lp_id=' . $this->lp_id . '"><img align="left" alt="" src="../img/'.$icon.'" title="" />&nbsp;'.$resource."</a></div></div>\r\n";
  5837. }
  5838. }
  5839. }
  5840. return $return;
  5841. }
  5842. /**
  5843. * Creates a list with all the exercises (quiz) in it
  5844. *
  5845. * @return string
  5846. */
  5847. function get_exercises()
  5848. {
  5849. // new for hotpotatoes
  5850. $uploadPath = DIR_HOTPOTATOES; //defined in main_api
  5851. $tbl_doc = Database::get_course_table(TABLE_DOCUMENT);
  5852. $tbl_quiz = Database::get_course_table(TABLE_QUIZ_TEST);
  5853. $sql_quiz = "
  5854. SELECT *
  5855. FROM " . $tbl_quiz . "
  5856. WHERE active<>'-1'
  5857. ORDER BY title ASC";
  5858. $sql_hot = "SELECT * FROM ".$tbl_doc." " .
  5859. " WHERE path LIKE '".$uploadPath."/%/%htm%'" .
  5860. " ORDER BY id ASC";
  5861. $res_quiz = api_sql_query($sql_quiz, __FILE__, __LINE__);
  5862. $res_hot = api_sql_query($sql_hot, __FILE__, __LINE__);
  5863. $return .= '<div class="lp_resource_header_end"' . " onclick=\"if(document.getElementById('resExercise').style.display == 'block') {document.getElementById('resExercise').style.display = 'none';} else {document.getElementById('resExercise').style.display = 'block';}\"" . ' style="cursor:pointer;"><img align="left" alt="" src="../img/lp_' . TOOL_QUIZ . '.gif" style="margin-right:5px;" title="" />'.get_lang('Quiz').'</div>';
  5864. $return .= '<div class="lp_resource_elements_end" id="resExercise">';
  5865. while ($row_hot = mysql_fetch_array($res_hot))
  5866. {
  5867. $return .= '<div class="lp_resource_element">';
  5868. //display quizhotpotatoes
  5869. $return .= '<img alt="" src="../img/jqz.jpg" style="margin-right:5px;" title="" />';
  5870. $return .= '<a href="' .api_get_self(). '?cidReq=' . $_GET['cidReq'] . '&amp;action=add_item&amp;type=' . TOOL_HOTPOTATOES . '&amp;file=' . $row_hot['id'] . '&amp;lp_id=' . $this->lp_id . '">' . $row_hot['title'] . '</a>';
  5871. //$return .= $row_quiz['title'];
  5872. $return .= '</div>';
  5873. }
  5874. while($row_quiz = Database::fetch_array($res_quiz))
  5875. {
  5876. $return .= '<div class="lp_resource_element">';
  5877. $return .= '<img alt="" src="../img/quizz_small.gif" style="margin-right:5px;" title="" />';
  5878. $return .= '<a href="' .api_get_self(). '?cidReq=' . $_GET['cidReq'] . '&amp;action=add_item&amp;type=' . TOOL_QUIZ . '&amp;file=' . $row_quiz['id'] . '&amp;lp_id=' . $this->lp_id . '">' . $row_quiz['title'] . '</a>';
  5879. //$return .= $row_quiz['title'];
  5880. $return .= '</div>';
  5881. }
  5882. if(Database::num_rows($res_quiz) == 0)
  5883. $return .= '<div class="lp_resource_element">'.get_lang("NoExercisesAvailable").'</div>';
  5884. $return .= '<div class="lp_resource_element">';
  5885. $return .= '<img alt="" src="../img/new_test_small.gif" style="margin-right:5px;" title="" />';
  5886. $return .= '<a href="'.api_get_path(REL_CODE_PATH).'exercice/exercise_admin.php">' . get_lang('NewExercise') . '</a>';
  5887. $return .= '</div>';
  5888. $return .= '</div>';
  5889. return $return;
  5890. }
  5891. /**
  5892. * Creates a list with all the links in it
  5893. *
  5894. * @return string
  5895. */
  5896. function get_links()
  5897. {
  5898. $tbl_link = Database::get_course_table(TABLE_LINK);
  5899. $sql_link = "
  5900. SELECT *
  5901. FROM " . $tbl_link . "
  5902. ORDER BY title ASC";
  5903. $res_link = api_sql_query($sql_link, __FILE__, __LINE__);
  5904. $return .= '<div class="lp_resource_header"' . " onclick=\"if(document.getElementById('resLink').style.display == 'block') {document.getElementById('resLink').style.display = 'none';} else {document.getElementById('resLink').style.display = 'block';}\"" . ' style="cursor:pointer;"><img align="left" alt="" src="../img/lp_' . TOOL_LINK . '.gif" style="margin-right:5px;" title="" />'.get_lang("Links").'</div>';
  5905. $return .= '<div class="lp_resource_elements" id="resLink">';
  5906. while($row_link = Database::fetch_array($res_link))
  5907. {
  5908. $return .= '<div class="lp_resource_element">';
  5909. $return .= '<img align="left" alt="" src="../img/file_html_small.gif" style="margin-right:5px;" title="" />';
  5910. $return .= '<a href="' .api_get_self(). '?cidReq=' . $_GET['cidReq'] . '&amp;action=add_item&amp;type=' . TOOL_LINK . '&amp;file=' . $row_link['id'] . '&amp;lp_id=' . $this->lp_id . '">' . $row_link['title'] . '</a>';
  5911. $return .= '</div>';
  5912. }
  5913. $return .= '<div class="lp_resource_element">';
  5914. $return .= '<img align="left" alt="" src="../img/file_html_new_small.gif" style="margin-right:5px;" title="" />';
  5915. $return .= '<a href="'.api_get_path(REL_CODE_PATH).'link/link.php?'.api_get_cidreq().'&action=addlink" title="' . get_lang('LinkAdd') . '">' . get_lang('LinkAdd') . '</a>';
  5916. $return .= '</div>';
  5917. if(Database::num_rows($res_link) == 0)
  5918. $return .= '<div class="lp_resource_element">'.get_lang("NoLinksAvailable").'</div>';
  5919. $return .= '</div>';
  5920. return $return;
  5921. }
  5922. /**
  5923. * Creates a list with all the student publications in it
  5924. *
  5925. * @return unknown
  5926. */
  5927. function get_student_publications()
  5928. {
  5929. $tbl_student = Database::get_course_table(TABLE_STUDENT_PUBLICATION);
  5930. $sql_student = "
  5931. SELECT *
  5932. FROM " . $tbl_student . "
  5933. ORDER BY title ASC";
  5934. $res_student = api_sql_query($sql_student, __FILE__, __LINE__);
  5935. $return .= '<div class="lp_resource_header"' . " onclick=\"if(document.getElementById('resStudent').style.display == 'block') {document.getElementById('resStudent').style.display = 'none';} else {document.getElementById('resStudent').style.display = 'block';}\"" . ' style="border-bottom:1px solid #999999; cursor:pointer;"><img align="left" alt="" src="../img/lp_' . TOOL_STUDENTPUBLICATION . '.gif" style="margin-right:5px;" title="" />'.get_lang('Student_publication').'</div>';
  5936. $return .= '<div class="lp_resource_elements" id="resStudent" style="border-bottom:1px solid #999999; border-top:0;">';
  5937. $return .= '<div class="lp_resource_element">';
  5938. $return .= '<img align="left" alt="" src="../img/works_small.gif" style="margin-right:5px;" title="" />';
  5939. $return .= '<a href="' .api_get_self(). '?cidReq=' . $_GET['cidReq'] . '&amp;action=add_item&amp;type=' . TOOL_STUDENTPUBLICATION . '&amp;lp_id=' . $this->lp_id . '">' . get_lang('AddAssignmentPage') . '</a>';
  5940. $return .= '</div>';
  5941. $return .= '</div>';
  5942. return $return;
  5943. }
  5944. function get_forums()
  5945. {
  5946. include ('../forum/forumfunction.inc.php');
  5947. include ('../forum/forumconfig.inc.php');
  5948. global $table_forums, $table_threads,$table_posts, $table_item_property, $table_users;
  5949. $table_forums = Database :: get_course_table(TABLE_FORUM);
  5950. $table_threads = Database :: get_course_table(TABLE_FORUM_THREAD);
  5951. $table_posts = Database :: get_course_table(TABLE_FORUM_POST);
  5952. $table_item_property = Database :: get_course_table(TABLE_ITEM_PROPERTY);
  5953. $table_users = Database :: get_main_table(TABLE_MAIN_USER);
  5954. $a_forums = get_forums();
  5955. $return .= '<div class="lp_resource_header"' . " onclick=\"if(document.getElementById('forums').style.display == 'block') {document.getElementById('forums').style.display = 'none';} else {document.getElementById('forums').style.display = 'block';}\"" . ' style="border-bottom:1px solid #999999; cursor:pointer;"><img align="left" alt="" src="../img/lp_forum.gif" style="margin-right:5px;" title="" />'.get_lang('Forums').'</div>';
  5956. $return .= '<div class="lp_resource_elements" id="forums" style="border-bottom:1px solid #999999; border-top:0;">';
  5957. foreach($a_forums as $forum)
  5958. {
  5959. $return .= '<div class="lp_resource_element">';
  5960. $return .= '<script type="text/javascript">
  5961. function toggle_forum(forum_id){
  5962. if(document.getElementById("forum_"+forum_id+"_content").style.display == "none"){
  5963. document.getElementById("forum_"+forum_id+"_content").style.display = "block";
  5964. document.getElementById("forum_"+forum_id+"_opener").src = "'.api_get_path(WEB_IMG_PATH).'remove.gif";
  5965. }
  5966. else {
  5967. document.getElementById("forum_"+forum_id+"_content").style.display = "none";
  5968. document.getElementById("forum_"+forum_id+"_opener").src = "'.api_get_path(WEB_IMG_PATH).'add.gif";
  5969. }
  5970. }
  5971. </script>
  5972. ';
  5973. $return .= '<img align="left" alt="" src="../img/lp_forum.gif" style="margin-right:5px;" title="" />';
  5974. $return .= '<a style="cursor:hand" onclick="toggle_forum('.$forum['forum_id'].')" style="vertical-align:middle"><img src="'.api_get_path(WEB_IMG_PATH).'add.gif" id="forum_'.$forum['forum_id'].'_opener" align="absbottom" /></a>
  5975. <a href="' .api_get_self(). '?cidReq=' . $_GET['cidReq'] . '&amp;action=add_item&amp;type=' . TOOL_FORUM . '&amp;forum_id=' . $forum['forum_id'] . '&amp;lp_id=' . $this->lp_id . '" style="vertical-align:middle">' . $forum['forum_title'] . '</a><ul style="display:none" id="forum_'.$forum['forum_id'].'_content">';
  5976. $a_threads = get_threads($forum['forum_id']);
  5977. if(is_array($a_threads)){
  5978. foreach($a_threads as $thread)
  5979. {
  5980. $return .= '<li><a href="' .api_get_self(). '?cidReq=' . $_GET['cidReq'] . '&amp;action=add_item&amp;type=' . TOOL_THREAD . '&amp;thread_id=' . $thread['thread_id'] . '&amp;lp_id=' . $this->lp_id . '">' . $thread['thread_title'] . '</a></li>';
  5981. }
  5982. }
  5983. $return .= '</ul></div>';
  5984. }
  5985. $return .= '<div class="lp_resource_element">';
  5986. $return .= '<img align="left" alt="" src="../img/forum_new_small.gif" style="margin-right:5px;" title="" />';
  5987. $return .= '<a href="'.api_get_path(REL_CODE_PATH).'forum/index.php?'.api_get_cidreq().'&action=add&amp;content=forum" title="'.get_lang('CreateANewForum').'">'.get_lang('CreateANewForum').'</a>';
  5988. $return .= '</div>';
  5989. return $return;
  5990. }
  5991. /**
  5992. * Exports the learning path as a SCORM package. This is the main function that
  5993. * gathers the content, transforms it, writes the imsmanifest.xml file, zips the
  5994. * whole thing and returns the zip.
  5995. *
  5996. * This method needs to be called in PHP5, as it will fail with non-adequate
  5997. * XML package (like the ones for PHP4), and it is *not* a static method, so
  5998. * you need to call it on a learnpath object.
  5999. * @TODO The method might be redefined later on in the scorm class itself to avoid
  6000. * creating a SCORM structure if there is one already. However, if the initial SCORM
  6001. * path has been modified, it should use the generic method here below.
  6002. * @TODO link this function with the export_lp() function in the same class
  6003. * @param string Optional name of zip file. If none, title of learnpath is
  6004. * domesticated and trailed with ".zip"
  6005. * @return string Returns the zip package string, or null if error
  6006. */
  6007. function scorm_export()
  6008. {
  6009. global $_course;
  6010. if (!class_exists('DomDocument'))
  6011. {
  6012. error_log('DOM functions not supported for PHP version below 5.0',0);
  6013. $this->error = 'PHP DOM functions not supported for PHP versions below 5.0';
  6014. return null;
  6015. }
  6016. //remove memory and time limits as much as possible as this might be a long process...
  6017. if(function_exists('ini_set'))
  6018. {
  6019. $mem = ini_get('memory_limit');
  6020. if(substr($mem,-1,1)=='M')
  6021. {
  6022. $mem_num = substr($mem,0,-1);
  6023. if($mem_num<128)
  6024. {
  6025. ini_set('memory_limit','128M');
  6026. }
  6027. }
  6028. else
  6029. {
  6030. ini_set('memory_limit','128M');
  6031. }
  6032. ini_set('max_execution_time',600);
  6033. //}else{
  6034. //error_log('Scorm export: could not change memory and time limits',0);
  6035. }
  6036. //Create the zip handler (this will remain available throughout the method)
  6037. $garbage_path = api_get_path(GARBAGE_PATH);
  6038. $sys_course_path = api_get_path(SYS_COURSE_PATH);
  6039. $temp_dir_short = uniqid();
  6040. $temp_zip_dir = $garbage_path."/".$temp_dir_short;
  6041. $temp_zip_file = $temp_zip_dir."/".md5(time()).".zip";
  6042. $zip_folder=new PclZip($temp_zip_file);
  6043. $current_course_path = api_get_path(SYS_COURSE_PATH).api_get_course_path();
  6044. $root_path = $main_path = api_get_path(SYS_PATH);
  6045. $files_cleanup = array();
  6046. //place to temporarily stash the zipfiles
  6047. //create the temp dir if it doesn't exist
  6048. //or do a cleanup befor creating the zipfile
  6049. if(!is_dir($temp_zip_dir))
  6050. {
  6051. mkdir($temp_zip_dir);
  6052. }
  6053. else
  6054. {//cleanup: check the temp dir for old files and delete them
  6055. $handle=opendir($temp_zip_dir);
  6056. while (false!==($file = readdir($handle)))
  6057. {
  6058. if ($file != "." && $file != "..")
  6059. {
  6060. unlink("$temp_zip_dir/$file");
  6061. }
  6062. }
  6063. closedir($handle);
  6064. }
  6065. $zip_files = $zip_files_abs = $zip_files_dist = array();
  6066. if(is_dir($current_course_path.'/scorm/'.$this->path) && is_file($current_course_path.'/scorm/'.$this->path.'/imsmanifest.xml'))
  6067. {
  6068. // remove the possible . at the end of the path
  6069. $dest_path_to_lp = substr($this->path, -1) == '.' ? substr($this->path, 0, -1) : $this->path;
  6070. $dest_path_to_scorm_folder = str_replace('//','/',$temp_zip_dir.'/scorm/'.$dest_path_to_lp);
  6071. $perm = api_get_setting('permissions_for_new_directories');
  6072. $perm = octdec(!empty($perm)?$perm:'0770');
  6073. mkdir ($dest_path_to_scorm_folder, $perm, true);
  6074. $zip_files_dist = copyr($current_course_path.'/scorm/'.$this->path, $dest_path_to_scorm_folder, array('imsmanifest'), $zip_files);
  6075. }
  6076. //Build a dummy imsmanifest structure. Do not add to the zip yet (we still need it)
  6077. //This structure is developed following regulations for SCORM 1.2 packaging in the SCORM 1.2 Content
  6078. //Aggregation Model official document, secion "2.3 Content Packaging"
  6079. $xmldoc = new DOMDocument('1.0',$this->encoding);
  6080. $root = $xmldoc->createElement('manifest');
  6081. $root->setAttribute('identifier','SingleCourseManifest');
  6082. $root->setAttribute('version','1.1');
  6083. $root->setAttribute('xmlns','http://www.imsproject.org/xsd/imscp_rootv1p1p2');
  6084. $root->setAttribute('xmlns:adlcp','http://www.adlnet.org/xsd/adlcp_rootv1p2');
  6085. $root->setAttribute('xmlns:xsi','http://www.w3.org/2001/XMLSchema-instance');
  6086. $root->setAttribute('xsi:schemaLocation','http://www.imsproject.org/xsd/imscp_rootv1p1p2 imscp_rootv1p1p2.xsd
  6087. http://www.imsglobal.org/xsd/imsmd_rootv1p2p1 imsmd_rootv1p2p1.xsd
  6088. http://www.adlnet.org/xsd/adlcp_rootv1p2 adlcp_rootv1p2.xsd');
  6089. //Build mandatory sub-root container elements
  6090. $metadata = $xmldoc->createElement('metadata');
  6091. $md_schema = $xmldoc->createElement('schema','ADL SCORM');
  6092. $metadata->appendChild($md_schema);
  6093. $md_schemaversion = $xmldoc->createElement('schemaversion','1.2');
  6094. $metadata->appendChild($md_schemaversion);
  6095. $root->appendChild($metadata);
  6096. $organizations = $xmldoc->createElement('organizations');
  6097. $resources = $xmldoc->createElement('resources');
  6098. //Build the only organization we will use in building our learnpaths
  6099. $organizations->setAttribute('default','dokeos_scorm_export');
  6100. $organization = $xmldoc->createElement('organization');
  6101. $organization->setAttribute('identifier','dokeos_scorm_export');
  6102. //to set the title of the SCORM entity (=organization), we take the name given
  6103. //in Dokeos and convert it to HTML entities using the Dokeos charset (not the
  6104. //learning path charset) as it is the encoding that defines how it is stored
  6105. //in the database. Then we convert it to HTML entities again as the "&" character
  6106. //alone is not authorized in XML (must be &amp;)
  6107. //The title is then decoded twice when extracting (see scorm::parse_manifest)
  6108. global $charset;
  6109. $org_title = $xmldoc->createElement('title',htmlentities(htmlentities($this->get_name(),ENT_QUOTES,$charset)));
  6110. $organization->appendChild($org_title);
  6111. //For each element, add it to the imsmanifest structure, then add it to the zip.
  6112. //Always call the learnpathItem->scorm_export() method to change it to the SCORM
  6113. //format
  6114. $link_updates = array();
  6115. foreach($this->items as $index => $item){
  6116. if(!in_array($item->type , array(TOOL_QUIZ, TOOL_FORUM, TOOL_THREAD, TOOL_LINK, TOOL_STUDENTPUBLICATION)))
  6117. {
  6118. //get included documents from this item
  6119. if($item->type=='sco')
  6120. $inc_docs = $item->get_resources_from_source(null,api_get_path(SYS_COURSE_PATH).api_get_course_path().'/'.'scorm/'.$this->path.'/'.$item->get_path());
  6121. else
  6122. $inc_docs = $item->get_resources_from_source();
  6123. //give a child element <item> to the <organization> element
  6124. $my_item_id = $item->get_id();
  6125. $my_item = $xmldoc->createElement('item');
  6126. $my_item->setAttribute('identifier','ITEM_'.$my_item_id);
  6127. $my_item->setAttribute('identifierref','RESOURCE_'.$my_item_id);
  6128. $my_item->setAttribute('isvisible','true');
  6129. //give a child element <title> to the <item> element
  6130. $my_title = $xmldoc->createElement('title',htmlspecialchars($item->get_title(),ENT_QUOTES));
  6131. $my_item->appendChild($my_title);
  6132. //give a child element <adlcp:prerequisites> to the <item> element
  6133. $my_prereqs = $xmldoc->createElement('adlcp:prerequisites',$this->get_scorm_prereq_string($my_item_id));
  6134. $my_prereqs->setAttribute('type','aicc_script');
  6135. $my_item->appendChild($my_prereqs);
  6136. //give a child element <adlcp:maxtimeallowed> to the <item> element - not yet supported
  6137. //$xmldoc->createElement('adlcp:maxtimeallowed','');
  6138. //give a child element <adlcp:timelimitaction> to the <item> element - not yet supported
  6139. //$xmldoc->createElement('adlcp:timelimitaction','');
  6140. //give a child element <adlcp:datafromlms> to the <item> element - not yet supported
  6141. //$xmldoc->createElement('adlcp:datafromlms','');
  6142. //give a child element <adlcp:masteryscore> to the <item> element
  6143. $my_masteryscore = $xmldoc->createElement('adlcp:masteryscore',$item->masteryscore);
  6144. $my_item->appendChild($my_masteryscore);
  6145. //attach this item to the organization element or hits parent if there is one
  6146. if(!empty($item->parent) && $item->parent!=0)
  6147. {
  6148. $children = $organization->childNodes;
  6149. $possible_parent = &$this->get_scorm_xml_node($children,'ITEM_'.$item->parent);
  6150. if(is_object($possible_parent))
  6151. {
  6152. $possible_parent->appendChild($my_item);
  6153. }
  6154. else
  6155. {
  6156. if($this->debug>0){error_log('Parent ITEM_'.$item->parent.' of item ITEM_'.$my_item_id.' not found');}
  6157. }
  6158. }
  6159. else
  6160. {
  6161. if($this->debug>0){error_log('No parent');}
  6162. $organization->appendChild($my_item);
  6163. }
  6164. //get the path of the file(s) from the course directory root
  6165. $my_file_path = $item->get_file_path('scorm/'.$this->path.'/');
  6166. $my_xml_file_path = htmlentities($my_file_path);
  6167. $my_sub_dir = dirname($my_file_path);
  6168. $my_xml_sub_dir = htmlentities($my_sub_dir);
  6169. //give a <resource> child to the <resources> element
  6170. $my_resource = $xmldoc->createElement('resource');
  6171. $my_resource->setAttribute('identifier','RESOURCE_'.$item->get_id());
  6172. $my_resource->setAttribute('type','webcontent');
  6173. $my_resource->setAttribute('href',$my_xml_file_path);
  6174. //adlcp:scormtype can be either 'sco' or 'asset'
  6175. if($item->type=='sco')
  6176. {
  6177. $my_resource->setAttribute('adlcp:scormtype','sco');
  6178. }
  6179. else
  6180. {
  6181. $my_resource->setAttribute('adlcp:scormtype','asset');
  6182. }
  6183. //xml:base is the base directory to find the files declared in this resource
  6184. $my_resource->setAttribute('xml:base','');
  6185. //give a <file> child to the <resource> element
  6186. $my_file = $xmldoc->createElement('file');
  6187. $my_file->setAttribute('href',$my_xml_file_path);
  6188. $my_resource->appendChild($my_file);
  6189. //dependency to other files - not yet supported
  6190. $i = 1;
  6191. foreach($inc_docs as $doc_info)
  6192. {
  6193. if(count($doc_info)<1 or empty($doc_info[0])){continue;}
  6194. $my_dep = $xmldoc->createElement('resource');
  6195. $res_id = 'RESOURCE_'.$item->get_id().'_'.$i;
  6196. $my_dep->setAttribute('identifier',$res_id);
  6197. $my_dep->setAttribute('type','webcontent');
  6198. $my_dep->setAttribute('adlcp:scormtype','asset');
  6199. $my_dep_file = $xmldoc->createElement('file');
  6200. //check type of URL
  6201. //error_log('Now dealing with '.$doc_info[0].' of type '.$doc_info[1].'-'.$doc_info[2],0);
  6202. if($doc_info[1] == 'remote')
  6203. { //remote file. Save url as is
  6204. $my_dep_file->setAttribute('href',$doc_info[0]);
  6205. $my_dep->setAttribute('xml:base','');
  6206. }elseif($doc_info[1] == 'local'){
  6207. switch($doc_info[2])
  6208. {
  6209. case 'url': //local URL - save path as url for now, don't zip file
  6210. $abs_path = api_get_path(SYS_PATH).str_replace(api_get_path(WEB_PATH),'',$doc_info[0]);
  6211. $current_dir = dirname($abs_path);
  6212. $file_path = realpath($abs_path);
  6213. $my_dep_file->setAttribute('href',$file_path);
  6214. $my_dep->setAttribute('xml:base','');
  6215. if(strstr($file_path,$main_path) !== false)
  6216. {//the calculated real path is really inside the dokeos root path
  6217. //reduce file path to what's under the DocumentRoot
  6218. $file_path = substr($file_path,strlen($root_path));
  6219. //echo $file_path;echo '<br><br>';
  6220. //error_log('Reduced path: '.$file_path,0);
  6221. $zip_files_abs[] = $file_path;
  6222. $link_updates[$my_file_path][] = array('orig'=>$doc_info[0],'dest'=>$file_path);
  6223. $my_dep_file->setAttribute('href',$file_path);
  6224. $my_dep->setAttribute('xml:base','');
  6225. }
  6226. else if (empty($file_path))
  6227. {
  6228. /*$document_root = substr(api_get_path(SYS_PATH), 0, strpos(api_get_path(SYS_PATH),api_get_path(REL_PATH)));
  6229. if(strpos($document_root,-1)=='/')
  6230. {
  6231. $document_root = substr(0, -1, $document_root);
  6232. }*/
  6233. $file_path = $_SERVER['DOCUMENT_ROOT'].$abs_path;
  6234. $file_path = str_replace('//','/',$file_path);
  6235. if(file_exists($file_path))
  6236. {
  6237. $file_path = substr($file_path,strlen($current_dir)); // we get the relative path
  6238. $zip_files[] = $my_sub_dir.'/'.$file_path;
  6239. $link_updates[$my_file_path][] = array('orig'=>$doc_info[0],'dest'=>$file_path);
  6240. $my_dep_file->setAttribute('href',$file_path);
  6241. $my_dep->setAttribute('xml:base','');
  6242. }
  6243. }
  6244. break;
  6245. case 'abs': //absolute path from DocumentRoot. Save file and leave path as is in the zip
  6246. $my_dep_file->setAttribute('href',$doc_info[0]);
  6247. $my_dep->setAttribute('xml:base','');
  6248. //$current_dir = dirname($current_course_path.'/'.$item->get_file_path()).'/';
  6249. $file_path = realpath(api_get_path(SYS_PATH).$doc_info[0]);
  6250. $file_path = str_replace('//','/',$file_path);
  6251. //prepare the current directory path (until just under 'document') with a trailing slash
  6252. $cur_path = substr($current_course_path,-1)=='/'?$current_course_path:$current_course_path.'/';
  6253. //check if the current document is in that path
  6254. if(strstr($file_path,$cur_path) !== false)
  6255. {
  6256. //the document is in that path, now get the relative path
  6257. //to the containing document
  6258. $orig_file_path = dirname($cur_path.$my_file_path).'/';
  6259. $relative_path ='';
  6260. if(strstr($file_path,$cur_path)!==false)
  6261. {
  6262. $relative_path = substr($file_path,strlen($orig_file_path));
  6263. $file_path = substr($file_path,strlen($cur_path));
  6264. }
  6265. else
  6266. {
  6267. //this case is still a problem as it's difficult to calculate a relative path easily
  6268. //might still generate wrong links
  6269. //$file_path = substr($file_path,strlen($cur_path));
  6270. //calculate the directory path to the current file (without trailing slash)
  6271. $my_relative_path = dirname($file_path);
  6272. $my_relative_file = basename($file_path);
  6273. //calculate the directory path to the containing file (without trailing slash)
  6274. $my_orig_file_path = substr($orig_file_path,0,-1);
  6275. $dotdot = '';
  6276. $subdir = '';
  6277. while(strstr($my_relative_path,$my_orig_file_path)===false && (strlen($my_orig_file_path)>1) && (strlen($my_relative_path)>1))
  6278. {
  6279. $my_relative_path2 = dirname($my_relative_path);
  6280. $my_orig_file_path = dirname($my_orig_file_path);
  6281. $subdir = substr($my_relative_path,strlen($my_relative_path2)+1)."/".$subdir;
  6282. $dotdot += '../';
  6283. $my_relative_path = $my_relative_path2;
  6284. }
  6285. $relative_path = $dotdot.$subdir.$my_relative_file;
  6286. }
  6287. //put the current document in the zip (this array is the array
  6288. //that will manage documents already in the course folder - relative)
  6289. $zip_files[] = $file_path;
  6290. //update the links to the current document in the containing document (make them relative)
  6291. $link_updates[$my_file_path][] = array('orig'=>$doc_info[0],'dest'=>$relative_path);
  6292. $my_dep_file->setAttribute('href',$file_path);
  6293. $my_dep->setAttribute('xml:base','');
  6294. }
  6295. elseif(strstr($file_path,$main_path) !== false)
  6296. {//the calculated real path is really inside the dokeos root path
  6297. //reduce file path to what's under the DocumentRoot
  6298. $file_path = substr($file_path,strlen($root_path));
  6299. //echo $file_path;echo '<br><br>';
  6300. //error_log('Reduced path: '.$file_path,0);
  6301. $zip_files_abs[] = $file_path;
  6302. $link_updates[$my_file_path][] = array('orig'=>$doc_info[0],'dest'=>$file_path);
  6303. $my_dep_file->setAttribute('href','document/'.$file_path);
  6304. $my_dep->setAttribute('xml:base','');
  6305. }
  6306. else if (empty($file_path))
  6307. {
  6308. /*$document_root = substr(api_get_path(SYS_PATH), 0, strpos(api_get_path(SYS_PATH),api_get_path(REL_PATH)));
  6309. if(strpos($document_root,-1)=='/')
  6310. {
  6311. $document_root = substr(0, -1, $document_root);
  6312. }*/
  6313. $file_path = $_SERVER['DOCUMENT_ROOT'].$doc_info[0];
  6314. $file_path = str_replace('//','/',$file_path);
  6315. if(file_exists($file_path))
  6316. {
  6317. $file_path = substr($file_path,strlen($current_dir)); // we get the relative path
  6318. $zip_files[] = $my_sub_dir.'/'.$file_path;
  6319. $link_updates[$my_file_path][] = array('orig'=>$doc_info[0],'dest'=>$file_path);
  6320. $my_dep_file->setAttribute('href','document/'.$file_path);
  6321. $my_dep->setAttribute('xml:base','');
  6322. }
  6323. }
  6324. break;
  6325. case 'rel': //path relative to the current document. Save xml:base as current document's directory and save file in zip as subdir.file_path
  6326. if(substr($doc_info[0],0,2)=='..')
  6327. { //relative path going up
  6328. $current_dir = dirname($current_course_path.'/'.$item->get_file_path()).'/';
  6329. $file_path = realpath($current_dir.$doc_info[0]);
  6330. //error_log($file_path.' <-> '.$main_path,0);
  6331. if(strstr($file_path,$main_path) !== false)
  6332. {//the calculated real path is really inside the dokeos root path
  6333. //reduce file path to what's under the DocumentRoot
  6334. $file_path = substr($file_path,strlen($root_path));
  6335. //error_log('Reduced path: '.$file_path,0);
  6336. $zip_files_abs[] = $file_path;
  6337. $link_updates[$my_file_path][] = array('orig'=>$doc_info[0],'dest'=>$file_path);
  6338. $my_dep_file->setAttribute('href','document/'.$file_path);
  6339. $my_dep->setAttribute('xml:base','');
  6340. }
  6341. }else{
  6342. $zip_files[] = $my_sub_dir.'/'.$doc_info[0];
  6343. $my_dep_file->setAttribute('href',$doc_info[0]);
  6344. $my_dep->setAttribute('xml:base',$my_xml_sub_dir);
  6345. }
  6346. break;
  6347. default:
  6348. $my_dep_file->setAttribute('href',$doc_info[0]);
  6349. $my_dep->setAttribute('xml:base','');
  6350. break;
  6351. }
  6352. }
  6353. $my_dep->appendChild($my_dep_file);
  6354. $resources->appendChild($my_dep);
  6355. $dependency = $xmldoc->createElement('dependency');
  6356. $dependency->setAttribute('identifierref',$res_id);
  6357. $my_resource->appendChild($dependency);
  6358. $i++;
  6359. }
  6360. //$my_dependency = $xmldoc->createElement('dependency');
  6361. //$my_dependency->setAttribute('identifierref','');
  6362. $resources->appendChild($my_resource);
  6363. $zip_files[] = $my_file_path;
  6364. //error_log('File '.$my_file_path. ' added to $zip_files',0);
  6365. }
  6366. else
  6367. { // if the item is a quiz or a link or whatever non-exportable, we include a step indicating it
  6368. if($item->type == TOOL_LINK)
  6369. {
  6370. $my_item = $xmldoc->createElement('item');
  6371. $my_item->setAttribute('identifier','ITEM_'.$item->get_id());
  6372. $my_item->setAttribute('identifierref','RESOURCE_'.$item->get_id());
  6373. $my_item->setAttribute('isvisible','true');
  6374. //give a child element <title> to the <item> element
  6375. $my_title = $xmldoc->createElement('title',htmlspecialchars($item->get_title(),ENT_QUOTES));
  6376. $my_item->appendChild($my_title);
  6377. //give a child element <adlcp:prerequisites> to the <item> element
  6378. $my_prereqs = $xmldoc->createElement('adlcp:prerequisites',$item->get_prereq_string());
  6379. $my_prereqs->setAttribute('type','aicc_script');
  6380. $my_item->appendChild($my_prereqs);
  6381. //give a child element <adlcp:maxtimeallowed> to the <item> element - not yet supported
  6382. //$xmldoc->createElement('adlcp:maxtimeallowed','');
  6383. //give a child element <adlcp:timelimitaction> to the <item> element - not yet supported
  6384. //$xmldoc->createElement('adlcp:timelimitaction','');
  6385. //give a child element <adlcp:datafromlms> to the <item> element - not yet supported
  6386. //$xmldoc->createElement('adlcp:datafromlms','');
  6387. //give a child element <adlcp:masteryscore> to the <item> element
  6388. $my_masteryscore = $xmldoc->createElement('adlcp:masteryscore',$item->masteryscore);
  6389. $my_item->appendChild($my_masteryscore);
  6390. //attach this item to the organization element or its parent if there is one
  6391. if(!empty($item->parent) && $item->parent!=0)
  6392. {
  6393. $children = $organization->childNodes;
  6394. for($i=0;$i<$children->length;$i++){
  6395. $item_temp = $children->item($i);
  6396. if ($item_temp -> nodeName == 'item')
  6397. {
  6398. if($item_temp->getAttribute('identifier') == 'ITEM_'.$item->parent)
  6399. {
  6400. $item_temp -> appendChild($my_item);
  6401. }
  6402. }
  6403. }
  6404. }
  6405. else
  6406. {
  6407. $organization->appendChild($my_item);
  6408. }
  6409. $my_file_path = 'link_'.$item->get_id().'.html';
  6410. $sql = 'SELECT url, title FROM '.Database :: get_course_table(TABLE_LINK).' WHERE id='.$item->path;
  6411. $rs = api_sql_query($sql, __FILE__, __LINE__);
  6412. if($link = Database :: fetch_array($rs))
  6413. {
  6414. $url = $link['url'];
  6415. $title = stripslashes($link['title']);
  6416. $links_to_create[$my_file_path] = array('title'=>$title,'url'=>$url);
  6417. $my_xml_file_path = htmlentities($my_file_path);
  6418. $my_sub_dir = dirname($my_file_path);
  6419. $my_xml_sub_dir = htmlentities($my_sub_dir);
  6420. //give a <resource> child to the <resources> element
  6421. $my_resource = $xmldoc->createElement('resource');
  6422. $my_resource->setAttribute('identifier','RESOURCE_'.$item->get_id());
  6423. $my_resource->setAttribute('type','webcontent');
  6424. $my_resource->setAttribute('href',$my_xml_file_path);
  6425. //adlcp:scormtype can be either 'sco' or 'asset'
  6426. $my_resource->setAttribute('adlcp:scormtype','asset');
  6427. //xml:base is the base directory to find the files declared in this resource
  6428. $my_resource->setAttribute('xml:base','');
  6429. //give a <file> child to the <resource> element
  6430. $my_file = $xmldoc->createElement('file');
  6431. $my_file->setAttribute('href',$my_xml_file_path);
  6432. $my_resource->appendChild($my_file);
  6433. $resources->appendChild($my_resource);
  6434. }
  6435. }
  6436. elseif($item->type == TOOL_QUIZ)
  6437. {
  6438. require_once(api_get_path(SYS_CODE_PATH).'exercice/exercise.class.php');
  6439. $exe_id = $item->path; //should be using ref when everything will be cleaned up in this regard
  6440. $exe = new Exercise();
  6441. $exe->read($exe_id);
  6442. $my_item = $xmldoc->createElement('item');
  6443. $my_item->setAttribute('identifier','ITEM_'.$item->get_id());
  6444. $my_item->setAttribute('identifierref','RESOURCE_'.$item->get_id());
  6445. $my_item->setAttribute('isvisible','true');
  6446. //give a child element <title> to the <item> element
  6447. $my_title = $xmldoc->createElement('title',htmlspecialchars($item->get_title(),ENT_QUOTES));
  6448. $my_item->appendChild($my_title);
  6449. //give a child element <adlcp:prerequisites> to the <item> element
  6450. $my_prereqs = $xmldoc->createElement('adlcp:prerequisites',$item->get_prereq_string());
  6451. $my_prereqs->setAttribute('type','aicc_script');
  6452. $my_item->appendChild($my_prereqs);
  6453. //give a child element <adlcp:masteryscore> to the <item> element
  6454. $my_masteryscore = $xmldoc->createElement('adlcp:masteryscore',$item->masteryscore);
  6455. $my_item->appendChild($my_masteryscore);
  6456. //attach this item to the organization element or hits parent if there is one
  6457. if(!empty($item->parent) && $item->parent!=0)
  6458. {
  6459. $children = $organization->childNodes;
  6460. for($i=0;$i<$children->length;$i++){
  6461. $item_temp = $children->item($i);
  6462. if ($item_temp -> nodeName == 'item')
  6463. {
  6464. if($item_temp->getAttribute('identifier') == 'ITEM_'.$item->parent)
  6465. {
  6466. $item_temp -> appendChild($my_item);
  6467. }
  6468. }
  6469. }
  6470. }
  6471. else
  6472. {
  6473. $organization->appendChild($my_item);
  6474. }
  6475. //include export scripts
  6476. require_once(api_get_path(SYS_CODE_PATH).'exercice/export/scorm/scorm_export.php');
  6477. //get the path of the file(s) from the course directory root
  6478. //$my_file_path = $item->get_file_path('scorm/'.$this->path.'/');
  6479. $my_file_path = 'quiz_'.$item->get_id().'.html';
  6480. //write the contents of the exported exercise into a (big) html file
  6481. //to later pack it into the exported SCORM. The file will be removed afterwards
  6482. $contents = export_exercise($exe_id,true);
  6483. $tmp_file_path = $garbage_path.$temp_dir_short.'/'.$my_file_path;
  6484. $res = file_put_contents($tmp_file_path,$contents);
  6485. if($res === false){error_log('Could not write into file '.$tmp_file_path.' '.__FILE__.' '.__LINE__,0);}
  6486. $files_cleanup[] = $tmp_file_path;
  6487. //error_log($tmp_path);die();
  6488. $my_xml_file_path = htmlentities($my_file_path);
  6489. $my_sub_dir = dirname($my_file_path);
  6490. $my_xml_sub_dir = htmlentities($my_sub_dir);
  6491. //give a <resource> child to the <resources> element
  6492. $my_resource = $xmldoc->createElement('resource');
  6493. $my_resource->setAttribute('identifier','RESOURCE_'.$item->get_id());
  6494. $my_resource->setAttribute('type','webcontent');
  6495. $my_resource->setAttribute('href',$my_xml_file_path);
  6496. //adlcp:scormtype can be either 'sco' or 'asset'
  6497. $my_resource->setAttribute('adlcp:scormtype','sco');
  6498. //xml:base is the base directory to find the files declared in this resource
  6499. $my_resource->setAttribute('xml:base','');
  6500. //give a <file> child to the <resource> element
  6501. $my_file = $xmldoc->createElement('file');
  6502. $my_file->setAttribute('href',$my_xml_file_path);
  6503. $my_resource->appendChild($my_file);
  6504. //get included docs
  6505. $inc_docs = $item->get_resources_from_source(null,$tmp_file_path);
  6506. //dependency to other files - not yet supported
  6507. $i = 1;
  6508. foreach($inc_docs as $doc_info)
  6509. {
  6510. if(count($doc_info)<1 or empty($doc_info[0])){continue;}
  6511. $my_dep = $xmldoc->createElement('resource');
  6512. $res_id = 'RESOURCE_'.$item->get_id().'_'.$i;
  6513. $my_dep->setAttribute('identifier',$res_id);
  6514. $my_dep->setAttribute('type','webcontent');
  6515. $my_dep->setAttribute('adlcp:scormtype','asset');
  6516. $my_dep_file = $xmldoc->createElement('file');
  6517. //check type of URL
  6518. //error_log('Now dealing with '.$doc_info[0].' of type '.$doc_info[1].'-'.$doc_info[2],0);
  6519. if($doc_info[1] == 'remote')
  6520. { //remote file. Save url as is
  6521. $my_dep_file->setAttribute('href',$doc_info[0]);
  6522. $my_dep->setAttribute('xml:base','');
  6523. }elseif($doc_info[1] == 'local'){
  6524. switch($doc_info[2])
  6525. {
  6526. case 'url': //local URL - save path as url for now, don't zip file
  6527. //save file but as local file (retrieve from URL)
  6528. $abs_path = api_get_path(SYS_PATH).str_replace(api_get_path(WEB_PATH),'',$doc_info[0]);
  6529. $current_dir = dirname($abs_path);
  6530. $file_path = realpath($abs_path);
  6531. $my_dep_file->setAttribute('href','document/'.$file_path);
  6532. $my_dep->setAttribute('xml:base','');
  6533. if(strstr($file_path,$main_path) !== false)
  6534. {//the calculated real path is really inside the dokeos root path
  6535. //reduce file path to what's under the DocumentRoot
  6536. $file_path = substr($file_path,strlen($root_path));
  6537. //echo $file_path;echo '<br><br>';
  6538. //error_log('Reduced path: '.$file_path,0);
  6539. $zip_files_abs[] = $file_path;
  6540. $link_updates[$my_file_path][] = array('orig'=>$doc_info[0],'dest'=>'document/'.$file_path);
  6541. $my_dep_file->setAttribute('href','document/'.$file_path);
  6542. $my_dep->setAttribute('xml:base','');
  6543. }
  6544. else if (empty($file_path))
  6545. {
  6546. /*$document_root = substr(api_get_path(SYS_PATH), 0, strpos(api_get_path(SYS_PATH),api_get_path(REL_PATH)));
  6547. if(strpos($document_root,-1)=='/')
  6548. {
  6549. $document_root = substr(0, -1, $document_root);
  6550. }*/
  6551. $file_path = $_SERVER['DOCUMENT_ROOT'].$abs_path;
  6552. $file_path = str_replace('//','/',$file_path);
  6553. if(file_exists($file_path))
  6554. {
  6555. $file_path = substr($file_path,strlen($current_dir)); // we get the relative path
  6556. $zip_files[] = $my_sub_dir.'/'.$file_path;
  6557. $link_updates[$my_file_path][] = array('orig'=>$doc_info[0],'dest'=>'document/'.$file_path);
  6558. $my_dep_file->setAttribute('href','document/'.$file_path);
  6559. $my_dep->setAttribute('xml:base','');
  6560. }
  6561. }
  6562. break;
  6563. case 'abs': //absolute path from DocumentRoot. Save file and leave path as is in the zip
  6564. $current_dir = dirname($current_course_path.'/'.$item->get_file_path()).'/';
  6565. $file_path = realpath($doc_info[0]);
  6566. $my_dep_file->setAttribute('href',$file_path);
  6567. $my_dep->setAttribute('xml:base','');
  6568. if(strstr($file_path,$main_path) !== false)
  6569. {//the calculated real path is really inside the dokeos root path
  6570. //reduce file path to what's under the DocumentRoot
  6571. $file_path = substr($file_path,strlen($root_path));
  6572. //echo $file_path;echo '<br><br>';
  6573. //error_log('Reduced path: '.$file_path,0);
  6574. $zip_files_abs[] = $file_path;
  6575. $link_updates[$my_file_path][] = array('orig'=>$doc_info[0],'dest'=>$file_path);
  6576. $my_dep_file->setAttribute('href','document/'.$file_path);
  6577. $my_dep->setAttribute('xml:base','');
  6578. }
  6579. else if (empty($file_path))
  6580. {
  6581. /*$document_root = substr(api_get_path(SYS_PATH), 0, strpos(api_get_path(SYS_PATH),api_get_path(REL_PATH)));
  6582. if(strpos($document_root,-1)=='/')
  6583. {
  6584. $document_root = substr(0, -1, $document_root);
  6585. }*/
  6586. $file_path = $_SERVER['DOCUMENT_ROOT'].$doc_info[0];
  6587. $file_path = str_replace('//','/',$file_path);
  6588. if(file_exists($file_path))
  6589. {
  6590. $file_path = substr($file_path,strlen($current_dir)); // we get the relative path
  6591. $zip_files[] = $my_sub_dir.'/'.$file_path;
  6592. $link_updates[$my_file_path][] = array('orig'=>$doc_info[0],'dest'=>$file_path);
  6593. $my_dep_file->setAttribute('href','document/'.$file_path);
  6594. $my_dep->setAttribute('xml:base','');
  6595. }
  6596. }
  6597. break;
  6598. case 'rel': //path relative to the current document. Save xml:base as current document's directory and save file in zip as subdir.file_path
  6599. if(substr($doc_info[0],0,2)=='..')
  6600. { //relative path going up
  6601. $current_dir = dirname($current_course_path.'/'.$item->get_file_path()).'/';
  6602. $file_path = realpath($current_dir.$doc_info[0]);
  6603. //error_log($file_path.' <-> '.$main_path,0);
  6604. if(strstr($file_path,$main_path) !== false)
  6605. {//the calculated real path is really inside the dokeos root path
  6606. //reduce file path to what's under the DocumentRoot
  6607. $file_path = substr($file_path,strlen($root_path));
  6608. //error_log('Reduced path: '.$file_path,0);
  6609. $zip_files_abs[] = $file_path;
  6610. $link_updates[$my_file_path][] = array('orig'=>$doc_info[0],'dest'=>$file_path);
  6611. $my_dep_file->setAttribute('href','document/'.$file_path);
  6612. $my_dep->setAttribute('xml:base','');
  6613. }
  6614. }else{
  6615. $zip_files[] = $my_sub_dir.'/'.$doc_info[0];
  6616. $my_dep_file->setAttribute('href',$doc_info[0]);
  6617. $my_dep->setAttribute('xml:base',$my_xml_sub_dir);
  6618. }
  6619. break;
  6620. default:
  6621. $my_dep_file->setAttribute('href',$doc_info[0]);
  6622. $my_dep->setAttribute('xml:base','');
  6623. break;
  6624. }
  6625. }
  6626. $my_dep->appendChild($my_dep_file);
  6627. $resources->appendChild($my_dep);
  6628. $dependency = $xmldoc->createElement('dependency');
  6629. $dependency->setAttribute('identifierref',$res_id);
  6630. $my_resource->appendChild($dependency);
  6631. $i++;
  6632. }
  6633. $resources->appendChild($my_resource);
  6634. $zip_files[] = $my_file_path;
  6635. }
  6636. else
  6637. {
  6638. //get the path of the file(s) from the course directory root
  6639. $my_file_path = 'non_exportable.html';
  6640. $my_xml_file_path = htmlentities($my_file_path);
  6641. $my_sub_dir = dirname($my_file_path);
  6642. $my_xml_sub_dir = htmlentities($my_sub_dir);
  6643. //give a <resource> child to the <resources> element
  6644. $my_resource = $xmldoc->createElement('resource');
  6645. $my_resource->setAttribute('identifier','RESOURCE_'.$item->get_id());
  6646. $my_resource->setAttribute('type','webcontent');
  6647. $my_resource->setAttribute('href','document/'.$my_xml_file_path);
  6648. //adlcp:scormtype can be either 'sco' or 'asset'
  6649. $my_resource->setAttribute('adlcp:scormtype','asset');
  6650. //xml:base is the base directory to find the files declared in this resource
  6651. $my_resource->setAttribute('xml:base','');
  6652. //give a <file> child to the <resource> element
  6653. $my_file = $xmldoc->createElement('file');
  6654. $my_file->setAttribute('href','document/'.$my_xml_file_path);
  6655. $my_resource->appendChild($my_file);
  6656. $resources->appendChild($my_resource);
  6657. }
  6658. }
  6659. }
  6660. $organizations->appendChild($organization);
  6661. $root->appendChild($organizations);
  6662. $root->appendChild($resources);
  6663. $xmldoc->appendChild($root);
  6664. //todo: add a readme file here, with a short description and a link to the Reload player
  6665. //then add the file to the zip, then destroy the file (this is done automatically)
  6666. // http://www.reload.ac.uk/scormplayer.html - once done, don't forget to close FS#138
  6667. //error_log(print_r($zip_files,true),0);
  6668. foreach($zip_files as $file_path)
  6669. {
  6670. if(empty($file_path)){continue;}
  6671. //error_log('getting document from '.api_get_path('SYS_COURSE_PATH').$_course['path'].'/'.$file_path.' removing '.api_get_path('SYS_COURSE_PATH').$_course['path'].'/',0);
  6672. $dest_file = $garbage_path.$temp_dir_short.'/'.$file_path;
  6673. $this->create_path($dest_file);
  6674. //error_log('copy '.api_get_path('SYS_COURSE_PATH').$_course['path'].'/'.$file_path.' to '.api_get_path('GARBAGE_PATH').$temp_dir_short.'/'.$file_path,0);
  6675. //echo $main_path.$file_path.'<br>';
  6676. @copy($sys_course_path.$_course['path'].'/'.$file_path,$dest_file);
  6677. //check if the file needs a link update
  6678. if(in_array($file_path,array_keys($link_updates))){
  6679. $string = file_get_contents($dest_file);
  6680. unlink($dest_file);
  6681. foreach($link_updates[$file_path] as $old_new)
  6682. {
  6683. //error_log('Replacing '.$old_new['orig'].' by '.$old_new['dest'].' in '.$file_path,0);
  6684. $string = str_replace($old_new['orig'],$old_new['dest'],$string);
  6685. }
  6686. file_put_contents($dest_file,$string);
  6687. }
  6688. }
  6689. foreach($zip_files_abs as $file_path)
  6690. {
  6691. if(empty($file_path)){continue;}
  6692. //error_log('getting document from '.api_get_path('SYS_COURSE_PATH').$_course['path'].'/'.$file_path.' removing '.api_get_path('SYS_COURSE_PATH').$_course['path'].'/',0);
  6693. $dest_file = $garbage_path.$temp_dir_short.'/document/'.$file_path;
  6694. $this->create_path($dest_file);
  6695. //error_log('Created path '.api_get_path('GARBAGE_PATH').$temp_dir_short.'/document/'.$file_path,0);
  6696. //error_log('copy '.api_get_path('SYS_COURSE_PATH').$_course['path'].'/'.$file_path.' to '.api_get_path('GARBAGE_PATH').$temp_dir_short.'/'.$file_path,0);
  6697. //echo $main_path.$file_path.' - '.$dest_file.'<br>';
  6698. copy($main_path.$file_path,$dest_file);
  6699. //check if the file needs a link update
  6700. if(in_array($file_path,array_keys($link_updates))){
  6701. $string = file_get_contents($dest_file);
  6702. unlink($dest_file);
  6703. foreach($link_updates[$file_path] as $old_new)
  6704. {
  6705. //error_log('Replacing '.$old_new['orig'].' by '.$old_new['dest'].' in '.$file_path,0);
  6706. $string = str_replace($old_new['orig'],$old_new['dest'],$string);
  6707. }
  6708. file_put_contents($dest_file,$string);
  6709. }
  6710. }
  6711. if(is_array($links_to_create))
  6712. {
  6713. foreach($links_to_create as $file=>$link)
  6714. {
  6715. $file_content = '<html><body><div style="text-align:center"><a href="'.$link['url'].'">'.$link['title'].'</a></div></body></html>';
  6716. file_put_contents($garbage_path.$temp_dir_short.'/'.$file, $file_content);
  6717. }
  6718. }
  6719. // add non exportable message explanation
  6720. $lang_not_exportable = get_lang('ThisItemIsNotExportable');
  6721. $file_content =
  6722. <<<EOD
  6723. <html>
  6724. <head>
  6725. <style>
  6726. .error-message {
  6727. font-family: arial, verdana, helvetica, sans-serif;
  6728. border-width: 1px;
  6729. border-style: solid;
  6730. left: 50%;
  6731. margin: 10px auto;
  6732. min-height: 30px;
  6733. padding: 5px;
  6734. right: 50%;
  6735. width: 500px;
  6736. background-color: #FFD1D1;
  6737. border-color: #FF0000;
  6738. color: #000;
  6739. }
  6740. </style>
  6741. <body>
  6742. <div class="error-message">
  6743. $lang_not_exportable
  6744. </div>
  6745. </body>
  6746. </html>
  6747. EOD;
  6748. if(!is_dir($garbage_path.$temp_dir_short.'/document'))
  6749. {
  6750. @mkdir($garbage_path.$temp_dir_short.'/document');
  6751. }
  6752. file_put_contents($garbage_path.$temp_dir_short.'/document/non_exportable.html', $file_content);
  6753. //Add the extra files that go along with a SCORM package
  6754. $main_code_path = api_get_path(SYS_CODE_PATH).'newscorm/packaging/';
  6755. $extra_files = scandir($main_code_path);
  6756. foreach($extra_files as $extra_file)
  6757. {
  6758. if(strpos($extra_file,'.')===0) continue;
  6759. else
  6760. {
  6761. $dest_file = $garbage_path.$temp_dir_short.'/'.$extra_file;
  6762. $this->create_path($dest_file);
  6763. copy($main_code_path.$extra_file,$dest_file);
  6764. }
  6765. }
  6766. //Finalize the imsmanifest structure, add to the zip, then return the zip
  6767. $xmldoc->save($garbage_path.'/'.$temp_dir_short.'/imsmanifest.xml');
  6768. $zip_folder->add($garbage_path.'/'.$temp_dir_short, PCLZIP_OPT_REMOVE_PATH, $garbage_path.'/'.$temp_dir_short.'/');
  6769. //clean possible temporary files
  6770. foreach($files_cleanup as $file)
  6771. {
  6772. $res = unlink($file);
  6773. if($res === false){error_log('Could not delete temp file '.$file.' '.__FILE__.' '.__LINE__,0);}
  6774. }
  6775. //Send file to client
  6776. //$name = 'scorm_export_'.$this->lp_id.'.zip';
  6777. require_once(api_get_path(LIBRARY_PATH).'fileUpload.lib.php');
  6778. $name = preg_replace('([^a-zA-Z0-9_\.])','-',html_entity_decode($this->get_name(),ENT_QUOTES)).'.zip';
  6779. DocumentManager::file_send_for_download($temp_zip_file,true,$name);
  6780. }
  6781. /**
  6782. * Temp function to be moved in main_api or the best place around for this. Creates a file path
  6783. * if it doesn't exist
  6784. */
  6785. function create_path($path){
  6786. $path_bits = split('/',dirname($path));
  6787. $path_built = '/';
  6788. foreach($path_bits as $bit){
  6789. if(!empty($bit)){
  6790. $new_path = $path_built.$bit;
  6791. if(is_dir($new_path)){
  6792. $path_built = $new_path.'/';
  6793. }
  6794. else
  6795. {
  6796. mkdir($new_path);
  6797. $path_built = $new_path.'/';
  6798. }
  6799. }
  6800. }
  6801. }
  6802. }
  6803. ?>