learnpath.class.php 296 KB

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