learnpath.class.php 332 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979
  1. <?php
  2. /* For licensing terms, see /dokeos_license.txt */
  3. /**
  4. * This (abstract?) class defines the parent attributes and methods for the dokeos learnpaths and scorm
  5. * learnpaths. It is used by the scorm class as well as the dokeos_lp class.
  6. * @package dokeos.learnpath
  7. * @author Yannick Warnier <ywarnier@beeznest.org>
  8. * @license GNU/GPL - See Dokeos license directory for details
  9. */
  10. /**
  11. * Defines the learnpath parent class
  12. * @package dokeos.learnpath
  13. */
  14. class learnpath {
  15. var $attempt = 0; //the number for the current ID view
  16. var $cc; //course (code) this learnpath is located in
  17. var $current; //id of the current item the user is viewing
  18. var $current_score; //the score of the current item
  19. var $current_time_start; //the time the user loaded this resource (this does not mean he can see it yet)
  20. var $current_time_stop; //the time the user closed this resource
  21. var $default_status = 'not attempted';
  22. var $encoding = 'UTF-8';
  23. var $error = '';
  24. var $extra_information = ''; //this string can be used by proprietary SCORM contents to store data about the current learnpath
  25. var $force_commit = false; //for SCORM only - if set to true, will send a scorm LMSCommit() request on each LMSSetValue()
  26. var $index; //the index of the active learnpath_item in $ordered_items array
  27. var $items = array();
  28. var $last; //item_id of last item viewed in the learning path
  29. var $last_item_seen = 0; //in case we have already come in this learnpath, reuse the last item seen if authorized
  30. var $license; //which license this course has been given - not used yet on 20060522
  31. var $lp_id; //DB ID for this learnpath
  32. var $lp_view_id; //DB ID for lp_view
  33. var $log_file; //file where to log learnpath API msg
  34. var $maker; //which maker has conceived the content (ENI, Articulate, ...)
  35. var $message = '';
  36. var $mode = 'embedded'; //holds the video display mode (fullscreen or embedded)
  37. var $name; //learnpath name (they generally have one)
  38. var $ordered_items = array(); //list of the learnpath items in the order they are to be read
  39. var $path = ''; //path inside the scorm directory (if scorm)
  40. var $theme; // the current theme of the learning path
  41. var $preview_image; // the current image of the learning path
  42. // Tells if all the items of the learnpath can be tried again. Defaults to "no" (=1)
  43. var $prevent_reinit = 1;
  44. // Describes the mode of progress bar display
  45. var $progress_bar_mode = '%';
  46. // Percentage progress as saved in the db
  47. var $progress_db = '0';
  48. var $proximity; //wether the content is distant or local or unknown
  49. var $refs_list = array (); //list of items by ref => db_id. Used only for prerequisites match.
  50. //!!!This array (refs_list) is built differently depending on the nature of the LP.
  51. //If SCORM, uses ref, if Dokeos, uses id to keep a unique value
  52. var $type; //type of learnpath. Could be 'dokeos', 'scorm', 'scorm2004', 'aicc', ...
  53. //TODO check if this type variable is useful here (instead of just in the controller script)
  54. var $user_id; //ID of the user that is viewing/using the course
  55. var $update_queue = array();
  56. var $scorm_debug = 0;
  57. var $arrMenu = array(); //array for the menu items
  58. var $debug = 0; //logging level
  59. var $lp_session_id =0;
  60. /**
  61. * Class constructor. Needs a database handler, a course code and a learnpath id from the database.
  62. * Also builds the list of items into $this->items.
  63. * @param string Course code
  64. * @param integer Learnpath ID
  65. * @param integer User ID
  66. * @return boolean True on success, false on error
  67. */
  68. function learnpath($course, $lp_id, $user_id) {
  69. //check params
  70. //check course code
  71. if($this->debug>0){error_log('New LP - In learnpath::learnpath('.$course.','.$lp_id.','.$user_id.')',0);}
  72. if(empty($course)){
  73. $this->error = 'Course code is empty';
  74. return false;
  75. }
  76. else
  77. {
  78. $main_table = Database::get_main_table(TABLE_MAIN_COURSE);
  79. //$course = Database::escape_string($course);
  80. $course = $this->escape_string($course);
  81. $sql = "SELECT * FROM $main_table WHERE code = '$course'";
  82. if($this->debug>2){error_log('New LP - learnpath::learnpath() '.__LINE__.' - Querying course: '.$sql,0);}
  83. //$res = Database::query($sql);
  84. $res = Database::query($sql, __FILE__, __LINE__);
  85. if(Database::num_rows($res)>0)
  86. {
  87. $this->cc = $course;
  88. }
  89. else
  90. {
  91. $this->error = 'Course code does not exist in database ('.$sql.')';
  92. return false;
  93. }
  94. }
  95. //check learnpath ID
  96. if(empty($lp_id))
  97. {
  98. $this->error = 'Learnpath ID is empty';
  99. return false;
  100. }
  101. else
  102. {
  103. //TODO make it flexible to use any course_code (still using env course code here)
  104. $lp_table = Database::get_course_table(TABLE_LP_MAIN);
  105. //$id = Database::escape_integer($id);
  106. $lp_id = $this->escape_string($lp_id);
  107. $sql = "SELECT * FROM $lp_table WHERE id = '$lp_id'";
  108. if($this->debug>2){error_log('New LP - learnpath::learnpath() '.__LINE__.' - Querying lp: '.$sql,0);}
  109. //$res = Database::query($sql);
  110. $res = Database::query($sql, __FILE__, __LINE__);
  111. if(Database::num_rows($res)>0)
  112. {
  113. $this->lp_id = $lp_id;
  114. $row = Database::fetch_array($res);
  115. $this->type = $row['lp_type'];
  116. $this->name = stripslashes($row['name']);
  117. $this->encoding = $row['default_encoding'];
  118. $this->proximity = $row['content_local'];
  119. $this->theme = $row['theme'];
  120. $this->maker = $row['content_maker'];
  121. $this->prevent_reinit = $row['prevent_reinit'];
  122. $this->license = $row['content_license'];
  123. $this->scorm_debug = $row['debug'];
  124. $this->js_lib = $row['js_lib'];
  125. $this->path = $row['path'];
  126. $this->preview_image= $row['preview_image'];
  127. $this->author= $row['author'];
  128. $this->lp_session_id = $row['session_id'];
  129. if($this->type == 2){
  130. if($row['force_commit'] == 1){
  131. $this->force_commit = true;
  132. }
  133. }
  134. $this->mode = $row['default_view_mod'];
  135. }
  136. else
  137. {
  138. $this->error = 'Learnpath ID does not exist in database ('.$sql.')';
  139. return false;
  140. }
  141. }
  142. //check user ID
  143. if(empty($user_id)){
  144. $this->error = 'User ID is empty';
  145. return false;
  146. }
  147. else
  148. {
  149. //$main_table = Database::get_main_user_table();
  150. $main_table = Database::get_main_table(TABLE_MAIN_USER);
  151. //$user_id = Database::escape_integer($user_id);
  152. $user_id = $this->escape_string($user_id);
  153. $sql = "SELECT * FROM $main_table WHERE user_id = '$user_id'";
  154. if($this->debug>2){error_log('New LP - learnpath::learnpath() '.__LINE__.' - Querying user: '.$sql,0);}
  155. //$res = Database::query($sql);
  156. $res = Database::query($sql, __FILE__, __LINE__);
  157. if(Database::num_rows($res)>0)
  158. {
  159. $this->user_id = $user_id;
  160. }
  161. else
  162. {
  163. $this->error = 'User ID does not exist in database ('.$sql.')';
  164. return false;
  165. }
  166. }
  167. //end of variables checking
  168. //now get the latest attempt from this user on this LP, if available, otherwise create a new one
  169. $lp_table = Database::get_course_table(TABLE_LP_VIEW);
  170. //selecting by view_count descending allows to get the highest view_count first
  171. $sql = "SELECT * FROM $lp_table WHERE lp_id = '$lp_id' AND user_id = '$user_id' ORDER BY view_count DESC";
  172. if ($this->debug > 2) {
  173. error_log('New LP - learnpath::learnpath() ' . __LINE__ . ' - querying lp_view: ' . $sql, 0);
  174. }
  175. //$res = Database::query($sql);
  176. $res = Database::query($sql, __FILE__, __LINE__);
  177. $view_id = 0; //used later to query lp_item_view
  178. if (Database :: num_rows($res) > 0) {
  179. if ($this->debug > 2) {
  180. error_log('New LP - learnpath::learnpath() ' . __LINE__ . ' - Found previous view', 0);
  181. }
  182. $row = Database :: fetch_array($res);
  183. $this->attempt = $row['view_count'];
  184. $this->lp_view_id = $row['id'];
  185. $this->last_item_seen = $row['last_item'];
  186. $this->progress_db = $row['progress'];
  187. } else {
  188. if ($this->debug > 2) {
  189. error_log('New LP - learnpath::learnpath() ' . __LINE__ . ' - NOT Found previous view', 0);
  190. }
  191. $this->attempt = 1;
  192. $sql_ins = "INSERT INTO $lp_table (lp_id,user_id,view_count) VALUES ($lp_id,$user_id,1)";
  193. $res_ins = Database::query($sql_ins, __FILE__, __LINE__);
  194. $this->lp_view_id = Database :: insert_id();
  195. if ($this->debug > 2) {
  196. error_log('New LP - learnpath::learnpath() ' . __LINE__ . ' - inserting new lp_view: ' . $sql_ins, 0);
  197. }
  198. }
  199. //initialise items
  200. $lp_item_table = Database::get_course_table(TABLE_LP_ITEM);
  201. $sql = "SELECT * FROM $lp_item_table WHERE lp_id = '".$this->lp_id."' ORDER BY parent_item_id, display_order";
  202. $res = Database::query($sql, __FILE__, __LINE__);
  203. while($row = Database::fetch_array($res))
  204. {
  205. $oItem = '';
  206. //$this->ordered_items[] = $row['id'];
  207. switch ($this->type) {
  208. case 3 : //aicc
  209. $oItem = new aiccItem('db', $row['id']);
  210. if (is_object($oItem)) {
  211. $my_item_id = $oItem->get_id();
  212. $oItem->set_lp_view($this->lp_view_id);
  213. $oItem->set_prevent_reinit($this->prevent_reinit);
  214. // Don't use reference here as the next loop will make the pointed object change
  215. $this->items[$my_item_id] = $oItem;
  216. $this->refs_list[$oItem->ref] = $my_item_id;
  217. if ($this->debug > 2) {
  218. error_log('New LP - learnpath::learnpath() - aicc object with id ' . $my_item_id . ' set in items[]', 0);
  219. }
  220. }
  221. break;
  222. case 2 :
  223. require_once ('scorm.class.php');
  224. require_once ('scormItem.class.php');
  225. $oItem = new scormItem('db', $row['id']);
  226. if (is_object($oItem)) {
  227. $my_item_id = $oItem->get_id();
  228. $oItem->set_lp_view($this->lp_view_id);
  229. $oItem->set_prevent_reinit($this->prevent_reinit);
  230. // Don't use reference here as the next loop will make the pointed object change
  231. $this->items[$my_item_id] = $oItem;
  232. $this->refs_list[$oItem->ref] = $my_item_id;
  233. if ($this->debug > 2) {
  234. error_log('New LP - object with id ' . $my_item_id . ' set in items[]', 0);
  235. }
  236. }
  237. break;
  238. case 1 :
  239. default :
  240. require_once ('learnpathItem.class.php');
  241. $oItem = new learnpathItem($row['id'], $user_id);
  242. if (is_object($oItem)) {
  243. $my_item_id = $oItem->get_id();
  244. //$oItem->set_lp_view($this->lp_view_id); moved down to when we are sure the item_view exists
  245. $oItem->set_prevent_reinit($this->prevent_reinit);
  246. // Don't use reference here as the next loop will make the pointed object change
  247. $this->items[$my_item_id] = $oItem;
  248. $this->refs_list[$my_item_id] = $my_item_id;
  249. if ($this->debug > 2) {
  250. error_log('New LP - learnpath::learnpath() ' . __LINE__ . ' - object with id ' . $my_item_id . ' set in items[]', 0);
  251. }
  252. }
  253. break;
  254. }
  255. //items is a list of pointers to all items, classified by DB ID, not SCO id
  256. if ($row['parent_item_id'] == 0 OR empty ($this->items[$row['parent_item_id']])) {
  257. $this->items[$row['id']]->set_level(0);
  258. } else {
  259. $level = $this->items[$row['parent_item_id']]->get_level() + 1;
  260. $this->items[$row['id']]->set_level($level);
  261. if (is_object($this->items[$row['parent_item_id']])) {
  262. //items is a list of pointers from item DB ids to item objects
  263. $this->items[$row['parent_item_id']]->add_child($row['id']);
  264. } else {
  265. if ($this->debug > 2) {
  266. error_log('New LP - learnpath::learnpath() ' . __LINE__ . ' - The parent item (' . $row['parent_item_id'] . ') of item ' . $row['id'] . ' could not be found', 0);
  267. }
  268. }
  269. }
  270. //get last viewing vars
  271. $lp_item_view_table = Database :: get_course_table(TABLE_LP_ITEM_VIEW);
  272. //this query should only return one or zero result
  273. $sql = "SELECT * " .
  274. "FROM $lp_item_view_table " .
  275. "WHERE lp_view_id = " . $this->lp_view_id . " " .
  276. "AND lp_item_id = " . $row['id'] . " ORDER BY view_count DESC ";
  277. if ($this->debug > 2) {
  278. error_log('New LP - learnpath::learnpath() - Selecting item_views: ' . $sql, 0);
  279. }
  280. //get the item status
  281. $res2 = Database::query($sql, __FILE__, __LINE__);
  282. if (Database :: num_rows($res2) > 0) {
  283. //if this learnpath has already been used by this user, get his last attempt count and
  284. //the last item seen back into this object
  285. //$max = 0;
  286. $row2 = Database :: fetch_array($res2);
  287. if ($this->debug > 2) {
  288. error_log('New LP - learnpath::learnpath() - Got item_view: ' . print_r($row2, true), 0);
  289. }
  290. $this->items[$row['id']]->set_status($row2['status']);
  291. if (empty ($row2['status'])) {
  292. $this->items[$row['id']]->set_status($this->default_status);
  293. }
  294. //$this->attempt = $row['view_count'];
  295. //$this->last_item = $row['id'];
  296. } else //no item found in lp_item_view for this view
  297. {
  298. //first attempt from this user. Set attempt to 1 and last_item to 0 (first item available)
  299. //TODO if the learnpath has not got attempts activated, always use attempt '1'
  300. //$this->attempt = 1;
  301. //$this->last_item = 0;
  302. $this->items[$row['id']]->set_status($this->default_status);
  303. //Add that row to the lp_item_view table so that we have something to show in the stats page
  304. $sql_ins = "INSERT INTO $lp_item_view_table " .
  305. "(lp_item_id, lp_view_id, view_count, status) VALUES " .
  306. "(" . $row['id'] . "," . $this->lp_view_id . ",1,'not attempted')";
  307. if ($this->debug > 2) {
  308. error_log('New LP - learnpath::learnpath() ' . __LINE__ . ' - Inserting blank item_view : ' . $sql_ins, 0);
  309. }
  310. $res_ins = Database::query($sql_ins, __FILE__, __LINE__);
  311. }
  312. //setting the view in the item object
  313. $this->items[$row['id']]->set_lp_view($this->lp_view_id);
  314. }
  315. $this->ordered_items = $this->get_flat_ordered_items_list($this->get_id(), 0);
  316. $this->max_ordered_items = 0;
  317. foreach ($this->ordered_items as $index => $dummy) {
  318. if ($index > $this->max_ordered_items AND !empty ($dummy)) {
  319. $this->max_ordered_items = $index;
  320. }
  321. }
  322. //TODO define the current item better
  323. $this->first();
  324. if ($this->debug > 2) {
  325. error_log('New LP - learnpath::learnpath() ' . __LINE__ . ' - End of learnpath constructor for learnpath ' . $this->get_id(), 0);
  326. }
  327. }
  328. /**
  329. * 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
  330. * I found it better to rewrite it. Old function is still available. Added also the possibility to add a description.
  331. *
  332. * @param int $parent
  333. * @param int $previous
  334. * @param string $type
  335. * @param int $id
  336. * @param string $title
  337. * @param string $description
  338. * @return int
  339. */
  340. function add_item($parent, $previous, $type = 'dokeos_chapter', $id, $title, $description, $prerequisites = 0, $max_time_allowed = 0) {
  341. if ($this->debug > 0) {
  342. error_log('New LP - In learnpath::add_item(' . $parent . ',' . $previous . ',' . $type . ',' . $id . ',' . $title . ')', 0);
  343. }
  344. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  345. $parent = intval($parent);
  346. $previous = intval($previous);
  347. $type = $this->escape_string($type);
  348. $id = intval($id);
  349. $max_time_allowed = $this->escape_string(htmlentities($max_time_allowed));
  350. if (empty ($max_time_allowed)) {
  351. $max_time_allowed = 0;
  352. }
  353. //$title = htmlspecialchars($title, ENT_QUOTES, $charset); // TODO: To be checked for encoding problems.
  354. //$title = $this->escape_string(api_convert_encoding($title, $this->encoding, $charset));
  355. $title = $this->escape_string(api_convert_encoding($title, $this->encoding, api_get_system_encoding()));
  356. $description = $this->escape_string(api_convert_encoding($description, $this->encoding, api_get_system_encoding()));
  357. $sql_count = " SELECT COUNT(id) AS num
  358. FROM " . $tbl_lp_item . "
  359. WHERE lp_id = " . $this->get_id() . " AND parent_item_id = " . $parent;
  360. $res_count = Database::query($sql_count, __FILE__, __LINE__);
  361. $row = Database :: fetch_array($res_count);
  362. $num = $row['num'];
  363. if ($num > 0) {
  364. if ($previous == 0) {
  365. $sql = "SELECT id, next_item_id, display_order
  366. FROM " . $tbl_lp_item . "
  367. WHERE
  368. lp_id = " . $this->get_id() . " AND
  369. parent_item_id = " . $parent . " AND
  370. previous_item_id = 0 OR previous_item_id=" . $parent;
  371. $result = Database::query($sql, __FILE__, __LINE__);
  372. $row = Database :: fetch_array($result);
  373. $tmp_previous = 0;
  374. $next = $row['id'];
  375. $display_order = 0;
  376. } else {
  377. $previous = (int) $previous;
  378. $sql = "
  379. SELECT
  380. id,
  381. previous_item_id,
  382. next_item_id,
  383. display_order
  384. FROM " . $tbl_lp_item . "
  385. WHERE
  386. lp_id = " . $this->get_id() . " AND
  387. id = " . $previous;
  388. $result = Database::query($sql, __FILE__, __LINE__);
  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, __FILE__, __LINE__);
  408. $max_score = Database :: result($rsQuiz, 0, 0);
  409. } else {
  410. $max_score = 100;
  411. }
  412. if ($prerequisites != 0) {
  413. $sql_ins = "
  414. INSERT INTO " . $tbl_lp_item . " (
  415. lp_id,
  416. item_type,
  417. ref,
  418. title,
  419. description,
  420. path,
  421. max_score,
  422. parent_item_id,
  423. previous_item_id,
  424. next_item_id,
  425. display_order,
  426. prerequisite,
  427. max_time_allowed
  428. ) VALUES (
  429. " . $this->get_id() . ",
  430. '" . $type . "',
  431. '',
  432. '" . $title . "',
  433. '" . $description . "',
  434. '" . $id . "',
  435. '" . $max_score . "',
  436. " . $parent . ",
  437. " . $previous . ",
  438. " . $next . ",
  439. " . ($display_order +1) . ",
  440. " . $prerequisites . ",
  441. " . $max_time_allowed . "
  442. )";
  443. } else {
  444. //insert new item
  445. $sql_ins = "
  446. INSERT INTO " . $tbl_lp_item . " (
  447. lp_id,
  448. item_type,
  449. ref,
  450. title,
  451. description,
  452. path,
  453. max_score,
  454. parent_item_id,
  455. previous_item_id,
  456. next_item_id,
  457. display_order,
  458. max_time_allowed
  459. ) VALUES (
  460. " . $this->get_id() . ",
  461. '" . $type . "',
  462. '',
  463. '" . $title . "',
  464. '" . $description . "',
  465. '" . $id . "',
  466. '" . $max_score . "',
  467. " . $parent . ",
  468. " . $previous . ",
  469. " . $next . ",
  470. " . ($display_order +1) . ",
  471. " . $max_time_allowed . "
  472. )";
  473. }
  474. if ($this->debug > 2) {
  475. error_log('New LP - Inserting dokeos_chapter: ' . $sql_ins, 0);
  476. }
  477. $res_ins = Database::query($sql_ins, __FILE__, __LINE__);
  478. if ($res_ins > 0) {
  479. $new_item_id = Database :: insert_id($res_ins);
  480. //update the item that should come after the new item
  481. $sql_update_next = "
  482. UPDATE " . $tbl_lp_item . "
  483. SET previous_item_id = " . $new_item_id . "
  484. WHERE id = " . $next;
  485. $res_update_next = Database::query($sql_update_next, __FILE__, __LINE__);
  486. //update the item that should be before the new item
  487. $sql_update_previous = "
  488. UPDATE " . $tbl_lp_item . "
  489. SET next_item_id = " . $new_item_id . "
  490. WHERE id = " . $tmp_previous;
  491. $res_update_previous = Database::query($sql_update_previous, __FILE__, __LINE__);
  492. //update all the items after the new item
  493. $sql_update_order = "
  494. UPDATE " . $tbl_lp_item . "
  495. SET display_order = display_order + 1
  496. WHERE
  497. lp_id = " . $this->get_id() . " AND
  498. id <> " . $new_item_id . " AND
  499. parent_item_id = " . $parent . " AND
  500. display_order > " . $display_order;
  501. $res_update_previous = Database::query($sql_update_order, __FILE__, __LINE__);
  502. //update the item that should come after the new item
  503. $sql_update_ref = "
  504. UPDATE " . $tbl_lp_item . "
  505. SET ref = " . $new_item_id . "
  506. WHERE id = " . $new_item_id;
  507. Database::query($sql_update_ref, __FILE__, __LINE__);
  508. }
  509. // upload audio
  510. if (!empty ($_FILES['mp3']['name'])) {
  511. // create the audio folder if it does not exist yet
  512. global $_course;
  513. $filepath = api_get_path('SYS_COURSE_PATH') . $_course['path'] . '/document/';
  514. if (!is_dir($filepath . 'audio')) {
  515. $perm = api_get_setting('permissions_for_new_directories');
  516. $perm = octdec(!empty ($perm) ? $perm : '0770');
  517. mkdir($filepath . 'audio', $perm);
  518. $audio_id = add_document($_course, '/audio', 'folder', 0, 'audio');
  519. api_item_property_update($_course, TOOL_DOCUMENT, $audio_id, 'FolderCreated', api_get_user_id());
  520. }
  521. // upload the file in the documents tool
  522. include_once (api_get_path(LIBRARY_PATH) . 'fileUpload.lib.php');
  523. $file_path = handle_uploaded_document($_course, $_FILES['mp3'], api_get_path('SYS_COURSE_PATH') . $_course['path'] . '/document', '/audio', api_get_user_id(), '', '', '', '', '', false);
  524. // getting the filename only
  525. $file_components = explode('/', $file_path);
  526. $file = $file_components[count($file_components) - 1];
  527. // store the mp3 file in the lp_item table
  528. $sql_insert_audio = "UPDATE $tbl_lp_item SET audio = '" . Database :: escape_string($file) . "' WHERE id = '" . Database :: escape_string($new_item_id) . "'";
  529. Database::query($sql_insert_audio, __FILE__, __LINE__);
  530. }
  531. return $new_item_id;
  532. }
  533. /**
  534. * Static admin function allowing addition of a learnpath to a course.
  535. * @param string Course code
  536. * @param string Learnpath name
  537. * @param string Learnpath description string, if provided
  538. * @param string Type of learnpath (default = 'guess', others = 'dokeos', 'aicc',...)
  539. * @param string Type of files origin (default = 'zip', others = 'dir','web_dir',...)
  540. * @param string Zip file containing the learnpath or directory containing the learnpath
  541. * @return integer The new learnpath ID on success, 0 on failure
  542. */
  543. function add_lp($course, $name, $description = '', $learnpath = 'guess', $origin = 'zip', $zipname = '') {
  544. global $charset;
  545. //if($this->debug>0){error_log('New LP - In learnpath::add_lp()',0);}
  546. //TODO
  547. $tbl_lp = Database :: get_course_table(TABLE_LP_MAIN);
  548. //check course code exists
  549. //check lp_name doesn't exist, otherwise append something
  550. $i = 0;
  551. $name = learnpath :: escape_string($name);
  552. //session_id
  553. $session_id = api_get_session_id();
  554. $check_name = "SELECT * FROM $tbl_lp WHERE name = '$name'";
  555. //if($this->debug>2){error_log('New LP - Checking the name for new LP: '.$check_name,0);}
  556. $res_name = Database::query($check_name, __FILE__, __LINE__);
  557. while (Database :: num_rows($res_name)) {
  558. //there is already one such name, update the current one a bit
  559. $i++;
  560. $name = $name . ' - ' . $i;
  561. $check_name = "SELECT * FROM $tbl_lp WHERE name = '$name'";
  562. //if($this->debug>2){error_log('New LP - Checking the name for new LP: '.$check_name,0);}
  563. $res_name = Database::query($check_name, __FILE__, __LINE__);
  564. }
  565. //new name does not exist yet; keep it
  566. //escape description
  567. $description = learnpath :: escape_string(api_htmlentities($description, ENT_QUOTES, $charset)); //Kevin: added htmlentities()
  568. $type = 1;
  569. switch ($learnpath) {
  570. case 'guess' :
  571. break;
  572. case 'dokeos' :
  573. $type = 1;
  574. break;
  575. case 'aicc' :
  576. break;
  577. }
  578. switch ($origin) {
  579. case 'zip' :
  580. //check zipname string. If empty, we are currently creating a new Dokeos learnpath
  581. break;
  582. case 'manual' :
  583. default :
  584. $get_max = "SELECT MAX(display_order) FROM $tbl_lp";
  585. $res_max = Database::query($get_max, __FILE__, __LINE__);
  586. if (Database :: num_rows($res_max) < 1) {
  587. $dsp = 1;
  588. } else {
  589. $row = Database :: fetch_array($res_max);
  590. $dsp = $row[0] + 1;
  591. }
  592. $sql_insert = "INSERT INTO $tbl_lp " .
  593. "(lp_type,name,description,path,default_view_mod," .
  594. "default_encoding,display_order,content_maker," .
  595. "content_local,js_lib,session_id) " .
  596. "VALUES ($type,'$name','$description','','embedded'," .
  597. "'UTF-8','$dsp','Dokeos'," .
  598. "'local','','".Database::escape_string($session_id)."')";
  599. //if($this->debug>2){error_log('New LP - Inserting new lp '.$sql_insert,0);}
  600. $res_insert = Database::query($sql_insert, __FILE__, __LINE__);
  601. $id = Database :: insert_id();
  602. if ($id > 0) {
  603. //insert into item_property
  604. api_item_property_update(api_get_course_info(), TOOL_LEARNPATH, $id, 'LearnpathAdded', api_get_user_id());
  605. return $id;
  606. }
  607. break;
  608. }
  609. }
  610. /**
  611. * Appends a message to the message attribute
  612. * @param string Message to append.
  613. */
  614. function append_message($string) {
  615. if ($this->debug > 0) {
  616. error_log('New LP - In learnpath::append_message()', 0);
  617. }
  618. $this->message .= $string;
  619. }
  620. /**
  621. * Autocompletes the parents of an item in case it's been completed or passed
  622. * @param integer Optional ID of the item from which to look for parents
  623. */
  624. function autocomplete_parents($item) {
  625. if ($this->debug > 0) {
  626. error_log('New LP - In learnpath::autocomplete_parents()', 0);
  627. }
  628. if (empty ($item)) {
  629. $item = $this->current;
  630. }
  631. $parent_id = $this->items[$item]->get_parent();
  632. if ($this->debug > 2) {
  633. error_log('New LP - autocompleting parent of item ' . $item . ' (item ' . $parent_id . ')', 0);
  634. }
  635. if (is_object($this->items[$item]) and !empty ($parent_id)) {
  636. //if $item points to an object and there is a parent
  637. if ($this->debug > 2) {
  638. error_log('New LP - ' . $item . ' is an item, proceed', 0);
  639. }
  640. $current_item = & $this->items[$item];
  641. $parent = & $this->items[$parent_id]; //get the parent
  642. //new experiment including failed and browsed in completed status
  643. $current_status = $current_item->get_status();
  644. if ($current_item->is_done() || $current_status == 'browsed' || $current_status == 'failed') {
  645. //if the current item is completed or passes or succeeded
  646. $completed = true;
  647. if ($this->debug > 2) {
  648. error_log('New LP - Status of current item is alright', 0);
  649. }
  650. foreach ($parent->get_children() as $child) {
  651. //check all his brothers (his parent's children) for completion status
  652. if ($child != $item) {
  653. if ($this->debug > 2) {
  654. error_log('New LP - Looking at brother with ID ' . $child . ', status is ' . $this->items[$child]->get_status(), 0);
  655. }
  656. //if($this->items[$child]->status_is(array('completed','passed','succeeded')))
  657. //Trying completing parents of failed and browsed items as well
  658. if ($this->items[$child]->status_is(array (
  659. 'completed',
  660. 'passed',
  661. 'succeeded',
  662. 'browsed',
  663. 'failed'
  664. ))) {
  665. //keep completion status to true
  666. } else {
  667. if ($this->debug > 2) {
  668. error_log('New LP - Found one incomplete child of ' . $parent_id . ': ' . $child . ' is ' . $this->items[$child]->get_status(), 0);
  669. }
  670. $completed = false;
  671. }
  672. }
  673. }
  674. if ($completed == true) { //if all the children were completed
  675. $parent->set_status('completed');
  676. $parent->save(false, $this->prerequisites_match($parent->get_id()));
  677. $this->update_queue[$parent->get_id()] = $parent->get_status();
  678. if ($this->debug > 2) {
  679. error_log('New LP - Added parent to update queue ' . print_r($this->update_queue, true), 0);
  680. }
  681. $this->autocomplete_parents($parent->get_id()); //recursive call
  682. }
  683. } else {
  684. //error_log('New LP - status of current item is not enough to get bothered with it',0);
  685. }
  686. }
  687. }
  688. /**
  689. * Autosaves the current results into the database for the whole learnpath
  690. */
  691. function autosave() {
  692. if ($this->debug > 0) {
  693. error_log('New LP - In learnpath::autosave()', 0);
  694. }
  695. //TODO add aditionnal save operations for the learnpath itself
  696. }
  697. /**
  698. * Clears the message attribute
  699. */
  700. function clear_message() {
  701. if ($this->debug > 0) {
  702. error_log('New LP - In learnpath::clear_message()', 0);
  703. }
  704. $this->message = '';
  705. }
  706. /**
  707. * Closes the current resource
  708. *
  709. * Stops the timer
  710. * Saves into the database if required
  711. * Clears the current resource data from this object
  712. * @return boolean True on success, false on failure
  713. */
  714. function close() {
  715. if ($this->debug > 0) {
  716. error_log('New LP - In learnpath::close()', 0);
  717. }
  718. if (empty ($this->lp_id)) {
  719. $this->error = 'Trying to close this learnpath but no ID is set';
  720. return false;
  721. }
  722. $this->current_time_stop = time();
  723. if ($this->save) {
  724. $learnpath_view_table = Database :: get_course_table(TABLE_LP_VIEW);
  725. /*
  726. $sql = "UPDATE $learnpath_view_table " .
  727. "SET " .
  728. "stop_time = ".$this->current_time_stop.", " .
  729. "score = ".$this->current_score.", ".
  730. "WHERE learnpath_id = '".$this->lp_id."'";
  731. //$res = Database::query($sql);
  732. $res = Database::query($res);
  733. if(Database::affected_rows($res)<1)
  734. {
  735. $this->error = 'Could not update learnpath_view table while closing learnpath';
  736. return false;
  737. }
  738. */
  739. }
  740. $this->ordered_items = array ();
  741. $this->index = 0;
  742. unset ($this->lp_id);
  743. //unset other stuff
  744. return true;
  745. }
  746. /**
  747. * Static admin function allowing removal of a learnpath
  748. * @param string Course code
  749. * @param integer Learnpath ID
  750. * @param string Whether to delete data or keep it (default: 'keep', others: 'remove')
  751. * @return boolean True on success, false on failure (might change that to return number of elements deleted)
  752. */
  753. function delete($course = null, $id = null, $delete = 'keep') {
  754. //TODO implement a way of getting this to work when the current object is not set
  755. //In clear: implement this in the item class as well (abstract class) and use the given ID in queries
  756. //if(empty($course)){$course = api_get_course_id();}
  757. //if(empty($id)){$id = $this->get_id();}
  758. //If an ID is specifically given and the current LP is not the same,
  759. //prevent delete
  760. if (!empty ($id) && ($id != $this->lp_id)) {
  761. return false;
  762. }
  763. $lp = Database :: get_course_table(TABLE_LP_MAIN);
  764. $lp_item = Database :: get_course_table(TABLE_LP_ITEM); // Proposed by Christophe (clefevre), see below.
  765. $lp_view = Database :: get_course_table(TABLE_LP_VIEW);
  766. $lp_item_view = Database :: get_course_table(TABLE_LP_ITEM_VIEW);
  767. //if($this->debug>0){error_log('New LP - In learnpath::delete()',0);}
  768. //delete lp item id
  769. foreach ($this->items as $id => $dummy) {
  770. //$this->items[$id]->delete();
  771. $sql_del_view = "DELETE FROM $lp_item_view WHERE lp_item_id = '" . $id . "'";
  772. $res_del_item_view = Database::query($sql_del_view, __FILE__, __LINE__);
  773. }
  774. // Proposed by Christophe (nickname: clefevre), see http://www.dokeos.com/forum/viewtopic.php?t=29673
  775. $sql_del_item = "DELETE FROM $lp_item WHERE lp_id = " . $this->lp_id;
  776. $res_del_item = Database::query($sql_del_item, __FILE__, __LINE__);
  777. $sql_del_view = "DELETE FROM $lp_view WHERE lp_id = " . $this->lp_id;
  778. //if($this->debug>2){error_log('New LP - Deleting views bound to lp '.$this->lp_id.': '.$sql_del_view,0);}
  779. $res_del_view = Database::query($sql_del_view, __FILE__, __LINE__);
  780. $this->toggle_publish($this->lp_id, 'i');
  781. //if($this->debug>2){error_log('New LP - Deleting lp '.$this->lp_id.' of type '.$this->type,0);}
  782. if ($this->type == 2 OR $this->type == 3) {
  783. //this is a scorm learning path, delete the files as well
  784. $sql = "SELECT path FROM $lp WHERE id = " . $this->lp_id;
  785. $res = Database::query($sql, __FILE__, __LINE__);
  786. if (Database :: num_rows($res) > 0) {
  787. $row = Database :: fetch_array($res);
  788. $path = $row['path'];
  789. $sql = "SELECT id FROM $lp WHERE path = '$path' AND id != " . $this->lp_id;
  790. $res = Database::query($sql, __FILE__, __LINE__);
  791. if (Database :: num_rows($res) > 0) { //another learning path uses this directory, so don't delete it
  792. if ($this->debug > 2) {
  793. error_log('New LP - In learnpath::delete(), found other LP using path ' . $path . ', keeping directory', 0);
  794. }
  795. } else {
  796. //no other LP uses that directory, delete it
  797. $course_rel_dir = api_get_course_path() . '/scorm/'; //scorm dir web path starting from /courses
  798. $course_scorm_dir = api_get_path(SYS_COURSE_PATH) . $course_rel_dir; //absolute system path for this course
  799. if ($delete == 'remove' && is_dir($course_scorm_dir . $path) and !empty ($course_scorm_dir)) {
  800. if ($this->debug > 2) {
  801. error_log('New LP - In learnpath::delete(), found SCORM, deleting directory: ' . $course_scorm_dir . $path, 0);
  802. }
  803. // Proposed by Christophe (clefevre).
  804. if (strcmp(substr($path, -2), "/.") == 0) {
  805. $path = substr($path, 0, -1); // Remove "." at the end
  806. }
  807. //exec('rm -rf ' . $course_scorm_dir . $path); // See Bug #5208, this is not OS-portable way.
  808. rmdirr($course_scorm_dir . $path);
  809. }
  810. }
  811. }
  812. }
  813. $sql_del_lp = "DELETE FROM $lp WHERE id = " . $this->lp_id;
  814. //if($this->debug>2){error_log('New LP - Deleting lp '.$this->lp_id.': '.$sql_del_lp,0);}
  815. $res_del_lp = Database::query($sql_del_lp, __FILE__, __LINE__);
  816. $this->update_display_order(); //updates the display order of all lps
  817. api_item_property_update(api_get_course_info(), TOOL_LEARNPATH, $this->lp_id, 'delete', api_get_user_id());
  818. require_once '../gradebook/lib/be.inc.php';
  819. $tbl_grade_link = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_LINK);
  820. //delete link of gradebook tool
  821. $sql = 'SELECT gl.id FROM ' . $tbl_grade_link . ' gl WHERE gl.type="4" AND gl.ref_id="' . $id . '";';
  822. $result = Database::query($sql, __FILE__, __LINE__);
  823. $row = Database :: fetch_array($result, 'ASSOC');
  824. $link = LinkFactory :: load($row['id']);
  825. if ($link[0] != null) {
  826. $link[0]->delete();
  827. }
  828. //TODO: also delete items and item-views
  829. if (api_get_setting('search_enabled') == 'true') {
  830. require_once (api_get_path(LIBRARY_PATH) . 'specific_fields_manager.lib.php');
  831. $r = delete_all_values_for_item($this->cc, TOOL_LEARNPATH, $this->lp_id);
  832. }
  833. }
  834. /**
  835. * Removes all the children of one item - dangerous!
  836. * @param integer Element ID of which children have to be removed
  837. * @return integer Total number of children removed
  838. */
  839. function delete_children_items($id) {
  840. if ($this->debug > 0) {
  841. error_log('New LP - In learnpath::delete_children_items(' . $id . ')', 0);
  842. }
  843. $num = 0;
  844. if (empty ($id) || $id != strval(intval($id))) {
  845. return false;
  846. }
  847. $lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  848. $sql = "SELECT * FROM $lp_item WHERE parent_item_id = $id";
  849. $res = Database::query($sql, __FILE__, __LINE__);
  850. while ($row = Database :: fetch_array($res)) {
  851. $num += $this->delete_children_items($row['id']);
  852. $sql_del = "DELETE FROM $lp_item WHERE id = " . $row['id'];
  853. $res_del = Database::query($sql_del, __FILE__, __LINE__);
  854. $num++;
  855. }
  856. return $num;
  857. }
  858. /**
  859. * Removes an item from the current learnpath
  860. * @param integer Elem ID (0 if first)
  861. * @param integer Whether to remove the resource/data from the system or leave it (default: 'keep', others 'remove')
  862. * @return integer Number of elements moved
  863. * @todo implement resource removal
  864. */
  865. function delete_item($id, $remove = 'keep') {
  866. if ($this->debug > 0) {
  867. error_log('New LP - In learnpath::delete_item()', 0);
  868. }
  869. //TODO - implement the resource removal
  870. if (empty ($id) || $id != strval(intval($id))) {
  871. return false;
  872. }
  873. //first select item to get previous, next, and display order
  874. $lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  875. $sql_sel = "SELECT * FROM $lp_item WHERE id = $id";
  876. $res_sel = Database::query($sql_sel, __FILE__, __LINE__);
  877. if (Database :: num_rows($res_sel) < 1) {
  878. return false;
  879. }
  880. $row = Database :: fetch_array($res_sel);
  881. $previous = $row['previous_item_id'];
  882. $next = $row['next_item_id'];
  883. $display = $row['display_order'];
  884. $parent = $row['parent_item_id'];
  885. $lp = $row['lp_id'];
  886. //delete children items
  887. $num = $this->delete_children_items($id);
  888. if ($this->debug > 2) {
  889. error_log('New LP - learnpath::delete_item() - deleted ' . $num . ' children of element ' . $id, 0);
  890. }
  891. //now delete the item
  892. $sql_del = "DELETE FROM $lp_item WHERE id = $id";
  893. if ($this->debug > 2) {
  894. error_log('New LP - Deleting item: ' . $sql_del, 0);
  895. }
  896. $res_del = Database::query($sql_del, __FILE__, __LINE__);
  897. //now update surrounding items
  898. $sql_upd = "UPDATE $lp_item SET next_item_id = $next WHERE id = $previous";
  899. $res_upd = Database::query($sql_upd, __FILE__, __LINE__);
  900. $sql_upd = "UPDATE $lp_item SET previous_item_id = $previous WHERE id = $next";
  901. $res_upd = Database::query($sql_upd, __FILE__, __LINE__);
  902. //now update all following items with new display order
  903. $sql_all = "UPDATE $lp_item SET display_order = display_order-1 WHERE lp_id = $lp AND parent_item_id = $parent AND display_order > $display";
  904. $res_all = Database::query($sql_all, __FILE__, __LINE__);
  905. // remove from search engine if enabled
  906. if (api_get_setting('search_enabled') == 'true') {
  907. $tbl_se_ref = Database :: get_main_table(TABLE_MAIN_SEARCH_ENGINE_REF);
  908. $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';
  909. $sql = sprintf($sql, $tbl_se_ref, $this->cc, TOOL_LEARNPATH, $lp, $id);
  910. $res = Database::query($sql, __FILE__, __LINE__);
  911. if (Database :: num_rows($res) > 0) {
  912. $row2 = Database :: fetch_array($res);
  913. require_once (api_get_path(LIBRARY_PATH) . 'search/DokeosIndexer.class.php');
  914. $di = new DokeosIndexer();
  915. $di->remove_document((int) $row2['search_did']);
  916. }
  917. $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';
  918. $sql = sprintf($sql, $tbl_se_ref, $this->cc, TOOL_LEARNPATH, $lp, $id);
  919. Database::query($sql, __FILE__, __LINE__);
  920. }
  921. }
  922. /**
  923. * Updates an item's content in place
  924. * @param integer Element ID
  925. * @param integer Parent item ID
  926. * @param integer Previous item ID
  927. * @param string Item title
  928. * @param string Item description
  929. * @param string Prerequisites (optional)
  930. * @param string Indexing terms (optional)
  931. * @param array The array resulting of the $_FILES[mp3] element
  932. * @return boolean True on success, false on error
  933. */
  934. function edit_item($id, $parent, $previous, $title, $description, $prerequisites = 0, $audio = NULL, $max_time_allowed = 0) {
  935. global $charset;
  936. if ($this->debug > 0) {
  937. error_log('New LP - In learnpath::edit_item()', 0);
  938. }
  939. if (empty ($max_time_allowed)) {
  940. $max_time_allowed = 0;
  941. }
  942. if (empty ($id) or ($id != strval(intval($id))) or empty ($title)) {
  943. return false;
  944. }
  945. $title = api_convert_encoding($title, $this->encoding, $charset);
  946. $description = api_convert_encoding($description, $this->encoding, $charset);
  947. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  948. $sql_select = "SELECT * FROM " . $tbl_lp_item . " WHERE id = " . $id;
  949. $res_select = Database::query($sql_select, __FILE__, __LINE__);
  950. $row_select = Database :: fetch_array($res_select);
  951. $audio_update_sql = '';
  952. if (is_array($audio) && !empty ($audio['tmp_name']) && $audio['error'] === 0) {
  953. // create the audio folder if it does not exist yet
  954. global $_course;
  955. $filepath = api_get_path('SYS_COURSE_PATH') . $_course['path'] . '/document/';
  956. if (!is_dir($filepath . 'audio')) {
  957. $perm = api_get_setting('permissions_for_new_directories');
  958. $perm = octdec(!empty ($perm) ? $perm : '0770');
  959. mkdir($filepath . 'audio', $perm);
  960. $audio_id = add_document($_course, '/audio', 'folder', 0, 'audio');
  961. api_item_property_update($_course, TOOL_DOCUMENT, $audio_id, 'FolderCreated', api_get_user_id());
  962. }
  963. //upload file in documents
  964. $pi = pathinfo($audio['name']);
  965. if ($pi['extension'] == 'mp3') {
  966. $c_det = api_get_course_info($this->cc);
  967. $bp = api_get_path(SYS_COURSE_PATH) . $c_det['path'] . '/document';
  968. $path = handle_uploaded_document($c_det, $audio, $bp, '/audio', api_get_user_id(), 0, null, '', 0, 'rename', false, 0);
  969. $path = substr($path, 7);
  970. //update reference in lp_item - audio path is the path from inside de document/audio/ dir
  971. $audio_update_sql = ", audio = '" . Database :: escape_string($path) . "' ";
  972. }
  973. }
  974. $same_parent = ($row_select['parent_item_id'] == $parent) ? true : false;
  975. $same_previous = ($row_select['previous_item_id'] == $previous) ? true : false;
  976. //TODO: htmlspecialchars to be checked for encoding related problems.
  977. if ($same_parent && $same_previous) {
  978. //only update title and description
  979. $sql_update = " UPDATE " . $tbl_lp_item . "
  980. SET title = '" . $this->escape_string($title) . "',
  981. prerequisite = '" . $prerequisites . "',
  982. description = '" . $this->escape_string($description) . "'
  983. " . $audio_update_sql . ",
  984. max_time_allowed = '" . $this->escape_string($max_time_allowed) . "'
  985. WHERE id = " . $id;
  986. $res_update = Database::query($sql_update, __FILE__, __LINE__);
  987. } else {
  988. $old_parent = $row_select['parent_item_id'];
  989. $old_previous = $row_select['previous_item_id'];
  990. $old_next = $row_select['next_item_id'];
  991. $old_order = $row_select['display_order'];
  992. $old_prerequisite = $row_select['prerequisite'];
  993. $old_max_time_allowed = $row_select['max_time_allowed'];
  994. /* BEGIN -- virtually remove the current item id */
  995. /* for the next and previous item it is like the current item doesn't exist anymore */
  996. if ($old_previous != 0) {
  997. $sql_update_next = "
  998. UPDATE " . $tbl_lp_item . "
  999. SET next_item_id = " . $old_next . "
  1000. WHERE id = " . $old_previous;
  1001. $res_update_next = Database::query($sql_update_next, __FILE__, __LINE__);
  1002. //echo '<p>' . $sql_update_next . '</p>';
  1003. }
  1004. if ($old_next != 0) {
  1005. $sql_update_previous = "
  1006. UPDATE " . $tbl_lp_item . "
  1007. SET previous_item_id = " . $old_previous . "
  1008. WHERE id = " . $old_next;
  1009. $res_update_previous = Database::query($sql_update_previous, __FILE__, __LINE__);
  1010. //echo '<p>' . $sql_update_previous . '</p>';
  1011. }
  1012. //display_order - 1 for every item with a display_order bigger then the display_order of the current item
  1013. $sql_update_order = "
  1014. UPDATE " . $tbl_lp_item . "
  1015. SET display_order = display_order - 1
  1016. WHERE
  1017. display_order > " . $old_order . " AND
  1018. parent_item_id = " . $old_parent;
  1019. $res_update_order = Database::query($sql_update_order, __FILE__, __LINE__);
  1020. //echo '<p>' . $sql_update_order . '</p>';
  1021. /* END -- virtually remove the current item id */
  1022. /* BEGIN -- update the current item id to his new location */
  1023. if ($previous == 0) {
  1024. //select the data of the item that should come after the current item
  1025. $sql_select_old = "
  1026. SELECT
  1027. id,
  1028. display_order
  1029. FROM " . $tbl_lp_item . "
  1030. WHERE
  1031. lp_id = " . $this->lp_id . " AND
  1032. parent_item_id = " . $parent . " AND
  1033. previous_item_id = " . $previous;
  1034. $res_select_old = Database::query($sql_select_old, __FILE__, __LINE__);
  1035. $row_select_old = Database :: fetch_array($res_select_old);
  1036. //echo '<p>' . $sql_select_old . '</p>';
  1037. //if the new parent didn't have children before
  1038. if (Database :: num_rows($res_select_old) == 0) {
  1039. $new_next = 0;
  1040. $new_order = 1;
  1041. } else {
  1042. $new_next = $row_select_old['id'];
  1043. $new_order = $row_select_old['display_order'];
  1044. }
  1045. //echo 'New next_item_id of current item: ' . $new_next . '<br />';
  1046. //echo 'New previous_item_id of current item: ' . $previous . '<br />';
  1047. //echo 'New display_order of current item: ' . $new_order . '<br />';
  1048. } else {
  1049. //select the data of the item that should come before the current item
  1050. $sql_select_old = "
  1051. SELECT
  1052. next_item_id,
  1053. display_order
  1054. FROM " . $tbl_lp_item . "
  1055. WHERE id = " . $previous;
  1056. $res_select_old = Database::query($sql_select_old, __FILE__, __LINE__);
  1057. $row_select_old = Database :: fetch_array($res_select_old);
  1058. //echo '<p>' . $sql_select_old . '</p>';
  1059. //echo 'New next_item_id of current item: ' . $row_select_old['next_item_id'] . '<br />';
  1060. //echo 'New previous_item_id of current item: ' . $previous . '<br />';
  1061. //echo 'New display_order of current item: ' . ($row_select_old['display_order'] + 1) . '<br />';
  1062. $new_next = $row_select_old['next_item_id'];
  1063. $new_order = $row_select_old['display_order'] + 1;
  1064. }
  1065. //TODO: htmlspecialchars to be checked for encoding related problems.
  1066. //update the current item with the new data
  1067. $sql_update = "
  1068. UPDATE " . $tbl_lp_item . "
  1069. SET
  1070. title = '" . $this->escape_string($title) . "',
  1071. description = '" . $this->escape_string($description) . "',
  1072. parent_item_id = " . $parent . ",
  1073. previous_item_id = " . $previous . ",
  1074. next_item_id = " . $new_next . ",
  1075. display_order = " . $new_order . "
  1076. " . $audio_update_sql . "
  1077. WHERE id = " . $id;
  1078. $res_update_next = Database::query($sql_update, __FILE__, __LINE__);
  1079. //echo '<p>' . $sql_update . '</p>';
  1080. if ($previous != 0) {
  1081. //update the previous item's next_item_id
  1082. $sql_update_previous = "
  1083. UPDATE " . $tbl_lp_item . "
  1084. SET next_item_id = " . $id . "
  1085. WHERE id = " . $previous;
  1086. $res_update_next = Database::query($sql_update_previous, __FILE__, __LINE__);
  1087. //echo '<p>' . $sql_update_previous . '</p>';
  1088. }
  1089. if ($new_next != 0) {
  1090. //update the next item's previous_item_id
  1091. $sql_update_next = "
  1092. UPDATE " . $tbl_lp_item . "
  1093. SET previous_item_id = " . $id . "
  1094. WHERE id = " . $new_next;
  1095. $res_update_next = Database::query($sql_update_next, __FILE__, __LINE__);
  1096. //echo '<p>' . $sql_update_next . '</p>';
  1097. }
  1098. if ($old_prerequisite != $prerequisites) {
  1099. $sql_update_next = "
  1100. UPDATE " . $tbl_lp_item . "
  1101. SET prerequisite = " . $prerequisites . "
  1102. WHERE id = " . $id;
  1103. $res_update_next = Database::query($sql_update_next, __FILE__, __LINE__);
  1104. }
  1105. if ($old_max_time_allowed != $max_time_allowed) {
  1106. $sql_update_max_time_allowed = "
  1107. UPDATE " . $tbl_lp_item . "
  1108. SET max_time_allowed = " . $max_time_allowed . "
  1109. WHERE id = " . $id;
  1110. $res_update_max_time_allowed = Database::query($sql_update_max_time_allowed, __FILE__, __LINE__);
  1111. }
  1112. //update all the items with the same or a bigger display_order than
  1113. //the current item
  1114. $sql_update_order = "
  1115. UPDATE " . $tbl_lp_item . "
  1116. SET display_order = display_order + 1
  1117. WHERE
  1118. lp_id = " . $this->get_id() . " AND
  1119. id <> " . $id . " AND
  1120. parent_item_id = " . $parent . " AND
  1121. display_order >= " . $new_order;
  1122. $res_update_next = Database::query($sql_update_order, __FILE__, __LINE__);
  1123. //echo '<p>' . $sql_update_order . '</p>';
  1124. /* END -- update the current item id to his new location */
  1125. }
  1126. }
  1127. /**
  1128. * Updates an item's prereq in place
  1129. * @param integer Element ID
  1130. * @param string Prerequisite Element ID
  1131. * @param string Prerequisite item type
  1132. * @param string Prerequisite min score
  1133. * @param string Prerequisite max score
  1134. * @return boolean True on success, false on error
  1135. */
  1136. function edit_item_prereq($id, $prerequisite_id, $mastery_score = 0, $max_score = 100) {
  1137. if ($this->debug > 0) {
  1138. error_log('New LP - In learnpath::edit_item_prereq(' . $id . ',' . $prerequisite_id . ',' . $mastery_score . ',' . $max_score . ')', 0);
  1139. }
  1140. if (empty ($id) or ($id != strval(intval($id))) or empty ($prerequisite_id)) {
  1141. return false;
  1142. }
  1143. $prerequisite_id = $this->escape_string($prerequisite_id);
  1144. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  1145. if (!is_numeric($mastery_score) || $mastery_score < 0)
  1146. $mastery_score = 0;
  1147. if (!is_numeric($max_score) || $max_score < 0)
  1148. $max_score = 100;
  1149. if ($mastery_score > $max_score)
  1150. $max_score = $mastery_score;
  1151. if (!is_numeric($prerequisite_id))
  1152. $prerequisite_id = 'NULL';
  1153. $sql_upd = " UPDATE " . $tbl_lp_item . "
  1154. SET prerequisite = " . $prerequisite_id . " WHERE id = " . $id;
  1155. $res_upd = Database::query($sql_upd, __FILE__, __LINE__);
  1156. if ($prerequisite_id != 'NULL' && $prerequisite_id != '') {
  1157. $sql_upd = " UPDATE " . $tbl_lp_item . " SET
  1158. mastery_score = " . $mastery_score .
  1159. //", max_score = " . $max_score . " " . //max score cannot be changed in the form anyway - see display_item_prerequisites_form()
  1160. " WHERE ref = '" . $prerequisite_id . "'"; //will this be enough to ensure unicity?
  1161. $res_upd = Database::query($sql_upd, __FILE__, __LINE__);
  1162. }
  1163. //TODO update the item object (can be ignored for now because refreshed)
  1164. return true;
  1165. }
  1166. /**
  1167. * Escapes a string with the available database escape function
  1168. * @param string String to escape
  1169. * @return string String escaped
  1170. */
  1171. function escape_string($string) {
  1172. //if($this->debug>0){error_log('New LP - In learnpath::escape_string('.$string.')',0);}
  1173. return Database :: escape_string($string);
  1174. }
  1175. /**
  1176. * Static admin function exporting a learnpath into a zip file
  1177. * @param string Export type (scorm, zip, cd)
  1178. * @param string Course code
  1179. * @param integer Learnpath ID
  1180. * @param string Zip file name
  1181. * @return string Zip file path (or false on error)
  1182. */
  1183. function export_lp($type, $course, $id, $zipname) {
  1184. //if($this->debug>0){error_log('New LP - In learnpath::export_lp()',0);}
  1185. //TODO
  1186. if (empty ($type) OR empty ($course) OR empty ($id) OR empty ($zipname)) {
  1187. return false;
  1188. }
  1189. $url = '';
  1190. switch ($type) {
  1191. case 'scorm' :
  1192. break;
  1193. case 'zip' :
  1194. break;
  1195. case 'cdrom' :
  1196. break;
  1197. }
  1198. return $url;
  1199. }
  1200. /**
  1201. * Gets all the chapters belonging to the same parent as the item/chapter given
  1202. * Can also be called as abstract method
  1203. * @param integer Item ID
  1204. * @return array A list of all the "brother items" (or an empty array on failure)
  1205. */
  1206. function get_brother_chapters($id) {
  1207. if ($this->debug > 0) {
  1208. error_log('New LP - In learnpath::get_brother_chapters()', 0);
  1209. }
  1210. if (empty ($id) OR $id != strval(intval($id))) {
  1211. return array ();
  1212. }
  1213. $lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  1214. $sql_parent = "SELECT * FROM $lp_item WHERE id = $id AND item_type='dokeos_chapter'";
  1215. $res_parent = Database::query($sql_parent, __FILE__, __LINE__);
  1216. if (Database :: num_rows($res_parent) > 0) {
  1217. $row_parent = Database :: fetch_array($res_parent);
  1218. $parent = $row_parent['parent_item_id'];
  1219. $sql_bros = "SELECT * FROM $lp_item WHERE parent_item_id = $parent AND id = $id AND item_type='dokeos_chapter' ORDER BY display_order";
  1220. $res_bros = Database::query($sql_bros, __FILE__, __LINE__);
  1221. $list = array ();
  1222. while ($row_bro = Database :: fetch_array($res_bros)) {
  1223. $list[] = $row_bro;
  1224. }
  1225. return $list;
  1226. }
  1227. return array ();
  1228. }
  1229. /**
  1230. * Gets all the items belonging to the same parent as the item given
  1231. * Can also be called as abstract method
  1232. * @param integer Item ID
  1233. * @return array A list of all the "brother items" (or an empty array on failure)
  1234. */
  1235. function get_brother_items($id) {
  1236. if ($this->debug > 0) {
  1237. error_log('New LP - In learnpath::get_brother_items(' . $id . ')', 0);
  1238. }
  1239. if (empty ($id) OR $id != strval(intval($id))) {
  1240. return array ();
  1241. }
  1242. $lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  1243. $sql_parent = "SELECT * FROM $lp_item WHERE id = $id";
  1244. $res_parent = Database::query($sql_parent, __FILE__, __LINE__);
  1245. if (Database :: num_rows($res_parent) > 0) {
  1246. $row_parent = Database :: fetch_array($res_parent);
  1247. $parent = $row_parent['parent_item_id'];
  1248. $sql_bros = "SELECT * FROM $lp_item WHERE parent_item_id = $parent ORDER BY display_order";
  1249. $res_bros = Database::query($sql_bros, __FILE__, __LINE__);
  1250. $list = array ();
  1251. while ($row_bro = Database :: fetch_array($res_bros)) {
  1252. $list[] = $row_bro;
  1253. }
  1254. return $list;
  1255. }
  1256. return array ();
  1257. }
  1258. /**
  1259. * Get the specific prefix index terms of this learning path
  1260. * @return array Array of terms
  1261. */
  1262. function get_common_index_terms_by_prefix($prefix) {
  1263. require_once api_get_path(LIBRARY_PATH) . 'specific_fields_manager.lib.php';
  1264. $terms = get_specific_field_values_list_by_prefix($prefix, $this->cc, TOOL_LEARNPATH, $this->lp_id);
  1265. $prefix_terms = array ();
  1266. foreach ($terms as $term) {
  1267. $prefix_terms[] = $term['value'];
  1268. }
  1269. return $prefix_terms;
  1270. }
  1271. /**
  1272. * Gets the number of items currently completed
  1273. * @return integer The number of items currently completed
  1274. */
  1275. function get_complete_items_count() {
  1276. if ($this->debug > 0) {
  1277. error_log('New LP - In learnpath::get_complete_items_count()', 0);
  1278. }
  1279. $i = 0;
  1280. foreach ($this->items as $id => $dummy) {
  1281. //if($this->items[$id]->status_is(array('completed','passed','succeeded'))){
  1282. //Trying failed and browsed considered "progressed" as well
  1283. if ($this->items[$id]->status_is(array (
  1284. 'completed',
  1285. 'passed',
  1286. 'succeeded',
  1287. 'browsed',
  1288. 'failed'
  1289. )) && $this->items[$id]->get_type() != 'dokeos_chapter' && $this->items[$id]->get_type() != 'dir') {
  1290. $i++;
  1291. }
  1292. }
  1293. return $i;
  1294. }
  1295. /**
  1296. * Gets the current item ID
  1297. * @return integer The current learnpath item id
  1298. */
  1299. function get_current_item_id() {
  1300. $current = 0;
  1301. if ($this->debug > 0) {
  1302. error_log('New LP - In learnpath::get_current_item_id()', 0);
  1303. }
  1304. if (!empty ($this->current)) {
  1305. $current = $this->current;
  1306. }
  1307. if ($this->debug > 2) {
  1308. error_log('New LP - In learnpath::get_current_item_id() - Returning ' . $current, 0);
  1309. }
  1310. return $current;
  1311. }
  1312. /** Force to get the first learnpath item id
  1313. * @return integer The current learnpath item id
  1314. */
  1315. function get_first_item_id() {
  1316. $current = 0;
  1317. if (is_array($this->ordered_items)) {
  1318. $current = $this->ordered_items[0];
  1319. }
  1320. return $current;
  1321. }
  1322. /**
  1323. * Gets the total number of items available for viewing in this SCORM
  1324. * @return integer The total number of items
  1325. */
  1326. function get_total_items_count() {
  1327. if ($this->debug > 0) {
  1328. error_log('New LP - In learnpath::get_total_items_count()', 0);
  1329. }
  1330. return count($this->items);
  1331. }
  1332. /**
  1333. * Gets the total number of items available for viewing in this SCORM but without chapters
  1334. * @return integer The total no-chapters number of items
  1335. */
  1336. function get_total_items_count_without_chapters() {
  1337. if ($this->debug > 0) {
  1338. error_log('New LP - In learnpath::get_total_items_count_without_chapters()', 0);
  1339. }
  1340. $total = 0;
  1341. foreach ($this->items as $temp => $temp2) {
  1342. if (!in_array($temp2->get_type(), array (
  1343. 'dokeos_chapter',
  1344. 'chapter',
  1345. 'dir'
  1346. )))
  1347. $total++;
  1348. }
  1349. return $total;
  1350. }
  1351. /**
  1352. * Gets the first element URL.
  1353. * @return string URL to load into the viewer
  1354. */
  1355. function first() {
  1356. if ($this->debug > 0) {
  1357. error_log('New LP - In learnpath::first()', 0);
  1358. }
  1359. //test if the last_item_seen exists and is not a dir
  1360. if (count($this->ordered_items) == 0) {
  1361. $this->index = 0;
  1362. }
  1363. if (!empty ($this->last_item_seen) && !empty ($this->items[$this->last_item_seen]) && $this->items[$this->last_item_seen]->get_type() != 'dir' && $this->items[$this->last_item_seen]->get_type() != 'dokeos_chapter' && $this->items[$this->last_item_seen]->is_done() != true) {
  1364. if ($this->debug > 2) {
  1365. 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);
  1366. }
  1367. $index = -1;
  1368. foreach ($this->ordered_items as $myindex => $item_id) {
  1369. if ($item_id == $this->last_item_seen) {
  1370. $index = $myindex;
  1371. break;
  1372. }
  1373. }
  1374. if ($index == -1) {
  1375. //index hasn't changed, so item not found - panic (this shouldn't happen)
  1376. if ($this->debug > 2) {
  1377. error_log('New LP - Last item (' . $this->last_item_seen . ') was found in items but not in ordered_items, panic!', 0);
  1378. }
  1379. return false;
  1380. } else {
  1381. $this->last = $this->last_item_seen;
  1382. $this->current = $this->last_item_seen;
  1383. $this->index = $index;
  1384. }
  1385. } else {
  1386. if ($this->debug > 2) {
  1387. error_log('New LP - In learnpath::first() - No last item seen', 0);
  1388. }
  1389. $index = 0;
  1390. //loop through all ordered items and stop at the first item that is
  1391. //not a directory *and* that has not been completed yet
  1392. 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) {
  1393. $index++;
  1394. }
  1395. $this->last = $this->current;
  1396. //current is
  1397. $this->current = $this->ordered_items[$index];
  1398. $this->index = $index;
  1399. if ($this->debug > 2) {
  1400. error_log('New LP - In learnpath::first() - No last item seen. New last = ' . $this->last . '(' . $this->ordered_items[$index] . ')', 0);
  1401. }
  1402. }
  1403. if ($this->debug > 2) {
  1404. error_log('New LP - In learnpath::first() - First item is ' . $this->get_current_item_id());
  1405. }
  1406. }
  1407. /**
  1408. * Gets the information about an item in a format usable as JavaScript to update
  1409. * the JS API by just printing this content into the <head> section of the message frame
  1410. * @param integer Item ID
  1411. * @return string
  1412. */
  1413. function get_js_info($item_id = '') {
  1414. if ($this->debug > 0) {
  1415. error_log('New LP - In learnpath::get_js_info(' . $item_id . ')', 0);
  1416. }
  1417. $info = '';
  1418. $item_id = $this->escape_string($item_id);
  1419. if (!empty ($item_id) && is_object($this->items[$item_id])) {
  1420. //if item is defined, return values from DB
  1421. $oItem = $this->items[$item_id];
  1422. $info .= '<script language="javascript">';
  1423. $info .= "top.set_score(" . $oItem->get_score() . ");\n";
  1424. $info .= "top.set_max(" . $oItem->get_max() . ");\n";
  1425. $info .= "top.set_min(" . $oItem->get_min() . ");\n";
  1426. $info .= "top.set_lesson_status('" . $oItem->get_status() . "');";
  1427. $info .= "top.set_session_time('" . $oItem->get_scorm_time('js') . "');";
  1428. $info .= "top.set_suspend_data('" . $oItem->get_suspend_data() . "');";
  1429. $info .= "top.set_saved_lesson_status('" . $oItem->get_status() . "');";
  1430. $info .= "top.set_flag_synchronized();";
  1431. $info .= '</script>';
  1432. if ($this->debug > 2) {
  1433. error_log('New LP - in learnpath::get_js_info(' . $item_id . ') - returning: ' . $info, 0);
  1434. }
  1435. return $info;
  1436. } else {
  1437. //if item_id is empty, just update to default SCORM data
  1438. $info .= '<script language="javascript">';
  1439. $info .= "top.set_score(" . learnpathItem :: get_score() . ");\n";
  1440. $info .= "top.set_max(" . learnpathItem :: get_max() . ");\n";
  1441. $info .= "top.set_min(" . learnpathItem :: get_min() . ");\n";
  1442. $info .= "top.set_lesson_status('" . learnpathItem :: get_status() . "');";
  1443. $info .= "top.set_session_time('" . learnpathItem :: get_scorm_time('js') . "');";
  1444. $info .= "top.set_suspend_data('" . learnpathItem :: get_suspend_data() . "');";
  1445. $info .= "top.set_saved_lesson_status('" . learnpathItem :: get_status() . "');";
  1446. $info .= "top.set_flag_synchronized();";
  1447. $info .= '</script>';
  1448. if ($this->debug > 2) {
  1449. error_log('New LP - in learnpath::get_js_info(' . $item_id . ') - returning: ' . $info, 0);
  1450. }
  1451. return $info;
  1452. }
  1453. }
  1454. /**
  1455. * Gets the js library from the database
  1456. * @return string The name of the javascript library to be used
  1457. */
  1458. function get_js_lib() {
  1459. $lib = '';
  1460. if (!empty ($this->js_lib)) {
  1461. $lib = $this->js_lib;
  1462. }
  1463. return $lib;
  1464. }
  1465. /**
  1466. * Gets the learnpath database ID
  1467. * @return integer Learnpath ID in the lp table
  1468. */
  1469. function get_id() {
  1470. //if($this->debug>0){error_log('New LP - In learnpath::get_id()',0);}
  1471. if (!empty ($this->lp_id)) {
  1472. return $this->lp_id;
  1473. } else {
  1474. return 0;
  1475. }
  1476. }
  1477. /**
  1478. * Gets the last element URL.
  1479. * @return string URL to load into the viewer
  1480. */
  1481. function get_last() {
  1482. if ($this->debug > 0) {
  1483. error_log('New LP - In learnpath::get_last()', 0);
  1484. }
  1485. $this->index = count($this->ordered_items) - 1;
  1486. return $this->ordered_items[$this->index];
  1487. }
  1488. /**
  1489. * Gets the navigation bar for the learnpath display screen
  1490. * @return string The HTML string to use as a navigation bar
  1491. */
  1492. function get_navigation_bar() {
  1493. if ($this->debug > 0) {
  1494. error_log('New LP - In learnpath::get_navigation_bar()', 0);
  1495. }
  1496. //TODO find a good value for the following variables
  1497. $file = '';
  1498. $openDir = '';
  1499. $edoceo = '';
  1500. $time = 0;
  1501. $navbar = '';
  1502. $RequestUri = '';
  1503. $mycurrentitemid = $this->get_current_item_id();
  1504. if ($this->mode == 'fullscreen') {
  1505. $navbar = '<table cellpadding="0" cellspacing="0" align="left">' . "\n" .
  1506. ' <tr> ' . "\n" .
  1507. ' <td>' . "\n" .
  1508. ' <div class="buttons">' . "\n" .
  1509. ' <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" .
  1510. ' <a href="" onclick="dokeos_xajax_handler.switch_item(' . $mycurrentitemid . ',\'previous\');return false;" title="previous"><img border="0" src="../img/lp_leftarrow.gif" title="' . get_lang('ScormPrevious') . '"></a>' . "\n" .
  1511. ' <a href="" onclick="dokeos_xajax_handler.switch_item(' . $mycurrentitemid . ',\'next\');return false;" title="next" ><img border="0" src="../img/lp_rightarrow.gif" title="' . get_lang('ScormNext') . '"></a>' . "\n" .
  1512. //' <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" .
  1513. //' <a href="lp_controller.php?action=list" target="_top" title="learnpaths list"><img border="0" src="../img/exit.png" title="Exit"></a>'."\n" .
  1514. ' </div>' . "\n" .
  1515. ' </td>' . "\n" .
  1516. ' </tr>' . "\n" .
  1517. '</table>' . "\n";
  1518. } else {
  1519. $navbar = '<table cellpadding="0" cellspacing="0" align="left">' . "\n" .
  1520. ' <tr> ' . "\n" .
  1521. ' <td>' . "\n" .
  1522. ' <div class="buttons">' . "\n" .
  1523. ' <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" .
  1524. ' <a href="" onclick="dokeos_xajax_handler.switch_item(' . $mycurrentitemid . ',\'previous\');return false;" title="previous"><img border="0" src="../img/lp_leftarrow.gif" title="' . get_lang('ScormPrevious') . '"></a>' . "\n" .
  1525. ' <a href="" onclick="dokeos_xajax_handler.switch_item(' . $mycurrentitemid . ',\'next\');return false;" title="next" ><img border="0" src="../img/lp_rightarrow.gif" title="' . get_lang('ScormNext') . '"></a>' . "\n" .
  1526. // ' <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" .
  1527. ' </div>' . "\n" .
  1528. ' </td>' . "\n" .
  1529. ' </tr>' . "\n" .
  1530. '</table>' . "\n";
  1531. }
  1532. return $navbar;
  1533. }
  1534. /**
  1535. * Gets the next resource in queue (url).
  1536. * @return string URL to load into the viewer
  1537. */
  1538. function get_next_index() {
  1539. if ($this->debug > 0) {
  1540. error_log('New LP - In learnpath::get_next_index()', 0);
  1541. }
  1542. //TODO
  1543. $index = $this->index;
  1544. $index++;
  1545. if ($this->debug > 2) {
  1546. error_log('New LP - Now looking at ordered_items[' . ($index) . '] - type is ' . $this->items[$this->ordered_items[$index]]->type, 0);
  1547. }
  1548. 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) {
  1549. $index++;
  1550. if ($index == $this->max_ordered_items) {
  1551. return $this->index;
  1552. }
  1553. }
  1554. if (empty ($this->ordered_items[$index])) {
  1555. return $this->index;
  1556. }
  1557. if ($this->debug > 2) {
  1558. error_log('New LP - index is now ' . $index, 0);
  1559. }
  1560. return $index;
  1561. }
  1562. /**
  1563. * Gets item_id for the next element
  1564. * @return integer Next item (DB) ID
  1565. */
  1566. function get_next_item_id() {
  1567. if ($this->debug > 0) {
  1568. error_log('New LP - In learnpath::get_next_item_id()', 0);
  1569. }
  1570. $new_index = $this->get_next_index();
  1571. if (!empty ($new_index)) {
  1572. if (isset ($this->ordered_items[$new_index])) {
  1573. if ($this->debug > 2) {
  1574. error_log('New LP - In learnpath::get_next_index() - Returning ' . $this->ordered_items[$new_index], 0);
  1575. }
  1576. return $this->ordered_items[$new_index];
  1577. }
  1578. }
  1579. if ($this->debug > 2) {
  1580. error_log('New LP - In learnpath::get_next_index() - Problem - Returning 0', 0);
  1581. }
  1582. return 0;
  1583. }
  1584. /**
  1585. * Returns the package type ('scorm','aicc','scorm2004','dokeos','ppt'...)
  1586. *
  1587. * Generally, the package provided is in the form of a zip file, so the function
  1588. * has been written to test a zip file. If not a zip, the function will return the
  1589. * default return value: ''
  1590. * @param string the path to the file
  1591. * @param string the original name of the file
  1592. * @return string 'scorm','aicc','scorm2004','dokeos' or '' if the package cannot be recognized
  1593. */
  1594. function get_package_type($file_path, $file_name) {
  1595. //get name of the zip file without the extension
  1596. $file_info = pathinfo($file_name);
  1597. $filename = $file_info['basename']; //name including extension
  1598. $extension = $file_info['extension']; //extension only
  1599. if (!empty ($_POST['ppt2lp']) && !in_array(strtolower($extension), array (
  1600. 'dll',
  1601. 'exe'
  1602. ))) {
  1603. return 'oogie';
  1604. }
  1605. if (!empty ($_POST['woogie']) && !in_array(strtolower($extension), array (
  1606. 'dll',
  1607. 'exe'
  1608. ))) {
  1609. return 'woogie';
  1610. }
  1611. $file_base_name = str_replace('.' . $extension, '', $filename); //filename without its extension
  1612. $zipFile = new pclZip($file_path);
  1613. // Check the zip content (real size and file extension)
  1614. $zipContentArray = $zipFile->listContent();
  1615. $package_type = '';
  1616. $at_root = false;
  1617. $manifest = '';
  1618. //the following loop should be stopped as soon as we found the right imsmanifest.xml (how to recognize it?)
  1619. if (is_array($zipContentArray) && count($zipContentArray) > 0) {
  1620. foreach ($zipContentArray as $thisContent) {
  1621. if (preg_match('~.(php.*|phtml)$~i', $thisContent['filename'])) {
  1622. //New behaviour: Don't do anything. These files will be removed in scorm::import_package
  1623. }
  1624. elseif (stristr($thisContent['filename'], 'imsmanifest.xml') !== FALSE) {
  1625. $manifest = $thisContent['filename']; //just the relative directory inside scorm/
  1626. $package_type = 'scorm';
  1627. break; //exit the foreach loop
  1628. }
  1629. elseif (preg_match('/aicc\//i', $thisContent['filename']) != false) {
  1630. //if found an aicc directory... (!= false means it cannot be false (error) or 0 (no match))
  1631. $package_type = 'aicc';
  1632. //break;//don't exit the loop, because if we find an imsmanifest afterwards, we want it, not the AICC
  1633. } else {
  1634. $package_type = '';
  1635. }
  1636. }
  1637. }
  1638. return $package_type;
  1639. }
  1640. /**
  1641. * Gets the previous resource in queue (url). Also initialises time values for this viewing
  1642. * @return string URL to load into the viewer
  1643. */
  1644. function get_previous_index() {
  1645. if ($this->debug > 0) {
  1646. error_log('New LP - In learnpath::get_previous_index()', 0);
  1647. }
  1648. $index = $this->index;
  1649. if (isset ($this->ordered_items[$index -1])) {
  1650. $index--;
  1651. 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')) {
  1652. $index--;
  1653. if ($index < 0) {
  1654. return $this->index;
  1655. }
  1656. }
  1657. } else {
  1658. if ($this->debug > 2) {
  1659. error_log('New LP - get_previous_index() - there was no previous index available, reusing ' . $index, 0);
  1660. }
  1661. //no previous item
  1662. }
  1663. return $index;
  1664. }
  1665. /**
  1666. * Gets item_id for the next element
  1667. * @return integer Previous item (DB) ID
  1668. */
  1669. function get_previous_item_id() {
  1670. if ($this->debug > 0) {
  1671. error_log('New LP - In learnpath::get_previous_item_id()', 0);
  1672. }
  1673. $new_index = $this->get_previous_index();
  1674. return $this->ordered_items[$new_index];
  1675. }
  1676. /**
  1677. * Gets the progress value from the progress_db attribute
  1678. * @return integer Current progress value
  1679. */
  1680. function get_progress() {
  1681. if ($this->debug > 0) {
  1682. error_log('New LP - In learnpath::get_progress()', 0);
  1683. }
  1684. if (!empty ($this->progress_db)) {
  1685. return $this->progress_db;
  1686. }
  1687. return 0;
  1688. }
  1689. /**
  1690. * Gets the progress value from the progress field in the database (allows use as abstract method)
  1691. * @param integer Learnpath ID
  1692. * @param integer User ID
  1693. * @param string Mode of display ('%','abs' or 'both')
  1694. * @param string Course database name (optional, defaults to '')
  1695. * @param boolean Whether to return null if no record was found (true), or 0 (false) (optional, defaults to false)
  1696. * @return integer Current progress value as found in the database
  1697. */
  1698. function get_db_progress($lp_id, $user_id, $mode = '%', $course_db = '', $sincere = false) {
  1699. //if($this->debug>0){error_log('New LP - In learnpath::get_db_progress()',0);}
  1700. $table = Database :: get_course_table(TABLE_LP_VIEW, $course_db);
  1701. $sql = "SELECT * FROM $table WHERE lp_id = $lp_id AND user_id = $user_id";
  1702. $res = Database::query($sql, __FILE__, __LINE__);
  1703. $view_id = 0;
  1704. if (Database :: num_rows($res) > 0) {
  1705. $row = Database :: fetch_array($res);
  1706. $progress = $row['progress'];
  1707. $view_id = $row['id'];
  1708. } else {
  1709. if ($sincere) {
  1710. return null;
  1711. }
  1712. }
  1713. if (empty ($progress)) {
  1714. $progress = '0';
  1715. }
  1716. if ($mode == '%') {
  1717. return $progress . '%';
  1718. } else {
  1719. //get the number of items completed and the number of items total
  1720. $tbl = Database :: get_course_table(TABLE_LP_ITEM, $course_db);
  1721. $sql = "SELECT count(*) FROM $tbl WHERE lp_id = " . $lp_id . "
  1722. AND item_type NOT IN('dokeos_chapter','chapter','dir')";
  1723. $res = Database::query($sql, __FILE__, __LINE__);
  1724. $row = Database :: fetch_array($res);
  1725. $total = $row[0];
  1726. $tbl_item_view = Database :: get_course_table(TABLE_LP_ITEM_VIEW, $course_db);
  1727. $tbl_item = Database :: get_course_table(TABLE_LP_ITEM, $course_db);
  1728. //$sql = "SELECT count(distinct(lp_item_id)) FROM $tbl WHERE lp_view_id = ".$view_id." AND status IN ('passed','completed','succeeded')";
  1729. //trying as also counting browsed and failed items
  1730. $sql = "SELECT count(distinct(lp_item_id))
  1731. FROM $tbl_item_view as item_view
  1732. INNER JOIN $tbl_item as item
  1733. ON item.id = item_view.lp_item_id
  1734. AND item_type NOT IN('dokeos_chapter','chapter','dir')
  1735. WHERE lp_view_id = " . $view_id . "
  1736. AND status IN ('passed','completed','succeeded','browsed','failed')";
  1737. $res = Database::query($sql, __FILE__, __LINE__);
  1738. $row = Database :: fetch_array($res);
  1739. $completed = $row[0];
  1740. if ($mode == 'abs') {
  1741. return $completed . '/' . $total;
  1742. }
  1743. elseif ($mode == 'both') {
  1744. if ($progress < ($completed / ($total ? $total : 1))) {
  1745. $progress = number_format(($completed / ($total ? $total : 1)) * 100, 0);
  1746. }
  1747. return $progress . '% (' . $completed . '/' . $total . ')';
  1748. }
  1749. }
  1750. return $progress;
  1751. }
  1752. /**
  1753. * Returns the HTML necessary to print a mediaplayer block inside a page
  1754. * @return string The mediaplayer HTML
  1755. */
  1756. function get_mediaplayer($autostart='true') {
  1757. global $_course;
  1758. // Database table definition
  1759. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  1760. $tbl_lp_item_view = Database :: get_course_table(TABLE_LP_ITEM_VIEW);
  1761. // getting all the information about the item
  1762. $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 " .
  1763. "WHERE lp.id = '" . $_SESSION['oLP']->current . "'";
  1764. $result = Database::query($sql, __FILE__, __LINE__);
  1765. $row = mysql_fetch_assoc($result);
  1766. $output = '';
  1767. if (!empty ($row['audio'])) {
  1768. $list = $_SESSION['oLP']->get_toc();
  1769. $type_quiz = false;
  1770. foreach($list as $toc) {
  1771. if ($toc['id'] == $_SESSION['oLP']->current && ($toc['type']=='quiz') ) {
  1772. $type_quiz = true;
  1773. }
  1774. }
  1775. if ($type_quiz) {
  1776. if ($_SESSION['oLP']->prevent_reinit == 1) {
  1777. $row['status'] === 'completed' ? $autostart_audio = 'false' : $autostart_audio = 'true';
  1778. } else {
  1779. $autostart_audio = $autostart;
  1780. }
  1781. } else {
  1782. $autostart_audio = 'true';
  1783. }
  1784. // the mp3 player
  1785. $output = '<div id="container">';
  1786. $output .= '<script type="text/javascript" src="../inc/lib/mediaplayer/swfobject.js"></script>';
  1787. $output .= '<script type="text/javascript">
  1788. var s1 = new SWFObject("../inc/lib/mediaplayer/player.swf","ply","250","20","9","#FFFFFF");
  1789. s1.addParam("allowscriptaccess","always");
  1790. s1.addParam("flashvars","file=' . api_get_path(WEB_COURSE_PATH) . $_course['path'] . '/document/audio/' . $row['audio'] . '&autostart=' . $autostart_audio.'");
  1791. s1.write("container");
  1792. </script></div>';
  1793. }
  1794. return $output;
  1795. }
  1796. /**
  1797. * Gets a progress bar for the learnpath by counting the number of items in it and the number of items
  1798. * completed so far.
  1799. * @param string Mode in which we want the values
  1800. * @param integer Progress value to display (optional but mandatory if used in abstract context)
  1801. * @param string Text to display near the progress value (optional but mandatory in abstract context)
  1802. * @param boolean true if it comes from a Diplay LP view
  1803. * @return string HTML string containing the progress bar
  1804. */
  1805. function get_progress_bar($mode = '', $percentage = -1, $text_add = '', $from_lp = false) {
  1806. //if($this->debug>0){error_log('New LP - In learnpath::get_progress_bar()',0);}
  1807. global $lp_theme_css;
  1808. // Setting up the CSS path of the current style if exists
  1809. if (!empty ($lp_theme_css)) {
  1810. $css_path = api_get_path(WEB_CODE_PATH) . 'css/' . $lp_theme_css . '/images/';
  1811. } else {
  1812. $css_path = '../img/';
  1813. }
  1814. //if($this->debug>0){error_log('New LP - In learnpath::get_progress_bar()',0);}
  1815. if (isset ($this) && is_object($this) && ($percentage == '-1' OR $text_add == '')) {
  1816. list ($percentage, $text_add) = $this->get_progress_bar_text($mode);
  1817. }
  1818. $text = $percentage . $text_add;
  1819. //Default progress bar config
  1820. // times that will be greater or shorter
  1821. $factor = 1.2;
  1822. if ($from_lp)
  1823. $progress_height = '26';
  1824. else
  1825. $progress_height = '16';
  1826. $size = str_replace('%', '', $percentage);
  1827. $output = ''
  1828. //.htmlentities(get_lang('ScormCompstatus'),ENT_QUOTES,'ISO-8859-1')."<br />"
  1829. . '<table border="0" cellpadding="0" cellspacing="0"><tr><td>' .
  1830. '<img id="progress_img_limit_left" src="' . $css_path . 'bar_1.gif" width="1" height="' . $progress_height . '">' .
  1831. '<img id="progress_img_full" src="' . $css_path . 'bar_1u.gif" width="' . $size * $factor . 'px" height="' . $progress_height . '" id="full_portion">' .
  1832. '<img id="progress_img_limit_middle" src="' . $css_path . 'bar_1m.gif" width="1" height="' . $progress_height . '">';
  1833. if ($percentage <= 98) {
  1834. $output .= '<img id="progress_img_empty" src="' . $css_path . 'bar_1r.gif" width="' . (100 - $size) * $factor . 'px" height="' . $progress_height . '" id="empty_portion">';
  1835. } else {
  1836. $output .= '<img id="progress_img_empty" src="' . $css_path . 'bar_1r.gif" width="0" height="' . $progress_height . '" id="empty_portion">';
  1837. }
  1838. $output .= '<img id="progress_bar_img_limit_right" src="' . $css_path . 'bar_1.gif" width="1" height="' . $progress_height . '"></td></tr></table>' .
  1839. '<div class="progresstext" id="progress_text">' . $text . '</div>';
  1840. return $output;
  1841. }
  1842. /**
  1843. * Gets the progress bar info to display inside the progress bar. Also used by scorm_api.php
  1844. * @param string Mode of display (can be '%' or 'abs').abs means we display a number of completed elements per total elements
  1845. * //@param integer Additional steps to fake as completed
  1846. * @return list Percentage or number and symbol (% or /xx)
  1847. */
  1848. function get_progress_bar_text($mode = '', $add = 0) {
  1849. if ($this->debug > 0) {
  1850. error_log('New LP - In learnpath::get_progress_bar_text()', 0);
  1851. }
  1852. if (empty ($mode)) {
  1853. $mode = $this->progress_bar_mode;
  1854. }
  1855. $total_items = $this->get_total_items_count_without_chapters();
  1856. if ($this->debug > 2) {
  1857. error_log('New LP - Total items available in this learnpath: ' . $total_items, 0);
  1858. }
  1859. $i = $this->get_complete_items_count();
  1860. if ($this->debug > 2) {
  1861. error_log('New LP - Items completed so far: ' . $i, 0);
  1862. }
  1863. if ($add != 0) {
  1864. $i += $add;
  1865. if ($this->debug > 2) {
  1866. error_log('New LP - Items completed so far (+modifier): ' . $i, 0);
  1867. }
  1868. }
  1869. $text = '';
  1870. if ($i > $total_items) {
  1871. $i = $total_items;
  1872. }
  1873. if ($mode == '%') {
  1874. if ($total_items > 0) {
  1875. $percentage = ((float) $i / (float) $total_items) * 100;
  1876. } else {
  1877. $percentage = 0;
  1878. }
  1879. $percentage = number_format($percentage, 0);
  1880. $text = '%';
  1881. }
  1882. elseif ($mode == 'abs') {
  1883. $percentage = $i;
  1884. $text = '/' . $total_items;
  1885. }
  1886. return array (
  1887. $percentage,
  1888. $text
  1889. );
  1890. }
  1891. /**
  1892. * Gets the progress bar mode
  1893. * @return string The progress bar mode attribute
  1894. */
  1895. function get_progress_bar_mode() {
  1896. if ($this->debug > 0) {
  1897. error_log('New LP - In learnpath::get_progress_bar_mode()', 0);
  1898. }
  1899. if (!empty ($this->progress_bar_mode)) {
  1900. return $this->progress_bar_mode;
  1901. } else {
  1902. return '%';
  1903. }
  1904. }
  1905. /**
  1906. * Gets the learnpath proximity (remote or local)
  1907. * @return string Learnpath proximity
  1908. */
  1909. function get_proximity() {
  1910. if ($this->debug > 0) {
  1911. error_log('New LP - In learnpath::get_proximity()', 0);
  1912. }
  1913. if (!empty ($this->proximity)) {
  1914. return $this->proximity;
  1915. } else {
  1916. return '';
  1917. }
  1918. }
  1919. /**
  1920. * Gets the learnpath theme (remote or local)
  1921. * @return string Learnpath theme
  1922. */
  1923. function get_theme() {
  1924. if ($this->debug > 0) {
  1925. error_log('New LP - In learnpath::get_theme()', 0);
  1926. }
  1927. if (!empty ($this->theme)) {
  1928. return $this->theme;
  1929. } else {
  1930. return '';
  1931. }
  1932. }
  1933. /**
  1934. * Gets the learnpath session id
  1935. * @return string Learnpath theme
  1936. */
  1937. function get_lp_session_id() {
  1938. if ($this->debug > 0) {
  1939. error_log('New LP - In learnpath::get_lp_session_id()', 0);
  1940. }
  1941. if (!empty ($this->lp_session_id)) {
  1942. return $this->lp_session_id;
  1943. } else {
  1944. return 0;
  1945. }
  1946. }
  1947. /**
  1948. * Gets the learnpath image
  1949. * @return string Web URL of the LP image
  1950. */
  1951. function get_preview_image() {
  1952. if ($this->debug > 0) {
  1953. error_log('New LP - In learnpath::get_preview_image()', 0);
  1954. }
  1955. if (!empty ($this->preview_image)) {
  1956. return $this->preview_image;
  1957. } else {
  1958. return '';
  1959. }
  1960. }
  1961. /**
  1962. * Gets the learnpath author
  1963. * @return string LP's author
  1964. */
  1965. function get_author() {
  1966. if ($this->debug > 0) {
  1967. error_log('New LP - In learnpath::get_author()', 0);
  1968. }
  1969. if (!empty ($this->author)) {
  1970. return $this->author;
  1971. } else {
  1972. return '';
  1973. }
  1974. }
  1975. /**
  1976. * Generate a new prerequisites string for a given item. If this item was a sco and
  1977. * its prerequisites were strings (instead of IDs), then transform those strings into
  1978. * IDs, knowing that SCORM IDs are kept in the "ref" field of the lp_item table.
  1979. * Prefix all item IDs that end-up in the prerequisites string by "ITEM_" to use the
  1980. * same rule as the scorm_export() method
  1981. * @param integer Item ID
  1982. * @return string Prerequisites string ready for the export as SCORM
  1983. */
  1984. function get_scorm_prereq_string($item_id) {
  1985. if ($this->debug > 0) {
  1986. error_log('New LP - In learnpath::get_scorm_prereq_string()', 0);
  1987. }
  1988. if (!is_object($this->items[$item_id])) {
  1989. return false;
  1990. }
  1991. $oItem = $this->items[$item_id];
  1992. $prereq = $oItem->get_prereq_string();
  1993. if (empty ($prereq)) {
  1994. return '';
  1995. }
  1996. 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,
  1997. //then simply return it (with the ITEM_ prefix)
  1998. return 'ITEM_' . $prereq;
  1999. } else {
  2000. if (isset ($this->refs_list[$prereq])) {
  2001. //it's a simple string item from which the ID can be found in the refs list
  2002. //so we can transform it directly to an ID for export
  2003. return 'ITEM_' . $this->refs_list[$prereq];
  2004. } else {
  2005. //last case, if it's a complex form, then find all the IDs (SCORM strings)
  2006. //and replace them, one by one, by the internal IDs (dokeos db)
  2007. //TODO modify the '*' replacement to replace the multiplier in front of it
  2008. //by a space as well
  2009. $find = array (
  2010. '&',
  2011. '|',
  2012. '~',
  2013. '=',
  2014. '<>',
  2015. '{',
  2016. '}',
  2017. '*',
  2018. '(',
  2019. ')'
  2020. );
  2021. $replace = array (
  2022. ' ',
  2023. ' ',
  2024. ' ',
  2025. ' ',
  2026. ' ',
  2027. ' ',
  2028. ' ',
  2029. ' ',
  2030. ' ',
  2031. ' '
  2032. );
  2033. $prereq_mod = str_replace($find, $replace, $prereq);
  2034. $ids = split(' ', $prereq_mod);
  2035. foreach ($ids as $id) {
  2036. $id = trim($id);
  2037. if (isset ($this->refs_list[$id])) {
  2038. $prereq = preg_replace('/[^a-zA-Z_0-9](' . $id . ')[^a-zA-Z_0-9]/', 'ITEM_' . $this->refs_list[$id], $prereq);
  2039. }
  2040. }
  2041. error_log('New LP - In learnpath::get_scorm_prereq_string(): returning modified string: ' . $prereq, 0);
  2042. return $prereq;
  2043. }
  2044. }
  2045. }
  2046. /**
  2047. * Returns the XML DOM document's node
  2048. * @param resource Reference to a list of objects to search for the given ITEM_*
  2049. * @param string The identifier to look for
  2050. * @return mixed The reference to the element found with that identifier. False if not found
  2051. */
  2052. function get_scorm_xml_node(& $children, $id) {
  2053. for ($i = 0; $i < $children->length; $i++) {
  2054. $item_temp = $children->item($i);
  2055. if ($item_temp->nodeName == 'item') {
  2056. if ($item_temp->getAttribute('identifier') == $id) {
  2057. return $item_temp;
  2058. }
  2059. }
  2060. $subchildren = $item_temp->childNodes;
  2061. if ($subchildren->length > 0) {
  2062. $val = $this->get_scorm_xml_node($subchildren, $id);
  2063. if (is_object($val)) {
  2064. return $val;
  2065. }
  2066. }
  2067. }
  2068. return false;
  2069. }
  2070. /**
  2071. * Returns a usable array of stats related to the current learnpath and user
  2072. * @return array Well-formatted array containing status for the current learnpath
  2073. */
  2074. function get_stats() {
  2075. if ($this->debug > 0) {
  2076. error_log('New LP - In learnpath::get_stats()', 0);
  2077. }
  2078. //TODO
  2079. }
  2080. /**
  2081. * Static method. Can be re-implemented by children. Gives an array of statistics for
  2082. * the given course (for all learnpaths and all users)
  2083. * @param string Course code
  2084. * @return array Well-formatted array containing status for the course's learnpaths
  2085. */
  2086. function get_stats_course($course) {
  2087. //if($this->debug>0){error_log('New LP - In learnpath::get_stats_course()',0);}
  2088. //TODO
  2089. }
  2090. /**
  2091. * Static method. Can be re-implemented by children. Gives an array of statistics for
  2092. * the given course and learnpath (for all users)
  2093. * @param string Course code
  2094. * @param integer Learnpath ID
  2095. * @return array Well-formatted array containing status for the specified learnpath
  2096. */
  2097. function get_stats_lp($course, $lp) {
  2098. //if($this->debug>0){error_log('New LP - In learnpath::get_stats_lp()',0);}
  2099. //TODO
  2100. }
  2101. /**
  2102. * Static method. Can be re-implemented by children. Gives an array of statistics for
  2103. * the given course, learnpath and user.
  2104. * @param string Course code
  2105. * @param integer Learnpath ID
  2106. * @param integer User ID
  2107. * @return array Well-formatted array containing status for the specified learnpath and user
  2108. */
  2109. function get_stats_lp_user($course, $lp, $user) {
  2110. //if($this->debug>0){error_log('New LP - In learnpath::get_stats_lp_user()',0);}
  2111. //TODO
  2112. }
  2113. /**
  2114. * Static method. Can be re-implemented by children. Gives an array of statistics for
  2115. * the given course and learnpath (for all users)
  2116. * @param string Course code
  2117. * @param integer User ID
  2118. * @return array Well-formatted array containing status for the user's learnpaths
  2119. */
  2120. function get_stats_user($course, $user) {
  2121. //if($this->debug>0){error_log('New LP - In learnpath::get_stats_user()',0);}
  2122. //TODO
  2123. }
  2124. /**
  2125. * Gets the status list for all LP's items
  2126. * @return array Array of [index] => [item ID => current status]
  2127. */
  2128. function get_items_status_list() {
  2129. if ($this->debug > 0) {
  2130. error_log('New LP - In learnpath::get_items_status_list()', 0);
  2131. }
  2132. $list = array ();
  2133. foreach ($this->ordered_items as $item_id) {
  2134. $list[] = array (
  2135. $item_id => $this->items[$item_id]->get_status()
  2136. );
  2137. }
  2138. return $list;
  2139. }
  2140. /**
  2141. * Return the number of interactions for the given learnpath Item View ID.
  2142. * This method can be used as static.
  2143. * @param integer Item View ID
  2144. * @return integer Number of interactions
  2145. */
  2146. function get_interactions_count_from_db($lp_iv_id = 0) {
  2147. if (empty ($lp_iv_id)) {
  2148. return -1;
  2149. }
  2150. $table = Database :: get_course_table(TABLE_LP_IV_INTERACTION);
  2151. $sql = "SELECT count(*) FROM $table WHERE lp_iv_id = $lp_iv_id";
  2152. $res = Database::query($sql, __FILE__, __LINE__);
  2153. $row = Database :: fetch_array($res);
  2154. $num = $row[0];
  2155. return $num;
  2156. }
  2157. /**
  2158. * Return the interactions as an array for the given lp_iv_id.
  2159. * This method can be used as static.
  2160. * @param integer Learnpath Item View ID
  2161. * @return array
  2162. * @todo Transcode labels instead of switching to HTML (which requires to know the encoding of the LP)
  2163. */
  2164. function get_iv_interactions_array($lp_iv_id = 0) {
  2165. $charset = api_get_setting('platform_charset');
  2166. $list = array ();
  2167. $table = Database :: get_course_table(TABLE_LP_IV_INTERACTION);
  2168. $sql = "SELECT * FROM $table WHERE lp_iv_id = $lp_iv_id ORDER BY order_id ASC";
  2169. $res = Database::query($sql, __FILE__, __LINE__);
  2170. $num = Database :: num_rows($res);
  2171. if ($num > 0) {
  2172. $list[] = array (
  2173. "order_id" => api_htmlentities(get_lang('Order'), ENT_QUOTES, $charset),
  2174. "id" => api_htmlentities(get_lang('InteractionID'), ENT_QUOTES, $charset),
  2175. "type" => api_htmlentities(get_lang('Type'), ENT_QUOTES, $charset),
  2176. "time" => api_htmlentities(get_lang('TimeFinished'), ENT_QUOTES, $charset),
  2177. "correct_responses" => api_htmlentities(get_lang('CorrectAnswers'), ENT_QUOTES, $charset),
  2178. "student_response" => api_htmlentities(get_lang('StudentResponse'), ENT_QUOTES, $charset),
  2179. "result" => api_htmlentities(get_lang('Result'), ENT_QUOTES, $charset),
  2180. "latency" => api_htmlentities(get_lang('LatencyTimeSpent'), ENT_QUOTES, $charset)
  2181. );
  2182. while ($row = Database :: fetch_array($res)) {
  2183. $list[] = array (
  2184. "order_id" => ($row['order_id'] + 1),
  2185. "id" => urldecode($row['interaction_id']), //urldecode because they often have %2F or stuff like that
  2186. "type" => $row['interaction_type'],
  2187. "time" => $row['completion_time'],
  2188. //"correct_responses"=>$row['correct_responses'],
  2189. //hide correct responses from students
  2190. "correct_responses" => '',
  2191. "student_response" => $row['student_response'],
  2192. "result" => $row['result'],
  2193. "latency" => $row['latency']
  2194. );
  2195. }
  2196. }
  2197. return $list;
  2198. }
  2199. /**
  2200. * Return the number of objectives for the given learnpath Item View ID.
  2201. * This method can be used as static.
  2202. * @param integer Item View ID
  2203. * @return integer Number of objectives
  2204. */
  2205. function get_objectives_count_from_db($lp_iv_id = 0) {
  2206. if (empty ($lp_iv_id)) {
  2207. return -1;
  2208. }
  2209. $table = Database :: get_course_table(TABLE_LP_IV_OBJECTIVE);
  2210. $sql = "SELECT count(*) FROM $table WHERE lp_iv_id = $lp_iv_id";
  2211. $res = Database::query($sql, __FILE__, __LINE__);
  2212. $row = Database :: fetch_array($res);
  2213. $num = $row[0];
  2214. return $num;
  2215. }
  2216. /**
  2217. * Return the objectives as an array for the given lp_iv_id.
  2218. * This method can be used as static.
  2219. * @param integer Learnpath Item View ID
  2220. * @return array
  2221. * @todo Translate labels
  2222. */
  2223. function get_iv_objectives_array($lp_iv_id = 0) {
  2224. global $chatset;
  2225. $list = array ();
  2226. $table = Database :: get_course_table(TABLE_LP_IV_OBJECTIVE);
  2227. $sql = "SELECT * FROM $table WHERE lp_iv_id = $lp_iv_id ORDER BY order_id ASC";
  2228. $res = Database::query($sql, __FILE__, __LINE__);
  2229. $num = Database :: num_rows($res);
  2230. if ($num > 0) {
  2231. $list[] = array (
  2232. "order_id" => api_htmlentities(get_lang('Order'), ENT_QUOTES, $charset),
  2233. "objective_id" => api_htmlentities(get_lang('ObjectiveID'), ENT_QUOTES, $charset),
  2234. "score_raw" => api_htmlentities(get_lang('ObjectiveRawScore'), ENT_QUOTES, $charset),
  2235. "score_max" => api_htmlentities(get_lang('ObjectiveMaxScore'), ENT_QUOTES, $charset),
  2236. "score_min" => api_htmlentities(get_lang('ObjectiveMinScore'), ENT_QUOTES, $charset),
  2237. "status" => api_htmlentities(get_lang('ObjectiveStatus'), ENT_QUOTES, $charset)
  2238. );
  2239. while ($row = Database :: fetch_array($res)) {
  2240. $list[] = array (
  2241. "order_id" => ($row['order_id'] + 1),
  2242. "objective_id" => urldecode($row['objective_id']), //urldecode because they often have %2F or stuff like that
  2243. "score_raw" => $row['score_raw'],
  2244. "score_max" => $row['score_max'],
  2245. "score_min" => $row['score_min'],
  2246. "status" => $row['status']
  2247. );
  2248. }
  2249. }
  2250. return $list;
  2251. }
  2252. /**
  2253. * Generate and return the table of contents for this learnpath. The (flat) table returned can be
  2254. * used by get_html_toc() to be ready to display
  2255. * @return array TOC as a table with 4 elements per row: title, link, status and level
  2256. */
  2257. function get_toc() {
  2258. if ($this->debug > 0) {
  2259. error_log('New LP - In learnpath::get_toc()', 0);
  2260. }
  2261. $toc = array ();
  2262. //echo "<pre>".print_r($this->items,true)."</pre>";
  2263. foreach ($this->ordered_items as $item_id) {
  2264. if ($this->debug > 2) {
  2265. error_log('New LP - learnpath::get_toc(): getting info for item ' . $item_id, 0);
  2266. }
  2267. //TODO change this link generation and use new function instead
  2268. $toc[] = array (
  2269. 'id' => $item_id,
  2270. 'title' => $this->items[$item_id]->get_title(),
  2271. //'link'=>get_addedresource_link_in_learnpath('document',$item_id,1),
  2272. 'status' => $this->items[$item_id]->get_status(),
  2273. 'level' => $this->items[$item_id]->get_level(),
  2274. 'type' => $this->items[$item_id]->get_type(),
  2275. 'description' => $this->items[$item_id]->get_description(),
  2276. 'path' => $this->items[$item_id]->get_path(),
  2277. );
  2278. }
  2279. if ($this->debug > 2) {
  2280. error_log('New LP - In learnpath::get_toc() - TOC array: ' . print_r($toc, true), 0);
  2281. }
  2282. return $toc;
  2283. }
  2284. /**
  2285. * Gets the learning path type
  2286. * @param boolean Return the name? If false, return the ID. Default is false.
  2287. * @return mixed Type ID or name, depending on the parameter
  2288. */
  2289. function get_type($get_name = false) {
  2290. $res = false;
  2291. if ($this->debug > 0) {
  2292. error_log('New LP - In learnpath::get_type()', 0);
  2293. }
  2294. if (!empty ($this->type)) {
  2295. if ($get_name) {
  2296. //get it from the lp_type table in main db
  2297. } else {
  2298. $res = $this->type;
  2299. }
  2300. }
  2301. if ($this->debug > 2) {
  2302. error_log('New LP - In learnpath::get_type() - Returning ' . ($res == false ? 'false' : $res), 0);
  2303. }
  2304. return $res;
  2305. }
  2306. /**
  2307. * Gets the learning path type as static method
  2308. * @param boolean Return the name? If false, return the ID. Default is false.
  2309. * @return mixed Type ID or name, depending on the parameter
  2310. */
  2311. function get_type_static($lp_id = 0) {
  2312. $tbl_lp = Database :: get_course_table(TABLE_LP_MAIN);
  2313. $sql = "SELECT lp_type FROM $tbl_lp WHERE id = '" . $lp_id . "'";
  2314. $res = Database::query($sql, __FILE__, __LINE__);
  2315. if ($res === false) {
  2316. return null;
  2317. }
  2318. if (Database :: num_rows($res) <= 0) {
  2319. return null;
  2320. }
  2321. $row = Database :: fetch_array($res);
  2322. return $row['lp_type'];
  2323. }
  2324. /**
  2325. * Gets a flat list of item IDs ordered for display (level by level ordered by order_display)
  2326. * This method can be used as abstract and is recursive
  2327. * @param integer Learnpath ID
  2328. * @param integer Parent ID of the items to look for
  2329. * @return mixed Ordered list of item IDs or false on error
  2330. */
  2331. function get_flat_ordered_items_list($lp, $parent = 0) {
  2332. //if($this->debug>0){error_log('New LP - In learnpath::get_flat_ordered_items_list('.$lp.','.$parent.')',0);}
  2333. $list = array ();
  2334. if (empty ($lp)) {
  2335. return false;
  2336. }
  2337. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  2338. $sql = "SELECT * FROM $tbl_lp_item WHERE lp_id = $lp AND parent_item_id = $parent ORDER BY display_order";
  2339. $res = Database::query($sql, __FILE__, __LINE__);
  2340. while ($row = Database :: fetch_array($res)) {
  2341. $sublist = learnpath :: get_flat_ordered_items_list($lp, $row['id']);
  2342. $list[] = $row['id'];
  2343. foreach ($sublist as $item) {
  2344. $list[] = $item;
  2345. }
  2346. }
  2347. return $list;
  2348. }
  2349. /**
  2350. * Uses the table generated by get_toc() and returns an HTML-formatted string ready to display
  2351. * @return string HTML TOC ready to display
  2352. */
  2353. /*function get_html_toc()
  2354. {
  2355. if($this->debug>0){error_log('New LP - In learnpath::get_html_toc()',0);}
  2356. $list = $this->get_toc();
  2357. //echo $this->current;
  2358. //$parent = $this->items[$this->current]->get_parent();
  2359. //if(empty($parent)){$parent = $this->ordered_items[$this->items[$this->current]->get_previous_index()];}
  2360. $html = '<div class="inner_lp_toc">'."\n" ;
  2361. // " onchange=\"javascript:document.getElementById('toc_$parent').focus();\">\n";
  2362. require_once('resourcelinker.inc.php');
  2363. //temp variables
  2364. $mycurrentitemid = $this->get_current_item_id();
  2365. foreach($list as $item)
  2366. {
  2367. if($this->debug>2){error_log('New LP - learnpath::get_html_toc(): using item '.$item['id'],0);}
  2368. //TODO complete this
  2369. $icon_name = array('not attempted' => '../img/notattempted.gif',
  2370. 'incomplete' => '../img/incomplete.gif',
  2371. 'failed' => '../img/failed.gif',
  2372. 'completed' => '../img/completed.gif',
  2373. 'passed' => '../img/passed.gif',
  2374. 'succeeded' => '../img/succeeded.gif',
  2375. 'browsed' => '../img/completed.gif');
  2376. $style = 'scorm_item';
  2377. if($item['id'] == $this->current){
  2378. $style = 'scorm_item_highlight';
  2379. }
  2380. //the anchor will let us center the TOC on the currently viewed item &^D
  2381. $html .= '<a name="atoc_'.$item['id'].'" /><div class="'.$style.'" style="padding-left: '.($item['level']/2).'em; padding-right:'.($item['level']/2).'em" id="toc_'.$item['id'].'" >' .
  2382. '<img id="toc_img_'.$item['id'].'" class="scorm_status_img" src="'.$icon_name[$item['status']].'" alt="'.substr($item['status'],0,1).'" />';
  2383. //$title = htmlspecialchars($item['title'],ENT_QUOTES,$this->encoding);
  2384. $title = $item['title'];
  2385. if(empty($title)){
  2386. $title = rl_get_resource_name(api_get_course_id(),$this->get_id(),$item['id']);
  2387. $title = htmlspecialchars($title,ENT_QUOTES,$this->encoding);
  2388. }
  2389. if(empty($title))$title = '-';
  2390. if($item['type']!='dokeos_chapter' and $item['type']!='dir'){
  2391. //$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>" ;
  2392. $url = $this->get_link('http',$item['id']);
  2393. //$html .= '<a href="'.$url.'" target="content_name" onclick="top.load_item('.$item['id'].',\''.$url.'\');">'.$title.'</a>' ;
  2394. //$html .= '<a href="" onclick="top.load_item('.$item['id'].',\''.$url.'\');return false;">'.$title.'</a>' ;
  2395. $html .= '<a href="" onclick="dokeos_xajax_handler.switch_item(' .
  2396. $mycurrentitemid.',' .
  2397. $item['id'].');' .
  2398. 'return false;" >'.$title.'</a>' ;
  2399. }else{
  2400. $html .= $title;
  2401. }
  2402. $html .= "</div>\n";
  2403. }
  2404. $html .= "</div>\n";
  2405. return $html;
  2406. }*/
  2407. /**
  2408. * Uses the table generated by get_toc() and returns an HTML-formatted string ready to display
  2409. * @return string HTML TOC ready to display
  2410. */
  2411. function get_html_toc() {
  2412. $is_allowed_to_edit = api_is_allowed_to_edit(null,true);
  2413. $charset = api_get_setting('platform_charset');
  2414. $display_action_links_with_icons = false;
  2415. if ($this->debug > 0) {
  2416. error_log('New LP - In learnpath::get_html_toc()', 0);
  2417. }
  2418. $list = $this->get_toc();
  2419. //echo $this->current;
  2420. //$parent = $this->items[$this->current]->get_parent();
  2421. //if(empty($parent)){$parent = $this->ordered_items[$this->items[$this->current]->get_previous_index()];}
  2422. $html = '<div class="scorm_title"><div class="scorm_title_text">' . Security::remove_XSS(api_convert_encoding($this->get_name(), $this->encoding, $charset)) . '</div></div>';
  2423. // build, display
  2424. if ($is_allowed_to_edit) {
  2425. $gradebook = Security :: remove_XSS($_GET['gradebook']);
  2426. //var_dump($this->get_lp_session_id());
  2427. if ($this->get_lp_session_id()==api_get_session_id()) {
  2428. $html .= '<div class="actions_lp">';
  2429. if ($display_action_links_with_icons) {
  2430. $html .= "<a href='lp_controller.php?" . api_get_cidreq() . "&amp;action=build&amp;lp_id=" . $this->lp_id . "' target='_parent'>" . Display :: return_icon('learnpath_build.gif', get_lang('Build')) . ' ' . get_lang('Build') . "</a>";
  2431. $html .= "<a href='lp_controller.php?" . api_get_cidreq() . "&amp;action=admin_view&amp;lp_id=" . $this->lp_id . "' target='_parent'>" . Display :: return_icon('learnpath_organize.gif', get_lang('BasicOverview')) . ' ' . get_lang('BasicOverview') . "</a>";
  2432. $html .= '<span>' . Display :: return_icon('learnpath_view_na.gif', get_lang("Display")) . ' <b>' . get_lang("Display") . '</b></span>';
  2433. } else {
  2434. $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>";
  2435. $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>";
  2436. $html .= '<span><b>' . get_lang('Display') . '</b></span>';
  2437. }
  2438. $html .= '</div>';
  2439. }
  2440. }
  2441. $html .= '<div id="inner_lp_toc" class="inner_lp_toc">' . "\n";
  2442. require_once ('resourcelinker.inc.php');
  2443. //temp variables
  2444. $mycurrentitemid = $this->get_current_item_id();
  2445. $color_counter = 0;
  2446. $i = 0;
  2447. foreach ($list as $item) {
  2448. if ($this->debug > 2) {
  2449. error_log('New LP - learnpath::get_html_toc(): using item ' . $item['id'], 0);
  2450. }
  2451. //TODO complete this
  2452. $icon_name = array (
  2453. 'not attempted' => '../img/notattempted.gif',
  2454. 'incomplete' => '../img/incomplete.gif',
  2455. 'failed' => '../img/failed.gif',
  2456. 'completed' => '../img/completed.gif',
  2457. 'passed' => '../img/passed.gif',
  2458. 'succeeded' => '../img/succeeded.gif',
  2459. 'browsed' => '../img/completed.gif'
  2460. );
  2461. $style = 'scorm_item';
  2462. $scorm_color_background = 'scorm_item';
  2463. $style_item = 'scorm_item';
  2464. $current = false;
  2465. if ($item['id'] == $this->current) {
  2466. $style = 'scorm_item_highlight';
  2467. $scorm_color_background = 'scorm_item_highlight';
  2468. } else
  2469. if ($color_counter % 2 == 0) {
  2470. $scorm_color_background = 'scorm_item_1';
  2471. } else {
  2472. $scorm_color_background = 'scorm_item_2';
  2473. }
  2474. if ($scorm_color_background != '') {
  2475. $html .= '<div id="toc_' . $item['id'] . '" class="' . $scorm_color_background . '">';
  2476. }
  2477. //the anchor will let us center the TOC on the currently viewed item &^D
  2478. if ($item['type'] != 'dokeos_module' AND $item['type'] != 'dokeos_chapter') {
  2479. $html .= '<a name="atoc_' . $item['id'] . '" />';
  2480. $html .= '<div class="' . $style_item . '" style="padding-left: ' . ($item['level'] * 1.5) . 'em; padding-right:' . ($item['level'] / 2) . 'em" title="' . $item['description'] . '" >';
  2481. } else {
  2482. $html .= '<div class="' . $style_item . '" style="padding-left: ' . ($item['level'] * 2) . 'em; padding-right:' . ($item['level'] * 1.5) . 'em" title="' . $item['description'] . '" >';
  2483. }
  2484. $title = $item['title'];
  2485. if (empty ($title)) {
  2486. $title = rl_get_resource_name(api_get_course_id(), $this->get_id(), $item['id']);
  2487. }
  2488. //$title = api_htmlentities($title, ENT_QUOTES, $this->encoding);
  2489. $title = Security::remove_XSS($title);
  2490. if ($item['type'] != 'dokeos_chapter' and $item['type'] != 'dir' AND $item['type'] != 'dokeos_module') {
  2491. //$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>" ;
  2492. $url = $this->get_link('http', $item['id']);
  2493. //$html .= '<a href="'.$url.'" target="content_name" onclick="top.load_item('.$item['id'].',\''.$url.'\');">'.$title.'</a>' ;
  2494. //$html .= '<a href="" onclick="top.load_item('.$item['id'].',\''.$url.'\');return false;">'.$title.'</a>' ;
  2495. //<img align="absbottom" width="13" height="13" src="../img/lp_document.png">&nbsp;background:#aaa;
  2496. $html .= '<a href="" onclick="dokeos_xajax_handler.switch_item(' .
  2497. $mycurrentitemid . ',' .
  2498. $item['id'] . ');' .
  2499. 'return false;" >' . stripslashes($title) . '</a>';
  2500. } elseif ($item['type'] == 'dokeos_module' || $item['type'] == 'dokeos_chapter') {
  2501. $html .= "<img align='absbottom' width='13' height='13' src='../img/lp_dokeos_module.png'>&nbsp;" . stripslashes($title);
  2502. } elseif ($item['type'] == 'dir') {
  2503. $html .= stripslashes($title);
  2504. }
  2505. $tbl_track_e_exercises = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
  2506. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  2507. $user_id = api_get_user_id();
  2508. $course_id = api_get_course_id();
  2509. $sql = "SELECT path FROM $tbl_track_e_exercises, $tbl_lp_item
  2510. WHERE path = '" . $item['path'] . "' AND exe_user_id = '$user_id' AND exe_cours_id = '$course_id' AND path = exe_exo_id AND status <> 'incomplete'";
  2511. $result = Database::query($sql, __FILE__, __LINE__);
  2512. $count = Database :: num_rows($result);
  2513. if ($item['type'] == 'quiz') {
  2514. if ($item['status'] == 'completed') {
  2515. $html .= "&nbsp;<img id='toc_img_" . $item['id'] . "' src='" . $icon_name[$item['status']] . "' alt='" . substr($item['status'], 0, 1) . "' width='12' height='12' />";
  2516. }
  2517. } else {
  2518. if ($item['type'] != 'dokeos_chapter' && $item['type'] != 'dokeos_module' && $item['type'] != 'dir') {
  2519. $html .= "&nbsp;<img id='toc_img_" . $item['id'] . "' src='" . $icon_name[$item['status']] . "' alt='" . substr($item['status'], 0, 1) . "' width='12' height='12' />";
  2520. }
  2521. }
  2522. $html .= "</div>";
  2523. if ($scorm_color_background != '') {
  2524. $html .= '</div>';
  2525. }
  2526. $color_counter++;
  2527. }
  2528. $html .= "</div>\n";
  2529. return $html;
  2530. }
  2531. /**
  2532. * Gets the learnpath maker name - generally the editor's name
  2533. * @return string Learnpath maker name
  2534. */
  2535. function get_maker() {
  2536. if ($this->debug > 0) {
  2537. error_log('New LP - In learnpath::get_maker()', 0);
  2538. }
  2539. if (!empty ($this->maker)) {
  2540. return $this->maker;
  2541. } else {
  2542. return '';
  2543. }
  2544. }
  2545. /**
  2546. * Gets the user-friendly message stored in $this->message
  2547. * @return string Message
  2548. */
  2549. function get_message() {
  2550. if ($this->debug > 0) {
  2551. error_log('New LP - In learnpath::get_message()', 0);
  2552. }
  2553. return $this->message;
  2554. }
  2555. /**
  2556. * Gets the learnpath name/title
  2557. * @return string Learnpath name/title
  2558. */
  2559. function get_name() {
  2560. if ($this->debug > 0) {
  2561. error_log('New LP - In learnpath::get_name()', 0);
  2562. }
  2563. if (!empty ($this->name)) {
  2564. return $this->name;
  2565. } else {
  2566. return 'N/A';
  2567. }
  2568. }
  2569. /**
  2570. * Gets a link to the resource from the present location, depending on item ID.
  2571. * @param string Type of link expected
  2572. * @param integer Learnpath item ID
  2573. * @return string Link to the lp_item resource
  2574. */
  2575. function get_link($type = 'http', $item_id = null) {
  2576. if ($this->debug > 0) {
  2577. error_log('New LP - In learnpath::get_link(' . $type . ',' . $item_id . ')', 0);
  2578. }
  2579. if (empty($item_id)) {
  2580. if ($this->debug > 2) {
  2581. error_log('New LP - In learnpath::get_link() - no item id given in learnpath::get_link(), using current: ' . $this->get_current_item_id(), 0);
  2582. }
  2583. $item_id = $this->get_current_item_id();
  2584. }
  2585. if (empty ($item_id)) {
  2586. if ($this->debug > 2) {
  2587. error_log('New LP - In learnpath::get_link() - no current item id found in learnpath object', 0);
  2588. }
  2589. //still empty, this means there was no item_id given and we are not in an object context or
  2590. //the object property is empty, return empty link
  2591. $item_id = $this->first();
  2592. return '';
  2593. }
  2594. $file = '';
  2595. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  2596. $lp_item_table = Database :: get_course_table(TABLE_LP_ITEM);
  2597. $lp_item_view_table = Database :: get_course_table(TABLE_LP_ITEM_VIEW);
  2598. $item_id = Database::escape_string($item_id);
  2599. $sel = "SELECT l.lp_type as ltype, l.path as lpath, li.item_type as litype, li.path as lipath, li.parameters as liparams " .
  2600. "FROM $lp_table l, $lp_item_table li WHERE li.id = $item_id AND li.lp_id = l.id";
  2601. if ($this->debug > 2) {
  2602. error_log('New LP - In learnpath::get_link() - selecting item ' . $sel, 0);
  2603. }
  2604. $res = Database::query($sel, __FILE__, __LINE__);
  2605. if (Database :: num_rows($res) > 0) {
  2606. $row = Database :: fetch_array($res);
  2607. //var_dump($row);
  2608. $lp_type = $row['ltype'];
  2609. $lp_path = $row['lpath'];
  2610. $lp_item_type = $row['litype'];
  2611. $lp_item_path = $row['lipath'];
  2612. $lp_item_params = $row['liparams'];
  2613. if (empty ($lp_item_params) && strpos($lp_item_path, '?') !== false) {
  2614. list ($lp_item_path, $lp_item_params) = explode('?', $lp_item_path);
  2615. }
  2616. //$lp_item_params = '?'.$lp_item_params;
  2617. //add ? if none - left commented to give freedom to scorm implementation
  2618. //if(substr($lp_item_params,0,1)!='?'){
  2619. // $lp_item_params = '?'.$lp_item_params;
  2620. //}
  2621. $sys_course_path = api_get_path(SYS_COURSE_PATH) . api_get_course_path();
  2622. if ($type == 'http') {
  2623. $course_path = api_get_path(WEB_COURSE_PATH) . api_get_course_path(); //web path
  2624. } else {
  2625. $course_path = $sys_course_path; //system path
  2626. }
  2627. //now go through the specific cases to get the end of the path
  2628. switch ($lp_type) {
  2629. case 1 :
  2630. if ($lp_item_type == 'dokeos_chapter') {
  2631. $file = 'lp_content.php?type=dir';
  2632. } else {
  2633. require_once ('resourcelinker.inc.php');
  2634. $file = rl_get_resource_link_for_learnpath(api_get_course_id(), $this->get_id(), $item_id);
  2635. // check how much attempts of a exercise exits in lp
  2636. $lp_item_id = $this->get_current_item_id();
  2637. $lp_view_id = $this->get_view_id();
  2638. $prevent_reinit = $this->items[$this->current]->get_prevent_reinit();
  2639. $list = $this->get_toc();
  2640. $type_quiz = false;
  2641. foreach ($list as $toc) {
  2642. if ($toc['id'] == $lp_item_id && ($toc['type'] == 'quiz')) {
  2643. $type_quiz = true;
  2644. }
  2645. }
  2646. if ($type_quiz) {
  2647. $lp_item_id = Database :: escape_string($lp_item_id);
  2648. $lp_view_id = Database :: escape_string($lp_view_id);
  2649. $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'";
  2650. $result = Database::query($sql, __FILE__, __LINE__);
  2651. $row_count = Database :: fetch_row($result);
  2652. $count_item_view = (int) $row_count[0];
  2653. $not_multiple_attempt = 0;
  2654. if ($prevent_reinit === 1 && $count_item_view > 0) {
  2655. $not_multiple_attempt = 1;
  2656. }
  2657. $file .= '&not_multiple_attempt=' . $not_multiple_attempt;
  2658. }
  2659. $tmp_array = explode("/", $file);
  2660. $document_name = $tmp_array[count($tmp_array) - 1];
  2661. if (strpos($document_name, '_DELETED_')) {
  2662. $file = 'blank.php?error=document_deleted';
  2663. }
  2664. }
  2665. break;
  2666. case 2 :
  2667. if ($this->debug > 2) {
  2668. error_log('New LP - In learnpath::get_link() ' . __LINE__ . ' - Item type: ' . $lp_item_type, 0);
  2669. }
  2670. if ($lp_item_type != 'dir') {
  2671. //Quite complex here:
  2672. //we want to make sure 'http://' (and similar) links can
  2673. //be loaded as is (withouth the Dokeos path in front) but
  2674. //some contents use this form: resource.htm?resource=http://blablabla
  2675. //which means we have to find a protocol at the path's start, otherwise
  2676. //it should not be considered as an external URL
  2677. //if($this->prerequisites_match($item_id)){
  2678. if (preg_match('#^[a-zA-Z]{2,5}://#', $lp_item_path) != 0) {
  2679. if ($this->debug > 2) {
  2680. error_log('New LP - In learnpath::get_link() ' . __LINE__ . ' - Found match for protocol in ' . $lp_item_path, 0);
  2681. }
  2682. //distant url, return as is
  2683. $file = $lp_item_path;
  2684. } else {
  2685. if ($this->debug > 2) {
  2686. error_log('New LP - In learnpath::get_link() ' . __LINE__ . ' - No starting protocol in ' . $lp_item_path, 0);
  2687. }
  2688. //prevent getting untranslatable urls
  2689. $lp_item_path = preg_replace('/%2F/', '/', $lp_item_path);
  2690. $lp_item_path = preg_replace('/%3A/', ':', $lp_item_path);
  2691. //prepare the path
  2692. $file = $course_path . '/scorm/' . $lp_path . '/' . $lp_item_path;
  2693. //TODO fix this for urls with protocol header
  2694. $file = str_replace('//', '/', $file);
  2695. $file = str_replace(':/', '://', $file);
  2696. if (substr($lp_path, -1) == '/') {
  2697. $lp_path = substr($lp_path, 0, -1);
  2698. }
  2699. if (!is_file(realpath($sys_course_path . '/scorm/' . $lp_path . '/' . $lp_item_path))) {
  2700. //if file not found
  2701. $decoded = html_entity_decode($lp_item_path);
  2702. list ($decoded) = explode('?', $decoded);
  2703. if (!is_file(realpath($sys_course_path . '/scorm/' . $lp_path . '/' . $decoded))) {
  2704. require_once ('resourcelinker.inc.php');
  2705. $file = rl_get_resource_link_for_learnpath(api_get_course_id(), $this->get_id(), $item_id);
  2706. if (empty($file)) {
  2707. $file = 'blank.php?error=document_not_found';
  2708. } else {
  2709. $tmp_array = explode("/", $file);
  2710. $document_name = $tmp_array[count($tmp_array) - 1];
  2711. if (strpos($document_name, '_DELETED_')) {
  2712. $file = 'blank.php?error=document_deleted';
  2713. }
  2714. }
  2715. } else {
  2716. $file = $course_path . '/scorm/' . $lp_path . '/' . $decoded;
  2717. }
  2718. }
  2719. }
  2720. //}else{
  2721. //prerequisites did not match
  2722. //$file = 'blank.php';
  2723. //}
  2724. //We want to use parameters if they were defined in the imsmanifest
  2725. if ($file != 'blank.php') {
  2726. $file .= (strstr($file, '?') === false ? '?' : '') . $lp_item_params;
  2727. }
  2728. } else {
  2729. $file = 'lp_content.php?type=dir';
  2730. }
  2731. break;
  2732. case 3 :
  2733. if ($this->debug > 2) {
  2734. error_log('New LP - In learnpath::get_link() ' . __LINE__ . ' - Item type: ' . $lp_item_type, 0);
  2735. }
  2736. //formatting AICC HACP append URL
  2737. $aicc_append = '?aicc_sid=' . urlencode(session_id()) . '&aicc_url=' . urlencode(api_get_path(WEB_CODE_PATH) . 'newscorm/aicc_hacp.php') . '&';
  2738. if ($lp_item_type != 'dir') {
  2739. //Quite complex here:
  2740. //we want to make sure 'http://' (and similar) links can
  2741. //be loaded as is (withouth the Dokeos path in front) but
  2742. //some contents use this form: resource.htm?resource=http://blablabla
  2743. //which means we have to find a protocol at the path's start, otherwise
  2744. //it should not be considered as an external URL
  2745. if (preg_match('#^[a-zA-Z]{2,5}://#', $lp_item_path) != 0) {
  2746. if ($this->debug > 2) {
  2747. error_log('New LP - In learnpath::get_link() ' . __LINE__ . ' - Found match for protocol in ' . $lp_item_path, 0);
  2748. }
  2749. //distant url, return as is
  2750. $file = $lp_item_path;
  2751. // Enabled and modified by Ivan Tcholakov, 16-OCT-2008.
  2752. /*
  2753. if(stristr($file,'<servername>')!==false){
  2754. $file = str_replace('<servername>',$course_path.'/scorm/'.$lp_path.'/',$lp_item_path);
  2755. }
  2756. */
  2757. if (stripos($file, '<servername>') !== false) {
  2758. //$file = str_replace('<servername>',$course_path.'/scorm/'.$lp_path.'/',$lp_item_path);
  2759. $web_course_path = str_replace('https://', '', str_replace('http://', '', $course_path));
  2760. $file = str_replace('<servername>', $web_course_path . '/scorm/' . $lp_path, $lp_item_path);
  2761. }
  2762. //
  2763. $file .= $aicc_append;
  2764. } else {
  2765. if ($this->debug > 2) {
  2766. error_log('New LP - In learnpath::get_link() ' . __LINE__ . ' - No starting protocol in ' . $lp_item_path, 0);
  2767. }
  2768. //prevent getting untranslatable urls
  2769. $lp_item_path = preg_replace('/%2F/', '/', $lp_item_path);
  2770. $lp_item_path = preg_replace('/%3A/', ':', $lp_item_path);
  2771. //prepare the path - lp_path might be unusable because it includes the "aicc" subdir name
  2772. $file = $course_path . '/scorm/' . $lp_path . '/' . $lp_item_path;
  2773. //TODO fix this for urls with protocol header
  2774. $file = str_replace('//', '/', $file);
  2775. $file = str_replace(':/', '://', $file);
  2776. $file .= $aicc_append;
  2777. }
  2778. } else {
  2779. $file = 'lp_content.php?type=dir';
  2780. }
  2781. break;
  2782. case 4 :
  2783. break;
  2784. default :
  2785. break;
  2786. }
  2787. }
  2788. if ($this->debug > 2) {
  2789. error_log('New LP - In learnpath::get_link() - returning "' . $file . '" from get_link', 0);
  2790. }
  2791. return $file;
  2792. }
  2793. /**
  2794. * Gets the latest usable view or generate a new one
  2795. * @param integer Optional attempt number. If none given, takes the highest from the lp_view table
  2796. * @return integer DB lp_view id
  2797. */
  2798. function get_view($attempt_num = 0) {
  2799. if ($this->debug > 0) {
  2800. error_log('New LP - In learnpath::get_view()', 0);
  2801. }
  2802. $search = '';
  2803. //use $attempt_num to enable multi-views management (disabled so far)
  2804. if ($attempt_num != 0 AND intval(strval($attempt_num)) == $attempt_num) {
  2805. $search = 'AND view_count = ' . $attempt_num;
  2806. }
  2807. //when missing $attempt_num, search for a unique lp_view record for this lp and user
  2808. $lp_view_table = Database :: get_course_table(TABLE_LP_VIEW);
  2809. $sql = "SELECT id, view_count FROM $lp_view_table " .
  2810. "WHERE lp_id = " . $this->get_id() . " " .
  2811. "AND user_id = " . $this->get_user_id() . " " .
  2812. $search .
  2813. " ORDER BY view_count DESC";
  2814. $res = Database::query($sql, __FILE__, __LINE__);
  2815. if (Database :: num_rows($res) > 0) {
  2816. $row = Database :: fetch_array($res);
  2817. $this->lp_view_id = $row['id'];
  2818. } else {
  2819. //no database record, create one
  2820. $sql = "INSERT INTO $lp_view_table(lp_id,user_id,view_count)" .
  2821. "VALUES (" . $this->get_id() . "," . $this->get_user_id() . ",1)";
  2822. $res = Database::query($sql, __FILE__, __LINE__);
  2823. $id = Database :: insert_id();
  2824. $this->lp_view_id = $id;
  2825. }
  2826. return $this->lp_view_id;
  2827. }
  2828. /**
  2829. * Gets the current view id
  2830. * @return integer View ID (from lp_view)
  2831. */
  2832. function get_view_id() {
  2833. if ($this->debug > 0) {
  2834. error_log('New LP - In learnpath::get_view_id()', 0);
  2835. }
  2836. if (!empty ($this->lp_view_id)) {
  2837. return $this->lp_view_id;
  2838. } else {
  2839. return 0;
  2840. }
  2841. }
  2842. /**
  2843. * Gets the update queue
  2844. * @return array Array containing IDs of items to be updated by JavaScript
  2845. */
  2846. function get_update_queue() {
  2847. if ($this->debug > 0) {
  2848. error_log('New LP - In learnpath::get_update_queue()', 0);
  2849. }
  2850. return $this->update_queue;
  2851. }
  2852. /**
  2853. * Gets the user ID
  2854. * @return integer User ID
  2855. */
  2856. function get_user_id() {
  2857. if ($this->debug > 0) {
  2858. error_log('New LP - In learnpath::get_user_id()', 0);
  2859. }
  2860. if (!empty ($this->user_id)) {
  2861. return $this->user_id;
  2862. } else {
  2863. return false;
  2864. }
  2865. }
  2866. /**
  2867. * Checks if any of the items has an audio element attached
  2868. * @return bool True or false
  2869. */
  2870. function has_audio() {
  2871. if ($this->debug > 1) {
  2872. error_log('New LP - In learnpath::has_audio()', 0);
  2873. }
  2874. $has = false;
  2875. foreach ($this->items as $i => $item) {
  2876. if (!empty ($this->items[$i]->audio)) {
  2877. $has = true;
  2878. break;
  2879. }
  2880. }
  2881. return $has;
  2882. }
  2883. /**
  2884. * Logs a message into a file
  2885. * @param string Message to log
  2886. * @return boolean True on success, false on error or if msg empty
  2887. */
  2888. function log($msg) {
  2889. if ($this->debug > 0) {
  2890. error_log('New LP - In learnpath::log()', 0);
  2891. }
  2892. //TODO
  2893. $this->error .= $msg . "\n";
  2894. return true;
  2895. }
  2896. /**
  2897. * Moves an item up and down at its level
  2898. * @param integer Item to move up and down
  2899. * @param string Direction 'up' or 'down'
  2900. * @return integer New display order, or false on error
  2901. */
  2902. function move_item($id, $direction) {
  2903. if ($this->debug > 0) {
  2904. error_log('New LP - In learnpath::move_item(' . $id . ',' . $direction . ')', 0);
  2905. }
  2906. if (empty ($id) or empty ($direction)) {
  2907. return false;
  2908. }
  2909. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  2910. $sql_sel = "
  2911. SELECT *
  2912. FROM " . $tbl_lp_item . "
  2913. WHERE id = " . $id;
  2914. $res_sel = Database::query($sql_sel, __FILE__, __LINE__);
  2915. //check if elem exists
  2916. if (Database :: num_rows($res_sel) < 1) {
  2917. return false;
  2918. }
  2919. //gather data
  2920. $row = Database :: fetch_array($res_sel);
  2921. $previous = $row['previous_item_id'];
  2922. $next = $row['next_item_id'];
  2923. $display = $row['display_order'];
  2924. $parent = $row['parent_item_id'];
  2925. $lp = $row['lp_id'];
  2926. //update the item (switch with previous/next one)
  2927. switch ($direction) {
  2928. case 'up' :
  2929. if ($this->debug > 2) {
  2930. error_log('Movement up detected', 0);
  2931. }
  2932. if ($display <= 1) { /*do nothing*/
  2933. } else {
  2934. $sql_sel2 = "SELECT *
  2935. FROM $tbl_lp_item
  2936. WHERE id = $previous";
  2937. if ($this->debug > 2) {
  2938. error_log('Selecting previous: ' . $sql_sel2, 0);
  2939. }
  2940. $res_sel2 = Database::query($sql_sel2, __FILE__, __LINE__);
  2941. if (Database :: num_rows($res_sel2) < 1) {
  2942. $previous_previous = 0;
  2943. }
  2944. //gather data
  2945. $row2 = Database :: fetch_array($res_sel2);
  2946. $previous_previous = $row2['previous_item_id'];
  2947. //update previous_previous item (switch "next" with current)
  2948. if ($previous_previous != 0) {
  2949. $sql_upd2 = "UPDATE $tbl_lp_item SET next_item_id = $id WHERE id = $previous_previous";
  2950. if ($this->debug > 2) {
  2951. error_log($sql_upd2, 0);
  2952. }
  2953. $res_upd2 = Database::query($sql_upd2, __FILE__, __LINE__);
  2954. }
  2955. //update previous item (switch with current)
  2956. if ($previous != 0) {
  2957. $sql_upd2 = "UPDATE $tbl_lp_item SET next_item_id = $next, previous_item_id = $id, display_order = display_order +1 WHERE id = $previous";
  2958. if ($this->debug > 2) {
  2959. error_log($sql_upd2, 0);
  2960. }
  2961. $res_upd2 = Database::query($sql_upd2, __FILE__, __LINE__);
  2962. }
  2963. //update current item (switch with previous)
  2964. if ($id != 0) {
  2965. $sql_upd2 = "UPDATE $tbl_lp_item SET next_item_id = $previous, previous_item_id = $previous_previous, display_order = display_order-1 WHERE id = $id";
  2966. if ($this->debug > 2) {
  2967. error_log($sql_upd2, 0);
  2968. }
  2969. $res_upd2 = Database::query($sql_upd2, __FILE__, __LINE__);
  2970. }
  2971. //update next item (new previous item)
  2972. if ($next != 0) {
  2973. $sql_upd2 = "UPDATE $tbl_lp_item SET previous_item_id = $previous WHERE id = $next";
  2974. if ($this->debug > 2) {
  2975. error_log($sql_upd2, 0);
  2976. }
  2977. $res_upd2 = Database::query($sql_upd2, __FILE__, __LINE__);
  2978. }
  2979. $display = $display -1;
  2980. }
  2981. break;
  2982. case 'down' :
  2983. if ($this->debug > 2) {
  2984. error_log('Movement down detected', 0);
  2985. }
  2986. if ($next == 0) { /*do nothing*/
  2987. } else {
  2988. $sql_sel2 = "SELECT * FROM $tbl_lp_item WHERE id = $next";
  2989. if ($this->debug > 2) {
  2990. error_log('Selecting next: ' . $sql_sel2, 0);
  2991. }
  2992. $res_sel2 = Database::query($sql_sel2, __FILE__, __LINE__);
  2993. if (Database :: num_rows($res_sel2) < 1) {
  2994. $next_next = 0;
  2995. }
  2996. //gather data
  2997. $row2 = Database :: fetch_array($res_sel2);
  2998. $next_next = $row2['next_item_id'];
  2999. //update previous item (switch with current)
  3000. if ($previous != 0) {
  3001. $sql_upd2 = "UPDATE $tbl_lp_item SET next_item_id = $next WHERE id = $previous";
  3002. $res_upd2 = Database::query($sql_upd2, __FILE__, __LINE__);
  3003. }
  3004. //update current item (switch with previous)
  3005. if ($id != 0) {
  3006. $sql_upd2 = "UPDATE $tbl_lp_item SET previous_item_id = $next, next_item_id = $next_next, display_order = display_order+1 WHERE id = $id";
  3007. $res_upd2 = Database::query($sql_upd2, __FILE__, __LINE__);
  3008. }
  3009. //update next item (new previous item)
  3010. if ($next != 0) {
  3011. $sql_upd2 = "UPDATE $tbl_lp_item SET previous_item_id = $previous, next_item_id = $id, display_order = display_order-1 WHERE id = $next";
  3012. $res_upd2 = Database::query($sql_upd2, __FILE__, __LINE__);
  3013. }
  3014. //update next_next item (switch "previous" with current)
  3015. if ($next_next != 0) {
  3016. $sql_upd2 = "UPDATE $tbl_lp_item SET previous_item_id = $id WHERE id = $next_next";
  3017. $res_upd2 = Database::query($sql_upd2, __FILE__, __LINE__);
  3018. }
  3019. $display = $display +1;
  3020. }
  3021. break;
  3022. default :
  3023. return false;
  3024. }
  3025. return $display;
  3026. }
  3027. /**
  3028. * Move a learnpath up (display_order)
  3029. * @param integer Learnpath ID
  3030. */
  3031. function move_up($lp_id) {
  3032. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3033. $sql = "SELECT * FROM $lp_table ORDER BY display_order";
  3034. $res = Database::query($sql, __FILE__, __LINE__);
  3035. if ($res === false)
  3036. return false;
  3037. $lps = array ();
  3038. $lp_order = array ();
  3039. $num = Database :: num_rows($res);
  3040. //first check the order is correct, globally (might be wrong because
  3041. //of versions < 1.8.4)
  3042. if ($num > 0) {
  3043. $i = 1;
  3044. while ($row = Database :: fetch_array($res)) {
  3045. if ($row['display_order'] != $i) { //if we find a gap in the order, we need to fix it
  3046. $need_fix = true;
  3047. $sql_u = "UPDATE $lp_table SET display_order = $i WHERE id = " . $row['id'];
  3048. $res_u = Database::query($sql_u, __FILE__, __LINE__);
  3049. }
  3050. $row['display_order'] = $i;
  3051. $lps[$row['id']] = $row;
  3052. $lp_order[$i] = $row['id'];
  3053. $i++;
  3054. }
  3055. }
  3056. if ($num > 1) //if there's only one element, no need to sort
  3057. {
  3058. $order = $lps[$lp_id]['display_order'];
  3059. if ($order > 1) //if it's the first element, no need to move up
  3060. {
  3061. $sql_u1 = "UPDATE $lp_table SET display_order = $order WHERE id = " . $lp_order[$order -1];
  3062. $res_u1 = Database::query($sql_u1, __FILE__, __LINE__);
  3063. $sql_u2 = "UPDATE $lp_table SET display_order = " . ($order -1) . " WHERE id = " . $lp_id;
  3064. $res_u2 = Database::query($sql_u2, __FILE__, __LINE__);
  3065. }
  3066. }
  3067. }
  3068. /**
  3069. * Move a learnpath down (display_order)
  3070. * @param integer Learnpath ID
  3071. */
  3072. function move_down($lp_id) {
  3073. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3074. $sql = "SELECT * FROM $lp_table ORDER BY display_order";
  3075. $res = Database::query($sql, __FILE__, __LINE__);
  3076. if ($res === false)
  3077. return false;
  3078. $lps = array ();
  3079. $lp_order = array ();
  3080. $num = Database :: num_rows($res);
  3081. $max = 0;
  3082. //first check the order is correct, globally (might be wrong because
  3083. //of versions < 1.8.4)
  3084. if ($num > 0) {
  3085. $i = 1;
  3086. while ($row = Database :: fetch_array($res)) {
  3087. $max = $i;
  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, __FILE__, __LINE__);
  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. {
  3101. $order = $lps[$lp_id]['display_order'];
  3102. if ($order < $max) //if it's the first element, no need to move up
  3103. {
  3104. $sql_u1 = "UPDATE $lp_table SET display_order = $order WHERE id = " . $lp_order[$order +1];
  3105. $res_u1 = Database::query($sql_u1, __FILE__, __LINE__);
  3106. $sql_u2 = "UPDATE $lp_table SET display_order = " . ($order +1) . " WHERE id = " . $lp_id;
  3107. $res_u2 = Database::query($sql_u2, __FILE__, __LINE__);
  3108. }
  3109. }
  3110. }
  3111. /**
  3112. * Updates learnpath attributes to point to the next element
  3113. * The last part is similar to set_current_item but processing the other way around
  3114. */
  3115. function next() {
  3116. if ($this->debug > 0) {
  3117. error_log('New LP - In learnpath::next()', 0);
  3118. }
  3119. $this->last = $this->get_current_item_id();
  3120. $this->items[$this->last]->save(false, $this->prerequisites_match($this->last));
  3121. $this->autocomplete_parents($this->last);
  3122. $new_index = $this->get_next_index();
  3123. if ($this->debug > 2) {
  3124. error_log('New LP - New index: ' . $new_index, 0);
  3125. }
  3126. $this->index = $new_index;
  3127. if ($this->debug > 2) {
  3128. error_log('New LP - Now having orderedlist[' . $new_index . '] = ' . $this->ordered_items[$new_index], 0);
  3129. }
  3130. $this->current = $this->ordered_items[$new_index];
  3131. if ($this->debug > 2) {
  3132. error_log('New LP - new item id is ' . $this->current . '-' . $this->get_current_item_id(), 0);
  3133. }
  3134. }
  3135. /**
  3136. * Open a resource = initialise all local variables relative to this resource. Depending on the child
  3137. * class, this might be redefined to allow several behaviours depending on the document type.
  3138. * @param integer Resource ID
  3139. * @return boolean True on success, false otherwise
  3140. */
  3141. function open($id) {
  3142. if ($this->debug > 0) {
  3143. error_log('New LP - In learnpath::open()', 0);
  3144. }
  3145. //TODO
  3146. //set the current resource attribute to this resource
  3147. //switch on element type (redefine in child class?)
  3148. //set status for this item to "opened"
  3149. //start timer
  3150. //initialise score
  3151. $this->index = 0; //or = the last item seen (see $this->last)
  3152. }
  3153. /**
  3154. * Check that all prerequisites are fulfilled. Returns true and an empty string on succes, returns false
  3155. * and the prerequisite string on error.
  3156. * This function is based on the rules for aicc_script language as described in the SCORM 1.2 CAM documentation page 108.
  3157. * @param integer Optional item ID. If none given, uses the current open item.
  3158. * @return boolean True if prerequisites are matched, false otherwise
  3159. * @return string Empty string if true returned, prerequisites string otherwise.
  3160. */
  3161. function prerequisites_match($item = null) {
  3162. if ($this->debug > 0) {
  3163. error_log('New LP - In learnpath::prerequisites_match()', 0);
  3164. }
  3165. if (empty ($item)) {
  3166. $item = $this->current;
  3167. }
  3168. if (is_object($this->items[$item])) {
  3169. $prereq_string = $this->items[$item]->get_prereq_string();
  3170. if (empty ($prereq_string)) {
  3171. return true;
  3172. }
  3173. //clean spaces
  3174. $prereq_string = str_replace(' ', '', $prereq_string);
  3175. if ($this->debug > 0) {
  3176. error_log('Found prereq_string: ' . $prereq_string, 0);
  3177. }
  3178. //now send to the parse_prereq() function that will check this component's prerequisites
  3179. $result = $this->items[$item]->parse_prereq($prereq_string, $this->items, $this->refs_list, $this->get_user_id());
  3180. if ($result === false) {
  3181. $this->set_error_msg($this->items[$item]->prereq_alert);
  3182. }
  3183. } else {
  3184. $result = true;
  3185. if ($this->debug > 1) {
  3186. error_log('New LP - $this->items[' . $item . '] was not an object', 0);
  3187. }
  3188. }
  3189. if ($this->debug > 1) {
  3190. error_log('New LP - End of prerequisites_match(). Error message is now ' . $this->error, 0);
  3191. }
  3192. return $result;
  3193. }
  3194. /**
  3195. * Updates learnpath attributes to point to the previous element
  3196. * The last part is similar to set_current_item but processing the other way around
  3197. */
  3198. function previous() {
  3199. if ($this->debug > 0) {
  3200. error_log('New LP - In learnpath::previous()', 0);
  3201. }
  3202. $this->last = $this->get_current_item_id();
  3203. $this->items[$this->last]->save(false, $this->prerequisites_match($this->last));
  3204. $this->autocomplete_parents($this->last);
  3205. $new_index = $this->get_previous_index();
  3206. $this->index = $new_index;
  3207. $this->current = $this->ordered_items[$new_index];
  3208. }
  3209. /**
  3210. * Publishes a learnpath. This basically means show or hide the learnpath
  3211. * to normal users.
  3212. * Can be used as abstract
  3213. * @param integer Learnpath ID
  3214. * @param string New visibility
  3215. */
  3216. function toggle_visibility($lp_id, $set_visibility = 1) {
  3217. //if($this->debug>0){error_log('New LP - In learnpath::toggle_visibility()',0);}
  3218. $action = 'visible';
  3219. if ($set_visibility != 1) {
  3220. $action = 'invisible';
  3221. }
  3222. return api_item_property_update(api_get_course_info(), TOOL_LEARNPATH, $lp_id, $action, api_get_user_id());
  3223. }
  3224. /**
  3225. * Publishes a learnpath. This basically means show or hide the learnpath
  3226. * on the course homepage
  3227. * Can be used as abstract
  3228. * @param integer Learnpath ID
  3229. * @param string New visibility
  3230. */
  3231. function toggle_publish($lp_id, $set_visibility = 'v') {
  3232. //if($this->debug>0){error_log('New LP - In learnpath::toggle_publish()',0);}
  3233. $tbl_lp = Database :: get_course_table(TABLE_LP_MAIN);
  3234. $sql = "SELECT * FROM $tbl_lp where id=$lp_id";
  3235. $result = Database::query($sql, __FILE__, __LINE__);
  3236. $row = Database :: fetch_array($result);
  3237. $name = domesticate($row['name']);
  3238. if ($set_visibility == 'i') {
  3239. $s = $name . " " . get_lang('_no_published');
  3240. $dialogBox = $s;
  3241. $v = 0;
  3242. }
  3243. if ($set_visibility == 'v') {
  3244. $s = $name . " " . get_lang('_published');
  3245. $dialogBox = $s;
  3246. $v = 1;
  3247. }
  3248. $tbl_tool = Database :: get_course_table(TABLE_TOOL_LIST);
  3249. $link = 'newscorm/lp_controller.php?action=view&lp_id=' . $lp_id;
  3250. $sql = "SELECT * FROM $tbl_tool where name='$name' and image='scormbuilder.gif' and link LIKE '$link%'";
  3251. $result = Database::query($sql, __FILE__, __LINE__);
  3252. $num = Database :: num_rows($result);
  3253. $row2 = Database :: fetch_array($result);
  3254. //if($this->debug>2){error_log('New LP - '.$sql.' - '.$num,0);}
  3255. if (($set_visibility == 'i') && ($num > 0)) {
  3256. $sql = "DELETE FROM $tbl_tool WHERE (name='$name' and image='scormbuilder.gif' and link LIKE '$link%')";
  3257. }
  3258. elseif (($set_visibility == 'v') && ($num == 0)) {
  3259. $sql = "INSERT INTO $tbl_tool (name, link, image, visibility, admin, address, added_tool) VALUES ('$name','newscorm/lp_controller.php?action=view&lp_id=$lp_id','scormbuilder.gif','$v','0','pastillegris.gif',0)";
  3260. } else {
  3261. //parameter and database incompatible, do nothing
  3262. }
  3263. $result = Database::query($sql, __FILE__, __LINE__);
  3264. //if($this->debug>2){error_log('New LP - Leaving learnpath::toggle_visibility: '.$sql,0);}
  3265. }
  3266. /**
  3267. * Restart the whole learnpath. Return the URL of the first element.
  3268. * Make sure the results are saved with anoter method. This method should probably be
  3269. * redefined in children classes.
  3270. * To use a similar method statically, use the create_new_attempt() method
  3271. * @return string URL to load in the viewer
  3272. */
  3273. function restart() {
  3274. if ($this->debug > 0) {
  3275. error_log('New LP - In learnpath::restart()', 0);
  3276. }
  3277. //TODO
  3278. //call autosave method to save the current progress
  3279. //$this->index = 0;
  3280. $lp_view_table = Database :: get_course_table(TABLE_LP_VIEW);
  3281. $sql = "INSERT INTO $lp_view_table (lp_id, user_id, view_count) " .
  3282. "VALUES (" . $this->lp_id . "," . $this->get_user_id() . "," . ($this->attempt + 1) . ")";
  3283. if ($this->debug > 2) {
  3284. error_log('New LP - Inserting new lp_view for restart: ' . $sql, 0);
  3285. }
  3286. $res = Database::query($sql, __FILE__, __LINE__);
  3287. if ($view_id = Database :: insert_id($res)) {
  3288. $this->lp_view_id = $view_id;
  3289. $this->attempt = $this->attempt + 1;
  3290. } else {
  3291. $this->error = 'Could not insert into item_view table...';
  3292. return false;
  3293. }
  3294. $this->autocomplete_parents($this->current);
  3295. foreach ($this->items as $index => $dummy) {
  3296. $this->items[$index]->restart();
  3297. $this->items[$index]->set_lp_view($this->lp_view_id);
  3298. }
  3299. $this->first();
  3300. return true;
  3301. }
  3302. /**
  3303. * Saves the current item
  3304. * @return boolean
  3305. */
  3306. function save_current() {
  3307. if ($this->debug > 0) {
  3308. error_log('New LP - In learnpath::save_current()', 0);
  3309. }
  3310. //TODO do a better check on the index pointing to the right item (it is supposed to be working
  3311. // on $ordered_items[] but not sure it's always safe to use with $items[])
  3312. if ($this->debug > 2) {
  3313. error_log('New LP - save_current() saving item ' . $this->current, 0);
  3314. }
  3315. if ($this->debug > 2) {
  3316. error_log('' . print_r($this->items, true), 0);
  3317. }
  3318. if (is_object($this->items[$this->current])) {
  3319. //$res = $this->items[$this->current]->save(false);
  3320. $res = $this->items[$this->current]->save(false, $this->prerequisites_match($this->current));
  3321. $this->autocomplete_parents($this->current);
  3322. $status = $this->items[$this->current]->get_status();
  3323. $this->append_message('new_item_status: ' . $status);
  3324. $this->update_queue[$this->current] = $status;
  3325. return $res;
  3326. }
  3327. return false;
  3328. }
  3329. /**
  3330. * Saves the given item
  3331. * @param integer Item ID. Optional (will take from $_REQUEST if null)
  3332. * @param boolean Save from url params (true) or from current attributes (false). Optional. Defaults to true
  3333. * @return boolean
  3334. */
  3335. function save_item($item_id = null, $from_outside = true) {
  3336. if ($this->debug > 0) {
  3337. error_log('New LP - In learnpath::save_item(' . $item_id . ',' . $from_outside . ')', 0);
  3338. }
  3339. //TODO do a better check on the index pointing to the right item (it is supposed to be working
  3340. // on $ordered_items[] but not sure it's always safe to use with $items[])
  3341. if (empty ($item_id)) {
  3342. $item_id = $this->escape_string($_REQUEST['id']);
  3343. }
  3344. if (empty ($item_id)) {
  3345. $item_id = $this->get_current_item_id();
  3346. }
  3347. if ($this->debug > 2) {
  3348. error_log('New LP - save_current() saving item ' . $item_id, 0);
  3349. }
  3350. if (is_object($this->items[$item_id])) {
  3351. $res = $this->items[$item_id]->save($from_outside, $this->prerequisites_match($item_id));
  3352. //$res = $this->items[$item_id]->save($from_outside);
  3353. $this->autocomplete_parents($item_id);
  3354. $status = $this->items[$item_id]->get_status();
  3355. $this->append_message('new_item_status: ' . $status);
  3356. $this->update_queue[$item_id] = $status;
  3357. return $res;
  3358. }
  3359. return false;
  3360. }
  3361. /**
  3362. * Saves the last item seen's ID only in case
  3363. */
  3364. function save_last()
  3365. {
  3366. if ($this->debug > 0) {
  3367. error_log('New LP - In learnpath::save_last()', 0);
  3368. }
  3369. $table = Database :: get_course_table(TABLE_LP_VIEW);
  3370. if (isset ($this->current)) {
  3371. if ($this->debug > 2) {
  3372. error_log('New LP - Saving current item (' . $this->current . ') for later review', 0);
  3373. }
  3374. $sql = "UPDATE $table SET last_item = " . Database::escape_string($this->get_current_item_id()). " " .
  3375. "WHERE lp_id = " . $this->get_id() . " AND user_id = " . $this->get_user_id();
  3376. if ($this->debug > 2) {
  3377. error_log('New LP - Saving last item seen : ' . $sql, 0);
  3378. }
  3379. $res = Database::query($sql, __FILE__, __LINE__);
  3380. }
  3381. //save progress
  3382. list ($progress, $text) = $this->get_progress_bar_text('%');
  3383. if ($progress >= 0 AND $progress <= 100) {
  3384. $progress = (int) $progress;
  3385. $sql = "UPDATE $table SET progress = $progress " .
  3386. "WHERE lp_id = " . $this->get_id() . " AND " .
  3387. "user_id = " . $this->get_user_id();
  3388. $res = Database::query($sql, __FILE__, __LINE__); //ignore errors as some tables might not have the progress field just yet
  3389. $this->progress_db = $progress;
  3390. }
  3391. }
  3392. /**
  3393. * Sets the current item ID (checks if valid and authorized first)
  3394. * @param integer New item ID. If not given or not authorized, defaults to current
  3395. */
  3396. function set_current_item($item_id = null) {
  3397. if ($this->debug > 0) {
  3398. error_log('New LP - In learnpath::set_current_item(' . $item_id . ')', 0);
  3399. }
  3400. if (empty ($item_id)) {
  3401. if ($this->debug > 2) {
  3402. error_log('New LP - No new current item given, ignore...', 0);
  3403. }
  3404. //do nothing
  3405. } else {
  3406. if ($this->debug > 2) {
  3407. error_log('New LP - New current item given is ' . $item_id . '...', 0);
  3408. }
  3409. if (is_numeric($item_id)) {
  3410. $item_id = $this->escape_string($item_id);
  3411. //TODO check in database here
  3412. $this->last = $this->current;
  3413. $this->current = $item_id;
  3414. //TODO update $this->index as well
  3415. foreach ($this->ordered_items as $index => $item) {
  3416. if ($item == $this->current) {
  3417. $this->index = $index;
  3418. break;
  3419. }
  3420. }
  3421. if ($this->debug > 2) {
  3422. error_log('New LP - set_current_item(' . $item_id . ') done. Index is now : ' . $this->index, 0);
  3423. }
  3424. } else {
  3425. error_log('New LP - set_current_item(' . $item_id . ') failed. Not a numeric value: ', 0);
  3426. }
  3427. }
  3428. }
  3429. /**
  3430. * Sets the encoding
  3431. * @param string New encoding
  3432. */
  3433. function set_encoding($enc = 'ISO-8859-15') {
  3434. if ($this->debug > 0) {
  3435. error_log('New LP - In learnpath::set_encoding()', 0);
  3436. }
  3437. $enc = strtoupper($enc);
  3438. $encodings = array (
  3439. 'UTF-8',
  3440. 'ISO-8859-1',
  3441. 'ISO-8859-15',
  3442. 'cp1251',
  3443. 'cp1252',
  3444. 'KOI8-R',
  3445. 'BIG5',
  3446. 'GB2312',
  3447. 'Shift_JIS',
  3448. 'EUC-JP',
  3449. ''
  3450. );
  3451. if (in_array($enc, $encodings)) {
  3452. $lp = $this->get_id();
  3453. if ($lp != 0) {
  3454. $tbl_lp = Database :: get_course_table(TABLE_LP_MAIN);
  3455. $sql = "UPDATE $tbl_lp SET default_encoding = '$enc' WHERE id = " . $lp;
  3456. $res = Database::query($sql, __FILE__, __LINE__);
  3457. return $res;
  3458. }
  3459. }
  3460. return false;
  3461. }
  3462. /**
  3463. * Sets the JS lib setting in the database directly.
  3464. * This is the JavaScript library file this lp needs to load on startup
  3465. * @param string Proximity setting
  3466. */
  3467. function set_jslib($lib = '') {
  3468. if ($this->debug > 0) {
  3469. error_log('New LP - In learnpath::set_jslib()', 0);
  3470. }
  3471. $lp = $this->get_id();
  3472. if ($lp != 0) {
  3473. $tbl_lp = Database :: get_course_table(TABLE_LP_MAIN);
  3474. $sql = "UPDATE $tbl_lp SET js_lib = '$lib' WHERE id = " . $lp;
  3475. $res = Database::query($sql, __FILE__, __LINE__);
  3476. return $res;
  3477. } else {
  3478. return false;
  3479. }
  3480. }
  3481. /**
  3482. * Sets the name of the LP maker (publisher) (and save)
  3483. * @param string Optional string giving the new content_maker of this learnpath
  3484. */
  3485. function set_maker($name = '') {
  3486. if ($this->debug > 0) {
  3487. error_log('New LP - In learnpath::set_maker()', 0);
  3488. }
  3489. if (empty ($name))
  3490. return false;
  3491. $this->maker = $this->escape_string($name);
  3492. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3493. $lp_id = $this->get_id();
  3494. $sql = "UPDATE $lp_table SET content_maker = '" . $this->maker . "' WHERE id = '$lp_id'";
  3495. if ($this->debug > 2) {
  3496. error_log('New LP - lp updated with new content_maker : ' . $this->maker, 0);
  3497. }
  3498. //$res = Database::query($sql);
  3499. $res = Database::query($sql, __FILE__, __LINE__);
  3500. return true;
  3501. }
  3502. /**
  3503. * Sets the name of the current learnpath (and save)
  3504. * @param string Optional string giving the new name of this learnpath
  3505. */
  3506. function set_name($name = '') {
  3507. if ($this->debug > 0) {
  3508. error_log('New LP - In learnpath::set_name()', 0);
  3509. }
  3510. if (empty ($name))
  3511. return false;
  3512. $this->name = $this->escape_string($name);
  3513. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3514. $lp_id = $this->get_id();
  3515. $sql = "UPDATE $lp_table SET name = '" . $this->name . "' WHERE id = '$lp_id'";
  3516. if ($this->debug > 2) {
  3517. error_log('New LP - lp updated with new name : ' . $this->name, 0);
  3518. }
  3519. //$res = Database::query($sql);
  3520. $res = Database::query($sql, __FILE__, __LINE__);
  3521. // if the lp is visible on the homepage, change his name there
  3522. if (Database::affected_rows()) {
  3523. $table = Database :: get_course_table(TABLE_TOOL_LIST);
  3524. $sql = 'UPDATE ' . $table . ' SET
  3525. name = "' . $this->name . '"
  3526. WHERE link = "newscorm/lp_controller.php?action=view&lp_id=' . $lp_id . '"';
  3527. Database::query($sql, __FILE__, __LINE__);
  3528. }
  3529. return true;
  3530. }
  3531. /**
  3532. * Set index specified prefix terms for all items in this path
  3533. * @param string Comma-separated list of terms
  3534. * @param char Xapian term prefix
  3535. * @return boolean False on error, true otherwise
  3536. */
  3537. function set_terms_by_prefix($terms_string, $prefix) {
  3538. if (api_get_setting('search_enabled') !== 'true')
  3539. return FALSE;
  3540. $terms_string = trim($terms_string);
  3541. $terms = explode(',', $terms_string);
  3542. array_walk($terms, 'trim_value');
  3543. $stored_terms = $this->get_common_index_terms_by_prefix($prefix);
  3544. //var_dump($stored_terms);
  3545. //var_dump($terms);
  3546. // don't do anything if no change, verify only at DB, not the search engine
  3547. if ((count(array_diff($terms, $stored_terms)) == 0) && (count(array_diff($stored_terms, $terms)) == 0))
  3548. return FALSE;
  3549. require_once ('xapian.php'); //TODO try catch every xapian use or make wrappers on api
  3550. require_once (api_get_path(LIBRARY_PATH) . 'search/DokeosIndexer.class.php');
  3551. require_once (api_get_path(LIBRARY_PATH) . 'search/xapian/XapianQuery.php');
  3552. require_once (api_get_path(LIBRARY_PATH) . 'search/IndexableChunk.class.php');
  3553. $items_table = Database :: get_course_table(TABLE_LP_ITEM);
  3554. //TODO: make query secure agains XSS : use member attr instead of post var
  3555. $lp_id = intval($_POST['lp_id']);
  3556. $sql = "SELECT * FROM $items_table WHERE lp_id = $lp_id";
  3557. $result = Database::query($sql);
  3558. $di = new DokeosIndexer();
  3559. while ($lp_item = Database :: fetch_array($result)) {
  3560. // get search_did
  3561. $tbl_se_ref = Database :: get_main_table(TABLE_MAIN_SEARCH_ENGINE_REF);
  3562. $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';
  3563. $sql = sprintf($sql, $tbl_se_ref, $this->cc, TOOL_LEARNPATH, $lp_id, $lp_item['id']);
  3564. $res = Database::query($sql, __FILE__, __LINE__);
  3565. if (Database::num_rows($res)>0) {
  3566. $se_ref = Database :: fetch_array($res);
  3567. // compare terms
  3568. $doc = $di->get_document($se_ref['search_did']);
  3569. $xapian_terms = xapian_get_doc_terms($doc, $prefix);
  3570. //var_dump($xapian_terms);
  3571. $xterms = array ();
  3572. foreach ($xapian_terms as $xapian_term)
  3573. $xterms[] = substr($xapian_term['name'], 1);
  3574. $dterms = $terms;
  3575. //var_dump($xterms);
  3576. //var_dump($dterms);
  3577. $missing_terms = array_diff($dterms, $xterms);
  3578. $deprecated_terms = array_diff($xterms, $dterms);
  3579. // save it to search engine
  3580. foreach ($missing_terms as $term) {
  3581. $doc->add_term($prefix . $term, 1);
  3582. }
  3583. foreach ($deprecated_terms as $term) {
  3584. $doc->remove_term($prefix . $term);
  3585. }
  3586. $di->getDb()->replace_document((int) $se_ref['search_did'], $doc);
  3587. $di->getDb()->flush();
  3588. }
  3589. }
  3590. return true;
  3591. }
  3592. /**
  3593. * Sets the theme of the LP (local/remote) (and save)
  3594. * @param string Optional string giving the new theme of this learnpath
  3595. * @return bool returns true if theme name is not empty
  3596. */
  3597. function set_theme($name = '') {
  3598. if ($this->debug > 0) {
  3599. error_log('New LP - In learnpath::set_theme()', 0);
  3600. }
  3601. $this->theme = $this->escape_string($name);
  3602. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3603. $lp_id = $this->get_id();
  3604. $sql = "UPDATE $lp_table SET theme = '" . $this->theme . "' WHERE id = '$lp_id'";
  3605. if ($this->debug > 2) {
  3606. error_log('New LP - lp updated with new theme : ' . $this->theme, 0);
  3607. }
  3608. //$res = Database::query($sql);
  3609. $res = Database::query($sql, __FILE__, __LINE__);
  3610. return true;
  3611. }
  3612. /**
  3613. * Sets the image of an LP (and save)
  3614. * @param string Optional string giving the new image of this learnpath
  3615. * @return bool returns true if theme name is not empty
  3616. */
  3617. function set_preview_image($name = '') {
  3618. if ($this->debug > 0) {
  3619. error_log('New LP - In learnpath::set_preview_image()', 0);
  3620. }
  3621. $this->preview_image = $this->escape_string($name);
  3622. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3623. $lp_id = $this->get_id();
  3624. $sql = "UPDATE $lp_table SET preview_image = '" . $this->preview_image . "' WHERE id = '$lp_id'";
  3625. if ($this->debug > 2) {
  3626. error_log('New LP - lp updated with new preview image : ' . $this->preview_image, 0);
  3627. }
  3628. $res = Database::query($sql, __FILE__, __LINE__);
  3629. return true;
  3630. }
  3631. /**
  3632. * Sets the author of a LP (and save)
  3633. * @param string Optional string giving the new author of this learnpath
  3634. * @return bool returns true if author's name is not empty
  3635. */
  3636. function set_author($name = '') {
  3637. if ($this->debug > 0) {
  3638. error_log('New LP - In learnpath::set_author()', 0);
  3639. }
  3640. $this->author = $this->escape_string($name);
  3641. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3642. $lp_id = $this->get_id();
  3643. $sql = "UPDATE $lp_table SET author = '" . $this->author . "' WHERE id = '$lp_id'";
  3644. if ($this->debug > 2) {
  3645. error_log('New LP - lp updated with new preview author : ' . $this->author, 0);
  3646. }
  3647. $res = Database::query($sql, __FILE__, __LINE__);
  3648. return true;
  3649. }
  3650. /**
  3651. * Sets the location/proximity of the LP (local/remote) (and save)
  3652. * @param string Optional string giving the new location of this learnpath
  3653. */
  3654. function set_proximity($name = '') {
  3655. if ($this->debug > 0) {
  3656. error_log('New LP - In learnpath::set_proximity()', 0);
  3657. }
  3658. if (empty ($name))
  3659. return false;
  3660. $this->proximity = $this->escape_string($name);
  3661. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3662. $lp_id = $this->get_id();
  3663. $sql = "UPDATE $lp_table SET content_local = '" . $this->proximity . "' WHERE id = '$lp_id'";
  3664. if ($this->debug > 2) {
  3665. error_log('New LP - lp updated with new proximity : ' . $this->proximity, 0);
  3666. }
  3667. //$res = Database::query($sql);
  3668. $res = Database::query($sql, __FILE__, __LINE__);
  3669. return true;
  3670. }
  3671. /**
  3672. * Sets the previous item ID to a given ID. Generally, this should be set to the previous 'current' item
  3673. * @param integer DB ID of the item
  3674. */
  3675. function set_previous_item($id) {
  3676. if ($this->debug > 0) {
  3677. error_log('New LP - In learnpath::set_previous_item()', 0);
  3678. }
  3679. $this->last = $id;
  3680. }
  3681. /**
  3682. * Sets the object's error message
  3683. * @param string Error message. If empty, reinits the error string
  3684. * @return void
  3685. */
  3686. function set_error_msg($error = '') {
  3687. if ($this->debug > 0) {
  3688. error_log('New LP - In learnpath::set_error_msg()', 0);
  3689. }
  3690. if (empty ($error)) {
  3691. $this->error = '';
  3692. } else {
  3693. $this->error .= $error;
  3694. }
  3695. }
  3696. /**
  3697. * Launches the current item if not 'sco' (starts timer and make sure there is a record ready in the DB)
  3698. *
  3699. */
  3700. function start_current_item($allow_new_attempt = false) {
  3701. if ($this->debug > 0) {
  3702. error_log('New LP - In learnpath::start_current_item()', 0);
  3703. }
  3704. if ($this->current != 0 AND is_object($this->items[$this->current])) {
  3705. $type = $this->get_type();
  3706. $item_type = $this->items[$this->current]->get_type();
  3707. if (($type == 2 && $item_type != 'sco') OR ($type == 3 && $item_type != 'au') OR ($type == 1 && $item_type != TOOL_QUIZ && $item_type != TOOL_HOTPOTATOES)) {
  3708. $this->items[$this->current]->open($allow_new_attempt);
  3709. $this->autocomplete_parents($this->current);
  3710. $prereq_check = $this->prerequisites_match($this->current);
  3711. $this->items[$this->current]->save(false, $prereq_check);
  3712. //$this->update_queue[$this->last] = $this->items[$this->last]->get_status();
  3713. } else {
  3714. //if sco, then it is supposed to have been updated by some other call
  3715. }
  3716. if ($item_type == 'sco') {
  3717. $this->items[$this->current]->restart();
  3718. }
  3719. }
  3720. if ($this->debug > 0) {
  3721. error_log('New LP - End of learnpath::start_current_item()', 0);
  3722. }
  3723. return true;
  3724. }
  3725. /**
  3726. * Stops the processing and counters for the old item (as held in $this->last)
  3727. * @param
  3728. */
  3729. function stop_previous_item() {
  3730. if ($this->debug > 0) {
  3731. error_log('New LP - In learnpath::stop_previous_item()', 0);
  3732. }
  3733. if ($this->last != 0 AND $this->last != $this->current AND is_object($this->items[$this->last])) {
  3734. if ($this->debug > 2) {
  3735. error_log('New LP - In learnpath::stop_previous_item() - ' . $this->last . ' is object', 0);
  3736. }
  3737. switch ($this->get_type()) {
  3738. case '3' :
  3739. if ($this->items[$this->last]->get_type() != 'au') {
  3740. if ($this->debug > 2) {
  3741. error_log('New LP - In learnpath::stop_previous_item() - ' . $this->last . ' in lp_type 3 is <> au', 0);
  3742. }
  3743. $this->items[$this->last]->close();
  3744. //$this->autocomplete_parents($this->last);
  3745. //$this->update_queue[$this->last] = $this->items[$this->last]->get_status();
  3746. } else {
  3747. if ($this->debug > 2) {
  3748. error_log('New LP - In learnpath::stop_previous_item() - Item is an AU, saving is managed by AICC signals', 0);
  3749. }
  3750. }
  3751. case '2' :
  3752. if ($this->items[$this->last]->get_type() != 'sco') {
  3753. if ($this->debug > 2) {
  3754. error_log('New LP - In learnpath::stop_previous_item() - ' . $this->last . ' in lp_type 2 is <> sco', 0);
  3755. }
  3756. $this->items[$this->last]->close();
  3757. //$this->autocomplete_parents($this->last);
  3758. //$this->update_queue[$this->last] = $this->items[$this->last]->get_status();
  3759. } else {
  3760. if ($this->debug > 2) {
  3761. error_log('New LP - In learnpath::stop_previous_item() - Item is a SCO, saving is managed by SCO signals', 0);
  3762. }
  3763. }
  3764. break;
  3765. case '1' :
  3766. default :
  3767. if ($this->debug > 2) {
  3768. error_log('New LP - In learnpath::stop_previous_item() - ' . $this->last . ' in lp_type 1 is asset', 0);
  3769. }
  3770. $this->items[$this->last]->close();
  3771. break;
  3772. }
  3773. } else {
  3774. if ($this->debug > 2) {
  3775. error_log('New LP - In learnpath::stop_previous_item() - No previous element found, ignoring...', 0);
  3776. }
  3777. return false;
  3778. }
  3779. return true;
  3780. }
  3781. /**
  3782. * Updates the default view mode from fullscreen to embedded and inversely
  3783. * @return string The current default view mode ('fullscreen' or 'embedded')
  3784. */
  3785. function update_default_view_mode() {
  3786. if ($this->debug > 0) {
  3787. error_log('New LP - In learnpath::update_default_view_mode()', 0);
  3788. }
  3789. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3790. $sql = "SELECT * FROM $lp_table WHERE id = " . $this->get_id();
  3791. $res = Database::query($sql, __FILE__, __LINE__);
  3792. if (Database :: num_rows($res) > 0) {
  3793. $row = Database :: fetch_array($res);
  3794. $view_mode = $row['default_view_mod'];
  3795. if ($view_mode == 'fullscreen') {
  3796. $view_mode = 'embedded';
  3797. }
  3798. elseif ($view_mode == 'embedded') {
  3799. $view_mode = 'fullscreen';
  3800. }
  3801. $sql = "UPDATE $lp_table SET default_view_mod = '$view_mode' WHERE id = " . $this->get_id();
  3802. $res = Database::query($sql, __FILE__, __LINE__);
  3803. $this->mode = $view_mode;
  3804. return $view_mode;
  3805. } else {
  3806. if ($this->debug > 2) {
  3807. error_log('New LP - Problem in update_default_view() - could not find LP ' . $this->get_id() . ' in DB', 0);
  3808. }
  3809. }
  3810. return -1;
  3811. }
  3812. /**
  3813. * Updates the default behaviour about auto-commiting SCORM updates
  3814. * @return boolean True if auto-commit has been set to 'on', false otherwise
  3815. */
  3816. function update_default_scorm_commit() {
  3817. if ($this->debug > 0) {
  3818. error_log('New LP - In learnpath::update_default_scorm_commit()', 0);
  3819. }
  3820. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3821. $sql = "SELECT * FROM $lp_table WHERE id = " . $this->get_id();
  3822. $res = Database::query($sql, __FILE__, __LINE__);
  3823. if (Database :: num_rows($res) > 0) {
  3824. $row = Database :: fetch_array($res);
  3825. $force = $row['force_commit'];
  3826. if ($force == 1) {
  3827. $force = 0;
  3828. $force_return = false;
  3829. }
  3830. elseif ($force == 0) {
  3831. $force = 1;
  3832. $force_return = true;
  3833. }
  3834. $sql = "UPDATE $lp_table SET force_commit = $force WHERE id = " . $this->get_id();
  3835. $res = Database::query($sql, __FILE__, __LINE__);
  3836. $this->force_commit = $force_return;
  3837. return $force_return;
  3838. } else {
  3839. if ($this->debug > 2) {
  3840. error_log('New LP - Problem in update_default_scorm_commit() - could not find LP ' . $this->get_id() . ' in DB', 0);
  3841. }
  3842. }
  3843. return -1;
  3844. }
  3845. /**
  3846. * Updates the order of learning paths (goes through all of them by order and fills the gaps)
  3847. * @return bool True on success, false on failure
  3848. */
  3849. function update_display_order() {
  3850. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3851. $sql = "SELECT * FROM $lp_table ORDER BY display_order";
  3852. $res = Database::query($sql, __FILE__, __LINE__);
  3853. if ($res === false)
  3854. return false;
  3855. $lps = array ();
  3856. $lp_order = array ();
  3857. $num = Database :: num_rows($res);
  3858. //first check the order is correct, globally (might be wrong because
  3859. //of versions < 1.8.4)
  3860. if ($num > 0) {
  3861. $i = 1;
  3862. while ($row = Database :: fetch_array($res)) {
  3863. if ($row['display_order'] != $i) { //if we find a gap in the order, we need to fix it
  3864. $need_fix = true;
  3865. $sql_u = "UPDATE $lp_table SET display_order = $i WHERE id = " . $row['id'];
  3866. $res_u = Database::query($sql_u, __FILE__, __LINE__);
  3867. }
  3868. $i++;
  3869. }
  3870. }
  3871. return true;
  3872. }
  3873. /**
  3874. * Updates the "prevent_reinit" value that enables control on reinitialising items on second view
  3875. * @return boolean True if prevent_reinit has been set to 'on', false otherwise (or 1 or 0 in this case)
  3876. */
  3877. function update_reinit() {
  3878. if ($this->debug > 0) {
  3879. error_log('New LP - In learnpath::update_reinit()', 0);
  3880. }
  3881. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3882. $sql = "SELECT * FROM $lp_table WHERE id = " . $this->get_id();
  3883. $res = Database::query($sql, __FILE__, __LINE__);
  3884. if (Database :: num_rows($res) > 0) {
  3885. $row = Database :: fetch_array($res);
  3886. $force = $row['prevent_reinit'];
  3887. if ($force == 1) {
  3888. $force = 0;
  3889. }
  3890. elseif ($force == 0) {
  3891. $force = 1;
  3892. }
  3893. $sql = "UPDATE $lp_table SET prevent_reinit = $force WHERE id = " . $this->get_id();
  3894. $res = Database::query($sql, __FILE__, __LINE__);
  3895. $this->prevent_reinit = $force;
  3896. return $force;
  3897. } else {
  3898. if ($this->debug > 2) {
  3899. error_log('New LP - Problem in update_reinit() - could not find LP ' . $this->get_id() . ' in DB', 0);
  3900. }
  3901. }
  3902. return -1;
  3903. }
  3904. /**
  3905. * Updates the "scorm_debug" value that shows or hide the debug window
  3906. * @return boolean True if scorm_debug has been set to 'on', false otherwise (or 1 or 0 in this case)
  3907. */
  3908. function update_scorm_debug() {
  3909. if ($this->debug > 0) {
  3910. error_log('New LP - In learnpath::update_scorm_debug()', 0);
  3911. }
  3912. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3913. $sql = "SELECT * FROM $lp_table WHERE id = " . $this->get_id();
  3914. $res = Database::query($sql, __FILE__, __LINE__);
  3915. if (Database :: num_rows($res) > 0) {
  3916. $row = Database :: fetch_array($res);
  3917. $force = $row['debug'];
  3918. if ($force == 1) {
  3919. $force = 0;
  3920. }
  3921. elseif ($force == 0) {
  3922. $force = 1;
  3923. }
  3924. $sql = "UPDATE $lp_table SET debug = $force WHERE id = " . $this->get_id();
  3925. $res = Database::query($sql, __FILE__, __LINE__);
  3926. $this->scorm_debug = $force;
  3927. return $force;
  3928. } else {
  3929. if ($this->debug > 2) {
  3930. error_log('New LP - Problem in update_scorm_debug() - could not find LP ' . $this->get_id() . ' in DB', 0);
  3931. }
  3932. }
  3933. return -1;
  3934. }
  3935. /**
  3936. * Function that makes a call to the function sort_tree_array and create_tree_array
  3937. *
  3938. * @author Kevin Van Den Haute
  3939. *
  3940. * @param unknown_type $array
  3941. */
  3942. function tree_array($array) {
  3943. if ($this->debug > 1) {
  3944. error_log('New LP - In learnpath::tree_array()', 0);
  3945. }
  3946. $array = $this->sort_tree_array($array);
  3947. $this->create_tree_array($array);
  3948. }
  3949. /**
  3950. * Creates an array with the elements of the learning path tree in it
  3951. *
  3952. * @author Kevin Van Den Haute
  3953. *
  3954. * @param array $array
  3955. * @param int $parent
  3956. * @param int $depth
  3957. * @param array $tmp
  3958. */
  3959. function create_tree_array($array, $parent = 0, $depth = -1, $tmp = array ()) {
  3960. if ($this->debug > 1) {
  3961. error_log('New LP - In learnpath::create_tree_array())', 0);
  3962. }
  3963. if (is_array($array)) {
  3964. for ($i = 0; $i < count($array); $i++) {
  3965. if ($array[$i]['parent_item_id'] == $parent) {
  3966. if (!in_array($array[$i]['parent_item_id'], $tmp)) {
  3967. $tmp[] = $array[$i]['parent_item_id'];
  3968. $depth++;
  3969. }
  3970. $preq = (empty ($array[$i]['prerequisite']) ? '' : $array[$i]['prerequisite']);
  3971. $this->arrMenu[] = array (
  3972. 'id' => $array[$i]['id'],
  3973. 'item_type' => $array[$i]['item_type'],
  3974. 'title' => $array[$i]['title'],
  3975. 'path' => $array[$i]['path'],
  3976. 'description' => $array[$i]['description'],
  3977. 'parent_item_id' => $array[$i]['parent_item_id'],
  3978. 'previous_item_id' => $array[$i]['previous_item_id'],
  3979. 'next_item_id' => $array[$i]['next_item_id'],
  3980. 'min_score' => $array[$i]['min_score'],
  3981. 'max_score' => $array[$i]['max_score'],
  3982. 'mastery_score' => $array[$i]['mastery_score'],
  3983. 'display_order' => $array[$i]['display_order'],
  3984. 'prerequisite' => $preq,
  3985. 'depth' => $depth,
  3986. 'audio' => $array[$i]['audio']
  3987. );
  3988. $this->create_tree_array($array, $array[$i]['id'], $depth, $tmp);
  3989. }
  3990. }
  3991. }
  3992. }
  3993. /**
  3994. * Sorts a multi dimensional array by parent id and display order
  3995. * @author Kevin Van Den Haute
  3996. *
  3997. * @param array $array (array with al the learning path items in it)
  3998. *
  3999. * @return array
  4000. */
  4001. function sort_tree_array($array) {
  4002. foreach ($array as $key => $row) {
  4003. $parent[$key] = $row['parent_item_id'];
  4004. $position[$key] = $row['display_order'];
  4005. }
  4006. if (count($array) > 0)
  4007. array_multisort($parent, SORT_ASC, $position, SORT_ASC, $array);
  4008. return $array;
  4009. }
  4010. /**
  4011. * Function that creates a table structure with a learning path his modules, chapters and documents.
  4012. * Also the actions for the modules, chapters and documents are in this table.
  4013. *
  4014. * @author Kevin Van Den Haute
  4015. *
  4016. * @param int $lp_id
  4017. *
  4018. * @return string
  4019. */
  4020. function overview() {
  4021. $is_allowed_to_edit = api_is_allowed_to_edit(null,true);
  4022. $platform_charset = api_get_system_encoding();
  4023. if ($this->debug > 0) {
  4024. error_log('New LP - In learnpath::overview()', 0);
  4025. }
  4026. global $charset, $_course;
  4027. $_SESSION['gradebook'] = Security :: remove_XSS($_GET['gradebook']);
  4028. $return = '';
  4029. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  4030. $sql = "SELECT * FROM " . $tbl_lp_item . "
  4031. WHERE lp_id = " . $this->lp_id;
  4032. $result = Database::query($sql, __FILE__, __LINE__);
  4033. $arrLP = array ();
  4034. while ($row = Database :: fetch_array($result)) {
  4035. $row['title'] = Security :: remove_XSS(api_convert_encoding($row['title'], $platform_charset, $this->encoding));
  4036. $row['description'] = Security :: remove_XSS(api_convert_encoding($row['description'], $platform_charset, $this->encoding));
  4037. $arrLP[] = array (
  4038. 'id' => $row['id'],
  4039. 'item_type' => $row['item_type'],
  4040. 'title' => $row['title'],
  4041. 'path' => $row['path'],
  4042. 'description' => $row['description'],
  4043. 'parent_item_id' => $row['parent_item_id'],
  4044. 'previous_item_id' => $row['previous_item_id'],
  4045. 'next_item_id' => $row['next_item_id'],
  4046. 'max_score' => $row['max_score'],
  4047. 'min_score' => $row['min_score'],
  4048. 'mastery_score' => $row['mastery_score'],
  4049. 'prerequisite' => $row['prerequisite'],
  4050. 'display_order' => $row['display_order'],
  4051. 'audio' => $row['audio']
  4052. );
  4053. }
  4054. $this->tree_array($arrLP);
  4055. $arrLP = $this->arrMenu;
  4056. unset ($this->arrMenu);
  4057. if ($is_allowed_to_edit) {
  4058. $gradebook = Security :: remove_XSS($_GET['gradebook']);
  4059. $return .= '<div class="actions">';
  4060. $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('learnpath_build.gif', get_lang('Build')) . ' ' . get_lang('Build') . '</a>';
  4061. $return .= '<span>' . Display :: return_icon('learnpath_organize_na.gif', get_lang("BasicOverview")) . ' <b>' . get_lang('BasicOverview') . '</b></span>';
  4062. $return .= '<a href="lp_controller.php?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&action=view&lp_id=' . $this->lp_id . '">' . Display :: return_icon('learnpath_view.gif', get_lang("Display")) . ' ' . get_lang('Display') . '</a> ' . Display :: return_icon('i.gif');
  4063. $return .= '<a href="lp_controller.php?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&amp;action=edit&amp;lp_id=' . Security :: remove_XSS($_GET['lp_id']) . '">' . Display :: return_icon('edit.gif', get_lang('CourseSettings')) . ' ' . get_lang('CourseSettings') . '</a>';
  4064. $return .= '<a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&amp;action=' . Security :: remove_XSS($_GET['action']) . '&amp;lp_id=' . Security :: remove_XSS($_GET['lp_id']) . '&amp;updateaudio=true">' . Display :: return_icon('audio.gif', get_lang('UpdateAllAudioFragments')) . ' ' . get_lang('UpdateAllAudioFragments') . '</a>';
  4065. $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") . '"><img alt="' . get_lang("NewChapter") . '" src="../img/lp_dokeos_chapter_add.gif" title="' . get_lang("NewChapter") . '" />' . get_lang("NewChapter") . '</a>';
  4066. $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") . '"><img alt="' . get_lang("NewStep") . '" src="../img/new_test.gif" title="' . get_lang("NewStep") . '" />' . get_lang("NewStep") . '</a>';
  4067. $return .= '</div>';
  4068. }
  4069. // we need to start a form when we want to update all the mp3 files
  4070. if ($_GET['updateaudio'] == 'true' AND count($arrLP) <> 0) {
  4071. $return .= '<form action="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&amp;action=' . Security :: remove_XSS($_GET['action']) . '&amp;lp_id=' . Security :: remove_XSS($_GET['lp_id']) . '" method="post" enctype="multipart/form-data" name="updatemp3" id="updatemp3">';
  4072. $return .= Display :: display_warning_message(get_lang('LeaveEmptyToKeepCurrentFile'));
  4073. }
  4074. $return .= '<table class="data_table">' . "\n";
  4075. $return .= "\t" . '<tr>' . "\n";
  4076. $return .= "\t" . '<th width="60%">' . get_lang("Title") . '</th>' . "\n";
  4077. //$return .= "\t" . '<th>'.get_lang("Description").'</th>' . "\n";
  4078. $return .= "\t" . '<th>' . get_lang("Audio") . '</th>' . "\n";
  4079. $return .= "\t" . '<th>' . get_lang("Move") . '</th>' . "\n";
  4080. $return .= "\t" . '<th>' . get_lang("Actions") . '</th>' . "\n";
  4081. $return .= "\t" . '</tr>' . "\n";
  4082. for ($i = 0; $i < count($arrLP); $i++) {
  4083. $title = $arrLP[$i]['title'];
  4084. if ($arrLP[$i]['description'] == '')
  4085. $arrLP[$i]['description'] = '&nbsp;';
  4086. if (($i % 2) == 0) {
  4087. $oddclass = "row_odd";
  4088. } else {
  4089. $oddclass = "row_even";
  4090. }
  4091. $return .= "\t" . '<tr class="' . $oddclass . '">' . "\n";
  4092. $icon_name = str_replace(' ', '', $arrLP[$i]['item_type']);
  4093. if (file_exists("../img/lp_" . $icon_name . ".png")) {
  4094. $return .= "\t\t" . '<td style="padding-left:' . $arrLP[$i]['depth'] * 10 . 'px;"><img align="left" src="../img/lp_' . $icon_name . '.png" style="margin-right:3px;" />' . $title . '</td>' . "\n";
  4095. } else
  4096. if (file_exists("../img/lp_" . $icon_name . ".gif")) {
  4097. $return .= "\t\t" . '<td style="padding-left:' . $arrLP[$i]['depth'] * 10 . 'px;"><img align="left" src="../img/lp_' . $icon_name . '.gif" style="margin-right:3px;" />' . $title . '</td>' . "\n";
  4098. } else {
  4099. //$return .= "\t\t" . '<td style="padding-left:' . $arrLP[$i]['depth'] * 10 . 'px;">' . Display::display_icon('folder_document.gif','',array('style'=>'margin-right:3px;')) . $title . '</td>' . "\n";
  4100. $return .= "\t\t" . '<td style="padding-left:' . $arrLP[$i]['depth'] * 10 . 'px;"><img align="left" src="../img/folder_document.gif" style="margin-right:3px;" />' . $title . '</td>' . "\n";
  4101. }
  4102. //$return .= "\t\t" . '<td>' . stripslashes($arrLP[$i]['description']) . '</td>' . "\n";
  4103. // The audio column
  4104. $return .= "\t\t" . '<td align="center">';
  4105. if (!$_GET['updateaudio'] OR $_GET['updateaudio'] <> 'true') {
  4106. if (!empty ($arrLP[$i]['audio'])) {
  4107. $return .= '<span id="container' . $i . '"><a href="http://www.macromedia.com/go/getflashplayer">Get the Flash Player</a> to see this player.</span>';
  4108. $return .= '<script type="text/javascript" src="../inc/lib/mediaplayer/swfobject.js"></script>';
  4109. $return .= '<script type="text/javascript">
  4110. var s1 = new SWFObject("../inc/lib/mediaplayer/player.swf","ply","250","20","9","#FFFFFF");
  4111. s1.addParam("allowscriptaccess","always");
  4112. s1.addParam("flashvars","file=../../courses/' . $_course['path'] . '/document/audio/' . $arrLP[$i]['audio'] . '");
  4113. s1.write("container' . $i . '");
  4114. </script>';
  4115. } else {
  4116. $return .= ' - ';
  4117. }
  4118. } else {
  4119. if ($arrLP[$i]['item_type'] != 'dokeos_chapter' && $arrLP[$i]['item_type'] != 'dokeos_module' && $arrLP[$i]['item_type'] != 'dir') {
  4120. $return .= ' <input type="file" name="mp3file' . $arrLP[$i]['id'] . '" id="mp3file" />';
  4121. if (!empty ($arrLP[$i]['audio'])) {
  4122. $return .= '<br /><input type="checkbox" name="removemp3' . $arrLP[$i]['id'] . '" id="checkbox' . $arrLP[$i]['id'] . '" />' . get_lang('RemoveAudio');
  4123. }
  4124. }
  4125. }
  4126. $return .= '</td>' . "\n";
  4127. if ($is_allowed_to_edit) {
  4128. $return .= "\t\t" . '<td align="center">' . "\n";
  4129. if ($arrLP[$i]['previous_item_id'] != 0) {
  4130. $return .= "\t\t\t" . '<a href="' . api_get_self() . '?cidReq=' . $_GET['cidReq'] . '&amp;action=move_item&amp;direction=up&amp;id=' . $arrLP[$i]['id'] . '&amp;lp_id=' . $this->lp_id . '">';
  4131. $return .= '<img style="margin:1px;" alt="" src="../img/arrow_up_' . ($arrLP[$i]['depth'] % 3) . '.gif" title="' . get_lang('MoveUp') . '"/>';
  4132. $return .= '</a>' . "\n";
  4133. } else
  4134. $return .= "\t\t\t" . '<img alt="" src="../img/blanco.png" title="" />' . "\n";
  4135. if ($arrLP[$i]['next_item_id'] != 0) {
  4136. $return .= "\t\t\t" . '<a href="' . api_get_self() . '?cidReq=' . $_GET['cidReq'] . '&amp;action=move_item&amp;direction=down&amp;id=' . $arrLP[$i]['id'] . '&amp;lp_id=' . $this->lp_id . '">';
  4137. $return .= '<img style="margin:1px;" src="../img/arrow_down_' . ($arrLP[$i]['depth'] % 3) . '.gif" title="' . get_lang('MoveDown') . '" />';
  4138. $return .= '</a>' . "\n";
  4139. } else
  4140. $return .= "\t\t\t" . '<img alt="" src="../img/blanco.png" title="" />' . "\n";
  4141. $return .= "\t\t" . '</td>' . "\n";
  4142. $return .= "\t\t" . '<td align="center">' . "\n";
  4143. if ($arrLP[$i]['item_type'] != 'dokeos_chapter' && $arrLP[$i]['item_type'] != 'dokeos_module') {
  4144. $return .= "\t\t\t" . '<a href="' . api_get_self() . '?cidReq=' . $_GET['cidReq'] . '&amp;action=edit_item&amp;view=build&amp;id=' . $arrLP[$i]['id'] . '&amp;lp_id=' . $this->lp_id . '&amp;path_item=' . $arrLP[$i]['path'] . '">';
  4145. $return .= '<img style="margin:1px;" alt="" src="../img/edit.gif" title="' . get_lang('_edit_learnpath_module') . '" />';
  4146. $return .= '</a>' . "\n";
  4147. } else {
  4148. $return .= "\t\t\t" . '<a href="' . api_get_self() . '?cidReq=' . $_GET['cidReq'] . '&amp;action=edit_item&amp;id=' . $arrLP[$i]['id'] . '&amp;lp_id=' . $this->lp_id . '&amp;path_item=' . $arrLP[$i]['path'] . '">';
  4149. $return .= '<img style="margin:1px;" alt="" src="../img/edit.gif" title="' . get_lang('_edit_learnpath_module') . '" />';
  4150. $return .= '</a>' . "\n";
  4151. }
  4152. $return .= "\t\t\t" . '<a href="' . api_get_self() . '?cidReq=' . $_GET['cidReq'] . '&amp;action=delete_item&amp;id=' . $arrLP[$i]['id'] . '&amp;lp_id=' . $this->lp_id . '" onclick="return confirmation(\'' . addslashes($title) . '\');">';
  4153. $return .= '<img style="margin:1px;" alt="" src="../img/delete.gif" title="' . get_lang('_delete_learnpath_module') . '" />';
  4154. $return .= '</a>' . "\n";
  4155. $return .= "\t\t" . '</td>' . "\n";
  4156. }
  4157. $return .= "\t" . '</tr>' . "\n";
  4158. }
  4159. if (count($arrLP) == 0) {
  4160. $return .= "\t" . '<tr>' . "\n";
  4161. $return .= "\t\t" . '<td colspan="4">' . get_lang("NoItemsInLp") . '</td>' . "\n";
  4162. $return .= "\t" . '</tr>' . "\n";
  4163. }
  4164. $return .= '</table>' . "\n";
  4165. // we need to close the form when we are updating the mp3 files
  4166. if ($_GET['updateaudio'] == 'true') {
  4167. $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?
  4168. }
  4169. // we need to close the form when we are updating the mp3 files
  4170. if ($_GET['updateaudio'] == 'true' AND count($arrLP) <> 0) {
  4171. $return .= '</form>';
  4172. }
  4173. return $return;
  4174. }
  4175. /**
  4176. * This function builds the action menu
  4177. *
  4178. * */
  4179. function build_action_menu() {
  4180. $gradebook = Security :: remove_XSS($_GET['gradebook']);
  4181. echo '<div class="actions">';
  4182. //echo '<span>'.Display::return_icon('learnpath_build.gif').' '.get_lang('Build').'</span>';
  4183. echo '<span>' . Display :: return_icon('learnpath_build_na.gif', get_lang('Build')) . ' <b>' . get_lang('Build') . '</b></span>';
  4184. echo '<a href="' . api_get_self() . '?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('learnpath_organize.gif', get_lang('BasicOverview')) . ' ' . get_lang('BasicOverview') . '</a>';
  4185. echo '<a href="lp_controller.php?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&amp;gradebook=' . $gradebook . '&action=view&lp_id=' . $_SESSION['oLP']->lp_id . '">' . Display :: return_icon('learnpath_view.gif', get_lang('Display')) . ' ' . get_lang('Display') . '</a>';
  4186. Display :: display_icon('i.gif');
  4187. echo '<a href="lp_controller.php?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&amp;action=edit&amp;lp_id=' . Security :: remove_XSS($_GET['lp_id']) . '">' . Display :: return_icon('edit.gif', get_lang('CourseSettings')) . ' ' . get_lang('CourseSettings') . '</a>';
  4188. echo '<a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&amp;action=admin_view&amp;lp_id=' . Security :: remove_XSS($_GET['lp_id']) . '&amp;updateaudio=true">' . Display :: return_icon('audio.gif', get_lang('UpdateAllAudioFragments')) . ' ' . get_lang('UpdateAllAudioFragments') . '</a>';
  4189. echo '<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") . '">' . Display :: return_icon('lp_dokeos_chapter_add.gif', get_lang('NewChapter')) . ' ' . get_lang("NewChapter") . '</a>';
  4190. echo '<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") . '">' . Display :: return_icon('new_test.gif', get_lang('NewStep')) . ' ' . get_lang("NewStep") . '</a>';
  4191. echo '</div>';
  4192. }
  4193. /**
  4194. * This functions builds the LP tree based on data from the database.
  4195. *
  4196. * @return string
  4197. * @uses dtree.js :: necessary javascript for building this tree
  4198. */
  4199. function build_tree() {
  4200. $platform_charset = api_get_system_encoding();
  4201. $return = "<script type=\"text/javascript\">\n";
  4202. $return .= "\tm = new dTree('m');\n\n";
  4203. $return .= "\tm.config.folderLinks = true;\n";
  4204. $return .= "\tm.config.useCookies = true;\n";
  4205. $return .= "\tm.config.useIcons = true;\n";
  4206. $return .= "\tm.config.useLines = true;\n";
  4207. $return .= "\tm.config.useSelection = true;\n";
  4208. $return .= "\tm.config.useStatustext = false;\n\n";
  4209. $menu = 0;
  4210. $parent = '';
  4211. $return .= "\tm.add(" . $menu . ", -1, '" . addslashes(Security::remove_XSS(($this->name))) . "');\n";
  4212. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  4213. $sql = " SELECT * FROM " . $tbl_lp_item . "
  4214. WHERE lp_id = " . Database :: escape_string($this->lp_id);
  4215. $result = Database::query($sql, __FILE__, __LINE__);
  4216. $arrLP = array ();
  4217. while ($row = Database :: fetch_array($result)) {
  4218. $row['title'] = Security :: remove_XSS(api_convert_encoding($row['title'], $platform_charset, $this->encoding));
  4219. $row['description'] = Security :: remove_XSS(api_convert_encoding($row['description'], $platform_charset, $this->encoding));
  4220. //$row['title'] = Security :: remove_XSS($row['title']);
  4221. $arrLP[] = array (
  4222. 'id' => $row['id'],
  4223. 'item_type' => $row['item_type'],
  4224. 'title' => $row['title'],
  4225. 'path' => $row['path'],
  4226. 'description' => $row['description'],
  4227. 'parent_item_id' => $row['parent_item_id'],
  4228. 'previous_item_id' => $row['previous_item_id'],
  4229. 'next_item_id' => $row['next_item_id'],
  4230. 'max_score' => $row['max_score'],
  4231. 'min_score' => $row['min_score'],
  4232. 'mastery_score' => $row['mastery_score'],
  4233. 'display_order' => $row['display_order']
  4234. );
  4235. }
  4236. $this->tree_array($arrLP);
  4237. $arrLP = $this->arrMenu;
  4238. unset ($this->arrMenu);
  4239. $title = '';
  4240. for ($i = 0; $i < count($arrLP); $i++) {
  4241. $title = addslashes($arrLP[$i]['title']);
  4242. $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;
  4243. $icon_name = str_replace(' ', '', $arrLP[$i]['item_type']);
  4244. if (file_exists("../img/lp_" . $icon_name . ".png")) {
  4245. $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";
  4246. } else
  4247. if (file_exists("../img/lp_" . $icon_name . ".gif")) {
  4248. $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";
  4249. } else {
  4250. $return .= "\tm.add(" . $arrLP[$i]['id'] . ", " . $arrLP[$i]['parent_item_id'] . ", '" . $title . "', '" . $menu_page . "', '', '', '../img/folder_document.gif', '../img/folder_document.gif');\n";
  4251. }
  4252. if ($menu < $arrLP[$i]['id'])
  4253. $menu = $arrLP[$i]['id'];
  4254. }
  4255. $return .= "\n\tdocument.write(m);\n";
  4256. $return .= "\t if(!m.selectedNode) m.s(1);";
  4257. $return .= "</script>\n";
  4258. return $return;
  4259. }
  4260. /**
  4261. * Create a new document //still needs some finetuning
  4262. *
  4263. * @param array $_course
  4264. * @return string
  4265. */
  4266. function create_document($_course) {
  4267. global $charset;
  4268. $dir = isset ($_GET['dir']) ? $_GET['dir'] : $_POST['dir']; // please do not modify this dirname formatting
  4269. if (strstr($dir, '..'))
  4270. $dir = '/';
  4271. if ($dir[0] == '.')
  4272. $dir = substr($dir, 1);
  4273. if ($dir[0] != '/')
  4274. $dir = '/' . $dir;
  4275. if ($dir[strlen($dir) - 1] != '/')
  4276. $dir .= '/';
  4277. $filepath = api_get_path('SYS_COURSE_PATH') . $_course['path'] . '/document' . $dir;
  4278. if (!is_dir($filepath)) {
  4279. $filepath = api_get_path('SYS_COURSE_PATH') . $_course['path'] . '/document/';
  4280. $dir = '/';
  4281. }
  4282. //stripslashes before calling replace_dangerous_char() because $_POST['title']
  4283. //is already escaped twice when it gets here
  4284. $title = replace_dangerous_char(stripslashes($_POST['title']));
  4285. $title = disable_dangerous_file($title);
  4286. $title = replace_accents($title);
  4287. $filename = $title;
  4288. $content = $_POST['content_lp'];
  4289. $tmp_filename = $filename;
  4290. $i = 0;
  4291. while (file_exists($filepath . $tmp_filename . '.html'))
  4292. $tmp_filename = $filename . '_' . ++ $i;
  4293. $filename = $tmp_filename . '.html';
  4294. $content = stripslashes(text_filter($content));
  4295. $content = str_replace(api_get_path('WEB_COURSE_PATH'), api_get_path(REL_PATH) . 'courses/', $content);
  4296. // change the path of mp3 to absolute
  4297. // first regexp deals with ../../../ urls
  4298. $content = preg_replace("|(flashvars=\"file=)(\.+/)+|", "$1" . api_get_path(REL_COURSE_PATH) . $_course['path'] . '/document/', $content);
  4299. //second regexp deals with audio/ urls
  4300. $content = preg_replace("|(flashvars=\"file=)([^/]+)/|", "$1" . api_get_path(REL_COURSE_PATH) . $_course['path'] . '/document/$2/', $content);
  4301. // for flv player : to prevent edition problem with firefox, we have to use a strange tip (don't blame me please)
  4302. $content = str_replace('</body>', '<style type="text/css">body{}</style></body>', $content);
  4303. if (!file_exists($filepath . $filename)) {
  4304. if ($fp = @ fopen($filepath . $filename, 'w')) {
  4305. fputs($fp, $content);
  4306. fclose($fp);
  4307. $file_size = filesize($filepath . $filename);
  4308. $save_file_path = $dir . $filename;
  4309. $document_id = add_document($_course, $save_file_path, 'file', $file_size, $filename . '.html');
  4310. if ($document_id) {
  4311. api_item_property_update($_course, TOOL_DOCUMENT, $document_id, 'DocumentAdded', api_get_user_id());
  4312. //update parent folders
  4313. //item_property_update_on_folder($_course, $_GET['dir'], $_user['user_id']);
  4314. $new_comment = (isset ($_POST['comment'])) ? trim($_POST['comment']) : '';
  4315. $new_title = (isset ($_POST['title'])) ? trim($_POST['title']) : '';
  4316. if ($new_comment || $new_title) {
  4317. $tbl_doc = Database :: get_course_table(TABLE_DOCUMENT);
  4318. $ct = '';
  4319. if ($new_comment)
  4320. $ct .= ", comment='" . $new_comment . "'";
  4321. if ($new_title)
  4322. $ct .= ", title='" . Database :: escape_string(htmlspecialchars($new_title, ENT_QUOTES, $charset)) . ".html '";
  4323. $sql_update = "
  4324. UPDATE " . $tbl_doc . "
  4325. SET " . substr($ct, 1) . "
  4326. WHERE id = " . $document_id;
  4327. Database::query($sql_update, __FILE__, __LINE__);
  4328. }
  4329. }
  4330. return $document_id;
  4331. }
  4332. }
  4333. }
  4334. /**
  4335. * Edit a document based on $_POST and $_GET parameters 'dir' and 'path'
  4336. *
  4337. * @param array $_course array
  4338. * @return void
  4339. */
  4340. function edit_document($_course) {
  4341. global $_configuration;
  4342. $dir = isset ($_GET['dir']) ? $_GET['dir'] : $_POST['dir']; // please do not modify this dirname formatting
  4343. if (strstr($dir, '..'))
  4344. $dir = '/';
  4345. if ($dir[0] == '.')
  4346. $dir = substr($dir, 1);
  4347. if ($dir[0] != '/')
  4348. $dir = '/' . $dir;
  4349. if ($dir[strlen($dir) - 1] != '/')
  4350. $dir .= '/';
  4351. $filepath = api_get_path('SYS_COURSE_PATH') . $_course['path'] . '/document' . $dir;
  4352. if (!is_dir($filepath)) {
  4353. $filepath = api_get_path('SYS_COURSE_PATH') . $_course['path'] . '/document/';
  4354. $dir = '/';
  4355. }
  4356. $table_doc = Database :: get_course_table(TABLE_DOCUMENT);
  4357. if (isset($_POST['path']) && !empty($_POST['path'])) {
  4358. $sql = "SELECT path
  4359. FROM " . $table_doc . "
  4360. WHERE id = " . Database::escape_string($_POST['path']);
  4361. $res = Database::query($sql, __FILE__, __LINE__);
  4362. $row = Database :: fetch_array($res);
  4363. $content = stripslashes($_POST['content_lp']);
  4364. $file = $filepath . $row['path'];
  4365. if ($fp = @ fopen($file, 'w')) {
  4366. $content = text_filter($content);
  4367. $content = str_replace(api_get_path('WEB_COURSE_PATH'), $_configuration['url_append'] . '/courses/', $content);
  4368. // change the path of mp3 to absolute
  4369. // first regexp deals with ../../../ urls
  4370. $content = preg_replace("|(flashvars=\"file=)(\.+/)+|", "$1" . api_get_path(REL_COURSE_PATH) . $_course['path'] . '/document/', $content);
  4371. //second regexp deals with audio/ urls
  4372. $content = preg_replace("|(flashvars=\"file=)([^/]+)/|", "$1" . api_get_path(REL_COURSE_PATH) . $_course['path'] . '/document/$2/', $content);
  4373. fputs($fp, $content);
  4374. fclose($fp);
  4375. }
  4376. }
  4377. }
  4378. /**
  4379. * Displays the selected item, with a panel for manipulating the item
  4380. *
  4381. * @param int $item_id
  4382. * @param string $msg
  4383. * @return string
  4384. */
  4385. function display_item($item_id, $iframe = true, $msg = '') {
  4386. global $_course; //will disappear
  4387. $return = '';
  4388. if (is_numeric($item_id)) {
  4389. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  4390. $tbl_doc = Database :: get_course_table(TABLE_DOCUMENT);
  4391. $sql = "SELECT lp.*
  4392. FROM " . $tbl_lp_item . " as lp
  4393. WHERE lp.id = " . Database :: escape_string($item_id);
  4394. $result = Database::query($sql, __FILE__, __LINE__);
  4395. while ($row = Database :: fetch_array($result)) {
  4396. $_SESSION['parent_item_id'] = ($row['item_type'] == 'dokeos_chapter' || $row['item_type'] == 'dokeos_module' || $row['item_type'] == 'dir') ? $item_id : 0;
  4397. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4398. $return .= '<div style="padding:10px;">';
  4399. if ($msg != '')
  4400. $return .= $msg;
  4401. $row['title'] = Security :: remove_XSS(api_convert_encoding($row['title'], api_get_system_encoding(), $this->encoding));
  4402. //$row['title'] = Security::remove_XSS(api_convert_encoding($row['title'], $this->encoding, api_get_system_encoding()));
  4403. $return .= '<p class="lp_title">' . $row['title'] . '</p>';
  4404. //$return .= '<p class="lp_text">' . ((trim($row['description']) == '') ? 'no description' : stripslashes($row['description'])) . '</p>';
  4405. //$return .= '<hr />';
  4406. if ($row['item_type'] == TOOL_DOCUMENT) {
  4407. $tbl_doc = Database :: get_course_table(TABLE_DOCUMENT);
  4408. $sql_doc = "SELECT path FROM " . $tbl_doc . " WHERE id = " . Database :: escape_string($row['path']);
  4409. $result = Database::query($sql_doc, __FILE__, __LINE__);
  4410. $path_file = Database :: result($result, 0, 0);
  4411. $path_parts = pathinfo($path_file);
  4412. if (in_array($path_parts['extension'], array (
  4413. 'html',
  4414. 'txt',
  4415. 'png',
  4416. 'jpg',
  4417. 'JPG',
  4418. 'jpeg',
  4419. 'JPEG',
  4420. 'gif',
  4421. 'swf'
  4422. ))) {
  4423. $return .= $this->display_document($row['path'], true, true);
  4424. }
  4425. }
  4426. $return .= '</div>';
  4427. }
  4428. }
  4429. return $return;
  4430. }
  4431. /**
  4432. * Shows the needed forms for editing a specific item
  4433. *
  4434. * @param int $item_id
  4435. * @return string
  4436. */
  4437. function display_edit_item($item_id) {
  4438. global $_course; //will disappear
  4439. $return = '';
  4440. if (is_numeric($item_id)) {
  4441. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  4442. $sql = "SELECT *
  4443. FROM " . $tbl_lp_item . "
  4444. WHERE id = " . Database :: escape_string($item_id);
  4445. $res = Database::query($sql, __FILE__, __LINE__);
  4446. $row = Database :: fetch_array($res);
  4447. switch ($row['item_type']) {
  4448. case 'dokeos_chapter' :
  4449. case 'dir' :
  4450. case 'asset' :
  4451. case 'sco' :
  4452. if (isset ($_GET['view']) && $_GET['view'] == 'build') {
  4453. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4454. $return .= $this->display_item_form($row['item_type'], get_lang("EditCurrentChapter") . ' :', 'edit', $item_id, $row);
  4455. } else {
  4456. $return .= $this->display_item_small_form($row['item_type'], get_lang("EditCurrentChapter") . ' :', $row);
  4457. }
  4458. break;
  4459. case TOOL_DOCUMENT :
  4460. $tbl_doc = Database :: get_course_table(TABLE_DOCUMENT);
  4461. $sql_step = " SELECT lp.*, doc.path as dir
  4462. FROM " . $tbl_lp_item . " as lp
  4463. LEFT JOIN " . $tbl_doc . " as doc ON doc.id = lp.path
  4464. WHERE lp.id = " . Database :: escape_string($item_id);
  4465. $res_step = Database::query($sql_step, __FILE__, __LINE__);
  4466. $row_step = Database :: fetch_array($res_step);
  4467. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4468. $return .= $this->display_document_form('edit', $item_id, $row_step);
  4469. break;
  4470. case TOOL_LINK :
  4471. $link_id = (string) $row['path'];
  4472. if (ctype_digit($link_id)) {
  4473. $tbl_link = Database :: get_course_table(TABLE_LINK);
  4474. $sql_select = 'SELECT url FROM ' . $tbl_link . ' WHERE id = ' . Database :: escape_string($link_id);
  4475. $res_link = Database::query($sql_select, __FILE__, __LINE__);
  4476. $row_link = Database :: fetch_array($res_link);
  4477. if (is_array($row_link)) {
  4478. $row['url'] = $row_link['url'];
  4479. }
  4480. }
  4481. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4482. $return .= $this->display_link_form('edit', $item_id, $row);
  4483. break;
  4484. case 'dokeos_module' :
  4485. if (isset ($_GET['view']) && $_GET['view'] == 'build') {
  4486. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4487. $return .= $this->display_item_form($row['item_type'], get_lang("EditCurrentModule") . ' :', 'edit', $item_id, $row);
  4488. } else {
  4489. $return .= $this->display_item_small_form($row['item_type'], get_lang("EditCurrentModule") . ' :', $row);
  4490. }
  4491. break;
  4492. case TOOL_QUIZ :
  4493. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4494. $return .= $this->display_quiz_form('edit', $item_id, $row);
  4495. break;
  4496. case TOOL_HOTPOTATOES :
  4497. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4498. $return .= $this->display_hotpotatoes_form('edit', $item_id, $row);
  4499. break;
  4500. case TOOL_STUDENTPUBLICATION :
  4501. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4502. $return .= $this->display_student_publication_form('edit', $item_id, $row);
  4503. break;
  4504. case TOOL_FORUM :
  4505. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4506. $return .= $this->display_forum_form('edit', $item_id, $row);
  4507. break;
  4508. case TOOL_THREAD :
  4509. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4510. $return .= $this->display_thread_form('edit', $item_id, $row);
  4511. break;
  4512. }
  4513. }
  4514. return $return;
  4515. }
  4516. /**
  4517. * Function that displays a list with al the resources that could be added to the learning path
  4518. *
  4519. * @return string
  4520. */
  4521. function display_resources() {
  4522. global $_course; //TODO: don't use globals
  4523. $return .= '<div class="sectiontitle">' . get_lang('CreateNewStep') . '</div>';
  4524. $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>'; //TODO: A hardcoded Spanish text is here.
  4525. $return .= '<div class="sectiontitle">' . get_lang('UseAnExistingResource') . '</div>';
  4526. $return .= '<div class="sectioncomment">';
  4527. /* get all the docs */
  4528. $return .= $this->get_documents();
  4529. /* get all the exercises */
  4530. $return .= $this->get_exercises();
  4531. /* get all the links */
  4532. $return .= $this->get_links();
  4533. /* get al the student publications */
  4534. $return .= $this->get_student_publications();
  4535. /* get al the forums */
  4536. $return .= $this->get_forums();
  4537. $return .= '</div>';
  4538. return $return;
  4539. }
  4540. /**
  4541. * Returns the extension of a document
  4542. *
  4543. * @param unknown_type $filename
  4544. * @return unknown
  4545. */
  4546. function get_extension($filename) {
  4547. $explode = explode('.', $filename);
  4548. return $explode[count($explode) - 1];
  4549. }
  4550. /**
  4551. * Displays a document by id
  4552. *
  4553. * @param unknown_type $id
  4554. * @return unknown
  4555. */
  4556. function display_document($id, $show_title = false, $iframe = true, $edit_link = false) {
  4557. global $_course; //temporary
  4558. $return = '';
  4559. $tbl_doc = Database :: get_course_table(TABLE_DOCUMENT);
  4560. $sql_doc = "SELECT * FROM " . $tbl_doc . "
  4561. WHERE id = " . $id;
  4562. $res_doc = Database::query($sql_doc, __FILE__, __LINE__);
  4563. $row_doc = Database :: fetch_array($res_doc);
  4564. //if($show_title)
  4565. //$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>';
  4566. //TODO: add a path filter
  4567. if ($iframe) {
  4568. $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>';
  4569. } else {
  4570. $return .= file_get_contents(api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document' . $row_doc['path']);
  4571. }
  4572. return $return;
  4573. }
  4574. /**
  4575. * Return HTML form to add/edit a quiz
  4576. *
  4577. * @param string Action (add/edit)
  4578. * @param integer Item ID if already exists
  4579. * @param mixed Extra information (quiz ID if integer)
  4580. * @return string HTML form
  4581. */
  4582. function display_quiz_form($action = 'add', $id = 0, $extra_info = '') {
  4583. global $charset;
  4584. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  4585. $tbl_quiz = Database :: get_course_table(TABLE_QUIZ_TEST);
  4586. if ($id != 0 && is_array($extra_info)) {
  4587. $item_title = stripslashes($extra_info['title']);
  4588. $item_description = stripslashes($extra_info['description']);
  4589. }
  4590. elseif (is_numeric($extra_info)) {
  4591. $sql_quiz = "
  4592. SELECT
  4593. title,
  4594. description
  4595. FROM " . $tbl_quiz . "
  4596. WHERE id = " . $extra_info;
  4597. $result = Database::query($sql_quiz, __FILE__, __LINE__);
  4598. $row = Database :: fetch_array($result);
  4599. $item_title = $row['title'];
  4600. $item_description = $row['description'];
  4601. } else {
  4602. $item_title = '';
  4603. $item_description = '';
  4604. }
  4605. $return = ' <div class="row">
  4606. <div class="form_header">';
  4607. if ($id != 0 && is_array($extra_info))
  4608. $parent = $extra_info['parent_item_id'];
  4609. else
  4610. $parent = 0;
  4611. $sql = "
  4612. SELECT *
  4613. FROM " . $tbl_lp_item . "
  4614. WHERE
  4615. lp_id = " . $this->lp_id;
  4616. $result = Database::query($sql, __FILE__, __LINE__);
  4617. $arrLP = array ();
  4618. while ($row = Database :: fetch_array($result)) {
  4619. $arrLP[] = array (
  4620. 'id' => $row['id'],
  4621. 'item_type' => $row['item_type'],
  4622. 'title' => $row['title'],
  4623. 'path' => $row['path'],
  4624. 'description' => $row['description'],
  4625. 'parent_item_id' => $row['parent_item_id'],
  4626. 'previous_item_id' => $row['previous_item_id'],
  4627. 'next_item_id' => $row['next_item_id'],
  4628. 'display_order' => $row['display_order'],
  4629. 'max_score' => $row['max_score'],
  4630. 'min_score' => $row['min_score'],
  4631. 'mastery_score' => $row['mastery_score'],
  4632. 'prerequisite' => $row['prerequisite'],
  4633. 'max_time_allowed' => $row['max_time_allowed']
  4634. );
  4635. }
  4636. $this->tree_array($arrLP);
  4637. $arrLP = $this->arrMenu;
  4638. unset ($this->arrMenu);
  4639. if ($action == 'add')
  4640. $return .= get_lang("CreateTheExercise") . '&nbsp;:' . "\n";
  4641. elseif ($action == 'move') $return .= get_lang("MoveTheCurrentExercise") . '&nbsp;:' . "\n";
  4642. else
  4643. $return .= get_lang("EditCurrentExecice") . '&nbsp;:' . "\n";
  4644. if (isset ($_GET['edit']) && $_GET['edit'] == 'true') {
  4645. $return .= Display :: return_warning_message('<p class="lp_title">' . get_lang("Warning") . ' !</p>' . get_lang("WarningEditingDocument"));
  4646. }
  4647. $return .= ' </div>
  4648. </div>';
  4649. $return .= '<div class="sectioncomment">';
  4650. $return .= '<form method="POST">' . "\n";
  4651. $return .= "\t" . '<table class="lp_form">' . "\n";
  4652. if ($action != 'move') {
  4653. $return .= "\t\t" . '<tr>' . "\n";
  4654. $return .= "\t\t\t" . '<td class="label"><label for="idTitle">' . get_lang('Title') . '</label></td>' . "\n";
  4655. $return .= "\t\t\t" . '<td class="input"><input id="idTitle" name="title" size="44" type="text" class="learnpath_item_form" value="' . $item_title . '" /></td>' . "\n";
  4656. $return .= "\t\t" . '</tr>' . "\n";
  4657. }
  4658. $return .= "\t\t" . '<tr>' . "\n";
  4659. $return .= "\t\t\t" . '<td class="label"><label for="idParent">' . get_lang('Parent') . '</label></td>' . "\n";
  4660. $return .= "\t\t\t" . '<td class="input">' . "\n";
  4661. $return .= "\t\t\t\t" . '<select id="idParent" style="width:100%;" name="parent" onchange="load_cbo(this.value);" class="learnpath_item_form" size="1">';
  4662. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
  4663. $arrHide = array (
  4664. $id
  4665. );
  4666. $parent_item_id = $_SESSION['parent_item_id'];
  4667. for ($i = 0; $i < count($arrLP); $i++) {
  4668. if ($action != 'add') {
  4669. 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)) {
  4670. $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'] . '">' . api_convert_encoding($arrLP[$i]['title'], $charset, $this->encoding) . '</option>';
  4671. } else {
  4672. $arrHide[] = $arrLP[$i]['id'];
  4673. }
  4674. } else {
  4675. if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
  4676. $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'] . '">' . api_convert_encoding($arrLP[$i]['title'], $charset, $this->encoding) . '</option>';
  4677. }
  4678. }
  4679. if (is_array($arrLP)) {
  4680. reset($arrLP);
  4681. }
  4682. $return .= "\t\t\t\t" . '</select>';
  4683. $return .= "\t\t\t" . '</td>' . "\n";
  4684. $return .= "\t\t" . '</tr>' . "\n";
  4685. $return .= "\t\t" . '<tr>' . "\n";
  4686. $return .= "\t\t\t" . '<td class="label"><label for="idPosition">' . get_lang('Position') . '</label></td>' . "\n";
  4687. $return .= "\t\t\t" . '<td class="input">' . "\n";
  4688. $return .= "\t\t\t\t" . '<select class="learnpath_item_form" style="width:100%;" id="idPosition" name="previous" size="1">';
  4689. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . get_lang('FirstPosition') . '</option>';
  4690. for ($i = 0; $i < count($arrLP); $i++) {
  4691. if ($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) {
  4692. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  4693. $selected = 'selected="selected" ';
  4694. elseif ($action == 'add') $selected = 'selected="selected" ';
  4695. else
  4696. $selected = '';
  4697. $return .= "\t\t\t\t\t" . '<option ' . $selected . 'value="' . $arrLP[$i]['id'] . '">' . get_lang("After") . ' "' . api_convert_encoding($arrLP[$i]['title'], $charset, $this->encoding) . '"</option>';
  4698. }
  4699. }
  4700. $return .= "\t\t\t\t" . '</select>';
  4701. $return .= "\t\t\t" . '</td>' . "\n";
  4702. $return .= "\t\t" . '</tr>' . "\n";
  4703. if ($action != 'move') {
  4704. $id_prerequisite = 0;
  4705. if (is_array($arrLP)) {
  4706. foreach ($arrLP as $key => $value) {
  4707. if ($value['id'] == $id) {
  4708. $id_prerequisite = $value['prerequisite'];
  4709. break;
  4710. }
  4711. }
  4712. }
  4713. $arrHide = array ();
  4714. for ($i = 0; $i < count($arrLP); $i++) {
  4715. if ($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter') {
  4716. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  4717. $s_selected_position = $arrLP[$i]['id'];
  4718. elseif ($action == 'add') $s_selected_position = 0;
  4719. $arrHide[$arrLP[$i]['id']]['value'] = api_convert_encoding($arrLP[$i]['title'], $charset, $this->encoding);
  4720. }
  4721. }
  4722. /*//comented the prerequisites, only visible in edit (exercise)
  4723. $return .= "\t\t" . '<tr>' . "\n";
  4724. $return .= "\t\t\t" . '<td class="label"><label for="idPrerequisites">'.get_lang('Prerequisites').'</label></td>' . "\n";
  4725. $return .= "\t\t\t" . '<td class="input"><select name="prerequisites" id="prerequisites" class="learnpath_item_form"><option value="0">'.get_lang("NoPrerequisites").'</option>';
  4726. foreach($arrHide as $key => $value){
  4727. if($key==$s_selected_position && $action == 'add'){
  4728. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  4729. }
  4730. elseif($key==$id_prerequisite && $action == 'edit'){
  4731. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  4732. }
  4733. else{
  4734. $return .= '<option value="'.$key.'">'.$value['value'].'</option>';
  4735. }
  4736. }
  4737. $return .= "</select></td>";
  4738. */
  4739. $return .= "\t\t" . '</tr>' . "\n";
  4740. /*$return .= "\t\t" . '<tr>' . "\n";
  4741. $return .= "\t\t\t" . '<td class="label"><label for="maxTimeAllowed">' . get_lang('MaxTimeAllowed') . '</label></td>' . "\n";
  4742. $return .= "\t\t\t" . '<td class="input"><input name="maxTimeAllowed" style="width:98%;" id="maxTimeAllowed" value="' . $extra_info['max_time_allowed'] . '" /></td>';
  4743. //Remove temporaly the test description
  4744. //$return .= "\t\t\t" . '<td class="label"><label for="idDescription">'.get_lang("Description").' :</label></td>' . "\n";
  4745. //$return .= "\t\t\t" . '<td class="input"><textarea id="idDescription" name="description" rows="4">' . $item_description . '</textarea></td>' . "\n";
  4746. $return .= "\t\t" . '</tr>' . "\n"; */
  4747. }
  4748. $return .= "\t\t" . '<tr>' . "\n";
  4749. $return .= "\t\t\t" . '<td>&nbsp;</td><td><button class="save" name="submit_button" type="submit">' . get_lang('AddExercise') . '</button></td>' . "\n";
  4750. $return .= "\t\t" . '</tr>' . "\n";
  4751. $return .= "\t" . '</table>' . "\n";
  4752. if ($action == 'move') {
  4753. $return .= "\t" . '<input name="title" type="hidden" value="' . $item_title . '" />' . "\n";
  4754. $return .= "\t" . '<input name="description" type="hidden" value="' . $item_description . '" />' . "\n";
  4755. }
  4756. if (is_numeric($extra_info)) {
  4757. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info . '" />' . "\n";
  4758. }
  4759. elseif (is_array($extra_info)) {
  4760. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />' . "\n";
  4761. }
  4762. $return .= "\t" . '<input name="type" type="hidden" value="' . TOOL_QUIZ . '" />' . "\n";
  4763. $return .= "\t" . '<input name="post_time" type="hidden" value="' . time() . '" />' . "\n";
  4764. $return .= '</form>' . "\n";
  4765. $return .= '</div>' . "\n";
  4766. return $return;
  4767. }
  4768. /**
  4769. * Addition of Hotpotatoes tests
  4770. * @param string Action
  4771. * @param integer Internal ID of the item
  4772. * @param mixed Extra information - can be an array with title and description indexes
  4773. * @return string HTML structure to display the hotpotatoes addition formular
  4774. */
  4775. function display_hotpotatoes_form($action = 'add', $id = 0, $extra_info = '') {
  4776. global $charset;
  4777. $uploadPath = DIR_HOTPOTATOES; //defined in main_api
  4778. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  4779. if ($id != 0 && is_array($extra_info)) {
  4780. $item_title = stripslashes($extra_info['title']);
  4781. $item_description = stripslashes($extra_info['description']);
  4782. }
  4783. elseif (is_numeric($extra_info)) {
  4784. $TBL_DOCUMENT = Database :: get_course_table(TABLE_DOCUMENT);
  4785. $sql_hot = "SELECT * FROM " . $TBL_DOCUMENT . "
  4786. WHERE path LIKE '" . $uploadPath . "/%/%htm%'
  4787. AND id = " . (int) $extra_info . " ORDER BY id ASC";
  4788. $res_hot = Database::query($sql_hot, __FILE__, __LINE__);
  4789. $row = Database :: fetch_array($res_hot);
  4790. $item_title = $row['title'];
  4791. $item_description = $row['description'];
  4792. if (!empty ($row['comment'])) {
  4793. $item_title = $row['comment'];
  4794. }
  4795. } else {
  4796. $item_title = '';
  4797. $item_description = '';
  4798. }
  4799. $item_title = api_convert_encoding($item_title, $charset, $this->encoding);
  4800. $item_description = api_convert_encoding($item_description, $charset, $this->encoding);
  4801. $return = '<div style="margin:3px 12px;">';
  4802. if ($id != 0 && is_array($extra_info))
  4803. $parent = $extra_info['parent_item_id'];
  4804. else
  4805. $parent = 0;
  4806. $sql = "
  4807. SELECT *
  4808. FROM " . $tbl_lp_item . "
  4809. WHERE
  4810. lp_id = " . $this->lp_id;
  4811. $result = Database::query($sql, __FILE__, __LINE__);
  4812. $arrLP = array ();
  4813. while ($row = Database :: fetch_array($result)) {
  4814. $arrLP[] = array (
  4815. 'id' => $row['id'],
  4816. 'item_type' => $row['item_type'],
  4817. 'title' => $row['title'],
  4818. 'path' => $row['path'],
  4819. 'description' => $row['description'],
  4820. 'parent_item_id' => $row['parent_item_id'],
  4821. 'previous_item_id' => $row['previous_item_id'],
  4822. 'next_item_id' => $row['next_item_id'],
  4823. 'display_order' => $row['display_order'],
  4824. 'max_score' => $row['max_score'],
  4825. 'min_score' => $row['min_score'],
  4826. 'mastery_score' => $row['mastery_score'],
  4827. 'prerequisite' => $row['prerequisite'],
  4828. 'max_time_allowed' => $row['max_time_allowed']
  4829. );
  4830. }
  4831. $this->tree_array($arrLP);
  4832. $arrLP = $this->arrMenu;
  4833. unset ($this->arrMenu);
  4834. if ($action == 'add')
  4835. $return .= '<p class="lp_title">' . get_lang("CreateTheExercise") . '&nbsp;:</p>' . "\n";
  4836. elseif ($action == 'move') $return .= '<p class="lp_title">' . get_lang("MoveTheCurrentExercise") . '&nbsp;:</p>' . "\n";
  4837. else
  4838. $return .= '<p class="lp_title">' . get_lang("EditCurrentExecice") . '&nbsp;:</p>' . "\n";
  4839. if (isset ($_GET['edit']) && $_GET['edit'] == 'true') {
  4840. $return .= Display :: return_warning_message('<p class="lp_title">' . get_lang("Warning") . ' !</p>' . get_lang("WarningEditingDocument"));
  4841. }
  4842. $return .= '<form method="POST">' . "\n";
  4843. $return .= "\t" . '<table cellpadding="0" cellspacing="0" class="lp_form">' . "\n";
  4844. $return .= "\t\t" . '<tr>' . "\n";
  4845. $return .= "\t\t\t" . '<td class="label"><label for="idParent">' . get_lang("Parent") . ' :</label></td>' . "\n";
  4846. $return .= "\t\t\t" . '<td class="input">' . "\n";
  4847. $return .= "\t\t\t\t" . '<select id="idParent" name="parent" onchange="load_cbo(this.value);" size="1">';
  4848. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
  4849. $arrHide = array (
  4850. $id
  4851. );
  4852. if (count($arrLP) > 0) {
  4853. for ($i = 0; $i < count($arrLP); $i++) {
  4854. if ($action != 'add') {
  4855. 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)) {
  4856. $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'] . '">' . api_convert_encoding($arrLP[$i]['title'], $charset, $this->encoding) . '</option>';
  4857. } else {
  4858. $arrHide[] = $arrLP[$i]['id'];
  4859. }
  4860. } else {
  4861. if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
  4862. $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'] . '">' . api_convert_encoding($arrLP[$i]['title'], $charset, $this->encoding) . '</option>';
  4863. }
  4864. }
  4865. reset($arrLP);
  4866. }
  4867. $return .= "\t\t\t\t" . '</select>';
  4868. $return .= "\t\t\t" . '</td>' . "\n";
  4869. $return .= "\t\t" . '</tr>' . "\n";
  4870. $return .= "\t\t" . '<tr>' . "\n";
  4871. $return .= "\t\t\t" . '<td class="label"><label for="idPosition">' . get_lang("Position") . ' :</label></td>' . "\n";
  4872. $return .= "\t\t\t" . '<td class="input">' . "\n";
  4873. $return .= "\t\t\t\t" . '<select id="idPosition" name="previous" size="1">';
  4874. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . get_lang('FirstPosition') . '</option>';
  4875. for ($i = 0; $i < count($arrLP); $i++) {
  4876. if ($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) {
  4877. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  4878. $selected = 'selected="selected" ';
  4879. elseif ($action == 'add') $selected = 'selected="selected" ';
  4880. else
  4881. $selected = '';
  4882. $return .= "\t\t\t\t\t" . '<option ' . $selected . 'value="' . $arrLP[$i]['id'] . '">' . get_lang("After") . ' "' . api_convert_encoding($arrLP[$i]['title'], $charset, $this->encoding) . '"</option>';
  4883. }
  4884. }
  4885. $return .= "\t\t\t\t" . '</select>';
  4886. $return .= "\t\t\t" . '</td>' . "\n";
  4887. $return .= "\t\t" . '</tr>' . "\n";
  4888. if ($action != 'move') {
  4889. $return .= "\t\t" . '<tr>' . "\n";
  4890. $return .= "\t\t\t" . '<td class="label"><label for="idTitle">' . get_lang("Title") . ' :</label></td>' . "\n";
  4891. $return .= "\t\t\t" . '<td class="input"><input id="idTitle" name="title" type="text" value="' . $item_title . '" /></td>' . "\n";
  4892. $return .= "\t\t" . '</tr>' . "\n";
  4893. $id_prerequisite = 0;
  4894. if (is_array($arrLP) && count($arrLP) > 0) {
  4895. foreach ($arrLP as $key => $value) {
  4896. if ($value['id'] == $id) {
  4897. $id_prerequisite = $value['prerequisite'];
  4898. break;
  4899. }
  4900. }
  4901. $arrHide = array ();
  4902. for ($i = 0; $i < count($arrLP); $i++) {
  4903. if ($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter') {
  4904. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  4905. $s_selected_position = $arrLP[$i]['id'];
  4906. elseif ($action == 'add') $s_selected_position = 0;
  4907. $arrHide[$arrLP[$i]['id']]['value'] = api_convert_encoding($arrLP[$i]['title'], $charset, $this->encoding);
  4908. }
  4909. }
  4910. }
  4911. $return .= "\t\t" . '<tr>' . "\n";
  4912. //$return .= "\t\t\t" . '<td class="label"><label for="idPrerequisites">'.get_lang("Prerequisites").' :</label></td>' . "\n";
  4913. //$return .= "\t\t\t" . '<td class="input"><select name="prerequisites" id="prerequisites"><option value="0">'.get_lang("NoPrerequisites").'</option>';
  4914. foreach ($arrHide as $key => $value) {
  4915. if ($key == $s_selected_position && $action == 'add') {
  4916. $return .= '<option value="' . $key . '" selected="selected">' . $value['value'] . '</option>';
  4917. }
  4918. elseif ($key == $id_prerequisite && $action == 'edit') {
  4919. $return .= '<option value="' . $key . '" selected="selected">' . $value['value'] . '</option>';
  4920. } else {
  4921. $return .= '<option value="' . $key . '">' . $value['value'] . '</option>';
  4922. }
  4923. }
  4924. $return .= "</select></td>";
  4925. $return .= "\t\t" . '</tr>' . "\n";
  4926. $return .= "\t\t" . '<tr>' . "\n";
  4927. //Remove temporaly the test description
  4928. //$return .= "\t\t\t" . '<td class="label"><label for="idDescription">'.get_lang("Description").' :</label></td>' . "\n";
  4929. //$return .= "\t\t\t" . '<td class="input"><textarea id="idDescription" name="description" rows="4">' . $item_description . '</textarea></td>' . "\n";
  4930. $return .= "\t\t" . '</tr>' . "\n";
  4931. }
  4932. $return .= "\t\t" . '<tr>' . "\n";
  4933. $return .= "\t\t\t" . '<td> &nbsp;</td><td><button class="save" name="submit_button" type="submit">' . get_lang('AddHotpotatoes') . '</button></td>' . "\n";
  4934. $return .= "\t\t" . '</tr>' . "\n";
  4935. $return .= "\t" . '</table>' . "\n";
  4936. if ($action == 'move') {
  4937. $return .= "\t" . '<input name="title" type="hidden" value="' . $item_title . '" />' . "\n";
  4938. $return .= "\t" . '<input name="description" type="hidden" value="' . $item_description . '" />' . "\n";
  4939. }
  4940. if (is_numeric($extra_info)) {
  4941. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info . '" />' . "\n";
  4942. }
  4943. elseif (is_array($extra_info)) {
  4944. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />' . "\n";
  4945. }
  4946. $return .= "\t" . '<input name="type" type="hidden" value="' . TOOL_HOTPOTATOES . '" />' . "\n";
  4947. $return .= "\t" . '<input name="post_time" type="hidden" value="' . time() . '" />' . "\n";
  4948. $return .= '</form>' . "\n";
  4949. $return .= '</div>' . "\n";
  4950. return $return;
  4951. }
  4952. //fin du hotpot form
  4953. /**
  4954. * Return the form to display the forum edit/add option
  4955. *
  4956. * @param string Action (add/edit)
  4957. * @param integer ID of the lp_item if already exists
  4958. * @param mixed Forum ID or title
  4959. * @return string HTML form
  4960. */
  4961. function display_forum_form($action = 'add', $id = 0, $extra_info = '') {
  4962. global $charset;
  4963. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  4964. $tbl_forum = Database :: get_course_table(TABLE_FORUM);
  4965. if ($id != 0 && is_array($extra_info)) {
  4966. $item_title = stripslashes($extra_info['title']);
  4967. }
  4968. elseif (is_numeric($extra_info)) {
  4969. $sql_forum = "
  4970. SELECT
  4971. forum_title as title, forum_comment as comment
  4972. FROM " . $tbl_forum . "
  4973. WHERE forum_id = " . $extra_info;
  4974. $result = Database::query($sql_forum, __FILE__, __LINE__);
  4975. $row = Database :: fetch_array($result);
  4976. $item_title = $row['title'];
  4977. $item_description = $row['comment'];
  4978. } else {
  4979. $item_title = '';
  4980. $item_description = '';
  4981. }
  4982. $item_title = api_convert_encoding($item_title, $charset, $this->encoding);
  4983. $item_description = api_convert_encoding($item_description, $charset, $this->encoding);
  4984. $return = ' <div class="row">
  4985. <div class="form_header">';
  4986. if ($id != 0 && is_array($extra_info))
  4987. $parent = $extra_info['parent_item_id'];
  4988. else
  4989. $parent = 0;
  4990. $sql = "
  4991. SELECT *
  4992. FROM " . $tbl_lp_item . "
  4993. WHERE
  4994. lp_id = " . $this->lp_id;
  4995. $result = Database::query($sql, __FILE__, __LINE__);
  4996. $arrLP = array ();
  4997. while ($row = Database :: fetch_array($result)) {
  4998. $arrLP[] = array (
  4999. 'id' => $row['id'],
  5000. 'item_type' => $row['item_type'],
  5001. 'title' => $row['title'],
  5002. 'path' => $row['path'],
  5003. 'description' => $row['description'],
  5004. 'parent_item_id' => $row['parent_item_id'],
  5005. 'previous_item_id' => $row['previous_item_id'],
  5006. 'next_item_id' => $row['next_item_id'],
  5007. 'display_order' => $row['display_order'],
  5008. 'max_score' => $row['max_score'],
  5009. 'min_score' => $row['min_score'],
  5010. 'mastery_score' => $row['mastery_score'],
  5011. 'prerequisite' => $row['prerequisite']
  5012. );
  5013. }
  5014. $this->tree_array($arrLP);
  5015. $arrLP = $this->arrMenu;
  5016. unset ($this->arrMenu);
  5017. if ($action == 'add')
  5018. $return .= get_lang("CreateTheForum") . '&nbsp;:' . "\n";
  5019. elseif ($action == 'move') $return .= get_lang("MoveTheCurrentForum") . '&nbsp;:' . "\n";
  5020. else
  5021. $return .= get_lang("EditCurrentForum") . '&nbsp;:' . "\n";
  5022. $return .= ' </div>
  5023. </div>';
  5024. $return .= '<div class="sectioncomment">';
  5025. $return .= '<form method="POST">' . "\n";
  5026. $return .= "\t" . '<table class="lp_form">' . "\n";
  5027. if ($action != 'move') {
  5028. $return .= "\t\t" . '<tr>' . "\n";
  5029. $return .= "\t\t\t" . '<td class="label"><label for="idTitle">' . get_lang('Title') . '</label></td>' . "\n";
  5030. $return .= "\t\t\t" . '<td class="input"><input id="idTitle" size="44" name="title" type="text" value="' . $item_title . '" class="learnpath_item_form" /></td>' . "\n";
  5031. $return .= "\t\t" . '</tr>' . "\n";
  5032. }
  5033. $return .= "\t\t" . '<tr>' . "\n";
  5034. $return .= "\t\t\t" . '<td class="label"><label for="idParent">' . get_lang('Parent') . '</label></td>' . "\n";
  5035. $return .= "\t\t\t" . '<td class="input">' . "\n";
  5036. $return .= "\t\t\t\t" . '<select id="idParent" style="width:100%;" name="parent" onchange="load_cbo(this.value);" class="learnpath_item_form" size="1">';
  5037. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
  5038. $arrHide = array (
  5039. $id
  5040. );
  5041. $parent_item_id = $_SESSION['parent_item_id'];
  5042. for ($i = 0; $i < count($arrLP); $i++) {
  5043. if ($action != 'add') {
  5044. 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)) {
  5045. $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'] . '">' . api_convert_encoding($arrLP[$i]['title'], $charset, $this->encoding) . '</option>';
  5046. } else {
  5047. $arrHide[] = $arrLP[$i]['id'];
  5048. }
  5049. } else {
  5050. if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
  5051. $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'] . '">' . api_convert_encoding($arrLP[$i]['title'], $charset, $this->encoding) . '</option>';
  5052. }
  5053. }
  5054. if (is_array($arrLP)) {
  5055. reset($arrLP);
  5056. }
  5057. $return .= "\t\t\t\t" . '</select>';
  5058. $return .= "\t\t\t" . '</td>' . "\n";
  5059. $return .= "\t\t" . '</tr>' . "\n";
  5060. $return .= "\t\t" . '<tr>' . "\n";
  5061. $return .= "\t\t\t" . '<td class="label"><label for="idPosition">' . get_lang('Position') . '</label></td>' . "\n";
  5062. $return .= "\t\t\t" . '<td class="input">' . "\n";
  5063. $return .= "\t\t\t\t" . '<select id="idPosition" name="previous" style="width:100%;" size="1" class="learnpath_item_form">';
  5064. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . get_lang('FirstPosition') . '</option>';
  5065. for ($i = 0; $i < count($arrLP); $i++) {
  5066. if ($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) {
  5067. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5068. $selected = 'selected="selected" ';
  5069. elseif ($action == 'add') $selected = 'selected="selected" ';
  5070. else
  5071. $selected = '';
  5072. $return .= "\t\t\t\t\t" . '<option ' . $selected . 'value="' . $arrLP[$i]['id'] . '">' . get_lang("After") . ' "' . api_convert_encoding($arrLP[$i]['title'], $charset, $this->encoding) . '"</option>';
  5073. }
  5074. }
  5075. $return .= "\t\t\t\t" . '</select>';
  5076. $return .= "\t\t\t" . '</td>' . "\n";
  5077. $return .= "\t\t" . '</tr>' . "\n";
  5078. if ($action != 'move') {
  5079. $return .= "\t\t" . '<tr>' . "\n";
  5080. //Remove temporaly the test description
  5081. //$return .= "\t\t\t" . '<td class="label"><label for="idDescription">'.get_lang("Description").' :</label></td>' . "\n";
  5082. //$return .= "\t\t\t" . '<td class="input"><textarea id="idDescription" name="description" rows="4">' . $item_description . '</textarea></td>' . "\n";
  5083. $return .= "\t\t" . '</tr>' . "\n";
  5084. $id_prerequisite = 0;
  5085. if (is_array($arrLP)) {
  5086. foreach ($arrLP as $key => $value) {
  5087. if ($value['id'] == $id) {
  5088. $id_prerequisite = $value['prerequisite'];
  5089. break;
  5090. }
  5091. }
  5092. }
  5093. $arrHide = array ();
  5094. for ($i = 0; $i < count($arrLP); $i++) {
  5095. if ($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter') {
  5096. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5097. $s_selected_position = $arrLP[$i]['id'];
  5098. elseif ($action == 'add') $s_selected_position = 0;
  5099. $arrHide[$arrLP[$i]['id']]['value'] = api_convert_encoding($arrLP[$i]['title'], $charset, $this->encoding);
  5100. }
  5101. }
  5102. /* //comented the prerequisites, only visible in edit (forum)
  5103. $return .= "\t\t" . '<tr>' . "\n";
  5104. $return .= "\t\t\t" . '<td class="label"><label for="idPrerequisites">'.get_lang('Prerequisites').'</label></td>' . "\n";
  5105. $return .= "\t\t\t" . '<td class="input"><select name="prerequisites" id="prerequisites" class="learnpath_item_form"><option value="0">'.get_lang("NoPrerequisites").'</option>';
  5106. foreach($arrHide as $key => $value) {
  5107. if($key==$s_selected_position && $action == 'add') {
  5108. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  5109. }elseif($key==$id_prerequisite && $action == 'edit') {
  5110. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  5111. } else {
  5112. $return .= '<option value="'.$key.'">'.$value['value'].'</option>';
  5113. }
  5114. }
  5115. $return .= "</select></td>";
  5116. */
  5117. $return .= "\t\t" . '</tr>' . "\n";
  5118. }
  5119. $return .= "\t\t" . '<tr>' . "\n";
  5120. $return .= "\t\t\t" . '<td>&nbsp;</td><td><button class="save" name="submit_button" type="submit"> ' . get_lang('AddForumToCourse') . ' </button></td>' . "\n";
  5121. $return .= "\t\t" . '</tr>' . "\n";
  5122. $return .= "\t" . '</table>' . "\n";
  5123. if ($action == 'move') {
  5124. $return .= "\t" . '<input name="title" type="hidden" value="' . $item_title . '" />' . "\n";
  5125. $return .= "\t" . '<input name="description" type="hidden" value="' . $item_description . '" />' . "\n";
  5126. }
  5127. if (is_numeric($extra_info)) {
  5128. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info . '" />' . "\n";
  5129. }
  5130. elseif (is_array($extra_info)) {
  5131. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />' . "\n";
  5132. }
  5133. $return .= "\t" . '<input name="type" type="hidden" value="' . TOOL_FORUM . '" />' . "\n";
  5134. $return .= "\t" . '<input name="post_time" type="hidden" value="' . time() . '" />' . "\n";
  5135. $return .= '</form>' . "\n";
  5136. $return .= '</div>' . "\n";
  5137. return $return;
  5138. }
  5139. /**
  5140. * Return HTML form to add/edit forum threads
  5141. * @param string Action (add/edit)
  5142. * @param integer Item ID if already exists in learning path
  5143. * @param mixed Extra information (thread ID if integer)
  5144. * @return string HTML form
  5145. */
  5146. function display_thread_form($action = 'add', $id = 0, $extra_info = '') {
  5147. global $charset;
  5148. echo '
  5149. <style>
  5150. div.row div.label {
  5151. width:110px;
  5152. }
  5153. div.row div.formw {
  5154. width: 82%;
  5155. }
  5156. </style>';
  5157. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  5158. $tbl_forum = Database :: get_course_table(TABLE_FORUM_THREAD);
  5159. if ($id != 0 && is_array($extra_info)) {
  5160. $item_title = stripslashes($extra_info['title']);
  5161. }
  5162. elseif (is_numeric($extra_info)) {
  5163. $sql_forum = "
  5164. SELECT
  5165. thread_title as title
  5166. FROM " . $tbl_forum . "
  5167. WHERE thread_id = " . $extra_info;
  5168. $result = Database::query($sql_forum, __FILE__, __LINE__);
  5169. $row = Database :: fetch_array($result);
  5170. $item_title = $row['title'];
  5171. $item_description = '';
  5172. } else {
  5173. $item_title = '';
  5174. $item_description = '';
  5175. }
  5176. $item_title = api_convert_encoding($item_title, $charset, $this->encoding);
  5177. $item_description = api_convert_encoding($item_description, $charset, $this->encoding);
  5178. $return = '<div style="margin:3px 12px;">';
  5179. if ($id != 0 && is_array($extra_info))
  5180. $parent = $extra_info['parent_item_id'];
  5181. else
  5182. $parent = 0;
  5183. $sql = "
  5184. SELECT *
  5185. FROM " . $tbl_lp_item . "
  5186. WHERE
  5187. lp_id = " . $this->lp_id;
  5188. $result = Database::query($sql, __FILE__, __LINE__);
  5189. $arrLP = array ();
  5190. while ($row = Database :: fetch_array($result)) {
  5191. $arrLP[] = array (
  5192. 'id' => $row['id'],
  5193. 'item_type' => $row['item_type'],
  5194. 'title' => $row['title'],
  5195. 'path' => $row['path'],
  5196. 'description' => $row['description'],
  5197. 'parent_item_id' => $row['parent_item_id'],
  5198. 'previous_item_id' => $row['previous_item_id'],
  5199. 'next_item_id' => $row['next_item_id'],
  5200. 'display_order' => $row['display_order'],
  5201. 'max_score' => $row['max_score'],
  5202. 'min_score' => $row['min_score'],
  5203. 'mastery_score' => $row['mastery_score'],
  5204. 'prerequisite' => $row['prerequisite']
  5205. );
  5206. }
  5207. $this->tree_array($arrLP);
  5208. $arrLP = $this->arrMenu;
  5209. unset ($this->arrMenu);
  5210. if ($action == 'add')
  5211. $return .= '<p class="lp_title">' . get_lang("CreateTheForum") . '&nbsp;:</p>' . "\n";
  5212. elseif ($action == 'move') $return .= '<p class="lp_title">' . get_lang("MoveTheCurrentForum") . '&nbsp;:</p>' . "\n";
  5213. else
  5214. $return .= '<p class="lp_title">' . get_lang("EditCurrentForum") . '&nbsp;:</p>' . "\n";
  5215. $return .= '<form method="POST">' . "\n";
  5216. $return .= "\t" . '<table cellpadding="0" cellspacing="0" class="lp_form">' . "\n";
  5217. $return .= "\t\t" . '<tr>' . "\n";
  5218. $return .= "\t\t\t" . '<td class="label"><label for="idParent">' . get_lang("Parent") . '&nbsp;:</label></td>' . "\n";
  5219. $return .= "\t\t\t" . '<td class="input">' . "\n";
  5220. $return .= "\t\t\t\t" . '<select id="idParent" name="parent" onchange="load_cbo(this.value);" size="1">';
  5221. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
  5222. $arrHide = array (
  5223. $id
  5224. );
  5225. for ($i = 0; $i < count($arrLP); $i++) {
  5226. if ($action != 'add') {
  5227. 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)) {
  5228. $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'] . '">' . api_convert_encoding($arrLP[$i]['title'], $charset, $this->encoding) . '</option>';
  5229. } else {
  5230. $arrHide[] = $arrLP[$i]['id'];
  5231. }
  5232. } else {
  5233. if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
  5234. $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'] . '">' . api_convert_encoding($arrLP[$i]['title'], $charset, $this->encoding) . '</option>';
  5235. }
  5236. }
  5237. if ($arrLP != null) {
  5238. reset($arrLP);
  5239. }
  5240. $return .= "\t\t\t\t" . '</select>';
  5241. $return .= "\t\t\t" . '</td>' . "\n";
  5242. $return .= "\t\t" . '</tr>' . "\n";
  5243. $return .= "\t\t" . '<tr>' . "\n";
  5244. $return .= "\t\t\t" . '<td class="label"><label for="idPosition">' . get_lang("Position") . '&nbsp;:</label></td>' . "\n";
  5245. $return .= "\t\t\t" . '<td class="input">' . "\n";
  5246. $return .= "\t\t\t\t" . '<select id="idPosition" name="previous" size="1">';
  5247. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . get_lang('FirstPosition') . '</option>';
  5248. for ($i = 0; $i < count($arrLP); $i++) {
  5249. if ($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) {
  5250. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5251. $selected = 'selected="selected" ';
  5252. elseif ($action == 'add') $selected = 'selected="selected" ';
  5253. else
  5254. $selected = '';
  5255. $return .= "\t\t\t\t\t" . '<option ' . $selected . 'value="' . $arrLP[$i]['id'] . '">' . get_lang("After") . ' "' . api_convert_encoding($arrLP[$i]['title'], $charset, $this->encoding) . '"</option>';
  5256. }
  5257. }
  5258. $return .= "\t\t\t\t" . '</select>';
  5259. $return .= "\t\t\t" . '</td>' . "\n";
  5260. $return .= "\t\t" . '</tr>' . "\n";
  5261. if ($action != 'move') {
  5262. $return .= "\t\t" . '<tr>' . "\n";
  5263. $return .= "\t\t\t" . '<td class="label"><label for="idTitle">' . get_lang("Title") . '&nbsp;:</label></td>' . "\n";
  5264. $return .= "\t\t\t" . '<td class="input"><input id="idTitle" name="title" type="text" value="' . $item_title . '" /></td>' . "\n";
  5265. $return .= "\t\t" . '</tr>' . "\n";
  5266. $return .= "\t\t" . '<tr>' . "\n";
  5267. //Remove temporaly the test description
  5268. //$return .= "\t\t\t" . '<td class="label"><label for="idDescription">'.get_lang("Description").' :</label></td>' . "\n";
  5269. //$return .= "\t\t\t" . '<td class="input"><textarea id="idDescription" name="description" rows="4">' . $item_description . '</textarea></td>' . "\n";
  5270. $return .= "\t\t" . '</tr>' . "\n";
  5271. $id_prerequisite = 0;
  5272. if ($arrLP != null) {
  5273. foreach ($arrLP as $key => $value) {
  5274. if ($value['id'] == $id) {
  5275. $id_prerequisite = $value['prerequisite'];
  5276. break;
  5277. }
  5278. }
  5279. }
  5280. $arrHide = array ();
  5281. for ($i = 0; $i < count($arrLP); $i++) {
  5282. if ($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter') {
  5283. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5284. $s_selected_position = $arrLP[$i]['id'];
  5285. elseif ($action == 'add') $s_selected_position = 0;
  5286. $arrHide[$arrLP[$i]['id']]['value'] = api_convert_encoding($arrLP[$i]['title'], $charset, $this->encoding);
  5287. }
  5288. }
  5289. $return .= "\t\t" . '<tr>' . "\n";
  5290. $return .= "\t\t\t" . '<td class="label"><label for="idPrerequisites">' . get_lang("Prerequisites") . '&nbsp;:</label></td>' . "\n";
  5291. $return .= "\t\t\t" . '<td class="input"><select name="prerequisites" id="prerequisites"><option value="0">' . get_lang("NoPrerequisites") . '</option>';
  5292. foreach ($arrHide as $key => $value) {
  5293. if ($key == $s_selected_position && $action == 'add') {
  5294. $return .= '<option value="' . $key . '" selected="selected">' . $value['value'] . '</option>';
  5295. }
  5296. elseif ($key == $id_prerequisite && $action == 'edit') {
  5297. $return .= '<option value="' . $key . '" selected="selected">' . $value['value'] . '</option>';
  5298. } else {
  5299. $return .= '<option value="' . $key . '">' . $value['value'] . '</option>';
  5300. }
  5301. }
  5302. $return .= "</select></td>";
  5303. $return .= "\t\t" . '</tr>' . "\n";
  5304. }
  5305. $return .= "\t\t" . '<tr>' . "\n";
  5306. $return .= "\t\t\t" . '<td colspan="2">
  5307. <button class="save" name="submit_button" type="submit" value="'.get_lang('Ok').'" />'.get_lang('Ok').'</button></td>' . "\n";
  5308. $return .= "\t\t" . '</tr>' . "\n";
  5309. $return .= "\t" . '</table>' . "\n";
  5310. if ($action == 'move') {
  5311. $return .= "\t" . '<input name="title" type="hidden" value="' . $item_title . '" />' . "\n";
  5312. $return .= "\t" . '<input name="description" type="hidden" value="' . $item_description . '" />' . "\n";
  5313. }
  5314. if (is_numeric($extra_info)) {
  5315. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info . '" />' . "\n";
  5316. }
  5317. elseif (is_array($extra_info)) {
  5318. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />' . "\n";
  5319. }
  5320. $return .= "\t" . '<input name="type" type="hidden" value="' . TOOL_THREAD . '" />' . "\n";
  5321. $return .= "\t" . '<input name="post_time" type="hidden" value="' . time() . '" />' . "\n";
  5322. $return .= '</form>' . "\n";
  5323. $return .= '</div>' . "\n";
  5324. return $return;
  5325. }
  5326. /**
  5327. * Return the HTML form to display an item (generally a section/module item)
  5328. *
  5329. * @param string Item type (module/dokeos_module)
  5330. * @param string Title (optional, only when creating)
  5331. * @param string Action ('add'/'edit')
  5332. * @param integer lp_item ID
  5333. * @param mixed Extra info
  5334. * @return string HTML form
  5335. */
  5336. function display_item_form($item_type, $title = '', $action = 'add', $id = 0, $extra_info = 'new') {
  5337. global $_course;
  5338. global $charset;
  5339. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  5340. if ($id != 0 && is_array($extra_info)) {
  5341. $item_title = $extra_info['title'];
  5342. $item_description = $extra_info['description'];
  5343. $item_path = api_get_path(WEB_COURSE_PATH) . $_course['path'] . '/scorm/' . $this->path . '/' . stripslashes($extra_info['path']);
  5344. } else {
  5345. $item_title = '';
  5346. $item_description = '';
  5347. }
  5348. $return = ' <div class="row">
  5349. <div class="form_header">';
  5350. if ($id != 0 && is_array($extra_info))
  5351. $parent = $extra_info['parent_item_id'];
  5352. else
  5353. $parent = 0;
  5354. $sql = "
  5355. SELECT *
  5356. FROM " . $tbl_lp_item . "
  5357. WHERE lp_id = " . $this->lp_id . " AND id != " . $id . " ";
  5358. if ($item_type == 'module')
  5359. $sql .= " AND parent_item_id = 0";
  5360. $result = Database::query($sql, __FILE__, __LINE__);
  5361. $arrLP = array ();
  5362. while ($row = Database :: fetch_array($result)) {
  5363. $arrLP[] = array (
  5364. 'id' => $row['id'],
  5365. 'item_type' => $row['item_type'],
  5366. 'title' => $row['title'],
  5367. 'path' => $row['path'],
  5368. 'description' => $row['description'],
  5369. 'parent_item_id' => $row['parent_item_id'],
  5370. 'previous_item_id' => $row['previous_item_id'],
  5371. 'next_item_id' => $row['next_item_id'],
  5372. 'max_score' => $row['max_score'],
  5373. 'min_score' => $row['min_score'],
  5374. 'mastery_score' => $row['mastery_score'],
  5375. 'prerequisite' => $row['prerequisite'],
  5376. 'display_order' => $row['display_order']
  5377. );
  5378. }
  5379. $this->tree_array($arrLP);
  5380. $arrLP = $this->arrMenu;
  5381. unset ($this->arrMenu);
  5382. $return .= $title . "\n";
  5383. $return .= ' </div>
  5384. </div>';
  5385. require_once (api_get_path(LIBRARY_PATH) . 'formvalidator/FormValidator.class.php');
  5386. $form = new FormValidator('form', 'POST', api_get_self() . "?" . $_SERVER["QUERY_STRING"]);
  5387. //$defaults["title"] = api_convert_encoding($item_title, $charset, $this->encoding);
  5388. $defaults["title"] = api_html_entity_decode(api_convert_encoding($item_title, $charset, $this->encoding), ENT_QUOTES, $charset);
  5389. $defaults["description"] = api_convert_encoding($item_description, $charset, $this->encoding);
  5390. $form->addElement('html', $return);
  5391. //$arrHide = array($id);
  5392. $arrHide[0]['value'] = Security :: remove_XSS(api_convert_encoding($this->name, api_get_system_encoding(), $_SESSION['oLP']->encoding));
  5393. $arrHide[0]['padding'] = 3;
  5394. $charset = api_get_system_encoding();
  5395. if ($item_type != 'module' && $item_type != 'dokeos_module') {
  5396. for ($i = 0; $i < count($arrLP); $i++) {
  5397. if ($action != 'add') {
  5398. 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)) {
  5399. $arrHide[$arrLP[$i]['id']]['value'] = api_convert_encoding($arrLP[$i]['title'], $charset, $this->encoding);
  5400. $arrHide[$arrLP[$i]['id']]['padding'] = 3 + $arrLP[$i]['depth'] * 10;
  5401. if ($parent == $arrLP[$i]['id']) {
  5402. $s_selected_parent = $arrHide[$arrLP[$i]['id']];
  5403. }
  5404. }
  5405. } else {
  5406. if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir') {
  5407. $arrHide[$arrLP[$i]['id']]['value'] = api_convert_encoding($arrLP[$i]['title'], $charset, $this->encoding);
  5408. $arrHide[$arrLP[$i]['id']]['padding'] = 3 + $arrLP[$i]['depth'] * 10;
  5409. if ($parent == $arrLP[$i]['id']) {
  5410. $s_selected_parent = $arrHide[$arrLP[$i]['id']];
  5411. }
  5412. }
  5413. }
  5414. }
  5415. if ($action != 'move') {
  5416. $form->addElement('text', 'title', get_lang('Title'), 'id="idTitle" class="learnpath_chapter_form" size="40%"');
  5417. $form->applyFilter('title', 'html_filter');
  5418. $form->addRule('title', '<div class="required">' . get_lang('ThisFieldIsRequired'), 'required');
  5419. //$form->addElement('textarea','description',get_lang("Description").' :', 'id="idDescription"');
  5420. } else {
  5421. $form->addElement('hidden', 'title');
  5422. }
  5423. $parent_select = & $form->addElement('select', 'parent', get_lang("Parent"), '', 'class="learnpath_chapter_form" style="width:37%;" id="Parent" onchange="load_cbo(this.value);"');
  5424. foreach ($arrHide as $key => $value) {
  5425. $parent_select->addOption($value['value'], $key, 'style="padding-left:' . $value['padding'] . 'px;"');
  5426. }
  5427. $parent_select->setSelected($s_selected_parent);
  5428. }
  5429. if (is_array($arrLP)) {
  5430. reset($arrLP);
  5431. }
  5432. $arrHide = array ();
  5433. //POSITION
  5434. for ($i = 0; $i < count($arrLP); $i++) {
  5435. if ($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) {
  5436. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5437. $s_selected_position = $arrLP[$i]['id'];
  5438. elseif ($action == 'add') $s_selected_position = $arrLP[$i]['id'];
  5439. $arrHide[$arrLP[$i]['id']]['value'] = get_lang("After") . ' "' . api_convert_encoding($arrLP[$i]['title'], $charset, $this->encoding);
  5440. }
  5441. }
  5442. $position = & $form->addElement('select', 'previous', get_lang('Position'), '', 'id="idPosition" class="learnpath_chapter_form" style="width:37%;"');
  5443. $position->addOption(get_lang('FirstPosition'), 0, 'style="padding-left:' . $value['padding'] . 'px;"');
  5444. foreach ($arrHide as $key => $value) {
  5445. $position->addOption($value['value'] . '"', $key, 'style="padding-left:' . $value['padding'] . 'px;"');
  5446. }
  5447. if (!empty ($s_selected_position)) {
  5448. $position->setSelected($s_selected_position);
  5449. }
  5450. if (is_array($arrLP)) {
  5451. reset($arrLP);
  5452. }
  5453. $form->addElement('style_submit_button', 'submit_button', get_lang('SaveSection'), 'class="save"');
  5454. if ($item_type == 'module' || $item_type == 'dokeos_module') {
  5455. $form->addElement('hidden', 'parent', '0');
  5456. }
  5457. $extension = pathinfo($item_path, PATHINFO_EXTENSION);
  5458. if (($item_type == 'asset' || $item_type == 'sco') && ($extension == 'html' || $extension == 'htm')) {
  5459. if ($item_type == 'sco') {
  5460. $form->addElement('html', '<script type="text/javascript">alert("' . get_lang('WarningWhenEditingScorm') . '")</script>');
  5461. }
  5462. $renderer = $form->defaultRenderer();
  5463. $renderer->setElementTemplate('<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{label}<br />{element}', 'content_lp');
  5464. $form->addElement('html_editor', 'content_lp', '', null, array('ToolbarSet' => 'LearningPathDocuments', 'Width' => '100%', 'Height' => '400', 'FullPage' => true));
  5465. $defaults["content_lp"] = file_get_contents($item_path);
  5466. }
  5467. $form->addElement('hidden', 'type', 'dokeos_' . $item_type);
  5468. $form->addElement('hidden', 'post_time', time());
  5469. $form->setDefaults($defaults);
  5470. return $form->return_form();
  5471. }
  5472. /**
  5473. * Returns the form to update or create a document
  5474. *
  5475. * @param string Action (add/edit)
  5476. * @param integer ID of the lp_item (if already exists)
  5477. * @param mixed Integer if document ID, string if info ('new')
  5478. * @return string HTML form
  5479. */
  5480. function display_document_form($action = 'add', $id = 0, $extra_info = 'new') {
  5481. global $charset;
  5482. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  5483. $tbl_doc = Database :: get_course_table(TABLE_DOCUMENT);
  5484. $path_parts = pathinfo($extra_info['dir']);
  5485. $no_display_edit_textarea = false;
  5486. //If action==edit document
  5487. //We don't display the document form if it's not an editable document (html or txt file)
  5488. if ($action == "edit") {
  5489. if (is_array($extra_info)) {
  5490. if ($path_parts['extension'] != "txt" && $path_parts['extension'] != "html") {
  5491. $no_display_edit_textarea = true;
  5492. }
  5493. }
  5494. }
  5495. $no_display_add = false;
  5496. //If action==add an existing document
  5497. //We don't display the document form if it's not an editable document (html or txt file)
  5498. if ($action == "add") {
  5499. if (is_numeric($extra_info)) {
  5500. $sql_doc = "SELECT path FROM " . $tbl_doc . "WHERE id = " . Database :: escape_string($extra_info);
  5501. $result = Database::query($sql_doc, __FILE__, __LINE__);
  5502. $path_file = Database :: result($result, 0, 0);
  5503. $path_parts = pathinfo($path_file);
  5504. if ($path_parts['extension'] != "txt" && $path_parts['extension'] != "html") {
  5505. $no_display_add = true;
  5506. }
  5507. }
  5508. }
  5509. if ($id != 0 && is_array($extra_info)) {
  5510. $item_title = stripslashes($extra_info['title']);
  5511. $item_description = stripslashes($extra_info['description']);
  5512. $item_terms = stripslashes($extra_info['terms']);
  5513. if (empty ($item_title)) {
  5514. $path_parts = pathinfo($extra_info['path']);
  5515. $item_title = stripslashes($path_parts['filename']);
  5516. }
  5517. }
  5518. elseif (is_numeric($extra_info)) {
  5519. $sql_doc = "SELECT path, title
  5520. FROM " . $tbl_doc . "
  5521. WHERE id = " . Database :: escape_string($extra_info);
  5522. $result = Database::query($sql_doc, __FILE__, __LINE__);
  5523. $row = Database :: fetch_array($result);
  5524. $explode = explode('.', $row['title']);
  5525. if (count($explode) > 1) {
  5526. for ($i = 0; $i < count($explode) - 1; $i++)
  5527. $item_title .= $explode[$i];
  5528. } else {
  5529. $item_title = $row['title'];
  5530. }
  5531. $item_title = str_replace('_', ' ', $item_title);
  5532. if (empty ($item_title)) {
  5533. $path_parts = pathinfo($row['path']);
  5534. $item_title = stripslashes($path_parts['filename']);
  5535. }
  5536. } else {
  5537. $item_title = '';
  5538. $item_description = '';
  5539. }
  5540. $return = ' <div class="row">
  5541. <div class="form_header">';
  5542. if ($id != 0 && is_array($extra_info))
  5543. $parent = $extra_info['parent_item_id'];
  5544. else
  5545. $parent = 0;
  5546. $sql = "
  5547. SELECT *
  5548. FROM " . $tbl_lp_item . "
  5549. WHERE
  5550. lp_id = " . $this->lp_id;
  5551. $result = Database::query($sql, __FILE__, __LINE__);
  5552. $arrLP = array ();
  5553. while ($row = Database :: fetch_array($result)) {
  5554. $arrLP[] = array (
  5555. 'id' => $row['id'],
  5556. 'item_type' => $row['item_type'],
  5557. 'title' => $row['title'],
  5558. 'path' => $row['path'],
  5559. 'description' => $row['description'],
  5560. 'parent_item_id' => $row['parent_item_id'],
  5561. 'previous_item_id' => $row['previous_item_id'],
  5562. 'next_item_id' => $row['next_item_id'],
  5563. 'display_order' => $row['display_order'],
  5564. 'max_score' => $row['max_score'],
  5565. 'min_score' => $row['min_score'],
  5566. 'mastery_score' => $row['mastery_score'],
  5567. 'prerequisite' => $row['prerequisite']
  5568. );
  5569. }
  5570. $this->tree_array($arrLP);
  5571. $arrLP = $this->arrMenu;
  5572. unset ($this->arrMenu);
  5573. if ($action == 'add') {
  5574. $return .= get_lang("CreateTheDocument") . "\n";
  5575. }
  5576. elseif ($action == 'move') {
  5577. $return .= get_lang("MoveTheCurrentDocument") . "\n";
  5578. } else {
  5579. $return .= get_lang("EditTheCurrentDocument") . "\n";
  5580. }
  5581. $return .= ' </div>
  5582. </div>';
  5583. if (isset ($_GET['edit']) && $_GET['edit'] == 'true') {
  5584. $return .= Display :: return_warning_message('<strong>' . get_lang("Warning") . ' !</strong><br />' . get_lang("WarningEditingDocument"), false);
  5585. }
  5586. require_once (api_get_path(LIBRARY_PATH) . 'formvalidator/FormValidator.class.php');
  5587. $form = new FormValidator('form', 'POST', api_get_self() . "?" . $_SERVER["QUERY_STRING"], '', 'enctype="multipart/form-data"');
  5588. $defaults["title"] = Security :: remove_XSS(api_convert_encoding($item_title, api_get_system_encoding() ,$this->encoding));
  5589. if (empty ($item_title)) {
  5590. $defaults["title"] = Security :: remove_XSS($item_title);
  5591. }
  5592. $defaults["description"] = api_convert_encoding($item_description, $charset, $this->encoding);
  5593. $form->addElement('html', $return);
  5594. if ($action != 'move') {
  5595. $form->addElement('text', 'title', get_lang('Title'), 'id="idTitle" class="learnpath_item_form" size=44%');
  5596. $form->applyFilter('title', 'html_filter');
  5597. }
  5598. //$arrHide = array($id);
  5599. $arrHide[0]['value'] = $this->name;
  5600. $arrHide[0]['padding'] = 3;
  5601. for ($i = 0; $i < count($arrLP); $i++) {
  5602. if ($action != 'add') {
  5603. 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)) {
  5604. $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
  5605. $arrHide[$arrLP[$i]['id']]['padding'] = 3 + $arrLP[$i]['depth'] * 10;
  5606. if ($parent == $arrLP[$i]['id']) {
  5607. $s_selected_parent = $arrHide[$arrLP[$i]['id']];
  5608. }
  5609. }
  5610. } else {
  5611. if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir') {
  5612. $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
  5613. $arrHide[$arrLP[$i]['id']]['padding'] = 3 + $arrLP[$i]['depth'] * 10;
  5614. if ($parent == $arrLP[$i]['id']) {
  5615. $s_selected_parent = $arrHide[$arrLP[$i]['id']];
  5616. }
  5617. }
  5618. }
  5619. }
  5620. $parent_select = & $form->addElement('select', 'parent', get_lang('Parent'), '', 'class="learnpath_item_form" style="width:40%;" onchange="load_cbo(this.value);"');
  5621. $my_count=0;
  5622. foreach ($arrHide as $key => $value) {
  5623. if ($my_count!=0) {
  5624. // the LP name is also the first section and is not in the same charset like the other sections
  5625. $value['value'] = Security :: remove_XSS(api_convert_encoding($value['value'], api_get_system_encoding(), $this->encoding));
  5626. $parent_select->addOption($value['value'], $key, 'style="padding-left:' . $value['padding'] . 'px;"');
  5627. } else {
  5628. $value['value'] = Security :: remove_XSS($value['value']);
  5629. $parent_select->addOption($value['value'], $key, 'style="padding-left:' . $value['padding'] . 'px;"');
  5630. }
  5631. $my_count++;
  5632. }
  5633. if (!empty ($id)) {
  5634. $parent_select->setSelected($parent);
  5635. } else {
  5636. $parent_item_id = $_SESSION['parent_item_id'];
  5637. $parent_select->setSelected($parent_item_id);
  5638. }
  5639. if (is_array($arrLP)) {
  5640. reset($arrLP);
  5641. }
  5642. $arrHide = array ();
  5643. //POSITION
  5644. for ($i = 0; $i < count($arrLP); $i++) {
  5645. if ($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) {
  5646. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5647. $s_selected_position = $arrLP[$i]['id'];
  5648. elseif ($action == 'add') $s_selected_position = $arrLP[$i]['id'];
  5649. $arrHide[$arrLP[$i]['id']]['value'] = get_lang("After") . ' "' . api_convert_encoding($arrLP[$i]['title'], $charset, $this->encoding) . '"';
  5650. }
  5651. }
  5652. $position = & $form->addElement('select', 'previous', get_lang('Position'), '', 'id="idPosition" class="learnpath_item_form" style="width:40%;"');
  5653. $position->addOption(get_lang("FirstPosition"), 0);
  5654. foreach ($arrHide as $key => $value) {
  5655. $position->addOption($value['value'], $key, 'style="padding-left:' . $value['padding'] . 'px;"');
  5656. }
  5657. $position->setSelected($s_selected_position);
  5658. if (is_array($arrLP)) {
  5659. reset($arrLP);
  5660. }
  5661. if ($action != 'move') {
  5662. $id_prerequisite = 0;
  5663. if (is_array($arrLP)) {
  5664. foreach ($arrLP as $key => $value) {
  5665. if ($value['id'] == $id) {
  5666. $id_prerequisite = $value['prerequisite'];
  5667. break;
  5668. }
  5669. }
  5670. }
  5671. //comented the prerequisites, only visible in edit (new document)
  5672. //$select_prerequisites=$form->addElement('select', 'prerequisites', get_lang('Prerequisites'),null,'id="prerequisites" class="learnpath_item_form" style="width:263px;"');
  5673. //$select_prerequisites->addOption(get_lang("NoPrerequisites"),0);
  5674. // form element for uploading an mp3 file
  5675. //$form->addElement('file','mp3',get_lang('UploadMp3audio'),'id="mp3" size="33"');
  5676. //$form->addRule('file', 'The extension of the Song file should be *.mp3', 'filename', '/^.*\.mp3$/');
  5677. /* Code deprecated - moved to lp level (not lp-item)
  5678. if ( api_get_setting('search_enabled') === 'true' )
  5679. {
  5680. //add terms field
  5681. $terms = $form->addElement('text','terms', get_lang('SearchFeatureTerms').'&nbsp;:','id="idTerms" class="learnpath_item_form"');
  5682. $terms->setValue($item_terms);
  5683. }
  5684. */
  5685. $arrHide = array ();
  5686. for ($i = 0; $i < count($arrLP); $i++) {
  5687. if ($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter') {
  5688. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5689. $s_selected_position = $arrLP[$i]['id'];
  5690. elseif ($action == 'add') $s_selected_position = $arrLP[$i]['id'];
  5691. $arrHide[$arrLP[$i]['id']]['value'] = api_convert_encoding($arrLP[$i]['title'], $charset, $this->encoding);
  5692. }
  5693. }
  5694. /* foreach($arrHide as $key => $value){
  5695. $select_prerequisites->addOption($value['value'],$key,'style="padding-left:'.$value['padding'].'px;"');
  5696. if($key==$s_selected_position && $action == 'add'){
  5697. $select_prerequisites -> setSelected(0);
  5698. }
  5699. elseif($key==$id_prerequisite && $action == 'edit'){
  5700. $select_prerequisites -> setSelected($id_prerequisite);
  5701. }
  5702. }
  5703. */
  5704. if (!$no_display_add) {
  5705. if (($extra_info == 'new' || $extra_info['item_type'] == TOOL_DOCUMENT || $_GET['edit'] == 'true')) {
  5706. if (isset ($_POST['content']))
  5707. $content = stripslashes($_POST['content']);
  5708. elseif (is_array($extra_info)) {
  5709. //If it's an html document or a text file
  5710. if (!$no_display_edit_textarea) {
  5711. $content = $this->display_document($extra_info['path'], false, false);
  5712. }
  5713. }
  5714. elseif (is_numeric($extra_info)) $content = $this->display_document($extra_info, false, false);
  5715. else
  5716. $content = '';
  5717. if (!$no_display_edit_textarea) {
  5718. // We need to claculate here some specific settings for the online editor.
  5719. // The calculated settings work for documents in the Documents tool
  5720. // (on the root or in subfolders).
  5721. // For documents in native scorm packages it is unclear whether the
  5722. // online editor should be activated or not.
  5723. $relative_path = $extra_info['dir'];
  5724. if ($relative_path == 'n/') {
  5725. // A new document, it is in the root of the repository.
  5726. $relative_path = '';
  5727. $relative_prefix = '';
  5728. } else {
  5729. // The document already exists. Whe have to determine its relative path towards the repository root.
  5730. $relative_path = explode('/', $relative_path);
  5731. $cnt = count($relative_path) - 2;
  5732. if ($cnt < 0) {
  5733. $cnt = 0;
  5734. }
  5735. $relative_prefix = str_repeat('../', $cnt);
  5736. $relative_path = array_slice($relative_path, 1, $cnt);
  5737. $relative_path = implode('/', $relative_path);
  5738. if (strlen($relative_path) > 0) {
  5739. $relative_path = $relative_path . '/';
  5740. }
  5741. }
  5742. $editor_config = array('ToolbarSet' => 'LearningPathDocuments', 'Width' => '100%', 'Height' => '700', 'FullPage' => true,
  5743. 'CreateDocumentDir' => $relative_prefix,
  5744. 'CreateDocumentWebDir' => api_get_path('WEB_COURSE_PATH') . api_get_course_path() . '/document/',
  5745. 'BaseHref' => api_get_path('WEB_COURSE_PATH') . api_get_course_path() . '/document/' . $relative_path
  5746. );
  5747. if ($_GET['action'] == 'add_item') {
  5748. $class = 'add';
  5749. $text = get_lang('LPCreateDocument');
  5750. } else
  5751. if ($_GET['action'] == 'edit_item') {
  5752. $class = 'save';
  5753. $text = get_lang('SaveDocument');
  5754. }
  5755. $form->addElement('style_submit_button', 'submit_button', $text, 'class="' . $class . '"');
  5756. $renderer = $form->defaultRenderer();
  5757. $renderer->setElementTemplate('<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{label}<br />{element}', 'content_lp');
  5758. $form->addElement('html', '<div style="margin:3px 12px">');
  5759. $form->addElement('html_editor', 'content_lp', '', null, $editor_config);
  5760. $form->addElement('html', '</div>');
  5761. $defaults["content_lp"] = $content;
  5762. }
  5763. }
  5764. elseif (is_numeric($extra_info)) {
  5765. $form->addElement('style_submit_button', 'submit_button', get_lang('SaveDocument'), 'class="save"');
  5766. $return = $this->display_document($extra_info, true, true, true);
  5767. $form->addElement('html', $return);
  5768. }
  5769. }
  5770. }
  5771. if ($action == 'move') {
  5772. $form->addElement('hidden', 'title', $item_title);
  5773. $form->addElement('hidden', 'description', $item_description);
  5774. }
  5775. if (is_numeric($extra_info)) {
  5776. $form->addElement('style_submit_button', 'submit_button', get_lang('SaveDocument'), 'value="submit_button", class="save"');
  5777. $form->addElement('hidden', 'path', $extra_info);
  5778. }
  5779. elseif (is_array($extra_info)) {
  5780. $form->addElement('style_submit_button', 'submit_button', get_lang('SaveDocument'), 'class="save"');
  5781. $form->addElement('hidden', 'path', $extra_info['path']);
  5782. }
  5783. $form->addElement('hidden', 'type', TOOL_DOCUMENT);
  5784. $form->addElement('hidden', 'post_time', time());
  5785. $form->setDefaults($defaults);
  5786. return $form->return_form();
  5787. }
  5788. /**
  5789. * Return HTML form to add/edit a link item
  5790. *
  5791. * @param string Action (add/edit)
  5792. * @param integer Item ID if exists
  5793. * @param mixed Extra info
  5794. * @return string HTML form
  5795. */
  5796. function display_link_form($action = 'add', $id = 0, $extra_info = '') {
  5797. global $charset;
  5798. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  5799. $tbl_link = Database :: get_course_table(TABLE_LINK);
  5800. if ($id != 0 && is_array($extra_info)) {
  5801. $item_title = stripslashes($extra_info['title']);
  5802. $item_description = stripslashes($extra_info['description']);
  5803. $item_url = stripslashes($extra_info['url']);
  5804. }
  5805. elseif (is_numeric($extra_info)) {
  5806. $sql_link = "
  5807. SELECT
  5808. title,
  5809. description,
  5810. url
  5811. FROM " . $tbl_link . "
  5812. WHERE id = " . $extra_info;
  5813. $result = Database::query($sql_link, __FILE__, __LINE__);
  5814. $row = Database :: fetch_array($result);
  5815. $item_title = $row['title'];
  5816. $item_description = $row['description'];
  5817. $item_url = $row['url'];
  5818. } else {
  5819. $item_title = '';
  5820. $item_description = '';
  5821. $item_url = '';
  5822. }
  5823. $item_title = api_convert_encoding($item_title, $charset, $this->encoding);
  5824. $item_description = api_convert_encoding($item_description, $charset, $this->encoding);
  5825. $return = ' <div class="row">
  5826. <div class="form_header">';
  5827. if ($id != 0 && is_array($extra_info))
  5828. $parent = $extra_info['parent_item_id'];
  5829. else
  5830. $parent = 0;
  5831. $sql = "
  5832. SELECT *
  5833. FROM " . $tbl_lp_item . "
  5834. WHERE
  5835. lp_id = " . $this->lp_id;
  5836. $result = Database::query($sql, __FILE__, __LINE__);
  5837. $arrLP = array ();
  5838. while ($row = Database :: fetch_array($result)) {
  5839. $arrLP[] = array (
  5840. 'id' => $row['id'],
  5841. 'item_type' => $row['item_type'],
  5842. 'title' => $row['title'],
  5843. 'path' => $row['path'],
  5844. 'description' => $row['description'],
  5845. 'parent_item_id' => $row['parent_item_id'],
  5846. 'previous_item_id' => $row['previous_item_id'],
  5847. 'next_item_id' => $row['next_item_id'],
  5848. 'display_order' => $row['display_order'],
  5849. 'max_score' => $row['max_score'],
  5850. 'min_score' => $row['min_score'],
  5851. 'mastery_score' => $row['mastery_score'],
  5852. 'prerequisite' => $row['prerequisite']
  5853. );
  5854. }
  5855. $this->tree_array($arrLP);
  5856. $arrLP = $this->arrMenu;
  5857. unset ($this->arrMenu);
  5858. if ($action == 'add')
  5859. $return .= get_lang("CreateTheLink") . '&nbsp;:' . "\n";
  5860. elseif ($action == 'move') $return .= get_lang("MoveCurrentLink") . '&nbsp;:' . "\n";
  5861. else
  5862. $return .= get_lang("EditCurrentLink") . '&nbsp;:' . "\n";
  5863. $return .= ' </div>
  5864. </div>';
  5865. $return .= '<div class="sectioncomment">';
  5866. $return .= '<form method="POST">' . "\n";
  5867. $return .= "\t" . '<table>' . "\n";
  5868. if ($action != 'move') {
  5869. $return .= "\t\t" . '<tr>' . "\n";
  5870. $return .= "\t\t\t" . '<td class="label"><label for="idTitle">' . get_lang('Title') . '</label></td>' . "\n";
  5871. $return .= "\t\t\t" . '<td class="input"><input id="idTitle" name="title" size="44" type="text" value="' . $item_title . '" class="learnpath_item_form"/></td>' . "\n";
  5872. $return .= "\t\t" . '</tr>' . "\n";
  5873. }
  5874. $return .= "\t\t" . '<tr>' . "\n";
  5875. $return .= "\t\t\t" . '<td class="label"><label for="idParent">' . get_lang('Parent') . '</label></td>' . "\n";
  5876. $return .= "\t\t\t" . '<td class="input">' . "\n";
  5877. $return .= "\t\t\t\t" . '<select id="idParent" style="width:100%;" name="parent" onchange="load_cbo(this.value);" class="learnpath_item_form" size="1">';
  5878. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
  5879. $arrHide = array (
  5880. $id
  5881. );
  5882. $parent_item_id = $_SESSION['parent_item_id'];
  5883. for ($i = 0; $i < count($arrLP); $i++) {
  5884. if ($action != 'add') {
  5885. 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)) {
  5886. $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'] . '">' . api_convert_encoding($arrLP[$i]['title'], $charset, $this->encoding) . '</option>';
  5887. } else {
  5888. $arrHide[] = $arrLP[$i]['id'];
  5889. }
  5890. } else {
  5891. if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
  5892. $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'] . '">' . api_convert_encoding($arrLP[$i]['title'], $charset, $this->encoding) . '</option>';
  5893. }
  5894. }
  5895. if (is_array($arrLP)) {
  5896. reset($arrLP);
  5897. }
  5898. $return .= "\t\t\t\t" . '</select>';
  5899. $return .= "\t\t\t" . '</td>' . "\n";
  5900. $return .= "\t\t" . '</tr>' . "\n";
  5901. $return .= "\t\t" . '<tr>' . "\n";
  5902. $return .= "\t\t\t" . '<td class="label"><label for="idPosition">' . get_lang('Position') . '</label></td>' . "\n";
  5903. $return .= "\t\t\t" . '<td class="input">' . "\n";
  5904. $return .= "\t\t\t\t" . '<select id="idPosition" name="previous" style="width:100%;" size="1" class="learnpath_item_form">';
  5905. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . get_lang("FirstPosition") . '</option>';
  5906. for ($i = 0; $i < count($arrLP); $i++) {
  5907. if ($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) {
  5908. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5909. $selected = 'selected="selected" ';
  5910. elseif ($action == 'add') $selected = 'selected="selected" ';
  5911. else
  5912. $selected = '';
  5913. $return .= "\t\t\t\t\t" . '<option ' . $selected . 'value="' . $arrLP[$i]['id'] . '">' . get_lang("After") . ' "' . api_convert_encoding($arrLP[$i]['title'], $charset, $this->encoding) . '"</option>';
  5914. }
  5915. }
  5916. $return .= "\t\t\t\t" . '</select>';
  5917. $return .= "\t\t\t" . '</td>' . "\n";
  5918. $return .= "\t\t" . '</tr>' . "\n";
  5919. if ($action != 'move') {
  5920. //Description filed is commentd for link
  5921. /*$return .= "\t\t" . '<tr>' . "\n";
  5922. $return .= "\t\t\t" . '<td class="label"><label for="idDescription">'.get_lang('Description').'</label></td>' . "\n";
  5923. $return .= "\t\t\t" . '<td class="input"><textarea id="idDescription" style="width:100%;" name="description" class="learnpath_item_form" rows="4">' . $item_description . '</textarea></td>' . "\n";
  5924. $return .= "\t\t" . '</tr>' . "\n";*/
  5925. $return .= "\t\t" . '<tr>' . "\n";
  5926. $return .= "\t\t\t" . '<td class="label"><label for="idURL">' . get_lang('Url') . '</label></td>' . "\n";
  5927. $return .= "\t\t\t" . '<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>' . "\n";
  5928. $return .= "\t\t" . '</tr>' . "\n";
  5929. $id_prerequisite = 0;
  5930. if (is_array($arrLP)) {
  5931. foreach ($arrLP as $key => $value) {
  5932. if ($value['id'] == $id) {
  5933. $id_prerequisite = $value['prerequisite'];
  5934. break;
  5935. }
  5936. }
  5937. }
  5938. $arrHide = array ();
  5939. for ($i = 0; $i < count($arrLP); $i++) {
  5940. if ($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter') {
  5941. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5942. $s_selected_position = $arrLP[$i]['id'];
  5943. elseif ($action == 'add') $s_selected_position = 0;
  5944. $arrHide[$arrLP[$i]['id']]['value'] = api_convert_encoding($arrLP[$i]['title'], $charset, $this->encoding);
  5945. }
  5946. }
  5947. /*//comented the prerequisites, only visible in edit (link)
  5948. $return .= "\t\t" . '<tr>' . "\n";
  5949. $return .= "\t\t\t" . '<td class="label"><label for="idPrerequisites">'.get_lang('Prerequisites').'</label></td>' . "\n";
  5950. $return .= "\t\t\t" . '<td class="input"><select name="prerequisites" id="prerequisites" class="learnpath_item_form"><option value="0">'.get_lang("NoPrerequisites").'</option>';
  5951. foreach($arrHide as $key => $value)
  5952. {
  5953. if($key==$s_selected_position && $action == 'add')
  5954. {
  5955. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  5956. }
  5957. elseif($key==$id_prerequisite && $action == 'edit'){
  5958. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  5959. }
  5960. else{
  5961. $return .= '<option value="'.$key.'">'.$value['value'].'</option>';
  5962. }
  5963. }
  5964. $return .= "</select></td>";
  5965. */
  5966. $return .= "\t\t" . '</tr>' . "\n";
  5967. }
  5968. $return .= "\t\t" . '<tr>' . "\n";
  5969. $return .= "\t\t\t" . '<td>&nbsp;</td><td><button class="save" name="submit_button" type="submit">' . get_lang("AddLinkToCourse") . '</button></td>' . "\n";
  5970. $return .= "\t\t" . '</tr>' . "\n";
  5971. $return .= "\t" . '</table>' . "\n";
  5972. if ($action == 'move') {
  5973. $return .= "\t" . '<input name="title" type="hidden" value="' . $item_title . '" />' . "\n";
  5974. $return .= "\t" . '<input name="description" type="hidden" value="' . $item_description . '" />' . "\n";
  5975. }
  5976. if (is_numeric($extra_info)) {
  5977. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info . '" />' . "\n";
  5978. }
  5979. elseif (is_array($extra_info)) {
  5980. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />' . "\n";
  5981. }
  5982. $return .= "\t" . '<input name="type" type="hidden" value="' . TOOL_LINK . '" />' . "\n";
  5983. $return .= "\t" . '<input name="post_time" type="hidden" value="' . time() . '" />' . "\n";
  5984. $return .= '</form>' . "\n";
  5985. $return .= '</div>' . "\n";
  5986. return $return;
  5987. }
  5988. /**
  5989. * Return HTML form to add/edit a student publication (work)
  5990. *
  5991. * @param string Action (add/edit)
  5992. * @param integer Item ID if already exists
  5993. * @param mixed Extra info (work ID if integer)
  5994. * @return string HTML form
  5995. */
  5996. function display_student_publication_form($action = 'add', $id = 0, $extra_info = '') {
  5997. global $charset;
  5998. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  5999. $tbl_publication = Database :: get_course_table(TABLE_STUDENT_PUBLICATION);
  6000. if ($id != 0 && is_array($extra_info)) {
  6001. $item_title = stripslashes($extra_info['title']);
  6002. $item_description = stripslashes($extra_info['description']);
  6003. }
  6004. elseif (is_numeric($extra_info)) {
  6005. $sql_publication = "
  6006. SELECT
  6007. title,
  6008. description
  6009. FROM " . $tbl_publication . "
  6010. WHERE id = " . $extra_info;
  6011. $result = Database::query($sql_publication, __FILE__, __LINE__);
  6012. $row = Database :: fetch_array($result);
  6013. $item_title = $row['title'];
  6014. } else {
  6015. $item_title = get_lang('Student_publication');
  6016. }
  6017. $item_title = api_convert_encoding($item_title, $charset, $this->encoding);
  6018. $return = ' <div class="row">
  6019. <div class="form_header">';
  6020. if ($id != 0 && is_array($extra_info))
  6021. $parent = $extra_info['parent_item_id'];
  6022. else
  6023. $parent = 0;
  6024. $sql = "
  6025. SELECT *
  6026. FROM " . $tbl_lp_item . "
  6027. WHERE
  6028. lp_id = " . $this->lp_id;
  6029. $result = Database::query($sql, __FILE__, __LINE__);
  6030. $arrLP = array ();
  6031. while ($row = Database :: fetch_array($result)) {
  6032. $arrLP[] = array (
  6033. 'id' => $row['id'],
  6034. 'item_type' => $row['item_type'],
  6035. 'title' => $row['title'],
  6036. 'path' => $row['path'],
  6037. 'description' => $row['description'],
  6038. 'parent_item_id' => $row['parent_item_id'],
  6039. 'previous_item_id' => $row['previous_item_id'],
  6040. 'next_item_id' => $row['next_item_id'],
  6041. 'display_order' => $row['display_order'],
  6042. 'max_score' => $row['max_score'],
  6043. 'min_score' => $row['min_score'],
  6044. 'mastery_score' => $row['mastery_score'],
  6045. 'prerequisite' => $row['prerequisite']
  6046. );
  6047. }
  6048. $this->tree_array($arrLP);
  6049. $arrLP = $this->arrMenu;
  6050. unset ($this->arrMenu);
  6051. if ($action == 'add')
  6052. $return .= get_lang("Student_publication") . '&nbsp;:' . "\n";
  6053. elseif ($action == 'move') $return .= get_lang("MoveCurrentStudentPublication") . '&nbsp;:' . "\n";
  6054. else
  6055. $return .= get_lang("EditCurrentStudentPublication") . '&nbsp;:' . "\n";
  6056. $return .= ' </div>
  6057. </div>';
  6058. $return .= '<div class="sectioncomment">';
  6059. $return .= '<form method="POST">' . "\n";
  6060. $return .= "\t" . '<table class="lp_form">' . "\n";
  6061. if ($action != 'move') {
  6062. $return .= "\t\t" . '<tr>' . "\n";
  6063. $return .= "\t\t\t" . '<td class="label"><label for="idTitle">' . get_lang('Title') . '</label></td>' . "\n";
  6064. $return .= "\t\t\t" . '<td class="input"><input id="idTitle" name="title" size="44" type="text" value="' . $item_title . '" class="learnpath_item_form" /></td>' . "\n";
  6065. $return .= "\t\t" . '</tr>' . "\n";
  6066. }
  6067. $return .= "\t\t" . '<tr>' . "\n";
  6068. $return .= "\t\t\t" . '<td class="label"><label for="idParent">' . get_lang('Parent') . '</label></td>' . "\n";
  6069. $return .= "\t\t\t" . '<td class="input">' . "\n";
  6070. $return .= "\t\t\t\t" . '<select id="idParent" name="parent" style="width:100%;" onchange="load_cbo(this.value);" class="learnpath_item_form" size="1">';
  6071. $parent_item_id = $_SESSION['parent_item_id'];
  6072. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
  6073. $arrHide = array (
  6074. $id
  6075. );
  6076. for ($i = 0; $i < count($arrLP); $i++) {
  6077. if ($action != 'add') {
  6078. 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)) {
  6079. $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'] . '">' . api_convert_encoding($arrLP[$i]['title'], $charset, $this->encoding) . '</option>';
  6080. } else {
  6081. $arrHide[] = $arrLP[$i]['id'];
  6082. }
  6083. } else {
  6084. if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
  6085. $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'] . '">' . api_convert_encoding($arrLP[$i]['title'], $charset, $this->encoding) . '</option>';
  6086. }
  6087. }
  6088. if (is_array($arrLP)) {
  6089. reset($arrLP);
  6090. }
  6091. $return .= "\t\t\t\t" . '</select>';
  6092. $return .= "\t\t\t" . '</td>' . "\n";
  6093. $return .= "\t\t" . '</tr>' . "\n";
  6094. $return .= "\t\t" . '<tr>' . "\n";
  6095. $return .= "\t\t\t" . '<td class="label"><label for="idPosition">' . get_lang('Position') . '</label></td>' . "\n";
  6096. $return .= "\t\t\t" . '<td class="input">' . "\n";
  6097. $return .= "\t\t\t\t" . '<select id="idPosition" name="previous" style="width:100%;" size="1" class="learnpath_item_form">';
  6098. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . get_lang("FirstPosition") . '</option>';
  6099. for ($i = 0; $i < count($arrLP); $i++) {
  6100. if ($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) {
  6101. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  6102. $selected = 'selected="selected" ';
  6103. elseif ($action == 'add') $selected = 'selected="selected" ';
  6104. else
  6105. $selected = '';
  6106. $return .= "\t\t\t\t\t" . '<option ' . $selected . 'value="' . $arrLP[$i]['id'] . '">' . get_lang("After") . ' "' . api_convert_encoding($arrLP[$i]['title'], $charset, $this->encoding) . '"</option>';
  6107. }
  6108. }
  6109. $return .= "\t\t\t\t" . '</select>';
  6110. $return .= "\t\t\t" . '</td>' . "\n";
  6111. $return .= "\t\t" . '</tr>' . "\n";
  6112. if ($action != 'move') {
  6113. $id_prerequisite = 0;
  6114. if (is_array($arrLP)) {
  6115. foreach ($arrLP as $key => $value) {
  6116. if ($value['id'] == $id) {
  6117. $id_prerequisite = $value['prerequisite'];
  6118. break;
  6119. }
  6120. }
  6121. }
  6122. $arrHide = array ();
  6123. for ($i = 0; $i < count($arrLP); $i++) {
  6124. if ($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter') {
  6125. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  6126. $s_selected_position = $arrLP[$i]['id'];
  6127. elseif ($action == 'add') $s_selected_position = 0;
  6128. $arrHide[$arrLP[$i]['id']]['value'] = api_convert_encoding($arrLP[$i]['title'], $charset, $this->encoding);
  6129. }
  6130. }
  6131. //comented the prerequisites, only visible in edit (work)
  6132. /*
  6133. $return .= "\t\t" . '<tr>' . "\n";
  6134. $return .= "\t\t\t" . '<td class="label"><label for="idPrerequisites">'.get_lang('Prerequisites').'</label></td>' . "\n";
  6135. $return .= "\t\t\t" . '<td class="input"><select name="prerequisites" id="prerequisites" class="learnpath_item_form"><option value="0">'.get_lang("NoPrerequisites").'</option>';
  6136. foreach($arrHide as $key => $value){
  6137. if($key==$s_selected_position && $action == 'add'){
  6138. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  6139. }
  6140. elseif($key==$id_prerequisite && $action == 'edit'){
  6141. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  6142. }
  6143. else{
  6144. $return .= '<option value="'.$key.'">'.$value['value'].'</option>';
  6145. }
  6146. }
  6147. $return .= "</select></td>";
  6148. */
  6149. $return .= "\t\t" . '</tr>' . "\n";
  6150. }
  6151. $return .= "\t\t" . '<tr>' . "\n";
  6152. $return .= "\t\t\t" . '<td>&nbsp</td><td><button class="save" name="submit_button" type="submit">' . get_lang("AddAssignmentToCourse") . '</button></td>' . "\n";
  6153. $return .= "\t\t" . '</tr>' . "\n";
  6154. $return .= "\t" . '</table>' . "\n";
  6155. if ($action == 'move') {
  6156. $return .= "\t" . '<input name="title" type="hidden" value="' . $item_title . '" />' . "\n";
  6157. $return .= "\t" . '<input name="description" type="hidden" value="' . $item_description . '" />' . "\n";
  6158. }
  6159. if (is_numeric($extra_info)) {
  6160. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info . '" />' . "\n";
  6161. }
  6162. elseif (is_array($extra_info)) {
  6163. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />' . "\n";
  6164. }
  6165. $return .= "\t" . '<input name="type" type="hidden" value="' . TOOL_STUDENTPUBLICATION . '" />' . "\n";
  6166. $return .= "\t" . '<input name="post_time" type="hidden" value="' . time() . '" />' . "\n";
  6167. $return .= '</form>' . "\n";
  6168. $return .= '</div>' . "\n";
  6169. return $return;
  6170. }
  6171. /**
  6172. * Displays the menu for manipulating a step
  6173. *
  6174. * @return unknown
  6175. */
  6176. function display_manipulate($item_id, $item_type = TOOL_DOCUMENT) {
  6177. global $charset, $_course;
  6178. $return = '<div class="actions">';
  6179. switch ($item_type) {
  6180. case 'dokeos_chapter' :
  6181. case 'chapter' :
  6182. //comented the message cause should not show it
  6183. //$lang = get_lang('TitleManipulateChapter');
  6184. break;
  6185. case 'dokeos_module' :
  6186. case 'module' :
  6187. //comented the message cause should not show it
  6188. //$lang = get_lang('TitleManipulateModule');
  6189. break;
  6190. case TOOL_DOCUMENT :
  6191. //comented the message cause should not show it
  6192. //$lang = get_lang('TitleManipulateDocument');
  6193. break;
  6194. case TOOL_LINK :
  6195. case 'link' :
  6196. //comented the message cause should not show it
  6197. //$lang = get_lang('TitleManipulateLink');
  6198. break;
  6199. case TOOL_QUIZ :
  6200. //comented the message cause should not show it
  6201. //$lang = get_lang('TitleManipulateQuiz');
  6202. break;
  6203. case TOOL_STUDENTPUBLICATION :
  6204. //comented the message cause should not show it
  6205. //$lang = get_lang('TitleManipulateStudentPublication');
  6206. break;
  6207. }
  6208. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  6209. $sql = "
  6210. SELECT
  6211. *
  6212. FROM " . $tbl_lp_item . " as lp
  6213. WHERE
  6214. lp.id = " . $item_id;
  6215. $result = Database::query($sql, __FILE__, __LINE__);
  6216. $row = mysql_fetch_assoc($result);
  6217. $s_title = $row['title'];
  6218. $s_title = api_convert_encoding($s_title, $charset, $this->encoding);
  6219. // we display an audio player if needed
  6220. if (!empty ($row['audio'])) {
  6221. $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>';
  6222. $return .= '<script type="text/javascript" src="../inc/lib/mediaplayer/swfobject.js"></script>';
  6223. $return .= '<script type="text/javascript">
  6224. var s1 = new SWFObject("../inc/lib/mediaplayer/player.swf","ply","250","20","9","#FFFFFF");
  6225. s1.addParam("allowscriptaccess","always");
  6226. s1.addParam("flashvars","file=../../courses/' . $_course['path'] . '/document/audio/' . $row['audio'] . '&autostart=true");
  6227. s1.write("container");
  6228. </script>';
  6229. }
  6230. //commented ":" for message in step
  6231. //$return .= $lang.': ';
  6232. $return .= '<a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&amp;action=edit_item&amp;view=build&amp;id=' . $item_id . '&amp;lp_id=' . $this->lp_id . '&path_item=' . $row['path'] . '" title="' . get_lang('Edit') . '"><img align="absbottom" alt="Edit the current item" src="../img/edit.gif" title="' . get_lang("Edit") . '" /> ' . get_lang("Edit") . '</a>';
  6233. $return .= '<a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&amp;action=move_item&amp;view=build&amp;id=' . $item_id . '&amp;lp_id=' . $this->lp_id . '" title="Move the current item"><img align="absbottom" alt="Move the current item" src="../img/deplacer_fichier.gif" title="' . get_lang("Move") . '" /> ' . get_lang("Move") . '</a>';
  6234. // commented for now as prerequisites cannot be added to chapters
  6235. if ($item_type != 'dokeos_chapter' && $item_type != 'chapter') {
  6236. $return .= '<a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&amp;action=edit_item_prereq&amp;view=build&amp;id=' . $item_id . '&amp;lp_id=' . $this->lp_id . '" title="' . get_lang('Prerequisites') . '"><img align="absbottom" alt="' . get_lang('Prerequisites') . '" src="../img/right.gif" title="' . get_lang('Prerequisites') . '" /> ' . get_lang('Prerequisites') . '</a>';
  6237. }
  6238. $return .= '<a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&amp;action=delete_item&amp;view=build&amp;id=' . $item_id . '&amp;lp_id=' . $this->lp_id . '" onclick="return confirmation(\'' . addslashes($s_title) . '\');" title="Delete the current item"><img alt="Delete the current item" align="absbottom" src="../img/delete.gif" title="' . get_lang("Delete") . '" /> ' . get_lang("Delete") . '</a>';
  6239. //$return .= '<br><br><p class="lp_text">' . ((trim($s_description) == '') ? ''.get_lang("NoDescription").'' : stripslashes(nl2br($s_description))) . '</p>';
  6240. //$return.="</td><td valign='top'>";
  6241. // get the audiorecorder. Use of ob_* functions since there are echos in the file
  6242. ob_start();
  6243. $audio_recorder_studentview = 'false';
  6244. $audio_recorder_item_id = $item_id;
  6245. if (api_get_setting('service_visio', 'active') == 'true') {
  6246. include ('audiorecorder.inc.php');
  6247. }
  6248. $return .= ob_get_contents();
  6249. ob_end_clean();
  6250. // end of audiorecorder include
  6251. $return .= '</div>';
  6252. return $return;
  6253. }
  6254. /**
  6255. * Creates the javascript needed for filling up the checkboxes without page reload
  6256. *
  6257. * @return string
  6258. */
  6259. function create_js() {
  6260. $return = '<script language="javascript" type="text/javascript">' . "\n";
  6261. $return .= 'function load_cbo(id){' . "\n";
  6262. $return .= "var cbo = document.getElementById('idPosition');\n";
  6263. $return .= 'for(var i = cbo.length - 1; i > 0; i--)';
  6264. $return .= 'cbo.options[i] = null;' . "\n";
  6265. $return .= 'var k=0;' . "\n";
  6266. $return .= 'for(var i = 1; i <= child_name[id].length; i++){' . "\n";
  6267. $return .= ' cbo.options[i] = new Option(child_name[id][i-1], child_value[id][i-1]);' . "\n";
  6268. $return .= 'k=i;';
  6269. $return .= '}' . "\n\n";
  6270. $return .= 'if( typeof cbo != "undefined" ) {cbo.options[k].selected = true;}';
  6271. $return .= '}';
  6272. $return .= 'var child_name = new Array();' . "\n";
  6273. $return .= 'var child_value = new Array();' . "\n\n";
  6274. $return .= 'child_name[0] = new Array();' . "\n";
  6275. $return .= 'child_value[0] = new Array();' . "\n\n";
  6276. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  6277. $sql_zero = "
  6278. SELECT *
  6279. FROM " . $tbl_lp_item . "
  6280. WHERE
  6281. lp_id = " . $this->lp_id . " AND
  6282. parent_item_id = 0
  6283. ORDER BY display_order ASC";
  6284. $res_zero = Database::query($sql_zero, __FILE__, __LINE__);
  6285. global $charset;
  6286. $i = 0;
  6287. while ($row_zero = Database :: fetch_array($res_zero)) {
  6288. $return .= 'child_name[0][' . $i . '] = "' . get_lang("After") . ' \"' . api_convert_encoding($row_zero['title'], $charset, $this->encoding) . '\"";' . "\n";
  6289. $return .= 'child_value[0][' . $i++ . '] = "' . $row_zero['id'] . '";' . "\n";
  6290. }
  6291. $return .= "\n";
  6292. $sql = "
  6293. SELECT *
  6294. FROM " . $tbl_lp_item . "
  6295. WHERE
  6296. lp_id = " . $this->lp_id;
  6297. $res = Database::query($sql, __FILE__, __LINE__);
  6298. while ($row = Database :: fetch_array($res)) {
  6299. $sql_parent = "
  6300. SELECT *
  6301. FROM " . $tbl_lp_item . "
  6302. WHERE parent_item_id = " . $row['id'] . "
  6303. ORDER BY display_order ASC";
  6304. $res_parent = Database::query($sql_parent, __FILE__, __LINE__);
  6305. $i = 0;
  6306. $return .= 'child_name[' . $row['id'] . '] = new Array();' . "\n";
  6307. $return .= 'child_value[' . $row['id'] . '] = new Array();' . "\n\n";
  6308. while ($row_parent = Database :: fetch_array($res_parent)) {
  6309. $return .= 'child_name[' . $row['id'] . '][' . $i . '] = "' . get_lang("After") . ' \"' . api_convert_encoding($row_parent['title'], $charset, $this->encoding) . '\"";' . "\n";
  6310. $return .= 'child_value[' . $row['id'] . '][' . $i++ . '] = "' . $row_parent['id'] . '";' . "\n";
  6311. }
  6312. $return .= "\n";
  6313. }
  6314. $return .= '</script>' . "\n";
  6315. return $return;
  6316. }
  6317. /**
  6318. * Display the form to allow moving an item
  6319. *
  6320. * @param integer Item ID
  6321. * @return string HTML form
  6322. */
  6323. function display_move_item($item_id) {
  6324. global $_course; //will disappear
  6325. global $charset;
  6326. $return = '';
  6327. if (is_numeric($item_id)) {
  6328. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  6329. $sql = "SELECT *
  6330. FROM " . $tbl_lp_item . "
  6331. WHERE id = " . $item_id;
  6332. $res = Database::query($sql, __FILE__, __LINE__);
  6333. $row = Database :: fetch_array($res);
  6334. switch ($row['item_type']) {
  6335. case 'dokeos_chapter' :
  6336. case 'dir' :
  6337. case 'asset' :
  6338. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6339. $return .= $this->display_item_form($row['item_type'], get_lang('MoveCurrentChapter'), 'move', $item_id, $row);
  6340. break;
  6341. case 'dokeos_module' :
  6342. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6343. $return .= $this->display_item_form($row['item_type'], 'Move th current module:', 'move', $item_id, $row);
  6344. break;
  6345. case TOOL_DOCUMENT :
  6346. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6347. $return .= $this->display_document_form('move', $item_id, $row);
  6348. break;
  6349. case TOOL_LINK :
  6350. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6351. $return .= $this->display_link_form('move', $item_id, $row);
  6352. break;
  6353. case TOOL_HOTPOTATOES :
  6354. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6355. $return .= $this->display_link_form('move', $item_id, $row);
  6356. break;
  6357. case TOOL_QUIZ :
  6358. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6359. $return .= $this->display_quiz_form('move', $item_id, $row);
  6360. break;
  6361. case TOOL_STUDENTPUBLICATION :
  6362. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6363. $return .= $this->display_student_publication_form('move', $item_id, $row);
  6364. break;
  6365. case TOOL_FORUM :
  6366. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6367. $return .= $this->display_forum_form('move', $item_id, $row);
  6368. }
  6369. }
  6370. return $return;
  6371. }
  6372. /**
  6373. * Displays a basic form on the overview page for changing the item title and the item description.
  6374. *
  6375. * @param string $item_type
  6376. * @param string $title
  6377. * @param array $data
  6378. * @return string
  6379. */
  6380. function display_item_small_form($item_type, $title = '', $data) {
  6381. global $charset;
  6382. $return .= '<div class="lp_small_form">' . "\n";
  6383. $return .= '<p class="lp_title">' . $title . '</p>';
  6384. $return .= '<form method="post">' . "\n";
  6385. $return .= '<table cellpadding="0" cellspacing="0" class="lp_form">';
  6386. $return .= "\t\t" . '<tr>' . "\n";
  6387. $return .= "\t\t\t" . '<td class="label"><label for="idTitle">Title&nbsp;:</label></td>' . "\n";
  6388. $return .= "\t\t\t" . '<td class="input"><input class="small_form" id="idTitle" name="title" type="text" value="' . api_html_entity_decode(api_convert_encoding(htmlspecialchars($data['title']), $charset, $this->encoding), ENT_QUOTES, $charset) . '" /></td>' . "\n";
  6389. $return .= "\t\t" . '</tr>' . "\n";
  6390. //it said these lines of code - see SVN#11724 and SVN#10770
  6391. //$return .= "\t\t" . '<tr>' . "\n";
  6392. //$return .= "\t\t\t" . '<td class="label"><label for="idDescription">Description&nbsp;:</label></td>' . "\n";
  6393. //$return .= "\t\t\t" . '<td class="input"><textarea class="small_form" id="idDescription" name="description" rows="4">' . $data['description'] . '</textarea></td>' . "\n";
  6394. //$return .= "\t\t" . '</tr>' . "\n";
  6395. $return .= "\t\t" . '<tr>' . "\n";
  6396. $return .= "\t\t\t" . '<td colspan="2"><button class="save" name="submit_button" type="submit">' . get_lang('Save') . '</button></td>' . "\n";
  6397. $return .= "\t\t" . '</tr>' . "\n";
  6398. $return .= "\t\t" . '</table>' . "\n";
  6399. $return .= "\t" . '<input name="parent" type="hidden" value="' . $data['parent_item_id'] . '"/>' . "\n";
  6400. $return .= "\t" . '<input name="previous" type="hidden" value="' . $data['previous_item_id'] . '"/>' . "\n";
  6401. $return .= '</form>';
  6402. $return .= '</div>';
  6403. return $return;
  6404. }
  6405. /**
  6406. * Return HTML form to allow prerequisites selection
  6407. *
  6408. * @param integer Item ID
  6409. * @return string HTML form
  6410. */
  6411. function display_item_prerequisites_form($item_id) {
  6412. global $charset;
  6413. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  6414. /* current prerequisite */
  6415. $sql = "
  6416. SELECT *
  6417. FROM " . $tbl_lp_item . "
  6418. WHERE id = " . $item_id;
  6419. $result = Database::query($sql, __FILE__, __LINE__);
  6420. $row = Database :: fetch_array($result);
  6421. $preq_id = $row['prerequisite'];
  6422. //$preq_mastery = $row['mastery_score'];
  6423. //$preq_max = $row['max_score'];
  6424. $return = $this->display_manipulate($item_id, TOOL_DOCUMENT);
  6425. $return = ' <div class="row">
  6426. <div class="form_header">';
  6427. $return .= get_lang('AddEditPrerequisites');
  6428. $return .= '</div> </div>';
  6429. $return .= '<div class="sectioncomment">';
  6430. $return .= '<form method="POST">';
  6431. $return .= '<table class="lp_prerequisites" style="border-collapse:collapse;">';
  6432. $return .= '<tr style="border-collapse:collapse;">';
  6433. $return .= '<th height="24" style="border:1px solid gray; background-color:#F0F0F0;">' . get_lang('Prerequisites') . '</th>';
  6434. $return .= '<th width="70" height="24" style="border:1px solid gray; background-color:#F0F0F0;">' . get_lang('Minimum') . '</th>';
  6435. $return .= '<th width="70" height="24" style="border:1px solid gray; background-color:#F0F0F0;">' . get_lang('Maximum') . '</th>';
  6436. $return .= '</tr>';
  6437. //$return .= '<tr >';
  6438. //$return .= '<td class="radio" style="border:1px solid gray;border-collapse:collapse;">';
  6439. //$return .= '<input checked="checked" id="idNone" name="prerequisites" style="margin-left:0; margin-right:10px;" type="radio" />';
  6440. //$return .= '<label for="idNone">' . get_lang('None') . '</label>';
  6441. //$return .= '</td><td colspan="2" />';
  6442. //$return .= '</tr>';
  6443. $sql = "
  6444. SELECT *
  6445. FROM " . $tbl_lp_item . "
  6446. WHERE
  6447. lp_id = " . $this->lp_id;
  6448. $result = Database::query($sql, __FILE__, __LINE__);
  6449. $arrLP = array ();
  6450. while ($row = Database :: fetch_array($result)) {
  6451. $arrLP[] = array (
  6452. 'id' => $row['id'],
  6453. 'item_type' => $row['item_type'],
  6454. 'title' => api_convert_encoding($row['title'], $charset, $this->encoding),
  6455. 'ref' => $row['ref'],
  6456. 'description' => $row['description'],
  6457. 'parent_item_id' => $row['parent_item_id'],
  6458. 'previous_item_id' => $row['previous_item_id'],
  6459. 'next_item_id' => $row['next_item_id'],
  6460. 'max_score' => $row['max_score'],
  6461. 'min_score' => $row['min_score'],
  6462. 'mastery_score' => $row['mastery_score'],
  6463. 'prerequisite' => $row['prerequisite'],
  6464. 'next_item_id' => $row['next_item_id'],
  6465. 'display_order' => $row['display_order']
  6466. );
  6467. if ($row['ref'] == $preq_id) {
  6468. $preq_mastery = $row['mastery_score'];
  6469. $preq_max = $row['max_score'];
  6470. }
  6471. }
  6472. $this->tree_array($arrLP);
  6473. $arrLP = $this->arrMenu;
  6474. unset ($this->arrMenu);
  6475. for ($i = 0; $i < count($arrLP); $i++) {
  6476. if ($arrLP[$i]['id'] == $item_id)
  6477. break;
  6478. $return .= '<tr >';
  6479. $return .= '<td style="border:1px solid #B0B0B0; border-collapse:collapse; height:25px; padding: 3px 5px 3px 3px;" class="radio"' . (($arrLP[$i]['item_type'] != TOOL_QUIZ && $arrLP[$i]['item_type'] != TOOL_HOTPOTATOES) ? ' colspan="3"' : '') . '>';
  6480. $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'] . '" />';
  6481. $icon_name = str_replace(' ', '', $arrLP[$i]['item_type']);
  6482. if (file_exists("../img/lp_" . $icon_name . ".png")) {
  6483. $return .= '<img alt="" src="../img/lp_' . $icon_name . '.png" style="margin-right:5px;" title="" />';
  6484. } else
  6485. if (file_exists("../img/lp_" . $icon_name . ".gif")) {
  6486. $return .= '<img alt="" src="../img/lp_' . $icon_name . '.gif" style="margin-right:5px;" title="" />';
  6487. } else {
  6488. $return .= Display::return_icon('folder_document.gif','',array('style'=>'margin-right:5px;'));
  6489. }
  6490. $return .= '<label for="id' . $arrLP[$i]['id'] . '">' . $arrLP[$i]['title'] . '</label>';
  6491. $return .= '</td>';
  6492. //$return .= '<td class="radio"' . (($arrLP[$i]['item_type'] != TOOL_HOTPOTATOES) ? ' colspan="3"' : '') . ' />';
  6493. if ($arrLP[$i]['item_type'] == TOOL_QUIZ) {
  6494. $return .= '<td class="exercise" style="border:1px solid #B0B0B0;">';
  6495. $return .= '<center><input size="4" maxlength="3" name="min_' . $arrLP[$i]['id'] . '" type="text" value="' . (($arrLP[$i]['id'] == $preq_id) ? $preq_mastery : 0) . '" /></center>';
  6496. $return .= '</td>';
  6497. $return .= '<td class="exercise" style="border:1px solid #B0B0B0;">';
  6498. $return .= '<center><input size="4" maxlength="3" name="max_' . $arrLP[$i]['id'] . '" type="text" value="' . $arrLP[$i]['max_score'] . '" disabled="true" /></center>';
  6499. $return .= '</td>';
  6500. }
  6501. if ($arrLP[$i]['item_type'] == TOOL_HOTPOTATOES) {
  6502. $return .= '<td class="exercise" style="border:1px solid #B0B0B0;">';
  6503. $return .= '<center><input size="4" maxlength="3" name="min_' . $arrLP[$i]['id'] . '" type="text" value="' . (($arrLP[$i]['id'] == $preq_id) ? $preq_mastery : 0) . '" /></center>';
  6504. $return .= '</td>';
  6505. $return .= '<td class="exercise" style="border:1px solid #B0B0B0;">';
  6506. $return .= '<center><input size="4" maxlength="3" name="max_' . $arrLP[$i]['id'] . '" type="text" value="' . $arrLP[$i]['max_score'] . '" disabled="true" /></center>';
  6507. $return .= '</td>';
  6508. }
  6509. $return .= '</tr>';
  6510. }
  6511. $return .= '<tr>';
  6512. $return .= '<td colspan="3">';
  6513. $return .= '</td>';
  6514. $return .= '</tr>';
  6515. $return .= '</table>';
  6516. $return .= '<div style="padding-top:3px;">';
  6517. $return .= '<button class="save" name="submit_button" type="submit">' . get_lang("ModifyPrerequisites") . ' </button></td>' . "\n";
  6518. $return .= '</div>';
  6519. $return .= '</form>';
  6520. $return .= '</div>';
  6521. return $return;
  6522. }
  6523. /**
  6524. * Creates a list with all the documents in it
  6525. *
  6526. * @return string
  6527. */
  6528. function get_documents() {
  6529. global $_course;
  6530. $tbl_doc = Database :: get_course_table(TABLE_DOCUMENT);
  6531. $sql_doc = "
  6532. SELECT *
  6533. FROM " . $tbl_doc . "
  6534. WHERE
  6535. path NOT LIKE '%_DELETED_%'
  6536. ORDER BY path ASC";
  6537. $res_doc = Database::query($sql_doc, __FILE__, __LINE__);
  6538. $return = '<div class="lp_resource_header"' . " onclick=\"if(document.getElementById('resDoc').style.display == 'block') {document.getElementById('resDoc').style.display = 'none';} else {document.getElementById('resDoc').style.display = 'block';}\"" . '>'.Display::return_icon('folder_document.gif',get_lang('Documents'),array('style'=>'margin-right:5px;', 'height' => '16px')).' '. get_lang('Documents') . '</div>';
  6539. $return .= '<div class="lp_resource_elements" id="resDoc">';
  6540. $resources = Database::store_result($res_doc);
  6541. $resources_sorted = array ();
  6542. // if you want to debug it, I advise you to do "echo" on the eval statements
  6543. foreach ($resources as $resource) {
  6544. $resource_paths = explode('/', $resource['path']);
  6545. array_shift($resource_paths);
  6546. $path_to_eval = $last_path = '';
  6547. $is_file = false;
  6548. foreach ($resource_paths as $key => $resource_path) {
  6549. if (strpos($resource_path, '.') === false && $key != count($resource_paths) - 1) { // it's a folder
  6550. $path_to_eval .= '["' . $resource_path . '"]["files"]';
  6551. } else
  6552. if (strpos($resource_path, '.') !== false)
  6553. $is_file = true;
  6554. $last_path = $resource_path;
  6555. }
  6556. if ($is_file) {
  6557. eval ('$resources_sorted' . $path_to_eval . '[' . $resource['id'] . '] = "' . $last_path . '";');
  6558. } else {
  6559. eval ('$resources_sorted' . $path_to_eval . '["' . $last_path . '"]["id"]=' . $resource['id'] . ';');
  6560. }
  6561. }
  6562. $return .= $this->write_resources_tree($resources_sorted);
  6563. $return .= '</div>';
  6564. if (Database :: num_rows($res_doc) == 0)
  6565. $return .= '<div class="lp_resource_element">' . get_lang("NoDocuments") . '</div>';
  6566. return $return;
  6567. }
  6568. /**
  6569. * Generate and return an HTML list of resources based on a given array.
  6570. *
  6571. * This list is used to show the course creator a list of available resources to choose from
  6572. * when creating a learning path.
  6573. * @param array Array of elements to add to the list
  6574. * @param integer Enables the tree display by shifting the new elements a certain distance to the right
  6575. * @return string The HTML list
  6576. */
  6577. function write_resources_tree($resources_sorted, $num = 0) {
  6578. include_once (api_get_path(LIBRARY_PATH) . 'fileDisplay.lib.php');
  6579. if (count($resources_sorted) > 0) {
  6580. foreach ($resources_sorted as $key => $resource) {
  6581. if (is_int($resource['id'])) { // it's a folder
  6582. $return .= '<div><div style="margin-left:' . ($num * 15) . 'px;margin-right:5px;"><img style="cursor: pointer;" src="../img/nolines_plus.gif" align="absmiddle" id="img_' . $resource["id"] . '" onclick="testResources(\'' . $resource["id"] . '\',\'img_' . $resource["id"] . '\')"><img alt="" src="../img/lp_folder.gif" title="" align="absmiddle" />&nbsp;<span onclick="testResources(\'' . $resource["id"] . '\',\'img_' . $resource["id"] . '\')" style="cursor: pointer;" >' . $key . '</span></div><div style="display: none;" id="' . $resource['id'] . '">';
  6583. $return .= $this->write_resources_tree($resource['files'], $num +1);
  6584. $return .= "</div></div>\r\n";
  6585. } else {
  6586. // it's a file
  6587. $icon = choose_image($resource);
  6588. $position = strrpos($icon, '.');
  6589. $icon = substr($icon, 0, $position) . '_small.gif';
  6590. $return .= '<div><div style="margin-left:' . (($num +1) * 15) . 'px;margin-right:5px;"><a href="' . api_get_self() . '?cidReq=' . $_GET['cidReq'] . '&amp;action=add_item&amp;type=' . TOOL_DOCUMENT . '&amp;file=' . $key . '&amp;lp_id=' . $this->lp_id . '"><img alt="" src="../img/' . $icon . '" title="" />&nbsp;' . $resource . "</a></div></div>\r\n";
  6591. }
  6592. }
  6593. }
  6594. return $return;
  6595. }
  6596. /**
  6597. * Creates a list with all the exercises (quiz) in it
  6598. *
  6599. * @return string
  6600. */
  6601. function get_exercises() {
  6602. // new for hotpotatoes
  6603. $uploadPath = DIR_HOTPOTATOES; //defined in main_api
  6604. $tbl_doc = Database :: get_course_table(TABLE_DOCUMENT);
  6605. $tbl_quiz = Database :: get_course_table(TABLE_QUIZ_TEST);
  6606. $sql_quiz = "
  6607. SELECT *
  6608. FROM " . $tbl_quiz . "
  6609. WHERE active<>'-1'
  6610. ORDER BY title ASC";
  6611. $sql_hot = "SELECT * FROM " . $tbl_doc . " " .
  6612. " WHERE path LIKE '" . $uploadPath . "/%/%htm%'" .
  6613. " ORDER BY id ASC";
  6614. $res_quiz = Database::query($sql_quiz, __FILE__, __LINE__);
  6615. $res_hot = Database::query($sql_hot, __FILE__, __LINE__);
  6616. $return .= '<div class="lp_resource_header"' . " onclick=\"if(document.getElementById('resExercise').style.display == 'block') {document.getElementById('resExercise').style.display = 'none';} else {document.getElementById('resExercise').style.display = 'block';}\"" . ' ><img align="left" alt="" src="../img/lp_' . TOOL_QUIZ . '.gif" style="margin-right:5px;" title="" />' . get_lang('Quiz') . '</div>';
  6617. $return .= '<div class="lp_resource_elements" id="resExercise">';
  6618. while ($row_hot = Database :: fetch_array($res_hot)) {
  6619. $return .= '<div class="lp_resource_element">';
  6620. //display quizhotpotatoes
  6621. $return .= '<img alt="" src="../img/jqz.gif" style="margin-right:5px;" title="" />';
  6622. $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'] : $row_hot['title']) . '</a>';
  6623. //$return .= $row_quiz['title'];
  6624. $return .= '</div>';
  6625. }
  6626. while ($row_quiz = Database :: fetch_array($res_quiz)) {
  6627. $return .= '<div class="lp_resource_element">';
  6628. $return .= '<img alt="" src="../img/quizz_small.gif" style="margin-right:5px;" title="" />';
  6629. $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 . '">' . $row_quiz['title'] . '</a>';
  6630. //$return .= $row_quiz['title'];
  6631. $return .= '</div>';
  6632. }
  6633. if (Database :: num_rows($res_quiz) == 0)
  6634. $return .= '<div class="lp_resource_element">' . get_lang("NoExercisesAvailable") . '</div>';
  6635. $return .= '<div class="lp_resource_element">';
  6636. $return .= '<img alt="" src="../img/new_test_small.gif" style="margin-right:5px;" title="" />';
  6637. $return .= '<a href="' . api_get_path(REL_CODE_PATH) . 'exercice/exercise_admin.php">' . get_lang('NewExercise') . '</a>';
  6638. $return .= '</div>';
  6639. $return .= '</div>';
  6640. return $return;
  6641. }
  6642. /**
  6643. * Creates a list with all the links in it
  6644. *
  6645. * @return string
  6646. */
  6647. function get_links() {
  6648. $tbl_link = Database :: get_course_table(TABLE_LINK);
  6649. $sql_link = "
  6650. SELECT *
  6651. FROM " . $tbl_link . "
  6652. ORDER BY title ASC";
  6653. $res_link = Database::query($sql_link, __FILE__, __LINE__);
  6654. $return .= '<div class="lp_resource_header"' . " onclick=\"if(document.getElementById('resLink').style.display == 'block') {document.getElementById('resLink').style.display = 'none';} else {document.getElementById('resLink').style.display = 'block';}\"" . '><img alt="" src="../img/lp_' . TOOL_LINK . '.gif" style="margin-right:5px;" title="" />' . get_lang("Links") . '</div>';
  6655. $return .= '<div class="lp_resource_elements" id="resLink">';
  6656. while ($row_link = Database :: fetch_array($res_link)) {
  6657. $return .= '<div class="lp_resource_element">';
  6658. $return .= '<img alt="" src="../img/file_html_small.gif" style="margin-right:5px;" title="" />';
  6659. $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>';
  6660. $return .= '</div>';
  6661. }
  6662. $return .= '<div class="lp_resource_element">';
  6663. $return .= '<img alt="" src="../img/file_html_new_small.gif" style="margin-right:5px;" title="" />';
  6664. $return .= '<a href="' . api_get_path(REL_CODE_PATH) . 'link/link.php?' . api_get_cidreq() . '&action=addlink" title="' . get_lang('LinkAdd') . '">' . get_lang('LinkAdd') . '</a>';
  6665. $return .= '</div>';
  6666. if (Database :: num_rows($res_link) == 0)
  6667. $return .= '<div class="lp_resource_element">' . get_lang("NoLinksAvailable") . '</div>';
  6668. $return .= '</div>';
  6669. return $return;
  6670. }
  6671. /**
  6672. * Creates a list with all the student publications in it
  6673. *
  6674. * @return unknown
  6675. */
  6676. function get_student_publications() {
  6677. $tbl_student = Database :: get_course_table(TABLE_STUDENT_PUBLICATION);
  6678. $sql_student = "
  6679. SELECT *
  6680. FROM " . $tbl_student . "
  6681. ORDER BY title ASC";
  6682. $res_student = Database::query($sql_student, __FILE__, __LINE__);
  6683. $return .= '<div class="lp_resource_header"' . " onclick=\"if(document.getElementById('resStudent').style.display == 'block') {document.getElementById('resStudent').style.display = 'none';} else {document.getElementById('resStudent').style.display = 'block';}\"" . '><img alt="" src="../img/lp_' . TOOL_STUDENTPUBLICATION . '.gif" style="margin-right:5px;" title="" />' . get_lang('Student_publication') . '</div>';
  6684. $return .= '<div class="lp_resource_elements" id="resStudent">';
  6685. $return .= '<div class="lp_resource_element">';
  6686. $return .= '<img align="left" alt="" src="../img/works_small.gif" style="margin-right:5px;" title="" />';
  6687. $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>';
  6688. $return .= '</div>';
  6689. $return .= '</div>';
  6690. return $return;
  6691. }
  6692. /**
  6693. * Creates a list with all the forums in it
  6694. *
  6695. * @return string
  6696. */
  6697. function get_forums() {
  6698. include ('../forum/forumfunction.inc.php');
  6699. include ('../forum/forumconfig.inc.php');
  6700. global $table_forums, $table_threads, $table_posts, $table_item_property, $table_users;
  6701. $table_forums = Database :: get_course_table(TABLE_FORUM);
  6702. $table_threads = Database :: get_course_table(TABLE_FORUM_THREAD);
  6703. $table_posts = Database :: get_course_table(TABLE_FORUM_POST);
  6704. $table_item_property = Database :: get_course_table(TABLE_ITEM_PROPERTY);
  6705. $table_users = Database :: get_main_table(TABLE_MAIN_USER);
  6706. $a_forums = get_forums();
  6707. $return .= '<div class="lp_resource_header"' . " onclick=\"if(document.getElementById('forums').style.display == 'block') {document.getElementById('forums').style.display = 'none';} else {document.getElementById('forums').style.display = 'block';}\"" . '><img alt="" src="../img/lp_forum.gif" style="margin-right:5px;" title="" />' . get_lang('Forums') . '</div>';
  6708. $return .= '<div class="lp_resource_elements" style="border:1px solid #999999;" id="forums">';
  6709. foreach ($a_forums as $forum) {
  6710. $return .= '<div class="lp_resource_element">';
  6711. $return .= '<script type="text/javascript">
  6712. function toggle_forum(forum_id){
  6713. if(document.getElementById("forum_"+forum_id+"_content").style.display == "none"){
  6714. document.getElementById("forum_"+forum_id+"_content").style.display = "block";
  6715. document.getElementById("forum_"+forum_id+"_opener").src = "' . api_get_path(WEB_IMG_PATH) . 'remove.gif";
  6716. }
  6717. else {
  6718. document.getElementById("forum_"+forum_id+"_content").style.display = "none";
  6719. document.getElementById("forum_"+forum_id+"_opener").src = "' . api_get_path(WEB_IMG_PATH) . 'add.gif";
  6720. }
  6721. }
  6722. </script>
  6723. ';
  6724. $return .= '<img alt="" src="../img/lp_forum.gif" style="margin-right:5px;" title="" />';
  6725. $return .= '<a style="cursor:hand" onclick="toggle_forum(' . $forum['forum_id'] . ')" style="vertical-align:middle"><img src="' . api_get_path(WEB_IMG_PATH) . 'add.gif" id="forum_' . $forum['forum_id'] . '_opener" align="absbottom" /></a>
  6726. <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">' . $forum['forum_title'] . '</a><ul style="display:none" id="forum_' . $forum['forum_id'] . '_content">';
  6727. $a_threads = get_threads($forum['forum_id']);
  6728. if (is_array($a_threads)) {
  6729. foreach ($a_threads as $thread) {
  6730. $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 . '">' . $thread['thread_title'] . '</a></li>';
  6731. }
  6732. }
  6733. $return .= '</ul></div>';
  6734. }
  6735. $return .= '<div class="lp_resource_element">';
  6736. $return .= '<img alt="" src="../img/forum_new_small.gif" style="margin-right:5px;" title="" />';
  6737. $return .= '<a href="' . api_get_path(REL_CODE_PATH) . 'forum/index.php?' . api_get_cidreq() . '&action=add&amp;content=forum" title="' . get_lang('CreateANewForum') . '">' . get_lang('CreateANewForum') . '</a>';
  6738. $return .= '</div>';
  6739. return $return;
  6740. }
  6741. /**
  6742. * Exports the learning path as a SCORM package. This is the main function that
  6743. * gathers the content, transforms it, writes the imsmanifest.xml file, zips the
  6744. * whole thing and returns the zip.
  6745. *
  6746. * This method needs to be called in PHP5, as it will fail with non-adequate
  6747. * XML package (like the ones for PHP4), and it is *not* a static method, so
  6748. * you need to call it on a learnpath object.
  6749. * @TODO The method might be redefined later on in the scorm class itself to avoid
  6750. * creating a SCORM structure if there is one already. However, if the initial SCORM
  6751. * path has been modified, it should use the generic method here below.
  6752. * @TODO link this function with the export_lp() function in the same class
  6753. * @param string Optional name of zip file. If none, title of learnpath is
  6754. * domesticated and trailed with ".zip"
  6755. * @return string Returns the zip package string, or null if error
  6756. */
  6757. function scorm_export()
  6758. {
  6759. global $_course;
  6760. global $charset;
  6761. if (!class_exists('DomDocument'))
  6762. {
  6763. error_log('DOM functions not supported for PHP version below 5.0',0);
  6764. $this->error = 'PHP DOM functions not supported for PHP versions below 5.0';
  6765. return null;
  6766. }
  6767. //remove memory and time limits as much as possible as this might be a long process...
  6768. if(function_exists('ini_set'))
  6769. {
  6770. $mem = ini_get('memory_limit');
  6771. if(substr($mem,-1,1)=='M')
  6772. {
  6773. $mem_num = substr($mem,0,-1);
  6774. if($mem_num<128)
  6775. {
  6776. ini_set('memory_limit','128M');
  6777. }
  6778. }
  6779. else
  6780. {
  6781. ini_set('memory_limit','128M');
  6782. }
  6783. ini_set('max_execution_time',600);
  6784. //}else{
  6785. //error_log('Scorm export: could not change memory and time limits',0);
  6786. }
  6787. //Create the zip handler (this will remain available throughout the method)
  6788. $archive_path = api_get_path(SYS_ARCHIVE_PATH);
  6789. $sys_course_path = api_get_path(SYS_COURSE_PATH);
  6790. $temp_dir_short = uniqid();
  6791. $temp_zip_dir = $archive_path."/".$temp_dir_short;
  6792. $temp_zip_file = $temp_zip_dir."/".md5(time()).".zip";
  6793. $zip_folder=new PclZip($temp_zip_file);
  6794. $current_course_path = api_get_path(SYS_COURSE_PATH).api_get_course_path();
  6795. $root_path = $main_path = api_get_path(SYS_PATH);
  6796. $files_cleanup = array();
  6797. //place to temporarily stash the zipfiles
  6798. //create the temp dir if it doesn't exist
  6799. //or do a cleanup befor creating the zipfile
  6800. if(!is_dir($temp_zip_dir))
  6801. {
  6802. mkdir($temp_zip_dir);
  6803. }
  6804. else
  6805. {//cleanup: check the temp dir for old files and delete them
  6806. $handle=opendir($temp_zip_dir);
  6807. while (false!==($file = readdir($handle)))
  6808. {
  6809. if ($file != "." && $file != "..")
  6810. {
  6811. unlink("$temp_zip_dir/$file");
  6812. }
  6813. }
  6814. closedir($handle);
  6815. }
  6816. $zip_files = $zip_files_abs = $zip_files_dist = array();
  6817. if(is_dir($current_course_path.'/scorm/'.$this->path) && is_file($current_course_path.'/scorm/'.$this->path.'/imsmanifest.xml'))
  6818. {
  6819. // remove the possible . at the end of the path
  6820. $dest_path_to_lp = substr($this->path, -1) == '.' ? substr($this->path, 0, -1) : $this->path;
  6821. $dest_path_to_scorm_folder = str_replace('//','/',$temp_zip_dir.'/scorm/'.$dest_path_to_lp);
  6822. $perm = api_get_setting('permissions_for_new_directories');
  6823. $perm = octdec(!empty($perm)?$perm:'0770');
  6824. mkdir ($dest_path_to_scorm_folder, $perm, true);
  6825. $zip_files_dist = copyr($current_course_path.'/scorm/'.$this->path, $dest_path_to_scorm_folder, array('imsmanifest'), $zip_files);
  6826. }
  6827. //Build a dummy imsmanifest structure. Do not add to the zip yet (we still need it)
  6828. //This structure is developed following regulations for SCORM 1.2 packaging in the SCORM 1.2 Content
  6829. //Aggregation Model official document, secion "2.3 Content Packaging"
  6830. $xmldoc = new DOMDocument('1.0',$this->encoding);
  6831. $root = $xmldoc->createElement('manifest');
  6832. $root->setAttribute('identifier','SingleCourseManifest');
  6833. $root->setAttribute('version','1.1');
  6834. $root->setAttribute('xmlns','http://www.imsproject.org/xsd/imscp_rootv1p1p2');
  6835. $root->setAttribute('xmlns:adlcp','http://www.adlnet.org/xsd/adlcp_rootv1p2');
  6836. $root->setAttribute('xmlns:xsi','http://www.w3.org/2001/XMLSchema-instance');
  6837. $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');
  6838. //Build mandatory sub-root container elements
  6839. $metadata = $xmldoc->createElement('metadata');
  6840. $md_schema = $xmldoc->createElement('schema','ADL SCORM');
  6841. $metadata->appendChild($md_schema);
  6842. $md_schemaversion = $xmldoc->createElement('schemaversion','1.2');
  6843. $metadata->appendChild($md_schemaversion);
  6844. $root->appendChild($metadata);
  6845. $organizations = $xmldoc->createElement('organizations');
  6846. $resources = $xmldoc->createElement('resources');
  6847. //Build the only organization we will use in building our learnpaths
  6848. $organizations->setAttribute('default','dokeos_scorm_export');
  6849. $organization = $xmldoc->createElement('organization');
  6850. $organization->setAttribute('identifier','dokeos_scorm_export');
  6851. //to set the title of the SCORM entity (=organization), we take the name given
  6852. //in Dokeos and convert it to HTML entities using the Dokeos charset (not the
  6853. //learning path charset) as it is the encoding that defines how it is stored
  6854. //in the database. Then we convert it to HTML entities again as the "&" character
  6855. //alone is not authorized in XML (must be &amp;)
  6856. //The title is then decoded twice when extracting (see scorm::parse_manifest)
  6857. $org_title = $xmldoc->createElement('title',htmlentities(api_htmlentities($this->get_name(),ENT_QUOTES,$charset)));
  6858. $organization->appendChild($org_title);
  6859. //For each element, add it to the imsmanifest structure, then add it to the zip.
  6860. //Always call the learnpathItem->scorm_export() method to change it to the SCORM
  6861. //format
  6862. $link_updates = array();
  6863. foreach($this->items as $index => $item){
  6864. if(!in_array($item->type , array(TOOL_QUIZ, TOOL_FORUM, TOOL_THREAD, TOOL_LINK, TOOL_STUDENTPUBLICATION)))
  6865. {
  6866. //get included documents from this item
  6867. if($item->type=='sco')
  6868. $inc_docs = $item->get_resources_from_source(null,api_get_path(SYS_COURSE_PATH).api_get_course_path().'/'.'scorm/'.$this->path.'/'.$item->get_path());
  6869. else
  6870. $inc_docs = $item->get_resources_from_source();
  6871. //give a child element <item> to the <organization> element
  6872. $my_item_id = $item->get_id();
  6873. $my_item = $xmldoc->createElement('item');
  6874. $my_item->setAttribute('identifier','ITEM_'.$my_item_id);
  6875. $my_item->setAttribute('identifierref','RESOURCE_'.$my_item_id);
  6876. $my_item->setAttribute('isvisible','true');
  6877. //give a child element <title> to the <item> element
  6878. $my_title = $xmldoc->createElement('title',htmlspecialchars($item->get_title(), ENT_QUOTES, $this->encoding));
  6879. $my_item->appendChild($my_title);
  6880. //give a child element <adlcp:prerequisites> to the <item> element
  6881. $my_prereqs = $xmldoc->createElement('adlcp:prerequisites',$this->get_scorm_prereq_string($my_item_id));
  6882. $my_prereqs->setAttribute('type','aicc_script');
  6883. $my_item->appendChild($my_prereqs);
  6884. //give a child element <adlcp:maxtimeallowed> to the <item> element - not yet supported
  6885. //$xmldoc->createElement('adlcp:maxtimeallowed','');
  6886. //give a child element <adlcp:timelimitaction> to the <item> element - not yet supported
  6887. //$xmldoc->createElement('adlcp:timelimitaction','');
  6888. //give a child element <adlcp:datafromlms> to the <item> element - not yet supported
  6889. //$xmldoc->createElement('adlcp:datafromlms','');
  6890. //give a child element <adlcp:masteryscore> to the <item> element
  6891. $my_masteryscore = $xmldoc->createElement('adlcp:masteryscore',$item->get_mastery_score());
  6892. $my_item->appendChild($my_masteryscore);
  6893. //attach this item to the organization element or hits parent if there is one
  6894. if(!empty($item->parent) && $item->parent!=0)
  6895. {
  6896. $children = $organization->childNodes;
  6897. $possible_parent = &$this->get_scorm_xml_node($children,'ITEM_'.$item->parent);
  6898. if(is_object($possible_parent))
  6899. {
  6900. $possible_parent->appendChild($my_item);
  6901. }
  6902. else
  6903. {
  6904. if($this->debug>0){error_log('Parent ITEM_'.$item->parent.' of item ITEM_'.$my_item_id.' not found');}
  6905. }
  6906. }
  6907. else
  6908. {
  6909. if($this->debug>0){error_log('No parent');}
  6910. $organization->appendChild($my_item);
  6911. }
  6912. //get the path of the file(s) from the course directory root
  6913. $my_file_path = $item->get_file_path('scorm/'.$this->path.'/');
  6914. $my_xml_file_path = api_htmlentities($my_file_path, ENT_QUOTES, $this->encoding);
  6915. $my_sub_dir = dirname($my_file_path);
  6916. $my_xml_sub_dir = api_htmlentities($my_sub_dir, ENT_QUOTES, $this->encoding);
  6917. //give a <resource> child to the <resources> element
  6918. $my_resource = $xmldoc->createElement('resource');
  6919. $my_resource->setAttribute('identifier','RESOURCE_'.$item->get_id());
  6920. $my_resource->setAttribute('type','webcontent');
  6921. $my_resource->setAttribute('href',$my_xml_file_path);
  6922. //adlcp:scormtype can be either 'sco' or 'asset'
  6923. if($item->type=='sco')
  6924. {
  6925. $my_resource->setAttribute('adlcp:scormtype','sco');
  6926. }
  6927. else
  6928. {
  6929. $my_resource->setAttribute('adlcp:scormtype','asset');
  6930. }
  6931. //xml:base is the base directory to find the files declared in this resource
  6932. $my_resource->setAttribute('xml:base','');
  6933. //give a <file> child to the <resource> element
  6934. $my_file = $xmldoc->createElement('file');
  6935. $my_file->setAttribute('href',$my_xml_file_path);
  6936. $my_resource->appendChild($my_file);
  6937. //dependency to other files - not yet supported
  6938. $i = 1;
  6939. foreach($inc_docs as $doc_info)
  6940. {
  6941. if(count($doc_info)<1 or empty($doc_info[0])){continue;}
  6942. $my_dep = $xmldoc->createElement('resource');
  6943. $res_id = 'RESOURCE_'.$item->get_id().'_'.$i;
  6944. $my_dep->setAttribute('identifier',$res_id);
  6945. $my_dep->setAttribute('type','webcontent');
  6946. $my_dep->setAttribute('adlcp:scormtype','asset');
  6947. $my_dep_file = $xmldoc->createElement('file');
  6948. //check type of URL
  6949. //error_log(__LINE__.'Now dealing with '.$doc_info[0].' of type '.$doc_info[1].'-'.$doc_info[2],0);
  6950. if($doc_info[1] == 'remote')
  6951. { //remote file. Save url as is
  6952. $my_dep_file->setAttribute('href',$doc_info[0]);
  6953. $my_dep->setAttribute('xml:base','');
  6954. }elseif($doc_info[1] == 'local'){
  6955. switch($doc_info[2])
  6956. {
  6957. case 'url': //local URL - save path as url for now, don't zip file
  6958. $abs_path = api_get_path(SYS_PATH).str_replace(api_get_path(WEB_PATH),'',$doc_info[0]);
  6959. $current_dir = dirname($abs_path);
  6960. $file_path = realpath($abs_path);
  6961. $my_dep_file->setAttribute('href',$file_path);
  6962. $my_dep->setAttribute('xml:base','');
  6963. if(strstr($file_path,$main_path) !== false)
  6964. {//the calculated real path is really inside the dokeos root path
  6965. //reduce file path to what's under the DocumentRoot
  6966. $file_path = substr($file_path,strlen($root_path)-1);
  6967. //echo $file_path;echo '<br><br>';
  6968. //error_log(__LINE__.'Reduced url path: '.$file_path,0);
  6969. $zip_files_abs[] = $file_path;
  6970. $link_updates[$my_file_path][] = array('orig'=>$doc_info[0],'dest'=>$file_path);
  6971. $my_dep_file->setAttribute('href',$file_path);
  6972. $my_dep->setAttribute('xml:base','');
  6973. }
  6974. else if (empty($file_path))
  6975. {
  6976. /*$document_root = substr(api_get_path(SYS_PATH), 0, strpos(api_get_path(SYS_PATH),api_get_path(REL_PATH)));
  6977. if(strpos($document_root,-1)=='/')
  6978. {
  6979. $document_root = substr(0, -1, $document_root);
  6980. }*/
  6981. $file_path = $_SERVER['DOCUMENT_ROOT'].$abs_path;
  6982. $file_path = str_replace('//','/',$file_path);
  6983. if(file_exists($file_path))
  6984. {
  6985. $file_path = substr($file_path,strlen($current_dir)); // we get the relative path
  6986. $zip_files[] = $my_sub_dir.'/'.$file_path;
  6987. $link_updates[$my_file_path][] = array('orig'=>$doc_info[0],'dest'=>$file_path);
  6988. $my_dep_file->setAttribute('href',$file_path);
  6989. $my_dep->setAttribute('xml:base','');
  6990. }
  6991. }
  6992. break;
  6993. case 'abs': //absolute path from DocumentRoot. Save file and leave path as is in the zip
  6994. $my_dep_file->setAttribute('href',$doc_info[0]);
  6995. $my_dep->setAttribute('xml:base','');
  6996. //$current_dir = dirname($current_course_path.'/'.$item->get_file_path()).'/';
  6997. //the next lines fix a bug when using the "subdir" mode of Dokeos, whereas
  6998. //an image path would be constructed as /var/www/subdir/subdir/img/foo.bar
  6999. $abs_img_path_without_subdir = $doc_info[0];
  7000. $relp = api_get_path(REL_PATH); //the url-append config param
  7001. $pos = strpos($abs_img_path_without_subdir,$relp);
  7002. if($pos===0)
  7003. {
  7004. $abs_img_path_without_subdir = '/'.substr($abs_img_path_without_subdir,strlen($relp));
  7005. }
  7006. //$file_path = realpath(api_get_path(SYS_PATH).$doc_info[0]);
  7007. $file_path = realpath(api_get_path(SYS_PATH).$abs_img_path_without_subdir);
  7008. $file_path = str_replace('\\','/',$file_path);
  7009. $file_path = str_replace('//','/',$file_path);
  7010. //error_log(__LINE__.'Abs path: '.$file_path,0);
  7011. //prepare the current directory path (until just under 'document') with a trailing slash
  7012. $cur_path = substr($current_course_path,-1)=='/'?$current_course_path:$current_course_path.'/';
  7013. //check if the current document is in that path
  7014. if(strstr($file_path,$cur_path) !== false)
  7015. {
  7016. //the document is in that path, now get the relative path
  7017. //to the containing document
  7018. $orig_file_path = dirname($cur_path.$my_file_path).'/';
  7019. $relative_path ='';
  7020. if(strstr($file_path,$cur_path)!==false)
  7021. {
  7022. $relative_path = substr($file_path,strlen($orig_file_path));
  7023. $file_path = substr($file_path,strlen($cur_path));
  7024. }
  7025. else
  7026. {
  7027. //this case is still a problem as it's difficult to calculate a relative path easily
  7028. //might still generate wrong links
  7029. //$file_path = substr($file_path,strlen($cur_path));
  7030. //calculate the directory path to the current file (without trailing slash)
  7031. $my_relative_path = dirname($file_path);
  7032. $my_relative_file = basename($file_path);
  7033. //calculate the directory path to the containing file (without trailing slash)
  7034. $my_orig_file_path = substr($orig_file_path,0,-1);
  7035. $dotdot = '';
  7036. $subdir = '';
  7037. while(strstr($my_relative_path,$my_orig_file_path)===false && (strlen($my_orig_file_path)>1) && (strlen($my_relative_path)>1))
  7038. {
  7039. $my_relative_path2 = dirname($my_relative_path);
  7040. $my_orig_file_path = dirname($my_orig_file_path);
  7041. $subdir = substr($my_relative_path,strlen($my_relative_path2)+1)."/".$subdir;
  7042. $dotdot += '../';
  7043. $my_relative_path = $my_relative_path2;
  7044. }
  7045. $relative_path = $dotdot.$subdir.$my_relative_file;
  7046. }
  7047. //put the current document in the zip (this array is the array
  7048. //that will manage documents already in the course folder - relative)
  7049. $zip_files[] = $file_path;
  7050. //update the links to the current document in the containing document (make them relative)
  7051. $link_updates[$my_file_path][] = array('orig'=>$doc_info[0],'dest'=>$relative_path);
  7052. $my_dep_file->setAttribute('href',$file_path);
  7053. $my_dep->setAttribute('xml:base','');
  7054. }
  7055. elseif(strstr($file_path,$main_path) !== false)
  7056. {//the calculated real path is really inside the dokeos root path
  7057. //reduce file path to what's under the DocumentRoot
  7058. $file_path = substr($file_path,strlen($root_path));
  7059. //echo $file_path;echo '<br><br>';
  7060. //error_log('Reduced path: '.$file_path,0);
  7061. $zip_files_abs[] = $file_path;
  7062. $link_updates[$my_file_path][] = array('orig'=>$doc_info[0],'dest'=>$file_path);
  7063. $my_dep_file->setAttribute('href','document/'.$file_path);
  7064. $my_dep->setAttribute('xml:base','');
  7065. }
  7066. else if (empty($file_path))
  7067. {
  7068. /*$document_root = substr(api_get_path(SYS_PATH), 0, strpos(api_get_path(SYS_PATH),api_get_path(REL_PATH)));
  7069. if(strpos($document_root,-1)=='/')
  7070. {
  7071. $document_root = substr(0, -1, $document_root);
  7072. }*/
  7073. $file_path = $_SERVER['DOCUMENT_ROOT'].$doc_info[0];
  7074. $file_path = str_replace('//','/',$file_path);
  7075. if(file_exists($file_path))
  7076. {
  7077. $file_path = substr($file_path,strlen($current_dir)); // we get the relative path
  7078. $zip_files[] = $my_sub_dir.'/'.$file_path;
  7079. $link_updates[$my_file_path][] = array('orig'=>$doc_info[0],'dest'=>$file_path);
  7080. $my_dep_file->setAttribute('href','document/'.$file_path);
  7081. $my_dep->setAttribute('xml:base','');
  7082. }
  7083. }
  7084. break;
  7085. 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
  7086. if(substr($doc_info[0],0,2)=='..')
  7087. { //relative path going up
  7088. $current_dir = dirname($current_course_path.'/'.$item->get_file_path()).'/';
  7089. $file_path = realpath($current_dir.$doc_info[0]);
  7090. //error_log($file_path.' <-> '.$main_path,0);
  7091. if(strstr($file_path,$main_path) !== false)
  7092. {//the calculated real path is really inside the dokeos root path
  7093. //reduce file path to what's under the DocumentRoot
  7094. $file_path = substr($file_path,strlen($root_path));
  7095. //error_log('Reduced path: '.$file_path,0);
  7096. $zip_files_abs[] = $file_path;
  7097. $link_updates[$my_file_path][] = array('orig'=>$doc_info[0],'dest'=>$file_path);
  7098. $my_dep_file->setAttribute('href','document/'.$file_path);
  7099. $my_dep->setAttribute('xml:base','');
  7100. }
  7101. }else{
  7102. $zip_files[] = $my_sub_dir.'/'.$doc_info[0];
  7103. $my_dep_file->setAttribute('href',$doc_info[0]);
  7104. $my_dep->setAttribute('xml:base',$my_xml_sub_dir);
  7105. }
  7106. break;
  7107. default:
  7108. $my_dep_file->setAttribute('href',$doc_info[0]);
  7109. $my_dep->setAttribute('xml:base','');
  7110. break;
  7111. }
  7112. }
  7113. $my_dep->appendChild($my_dep_file);
  7114. $resources->appendChild($my_dep);
  7115. $dependency = $xmldoc->createElement('dependency');
  7116. $dependency->setAttribute('identifierref',$res_id);
  7117. $my_resource->appendChild($dependency);
  7118. $i++;
  7119. }
  7120. //$my_dependency = $xmldoc->createElement('dependency');
  7121. //$my_dependency->setAttribute('identifierref','');
  7122. $resources->appendChild($my_resource);
  7123. $zip_files[] = $my_file_path;
  7124. //error_log('File '.$my_file_path. ' added to $zip_files',0);
  7125. }
  7126. else
  7127. { // if the item is a quiz or a link or whatever non-exportable, we include a step indicating it
  7128. if($item->type == TOOL_LINK)
  7129. {
  7130. $my_item = $xmldoc->createElement('item');
  7131. $my_item->setAttribute('identifier','ITEM_'.$item->get_id());
  7132. $my_item->setAttribute('identifierref','RESOURCE_'.$item->get_id());
  7133. $my_item->setAttribute('isvisible','true');
  7134. //give a child element <title> to the <item> element
  7135. $my_title = $xmldoc->createElement('title',htmlspecialchars($item->get_title(),ENT_QUOTES));
  7136. $my_item->appendChild($my_title);
  7137. //give a child element <adlcp:prerequisites> to the <item> element
  7138. $my_prereqs = $xmldoc->createElement('adlcp:prerequisites',$item->get_prereq_string());
  7139. $my_prereqs->setAttribute('type','aicc_script');
  7140. $my_item->appendChild($my_prereqs);
  7141. //give a child element <adlcp:maxtimeallowed> to the <item> element - not yet supported
  7142. //$xmldoc->createElement('adlcp:maxtimeallowed','');
  7143. //give a child element <adlcp:timelimitaction> to the <item> element - not yet supported
  7144. //$xmldoc->createElement('adlcp:timelimitaction','');
  7145. //give a child element <adlcp:datafromlms> to the <item> element - not yet supported
  7146. //$xmldoc->createElement('adlcp:datafromlms','');
  7147. //give a child element <adlcp:masteryscore> to the <item> element
  7148. $my_masteryscore = $xmldoc->createElement('adlcp:masteryscore',$item->get_mastery_score());
  7149. $my_item->appendChild($my_masteryscore);
  7150. //attach this item to the organization element or its parent if there is one
  7151. if(!empty($item->parent) && $item->parent!=0)
  7152. {
  7153. $children = $organization->childNodes;
  7154. for($i=0;$i<$children->length;$i++){
  7155. $item_temp = $children->item($i);
  7156. if ($item_temp -> nodeName == 'item')
  7157. {
  7158. if($item_temp->getAttribute('identifier') == 'ITEM_'.$item->parent)
  7159. {
  7160. $item_temp -> appendChild($my_item);
  7161. }
  7162. }
  7163. }
  7164. }
  7165. else
  7166. {
  7167. $organization->appendChild($my_item);
  7168. }
  7169. $my_file_path = 'link_'.$item->get_id().'.html';
  7170. $sql = 'SELECT url, title FROM '.Database :: get_course_table(TABLE_LINK).' WHERE id='.$item->path;
  7171. $rs = Database::query($sql, __FILE__, __LINE__);
  7172. if($link = Database :: fetch_array($rs))
  7173. {
  7174. $url = $link['url'];
  7175. $title = stripslashes($link['title']);
  7176. $links_to_create[$my_file_path] = array('title'=>$title,'url'=>$url);
  7177. $my_xml_file_path = api_htmlentities($my_file_path, ENT_QUOTES, $this->encoding);
  7178. $my_sub_dir = dirname($my_file_path);
  7179. $my_xml_sub_dir = api_htmlentities($my_sub_dir, ENT_QUOTES, $this->encoding);
  7180. //give a <resource> child to the <resources> element
  7181. $my_resource = $xmldoc->createElement('resource');
  7182. $my_resource->setAttribute('identifier','RESOURCE_'.$item->get_id());
  7183. $my_resource->setAttribute('type','webcontent');
  7184. $my_resource->setAttribute('href',$my_xml_file_path);
  7185. //adlcp:scormtype can be either 'sco' or 'asset'
  7186. $my_resource->setAttribute('adlcp:scormtype','asset');
  7187. //xml:base is the base directory to find the files declared in this resource
  7188. $my_resource->setAttribute('xml:base','');
  7189. //give a <file> child to the <resource> element
  7190. $my_file = $xmldoc->createElement('file');
  7191. $my_file->setAttribute('href',$my_xml_file_path);
  7192. $my_resource->appendChild($my_file);
  7193. $resources->appendChild($my_resource);
  7194. }
  7195. }
  7196. elseif($item->type == TOOL_QUIZ)
  7197. {
  7198. require_once(api_get_path(SYS_CODE_PATH).'exercice/exercise.class.php');
  7199. $exe_id = $item->path; //should be using ref when everything will be cleaned up in this regard
  7200. $exe = new Exercise();
  7201. $exe->read($exe_id);
  7202. $my_item = $xmldoc->createElement('item');
  7203. $my_item->setAttribute('identifier','ITEM_'.$item->get_id());
  7204. $my_item->setAttribute('identifierref','RESOURCE_'.$item->get_id());
  7205. $my_item->setAttribute('isvisible','true');
  7206. //give a child element <title> to the <item> element
  7207. $my_title = $xmldoc->createElement('title',htmlspecialchars($item->get_title(), ENT_QUOTES, $this->encoding));
  7208. $my_item->appendChild($my_title);
  7209. $my_max_score = $xmldoc->createElement('max_score',$item->get_max());
  7210. $my_item->appendChild($my_max_score);
  7211. //give a child element <adlcp:prerequisites> to the <item> element
  7212. $my_prereqs = $xmldoc->createElement('adlcp:prerequisites',$item->get_prereq_string());
  7213. $my_prereqs->setAttribute('type','aicc_script');
  7214. $my_item->appendChild($my_prereqs);
  7215. //give a child element <adlcp:masteryscore> to the <item> element
  7216. $my_masteryscore = $xmldoc->createElement('adlcp:masteryscore',$item->get_mastery_score());
  7217. $my_item->appendChild($my_masteryscore);
  7218. //attach this item to the organization element or hits parent if there is one
  7219. if(!empty($item->parent) && $item->parent!=0)
  7220. {
  7221. $children = $organization->childNodes;
  7222. for($i=0;$i<$children->length;$i++){
  7223. $item_temp = $children->item($i);
  7224. if ($item_temp -> nodeName == 'item')
  7225. {
  7226. if($item_temp->getAttribute('identifier') == 'ITEM_'.$item->parent)
  7227. {
  7228. $item_temp -> appendChild($my_item);
  7229. }
  7230. }
  7231. }
  7232. }
  7233. else
  7234. {
  7235. $organization->appendChild($my_item);
  7236. }
  7237. //include export scripts
  7238. require_once(api_get_path(SYS_CODE_PATH).'exercice/export/scorm/scorm_export.php');
  7239. //get the path of the file(s) from the course directory root
  7240. //$my_file_path = $item->get_file_path('scorm/'.$this->path.'/');
  7241. $my_file_path = 'quiz_'.$item->get_id().'.html';
  7242. //write the contents of the exported exercise into a (big) html file
  7243. //to later pack it into the exported SCORM. The file will be removed afterwards
  7244. $contents = export_exercise($exe_id,true);
  7245. $tmp_file_path = $archive_path.$temp_dir_short.'/'.$my_file_path;
  7246. $res = file_put_contents($tmp_file_path,$contents);
  7247. if($res === false){error_log('Could not write into file '.$tmp_file_path.' '.__FILE__.' '.__LINE__,0);}
  7248. $files_cleanup[] = $tmp_file_path;
  7249. //error_log($tmp_path);die();
  7250. $my_xml_file_path = api_htmlentities($my_file_path, ENT_QUOTES, $this->encoding);
  7251. $my_sub_dir = dirname($my_file_path);
  7252. $my_xml_sub_dir = api_htmlentities($my_sub_dir, ENT_QUOTES, $this->encoding);
  7253. //give a <resource> child to the <resources> element
  7254. $my_resource = $xmldoc->createElement('resource');
  7255. $my_resource->setAttribute('identifier','RESOURCE_'.$item->get_id());
  7256. $my_resource->setAttribute('type','webcontent');
  7257. $my_resource->setAttribute('href',$my_xml_file_path);
  7258. //adlcp:scormtype can be either 'sco' or 'asset'
  7259. $my_resource->setAttribute('adlcp:scormtype','sco');
  7260. //xml:base is the base directory to find the files declared in this resource
  7261. $my_resource->setAttribute('xml:base','');
  7262. //give a <file> child to the <resource> element
  7263. $my_file = $xmldoc->createElement('file');
  7264. $my_file->setAttribute('href',$my_xml_file_path);
  7265. $my_resource->appendChild($my_file);
  7266. //get included docs
  7267. $inc_docs = $item->get_resources_from_source(null,$tmp_file_path);
  7268. //dependency to other files - not yet supported
  7269. $i = 1;
  7270. foreach($inc_docs as $doc_info)
  7271. {
  7272. if(count($doc_info)<1 or empty($doc_info[0])){continue;}
  7273. $my_dep = $xmldoc->createElement('resource');
  7274. $res_id = 'RESOURCE_'.$item->get_id().'_'.$i;
  7275. $my_dep->setAttribute('identifier',$res_id);
  7276. $my_dep->setAttribute('type','webcontent');
  7277. $my_dep->setAttribute('adlcp:scormtype','asset');
  7278. $my_dep_file = $xmldoc->createElement('file');
  7279. //check type of URL
  7280. //error_log(__LINE__.'Now dealing with '.$doc_info[0].' of type '.$doc_info[1].'-'.$doc_info[2],0);
  7281. if($doc_info[1] == 'remote')
  7282. { //remote file. Save url as is
  7283. $my_dep_file->setAttribute('href',$doc_info[0]);
  7284. $my_dep->setAttribute('xml:base','');
  7285. }elseif($doc_info[1] == 'local'){
  7286. switch($doc_info[2])
  7287. {
  7288. case 'url': //local URL - save path as url for now, don't zip file
  7289. //save file but as local file (retrieve from URL)
  7290. $abs_path = api_get_path(SYS_PATH).str_replace(api_get_path(WEB_PATH),'',$doc_info[0]);
  7291. $current_dir = dirname($abs_path);
  7292. $file_path = realpath($abs_path);
  7293. $my_dep_file->setAttribute('href','document/'.$file_path);
  7294. $my_dep->setAttribute('xml:base','');
  7295. if(strstr($file_path,$main_path) !== false)
  7296. {//the calculated real path is really inside the dokeos root path
  7297. //reduce file path to what's under the DocumentRoot
  7298. $file_path = substr($file_path,strlen($root_path));
  7299. //echo $file_path;echo '<br><br>';
  7300. //error_log('Reduced path: '.$file_path,0);
  7301. $zip_files_abs[] = $file_path;
  7302. $link_updates[$my_file_path][] = array('orig'=>$doc_info[0],'dest'=>'document/'.$file_path);
  7303. $my_dep_file->setAttribute('href','document/'.$file_path);
  7304. $my_dep->setAttribute('xml:base','');
  7305. }
  7306. else if (empty($file_path))
  7307. {
  7308. /*$document_root = substr(api_get_path(SYS_PATH), 0, strpos(api_get_path(SYS_PATH),api_get_path(REL_PATH)));
  7309. if(strpos($document_root,-1)=='/')
  7310. {
  7311. $document_root = substr(0, -1, $document_root);
  7312. }*/
  7313. $file_path = $_SERVER['DOCUMENT_ROOT'].$abs_path;
  7314. $file_path = str_replace('//','/',$file_path);
  7315. if(file_exists($file_path))
  7316. {
  7317. $file_path = substr($file_path,strlen($current_dir)); // we get the relative path
  7318. $zip_files[] = $my_sub_dir.'/'.$file_path;
  7319. $link_updates[$my_file_path][] = array('orig'=>$doc_info[0],'dest'=>'document/'.$file_path);
  7320. $my_dep_file->setAttribute('href','document/'.$file_path);
  7321. $my_dep->setAttribute('xml:base','');
  7322. }
  7323. }
  7324. break;
  7325. case 'abs': //absolute path from DocumentRoot. Save file and leave path as is in the zip
  7326. $current_dir = dirname($current_course_path.'/'.$item->get_file_path()).'/';
  7327. $file_path = realpath($doc_info[0]);
  7328. $my_dep_file->setAttribute('href',$file_path);
  7329. $my_dep->setAttribute('xml:base','');
  7330. if(strstr($file_path,$main_path) !== false)
  7331. {//the calculated real path is really inside the dokeos root path
  7332. //reduce file path to what's under the DocumentRoot
  7333. $file_path = substr($file_path,strlen($root_path));
  7334. //echo $file_path;echo '<br><br>';
  7335. //error_log('Reduced path: '.$file_path,0);
  7336. $zip_files_abs[] = $file_path;
  7337. $link_updates[$my_file_path][] = array('orig'=>$doc_info[0],'dest'=>$file_path);
  7338. $my_dep_file->setAttribute('href','document/'.$file_path);
  7339. $my_dep->setAttribute('xml:base','');
  7340. }
  7341. else if (empty($file_path))
  7342. {
  7343. /*$document_root = substr(api_get_path(SYS_PATH), 0, strpos(api_get_path(SYS_PATH),api_get_path(REL_PATH)));
  7344. if(strpos($document_root,-1)=='/')
  7345. {
  7346. $document_root = substr(0, -1, $document_root);
  7347. }*/
  7348. $file_path = $_SERVER['DOCUMENT_ROOT'].$doc_info[0];
  7349. $file_path = str_replace('//','/',$file_path);
  7350. if(file_exists($file_path))
  7351. {
  7352. $file_path = substr($file_path,strlen($current_dir)); // we get the relative path
  7353. $zip_files[] = $my_sub_dir.'/'.$file_path;
  7354. $link_updates[$my_file_path][] = array('orig'=>$doc_info[0],'dest'=>$file_path);
  7355. $my_dep_file->setAttribute('href','document/'.$file_path);
  7356. $my_dep->setAttribute('xml:base','');
  7357. }
  7358. }
  7359. break;
  7360. 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
  7361. if(substr($doc_info[0],0,2)=='..')
  7362. { //relative path going up
  7363. $current_dir = dirname($current_course_path.'/'.$item->get_file_path()).'/';
  7364. $file_path = realpath($current_dir.$doc_info[0]);
  7365. //error_log($file_path.' <-> '.$main_path,0);
  7366. if(strstr($file_path,$main_path) !== false)
  7367. {//the calculated real path is really inside the dokeos root path
  7368. //reduce file path to what's under the DocumentRoot
  7369. $file_path = substr($file_path,strlen($root_path));
  7370. $file_path_dest=$file_path;
  7371. //file path is courses/DOKEOS/document/....
  7372. $info_file_path=explode('/',$file_path);
  7373. if ($info_file_path[0]=='courses') {//add character "/" in file path
  7374. $file_path_dest='/'.$file_path;
  7375. }
  7376. //error_log('Reduced path: '.$file_path,0);
  7377. $zip_files_abs[] = $file_path;
  7378. $link_updates[$my_file_path][] = array('orig'=>$doc_info[0],'dest'=>$file_path_dest);
  7379. $my_dep_file->setAttribute('href','document/'.$file_path);
  7380. $my_dep->setAttribute('xml:base','');
  7381. }
  7382. }else{
  7383. $zip_files[] = $my_sub_dir.'/'.$doc_info[0];
  7384. $my_dep_file->setAttribute('href',$doc_info[0]);
  7385. $my_dep->setAttribute('xml:base',$my_xml_sub_dir);
  7386. }
  7387. break;
  7388. default:
  7389. $my_dep_file->setAttribute('href',$doc_info[0]);// ../../courses/
  7390. $my_dep->setAttribute('xml:base','');
  7391. break;
  7392. }
  7393. }
  7394. $my_dep->appendChild($my_dep_file);
  7395. $resources->appendChild($my_dep);
  7396. $dependency = $xmldoc->createElement('dependency');
  7397. $dependency->setAttribute('identifierref',$res_id);
  7398. $my_resource->appendChild($dependency);
  7399. $i++;
  7400. }
  7401. $resources->appendChild($my_resource);
  7402. $zip_files[] = $my_file_path;
  7403. }
  7404. else
  7405. {
  7406. //get the path of the file(s) from the course directory root
  7407. $my_file_path = 'non_exportable.html';
  7408. $my_xml_file_path = api_htmlentities($my_file_path, ENT_COMPAT, $this->encoding);
  7409. $my_sub_dir = dirname($my_file_path);
  7410. $my_xml_sub_dir = api_htmlentities($my_sub_dir, ENT_COMPAT, $this->encoding);
  7411. //give a <resource> child to the <resources> element
  7412. $my_resource = $xmldoc->createElement('resource');
  7413. $my_resource->setAttribute('identifier','RESOURCE_'.$item->get_id());
  7414. $my_resource->setAttribute('type','webcontent');
  7415. $my_resource->setAttribute('href','document/'.$my_xml_file_path);
  7416. //adlcp:scormtype can be either 'sco' or 'asset'
  7417. $my_resource->setAttribute('adlcp:scormtype','asset');
  7418. //xml:base is the base directory to find the files declared in this resource
  7419. $my_resource->setAttribute('xml:base','');
  7420. //give a <file> child to the <resource> element
  7421. $my_file = $xmldoc->createElement('file');
  7422. $my_file->setAttribute('href','document/'.$my_xml_file_path);
  7423. $my_resource->appendChild($my_file);
  7424. $resources->appendChild($my_resource);
  7425. }
  7426. }
  7427. }
  7428. $organizations->appendChild($organization);
  7429. $root->appendChild($organizations);
  7430. $root->appendChild($resources);
  7431. $xmldoc->appendChild($root);
  7432. //todo: add a readme file here, with a short description and a link to the Reload player
  7433. //then add the file to the zip, then destroy the file (this is done automatically)
  7434. // http://www.reload.ac.uk/scormplayer.html - once done, don't forget to close FS#138
  7435. //error_log(print_r($zip_files,true),0);
  7436. foreach($zip_files as $file_path)
  7437. {
  7438. if(empty($file_path)){continue;}
  7439. //error_log(__LINE__.'getting document from '.$sys_course_path.$_course['path'].'/'.$file_path.' removing '.$sys_course_path.$_course['path'].'/',0);
  7440. $dest_file = $archive_path.$temp_dir_short.'/'.$file_path;
  7441. $this->create_path($dest_file);
  7442. //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);
  7443. //echo $main_path.$file_path.'<br>';
  7444. @copy($sys_course_path.$_course['path'].'/'.$file_path,$dest_file);
  7445. //check if the file needs a link update
  7446. if(in_array($file_path,array_keys($link_updates))){
  7447. $string = file_get_contents($dest_file);
  7448. unlink($dest_file);
  7449. foreach($link_updates[$file_path] as $old_new)
  7450. {
  7451. //error_log('Replacing '.$old_new['orig'].' by '.$old_new['dest'].' in '.$file_path,0);
  7452. //this is an ugly hack that allows .flv files to be found by the flv player that
  7453. // will be added in document/main/inc/lib/flv_player/flv_player.swf and that needs
  7454. // to find the flv to play in document/main/, so we replace main/ in the flv path by
  7455. // ../../.. to return from inc/lib/flv_player to the document/main path
  7456. if(substr($old_new['dest'],-3)=='flv' && substr($old_new['dest'],0,5)=='main/')
  7457. {
  7458. $old_new['dest'] = str_replace('main/','../../../',$old_new['dest']);
  7459. }
  7460. elseif(substr($old_new['dest'],-3)=='flv' && substr($old_new['dest'],0,6)=='video/')
  7461. {
  7462. $old_new['dest'] = str_replace('video/','../../../../video/',$old_new['dest']);
  7463. }
  7464. $string = str_replace($old_new['orig'],$old_new['dest'],$string);
  7465. }
  7466. file_put_contents($dest_file,$string);
  7467. }
  7468. }
  7469. foreach($zip_files_abs as $file_path)
  7470. {
  7471. if(empty($file_path)){continue;}
  7472. //error_log(__LINE__.'checking existence of '.$main_path.$file_path.'',0);
  7473. if(!is_file($main_path.$file_path) || !is_readable($main_path.$file_path)){continue;}
  7474. //error_log(__LINE__.'getting document from '.$main_path.$file_path.' removing '.api_get_path('SYS_COURSE_PATH').$_course['path'].'/',0);
  7475. $dest_file = $archive_path.$temp_dir_short.'/document/'.$file_path;
  7476. $this->create_path($dest_file);
  7477. //error_log('Created path '.api_get_path(SYS_ARCHIVE_PATH).$temp_dir_short.'/document/'.$file_path,0);
  7478. //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);
  7479. //echo $main_path.$file_path.' - '.$dest_file.'<br>';
  7480. copy($main_path.$file_path,$dest_file);
  7481. //check if the file needs a link update
  7482. if(in_array($file_path,array_keys($link_updates)))
  7483. {
  7484. $string = file_get_contents($dest_file);
  7485. unlink($dest_file);
  7486. foreach($link_updates[$file_path] as $old_new)
  7487. {
  7488. //error_log('Replacing '.$old_new['orig'].' by '.$old_new['dest'].' in '.$file_path,0);
  7489. //this is an ugly hack that allows .flv files to be found by the flv player that
  7490. // will be added in document/main/inc/lib/flv_player/flv_player.swf and that needs
  7491. // to find the flv to play in document/main/, so we replace main/ in the flv path by
  7492. // ../../.. to return from inc/lib/flv_player to the document/main path
  7493. if(substr($old_new['dest'],-3)=='flv' && substr($old_new['dest'],0,5)=='main/')
  7494. {
  7495. $old_new['dest'] = str_replace('main/','../../../',$old_new['dest']);
  7496. }
  7497. $string = str_replace($old_new['orig'],$old_new['dest'],$string);
  7498. }
  7499. file_put_contents($dest_file,$string);
  7500. }
  7501. }
  7502. if(is_array($links_to_create))
  7503. {
  7504. foreach($links_to_create as $file=>$link)
  7505. {
  7506. $file_content = '<html><body><div style="text-align:center"><a href="'.$link['url'].'">'.$link['title'].'</a></div></body></html>';
  7507. file_put_contents($archive_path.$temp_dir_short.'/'.$file, $file_content);
  7508. }
  7509. }
  7510. // add non exportable message explanation
  7511. $lang_not_exportable = get_lang('ThisItemIsNotExportable');
  7512. $file_content =
  7513. <<<EOD
  7514. <html>
  7515. <head>
  7516. <style>
  7517. .error-message {
  7518. font-family: arial, verdana, helvetica, sans-serif;
  7519. border-width: 1px;
  7520. border-style: solid;
  7521. left: 50%;
  7522. margin: 10px auto;
  7523. min-height: 30px;
  7524. padding: 5px;
  7525. right: 50%;
  7526. width: 500px;
  7527. background-color: #FFD1D1;
  7528. border-color: #FF0000;
  7529. color: #000;
  7530. }
  7531. </style>
  7532. <body>
  7533. <div class="error-message">
  7534. $lang_not_exportable
  7535. </div>
  7536. </body>
  7537. </html>
  7538. EOD;
  7539. if(!is_dir($archive_path.$temp_dir_short.'/document'))
  7540. {
  7541. @mkdir($archive_path.$temp_dir_short.'/document');
  7542. }
  7543. file_put_contents($archive_path.$temp_dir_short.'/document/non_exportable.html', $file_content);
  7544. //Add the extra files that go along with a SCORM package
  7545. $main_code_path = api_get_path(SYS_CODE_PATH).'newscorm/packaging/';
  7546. $extra_files = scandir($main_code_path);
  7547. foreach ($extra_files as $extra_file) {
  7548. if (strpos($extra_file, '.') === 0)
  7549. continue;
  7550. else {
  7551. $dest_file = $archive_path . $temp_dir_short . '/' . $extra_file;
  7552. $this->create_path($dest_file);
  7553. copy($main_code_path.$extra_file,$dest_file);
  7554. }
  7555. }
  7556. //Finalize the imsmanifest structure, add to the zip, then return the zip
  7557. $xmldoc->save($archive_path.'/'.$temp_dir_short.'/imsmanifest.xml');
  7558. $zip_folder->add($archive_path.'/'.$temp_dir_short, PCLZIP_OPT_REMOVE_PATH, $archive_path.'/'.$temp_dir_short.'/');
  7559. //clean possible temporary files
  7560. foreach($files_cleanup as $file)
  7561. {
  7562. $res = unlink($file);
  7563. if($res === false){error_log('Could not delete temp file '.$file.' '.__FILE__.' '.__LINE__,0);}
  7564. }
  7565. //Send file to client
  7566. //$name = 'scorm_export_'.$this->lp_id.'.zip';
  7567. require_once(api_get_path(LIBRARY_PATH).'fileUpload.lib.php');
  7568. $name = preg_replace('([^a-zA-Z0-9_\.])','-',html_entity_decode($this->get_name(),ENT_QUOTES)).'.zip';
  7569. DocumentManager::file_send_for_download($temp_zip_file,true,$name);
  7570. }
  7571. /**
  7572. * Temp function to be moved in main_api or the best place around for this. Creates a file path
  7573. * if it doesn't exist
  7574. */
  7575. function create_path($path) {
  7576. $path_bits = split('/', dirname($path));
  7577. // IS_WINDOWS_OS has been defined in main_api.lib.php
  7578. $path_built = IS_WINDOWS_OS ? '' : '/';
  7579. foreach ($path_bits as $bit) {
  7580. if (!empty ($bit)) {
  7581. $new_path = $path_built . $bit;
  7582. if (is_dir($new_path)) {
  7583. $path_built = $new_path . '/';
  7584. } else {
  7585. mkdir($new_path);
  7586. $path_built = $new_path . '/';
  7587. }
  7588. }
  7589. }
  7590. }
  7591. /**
  7592. * Delete the image relative to this learning path. No parameter. Only works on instanciated object.
  7593. * @return boolean The results of the unlink function, or false if there was no image to start with
  7594. */
  7595. function delete_lp_image() {
  7596. $img = $this->get_preview_image();
  7597. if ($img != '') {
  7598. $del_file = api_get_path(SYS_COURSE_PATH) . api_get_course_path() . '/upload/learning_path/images/' . $img;
  7599. $this->set_preview_image('');
  7600. return @ unlink($del_file);
  7601. } else {
  7602. return false;
  7603. }
  7604. }
  7605. /**
  7606. * Uploads an author image to the upload/learning_path/images directory
  7607. * @param array The image array, coming from the $_FILES superglobal
  7608. * @return boolean True on success, false on error
  7609. */
  7610. function upload_image($image_array) {
  7611. $image_moved = false;
  7612. if (!empty ($image_array['name'])) {
  7613. $upload_ok = process_uploaded_file($image_array);
  7614. $has_attachment = true;
  7615. } else {
  7616. $image_moved = true;
  7617. }
  7618. if ($upload_ok) {
  7619. if ($has_attachment) {
  7620. $courseDir = api_get_course_path() . '/upload/learning_path/images';
  7621. $sys_course_path = api_get_path(SYS_COURSE_PATH);
  7622. $updir = $sys_course_path . $courseDir;
  7623. // Try to add an extension to the file if it hasn't one
  7624. $new_file_name = add_ext_on_mime(stripslashes($image_array['name']), $image_array['type']);
  7625. if (!filter_extension($new_file_name)) {
  7626. //Display :: display_error_message(get_lang('UplUnableToSaveFileFilteredExtension'));
  7627. $image_moved = false;
  7628. } else {
  7629. $file_extension = explode('.', $image_array['name']);
  7630. $file_extension = strtolower($file_extension[sizeof($file_extension) - 1]);
  7631. $new_file_name = uniqid('') . '.' . $file_extension;
  7632. $new_path = $updir . '/' . $new_file_name;
  7633. //$result= @move_uploaded_file($image_array['tmp_name'], $new_path);
  7634. // resize the image
  7635. include_once (api_get_path(LIBRARY_PATH) . 'image.lib.php');
  7636. $temp = new image($image_array['tmp_name']);
  7637. $picture_infos=@getimagesize($image_array['tmp_name']); // $picture_infos[0]-> width
  7638. if ($picture_infos[0] > 104) {
  7639. $thumbwidth = 104;
  7640. } else {
  7641. $thumbwidth = $picture_infos[0];
  7642. }
  7643. if ($picture_infos[1] > 96) {
  7644. $new_height = 96;
  7645. } else {
  7646. $new_height = $picture_infos[1];
  7647. }
  7648. //$new_height = round(($thumbwidth/$picture_infos[0])*$picture_infos[1]);
  7649. $temp->resize($thumbwidth,$new_height,0);
  7650. $type=$picture_infos[2];
  7651. $result=false;
  7652. switch ($type)
  7653. {
  7654. case 2 :
  7655. $result=$temp->send_image('JPG',$new_path);
  7656. break;
  7657. case 3 :
  7658. $result=$temp->send_image('PNG',$new_path);
  7659. break;
  7660. case 1 :
  7661. $result=$temp->send_image('GIF',$new_path);
  7662. break;
  7663. }
  7664. $temp->resize($thumbwidth, $new_height, 0);
  7665. $type = $picture_infos[2];
  7666. $result = false;
  7667. switch ($type) {
  7668. case 2 :
  7669. $result = $temp->send_image('JPG', $new_path);
  7670. break;
  7671. case 3 :
  7672. $result = $temp->send_image('PNG', $new_path);
  7673. break;
  7674. case 1 :
  7675. $result = $temp->send_image('GIF', $new_path);
  7676. break;
  7677. }
  7678. // Storing the image filename
  7679. if ($result) {
  7680. $image_moved = true;
  7681. $this->set_preview_image($new_file_name);
  7682. return true;
  7683. }
  7684. }
  7685. }
  7686. }
  7687. return false;
  7688. }
  7689. }
  7690. if (!function_exists('trim_value')) {
  7691. function trim_value(& $value) {
  7692. $value = trim($value);
  7693. }
  7694. }