learnpath.class.php 296 KB

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