learnpath.class.php 411 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * This class defines the parent attributes and methods for Chamilo learnpaths and SCORM
  5. * learnpaths. It is used by the scorm class.
  6. *
  7. * @package chamilo.learnpath
  8. * @author Yannick Warnier <ywarnier@beeznest.org>
  9. * @author Julio Montoya <gugli100@gmail.com> Several improvements and fixes
  10. */
  11. /**
  12. * Defines the learnpath parent class
  13. * @package chamilo.learnpath
  14. */
  15. class learnpath {
  16. public $attempt = 0; // The number for the current ID view.
  17. public $cc; // Course (code) this learnpath is located in. @todo change name for something more comprensible ...
  18. public $current; // Id of the current item the user is viewing.
  19. public $current_score; // The score of the current item.
  20. public $current_time_start; // The time the user loaded this resource (this does not mean he can see it yet).
  21. public $current_time_stop; // The time the user closed this resource.
  22. public $default_status = 'not attempted';
  23. public $encoding = 'UTF-8';
  24. public $error = '';
  25. public $extra_information = ''; // This string can be used by proprietary SCORM contents to store data about the current learnpath.
  26. public $force_commit = false; // For SCORM only - if set to true, will send a scorm LMSCommit() request on each LMSSetValue().
  27. public $index; // The index of the active learnpath_item in $ordered_items array.
  28. public $items = array();
  29. public $last; // item_id of last item viewed in the learning path.
  30. public $last_item_seen = 0; // In case we have already come in this learnpath, reuse the last item seen if authorized.
  31. public $license; // Which license this course has been given - not used yet on 20060522.
  32. public $lp_id; // DB ID for this learnpath.
  33. public $lp_view_id; // DB ID for lp_view
  34. public $log_file; // File where to log learnpath API msg.
  35. public $maker; // Which maker has conceived the content (ENI, Articulate, ...).
  36. public $message = '';
  37. public $mode = 'embedded'; // Holds the video display mode (fullscreen or embedded).
  38. public $name; // Learnpath name (they generally have one).
  39. public $ordered_items = array(); // List of the learnpath items in the order they are to be read.
  40. public $path = ''; // Path inside the scorm directory (if scorm).
  41. public $theme; // The current theme of the learning path.
  42. public $preview_image; // The current image of the learning path.
  43. // Tells if all the items of the learnpath can be tried again. Defaults to "no" (=1).
  44. public $prevent_reinit = 1;
  45. // Describes the mode of progress bar display.
  46. public $progress_bar_mode = '%';
  47. // Percentage progress as saved in the db.
  48. public $progress_db = '0';
  49. public $proximity; // Wether the content is distant or local or unknown.
  50. public $refs_list = array (); //list of items by ref => db_id. Used only for prerequisites match.
  51. // !!!This array (refs_list) is built differently depending on the nature of the LP.
  52. // If SCORM, uses ref, if Chamilo, uses id to keep a unique value.
  53. public $type; //type of learnpath. Could be 'dokeos', 'scorm', 'scorm2004', 'aicc', ...
  54. // TODO: Check if this type variable is useful here (instead of just in the controller script).
  55. public $user_id; //ID of the user that is viewing/using the course
  56. public $update_queue = array();
  57. public $scorm_debug = 0;
  58. public $arrMenu = array(); // Array for the menu items.
  59. public $debug = 0; // Logging level.
  60. public $lp_session_id =0;
  61. public $lp_view_session_id =0; // The specific view might be bound to a session.
  62. public $prerequisite = 0;
  63. public $use_max_score = 1; // 1 or 0
  64. public $created_on = '';
  65. public $modified_on = '';
  66. public $publicated_on = '';
  67. public $expired_on = '';
  68. /**
  69. * Class constructor. Needs a database handler, a course code and a learnpath id from the database.
  70. * Also builds the list of items into $this->items.
  71. * @param string Course code
  72. * @param integer Learnpath ID
  73. * @param integer User ID
  74. * @return boolean True on success, false on error
  75. */
  76. public function __construct($course, $lp_id, $user_id) {
  77. $this->encoding = api_get_system_encoding(); // Chamilo 1.8.8: We intend always to use the system encoding.
  78. // Check params.
  79. // Check course code.
  80. $course_db = '';
  81. if ($this->debug > 0) {error_log('New LP - In learnpath::__construct('.$course.','.$lp_id.','.$user_id.')', 0); }
  82. if (empty($course)) {
  83. $this->error = 'Course code is empty';
  84. return false;
  85. } else {
  86. $main_table = Database::get_main_table(TABLE_MAIN_COURSE);
  87. //$course = Database::escape_string($course);
  88. $course = $this->escape_string($course);
  89. $sql = "SELECT * FROM $main_table WHERE code = '$course'";
  90. if ($this->debug > 2) { error_log('New LP - learnpath::__construct() '.__LINE__.' - Querying course: '.$sql, 0); }
  91. $res = Database::query($sql);
  92. if (Database::num_rows($res) > 0) {
  93. $this->cc = $course;
  94. $row_course = Database::fetch_array($res);
  95. $course_db = $row_course['db_name'];
  96. } else {
  97. $this->error = 'Course code does not exist in database ('.$sql.')';
  98. return false;
  99. }
  100. }
  101. // Check learnpath ID.
  102. if (empty($lp_id)) {
  103. $this->error = 'Learnpath ID is empty';
  104. return false;
  105. } else {
  106. // TODO: Make it flexible to use any course_code (still using env course code here).
  107. $lp_table = Database::get_course_table(TABLE_LP_MAIN, $course_db);
  108. //$id = Database::escape_integer($id);
  109. $lp_id = $this->escape_string($lp_id);
  110. $sql = "SELECT * FROM $lp_table WHERE id = '$lp_id'";
  111. if ($this->debug > 2) { error_log('New LP - learnpath::__construct() '.__LINE__.' - Querying lp: '.$sql, 0); }
  112. $res = Database::query($sql);
  113. if (Database::num_rows($res) > 0) {
  114. $this->lp_id = $lp_id;
  115. $row = Database::fetch_array($res);
  116. $this->type = $row['lp_type'];
  117. $this->name = stripslashes($row['name']);
  118. //$this->encoding = $row['default_encoding']; // Chamilo 1.8.8: We intend not to use 'default_encoding' field anymore.
  119. $this->proximity = $row['content_local'];
  120. $this->theme = $row['theme'];
  121. $this->maker = $row['content_maker'];
  122. $this->prevent_reinit = $row['prevent_reinit'];
  123. $this->license = $row['content_license'];
  124. $this->scorm_debug = $row['debug'];
  125. $this->js_lib = $row['js_lib'];
  126. $this->path = $row['path'];
  127. $this->preview_image = $row['preview_image'];
  128. $this->author = $row['author'];
  129. $this->lp_session_id = $row['session_id'];
  130. $this->use_max_score = $row['use_max_score'];
  131. $this->created_on = $row['created_on'];
  132. $this->modified_on = $row['modified_on'];
  133. if ($row['publicated_on'] != '0000-00-00 00:00:00') {
  134. $this->publicated_on = $row['publicated_on'];
  135. }
  136. if ($row['expired_on'] != '0000-00-00 00:00:00') {
  137. $this->expired_on = $row['expired_on'];
  138. }
  139. if ($this->type == 2) {
  140. if ($row['force_commit'] == 1) {
  141. $this->force_commit = true;
  142. }
  143. }
  144. $this->mode = $row['default_view_mod'];
  145. } else {
  146. $this->error = 'Learnpath ID does not exist in database ('.$sql.')';
  147. return false;
  148. }
  149. }
  150. // Check user ID.
  151. if (empty($user_id)) {
  152. $this->error = 'User ID is empty';
  153. return false;
  154. } else {
  155. //$main_table = Database::get_main_user_table();
  156. $main_table = Database::get_main_table(TABLE_MAIN_USER);
  157. //$user_id = Database::escape_integer($user_id);
  158. $user_id = $this->escape_string($user_id);
  159. $sql = "SELECT * FROM $main_table WHERE user_id = '$user_id'";
  160. if ($this->debug > 2) { error_log('New LP - learnpath::__construct() '.__LINE__.' - Querying user: '.$sql, 0); }
  161. $res = Database::query($sql);
  162. if (Database::num_rows($res) > 0) {
  163. $this->user_id = $user_id;
  164. } else {
  165. $this->error = 'User ID does not exist in database ('.$sql.')';
  166. return false;
  167. }
  168. }
  169. // End of variables checking.
  170. $session_id = api_get_session_id();
  171. // Get the session condition for learning paths of the base + session.
  172. $session = api_get_session_condition($session_id);
  173. // Now get the latest attempt from this user on this LP, if available, otherwise create a new one.
  174. $lp_table = Database::get_course_table(TABLE_LP_VIEW, $course_db);
  175. // Selecting by view_count descending allows to get the highest view_count first.
  176. $sql = "SELECT * FROM $lp_table WHERE lp_id = '$lp_id' AND user_id = '$user_id' $session ORDER BY view_count DESC";
  177. if ($this->debug > 2) { error_log('New LP - learnpath::__construct() ' . __LINE__ . ' - querying lp_view: ' . $sql, 0); }
  178. $res = Database::query($sql);
  179. $view_id = 0; // Used later to query lp_item_view.
  180. if (Database :: num_rows($res) > 0) {
  181. if ($this->debug > 2) {
  182. error_log('New LP - learnpath::__construct() ' . __LINE__ . ' - Found previous view', 0);
  183. }
  184. $row = Database :: fetch_array($res);
  185. $this->attempt = $row['view_count'];
  186. $this->lp_view_id = $row['id'];
  187. $this->last_item_seen = $row['last_item'];
  188. $this->progress_db = $row['progress'];
  189. $this->lp_view_session_id = $row['session_id'];
  190. } else {
  191. if ($this->debug > 2) {
  192. error_log('New LP - learnpath::__construct() ' . __LINE__ . ' - NOT Found previous view', 0);
  193. }
  194. $this->attempt = 1;
  195. $sql_ins = "INSERT INTO $lp_table (lp_id,user_id,view_count, session_id) VALUES ($lp_id,$user_id,1,$session_id)";
  196. $res_ins = Database::query($sql_ins);
  197. $this->lp_view_id = Database :: insert_id();
  198. if ($this->debug > 2) {
  199. error_log('New LP - learnpath::__construct() ' . __LINE__ . ' - inserting new lp_view: ' . $sql_ins, 0);
  200. }
  201. }
  202. // Initialise items.
  203. $lp_item_table = Database::get_course_table(TABLE_LP_ITEM, $course_db);
  204. $sql = "SELECT * FROM $lp_item_table WHERE lp_id = '".$this->lp_id."' ORDER BY parent_item_id, display_order";
  205. $res = Database::query($sql);
  206. while ($row = Database::fetch_array($res)) {
  207. $oItem = '';
  208. //$this->ordered_items[] = $row['id'];
  209. switch ($this->type) {
  210. case 3: //aicc
  211. $oItem = new aiccItem('db', $row['id'], $course_db);
  212. if (is_object($oItem)) {
  213. $my_item_id = $oItem->get_id();
  214. $oItem->set_lp_view($this->lp_view_id, $course_db);
  215. $oItem->set_prevent_reinit($this->prevent_reinit);
  216. // Don't use reference here as the next loop will make the pointed object change.
  217. $this->items[$my_item_id] = $oItem;
  218. $this->refs_list[$oItem->ref] = $my_item_id;
  219. if ($this->debug > 2) {
  220. error_log('New LP - learnpath::__construct() - aicc object with id ' . $my_item_id . ' set in items[]', 0);
  221. }
  222. }
  223. break;
  224. case 2:
  225. require_once 'scorm.class.php';
  226. require_once 'scormItem.class.php';
  227. $oItem = new scormItem('db', $row['id'], $course_db);
  228. if (is_object($oItem)) {
  229. $my_item_id = $oItem->get_id();
  230. $oItem->set_lp_view($this->lp_view_id, $course_db);
  231. $oItem->set_prevent_reinit($this->prevent_reinit);
  232. // Don't use reference here as the next loop will make the pointed object change.
  233. $this->items[$my_item_id] = $oItem;
  234. $this->refs_list[$oItem->ref] = $my_item_id;
  235. if ($this->debug > 2) {
  236. error_log('New LP - object with id ' . $my_item_id . ' set in items[]', 0);
  237. }
  238. }
  239. break;
  240. case 1:
  241. default:
  242. require_once 'learnpathItem.class.php';
  243. $oItem = new learnpathItem($row['id'], $user_id, $course_db);
  244. if (is_object($oItem)) {
  245. $my_item_id = $oItem->get_id();
  246. //$oItem->set_lp_view($this->lp_view_id); // Moved down to when we are sure the item_view exists.
  247. $oItem->set_prevent_reinit($this->prevent_reinit);
  248. // Don't use reference here as the next loop will make the pointed object change.
  249. $this->items[$my_item_id] = $oItem;
  250. $this->refs_list[$my_item_id] = $my_item_id;
  251. if ($this->debug > 2) {
  252. error_log('New LP - learnpath::__construct() ' . __LINE__ . ' - object with id ' . $my_item_id . ' set in items[]', 0);
  253. }
  254. }
  255. break;
  256. }
  257. // Items is a list of pointers to all items, classified by DB ID, not SCO id.
  258. if ($row['parent_item_id'] == 0 || empty ($this->items[$row['parent_item_id']])) {
  259. if (is_object($this->items[$row['id']])) {
  260. $this->items[$row['id']]->set_level(0);
  261. }
  262. } else {
  263. $level = $this->items[$row['parent_item_id']]->get_level() + 1;
  264. $this->items[$row['id']]->set_level($level);
  265. if (is_object($this->items[$row['parent_item_id']])) {
  266. // Items is a list of pointers from item DB ids to item objects.
  267. $this->items[$row['parent_item_id']]->add_child($row['id']);
  268. } else {
  269. if ($this->debug > 2) {
  270. error_log('New LP - learnpath::__construct() ' . __LINE__ . ' - The parent item (' . $row['parent_item_id'] . ') of item ' . $row['id'] . ' could not be found', 0);
  271. }
  272. }
  273. }
  274. // Get last viewing vars.
  275. $lp_item_view_table = Database :: get_course_table(TABLE_LP_ITEM_VIEW, $course_db);
  276. // This query should only return one or zero result.
  277. $sql = "SELECT * " .
  278. "FROM $lp_item_view_table " .
  279. "WHERE lp_view_id = " . $this->lp_view_id . " " .
  280. "AND lp_item_id = " . $row['id'] . " ORDER BY view_count DESC ";
  281. if ($this->debug > 2) {
  282. error_log('New LP - learnpath::__construct() - Selecting item_views: ' . $sql, 0);
  283. }
  284. // Get the item status.
  285. $res2 = Database::query($sql);
  286. if (Database :: num_rows($res2) > 0) {
  287. // If this learnpath has already been used by this user, get his last attempt count and
  288. // the last item seen back into this object.
  289. //$max = 0;
  290. $row2 = Database :: fetch_array($res2);
  291. if ($this->debug > 2) {
  292. error_log('New LP - learnpath::__construct() - Got item_view: ' . print_r($row2, true), 0);
  293. }
  294. if (is_object($this->items[$row['id']])) {
  295. $this->items[$row['id']]->set_status($row2['status']);
  296. if (empty ($row2['status'])) {
  297. $this->items[$row['id']]->set_status($this->default_status);
  298. }
  299. }
  300. //$this->attempt = $row['view_count'];
  301. //$this->last_item = $row['id'];
  302. } else { // No item has been found in lp_item_view for this view.
  303. // The first attempt of this user. Set attempt to 1 and last_item to 0 (first item available).
  304. // TODO: If the learnpath has not got attempts activated, always use attempt '1'.
  305. //$this->attempt = 1;
  306. //$this->last_item = 0;
  307. if (is_object($this->items[$row['id']])) {
  308. $this->items[$row['id']]->set_status($this->default_status);
  309. }
  310. // Add that row to the lp_item_view table so that we have something to show in the stats page.
  311. $sql_ins = "INSERT INTO $lp_item_view_table " .
  312. "(lp_item_id, lp_view_id, view_count, status) VALUES " .
  313. "(" . $row['id'] . "," . $this->lp_view_id . ",1,'not attempted')";
  314. if ($this->debug > 2) {
  315. error_log('New LP - learnpath::__construct() ' . __LINE__ . ' - Inserting blank item_view : ' . $sql_ins, 0);
  316. }
  317. $res_ins = Database::query($sql_ins);
  318. }
  319. // Setting the view in the item object.
  320. if (is_object($this->items[$row['id']])) {
  321. $this->items[$row['id']]->set_lp_view($this->lp_view_id, $course_db);
  322. }
  323. }
  324. $this->ordered_items = $this->get_flat_ordered_items_list($this->get_id(), 0, $course_db);
  325. $this->max_ordered_items = 0;
  326. foreach ($this->ordered_items as $index => $dummy) {
  327. if ($index > $this->max_ordered_items && !empty($dummy)) {
  328. $this->max_ordered_items = $index;
  329. }
  330. }
  331. // TODO: Define the current item better.
  332. $this->first();
  333. if ($this->debug > 2) {
  334. error_log('New LP - learnpath::__construct() ' . __LINE__ . ' - End of learnpath constructor for learnpath ' . $this->get_id(), 0);
  335. }
  336. }
  337. /**
  338. * 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
  339. * I found it better to rewrite it. Old function is still available. Added also the possibility to add a description.
  340. *
  341. * @param int $parent
  342. * @param int $previous
  343. * @param string $type
  344. * @param int resource ID (ref)
  345. * @param string $title
  346. * @param string $description
  347. * @return int
  348. */
  349. public function add_item($parent, $previous, $type = 'dokeos_chapter', $id, $title, $description, $prerequisites = 0, $max_time_allowed = 0) {
  350. if ($this->debug > 0) {
  351. error_log('New LP - In learnpath::add_item(' . $parent . ',' . $previous . ',' . $type . ',' . $id . ',' . $title . ')', 0);
  352. }
  353. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  354. $parent = intval($parent);
  355. $previous = intval($previous);
  356. $type = $this->escape_string($type);
  357. $id = intval($id);
  358. $max_time_allowed = $this->escape_string(htmlentities($max_time_allowed));
  359. if (empty ($max_time_allowed)) {
  360. $max_time_allowed = 0;
  361. }
  362. $title = $this->escape_string($title);
  363. $description = $this->escape_string($description);
  364. $sql_count = " SELECT COUNT(id) AS num
  365. FROM " . $tbl_lp_item . "
  366. WHERE lp_id = " . $this->get_id() . " AND parent_item_id = " . $parent;
  367. $res_count = Database::query($sql_count);
  368. $row = Database :: fetch_array($res_count);
  369. $num = $row['num'];
  370. if ($num > 0) {
  371. if ($previous == 0) {
  372. $sql = "SELECT id, next_item_id, display_order
  373. FROM " . $tbl_lp_item . "
  374. WHERE
  375. lp_id = " . $this->get_id() . " AND
  376. parent_item_id = " . $parent . " AND
  377. previous_item_id = 0 OR previous_item_id=" . $parent;
  378. $result = Database::query($sql);
  379. $row = Database :: fetch_array($result);
  380. $tmp_previous = 0;
  381. $next = $row['id'];
  382. $display_order = 0;
  383. } else {
  384. $previous = (int) $previous;
  385. $sql = "SELECT id, previous_item_id, next_item_id, display_order
  386. FROM " . $tbl_lp_item . "
  387. WHERE lp_id = " . $this->get_id() . " AND id = " . $previous;
  388. $result = Database::query($sql);
  389. $row = Database :: fetch_array($result);
  390. $tmp_previous = $row['id'];
  391. $next = $row['next_item_id'];
  392. $display_order = $row['display_order'];
  393. }
  394. } else {
  395. $tmp_previous = 0;
  396. $next = 0;
  397. $display_order = 0;
  398. }
  399. $new_item_id = -1;
  400. $id = $this->escape_string($id);
  401. if ($type == 'quiz') {
  402. $sql = 'SELECT SUM(ponderation)
  403. FROM ' . Database :: get_course_table(TABLE_QUIZ_QUESTION) . ' as quiz_question
  404. INNER JOIN ' . Database :: get_course_table(TABLE_QUIZ_TEST_QUESTION) . ' as quiz_rel_question
  405. ON quiz_question.id = quiz_rel_question.question_id
  406. AND quiz_rel_question.exercice_id = ' . $id;
  407. $rsQuiz = Database::query($sql);
  408. $max_score = Database :: result($rsQuiz, 0, 0);
  409. } else {
  410. $max_score = 100;
  411. }
  412. if ($prerequisites != 0) {
  413. $sql_ins = "INSERT INTO " . $tbl_lp_item . " ( ".
  414. "lp_id, ".
  415. "item_type, ".
  416. "ref, ".
  417. "title, ".
  418. "description, ".
  419. "path, ".
  420. "max_score, ".
  421. "parent_item_id, ".
  422. "previous_item_id, ".
  423. "next_item_id, ".
  424. "display_order, ".
  425. "prerequisite, ".
  426. "max_time_allowed ".
  427. ") VALUES ( ".
  428. $this->get_id() . ", ".
  429. "'" . $type . "', ".
  430. "'', ".
  431. "'" . $title . "', ".
  432. "'" . $description . "', ".
  433. "'" . $id . "', ".
  434. "'" . $max_score . "', ".
  435. $parent . ", ".
  436. $previous . ", ".
  437. $next . ", ".
  438. ($display_order +1) . ", ".
  439. $prerequisites . ", ".
  440. $max_time_allowed .
  441. ")";
  442. } else {
  443. // Insert new item.
  444. $sql_ins = "
  445. INSERT INTO " . $tbl_lp_item . " ( ".
  446. "lp_id, ".
  447. "item_type, ".
  448. "ref, ".
  449. "title, ".
  450. "description, ".
  451. "path, ".
  452. "max_score, ".
  453. "parent_item_id, ".
  454. "previous_item_id, ".
  455. "next_item_id, ".
  456. "display_order, ".
  457. "max_time_allowed ".
  458. ") VALUES (".
  459. $this->get_id() . ",".
  460. "'" . $type . "',".
  461. "'',".
  462. "'" . $title . "',".
  463. "'" . $description . "',".
  464. "'" . $id . "',".
  465. "'" . $max_score . "',".
  466. $parent . ",".
  467. $previous . ",".
  468. $next . ",".
  469. ($display_order +1) . ",".
  470. $max_time_allowed .
  471. ")";
  472. }
  473. if ($this->debug > 2) {
  474. error_log('New LP - Inserting dokeos_chapter: ' . $sql_ins, 0);
  475. }
  476. $res_ins = Database::query($sql_ins);
  477. if ($res_ins > 0) {
  478. $new_item_id = Database :: insert_id($res_ins);
  479. // Update the item that should come after the new item.
  480. $sql_update_next = "
  481. UPDATE " . $tbl_lp_item . "
  482. SET previous_item_id = " . $new_item_id . "
  483. WHERE id = " . $next;
  484. $res_update_next = Database::query($sql_update_next);
  485. // Update the item that should be before the new item.
  486. $sql_update_previous = "
  487. UPDATE " . $tbl_lp_item . "
  488. SET next_item_id = " . $new_item_id . "
  489. WHERE id = " . $tmp_previous;
  490. $res_update_previous = Database::query($sql_update_previous);
  491. // Update all the items after the new item.
  492. $sql_update_order = "
  493. UPDATE " . $tbl_lp_item . "
  494. SET display_order = display_order + 1
  495. WHERE
  496. lp_id = " . $this->get_id() . " AND
  497. id <> " . $new_item_id . " AND
  498. parent_item_id = " . $parent . " AND
  499. display_order > " . $display_order;
  500. $res_update_previous = Database::query($sql_update_order);
  501. // Update the item that should come after the new item.
  502. $sql_update_ref = "UPDATE " . $tbl_lp_item . "
  503. SET ref = " . $new_item_id . "
  504. WHERE id = " . $new_item_id;
  505. Database::query($sql_update_ref);
  506. }
  507. // Upload audio.
  508. if (!empty ($_FILES['mp3']['name'])) {
  509. // Create the audio folder if it does not exist yet.
  510. global $_course;
  511. $filepath = api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document/';
  512. if (!is_dir($filepath . 'audio')) {
  513. mkdir($filepath . 'audio', api_get_permissions_for_new_directories());
  514. $audio_id = add_document($_course, '/audio', 'folder', 0, 'audio');
  515. api_item_property_update($_course, TOOL_DOCUMENT, $audio_id, 'FolderCreated', api_get_user_id(), null, null, null, null, api_get_session_id());
  516. }
  517. // Upload the file in the documents tool.
  518. include_once api_get_path(LIBRARY_PATH).'fileUpload.lib.php';
  519. $file_path = handle_uploaded_document($_course, $_FILES['mp3'], api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document', '/audio', api_get_user_id(), '', '', '', '', '', false);
  520. // Getting the filename only.
  521. $file_components = explode('/', $file_path);
  522. $file = $file_components[count($file_components) - 1];
  523. // Store the mp3 file in the lp_item table.
  524. $sql_insert_audio = "UPDATE $tbl_lp_item SET audio = '" . Database :: escape_string($file) . "' WHERE id = '" . Database :: escape_string($new_item_id) . "'";
  525. Database::query($sql_insert_audio);
  526. }
  527. return $new_item_id;
  528. }
  529. /**
  530. * Static admin function allowing addition of a learnpath to a course.
  531. * @param string Course code
  532. * @param string Learnpath name
  533. * @param string Learnpath description string, if provided
  534. * @param string Type of learnpath (default = 'guess', others = 'dokeos', 'aicc',...)
  535. * @param string Type of files origin (default = 'zip', others = 'dir','web_dir',...)
  536. * @param string Zip file containing the learnpath or directory containing the learnpath
  537. * @return integer The new learnpath ID on success, 0 on failure
  538. */
  539. public function add_lp($course, $name, $description = '', $learnpath = 'guess', $origin = 'zip', $zipname = '', $publicated_on = '', $expired_on = '') {
  540. global $charset;
  541. //if ($this->debug > 0) { error_log('New LP - In learnpath::add_lp()', 0); }
  542. $tbl_lp = Database :: get_course_table(TABLE_LP_MAIN);
  543. // Check course code exists.
  544. // Check lp_name doesn't exist, otherwise append something.
  545. $i = 0;
  546. $name = learnpath :: escape_string($name);
  547. // Session id.
  548. $session_id = api_get_session_id();
  549. $check_name = "SELECT * FROM $tbl_lp WHERE name = '$name'";
  550. //if ($this->debug > 2) { error_log('New LP - Checking the name for new LP: '.$check_name, 0); }
  551. $res_name = Database::query($check_name);
  552. if ($publicated_on == '0000-00-00 00:00:00' || empty($publicated_on)) {
  553. //by default the publication date is the same that the creation date
  554. //The behaviour above was changed due BT#2800
  555. $publicated_on = '';
  556. } else {
  557. $publicated_on = Database::escape_string(api_get_utc_datetime($publicated_on));
  558. }
  559. if ($expired_on == '0000-00-00 00:00:00' || empty($expired_on)) {
  560. $expired_on = '';
  561. } else {
  562. $expired_on = Database::escape_string(api_get_utc_datetime($expired_on));
  563. }
  564. while (Database :: num_rows($res_name)) {
  565. // There is already one such name, update the current one a bit.
  566. $i++;
  567. $name = $name . ' - ' . $i;
  568. $check_name = "SELECT * FROM $tbl_lp WHERE name = '$name'";
  569. //if ($this->debug > 2) { error_log('New LP - Checking the name for new LP: '.$check_name, 0); }
  570. $res_name = Database::query($check_name);
  571. }
  572. // New name does not exist yet; keep it.
  573. // Escape description.
  574. $description = learnpath :: escape_string(api_htmlentities($description, ENT_QUOTES, $charset)); // Kevin: added htmlentities().
  575. $type = 1;
  576. switch ($learnpath) {
  577. case 'guess':
  578. break;
  579. case 'dokeos':
  580. case 'chamilo':
  581. $type = 1;
  582. break;
  583. case 'aicc':
  584. break;
  585. }
  586. switch ($origin) {
  587. case 'zip':
  588. // Check zipname string. If empty, we are currently creating a new Chamilo learnpath.
  589. break;
  590. case 'manual':
  591. default:
  592. $get_max = "SELECT MAX(display_order) FROM $tbl_lp";
  593. $res_max = Database::query($get_max);
  594. if (Database :: num_rows($res_max) < 1) {
  595. $dsp = 1;
  596. } else {
  597. $row = Database :: fetch_array($res_max);
  598. $dsp = $row[0] + 1;
  599. }
  600. $sql_insert = "INSERT INTO $tbl_lp (lp_type,name,description,path,default_view_mod, default_encoding,display_order,content_maker,content_local,js_lib,session_id, created_on, publicated_on, expired_on) " .
  601. "VALUES ($type,'$name','$description','','embedded','UTF-8','$dsp','Chamilo','local','','".$session_id."', '".api_get_utc_datetime()."' , '".$publicated_on."' , '".$expired_on."')";
  602. //if ($this->debug > 2) { error_log('New LP - Inserting new lp '.$sql_insert, 0); }
  603. $res_insert = Database::query($sql_insert);
  604. $id = Database :: insert_id();
  605. if ($id > 0) {
  606. // Insert into item_property.
  607. api_item_property_update(api_get_course_info(), TOOL_LEARNPATH, $id, 'LearnpathAdded', api_get_user_id());
  608. return $id;
  609. }
  610. break;
  611. }
  612. }
  613. /**
  614. * Appends a message to the message attribute
  615. * @param string Message to append.
  616. */
  617. public function append_message($string) {
  618. if ($this->debug > 0) {
  619. error_log('New LP - In learnpath::append_message()', 0);
  620. }
  621. $this->message .= $string;
  622. }
  623. /**
  624. * Autocompletes the parents of an item in case it's been completed or passed
  625. * @param integer Optional ID of the item from which to look for parents
  626. */
  627. public function autocomplete_parents($item) {
  628. if ($this->debug > 0) {
  629. error_log('New LP - In learnpath::autocomplete_parents()', 0);
  630. }
  631. if (empty ($item)) {
  632. $item = $this->current;
  633. }
  634. $parent_id = $this->items[$item]->get_parent();
  635. if ($this->debug > 2) {
  636. error_log('New LP - autocompleting parent of item ' . $item . ' (item ' . $parent_id . ')', 0);
  637. }
  638. if (is_object($this->items[$item]) and !empty ($parent_id)) {
  639. // if $item points to an object and there is a parent.
  640. if ($this->debug > 2) {
  641. error_log('New LP - ' . $item . ' is an item, proceed', 0);
  642. }
  643. $current_item = & $this->items[$item];
  644. $parent = & $this->items[$parent_id]; // Get the parent.
  645. // New experiment including failed and browsed in completed status.
  646. $current_status = $current_item->get_status();
  647. if ($current_item->is_done() || $current_status == 'browsed' || $current_status == 'failed') {
  648. // If the current item is completed or passes or succeeded.
  649. $completed = true;
  650. if ($this->debug > 2) {
  651. error_log('New LP - Status of current item is alright', 0);
  652. }
  653. foreach ($parent->get_children() as $child) {
  654. // Check all his brothers (his parent's children) for completion status.
  655. if ($child != $item) {
  656. if ($this->debug > 2) {
  657. error_log('New LP - Looking at brother with ID ' . $child . ', status is ' . $this->items[$child]->get_status(), 0);
  658. }
  659. //if($this->items[$child]->status_is(array('completed','passed','succeeded')))
  660. // Trying completing parents of failed and browsed items as well.
  661. if ($this->items[$child]->status_is(array (
  662. 'completed',
  663. 'passed',
  664. 'succeeded',
  665. 'browsed',
  666. 'failed'
  667. ))) {
  668. // Keep completion status to true.
  669. } else {
  670. if ($this->debug > 2) {
  671. error_log('New LP - Found one incomplete child of ' . $parent_id . ': ' . $child . ' is ' . $this->items[$child]->get_status(), 0);
  672. }
  673. $completed = false;
  674. }
  675. }
  676. }
  677. if ($completed) { // If all the children were completed:
  678. $parent->set_status('completed');
  679. $parent->save(false, $this->prerequisites_match($parent->get_id()));
  680. $this->update_queue[$parent->get_id()] = $parent->get_status();
  681. if ($this->debug > 2) {
  682. error_log('New LP - Added parent to update queue ' . print_r($this->update_queue, true), 0);
  683. }
  684. $this->autocomplete_parents($parent->get_id()); // Recursive call.
  685. }
  686. } else {
  687. //error_log('New LP - status of current item is not enough to get bothered with it', 0);
  688. }
  689. }
  690. }
  691. /**
  692. * Autosaves the current results into the database for the whole learnpath
  693. */
  694. public function autosave() {
  695. if ($this->debug > 0) {
  696. error_log('New LP - In learnpath::autosave()', 0);
  697. }
  698. // TODO: Add save operations for the learnpath itself.
  699. }
  700. /**
  701. * Clears the message attribute
  702. */
  703. public function clear_message() {
  704. if ($this->debug > 0) {
  705. error_log('New LP - In learnpath::clear_message()', 0);
  706. }
  707. $this->message = '';
  708. }
  709. /**
  710. * Closes the current resource
  711. *
  712. * Stops the timer
  713. * Saves into the database if required
  714. * Clears the current resource data from this object
  715. * @return boolean True on success, false on failure
  716. */
  717. public function close() {
  718. if ($this->debug > 0) {
  719. error_log('New LP - In learnpath::close()', 0);
  720. }
  721. if (empty ($this->lp_id)) {
  722. $this->error = 'Trying to close this learnpath but no ID is set';
  723. return false;
  724. }
  725. $this->current_time_stop = time();
  726. if ($this->save) {
  727. $learnpath_view_table = Database :: get_course_table(TABLE_LP_VIEW);
  728. /*
  729. $sql = "UPDATE $learnpath_view_table " .
  730. "SET " .
  731. "stop_time = ".$this->current_time_stop.", " .
  732. "score = ".$this->current_score.", ".
  733. "WHERE learnpath_id = '".$this->lp_id."'";
  734. //$res = Database::query($sql);
  735. $res = Database::query($res);
  736. if (Database::affected_rows($res) < 1) {
  737. $this->error = 'Could not update learnpath_view table while closing learnpath';
  738. return false;
  739. }
  740. */
  741. }
  742. $this->ordered_items = array ();
  743. $this->index = 0;
  744. unset ($this->lp_id);
  745. //unset other stuff
  746. return true;
  747. }
  748. /**
  749. * Static admin function allowing removal of a learnpath
  750. * @param string Course code
  751. * @param integer Learnpath ID
  752. * @param string Whether to delete data or keep it (default: 'keep', others: 'remove')
  753. * @return boolean True on success, false on failure (might change that to return number of elements deleted)
  754. */
  755. public function delete($course = null, $id = null, $delete = 'keep') {
  756. // TODO: Implement a way of getting this to work when the current object is not set.
  757. // In clear: implement this in the item class as well (abstract class) and use the given ID in queries.
  758. //if (empty($course)) { $course = api_get_course_id(); }
  759. //if (empty($id)) { $id = $this->get_id(); }
  760. // If an ID is specifically given and the current LP is not the same, prevent delete.
  761. if (!empty ($id) && ($id != $this->lp_id)) {
  762. return false;
  763. }
  764. $lp = Database :: get_course_table(TABLE_LP_MAIN);
  765. $lp_item = Database :: get_course_table(TABLE_LP_ITEM); // Proposed by Christophe (clefevre), see below.
  766. $lp_view = Database :: get_course_table(TABLE_LP_VIEW);
  767. $lp_item_view = Database :: get_course_table(TABLE_LP_ITEM_VIEW);
  768. //if ($this->debug > 0) { error_log('New LP - In learnpath::delete()', 0); }
  769. // Delete lp item id.
  770. foreach ($this->items as $id => $dummy) {
  771. //$this->items[$id]->delete();
  772. $sql_del_view = "DELETE FROM $lp_item_view WHERE lp_item_id = '" . $id . "'";
  773. $res_del_item_view = Database::query($sql_del_view);
  774. }
  775. // Proposed by Christophe (nickname: clefevre), see http://www.dokeos.com/forum/viewtopic.php?t=29673
  776. $sql_del_item = "DELETE FROM $lp_item WHERE lp_id = " . $this->lp_id;
  777. $res_del_item = Database::query($sql_del_item);
  778. $sql_del_view = "DELETE FROM $lp_view WHERE lp_id = " . $this->lp_id;
  779. //if ($this->debug > 2) { error_log('New LP - Deleting views bound to lp '.$this->lp_id.': '.$sql_del_view, 0); }
  780. $res_del_view = Database::query($sql_del_view);
  781. $this->toggle_publish($this->lp_id, 'i');
  782. //if ($this->debug > 2) { error_log('New LP - Deleting lp '.$this->lp_id.' of type '.$this->type, 0); }
  783. if ($this->type == 2 || $this->type == 3) {
  784. // This is a scorm learning path, delete the files as well.
  785. $sql = "SELECT path FROM $lp WHERE id = " . $this->lp_id;
  786. $res = Database::query($sql);
  787. if (Database :: num_rows($res) > 0) {
  788. $row = Database :: fetch_array($res);
  789. $path = $row['path'];
  790. $sql = "SELECT id FROM $lp WHERE path = '$path' AND id != " . $this->lp_id;
  791. $res = Database::query($sql);
  792. if (Database :: num_rows($res) > 0) { // Another learning path uses this directory, so don't delete it.
  793. if ($this->debug > 2) {
  794. error_log('New LP - In learnpath::delete(), found other LP using path ' . $path . ', keeping directory', 0);
  795. }
  796. } else {
  797. // No other LP uses that directory, delete it.
  798. $course_rel_dir = api_get_course_path() . '/scorm/'; // scorm dir web path starting from /courses
  799. $course_scorm_dir = api_get_path(SYS_COURSE_PATH) . $course_rel_dir; // The absolute system path for this course.
  800. if ($delete == 'remove' && is_dir($course_scorm_dir . $path) and !empty ($course_scorm_dir)) {
  801. if ($this->debug > 2) {
  802. error_log('New LP - In learnpath::delete(), found SCORM, deleting directory: ' . $course_scorm_dir . $path, 0);
  803. }
  804. // Proposed by Christophe (clefevre).
  805. if (strcmp(substr($path, -2), "/.") == 0) {
  806. $path = substr($path, 0, -1); // Remove "." at the end.
  807. }
  808. //exec('rm -rf ' . $course_scorm_dir . $path); // See Bug #5208, this is not OS-portable way.
  809. rmdirr($course_scorm_dir . $path);
  810. }
  811. }
  812. }
  813. }
  814. $sql_del_lp = "DELETE FROM $lp WHERE id = " . $this->lp_id;
  815. //if ($this->debug > 2) { error_log('New LP - Deleting lp '.$this->lp_id.': '.$sql_del_lp, 0); }
  816. $res_del_lp = Database::query($sql_del_lp);
  817. $this->update_display_order(); // Updates the display order of all lps.
  818. api_item_property_update(api_get_course_info(), TOOL_LEARNPATH, $this->lp_id, 'delete', api_get_user_id());
  819. require_once '../gradebook/lib/be.inc.php';
  820. // Delete link of gradebook tool
  821. //$tbl_grade_link = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_LINK);
  822. /*$sql = 'SELECT gl.id FROM ' . $tbl_grade_link . ' gl WHERE gl.type="4" AND gl.ref_id="' . $id . '";';
  823. $result = Database::query($sql);
  824. $row = Database :: fetch_array($result, 'ASSOC');*/
  825. // Fixing gradebook link deleted see #5229.
  826. /*
  827. if (!empty($row['id'])) {
  828. $link = LinkFactory :: load($row['id']);
  829. if ($link[0] != null) {
  830. $link[0]->delete();
  831. }
  832. }*/
  833. require_once api_get_path(SYS_CODE_PATH).'gradebook/lib/gradebook_functions.inc.php';
  834. $link_id = is_resource_in_course_gradebook(api_get_course_id(), 4 , $id, api_get_session_id());
  835. if ($link_id !== false) {
  836. remove_resource_from_course_gradebook($link_id);
  837. }
  838. if (api_get_setting('search_enabled') == 'true') {
  839. require_once api_get_path(LIBRARY_PATH).'specific_fields_manager.lib.php';
  840. $r = delete_all_values_for_item($this->cc, TOOL_LEARNPATH, $this->lp_id);
  841. }
  842. }
  843. /**
  844. * Removes all the children of one item - dangerous!
  845. * @param integer Element ID of which children have to be removed
  846. * @return integer Total number of children removed
  847. */
  848. public function delete_children_items($id) {
  849. if ($this->debug > 0) {
  850. error_log('New LP - In learnpath::delete_children_items(' . $id . ')', 0);
  851. }
  852. $num = 0;
  853. if (empty ($id) || $id != strval(intval($id))) {
  854. return false;
  855. }
  856. $lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  857. $sql = "SELECT * FROM $lp_item WHERE parent_item_id = $id";
  858. $res = Database::query($sql);
  859. while ($row = Database :: fetch_array($res)) {
  860. $num += $this->delete_children_items($row['id']);
  861. $sql_del = "DELETE FROM $lp_item WHERE id = " . $row['id'];
  862. $res_del = Database::query($sql_del);
  863. $num++;
  864. }
  865. return $num;
  866. }
  867. /**
  868. * Removes an item from the current learnpath
  869. * @param integer Elem ID (0 if first)
  870. * @param integer Whether to remove the resource/data from the system or leave it (default: 'keep', others 'remove')
  871. * @return integer Number of elements moved
  872. * @todo implement resource removal
  873. */
  874. public function delete_item($id, $remove = 'keep') {
  875. if ($this->debug > 0) {
  876. error_log('New LP - In learnpath::delete_item()', 0);
  877. }
  878. // TODO: Implement the resource removal.
  879. if (empty ($id) || $id != strval(intval($id))) {
  880. return false;
  881. }
  882. // First select item to get previous, next, and display order.
  883. $lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  884. $sql_sel = "SELECT * FROM $lp_item WHERE id = $id";
  885. $res_sel = Database::query($sql_sel);
  886. if (Database :: num_rows($res_sel) < 1) {
  887. return false;
  888. }
  889. $row = Database :: fetch_array($res_sel);
  890. $previous = $row['previous_item_id'];
  891. $next = $row['next_item_id'];
  892. $display = $row['display_order'];
  893. $parent = $row['parent_item_id'];
  894. $lp = $row['lp_id'];
  895. // Delete children items.
  896. $num = $this->delete_children_items($id);
  897. if ($this->debug > 2) {
  898. error_log('New LP - learnpath::delete_item() - deleted ' . $num . ' children of element ' . $id, 0);
  899. }
  900. // Now delete the item.
  901. $sql_del = "DELETE FROM $lp_item WHERE id = $id";
  902. if ($this->debug > 2) {
  903. error_log('New LP - Deleting item: ' . $sql_del, 0);
  904. }
  905. $res_del = Database::query($sql_del);
  906. // Now update surrounding items.
  907. $sql_upd = "UPDATE $lp_item SET next_item_id = $next WHERE id = $previous";
  908. $res_upd = Database::query($sql_upd);
  909. $sql_upd = "UPDATE $lp_item SET previous_item_id = $previous WHERE id = $next";
  910. $res_upd = Database::query($sql_upd);
  911. // Now update all following items with new display order.
  912. $sql_all = "UPDATE $lp_item SET display_order = display_order-1 WHERE lp_id = $lp AND parent_item_id = $parent AND display_order > $display";
  913. $res_all = Database::query($sql_all);
  914. //Removing prerequisites since the item will not longer exist
  915. $sql_all = "UPDATE $lp_item SET prerequisite = '' WHERE prerequisite = $id";
  916. $res_all = Database::query($sql_all);
  917. // Remove from search engine if enabled.
  918. if (api_get_setting('search_enabled') == 'true') {
  919. $tbl_se_ref = Database :: get_main_table(TABLE_MAIN_SEARCH_ENGINE_REF);
  920. $sql = 'SELECT * FROM %s WHERE course_code=\'%s\' AND tool_id=\'%s\' AND ref_id_high_level=%s AND ref_id_second_level=%d LIMIT 1';
  921. $sql = sprintf($sql, $tbl_se_ref, $this->cc, TOOL_LEARNPATH, $lp, $id);
  922. $res = Database::query($sql);
  923. if (Database :: num_rows($res) > 0) {
  924. $row2 = Database :: fetch_array($res);
  925. require_once api_get_path(LIBRARY_PATH).'search/DokeosIndexer.class.php';
  926. $di = new DokeosIndexer();
  927. $di->remove_document((int) $row2['search_did']);
  928. }
  929. $sql = 'DELETE FROM %s WHERE course_code=\'%s\' AND tool_id=\'%s\' AND ref_id_high_level=%s AND ref_id_second_level=%d LIMIT 1';
  930. $sql = sprintf($sql, $tbl_se_ref, $this->cc, TOOL_LEARNPATH, $lp, $id);
  931. Database::query($sql);
  932. }
  933. }
  934. /**
  935. * Updates an item's content in place
  936. * @param integer Element ID
  937. * @param integer Parent item ID
  938. * @param integer Previous item ID
  939. * @param string Item title
  940. * @param string Item description
  941. * @param string Prerequisites (optional)
  942. * @param string Indexing terms (optional)
  943. * @param array The array resulting of the $_FILES[mp3] element
  944. * @return boolean True on success, false on error
  945. */
  946. public function edit_item($id, $parent, $previous, $title, $description, $prerequisites = 0, $audio = null, $max_time_allowed = 0) {
  947. if ($this->debug > 0) {
  948. error_log('New LP - In learnpath::edit_item()', 0);
  949. }
  950. if (empty ($max_time_allowed)) {
  951. $max_time_allowed = 0;
  952. }
  953. if (empty ($id) || ($id != strval(intval($id))) || empty ($title)) {
  954. return false;
  955. }
  956. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  957. $sql_select = "SELECT * FROM " . $tbl_lp_item . " WHERE id = " . $id;
  958. $res_select = Database::query($sql_select);
  959. $row_select = Database :: fetch_array($res_select);
  960. $audio_update_sql = '';
  961. if (is_array($audio) && !empty ($audio['tmp_name']) && $audio['error'] === 0) {
  962. // Create the audio folder if it does not exist yet.
  963. global $_course;
  964. $filepath = api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document/';
  965. if (!is_dir($filepath . 'audio')) {
  966. mkdir($filepath . 'audio', api_get_permissions_for_new_directories());
  967. $audio_id = add_document($_course, '/audio', 'folder', 0, 'audio');
  968. api_item_property_update($_course, TOOL_DOCUMENT, $audio_id, 'FolderCreated', api_get_user_id(), null, null, null, null, api_get_session_id());
  969. }
  970. // Upload file in documents.
  971. $pi = pathinfo($audio['name']);
  972. if ($pi['extension'] == 'mp3') {
  973. $c_det = api_get_course_info($this->cc);
  974. $bp = api_get_path(SYS_COURSE_PATH) . $c_det['path'] . '/document';
  975. $path = handle_uploaded_document($c_det, $audio, $bp, '/audio', api_get_user_id(), 0, null, '', 0, 'rename', false, 0);
  976. $path = substr($path, 7);
  977. // Update reference in lp_item - audio path is the path from inside de document/audio/ dir.
  978. $audio_update_sql = ", audio = '" . Database :: escape_string($path) . "' ";
  979. }
  980. }
  981. $same_parent = ($row_select['parent_item_id'] == $parent) ? true : false;
  982. $same_previous = ($row_select['previous_item_id'] == $previous) ? true : false;
  983. // TODO: htmlspecialchars to be checked for encoding related problems.
  984. if ($same_parent && $same_previous) {
  985. // Only update title and description.
  986. $sql_update = " UPDATE " . $tbl_lp_item . "
  987. SET title = '" . $this->escape_string($title) . "',
  988. prerequisite = '" . $prerequisites . "',
  989. description = '" . $this->escape_string($description) . "'
  990. " . $audio_update_sql . ",
  991. max_time_allowed = '" . $this->escape_string($max_time_allowed) . "'
  992. WHERE id = " . $id;
  993. $res_update = Database::query($sql_update);
  994. } else {
  995. $old_parent = $row_select['parent_item_id'];
  996. $old_previous = $row_select['previous_item_id'];
  997. $old_next = $row_select['next_item_id'];
  998. $old_order = $row_select['display_order'];
  999. $old_prerequisite = $row_select['prerequisite'];
  1000. $old_max_time_allowed = $row_select['max_time_allowed'];
  1001. /* BEGIN -- virtually remove the current item id */
  1002. /* for the next and previous item it is like the current item doesn't exist anymore */
  1003. if ($old_previous != 0) {
  1004. $sql_update_next = "
  1005. UPDATE " . $tbl_lp_item . "
  1006. SET next_item_id = " . $old_next . "
  1007. WHERE id = " . $old_previous;
  1008. $res_update_next = Database::query($sql_update_next);
  1009. //echo '<p>' . $sql_update_next . '</p>';
  1010. }
  1011. if ($old_next != 0) {
  1012. $sql_update_previous = "
  1013. UPDATE " . $tbl_lp_item . "
  1014. SET previous_item_id = " . $old_previous . "
  1015. WHERE id = " . $old_next;
  1016. $res_update_previous = Database::query($sql_update_previous);
  1017. //echo '<p>' . $sql_update_previous . '</p>';
  1018. }
  1019. // display_order - 1 for every item with a display_order bigger then the display_order of the current item.
  1020. $sql_update_order = "
  1021. UPDATE " . $tbl_lp_item . "
  1022. SET display_order = display_order - 1
  1023. WHERE
  1024. display_order > " . $old_order . " AND lp_id = " . $this->lp_id . " AND
  1025. parent_item_id = " . $old_parent;
  1026. $res_update_order = Database::query($sql_update_order);
  1027. //echo '<p>' . $sql_update_order . '</p>';
  1028. /* END -- virtually remove the current item id */
  1029. /* BEGIN -- update the current item id to his new location */
  1030. if ($previous == 0) {
  1031. // Select the data of the item that should come after the current item.
  1032. $sql_select_old = "
  1033. SELECT
  1034. id,
  1035. display_order
  1036. FROM " . $tbl_lp_item . "
  1037. WHERE
  1038. lp_id = " . $this->lp_id . " AND
  1039. parent_item_id = " . $parent . " AND
  1040. previous_item_id = " . $previous;
  1041. $res_select_old = Database::query($sql_select_old);
  1042. $row_select_old = Database :: fetch_array($res_select_old);
  1043. //echo '<p>' . $sql_select_old . '</p>';
  1044. // If the new parent didn't have children before.
  1045. if (Database :: num_rows($res_select_old) == 0) {
  1046. $new_next = 0;
  1047. $new_order = 1;
  1048. } else {
  1049. $new_next = $row_select_old['id'];
  1050. $new_order = $row_select_old['display_order'];
  1051. }
  1052. //echo 'New next_item_id of current item: ' . $new_next . '<br />';
  1053. //echo 'New previous_item_id of current item: ' . $previous . '<br />';
  1054. //echo 'New display_order of current item: ' . $new_order . '<br />';
  1055. } else {
  1056. // Select the data of the item that should come before the current item.
  1057. $sql_select_old = "
  1058. SELECT
  1059. next_item_id,
  1060. display_order
  1061. FROM " . $tbl_lp_item . "
  1062. WHERE id = " . $previous;
  1063. $res_select_old = Database::query($sql_select_old);
  1064. $row_select_old = Database :: fetch_array($res_select_old);
  1065. //echo '<p>' . $sql_select_old . '</p>';
  1066. //echo 'New next_item_id of current item: ' . $row_select_old['next_item_id'] . '<br />';
  1067. //echo 'New previous_item_id of current item: ' . $previous . '<br />';
  1068. //echo 'New display_order of current item: ' . ($row_select_old['display_order'] + 1) . '<br />';
  1069. $new_next = $row_select_old['next_item_id'];
  1070. $new_order = $row_select_old['display_order'] + 1;
  1071. }
  1072. // TODO: htmlspecialchars to be checked for encoding related problems.
  1073. // Update the current item with the new data.
  1074. $sql_update = "
  1075. UPDATE " . $tbl_lp_item . "
  1076. SET
  1077. title = '" . $this->escape_string($title) . "',
  1078. description = '" . $this->escape_string($description) . "',
  1079. parent_item_id = " . $parent . ",
  1080. previous_item_id = " . $previous . ",
  1081. next_item_id = " . $new_next . ",
  1082. display_order = " . $new_order . "
  1083. " . $audio_update_sql . "
  1084. WHERE id = " . $id;
  1085. $res_update_next = Database::query($sql_update);
  1086. //echo '<p>' . $sql_update . '</p>';
  1087. if ($previous != 0) {
  1088. // Update the previous item's next_item_id.
  1089. $sql_update_previous = "
  1090. UPDATE " . $tbl_lp_item . "
  1091. SET next_item_id = " . $id . "
  1092. WHERE id = " . $previous;
  1093. $res_update_next = Database::query($sql_update_previous);
  1094. //echo '<p>' . $sql_update_previous . '</p>';
  1095. }
  1096. if ($new_next != 0) {
  1097. // Update the next item's previous_item_id.
  1098. $sql_update_next = "
  1099. UPDATE " . $tbl_lp_item . "
  1100. SET previous_item_id = " . $id . "
  1101. WHERE id = " . $new_next;
  1102. $res_update_next = Database::query($sql_update_next);
  1103. //echo '<p>' . $sql_update_next . '</p>';
  1104. }
  1105. if ($old_prerequisite != $prerequisites) {
  1106. $sql_update_next = "
  1107. UPDATE " . $tbl_lp_item . "
  1108. SET prerequisite = " . $prerequisites . "
  1109. WHERE id = " . $id;
  1110. $res_update_next = Database::query($sql_update_next);
  1111. }
  1112. if ($old_max_time_allowed != $max_time_allowed) {
  1113. $sql_update_max_time_allowed = "
  1114. UPDATE " . $tbl_lp_item . "
  1115. SET max_time_allowed = " . $max_time_allowed . "
  1116. WHERE id = " . $id;
  1117. $res_update_max_time_allowed = Database::query($sql_update_max_time_allowed);
  1118. }
  1119. // Update all the items with the same or a bigger display_order than the current item.
  1120. $sql_update_order = "
  1121. UPDATE " . $tbl_lp_item . "
  1122. SET display_order = display_order + 1
  1123. WHERE
  1124. lp_id = " . $this->get_id() . " AND
  1125. id <> " . $id . " AND
  1126. parent_item_id = " . $parent . " AND
  1127. display_order >= " . $new_order;
  1128. $res_update_next = Database::query($sql_update_order);
  1129. }
  1130. }
  1131. /**
  1132. * Updates an item's prereq in place
  1133. * @param integer Element ID
  1134. * @param string Prerequisite Element ID
  1135. * @param string Prerequisite item type
  1136. * @param string Prerequisite min score
  1137. * @param string Prerequisite max score
  1138. * @return boolean True on success, false on error
  1139. */
  1140. public function edit_item_prereq($id, $prerequisite_id, $mastery_score = 0, $max_score = 100) {
  1141. if ($this->debug > 0) {
  1142. error_log('New LP - In learnpath::edit_item_prereq(' . $id . ',' . $prerequisite_id . ',' . $mastery_score . ',' . $max_score . ')', 0);
  1143. }
  1144. if (empty ($id) or ($id != strval(intval($id))) or empty ($prerequisite_id)) {
  1145. return false;
  1146. }
  1147. $prerequisite_id = $this->escape_string($prerequisite_id);
  1148. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  1149. if (!is_numeric($mastery_score) || $mastery_score < 0)
  1150. $mastery_score = 0;
  1151. if (!is_numeric($max_score) || $max_score < 0)
  1152. $max_score = 100;
  1153. if ($mastery_score > $max_score)
  1154. $max_score = $mastery_score;
  1155. if (!is_numeric($prerequisite_id))
  1156. $prerequisite_id = 'NULL';
  1157. $sql_upd = " UPDATE " . $tbl_lp_item . "
  1158. SET prerequisite = " . $prerequisite_id . " WHERE id = " . $id;
  1159. $res_upd = Database::query($sql_upd);
  1160. if ($prerequisite_id != 'NULL' && $prerequisite_id != '') {
  1161. $sql_upd = " UPDATE " . $tbl_lp_item . " SET
  1162. mastery_score = " . $mastery_score .
  1163. //", max_score = " . $max_score . " " . // Max score cannot be changed in the form anyway - see display_item_prerequisites_form().
  1164. " WHERE ref = '" . $prerequisite_id . "'"; // Will this be enough to ensure unicity?
  1165. $res_upd = Database::query($sql_upd);
  1166. }
  1167. // TODO: Update the item object (can be ignored for now because refreshed).
  1168. return true;
  1169. }
  1170. /**
  1171. * Escapes a string with the available database escape function
  1172. * @param string String to escape
  1173. * @return string String escaped
  1174. */
  1175. public function escape_string($string) {
  1176. //if ($this->debug > 0) { error_log('New LP - In learnpath::escape_string('.$string.')', 0); }
  1177. return Database :: escape_string($string);
  1178. }
  1179. /**
  1180. * Static admin function exporting a learnpath into a zip file
  1181. * @param string Export type (scorm, zip, cd)
  1182. * @param string Course code
  1183. * @param integer Learnpath ID
  1184. * @param string Zip file name
  1185. * @return string Zip file path (or false on error)
  1186. */
  1187. public function export_lp($type, $course, $id, $zipname) {
  1188. //if ($this->debug > 0) { error_log('New LP - In learnpath::export_lp()', 0); }
  1189. if (empty($type) || empty($course) || empty($id) || empty($zipname)) {
  1190. return false;
  1191. }
  1192. $url = '';
  1193. switch ($type) {
  1194. case 'scorm':
  1195. break;
  1196. case 'zip':
  1197. break;
  1198. case 'cdrom':
  1199. break;
  1200. }
  1201. return $url;
  1202. }
  1203. /**
  1204. * Gets all the chapters belonging to the same parent as the item/chapter given
  1205. * Can also be called as abstract method
  1206. * @param integer Item ID
  1207. * @return array A list of all the "brother items" (or an empty array on failure)
  1208. */
  1209. public function get_brother_chapters($id) {
  1210. if ($this->debug > 0) {
  1211. error_log('New LP - In learnpath::get_brother_chapters()', 0);
  1212. }
  1213. if (empty ($id) OR $id != strval(intval($id))) {
  1214. return array ();
  1215. }
  1216. $lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  1217. $sql_parent = "SELECT * FROM $lp_item WHERE id = $id AND item_type='dokeos_chapter'";
  1218. $res_parent = Database::query($sql_parent);
  1219. if (Database :: num_rows($res_parent) > 0) {
  1220. $row_parent = Database :: fetch_array($res_parent);
  1221. $parent = $row_parent['parent_item_id'];
  1222. $sql_bros = "SELECT * FROM $lp_item WHERE parent_item_id = $parent AND id = $id AND item_type='dokeos_chapter' ORDER BY display_order";
  1223. $res_bros = Database::query($sql_bros);
  1224. $list = array ();
  1225. while ($row_bro = Database :: fetch_array($res_bros)) {
  1226. $list[] = $row_bro;
  1227. }
  1228. return $list;
  1229. }
  1230. return array ();
  1231. }
  1232. /**
  1233. * Gets all the items belonging to the same parent as the item given
  1234. * Can also be called as abstract method
  1235. * @param integer Item ID
  1236. * @return array A list of all the "brother items" (or an empty array on failure)
  1237. */
  1238. public function get_brother_items($id) {
  1239. if ($this->debug > 0) {
  1240. error_log('New LP - In learnpath::get_brother_items(' . $id . ')', 0);
  1241. }
  1242. if (empty ($id) OR $id != strval(intval($id))) {
  1243. return array ();
  1244. }
  1245. $lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  1246. $sql_parent = "SELECT * FROM $lp_item WHERE id = $id";
  1247. $res_parent = Database::query($sql_parent);
  1248. if (Database :: num_rows($res_parent) > 0) {
  1249. $row_parent = Database :: fetch_array($res_parent);
  1250. $parent = $row_parent['parent_item_id'];
  1251. $sql_bros = "SELECT * FROM $lp_item WHERE parent_item_id = $parent ORDER BY display_order";
  1252. $res_bros = Database::query($sql_bros);
  1253. $list = array ();
  1254. while ($row_bro = Database :: fetch_array($res_bros)) {
  1255. $list[] = $row_bro;
  1256. }
  1257. return $list;
  1258. }
  1259. return array ();
  1260. }
  1261. /**
  1262. * Get the specific prefix index terms of this learning path
  1263. * @return array Array of terms
  1264. */
  1265. public function get_common_index_terms_by_prefix($prefix) {
  1266. require_once api_get_path(LIBRARY_PATH).'specific_fields_manager.lib.php';
  1267. $terms = get_specific_field_values_list_by_prefix($prefix, $this->cc, TOOL_LEARNPATH, $this->lp_id);
  1268. $prefix_terms = array();
  1269. if (!empty($terms)) {
  1270. foreach ($terms as $term) {
  1271. $prefix_terms[] = $term['value'];
  1272. }
  1273. }
  1274. return $prefix_terms;
  1275. }
  1276. /**
  1277. * Gets the number of items currently completed
  1278. * @return integer The number of items currently completed
  1279. */
  1280. public function get_complete_items_count() {
  1281. if ($this->debug > 0) {
  1282. error_log('New LP - In learnpath::get_complete_items_count()', 0);
  1283. }
  1284. $i = 0;
  1285. foreach ($this->items as $id => $dummy) {
  1286. // Trying failed and browsed considered "progressed" as well.
  1287. if ($this->items[$id]->status_is(array (
  1288. 'completed',
  1289. 'passed',
  1290. 'succeeded',
  1291. 'browsed',
  1292. 'failed'
  1293. )) && $this->items[$id]->get_type() != 'dokeos_chapter' && $this->items[$id]->get_type() != 'dir') {
  1294. $i++;
  1295. }
  1296. }
  1297. return $i;
  1298. }
  1299. /**
  1300. * Gets the current item ID
  1301. * @return integer The current learnpath item id
  1302. */
  1303. public function get_current_item_id() {
  1304. $current = 0;
  1305. if ($this->debug > 0) {
  1306. error_log('New LP - In learnpath::get_current_item_id()', 0);
  1307. }
  1308. if (!empty ($this->current)) {
  1309. $current = $this->current;
  1310. }
  1311. if ($this->debug > 2) {
  1312. error_log('New LP - In learnpath::get_current_item_id() - Returning ' . $current, 0);
  1313. }
  1314. return $current;
  1315. }
  1316. /**
  1317. * Force to get the first learnpath item id
  1318. * @return integer The current learnpath item id
  1319. */
  1320. public function get_first_item_id() {
  1321. $current = 0;
  1322. if (is_array($this->ordered_items)) {
  1323. $current = $this->ordered_items[0];
  1324. }
  1325. return $current;
  1326. }
  1327. /**
  1328. * Gets the total number of items available for viewing in this SCORM
  1329. * @return integer The total number of items
  1330. */
  1331. public function get_total_items_count() {
  1332. if ($this->debug > 0) {
  1333. error_log('New LP - In learnpath::get_total_items_count()', 0);
  1334. }
  1335. return count($this->items);
  1336. }
  1337. /**
  1338. * Gets the total number of items available for viewing in this SCORM but without chapters
  1339. * @return integer The total no-chapters number of items
  1340. */
  1341. public function get_total_items_count_without_chapters() {
  1342. if ($this->debug > 0) {
  1343. error_log('New LP - In learnpath::get_total_items_count_without_chapters()', 0);
  1344. }
  1345. $total = 0;
  1346. foreach ($this->items as $temp => $temp2) {
  1347. if (!in_array($temp2->get_type(), array (
  1348. 'dokeos_chapter',
  1349. 'chapter',
  1350. 'dir'
  1351. )))
  1352. $total++;
  1353. }
  1354. return $total;
  1355. }
  1356. /**
  1357. * Gets the first element URL.
  1358. * @return string URL to load into the viewer
  1359. */
  1360. public function first() {
  1361. if ($this->debug > 0) {
  1362. error_log('New LP - In learnpath::first()', 0);
  1363. }
  1364. // Test if the last_item_seen exists and is not a dir.
  1365. if (count($this->ordered_items) == 0) {
  1366. $this->index = 0;
  1367. }
  1368. if (!empty($this->last_item_seen) && !empty($this->items[$this->last_item_seen]) && $this->items[$this->last_item_seen]->get_type() != 'dir' && $this->items[$this->last_item_seen]->get_type() != 'dokeos_chapter' && !$this->items[$this->last_item_seen]->is_done()) {
  1369. if ($this->debug > 2) {
  1370. 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);
  1371. }
  1372. $index = -1;
  1373. foreach ($this->ordered_items as $myindex => $item_id) {
  1374. if ($item_id == $this->last_item_seen) {
  1375. $index = $myindex;
  1376. break;
  1377. }
  1378. }
  1379. if ($index == -1) {
  1380. // Index hasn't changed, so item not found - panic (this shouldn't happen).
  1381. if ($this->debug > 2) {
  1382. error_log('New LP - Last item (' . $this->last_item_seen . ') was found in items but not in ordered_items, panic!', 0);
  1383. }
  1384. return false;
  1385. } else {
  1386. $this->last = $this->last_item_seen;
  1387. $this->current = $this->last_item_seen;
  1388. $this->index = $index;
  1389. }
  1390. } else {
  1391. if ($this->debug > 2) {
  1392. error_log('New LP - In learnpath::first() - No last item seen', 0);
  1393. }
  1394. $index = 0;
  1395. // Loop through all ordered items and stop at the first item that is
  1396. // not a directory *and* that has not been completed yet.
  1397. while (!empty($this->ordered_items[$index]) AND is_a($this->items[$this->ordered_items[$index]], 'learnpathItem') AND ($this->items[$this->ordered_items[$index]]->get_type() == 'dir' OR $this->items[$this->ordered_items[$index]]->get_type() == 'dokeos_chapter' OR $this->items[$this->ordered_items[$index]]->is_done() === true) AND $index < $this->max_ordered_items) {
  1398. $index++;
  1399. }
  1400. $this->last = $this->current;
  1401. // current is
  1402. $this->current = $this->ordered_items[$index];
  1403. $this->index = $index;
  1404. if ($this->debug > 2) {
  1405. error_log('New LP - In learnpath::first() - No last item seen. New last = ' . $this->last . '(' . $this->ordered_items[$index] . ')', 0);
  1406. }
  1407. }
  1408. if ($this->debug > 2) {
  1409. error_log('New LP - In learnpath::first() - First item is ' . $this->get_current_item_id());
  1410. }
  1411. }
  1412. /**
  1413. * Gets the information about an item in a format usable as JavaScript to update
  1414. * the JS API by just printing this content into the <head> section of the message frame
  1415. * @param integer Item ID
  1416. * @return string
  1417. */
  1418. public function get_js_info($item_id = '') {
  1419. if ($this->debug > 0) {
  1420. error_log('New LP - In learnpath::get_js_info(' . $item_id . ')', 0);
  1421. }
  1422. $info = '';
  1423. $item_id = $this->escape_string($item_id);
  1424. if (!empty($item_id) && is_object($this->items[$item_id])) {
  1425. //if item is defined, return values from DB
  1426. $oItem = $this->items[$item_id];
  1427. $info .= '<script language="javascript">';
  1428. $info .= "top.set_score(" . $oItem->get_score() . ");\n";
  1429. $info .= "top.set_max(" . $oItem->get_max() . ");\n";
  1430. $info .= "top.set_min(" . $oItem->get_min() . ");\n";
  1431. $info .= "top.set_lesson_status('" . $oItem->get_status() . "');";
  1432. $info .= "top.set_session_time('" . $oItem->get_scorm_time('js') . "');";
  1433. $info .= "top.set_suspend_data('" . $oItem->get_suspend_data() . "');";
  1434. $info .= "top.set_saved_lesson_status('" . $oItem->get_status() . "');";
  1435. $info .= "top.set_flag_synchronized();";
  1436. $info .= '</script>';
  1437. if ($this->debug > 2) {
  1438. error_log('New LP - in learnpath::get_js_info(' . $item_id . ') - returning: ' . $info, 0);
  1439. }
  1440. return $info;
  1441. } else {
  1442. // If item_id is empty, just update to default SCORM data.
  1443. $info .= '<script language="javascript">';
  1444. $info .= "top.set_score(" . learnpathItem :: get_score() . ");\n";
  1445. $info .= "top.set_max(" . learnpathItem :: get_max() . ");\n";
  1446. $info .= "top.set_min(" . learnpathItem :: get_min() . ");\n";
  1447. $info .= "top.set_lesson_status('" . learnpathItem :: get_status() . "');";
  1448. $info .= "top.set_session_time('" . learnpathItem :: get_scorm_time('js') . "');";
  1449. $info .= "top.set_suspend_data('" . learnpathItem :: get_suspend_data() . "');";
  1450. $info .= "top.set_saved_lesson_status('" . learnpathItem :: get_status() . "');";
  1451. $info .= "top.set_flag_synchronized();";
  1452. $info .= '</script>';
  1453. if ($this->debug > 2) {
  1454. error_log('New LP - in learnpath::get_js_info(' . $item_id . ') - returning: ' . $info, 0);
  1455. }
  1456. return $info;
  1457. }
  1458. }
  1459. /**
  1460. * Gets the js library from the database
  1461. * @return string The name of the javascript library to be used
  1462. */
  1463. public function get_js_lib() {
  1464. $lib = '';
  1465. if (!empty ($this->js_lib)) {
  1466. $lib = $this->js_lib;
  1467. }
  1468. return $lib;
  1469. }
  1470. /**
  1471. * Gets the learnpath database ID
  1472. * @return integer Learnpath ID in the lp table
  1473. */
  1474. public function get_id() {
  1475. //if ($this->debug > 0) { error_log('New LP - In learnpath::get_id()', 0); }
  1476. if (!empty ($this->lp_id)) {
  1477. return $this->lp_id;
  1478. } else {
  1479. return 0;
  1480. }
  1481. }
  1482. /**
  1483. * Gets the last element URL.
  1484. * @return string URL to load into the viewer
  1485. */
  1486. public function get_last() {
  1487. if ($this->debug > 0) {
  1488. error_log('New LP - In learnpath::get_last()', 0);
  1489. }
  1490. $this->index = count($this->ordered_items) - 1;
  1491. return $this->ordered_items[$this->index];
  1492. }
  1493. /**
  1494. * Gets the navigation bar for the learnpath display screen
  1495. * @return string The HTML string to use as a navigation bar
  1496. */
  1497. public function get_navigation_bar() {
  1498. if ($this->debug > 0) {
  1499. error_log('New LP - In learnpath::get_navigation_bar()', 0);
  1500. }
  1501. // TODO: Find a good value for the following variables.
  1502. $file = '';
  1503. $openDir = '';
  1504. $edoceo = '';
  1505. $time = 0;
  1506. $navbar = '';
  1507. $RequestUri = '';
  1508. $mycurrentitemid = $this->get_current_item_id();
  1509. if ($this->mode == 'fullscreen') {
  1510. $navbar = '<table cellpadding="0" cellspacing="0" align="left">' . "\n" .
  1511. ' <tr> ' . "\n" .
  1512. ' <td>' . "\n" .
  1513. ' <div class="buttons">' . "\n" .
  1514. ' <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('Reporting') . '"></a>' . "\n" .
  1515. ' <a href="" onClick="switch_item(' . $mycurrentitemid . ',\'previous\');return false;" title="previous"><img border="0" src="../img/lp_leftarrow.gif" title="' . get_lang('ScormPrevious') . '"></a>' . "\n" .
  1516. ' <a href="" onClick="switch_item(' . $mycurrentitemid . ',\'next\');return false;" title="next" ><img border="0" src="../img/lp_rightarrow.gif" title="' . get_lang('ScormNext') . '"></a>' . "\n" .
  1517. //' <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" .
  1518. //' <a href="lp_controller.php?action=list" target="_top" title="learnpaths list"><img border="0" src="../img/exit.png" title="Exit"></a>'."\n" .
  1519. ' </div>' . "\n" .
  1520. ' </td>' . "\n" .
  1521. ' </tr>' . "\n" .
  1522. '</table>';
  1523. } else {
  1524. $navbar = '<table cellpadding="0" cellspacing="0" align="left">' . "\n" .
  1525. ' <tr> ' . "\n" .
  1526. ' <td>' . "\n" .
  1527. ' <div class="buttons">' . "\n" .
  1528. ' <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('Reporting') . '"></a>' . "\n" .
  1529. ' <a href="" onClick="switch_item(' . $mycurrentitemid . ',\'previous\');return false;" title="previous"><img border="0" src="../img/lp_leftarrow.gif" title="' . get_lang('ScormPrevious') . '"></a>' . "\n" .
  1530. ' <a href="" onClick="switch_item(' . $mycurrentitemid . ',\'next\');return false;" title="next" ><img border="0" src="../img/lp_rightarrow.gif" title="' . get_lang('ScormNext') . '"></a>' . "\n" .
  1531. // ' <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" .
  1532. ' </div>' . "\n" .
  1533. ' </td>' . "\n" .
  1534. ' </tr>' . "\n" .
  1535. '</table>';
  1536. }
  1537. return $navbar;
  1538. }
  1539. /**
  1540. * Gets the next resource in queue (url).
  1541. * @return string URL to load into the viewer
  1542. */
  1543. public function get_next_index() {
  1544. if ($this->debug > 0) {
  1545. error_log('New LP - In learnpath::get_next_index()', 0);
  1546. }
  1547. // TODO
  1548. $index = $this->index;
  1549. $index++;
  1550. if ($this->debug > 2) {
  1551. error_log('New LP - Now looking at ordered_items[' . ($index) . '] - type is ' . $this->items[$this->ordered_items[$index]]->type, 0);
  1552. }
  1553. 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) {
  1554. $index++;
  1555. if ($index == $this->max_ordered_items){
  1556. if ($this->items[$this->ordered_items[$index]]->get_type() == 'dir' || $this->items[$this->ordered_items[$index]]->get_type() == 'dokeos_chapter') {
  1557. return $this->index;
  1558. } else {
  1559. return $index;
  1560. }
  1561. }
  1562. }
  1563. if (empty ($this->ordered_items[$index])) {
  1564. return $this->index;
  1565. }
  1566. if ($this->debug > 2) {
  1567. error_log('New LP - index is now ' . $index, 0);
  1568. }
  1569. return $index;
  1570. }
  1571. /**
  1572. * Gets item_id for the next element
  1573. * @return integer Next item (DB) ID
  1574. */
  1575. public function get_next_item_id() {
  1576. if ($this->debug > 0) {
  1577. error_log('New LP - In learnpath::get_next_item_id()', 0);
  1578. }
  1579. $new_index = $this->get_next_index();
  1580. if (!empty ($new_index)) {
  1581. if (isset ($this->ordered_items[$new_index])) {
  1582. if ($this->debug > 2) {
  1583. error_log('New LP - In learnpath::get_next_index() - Returning ' . $this->ordered_items[$new_index], 0);
  1584. }
  1585. return $this->ordered_items[$new_index];
  1586. }
  1587. }
  1588. if ($this->debug > 2) {
  1589. error_log('New LP - In learnpath::get_next_index() - Problem - Returning 0', 0);
  1590. }
  1591. return 0;
  1592. }
  1593. /**
  1594. * Returns the package type ('scorm','aicc','scorm2004','dokeos','ppt'...)
  1595. *
  1596. * Generally, the package provided is in the form of a zip file, so the function
  1597. * has been written to test a zip file. If not a zip, the function will return the
  1598. * default return value: ''
  1599. * @param string the path to the file
  1600. * @param string the original name of the file
  1601. * @return string 'scorm','aicc','scorm2004','dokeos' or '' if the package cannot be recognized
  1602. */
  1603. public function get_package_type($file_path, $file_name) {
  1604. // Get name of the zip file without the extension.
  1605. $file_info = pathinfo($file_name);
  1606. $filename = $file_info['basename']; // Name including extension.
  1607. $extension = $file_info['extension']; // Extension only.
  1608. if (!empty($_POST['ppt2lp']) && !in_array(strtolower($extension), array (
  1609. 'dll',
  1610. 'exe'
  1611. ))) {
  1612. return 'oogie';
  1613. }
  1614. if (!empty($_POST['woogie']) && !in_array(strtolower($extension), array (
  1615. 'dll',
  1616. 'exe'
  1617. ))) {
  1618. return 'woogie';
  1619. }
  1620. $file_base_name = str_replace('.' . $extension, '', $filename); // Filename without its extension.
  1621. $zipFile = new pclZip($file_path);
  1622. // Check the zip content (real size and file extension).
  1623. $zipContentArray = $zipFile->listContent();
  1624. $package_type = '';
  1625. $at_root = false;
  1626. $manifest = '';
  1627. // The following loop should be stopped as soon as we found the right imsmanifest.xml (how to recognize it?).
  1628. if (is_array($zipContentArray) && count($zipContentArray) > 0) {
  1629. foreach ($zipContentArray as $thisContent) {
  1630. if (preg_match('~.(php.*|phtml)$~i', $thisContent['filename'])) {
  1631. // New behaviour: Don't do anything. These files will be removed in scorm::import_package.
  1632. }
  1633. elseif (stristr($thisContent['filename'], 'imsmanifest.xml') !== false) {
  1634. $manifest = $thisContent['filename']; // Just the relative directory inside scorm/
  1635. $package_type = 'scorm';
  1636. break; // Exit the foreach loop.
  1637. }
  1638. elseif (preg_match('/aicc\//i', $thisContent['filename'])) {
  1639. // If found an aicc directory... (!= false means it cannot be false (error) or 0 (no match)).
  1640. $package_type = 'aicc';
  1641. //break; // Don't exit the loop, because if we find an imsmanifest afterwards, we want it, not the AICC.
  1642. } else {
  1643. $package_type = '';
  1644. }
  1645. }
  1646. }
  1647. return $package_type;
  1648. }
  1649. /**
  1650. * Gets the previous resource in queue (url). Also initialises time values for this viewing
  1651. * @return string URL to load into the viewer
  1652. */
  1653. public function get_previous_index() {
  1654. if ($this->debug > 0) {
  1655. error_log('New LP - In learnpath::get_previous_index()', 0);
  1656. }
  1657. $index = $this->index;
  1658. if (isset ($this->ordered_items[$index -1])) {
  1659. $index--;
  1660. 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')) {
  1661. $index--;
  1662. if ($index < 0) {
  1663. return $this->index;
  1664. }
  1665. }
  1666. } else {
  1667. if ($this->debug > 2) {
  1668. error_log('New LP - get_previous_index() - there was no previous index available, reusing ' . $index, 0);
  1669. }
  1670. // There is no previous item.
  1671. }
  1672. return $index;
  1673. }
  1674. /**
  1675. * Gets item_id for the next element
  1676. * @return integer Previous item (DB) ID
  1677. */
  1678. public function get_previous_item_id() {
  1679. if ($this->debug > 0) {
  1680. error_log('New LP - In learnpath::get_previous_item_id()', 0);
  1681. }
  1682. $new_index = $this->get_previous_index();
  1683. return $this->ordered_items[$new_index];
  1684. }
  1685. /**
  1686. * Gets the progress value from the progress_db attribute
  1687. * @return integer Current progress value
  1688. */
  1689. public function get_progress() {
  1690. if ($this->debug > 0) {
  1691. error_log('New LP - In learnpath::get_progress()', 0);
  1692. }
  1693. if (!empty ($this->progress_db)) {
  1694. return $this->progress_db;
  1695. }
  1696. return 0;
  1697. }
  1698. /**
  1699. * Gets the progress value from the progress field in the database (allows use as abstract method)
  1700. * @param integer Learnpath ID
  1701. * @param integer User ID
  1702. * @param string Mode of display ('%','abs' or 'both')
  1703. * @param string Course database name (optional, defaults to '')
  1704. * @param boolean Whether to return null if no record was found (true), or 0 (false) (optional, defaults to false)
  1705. * @return integer Current progress value as found in the database
  1706. */
  1707. public function get_db_progress($lp_id, $user_id, $mode = '%', $course_db = '', $sincere = false,$session_id = 0) {
  1708. //if ($this->debug > 0) { error_log('New LP - In learnpath::get_db_progress()', 0); }
  1709. $session_id = intval($session_id);
  1710. $session_condition = api_get_session_condition($session_id);
  1711. $table = Database :: get_course_table(TABLE_LP_VIEW, $course_db);
  1712. $sql = "SELECT * FROM $table WHERE lp_id = $lp_id AND user_id = $user_id $session_condition";
  1713. $res = Database::query($sql);
  1714. $view_id = 0;
  1715. if (Database :: num_rows($res) > 0) {
  1716. $row = Database :: fetch_array($res);
  1717. $progress = $row['progress'];
  1718. $view_id = $row['id'];
  1719. } else {
  1720. if ($sincere) {
  1721. return null;
  1722. }
  1723. }
  1724. if (empty ($progress)) {
  1725. $progress = '0';
  1726. }
  1727. if ($mode == '%') {
  1728. return $progress . '%';
  1729. } else {
  1730. // Get the number of items completed and the number of items total.
  1731. $tbl = Database :: get_course_table(TABLE_LP_ITEM, $course_db);
  1732. $sql = "SELECT count(*) FROM $tbl WHERE lp_id = " . $lp_id . "
  1733. AND item_type NOT IN('dokeos_chapter','chapter','dir')";
  1734. $res = Database::query($sql);
  1735. $row = Database :: fetch_array($res);
  1736. $total = $row[0];
  1737. $tbl_item_view = Database :: get_course_table(TABLE_LP_ITEM_VIEW, $course_db);
  1738. $tbl_item = Database :: get_course_table(TABLE_LP_ITEM, $course_db);
  1739. //$sql = "SELECT count(distinct(lp_item_id)) FROM $tbl WHERE lp_view_id = ".$view_id." AND status IN ('passed','completed','succeeded')";
  1740. // Trying as also counting browsed and failed items.
  1741. $sql = "SELECT count(distinct(lp_item_id))
  1742. FROM $tbl_item_view as item_view
  1743. INNER JOIN $tbl_item as item
  1744. ON item.id = item_view.lp_item_id
  1745. AND item_type NOT IN('dokeos_chapter','chapter','dir')
  1746. WHERE lp_view_id = " . $view_id . "
  1747. AND status IN ('passed','completed','succeeded','browsed','failed')"; //echo '<br />';
  1748. $res = Database::query($sql);
  1749. $row = Database :: fetch_array($res);
  1750. $completed = $row[0];
  1751. if ($mode == 'abs') {
  1752. return $completed . '/' . $total;
  1753. }
  1754. elseif ($mode == 'both') {
  1755. if ($progress < ($completed / ($total ? $total : 1))) {
  1756. $progress = number_format(($completed / ($total ? $total : 1)) * 100, 0);
  1757. }
  1758. return $progress . '% (' . $completed . '/' . $total . ')';
  1759. }
  1760. }
  1761. return $progress;
  1762. }
  1763. /**
  1764. * Returns the HTML necessary to print a mediaplayer block inside a page
  1765. * @return string The mediaplayer HTML
  1766. */
  1767. public function get_mediaplayer($autostart='true') {
  1768. global $_course;
  1769. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  1770. $tbl_lp_item_view = Database :: get_course_table(TABLE_LP_ITEM_VIEW);
  1771. // Getting all the information about the item.
  1772. $sql = "SELECT * FROM " . $tbl_lp_item . " as lp inner join " . $tbl_lp_item_view . " as lp_view on lp.id = lp_view.lp_item_id " .
  1773. "WHERE lp.id = '" . $_SESSION['oLP']->current . "'";
  1774. $result = Database::query($sql);
  1775. $row = Database::fetch_assoc($result);
  1776. $output = '';
  1777. if (!empty ($row['audio'])) {
  1778. $list = $_SESSION['oLP']->get_toc();
  1779. $type_quiz = false;
  1780. foreach($list as $toc) {
  1781. if ($toc['id'] == $_SESSION['oLP']->current && ($toc['type']=='quiz') ) {
  1782. $type_quiz = true;
  1783. }
  1784. }
  1785. if ($type_quiz) {
  1786. if ($_SESSION['oLP']->prevent_reinit == 1) {
  1787. $row['status'] === 'completed' ? $autostart_audio = 'false' : $autostart_audio = 'true';
  1788. } else {
  1789. $autostart_audio = $autostart;
  1790. }
  1791. } else {
  1792. $autostart_audio = 'true';
  1793. }
  1794. // The mp3 player.
  1795. $output = '<div id="container">';
  1796. $output .= '<script type="text/javascript" src="../inc/lib/mediaplayer/swfobject.js"></script>';
  1797. $output .= '<script type="text/javascript">
  1798. var s1 = new SWFObject("../inc/lib/mediaplayer/player.swf","ply","250","20","9","#FFFFFF");
  1799. s1.addParam("allowscriptaccess","always");
  1800. s1.addParam("flashvars","file=' . api_get_path(WEB_COURSE_PATH) . $_course['path'] . '/document/audio/' . $row['audio'] . '&autostart=' . $autostart_audio.'");
  1801. s1.write("container");
  1802. </script></div>';
  1803. }
  1804. return $output;
  1805. }
  1806. /**
  1807. * This function checks if the learnpath is visible for student after the progress of its prerequisite is completed, and considering time availability
  1808. * @param int Learnpath id
  1809. * @param int Student id
  1810. * @param string Course code (optional)
  1811. * @return bool True if
  1812. */
  1813. public function is_lp_visible_for_student($lp_id, $student_id, $course = null) {
  1814. $lp_id = (int)$lp_id;
  1815. $course = api_get_course_info($course);
  1816. $tbl_learnpath = Database :: get_course_table(TABLE_LP_MAIN,$course['dbName']);
  1817. // Get current prerequisite
  1818. $sql = "SELECT id, prerequisite, publicated_on, expired_on FROM $tbl_learnpath WHERE id = $lp_id";
  1819. $rs = Database::query($sql);
  1820. $now = time();
  1821. if (Database::num_rows($rs)>0) {
  1822. $row = Database::fetch_array($rs, 'ASSOC');
  1823. $prerequisite = $row['prerequisite'];
  1824. $is_visible = true;
  1825. $progress = 0;
  1826. if (!empty($prerequisite)) {
  1827. $progress = self::get_db_progress($prerequisite,$student_id,'%', '', false, api_get_session_id());
  1828. $progress = intval($progress);
  1829. if ($progress < 100) {
  1830. $is_visible = false;
  1831. }
  1832. }
  1833. // Also check the time availability of the LP
  1834. if ($is_visible) {
  1835. //Adding visibility reestrinctions
  1836. if (!empty($row['publicated_on']) && $row['publicated_on'] != '0000-00-00 00:00:00') {
  1837. if ($now < api_strtotime($row['publicated_on'], 'UTC')) {
  1838. //api_not_allowed();
  1839. $is_visible = false;
  1840. }
  1841. }
  1842. //Blocking empty start times see BT#2800
  1843. /*
  1844. if (empty($row['publicated_on']) || $row['publicated_on'] == '0000-00-00 00:00:00') {
  1845. //api_not_allowed();
  1846. $is_visible = false;
  1847. }*/
  1848. if (!empty($row['expired_on']) && $row['expired_on'] != '0000-00-00 00:00:00') {
  1849. if ($now > api_strtotime($row['expired_on'], 'UTC')) {
  1850. //api_not_allowed();
  1851. $is_visible = false;
  1852. }
  1853. }
  1854. }
  1855. return $is_visible;
  1856. }
  1857. return false;
  1858. }
  1859. /**
  1860. * Gets a progress bar for the learnpath by counting the number of items in it and the number of items
  1861. * completed so far.
  1862. * @param string Mode in which we want the values
  1863. * @param integer Progress value to display (optional but mandatory if used in abstract context)
  1864. * @param string Text to display near the progress value (optional but mandatory in abstract context)
  1865. * @param boolean true if it comes from a Diplay LP view
  1866. * @return string HTML string containing the progress bar
  1867. */
  1868. public function get_progress_bar($mode = '', $percentage = -1, $text_add = '', $from_lp = false) {
  1869. //if ($this->debug > 0) {error_log('New LP - In learnpath::get_progress_bar('.$mode.','.$percentage.','.$text_add.','.$from_lp.')', 0); }
  1870. global $lp_theme_css;
  1871. // Setting up the CSS path of the current style if exists.
  1872. if (!empty ($lp_theme_css)) {
  1873. $css_path = api_get_path(WEB_CODE_PATH) . 'css/' . $lp_theme_css . '/images/';
  1874. } else {
  1875. $css_path = '../img/';
  1876. }
  1877. //if ($this->debug > 0) { error_log('New LP - In learnpath::get_progress_bar()', 0); }
  1878. if (isset($this) && is_object($this) && ($percentage == '-1' OR $text_add == '')) {
  1879. list($percentage, $text_add) = $this->get_progress_bar_text($mode);
  1880. }
  1881. $text = $percentage . $text_add;
  1882. // Default progress bar config
  1883. // times that will be greater or shorter
  1884. $factor = 1.2;
  1885. if ($from_lp)
  1886. $progress_height = '26';
  1887. else
  1888. $progress_height = '16';
  1889. $size = str_replace('%', '', $percentage);
  1890. $output ='<div style="width:135px">' .
  1891. '<img id="progress_img_limit_left" src="' . $css_path . 'bar_1.gif" width="1" height="' . $progress_height . '">' .
  1892. '<img id="progress_img_full" src="' . $css_path . 'bar_1u.gif" width="' . $size * $factor . 'px" height="' . $progress_height . '" id="full_portion">' .
  1893. '<img id="progress_img_limit_middle" src="' . $css_path . 'bar_1m.gif" width="1" height="' . $progress_height . '">';
  1894. if ($percentage <= 98) {
  1895. $output .= '<img id="progress_img_empty" src="' . $css_path . 'bar_1r.gif" width="' . (100 - $size) * $factor . 'px" height="' . $progress_height . '" id="empty_portion">';
  1896. } else {
  1897. $output .= '<img id="progress_img_empty" src="' . $css_path . 'bar_1r.gif" width="0" height="' . $progress_height . '" id="empty_portion">';
  1898. }
  1899. $output .= '<img id="progress_bar_img_limit_right" src="' . $css_path . 'bar_1.gif" width="1" height="' . $progress_height . '"></div>' .
  1900. '<div class="progresstext" id="progress_text">' . $text . '</div>';
  1901. return $output;
  1902. }
  1903. /**
  1904. * Gets the progress bar info to display inside the progress bar. Also used by scorm_api.php
  1905. * @param string Mode of display (can be '%' or 'abs').abs means we display a number of completed elements per total elements
  1906. * @param integer Additional steps to fake as completed
  1907. * @return list Percentage or number and symbol (% or /xx)
  1908. */
  1909. public function get_progress_bar_text($mode = '', $add = 0) {
  1910. if ($this->debug > 0) {
  1911. error_log('New LP - In learnpath::get_progress_bar_text()', 0);
  1912. }
  1913. if (empty ($mode)) {
  1914. $mode = $this->progress_bar_mode;
  1915. }
  1916. $total_items = $this->get_total_items_count_without_chapters();
  1917. if ($this->debug > 2) {
  1918. error_log('New LP - Total items available in this learnpath: ' . $total_items, 0);
  1919. }
  1920. $i = $this->get_complete_items_count();
  1921. if ($this->debug > 2) {
  1922. error_log('New LP - Items completed so far: ' . $i, 0);
  1923. }
  1924. if ($add != 0) {
  1925. $i += $add;
  1926. if ($this->debug > 2) {
  1927. error_log('New LP - Items completed so far (+modifier): ' . $i, 0);
  1928. }
  1929. }
  1930. $text = '';
  1931. if ($i > $total_items) {
  1932. $i = $total_items;
  1933. }
  1934. if ($mode == '%') {
  1935. if ($total_items > 0) {
  1936. $percentage = ((float) $i / (float) $total_items) * 100;
  1937. } else {
  1938. $percentage = 0;
  1939. }
  1940. $percentage = number_format($percentage, 0);
  1941. $text = '%';
  1942. }
  1943. elseif ($mode == 'abs') {
  1944. $percentage = $i;
  1945. $text = '/' . $total_items;
  1946. }
  1947. return array (
  1948. $percentage,
  1949. $text
  1950. );
  1951. }
  1952. /**
  1953. * Gets the progress bar mode
  1954. * @return string The progress bar mode attribute
  1955. */
  1956. public function get_progress_bar_mode() {
  1957. if ($this->debug > 0) {
  1958. error_log('New LP - In learnpath::get_progress_bar_mode()', 0);
  1959. }
  1960. if (!empty ($this->progress_bar_mode)) {
  1961. return $this->progress_bar_mode;
  1962. } else {
  1963. return '%';
  1964. }
  1965. }
  1966. /**
  1967. * Gets the learnpath proximity (remote or local)
  1968. * @return string Learnpath proximity
  1969. */
  1970. public function get_proximity() {
  1971. if ($this->debug > 0) {
  1972. error_log('New LP - In learnpath::get_proximity()', 0);
  1973. }
  1974. if (!empty ($this->proximity)) {
  1975. return $this->proximity;
  1976. } else {
  1977. return '';
  1978. }
  1979. }
  1980. /**
  1981. * Gets the learnpath theme (remote or local)
  1982. * @return string Learnpath theme
  1983. */
  1984. public function get_theme() {
  1985. if ($this->debug > 0) {
  1986. error_log('New LP - In learnpath::get_theme()', 0);
  1987. }
  1988. if (!empty ($this->theme)) {
  1989. return $this->theme;
  1990. } else {
  1991. return '';
  1992. }
  1993. }
  1994. /**
  1995. * Gets the learnpath session id
  1996. * @return string Learnpath theme
  1997. */
  1998. public function get_lp_session_id() {
  1999. if ($this->debug > 0) {
  2000. error_log('New LP - In learnpath::get_lp_session_id()', 0);
  2001. }
  2002. if (!empty ($this->lp_session_id)) {
  2003. return $this->lp_session_id;
  2004. } else {
  2005. return 0;
  2006. }
  2007. }
  2008. /**
  2009. * Gets the learnpath image
  2010. * @return string Web URL of the LP image
  2011. */
  2012. public function get_preview_image() {
  2013. if ($this->debug > 0) {
  2014. error_log('New LP - In learnpath::get_preview_image()', 0);
  2015. }
  2016. if (!empty ($this->preview_image)) {
  2017. return $this->preview_image;
  2018. } else {
  2019. return '';
  2020. }
  2021. }
  2022. /**
  2023. * Gets the learnpath author
  2024. * @return string LP's author
  2025. */
  2026. public function get_author() {
  2027. if ($this->debug > 0) {
  2028. error_log('New LP - In learnpath::get_author()', 0);
  2029. }
  2030. if (!empty ($this->author)) {
  2031. return $this->author;
  2032. } else {
  2033. return '';
  2034. }
  2035. }
  2036. /**
  2037. * Generate a new prerequisites string for a given item. If this item was a sco and
  2038. * its prerequisites were strings (instead of IDs), then transform those strings into
  2039. * IDs, knowing that SCORM IDs are kept in the "ref" field of the lp_item table.
  2040. * Prefix all item IDs that end-up in the prerequisites string by "ITEM_" to use the
  2041. * same rule as the scorm_export() method
  2042. * @param integer Item ID
  2043. * @return string Prerequisites string ready for the export as SCORM
  2044. */
  2045. public function get_scorm_prereq_string($item_id) {
  2046. if ($this->debug > 0) {
  2047. error_log('New LP - In learnpath::get_scorm_prereq_string()', 0);
  2048. }
  2049. if (!is_object($this->items[$item_id])) {
  2050. return false;
  2051. }
  2052. $oItem = $this->items[$item_id];
  2053. $prereq = $oItem->get_prereq_string();
  2054. if (empty ($prereq)) {
  2055. return '';
  2056. }
  2057. if (preg_match('/^\d+$/', $prereq) && is_object($this->items[$prereq])) { // If the prerequisite is a simple integer ID and this ID exists as an item ID,
  2058. // then simply return it (with the ITEM_ prefix).
  2059. return 'ITEM_' . $prereq;
  2060. } else {
  2061. if (isset ($this->refs_list[$prereq])) {
  2062. // It's a simple string item from which the ID can be found in the refs list,
  2063. // so we can transform it directly to an ID for export.
  2064. return 'ITEM_' . $this->refs_list[$prereq];
  2065. } else {
  2066. // The last case, if it's a complex form, then find all the IDs (SCORM strings)
  2067. // and replace them, one by one, by the internal IDs (chamilo db)
  2068. // TODO: Modify the '*' replacement to replace the multiplier in front of it
  2069. // by a space as well.
  2070. $find = array (
  2071. '&',
  2072. '|',
  2073. '~',
  2074. '=',
  2075. '<>',
  2076. '{',
  2077. '}',
  2078. '*',
  2079. '(',
  2080. ')'
  2081. );
  2082. $replace = array (
  2083. ' ',
  2084. ' ',
  2085. ' ',
  2086. ' ',
  2087. ' ',
  2088. ' ',
  2089. ' ',
  2090. ' ',
  2091. ' ',
  2092. ' '
  2093. );
  2094. $prereq_mod = str_replace($find, $replace, $prereq);
  2095. $ids = split(' ', $prereq_mod);
  2096. foreach ($ids as $id) {
  2097. $id = trim($id);
  2098. if (isset ($this->refs_list[$id])) {
  2099. $prereq = preg_replace('/[^a-zA-Z_0-9](' . $id . ')[^a-zA-Z_0-9]/', 'ITEM_' . $this->refs_list[$id], $prereq);
  2100. }
  2101. }
  2102. error_log('New LP - In learnpath::get_scorm_prereq_string(): returning modified string: ' . $prereq, 0);
  2103. return $prereq;
  2104. }
  2105. }
  2106. }
  2107. /**
  2108. * Returns the XML DOM document's node
  2109. * @param resource Reference to a list of objects to search for the given ITEM_*
  2110. * @param string The identifier to look for
  2111. * @return mixed The reference to the element found with that identifier. False if not found
  2112. */
  2113. public function get_scorm_xml_node(& $children, $id) {
  2114. for ($i = 0; $i < $children->length; $i++) {
  2115. $item_temp = $children->item($i);
  2116. if ($item_temp->nodeName == 'item') {
  2117. if ($item_temp->getAttribute('identifier') == $id) {
  2118. return $item_temp;
  2119. }
  2120. }
  2121. $subchildren = $item_temp->childNodes;
  2122. if ($subchildren->length > 0) {
  2123. $val = $this->get_scorm_xml_node($subchildren, $id);
  2124. if (is_object($val)) {
  2125. return $val;
  2126. }
  2127. }
  2128. }
  2129. return false;
  2130. }
  2131. /**
  2132. * Returns a usable array of stats related to the current learnpath and user
  2133. * @return array Well-formatted array containing status for the current learnpath
  2134. */
  2135. public function get_stats() {
  2136. if ($this->debug > 0) {
  2137. error_log('New LP - In learnpath::get_stats()', 0);
  2138. }
  2139. // TODO
  2140. }
  2141. /**
  2142. * Static method. Can be re-implemented by children. Gives an array of statistics for
  2143. * the given course (for all learnpaths and all users)
  2144. * @param string Course code
  2145. * @return array Well-formatted array containing status for the course's learnpaths
  2146. */
  2147. public function get_stats_course($course) {
  2148. //if ($this->debug > 0) { error_log('New LP - In learnpath::get_stats_course()', 0); }
  2149. // TODO
  2150. }
  2151. /**
  2152. * Static method. Can be re-implemented by children. Gives an array of statistics for
  2153. * the given course and learnpath (for all users)
  2154. * @param string Course code
  2155. * @param integer Learnpath ID
  2156. * @return array Well-formatted array containing status for the specified learnpath
  2157. */
  2158. public function get_stats_lp($course, $lp) {
  2159. //if ($this->debug > 0) { error_log('New LP - In learnpath::get_stats_lp()', 0); }
  2160. // TODO
  2161. }
  2162. /**
  2163. * Static method. Can be re-implemented by children. Gives an array of statistics for
  2164. * the given course, learnpath and user.
  2165. * @param string Course code
  2166. * @param integer Learnpath ID
  2167. * @param integer User ID
  2168. * @return array Well-formatted array containing status for the specified learnpath and user
  2169. */
  2170. public function get_stats_lp_user($course, $lp, $user) {
  2171. //if ($this->debug > 0) { error_log('New LP - In learnpath::get_stats_lp_user()', 0); }
  2172. // TODO
  2173. }
  2174. /**
  2175. * Static method. Can be re-implemented by children. Gives an array of statistics for
  2176. * the given course and learnpath (for all users)
  2177. * @param string Course code
  2178. * @param integer User ID
  2179. * @return array Well-formatted array containing status for the user's learnpaths
  2180. */
  2181. public function get_stats_user($course, $user) {
  2182. //if ($this->debug > 0) { error_log('New LP - In learnpath::get_stats_user()', 0); }
  2183. // TODO
  2184. }
  2185. /**
  2186. * Gets the status list for all LP's items
  2187. * @return array Array of [index] => [item ID => current status]
  2188. */
  2189. public function get_items_status_list() {
  2190. if ($this->debug > 0) {
  2191. error_log('New LP - In learnpath::get_items_status_list()', 0);
  2192. }
  2193. $list = array ();
  2194. foreach ($this->ordered_items as $item_id) {
  2195. $list[] = array (
  2196. $item_id => $this->items[$item_id]->get_status()
  2197. );
  2198. }
  2199. return $list;
  2200. }
  2201. /**
  2202. * Return the number of interactions for the given learnpath Item View ID.
  2203. * This method can be used as static.
  2204. * @param integer Item View ID
  2205. * @return integer Number of interactions
  2206. */
  2207. public function get_interactions_count_from_db($lp_iv_id = 0, $course_code = null) {
  2208. if (empty ($lp_iv_id)) {
  2209. return -1;
  2210. }
  2211. $course_info = api_get_course_info($course_code);
  2212. $table = Database :: get_course_table(TABLE_LP_IV_INTERACTION, $course_info['db_name']);
  2213. $sql = "SELECT count(*) FROM $table WHERE lp_iv_id = $lp_iv_id";
  2214. $res = Database::query($sql);
  2215. $row = Database :: fetch_array($res);
  2216. $num = $row[0];
  2217. return $num;
  2218. }
  2219. /**
  2220. * Return the interactions as an array for the given lp_iv_id.
  2221. * This method can be used as static.
  2222. * @param integer Learnpath Item View ID
  2223. * @return array
  2224. * @todo Transcode labels instead of switching to HTML (which requires to know the encoding of the LP)
  2225. */
  2226. public function get_iv_interactions_array($lp_iv_id = 0) {
  2227. $list = array ();
  2228. $table = Database :: get_course_table(TABLE_LP_IV_INTERACTION);
  2229. $sql = "SELECT * FROM $table WHERE lp_iv_id = $lp_iv_id ORDER BY order_id ASC";
  2230. $res = Database::query($sql);
  2231. $num = Database :: num_rows($res);
  2232. if ($num > 0) {
  2233. $list[] = array (
  2234. 'order_id' => api_htmlentities(get_lang('Order'), ENT_QUOTES),
  2235. 'id' => api_htmlentities(get_lang('InteractionID'), ENT_QUOTES),
  2236. 'type' => api_htmlentities(get_lang('Type'), ENT_QUOTES),
  2237. 'time' => api_htmlentities(get_lang('TimeFinished'), ENT_QUOTES),
  2238. 'correct_responses' => api_htmlentities(get_lang('CorrectAnswers'), ENT_QUOTES),
  2239. 'student_response' => api_htmlentities(get_lang('StudentResponse'), ENT_QUOTES),
  2240. 'result' => api_htmlentities(get_lang('Result'), ENT_QUOTES),
  2241. 'latency' => api_htmlentities(get_lang('LatencyTimeSpent'), ENT_QUOTES)
  2242. );
  2243. while ($row = Database :: fetch_array($res)) {
  2244. $list[] = array (
  2245. 'order_id' => ($row['order_id'] + 1),
  2246. 'id' => urldecode($row['interaction_id']), //urldecode because they often have %2F or stuff like that
  2247. 'type' => $row['interaction_type'],
  2248. 'time' => $row['completion_time'],
  2249. //'correct_responses' => $row['correct_responses'],
  2250. 'correct_responses' => '', // Hide correct responses from students.
  2251. 'student_response' => $row['student_response'],
  2252. 'result' => $row['result'],
  2253. 'latency' => $row['latency']
  2254. );
  2255. }
  2256. }
  2257. return $list;
  2258. }
  2259. /**
  2260. * Return the number of objectives for the given learnpath Item View ID.
  2261. * This method can be used as static.
  2262. * @param integer Item View ID
  2263. * @return integer Number of objectives
  2264. */
  2265. public function get_objectives_count_from_db($lp_iv_id = 0, $course_code = null) {
  2266. if (empty ($lp_iv_id)) {
  2267. return -1;
  2268. }
  2269. $course_info = api_get_course_info($course_code);
  2270. $table = Database :: get_course_table(TABLE_LP_IV_OBJECTIVE, $course_info['db_name']);
  2271. $sql = "SELECT count(*) FROM $table WHERE lp_iv_id = $lp_iv_id";
  2272. $res = Database::query($sql);
  2273. $row = Database :: fetch_array($res);
  2274. $num = $row[0];
  2275. return $num;
  2276. }
  2277. /**
  2278. * Return the objectives as an array for the given lp_iv_id.
  2279. * This method can be used as static.
  2280. * @param integer Learnpath Item View ID
  2281. * @return array
  2282. * @todo Translate labels
  2283. */
  2284. public function get_iv_objectives_array($lp_iv_id = 0) {
  2285. $list = array();
  2286. $table = Database :: get_course_table(TABLE_LP_IV_OBJECTIVE);
  2287. $sql = "SELECT * FROM $table WHERE lp_iv_id = $lp_iv_id ORDER BY order_id ASC";
  2288. $res = Database::query($sql);
  2289. $num = Database :: num_rows($res);
  2290. if ($num > 0) {
  2291. $list[] = array (
  2292. 'order_id' => api_htmlentities(get_lang('Order'), ENT_QUOTES),
  2293. 'objective_id' => api_htmlentities(get_lang('ObjectiveID'), ENT_QUOTES),
  2294. 'score_raw' => api_htmlentities(get_lang('ObjectiveRawScore'), ENT_QUOTES),
  2295. 'score_max' => api_htmlentities(get_lang('ObjectiveMaxScore'), ENT_QUOTES),
  2296. 'score_min' => api_htmlentities(get_lang('ObjectiveMinScore'), ENT_QUOTES),
  2297. 'status' => api_htmlentities(get_lang('ObjectiveStatus'), ENT_QUOTES)
  2298. );
  2299. while ($row = Database :: fetch_array($res)) {
  2300. $list[] = array (
  2301. 'order_id' => ($row['order_id'] + 1),
  2302. 'objective_id' => urldecode($row['objective_id']), // urldecode() because they often have %2F or stuff like that.
  2303. 'score_raw' => $row['score_raw'],
  2304. 'score_max' => $row['score_max'],
  2305. 'score_min' => $row['score_min'],
  2306. 'status' => $row['status']
  2307. );
  2308. }
  2309. }
  2310. return $list;
  2311. }
  2312. /**
  2313. * Generate and return the table of contents for this learnpath. The (flat) table returned can be
  2314. * used by get_html_toc() to be ready to display
  2315. * @return array TOC as a table with 4 elements per row: title, link, status and level
  2316. */
  2317. public function get_toc() {
  2318. if ($this->debug > 0) {
  2319. error_log('New LP - In learnpath::get_toc()', 0);
  2320. }
  2321. $toc = array ();
  2322. //echo "<pre>".print_r($this->items,true)."</pre>";
  2323. foreach ($this->ordered_items as $item_id) {
  2324. if ($this->debug > 2) {
  2325. error_log('New LP - learnpath::get_toc(): getting info for item ' . $item_id, 0);
  2326. }
  2327. // TODO: Change this link generation and use new function instead.
  2328. $toc[] = array (
  2329. 'id' => $item_id,
  2330. 'title' => $this->items[$item_id]->get_title(),
  2331. //'link' => get_addedresource_link_in_learnpath('document', $item_id, 1),
  2332. 'status' => $this->items[$item_id]->get_status(),
  2333. 'level' => $this->items[$item_id]->get_level(),
  2334. 'type' => $this->items[$item_id]->get_type(),
  2335. 'description' => $this->items[$item_id]->get_description(),
  2336. 'path' => $this->items[$item_id]->get_path(),
  2337. );
  2338. }
  2339. if ($this->debug > 2) {
  2340. error_log('New LP - In learnpath::get_toc() - TOC array: ' . print_r($toc, true), 0);
  2341. }
  2342. return $toc;
  2343. }
  2344. /**
  2345. * Generate and return the table of contents for this learnpath. The JS
  2346. * table returned is used inside of scorm_api.php
  2347. * @return string A JS array vairiable construction
  2348. */
  2349. public function get_items_details_as_js($varname = 'olms.lms_item_types') {
  2350. if ($this->debug > 0) {
  2351. error_log('New LP - In learnpath::get_items_details_as_js()', 0);
  2352. }
  2353. $toc = $varname.' = new Array();';
  2354. //echo "<pre>".print_r($this->items,true)."</pre>";
  2355. foreach ($this->ordered_items as $item_id) {
  2356. if ($this->debug > 2) {
  2357. error_log('New LP - learnpath::get_items_details_as_js(): getting info for item ' . $item_id, 0);
  2358. }
  2359. $toc.= $varname."['i$item_id'] = '".$this->items[$item_id]->get_type()."';";
  2360. }
  2361. if ($this->debug > 2) {
  2362. error_log('New LP - In learnpath::get_items_details_as_js() - TOC array: ' . print_r($toc, true), 0);
  2363. }
  2364. return $toc;
  2365. }
  2366. /**
  2367. * Gets the learning path type
  2368. * @param boolean Return the name? If false, return the ID. Default is false.
  2369. * @return mixed Type ID or name, depending on the parameter
  2370. */
  2371. public function get_type($get_name = false) {
  2372. $res = false;
  2373. if ($this->debug > 0) {
  2374. error_log('New LP - In learnpath::get_type()', 0);
  2375. }
  2376. if (!empty ($this->type)) {
  2377. if ($get_name) {
  2378. // Get it from the lp_type table in main db.
  2379. } else {
  2380. $res = $this->type;
  2381. }
  2382. }
  2383. if ($this->debug > 2) {
  2384. error_log('New LP - In learnpath::get_type() - Returning ' . ($res ? $res : 'false'), 0);
  2385. }
  2386. return $res;
  2387. }
  2388. /**
  2389. * Gets the learning path type as static method
  2390. * @param boolean Return the name? If false, return the ID. Default is false.
  2391. * @return mixed Type ID or name, depending on the parameter
  2392. */
  2393. public function get_type_static($lp_id = 0) {
  2394. $tbl_lp = Database :: get_course_table(TABLE_LP_MAIN);
  2395. $sql = "SELECT lp_type FROM $tbl_lp WHERE id = '" . $lp_id . "'";
  2396. $res = Database::query($sql);
  2397. if ($res === false) {
  2398. return null;
  2399. }
  2400. if (Database :: num_rows($res) <= 0) {
  2401. return null;
  2402. }
  2403. $row = Database :: fetch_array($res);
  2404. return $row['lp_type'];
  2405. }
  2406. /**
  2407. * Gets a flat list of item IDs ordered for display (level by level ordered by order_display)
  2408. * This method can be used as abstract and is recursive
  2409. * @param integer Learnpath ID
  2410. * @param integer Parent ID of the items to look for
  2411. * @return mixed Ordered list of item IDs or false on error
  2412. */
  2413. public function get_flat_ordered_items_list($lp, $parent = 0, $course_db = '') {
  2414. //if ($this->debug > 0) { error_log('New LP - In learnpath::get_flat_ordered_items_list('.$lp.','.$parent.')', 0); }
  2415. $list = array();
  2416. if (empty ($lp)) {
  2417. return false;
  2418. }
  2419. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM, $course_db);
  2420. $sql = "SELECT * FROM $tbl_lp_item WHERE lp_id = $lp AND parent_item_id = $parent ORDER BY display_order";
  2421. $res = Database::query($sql);
  2422. while ($row = Database :: fetch_array($res)) {
  2423. $sublist = learnpath :: get_flat_ordered_items_list($lp, $row['id'], $course_db);
  2424. $list[] = $row['id'];
  2425. foreach ($sublist as $item) {
  2426. $list[] = $item;
  2427. }
  2428. }
  2429. return $list;
  2430. }
  2431. /**
  2432. * Uses the table generated by get_toc() and returns an HTML-formatted string ready to display
  2433. * @return string HTML TOC ready to display
  2434. */
  2435. public function get_html_toc() {
  2436. $is_allowed_to_edit = api_is_allowed_to_edit(null, true);
  2437. $charset = api_get_system_encoding();
  2438. $display_action_links_with_icons = false;
  2439. if ($this->debug > 0) {
  2440. error_log('New LP - In learnpath::get_html_toc()', 0);
  2441. }
  2442. $list = $this->get_toc();
  2443. //echo $this->current;
  2444. //$parent = $this->items[$this->current]->get_parent();
  2445. //if (empty($parent)) { $parent = $this->ordered_items[$this->items[$this->current]->get_previous_index()]; }
  2446. $html = '<div id="scorm_title" class="scorm_title"><div class="scorm_title_text">' . Security::remove_XSS($this->get_name()) . '</div></div>';
  2447. // Build, display.
  2448. if ($is_allowed_to_edit) {
  2449. $gradebook = Security :: remove_XSS($_GET['gradebook']);
  2450. if ($this->get_lp_session_id() == api_get_session_id()) {
  2451. $html .= '<div id="actions_lp" class="actions_lp">';
  2452. if ($display_action_links_with_icons) {
  2453. $html .= '<div style = "text-align:center;">';
  2454. $html .= "<a href='lp_controller.php?" . api_get_cidreq() . "&amp;action=build&amp;lp_id=" . $this->lp_id . "' target='_parent'>" . Display :: return_icon('build_learnpath.png', get_lang('Build'),'','32')."</a>";
  2455. $html .= "<a href='lp_controller.php?" . api_get_cidreq() . "&amp;action=admin_view&amp;lp_id=" . $this->lp_id . "' target='_parent'>" . Display :: return_icon('move_learnpath.png', get_lang('BasicOverview'),'','32')."</a>";
  2456. $html .= '<span>' . Display :: return_icon('view_remove_na.png', get_lang('Display'),'','32').'</span><br />';
  2457. $html .= '<a href="lp_controller.php?' . api_get_cidreq() . '">'. get_lang('ReturnToLPList') . '</a>';
  2458. $html .= '</div>';
  2459. } else {
  2460. $html .= '<div style = "text-align:center;">';
  2461. $html .= "<a href='lp_controller.php?" . api_get_cidreq() . "&amp;gradebook=$gradebook&amp;action=build&amp;lp_id=" . $this->lp_id . "' target='_parent'>" . get_lang('Build') . "</a>";
  2462. $html .= "<a href='lp_controller.php?" . api_get_cidreq() . "&amp;action=admin_view&amp;lp_id=" . $this->lp_id . "' target='_parent'>" . get_lang('BasicOverview') . "</a>";
  2463. $html .= '<span><b>' . get_lang('Display') . '</b></span><br />';
  2464. $html .= '<a href="lp_controller.php?' . api_get_cidreq() . '">'. get_lang('ReturnToLPList') . '</a>';
  2465. $html .= '</div>';
  2466. }
  2467. $html .= '</div>';
  2468. }
  2469. }
  2470. $html .= '<div id="inner_lp_toc" class="inner_lp_toc">';
  2471. require_once 'resourcelinker.inc.php';
  2472. // Temporary variables.
  2473. $mycurrentitemid = $this->get_current_item_id();
  2474. $color_counter = 0;
  2475. $i = 0;
  2476. foreach ($list as $item) {
  2477. if ($this->debug > 2) {
  2478. error_log('New LP - learnpath::get_html_toc(): using item ' . $item['id'], 0);
  2479. }
  2480. // TODO: Complete this.
  2481. $icon_name = array (
  2482. 'not attempted' => '../img/notattempted.gif',
  2483. 'incomplete' => '../img/incomplete.png',
  2484. 'failed' => '../img/delete.png',
  2485. 'completed' => '../img/completed.png',
  2486. 'passed' => '../img/passed.png',
  2487. 'succeeded' => '../img/succeeded.png',
  2488. 'browsed' => '../img/completed.png',
  2489. );
  2490. $style = 'scorm_item';
  2491. $scorm_color_background = 'scorm_item';
  2492. $style_item = 'scorm_item';
  2493. $current = false;
  2494. if ($item['id'] == $this->current) {
  2495. $style = 'scorm_item_highlight';
  2496. $scorm_color_background = 'scorm_item_highlight';
  2497. } else {
  2498. if ($color_counter % 2 == 0) {
  2499. $scorm_color_background = 'scorm_item_1';
  2500. } else {
  2501. $scorm_color_background = 'scorm_item_2';
  2502. }
  2503. if ($item['type'] == 'dokeos_module' || $item['type'] == 'dokeos_chapter') {
  2504. $scorm_color_background =' scorm_item_section ';
  2505. }
  2506. }
  2507. if ($scorm_color_background != '') {
  2508. $html .= '<div id="toc_' . $item['id'] . '" class="' . $scorm_color_background . '">';
  2509. }
  2510. // The anchor will let us center the TOC on the currently viewed item &^D
  2511. if ($item['type'] != 'dokeos_module' && $item['type'] != 'dokeos_chapter') {
  2512. $html .= '<a name="atoc_' . $item['id'] . '" />';
  2513. $html .= '<div class="' . $style_item . '" style="padding-left: ' . ($item['level'] * 1.5) . 'em; padding-right:' . ($item['level'] / 2) . 'em" title="' . $item['description'] . '" >';
  2514. } else {
  2515. $html .= '<div class="' . $style_item . '" style="padding-left: ' . ($item['level'] * 2) . 'em; padding-right:' . ($item['level'] * 1.5) . 'em" title="' . $item['description'] . '" >';
  2516. }
  2517. $title = $item['title'];
  2518. if (empty ($title)) {
  2519. $title = rl_get_resource_name(api_get_course_id(), $this->get_id(), $item['id']);
  2520. }
  2521. $title = Security::remove_XSS($title);
  2522. if ($item['type'] != 'dokeos_chapter' && $item['type'] != 'dir' && $item['type'] != 'dokeos_module') {
  2523. //$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>" ;
  2524. $url = $this->get_link('http', $item['id']);
  2525. //$html .= '<a href="'.$url.'" target="content_name" onClick="top.load_item('.$item['id'].',\''.$url.'\');">'.$title.'</a>' ;
  2526. //$html .= '<a href="" onClick="top.load_item('.$item['id'].',\''.$url.'\');return false;">'.$title.'</a>' ;
  2527. //<img align="absbottom" width="13" height="13" src="../img/lp_document.png">&nbsp;background:#aaa;
  2528. $html .= '<a href="" onClick="switch_item(' .$mycurrentitemid . ',' .$item['id'] . ');' .'return false;" >' . stripslashes($title) . '</a>';
  2529. } elseif ($item['type'] == 'dokeos_module' || $item['type'] == 'dokeos_chapter') {
  2530. $html .= "<img align='absbottom' width='13' height='13' src='../img/lp_dokeos_module.png'>&nbsp;" . stripslashes($title);
  2531. } elseif ($item['type'] == 'dir') {
  2532. $html .= stripslashes($title);
  2533. }
  2534. $tbl_track_e_exercises = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
  2535. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  2536. $user_id = api_get_user_id();
  2537. $course_id = api_get_course_id();
  2538. $sql = "SELECT path FROM $tbl_track_e_exercises, $tbl_lp_item
  2539. WHERE path = '" . $item['path'] . "' AND exe_user_id = '$user_id' AND exe_cours_id = '$course_id' AND path = exe_exo_id AND status <> 'incomplete'";
  2540. $result = Database::query($sql);
  2541. $count = Database :: num_rows($result);
  2542. if ($item['type'] == 'quiz') {
  2543. if ($item['status'] == 'completed') {
  2544. $html .= "&nbsp;<img id='toc_img_" . $item['id'] . "' src='" . $icon_name[$item['status']] . "' alt='" . substr($item['status'], 0, 1) . "' width='14' />";
  2545. }
  2546. } else {
  2547. if ($item['type'] != 'dokeos_chapter' && $item['type'] != 'dokeos_module' && $item['type'] != 'dir') {
  2548. $html .= "&nbsp;<img id='toc_img_" . $item['id'] . "' src='" . $icon_name[$item['status']] . "' alt='" . substr($item['status'], 0, 1) . "' width='14' />";
  2549. }
  2550. }
  2551. $html .= "</div>";
  2552. if ($scorm_color_background != '') {
  2553. $html .= '</div>';
  2554. }
  2555. $color_counter++;
  2556. }
  2557. $html .= "</div>";
  2558. return $html;
  2559. }
  2560. /**
  2561. * Gets the learnpath maker name - generally the editor's name
  2562. * @return string Learnpath maker name
  2563. */
  2564. public function get_maker() {
  2565. if ($this->debug > 0) {
  2566. error_log('New LP - In learnpath::get_maker()', 0);
  2567. }
  2568. if (!empty ($this->maker)) {
  2569. return $this->maker;
  2570. } else {
  2571. return '';
  2572. }
  2573. }
  2574. /**
  2575. * Gets the user-friendly message stored in $this->message
  2576. * @return string Message
  2577. */
  2578. public function get_message() {
  2579. if ($this->debug > 0) {
  2580. error_log('New LP - In learnpath::get_message()', 0);
  2581. }
  2582. return $this->message;
  2583. }
  2584. /**
  2585. * Gets the learnpath name/title
  2586. * @return string Learnpath name/title
  2587. */
  2588. public function get_name() {
  2589. if ($this->debug > 0) {
  2590. error_log('New LP - In learnpath::get_name()', 0);
  2591. }
  2592. if (!empty ($this->name)) {
  2593. return $this->name;
  2594. } else {
  2595. return 'N/A';
  2596. }
  2597. }
  2598. /**
  2599. * Gets a link to the resource from the present location, depending on item ID.
  2600. * @param string Type of link expected
  2601. * @param integer Learnpath item ID
  2602. * @return string Link to the lp_item resource
  2603. */
  2604. public function get_link($type = 'http', $item_id = null) {
  2605. if ($this->debug > 0) {
  2606. error_log('New LP - In learnpath::get_link(' . $type . ',' . $item_id . ')', 0);
  2607. }
  2608. if (empty($item_id)) {
  2609. if ($this->debug > 2) {
  2610. error_log('New LP - In learnpath::get_link() - no item id given in learnpath::get_link(), using current: ' . $this->get_current_item_id(), 0);
  2611. }
  2612. $item_id = $this->get_current_item_id();
  2613. }
  2614. if (empty ($item_id)) {
  2615. if ($this->debug > 2) {
  2616. error_log('New LP - In learnpath::get_link() - no current item id found in learnpath object', 0);
  2617. }
  2618. //still empty, this means there was no item_id given and we are not in an object context or
  2619. //the object property is empty, return empty link
  2620. $item_id = $this->first();
  2621. return '';
  2622. }
  2623. $file = '';
  2624. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  2625. $lp_item_table = Database :: get_course_table(TABLE_LP_ITEM);
  2626. $lp_item_view_table = Database :: get_course_table(TABLE_LP_ITEM_VIEW);
  2627. $item_id = Database::escape_string($item_id);
  2628. $sel = "SELECT l.lp_type as ltype, l.path as lpath, li.item_type as litype, li.path as lipath, li.parameters as liparams " .
  2629. "FROM $lp_table l, $lp_item_table li WHERE li.id = $item_id AND li.lp_id = l.id";
  2630. if ($this->debug > 2) {
  2631. error_log('New LP - In learnpath::get_link() - selecting item ' . $sel, 0);
  2632. }
  2633. $res = Database::query($sel);
  2634. if (Database :: num_rows($res) > 0) {
  2635. $row = Database :: fetch_array($res);
  2636. $lp_type = $row['ltype'];
  2637. $lp_path = $row['lpath'];
  2638. $lp_item_type = $row['litype'];
  2639. $lp_item_path = $row['lipath'];
  2640. $lp_item_params = $row['liparams'];
  2641. if (empty ($lp_item_params) && strpos($lp_item_path, '?') !== false) {
  2642. list ($lp_item_path, $lp_item_params) = explode('?', $lp_item_path);
  2643. }
  2644. //$lp_item_params = '?'.$lp_item_params;
  2645. //add ? if none - left commented to give freedom to scorm implementation
  2646. //if(substr($lp_item_params,0,1)!='?'){
  2647. // $lp_item_params = '?'.$lp_item_params;
  2648. //}
  2649. $sys_course_path = api_get_path(SYS_COURSE_PATH) . api_get_course_path();
  2650. if ($type == 'http') {
  2651. $course_path = api_get_path(WEB_COURSE_PATH) . api_get_course_path(); //web path
  2652. } else {
  2653. $course_path = $sys_course_path; //system path
  2654. }
  2655. // Fixed issue BT#1272 - If the item type is a Chamilo Item (quiz, link, etc), then change the lp type to thread it as a normal Chamilo LP not a SCO.
  2656. if (in_array($lp_item_type, array('quiz', 'document', 'link', 'forum', 'thread', 'student_publication'))) {
  2657. $lp_type = 1;
  2658. }
  2659. // Now go through the specific cases to get the end of the path.
  2660. // @todo Use constants instead of int values.
  2661. switch ($lp_type) {
  2662. case 1 :
  2663. if ($lp_item_type == 'dokeos_chapter') {
  2664. $file = 'lp_content.php?type=dir';
  2665. } else {
  2666. require_once 'resourcelinker.inc.php';
  2667. $file = rl_get_resource_link_for_learnpath(api_get_course_id(), $this->get_id(), $item_id);
  2668. if ($lp_item_type == 'link') {
  2669. require_once api_get_path(LIBRARY_PATH).'link.lib.php';
  2670. if (is_youtube_link($file)) {
  2671. $src = get_youtube_video_id($file);
  2672. $file = 'embed.php?type=youtube&src='.$src;
  2673. }
  2674. } else {
  2675. // check how much attempts of a exercise exits in lp
  2676. $lp_item_id = $this->get_current_item_id();
  2677. $lp_view_id = $this->get_view_id();
  2678. $prevent_reinit = $this->items[$this->current]->get_prevent_reinit();
  2679. $list = $this->get_toc();
  2680. $type_quiz = false;
  2681. foreach ($list as $toc) {
  2682. if ($toc['id'] == $lp_item_id && ($toc['type'] == 'quiz')) {
  2683. $type_quiz = true;
  2684. }
  2685. }
  2686. if ($type_quiz) {
  2687. $lp_item_id = Database :: escape_string($lp_item_id);
  2688. $lp_view_id = Database :: escape_string($lp_view_id);
  2689. $sql = "SELECT count(*) FROM $lp_item_view_table WHERE lp_item_id='" . (int) $lp_item_id . "' AND lp_view_id ='" . (int) $lp_view_id . "' AND status='completed'";
  2690. $result = Database::query($sql);
  2691. $row_count = Database :: fetch_row($result);
  2692. $count_item_view = (int) $row_count[0];
  2693. $not_multiple_attempt = 0;
  2694. if ($prevent_reinit === 1 && $count_item_view > 0) {
  2695. $not_multiple_attempt = 1;
  2696. }
  2697. $file .= '&not_multiple_attempt=' . $not_multiple_attempt;
  2698. }
  2699. $tmp_array = explode('/', $file);
  2700. $document_name = $tmp_array[count($tmp_array) - 1];
  2701. if (strpos($document_name, '_DELETED_')) {
  2702. $file = 'blank.php?error=document_deleted';
  2703. }
  2704. }
  2705. }
  2706. break;
  2707. case 2 :
  2708. if ($this->debug > 2) {
  2709. error_log('New LP - In learnpath::get_link() ' . __LINE__ . ' - Item type: ' . $lp_item_type, 0);
  2710. }
  2711. if ($lp_item_type != 'dir') {
  2712. // Quite complex here:
  2713. // We want to make sure 'http://' (and similar) links can
  2714. // be loaded as is (withouth the Chamilo path in front) but
  2715. // some contents use this form: resource.htm?resource=http://blablabla
  2716. // which means we have to find a protocol at the path's start, otherwise
  2717. // it should not be considered as an external URL.
  2718. //if ($this->prerequisites_match($item_id)) {
  2719. if (preg_match('#^[a-zA-Z]{2,5}://#', $lp_item_path) != 0) {
  2720. if ($this->debug > 2) {
  2721. error_log('New LP - In learnpath::get_link() ' . __LINE__ . ' - Found match for protocol in ' . $lp_item_path, 0);
  2722. }
  2723. // Distant url, return as is.
  2724. $file = $lp_item_path;
  2725. } else {
  2726. if ($this->debug > 2) {
  2727. error_log('New LP - In learnpath::get_link() ' . __LINE__ . ' - No starting protocol in ' . $lp_item_path, 0);
  2728. }
  2729. // Prevent getting untranslatable urls.
  2730. $lp_item_path = preg_replace('/%2F/', '/', $lp_item_path);
  2731. $lp_item_path = preg_replace('/%3A/', ':', $lp_item_path);
  2732. // Prepare the path.
  2733. $file = $course_path . '/scorm/' . $lp_path . '/' . $lp_item_path;
  2734. // TODO: Fix this for urls with protocol header.
  2735. $file = str_replace('//', '/', $file);
  2736. $file = str_replace(':/', '://', $file);
  2737. if (substr($lp_path, -1) == '/') {
  2738. $lp_path = substr($lp_path, 0, -1);
  2739. }
  2740. if (!is_file(realpath($sys_course_path . '/scorm/' . $lp_path . '/' . $lp_item_path))) {
  2741. // if file not found.
  2742. $decoded = html_entity_decode($lp_item_path);
  2743. list ($decoded) = explode('?', $decoded);
  2744. if (!is_file(realpath($sys_course_path . '/scorm/' . $lp_path . '/' . $decoded))) {
  2745. require_once 'resourcelinker.inc.php';
  2746. $file = rl_get_resource_link_for_learnpath(api_get_course_id(), $this->get_id(), $item_id);
  2747. if (empty($file)) {
  2748. $file = 'blank.php?error=document_not_found';
  2749. } else {
  2750. $tmp_array = explode('/', $file);
  2751. $document_name = $tmp_array[count($tmp_array) - 1];
  2752. if (strpos($document_name, '_DELETED_')) {
  2753. $file = 'blank.php?error=document_deleted';
  2754. } else {
  2755. $file = 'blank.php?error=document_not_found';
  2756. }
  2757. }
  2758. } else {
  2759. $file = $course_path . '/scorm/' . $lp_path . '/' . $decoded;
  2760. }
  2761. }
  2762. }
  2763. //}else{
  2764. //prerequisites did not match
  2765. //$file = 'blank.php';
  2766. //}
  2767. // We want to use parameters if they were defined in the imsmanifest.
  2768. if ($file != 'blank.php') {
  2769. $file .= (strstr($file, '?') === false ? '?' : '') . $lp_item_params;
  2770. }
  2771. } else {
  2772. $file = 'lp_content.php?type=dir';
  2773. }
  2774. break;
  2775. case 3 :
  2776. if ($this->debug > 2) {
  2777. error_log('New LP - In learnpath::get_link() ' . __LINE__ . ' - Item type: ' . $lp_item_type, 0);
  2778. }
  2779. // Formatting AICC HACP append URL.
  2780. $aicc_append = '?aicc_sid=' . urlencode(session_id()) . '&aicc_url=' . urlencode(api_get_path(WEB_CODE_PATH) . 'newscorm/aicc_hacp.php') . '&';
  2781. if ($lp_item_type != 'dir') {
  2782. // Quite complex here:
  2783. // We want to make sure 'http://' (and similar) links can
  2784. // be loaded as is (withouth the Chamilo path in front) but
  2785. // some contents use this form: resource.htm?resource=http://blablabla
  2786. // which means we have to find a protocol at the path's start, otherwise
  2787. // it should not be considered as an external URL.
  2788. if (preg_match('#^[a-zA-Z]{2,5}://#', $lp_item_path) != 0) {
  2789. if ($this->debug > 2) {
  2790. error_log('New LP - In learnpath::get_link() ' . __LINE__ . ' - Found match for protocol in ' . $lp_item_path, 0);
  2791. }
  2792. // Distant url, return as is.
  2793. $file = $lp_item_path;
  2794. // Enabled and modified by Ivan Tcholakov, 16-OCT-2008.
  2795. /*
  2796. if (stristr($file,'<servername>') !== false) {
  2797. $file = str_replace('<servername>', $course_path.'/scorm/'.$lp_path.'/', $lp_item_path);
  2798. }
  2799. */
  2800. if (stripos($file, '<servername>') !== false) {
  2801. //$file = str_replace('<servername>',$course_path.'/scorm/'.$lp_path.'/',$lp_item_path);
  2802. $web_course_path = str_replace('https://', '', str_replace('http://', '', $course_path));
  2803. $file = str_replace('<servername>', $web_course_path . '/scorm/' . $lp_path, $lp_item_path);
  2804. }
  2805. //
  2806. $file .= $aicc_append;
  2807. } else {
  2808. if ($this->debug > 2) {
  2809. error_log('New LP - In learnpath::get_link() ' . __LINE__ . ' - No starting protocol in ' . $lp_item_path, 0);
  2810. }
  2811. // Prevent getting untranslatable urls.
  2812. $lp_item_path = preg_replace('/%2F/', '/', $lp_item_path);
  2813. $lp_item_path = preg_replace('/%3A/', ':', $lp_item_path);
  2814. // Prepare the path - lp_path might be unusable because it includes the "aicc" subdir name.
  2815. $file = $course_path . '/scorm/' . $lp_path . '/' . $lp_item_path;
  2816. // TODO: Fix this for urls with protocol header.
  2817. $file = str_replace('//', '/', $file);
  2818. $file = str_replace(':/', '://', $file);
  2819. $file .= $aicc_append;
  2820. }
  2821. } else {
  2822. $file = 'lp_content.php?type=dir';
  2823. }
  2824. break;
  2825. case 4 :
  2826. break;
  2827. default :
  2828. break;
  2829. }
  2830. }
  2831. if ($this->debug > 2) {
  2832. error_log('New LP - In learnpath::get_link() - returning "' . $file . '" from get_link', 0);
  2833. }
  2834. return $file;
  2835. }
  2836. /**
  2837. * Gets the latest usable view or generate a new one
  2838. * @param integer Optional attempt number. If none given, takes the highest from the lp_view table
  2839. * @return integer DB lp_view id
  2840. */
  2841. public function get_view($attempt_num = 0) {
  2842. if ($this->debug > 0) {
  2843. error_log('New LP - In learnpath::get_view()', 0);
  2844. }
  2845. $search = '';
  2846. // Use $attempt_num to enable multi-views management (disabled so far).
  2847. if ($attempt_num != 0 AND intval(strval($attempt_num)) == $attempt_num) {
  2848. $search = 'AND view_count = ' . $attempt_num;
  2849. }
  2850. // When missing $attempt_num, search for a unique lp_view record for this lp and user.
  2851. $lp_view_table = Database :: get_course_table(TABLE_LP_VIEW);
  2852. $sql = "SELECT id, view_count FROM $lp_view_table " .
  2853. "WHERE lp_id = " . $this->get_id() . " " .
  2854. "AND user_id = " . $this->get_user_id() . " " .
  2855. $search .
  2856. " ORDER BY view_count DESC";
  2857. $res = Database::query($sql);
  2858. if (Database :: num_rows($res) > 0) {
  2859. $row = Database :: fetch_array($res);
  2860. $this->lp_view_id = $row['id'];
  2861. } else {
  2862. // There is no database record, create one.
  2863. $sql = "INSERT INTO $lp_view_table(lp_id,user_id,view_count)" .
  2864. "VALUES (" . $this->get_id() . "," . $this->get_user_id() . ",1)";
  2865. $res = Database::query($sql);
  2866. $id = Database :: insert_id();
  2867. $this->lp_view_id = $id;
  2868. }
  2869. return $this->lp_view_id;
  2870. }
  2871. /**
  2872. * Gets the current view id
  2873. * @return integer View ID (from lp_view)
  2874. */
  2875. public function get_view_id() {
  2876. if ($this->debug > 0) {
  2877. error_log('New LP - In learnpath::get_view_id()', 0);
  2878. }
  2879. if (!empty ($this->lp_view_id)) {
  2880. return $this->lp_view_id;
  2881. } else {
  2882. return 0;
  2883. }
  2884. }
  2885. /**
  2886. * Gets the update queue
  2887. * @return array Array containing IDs of items to be updated by JavaScript
  2888. */
  2889. public function get_update_queue() {
  2890. if ($this->debug > 0) {
  2891. error_log('New LP - In learnpath::get_update_queue()', 0);
  2892. }
  2893. return $this->update_queue;
  2894. }
  2895. /**
  2896. * Gets the user ID
  2897. * @return integer User ID
  2898. */
  2899. public function get_user_id() {
  2900. if ($this->debug > 0) {
  2901. error_log('New LP - In learnpath::get_user_id()', 0);
  2902. }
  2903. if (!empty ($this->user_id)) {
  2904. return $this->user_id;
  2905. } else {
  2906. return false;
  2907. }
  2908. }
  2909. /**
  2910. * Checks if any of the items has an audio element attached
  2911. * @return bool True or false
  2912. */
  2913. public function has_audio() {
  2914. if ($this->debug > 1) {
  2915. error_log('New LP - In learnpath::has_audio()', 0);
  2916. }
  2917. $has = false;
  2918. foreach ($this->items as $i => $item) {
  2919. if (!empty ($this->items[$i]->audio)) {
  2920. $has = true;
  2921. break;
  2922. }
  2923. }
  2924. return $has;
  2925. }
  2926. /**
  2927. * Logs a message into a file
  2928. * @param string Message to log
  2929. * @return boolean True on success, false on error or if msg empty
  2930. */
  2931. public function log($msg) {
  2932. if ($this->debug > 0) {
  2933. error_log('New LP - In learnpath::log()', 0);
  2934. }
  2935. // TODO
  2936. $this->error .= $msg;
  2937. return true;
  2938. }
  2939. /**
  2940. * Moves an item up and down at its level
  2941. * @param integer Item to move up and down
  2942. * @param string Direction 'up' or 'down'
  2943. * @return integer New display order, or false on error
  2944. */
  2945. public function move_item($id, $direction) {
  2946. if ($this->debug > 0) {
  2947. error_log('New LP - In learnpath::move_item(' . $id . ',' . $direction . ')', 0);
  2948. }
  2949. if (empty ($id) or empty ($direction)) {
  2950. return false;
  2951. }
  2952. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  2953. $sql_sel = "
  2954. SELECT *
  2955. FROM " . $tbl_lp_item . "
  2956. WHERE id = " . $id;
  2957. $res_sel = Database::query($sql_sel);
  2958. // Check if elem exists.
  2959. if (Database :: num_rows($res_sel) < 1) {
  2960. return false;
  2961. }
  2962. // Gather data.
  2963. $row = Database :: fetch_array($res_sel);
  2964. $previous = $row['previous_item_id'];
  2965. $next = $row['next_item_id'];
  2966. $display = $row['display_order'];
  2967. $parent = $row['parent_item_id'];
  2968. $lp = $row['lp_id'];
  2969. // Update the item (switch with previous/next one).
  2970. switch ($direction) {
  2971. case 'up' :
  2972. if ($this->debug > 2) {
  2973. error_log('Movement up detected', 0);
  2974. }
  2975. if ($display <= 1) { /*do nothing*/
  2976. } else {
  2977. $sql_sel2 = "SELECT *
  2978. FROM $tbl_lp_item
  2979. WHERE id = $previous";
  2980. if ($this->debug > 2) {
  2981. error_log('Selecting previous: ' . $sql_sel2, 0);
  2982. }
  2983. $res_sel2 = Database::query($sql_sel2);
  2984. if (Database :: num_rows($res_sel2) < 1) {
  2985. $previous_previous = 0;
  2986. }
  2987. // Gather data.
  2988. $row2 = Database :: fetch_array($res_sel2);
  2989. $previous_previous = $row2['previous_item_id'];
  2990. // Update previous_previous item (switch "next" with current).
  2991. if ($previous_previous != 0) {
  2992. $sql_upd2 = "UPDATE $tbl_lp_item SET next_item_id = $id WHERE id = $previous_previous";
  2993. if ($this->debug > 2) {
  2994. error_log($sql_upd2, 0);
  2995. }
  2996. $res_upd2 = Database::query($sql_upd2);
  2997. }
  2998. // Update previous item (switch with current).
  2999. if ($previous != 0) {
  3000. $sql_upd2 = "UPDATE $tbl_lp_item SET next_item_id = $next, previous_item_id = $id, display_order = display_order +1 WHERE id = $previous";
  3001. if ($this->debug > 2) {
  3002. error_log($sql_upd2, 0);
  3003. }
  3004. $res_upd2 = Database::query($sql_upd2);
  3005. }
  3006. // Update current item (switch with previous).
  3007. if ($id != 0) {
  3008. $sql_upd2 = "UPDATE $tbl_lp_item SET next_item_id = $previous, previous_item_id = $previous_previous, display_order = display_order-1 WHERE id = $id";
  3009. if ($this->debug > 2) {
  3010. error_log($sql_upd2, 0);
  3011. }
  3012. $res_upd2 = Database::query($sql_upd2);
  3013. }
  3014. // Update next item (new previous item).
  3015. if ($next != 0) {
  3016. $sql_upd2 = "UPDATE $tbl_lp_item SET previous_item_id = $previous WHERE id = $next";
  3017. if ($this->debug > 2) {
  3018. error_log($sql_upd2, 0);
  3019. }
  3020. $res_upd2 = Database::query($sql_upd2);
  3021. }
  3022. $display = $display -1;
  3023. }
  3024. break;
  3025. case 'down' :
  3026. if ($this->debug > 2) {
  3027. error_log('Movement down detected', 0);
  3028. }
  3029. if ($next == 0) { /* Do nothing. */
  3030. } else {
  3031. $sql_sel2 = "SELECT * FROM $tbl_lp_item WHERE id = $next";
  3032. if ($this->debug > 2) {
  3033. error_log('Selecting next: ' . $sql_sel2, 0);
  3034. }
  3035. $res_sel2 = Database::query($sql_sel2);
  3036. if (Database :: num_rows($res_sel2) < 1) {
  3037. $next_next = 0;
  3038. }
  3039. // Gather data.
  3040. $row2 = Database :: fetch_array($res_sel2);
  3041. $next_next = $row2['next_item_id'];
  3042. // Update previous item (switch with current).
  3043. if ($previous != 0) {
  3044. $sql_upd2 = "UPDATE $tbl_lp_item SET next_item_id = $next WHERE id = $previous";
  3045. $res_upd2 = Database::query($sql_upd2);
  3046. }
  3047. // Update current item (switch with previous).
  3048. if ($id != 0) {
  3049. $sql_upd2 = "UPDATE $tbl_lp_item SET previous_item_id = $next, next_item_id = $next_next, display_order = display_order+1 WHERE id = $id";
  3050. $res_upd2 = Database::query($sql_upd2);
  3051. }
  3052. // Update next item (new previous item).
  3053. if ($next != 0) {
  3054. $sql_upd2 = "UPDATE $tbl_lp_item SET previous_item_id = $previous, next_item_id = $id, display_order = display_order-1 WHERE id = $next";
  3055. $res_upd2 = Database::query($sql_upd2);
  3056. }
  3057. // Update next_next item (switch "previous" with current).
  3058. if ($next_next != 0) {
  3059. $sql_upd2 = "UPDATE $tbl_lp_item SET previous_item_id = $id WHERE id = $next_next";
  3060. $res_upd2 = Database::query($sql_upd2);
  3061. }
  3062. $display = $display +1;
  3063. }
  3064. break;
  3065. default :
  3066. return false;
  3067. }
  3068. return $display;
  3069. }
  3070. /**
  3071. * Move a learnpath up (display_order)
  3072. * @param integer Learnpath ID
  3073. */
  3074. public function move_up($lp_id) {
  3075. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3076. $sql = "SELECT * FROM $lp_table ORDER BY display_order";
  3077. $res = Database::query($sql);
  3078. if ($res === false)
  3079. return false;
  3080. $lps = array ();
  3081. $lp_order = array ();
  3082. $num = Database :: num_rows($res);
  3083. // First check the order is correct, globally (might be wrong because
  3084. // of versions < 1.8.4)
  3085. if ($num > 0) {
  3086. $i = 1;
  3087. while ($row = Database :: fetch_array($res)) {
  3088. if ($row['display_order'] != $i) { // If we find a gap in the order, we need to fix it.
  3089. $need_fix = true;
  3090. $sql_u = "UPDATE $lp_table SET display_order = $i WHERE id = " . $row['id'];
  3091. $res_u = Database::query($sql_u);
  3092. }
  3093. $row['display_order'] = $i;
  3094. $lps[$row['id']] = $row;
  3095. $lp_order[$i] = $row['id'];
  3096. $i++;
  3097. }
  3098. }
  3099. if ($num > 1) { // If there's only one element, no need to sort.
  3100. $order = $lps[$lp_id]['display_order'];
  3101. if ($order > 1) { // If it's the first element, no need to move up.
  3102. $sql_u1 = "UPDATE $lp_table SET display_order = $order WHERE id = " . $lp_order[$order - 1];
  3103. $res_u1 = Database::query($sql_u1);
  3104. $sql_u2 = "UPDATE $lp_table SET display_order = " . ($order - 1) . " WHERE id = " . $lp_id;
  3105. $res_u2 = Database::query($sql_u2);
  3106. }
  3107. }
  3108. }
  3109. /**
  3110. * Move a learnpath down (display_order)
  3111. * @param integer Learnpath ID
  3112. */
  3113. public function move_down($lp_id) {
  3114. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3115. $sql = "SELECT * FROM $lp_table ORDER BY display_order";
  3116. $res = Database::query($sql);
  3117. if ($res === false)
  3118. return false;
  3119. $lps = array ();
  3120. $lp_order = array ();
  3121. $num = Database :: num_rows($res);
  3122. $max = 0;
  3123. // First check the order is correct, globally (might be wrong because
  3124. // of versions < 1.8.4).
  3125. if ($num > 0) {
  3126. $i = 1;
  3127. while ($row = Database :: fetch_array($res)) {
  3128. $max = $i;
  3129. if ($row['display_order'] != $i) { // If we find a gap in the order, we need to fix it.
  3130. $need_fix = true;
  3131. $sql_u = "UPDATE $lp_table SET display_order = $i WHERE id = " . $row['id'];
  3132. $res_u = Database::query($sql_u);
  3133. }
  3134. $row['display_order'] = $i;
  3135. $lps[$row['id']] = $row;
  3136. $lp_order[$i] = $row['id'];
  3137. $i++;
  3138. }
  3139. }
  3140. if ($num > 1) { // If there's only one element, no need to sort.
  3141. $order = $lps[$lp_id]['display_order'];
  3142. if ($order < $max) { // If it's the first element, no need to move up.
  3143. $sql_u1 = "UPDATE $lp_table SET display_order = $order WHERE id = " . $lp_order[$order + 1];
  3144. $res_u1 = Database::query($sql_u1);
  3145. $sql_u2 = "UPDATE $lp_table SET display_order = " . ($order + 1) . " WHERE id = " . $lp_id;
  3146. $res_u2 = Database::query($sql_u2);
  3147. }
  3148. }
  3149. }
  3150. /**
  3151. * Updates learnpath attributes to point to the next element
  3152. * The last part is similar to set_current_item but processing the other way around
  3153. */
  3154. public function next() {
  3155. if ($this->debug > 0) {
  3156. error_log('New LP - In learnpath::next()', 0);
  3157. }
  3158. $this->last = $this->get_current_item_id();
  3159. $this->items[$this->last]->save(false, $this->prerequisites_match($this->last));
  3160. $this->autocomplete_parents($this->last);
  3161. $new_index = $this->get_next_index();
  3162. if ($this->debug > 2) {
  3163. error_log('New LP - New index: ' . $new_index, 0);
  3164. }
  3165. $this->index = $new_index;
  3166. if ($this->debug > 2) {
  3167. error_log('New LP - Now having orderedlist[' . $new_index . '] = ' . $this->ordered_items[$new_index], 0);
  3168. }
  3169. $this->current = $this->ordered_items[$new_index];
  3170. if ($this->debug > 2) {
  3171. error_log('New LP - new item id is ' . $this->current . '-' . $this->get_current_item_id(), 0);
  3172. }
  3173. }
  3174. /**
  3175. * Open a resource = initialise all local variables relative to this resource. Depending on the child
  3176. * class, this might be redefined to allow several behaviours depending on the document type.
  3177. * @param integer Resource ID
  3178. * @return boolean True on success, false otherwise
  3179. */
  3180. public function open($id) {
  3181. if ($this->debug > 0) {
  3182. error_log('New LP - In learnpath::open()', 0);
  3183. }
  3184. // TODO:
  3185. // set the current resource attribute to this resource
  3186. // switch on element type (redefine in child class?)
  3187. // set status for this item to "opened"
  3188. // start timer
  3189. // initialise score
  3190. $this->index = 0; //or = the last item seen (see $this->last)
  3191. }
  3192. /**
  3193. * Check that all prerequisites are fulfilled. Returns true and an empty string on succes, returns false
  3194. * and the prerequisite string on error.
  3195. * This function is based on the rules for aicc_script language as described in the SCORM 1.2 CAM documentation page 108.
  3196. * @param integer Optional item ID. If none given, uses the current open item.
  3197. * @return boolean True if prerequisites are matched, false otherwise - Empty string if true returned, prerequisites string otherwise.
  3198. */
  3199. public function prerequisites_match($item = null) {
  3200. if ($this->debug > 0) {
  3201. error_log('New LP - In learnpath::prerequisites_match()', 0);
  3202. }
  3203. if (empty ($item)) {
  3204. $item = $this->current;
  3205. }
  3206. if (is_object($this->items[$item])) {
  3207. $prereq_string = $this->items[$item]->get_prereq_string();
  3208. if (empty ($prereq_string)) {
  3209. return true;
  3210. }
  3211. // Clean spaces.
  3212. $prereq_string = str_replace(' ', '', $prereq_string);
  3213. if ($this->debug > 0) {
  3214. error_log('Found prereq_string: ' . $prereq_string, 0);
  3215. }
  3216. // Now send to the parse_prereq() function that will check this component's prerequisites.
  3217. $result = $this->items[$item]->parse_prereq($prereq_string, $this->items, $this->refs_list, $this->get_user_id());
  3218. if ($result === false) {
  3219. $this->set_error_msg($this->items[$item]->prereq_alert);
  3220. }
  3221. } else {
  3222. $result = true;
  3223. if ($this->debug > 1) {
  3224. error_log('New LP - $this->items[' . $item . '] was not an object', 0);
  3225. }
  3226. }
  3227. if ($this->debug > 1) {
  3228. error_log('New LP - End of prerequisites_match(). Error message is now ' . $this->error, 0);
  3229. }
  3230. return $result;
  3231. }
  3232. /**
  3233. * Updates learnpath attributes to point to the previous element
  3234. * The last part is similar to set_current_item but processing the other way around
  3235. */
  3236. public function previous() {
  3237. if ($this->debug > 0) {
  3238. error_log('New LP - In learnpath::previous()', 0);
  3239. }
  3240. $this->last = $this->get_current_item_id();
  3241. $this->items[$this->last]->save(false, $this->prerequisites_match($this->last));
  3242. $this->autocomplete_parents($this->last);
  3243. $new_index = $this->get_previous_index();
  3244. $this->index = $new_index;
  3245. $this->current = $this->ordered_items[$new_index];
  3246. }
  3247. /**
  3248. * Publishes a learnpath. This basically means show or hide the learnpath
  3249. * to normal users.
  3250. * Can be used as abstract
  3251. * @param integer Learnpath ID
  3252. * @param string New visibility
  3253. */
  3254. public function toggle_visibility($lp_id, $set_visibility = 1) {
  3255. //if ($this->debug > 0) { error_log('New LP - In learnpath::toggle_visibility()', 0); }
  3256. $action = 'visible';
  3257. if ($set_visibility != 1) {
  3258. $action = 'invisible';
  3259. }
  3260. return api_item_property_update(api_get_course_info(), TOOL_LEARNPATH, $lp_id, $action, api_get_user_id());
  3261. }
  3262. /**
  3263. * Publishes a learnpath. This basically means show or hide the learnpath
  3264. * on the course homepage
  3265. * Can be used as abstract
  3266. * @param integer Learnpath id
  3267. * @param string New visibility (v/s - visible/invisible)
  3268. */
  3269. public function toggle_publish($lp_id, $set_visibility = 'v') {
  3270. //if ($this->debug > 0) { error_log('New LP - In learnpath::toggle_publish()', 0); }
  3271. $tbl_lp = Database :: get_course_table(TABLE_LP_MAIN);
  3272. $sql = "SELECT * FROM $tbl_lp where id=$lp_id";
  3273. $result = Database::query($sql);
  3274. $row = Database :: fetch_array($result);
  3275. $name = domesticate($row['name']);
  3276. if ($set_visibility == 'i') {
  3277. $s = $name . " " . get_lang('_no_published');
  3278. $dialogBox = $s;
  3279. $v = 0;
  3280. }
  3281. if ($set_visibility == 'v') {
  3282. $s = $name . " " . get_lang('_published');
  3283. $dialogBox = $s;
  3284. $v = 1;
  3285. }
  3286. $session_id = api_get_session_id();
  3287. $session_condition = api_get_session_condition($session_id);
  3288. $tbl_tool = Database :: get_course_table(TABLE_TOOL_LIST);
  3289. $link = 'newscorm/lp_controller.php?action=view&lp_id=' . $lp_id.'&id_session='.$session_id;
  3290. $sql = "SELECT * FROM $tbl_tool where name='$name' and image='scormbuilder.gif' and link LIKE '$link%' $session_condition";
  3291. $result = Database::query($sql);
  3292. $num = Database :: num_rows($result);
  3293. $row2 = Database :: fetch_array($result);
  3294. //if ($this->debug > 2) { error_log('New LP - '.$sql.' - '.$num, 0); }
  3295. if (($set_visibility == 'i') && ($num > 0)) {
  3296. $sql = "DELETE FROM $tbl_tool WHERE (name='$name' and image='scormbuilder.gif' and link LIKE '$link%' $session_condition)";
  3297. } elseif (($set_visibility == 'v') && ($num == 0)) {
  3298. $sql = "INSERT INTO $tbl_tool (name, link, image, visibility, admin, address, added_tool, session_id) VALUES ('$name','$link','scormbuilder.gif','$v','0','pastillegris.gif',0, $session_id)";
  3299. } else {
  3300. // Parameter and database incompatible, do nothing.
  3301. }
  3302. $result = Database::query($sql);
  3303. //if ($this->debug > 2) { error_log('New LP - Leaving learnpath::toggle_visibility: '.$sql, 0); }
  3304. }
  3305. /**
  3306. * Restart the whole learnpath. Return the URL of the first element.
  3307. * Make sure the results are saved with anoter method. This method should probably be
  3308. * redefined in children classes.
  3309. * To use a similar method statically, use the create_new_attempt() method
  3310. * @return string URL to load in the viewer
  3311. */
  3312. public function restart() {
  3313. if ($this->debug > 0) {
  3314. error_log('New LP - In learnpath::restart()', 0);
  3315. }
  3316. // TODO
  3317. // Call autosave method to save the current progress.
  3318. //$this->index = 0;
  3319. $session_id = api_get_session_id();
  3320. $lp_view_table = Database :: get_course_table(TABLE_LP_VIEW);
  3321. $sql = "INSERT INTO $lp_view_table (lp_id, user_id, view_count, session_id) " .
  3322. "VALUES (" . $this->lp_id . "," . $this->get_user_id() . "," . ($this->attempt + 1) . ", $session_id)";
  3323. if ($this->debug > 2) {
  3324. error_log('New LP - Inserting new lp_view for restart: ' . $sql, 0);
  3325. }
  3326. $res = Database::query($sql);
  3327. if ($view_id = Database :: insert_id($res)) {
  3328. $this->lp_view_id = $view_id;
  3329. $this->attempt = $this->attempt + 1;
  3330. } else {
  3331. $this->error = 'Could not insert into item_view table...';
  3332. return false;
  3333. }
  3334. $this->autocomplete_parents($this->current);
  3335. foreach ($this->items as $index => $dummy) {
  3336. $this->items[$index]->restart();
  3337. $this->items[$index]->set_lp_view($this->lp_view_id);
  3338. }
  3339. $this->first();
  3340. return true;
  3341. }
  3342. /**
  3343. * Saves the current item
  3344. * @return boolean
  3345. */
  3346. public function save_current() {
  3347. if ($this->debug > 0) {
  3348. error_log('New LP - In learnpath::save_current()', 0);
  3349. }
  3350. // TODO: Do a better check on the index pointing to the right item (it is supposed to be working
  3351. // on $ordered_items[] but not sure it's always safe to use with $items[]).
  3352. if ($this->debug > 2) {
  3353. error_log('New LP - save_current() saving item ' . $this->current, 0);
  3354. }
  3355. if ($this->debug > 2) {
  3356. error_log('' . print_r($this->items, true), 0);
  3357. }
  3358. if (is_object($this->items[$this->current])) {
  3359. //$res = $this->items[$this->current]->save(false);
  3360. $res = $this->items[$this->current]->save(false, $this->prerequisites_match($this->current));
  3361. $this->autocomplete_parents($this->current);
  3362. $status = $this->items[$this->current]->get_status();
  3363. $this->append_message('new_item_status: ' . $status);
  3364. $this->update_queue[$this->current] = $status;
  3365. return $res;
  3366. }
  3367. return false;
  3368. }
  3369. /**
  3370. * Saves the given item
  3371. * @param integer Item ID. Optional (will take from $_REQUEST if null)
  3372. * @param boolean Save from url params (true) or from current attributes (false). Optional. Defaults to true
  3373. * @return boolean
  3374. */
  3375. public function save_item($item_id = null, $from_outside = true) {
  3376. if ($this->debug > 0) {
  3377. error_log('New LP - In learnpath::save_item(' . $item_id . ',' . $from_outside . ')', 0);
  3378. }
  3379. // TODO: Do a better check on the index pointing to the right item (it is supposed to be working
  3380. // on $ordered_items[] but not sure it's always safe to use with $items[]).
  3381. if (empty ($item_id)) {
  3382. $item_id = $this->escape_string($_REQUEST['id']);
  3383. }
  3384. if (empty ($item_id)) {
  3385. $item_id = $this->get_current_item_id();
  3386. }
  3387. if ($this->debug > 2) {
  3388. error_log('New LP - save_current() saving item ' . $item_id, 0);
  3389. }
  3390. if (is_object($this->items[$item_id])) {
  3391. $res = $this->items[$item_id]->save($from_outside, $this->prerequisites_match($item_id));
  3392. //$res = $this->items[$item_id]->save($from_outside);
  3393. $this->autocomplete_parents($item_id);
  3394. $status = $this->items[$item_id]->get_status();
  3395. $this->append_message('new_item_status: ' . $status);
  3396. $this->update_queue[$item_id] = $status;
  3397. return $res;
  3398. }
  3399. return false;
  3400. }
  3401. /**
  3402. * Saves the last item seen's ID only in case
  3403. */
  3404. public function save_last() {
  3405. if ($this->debug > 0) {
  3406. error_log('New LP - In learnpath::save_last()', 0);
  3407. }
  3408. $session_condition = api_get_session_condition(api_get_session_id(), true, false);
  3409. $table = Database :: get_course_table(TABLE_LP_VIEW);
  3410. if (isset ($this->current)) {
  3411. if ($this->debug > 2) {
  3412. error_log('New LP - Saving current item (' . $this->current . ') for later review', 0);
  3413. }
  3414. $sql = "UPDATE $table SET last_item = " . Database::escape_string($this->get_current_item_id()). " " .
  3415. "WHERE lp_id = " . $this->get_id() . " AND user_id = " . $this->get_user_id().' '.$session_condition;
  3416. if ($this->debug > 2) {
  3417. error_log('New LP - Saving last item seen : ' . $sql, 0);
  3418. }
  3419. $res = Database::query($sql);
  3420. }
  3421. // Save progress.
  3422. list($progress, $text) = $this->get_progress_bar_text('%');
  3423. if ($progress >= 0 && $progress <= 100) {
  3424. $progress = (int) $progress;
  3425. $sql = "UPDATE $table SET progress = $progress " .
  3426. "WHERE lp_id = " . $this->get_id() . " AND " .
  3427. "user_id = " . $this->get_user_id().' '.$session_condition;
  3428. $res = Database::query($sql); // Ignore errors as some tables might not have the progress field just yet.
  3429. $this->progress_db = $progress;
  3430. }
  3431. }
  3432. /**
  3433. * Sets the current item ID (checks if valid and authorized first)
  3434. * @param integer New item ID. If not given or not authorized, defaults to current
  3435. */
  3436. public function set_current_item($item_id = null) {
  3437. if ($this->debug > 0) {
  3438. error_log('New LP - In learnpath::set_current_item(' . $item_id . ')', 0);
  3439. }
  3440. if (empty ($item_id)) {
  3441. if ($this->debug > 2) {
  3442. error_log('New LP - No new current item given, ignore...', 0);
  3443. }
  3444. // Do nothing.
  3445. } else {
  3446. if ($this->debug > 2) {
  3447. error_log('New LP - New current item given is ' . $item_id . '...', 0);
  3448. }
  3449. if (is_numeric($item_id)) {
  3450. $item_id = $this->escape_string($item_id);
  3451. // TODO: Check in database here.
  3452. $this->last = $this->current;
  3453. $this->current = $item_id;
  3454. // TODO: Update $this->index as well.
  3455. foreach ($this->ordered_items as $index => $item) {
  3456. if ($item == $this->current) {
  3457. $this->index = $index;
  3458. break;
  3459. }
  3460. }
  3461. if ($this->debug > 2) {
  3462. error_log('New LP - set_current_item(' . $item_id . ') done. Index is now : ' . $this->index, 0);
  3463. }
  3464. } else {
  3465. error_log('New LP - set_current_item(' . $item_id . ') failed. Not a numeric value: ', 0);
  3466. }
  3467. }
  3468. }
  3469. /**
  3470. * Sets the encoding
  3471. * @param string New encoding
  3472. * TODO (as of Chamilo 1.8.8): Check in the future whether this method is needed.
  3473. */
  3474. public function set_encoding($enc = 'UTF-8') {
  3475. if ($this->debug > 0) {
  3476. error_log('New LP - In learnpath::set_encoding()', 0);
  3477. }
  3478. /* // Deprecated code (Chamilo 1.8.8).
  3479. $enc = strtoupper($enc);
  3480. $encodings = array (
  3481. 'UTF-8',
  3482. 'ISO-8859-1',
  3483. 'ISO-8859-15',
  3484. 'cp1251',
  3485. 'cp1252',
  3486. 'KOI8-R',
  3487. 'BIG5',
  3488. 'GB2312',
  3489. 'Shift_JIS',
  3490. 'EUC-JP',
  3491. ''
  3492. );
  3493. if (in_array($enc, $encodings)) { // TODO: Incorrect comparison, fix it.
  3494. $lp = $this->get_id();
  3495. if ($lp != 0) {
  3496. $tbl_lp = Database :: get_course_table(TABLE_LP_MAIN);
  3497. $sql = "UPDATE $tbl_lp SET default_encoding = '$enc' WHERE id = " . $lp;
  3498. $res = Database::query($sql);
  3499. return $res;
  3500. }
  3501. }
  3502. return false;
  3503. */
  3504. $enc = api_refine_encoding_id($enc);
  3505. if (empty($enc)) {
  3506. $enc = api_get_system_encoding();
  3507. }
  3508. if (api_is_encoding_supported($enc)) {
  3509. $lp = $this->get_id();
  3510. if ($lp != 0) {
  3511. $tbl_lp = Database :: get_course_table(TABLE_LP_MAIN);
  3512. $sql = "UPDATE $tbl_lp SET default_encoding = '$enc' WHERE id = " . $lp;
  3513. $res = Database::query($sql);
  3514. return $res;
  3515. }
  3516. }
  3517. return false;
  3518. }
  3519. /**
  3520. * Sets the JS lib setting in the database directly.
  3521. * This is the JavaScript library file this lp needs to load on startup
  3522. * @param string Proximity setting
  3523. * @return boolean True on update success. False otherwise.
  3524. */
  3525. public function set_jslib($lib = '') {
  3526. if ($this->debug > 0) {
  3527. error_log('New LP - In learnpath::set_jslib()', 0);
  3528. }
  3529. $lp = $this->get_id();
  3530. if ($lp != 0) {
  3531. $tbl_lp = Database :: get_course_table(TABLE_LP_MAIN);
  3532. $sql = "UPDATE $tbl_lp SET js_lib = '$lib' WHERE id = " . $lp;
  3533. $res = Database::query($sql);
  3534. return $res;
  3535. } else {
  3536. return false;
  3537. }
  3538. }
  3539. /**
  3540. * Sets the name of the LP maker (publisher) (and save)
  3541. * @param string Optional string giving the new content_maker of this learnpath
  3542. * @return boolean True
  3543. */
  3544. public function set_maker($name = '') {
  3545. if ($this->debug > 0) {
  3546. error_log('New LP - In learnpath::set_maker()', 0);
  3547. }
  3548. if (empty ($name))
  3549. return false;
  3550. $this->maker = $this->escape_string($name);
  3551. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3552. $lp_id = $this->get_id();
  3553. $sql = "UPDATE $lp_table SET content_maker = '" . $this->maker . "' WHERE id = '$lp_id'";
  3554. if ($this->debug > 2) {
  3555. error_log('New LP - lp updated with new content_maker : ' . $this->maker, 0);
  3556. }
  3557. $res = Database::query($sql);
  3558. return true;
  3559. }
  3560. /**
  3561. * Sets the name of the current learnpath (and save)
  3562. * @param string Optional string giving the new name of this learnpath
  3563. * @return boolean True/False
  3564. */
  3565. public function set_name($name = '') {
  3566. if ($this->debug > 0) {
  3567. error_log('New LP - In learnpath::set_name()', 0);
  3568. }
  3569. if (empty ($name))
  3570. return false;
  3571. $this->name = $this->escape_string($name);
  3572. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3573. $lp_id = $this->get_id();
  3574. $sql = "UPDATE $lp_table SET name = '" . $this->name . "' WHERE id = '$lp_id'";
  3575. if ($this->debug > 2) {
  3576. error_log('New LP - lp updated with new name : ' . $this->name, 0);
  3577. }
  3578. $res = Database::query($sql);
  3579. // If the lp is visible on the homepage, change his name there.
  3580. if (Database::affected_rows()) {
  3581. $table = Database :: get_course_table(TABLE_TOOL_LIST);
  3582. $sql = 'UPDATE ' . $table . ' SET
  3583. name = "' . $this->name . '"
  3584. WHERE link = "newscorm/lp_controller.php?action=view&lp_id=' . $lp_id . '"';
  3585. Database::query($sql);
  3586. }
  3587. return true;
  3588. }
  3589. /**
  3590. * Set index specified prefix terms for all items in this path
  3591. * @param string Comma-separated list of terms
  3592. * @param char Xapian term prefix
  3593. * @return boolean False on error, true otherwise
  3594. */
  3595. public function set_terms_by_prefix($terms_string, $prefix) {
  3596. if (api_get_setting('search_enabled') !== 'true')
  3597. return false;
  3598. if (!extension_loaded('xapian')) {
  3599. return false;
  3600. }
  3601. $terms_string = trim($terms_string);
  3602. $terms = explode(',', $terms_string);
  3603. array_walk($terms, 'trim_value');
  3604. $stored_terms = $this->get_common_index_terms_by_prefix($prefix);
  3605. // Don't do anything if no change, verify only at DB, not the search engine.
  3606. if ((count(array_diff($terms, $stored_terms)) == 0) && (count(array_diff($stored_terms, $terms)) == 0))
  3607. return false;
  3608. require_once 'xapian.php'; // TODO: Try catch every xapian use or make wrappers on API.
  3609. require_once api_get_path(LIBRARY_PATH).'search/DokeosIndexer.class.php';
  3610. require_once api_get_path(LIBRARY_PATH).'search/xapian/XapianQuery.php';
  3611. require_once api_get_path(LIBRARY_PATH).'search/IndexableChunk.class.php';
  3612. $items_table = Database :: get_course_table(TABLE_LP_ITEM);
  3613. // TODO: Make query secure agains XSS : use member attr instead of post var.
  3614. $lp_id = intval($_POST['lp_id']);
  3615. $sql = "SELECT * FROM $items_table WHERE lp_id = $lp_id";
  3616. $result = Database::query($sql);
  3617. $di = new DokeosIndexer();
  3618. while ($lp_item = Database :: fetch_array($result)) {
  3619. // Get search_did.
  3620. $tbl_se_ref = Database :: get_main_table(TABLE_MAIN_SEARCH_ENGINE_REF);
  3621. $sql = 'SELECT * FROM %s WHERE course_code=\'%s\' AND tool_id=\'%s\' AND ref_id_high_level=%s AND ref_id_second_level=%d LIMIT 1';
  3622. $sql = sprintf($sql, $tbl_se_ref, $this->cc, TOOL_LEARNPATH, $lp_id, $lp_item['id']);
  3623. //echo $sql; echo '<br>';
  3624. $res = Database::query($sql);
  3625. if (Database::num_rows($res) > 0) {
  3626. $se_ref = Database :: fetch_array($res);
  3627. // Compare terms.
  3628. $doc = $di->get_document($se_ref['search_did']);
  3629. $xapian_terms = xapian_get_doc_terms($doc, $prefix);
  3630. $xterms = array ();
  3631. foreach ($xapian_terms as $xapian_term) {
  3632. $xterms[] = substr($xapian_term['name'], 1);
  3633. }
  3634. $dterms = $terms;
  3635. $missing_terms = array_diff($dterms, $xterms);
  3636. $deprecated_terms = array_diff($xterms, $dterms);
  3637. // Save it to search engine.
  3638. foreach ($missing_terms as $term) {
  3639. $doc->add_term($prefix . $term, 1);
  3640. }
  3641. foreach ($deprecated_terms as $term) {
  3642. $doc->remove_term($prefix . $term);
  3643. }
  3644. $di->getDb()->replace_document((int) $se_ref['search_did'], $doc);
  3645. $di->getDb()->flush();
  3646. } else {
  3647. //@todo What we should do here?
  3648. }
  3649. }
  3650. return true;
  3651. }
  3652. /**
  3653. * Sets the theme of the LP (local/remote) (and save)
  3654. * @param string Optional string giving the new theme of this learnpath
  3655. * @return bool Returns true if theme name is not empty
  3656. */
  3657. public function set_theme($name = '') {
  3658. if ($this->debug > 0) {
  3659. error_log('New LP - In learnpath::set_theme()', 0);
  3660. }
  3661. $this->theme = $this->escape_string($name);
  3662. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3663. $lp_id = $this->get_id();
  3664. $sql = "UPDATE $lp_table SET theme = '" . $this->theme . "' WHERE id = '$lp_id'";
  3665. if ($this->debug > 2) {
  3666. error_log('New LP - lp updated with new theme : ' . $this->theme, 0);
  3667. }
  3668. //$res = Database::query($sql);
  3669. $res = Database::query($sql);
  3670. return true;
  3671. }
  3672. /**
  3673. * Sets the image of an LP (and save)
  3674. * @param string Optional string giving the new image of this learnpath
  3675. * @return bool Returns true if theme name is not empty
  3676. */
  3677. public function set_preview_image($name = '') {
  3678. if ($this->debug > 0) {
  3679. error_log('New LP - In learnpath::set_preview_image()', 0);
  3680. }
  3681. $this->preview_image = $this->escape_string($name);
  3682. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3683. $lp_id = $this->get_id();
  3684. $sql = "UPDATE $lp_table SET preview_image = '" . $this->preview_image . "' WHERE id = '$lp_id'";
  3685. if ($this->debug > 2) {
  3686. error_log('New LP - lp updated with new preview image : ' . $this->preview_image, 0);
  3687. }
  3688. $res = Database::query($sql);
  3689. return true;
  3690. }
  3691. /**
  3692. * Sets the author of a LP (and save)
  3693. * @param string Optional string giving the new author of this learnpath
  3694. * @return bool Returns true if author's name is not empty
  3695. */
  3696. public function set_author($name = '') {
  3697. if ($this->debug > 0) {
  3698. error_log('New LP - In learnpath::set_author()', 0);
  3699. }
  3700. $this->author = $this->escape_string($name);
  3701. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3702. $lp_id = $this->get_id();
  3703. $sql = "UPDATE $lp_table SET author = '" . $this->author . "' WHERE id = '$lp_id'";
  3704. if ($this->debug > 2) {
  3705. error_log('New LP - lp updated with new preview author : ' . $this->author, 0);
  3706. }
  3707. $res = Database::query($sql);
  3708. return true;
  3709. }
  3710. /**
  3711. * Sets the prerequisite of a LP (and save)
  3712. * @param int integer giving the new prerequisite of this learnpath
  3713. * @return bool returns true if prerequisite is not empty
  3714. */
  3715. public function set_prerequisite($prerequisite) {
  3716. if ($this->debug > 0) {
  3717. error_log('New LP - In learnpath::set_prerequisite()', 0);
  3718. }
  3719. $this->prerequisite = intval($prerequisite);
  3720. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3721. $lp_id = $this->get_id();
  3722. $sql = "UPDATE $lp_table SET prerequisite = '".$this->prerequisite."' WHERE id = '$lp_id'";
  3723. if ($this->debug > 2) {
  3724. error_log('New LP - lp updated with new preview requisite : ' . $this->requisite, 0);
  3725. }
  3726. $res = Database::query($sql);
  3727. return true;
  3728. }
  3729. /**
  3730. * Sets the location/proximity of the LP (local/remote) (and save)
  3731. * @param string Optional string giving the new location of this learnpath
  3732. * @return boolean True on success / False on error
  3733. */
  3734. public function set_proximity($name = '') {
  3735. if ($this->debug > 0) {
  3736. error_log('New LP - In learnpath::set_proximity()', 0);
  3737. }
  3738. if (empty ($name))
  3739. return false;
  3740. $this->proximity = $this->escape_string($name);
  3741. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3742. $lp_id = $this->get_id();
  3743. $sql = "UPDATE $lp_table SET content_local = '" . $this->proximity . "' WHERE id = '$lp_id'";
  3744. if ($this->debug > 2) {
  3745. error_log('New LP - lp updated with new proximity : ' . $this->proximity, 0);
  3746. }
  3747. $res = Database::query($sql);
  3748. return true;
  3749. }
  3750. /**
  3751. * Sets the previous item ID to a given ID. Generally, this should be set to the previous 'current' item
  3752. * @param integer DB ID of the item
  3753. */
  3754. public function set_previous_item($id) {
  3755. if ($this->debug > 0) {
  3756. error_log('New LP - In learnpath::set_previous_item()', 0);
  3757. }
  3758. $this->last = $id;
  3759. }
  3760. /**
  3761. * Sets use_max_score
  3762. * @param string Optional string giving the new location of this learnpath
  3763. * @return boolean True on success / False on error
  3764. */
  3765. public function set_use_max_score($use_max_score = 1) {
  3766. if ($this->debug > 0) {
  3767. error_log('New LP - In learnpath::set_use_max_score()', 0);
  3768. }
  3769. $use_max_score = intval($use_max_score);
  3770. $this->use_max_score = $use_max_score;
  3771. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3772. $lp_id = $this->get_id();
  3773. $sql = "UPDATE $lp_table SET use_max_score = '" . $this->use_max_score . "' WHERE id = '$lp_id'";
  3774. if ($this->debug > 2) {
  3775. error_log('New LP - lp updated with new use_max_score : ' . $this->use_max_score, 0);
  3776. }
  3777. $res = Database::query($sql);
  3778. return true;
  3779. }
  3780. /**
  3781. * Sets and saves the expired_on date
  3782. * @param string Optional string giving the new author of this learnpath
  3783. * @return bool Returns true if author's name is not empty
  3784. */
  3785. public function set_expired_on($expired_on) {
  3786. if ($this->debug > 0) {
  3787. error_log('New LP - In learnpath::set_expired_on()', 0);
  3788. }
  3789. if (!empty($expired_on)) {
  3790. $this->expired_on = $this->escape_string(api_get_utc_datetime($expired_on));
  3791. } else {
  3792. $this->expired_on = '';
  3793. }
  3794. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3795. $lp_id = $this->get_id();
  3796. $sql = "UPDATE $lp_table SET expired_on = '" . $this->expired_on . "' WHERE id = '$lp_id'";
  3797. if ($this->debug > 2) {
  3798. error_log('New LP - lp updated with new expired_on : ' . $this->expired_on, 0);
  3799. }
  3800. $res = Database::query($sql);
  3801. return true;
  3802. }
  3803. /**
  3804. * Sets and saves the publicated_on date
  3805. * @param string Optional string giving the new author of this learnpath
  3806. * @return bool Returns true if author's name is not empty
  3807. */
  3808. public function set_publicated_on($publicated_on) {
  3809. if ($this->debug > 0) {
  3810. error_log('New LP - In learnpath::set_expired_on()', 0);
  3811. }
  3812. if (!empty($publicated_on)) {
  3813. $this->publicated_on = $this->escape_string(api_get_utc_datetime($publicated_on));
  3814. } else {
  3815. $this->publicated_on = '';
  3816. }
  3817. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3818. $lp_id = $this->get_id();
  3819. $sql = "UPDATE $lp_table SET publicated_on = '" . $this->publicated_on . "' WHERE id = '$lp_id'";
  3820. if ($this->debug > 2) {
  3821. error_log('New LP - lp updated with new publicated_on : ' . $this->publicated_on, 0);
  3822. }
  3823. $res = Database::query($sql);
  3824. return true;
  3825. }
  3826. /**
  3827. * Sets and saves the expired_on date
  3828. * @param string Optional string giving the new author of this learnpath
  3829. * @return bool Returns true if author's name is not empty
  3830. */
  3831. public function set_modified_on() {
  3832. if ($this->debug > 0) {
  3833. error_log('New LP - In learnpath::set_expired_on()', 0);
  3834. }
  3835. $this->modified_on = api_get_utc_datetime();
  3836. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3837. $lp_id = $this->get_id();
  3838. $sql = "UPDATE $lp_table SET modified_on = '" . $this->modified_on . "' WHERE id = '$lp_id'";
  3839. if ($this->debug > 2) {
  3840. error_log('New LP - lp updated with new expired_on : ' . $this->modified_on, 0);
  3841. }
  3842. $res = Database::query($sql);
  3843. return true;
  3844. }
  3845. /**
  3846. * Sets the object's error message
  3847. * @param string Error message. If empty, reinits the error string
  3848. * @return void
  3849. */
  3850. public function set_error_msg($error = '') {
  3851. if ($this->debug > 0) {
  3852. error_log('New LP - In learnpath::set_error_msg()', 0);
  3853. }
  3854. if (empty ($error)) {
  3855. $this->error = '';
  3856. } else {
  3857. $this->error .= $error;
  3858. }
  3859. }
  3860. /**
  3861. * Launches the current item if not 'sco' (starts timer and make sure there is a record ready in the DB)
  3862. * @param boolean Whether to allow a new attempt or not
  3863. * @return boolean True
  3864. */
  3865. public function start_current_item($allow_new_attempt = false) {
  3866. if ($this->debug > 0) {
  3867. error_log('New LP - In learnpath::start_current_item()', 0);
  3868. }
  3869. if ($this->current != 0 AND is_object($this->items[$this->current])) {
  3870. $type = $this->get_type();
  3871. $item_type = $this->items[$this->current]->get_type();
  3872. if (($type == 2 && $item_type != 'sco') OR ($type == 3 && $item_type != 'au') OR ($type == 1 && $item_type != TOOL_QUIZ && $item_type != TOOL_HOTPOTATOES)) {
  3873. $this->items[$this->current]->open($allow_new_attempt);
  3874. $this->autocomplete_parents($this->current);
  3875. $prereq_check = $this->prerequisites_match($this->current);
  3876. $this->items[$this->current]->save(false, $prereq_check);
  3877. //$this->update_queue[$this->last] = $this->items[$this->last]->get_status();
  3878. } else {
  3879. // If sco, then it is supposed to have been updated by some other call.
  3880. }
  3881. if ($item_type == 'sco') {
  3882. $this->items[$this->current]->restart();
  3883. }
  3884. }
  3885. if ($this->debug > 0) {
  3886. error_log('New LP - End of learnpath::start_current_item()', 0);
  3887. }
  3888. return true;
  3889. }
  3890. /**
  3891. * Stops the processing and counters for the old item (as held in $this->last)
  3892. * @return boolean True/False
  3893. */
  3894. public function stop_previous_item() {
  3895. if ($this->debug > 0) {
  3896. error_log('New LP - In learnpath::stop_previous_item()', 0);
  3897. }
  3898. if ($this->last != 0 && $this->last != $this->current && is_object($this->items[$this->last])) {
  3899. if ($this->debug > 2) {
  3900. error_log('New LP - In learnpath::stop_previous_item() - ' . $this->last . ' is object', 0);
  3901. }
  3902. switch ($this->get_type()) {
  3903. case '3' :
  3904. if ($this->items[$this->last]->get_type() != 'au') {
  3905. if ($this->debug > 2) {
  3906. error_log('New LP - In learnpath::stop_previous_item() - ' . $this->last . ' in lp_type 3 is <> au', 0);
  3907. }
  3908. $this->items[$this->last]->close();
  3909. //$this->autocomplete_parents($this->last);
  3910. //$this->update_queue[$this->last] = $this->items[$this->last]->get_status();
  3911. } else {
  3912. if ($this->debug > 2) {
  3913. error_log('New LP - In learnpath::stop_previous_item() - Item is an AU, saving is managed by AICC signals', 0);
  3914. }
  3915. }
  3916. case '2' :
  3917. if ($this->items[$this->last]->get_type() != 'sco') {
  3918. if ($this->debug > 2) {
  3919. error_log('New LP - In learnpath::stop_previous_item() - ' . $this->last . ' in lp_type 2 is <> sco', 0);
  3920. }
  3921. $this->items[$this->last]->close();
  3922. //$this->autocomplete_parents($this->last);
  3923. //$this->update_queue[$this->last] = $this->items[$this->last]->get_status();
  3924. } else {
  3925. if ($this->debug > 2) {
  3926. error_log('New LP - In learnpath::stop_previous_item() - Item is a SCO, saving is managed by SCO signals', 0);
  3927. }
  3928. }
  3929. break;
  3930. case '1' :
  3931. default :
  3932. if ($this->debug > 2) {
  3933. error_log('New LP - In learnpath::stop_previous_item() - ' . $this->last . ' in lp_type 1 is asset', 0);
  3934. }
  3935. $this->items[$this->last]->close();
  3936. break;
  3937. }
  3938. } else {
  3939. if ($this->debug > 2) {
  3940. error_log('New LP - In learnpath::stop_previous_item() - No previous element found, ignoring...', 0);
  3941. }
  3942. return false;
  3943. }
  3944. return true;
  3945. }
  3946. /**
  3947. * Updates the default view mode from fullscreen to embedded and inversely
  3948. * @return string The current default view mode ('fullscreen' or 'embedded')
  3949. */
  3950. public function update_default_view_mode() {
  3951. if ($this->debug > 0) {
  3952. error_log('New LP - In learnpath::update_default_view_mode()', 0);
  3953. }
  3954. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3955. $sql = "SELECT * FROM $lp_table WHERE id = " . $this->get_id();
  3956. $res = Database::query($sql);
  3957. if (Database :: num_rows($res) > 0) {
  3958. $row = Database :: fetch_array($res);
  3959. $view_mode = $row['default_view_mod'];
  3960. if ($view_mode == 'fullscreen') {
  3961. $view_mode = 'embedded';
  3962. } elseif ($view_mode == 'embedded') {
  3963. $view_mode = 'embedframe';
  3964. } elseif ($view_mode == 'embedframe') {
  3965. $view_mode = 'fullscreen';
  3966. }
  3967. $sql = "UPDATE $lp_table SET default_view_mod = '$view_mode' WHERE id = " . $this->get_id();
  3968. $res = Database::query($sql);
  3969. $this->mode = $view_mode;
  3970. return $view_mode;
  3971. } else {
  3972. if ($this->debug > 2) {
  3973. error_log('New LP - Problem in update_default_view() - could not find LP ' . $this->get_id() . ' in DB', 0);
  3974. }
  3975. }
  3976. return -1;
  3977. }
  3978. /**
  3979. * Updates the default behaviour about auto-commiting SCORM updates
  3980. * @return boolean True if auto-commit has been set to 'on', false otherwise
  3981. */
  3982. public function update_default_scorm_commit() {
  3983. if ($this->debug > 0) {
  3984. error_log('New LP - In learnpath::update_default_scorm_commit()', 0);
  3985. }
  3986. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3987. $sql = "SELECT * FROM $lp_table WHERE id = " . $this->get_id();
  3988. $res = Database::query($sql);
  3989. if (Database :: num_rows($res) > 0) {
  3990. $row = Database :: fetch_array($res);
  3991. $force = $row['force_commit'];
  3992. if ($force == 1) {
  3993. $force = 0;
  3994. $force_return = false;
  3995. } elseif ($force == 0) {
  3996. $force = 1;
  3997. $force_return = true;
  3998. }
  3999. $sql = "UPDATE $lp_table SET force_commit = $force WHERE id = " . $this->get_id();
  4000. $res = Database::query($sql);
  4001. $this->force_commit = $force_return;
  4002. return $force_return;
  4003. } else {
  4004. if ($this->debug > 2) {
  4005. error_log('New LP - Problem in update_default_scorm_commit() - could not find LP ' . $this->get_id() . ' in DB', 0);
  4006. }
  4007. }
  4008. return -1;
  4009. }
  4010. /**
  4011. * Updates the order of learning paths (goes through all of them by order and fills the gaps)
  4012. * @return bool True on success, false on failure
  4013. */
  4014. public function update_display_order() {
  4015. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  4016. $sql = "SELECT * FROM $lp_table ORDER BY display_order";
  4017. $res = Database::query($sql);
  4018. if ($res === false)
  4019. return false;
  4020. $lps = array ();
  4021. $lp_order = array ();
  4022. $num = Database :: num_rows($res);
  4023. // First check the order is correct, globally (might be wrong because
  4024. // of versions < 1.8.4).
  4025. if ($num > 0) {
  4026. $i = 1;
  4027. while ($row = Database :: fetch_array($res)) {
  4028. if ($row['display_order'] != $i) { // If we find a gap in the order, we need to fix it.
  4029. $need_fix = true;
  4030. $sql_u = "UPDATE $lp_table SET display_order = $i WHERE id = " . $row['id'];
  4031. $res_u = Database::query($sql_u);
  4032. }
  4033. $i++;
  4034. }
  4035. }
  4036. return true;
  4037. }
  4038. /**
  4039. * Updates the "prevent_reinit" value that enables control on reinitialising items on second view
  4040. * @return boolean True if prevent_reinit has been set to 'on', false otherwise (or 1 or 0 in this case)
  4041. */
  4042. public function update_reinit() {
  4043. if ($this->debug > 0) {
  4044. error_log('New LP - In learnpath::update_reinit()', 0);
  4045. }
  4046. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  4047. $sql = "SELECT * FROM $lp_table WHERE id = " . $this->get_id();
  4048. $res = Database::query($sql);
  4049. if (Database :: num_rows($res) > 0) {
  4050. $row = Database :: fetch_array($res);
  4051. $force = $row['prevent_reinit'];
  4052. if ($force == 1) {
  4053. $force = 0;
  4054. } elseif ($force == 0) {
  4055. $force = 1;
  4056. }
  4057. $sql = "UPDATE $lp_table SET prevent_reinit = $force WHERE id = " . $this->get_id();
  4058. $res = Database::query($sql);
  4059. $this->prevent_reinit = $force;
  4060. return $force;
  4061. } else {
  4062. if ($this->debug > 2) {
  4063. error_log('New LP - Problem in update_reinit() - could not find LP ' . $this->get_id() . ' in DB', 0);
  4064. }
  4065. }
  4066. return -1;
  4067. }
  4068. /**
  4069. * Updates the "scorm_debug" value that shows or hide the debug window
  4070. * @return boolean True if scorm_debug has been set to 'on', false otherwise (or 1 or 0 in this case)
  4071. */
  4072. public function update_scorm_debug() {
  4073. if ($this->debug > 0) {
  4074. error_log('New LP - In learnpath::update_scorm_debug()', 0);
  4075. }
  4076. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  4077. $sql = "SELECT * FROM $lp_table WHERE id = " . $this->get_id();
  4078. $res = Database::query($sql);
  4079. if (Database :: num_rows($res) > 0) {
  4080. $row = Database :: fetch_array($res);
  4081. $force = $row['debug'];
  4082. if ($force == 1) {
  4083. $force = 0;
  4084. } elseif ($force == 0) {
  4085. $force = 1;
  4086. }
  4087. $sql = "UPDATE $lp_table SET debug = $force WHERE id = " . $this->get_id();
  4088. $res = Database::query($sql);
  4089. $this->scorm_debug = $force;
  4090. return $force;
  4091. } else {
  4092. if ($this->debug > 2) {
  4093. error_log('New LP - Problem in update_scorm_debug() - could not find LP ' . $this->get_id() . ' in DB', 0);
  4094. }
  4095. }
  4096. return -1;
  4097. }
  4098. /**
  4099. * Function that makes a call to the function sort_tree_array and create_tree_array
  4100. * @author Kevin Van Den Haute
  4101. * @param array
  4102. */
  4103. public function tree_array($array) {
  4104. if ($this->debug > 1) {
  4105. error_log('New LP - In learnpath::tree_array()', 0);
  4106. }
  4107. $array = $this->sort_tree_array($array);
  4108. $this->create_tree_array($array);
  4109. }
  4110. /**
  4111. * Creates an array with the elements of the learning path tree in it
  4112. *
  4113. * @author Kevin Van Den Haute
  4114. * @param array $array
  4115. * @param int $parent
  4116. * @param int $depth
  4117. * @param array $tmp
  4118. */
  4119. public function create_tree_array($array, $parent = 0, $depth = -1, $tmp = array ()) {
  4120. if ($this->debug > 1) {
  4121. error_log('New LP - In learnpath::create_tree_array())', 0);
  4122. }
  4123. if (is_array($array)) {
  4124. for ($i = 0; $i < count($array); $i++) {
  4125. if ($array[$i]['parent_item_id'] == $parent) {
  4126. if (!in_array($array[$i]['parent_item_id'], $tmp)) {
  4127. $tmp[] = $array[$i]['parent_item_id'];
  4128. $depth++;
  4129. }
  4130. $preq = (empty($array[$i]['prerequisite']) ? '' : $array[$i]['prerequisite']);
  4131. $audio = isset($array[$i]['audio']) ? $array[$i]['audio'] : null;
  4132. $this->arrMenu[] = array (
  4133. 'id' => $array[$i]['id'],
  4134. 'item_type' => $array[$i]['item_type'],
  4135. 'title' => $array[$i]['title'],
  4136. 'path' => $array[$i]['path'],
  4137. 'description' => $array[$i]['description'],
  4138. 'parent_item_id' => $array[$i]['parent_item_id'],
  4139. 'previous_item_id' => $array[$i]['previous_item_id'],
  4140. 'next_item_id' => $array[$i]['next_item_id'],
  4141. 'min_score' => $array[$i]['min_score'],
  4142. 'max_score' => $array[$i]['max_score'],
  4143. 'mastery_score' => $array[$i]['mastery_score'],
  4144. 'display_order' => $array[$i]['display_order'],
  4145. 'prerequisite' => $preq,
  4146. 'depth' => $depth,
  4147. 'audio' => $audio
  4148. );
  4149. $this->create_tree_array($array, $array[$i]['id'], $depth, $tmp);
  4150. }
  4151. }
  4152. }
  4153. }
  4154. /**
  4155. * Sorts a multi dimensional array by parent id and display order
  4156. * @author Kevin Van Den Haute
  4157. *
  4158. * @param array $array (array with al the learning path items in it)
  4159. *
  4160. * @return array
  4161. */
  4162. public function sort_tree_array($array) {
  4163. foreach ($array as $key => $row) {
  4164. $parent[$key] = $row['parent_item_id'];
  4165. $position[$key] = $row['display_order'];
  4166. }
  4167. if (count($array) > 0)
  4168. array_multisort($parent, SORT_ASC, $position, SORT_ASC, $array);
  4169. return $array;
  4170. }
  4171. /**
  4172. * Function that creates a table structure with a learning path his modules, chapters and documents.
  4173. * Also the actions for the modules, chapters and documents are in this table.
  4174. * @author Kevin Van Den Haute
  4175. * @param int $lp_id
  4176. * @return string
  4177. */
  4178. public function overview() {
  4179. $is_allowed_to_edit = api_is_allowed_to_edit(null,true);
  4180. if ($this->debug > 0) {
  4181. error_log('New LP - In learnpath::overview()', 0);
  4182. }
  4183. global $charset, $_course;
  4184. $_SESSION['gradebook'] = isset($_GET['gradebook']) ? Security :: remove_XSS($_GET['gradebook']) : null;
  4185. $return = '';
  4186. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  4187. $sql = "SELECT * FROM " . $tbl_lp_item . "
  4188. WHERE lp_id = " . $this->lp_id;
  4189. $result = Database::query($sql);
  4190. $arrLP = array ();
  4191. while ($row = Database :: fetch_array($result)) {
  4192. $row['title'] = Security :: remove_XSS($row['title']);
  4193. $row['description'] = Security :: remove_XSS($row['description']);
  4194. $arrLP[] = array (
  4195. 'id' => $row['id'],
  4196. 'item_type' => $row['item_type'],
  4197. 'title' => $row['title'],
  4198. 'path' => $row['path'],
  4199. 'description' => $row['description'],
  4200. 'parent_item_id' => $row['parent_item_id'],
  4201. 'previous_item_id' => $row['previous_item_id'],
  4202. 'next_item_id' => $row['next_item_id'],
  4203. 'max_score' => $row['max_score'],
  4204. 'min_score' => $row['min_score'],
  4205. 'mastery_score' => $row['mastery_score'],
  4206. 'prerequisite' => $row['prerequisite'],
  4207. 'display_order' => $row['display_order'],
  4208. 'audio' => $row['audio']
  4209. );
  4210. }
  4211. $this->tree_array($arrLP);
  4212. $arrLP = $this->arrMenu;
  4213. unset ($this->arrMenu);
  4214. $update_audio = isset($_GET['updateaudio']) ? $_GET['updateaudio'] : null;
  4215. if ($is_allowed_to_edit) {
  4216. $token = Security::get_token();
  4217. $gradebook = isset($_GET['gradebook']) ? Security :: remove_XSS($_GET['gradebook']) : null;
  4218. $return .= '<div class="actions">';
  4219. $return .= '<a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&amp;gradebook=' . $gradebook . '&amp;action=build&amp;lp_id=' . $this->lp_id . '" title="' . get_lang('Build') . '">' . Display :: return_icon('build_learnpath.png', get_lang('Build'),'','32').'</a>';
  4220. if ($update_audio == 'true') {
  4221. $return .='<a href="lp_controller.php?cidReq='.Security::remove_XSS($_GET['cidReq']) .'&amp;gradebook='.$gradebook.'&amp;action=admin_view&amp;lp_id=' . $_SESSION['oLP']->lp_id . '" title="'.get_lang('BasicOverview').'">'.Display::return_icon('move_learnpath.png', get_lang('BasicOverview'),'','32').'</a>';
  4222. } else {
  4223. $return .= Display :: return_icon('move_learnpath_na.png', get_lang('BasicOverview'),'',32);
  4224. }
  4225. $return .= '<a href="lp_controller.php?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&action=view&lp_id=' . $this->lp_id . '">' . Display :: return_icon('view_left_right.png', get_lang('Display'),'','32').'</a>';
  4226. $return .= ' '.Display :: return_icon('i.gif');
  4227. $return .= '<a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&amp;gradebook=' . $gradebook . '&amp;action=add_item&amp;type=step&amp;lp_id=' . $_SESSION['oLP']->lp_id . '" title="' . get_lang('NewStep') . '">
  4228. '. Display :: return_icon('new_learnigpath_object.png', get_lang('NewStep'),'','32').'</a>';
  4229. $return .= '<a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&amp;gradebook=' . $gradebook . '&amp;action=add_item&amp;type=chapter&amp;lp_id=' . $_SESSION['oLP']->lp_id . '" title="' . get_lang('NewChapter') . '">
  4230. '. Display :: return_icon('add_learnpath_section.png', get_lang('NewChapter'),'','32').'</a>';
  4231. if ($update_audio == 'true') {
  4232. $return .= Display::url(Display :: return_icon('upload_audio_na.png', get_lang('UpdateAllAudioFragments'),'','32'),'#');
  4233. } else {
  4234. $return .= '<a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&amp;action=' . Security :: remove_XSS($_GET['action']) . '&amp;lp_id=' . $_SESSION['oLP']->lp_id . '&amp;updateaudio=true">' . Display :: return_icon('upload_audio.png', get_lang('UpdateAllAudioFragments'),'','32').'</a>';
  4235. }
  4236. $return .= '<a href="lp_controller.php?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&amp;action=edit&amp;lp_id=' . $_SESSION['oLP']->lp_id . '">' . Display :: return_icon('settings.png', get_lang('CourseSettings'),'','32').'</a>';
  4237. $return .= '</div>';
  4238. }
  4239. // we need to start a form when we want to update all the mp3 files
  4240. if ($update_audio == 'true' AND count($arrLP) <> 0) {
  4241. $return .= '<form action="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&amp;updateaudio=' . Security :: remove_XSS($_GET['updateaudio']) .'&amp;action=' . Security :: remove_XSS($_GET['action']) . '&amp;lp_id=' . $_SESSION['oLP']->lp_id . '" method="post" enctype="multipart/form-data" name="updatemp3" id="updatemp3">';
  4242. //$return .= Display::return_message(get_lang('LeaveEmptyToKeepCurrentFile'), 'warning');
  4243. }
  4244. $return .= '<div id="message"></div>';
  4245. $return_audio .= '<table class="data_table">';
  4246. $return_audio .= '<tr>';
  4247. $return_audio .= '<th width="60%">' . get_lang('Title') . '</th>';
  4248. $return_audio .= '<th>' . get_lang('Audio') . '</th>';
  4249. //$return_audio .= '<th>' . get_lang('Actions') . '</th>';
  4250. $return_audio .= '</tr>';
  4251. $elements = array();
  4252. for ($i = 0; $i < count($arrLP); $i++) {
  4253. $title = $arrLP[$i]['title'];
  4254. if (($i % 2) == 0) {
  4255. $oddclass = 'row_odd';
  4256. } else {
  4257. $oddclass = 'row_even';
  4258. }
  4259. $return_audio .= '<tr id ="lp_item_'.$arrLP[$i]['id'] .'" class="' . $oddclass . '">';
  4260. // "lp_item_'.$i.' is important for the drag and drop otherwise the LP will not work
  4261. $icon_name = str_replace(' ', '', $arrLP[$i]['item_type']);
  4262. /*
  4263. if (file_exists('../img/lp_' . $icon_name . '.png')) {
  4264. $return .= '<td style="padding-left:' . $arrLP[$i]['depth'] * 10 . 'px;"><img align="left" src="../img/lp_' . $icon_name . '.png" style="margin-right:3px;" />' . $title . '</td>';
  4265. } else {
  4266. if (file_exists('../img/lp_' . $icon_name . '.gif')) {
  4267. $return .= '<td style="padding-left:' . $arrLP[$i]['depth'] * 10 . 'px;"><img align="left" src="../img/lp_' . $icon_name . '.gif" style="margin-right:3px;" />' . $title . '</td>';
  4268. } else {
  4269. //$return .= '<td style="padding-left:' . $arrLP[$i]['depth'] * 10 . 'px;">' . Display::display_icon('folder_document.gif','',array('style'=>'margin-right:3px;')) . $title . '</td>';
  4270. $return .= '<td style="padding-left:' . $arrLP[$i]['depth'] * 10 . 'px;"><img align="left" src="../img/folder_document.gif" style="margin-right:3px;" />' . $title . '</td>';
  4271. }
  4272. }*/
  4273. $icon = '';
  4274. if (file_exists('../img/lp_' . $icon_name . '.png')) {
  4275. $icon = '<img align="left" src="../img/lp_' . $icon_name . '.png" style="margin-right:3px;" />';
  4276. } else {
  4277. if (file_exists('../img/lp_' . $icon_name . '.gif')) {
  4278. $icon = '<img align="left" src="../img/lp_' . $icon_name . '.gif" style="margin-right:3px;" />';
  4279. } else {
  4280. $icon = '<img align="left" src="../img/folder_document.gif" style="margin-right:3px;" />';
  4281. }
  4282. }
  4283. // The audio column.
  4284. $return_audio .= '<td align="center">';
  4285. $audio = '';
  4286. if (!$update_audio OR $update_audio <> 'true') {
  4287. if (!empty ($arrLP[$i]['audio'])) {
  4288. $audio .= '<span id="container'.$i.'"><a href="http://www.macromedia.com/go/getflashplayer">Get the Flash Player</a> to see this player.</span>';
  4289. $audio .= '<script type="text/javascript" src="../inc/lib/mediaplayer/swfobject.js"></script>';
  4290. $audio .= '<script type="text/javascript">
  4291. var s1 = new SWFObject("../inc/lib/mediaplayer/player.swf","ply","250","20","9","#FFFFFF");
  4292. s1.addParam("allowscriptaccess","always");
  4293. s1.addParam("flashvars","file=../../courses/' . $_course['path'] . '/document/audio/' . $arrLP[$i]['audio'] . '");
  4294. s1.write("container' . $i . '");
  4295. </script>';
  4296. } else {
  4297. $audio .= '';
  4298. }
  4299. } else {
  4300. if ($arrLP[$i]['item_type'] != 'dokeos_chapter' && $arrLP[$i]['item_type'] != 'dokeos_module' && $arrLP[$i]['item_type'] != 'dir') {
  4301. $audio .= '<input type="file" name="mp3file' . $arrLP[$i]['id'] . '" id="mp3file" />';
  4302. if (!empty ($arrLP[$i]['audio'])) {
  4303. $audio .= '<br />'.Security::remove_XSS($arrLP[$i]['audio']).'<br /><input type="checkbox" name="removemp3' . $arrLP[$i]['id'] . '" id="checkbox' . $arrLP[$i]['id'] . '" />' . get_lang('RemoveAudio');
  4304. }
  4305. }
  4306. }
  4307. $return_audio .= Display::span($title.$icon).Display::tag('td', $audio, array('style'=>'text-align:right'));
  4308. $return_audio .= '</td>';
  4309. $move_icon = '';
  4310. $edit_icon = '';
  4311. $delete_icon = '';
  4312. if ($is_allowed_to_edit) {
  4313. if (!$update_audio OR $update_audio <> 'true') {
  4314. $move_icon .= '<a class="moved" href="#">';
  4315. $move_icon .= Display::return_icon('move.png', get_lang('Move'), array(), 24);
  4316. $move_icon .= '</a>';
  4317. }
  4318. if ($arrLP[$i]['item_type'] != 'dokeos_chapter' && $arrLP[$i]['item_type'] != 'dokeos_module') {
  4319. $edit_icon .= '<a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&amp;action=edit_item&amp;view=build&amp;id=' . $arrLP[$i]['id'] . '&amp;lp_id=' . $this->lp_id . '&amp;path_item=' . $arrLP[$i]['path'] . '">';
  4320. $edit_icon .= '<img style="margin:1px;" alt="" src="../img/edit.png" title="' . get_lang('_edit_learnpath_module') . '" />';
  4321. $edit_icon .= '</a>';
  4322. } else {
  4323. $edit_icon .= '<a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&amp;action=edit_item&amp;id=' . $arrLP[$i]['id'] . '&amp;lp_id=' . $this->lp_id . '&amp;path_item=' . $arrLP[$i]['path'] . '">';
  4324. $edit_icon .= '<img style="margin:1px;" alt="" src="../img/edit.png" title="' . get_lang('_edit_learnpath_module') . '" />';
  4325. $edit_icon .= '</a>';
  4326. }
  4327. $delete_icon .= '<a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&amp;action=delete_item&amp;id=' . $arrLP[$i]['id'] . '&amp;lp_id=' . $this->lp_id . '" onClick="return confirmation(\'' . addslashes($title) . '\');">';
  4328. $delete_icon .= '<img style="margin:1px;" alt="" src="../img/delete.png" title="' . get_lang('_delete_learnpath_module') . '" />';
  4329. $delete_icon .= '</a>';
  4330. }
  4331. if ($update_audio != 'true') {
  4332. $row = $move_icon.Display::span($title.$icon).Display::span($audio.$edit_icon.$delete_icon, array('class'=>'button_actions'));
  4333. } else {
  4334. $row = Display::span($title.$icon).Display::span($audio, array('class'=>'button_actions'));
  4335. }
  4336. $parent_id = $arrLP[$i]['parent_item_id'];
  4337. $default_data[$arrLP[$i]['id']] = $row;
  4338. $default_content[$arrLP[$i]['id']] = $arrLP[$i];
  4339. if (empty($parent_id)) {
  4340. $elements[$arrLP[$i]['id']]['data'] = $row;
  4341. $elements[$arrLP[$i]['id']]['type'] = $arrLP[$i]['item_type'];
  4342. } else {
  4343. $parent_arrays = array();
  4344. if ($arrLP[$i]['depth'] > 1) {
  4345. //Getting list of parents
  4346. for($j = 0; $j < $arrLP[$i]['depth']; $j++) {
  4347. foreach($arrLP as $item) {
  4348. if ($item['id'] == $parent_id) {
  4349. if ($item['parent_item_id'] == 0) {
  4350. $parent_id = $item['id'];
  4351. //$parent_arrays[] = $parent_id;
  4352. break;
  4353. } else {
  4354. $parent_id = $item['parent_item_id'];
  4355. if (empty($parent_arrays)) {
  4356. $parent_arrays[] = intval($item['id']);
  4357. }
  4358. $parent_arrays[] = $parent_id;
  4359. break;
  4360. }
  4361. }
  4362. }
  4363. }
  4364. }
  4365. if (!empty($parent_arrays)) {
  4366. $parent_arrays = array_reverse($parent_arrays);
  4367. $value_to_insert = array();
  4368. $val = '$elements';
  4369. $x = 0;
  4370. foreach($parent_arrays as $item) {
  4371. if ($x != count($parent_arrays) -1) {
  4372. $val .= '["'.$item.'"]["children"]';
  4373. } else {
  4374. $val .= '["'.$item.'"]["children"]';
  4375. }
  4376. $x++;
  4377. }
  4378. $val .= "";
  4379. $generated_array = null;
  4380. $code_str = $val."[".$arrLP[$i]['id']."][\"load_data\"] = '".$arrLP[$i]['id']."' ; ";
  4381. eval($code_str);
  4382. } else {
  4383. $elements[$parent_id]['children'][$arrLP[$i]['id']]['data'] = $row;
  4384. $elements[$parent_id]['children'][$arrLP[$i]['id']]['type'] = $arrLP[$i]['item_type'];
  4385. }
  4386. }
  4387. }
  4388. //@todo move this somewhere else
  4389. function print_recursive($elements, $default_data, $default_content) {
  4390. $return = '';
  4391. foreach($elements as $key => $item) {
  4392. if (isset($item['load_data']) || empty($item['data'])) {
  4393. $item['data'] = $default_data[$item['load_data']];
  4394. $item['type'] = $default_content[$item['load_data']]['item_type'];
  4395. }
  4396. $sub_list = '';
  4397. if (isset($item['type']) && $item['type'] == 'dokeos_chapter') {
  4398. $sub_list = Display::tag('li', '', array('class'=>'sub_item empty')); // empty value
  4399. }
  4400. if (empty($item['children'])) {
  4401. $sub_list = Display::tag('ul', $sub_list, array('id'=>'UL_'.$key, 'class'=>'record container'));
  4402. $return .= Display::tag('li', Display::div($item['data'], array('class'=>'item_data')).$sub_list, array('id'=>$key, 'class'=>'record container'));
  4403. } else {
  4404. //sections
  4405. if (isset($item['children'])) {
  4406. $data = print_recursive($item['children'], $default_data, $default_content);
  4407. }
  4408. /*foreach($item['children'] as $my_key => $sub_item) {
  4409. $sub_list .= Display::tag('li', $sub_item['data'], array('id'=>$my_key,'class'=>'record item'));
  4410. }*/
  4411. $sub_list = Display::tag('ul', $sub_list.$data, array('id'=>'UL_'.$key, 'class'=>'record container'));
  4412. $return .= Display::tag('li', Display::div($item['data'], array('class'=>'item_data')).$sub_list, array('id'=>$key, 'class'=>'record container'));
  4413. }
  4414. }
  4415. return $return;
  4416. }
  4417. if ($update_audio != 'true') {
  4418. $return .= '<div style="width:90%;"><ul id="lp_item_list">';
  4419. $return .= print_recursive($elements, $default_data, $default_content);
  4420. $return .='</ul></div>';
  4421. $return .= Display::div(Display::url(get_lang('Save'), '#', array('id'=>'listSubmit', 'class'=>'a_button orange medium')), array('style'=>'float:left; margin-top:15px;width:100%'));
  4422. } else {
  4423. $return .= $return_audio.'</table>';
  4424. }
  4425. /*
  4426. if (count($arrLP) == 0) {
  4427. $return .= '<tr>';
  4428. $return .= '<td colspan="4">' . get_lang('NoItemsInLp') . '</td>';
  4429. $return .= '</tr>';
  4430. }*/
  4431. // We need to close the form when we are updating the mp3 files.
  4432. if ($update_audio == 'true') {
  4433. $return .= '<div style="margin:40px 0; float:right;"><button class="save" type="submit" name="save_audio" id="save_audio">' . get_lang('SaveAudioAndOrganization') . '</button></div>'; // TODO: What kind of language variable is this?
  4434. }
  4435. // We need to close the form when we are updating the mp3 files.
  4436. if ($update_audio == 'true' && count($arrLP) != 0) {
  4437. $return .= '</form>';
  4438. }
  4439. return $return;
  4440. }
  4441. /**
  4442. * This function builds the action menu
  4443. * @return void
  4444. */
  4445. public function build_action_menu() {
  4446. $gradebook = isset($_GET['gradebook']) ? Security :: remove_XSS($_GET['gradebook']) : null;
  4447. echo '<div class="actions">';
  4448. echo Display :: return_icon('build_learnpath_na.png', get_lang('Build'),'','32');
  4449. echo '<a href="' . api_get_self().'?'.api_get_cidreq().'&amp;gradebook=' . $gradebook . '&amp;action=admin_view&amp;lp_id=' . $_SESSION['oLP']->lp_id . '" title="' . get_lang('BasicOverview') . '">' . Display :: return_icon('move_learnpath.png', get_lang('BasicOverview'),'','32').'</a>';
  4450. echo '<a href="lp_controller.php?'.api_get_cidreq().'&amp;gradebook=' . $gradebook . '&action=view&lp_id=' . $_SESSION['oLP']->lp_id . '">' . Display :: return_icon('view_left_right.png', get_lang('Display'),'','32').'</a> ';
  4451. Display :: display_icon('i.gif');
  4452. echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&amp;gradebook=' . $gradebook . '&amp;action=add_item&amp;type=step&amp;lp_id=' . $_SESSION['oLP']->lp_id . '" title="' . get_lang('NewStep') . '">' . Display :: return_icon('new_learnigpath_object.png', get_lang('NewStep'),'','32').'</a>';
  4453. echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&amp;gradebook=' . $gradebook . '&amp;action=add_item&amp;type=chapter&amp;lp_id=' . $_SESSION['oLP']->lp_id . '" title="' . get_lang('NewChapter') . '">' . Display :: return_icon('add_learnpath_section.png', get_lang('NewChapter'),'','32').'</a>';
  4454. echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&amp;action=admin_view&amp;lp_id=' . $_SESSION['oLP']->lp_id . '&amp;updateaudio=true">' . Display :: return_icon('upload_audio.png', get_lang('UpdateAllAudioFragments'),'','32').'</a>';
  4455. echo '<a href="lp_controller.php?'.api_get_cidreq().'&amp;action=edit&amp;lp_id=' . $_SESSION['oLP']->lp_id . '">' . Display :: return_icon('settings.png', get_lang('CourseSettings'),'','32').'</a>';
  4456. echo '</div>';
  4457. }
  4458. /**
  4459. * This functions builds the LP tree based on data from the database.
  4460. * @return string
  4461. * @uses dtree.js :: necessary javascript for building this tree
  4462. */
  4463. public function build_tree() {
  4464. $return = "<script type=\"text/javascript\">\n";
  4465. $return .= "\tm = new dTree('m');\n\n";
  4466. $return .= "\tm.config.folderLinks = true;\n";
  4467. $return .= "\tm.config.useCookies = true;\n";
  4468. $return .= "\tm.config.useIcons = true;\n";
  4469. $return .= "\tm.config.useLines = true;\n";
  4470. $return .= "\tm.config.useSelection = true;\n";
  4471. $return .= "\tm.config.useStatustext = false;\n\n";
  4472. $menu = 0;
  4473. $parent = '';
  4474. $return .= "\tm.add(" . $menu . ", -1, '" . addslashes(Security::remove_XSS(($this->name))) . "');\n";
  4475. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  4476. $sql = " SELECT id, title, description, item_type, path, parent_item_id, previous_item_id, next_item_id, max_score, min_score, mastery_score, display_order
  4477. FROM $tbl_lp_item
  4478. WHERE lp_id = " . Database :: escape_string($this->lp_id);
  4479. $result = Database::query($sql);
  4480. $arrLP = array ();
  4481. while ($row = Database :: fetch_array($result)) {
  4482. $row['title'] = Security :: remove_XSS($row['title']);
  4483. $row['description'] = Security :: remove_XSS($row['description']);
  4484. $arrLP[] = array (
  4485. 'id' => $row['id'],
  4486. 'item_type' => $row['item_type'],
  4487. 'title' => $row['title'],
  4488. 'path' => $row['path'],
  4489. 'description' => $row['description'],
  4490. 'parent_item_id' => $row['parent_item_id'],
  4491. 'previous_item_id' => $row['previous_item_id'],
  4492. 'next_item_id' => $row['next_item_id'],
  4493. 'max_score' => $row['max_score'],
  4494. 'min_score' => $row['min_score'],
  4495. 'mastery_score' => $row['mastery_score'],
  4496. 'display_order' => $row['display_order']
  4497. );
  4498. }
  4499. $this->tree_array($arrLP);
  4500. $arrLP = $this->arrMenu;
  4501. unset ($this->arrMenu);
  4502. $title = '';
  4503. for ($i = 0; $i < count($arrLP); $i++) {
  4504. $title = addslashes($arrLP[$i]['title']);
  4505. $menu_page = api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&amp;action=view_item&amp;id=' . $arrLP[$i]['id'] . '&amp;lp_id=' . $_SESSION['oLP']->lp_id;
  4506. $icon_name = str_replace(' ', '', $arrLP[$i]['item_type']);
  4507. if (file_exists('../img/lp_' . $icon_name . '.png')) {
  4508. $return .= "\tm.add(" . $arrLP[$i]['id'] . ", " . $arrLP[$i]['parent_item_id'] . ", '" . $title . "', '" . $menu_page . "', '', '', '../img/lp_" . $icon_name . ".png', '../img/lp_" . $icon_name . ".png');\n";
  4509. } else
  4510. if (file_exists('../img/lp_' . $icon_name . '.gif')) {
  4511. $return .= "\tm.add(" . $arrLP[$i]['id'] . ", " . $arrLP[$i]['parent_item_id'] . ", '" . $title . "', '" . $menu_page . "', '', '', '../img/lp_" . $icon_name . ".gif', '../img/lp_" . $icon_name . ".gif');\n";
  4512. } else {
  4513. $return .= "\tm.add(" . $arrLP[$i]['id'] . ", " . $arrLP[$i]['parent_item_id'] . ", '" . $title . "', '" . $menu_page . "', '', '', '../img/folder_document.gif', '../img/folder_document.gif');\n";
  4514. }
  4515. if ($menu < $arrLP[$i]['id'])
  4516. $menu = $arrLP[$i]['id'];
  4517. }
  4518. $return .= "\n\tdocument.write(m);\n";
  4519. $return .= "\t if(!m.selectedNode) m.s(1);";
  4520. $return .= "</script>\n";
  4521. return $return;
  4522. }
  4523. public function generate_lp_folder($course, $dir) {
  4524. $filepath = '';
  4525. //Creating learning_path folder
  4526. $dir = '/learning_path';
  4527. $filepath = api_get_path(SYS_COURSE_PATH) . $course['path'] . '/document';
  4528. $folder = null;
  4529. if (!is_dir($filepath.'/'.$dir)) {
  4530. $folder = create_unexisting_directory($course, api_get_user_id(), api_get_session_id(), 0, 0, $filepath, $dir , get_lang('LearningPaths'));
  4531. } else {
  4532. $folder = true;
  4533. }
  4534. $dir = '/learning_path/';
  4535. //Creating LP folder
  4536. if ($folder) {
  4537. //Limits title size
  4538. $title = api_substr(replace_dangerous_char($this->name), 0 , 80);
  4539. $dir = $dir.$title;
  4540. $filepath = api_get_path(SYS_COURSE_PATH) . $course['path'] . '/document';
  4541. if (!is_dir($filepath.'/'.$dir)) {
  4542. $folder = create_unexisting_directory($course, api_get_user_id(), api_get_session_id(), 0, 0, $filepath, $dir , $this->name);
  4543. } else {
  4544. $folder = true;
  4545. }
  4546. $dir = $dir.'/';
  4547. if ($folder) {
  4548. $filepath = api_get_path(SYS_COURSE_PATH) . $course['path'] . '/document'.$dir;
  4549. }
  4550. }
  4551. $array = array('dir' => $dir, 'filepath' => $filepath);
  4552. return $array;
  4553. }
  4554. /**
  4555. * Create a new document //still needs some finetuning
  4556. * @param array $_course
  4557. * @return string
  4558. */
  4559. public function create_document($_course) {
  4560. global $charset;
  4561. $dir = isset ($_GET['dir']) ? $_GET['dir'] : $_POST['dir']; // Please, do not modify this dirname formatting.
  4562. if (strstr($dir, '..'))
  4563. $dir = '/';
  4564. if ($dir[0] == '.')
  4565. $dir = substr($dir, 1);
  4566. if ($dir[0] != '/')
  4567. $dir = '/' . $dir;
  4568. if ($dir[strlen($dir) - 1] != '/')
  4569. $dir .= '/';
  4570. $filepath = api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document' . $dir;
  4571. if (empty($_POST['dir']) && empty($_GET['dir'])) {
  4572. $result = $this->generate_lp_folder($_course, $dir);
  4573. $dir = $result['dir'];
  4574. $filepath = $result['filepath'];
  4575. }
  4576. if (!is_dir($filepath)) {
  4577. $filepath = api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document/';
  4578. $dir = '/';
  4579. }
  4580. // stripslashes() before calling replace_dangerous_char() because $_POST['title']
  4581. // is already escaped twice when it gets here.
  4582. $title = replace_dangerous_char(stripslashes($_POST['title']));
  4583. $title = disable_dangerous_file($title);
  4584. $filename = $title;
  4585. $content = $_POST['content_lp'];
  4586. $tmp_filename = $filename;
  4587. $i = 0;
  4588. while (file_exists($filepath . $tmp_filename . '.html'))
  4589. $tmp_filename = $filename . '_' . ++ $i;
  4590. $filename = $tmp_filename . '.html';
  4591. $content = stripslashes($content);
  4592. $content = str_replace(api_get_path(WEB_COURSE_PATH), api_get_path(REL_PATH).'courses/', $content);
  4593. // Change the path of mp3 to absolute.
  4594. // The first regexp deals with ../../../ urls.
  4595. $content = preg_replace("|(flashvars=\"file=)(\.+/)+|", "$1" . api_get_path(REL_COURSE_PATH) . $_course['path'] . '/document/', $content);
  4596. // The second regexp deals with audio/ urls.
  4597. $content = preg_replace("|(flashvars=\"file=)([^/]+)/|", "$1" . api_get_path(REL_COURSE_PATH) . $_course['path'] . '/document/$2/', $content);
  4598. // For flv player: To prevent edition problem with firefox, we have to use a strange tip (don't blame me please).
  4599. $content = str_replace('</body>', '<style type="text/css">body{}</style></body>', $content);
  4600. if (!file_exists($filepath . $filename)) {
  4601. if ($fp = @ fopen($filepath . $filename, 'w')) {
  4602. fputs($fp, $content);
  4603. fclose($fp);
  4604. $file_size = filesize($filepath . $filename);
  4605. $save_file_path = $dir.$filename;
  4606. $document_id = add_document($_course, $save_file_path, 'file', $file_size, $tmp_filename);
  4607. if ($document_id) {
  4608. api_item_property_update($_course, TOOL_DOCUMENT, $document_id, 'DocumentAdded', api_get_user_id(), null, null, null, null, api_get_session_id());
  4609. $new_comment = (isset($_POST['comment'])) ? trim($_POST['comment']) : '';
  4610. $new_title = (isset($_POST['title'])) ? trim($_POST['title']) : '';
  4611. if ($new_comment || $new_title) {
  4612. $tbl_doc = Database :: get_course_table(TABLE_DOCUMENT);
  4613. $ct = '';
  4614. if ($new_comment)
  4615. $ct .= ", comment='" . Database::escape_string($new_comment). "'";
  4616. if ($new_title)
  4617. $ct .= ", title='" . Database :: escape_string(htmlspecialchars($new_title, ENT_QUOTES, $charset))."' ";
  4618. $sql_update = "UPDATE " . $tbl_doc ." SET " . substr($ct, 1)." WHERE id = " . $document_id;
  4619. Database::query($sql_update);
  4620. }
  4621. }
  4622. return $document_id;
  4623. }
  4624. }
  4625. }
  4626. /**
  4627. * Edit a document based on $_POST and $_GET parameters 'dir' and 'path'
  4628. * @param array $_course array
  4629. * @return void
  4630. */
  4631. public function edit_document($_course) {
  4632. global $_configuration;
  4633. $dir = isset ($_GET['dir']) ? $_GET['dir'] : $_POST['dir']; // Please, do not modify this dirname formatting.
  4634. if (strstr($dir, '..'))
  4635. $dir = '/';
  4636. if ($dir[0] == '.')
  4637. $dir = substr($dir, 1);
  4638. if ($dir[0] != '/')
  4639. $dir = '/' . $dir;
  4640. if ($dir[strlen($dir) - 1] != '/')
  4641. $dir .= '/';
  4642. $filepath = api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document' . $dir;
  4643. if (!is_dir($filepath)) {
  4644. $filepath = api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document/';
  4645. $dir = '/';
  4646. }
  4647. $table_doc = Database :: get_course_table(TABLE_DOCUMENT);
  4648. if (isset($_POST['path']) && !empty($_POST['path'])) {
  4649. $document_id = intval($_POST['path']);
  4650. $sql = "SELECT path FROM " . $table_doc . " WHERE id = " . $document_id;
  4651. $res = Database::query($sql);
  4652. $row = Database :: fetch_array($res);
  4653. $content = stripslashes($_POST['content_lp']);
  4654. $file = $filepath . $row['path'];
  4655. if ($fp = @ fopen($file, 'w')) {
  4656. $content = text_filter($content);
  4657. $content = str_replace(api_get_path(WEB_COURSE_PATH), $_configuration['url_append'] . '/courses/', $content);
  4658. // Change the path of mp3 to absolute.
  4659. // The first regexp deals with ../../../ urls.
  4660. $content = preg_replace("|(flashvars=\"file=)(\.+/)+|", "$1" . api_get_path(REL_COURSE_PATH) . $_course['path'] . '/document/', $content);
  4661. // The second regexp deals with audio/ urls.
  4662. $content = preg_replace("|(flashvars=\"file=)([^/]+)/|", "$1" . api_get_path(REL_COURSE_PATH) . $_course['path'] . '/document/$2/', $content);
  4663. fputs($fp, $content);
  4664. fclose($fp);
  4665. $sql_update = "UPDATE " . $table_doc ." SET title='".Database::escape_string($_POST['title'])."' WHERE id = " . $document_id;
  4666. Database::query($sql_update);
  4667. }
  4668. }
  4669. }
  4670. /**
  4671. * Displays the selected item, with a panel for manipulating the item
  4672. * @param int $item_id
  4673. * @param string $msg
  4674. * @return string
  4675. */
  4676. public function display_item($item_id, $iframe = true, $msg = '') {
  4677. global $_course; // It will disappear.
  4678. $return = '';
  4679. if (is_numeric($item_id)) {
  4680. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  4681. $tbl_doc = Database :: get_course_table(TABLE_DOCUMENT);
  4682. $sql = "SELECT lp.* FROM " . $tbl_lp_item . " as lp
  4683. WHERE lp.id = " . Database :: escape_string($item_id);
  4684. $result = Database::query($sql);
  4685. while ($row = Database :: fetch_array($result)) {
  4686. $_SESSION['parent_item_id'] = ($row['item_type'] == 'dokeos_chapter' || $row['item_type'] == 'dokeos_module' || $row['item_type'] == 'dir') ? $item_id : 0;
  4687. // Prevents wrong parent selection for document, see Bug#1251.
  4688. if ($row['item_type'] != 'dokeos_chapter' || $row['item_type'] != 'dokeos_module') {
  4689. $_SESSION['parent_item_id'] = $row['parent_item_id'];
  4690. }
  4691. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4692. $return .= '<div style="padding:10px;">';
  4693. if ($msg != '')
  4694. $return .= $msg;
  4695. $return .= '<p class="lp_title">' . $row['title'] . '</p>';
  4696. //$return .= '<p class="lp_text">' . ((trim($row['description']) == '') ? 'no description' : stripslashes($row['description'])) . '</p>';
  4697. //$return .= '<hr />';
  4698. switch ($row['item_type']) {
  4699. case TOOL_QUIZ:
  4700. if (!empty($row['path'])) {
  4701. require_once api_get_path(SYS_CODE_PATH).'exercice/exercise.class.php';
  4702. $exercise = new Exercise();
  4703. $exercise->read($row['path']);
  4704. // $exercise_url = api_get_path(WEB_CODE_PATH).'exercice/admin.php?exerciseId='.$exercise->id.'&'.api_get_cidReq().'&id_session='.api_get_session_id();
  4705. $return .=$exercise->description.'<br />';
  4706. //$return .=Display::url($exercise_url, $exercise_url).'<br />';*/
  4707. }
  4708. break;
  4709. case TOOL_DOCUMENT:
  4710. $tbl_doc = Database :: get_course_table(TABLE_DOCUMENT);
  4711. $sql_doc = "SELECT path FROM " . $tbl_doc . " WHERE id = " . Database :: escape_string($row['path']);
  4712. $result = Database::query($sql_doc);
  4713. $path_file = Database :: result($result, 0, 0);
  4714. $path_parts = pathinfo($path_file);
  4715. // TODO: Correct the following naive comparisons, also, htm extension is missing.
  4716. if (in_array($path_parts['extension'], array (
  4717. 'html',
  4718. 'txt',
  4719. 'png',
  4720. 'jpg',
  4721. 'JPG',
  4722. 'jpeg',
  4723. 'JPEG',
  4724. 'gif',
  4725. 'swf'
  4726. ))) {
  4727. $return .= $this->display_document($row['path'], true, true);
  4728. }
  4729. break;
  4730. }
  4731. $return .= '</div>';
  4732. }
  4733. }
  4734. return $return;
  4735. }
  4736. /**
  4737. * Shows the needed forms for editing a specific item
  4738. * @param int $item_id
  4739. * @return string
  4740. */
  4741. public function display_edit_item($item_id) {
  4742. global $_course; // It will disappear.
  4743. $return = '';
  4744. if (is_numeric($item_id)) {
  4745. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  4746. $sql = "SELECT * FROM $tbl_lp_item WHERE id = " . Database :: escape_string($item_id);
  4747. $res = Database::query($sql);
  4748. $row = Database::fetch_array($res);
  4749. switch ($row['item_type']) {
  4750. case 'dokeos_chapter' :
  4751. case 'dir' :
  4752. case 'asset' :
  4753. case 'sco' :
  4754. if (isset ($_GET['view']) && $_GET['view'] == 'build') {
  4755. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4756. $return .= $this->display_item_form($row['item_type'], get_lang('EditCurrentChapter') . ' :', 'edit', $item_id, $row);
  4757. } else {
  4758. $return .= $this->display_item_small_form($row['item_type'], get_lang('EditCurrentChapter') . ' :', $row);
  4759. }
  4760. break;
  4761. case TOOL_DOCUMENT :
  4762. $tbl_doc = Database :: get_course_table(TABLE_DOCUMENT);
  4763. $sql_step = " SELECT lp.*, doc.path as dir
  4764. FROM " . $tbl_lp_item . " as lp
  4765. LEFT JOIN " . $tbl_doc . " as doc ON doc.id = lp.path
  4766. WHERE lp.id = " . Database :: escape_string($item_id);
  4767. $res_step = Database::query($sql_step);
  4768. $row_step = Database :: fetch_array($res_step);
  4769. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4770. $return .= $this->display_document_form('edit', $item_id, $row_step);
  4771. break;
  4772. case TOOL_LINK :
  4773. $link_id = (string) $row['path'];
  4774. if (ctype_digit($link_id)) {
  4775. $tbl_link = Database :: get_course_table(TABLE_LINK);
  4776. $sql_select = 'SELECT url FROM ' . $tbl_link . ' WHERE id = ' . Database :: escape_string($link_id);
  4777. $res_link = Database::query($sql_select);
  4778. $row_link = Database :: fetch_array($res_link);
  4779. if (is_array($row_link)) {
  4780. $row['url'] = $row_link['url'];
  4781. }
  4782. }
  4783. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4784. $return .= $this->display_link_form('edit', $item_id, $row);
  4785. break;
  4786. case 'dokeos_module' :
  4787. if (isset ($_GET['view']) && $_GET['view'] == 'build') {
  4788. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4789. $return .= $this->display_item_form($row['item_type'], get_lang('EditCurrentModule') . ' :', 'edit', $item_id, $row);
  4790. } else {
  4791. $return .= $this->display_item_small_form($row['item_type'], get_lang('EditCurrentModule') . ' :', $row);
  4792. }
  4793. break;
  4794. case TOOL_QUIZ :
  4795. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4796. $return .= $this->display_quiz_form('edit', $item_id, $row);
  4797. break;
  4798. case TOOL_HOTPOTATOES :
  4799. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4800. $return .= $this->display_hotpotatoes_form('edit', $item_id, $row);
  4801. break;
  4802. case TOOL_STUDENTPUBLICATION :
  4803. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4804. $return .= $this->display_student_publication_form('edit', $item_id, $row);
  4805. break;
  4806. case TOOL_FORUM :
  4807. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4808. $return .= $this->display_forum_form('edit', $item_id, $row);
  4809. break;
  4810. case TOOL_THREAD :
  4811. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4812. $return .= $this->display_thread_form('edit', $item_id, $row);
  4813. break;
  4814. }
  4815. }
  4816. return $return;
  4817. }
  4818. /**
  4819. * Function that displays a list with al the resources that could be added to the learning path
  4820. * @return string
  4821. */
  4822. public function display_resources() {
  4823. global $_course; // TODO: Don't use globals.
  4824. /*$return .= '<div class="sectiontitle">' . get_lang('CreateNewStep') . '</div>';
  4825. $return .= '<div class="sectioncomment"><a href="' . api_get_self() . '?cidReq=' . $_GET['cidReq'] . '&amp;action=add_item&amp;type=' . TOOL_DOCUMENT . '&amp;lp_id=' . $_SESSION['oLP']->lp_id . '">' . '<img title="Nuevo documento" src="../img/new_doc.gif" alt="Nuevo documento"/> ' . get_lang('NewDocument') . '</a></div>';
  4826. $return .= '<div class="sectiontitle">' . get_lang('UseAnExistingResource') . '</div>';*/
  4827. //Get all the docs
  4828. $documents = $this->get_documents();
  4829. //Get all the exercises
  4830. $exercises = $this->get_exercises();
  4831. // Get all the links
  4832. $links = $this->get_links();
  4833. //Get al the student publications
  4834. $works = $this->get_student_publications();
  4835. //Get al the forums
  4836. $forums = $this->get_forums();
  4837. $headers = array( Display::return_icon('folder_document.png', get_lang('Documents'), array(), 64),
  4838. Display::return_icon('quiz.png', get_lang('Quiz'), array(), 64),
  4839. Display::return_icon('links.png', get_lang('Links'), array(), 64),
  4840. Display::return_icon('works.png', get_lang('Works'), array(), 64),
  4841. Display::return_icon('forum.png', get_lang('Forums'), array(), 64),
  4842. );
  4843. echo Display::tabs($headers, array($documents, $exercises, $links, $works, $forums), 'resource_tab');
  4844. return true;
  4845. }
  4846. /**
  4847. * Returns the extension of a document
  4848. * @param string filename
  4849. * @return string Extension (part after the last dot)
  4850. */
  4851. public function get_extension($filename) {
  4852. $explode = explode('.', $filename);
  4853. return $explode[count($explode) - 1];
  4854. }
  4855. /**
  4856. * Displays a document by id
  4857. *
  4858. * @param unknown_type $id
  4859. * @return unknown
  4860. */
  4861. public function display_document($id, $show_title = false, $iframe = true, $edit_link = false) {
  4862. global $_course; // It is temporary.
  4863. $return = '';
  4864. $tbl_doc = Database :: get_course_table(TABLE_DOCUMENT);
  4865. $sql_doc = "SELECT * FROM " . $tbl_doc . "
  4866. WHERE id = " . $id;
  4867. $res_doc = Database::query($sql_doc);
  4868. $row_doc = Database :: fetch_array($res_doc);
  4869. //if ($show_title)
  4870. //$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>';
  4871. // TODO: Add a path filter.
  4872. if ($iframe) {
  4873. $return .= '<iframe id="learnpath_preview_frame" frameborder="0" height="400" width="100%" scrolling="auto" src="' . api_get_path(WEB_COURSE_PATH) . $_course['path'] . '/document' . str_replace('%2F', '/', urlencode($row_doc['path'])) . '?' . api_get_cidreq() . '"></iframe>';
  4874. } else {
  4875. $return .= file_get_contents(api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document' . $row_doc['path']);
  4876. }
  4877. return $return;
  4878. }
  4879. /**
  4880. * Return HTML form to add/edit a quiz
  4881. * @param string Action (add/edit)
  4882. * @param integer Item ID if already exists
  4883. * @param mixed Extra information (quiz ID if integer)
  4884. * @return string HTML form
  4885. */
  4886. public function display_quiz_form($action = 'add', $id = 0, $extra_info = '') {
  4887. global $charset;
  4888. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  4889. $tbl_quiz = Database :: get_course_table(TABLE_QUIZ_TEST);
  4890. if ($id != 0 && is_array($extra_info)) {
  4891. $item_title = $extra_info['title'];
  4892. $item_description = $extra_info['description'];
  4893. } elseif (is_numeric($extra_info)) {
  4894. $sql_quiz = "SELECT title, description FROM " . $tbl_quiz . " WHERE id = " . $extra_info;
  4895. $result = Database::query($sql_quiz);
  4896. $row = Database :: fetch_array($result);
  4897. $item_title = $row['title'];
  4898. $item_description = $row['description'];
  4899. } else {
  4900. $item_title = '';
  4901. $item_description = '';
  4902. }
  4903. $item_title = Security::remove_XSS($item_title);
  4904. $item_description = Security::remove_XSS($item_description);
  4905. $return = ' <div class="row">
  4906. <div class="form_header">';
  4907. if ($id != 0 && is_array($extra_info))
  4908. $parent = $extra_info['parent_item_id'];
  4909. else
  4910. $parent = 0;
  4911. $sql = "SELECT * FROM " . $tbl_lp_item . " WHERE lp_id = " . $this->lp_id;
  4912. $result = Database::query($sql);
  4913. $arrLP = array ();
  4914. while ($row = Database :: fetch_array($result)) {
  4915. $arrLP[] = array (
  4916. 'id' => $row['id'],
  4917. 'item_type' => $row['item_type'],
  4918. 'title' => $row['title'],
  4919. 'path' => $row['path'],
  4920. 'description' => $row['description'],
  4921. 'parent_item_id' => $row['parent_item_id'],
  4922. 'previous_item_id' => $row['previous_item_id'],
  4923. 'next_item_id' => $row['next_item_id'],
  4924. 'display_order' => $row['display_order'],
  4925. 'max_score' => $row['max_score'],
  4926. 'min_score' => $row['min_score'],
  4927. 'mastery_score' => $row['mastery_score'],
  4928. 'prerequisite' => $row['prerequisite'],
  4929. 'max_time_allowed' => $row['max_time_allowed']
  4930. );
  4931. }
  4932. $this->tree_array($arrLP);
  4933. $arrLP = $this->arrMenu;
  4934. unset ($this->arrMenu);
  4935. if ($action == 'add')
  4936. $return .= get_lang('CreateTheExercise') . '&nbsp;:';
  4937. elseif ($action == 'move') $return .= get_lang('MoveTheCurrentExercise') . '&nbsp;:';
  4938. else
  4939. $return .= get_lang('EditCurrentExecice') . '&nbsp;:';
  4940. if (isset ($_GET['edit']) && $_GET['edit'] == 'true') {
  4941. $return .= Display :: return_warning_message('<p class="lp_title">' . get_lang('Warning') . ' !</p>' . get_lang('WarningEditingDocument'));
  4942. }
  4943. $return .= ' </div>
  4944. </div>';
  4945. $return .= '<div class="sectioncomment">';
  4946. $return .= '<form method="POST">';
  4947. $return .= '<table class="lp_form">';
  4948. if ($action != 'move') {
  4949. $return .= '<tr>';
  4950. $return .= '<td class="label"><label for="idTitle">' . get_lang('Title') . '</label></td>';
  4951. $return .= '<td class="input"><input id="idTitle" name="title" size="44" type="text" class="learnpath_item_form" value="' . $item_title . '" /></td>';
  4952. $return .= '</tr>';
  4953. }
  4954. $return .= '<tr>';
  4955. $return .= '<td class="label"><label for="idParent">' . get_lang('Parent') . '</label></td>';
  4956. $return .= '<td class="input">';
  4957. $return .= '<select id="idParent" style="width:100%;" name="parent" onChange="javascript: load_cbo(this.value);" class="learnpath_item_form" size="1">';
  4958. $return .= '<option class="top" value="0">' . $this->name . '</option>';
  4959. $arrHide = array (
  4960. $id
  4961. );
  4962. //$parent_item_id = $_SESSION['parent_item_id'];
  4963. for ($i = 0; $i < count($arrLP); $i++) {
  4964. if ($action != 'add') {
  4965. 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)) {
  4966. $return .= '<option ' . (($parent == $arrLP[$i]['id']) ? 'selected="selected" ' : '') . 'style="padding-left:' . ($arrLP[$i]['depth'] * 10) . 'px;" value="' . $arrLP[$i]['id'] . '">' . $arrLP[$i]['title'] . '</option>';
  4967. } else {
  4968. $arrHide[] = $arrLP[$i]['id'];
  4969. }
  4970. } else {
  4971. if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
  4972. $return .= '<option ' . (($parent == $arrLP[$i]['id']) ? 'selected="selected" ' : '') . 'style="padding-left:' . ($arrLP[$i]['depth'] * 10) . 'px;" value="' . $arrLP[$i]['id'] . '">' . $arrLP[$i]['title'] . '</option>';
  4973. }
  4974. }
  4975. if (is_array($arrLP)) {
  4976. reset($arrLP);
  4977. }
  4978. $return .= '</select>';
  4979. $return .= '</td>';
  4980. $return .= '</tr>';
  4981. $return .= '<tr>';
  4982. $return .= '<td class="label"><label for="previous">' . get_lang('Position') . '</label></td>';
  4983. $return .= '<td class="input">';
  4984. $return .= '<select class="learnpath_item_form" style="width:100%;" id="previous" name="previous" size="1">';
  4985. $return .= '<option class="top" value="0">' . get_lang('FirstPosition') . '</option>';
  4986. for ($i = 0; $i < count($arrLP); $i++) {
  4987. if ($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) {
  4988. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  4989. $selected = 'selected="selected" ';
  4990. elseif ($action == 'add') $selected = 'selected="selected" ';
  4991. else
  4992. $selected = '';
  4993. $return .= '<option ' . $selected . 'value="' . $arrLP[$i]['id'] . '">' . get_lang('After') . ' "' . $arrLP[$i]['title'] . '"</option>';
  4994. }
  4995. }
  4996. $return .= '</select>';
  4997. $return .= '</td>';
  4998. $return .= '</tr>';
  4999. if ($action != 'move') {
  5000. $id_prerequisite = 0;
  5001. if (is_array($arrLP)) {
  5002. foreach ($arrLP as $key => $value) {
  5003. if ($value['id'] == $id) {
  5004. $id_prerequisite = $value['prerequisite'];
  5005. break;
  5006. }
  5007. }
  5008. }
  5009. $arrHide = array ();
  5010. for ($i = 0; $i < count($arrLP); $i++) {
  5011. if ($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter') {
  5012. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5013. $s_selected_position = $arrLP[$i]['id'];
  5014. elseif ($action == 'add') $s_selected_position = 0;
  5015. $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
  5016. }
  5017. }
  5018. /*// Commented the prerequisites, only visible in edit (exercise).
  5019. $return .= '<tr>';
  5020. $return .= '<td class="label"><label for="idPrerequisites">'.get_lang('Prerequisites').'</label></td>';
  5021. $return .= '<td class="input"><select name="prerequisites" id="prerequisites" class="learnpath_item_form"><option value="0">'.get_lang('NoPrerequisites').'</option>';
  5022. foreach($arrHide as $key => $value){
  5023. if($key==$s_selected_position && $action == 'add'){
  5024. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  5025. }
  5026. elseif($key==$id_prerequisite && $action == 'edit'){
  5027. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  5028. }
  5029. else{
  5030. $return .= '<option value="'.$key.'">'.$value['value'].'</option>';
  5031. }
  5032. }
  5033. $return .= "</select></td>";
  5034. */
  5035. $return .= '</tr>';
  5036. /*$return .= '<tr>';
  5037. $return .= '<td class="label"><label for="maxTimeAllowed">' . get_lang('MaxTimeAllowed') . '</label></td>';
  5038. $return .= '<td class="input"><input name="maxTimeAllowed" style="width:98%;" id="maxTimeAllowed" value="' . $extra_info['max_time_allowed'] . '" /></td>';
  5039. // Remove temporarily the test description.
  5040. //$return .= '<td class="label"><label for="idDescription">'.get_lang('Description').' :</label></td>';
  5041. //$return .= '<td class="input"><textarea id="idDescription" name="description" rows="4">' . $item_description . '</textarea></td>';
  5042. $return .= '</tr>'; */
  5043. }
  5044. $return .= '<tr>';
  5045. if ($action == 'add') {
  5046. $return .= '<td>&nbsp;</td><td><button class="save" name="submit_button" type="submit">' . get_lang('AddExercise') . '</button></td>';
  5047. } else {
  5048. $return .= '<td>&nbsp;</td><td><button class="save" name="submit_button" type="submit">' . get_lang('EditCurrentExecice') . '</button></td>';
  5049. }
  5050. $return .= '</tr>';
  5051. $return .= '</table>';
  5052. if ($action == 'move') {
  5053. $return .= '<input name="title" type="hidden" value="' . $item_title . '" />';
  5054. $return .= '<input name="description" type="hidden" value="' . $item_description . '" />';
  5055. }
  5056. if (is_numeric($extra_info)) {
  5057. $return .= '<input name="path" type="hidden" value="' . $extra_info . '" />';
  5058. }
  5059. elseif (is_array($extra_info)) {
  5060. $return .= '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />';
  5061. }
  5062. $return .= '<input name="type" type="hidden" value="' . TOOL_QUIZ . '" />';
  5063. $return .= '<input name="post_time" type="hidden" value="' . time() . '" />';
  5064. $return .= '</form>';
  5065. $return .= '</div>';
  5066. return $return;
  5067. }
  5068. /**
  5069. * Addition of Hotpotatoes tests
  5070. * @param string Action
  5071. * @param integer Internal ID of the item
  5072. * @param mixed Extra information - can be an array with title and description indexes
  5073. * @return string HTML structure to display the hotpotatoes addition formular
  5074. */
  5075. public function display_hotpotatoes_form($action = 'add', $id = 0, $extra_info = '') {
  5076. global $charset;
  5077. $uploadPath = DIR_HOTPOTATOES; //defined in main_api
  5078. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  5079. if ($id != 0 && is_array($extra_info)) {
  5080. $item_title = stripslashes($extra_info['title']);
  5081. $item_description = stripslashes($extra_info['description']);
  5082. } elseif (is_numeric($extra_info)) {
  5083. $TBL_DOCUMENT = Database :: get_course_table(TABLE_DOCUMENT);
  5084. $sql_hot = "SELECT * FROM " . $TBL_DOCUMENT . "
  5085. WHERE path LIKE '" . $uploadPath . "/%/%htm%'
  5086. AND id = " . (int) $extra_info . " ORDER BY id ASC";
  5087. $res_hot = Database::query($sql_hot);
  5088. $row = Database::fetch_array($res_hot);
  5089. $item_title = $row['title'];
  5090. $item_description = $row['description'];
  5091. if (!empty ($row['comment'])) {
  5092. $item_title = $row['comment'];
  5093. }
  5094. } else {
  5095. $item_title = '';
  5096. $item_description = '';
  5097. }
  5098. if ($id != 0 && is_array($extra_info))
  5099. $parent = $extra_info['parent_item_id'];
  5100. else
  5101. $parent = 0;
  5102. $sql = "SELECT * FROM $tbl_lp_item WHERE lp_id = " . $this->lp_id;
  5103. $result = Database::query($sql);
  5104. $arrLP = array ();
  5105. while ($row = Database :: fetch_array($result)) {
  5106. $arrLP[] = array (
  5107. 'id' => $row['id'],
  5108. 'item_type' => $row['item_type'],
  5109. 'title' => $row['title'],
  5110. 'path' => $row['path'],
  5111. 'description' => $row['description'],
  5112. 'parent_item_id' => $row['parent_item_id'],
  5113. 'previous_item_id' => $row['previous_item_id'],
  5114. 'next_item_id' => $row['next_item_id'],
  5115. 'display_order' => $row['display_order'],
  5116. 'max_score' => $row['max_score'],
  5117. 'min_score' => $row['min_score'],
  5118. 'mastery_score' => $row['mastery_score'],
  5119. 'prerequisite' => $row['prerequisite'],
  5120. 'max_time_allowed' => $row['max_time_allowed']
  5121. );
  5122. }
  5123. /*
  5124. $this->tree_array($arrLP);
  5125. $arrLP = $this->arrMenu;
  5126. unset ($this->arrMenu);*/
  5127. if ($action == 'add')
  5128. $return .= '<div class="row"><div class="form_header">' . get_lang('CreateTheExercise') . '&nbsp;:</div></div>';
  5129. elseif ($action == 'move') $return .= '<p class="lp_title">' . get_lang('MoveTheCurrentExercise') . '&nbsp;:</p>';
  5130. else
  5131. //$return .= '<p class="form_header">' . get_lang('EditCurrentExecice') . '&nbsp;:</p>';
  5132. $return .= '<div class="row"><div class="form_header">' . get_lang('EditCurrentExecice') . '&nbsp;:</div></div>';
  5133. if (isset ($_GET['edit']) && $_GET['edit'] == 'true') {
  5134. $return .= Display :: return_warning_message('<p class="lp_title">' . get_lang('Warning') . ' !</p>' . get_lang('WarningEditingDocument'));
  5135. }
  5136. $return .= '<form method="POST">';
  5137. $return .= '<table cellpadding="0" cellspacing="0" class="lp_form">';
  5138. $return .= '<tr>';
  5139. $return .= '<td class="label"><label for="idParent">' . get_lang('Parent') . ' :</label></td>';
  5140. $return .= '<td class="input">';
  5141. $return .= "\t\t\t\t" . '<select id="idParent" name="parent" onChange="javascript: load_cbo(this.value);" size="1">';
  5142. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
  5143. $arrHide = array (
  5144. $id
  5145. );
  5146. if (count($arrLP) > 0) {
  5147. for ($i = 0; $i < count($arrLP); $i++) {
  5148. if ($action != 'add') {
  5149. 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)) {
  5150. $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'] . '">' . $arrLP[$i]['title'] . '</option>';
  5151. } else {
  5152. $arrHide[] = $arrLP[$i]['id'];
  5153. }
  5154. } else {
  5155. if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
  5156. $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'] . '">' . $arrLP[$i]['title'] . '</option>';
  5157. }
  5158. }
  5159. reset($arrLP);
  5160. }
  5161. $return .= "\t\t\t\t" . '</select>';
  5162. $return .= '</td>';
  5163. $return .= '</tr>';
  5164. $return .= '<tr>';
  5165. $return .= '<td class="label"><label for="previous">' . get_lang('Position') . ' :</label></td>';
  5166. $return .= '<td class="input">';
  5167. $return .= "\t\t\t\t" . '<select id="previous" name="previous" size="1">';
  5168. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . get_lang('FirstPosition') . '</option>';
  5169. for ($i = 0; $i < count($arrLP); $i++) {
  5170. if ($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) {
  5171. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5172. $selected = 'selected="selected" ';
  5173. elseif ($action == 'add') $selected = 'selected="selected" ';
  5174. else
  5175. $selected = '';
  5176. $return .= "\t\t\t\t\t" . '<option ' . $selected . 'value="' . $arrLP[$i]['id'] . '">' . get_lang('After') . ' "' . $arrLP[$i]['title'] . '"</option>';
  5177. }
  5178. }
  5179. $return .= "\t\t\t\t" . '</select>';
  5180. $return .= '</td>';
  5181. $return .= '</tr>';
  5182. if ($action != 'move') {
  5183. $return .= '<tr>';
  5184. $return .= '<td class="label"><label for="idTitle">' . get_lang('Title') . ' :</label></td>';
  5185. $return .= '<td class="input"><input id="idTitle" name="title" type="text" value="' . $item_title . '" /></td>';
  5186. $return .= '</tr>';
  5187. $id_prerequisite = 0;
  5188. if (is_array($arrLP) && count($arrLP) > 0) {
  5189. foreach ($arrLP as $key => $value) {
  5190. if ($value['id'] == $id) {
  5191. $id_prerequisite = $value['prerequisite'];
  5192. break;
  5193. }
  5194. }
  5195. $arrHide = array ();
  5196. for ($i = 0; $i < count($arrLP); $i++) {
  5197. if ($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter') {
  5198. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5199. $s_selected_position = $arrLP[$i]['id'];
  5200. elseif ($action == 'add') $s_selected_position = 0;
  5201. $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
  5202. }
  5203. }
  5204. }
  5205. //$return .= '<tr>';
  5206. //$return .= '<td class="label"><label for="idPrerequisites">'.get_lang('Prerequisites').' :</label></td>';
  5207. //$return .= '<td class="input"><select name="prerequisites" id="prerequisites"><option value="0">'.get_lang('NoPrerequisites').'</option>';
  5208. /*
  5209. foreach ($arrHide as $key => $value) {
  5210. if ($key == $s_selected_position && $action == 'add') {
  5211. $return .= '<option value="' . $key . '" selected="selected">' . $value['value'] . '</option>';
  5212. }
  5213. elseif ($key == $id_prerequisite && $action == 'edit') {
  5214. $return .= '<option value="' . $key . '" selected="selected">' . $value['value'] . '</option>';
  5215. } else {
  5216. $return .= '<option value="' . $key . '">' . $value['value'] . '</option>';
  5217. }
  5218. }
  5219. */
  5220. //$return .= "</select></td>";
  5221. //$return .= '</tr>';
  5222. //$return .= '<tr>';
  5223. //$return .= '</tr>';
  5224. }
  5225. $return .= '<tr>';
  5226. $return .= '<td>&nbsp; </td><td><button class="save" name="submit_button" action="edit" type="submit">' . get_lang('SaveHotpotatoes') . '</button></td>';
  5227. $return .= '</tr>';
  5228. $return .= '</table>';
  5229. if ($action == 'move') {
  5230. $return .= '<input name="title" type="hidden" value="' . $item_title . '" />';
  5231. $return .= '<input name="description" type="hidden" value="' . $item_description . '" />';
  5232. }
  5233. if (is_numeric($extra_info)) {
  5234. $return .= '<input name="path" type="hidden" value="' . $extra_info . '" />';
  5235. }
  5236. elseif (is_array($extra_info)) {
  5237. $return .= '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />';
  5238. }
  5239. $return .= '<input name="type" type="hidden" value="' . TOOL_HOTPOTATOES . '" />';
  5240. $return .= '<input name="post_time" type="hidden" value="' . time() . '" />';
  5241. $return .= '</form>';
  5242. return $return;
  5243. }
  5244. /**
  5245. * Return the form to display the forum edit/add option
  5246. * @param string Action (add/edit)
  5247. * @param integer ID of the lp_item if already exists
  5248. * @param mixed Forum ID or title
  5249. * @return string HTML form
  5250. */
  5251. public function display_forum_form($action = 'add', $id = 0, $extra_info = '') {
  5252. global $charset;
  5253. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  5254. $tbl_forum = Database :: get_course_table(TABLE_FORUM);
  5255. if ($id != 0 && is_array($extra_info)) {
  5256. $item_title = stripslashes($extra_info['title']);
  5257. }
  5258. elseif (is_numeric($extra_info)) {
  5259. $sql_forum = "
  5260. SELECT
  5261. forum_title as title, forum_comment as comment
  5262. FROM " . $tbl_forum . "
  5263. WHERE forum_id = " . $extra_info;
  5264. $result = Database::query($sql_forum);
  5265. $row = Database :: fetch_array($result);
  5266. $item_title = $row['title'];
  5267. $item_description = $row['comment'];
  5268. } else {
  5269. $item_title = '';
  5270. $item_description = '';
  5271. }
  5272. $return = ' <div class="row">
  5273. <div class="form_header">';
  5274. if ($id != 0 && is_array($extra_info))
  5275. $parent = $extra_info['parent_item_id'];
  5276. else
  5277. $parent = 0;
  5278. $sql = "
  5279. SELECT *
  5280. FROM " . $tbl_lp_item . "
  5281. WHERE
  5282. lp_id = " . $this->lp_id;
  5283. $result = Database::query($sql);
  5284. $arrLP = array ();
  5285. while ($row = Database :: fetch_array($result)) {
  5286. $arrLP[] = array (
  5287. 'id' => $row['id'],
  5288. 'item_type' => $row['item_type'],
  5289. 'title' => $row['title'],
  5290. 'path' => $row['path'],
  5291. 'description' => $row['description'],
  5292. 'parent_item_id' => $row['parent_item_id'],
  5293. 'previous_item_id' => $row['previous_item_id'],
  5294. 'next_item_id' => $row['next_item_id'],
  5295. 'display_order' => $row['display_order'],
  5296. 'max_score' => $row['max_score'],
  5297. 'min_score' => $row['min_score'],
  5298. 'mastery_score' => $row['mastery_score'],
  5299. 'prerequisite' => $row['prerequisite']
  5300. );
  5301. }
  5302. $this->tree_array($arrLP);
  5303. $arrLP = $this->arrMenu;
  5304. unset ($this->arrMenu);
  5305. if ($action == 'add')
  5306. $return .= get_lang('CreateTheForum') . '&nbsp;:';
  5307. elseif ($action == 'move') $return .= get_lang('MoveTheCurrentForum') . '&nbsp;:';
  5308. else
  5309. $return .= get_lang('EditCurrentForum') . '&nbsp;:';
  5310. $return .= ' </div>
  5311. </div>';
  5312. $return .= '<div class="sectioncomment">';
  5313. $return .= '<form method="POST">';
  5314. $return .= '<table class="lp_form">';
  5315. if ($action != 'move') {
  5316. $return .= '<tr>';
  5317. $return .= '<td class="label"><label for="idTitle">' . get_lang('Title') . '</label></td>';
  5318. $return .= '<td class="input"><input id="idTitle" size="44" name="title" type="text" value="' . $item_title . '" class="learnpath_item_form" /></td>';
  5319. $return .= '</tr>';
  5320. }
  5321. $return .= '<tr>';
  5322. $return .= '<td class="label"><label for="idParent">' . get_lang('Parent') . '</label></td>';
  5323. $return .= '<td class="input">';
  5324. $return .= "\t\t\t\t" . '<select id="idParent" style="width:100%;" name="parent" onChange="javascript: load_cbo(this.value);" class="learnpath_item_form" size="1">';
  5325. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
  5326. $arrHide = array (
  5327. $id
  5328. );
  5329. //$parent_item_id = $_SESSION['parent_item_id'];
  5330. for ($i = 0; $i < count($arrLP); $i++) {
  5331. if ($action != 'add') {
  5332. 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)) {
  5333. $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'] . '">' . $arrLP[$i]['title'] . '</option>';
  5334. } else {
  5335. $arrHide[] = $arrLP[$i]['id'];
  5336. }
  5337. } else {
  5338. if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
  5339. $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'] . '">' . $arrLP[$i]['title'] . '</option>';
  5340. }
  5341. }
  5342. if (is_array($arrLP)) {
  5343. reset($arrLP);
  5344. }
  5345. $return .= "\t\t\t\t" . '</select>';
  5346. $return .= '</td>';
  5347. $return .= '</tr>';
  5348. $return .= '<tr>';
  5349. $return .= '<td class="label"><label for="previous">' . get_lang('Position') . '</label></td>';
  5350. $return .= '<td class="input">';
  5351. $return .= "\t\t\t\t" . '<select id="previous" name="previous" style="width:100%;" size="1" class="learnpath_item_form">';
  5352. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . get_lang('FirstPosition') . '</option>';
  5353. for ($i = 0; $i < count($arrLP); $i++) {
  5354. if ($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) {
  5355. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5356. $selected = 'selected="selected" ';
  5357. elseif ($action == 'add') $selected = 'selected="selected" ';
  5358. else
  5359. $selected = '';
  5360. $return .= "\t\t\t\t\t" . '<option ' . $selected . 'value="' . $arrLP[$i]['id'] . '">' . get_lang('After') . ' "' . $arrLP[$i]['title'] . '"</option>';
  5361. }
  5362. }
  5363. $return .= "\t\t\t\t" . '</select>';
  5364. $return .= '</td>';
  5365. $return .= '</tr>';
  5366. if ($action != 'move') {
  5367. $return .= '<tr>';
  5368. $return .= '</tr>';
  5369. $id_prerequisite = 0;
  5370. if (is_array($arrLP)) {
  5371. foreach ($arrLP as $key => $value) {
  5372. if ($value['id'] == $id) {
  5373. $id_prerequisite = $value['prerequisite'];
  5374. break;
  5375. }
  5376. }
  5377. }
  5378. $arrHide = array ();
  5379. for ($i = 0; $i < count($arrLP); $i++) {
  5380. if ($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter') {
  5381. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5382. $s_selected_position = $arrLP[$i]['id'];
  5383. elseif ($action == 'add') $s_selected_position = 0;
  5384. $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
  5385. }
  5386. }
  5387. $return .= '</tr>';
  5388. }
  5389. $return .= '<tr>';
  5390. if ($action == 'add') {
  5391. $return .= '<td>&nbsp;</td><td><button class="save" name="submit_button" type="submit"> ' . get_lang('AddForumToCourse') . ' </button></td>';
  5392. } else {
  5393. $return .= '<td>&nbsp;</td><td><button class="save" name="submit_button" type="submit"> ' . get_lang('EditCurrentForum') . ' </button></td>';
  5394. }
  5395. $return .= '</tr>';
  5396. $return .= '</table>';
  5397. if ($action == 'move') {
  5398. $return .= '<input name="title" type="hidden" value="' . $item_title . '" />';
  5399. $return .= '<input name="description" type="hidden" value="' . $item_description . '" />';
  5400. }
  5401. if (is_numeric($extra_info)) {
  5402. $return .= '<input name="path" type="hidden" value="' . $extra_info . '" />';
  5403. }
  5404. elseif (is_array($extra_info)) {
  5405. $return .= '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />';
  5406. }
  5407. $return .= '<input name="type" type="hidden" value="' . TOOL_FORUM . '" />';
  5408. $return .= '<input name="post_time" type="hidden" value="' . time() . '" />';
  5409. $return .= '</form>';
  5410. $return .= '</div>';
  5411. return $return;
  5412. }
  5413. /**
  5414. * Return HTML form to add/edit forum threads
  5415. * @param string Action (add/edit)
  5416. * @param integer Item ID if already exists in learning path
  5417. * @param mixed Extra information (thread ID if integer)
  5418. * @return string HTML form
  5419. */
  5420. public function display_thread_form($action = 'add', $id = 0, $extra_info = '') {
  5421. global $charset;
  5422. echo '
  5423. <style>
  5424. div.row div.label {
  5425. width:110px;
  5426. }
  5427. div.row div.formw {
  5428. width: 82%;
  5429. }
  5430. </style>';
  5431. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  5432. $tbl_forum = Database :: get_course_table(TABLE_FORUM_THREAD);
  5433. if ($id != 0 && is_array($extra_info)) {
  5434. $item_title = stripslashes($extra_info['title']);
  5435. }
  5436. elseif (is_numeric($extra_info)) {
  5437. $sql_forum = "
  5438. SELECT
  5439. thread_title as title
  5440. FROM " . $tbl_forum . "
  5441. WHERE thread_id = " . $extra_info;
  5442. $result = Database::query($sql_forum);
  5443. $row = Database :: fetch_array($result);
  5444. $item_title = $row['title'];
  5445. $item_description = '';
  5446. } else {
  5447. $item_title = '';
  5448. $item_description = '';
  5449. }
  5450. $return = '<div style="margin:3px 12px;">';
  5451. if ($id != 0 && is_array($extra_info))
  5452. $parent = $extra_info['parent_item_id'];
  5453. else
  5454. $parent = 0;
  5455. $sql = "
  5456. SELECT *
  5457. FROM " . $tbl_lp_item . "
  5458. WHERE
  5459. lp_id = " . $this->lp_id;
  5460. $result = Database::query($sql);
  5461. $arrLP = array ();
  5462. while ($row = Database :: fetch_array($result)) {
  5463. $arrLP[] = array (
  5464. 'id' => $row['id'],
  5465. 'item_type' => $row['item_type'],
  5466. 'title' => $row['title'],
  5467. 'path' => $row['path'],
  5468. 'description' => $row['description'],
  5469. 'parent_item_id' => $row['parent_item_id'],
  5470. 'previous_item_id' => $row['previous_item_id'],
  5471. 'next_item_id' => $row['next_item_id'],
  5472. 'display_order' => $row['display_order'],
  5473. 'max_score' => $row['max_score'],
  5474. 'min_score' => $row['min_score'],
  5475. 'mastery_score' => $row['mastery_score'],
  5476. 'prerequisite' => $row['prerequisite']
  5477. );
  5478. }
  5479. $this->tree_array($arrLP);
  5480. $arrLP = $this->arrMenu;
  5481. unset ($this->arrMenu);
  5482. if ($action == 'add')
  5483. $return .= '<p class="lp_title">' . get_lang('CreateTheForum') . '&nbsp;:</p>';
  5484. elseif ($action == 'move') $return .= '<p class="lp_title">' . get_lang('MoveTheCurrentForum') . '&nbsp;:</p>';
  5485. else
  5486. $return .= '<p class="lp_title">' . get_lang('EditCurrentForum') . '&nbsp;:</p>';
  5487. $return .= '<form method="POST">';
  5488. $return .= '<table cellpadding="0" cellspacing="0" class="lp_form">';
  5489. $return .= '<tr>';
  5490. $return .= '<td class="label"><label for="idParent">' . get_lang('Parent') . '&nbsp;:</label></td>';
  5491. $return .= '<td class="input">';
  5492. $return .= "\t\t\t\t" . '<select id="idParent" name="parent" onChange="javascript: load_cbo(this.value);" size="1">';
  5493. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
  5494. $arrHide = array (
  5495. $id
  5496. );
  5497. for ($i = 0; $i < count($arrLP); $i++) {
  5498. if ($action != 'add') {
  5499. 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)) {
  5500. $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'] . '">' . $arrLP[$i]['title'] . '</option>';
  5501. } else {
  5502. $arrHide[] = $arrLP[$i]['id'];
  5503. }
  5504. } else {
  5505. if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
  5506. $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'] . '">' . $arrLP[$i]['title'] . '</option>';
  5507. }
  5508. }
  5509. if ($arrLP != null) {
  5510. reset($arrLP);
  5511. }
  5512. $return .= "\t\t\t\t" . '</select>';
  5513. $return .= '</td>';
  5514. $return .= '</tr>';
  5515. $return .= '<tr>';
  5516. $return .= '<td class="label"><label for="previous">' . get_lang('Position') . '&nbsp;:</label></td>';
  5517. $return .= '<td class="input">';
  5518. $return .= "\t\t\t\t" . '<select id="previous" name="previous" size="1">';
  5519. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . get_lang('FirstPosition') . '</option>';
  5520. for ($i = 0; $i < count($arrLP); $i++) {
  5521. if ($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) {
  5522. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5523. $selected = 'selected="selected" ';
  5524. elseif ($action == 'add') $selected = 'selected="selected" ';
  5525. else
  5526. $selected = '';
  5527. $return .= "\t\t\t\t\t" . '<option ' . $selected . 'value="' . $arrLP[$i]['id'] . '">' . get_lang('After') . ' "' . $arrLP[$i]['title'] . '"</option>';
  5528. }
  5529. }
  5530. $return .= "\t\t\t\t" . '</select>';
  5531. $return .= '</td>';
  5532. $return .= '</tr>';
  5533. if ($action != 'move') {
  5534. $return .= '<tr>';
  5535. $return .= '<td class="label"><label for="idTitle">' . get_lang('Title') . '&nbsp;:</label></td>';
  5536. $return .= '<td class="input"><input id="idTitle" name="title" type="text" value="' . $item_title . '" /></td>';
  5537. $return .= '</tr>';
  5538. $return .= '<tr>';
  5539. $return .= '</tr>';
  5540. $id_prerequisite = 0;
  5541. if ($arrLP != null) {
  5542. foreach ($arrLP as $key => $value) {
  5543. if ($value['id'] == $id) {
  5544. $id_prerequisite = $value['prerequisite'];
  5545. break;
  5546. }
  5547. }
  5548. }
  5549. $arrHide = array();
  5550. for ($i = 0; $i < count($arrLP); $i++) {
  5551. if ($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter') {
  5552. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5553. $s_selected_position = $arrLP[$i]['id'];
  5554. elseif ($action == 'add') $s_selected_position = 0;
  5555. $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
  5556. }
  5557. }
  5558. $return .= '<tr>';
  5559. $return .= '<td class="label"><label for="idPrerequisites">' . get_lang('Prerequisites') . '&nbsp;:</label></td>';
  5560. $return .= '<td class="input"><select name="prerequisites" id="prerequisites"><option value="0">' . get_lang('NoPrerequisites') . '</option>';
  5561. foreach ($arrHide as $key => $value) {
  5562. if ($key == $s_selected_position && $action == 'add') {
  5563. $return .= '<option value="' . $key . '" selected="selected">' . $value['value'] . '</option>';
  5564. }
  5565. elseif ($key == $id_prerequisite && $action == 'edit') {
  5566. $return .= '<option value="' . $key . '" selected="selected">' . $value['value'] . '</option>';
  5567. } else {
  5568. $return .= '<option value="' . $key . '">' . $value['value'] . '</option>';
  5569. }
  5570. }
  5571. $return .= "</select></td>";
  5572. $return .= '</tr>';
  5573. }
  5574. $return .= '<tr>';
  5575. $return .= '<td colspan="2">
  5576. <button class="save" name="submit_button" type="submit" value="'.get_lang('Ok').'" />'.get_lang('Ok').'</button></td>';
  5577. $return .= '</tr>';
  5578. $return .= '</table>';
  5579. if ($action == 'move') {
  5580. $return .= '<input name="title" type="hidden" value="' . $item_title . '" />';
  5581. $return .= '<input name="description" type="hidden" value="' . $item_description . '" />';
  5582. }
  5583. if (is_numeric($extra_info)) {
  5584. $return .= '<input name="path" type="hidden" value="' . $extra_info . '" />';
  5585. }
  5586. elseif (is_array($extra_info)) {
  5587. $return .= '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />';
  5588. }
  5589. $return .= '<input name="type" type="hidden" value="' . TOOL_THREAD . '" />';
  5590. $return .= '<input name="post_time" type="hidden" value="' . time() . '" />';
  5591. $return .= '</form>';
  5592. $return .= '</div>';
  5593. return $return;
  5594. }
  5595. /**
  5596. * Return the HTML form to display an item (generally a section/module item)
  5597. * @param string Item type (module/dokeos_module)
  5598. * @param string Title (optional, only when creating)
  5599. * @param string Action ('add'/'edit')
  5600. * @param integer lp_item ID
  5601. * @param mixed Extra info
  5602. * @return string HTML form
  5603. */
  5604. public function display_item_form($item_type, $title = '', $action = 'add', $id = 0, $extra_info = 'new') {
  5605. global $_course;
  5606. global $charset;
  5607. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  5608. if ($id != 0 && is_array($extra_info)) {
  5609. $item_title = $extra_info['title'];
  5610. $item_description = $extra_info['description'];
  5611. $item_path = api_get_path(WEB_COURSE_PATH) . $_course['path'] . '/scorm/' . $this->path . '/' . stripslashes($extra_info['path']);
  5612. $item_path_fck = '/scorm/' . $this->path . '/' . stripslashes($extra_info['path']);
  5613. } else {
  5614. $item_title = '';
  5615. $item_description = '';
  5616. $item_path_fck = '';
  5617. }
  5618. $return = '<div class="row">
  5619. <div class="form_header">';
  5620. if ($id != 0 && is_array($extra_info))
  5621. $parent = $extra_info['parent_item_id'];
  5622. else
  5623. $parent = 0;
  5624. $id = intval($id);
  5625. $sql = "SELECT * FROM " . $tbl_lp_item . "
  5626. WHERE lp_id = " . $this->lp_id . " AND id != $id";
  5627. if ($item_type == 'module')
  5628. $sql .= " AND parent_item_id = 0";
  5629. $result = Database::query($sql);
  5630. $arrLP = array ();
  5631. while ($row = Database :: fetch_array($result)) {
  5632. $arrLP[] = array (
  5633. 'id' => $row['id'],
  5634. 'item_type' => $row['item_type'],
  5635. 'title' => $row['title'],
  5636. 'path' => $row['path'],
  5637. 'description' => $row['description'],
  5638. 'parent_item_id' => $row['parent_item_id'],
  5639. 'previous_item_id' => $row['previous_item_id'],
  5640. 'next_item_id' => $row['next_item_id'],
  5641. 'max_score' => $row['max_score'],
  5642. 'min_score' => $row['min_score'],
  5643. 'mastery_score' => $row['mastery_score'],
  5644. 'prerequisite' => $row['prerequisite'],
  5645. 'display_order' => $row['display_order']
  5646. );
  5647. }
  5648. $this->tree_array($arrLP);
  5649. $arrLP = $this->arrMenu;
  5650. unset ($this->arrMenu);
  5651. $return .= $title;
  5652. $return .= '</div>
  5653. </div>';
  5654. require_once api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php';
  5655. $form = new FormValidator('form', 'POST', api_get_self() . '?' . $_SERVER['QUERY_STRING']);
  5656. $defaults['title'] = api_html_entity_decode($item_title, ENT_QUOTES, $charset);
  5657. $defaults['description'] = $item_description;
  5658. $form->addElement('html', $return);
  5659. //$arrHide = array($id);
  5660. $arrHide[0]['value'] = Security :: remove_XSS($this->name);
  5661. $arrHide[0]['padding'] = 3;
  5662. $charset = api_get_system_encoding();
  5663. if ($item_type != 'module' && $item_type != 'dokeos_module') {
  5664. for ($i = 0; $i < count($arrLP); $i++) {
  5665. if ($action != 'add') {
  5666. 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)) {
  5667. $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
  5668. $arrHide[$arrLP[$i]['id']]['padding'] = 3 + $arrLP[$i]['depth'] * 10;
  5669. if ($parent == $arrLP[$i]['id']) {
  5670. $s_selected_parent = $arrHide[$arrLP[$i]['id']];
  5671. }
  5672. }
  5673. } else {
  5674. if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir') {
  5675. $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
  5676. $arrHide[$arrLP[$i]['id']]['padding'] = 3 + $arrLP[$i]['depth'] * 10;
  5677. if ($parent == $arrLP[$i]['id']) {
  5678. $s_selected_parent = $arrHide[$arrLP[$i]['id']];
  5679. }
  5680. }
  5681. }
  5682. }
  5683. if ($action != 'move') {
  5684. $form->addElement('text', 'title', get_lang('Title'), 'id="idTitle" class="learnpath_chapter_form" size="40%"');
  5685. $form->applyFilter('title', 'html_filter');
  5686. $form->addRule('title', '<div class="required">' . get_lang('ThisFieldIsRequired'), 'required');
  5687. //$form->addElement('textarea', 'description', get_lang('Description').' :', 'id="idDescription"');
  5688. } else {
  5689. $form->addElement('hidden', 'title');
  5690. }
  5691. $parent_select = & $form->addElement('select', 'parent', get_lang('Parent'), '', 'class="learnpath_chapter_form" style="width:37%;" id="idParent" onchange="javascript: load_cbo(this.value);"');
  5692. foreach ($arrHide as $key => $value) {
  5693. $parent_select->addOption($value['value'], $key, 'style="padding-left:' . $value['padding'] . 'px;"');
  5694. }
  5695. if (!empty($s_selected_parent)) {
  5696. $parent_select->setSelected($s_selected_parent);
  5697. }
  5698. }
  5699. if (is_array($arrLP)) {
  5700. reset($arrLP);
  5701. }
  5702. $arrHide = array ();
  5703. // POSITION
  5704. for ($i = 0; $i < count($arrLP); $i++) {
  5705. if ($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) {
  5706. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5707. $s_selected_position = $arrLP[$i]['id'];
  5708. elseif ($action == 'add') $s_selected_position = $arrLP[$i]['id'];
  5709. $arrHide[$arrLP[$i]['id']]['value'] = get_lang('After') . ' "' . $arrLP[$i]['title'] . '"';
  5710. }
  5711. }
  5712. $position = & $form->addElement('select', 'previous', get_lang('Position'), '', 'id="previous" class="learnpath_chapter_form" style="width:37%;"');
  5713. $padding = isset($value['padding']) ? $value['padding'] : 0;
  5714. $position->addOption(get_lang('FirstPosition'), 0, 'style="padding-left:' . $padding . 'px;"');
  5715. foreach ($arrHide as $key => $value) {
  5716. $position->addOption($value['value'] . '"', $key, 'style="padding-left:' . $padding . 'px;"');
  5717. }
  5718. if (!empty ($s_selected_position)) {
  5719. $position->setSelected($s_selected_position);
  5720. }
  5721. if (is_array($arrLP)) {
  5722. reset($arrLP);
  5723. }
  5724. $form->addElement('style_submit_button', 'submit_button', get_lang('SaveSection'), 'class="save"');
  5725. if ($item_type == 'module' || $item_type == 'dokeos_module') {
  5726. $form->addElement('hidden', 'parent', '0');
  5727. }
  5728. $extension = null;
  5729. if (!empty($item_path)) {
  5730. $extension = pathinfo($item_path, PATHINFO_EXTENSION);
  5731. }
  5732. if (($item_type == 'asset' || $item_type == 'sco') && ($extension == 'html' || $extension == 'htm')) {
  5733. if ($item_type == 'sco') {
  5734. $form->addElement('html', '<script type="text/javascript">alert("' . get_lang('WarningWhenEditingScorm') . '")</script>');
  5735. }
  5736. $renderer = $form->defaultRenderer();
  5737. $renderer->setElementTemplate('<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{label}<br />{element}', 'content_lp');
  5738. $relative_prefix = '';
  5739. $editor_config = array( 'ToolbarSet' => 'LearningPathDocuments',
  5740. 'Width' => '100%',
  5741. 'Height' => '500',
  5742. 'FullPage' => true,
  5743. 'CreateDocumentDir' => $relative_prefix,
  5744. 'CreateDocumentWebDir' => api_get_path(WEB_COURSE_PATH) . api_get_course_path().'/scorm/',
  5745. 'BaseHref' => api_get_path(WEB_COURSE_PATH) . api_get_course_path().$item_path_fck
  5746. );
  5747. $form->addElement('html_editor', 'content_lp', '', null, $editor_config);
  5748. $defaults['content_lp'] = file_get_contents($item_path);
  5749. }
  5750. $form->addElement('hidden', 'type', 'dokeos_' . $item_type);
  5751. $form->addElement('hidden', 'post_time', time());
  5752. $form->setDefaults($defaults);
  5753. return $form->return_form();
  5754. }
  5755. /**
  5756. * Returns the form to update or create a document
  5757. * @param string Action (add/edit)
  5758. * @param integer ID of the lp_item (if already exists)
  5759. * @param mixed Integer if document ID, string if info ('new')
  5760. * @return string HTML form
  5761. */
  5762. public function display_document_form($action = 'add', $id = 0, $extra_info = 'new') {
  5763. global $charset;
  5764. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  5765. $tbl_doc = Database :: get_course_table(TABLE_DOCUMENT);
  5766. $path_parts = pathinfo($extra_info['dir']);
  5767. $no_display_edit_textarea = false;
  5768. //If action==edit document
  5769. //We don't display the document form if it's not an editable document (html or txt file)
  5770. if ($action == "edit") {
  5771. if (is_array($extra_info)) {
  5772. if ($path_parts['extension'] != "txt" && $path_parts['extension'] != "html") {
  5773. $no_display_edit_textarea = true;
  5774. }
  5775. }
  5776. }
  5777. $no_display_add = false;
  5778. // If action==add an existing document
  5779. // We don't display the document form if it's not an editable document (html or txt file).
  5780. if ($action == "add") {
  5781. if (is_numeric($extra_info)) {
  5782. $sql_doc = "SELECT path FROM " . $tbl_doc . "WHERE id = " . Database :: escape_string($extra_info);
  5783. $result = Database::query($sql_doc);
  5784. $path_file = Database :: result($result, 0, 0);
  5785. $path_parts = pathinfo($path_file);
  5786. if ($path_parts['extension'] != "txt" && $path_parts['extension'] != "html") {
  5787. $no_display_add = true;
  5788. }
  5789. }
  5790. }
  5791. if ($id != 0 && is_array($extra_info)) {
  5792. $item_title = stripslashes($extra_info['title']);
  5793. $item_description = stripslashes($extra_info['description']);
  5794. $item_terms = stripslashes($extra_info['terms']);
  5795. if (empty ($item_title)) {
  5796. $path_parts = pathinfo($extra_info['path']);
  5797. $item_title = stripslashes($path_parts['filename']);
  5798. }
  5799. } elseif (is_numeric($extra_info)) {
  5800. $sql_doc = "SELECT path, title FROM " . $tbl_doc . "
  5801. WHERE id = " . Database :: escape_string($extra_info);
  5802. $result = Database::query($sql_doc);
  5803. $row = Database::fetch_array($result);
  5804. $explode = explode('.', $row['title']);
  5805. if (count($explode) > 1) {
  5806. for ($i = 0; $i < count($explode) - 1; $i++)
  5807. $item_title .= $explode[$i];
  5808. } else {
  5809. $item_title = $row['title'];
  5810. }
  5811. $item_title = str_replace('_', ' ', $item_title);
  5812. if (empty ($item_title)) {
  5813. $path_parts = pathinfo($row['path']);
  5814. $item_title = stripslashes($path_parts['filename']);
  5815. }
  5816. } else {
  5817. $item_title = '';
  5818. $item_description = '';
  5819. }
  5820. $return = '<div class="row">
  5821. <div class="form_header">';
  5822. if ($id != 0 && is_array($extra_info))
  5823. $parent = $extra_info['parent_item_id'];
  5824. else
  5825. $parent = 0;
  5826. $sql = "SELECT * FROM " . $tbl_lp_item . "
  5827. WHERE lp_id = " . $this->lp_id;
  5828. $result = Database::query($sql);
  5829. $arrLP = array ();
  5830. while ($row = Database :: fetch_array($result)) {
  5831. $arrLP[] = array (
  5832. 'id' => $row['id'],
  5833. 'item_type' => $row['item_type'],
  5834. 'title' => $row['title'],
  5835. 'path' => $row['path'],
  5836. 'description' => $row['description'],
  5837. 'parent_item_id' => $row['parent_item_id'],
  5838. 'previous_item_id' => $row['previous_item_id'],
  5839. 'next_item_id' => $row['next_item_id'],
  5840. 'display_order' => $row['display_order'],
  5841. 'max_score' => $row['max_score'],
  5842. 'min_score' => $row['min_score'],
  5843. 'mastery_score' => $row['mastery_score'],
  5844. 'prerequisite' => $row['prerequisite']
  5845. );
  5846. }
  5847. $this->tree_array($arrLP);
  5848. $arrLP = $this->arrMenu;
  5849. unset ($this->arrMenu);
  5850. if ($action == 'add') {
  5851. $return .= get_lang('CreateTheDocument');
  5852. } elseif ($action == 'move') {
  5853. $return .= get_lang('MoveTheCurrentDocument');
  5854. } else {
  5855. $return .= get_lang('EditTheCurrentDocument');
  5856. }
  5857. $return .= '</div>
  5858. </div>';
  5859. if (isset ($_GET['edit']) && $_GET['edit'] == 'true') {
  5860. $return .= Display :: return_warning_message('<strong>' . get_lang('Warning') . ' !</strong><br />' . get_lang('WarningEditingDocument'), false);
  5861. }
  5862. require_once api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php';
  5863. $form = new FormValidator('form', 'POST', api_get_self() . '?' . $_SERVER['QUERY_STRING'], '', 'enctype="multipart/form-data"');
  5864. $defaults['title'] = Security :: remove_XSS($item_title);
  5865. if (empty($item_title)) {
  5866. $defaults['title'] = Security::remove_XSS($item_title);
  5867. }
  5868. $defaults['description'] = $item_description;
  5869. $form->addElement('html', $return);
  5870. if ($action != 'move') {
  5871. $form->addElement('text', 'title', get_lang('Title'), 'id="idTitle" class="learnpath_item_form" size=44%');
  5872. $form->applyFilter('title', 'html_filter');
  5873. }
  5874. //$arrHide = array($id);
  5875. $arrHide[0]['value'] = $this->name;
  5876. $arrHide[0]['padding'] = 3;
  5877. for ($i = 0; $i < count($arrLP); $i++) {
  5878. if ($action != 'add') {
  5879. 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)) {
  5880. $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
  5881. $arrHide[$arrLP[$i]['id']]['padding'] = 3 + $arrLP[$i]['depth'] * 10;
  5882. if ($parent == $arrLP[$i]['id']) {
  5883. $s_selected_parent = $arrHide[$arrLP[$i]['id']];
  5884. }
  5885. }
  5886. } else {
  5887. if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir') {
  5888. $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
  5889. $arrHide[$arrLP[$i]['id']]['padding'] = 3 + $arrLP[$i]['depth'] * 10;
  5890. if ($parent == $arrLP[$i]['id']) {
  5891. $s_selected_parent = $arrHide[$arrLP[$i]['id']];
  5892. }
  5893. }
  5894. }
  5895. }
  5896. $parent_select = & $form->addElement('select', 'parent', get_lang('Parent'), '', 'class="learnpath_item_form" id="idParent" style="width:40%;" onchange="javascript: load_cbo(this.value);"');
  5897. $my_count=0;
  5898. foreach ($arrHide as $key => $value) {
  5899. if ($my_count!=0) {
  5900. // The LP name is also the first section and is not in the same charset like the other sections.
  5901. $value['value'] = Security :: remove_XSS($value['value']);
  5902. $parent_select->addOption($value['value'], $key, 'style="padding-left:' . $value['padding'] . 'px;"');
  5903. } else {
  5904. $value['value'] = Security :: remove_XSS($value['value']);
  5905. $parent_select->addOption($value['value'], $key, 'style="padding-left:' . $value['padding'] . 'px;"');
  5906. }
  5907. $my_count++;
  5908. }
  5909. if (!empty($id)) {
  5910. $parent_select->setSelected($parent);
  5911. } else {
  5912. $parent_item_id = $_SESSION['parent_item_id'];
  5913. $parent_select->setSelected($parent_item_id);
  5914. }
  5915. if (is_array($arrLP)) {
  5916. reset($arrLP);
  5917. }
  5918. $arrHide = array ();
  5919. //POSITION
  5920. for ($i = 0; $i < count($arrLP); $i++) {
  5921. if ($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) {
  5922. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5923. $s_selected_position = $arrLP[$i]['id'];
  5924. elseif ($action == 'add') $s_selected_position = $arrLP[$i]['id'];
  5925. $arrHide[$arrLP[$i]['id']]['value'] = get_lang('After') . ' "' . $arrLP[$i]['title'] . '"';
  5926. }
  5927. }
  5928. $position = & $form->addElement('select', 'previous', get_lang('Position'), '', 'id="previous" class="learnpath_item_form" style="width:40%;"');
  5929. $position->addOption(get_lang('FirstPosition'), 0);
  5930. foreach ($arrHide as $key => $value) {
  5931. $padding = isset($value['padding']) ? $value['padding']: 0;
  5932. $position->addOption($value['value'], $key, 'style="padding-left:' . $padding . 'px;"');
  5933. }
  5934. $position->setSelected($s_selected_position);
  5935. if (is_array($arrLP)) {
  5936. reset($arrLP);
  5937. }
  5938. if ($action != 'move') {
  5939. $id_prerequisite = 0;
  5940. if (is_array($arrLP)) {
  5941. foreach ($arrLP as $key => $value) {
  5942. if ($value['id'] == $id) {
  5943. $id_prerequisite = $value['prerequisite'];
  5944. break;
  5945. }
  5946. }
  5947. }
  5948. $arrHide = array ();
  5949. for ($i = 0; $i < count($arrLP); $i++) {
  5950. if ($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter') {
  5951. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5952. $s_selected_position = $arrLP[$i]['id'];
  5953. elseif ($action == 'add') $s_selected_position = $arrLP[$i]['id'];
  5954. $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
  5955. }
  5956. }
  5957. if (!$no_display_add) {
  5958. if (($extra_info == 'new' || $extra_info['item_type'] == TOOL_DOCUMENT || $_GET['edit'] == 'true')) {
  5959. if (isset ($_POST['content']))
  5960. $content = stripslashes($_POST['content']);
  5961. elseif (is_array($extra_info)) {
  5962. //If it's an html document or a text file
  5963. if (!$no_display_edit_textarea) {
  5964. $content = $this->display_document($extra_info['path'], false, false);
  5965. }
  5966. } elseif (is_numeric($extra_info))
  5967. $content = $this->display_document($extra_info, false, false);
  5968. else
  5969. $content = '';
  5970. if (!$no_display_edit_textarea) {
  5971. // We need to calculate here some specific settings for the online editor.
  5972. // The calculated settings work for documents in the Documents tool
  5973. // (on the root or in subfolders).
  5974. // For documents in native scorm packages it is unclear whether the
  5975. // online editor should be activated or not.
  5976. // A new document, it is in the root of the repository.
  5977. $relative_path = '';
  5978. $relative_prefix = '';
  5979. if (is_array($extra_info) && $extra_info != 'new') {
  5980. // The document already exists. Whe have to determine its relative path towards the repository root.
  5981. $relative_path = explode('/', $extra_info['dir']);
  5982. $cnt = count($relative_path) - 2;
  5983. if ($cnt < 0) {
  5984. $cnt = 0;
  5985. }
  5986. $relative_prefix = str_repeat('../', $cnt);
  5987. $relative_path = array_slice($relative_path, 1, $cnt);
  5988. $relative_path = implode('/', $relative_path);
  5989. if (strlen($relative_path) > 0) {
  5990. $relative_path = $relative_path . '/';
  5991. }
  5992. } else {
  5993. global $_course;
  5994. $result = $this->generate_lp_folder($_course, '');
  5995. $relative_path = api_substr($result['dir'], 1, strlen($result['dir']));
  5996. $relative_prefix = '../../';
  5997. }
  5998. $editor_config = array( 'ToolbarSet' => 'LearningPathDocuments',
  5999. 'Width' => '100%',
  6000. 'Height' => '500',
  6001. 'FullPage' => true,
  6002. 'CreateDocumentDir' => $relative_prefix,
  6003. 'CreateDocumentWebDir' => api_get_path(WEB_COURSE_PATH) . api_get_course_path().'/document/',
  6004. 'BaseHref' => api_get_path(WEB_COURSE_PATH) . api_get_course_path().'/document/'.$relative_path
  6005. );
  6006. if ($_GET['action'] == 'add_item') {
  6007. $class = 'add';
  6008. $text = get_lang('LPCreateDocument');
  6009. } else
  6010. if ($_GET['action'] == 'edit_item') {
  6011. $class = 'save';
  6012. $text = get_lang('SaveDocument');
  6013. }
  6014. $form->addElement('style_submit_button', 'submit_button', $text, 'class="' . $class . '"');
  6015. $renderer = $form->defaultRenderer();
  6016. $renderer->setElementTemplate('<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{label}<br />{element}', 'content_lp');
  6017. $form->addElement('html', '<div style="margin:3px 12px">');
  6018. $form->addElement('html_editor', 'content_lp', '', null, $editor_config);
  6019. $form->addElement('html', '</div>');
  6020. $defaults['content_lp'] = $content;
  6021. }
  6022. } elseif (is_numeric($extra_info)) {
  6023. $form->addElement('style_submit_button', 'submit_button', get_lang('SaveDocument'), 'class="save"');
  6024. $return = $this->display_document($extra_info, true, true, true);
  6025. $form->addElement('html', $return);
  6026. }
  6027. }
  6028. }
  6029. if ($action == 'move') {
  6030. $form->addElement('hidden', 'title', $item_title);
  6031. $form->addElement('hidden', 'description', $item_description);
  6032. }
  6033. if (is_numeric($extra_info)) {
  6034. $form->addElement('style_submit_button', 'submit_button', get_lang('SaveDocument'), 'value="submit_button", class="save"');
  6035. $form->addElement('hidden', 'path', $extra_info);
  6036. }
  6037. elseif (is_array($extra_info)) {
  6038. $form->addElement('style_submit_button', 'submit_button', get_lang('SaveDocument'), 'class="save"');
  6039. $form->addElement('hidden', 'path', $extra_info['path']);
  6040. }
  6041. $form->addElement('hidden', 'type', TOOL_DOCUMENT);
  6042. $form->addElement('hidden', 'post_time', time());
  6043. $form->setDefaults($defaults);
  6044. return $form->return_form();
  6045. }
  6046. /**
  6047. * Return HTML form to add/edit a link item
  6048. * @param string Action (add/edit)
  6049. * @param integer Item ID if exists
  6050. * @param mixed Extra info
  6051. * @return string HTML form
  6052. */
  6053. public function display_link_form($action = 'add', $id = 0, $extra_info = '') {
  6054. global $charset;
  6055. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  6056. $tbl_link = Database :: get_course_table(TABLE_LINK);
  6057. if ($id != 0 && is_array($extra_info)) {
  6058. $item_title = stripslashes($extra_info['title']);
  6059. $item_description = stripslashes($extra_info['description']);
  6060. $item_url = stripslashes($extra_info['url']);
  6061. } elseif (is_numeric($extra_info)) {
  6062. $sql_link = "SELECT title, description, url FROM " . $tbl_link . " WHERE id = " . $extra_info;
  6063. $result = Database::query($sql_link);
  6064. $row = Database :: fetch_array($result);
  6065. $item_title = $row['title'];
  6066. $item_description = $row['description'];
  6067. $item_url = $row['url'];
  6068. } else {
  6069. $item_title = '';
  6070. $item_description = '';
  6071. $item_url = '';
  6072. }
  6073. $return = ' <div class="row">
  6074. <div class="form_header">';
  6075. if ($id != 0 && is_array($extra_info))
  6076. $parent = $extra_info['parent_item_id'];
  6077. else
  6078. $parent = 0;
  6079. $sql = "SELECT * FROM " . $tbl_lp_item . " WHERE lp_id = " . $this->lp_id;
  6080. $result = Database::query($sql);
  6081. $arrLP = array ();
  6082. while ($row = Database :: fetch_array($result)) {
  6083. $arrLP[] = array (
  6084. 'id' => $row['id'],
  6085. 'item_type' => $row['item_type'],
  6086. 'title' => $row['title'],
  6087. 'path' => $row['path'],
  6088. 'description' => $row['description'],
  6089. 'parent_item_id' => $row['parent_item_id'],
  6090. 'previous_item_id' => $row['previous_item_id'],
  6091. 'next_item_id' => $row['next_item_id'],
  6092. 'display_order' => $row['display_order'],
  6093. 'max_score' => $row['max_score'],
  6094. 'min_score' => $row['min_score'],
  6095. 'mastery_score' => $row['mastery_score'],
  6096. 'prerequisite' => $row['prerequisite']
  6097. );
  6098. }
  6099. $this->tree_array($arrLP);
  6100. $arrLP = $this->arrMenu;
  6101. unset ($this->arrMenu);
  6102. if ($action == 'add')
  6103. $return .= get_lang('CreateTheLink') . '&nbsp;:';
  6104. elseif ($action == 'move') $return .= get_lang('MoveCurrentLink') . '&nbsp;:';
  6105. else
  6106. $return .= get_lang('EditCurrentLink') . '&nbsp;:';
  6107. $return .= ' </div>
  6108. </div>';
  6109. $return .= '<div class="sectioncomment">';
  6110. $return .= '<form method="POST">';
  6111. $return .= '<table>';
  6112. if ($action != 'move') {
  6113. $return .= '<tr>';
  6114. $return .= '<td class="label"><label for="idTitle">' . get_lang('Title') . '</label></td>';
  6115. $return .= '<td class="input"><input id="idTitle" name="title" size="44" type="text" value="' . $item_title . '" class="learnpath_item_form"/></td>';
  6116. $return .= '</tr>';
  6117. }
  6118. $return .= '<tr>';
  6119. $return .= '<td class="label"><label for="idParent">' . get_lang('Parent') . '</label></td>';
  6120. $return .= '<td class="input">';
  6121. $return .= '<select id="idParent" style="width:100%;" name="parent" onChange="javascript: load_cbo(this.value);" class="learnpath_item_form" size="1">';
  6122. $return .= '<option class="top" value="0">' . $this->name . '</option>';
  6123. $arrHide = array (
  6124. $id
  6125. );
  6126. $parent_item_id = $_SESSION['parent_item_id'];
  6127. for ($i = 0; $i < count($arrLP); $i++) {
  6128. if ($action != 'add') {
  6129. 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)) {
  6130. $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'] . '">' . $arrLP[$i]['title'] . '</option>';
  6131. } else {
  6132. $arrHide[] = $arrLP[$i]['id'];
  6133. }
  6134. } else {
  6135. if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
  6136. $return .= "\t\t\t\t\t" . '<option ' . (($parent_item_id == $arrLP[$i]['id']) ? 'selected="selected" ' : '') . 'style="padding-left:' . ($arrLP[$i]['depth'] * 10) . 'px;" value="' . $arrLP[$i]['id'] . '">' . $arrLP[$i]['title'] . '</option>';
  6137. }
  6138. }
  6139. if (is_array($arrLP)) {
  6140. reset($arrLP);
  6141. }
  6142. $return .= "\t\t\t\t" . '</select>';
  6143. $return .= '</td>';
  6144. $return .= '</tr>';
  6145. $return .= '<tr>';
  6146. $return .= '<td class="label"><label for="previous">' . get_lang('Position') . '</label></td>';
  6147. $return .= '<td class="input">';
  6148. $return .= "\t\t\t\t" . '<select id="previous" name="previous" style="width:100%;" size="1" class="learnpath_item_form">';
  6149. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . get_lang('FirstPosition') . '</option>';
  6150. for ($i = 0; $i < count($arrLP); $i++) {
  6151. if ($arrLP[$i]['parent_item_id'] == $parent_item_id && $arrLP[$i]['id'] != $id) {
  6152. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  6153. $selected = 'selected="selected" ';
  6154. elseif ($action == 'add')
  6155. $selected = 'selected="selected" ';
  6156. else
  6157. $selected = '';
  6158. $return .= '<option ' . $selected . 'value="' . $arrLP[$i]['id'] . '">' . get_lang('After') . ' "' . $arrLP[$i]['title'] . '"</option>';
  6159. }
  6160. }
  6161. $return .= '</select>';
  6162. $return .= '</td>';
  6163. $return .= '</tr>';
  6164. if ($action != 'move') {
  6165. $return .= '<tr>';
  6166. $return .= '<td class="label"><label for="idURL">' . get_lang('Url') . '</label></td>';
  6167. $return .= '<td class="input"><input' . (is_numeric($extra_info) ? ' disabled="disabled"' : '') . ' id="idURL" name="url" style="width:99%;" type="text" value="' . $item_url . '" class="learnpath_item_form" /></td>';
  6168. $return .= '</tr>';
  6169. $id_prerequisite = 0;
  6170. if (is_array($arrLP)) {
  6171. foreach ($arrLP as $key => $value) {
  6172. if ($value['id'] == $id) {
  6173. $id_prerequisite = $value['prerequisite'];
  6174. break;
  6175. }
  6176. }
  6177. }
  6178. $arrHide = array ();
  6179. for ($i = 0; $i < count($arrLP); $i++) {
  6180. if ($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter') {
  6181. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  6182. $s_selected_position = $arrLP[$i]['id'];
  6183. elseif ($action == 'add') $s_selected_position = 0;
  6184. $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
  6185. }
  6186. }
  6187. /*// Commented the prerequisites, only visible in edit (link).
  6188. $return .= '<tr>';
  6189. $return .= '<td class="label"><label for="idPrerequisites">'.get_lang('Prerequisites').'</label></td>';
  6190. $return .= '<td class="input"><select name="prerequisites" id="prerequisites" class="learnpath_item_form"><option value="0">'.get_lang('NoPrerequisites').'</option>';
  6191. foreach($arrHide as $key => $value) {
  6192. if ($key == $s_selected_position && $action == 'add') {
  6193. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  6194. }
  6195. elseif ($key == $id_prerequisite && $action == 'edit') {
  6196. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  6197. }
  6198. else {
  6199. $return .= '<option value="'.$key.'">'.$value['value'].'</option>';
  6200. }
  6201. }
  6202. $return .= "</select></td>";
  6203. */
  6204. $return .= '</tr>';
  6205. }
  6206. $return .= '<tr>';
  6207. if ($action == 'add') {
  6208. $return .= '<td>&nbsp;</td><td><button class="save" name="submit_button" type="submit">' . get_lang('AddLinkToCourse') . '</button></td>';
  6209. } else {
  6210. $return .= '<td>&nbsp;</td><td><button class="save" name="submit_button" type="submit">' . get_lang('EditCurrentLink') . '</button></td>';
  6211. }
  6212. $return .= '</tr>';
  6213. $return .= '</table>';
  6214. if ($action == 'move') {
  6215. $return .= '<input name="title" type="hidden" value="' . $item_title . '" />';
  6216. $return .= '<input name="description" type="hidden" value="' . $item_description . '" />';
  6217. }
  6218. if (is_numeric($extra_info)) {
  6219. $return .= '<input name="path" type="hidden" value="' . $extra_info . '" />';
  6220. }
  6221. elseif (is_array($extra_info)) {
  6222. $return .= '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />';
  6223. }
  6224. $return .= '<input name="type" type="hidden" value="' . TOOL_LINK . '" />';
  6225. $return .= '<input name="post_time" type="hidden" value="' . time() . '" />';
  6226. $return .= '</form>';
  6227. $return .= '</div>';
  6228. return $return;
  6229. }
  6230. /**
  6231. * Return HTML form to add/edit a student publication (work)
  6232. * @param string Action (add/edit)
  6233. * @param integer Item ID if already exists
  6234. * @param mixed Extra info (work ID if integer)
  6235. * @return string HTML form
  6236. */
  6237. public function display_student_publication_form($action = 'add', $id = 0, $extra_info = '') {
  6238. global $charset;
  6239. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  6240. $tbl_publication = Database :: get_course_table(TABLE_STUDENT_PUBLICATION);
  6241. if ($id != 0 && is_array($extra_info)) {
  6242. $item_title = stripslashes($extra_info['title']);
  6243. $item_description = stripslashes($extra_info['description']);
  6244. }
  6245. elseif (is_numeric($extra_info)) {
  6246. $sql_publication = "
  6247. SELECT
  6248. title,
  6249. description
  6250. FROM " . $tbl_publication . "
  6251. WHERE id = " . $extra_info;
  6252. $result = Database::query($sql_publication);
  6253. $row = Database :: fetch_array($result);
  6254. $item_title = $row['title'];
  6255. } else {
  6256. $item_title = get_lang('Student_publication');
  6257. }
  6258. $return = ' <div class="row">
  6259. <div class="form_header">';
  6260. if ($id != 0 && is_array($extra_info))
  6261. $parent = $extra_info['parent_item_id'];
  6262. else
  6263. $parent = 0;
  6264. $sql = "
  6265. SELECT *
  6266. FROM " . $tbl_lp_item . "
  6267. WHERE
  6268. lp_id = " . $this->lp_id;
  6269. $result = Database::query($sql);
  6270. $arrLP = array ();
  6271. while ($row = Database :: fetch_array($result)) {
  6272. $arrLP[] = array (
  6273. 'id' => $row['id'],
  6274. 'item_type' => $row['item_type'],
  6275. 'title' => $row['title'],
  6276. 'path' => $row['path'],
  6277. 'description' => $row['description'],
  6278. 'parent_item_id' => $row['parent_item_id'],
  6279. 'previous_item_id' => $row['previous_item_id'],
  6280. 'next_item_id' => $row['next_item_id'],
  6281. 'display_order' => $row['display_order'],
  6282. 'max_score' => $row['max_score'],
  6283. 'min_score' => $row['min_score'],
  6284. 'mastery_score' => $row['mastery_score'],
  6285. 'prerequisite' => $row['prerequisite']
  6286. );
  6287. }
  6288. $this->tree_array($arrLP);
  6289. $arrLP = $this->arrMenu;
  6290. unset ($this->arrMenu);
  6291. if ($action == 'add')
  6292. $return .= get_lang('Student_publication') . '&nbsp;:' . "\n";
  6293. elseif ($action == 'move') $return .= get_lang('MoveCurrentStudentPublication') . '&nbsp;:' . "\n";
  6294. else
  6295. $return .= get_lang('EditCurrentStudentPublication') . '&nbsp;:' . "\n";
  6296. $return .= ' </div>
  6297. </div>';
  6298. $return .= '<div class="sectioncomment">';
  6299. $return .= '<form method="POST">';
  6300. $return .= '<table class="lp_form">';
  6301. if ($action != 'move') {
  6302. $return .= '<tr>';
  6303. $return .= '<td class="label"><label for="idTitle">' . get_lang('Title') . '</label></td>';
  6304. $return .= '<td class="input"><input id="idTitle" name="title" size="44" type="text" value="' . $item_title . '" class="learnpath_item_form" /></td>';
  6305. $return .= '</tr>';
  6306. }
  6307. $return .= '<tr>';
  6308. $return .= '<td class="label"><label for="idParent">' . get_lang('Parent') . '</label></td>';
  6309. $return .= '<td class="input">';
  6310. $return .= "\t\t\t\t" . '<select id="idParent" name="parent" style="width:100%;" onChange="javascript: load_cbo(this.value);" class="learnpath_item_form" size="1">';
  6311. //$parent_item_id = $_SESSION['parent_item_id'];
  6312. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
  6313. $arrHide = array (
  6314. $id
  6315. );
  6316. for ($i = 0; $i < count($arrLP); $i++) {
  6317. if ($action != 'add') {
  6318. 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)) {
  6319. $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'] . '">' . $arrLP[$i]['title'] . '</option>';
  6320. } else {
  6321. $arrHide[] = $arrLP[$i]['id'];
  6322. }
  6323. } else {
  6324. if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
  6325. $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'] . '">' . $arrLP[$i]['title'] . '</option>';
  6326. }
  6327. }
  6328. if (is_array($arrLP)) {
  6329. reset($arrLP);
  6330. }
  6331. $return .= "\t\t\t\t" . '</select>';
  6332. $return .= '</td>';
  6333. $return .= '</tr>';
  6334. $return .= '<tr>';
  6335. $return .= '<td class="label"><label for="previous">' . get_lang('Position') . '</label></td>';
  6336. $return .= '<td class="input">';
  6337. $return .= "\t\t\t\t" . '<select id="previous" name="previous" style="width:100%;" size="1" class="learnpath_item_form">';
  6338. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . get_lang('FirstPosition') . '</option>';
  6339. for ($i = 0; $i < count($arrLP); $i++) {
  6340. if ($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) {
  6341. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  6342. $selected = 'selected="selected" ';
  6343. elseif ($action == 'add') $selected = 'selected="selected" ';
  6344. else
  6345. $selected = '';
  6346. $return .= "\t\t\t\t\t" . '<option ' . $selected . 'value="' . $arrLP[$i]['id'] . '">' . get_lang('After') . ' "' . $arrLP[$i]['title'] . '"</option>';
  6347. }
  6348. }
  6349. $return .= "\t\t\t\t" . '</select>';
  6350. $return .= '</td>';
  6351. $return .= '</tr>';
  6352. if ($action != 'move') {
  6353. $id_prerequisite = 0;
  6354. if (is_array($arrLP)) {
  6355. foreach ($arrLP as $key => $value) {
  6356. if ($value['id'] == $id) {
  6357. $id_prerequisite = $value['prerequisite'];
  6358. break;
  6359. }
  6360. }
  6361. }
  6362. $arrHide = array ();
  6363. for ($i = 0; $i < count($arrLP); $i++) {
  6364. if ($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter') {
  6365. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  6366. $s_selected_position = $arrLP[$i]['id'];
  6367. elseif ($action == 'add') $s_selected_position = 0;
  6368. $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
  6369. }
  6370. }
  6371. // Commented the prerequisites, only visible in edit (work).
  6372. /*
  6373. $return .= '<tr>';
  6374. $return .= '<td class="label"><label for="idPrerequisites">'.get_lang('Prerequisites').'</label></td>';
  6375. $return .= '<td class="input"><select name="prerequisites" id="prerequisites" class="learnpath_item_form"><option value="0">'.get_lang('NoPrerequisites').'</option>';
  6376. foreach($arrHide as $key => $value) {
  6377. if ($key == $s_selected_position && $action == 'add') {
  6378. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  6379. }
  6380. elseif ($key == $id_prerequisite && $action == 'edit') {
  6381. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  6382. }
  6383. else {
  6384. $return .= '<option value="'.$key.'">'.$value['value'].'</option>';
  6385. }
  6386. }
  6387. $return .= "</select></td>";
  6388. */
  6389. $return .= '</tr>';
  6390. }
  6391. $return .= '<tr>';
  6392. if ($action == 'add') {
  6393. $return .= '<td>&nbsp</td><td><button class="save" name="submit_button" type="submit">' . get_lang('AddAssignmentToCourse') . '</button></td>';
  6394. } else {
  6395. $return .= '<td>&nbsp</td><td><button class="save" name="submit_button" type="submit">' . get_lang('EditCurrentStudentPublication') . '</button></td>';
  6396. }
  6397. $return .= '</tr>';
  6398. $return .= '</table>';
  6399. if ($action == 'move') {
  6400. $return .= '<input name="title" type="hidden" value="' . $item_title . '" />';
  6401. $return .= '<input name="description" type="hidden" value="' . $item_description . '" />';
  6402. }
  6403. if (is_numeric($extra_info)) {
  6404. $return .= '<input name="path" type="hidden" value="' . $extra_info . '" />';
  6405. } elseif (is_array($extra_info)) {
  6406. $return .= '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />';
  6407. }
  6408. $return .= '<input name="type" type="hidden" value="' . TOOL_STUDENTPUBLICATION . '" />';
  6409. $return .= '<input name="post_time" type="hidden" value="' . time() . '" />';
  6410. $return .= '</form>';
  6411. $return .= '</div>';
  6412. return $return;
  6413. }
  6414. /**
  6415. * Displays the menu for manipulating a step
  6416. * @return string html
  6417. */
  6418. public function display_manipulate($item_id, $item_type = TOOL_DOCUMENT) {
  6419. global $charset, $_course;
  6420. $return = '<div class="actions">';
  6421. switch ($item_type) {
  6422. case 'dokeos_chapter' :
  6423. case 'chapter' :
  6424. // Commented the message cause should not show it.
  6425. //$lang = get_lang('TitleManipulateChapter');
  6426. break;
  6427. case 'dokeos_module' :
  6428. case 'module' :
  6429. // Commented the message cause should not show it.
  6430. //$lang = get_lang('TitleManipulateModule');
  6431. break;
  6432. case TOOL_DOCUMENT :
  6433. // Commented the message cause should not show it.
  6434. //$lang = get_lang('TitleManipulateDocument');
  6435. break;
  6436. case TOOL_LINK :
  6437. case 'link' :
  6438. // Commented the message cause should not show it.
  6439. //$lang = get_lang('TitleManipulateLink');
  6440. break;
  6441. case TOOL_QUIZ :
  6442. // Commented the message cause should not show it.
  6443. //$lang = get_lang('TitleManipulateQuiz');
  6444. break;
  6445. case TOOL_STUDENTPUBLICATION :
  6446. // Commented the message cause should not show it.
  6447. //$lang = get_lang('TitleManipulateStudentPublication');
  6448. break;
  6449. }
  6450. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  6451. $item_id = intval($item_id);
  6452. $sql = "SELECT * FROM " . $tbl_lp_item . " as lp WHERE lp.id = " . $item_id;
  6453. $result = Database::query($sql);
  6454. $row = Database::fetch_assoc($result);
  6455. $s_title = $row['title'];
  6456. // We display an audio player if needed.
  6457. if (!empty ($row['audio'])) {
  6458. $return .= '<div class="lp_mediaplayer" id="container"><a href="http://www.macromedia.com/go/getflashplayer">Get the Flash Player</a> to see this player.</div>';
  6459. $return .= '<script type="text/javascript" src="../inc/lib/mediaplayer/swfobject.js"></script>';
  6460. $return .= '<script type="text/javascript">
  6461. var s1 = new SWFObject("../inc/lib/mediaplayer/player.swf","ply","250","20","9","#FFFFFF");
  6462. s1.addParam("allowscriptaccess","always");
  6463. s1.addParam("flashvars","file=../../courses/' . $_course['path'] . '/document/audio/' . $row['audio'] . '&autostart=true");
  6464. s1.write("container");
  6465. </script>';
  6466. }
  6467. // Commented ":" for message in step.
  6468. //$return .= $lang.': ';
  6469. $url = api_get_self() . '?cidReq='.Security::remove_XSS($_GET['cidReq']).'&view=build&id='.$item_id .'&lp_id='.$this->lp_id;
  6470. $return .= Display::url(Display::return_icon('edit.png', get_lang('Edit'), array(), 22), $url.'&action=edit_item&path_item=' . $row['path']);
  6471. $return .= Display::url(Display::return_icon('move.png', get_lang('Move'), array(), 22), $url.'&action=move_item');
  6472. // Commented for now as prerequisites cannot be added to chapters.
  6473. if ($item_type != 'dokeos_chapter' && $item_type != 'chapter') {
  6474. $return .= Display::url(Display::return_icon('accept.png', get_lang('Prerequisites'), array(), 22), $url.'&action=edit_item_prereq');
  6475. }
  6476. $return .= Display::url(Display::return_icon('delete.png', get_lang('Delete'), array(), 22), $url.'&action=delete_item');
  6477. /*
  6478. // Get the audiorecorder. Use of ob_* functions since there are echos in the file.
  6479. ob_start();
  6480. $audio_recorder_studentview = 'false';
  6481. $audio_recorder_item_id = $item_id;
  6482. if (api_get_setting('service_visio', 'active') == 'true') {
  6483. require_once 'audiorecorder.inc.php';
  6484. }
  6485. $return .= ob_get_contents();
  6486. ob_end_clean();
  6487. // End of audiorecorder include
  6488. */
  6489. $return .= '</div>';
  6490. return $return;
  6491. }
  6492. /**
  6493. * Creates the javascript needed for filling up the checkboxes without page reload
  6494. *
  6495. * @return string
  6496. */
  6497. public function get_js_dropdown_array() {
  6498. $return = 'var child_name = new Array();' . "\n";
  6499. $return .= 'var child_value = new Array();' . "\n\n";
  6500. $return .= 'child_name[0] = new Array();' . "\n";
  6501. $return .= 'child_value[0] = new Array();' . "\n\n";
  6502. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  6503. $sql_zero = "
  6504. SELECT * FROM " . $tbl_lp_item . "
  6505. WHERE lp_id = " . $this->lp_id . " AND parent_item_id = 0
  6506. ORDER BY display_order ASC";
  6507. $res_zero = Database::query($sql_zero);
  6508. global $charset;
  6509. $i = 0;
  6510. while ($row_zero = Database :: fetch_array($res_zero)) {
  6511. $js_var = json_encode(get_lang('After').' '.$row_zero['title']);
  6512. $return .= 'child_name[0][' . $i . '] = '.$js_var.' ;' . "\n";
  6513. $return .= 'child_value[0][' . $i++ . '] = "' . $row_zero['id'] . '";' . "\n";
  6514. }
  6515. $return .= "\n";
  6516. $sql = "SELECT * FROM " . $tbl_lp_item . " WHERE lp_id = " . $this->lp_id;
  6517. $res = Database::query($sql);
  6518. while ($row = Database :: fetch_array($res)) {
  6519. $sql_parent = "
  6520. SELECT * FROM " . $tbl_lp_item . "
  6521. WHERE parent_item_id = " . $row['id'] . "
  6522. ORDER BY display_order ASC";
  6523. $res_parent = Database::query($sql_parent);
  6524. $i = 0;
  6525. $return .= 'child_name[' . $row['id'] . '] = new Array();' . "\n";
  6526. $return .= 'child_value[' . $row['id'] . '] = new Array();' . "\n\n";
  6527. while ($row_parent = Database :: fetch_array($res_parent)) {
  6528. $js_var = json_encode(get_lang('After').' '.$row_parent['title']);
  6529. $return .= 'child_name[' . $row['id'] . '][' . $i . '] = '.$js_var.' ;' . "\n";
  6530. $return .= 'child_value[' . $row['id'] . '][' . $i++ . '] = "' . $row_parent['id'] . '";' . "\n";
  6531. }
  6532. $return .= "\n";
  6533. }
  6534. return $return;
  6535. }
  6536. /**
  6537. * Display the form to allow moving an item
  6538. * @param integer Item ID
  6539. * @return string HTML form
  6540. */
  6541. public function display_move_item($item_id) {
  6542. global $_course; //will disappear
  6543. global $charset;
  6544. $return = '';
  6545. if (is_numeric($item_id)) {
  6546. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  6547. $sql = "SELECT *
  6548. FROM " . $tbl_lp_item . "
  6549. WHERE id = " . $item_id;
  6550. $res = Database::query($sql);
  6551. $row = Database :: fetch_array($res);
  6552. switch ($row['item_type']) {
  6553. case 'dokeos_chapter' :
  6554. case 'dir' :
  6555. case 'asset' :
  6556. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6557. $return .= $this->display_item_form($row['item_type'], get_lang('MoveCurrentChapter'), 'move', $item_id, $row);
  6558. break;
  6559. case 'dokeos_module' :
  6560. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6561. $return .= $this->display_item_form($row['item_type'], 'Move th current module:', 'move', $item_id, $row);
  6562. break;
  6563. case TOOL_DOCUMENT :
  6564. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6565. $return .= $this->display_document_form('move', $item_id, $row);
  6566. break;
  6567. case TOOL_LINK :
  6568. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6569. $return .= $this->display_link_form('move', $item_id, $row);
  6570. break;
  6571. case TOOL_HOTPOTATOES :
  6572. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6573. $return .= $this->display_link_form('move', $item_id, $row);
  6574. break;
  6575. case TOOL_QUIZ :
  6576. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6577. $return .= $this->display_quiz_form('move', $item_id, $row);
  6578. break;
  6579. case TOOL_STUDENTPUBLICATION :
  6580. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6581. $return .= $this->display_student_publication_form('move', $item_id, $row);
  6582. break;
  6583. case TOOL_FORUM :
  6584. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6585. $return .= $this->display_forum_form('move', $item_id, $row);
  6586. break;
  6587. case TOOL_THREAD :
  6588. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6589. $return .= $this->display_forum_form('move', $item_id, $row);
  6590. break;
  6591. }
  6592. }
  6593. return $return;
  6594. }
  6595. /**
  6596. * Displays a basic form on the overview page for changing the item title and the item description.
  6597. * @param string $item_type
  6598. * @param string $title
  6599. * @param array $data
  6600. * @return string
  6601. */
  6602. public function display_item_small_form($item_type, $title = '', $data) {
  6603. global $charset;
  6604. $return = '<div class="lp_small_form">';
  6605. $return .= '<p class="lp_title">' . $title . '</p>';
  6606. $return .= '<form method="post">';
  6607. $return .= '<table cellpadding="0" cellspacing="0" class="lp_form">';
  6608. $return .= '<tr>';
  6609. $return .= '<td class="label"><label for="idTitle">Title&nbsp;:</label></td>';
  6610. $return .= '<td class="input"><input class="small_form" id="idTitle" name="title" type="text" value="' . api_html_entity_decode($data['title'], ENT_QUOTES) . '" /></td>';
  6611. $return .= '</tr>';
  6612. // It said these lines of code - see SVN#11724 and SVN#10770
  6613. //$return .= '<tr>';
  6614. //$return .= '<td class="label"><label for="idDescription">Description&nbsp;:</label></td>';
  6615. //$return .= '<td class="input"><textarea class="small_form" id="idDescription" name="description" rows="4">' . $data['description'] . '</textarea></td>';
  6616. //$return .= '</tr>';
  6617. $return .= '<tr>';
  6618. $return .= '<td colspan="2"><button class="save" name="submit_button" type="submit">' . get_lang('Save') . '</button></td>';
  6619. $return .= '</tr>';
  6620. $return .= '</table>';
  6621. $return .= '<input name="parent" type="hidden" value="' . $data['parent_item_id'] . '"/>';
  6622. $return .= '<input name="previous" type="hidden" value="' . $data['previous_item_id'] . '"/>';
  6623. $return .= '</form>';
  6624. $return .= '</div>';
  6625. return $return;
  6626. }
  6627. /**
  6628. * Return HTML form to allow prerequisites selection
  6629. * @param integer Item ID
  6630. * @return string HTML form
  6631. */
  6632. public function display_item_prerequisites_form($item_id) {
  6633. global $charset;
  6634. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  6635. $item_id = intval($item_id);
  6636. /* Current prerequisite */
  6637. $sql = "SELECT * FROM $tbl_lp_item WHERE id = " . $item_id;
  6638. $result = Database::query($sql);
  6639. $row = Database::fetch_array($result);
  6640. $preq_id = $row['prerequisite'];
  6641. //$preq_mastery = $row['mastery_score'];
  6642. //$preq_max = $row['max_score'];
  6643. $return = $this->display_manipulate($item_id, TOOL_DOCUMENT);
  6644. $return = ' <div class="row">
  6645. <div class="form_header">';
  6646. $return .= get_lang('AddEditPrerequisites');
  6647. $return .= '</div></div>';
  6648. $return .= '<div class="sectioncomment">';
  6649. $return .= '<form method="POST">';
  6650. $return .= '<table class="data_table" style="width:650px">';
  6651. $return .= '<tr>';
  6652. $return .= '<th height="24">' . get_lang('Prerequisites') . '</th>';
  6653. $return .= '<th width="70" height="24">' . get_lang('Minimum') . '</th>';
  6654. $return .= '<th width="70" height="24">' . get_lang('Maximum') . '</th>';
  6655. $return .= '</tr>';
  6656. // Adding the none option to the prerequisites see http://www.chamilo.org/es/node/146
  6657. $return .= '<tr >';
  6658. $return .= '<td colspan="3" class="radio">';
  6659. $return .= '<input checked="checked" id="idNone" name="prerequisites" style="margin-left:0px; margin-right:10px;" type="radio" />';
  6660. $return .= '<label for="idNone">' . get_lang('None') . '</label>';
  6661. $return .= '</tr>';
  6662. $sql = "SELECT * FROM " . $tbl_lp_item . " WHERE lp_id = " . $this->lp_id;
  6663. $result = Database::query($sql);
  6664. $arrLP = array ();
  6665. while ($row = Database :: fetch_array($result)) {
  6666. $arrLP[] = array (
  6667. 'id' => $row['id'],
  6668. 'item_type' => $row['item_type'],
  6669. 'title' => $row['title'],
  6670. 'ref' => $row['ref'],
  6671. 'description' => $row['description'],
  6672. 'parent_item_id' => $row['parent_item_id'],
  6673. 'previous_item_id' => $row['previous_item_id'],
  6674. 'next_item_id' => $row['next_item_id'],
  6675. 'max_score' => $row['max_score'],
  6676. 'min_score' => $row['min_score'],
  6677. 'mastery_score' => $row['mastery_score'],
  6678. 'prerequisite' => $row['prerequisite'],
  6679. 'next_item_id' => $row['next_item_id'],
  6680. 'display_order' => $row['display_order']
  6681. );
  6682. if ($row['ref'] == $preq_id) {
  6683. $preq_mastery = $row['mastery_score'];
  6684. $preq_max = $row['max_score'];
  6685. }
  6686. }
  6687. $this->tree_array($arrLP);
  6688. $arrLP = $this->arrMenu;
  6689. unset ($this->arrMenu);
  6690. for ($i = 0; $i < count($arrLP); $i++) {
  6691. if ($arrLP[$i]['id'] == $item_id)
  6692. break;
  6693. $return .= '<tr>';
  6694. $return .= '<td class="radio"' . (($arrLP[$i]['item_type'] != TOOL_QUIZ && $arrLP[$i]['item_type'] != TOOL_HOTPOTATOES) ? ' colspan="3"' : '') . '>';
  6695. $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'] . '" />';
  6696. $icon_name = str_replace(' ', '', $arrLP[$i]['item_type']);
  6697. if (file_exists('../img/lp_' . $icon_name . '.png')) {
  6698. $return .= '<img alt="" src="../img/lp_' . $icon_name . '.png" style="margin-right:5px;" title="" />';
  6699. } else
  6700. if (file_exists('../img/lp_' . $icon_name . '.gif')) {
  6701. $return .= '<img alt="" src="../img/lp_' . $icon_name . '.gif" style="margin-right:5px;" title="" />';
  6702. } else {
  6703. $return .= Display::return_icon('folder_document.gif','',array('style'=>'margin-right:5px;'));
  6704. }
  6705. $return .= '<label for="id' . $arrLP[$i]['id'] . '">' . $arrLP[$i]['title'] . '</label>';
  6706. $return .= '</td>';
  6707. //$return .= '<td class="radio"' . (($arrLP[$i]['item_type'] != TOOL_HOTPOTATOES) ? ' colspan="3"' : '') . ' />';
  6708. if ($arrLP[$i]['item_type'] == TOOL_QUIZ) {
  6709. $return .= '<td class="exercise" style="border:1px solid #ccc;">';
  6710. $return .= '<center><input size="4" maxlength="3" name="min_' . $arrLP[$i]['id'] . '" type="text" value="' . (($arrLP[$i]['id'] == $preq_id) ? $preq_mastery : 0) . '" /></center>';
  6711. $return .= '</td>';
  6712. $return .= '<td class="exercise" style="border:1px solid #ccc;">';
  6713. $return .= '<center><input size="4" maxlength="3" name="max_' . $arrLP[$i]['id'] . '" type="text" value="' . $arrLP[$i]['max_score'] . '" disabled="true" /></center>';
  6714. $return .= '</td>';
  6715. }
  6716. if ($arrLP[$i]['item_type'] == TOOL_HOTPOTATOES) {
  6717. $return .= '<td class="exercise" style="border:1px solid #ccc;">';
  6718. $return .= '<center><input size="4" maxlength="3" name="min_' . $arrLP[$i]['id'] . '" type="text" value="' . (($arrLP[$i]['id'] == $preq_id) ? $preq_mastery : 0) . '" /></center>';
  6719. $return .= '</td>';
  6720. $return .= '<td class="exercise" style="border:1px solid #ccc;">';
  6721. $return .= '<center><input size="4" maxlength="3" name="max_' . $arrLP[$i]['id'] . '" type="text" value="' . $arrLP[$i]['max_score'] . '" disabled="true" /></center>';
  6722. $return .= '</td>';
  6723. }
  6724. $return .= '</tr>';
  6725. }
  6726. $return .= '<tr>';
  6727. $return .= '</tr>';
  6728. $return .= '</table>';
  6729. $return .= '<div style="padding-top:3px;">';
  6730. $return .= '<button class="save" name="submit_button" type="submit">' . get_lang('ModifyPrerequisites') . ' </button></td>';
  6731. $return .= '</div>';
  6732. $return .= '</form>';
  6733. $return .= '</div>';
  6734. return $return;
  6735. }
  6736. /**
  6737. * Return HTML list to allow prerequisites selection for lp
  6738. * @param integer Item ID
  6739. * @return string HTML form
  6740. */
  6741. public function display_lp_prerequisites_list() {
  6742. global $charset;
  6743. $lp_id = $this->lp_id;
  6744. $tbl_lp = Database :: get_course_table(TABLE_LP_MAIN);
  6745. // get current prerequisite
  6746. $sql = "SELECT * FROM $tbl_lp WHERE id = $lp_id ";
  6747. $result = Database::query($sql);
  6748. $row = Database :: fetch_array($result);
  6749. $preq_id = $row['prerequisite'];
  6750. $session_id = api_get_session_id();
  6751. $session_condition = api_get_session_condition($session_id, false);
  6752. $sql = "SELECT * FROM $tbl_lp $session_condition ORDER BY display_order ";
  6753. $rs = Database::query($sql);
  6754. $return = '';
  6755. $return .= '<select name="prerequisites" >';
  6756. $return .= '<option value="0">'.get_lang('None').'</option>';
  6757. if (Database::num_rows($rs) > 0) {
  6758. while ($row = Database::fetch_array($rs)) {
  6759. if ($row['id'] == $lp_id) {
  6760. continue;
  6761. }
  6762. $return .= '<option value="'.$row['id'].'" '.(($row['id']==$preq_id)?' selected ' : '').'>'.$row['name'].'</option>';
  6763. }
  6764. }
  6765. $return .= '</select>';
  6766. return $return;
  6767. }
  6768. /**
  6769. * Creates a list with all the documents in it
  6770. * @return string
  6771. */
  6772. public function get_documents() {
  6773. $course_info = api_get_course_info();
  6774. require_once api_get_path(LIBRARY_PATH).'document.lib.php';
  6775. $document_tree = DocumentManager::get_document_preview($course_info, $this->lp_id);
  6776. return $document_tree;
  6777. }
  6778. /**
  6779. * Creates a list with all the exercises (quiz) in it
  6780. * @return string
  6781. */
  6782. public function get_exercises() {
  6783. // New for hotpotatoes.
  6784. $uploadPath = DIR_HOTPOTATOES; //defined in main_api
  6785. $tbl_doc = Database :: get_course_table(TABLE_DOCUMENT);
  6786. $tbl_quiz = Database :: get_course_table(TABLE_QUIZ_TEST);
  6787. $session_id = api_get_session_id();
  6788. $condition_session = api_get_session_condition($session_id);
  6789. $sql_quiz = "SELECT * FROM $tbl_quiz WHERE active<>'-1' $condition_session ORDER BY title ASC";
  6790. $sql_hot = "SELECT * FROM $tbl_doc WHERE path LIKE '" . $uploadPath . "/%/%htm%' $condition_session ORDER BY id ASC";
  6791. $res_quiz = Database::query($sql_quiz);
  6792. $res_hot = Database::query($sql_hot);
  6793. //$return .= '<div class="lp_resource_header"' . " onclick=\"javascript: if(document.getElementById('resExercise').style.display == 'block') {document.getElementById('resExercise').style.display = 'none';} else {document.getElementById('resExercise').style.display = 'block';}\"" . ' ><img align="left" alt="" src="../img/lp_' . TOOL_QUIZ . '.gif" style="margin-right:5px;" title="" />' . get_lang('Quiz') . '</div>';
  6794. $return = '<div class="lp_resource">';
  6795. $return .= '<div class="lp_resource_element">';
  6796. $return .= '<img alt="" src="../img/new_test_small.gif" style="margin-right:5px;" title="" />';
  6797. $return .= '<a href="' . api_get_path(REL_CODE_PATH) . 'exercice/exercise_admin.php?lp_id=' . $this->lp_id . '">' . get_lang('NewExercise') . '</a>';
  6798. $return .= '</div>';
  6799. while ($row_hot = Database :: fetch_array($res_hot)) {
  6800. $return .= '<div class="lp_resource_element">';
  6801. // Display quizhotpotatoes.
  6802. $return .= '<img alt="hp" src="../img/hotpotatoes_s.png" style="margin-right:5px;" title="" width="18px" height="18px" />';
  6803. $return .= '<a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&amp;action=add_item&amp;type=' . TOOL_HOTPOTATOES . '&amp;file=' . $row_hot['id'] . '&amp;lp_id=' . $this->lp_id . '">' . ((!empty ($row_hot['comment'])) ? $row_hot['comment'] : Security :: remove_XSS($row_hot['title'])) . '</a>';
  6804. //$return .= $row_quiz['title'];
  6805. $return .= '</div>';
  6806. }
  6807. while ($row_quiz = Database :: fetch_array($res_quiz)) {
  6808. $return .= '<div class="lp_resource_element">';
  6809. $return .= '<img alt="" src="../img/quizz_small.gif" style="margin-right:5px;" title="" />';
  6810. $return .= '<a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&amp;action=add_item&amp;type=' . TOOL_QUIZ . '&amp;file=' . $row_quiz['id'] . '&amp;lp_id=' . $this->lp_id . '">' . Security :: remove_XSS($row_quiz['title']) . '</a>';
  6811. //$return .= $row_quiz['title'];
  6812. $return .= '</div>';
  6813. }
  6814. /*if (Database :: num_rows($res_quiz) == 0) {
  6815. $return .= '<div class="lp_resource_element">' . get_lang('NoExercisesAvailable') . '</div>';
  6816. }*/
  6817. $return .= '</div>';
  6818. return $return;
  6819. }
  6820. /**
  6821. * Creates a list with all the links in it
  6822. * @return string
  6823. */
  6824. public function get_links() {
  6825. $tbl_link = Database :: get_course_table(TABLE_LINK);
  6826. $session_id = api_get_session_id();
  6827. $condition_session = api_get_session_condition($session_id,false);
  6828. $sql_link = "SELECT * FROM $tbl_link $condition_session ORDER BY title ASC";
  6829. $res_link = Database::query($sql_link);
  6830. //$return .= '<div class="lp_resource_header"' . " onclick=\"javascript: if(document.getElementById('resLink').style.display == 'block') {document.getElementById('resLink').style.display = 'none';} else {document.getElementById('resLink').style.display = 'block';}\"" . '><img alt="" src="../img/lp_' . TOOL_LINK . '.gif" style="margin-right:5px;" title="" />' . get_lang('Links') . '</div>';
  6831. $return = '<div class="lp_resource">';
  6832. $return .= '<div class="lp_resource_element">';
  6833. $return .= '<img alt="" src="../img/linksnew.gif" style="margin-right:5px;width:16px" title="" />';
  6834. $return .= '<a href="' . api_get_path(REL_CODE_PATH) . 'link/link.php?' . api_get_cidreq() . '&action=addlink&amp;lp_id=' . $this->lp_id . '" title="' . get_lang('LinkAdd') . '">' . get_lang('LinkAdd') . '</a>';
  6835. $return .= '</div>';
  6836. while ($row_link = Database :: fetch_array($res_link)) {
  6837. $return .= '<div class="lp_resource_element">';
  6838. $return .= '<img alt="" src="../img/lp_link.gif" style="margin-right:5px;" title="" />';
  6839. $return .= '<a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_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>';
  6840. $return .= '</div>';
  6841. }
  6842. /*if (Database :: num_rows($res_link) == 0)
  6843. $return .= '<div class="lp_resource_element">' . get_lang('NoLinksAvailable') . '</div>';
  6844. */
  6845. $return .= '</div>';
  6846. return $return;
  6847. }
  6848. /**
  6849. * Creates a list with all the student publications in it
  6850. * @return unknown
  6851. */
  6852. public function get_student_publications() {
  6853. $tbl_student = Database :: get_course_table(TABLE_STUDENT_PUBLICATION);
  6854. $session_id = api_get_session_id();
  6855. $condition_session = api_get_session_condition($session_id, false);
  6856. $sql_student = "SELECT * FROM $tbl_student $condition_session ORDER BY title ASC";
  6857. $res_student = Database::query($sql_student);
  6858. //$return .= '<div class="lp_resource_header"' . " onclick=\"javascript: if(document.getElementById('resStudent').style.display == 'block') {document.getElementById('resStudent').style.display = 'none';} else {document.getElementById('resStudent').style.display = 'block';}\"" . '><img alt="" src="../img/lp_' . TOOL_STUDENTPUBLICATION . '.gif" style="margin-right:5px;" title="" />' . get_lang('Student_publication') . '</div>';
  6859. $return = '<div class="lp_resource" >';
  6860. $return .= '<div class="lp_resource_element">';
  6861. $return .= '<img align="left" alt="" src="../img/works_small.gif" style="margin-right:5px;" title="" />';
  6862. $return .= '<a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&amp;action=add_item&amp;type=' . TOOL_STUDENTPUBLICATION . '&amp;lp_id=' . $this->lp_id . '">' . get_lang('AddAssignmentPage') . '</a>';
  6863. $return .= '</div>';
  6864. $return .= '</div>';
  6865. return $return;
  6866. }
  6867. /**
  6868. * Creates a list with all the forums in it
  6869. * @return string
  6870. */
  6871. public function get_forums() {
  6872. require_once '../forum/forumfunction.inc.php';
  6873. require_once '../forum/forumconfig.inc.php';
  6874. global $table_forums, $table_threads, $table_posts, $table_item_property, $table_users;
  6875. $table_forums = Database :: get_course_table(TABLE_FORUM);
  6876. $table_threads = Database :: get_course_table(TABLE_FORUM_THREAD);
  6877. $table_posts = Database :: get_course_table(TABLE_FORUM_POST);
  6878. $table_item_property = Database :: get_course_table(TABLE_ITEM_PROPERTY);
  6879. $table_users = Database :: get_main_table(TABLE_MAIN_USER);
  6880. $a_forums = get_forums();
  6881. //$return .= '<div class="lp_resource_header"' . " onclick=\"javascript: if(document.getElementById('forums').style.display == 'block') {document.getElementById('forums').style.display = 'none';} else {document.getElementById('forums').style.display = 'block';}\"" . '><img alt="" src="../img/lp_forum.gif" style="margin-right:5px;" title="" />' . get_lang('Forums') . '</div>';
  6882. $return = '<div class="lp_resource">';
  6883. $return .= '<div class="lp_resource_element">';
  6884. $return .= '<img alt="" src="../img/forum_new_small.gif" style="margin-right:5px;" title="" />';
  6885. $return .= '<a href="' . api_get_path(REL_CODE_PATH) . 'forum/index.php?' . api_get_cidreq() . '&action=add&amp;content=forum&amp;origin=learnpath&amp;lp_id=' . $this->lp_id . '" title="' . get_lang('CreateANewForum') . '">' . get_lang('CreateANewForum') . '</a>';
  6886. $return .= '</div>';
  6887. foreach ($a_forums as $forum) {
  6888. $return .= '<div class="lp_resource_element_no_link">';
  6889. $return .= '<script type="text/javascript">
  6890. function toggle_forum(forum_id){
  6891. if(document.getElementById("forum_"+forum_id+"_content").style.display == "none"){
  6892. document.getElementById("forum_"+forum_id+"_content").style.display = "block";
  6893. document.getElementById("forum_"+forum_id+"_opener").src = "' . api_get_path(WEB_IMG_PATH) . 'remove.gif";
  6894. }
  6895. else {
  6896. document.getElementById("forum_"+forum_id+"_content").style.display = "none";
  6897. document.getElementById("forum_"+forum_id+"_opener").src = "' . api_get_path(WEB_IMG_PATH) . 'add.gif";
  6898. }
  6899. }
  6900. </script>';
  6901. if (!empty($forum['forum_id'])) {
  6902. $return .= '<img alt="" src="../img/lp_forum.gif" style="margin-right:5px;" title="" />';
  6903. $return .= '<a style="cursor:hand" onclick="javascript: 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>
  6904. <a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_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">' . Security :: remove_XSS($forum['forum_title']) . '</a><ul style="display:none" id="forum_' . $forum['forum_id'] . '_content">';
  6905. }
  6906. $a_threads = get_threads($forum['forum_id']);
  6907. if (is_array($a_threads)) {
  6908. foreach ($a_threads as $thread) {
  6909. $return .= '<li><a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&amp;action=add_item&amp;type=' . TOOL_THREAD . '&amp;thread_id=' . $thread['thread_id'] . '&amp;lp_id=' . $this->lp_id . '">' . Security :: remove_XSS($thread['thread_title']) . '</a></li>';
  6910. }
  6911. }
  6912. $return .= '</ul></div>';
  6913. }
  6914. return $return;
  6915. }
  6916. /**
  6917. * // TODO: The output encoding should be equal to the system encoding.
  6918. *
  6919. * Exports the learning path as a SCORM package. This is the main function that
  6920. * gathers the content, transforms it, writes the imsmanifest.xml file, zips the
  6921. * whole thing and returns the zip.
  6922. *
  6923. * This method needs to be called in PHP5, as it will fail with non-adequate
  6924. * XML package (like the ones for PHP4), and it is *not* a static method, so
  6925. * you need to call it on a learnpath object.
  6926. * @TODO The method might be redefined later on in the scorm class itself to avoid
  6927. * creating a SCORM structure if there is one already. However, if the initial SCORM
  6928. * path has been modified, it should use the generic method here below.
  6929. * @TODO link this function with the export_lp() function in the same class
  6930. * @param string Optional name of zip file. If none, title of learnpath is
  6931. * domesticated and trailed with ".zip"
  6932. * @return string Returns the zip package string, or null if error
  6933. */
  6934. public function scorm_export() {
  6935. global $_course;
  6936. // Remove memory and time limits as much as possible as this might be a long process...
  6937. if (function_exists('ini_set')) {
  6938. $mem = ini_get('memory_limit');
  6939. if (substr($mem, -1, 1) == 'M') {
  6940. $mem_num = substr($mem, 0, -1);
  6941. if ($mem_num < 128) {
  6942. ini_set('memory_limit', '128M');
  6943. }
  6944. } else {
  6945. ini_set('memory_limit', '128M');
  6946. }
  6947. ini_set('max_execution_time', 600);
  6948. //} else {
  6949. //error_log('Scorm export: could not change memory and time limits', 0);
  6950. }
  6951. // Create the zip handler (this will remain available throughout the method).
  6952. $archive_path = api_get_path(SYS_ARCHIVE_PATH);
  6953. $sys_course_path = api_get_path(SYS_COURSE_PATH);
  6954. $temp_dir_short = uniqid();
  6955. $temp_zip_dir = $archive_path.'/'.$temp_dir_short;
  6956. $temp_zip_file = $temp_zip_dir.'/'.md5(time()).'.zip';
  6957. $zip_folder = new PclZip($temp_zip_file);
  6958. $current_course_path = api_get_path(SYS_COURSE_PATH).api_get_course_path();
  6959. $root_path = $main_path = api_get_path(SYS_PATH);
  6960. $files_cleanup = array();
  6961. // Place to temporarily stash the zipfiles.
  6962. // create the temp dir if it doesn't exist
  6963. // or do a cleanup befor creating the zipfile.
  6964. if (!is_dir($temp_zip_dir)) {
  6965. mkdir($temp_zip_dir, api_get_permissions_for_new_directories());
  6966. } else {
  6967. // Cleanup: Check the temp dir for old files and delete them.
  6968. $handle = opendir($temp_zip_dir);
  6969. while (false !== ($file = readdir($handle))) {
  6970. if ($file != '.' && $file != '..') {
  6971. unlink("$temp_zip_dir/$file");
  6972. }
  6973. }
  6974. closedir($handle);
  6975. }
  6976. $zip_files = $zip_files_abs = $zip_files_dist = array();
  6977. if (is_dir($current_course_path.'/scorm/'.$this->path) && is_file($current_course_path.'/scorm/'.$this->path.'/imsmanifest.xml')) {
  6978. // Remove the possible . at the end of the path.
  6979. $dest_path_to_lp = substr($this->path, -1) == '.' ? substr($this->path, 0, -1) : $this->path;
  6980. $dest_path_to_scorm_folder = str_replace('//','/',$temp_zip_dir.'/scorm/'.$dest_path_to_lp);
  6981. mkdir($dest_path_to_scorm_folder, api_get_permissions_for_new_directories(), true);
  6982. $zip_files_dist = copyr($current_course_path.'/scorm/'.$this->path, $dest_path_to_scorm_folder, array('imsmanifest'), $zip_files);
  6983. }
  6984. // Build a dummy imsmanifest structure. Do not add to the zip yet (we still need it).
  6985. // This structure is developed following regulations for SCORM 1.2 packaging in the SCORM 1.2 Content
  6986. // Aggregation Model official document, secion "2.3 Content Packaging".
  6987. $xmldoc = new DOMDocument('1.0'); // We are going to build a UTF-8 encoded manifest. Later we will recode it to the desired (and supported) encoding.
  6988. $root = $xmldoc->createElement('manifest');
  6989. $root->setAttribute('identifier', 'SingleCourseManifest');
  6990. $root->setAttribute('version', '1.1');
  6991. $root->setAttribute('xmlns', 'http://www.imsproject.org/xsd/imscp_rootv1p1p2');
  6992. $root->setAttribute('xmlns:adlcp', 'http://www.adlnet.org/xsd/adlcp_rootv1p2');
  6993. $root->setAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance');
  6994. $root->setAttribute('xsi:schemaLocation', 'http://www.imsproject.org/xsd/imscp_rootv1p1p2 imscp_rootv1p1p2.xsd http://www.imsglobal.org/xsd/imsmd_rootv1p2p1 imsmd_rootv1p2p1.xsd http://www.adlnet.org/xsd/adlcp_rootv1p2 adlcp_rootv1p2.xsd');
  6995. // Build mandatory sub-root container elements.
  6996. $metadata = $xmldoc->createElement('metadata');
  6997. $md_schema = $xmldoc->createElement('schema', 'ADL SCORM');
  6998. $metadata->appendChild($md_schema);
  6999. $md_schemaversion = $xmldoc->createElement('schemaversion', '1.2');
  7000. $metadata->appendChild($md_schemaversion);
  7001. $root->appendChild($metadata);
  7002. $organizations = $xmldoc->createElement('organizations');
  7003. $resources = $xmldoc->createElement('resources');
  7004. // Build the only organization we will use in building our learnpaths.
  7005. $organizations->setAttribute('default', 'chamilo_scorm_export');
  7006. $organization = $xmldoc->createElement('organization');
  7007. $organization->setAttribute('identifier', 'chamilo_scorm_export');
  7008. // To set the title of the SCORM entity (=organization), we take the name given
  7009. // in Chamilo and convert it to HTML entities using the Chamilo charset (not the
  7010. // learning path charset) as it is the encoding that defines how it is stored
  7011. // in the database. Then we convert it to HTML entities again as the "&" character
  7012. // alone is not authorized in XML (must be &amp;).
  7013. // The title is then decoded twice when extracting (see scorm::parse_manifest).
  7014. $org_title = $xmldoc->createElement('title', api_utf8_encode($this->get_name()));
  7015. $organization->appendChild($org_title);
  7016. // For each element, add it to the imsmanifest structure, then add it to the zip.
  7017. // Always call the learnpathItem->scorm_export() method to change it to the SCORM format.
  7018. $link_updates = array();
  7019. foreach ($this->items as $index => $item) {
  7020. if (!in_array($item->type, array(TOOL_QUIZ, TOOL_FORUM, TOOL_THREAD, TOOL_LINK, TOOL_STUDENTPUBLICATION))) {
  7021. // Get included documents from this item.
  7022. if ($item->type == 'sco')
  7023. $inc_docs = $item->get_resources_from_source(null, api_get_path(SYS_COURSE_PATH).api_get_course_path().'/'.'scorm/'.$this->path.'/'.$item->get_path());
  7024. else
  7025. $inc_docs = $item->get_resources_from_source();
  7026. // Give a child element <item> to the <organization> element.
  7027. $my_item_id = $item->get_id();
  7028. $my_item = $xmldoc->createElement('item');
  7029. $my_item->setAttribute('identifier', 'ITEM_'.$my_item_id);
  7030. $my_item->setAttribute('identifierref', 'RESOURCE_'.$my_item_id);
  7031. $my_item->setAttribute('isvisible', 'true');
  7032. // Give a child element <title> to the <item> element.
  7033. $my_title = $xmldoc->createElement('title', htmlspecialchars(api_utf8_encode($item->get_title()), ENT_QUOTES, 'UTF-8'));
  7034. $my_item->appendChild($my_title);
  7035. // Give a child element <adlcp:prerequisites> to the <item> element.
  7036. $my_prereqs = $xmldoc->createElement('adlcp:prerequisites', $this->get_scorm_prereq_string($my_item_id));
  7037. $my_prereqs->setAttribute('type', 'aicc_script');
  7038. $my_item->appendChild($my_prereqs);
  7039. // Give a child element <adlcp:maxtimeallowed> to the <item> element - not yet supported.
  7040. //$xmldoc->createElement('adlcp:maxtimeallowed','');
  7041. // Give a child element <adlcp:timelimitaction> to the <item> element - not yet supported.
  7042. //$xmldoc->createElement('adlcp:timelimitaction','');
  7043. // Give a child element <adlcp:datafromlms> to the <item> element - not yet supported.
  7044. //$xmldoc->createElement('adlcp:datafromlms','');
  7045. // Give a child element <adlcp:masteryscore> to the <item> element.
  7046. $my_masteryscore = $xmldoc->createElement('adlcp:masteryscore', $item->get_mastery_score());
  7047. $my_item->appendChild($my_masteryscore);
  7048. // Attach this item to the organization element or hits parent if there is one.
  7049. if (!empty($item->parent) && $item->parent != 0) {
  7050. $children = $organization->childNodes;
  7051. $possible_parent = &$this->get_scorm_xml_node($children, 'ITEM_'.$item->parent);
  7052. if (is_object($possible_parent)) {
  7053. $possible_parent->appendChild($my_item);
  7054. } else {
  7055. if ($this->debug > 0) { error_log('Parent ITEM_'.$item->parent.' of item ITEM_'.$my_item_id.' not found'); }
  7056. }
  7057. } else {
  7058. if ($this->debug > 0) { error_log('No parent'); }
  7059. $organization->appendChild($my_item);
  7060. }
  7061. // Get the path of the file(s) from the course directory root.
  7062. $my_file_path = $item->get_file_path('scorm/'.$this->path.'/');
  7063. //$my_xml_file_path = api_htmlentities(api_utf8_encode($my_file_path), ENT_QUOTES, 'UTF-8');
  7064. $my_xml_file_path = $my_file_path;
  7065. $my_sub_dir = dirname($my_file_path);
  7066. $my_sub_dir = str_replace('\\', '/', $my_sub_dir);
  7067. //$my_xml_sub_dir = api_htmlentities(api_utf8_encode($my_sub_dir), ENT_QUOTES, 'UTF-8');
  7068. $my_xml_sub_dir = $my_sub_dir;
  7069. // Give a <resource> child to the <resources> element
  7070. $my_resource = $xmldoc->createElement('resource');
  7071. $my_resource->setAttribute('identifier', 'RESOURCE_'.$item->get_id());
  7072. $my_resource->setAttribute('type', 'webcontent');
  7073. $my_resource->setAttribute('href', $my_xml_file_path);
  7074. // adlcp:scormtype can be either 'sco' or 'asset'.
  7075. if ($item->type == 'sco') {
  7076. $my_resource->setAttribute('adlcp:scormtype', 'sco');
  7077. } else {
  7078. $my_resource->setAttribute('adlcp:scormtype', 'asset');
  7079. }
  7080. // xml:base is the base directory to find the files declared in this resource.
  7081. $my_resource->setAttribute('xml:base', '');
  7082. // Give a <file> child to the <resource> element.
  7083. $my_file = $xmldoc->createElement('file');
  7084. $my_file->setAttribute('href', $my_xml_file_path);
  7085. $my_resource->appendChild($my_file);
  7086. // Dependency to other files - not yet supported.
  7087. $i = 1;
  7088. foreach ($inc_docs as $doc_info) {
  7089. if (count($doc_info) < 1 || empty($doc_info[0])) { continue; }
  7090. $my_dep = $xmldoc->createElement('resource');
  7091. $res_id = 'RESOURCE_'.$item->get_id().'_'.$i;
  7092. $my_dep->setAttribute('identifier', $res_id);
  7093. $my_dep->setAttribute('type', 'webcontent');
  7094. $my_dep->setAttribute('adlcp:scormtype', 'asset');
  7095. $my_dep_file = $xmldoc->createElement('file');
  7096. // Check type of URL.
  7097. //error_log(__LINE__.'Now dealing with '.$doc_info[0].' of type '.$doc_info[1].'-'.$doc_info[2], 0);
  7098. if ($doc_info[1] == 'remote') {
  7099. // Remote file. Save url as is.
  7100. $my_dep_file->setAttribute('href', $doc_info[0]);
  7101. $my_dep->setAttribute('xml:base', '');
  7102. } elseif ($doc_info[1] == 'local') {
  7103. switch ($doc_info[2]) {
  7104. case 'url': // Local URL - save path as url for now, don't zip file.
  7105. $abs_path = api_get_path(SYS_PATH).str_replace(api_get_path(WEB_PATH), '', $doc_info[0]);
  7106. $current_dir = dirname($abs_path);
  7107. $current_dir = str_replace('\\', '/', $current_dir);
  7108. $file_path = realpath($abs_path);
  7109. $file_path = str_replace('\\', '/', $file_path);
  7110. $my_dep_file->setAttribute('href', $file_path);
  7111. $my_dep->setAttribute('xml:base', '');
  7112. if (strstr($file_path, $main_path) !== false) {
  7113. // The calculated real path is really inside Chamilo's root path.
  7114. // Reduce file path to what's under the DocumentRoot.
  7115. $file_path = substr($file_path, strlen($root_path) - 1);
  7116. //echo $file_path;echo '<br /><br />';
  7117. //error_log(__LINE__.'Reduced url path: '.$file_path, 0);
  7118. $zip_files_abs[] = $file_path;
  7119. $link_updates[$my_file_path][] = array('orig' => $doc_info[0], 'dest' => $file_path);
  7120. $my_dep_file->setAttribute('href', $file_path);
  7121. $my_dep->setAttribute('xml:base', '');
  7122. }
  7123. elseif (empty($file_path)) {
  7124. /*$document_root = substr(api_get_path(SYS_PATH), 0, strpos(api_get_path(SYS_PATH), api_get_path(REL_PATH)));
  7125. if (strpos($document_root, -1) == '/') {
  7126. $document_root = substr(0, -1, $document_root);
  7127. }*/
  7128. $file_path = $_SERVER['DOCUMENT_ROOT'].$abs_path;
  7129. $file_path = str_replace('//', '/', $file_path);
  7130. if (file_exists($file_path)) {
  7131. $file_path = substr($file_path, strlen($current_dir)); // We get the relative path.
  7132. $zip_files[] = $my_sub_dir.'/'.$file_path;
  7133. $link_updates[$my_file_path][] = array('orig' => $doc_info[0], 'dest' => $file_path);
  7134. $my_dep_file->setAttribute('href', $file_path);
  7135. $my_dep->setAttribute('xml:base', '');
  7136. }
  7137. }
  7138. break;
  7139. case 'abs': // Absolute path from DocumentRoot. Save file and leave path as is in the zip.
  7140. $my_dep_file->setAttribute('href', $doc_info[0]);
  7141. $my_dep->setAttribute('xml:base', '');
  7142. //$current_dir = str_replace('\\', '/', dirname($current_course_path.'/'.$item->get_file_path())).'/';
  7143. // The next lines fix a bug when using the "subdir" mode of Chamilo, whereas
  7144. // an image path would be constructed as /var/www/subdir/subdir/img/foo.bar
  7145. $abs_img_path_without_subdir = $doc_info[0];
  7146. $relp = api_get_path(REL_PATH); // The url-append config param.
  7147. $pos = strpos($abs_img_path_without_subdir, $relp);
  7148. if ($pos === 0) {
  7149. $abs_img_path_without_subdir = '/'.substr($abs_img_path_without_subdir, strlen($relp));
  7150. }
  7151. //$file_path = realpath(api_get_path(SYS_PATH).$doc_info[0]);
  7152. $file_path = realpath(api_get_path(SYS_PATH).$abs_img_path_without_subdir);
  7153. $file_path = str_replace('\\', '/', $file_path);
  7154. $file_path = str_replace('//', '/', $file_path);
  7155. //error_log(__LINE__.'Abs path: '.$file_path, 0);
  7156. // Prepare the current directory path (until just under 'document') with a trailing slash.
  7157. $cur_path = substr($current_course_path, -1) == '/' ? $current_course_path : $current_course_path.'/';
  7158. // Check if the current document is in that path.
  7159. if (strstr($file_path, $cur_path) !== false) {
  7160. // The document is in that path, now get the relative path
  7161. // to the containing document.
  7162. $orig_file_path = dirname($cur_path.$my_file_path).'/';
  7163. $orig_file_path = str_replace('\\', '/', $orig_file_path);
  7164. $relative_path = '';
  7165. if (strstr($file_path, $cur_path) !== false) {
  7166. $relative_path = substr($file_path, strlen($orig_file_path));
  7167. $file_path = substr($file_path, strlen($cur_path));
  7168. } else {
  7169. // This case is still a problem as it's difficult to calculate a relative path easily
  7170. // might still generate wrong links.
  7171. //$file_path = substr($file_path,strlen($cur_path));
  7172. // Calculate the directory path to the current file (without trailing slash).
  7173. $my_relative_path = dirname($file_path);
  7174. $my_relative_path = str_replace('\\', '/', $my_relative_path);
  7175. $my_relative_file = basename($file_path);
  7176. // Calculate the directory path to the containing file (without trailing slash).
  7177. $my_orig_file_path = substr($orig_file_path, 0, -1);
  7178. $dotdot = '';
  7179. $subdir = '';
  7180. while (strstr($my_relative_path, $my_orig_file_path) === false && (strlen($my_orig_file_path) > 1) && (strlen($my_relative_path) > 1)) {
  7181. $my_relative_path2 = dirname($my_relative_path);
  7182. $my_relative_path2 = str_replace('\\', '/', $my_relative_path2);
  7183. $my_orig_file_path = dirname($my_orig_file_path);
  7184. $my_orig_file_path = str_replace('\\', '/', $my_orig_file_path);
  7185. $subdir = substr($my_relative_path, strlen($my_relative_path2) + 1).'/'.$subdir;
  7186. $dotdot += '../';
  7187. $my_relative_path = $my_relative_path2;
  7188. }
  7189. $relative_path = $dotdot.$subdir.$my_relative_file;
  7190. }
  7191. // Put the current document in the zip (this array is the array
  7192. // that will manage documents already in the course folder - relative).
  7193. $zip_files[] = $file_path;
  7194. // Update the links to the current document in the containing document (make them relative).
  7195. $link_updates[$my_file_path][] = array('orig' => $doc_info[0], 'dest' => $relative_path);
  7196. $my_dep_file->setAttribute('href', $file_path);
  7197. $my_dep->setAttribute('xml:base', '');
  7198. }
  7199. elseif (strstr($file_path,$main_path) !== false) {
  7200. // The calculated real path is really inside Chamilo's root path.
  7201. // Reduce file path to what's under the DocumentRoot.
  7202. $file_path = substr($file_path, strlen($root_path));
  7203. //echo $file_path;echo '<br /><br />';
  7204. //error_log('Reduced path: '.$file_path, 0);
  7205. $zip_files_abs[] = $file_path;
  7206. $link_updates[$my_file_path][] = array('orig' => $doc_info[0], 'dest' => $file_path);
  7207. $my_dep_file->setAttribute('href', 'document/'.$file_path);
  7208. $my_dep->setAttribute('xml:base', '');
  7209. }
  7210. elseif (empty($file_path)) {
  7211. /*$document_root = substr(api_get_path(SYS_PATH), 0, strpos(api_get_path(SYS_PATH), api_get_path(REL_PATH)));
  7212. if(strpos($document_root,-1) == '/') {
  7213. $document_root = substr(0, -1, $document_root);
  7214. }*/
  7215. $file_path = $_SERVER['DOCUMENT_ROOT'].$doc_info[0];
  7216. $file_path = str_replace('//', '/', $file_path);
  7217. if (file_exists($file_path)) {
  7218. $file_path = substr($file_path,strlen($current_dir)); // We get the relative path.
  7219. $zip_files[] = $my_sub_dir.'/'.$file_path;
  7220. $link_updates[$my_file_path][] = array('orig' => $doc_info[0], 'dest' => $file_path);
  7221. $my_dep_file->setAttribute('href','document/'.$file_path);
  7222. $my_dep->setAttribute('xml:base', '');
  7223. }
  7224. }
  7225. break;
  7226. 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
  7227. if (substr($doc_info[0], 0, 2) == '..') {
  7228. // Relative path going up.
  7229. $current_dir = dirname($current_course_path.'/'.$item->get_file_path()).'/';
  7230. $current_dir = str_replace('\\', '/', $current_dir);
  7231. $file_path = realpath($current_dir.$doc_info[0]);
  7232. $file_path = str_replace('\\', '/', $file_path);
  7233. //error_log($file_path.' <-> '.$main_path,0);
  7234. if (strstr($file_path, $main_path) !== false) {
  7235. // The calculated real path is really inside Chamilo's root path.
  7236. // Reduce file path to what's under the DocumentRoot.
  7237. $file_path = substr($file_path, strlen($root_path));
  7238. //error_log('Reduced path: '.$file_path, 0);
  7239. $zip_files_abs[] = $file_path;
  7240. $link_updates[$my_file_path][] = array('orig' => $doc_info[0], 'dest' => $file_path);
  7241. $my_dep_file->setAttribute('href', 'document/'.$file_path);
  7242. $my_dep->setAttribute('xml:base', '');
  7243. }
  7244. } else {
  7245. $zip_files[] = $my_sub_dir.'/'.$doc_info[0];
  7246. $my_dep_file->setAttribute('href', $doc_info[0]);
  7247. $my_dep->setAttribute('xml:base', $my_xml_sub_dir);
  7248. }
  7249. break;
  7250. default:
  7251. $my_dep_file->setAttribute('href', $doc_info[0]);
  7252. $my_dep->setAttribute('xml:base', '');
  7253. break;
  7254. }
  7255. }
  7256. $my_dep->appendChild($my_dep_file);
  7257. $resources->appendChild($my_dep);
  7258. $dependency = $xmldoc->createElement('dependency');
  7259. $dependency->setAttribute('identifierref', $res_id);
  7260. $my_resource->appendChild($dependency);
  7261. $i++;
  7262. }
  7263. //$my_dependency = $xmldoc->createElement('dependency');
  7264. //$my_dependency->setAttribute('identifierref', '');
  7265. $resources->appendChild($my_resource);
  7266. $zip_files[] = $my_file_path;
  7267. //error_log('File '.$my_file_path. ' added to $zip_files', 0);
  7268. } else {
  7269. // If the item is a quiz or a link or whatever non-exportable, we include a step indicating it.
  7270. if ($item->type == TOOL_LINK) {
  7271. $my_item = $xmldoc->createElement('item');
  7272. $my_item->setAttribute('identifier', 'ITEM_'.$item->get_id());
  7273. $my_item->setAttribute('identifierref', 'RESOURCE_'.$item->get_id());
  7274. $my_item->setAttribute('isvisible', 'true');
  7275. // Give a child element <title> to the <item> element.
  7276. $my_title = $xmldoc->createElement('title', htmlspecialchars(api_utf8_encode($item->get_title()), ENT_QUOTES, 'UTF-8'));
  7277. $my_item->appendChild($my_title);
  7278. // Give a child element <adlcp:prerequisites> to the <item> element.
  7279. $my_prereqs = $xmldoc->createElement('adlcp:prerequisites', $item->get_prereq_string());
  7280. $my_prereqs->setAttribute('type', 'aicc_script');
  7281. $my_item->appendChild($my_prereqs);
  7282. // Give a child element <adlcp:maxtimeallowed> to the <item> element - not yet supported.
  7283. //$xmldoc->createElement('adlcp:maxtimeallowed', '');
  7284. // Give a child element <adlcp:timelimitaction> to the <item> element - not yet supported.
  7285. //$xmldoc->createElement('adlcp:timelimitaction', '');
  7286. // Give a child element <adlcp:datafromlms> to the <item> element - not yet supported.
  7287. //$xmldoc->createElement('adlcp:datafromlms', '');
  7288. // Give a child element <adlcp:masteryscore> to the <item> element.
  7289. $my_masteryscore = $xmldoc->createElement('adlcp:masteryscore', $item->get_mastery_score());
  7290. $my_item->appendChild($my_masteryscore);
  7291. // Attach this item to the organization element or its parent if there is one.
  7292. if (!empty($item->parent) && $item->parent != 0) {
  7293. $children = $organization->childNodes;
  7294. for ($i = 0; $i < $children->length; $i++) {
  7295. $item_temp = $children->item($i);
  7296. if ($item_temp -> nodeName == 'item') {
  7297. if ($item_temp->getAttribute('identifier') == 'ITEM_'.$item->parent) {
  7298. $item_temp -> appendChild($my_item);
  7299. }
  7300. }
  7301. }
  7302. } else {
  7303. $organization->appendChild($my_item);
  7304. }
  7305. $my_file_path = 'link_'.$item->get_id().'.html';
  7306. $sql = 'SELECT url, title FROM '.Database :: get_course_table(TABLE_LINK).' WHERE id='.$item->path;
  7307. $rs = Database::query($sql);
  7308. if ($link = Database :: fetch_array($rs)) {
  7309. $url = $link['url'];
  7310. $title = stripslashes($link['title']);
  7311. $links_to_create[$my_file_path] = array('title' => $title, 'url' => $url);
  7312. //$my_xml_file_path = api_htmlentities(api_utf8_encode($my_file_path), ENT_QUOTES, 'UTF-8');
  7313. $my_xml_file_path = $my_file_path;
  7314. $my_sub_dir = dirname($my_file_path);
  7315. $my_sub_dir = str_replace('\\', '/', $my_sub_dir);
  7316. //$my_xml_sub_dir = api_htmlentities(api_utf8_encode($my_sub_dir), ENT_QUOTES, 'UTF-8');
  7317. $my_xml_sub_dir = $my_sub_dir;
  7318. // Give a <resource> child to the <resources> element.
  7319. $my_resource = $xmldoc->createElement('resource');
  7320. $my_resource->setAttribute('identifier', 'RESOURCE_'.$item->get_id());
  7321. $my_resource->setAttribute('type', 'webcontent');
  7322. $my_resource->setAttribute('href', $my_xml_file_path);
  7323. // adlcp:scormtype can be either 'sco' or 'asset'.
  7324. $my_resource->setAttribute('adlcp:scormtype', 'asset');
  7325. // xml:base is the base directory to find the files declared in this resource.
  7326. $my_resource->setAttribute('xml:base', '');
  7327. // give a <file> child to the <resource> element.
  7328. $my_file = $xmldoc->createElement('file');
  7329. $my_file->setAttribute('href', $my_xml_file_path);
  7330. $my_resource->appendChild($my_file);
  7331. $resources->appendChild($my_resource);
  7332. }
  7333. }
  7334. elseif ($item->type == TOOL_QUIZ) {
  7335. require_once api_get_path(SYS_CODE_PATH).'exercice/exercise.class.php';
  7336. $exe_id = $item->path; // Should be using ref when everything will be cleaned up in this regard.
  7337. $exe = new Exercise();
  7338. $exe->read($exe_id);
  7339. $my_item = $xmldoc->createElement('item');
  7340. $my_item->setAttribute('identifier', 'ITEM_'.$item->get_id());
  7341. $my_item->setAttribute('identifierref', 'RESOURCE_'.$item->get_id());
  7342. $my_item->setAttribute('isvisible', 'true');
  7343. // Give a child element <title> to the <item> element.
  7344. $my_title = $xmldoc->createElement('title', htmlspecialchars(api_utf8_encode($item->get_title()), ENT_QUOTES, 'UTF-8'));
  7345. $my_item->appendChild($my_title);
  7346. $my_max_score = $xmldoc->createElement('max_score', $item->get_max());
  7347. //$my_item->appendChild($my_max_score);
  7348. // Give a child element <adlcp:prerequisites> to the <item> element.
  7349. $my_prereqs = $xmldoc->createElement('adlcp:prerequisites', $item->get_prereq_string());
  7350. $my_prereqs->setAttribute('type','aicc_script');
  7351. $my_item->appendChild($my_prereqs);
  7352. // Give a child element <adlcp:masteryscore> to the <item> element.
  7353. $my_masteryscore = $xmldoc->createElement('adlcp:masteryscore', $item->get_mastery_score());
  7354. $my_item->appendChild($my_masteryscore);
  7355. // Attach this item to the organization element or hits parent if there is one.
  7356. if (!empty($item->parent) && $item->parent != 0) {
  7357. $children = $organization->childNodes;
  7358. for ($i = 0; $i < $children->length; $i++) {
  7359. $item_temp = $children->item($i);
  7360. if ($item_temp -> nodeName == 'item') {
  7361. if ($item_temp->getAttribute('identifier') == 'ITEM_'.$item->parent) {
  7362. $item_temp -> appendChild($my_item);
  7363. }
  7364. }
  7365. }
  7366. } else {
  7367. $organization->appendChild($my_item);
  7368. }
  7369. // Include export scripts.
  7370. require_once api_get_path(SYS_CODE_PATH).'exercice/export/scorm/scorm_export.php';
  7371. // Get the path of the file(s) from the course directory root
  7372. //$my_file_path = $item->get_file_path('scorm/'.$this->path.'/');
  7373. $my_file_path = 'quiz_'.$item->get_id().'.html';
  7374. // Write the contents of the exported exercise into a (big) html file
  7375. // to later pack it into the exported SCORM. The file will be removed afterwards.
  7376. $contents = export_exercise($exe_id,true);
  7377. $tmp_file_path = $archive_path.$temp_dir_short.'/'.$my_file_path;
  7378. $res = file_put_contents($tmp_file_path, $contents);
  7379. if ($res === false) { error_log('Could not write into file '.$tmp_file_path.' '.__FILE__.' '.__LINE__, 0); }
  7380. $files_cleanup[] = $tmp_file_path;
  7381. //error_log($tmp_path); die();
  7382. //$my_xml_file_path = api_htmlentities(api_utf8_encode($my_file_path), ENT_QUOTES, 'UTF-8');
  7383. $my_xml_file_path = $my_file_path;
  7384. $my_sub_dir = dirname($my_file_path);
  7385. $my_sub_dir = str_replace('\\', '/', $my_sub_dir);
  7386. //$my_xml_sub_dir = api_htmlentities(api_utf8_encode($my_sub_dir), ENT_QUOTES, 'UTF-8');
  7387. $my_xml_sub_dir = $my_sub_dir;
  7388. // Give a <resource> child to the <resources> element.
  7389. $my_resource = $xmldoc->createElement('resource');
  7390. $my_resource->setAttribute('identifier', 'RESOURCE_'.$item->get_id());
  7391. $my_resource->setAttribute('type', 'webcontent');
  7392. $my_resource->setAttribute('href', $my_xml_file_path);
  7393. // adlcp:scormtype can be either 'sco' or 'asset'.
  7394. $my_resource->setAttribute('adlcp:scormtype', 'sco');
  7395. // xml:base is the base directory to find the files declared in this resource.
  7396. $my_resource->setAttribute('xml:base', '');
  7397. // Give a <file> child to the <resource> element.
  7398. $my_file = $xmldoc->createElement('file');
  7399. $my_file->setAttribute('href', $my_xml_file_path);
  7400. $my_resource->appendChild($my_file);
  7401. // Get included docs.
  7402. $inc_docs = $item->get_resources_from_source(null,$tmp_file_path);
  7403. // Dependency to other files - not yet supported.
  7404. $i = 1;
  7405. foreach ($inc_docs as $doc_info) {
  7406. if (count($doc_info) < 1 || empty($doc_info[0])) { continue; }
  7407. $my_dep = $xmldoc->createElement('resource');
  7408. $res_id = 'RESOURCE_'.$item->get_id().'_'.$i;
  7409. $my_dep->setAttribute('identifier', $res_id);
  7410. $my_dep->setAttribute('type', 'webcontent');
  7411. $my_dep->setAttribute('adlcp:scormtype', 'asset');
  7412. $my_dep_file = $xmldoc->createElement('file');
  7413. // Check type of URL.
  7414. //error_log(__LINE__.'Now dealing with '.$doc_info[0].' of type '.$doc_info[1].'-'.$doc_info[2], 0);
  7415. if ($doc_info[1] == 'remote') {
  7416. // Remote file. Save url as is.
  7417. $my_dep_file->setAttribute('href', $doc_info[0]);
  7418. $my_dep->setAttribute('xml:base', '');
  7419. } elseif ($doc_info[1] == 'local') {
  7420. switch ($doc_info[2]) {
  7421. case 'url': // Local URL - save path as url for now, don't zip file.
  7422. // Save file but as local file (retrieve from URL).
  7423. $abs_path = api_get_path(SYS_PATH).str_replace(api_get_path(WEB_PATH), '', $doc_info[0]);
  7424. $current_dir = dirname($abs_path);
  7425. $current_dir = str_replace('\\', '/', $current_dir);
  7426. $file_path = realpath($abs_path);
  7427. $file_path = str_replace('\\', '/', $file_path);
  7428. $my_dep_file->setAttribute('href', 'document/'.$file_path);
  7429. $my_dep->setAttribute('xml:base', '');
  7430. if (strstr($file_path, $main_path) !== false) {
  7431. // The calculated real path is really inside the chamilo root path.
  7432. // Reduce file path to what's under the DocumentRoot.
  7433. $file_path = substr($file_path, strlen($root_path));
  7434. //echo $file_path;echo '<br /><br />';
  7435. //error_log('Reduced path: '.$file_path, 0);
  7436. $zip_files_abs[] = $file_path;
  7437. $link_updates[$my_file_path][] = array('orig' => $doc_info[0], 'dest' => 'document/'.$file_path);
  7438. $my_dep_file->setAttribute('href', 'document/'.$file_path);
  7439. $my_dep->setAttribute('xml:base', '');
  7440. }
  7441. elseif (empty($file_path)) {
  7442. /*$document_root = substr(api_get_path(SYS_PATH), 0, strpos(api_get_path(SYS_PATH),api_get_path(REL_PATH)));
  7443. if (strpos($document_root,-1) == '/') {
  7444. $document_root = substr(0, -1, $document_root);
  7445. }*/
  7446. $file_path = $_SERVER['DOCUMENT_ROOT'].$abs_path;
  7447. $file_path = str_replace('//', '/', $file_path);
  7448. if (file_exists($file_path)) {
  7449. $file_path = substr($file_path, strlen($current_dir)); // We get the relative path.
  7450. $zip_files[] = $my_sub_dir.'/'.$file_path;
  7451. $link_updates[$my_file_path][] = array('orig' => $doc_info[0], 'dest' => 'document/'.$file_path);
  7452. $my_dep_file->setAttribute('href', 'document/'.$file_path);
  7453. $my_dep->setAttribute('xml:base', '');
  7454. }
  7455. }
  7456. break;
  7457. case 'abs': // Absolute path from DocumentRoot. Save file and leave path as is in the zip.
  7458. $current_dir = dirname($current_course_path.'/'.$item->get_file_path()).'/';
  7459. $current_dir = str_replace('\\', '/', $current_dir);
  7460. $file_path = realpath($doc_info[0]);
  7461. $file_path = str_replace('\\', '/', $file_path);
  7462. $my_dep_file->setAttribute('href', $file_path);
  7463. $my_dep->setAttribute('xml:base', '');
  7464. if (strstr($file_path,$main_path) !== false) {
  7465. // The calculated real path is really inside the chamilo root path.
  7466. // Reduce file path to what's under the DocumentRoot.
  7467. $file_path = substr($file_path, strlen($root_path));
  7468. //echo $file_path;echo '<br /><br />';
  7469. //error_log('Reduced path: '.$file_path, 0);
  7470. $zip_files_abs[] = $file_path;
  7471. $link_updates[$my_file_path][] = array('orig' => $doc_info[0], 'dest' => $file_path);
  7472. $my_dep_file->setAttribute('href', 'document/'.$file_path);
  7473. $my_dep->setAttribute('xml:base', '');
  7474. }
  7475. elseif (empty($file_path)) {
  7476. /*$document_root = substr(api_get_path(SYS_PATH), 0, strpos(api_get_path(SYS_PATH), api_get_path(REL_PATH)));
  7477. if (strpos($document_root,-1) == '/') {
  7478. $document_root = substr(0, -1, $document_root);
  7479. }*/
  7480. $file_path = $_SERVER['DOCUMENT_ROOT'].$doc_info[0];
  7481. $file_path = str_replace('//', '/', $file_path);
  7482. if (file_exists($file_path)) {
  7483. $file_path = substr($file_path,strlen($current_dir)); // We get the relative path.
  7484. $zip_files[] = $my_sub_dir.'/'.$file_path;
  7485. $link_updates[$my_file_path][] = array('orig' => $doc_info[0], 'dest' => $file_path);
  7486. $my_dep_file->setAttribute('href', 'document/'.$file_path);
  7487. $my_dep->setAttribute('xml:base', '');
  7488. }
  7489. }
  7490. break;
  7491. 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
  7492. if (substr($doc_info[0], 0, 2) == '..') {
  7493. // Relative path going up.
  7494. $current_dir = dirname($current_course_path.'/'.$item->get_file_path()).'/';
  7495. $current_dir = str_replace('\\', '/', $current_dir);
  7496. $file_path = realpath($current_dir.$doc_info[0]);
  7497. $file_path = str_replace('\\', '/', $file_path);
  7498. //error_log($file_path.' <-> '.$main_path, 0);
  7499. if (strstr($file_path, $main_path) !== false) {
  7500. // The calculated real path is really inside Chamilo's root path.
  7501. // Reduce file path to what's under the DocumentRoot.
  7502. $file_path = substr($file_path, strlen($root_path));
  7503. $file_path_dest = $file_path;
  7504. // File path is courses/CHAMILO/document/....
  7505. $info_file_path = explode('/', $file_path);
  7506. if ($info_file_path[0] == 'courses') { // Add character "/" in file path.
  7507. $file_path_dest = 'document/'.$file_path;
  7508. }
  7509. //error_log('Reduced path: '.$file_path, 0);
  7510. $zip_files_abs[] = $file_path;
  7511. $link_updates[$my_file_path][] = array('orig' => $doc_info[0], 'dest' => $file_path_dest);
  7512. $my_dep_file->setAttribute('href', 'document/'.$file_path);
  7513. $my_dep->setAttribute('xml:base', '');
  7514. }
  7515. } else {
  7516. $zip_files[] = $my_sub_dir.'/'.$doc_info[0];
  7517. $my_dep_file->setAttribute('href', $doc_info[0]);
  7518. $my_dep->setAttribute('xml:base', $my_xml_sub_dir);
  7519. }
  7520. break;
  7521. default:
  7522. $my_dep_file->setAttribute('href', $doc_info[0]); // ../../courses/
  7523. $my_dep->setAttribute('xml:base', '');
  7524. break;
  7525. }
  7526. }
  7527. $my_dep->appendChild($my_dep_file);
  7528. $resources->appendChild($my_dep);
  7529. $dependency = $xmldoc->createElement('dependency');
  7530. $dependency->setAttribute('identifierref', $res_id);
  7531. $my_resource->appendChild($dependency);
  7532. $i++;
  7533. }
  7534. $resources->appendChild($my_resource);
  7535. $zip_files[] = $my_file_path;
  7536. } else {
  7537. // Get the path of the file(s) from the course directory root
  7538. $my_file_path = 'non_exportable.html';
  7539. //$my_xml_file_path = api_htmlentities(api_utf8_encode($my_file_path), ENT_COMPAT, 'UTF-8');
  7540. $my_xml_file_path = $my_file_path;
  7541. $my_sub_dir = dirname($my_file_path);
  7542. $my_sub_dir = str_replace('\\', '/', $my_sub_dir);
  7543. //$my_xml_sub_dir = api_htmlentities(api_utf8_encode($my_sub_dir), ENT_COMPAT, 'UTF-8');
  7544. $my_xml_sub_dir = $my_sub_dir;
  7545. // Give a <resource> child to the <resources> element.
  7546. $my_resource = $xmldoc->createElement('resource');
  7547. $my_resource->setAttribute('identifier', 'RESOURCE_'.$item->get_id());
  7548. $my_resource->setAttribute('type', 'webcontent');
  7549. $my_resource->setAttribute('href', 'document/'.$my_xml_file_path);
  7550. // adlcp:scormtype can be either 'sco' or 'asset'.
  7551. $my_resource->setAttribute('adlcp:scormtype', 'asset');
  7552. // xml:base is the base directory to find the files declared in this resource.
  7553. $my_resource->setAttribute('xml:base', '');
  7554. // Give a <file> child to the <resource> element.
  7555. $my_file = $xmldoc->createElement('file');
  7556. $my_file->setAttribute('href', 'document/'.$my_xml_file_path);
  7557. $my_resource->appendChild($my_file);
  7558. $resources->appendChild($my_resource);
  7559. }
  7560. }
  7561. }
  7562. $organizations->appendChild($organization);
  7563. $root->appendChild($organizations);
  7564. $root->appendChild($resources);
  7565. $xmldoc->appendChild($root);
  7566. // TODO: Add a readme file here, with a short description and a link to the Reload player
  7567. // then add the file to the zip, then destroy the file (this is done automatically).
  7568. // http://www.reload.ac.uk/scormplayer.html - once done, don't forget to close FS#138
  7569. //error_log(print_r($zip_files,true), 0);
  7570. foreach ($zip_files as $file_path) {
  7571. if (empty($file_path)) { continue; }
  7572. //error_log(__LINE__.'getting document from '.$sys_course_path.$_course['path'].'/'.$file_path.' removing '.$sys_course_path.$_course['path'].'/',0);
  7573. $dest_file = $archive_path.$temp_dir_short.'/'.$file_path;
  7574. $this->create_path($dest_file);
  7575. //error_log('copy '.api_get_path(SYS_COURSE_PATH).$_course['path'].'/'.$file_path.' to '.api_get_path(SYS_ARCHIVE_PATH).$temp_dir_short.'/'.$file_path,0);
  7576. //echo $main_path.$file_path.'<br />';
  7577. @copy($sys_course_path.$_course['path'].'/'.$file_path, $dest_file);
  7578. // Check if the file needs a link update.
  7579. if (in_array($file_path, array_keys($link_updates))) {
  7580. $string = file_get_contents($dest_file);
  7581. unlink($dest_file);
  7582. foreach ($link_updates[$file_path] as $old_new) {
  7583. //error_log('Replacing '.$old_new['orig'].' by '.$old_new['dest'].' in '.$file_path, 0);
  7584. // This is an ugly hack that allows .flv files to be found by the flv player that
  7585. // will be added in document/main/inc/lib/flv_player/flv_player.swf and that needs
  7586. // to find the flv to play in document/main/, so we replace main/ in the flv path by
  7587. // ../../.. to return from inc/lib/flv_player to the document/main path.
  7588. if (substr($old_new['dest'], -3) == 'flv' && substr($old_new['dest'], 0, 5) == 'main/') {
  7589. $old_new['dest'] = str_replace('main/', '../../../', $old_new['dest']);
  7590. }
  7591. elseif (substr($old_new['dest'], -3) == 'flv' && substr($old_new['dest'], 0, 6) == 'video/') {
  7592. $old_new['dest'] = str_replace('video/', '../../../../video/', $old_new['dest']);
  7593. }
  7594. $string = str_replace($old_new['orig'], $old_new['dest'], $string);
  7595. }
  7596. file_put_contents($dest_file, $string);
  7597. }
  7598. }
  7599. foreach ($zip_files_abs as $file_path) {
  7600. if (empty($file_path)) { continue; }
  7601. //error_log(__LINE__.'checking existence of '.$main_path.$file_path.'', 0);
  7602. if (!is_file($main_path.$file_path) || !is_readable($main_path.$file_path)) { continue; }
  7603. //error_log(__LINE__.'getting document from '.$main_path.$file_path.' removing '.api_get_path(SYS_COURSE_PATH).$_course['path'].'/', 0);
  7604. $dest_file = $archive_path.$temp_dir_short.'/document/'.$file_path;
  7605. $this->create_path($dest_file);
  7606. //error_log('Created path '.api_get_path(SYS_ARCHIVE_PATH).$temp_dir_short.'/document/'.$file_path, 0);
  7607. //error_log('copy '.api_get_path(SYS_COURSE_PATH).$_course['path'].'/'.$file_path.' to '.api_get_path(SYS_ARCHIVE_PATH).$temp_dir_short.'/'.$file_path, 0);
  7608. //echo $main_path.$file_path.' - '.$dest_file.'<br />';
  7609. copy($main_path.$file_path, $dest_file);
  7610. // Check if the file needs a link update.
  7611. if (in_array($file_path, array_keys($link_updates))) {
  7612. $string = file_get_contents($dest_file);
  7613. unlink($dest_file);
  7614. foreach ($link_updates[$file_path] as $old_new) {
  7615. //error_log('Replacing '.$old_new['orig'].' by '.$old_new['dest'].' in '.$file_path, 0);
  7616. // This is an ugly hack that allows .flv files to be found by the flv player that
  7617. // will be added in document/main/inc/lib/flv_player/flv_player.swf and that needs
  7618. // to find the flv to play in document/main/, so we replace main/ in the flv path by
  7619. // ../../.. to return from inc/lib/flv_player to the document/main path.
  7620. if (substr($old_new['dest'], -3) == 'flv' && substr($old_new['dest'], 0, 5) == 'main/') {
  7621. $old_new['dest'] = str_replace('main/', '../../../', $old_new['dest']);
  7622. }
  7623. $string = str_replace($old_new['orig'], $old_new['dest'], $string);
  7624. }
  7625. file_put_contents($dest_file, $string);
  7626. }
  7627. }
  7628. if (is_array($links_to_create)) {
  7629. foreach ($links_to_create as $file => $link) {
  7630. $file_content = '<!DOCTYPE html
  7631. PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  7632. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  7633. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="'.api_get_language_isocode().'" lang="'.api_get_language_isocode().'">
  7634. <head>
  7635. <title>'.$link['title'].'</title>
  7636. <meta http-equiv="Content-Type" content="text/html; charset='.api_get_system_encoding().'" />
  7637. </head>
  7638. <body dir="'.api_get_text_direction().'">
  7639. <div style="text-align:center"><a href="'.$link['url'].'">'.$link['title'].'</a></div>
  7640. </body>
  7641. </html>';
  7642. file_put_contents($archive_path.$temp_dir_short.'/'.$file, $file_content);
  7643. }
  7644. }
  7645. // Add non exportable message explanation.
  7646. $lang_not_exportable = get_lang('ThisItemIsNotExportable');
  7647. $file_content = '<!DOCTYPE html
  7648. PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  7649. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  7650. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="'.api_get_language_isocode().'" lang="'.api_get_language_isocode().'">
  7651. <head>
  7652. <title>'.$lang_not_exportable.'</title>
  7653. <meta http-equiv="Content-Type" content="text/html; charset='.api_get_system_encoding().'" />
  7654. </head>
  7655. <body dir="'.api_get_text_direction().'">
  7656. ';
  7657. $file_content .=
  7658. <<<EOD
  7659. <style>
  7660. .error-message {
  7661. font-family: arial, verdana, helvetica, sans-serif;
  7662. border-width: 1px;
  7663. border-style: solid;
  7664. left: 50%;
  7665. margin: 10px auto;
  7666. min-height: 30px;
  7667. padding: 5px;
  7668. right: 50%;
  7669. width: 500px;
  7670. background-color: #FFD1D1;
  7671. border-color: #FF0000;
  7672. color: #000;
  7673. }
  7674. </style>
  7675. <body>
  7676. <div class="error-message">
  7677. $lang_not_exportable
  7678. </div>
  7679. </body>
  7680. </html>
  7681. EOD;
  7682. if (!is_dir($archive_path.$temp_dir_short.'/document')) {
  7683. @mkdir($archive_path.$temp_dir_short.'/document', api_get_permissions_for_new_directories());
  7684. }
  7685. file_put_contents($archive_path.$temp_dir_short.'/document/non_exportable.html', $file_content);
  7686. // Add the extra files that go along with a SCORM package.
  7687. $main_code_path = api_get_path(SYS_CODE_PATH).'newscorm/packaging/';
  7688. $extra_files = scandir($main_code_path);
  7689. foreach ($extra_files as $extra_file) {
  7690. if (strpos($extra_file, '.') === 0)
  7691. continue;
  7692. else {
  7693. $dest_file = $archive_path . $temp_dir_short . '/' . $extra_file;
  7694. $this->create_path($dest_file);
  7695. copy($main_code_path.$extra_file, $dest_file);
  7696. }
  7697. }
  7698. // Finalize the imsmanifest structure, add to the zip, then return the zip.
  7699. $manifest = @$xmldoc->saveXML();
  7700. $manifest = api_utf8_decode_xml($manifest); // The manifest gets the system encoding now.
  7701. file_put_contents($archive_path.'/'.$temp_dir_short.'/imsmanifest.xml', $manifest);
  7702. $zip_folder->add($archive_path.'/'.$temp_dir_short, PCLZIP_OPT_REMOVE_PATH, $archive_path.'/'.$temp_dir_short.'/');
  7703. // Clean possible temporary files.
  7704. foreach ($files_cleanup as $file) {
  7705. $res = unlink($file);
  7706. if ($res === false) { error_log('Could not delete temp file '.$file.' '.__FILE__.' '.__LINE__, 0); }
  7707. }
  7708. // Send file to client.
  7709. //$name = 'scorm_export_'.$this->lp_id.'.zip';
  7710. require_once api_get_path(LIBRARY_PATH).'fileUpload.lib.php';
  7711. $name = replace_dangerous_char($this->get_name()).'.zip';
  7712. DocumentManager::file_send_for_download($temp_zip_file, true, $name);
  7713. }
  7714. public function scorm_export_to_pdf($lp_id) {
  7715. $lp_id = intval($lp_id);
  7716. $files_to_export = array();
  7717. $course_data = api_get_course_info($this->cc);
  7718. if (!empty($course_data)) {
  7719. $scorm_path = api_get_path(SYS_COURSE_PATH).$course_data['path'].'/scorm/'.$this->path;
  7720. require_once api_get_path(LIBRARY_PATH).'document.lib.php';
  7721. $list = $this->get_flat_ordered_items_list($lp_id);
  7722. foreach($list as $item_id) {
  7723. $item = $this->items[$item_id];
  7724. //Getting documents from a LP with chamilo documents
  7725. switch ($item->type) {
  7726. case 'document':
  7727. $file_data = DocumentManager::get_document_data_by_id($item->path, $this->cc);
  7728. $file_path = api_get_path(SYS_COURSE_PATH).$course_data['path'].'/document'.$file_data['path'];
  7729. if (file_exists($file_path)) {
  7730. $files_to_export[] = array('title'=>$item->get_title(),'path'=>$file_path);
  7731. }
  7732. break;
  7733. case 'sco':
  7734. $file_path = $scorm_path.'/'.$item->path;
  7735. if (file_exists($file_path)) {
  7736. $files_to_export[] = array('title'=>$item->get_title(),'path'=>$file_path);
  7737. }
  7738. break;
  7739. case 'dokeos_chapter':
  7740. case 'dir':
  7741. case 'chapter':
  7742. $files_to_export[] = array('title'=>$item->get_title(),'path'=>null);
  7743. break;
  7744. }
  7745. }
  7746. require_once api_get_path(LIBRARY_PATH).'pdf.lib.php';
  7747. $pdf = new PDF();
  7748. $result = $pdf->html_to_pdf($files_to_export, $this->name, $this->cc, true);
  7749. return $result;
  7750. }
  7751. return false;
  7752. }
  7753. /**
  7754. * Temp function to be moved in main_api or the best place around for this. Creates a file path
  7755. * if it doesn't exist
  7756. */
  7757. public function create_path($path) {
  7758. $path_bits = split('/', dirname($path));
  7759. // IS_WINDOWS_OS has been defined in main_api.lib.php
  7760. $path_built = IS_WINDOWS_OS ? '' : '/';
  7761. foreach ($path_bits as $bit) {
  7762. if (!empty ($bit)) {
  7763. $new_path = $path_built . $bit;
  7764. if (is_dir($new_path)) {
  7765. $path_built = $new_path . '/';
  7766. } else {
  7767. mkdir($new_path, api_get_permissions_for_new_directories());
  7768. $path_built = $new_path . '/';
  7769. }
  7770. }
  7771. }
  7772. }
  7773. /**
  7774. * Delete the image relative to this learning path. No parameter. Only works on instanciated object.
  7775. * @return boolean The results of the unlink function, or false if there was no image to start with
  7776. */
  7777. public function delete_lp_image() {
  7778. $img = $this->get_preview_image();
  7779. if ($img != '') {
  7780. $del_file = api_get_path(SYS_COURSE_PATH) . api_get_course_path() . '/upload/learning_path/images/' . $img;
  7781. $this->set_preview_image('');
  7782. return @ unlink($del_file);
  7783. } else {
  7784. return false;
  7785. }
  7786. }
  7787. /**
  7788. * Uploads an author image to the upload/learning_path/images directory
  7789. * @param array The image array, coming from the $_FILES superglobal
  7790. * @return boolean True on success, false on error
  7791. */
  7792. public function upload_image($image_array) {
  7793. $image_moved = false;
  7794. if (!empty ($image_array['name'])) {
  7795. $upload_ok = process_uploaded_file($image_array);
  7796. $has_attachment = true;
  7797. } else {
  7798. $image_moved = true;
  7799. }
  7800. if ($upload_ok) {
  7801. if ($has_attachment) {
  7802. $courseDir = api_get_course_path() . '/upload/learning_path/images';
  7803. $sys_course_path = api_get_path(SYS_COURSE_PATH);
  7804. $updir = $sys_course_path . $courseDir;
  7805. // Try to add an extension to the file if it hasn't one.
  7806. $new_file_name = add_ext_on_mime(stripslashes($image_array['name']), $image_array['type']);
  7807. if (!filter_extension($new_file_name)) {
  7808. //Display :: display_error_message(get_lang('UplUnableToSaveFileFilteredExtension'));
  7809. $image_moved = false;
  7810. } else {
  7811. $file_extension = explode('.', $image_array['name']);
  7812. $file_extension = strtolower($file_extension[sizeof($file_extension) - 1]);
  7813. $new_file_name = uniqid('') . '.' . $file_extension;
  7814. $new_path = $updir . '/' . $new_file_name;
  7815. // Resize the image.
  7816. $temp = new Image($image_array['tmp_name']);
  7817. $picture_infos = $temp->get_image_info();
  7818. if ($picture_infos['width'] > 104) {
  7819. $thumbwidth = 104;
  7820. } else {
  7821. $thumbwidth = $picture_infos['width'];
  7822. }
  7823. if ($picture_infos['height'] > 96) {
  7824. $new_height = 96;
  7825. } else {
  7826. $new_height = $picture_infos['height'];
  7827. }
  7828. $temp->resize($thumbwidth, $new_height, 0);
  7829. $result = $temp->send_image($new_path);
  7830. // Storing the image filename.
  7831. if ($result) {
  7832. $image_moved = true;
  7833. $this->set_preview_image($new_file_name);
  7834. return true;
  7835. }
  7836. }
  7837. }
  7838. }
  7839. return false;
  7840. }
  7841. public function set_autolunch($lp_id, $status) {
  7842. $lp_id = intval($lp_id);
  7843. $status = intval($status);
  7844. $lp_table = Database::get_course_table(TABLE_LP_MAIN);
  7845. //Setting everything to autolunch = 0
  7846. $attributes['autolunch'] = 0;
  7847. $where = array('session_id = ? '=> api_get_session_id());
  7848. Database::update($lp_table, $attributes,$where);
  7849. if ($status == 1) {
  7850. //Setting my lp_id to autolunch = 1
  7851. $attributes['autolunch'] = 1;
  7852. $where = array('id = ? AND session_id = ? '=> array($lp_id, api_get_session_id()));
  7853. Database::update($lp_table, $attributes, $where );
  7854. }
  7855. }
  7856. /**
  7857. * Gets previous_item_id for the next element of the lp_item table
  7858. * @author Isaac flores paz
  7859. * @return integer Previous item ID
  7860. */
  7861. function select_previous_item_id() {
  7862. if ($this->debug > 0) {
  7863. error_log('New LP - In learnpath::select_previous_item_id()', 0);
  7864. }
  7865. $table_lp_item = Database::get_course_table(TABLE_LP_ITEM);
  7866. // Get the max order of the items
  7867. $sql_max_order = "SELECT max(display_order) AS display_order FROM $table_lp_item WHERE lp_id = '" . $this->lp_id . "'";
  7868. $rs_max_order = Database::query($sql_max_order);
  7869. $row_max_order = Database::fetch_object($rs_max_order);
  7870. $max_order = $row_max_order->display_order;
  7871. // Get the previous item ID
  7872. $sql_max = "SELECT id as previous FROM $table_lp_item WHERE lp_id = '" . $this->lp_id . "' AND display_order = '".$max_order."' ";
  7873. $rs_max = Database::query($sql_max, __FILE__, __LINE__);
  7874. $row_max = Database::fetch_object($rs_max);
  7875. // Return the previous item ID
  7876. return $row_max->previous;
  7877. }
  7878. }
  7879. if (!function_exists('trim_value')) {
  7880. function trim_value(& $value) {
  7881. $value = trim($value);
  7882. }
  7883. }