learnpath.class.php 414 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * This class defines the parent attributes and methods for Chamilo learnpaths and SCORM
  5. * learnpaths. It is used by the scorm class.
  6. *
  7. * @package chamilo.learnpath
  8. * @author Yannick Warnier <ywarnier@beeznest.org>
  9. * @author Julio Montoya <gugli100@gmail.com> Improvements
  10. */
  11. /**
  12. * Defines the learnpath parent class
  13. * @package chamilo.learnpath
  14. */
  15. class learnpath {
  16. public $attempt = 0; // The number for the current ID view.
  17. public $cc; // Course (code) this learnpath is located in. @todo change name for something more comprensible ...
  18. public $current; // Id of the current item the user is viewing.
  19. public $current_score; // The score of the current item.
  20. public $current_time_start; // The time the user loaded this resource (this does not mean he can see it yet).
  21. public $current_time_stop; // The time the user closed this resource.
  22. public $default_status = 'not attempted';
  23. public $encoding = 'UTF-8';
  24. public $error = '';
  25. public $extra_information = ''; // This string can be used by proprietary SCORM contents to store data about the current learnpath.
  26. public $force_commit = false; // For SCORM only - if set to true, will send a scorm LMSCommit() request on each LMSSetValue().
  27. public $index; // The index of the active learnpath_item in $ordered_items array.
  28. public $items = array();
  29. public $last; // item_id of last item viewed in the learning path.
  30. public $last_item_seen = 0; // In case we have already come in this learnpath, reuse the last item seen if authorized.
  31. public $license; // Which license this course has been given - not used yet on 20060522.
  32. public $lp_id; // DB ID for this learnpath.
  33. public $lp_view_id; // DB ID for lp_view
  34. public $log_file; // File where to log learnpath API msg.
  35. public $maker; // Which maker has conceived the content (ENI, Articulate, ...).
  36. public $message = '';
  37. public $mode = 'embedded'; // Holds the video display mode (fullscreen or embedded).
  38. public $name; // Learnpath name (they generally have one).
  39. public $ordered_items = array(); // List of the learnpath items in the order they are to be read.
  40. public $path = ''; // Path inside the scorm directory (if scorm).
  41. public $theme; // The current theme of the learning path.
  42. public $preview_image; // The current image of the learning path.
  43. // Tells if all the items of the learnpath can be tried again. Defaults to "no" (=1).
  44. public $prevent_reinit = 1;
  45. // Describes the mode of progress bar display.
  46. public $progress_bar_mode = '%';
  47. // Percentage progress as saved in the db.
  48. public $progress_db = '0';
  49. public $proximity; // Wether the content is distant or local or unknown.
  50. public $refs_list = array (); //list of items by ref => db_id. Used only for prerequisites match.
  51. // !!!This array (refs_list) is built differently depending on the nature of the LP.
  52. // If SCORM, uses ref, if Chamilo, uses id to keep a unique value.
  53. public $type; //type of learnpath. Could be 'dokeos', 'scorm', 'scorm2004', 'aicc', ...
  54. // TODO: Check if this type variable is useful here (instead of just in the controller script).
  55. public $user_id; //ID of the user that is viewing/using the course
  56. public $update_queue = array();
  57. public $scorm_debug = 0;
  58. public $arrMenu = array(); // Array for the menu items.
  59. public $debug = 0; // Logging level.
  60. public $lp_session_id =0;
  61. public $lp_view_session_id =0; // The specific view might be bound to a session.
  62. public $prerequisite = 0;
  63. public $use_max_score = 1; // 1 or 0
  64. public $created_on = '';
  65. public $modified_on = '';
  66. public $publicated_on = '';
  67. public $expired_on = '';
  68. /**
  69. * Class constructor. Needs a database handler, a course code and a learnpath id from the database.
  70. * Also builds the list of items into $this->items.
  71. * @param string Course code
  72. * @param integer Learnpath ID
  73. * @param integer User ID
  74. * @return boolean True on success, false on error
  75. */
  76. public function __construct($course, $lp_id, $user_id) {
  77. $this->encoding = api_get_system_encoding(); // Chamilo 1.8.8: We intend always to use the system encoding.
  78. // Check params.
  79. // Check course code.
  80. $course_db = '';
  81. if ($this->debug > 0) {error_log('New LP - In learnpath::__construct('.$course.','.$lp_id.','.$user_id.')', 0); }
  82. if (empty($course)) {
  83. $this->error = 'Course code is empty';
  84. return false;
  85. } else {
  86. $main_table = Database::get_main_table(TABLE_MAIN_COURSE);
  87. //$course = Database::escape_string($course);
  88. $course = $this->escape_string($course);
  89. $sql = "SELECT * FROM $main_table WHERE code = '$course'";
  90. if ($this->debug > 2) { error_log('New LP - learnpath::__construct() '.__LINE__.' - Querying course: '.$sql, 0); }
  91. $res = Database::query($sql);
  92. if (Database::num_rows($res) > 0) {
  93. $this->cc = $course;
  94. $row_course = Database::fetch_array($res);
  95. $course_db = $row_course['db_name'];
  96. } else {
  97. $this->error = 'Course code does not exist in database ('.$sql.')';
  98. return false;
  99. }
  100. }
  101. // Check learnpath ID.
  102. if (empty($lp_id)) {
  103. $this->error = 'Learnpath ID is empty';
  104. return false;
  105. } else {
  106. // TODO: Make it flexible to use any course_code (still using env course code here).
  107. $lp_table = Database::get_course_table(TABLE_LP_MAIN, $course_db);
  108. //$id = Database::escape_integer($id);
  109. $lp_id = $this->escape_string($lp_id);
  110. $sql = "SELECT * FROM $lp_table WHERE id = '$lp_id'";
  111. if ($this->debug > 2) { error_log('New LP - learnpath::__construct() '.__LINE__.' - Querying lp: '.$sql, 0); }
  112. $res = Database::query($sql);
  113. if (Database::num_rows($res) > 0) {
  114. $this->lp_id = $lp_id;
  115. $row = Database::fetch_array($res);
  116. $this->type = $row['lp_type'];
  117. $this->name = stripslashes($row['name']);
  118. //$this->encoding = $row['default_encoding']; // Chamilo 1.8.8: We intend not to use 'default_encoding' field anymore.
  119. $this->proximity = $row['content_local'];
  120. $this->theme = $row['theme'];
  121. $this->maker = $row['content_maker'];
  122. $this->prevent_reinit = $row['prevent_reinit'];
  123. $this->license = $row['content_license'];
  124. $this->scorm_debug = $row['debug'];
  125. $this->js_lib = $row['js_lib'];
  126. $this->path = $row['path'];
  127. $this->preview_image = $row['preview_image'];
  128. $this->author = $row['author'];
  129. $this->lp_session_id = $row['session_id'];
  130. $this->use_max_score = $row['use_max_score'];
  131. $this->created_on = $row['created_on'];
  132. $this->modified_on = $row['modified_on'];
  133. if ($row['publicated_on'] != '0000-00-00 00:00:00') {
  134. $this->publicated_on = $row['publicated_on'];
  135. }
  136. if ($row['expired_on'] != '0000-00-00 00:00:00') {
  137. $this->expired_on = $row['expired_on'];
  138. }
  139. if ($this->type == 2) {
  140. if ($row['force_commit'] == 1) {
  141. $this->force_commit = true;
  142. }
  143. }
  144. $this->mode = $row['default_view_mod'];
  145. } else {
  146. $this->error = 'Learnpath ID does not exist in database ('.$sql.')';
  147. return false;
  148. }
  149. }
  150. // Check user ID.
  151. if (empty($user_id)) {
  152. $this->error = 'User ID is empty';
  153. return false;
  154. } else {
  155. //$main_table = Database::get_main_user_table();
  156. $main_table = Database::get_main_table(TABLE_MAIN_USER);
  157. //$user_id = Database::escape_integer($user_id);
  158. $user_id = $this->escape_string($user_id);
  159. $sql = "SELECT * FROM $main_table WHERE user_id = '$user_id'";
  160. if ($this->debug > 2) { error_log('New LP - learnpath::__construct() '.__LINE__.' - Querying user: '.$sql, 0); }
  161. $res = Database::query($sql);
  162. if (Database::num_rows($res) > 0) {
  163. $this->user_id = $user_id;
  164. } else {
  165. $this->error = 'User ID does not exist in database ('.$sql.')';
  166. return false;
  167. }
  168. }
  169. // End of variables checking.
  170. $session_id = api_get_session_id();
  171. // Get the session condition for learning paths of the base + session.
  172. $session = api_get_session_condition($session_id);
  173. // Now get the latest attempt from this user on this LP, if available, otherwise create a new one.
  174. $lp_table = Database::get_course_table(TABLE_LP_VIEW, $course_db);
  175. // Selecting by view_count descending allows to get the highest view_count first.
  176. $sql = "SELECT * FROM $lp_table WHERE lp_id = '$lp_id' AND user_id = '$user_id' $session ORDER BY view_count DESC";
  177. if ($this->debug > 2) { error_log('New LP - learnpath::__construct() ' . __LINE__ . ' - querying lp_view: ' . $sql, 0); }
  178. $res = Database::query($sql);
  179. $view_id = 0; // Used later to query lp_item_view.
  180. if (Database :: num_rows($res) > 0) {
  181. if ($this->debug > 2) {
  182. error_log('New LP - learnpath::__construct() ' . __LINE__ . ' - Found previous view', 0);
  183. }
  184. $row = Database :: fetch_array($res);
  185. $this->attempt = $row['view_count'];
  186. $this->lp_view_id = $row['id'];
  187. $this->last_item_seen = $row['last_item'];
  188. $this->progress_db = $row['progress'];
  189. $this->lp_view_session_id = $row['session_id'];
  190. } else {
  191. if ($this->debug > 2) {
  192. error_log('New LP - learnpath::__construct() ' . __LINE__ . ' - NOT Found previous view', 0);
  193. }
  194. $this->attempt = 1;
  195. $sql_ins = "INSERT INTO $lp_table (lp_id,user_id,view_count, session_id) VALUES ($lp_id,$user_id,1,$session_id)";
  196. $res_ins = Database::query($sql_ins);
  197. $this->lp_view_id = Database :: insert_id();
  198. if ($this->debug > 2) {
  199. error_log('New LP - learnpath::__construct() ' . __LINE__ . ' - inserting new lp_view: ' . $sql_ins, 0);
  200. }
  201. }
  202. // Initialise items.
  203. $lp_item_table = Database::get_course_table(TABLE_LP_ITEM, $course_db);
  204. $sql = "SELECT * FROM $lp_item_table WHERE lp_id = '".$this->lp_id."' ORDER BY parent_item_id, display_order";
  205. $res = Database::query($sql);
  206. while ($row = Database::fetch_array($res)) {
  207. $oItem = '';
  208. //$this->ordered_items[] = $row['id'];
  209. switch ($this->type) {
  210. case 3: //aicc
  211. $oItem = new aiccItem('db', $row['id'], $course_db);
  212. if (is_object($oItem)) {
  213. $my_item_id = $oItem->get_id();
  214. $oItem->set_lp_view($this->lp_view_id, $course_db);
  215. $oItem->set_prevent_reinit($this->prevent_reinit);
  216. // Don't use reference here as the next loop will make the pointed object change.
  217. $this->items[$my_item_id] = $oItem;
  218. $this->refs_list[$oItem->ref] = $my_item_id;
  219. if ($this->debug > 2) {
  220. error_log('New LP - learnpath::__construct() - aicc object with id ' . $my_item_id . ' set in items[]', 0);
  221. }
  222. }
  223. break;
  224. case 2:
  225. require_once 'scorm.class.php';
  226. require_once 'scormItem.class.php';
  227. $oItem = new scormItem('db', $row['id'], $course_db);
  228. if (is_object($oItem)) {
  229. $my_item_id = $oItem->get_id();
  230. $oItem->set_lp_view($this->lp_view_id, $course_db);
  231. $oItem->set_prevent_reinit($this->prevent_reinit);
  232. // Don't use reference here as the next loop will make the pointed object change.
  233. $this->items[$my_item_id] = $oItem;
  234. $this->refs_list[$oItem->ref] = $my_item_id;
  235. if ($this->debug > 2) {
  236. error_log('New LP - object with id ' . $my_item_id . ' set in items[]', 0);
  237. }
  238. }
  239. break;
  240. case 1:
  241. default:
  242. require_once 'learnpathItem.class.php';
  243. $oItem = new learnpathItem($row['id'], $user_id, $course_db);
  244. if (is_object($oItem)) {
  245. $my_item_id = $oItem->get_id();
  246. //$oItem->set_lp_view($this->lp_view_id); // Moved down to when we are sure the item_view exists.
  247. $oItem->set_prevent_reinit($this->prevent_reinit);
  248. // Don't use reference here as the next loop will make the pointed object change.
  249. $this->items[$my_item_id] = $oItem;
  250. $this->refs_list[$my_item_id] = $my_item_id;
  251. if ($this->debug > 2) {
  252. error_log('New LP - learnpath::__construct() ' . __LINE__ . ' - object with id ' . $my_item_id . ' set in items[]', 0);
  253. }
  254. }
  255. break;
  256. }
  257. // Items is a list of pointers to all items, classified by DB ID, not SCO id.
  258. if ($row['parent_item_id'] == 0 || empty ($this->items[$row['parent_item_id']])) {
  259. if (is_object($this->items[$row['id']])) {
  260. $this->items[$row['id']]->set_level(0);
  261. }
  262. } else {
  263. $level = $this->items[$row['parent_item_id']]->get_level() + 1;
  264. $this->items[$row['id']]->set_level($level);
  265. if (is_object($this->items[$row['parent_item_id']])) {
  266. // Items is a list of pointers from item DB ids to item objects.
  267. $this->items[$row['parent_item_id']]->add_child($row['id']);
  268. } else {
  269. if ($this->debug > 2) {
  270. error_log('New LP - learnpath::__construct() ' . __LINE__ . ' - The parent item (' . $row['parent_item_id'] . ') of item ' . $row['id'] . ' could not be found', 0);
  271. }
  272. }
  273. }
  274. // Get last viewing vars.
  275. $lp_item_view_table = Database :: get_course_table(TABLE_LP_ITEM_VIEW, $course_db);
  276. // This query should only return one or zero result.
  277. $sql = "SELECT * " .
  278. "FROM $lp_item_view_table " .
  279. "WHERE lp_view_id = " . $this->lp_view_id . " " .
  280. "AND lp_item_id = " . $row['id'] . " ORDER BY view_count DESC ";
  281. if ($this->debug > 2) {
  282. error_log('New LP - learnpath::__construct() - Selecting item_views: ' . $sql, 0);
  283. }
  284. // Get the item status.
  285. $res2 = Database::query($sql);
  286. if (Database :: num_rows($res2) > 0) {
  287. // If this learnpath has already been used by this user, get his last attempt count and
  288. // the last item seen back into this object.
  289. //$max = 0;
  290. $row2 = Database :: fetch_array($res2);
  291. if ($this->debug > 2) {
  292. error_log('New LP - learnpath::__construct() - Got item_view: ' . print_r($row2, true), 0);
  293. }
  294. if (is_object($this->items[$row['id']])) {
  295. $this->items[$row['id']]->set_status($row2['status']);
  296. if (empty ($row2['status'])) {
  297. $this->items[$row['id']]->set_status($this->default_status);
  298. }
  299. }
  300. //$this->attempt = $row['view_count'];
  301. //$this->last_item = $row['id'];
  302. } else { // No item has been found in lp_item_view for this view.
  303. // The first attempt of this user. Set attempt to 1 and last_item to 0 (first item available).
  304. // TODO: If the learnpath has not got attempts activated, always use attempt '1'.
  305. //$this->attempt = 1;
  306. //$this->last_item = 0;
  307. if (is_object($this->items[$row['id']])) {
  308. $this->items[$row['id']]->set_status($this->default_status);
  309. }
  310. // Add that row to the lp_item_view table so that we have something to show in the stats page.
  311. $sql_ins = "INSERT INTO $lp_item_view_table " .
  312. "(lp_item_id, lp_view_id, view_count, status) VALUES " .
  313. "(" . $row['id'] . "," . $this->lp_view_id . ",1,'not attempted')";
  314. if ($this->debug > 2) {
  315. error_log('New LP - learnpath::__construct() ' . __LINE__ . ' - Inserting blank item_view : ' . $sql_ins, 0);
  316. }
  317. $res_ins = Database::query($sql_ins);
  318. }
  319. // Setting the view in the item object.
  320. if (is_object($this->items[$row['id']])) {
  321. $this->items[$row['id']]->set_lp_view($this->lp_view_id, $course_db);
  322. }
  323. }
  324. $this->ordered_items = $this->get_flat_ordered_items_list($this->get_id(), 0, $course_db);
  325. $this->max_ordered_items = 0;
  326. foreach ($this->ordered_items as $index => $dummy) {
  327. if ($index > $this->max_ordered_items && !empty($dummy)) {
  328. $this->max_ordered_items = $index;
  329. }
  330. }
  331. // TODO: Define the current item better.
  332. $this->first();
  333. if ($this->debug > 2) {
  334. error_log('New LP - learnpath::__construct() ' . __LINE__ . ' - End of learnpath constructor for learnpath ' . $this->get_id(), 0);
  335. }
  336. }
  337. /**
  338. * Function rewritten based on old_add_item() from Yannick Warnier. Due the fact that users can decide where the item should come, I had to overlook this function and
  339. * I found it better to rewrite it. Old function is still available. Added also the possibility to add a description.
  340. *
  341. * @param int $parent
  342. * @param int $previous
  343. * @param string $type
  344. * @param int resource ID (ref)
  345. * @param string $title
  346. * @param string $description
  347. * @return int
  348. */
  349. public function add_item($parent, $previous, $type = 'dokeos_chapter', $id, $title, $description, $prerequisites = 0, $max_time_allowed = 0) {
  350. if ($this->debug > 0) {
  351. error_log('New LP - In learnpath::add_item(' . $parent . ',' . $previous . ',' . $type . ',' . $id . ',' . $title . ')', 0);
  352. }
  353. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  354. $parent = intval($parent);
  355. $previous = intval($previous);
  356. $type = $this->escape_string($type);
  357. $id = intval($id);
  358. $max_time_allowed = $this->escape_string(htmlentities($max_time_allowed));
  359. if (empty ($max_time_allowed)) {
  360. $max_time_allowed = 0;
  361. }
  362. $title = $this->escape_string($title);
  363. $description = $this->escape_string($description);
  364. $sql_count = " SELECT COUNT(id) AS num
  365. FROM " . $tbl_lp_item . "
  366. WHERE lp_id = " . $this->get_id() . " AND parent_item_id = " . $parent;
  367. $res_count = Database::query($sql_count);
  368. $row = Database :: fetch_array($res_count);
  369. $num = $row['num'];
  370. if ($num > 0) {
  371. if ($previous == 0) {
  372. $sql = "SELECT id, next_item_id, display_order
  373. FROM " . $tbl_lp_item . "
  374. WHERE
  375. lp_id = " . $this->get_id() . " AND
  376. parent_item_id = " . $parent . " AND
  377. previous_item_id = 0 OR previous_item_id=" . $parent;
  378. $result = Database::query($sql);
  379. $row = Database :: fetch_array($result);
  380. $tmp_previous = 0;
  381. $next = $row['id'];
  382. $display_order = 0;
  383. } else {
  384. $previous = (int) $previous;
  385. $sql = "
  386. SELECT
  387. id,
  388. previous_item_id,
  389. next_item_id,
  390. display_order
  391. FROM " . $tbl_lp_item . "
  392. WHERE
  393. lp_id = " . $this->get_id() . " AND
  394. id = " . $previous;
  395. $result = Database::query($sql);
  396. $row = Database :: fetch_array($result);
  397. $tmp_previous = $row['id'];
  398. $next = $row['next_item_id'];
  399. $display_order = $row['display_order'];
  400. }
  401. } else {
  402. $tmp_previous = 0;
  403. $next = 0;
  404. $display_order = 0;
  405. }
  406. $new_item_id = -1;
  407. $id = $this->escape_string($id);
  408. if ($type == 'quiz') {
  409. $sql = 'SELECT SUM(ponderation)
  410. FROM ' . Database :: get_course_table(TABLE_QUIZ_QUESTION) . ' as quiz_question
  411. INNER JOIN ' . Database :: get_course_table(TABLE_QUIZ_TEST_QUESTION) . ' as quiz_rel_question
  412. ON quiz_question.id = quiz_rel_question.question_id
  413. AND quiz_rel_question.exercice_id = ' . $id;
  414. $rsQuiz = Database::query($sql);
  415. $max_score = Database :: result($rsQuiz, 0, 0);
  416. } else {
  417. $max_score = 100;
  418. }
  419. if ($prerequisites != 0) {
  420. $sql_ins = "
  421. INSERT INTO " . $tbl_lp_item . " ( ".
  422. "lp_id, ".
  423. "item_type, ".
  424. "ref, ".
  425. "title, ".
  426. "description, ".
  427. "path, ".
  428. "max_score, ".
  429. "parent_item_id, ".
  430. "previous_item_id, ".
  431. "next_item_id, ".
  432. "display_order, ".
  433. "prerequisite, ".
  434. "max_time_allowed ".
  435. ") VALUES ( ".
  436. $this->get_id() . ", ".
  437. "'" . $type . "', ".
  438. "'', ".
  439. "'" . $title . "', ".
  440. "'" . $description . "', ".
  441. "'" . $id . "', ".
  442. "'" . $max_score . "', ".
  443. $parent . ", ".
  444. $previous . ", ".
  445. $next . ", ".
  446. ($display_order +1) . ", ".
  447. $prerequisites . ", ".
  448. $max_time_allowed .
  449. ")";
  450. } else {
  451. // Insert new item.
  452. $sql_ins = "
  453. INSERT INTO " . $tbl_lp_item . " ( ".
  454. "lp_id, ".
  455. "item_type, ".
  456. "ref, ".
  457. "title, ".
  458. "description, ".
  459. "path, ".
  460. "max_score, ".
  461. "parent_item_id, ".
  462. "previous_item_id, ".
  463. "next_item_id, ".
  464. "display_order, ".
  465. "max_time_allowed ".
  466. ") VALUES (".
  467. $this->get_id() . ",".
  468. "'" . $type . "',".
  469. "'',".
  470. "'" . $title . "',".
  471. "'" . $description . "',".
  472. "'" . $id . "',".
  473. "'" . $max_score . "',".
  474. $parent . ",".
  475. $previous . ",".
  476. $next . ",".
  477. ($display_order +1) . ",".
  478. $max_time_allowed .
  479. ")";
  480. }
  481. if ($this->debug > 2) {
  482. error_log('New LP - Inserting dokeos_chapter: ' . $sql_ins, 0);
  483. }
  484. $res_ins = Database::query($sql_ins);
  485. if ($res_ins > 0) {
  486. $new_item_id = Database :: insert_id($res_ins);
  487. // Update the item that should come after the new item.
  488. $sql_update_next = "
  489. UPDATE " . $tbl_lp_item . "
  490. SET previous_item_id = " . $new_item_id . "
  491. WHERE id = " . $next;
  492. $res_update_next = Database::query($sql_update_next);
  493. // Update the item that should be before the new item.
  494. $sql_update_previous = "
  495. UPDATE " . $tbl_lp_item . "
  496. SET next_item_id = " . $new_item_id . "
  497. WHERE id = " . $tmp_previous;
  498. $res_update_previous = Database::query($sql_update_previous);
  499. // Update all the items after the new item.
  500. $sql_update_order = "
  501. UPDATE " . $tbl_lp_item . "
  502. SET display_order = display_order + 1
  503. WHERE
  504. lp_id = " . $this->get_id() . " AND
  505. id <> " . $new_item_id . " AND
  506. parent_item_id = " . $parent . " AND
  507. display_order > " . $display_order;
  508. $res_update_previous = Database::query($sql_update_order);
  509. // Update the item that should come after the new item.
  510. $sql_update_ref = "
  511. UPDATE " . $tbl_lp_item . "
  512. SET ref = " . $new_item_id . "
  513. WHERE id = " . $new_item_id;
  514. Database::query($sql_update_ref);
  515. }
  516. // Upload audio.
  517. if (!empty ($_FILES['mp3']['name'])) {
  518. // Create the audio folder if it does not exist yet.
  519. global $_course;
  520. $filepath = api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document/';
  521. if (!is_dir($filepath . 'audio')) {
  522. mkdir($filepath . 'audio', api_get_permissions_for_new_directories());
  523. $audio_id = add_document($_course, '/audio', 'folder', 0, 'audio');
  524. api_item_property_update($_course, TOOL_DOCUMENT, $audio_id, 'FolderCreated', api_get_user_id(), null, null, null, null, api_get_session_id());
  525. }
  526. // Upload the file in the documents tool.
  527. include_once api_get_path(LIBRARY_PATH).'fileUpload.lib.php';
  528. $file_path = handle_uploaded_document($_course, $_FILES['mp3'], api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document', '/audio', api_get_user_id(), '', '', '', '', '', false);
  529. // Getting the filename only.
  530. $file_components = explode('/', $file_path);
  531. $file = $file_components[count($file_components) - 1];
  532. // Store the mp3 file in the lp_item table.
  533. $sql_insert_audio = "UPDATE $tbl_lp_item SET audio = '" . Database :: escape_string($file) . "' WHERE id = '" . Database :: escape_string($new_item_id) . "'";
  534. Database::query($sql_insert_audio);
  535. }
  536. return $new_item_id;
  537. }
  538. /**
  539. * Static admin function allowing addition of a learnpath to a course.
  540. * @param string Course code
  541. * @param string Learnpath name
  542. * @param string Learnpath description string, if provided
  543. * @param string Type of learnpath (default = 'guess', others = 'dokeos', 'aicc',...)
  544. * @param string Type of files origin (default = 'zip', others = 'dir','web_dir',...)
  545. * @param string Zip file containing the learnpath or directory containing the learnpath
  546. * @return integer The new learnpath ID on success, 0 on failure
  547. */
  548. public function add_lp($course, $name, $description = '', $learnpath = 'guess', $origin = 'zip', $zipname = '', $publicated_on = '', $expired_on = '') {
  549. global $charset;
  550. //if ($this->debug > 0) { error_log('New LP - In learnpath::add_lp()', 0); }
  551. $tbl_lp = Database :: get_course_table(TABLE_LP_MAIN);
  552. // Check course code exists.
  553. // Check lp_name doesn't exist, otherwise append something.
  554. $i = 0;
  555. $name = learnpath :: escape_string($name);
  556. // Session id.
  557. $session_id = api_get_session_id();
  558. $check_name = "SELECT * FROM $tbl_lp WHERE name = '$name'";
  559. //if ($this->debug > 2) { error_log('New LP - Checking the name for new LP: '.$check_name, 0); }
  560. $res_name = Database::query($check_name);
  561. if ($publicated_on == '0000-00-00 00:00:00' || empty($publicated_on)) {
  562. //by default the publication date is the same that the creation date
  563. $publicated_on = api_get_utc_datetime();
  564. } else {
  565. $publicated_on = Database::escape_string(api_get_utc_datetime($publicated_on));
  566. }
  567. if ($expired_on == '0000-00-00 00:00:00' || empty($expired_on)) {
  568. $expired_on = '';
  569. } else {
  570. $expired_on = Database::escape_string(api_get_utc_datetime($expired_on));
  571. }
  572. while (Database :: num_rows($res_name)) {
  573. // There is already one such name, update the current one a bit.
  574. $i++;
  575. $name = $name . ' - ' . $i;
  576. $check_name = "SELECT * FROM $tbl_lp WHERE name = '$name'";
  577. //if ($this->debug > 2) { error_log('New LP - Checking the name for new LP: '.$check_name, 0); }
  578. $res_name = Database::query($check_name);
  579. }
  580. // New name does not exist yet; keep it.
  581. // Escape description.
  582. $description = learnpath :: escape_string(api_htmlentities($description, ENT_QUOTES, $charset)); // Kevin: added htmlentities().
  583. $type = 1;
  584. switch ($learnpath) {
  585. case 'guess':
  586. break;
  587. case 'dokeos':
  588. case 'chamilo':
  589. $type = 1;
  590. break;
  591. case 'aicc':
  592. break;
  593. }
  594. switch ($origin) {
  595. case 'zip':
  596. // Check zipname string. If empty, we are currently creating a new Chamilo learnpath.
  597. break;
  598. case 'manual':
  599. default:
  600. $get_max = "SELECT MAX(display_order) FROM $tbl_lp";
  601. $res_max = Database::query($get_max);
  602. if (Database :: num_rows($res_max) < 1) {
  603. $dsp = 1;
  604. } else {
  605. $row = Database :: fetch_array($res_max);
  606. $dsp = $row[0] + 1;
  607. }
  608. $sql_insert = "INSERT INTO $tbl_lp (lp_type,name,description,path,default_view_mod, default_encoding,display_order,content_maker,content_local,js_lib,session_id, created_on, publicated_on, expired_on) " .
  609. "VALUES ($type,'$name','$description','','embedded','UTF-8','$dsp','Chamilo','local','','".$session_id."', '".api_get_utc_datetime()."' , '".$publicated_on."' , '".$expired_on."')";
  610. //if ($this->debug > 2) { error_log('New LP - Inserting new lp '.$sql_insert, 0); }
  611. $res_insert = Database::query($sql_insert);
  612. $id = Database :: insert_id();
  613. if ($id > 0) {
  614. // Insert into item_property.
  615. api_item_property_update(api_get_course_info(), TOOL_LEARNPATH, $id, 'LearnpathAdded', api_get_user_id());
  616. return $id;
  617. }
  618. break;
  619. }
  620. }
  621. /**
  622. * Appends a message to the message attribute
  623. * @param string Message to append.
  624. */
  625. public function append_message($string) {
  626. if ($this->debug > 0) {
  627. error_log('New LP - In learnpath::append_message()', 0);
  628. }
  629. $this->message .= $string;
  630. }
  631. /**
  632. * Autocompletes the parents of an item in case it's been completed or passed
  633. * @param integer Optional ID of the item from which to look for parents
  634. */
  635. public function autocomplete_parents($item) {
  636. if ($this->debug > 0) {
  637. error_log('New LP - In learnpath::autocomplete_parents()', 0);
  638. }
  639. if (empty ($item)) {
  640. $item = $this->current;
  641. }
  642. $parent_id = $this->items[$item]->get_parent();
  643. if ($this->debug > 2) {
  644. error_log('New LP - autocompleting parent of item ' . $item . ' (item ' . $parent_id . ')', 0);
  645. }
  646. if (is_object($this->items[$item]) and !empty ($parent_id)) {
  647. // if $item points to an object and there is a parent.
  648. if ($this->debug > 2) {
  649. error_log('New LP - ' . $item . ' is an item, proceed', 0);
  650. }
  651. $current_item = & $this->items[$item];
  652. $parent = & $this->items[$parent_id]; // Get the parent.
  653. // New experiment including failed and browsed in completed status.
  654. $current_status = $current_item->get_status();
  655. if ($current_item->is_done() || $current_status == 'browsed' || $current_status == 'failed') {
  656. // If the current item is completed or passes or succeeded.
  657. $completed = true;
  658. if ($this->debug > 2) {
  659. error_log('New LP - Status of current item is alright', 0);
  660. }
  661. foreach ($parent->get_children() as $child) {
  662. // Check all his brothers (his parent's children) for completion status.
  663. if ($child != $item) {
  664. if ($this->debug > 2) {
  665. error_log('New LP - Looking at brother with ID ' . $child . ', status is ' . $this->items[$child]->get_status(), 0);
  666. }
  667. //if($this->items[$child]->status_is(array('completed','passed','succeeded')))
  668. // Trying completing parents of failed and browsed items as well.
  669. if ($this->items[$child]->status_is(array (
  670. 'completed',
  671. 'passed',
  672. 'succeeded',
  673. 'browsed',
  674. 'failed'
  675. ))) {
  676. // Keep completion status to true.
  677. } else {
  678. if ($this->debug > 2) {
  679. error_log('New LP - Found one incomplete child of ' . $parent_id . ': ' . $child . ' is ' . $this->items[$child]->get_status(), 0);
  680. }
  681. $completed = false;
  682. }
  683. }
  684. }
  685. if ($completed) { // If all the children were completed:
  686. $parent->set_status('completed');
  687. $parent->save(false, $this->prerequisites_match($parent->get_id()));
  688. $this->update_queue[$parent->get_id()] = $parent->get_status();
  689. if ($this->debug > 2) {
  690. error_log('New LP - Added parent to update queue ' . print_r($this->update_queue, true), 0);
  691. }
  692. $this->autocomplete_parents($parent->get_id()); // Recursive call.
  693. }
  694. } else {
  695. //error_log('New LP - status of current item is not enough to get bothered with it', 0);
  696. }
  697. }
  698. }
  699. /**
  700. * Autosaves the current results into the database for the whole learnpath
  701. */
  702. public function autosave() {
  703. if ($this->debug > 0) {
  704. error_log('New LP - In learnpath::autosave()', 0);
  705. }
  706. // TODO: Add save operations for the learnpath itself.
  707. }
  708. /**
  709. * Clears the message attribute
  710. */
  711. public function clear_message() {
  712. if ($this->debug > 0) {
  713. error_log('New LP - In learnpath::clear_message()', 0);
  714. }
  715. $this->message = '';
  716. }
  717. /**
  718. * Closes the current resource
  719. *
  720. * Stops the timer
  721. * Saves into the database if required
  722. * Clears the current resource data from this object
  723. * @return boolean True on success, false on failure
  724. */
  725. public function close() {
  726. if ($this->debug > 0) {
  727. error_log('New LP - In learnpath::close()', 0);
  728. }
  729. if (empty ($this->lp_id)) {
  730. $this->error = 'Trying to close this learnpath but no ID is set';
  731. return false;
  732. }
  733. $this->current_time_stop = time();
  734. if ($this->save) {
  735. $learnpath_view_table = Database :: get_course_table(TABLE_LP_VIEW);
  736. /*
  737. $sql = "UPDATE $learnpath_view_table " .
  738. "SET " .
  739. "stop_time = ".$this->current_time_stop.", " .
  740. "score = ".$this->current_score.", ".
  741. "WHERE learnpath_id = '".$this->lp_id."'";
  742. //$res = Database::query($sql);
  743. $res = Database::query($res);
  744. if (Database::affected_rows($res) < 1) {
  745. $this->error = 'Could not update learnpath_view table while closing learnpath';
  746. return false;
  747. }
  748. */
  749. }
  750. $this->ordered_items = array ();
  751. $this->index = 0;
  752. unset ($this->lp_id);
  753. //unset other stuff
  754. return true;
  755. }
  756. /**
  757. * Static admin function allowing removal of a learnpath
  758. * @param string Course code
  759. * @param integer Learnpath ID
  760. * @param string Whether to delete data or keep it (default: 'keep', others: 'remove')
  761. * @return boolean True on success, false on failure (might change that to return number of elements deleted)
  762. */
  763. public function delete($course = null, $id = null, $delete = 'keep') {
  764. // TODO: Implement a way of getting this to work when the current object is not set.
  765. // In clear: implement this in the item class as well (abstract class) and use the given ID in queries.
  766. //if (empty($course)) { $course = api_get_course_id(); }
  767. //if (empty($id)) { $id = $this->get_id(); }
  768. // If an ID is specifically given and the current LP is not the same, prevent delete.
  769. if (!empty ($id) && ($id != $this->lp_id)) {
  770. return false;
  771. }
  772. $lp = Database :: get_course_table(TABLE_LP_MAIN);
  773. $lp_item = Database :: get_course_table(TABLE_LP_ITEM); // Proposed by Christophe (clefevre), see below.
  774. $lp_view = Database :: get_course_table(TABLE_LP_VIEW);
  775. $lp_item_view = Database :: get_course_table(TABLE_LP_ITEM_VIEW);
  776. //if ($this->debug > 0) { error_log('New LP - In learnpath::delete()', 0); }
  777. // Delete lp item id.
  778. foreach ($this->items as $id => $dummy) {
  779. //$this->items[$id]->delete();
  780. $sql_del_view = "DELETE FROM $lp_item_view WHERE lp_item_id = '" . $id . "'";
  781. $res_del_item_view = Database::query($sql_del_view);
  782. }
  783. // Proposed by Christophe (nickname: clefevre), see http://www.dokeos.com/forum/viewtopic.php?t=29673
  784. $sql_del_item = "DELETE FROM $lp_item WHERE lp_id = " . $this->lp_id;
  785. $res_del_item = Database::query($sql_del_item);
  786. $sql_del_view = "DELETE FROM $lp_view WHERE lp_id = " . $this->lp_id;
  787. //if ($this->debug > 2) { error_log('New LP - Deleting views bound to lp '.$this->lp_id.': '.$sql_del_view, 0); }
  788. $res_del_view = Database::query($sql_del_view);
  789. $this->toggle_publish($this->lp_id, 'i');
  790. //if ($this->debug > 2) { error_log('New LP - Deleting lp '.$this->lp_id.' of type '.$this->type, 0); }
  791. if ($this->type == 2 || $this->type == 3) {
  792. // This is a scorm learning path, delete the files as well.
  793. $sql = "SELECT path FROM $lp WHERE id = " . $this->lp_id;
  794. $res = Database::query($sql);
  795. if (Database :: num_rows($res) > 0) {
  796. $row = Database :: fetch_array($res);
  797. $path = $row['path'];
  798. $sql = "SELECT id FROM $lp WHERE path = '$path' AND id != " . $this->lp_id;
  799. $res = Database::query($sql);
  800. if (Database :: num_rows($res) > 0) { // Another learning path uses this directory, so don't delete it.
  801. if ($this->debug > 2) {
  802. error_log('New LP - In learnpath::delete(), found other LP using path ' . $path . ', keeping directory', 0);
  803. }
  804. } else {
  805. // No other LP uses that directory, delete it.
  806. $course_rel_dir = api_get_course_path() . '/scorm/'; // scorm dir web path starting from /courses
  807. $course_scorm_dir = api_get_path(SYS_COURSE_PATH) . $course_rel_dir; // The absolute system path for this course.
  808. if ($delete == 'remove' && is_dir($course_scorm_dir . $path) and !empty ($course_scorm_dir)) {
  809. if ($this->debug > 2) {
  810. error_log('New LP - In learnpath::delete(), found SCORM, deleting directory: ' . $course_scorm_dir . $path, 0);
  811. }
  812. // Proposed by Christophe (clefevre).
  813. if (strcmp(substr($path, -2), "/.") == 0) {
  814. $path = substr($path, 0, -1); // Remove "." at the end.
  815. }
  816. //exec('rm -rf ' . $course_scorm_dir . $path); // See Bug #5208, this is not OS-portable way.
  817. rmdirr($course_scorm_dir . $path);
  818. }
  819. }
  820. }
  821. }
  822. $sql_del_lp = "DELETE FROM $lp WHERE id = " . $this->lp_id;
  823. //if ($this->debug > 2) { error_log('New LP - Deleting lp '.$this->lp_id.': '.$sql_del_lp, 0); }
  824. $res_del_lp = Database::query($sql_del_lp);
  825. $this->update_display_order(); // Updates the display order of all lps.
  826. api_item_property_update(api_get_course_info(), TOOL_LEARNPATH, $this->lp_id, 'delete', api_get_user_id());
  827. require_once '../gradebook/lib/be.inc.php';
  828. // Delete link of gradebook tool
  829. //$tbl_grade_link = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_LINK);
  830. /*$sql = 'SELECT gl.id FROM ' . $tbl_grade_link . ' gl WHERE gl.type="4" AND gl.ref_id="' . $id . '";';
  831. $result = Database::query($sql);
  832. $row = Database :: fetch_array($result, 'ASSOC');*/
  833. // Fixing gradebook link deleted see #5229.
  834. /*
  835. if (!empty($row['id'])) {
  836. $link = LinkFactory :: load($row['id']);
  837. if ($link[0] != null) {
  838. $link[0]->delete();
  839. }
  840. }*/
  841. require_once api_get_path(SYS_CODE_PATH).'gradebook/lib/gradebook_functions.inc.php';
  842. $link_id = is_resource_in_course_gradebook(api_get_course_id(), 4 , $id, api_get_session_id());
  843. if ($link_id !== false) {
  844. remove_resource_from_course_gradebook($link_id);
  845. }
  846. if (api_get_setting('search_enabled') == 'true') {
  847. require_once api_get_path(LIBRARY_PATH).'specific_fields_manager.lib.php';
  848. $r = delete_all_values_for_item($this->cc, TOOL_LEARNPATH, $this->lp_id);
  849. }
  850. }
  851. /**
  852. * Removes all the children of one item - dangerous!
  853. * @param integer Element ID of which children have to be removed
  854. * @return integer Total number of children removed
  855. */
  856. public function delete_children_items($id) {
  857. if ($this->debug > 0) {
  858. error_log('New LP - In learnpath::delete_children_items(' . $id . ')', 0);
  859. }
  860. $num = 0;
  861. if (empty ($id) || $id != strval(intval($id))) {
  862. return false;
  863. }
  864. $lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  865. $sql = "SELECT * FROM $lp_item WHERE parent_item_id = $id";
  866. $res = Database::query($sql);
  867. while ($row = Database :: fetch_array($res)) {
  868. $num += $this->delete_children_items($row['id']);
  869. $sql_del = "DELETE FROM $lp_item WHERE id = " . $row['id'];
  870. $res_del = Database::query($sql_del);
  871. $num++;
  872. }
  873. return $num;
  874. }
  875. /**
  876. * Removes an item from the current learnpath
  877. * @param integer Elem ID (0 if first)
  878. * @param integer Whether to remove the resource/data from the system or leave it (default: 'keep', others 'remove')
  879. * @return integer Number of elements moved
  880. * @todo implement resource removal
  881. */
  882. public function delete_item($id, $remove = 'keep') {
  883. if ($this->debug > 0) {
  884. error_log('New LP - In learnpath::delete_item()', 0);
  885. }
  886. // TODO: Implement the resource removal.
  887. if (empty ($id) || $id != strval(intval($id))) {
  888. return false;
  889. }
  890. // First select item to get previous, next, and display order.
  891. $lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  892. $sql_sel = "SELECT * FROM $lp_item WHERE id = $id";
  893. $res_sel = Database::query($sql_sel);
  894. if (Database :: num_rows($res_sel) < 1) {
  895. return false;
  896. }
  897. $row = Database :: fetch_array($res_sel);
  898. $previous = $row['previous_item_id'];
  899. $next = $row['next_item_id'];
  900. $display = $row['display_order'];
  901. $parent = $row['parent_item_id'];
  902. $lp = $row['lp_id'];
  903. // Delete children items.
  904. $num = $this->delete_children_items($id);
  905. if ($this->debug > 2) {
  906. error_log('New LP - learnpath::delete_item() - deleted ' . $num . ' children of element ' . $id, 0);
  907. }
  908. // Now delete the item.
  909. $sql_del = "DELETE FROM $lp_item WHERE id = $id";
  910. if ($this->debug > 2) {
  911. error_log('New LP - Deleting item: ' . $sql_del, 0);
  912. }
  913. $res_del = Database::query($sql_del);
  914. // Now update surrounding items.
  915. $sql_upd = "UPDATE $lp_item SET next_item_id = $next WHERE id = $previous";
  916. $res_upd = Database::query($sql_upd);
  917. $sql_upd = "UPDATE $lp_item SET previous_item_id = $previous WHERE id = $next";
  918. $res_upd = Database::query($sql_upd);
  919. // Now update all following items with new display order.
  920. $sql_all = "UPDATE $lp_item SET display_order = display_order-1 WHERE lp_id = $lp AND parent_item_id = $parent AND display_order > $display";
  921. $res_all = Database::query($sql_all);
  922. //Removing prerequisites since the item will not longer exist
  923. $sql_all = "UPDATE $lp_item SET prerequisite = '' WHERE prerequisite = $id";
  924. $res_all = Database::query($sql_all);
  925. // Remove from search engine if enabled.
  926. if (api_get_setting('search_enabled') == 'true') {
  927. $tbl_se_ref = Database :: get_main_table(TABLE_MAIN_SEARCH_ENGINE_REF);
  928. $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';
  929. $sql = sprintf($sql, $tbl_se_ref, $this->cc, TOOL_LEARNPATH, $lp, $id);
  930. $res = Database::query($sql);
  931. if (Database :: num_rows($res) > 0) {
  932. $row2 = Database :: fetch_array($res);
  933. require_once api_get_path(LIBRARY_PATH).'search/DokeosIndexer.class.php';
  934. $di = new DokeosIndexer();
  935. $di->remove_document((int) $row2['search_did']);
  936. }
  937. $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';
  938. $sql = sprintf($sql, $tbl_se_ref, $this->cc, TOOL_LEARNPATH, $lp, $id);
  939. Database::query($sql);
  940. }
  941. }
  942. /**
  943. * Updates an item's content in place
  944. * @param integer Element ID
  945. * @param integer Parent item ID
  946. * @param integer Previous item ID
  947. * @param string Item title
  948. * @param string Item description
  949. * @param string Prerequisites (optional)
  950. * @param string Indexing terms (optional)
  951. * @param array The array resulting of the $_FILES[mp3] element
  952. * @return boolean True on success, false on error
  953. */
  954. public function edit_item($id, $parent, $previous, $title, $description, $prerequisites = 0, $audio = null, $max_time_allowed = 0) {
  955. if ($this->debug > 0) {
  956. error_log('New LP - In learnpath::edit_item()', 0);
  957. }
  958. if (empty ($max_time_allowed)) {
  959. $max_time_allowed = 0;
  960. }
  961. if (empty ($id) || ($id != strval(intval($id))) || empty ($title)) {
  962. return false;
  963. }
  964. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  965. $sql_select = "SELECT * FROM " . $tbl_lp_item . " WHERE id = " . $id;
  966. $res_select = Database::query($sql_select);
  967. $row_select = Database :: fetch_array($res_select);
  968. $audio_update_sql = '';
  969. if (is_array($audio) && !empty ($audio['tmp_name']) && $audio['error'] === 0) {
  970. // Create the audio folder if it does not exist yet.
  971. global $_course;
  972. $filepath = api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document/';
  973. if (!is_dir($filepath . 'audio')) {
  974. mkdir($filepath . 'audio', api_get_permissions_for_new_directories());
  975. $audio_id = add_document($_course, '/audio', 'folder', 0, 'audio');
  976. api_item_property_update($_course, TOOL_DOCUMENT, $audio_id, 'FolderCreated', api_get_user_id(), null, null, null, null, api_get_session_id());
  977. }
  978. // Upload file in documents.
  979. $pi = pathinfo($audio['name']);
  980. if ($pi['extension'] == 'mp3') {
  981. $c_det = api_get_course_info($this->cc);
  982. $bp = api_get_path(SYS_COURSE_PATH) . $c_det['path'] . '/document';
  983. $path = handle_uploaded_document($c_det, $audio, $bp, '/audio', api_get_user_id(), 0, null, '', 0, 'rename', false, 0);
  984. $path = substr($path, 7);
  985. // Update reference in lp_item - audio path is the path from inside de document/audio/ dir.
  986. $audio_update_sql = ", audio = '" . Database :: escape_string($path) . "' ";
  987. }
  988. }
  989. $same_parent = ($row_select['parent_item_id'] == $parent) ? true : false;
  990. $same_previous = ($row_select['previous_item_id'] == $previous) ? true : false;
  991. // TODO: htmlspecialchars to be checked for encoding related problems.
  992. if ($same_parent && $same_previous) {
  993. // Only update title and description.
  994. $sql_update = " UPDATE " . $tbl_lp_item . "
  995. SET title = '" . $this->escape_string($title) . "',
  996. prerequisite = '" . $prerequisites . "',
  997. description = '" . $this->escape_string($description) . "'
  998. " . $audio_update_sql . ",
  999. max_time_allowed = '" . $this->escape_string($max_time_allowed) . "'
  1000. WHERE id = " . $id;
  1001. $res_update = Database::query($sql_update);
  1002. } else {
  1003. $old_parent = $row_select['parent_item_id'];
  1004. $old_previous = $row_select['previous_item_id'];
  1005. $old_next = $row_select['next_item_id'];
  1006. $old_order = $row_select['display_order'];
  1007. $old_prerequisite = $row_select['prerequisite'];
  1008. $old_max_time_allowed = $row_select['max_time_allowed'];
  1009. /* BEGIN -- virtually remove the current item id */
  1010. /* for the next and previous item it is like the current item doesn't exist anymore */
  1011. if ($old_previous != 0) {
  1012. $sql_update_next = "
  1013. UPDATE " . $tbl_lp_item . "
  1014. SET next_item_id = " . $old_next . "
  1015. WHERE id = " . $old_previous;
  1016. $res_update_next = Database::query($sql_update_next);
  1017. //echo '<p>' . $sql_update_next . '</p>';
  1018. }
  1019. if ($old_next != 0) {
  1020. $sql_update_previous = "
  1021. UPDATE " . $tbl_lp_item . "
  1022. SET previous_item_id = " . $old_previous . "
  1023. WHERE id = " . $old_next;
  1024. $res_update_previous = Database::query($sql_update_previous);
  1025. //echo '<p>' . $sql_update_previous . '</p>';
  1026. }
  1027. // display_order - 1 for every item with a display_order bigger then the display_order of the current item.
  1028. $sql_update_order = "
  1029. UPDATE " . $tbl_lp_item . "
  1030. SET display_order = display_order - 1
  1031. WHERE
  1032. display_order > " . $old_order . " AND lp_id = " . $this->lp_id . " AND
  1033. parent_item_id = " . $old_parent;
  1034. $res_update_order = Database::query($sql_update_order);
  1035. //echo '<p>' . $sql_update_order . '</p>';
  1036. /* END -- virtually remove the current item id */
  1037. /* BEGIN -- update the current item id to his new location */
  1038. if ($previous == 0) {
  1039. // Select the data of the item that should come after the current item.
  1040. $sql_select_old = "
  1041. SELECT
  1042. id,
  1043. display_order
  1044. FROM " . $tbl_lp_item . "
  1045. WHERE
  1046. lp_id = " . $this->lp_id . " AND
  1047. parent_item_id = " . $parent . " AND
  1048. previous_item_id = " . $previous;
  1049. $res_select_old = Database::query($sql_select_old);
  1050. $row_select_old = Database :: fetch_array($res_select_old);
  1051. //echo '<p>' . $sql_select_old . '</p>';
  1052. // If the new parent didn't have children before.
  1053. if (Database :: num_rows($res_select_old) == 0) {
  1054. $new_next = 0;
  1055. $new_order = 1;
  1056. } else {
  1057. $new_next = $row_select_old['id'];
  1058. $new_order = $row_select_old['display_order'];
  1059. }
  1060. //echo 'New next_item_id of current item: ' . $new_next . '<br />';
  1061. //echo 'New previous_item_id of current item: ' . $previous . '<br />';
  1062. //echo 'New display_order of current item: ' . $new_order . '<br />';
  1063. } else {
  1064. // Select the data of the item that should come before the current item.
  1065. $sql_select_old = "
  1066. SELECT
  1067. next_item_id,
  1068. display_order
  1069. FROM " . $tbl_lp_item . "
  1070. WHERE id = " . $previous;
  1071. $res_select_old = Database::query($sql_select_old);
  1072. $row_select_old = Database :: fetch_array($res_select_old);
  1073. //echo '<p>' . $sql_select_old . '</p>';
  1074. //echo 'New next_item_id of current item: ' . $row_select_old['next_item_id'] . '<br />';
  1075. //echo 'New previous_item_id of current item: ' . $previous . '<br />';
  1076. //echo 'New display_order of current item: ' . ($row_select_old['display_order'] + 1) . '<br />';
  1077. $new_next = $row_select_old['next_item_id'];
  1078. $new_order = $row_select_old['display_order'] + 1;
  1079. }
  1080. // TODO: htmlspecialchars to be checked for encoding related problems.
  1081. // Update the current item with the new data.
  1082. $sql_update = "
  1083. UPDATE " . $tbl_lp_item . "
  1084. SET
  1085. title = '" . $this->escape_string($title) . "',
  1086. description = '" . $this->escape_string($description) . "',
  1087. parent_item_id = " . $parent . ",
  1088. previous_item_id = " . $previous . ",
  1089. next_item_id = " . $new_next . ",
  1090. display_order = " . $new_order . "
  1091. " . $audio_update_sql . "
  1092. WHERE id = " . $id;
  1093. $res_update_next = Database::query($sql_update);
  1094. //echo '<p>' . $sql_update . '</p>';
  1095. if ($previous != 0) {
  1096. // Update the previous item's next_item_id.
  1097. $sql_update_previous = "
  1098. UPDATE " . $tbl_lp_item . "
  1099. SET next_item_id = " . $id . "
  1100. WHERE id = " . $previous;
  1101. $res_update_next = Database::query($sql_update_previous);
  1102. //echo '<p>' . $sql_update_previous . '</p>';
  1103. }
  1104. if ($new_next != 0) {
  1105. // Update the next item's previous_item_id.
  1106. $sql_update_next = "
  1107. UPDATE " . $tbl_lp_item . "
  1108. SET previous_item_id = " . $id . "
  1109. WHERE id = " . $new_next;
  1110. $res_update_next = Database::query($sql_update_next);
  1111. //echo '<p>' . $sql_update_next . '</p>';
  1112. }
  1113. if ($old_prerequisite != $prerequisites) {
  1114. $sql_update_next = "
  1115. UPDATE " . $tbl_lp_item . "
  1116. SET prerequisite = " . $prerequisites . "
  1117. WHERE id = " . $id;
  1118. $res_update_next = Database::query($sql_update_next);
  1119. }
  1120. if ($old_max_time_allowed != $max_time_allowed) {
  1121. $sql_update_max_time_allowed = "
  1122. UPDATE " . $tbl_lp_item . "
  1123. SET max_time_allowed = " . $max_time_allowed . "
  1124. WHERE id = " . $id;
  1125. $res_update_max_time_allowed = Database::query($sql_update_max_time_allowed);
  1126. }
  1127. // Update all the items with the same or a bigger display_order than the current item.
  1128. $sql_update_order = "
  1129. UPDATE " . $tbl_lp_item . "
  1130. SET display_order = display_order + 1
  1131. WHERE
  1132. lp_id = " . $this->get_id() . " AND
  1133. id <> " . $id . " AND
  1134. parent_item_id = " . $parent . " AND
  1135. display_order >= " . $new_order;
  1136. $res_update_next = Database::query($sql_update_order);
  1137. }
  1138. }
  1139. /**
  1140. * Updates an item's prereq in place
  1141. * @param integer Element ID
  1142. * @param string Prerequisite Element ID
  1143. * @param string Prerequisite item type
  1144. * @param string Prerequisite min score
  1145. * @param string Prerequisite max score
  1146. * @return boolean True on success, false on error
  1147. */
  1148. public function edit_item_prereq($id, $prerequisite_id, $mastery_score = 0, $max_score = 100) {
  1149. if ($this->debug > 0) {
  1150. error_log('New LP - In learnpath::edit_item_prereq(' . $id . ',' . $prerequisite_id . ',' . $mastery_score . ',' . $max_score . ')', 0);
  1151. }
  1152. if (empty ($id) or ($id != strval(intval($id))) or empty ($prerequisite_id)) {
  1153. return false;
  1154. }
  1155. $prerequisite_id = $this->escape_string($prerequisite_id);
  1156. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  1157. if (!is_numeric($mastery_score) || $mastery_score < 0)
  1158. $mastery_score = 0;
  1159. if (!is_numeric($max_score) || $max_score < 0)
  1160. $max_score = 100;
  1161. if ($mastery_score > $max_score)
  1162. $max_score = $mastery_score;
  1163. if (!is_numeric($prerequisite_id))
  1164. $prerequisite_id = 'NULL';
  1165. $sql_upd = " UPDATE " . $tbl_lp_item . "
  1166. SET prerequisite = " . $prerequisite_id . " WHERE id = " . $id;
  1167. $res_upd = Database::query($sql_upd);
  1168. if ($prerequisite_id != 'NULL' && $prerequisite_id != '') {
  1169. $sql_upd = " UPDATE " . $tbl_lp_item . " SET
  1170. mastery_score = " . $mastery_score .
  1171. //", max_score = " . $max_score . " " . // Max score cannot be changed in the form anyway - see display_item_prerequisites_form().
  1172. " WHERE ref = '" . $prerequisite_id . "'"; // Will this be enough to ensure unicity?
  1173. $res_upd = Database::query($sql_upd);
  1174. }
  1175. // TODO: Update the item object (can be ignored for now because refreshed).
  1176. return true;
  1177. }
  1178. /**
  1179. * Escapes a string with the available database escape function
  1180. * @param string String to escape
  1181. * @return string String escaped
  1182. */
  1183. public function escape_string($string) {
  1184. //if ($this->debug > 0) { error_log('New LP - In learnpath::escape_string('.$string.')', 0); }
  1185. return Database :: escape_string($string);
  1186. }
  1187. /**
  1188. * Static admin function exporting a learnpath into a zip file
  1189. * @param string Export type (scorm, zip, cd)
  1190. * @param string Course code
  1191. * @param integer Learnpath ID
  1192. * @param string Zip file name
  1193. * @return string Zip file path (or false on error)
  1194. */
  1195. public function export_lp($type, $course, $id, $zipname) {
  1196. //if ($this->debug > 0) { error_log('New LP - In learnpath::export_lp()', 0); }
  1197. if (empty($type) || empty($course) || empty($id) || empty($zipname)) {
  1198. return false;
  1199. }
  1200. $url = '';
  1201. switch ($type) {
  1202. case 'scorm':
  1203. break;
  1204. case 'zip':
  1205. break;
  1206. case 'cdrom':
  1207. break;
  1208. }
  1209. return $url;
  1210. }
  1211. /**
  1212. * Gets all the chapters belonging to the same parent as the item/chapter given
  1213. * Can also be called as abstract method
  1214. * @param integer Item ID
  1215. * @return array A list of all the "brother items" (or an empty array on failure)
  1216. */
  1217. public function get_brother_chapters($id) {
  1218. if ($this->debug > 0) {
  1219. error_log('New LP - In learnpath::get_brother_chapters()', 0);
  1220. }
  1221. if (empty ($id) OR $id != strval(intval($id))) {
  1222. return array ();
  1223. }
  1224. $lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  1225. $sql_parent = "SELECT * FROM $lp_item WHERE id = $id AND item_type='dokeos_chapter'";
  1226. $res_parent = Database::query($sql_parent);
  1227. if (Database :: num_rows($res_parent) > 0) {
  1228. $row_parent = Database :: fetch_array($res_parent);
  1229. $parent = $row_parent['parent_item_id'];
  1230. $sql_bros = "SELECT * FROM $lp_item WHERE parent_item_id = $parent AND id = $id AND item_type='dokeos_chapter' ORDER BY display_order";
  1231. $res_bros = Database::query($sql_bros);
  1232. $list = array ();
  1233. while ($row_bro = Database :: fetch_array($res_bros)) {
  1234. $list[] = $row_bro;
  1235. }
  1236. return $list;
  1237. }
  1238. return array ();
  1239. }
  1240. /**
  1241. * Gets all the items belonging to the same parent as the item given
  1242. * Can also be called as abstract method
  1243. * @param integer Item ID
  1244. * @return array A list of all the "brother items" (or an empty array on failure)
  1245. */
  1246. public function get_brother_items($id) {
  1247. if ($this->debug > 0) {
  1248. error_log('New LP - In learnpath::get_brother_items(' . $id . ')', 0);
  1249. }
  1250. if (empty ($id) OR $id != strval(intval($id))) {
  1251. return array ();
  1252. }
  1253. $lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  1254. $sql_parent = "SELECT * FROM $lp_item WHERE id = $id";
  1255. $res_parent = Database::query($sql_parent);
  1256. if (Database :: num_rows($res_parent) > 0) {
  1257. $row_parent = Database :: fetch_array($res_parent);
  1258. $parent = $row_parent['parent_item_id'];
  1259. $sql_bros = "SELECT * FROM $lp_item WHERE parent_item_id = $parent ORDER BY display_order";
  1260. $res_bros = Database::query($sql_bros);
  1261. $list = array ();
  1262. while ($row_bro = Database :: fetch_array($res_bros)) {
  1263. $list[] = $row_bro;
  1264. }
  1265. return $list;
  1266. }
  1267. return array ();
  1268. }
  1269. /**
  1270. * Get the specific prefix index terms of this learning path
  1271. * @return array Array of terms
  1272. */
  1273. public function get_common_index_terms_by_prefix($prefix) {
  1274. require_once api_get_path(LIBRARY_PATH).'specific_fields_manager.lib.php';
  1275. $terms = get_specific_field_values_list_by_prefix($prefix, $this->cc, TOOL_LEARNPATH, $this->lp_id);
  1276. $prefix_terms = array();
  1277. if (!empty($terms)) {
  1278. foreach ($terms as $term) {
  1279. $prefix_terms[] = $term['value'];
  1280. }
  1281. }
  1282. return $prefix_terms;
  1283. }
  1284. /**
  1285. * Gets the number of items currently completed
  1286. * @return integer The number of items currently completed
  1287. */
  1288. public function get_complete_items_count() {
  1289. if ($this->debug > 0) {
  1290. error_log('New LP - In learnpath::get_complete_items_count()', 0);
  1291. }
  1292. $i = 0;
  1293. foreach ($this->items as $id => $dummy) {
  1294. // Trying failed and browsed considered "progressed" as well.
  1295. if ($this->items[$id]->status_is(array (
  1296. 'completed',
  1297. 'passed',
  1298. 'succeeded',
  1299. 'browsed',
  1300. 'failed'
  1301. )) && $this->items[$id]->get_type() != 'dokeos_chapter' && $this->items[$id]->get_type() != 'dir') {
  1302. $i++;
  1303. }
  1304. }
  1305. return $i;
  1306. }
  1307. /**
  1308. * Gets the current item ID
  1309. * @return integer The current learnpath item id
  1310. */
  1311. public function get_current_item_id() {
  1312. $current = 0;
  1313. if ($this->debug > 0) {
  1314. error_log('New LP - In learnpath::get_current_item_id()', 0);
  1315. }
  1316. if (!empty ($this->current)) {
  1317. $current = $this->current;
  1318. }
  1319. if ($this->debug > 2) {
  1320. error_log('New LP - In learnpath::get_current_item_id() - Returning ' . $current, 0);
  1321. }
  1322. return $current;
  1323. }
  1324. /**
  1325. * Force to get the first learnpath item id
  1326. * @return integer The current learnpath item id
  1327. */
  1328. public function get_first_item_id() {
  1329. $current = 0;
  1330. if (is_array($this->ordered_items)) {
  1331. $current = $this->ordered_items[0];
  1332. }
  1333. return $current;
  1334. }
  1335. /**
  1336. * Gets the total number of items available for viewing in this SCORM
  1337. * @return integer The total number of items
  1338. */
  1339. public function get_total_items_count() {
  1340. if ($this->debug > 0) {
  1341. error_log('New LP - In learnpath::get_total_items_count()', 0);
  1342. }
  1343. return count($this->items);
  1344. }
  1345. /**
  1346. * Gets the total number of items available for viewing in this SCORM but without chapters
  1347. * @return integer The total no-chapters number of items
  1348. */
  1349. public function get_total_items_count_without_chapters() {
  1350. if ($this->debug > 0) {
  1351. error_log('New LP - In learnpath::get_total_items_count_without_chapters()', 0);
  1352. }
  1353. $total = 0;
  1354. foreach ($this->items as $temp => $temp2) {
  1355. if (!in_array($temp2->get_type(), array (
  1356. 'dokeos_chapter',
  1357. 'chapter',
  1358. 'dir'
  1359. )))
  1360. $total++;
  1361. }
  1362. return $total;
  1363. }
  1364. /**
  1365. * Gets the first element URL.
  1366. * @return string URL to load into the viewer
  1367. */
  1368. public function first() {
  1369. if ($this->debug > 0) {
  1370. error_log('New LP - In learnpath::first()', 0);
  1371. }
  1372. // Test if the last_item_seen exists and is not a dir.
  1373. if (count($this->ordered_items) == 0) {
  1374. $this->index = 0;
  1375. }
  1376. 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()) {
  1377. if ($this->debug > 2) {
  1378. 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);
  1379. }
  1380. $index = -1;
  1381. foreach ($this->ordered_items as $myindex => $item_id) {
  1382. if ($item_id == $this->last_item_seen) {
  1383. $index = $myindex;
  1384. break;
  1385. }
  1386. }
  1387. if ($index == -1) {
  1388. // Index hasn't changed, so item not found - panic (this shouldn't happen).
  1389. if ($this->debug > 2) {
  1390. error_log('New LP - Last item (' . $this->last_item_seen . ') was found in items but not in ordered_items, panic!', 0);
  1391. }
  1392. return false;
  1393. } else {
  1394. $this->last = $this->last_item_seen;
  1395. $this->current = $this->last_item_seen;
  1396. $this->index = $index;
  1397. }
  1398. } else {
  1399. if ($this->debug > 2) {
  1400. error_log('New LP - In learnpath::first() - No last item seen', 0);
  1401. }
  1402. $index = 0;
  1403. // Loop through all ordered items and stop at the first item that is
  1404. // not a directory *and* that has not been completed yet.
  1405. 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) {
  1406. $index++;
  1407. }
  1408. $this->last = $this->current;
  1409. // current is
  1410. $this->current = $this->ordered_items[$index];
  1411. $this->index = $index;
  1412. if ($this->debug > 2) {
  1413. error_log('New LP - In learnpath::first() - No last item seen. New last = ' . $this->last . '(' . $this->ordered_items[$index] . ')', 0);
  1414. }
  1415. }
  1416. if ($this->debug > 2) {
  1417. error_log('New LP - In learnpath::first() - First item is ' . $this->get_current_item_id());
  1418. }
  1419. }
  1420. /**
  1421. * Gets the information about an item in a format usable as JavaScript to update
  1422. * the JS API by just printing this content into the <head> section of the message frame
  1423. * @param integer Item ID
  1424. * @return string
  1425. */
  1426. public function get_js_info($item_id = '') {
  1427. if ($this->debug > 0) {
  1428. error_log('New LP - In learnpath::get_js_info(' . $item_id . ')', 0);
  1429. }
  1430. $info = '';
  1431. $item_id = $this->escape_string($item_id);
  1432. if (!empty($item_id) && is_object($this->items[$item_id])) {
  1433. //if item is defined, return values from DB
  1434. $oItem = $this->items[$item_id];
  1435. $info .= '<script language="javascript">';
  1436. $info .= "top.set_score(" . $oItem->get_score() . ");\n";
  1437. $info .= "top.set_max(" . $oItem->get_max() . ");\n";
  1438. $info .= "top.set_min(" . $oItem->get_min() . ");\n";
  1439. $info .= "top.set_lesson_status('" . $oItem->get_status() . "');";
  1440. $info .= "top.set_session_time('" . $oItem->get_scorm_time('js') . "');";
  1441. $info .= "top.set_suspend_data('" . $oItem->get_suspend_data() . "');";
  1442. $info .= "top.set_saved_lesson_status('" . $oItem->get_status() . "');";
  1443. $info .= "top.set_flag_synchronized();";
  1444. $info .= '</script>';
  1445. if ($this->debug > 2) {
  1446. error_log('New LP - in learnpath::get_js_info(' . $item_id . ') - returning: ' . $info, 0);
  1447. }
  1448. return $info;
  1449. } else {
  1450. // If item_id is empty, just update to default SCORM data.
  1451. $info .= '<script language="javascript">';
  1452. $info .= "top.set_score(" . learnpathItem :: get_score() . ");\n";
  1453. $info .= "top.set_max(" . learnpathItem :: get_max() . ");\n";
  1454. $info .= "top.set_min(" . learnpathItem :: get_min() . ");\n";
  1455. $info .= "top.set_lesson_status('" . learnpathItem :: get_status() . "');";
  1456. $info .= "top.set_session_time('" . learnpathItem :: get_scorm_time('js') . "');";
  1457. $info .= "top.set_suspend_data('" . learnpathItem :: get_suspend_data() . "');";
  1458. $info .= "top.set_saved_lesson_status('" . learnpathItem :: get_status() . "');";
  1459. $info .= "top.set_flag_synchronized();";
  1460. $info .= '</script>';
  1461. if ($this->debug > 2) {
  1462. error_log('New LP - in learnpath::get_js_info(' . $item_id . ') - returning: ' . $info, 0);
  1463. }
  1464. return $info;
  1465. }
  1466. }
  1467. /**
  1468. * Gets the js library from the database
  1469. * @return string The name of the javascript library to be used
  1470. */
  1471. public function get_js_lib() {
  1472. $lib = '';
  1473. if (!empty ($this->js_lib)) {
  1474. $lib = $this->js_lib;
  1475. }
  1476. return $lib;
  1477. }
  1478. /**
  1479. * Gets the learnpath database ID
  1480. * @return integer Learnpath ID in the lp table
  1481. */
  1482. public function get_id() {
  1483. //if ($this->debug > 0) { error_log('New LP - In learnpath::get_id()', 0); }
  1484. if (!empty ($this->lp_id)) {
  1485. return $this->lp_id;
  1486. } else {
  1487. return 0;
  1488. }
  1489. }
  1490. /**
  1491. * Gets the last element URL.
  1492. * @return string URL to load into the viewer
  1493. */
  1494. public function get_last() {
  1495. if ($this->debug > 0) {
  1496. error_log('New LP - In learnpath::get_last()', 0);
  1497. }
  1498. $this->index = count($this->ordered_items) - 1;
  1499. return $this->ordered_items[$this->index];
  1500. }
  1501. /**
  1502. * Gets the navigation bar for the learnpath display screen
  1503. * @return string The HTML string to use as a navigation bar
  1504. */
  1505. public function get_navigation_bar() {
  1506. if ($this->debug > 0) {
  1507. error_log('New LP - In learnpath::get_navigation_bar()', 0);
  1508. }
  1509. // TODO: Find a good value for the following variables.
  1510. $file = '';
  1511. $openDir = '';
  1512. $edoceo = '';
  1513. $time = 0;
  1514. $navbar = '';
  1515. $RequestUri = '';
  1516. $mycurrentitemid = $this->get_current_item_id();
  1517. if ($this->mode == 'fullscreen') {
  1518. $navbar = '<table cellpadding="0" cellspacing="0" align="left">' . "\n" .
  1519. ' <tr> ' . "\n" .
  1520. ' <td>' . "\n" .
  1521. ' <div class="buttons">' . "\n" .
  1522. ' <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" .
  1523. ' <a href="" onClick="switch_item(' . $mycurrentitemid . ',\'previous\');return false;" title="previous"><img border="0" src="../img/lp_leftarrow.gif" title="' . get_lang('ScormPrevious') . '"></a>' . "\n" .
  1524. ' <a href="" onClick="switch_item(' . $mycurrentitemid . ',\'next\');return false;" title="next" ><img border="0" src="../img/lp_rightarrow.gif" title="' . get_lang('ScormNext') . '"></a>' . "\n" .
  1525. //' <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" .
  1526. //' <a href="lp_controller.php?action=list" target="_top" title="learnpaths list"><img border="0" src="../img/exit.png" title="Exit"></a>'."\n" .
  1527. ' </div>' . "\n" .
  1528. ' </td>' . "\n" .
  1529. ' </tr>' . "\n" .
  1530. '</table>';
  1531. } else {
  1532. $navbar = '<table cellpadding="0" cellspacing="0" align="left">' . "\n" .
  1533. ' <tr> ' . "\n" .
  1534. ' <td>' . "\n" .
  1535. ' <div class="buttons">' . "\n" .
  1536. ' <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" .
  1537. ' <a href="" onClick="switch_item(' . $mycurrentitemid . ',\'previous\');return false;" title="previous"><img border="0" src="../img/lp_leftarrow.gif" title="' . get_lang('ScormPrevious') . '"></a>' . "\n" .
  1538. ' <a href="" onClick="switch_item(' . $mycurrentitemid . ',\'next\');return false;" title="next" ><img border="0" src="../img/lp_rightarrow.gif" title="' . get_lang('ScormNext') . '"></a>' . "\n" .
  1539. // ' <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" .
  1540. ' </div>' . "\n" .
  1541. ' </td>' . "\n" .
  1542. ' </tr>' . "\n" .
  1543. '</table>';
  1544. }
  1545. return $navbar;
  1546. }
  1547. /**
  1548. * Gets the next resource in queue (url).
  1549. * @return string URL to load into the viewer
  1550. */
  1551. public function get_next_index() {
  1552. if ($this->debug > 0) {
  1553. error_log('New LP - In learnpath::get_next_index()', 0);
  1554. }
  1555. // TODO
  1556. $index = $this->index;
  1557. $index++;
  1558. if ($this->debug > 2) {
  1559. error_log('New LP - Now looking at ordered_items[' . ($index) . '] - type is ' . $this->items[$this->ordered_items[$index]]->type, 0);
  1560. }
  1561. 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) {
  1562. $index++;
  1563. if ($index == $this->max_ordered_items){
  1564. if ($this->items[$this->ordered_items[$index]]->get_type() == 'dir' || $this->items[$this->ordered_items[$index]]->get_type() == 'dokeos_chapter') {
  1565. return $this->index;
  1566. } else {
  1567. return $index;
  1568. }
  1569. }
  1570. }
  1571. if (empty ($this->ordered_items[$index])) {
  1572. return $this->index;
  1573. }
  1574. if ($this->debug > 2) {
  1575. error_log('New LP - index is now ' . $index, 0);
  1576. }
  1577. return $index;
  1578. }
  1579. /**
  1580. * Gets item_id for the next element
  1581. * @return integer Next item (DB) ID
  1582. */
  1583. public function get_next_item_id() {
  1584. if ($this->debug > 0) {
  1585. error_log('New LP - In learnpath::get_next_item_id()', 0);
  1586. }
  1587. $new_index = $this->get_next_index();
  1588. if (!empty ($new_index)) {
  1589. if (isset ($this->ordered_items[$new_index])) {
  1590. if ($this->debug > 2) {
  1591. error_log('New LP - In learnpath::get_next_index() - Returning ' . $this->ordered_items[$new_index], 0);
  1592. }
  1593. return $this->ordered_items[$new_index];
  1594. }
  1595. }
  1596. if ($this->debug > 2) {
  1597. error_log('New LP - In learnpath::get_next_index() - Problem - Returning 0', 0);
  1598. }
  1599. return 0;
  1600. }
  1601. /**
  1602. * Returns the package type ('scorm','aicc','scorm2004','dokeos','ppt'...)
  1603. *
  1604. * Generally, the package provided is in the form of a zip file, so the function
  1605. * has been written to test a zip file. If not a zip, the function will return the
  1606. * default return value: ''
  1607. * @param string the path to the file
  1608. * @param string the original name of the file
  1609. * @return string 'scorm','aicc','scorm2004','dokeos' or '' if the package cannot be recognized
  1610. */
  1611. public function get_package_type($file_path, $file_name) {
  1612. // Get name of the zip file without the extension.
  1613. $file_info = pathinfo($file_name);
  1614. $filename = $file_info['basename']; // Name including extension.
  1615. $extension = $file_info['extension']; // Extension only.
  1616. if (!empty($_POST['ppt2lp']) && !in_array(strtolower($extension), array (
  1617. 'dll',
  1618. 'exe'
  1619. ))) {
  1620. return 'oogie';
  1621. }
  1622. if (!empty($_POST['woogie']) && !in_array(strtolower($extension), array (
  1623. 'dll',
  1624. 'exe'
  1625. ))) {
  1626. return 'woogie';
  1627. }
  1628. $file_base_name = str_replace('.' . $extension, '', $filename); // Filename without its extension.
  1629. $zipFile = new pclZip($file_path);
  1630. // Check the zip content (real size and file extension).
  1631. $zipContentArray = $zipFile->listContent();
  1632. $package_type = '';
  1633. $at_root = false;
  1634. $manifest = '';
  1635. // The following loop should be stopped as soon as we found the right imsmanifest.xml (how to recognize it?).
  1636. if (is_array($zipContentArray) && count($zipContentArray) > 0) {
  1637. foreach ($zipContentArray as $thisContent) {
  1638. if (preg_match('~.(php.*|phtml)$~i', $thisContent['filename'])) {
  1639. // New behaviour: Don't do anything. These files will be removed in scorm::import_package.
  1640. }
  1641. elseif (stristr($thisContent['filename'], 'imsmanifest.xml') !== false) {
  1642. $manifest = $thisContent['filename']; // Just the relative directory inside scorm/
  1643. $package_type = 'scorm';
  1644. break; // Exit the foreach loop.
  1645. }
  1646. elseif (preg_match('/aicc\//i', $thisContent['filename'])) {
  1647. // If found an aicc directory... (!= false means it cannot be false (error) or 0 (no match)).
  1648. $package_type = 'aicc';
  1649. //break; // Don't exit the loop, because if we find an imsmanifest afterwards, we want it, not the AICC.
  1650. } else {
  1651. $package_type = '';
  1652. }
  1653. }
  1654. }
  1655. return $package_type;
  1656. }
  1657. /**
  1658. * Gets the previous resource in queue (url). Also initialises time values for this viewing
  1659. * @return string URL to load into the viewer
  1660. */
  1661. public function get_previous_index() {
  1662. if ($this->debug > 0) {
  1663. error_log('New LP - In learnpath::get_previous_index()', 0);
  1664. }
  1665. $index = $this->index;
  1666. if (isset ($this->ordered_items[$index -1])) {
  1667. $index--;
  1668. 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')) {
  1669. $index--;
  1670. if ($index < 0) {
  1671. return $this->index;
  1672. }
  1673. }
  1674. } else {
  1675. if ($this->debug > 2) {
  1676. error_log('New LP - get_previous_index() - there was no previous index available, reusing ' . $index, 0);
  1677. }
  1678. // There is no previous item.
  1679. }
  1680. return $index;
  1681. }
  1682. /**
  1683. * Gets item_id for the next element
  1684. * @return integer Previous item (DB) ID
  1685. */
  1686. public function get_previous_item_id() {
  1687. if ($this->debug > 0) {
  1688. error_log('New LP - In learnpath::get_previous_item_id()', 0);
  1689. }
  1690. $new_index = $this->get_previous_index();
  1691. return $this->ordered_items[$new_index];
  1692. }
  1693. /**
  1694. * Gets the progress value from the progress_db attribute
  1695. * @return integer Current progress value
  1696. */
  1697. public function get_progress() {
  1698. if ($this->debug > 0) {
  1699. error_log('New LP - In learnpath::get_progress()', 0);
  1700. }
  1701. if (!empty ($this->progress_db)) {
  1702. return $this->progress_db;
  1703. }
  1704. return 0;
  1705. }
  1706. /**
  1707. * Gets the progress value from the progress field in the database (allows use as abstract method)
  1708. * @param integer Learnpath ID
  1709. * @param integer User ID
  1710. * @param string Mode of display ('%','abs' or 'both')
  1711. * @param string Course database name (optional, defaults to '')
  1712. * @param boolean Whether to return null if no record was found (true), or 0 (false) (optional, defaults to false)
  1713. * @return integer Current progress value as found in the database
  1714. */
  1715. public function get_db_progress($lp_id, $user_id, $mode = '%', $course_db = '', $sincere = false,$session_id = 0) {
  1716. //if ($this->debug > 0) { error_log('New LP - In learnpath::get_db_progress()', 0); }
  1717. $session_id = intval($session_id);
  1718. $session_condition = api_get_session_condition($session_id);
  1719. $table = Database :: get_course_table(TABLE_LP_VIEW, $course_db);
  1720. $sql = "SELECT * FROM $table WHERE lp_id = $lp_id AND user_id = $user_id $session_condition";
  1721. $res = Database::query($sql);
  1722. $view_id = 0;
  1723. if (Database :: num_rows($res) > 0) {
  1724. $row = Database :: fetch_array($res);
  1725. $progress = $row['progress'];
  1726. $view_id = $row['id'];
  1727. } else {
  1728. if ($sincere) {
  1729. return null;
  1730. }
  1731. }
  1732. if (empty ($progress)) {
  1733. $progress = '0';
  1734. }
  1735. if ($mode == '%') {
  1736. return $progress . '%';
  1737. } else {
  1738. // Get the number of items completed and the number of items total.
  1739. $tbl = Database :: get_course_table(TABLE_LP_ITEM, $course_db);
  1740. $sql = "SELECT count(*) FROM $tbl WHERE lp_id = " . $lp_id . "
  1741. AND item_type NOT IN('dokeos_chapter','chapter','dir')";
  1742. $res = Database::query($sql);
  1743. $row = Database :: fetch_array($res);
  1744. $total = $row[0];
  1745. $tbl_item_view = Database :: get_course_table(TABLE_LP_ITEM_VIEW, $course_db);
  1746. $tbl_item = Database :: get_course_table(TABLE_LP_ITEM, $course_db);
  1747. //$sql = "SELECT count(distinct(lp_item_id)) FROM $tbl WHERE lp_view_id = ".$view_id." AND status IN ('passed','completed','succeeded')";
  1748. // Trying as also counting browsed and failed items.
  1749. $sql = "SELECT count(distinct(lp_item_id))
  1750. FROM $tbl_item_view as item_view
  1751. INNER JOIN $tbl_item as item
  1752. ON item.id = item_view.lp_item_id
  1753. AND item_type NOT IN('dokeos_chapter','chapter','dir')
  1754. WHERE lp_view_id = " . $view_id . "
  1755. AND status IN ('passed','completed','succeeded','browsed','failed')"; //echo '<br />';
  1756. $res = Database::query($sql);
  1757. $row = Database :: fetch_array($res);
  1758. $completed = $row[0];
  1759. if ($mode == 'abs') {
  1760. return $completed . '/' . $total;
  1761. }
  1762. elseif ($mode == 'both') {
  1763. if ($progress < ($completed / ($total ? $total : 1))) {
  1764. $progress = number_format(($completed / ($total ? $total : 1)) * 100, 0);
  1765. }
  1766. return $progress . '% (' . $completed . '/' . $total . ')';
  1767. }
  1768. }
  1769. return $progress;
  1770. }
  1771. /**
  1772. * Returns the HTML necessary to print a mediaplayer block inside a page
  1773. * @return string The mediaplayer HTML
  1774. */
  1775. public function get_mediaplayer($autostart='true') {
  1776. global $_course;
  1777. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  1778. $tbl_lp_item_view = Database :: get_course_table(TABLE_LP_ITEM_VIEW);
  1779. // Getting all the information about the item.
  1780. $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 " .
  1781. "WHERE lp.id = '" . $_SESSION['oLP']->current . "'";
  1782. $result = Database::query($sql);
  1783. $row = Database::fetch_assoc($result);
  1784. $output = '';
  1785. if (!empty ($row['audio'])) {
  1786. $list = $_SESSION['oLP']->get_toc();
  1787. $type_quiz = false;
  1788. foreach($list as $toc) {
  1789. if ($toc['id'] == $_SESSION['oLP']->current && ($toc['type']=='quiz') ) {
  1790. $type_quiz = true;
  1791. }
  1792. }
  1793. if ($type_quiz) {
  1794. if ($_SESSION['oLP']->prevent_reinit == 1) {
  1795. $row['status'] === 'completed' ? $autostart_audio = 'false' : $autostart_audio = 'true';
  1796. } else {
  1797. $autostart_audio = $autostart;
  1798. }
  1799. } else {
  1800. $autostart_audio = 'true';
  1801. }
  1802. // The mp3 player.
  1803. $output = '<div id="container">';
  1804. $output .= '<script type="text/javascript" src="../inc/lib/mediaplayer/swfobject.js"></script>';
  1805. $output .= '<script type="text/javascript">
  1806. var s1 = new SWFObject("../inc/lib/mediaplayer/player.swf","ply","250","20","9","#FFFFFF");
  1807. s1.addParam("allowscriptaccess","always");
  1808. s1.addParam("flashvars","file=' . api_get_path(WEB_COURSE_PATH) . $_course['path'] . '/document/audio/' . $row['audio'] . '&autostart=' . $autostart_audio.'");
  1809. s1.write("container");
  1810. </script></div>';
  1811. }
  1812. return $output;
  1813. }
  1814. /**
  1815. * This function checks if the learnpath is visible for student after the progress of its prerequisite is completed, and considering time availability
  1816. * @param int Learnpath id
  1817. * @param int Student id
  1818. * @param string Course code (optional)
  1819. * @return bool True if
  1820. */
  1821. public function is_lp_visible_for_student($lp_id, $student_id, $course = null) {
  1822. $lp_id = (int)$lp_id;
  1823. $course = api_get_course_info($course);
  1824. $tbl_learnpath = Database :: get_course_table(TABLE_LP_MAIN,$course['dbName']);
  1825. // Get current prerequisite
  1826. $sql = "SELECT id, prerequisite, publicated_on, expired_on FROM $tbl_learnpath WHERE id = $lp_id";
  1827. $rs = Database::query($sql);
  1828. if (Database::num_rows($rs)>0) {
  1829. $row = Database::fetch_array($rs);
  1830. $prerequisite = $row['prerequisite'];
  1831. $find = array(' ','-',':');
  1832. $from = str_replace($find,'',api_get_local_time($row['publicated_on']));
  1833. $to = str_replace($find,'',api_get_local_time($row['expired_on']));
  1834. $is_visible = true;
  1835. $progress = 0;
  1836. if (!empty($prerequisite)) {
  1837. $progress = self::get_db_progress($prerequisite,$student_id,'%', '', false, api_get_session_id());
  1838. $progress = intval($progress);
  1839. if ($progress < 100) {
  1840. $is_visible = false;
  1841. }
  1842. }
  1843. // Also check the time availability of the learning path
  1844. if ($is_visible) {
  1845. $now = str_replace($find,'',api_get_local_time());
  1846. if ((($row['publicated_on']!='0000-00-00 00:00:00') && ($now<$from)) or (($row['expired_on']!='0000-00-00 00:00:00') && ($now>$to))) {
  1847. $is_visible = false;
  1848. }
  1849. }
  1850. return $is_visible;
  1851. }
  1852. return false;
  1853. }
  1854. /**
  1855. * Gets a progress bar for the learnpath by counting the number of items in it and the number of items
  1856. * completed so far.
  1857. * @param string Mode in which we want the values
  1858. * @param integer Progress value to display (optional but mandatory if used in abstract context)
  1859. * @param string Text to display near the progress value (optional but mandatory in abstract context)
  1860. * @param boolean true if it comes from a Diplay LP view
  1861. * @return string HTML string containing the progress bar
  1862. */
  1863. public function get_progress_bar($mode = '', $percentage = -1, $text_add = '', $from_lp = false) {
  1864. //if ($this->debug > 0) {error_log('New LP - In learnpath::get_progress_bar('.$mode.','.$percentage.','.$text_add.','.$from_lp.')', 0); }
  1865. global $lp_theme_css;
  1866. // Setting up the CSS path of the current style if exists.
  1867. if (!empty ($lp_theme_css)) {
  1868. $css_path = api_get_path(WEB_CODE_PATH) . 'css/' . $lp_theme_css . '/images/';
  1869. } else {
  1870. $css_path = '../img/';
  1871. }
  1872. //if ($this->debug > 0) { error_log('New LP - In learnpath::get_progress_bar()', 0); }
  1873. if (isset($this) && is_object($this) && ($percentage == '-1' OR $text_add == '')) {
  1874. list($percentage, $text_add) = $this->get_progress_bar_text($mode);
  1875. }
  1876. $text = $percentage . $text_add;
  1877. // Default progress bar config
  1878. // times that will be greater or shorter
  1879. $factor = 1.2;
  1880. if ($from_lp)
  1881. $progress_height = '26';
  1882. else
  1883. $progress_height = '16';
  1884. $size = str_replace('%', '', $percentage);
  1885. $output ='<div style="width:135px">' .
  1886. '<img id="progress_img_limit_left" src="' . $css_path . 'bar_1.gif" width="1" height="' . $progress_height . '">' .
  1887. '<img id="progress_img_full" src="' . $css_path . 'bar_1u.gif" width="' . $size * $factor . 'px" height="' . $progress_height . '" id="full_portion">' .
  1888. '<img id="progress_img_limit_middle" src="' . $css_path . 'bar_1m.gif" width="1" height="' . $progress_height . '">';
  1889. if ($percentage <= 98) {
  1890. $output .= '<img id="progress_img_empty" src="' . $css_path . 'bar_1r.gif" width="' . (100 - $size) * $factor . 'px" height="' . $progress_height . '" id="empty_portion">';
  1891. } else {
  1892. $output .= '<img id="progress_img_empty" src="' . $css_path . 'bar_1r.gif" width="0" height="' . $progress_height . '" id="empty_portion">';
  1893. }
  1894. $output .= '<img id="progress_bar_img_limit_right" src="' . $css_path . 'bar_1.gif" width="1" height="' . $progress_height . '"></div>' .
  1895. '<div class="progresstext" id="progress_text">' . $text . '</div>';
  1896. return $output;
  1897. }
  1898. /**
  1899. * Gets the progress bar info to display inside the progress bar. Also used by scorm_api.php
  1900. * @param string Mode of display (can be '%' or 'abs').abs means we display a number of completed elements per total elements
  1901. * @param integer Additional steps to fake as completed
  1902. * @return list Percentage or number and symbol (% or /xx)
  1903. */
  1904. public function get_progress_bar_text($mode = '', $add = 0) {
  1905. if ($this->debug > 0) {
  1906. error_log('New LP - In learnpath::get_progress_bar_text()', 0);
  1907. }
  1908. if (empty ($mode)) {
  1909. $mode = $this->progress_bar_mode;
  1910. }
  1911. $total_items = $this->get_total_items_count_without_chapters();
  1912. if ($this->debug > 2) {
  1913. error_log('New LP - Total items available in this learnpath: ' . $total_items, 0);
  1914. }
  1915. $i = $this->get_complete_items_count();
  1916. if ($this->debug > 2) {
  1917. error_log('New LP - Items completed so far: ' . $i, 0);
  1918. }
  1919. if ($add != 0) {
  1920. $i += $add;
  1921. if ($this->debug > 2) {
  1922. error_log('New LP - Items completed so far (+modifier): ' . $i, 0);
  1923. }
  1924. }
  1925. $text = '';
  1926. if ($i > $total_items) {
  1927. $i = $total_items;
  1928. }
  1929. if ($mode == '%') {
  1930. if ($total_items > 0) {
  1931. $percentage = ((float) $i / (float) $total_items) * 100;
  1932. } else {
  1933. $percentage = 0;
  1934. }
  1935. $percentage = number_format($percentage, 0);
  1936. $text = '%';
  1937. }
  1938. elseif ($mode == 'abs') {
  1939. $percentage = $i;
  1940. $text = '/' . $total_items;
  1941. }
  1942. return array (
  1943. $percentage,
  1944. $text
  1945. );
  1946. }
  1947. /**
  1948. * Gets the progress bar mode
  1949. * @return string The progress bar mode attribute
  1950. */
  1951. public function get_progress_bar_mode() {
  1952. if ($this->debug > 0) {
  1953. error_log('New LP - In learnpath::get_progress_bar_mode()', 0);
  1954. }
  1955. if (!empty ($this->progress_bar_mode)) {
  1956. return $this->progress_bar_mode;
  1957. } else {
  1958. return '%';
  1959. }
  1960. }
  1961. /**
  1962. * Gets the learnpath proximity (remote or local)
  1963. * @return string Learnpath proximity
  1964. */
  1965. public function get_proximity() {
  1966. if ($this->debug > 0) {
  1967. error_log('New LP - In learnpath::get_proximity()', 0);
  1968. }
  1969. if (!empty ($this->proximity)) {
  1970. return $this->proximity;
  1971. } else {
  1972. return '';
  1973. }
  1974. }
  1975. /**
  1976. * Gets the learnpath theme (remote or local)
  1977. * @return string Learnpath theme
  1978. */
  1979. public function get_theme() {
  1980. if ($this->debug > 0) {
  1981. error_log('New LP - In learnpath::get_theme()', 0);
  1982. }
  1983. if (!empty ($this->theme)) {
  1984. return $this->theme;
  1985. } else {
  1986. return '';
  1987. }
  1988. }
  1989. /**
  1990. * Gets the learnpath session id
  1991. * @return string Learnpath theme
  1992. */
  1993. public function get_lp_session_id() {
  1994. if ($this->debug > 0) {
  1995. error_log('New LP - In learnpath::get_lp_session_id()', 0);
  1996. }
  1997. if (!empty ($this->lp_session_id)) {
  1998. return $this->lp_session_id;
  1999. } else {
  2000. return 0;
  2001. }
  2002. }
  2003. /**
  2004. * Gets the learnpath image
  2005. * @return string Web URL of the LP image
  2006. */
  2007. public function get_preview_image() {
  2008. if ($this->debug > 0) {
  2009. error_log('New LP - In learnpath::get_preview_image()', 0);
  2010. }
  2011. if (!empty ($this->preview_image)) {
  2012. return $this->preview_image;
  2013. } else {
  2014. return '';
  2015. }
  2016. }
  2017. /**
  2018. * Gets the learnpath author
  2019. * @return string LP's author
  2020. */
  2021. public function get_author() {
  2022. if ($this->debug > 0) {
  2023. error_log('New LP - In learnpath::get_author()', 0);
  2024. }
  2025. if (!empty ($this->author)) {
  2026. return $this->author;
  2027. } else {
  2028. return '';
  2029. }
  2030. }
  2031. /**
  2032. * Generate a new prerequisites string for a given item. If this item was a sco and
  2033. * its prerequisites were strings (instead of IDs), then transform those strings into
  2034. * IDs, knowing that SCORM IDs are kept in the "ref" field of the lp_item table.
  2035. * Prefix all item IDs that end-up in the prerequisites string by "ITEM_" to use the
  2036. * same rule as the scorm_export() method
  2037. * @param integer Item ID
  2038. * @return string Prerequisites string ready for the export as SCORM
  2039. */
  2040. public function get_scorm_prereq_string($item_id) {
  2041. if ($this->debug > 0) {
  2042. error_log('New LP - In learnpath::get_scorm_prereq_string()', 0);
  2043. }
  2044. if (!is_object($this->items[$item_id])) {
  2045. return false;
  2046. }
  2047. $oItem = $this->items[$item_id];
  2048. $prereq = $oItem->get_prereq_string();
  2049. if (empty ($prereq)) {
  2050. return '';
  2051. }
  2052. 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,
  2053. // then simply return it (with the ITEM_ prefix).
  2054. return 'ITEM_' . $prereq;
  2055. } else {
  2056. if (isset ($this->refs_list[$prereq])) {
  2057. // It's a simple string item from which the ID can be found in the refs list,
  2058. // so we can transform it directly to an ID for export.
  2059. return 'ITEM_' . $this->refs_list[$prereq];
  2060. } else {
  2061. // The last case, if it's a complex form, then find all the IDs (SCORM strings)
  2062. // and replace them, one by one, by the internal IDs (chamilo db)
  2063. // TODO: Modify the '*' replacement to replace the multiplier in front of it
  2064. // by a space as well.
  2065. $find = array (
  2066. '&',
  2067. '|',
  2068. '~',
  2069. '=',
  2070. '<>',
  2071. '{',
  2072. '}',
  2073. '*',
  2074. '(',
  2075. ')'
  2076. );
  2077. $replace = array (
  2078. ' ',
  2079. ' ',
  2080. ' ',
  2081. ' ',
  2082. ' ',
  2083. ' ',
  2084. ' ',
  2085. ' ',
  2086. ' ',
  2087. ' '
  2088. );
  2089. $prereq_mod = str_replace($find, $replace, $prereq);
  2090. $ids = split(' ', $prereq_mod);
  2091. foreach ($ids as $id) {
  2092. $id = trim($id);
  2093. if (isset ($this->refs_list[$id])) {
  2094. $prereq = preg_replace('/[^a-zA-Z_0-9](' . $id . ')[^a-zA-Z_0-9]/', 'ITEM_' . $this->refs_list[$id], $prereq);
  2095. }
  2096. }
  2097. error_log('New LP - In learnpath::get_scorm_prereq_string(): returning modified string: ' . $prereq, 0);
  2098. return $prereq;
  2099. }
  2100. }
  2101. }
  2102. /**
  2103. * Returns the XML DOM document's node
  2104. * @param resource Reference to a list of objects to search for the given ITEM_*
  2105. * @param string The identifier to look for
  2106. * @return mixed The reference to the element found with that identifier. False if not found
  2107. */
  2108. public function get_scorm_xml_node(& $children, $id) {
  2109. for ($i = 0; $i < $children->length; $i++) {
  2110. $item_temp = $children->item($i);
  2111. if ($item_temp->nodeName == 'item') {
  2112. if ($item_temp->getAttribute('identifier') == $id) {
  2113. return $item_temp;
  2114. }
  2115. }
  2116. $subchildren = $item_temp->childNodes;
  2117. if ($subchildren->length > 0) {
  2118. $val = $this->get_scorm_xml_node($subchildren, $id);
  2119. if (is_object($val)) {
  2120. return $val;
  2121. }
  2122. }
  2123. }
  2124. return false;
  2125. }
  2126. /**
  2127. * Returns a usable array of stats related to the current learnpath and user
  2128. * @return array Well-formatted array containing status for the current learnpath
  2129. */
  2130. public function get_stats() {
  2131. if ($this->debug > 0) {
  2132. error_log('New LP - In learnpath::get_stats()', 0);
  2133. }
  2134. // TODO
  2135. }
  2136. /**
  2137. * Static method. Can be re-implemented by children. Gives an array of statistics for
  2138. * the given course (for all learnpaths and all users)
  2139. * @param string Course code
  2140. * @return array Well-formatted array containing status for the course's learnpaths
  2141. */
  2142. public function get_stats_course($course) {
  2143. //if ($this->debug > 0) { error_log('New LP - In learnpath::get_stats_course()', 0); }
  2144. // TODO
  2145. }
  2146. /**
  2147. * Static method. Can be re-implemented by children. Gives an array of statistics for
  2148. * the given course and learnpath (for all users)
  2149. * @param string Course code
  2150. * @param integer Learnpath ID
  2151. * @return array Well-formatted array containing status for the specified learnpath
  2152. */
  2153. public function get_stats_lp($course, $lp) {
  2154. //if ($this->debug > 0) { error_log('New LP - In learnpath::get_stats_lp()', 0); }
  2155. // TODO
  2156. }
  2157. /**
  2158. * Static method. Can be re-implemented by children. Gives an array of statistics for
  2159. * the given course, learnpath and user.
  2160. * @param string Course code
  2161. * @param integer Learnpath ID
  2162. * @param integer User ID
  2163. * @return array Well-formatted array containing status for the specified learnpath and user
  2164. */
  2165. public function get_stats_lp_user($course, $lp, $user) {
  2166. //if ($this->debug > 0) { error_log('New LP - In learnpath::get_stats_lp_user()', 0); }
  2167. // TODO
  2168. }
  2169. /**
  2170. * Static method. Can be re-implemented by children. Gives an array of statistics for
  2171. * the given course and learnpath (for all users)
  2172. * @param string Course code
  2173. * @param integer User ID
  2174. * @return array Well-formatted array containing status for the user's learnpaths
  2175. */
  2176. public function get_stats_user($course, $user) {
  2177. //if ($this->debug > 0) { error_log('New LP - In learnpath::get_stats_user()', 0); }
  2178. // TODO
  2179. }
  2180. /**
  2181. * Gets the status list for all LP's items
  2182. * @return array Array of [index] => [item ID => current status]
  2183. */
  2184. public function get_items_status_list() {
  2185. if ($this->debug > 0) {
  2186. error_log('New LP - In learnpath::get_items_status_list()', 0);
  2187. }
  2188. $list = array ();
  2189. foreach ($this->ordered_items as $item_id) {
  2190. $list[] = array (
  2191. $item_id => $this->items[$item_id]->get_status()
  2192. );
  2193. }
  2194. return $list;
  2195. }
  2196. /**
  2197. * Return the number of interactions for the given learnpath Item View ID.
  2198. * This method can be used as static.
  2199. * @param integer Item View ID
  2200. * @return integer Number of interactions
  2201. */
  2202. public function get_interactions_count_from_db($lp_iv_id = 0, $course_code = null) {
  2203. if (empty ($lp_iv_id)) {
  2204. return -1;
  2205. }
  2206. $course_info = api_get_course_info($course_code);
  2207. $table = Database :: get_course_table(TABLE_LP_IV_INTERACTION, $course_info['db_name']);
  2208. $sql = "SELECT count(*) FROM $table WHERE lp_iv_id = $lp_iv_id";
  2209. $res = Database::query($sql);
  2210. $row = Database :: fetch_array($res);
  2211. $num = $row[0];
  2212. return $num;
  2213. }
  2214. /**
  2215. * Return the interactions as an array for the given lp_iv_id.
  2216. * This method can be used as static.
  2217. * @param integer Learnpath Item View ID
  2218. * @return array
  2219. * @todo Transcode labels instead of switching to HTML (which requires to know the encoding of the LP)
  2220. */
  2221. public function get_iv_interactions_array($lp_iv_id = 0) {
  2222. $list = array ();
  2223. $table = Database :: get_course_table(TABLE_LP_IV_INTERACTION);
  2224. $sql = "SELECT * FROM $table WHERE lp_iv_id = $lp_iv_id ORDER BY order_id ASC";
  2225. $res = Database::query($sql);
  2226. $num = Database :: num_rows($res);
  2227. if ($num > 0) {
  2228. $list[] = array (
  2229. 'order_id' => api_htmlentities(get_lang('Order'), ENT_QUOTES),
  2230. 'id' => api_htmlentities(get_lang('InteractionID'), ENT_QUOTES),
  2231. 'type' => api_htmlentities(get_lang('Type'), ENT_QUOTES),
  2232. 'time' => api_htmlentities(get_lang('TimeFinished'), ENT_QUOTES),
  2233. 'correct_responses' => api_htmlentities(get_lang('CorrectAnswers'), ENT_QUOTES),
  2234. 'student_response' => api_htmlentities(get_lang('StudentResponse'), ENT_QUOTES),
  2235. 'result' => api_htmlentities(get_lang('Result'), ENT_QUOTES),
  2236. 'latency' => api_htmlentities(get_lang('LatencyTimeSpent'), ENT_QUOTES)
  2237. );
  2238. while ($row = Database :: fetch_array($res)) {
  2239. $list[] = array (
  2240. 'order_id' => ($row['order_id'] + 1),
  2241. 'id' => urldecode($row['interaction_id']), //urldecode because they often have %2F or stuff like that
  2242. 'type' => $row['interaction_type'],
  2243. 'time' => $row['completion_time'],
  2244. //'correct_responses' => $row['correct_responses'],
  2245. 'correct_responses' => '', // Hide correct responses from students.
  2246. 'student_response' => $row['student_response'],
  2247. 'result' => $row['result'],
  2248. 'latency' => $row['latency']
  2249. );
  2250. }
  2251. }
  2252. return $list;
  2253. }
  2254. /**
  2255. * Return the number of objectives for the given learnpath Item View ID.
  2256. * This method can be used as static.
  2257. * @param integer Item View ID
  2258. * @return integer Number of objectives
  2259. */
  2260. public function get_objectives_count_from_db($lp_iv_id = 0, $course_code = null) {
  2261. if (empty ($lp_iv_id)) {
  2262. return -1;
  2263. }
  2264. $course_info = api_get_course_info($course_code);
  2265. $table = Database :: get_course_table(TABLE_LP_IV_OBJECTIVE, $course_info['db_name']);
  2266. $sql = "SELECT count(*) FROM $table WHERE lp_iv_id = $lp_iv_id";
  2267. $res = Database::query($sql);
  2268. $row = Database :: fetch_array($res);
  2269. $num = $row[0];
  2270. return $num;
  2271. }
  2272. /**
  2273. * Return the objectives as an array for the given lp_iv_id.
  2274. * This method can be used as static.
  2275. * @param integer Learnpath Item View ID
  2276. * @return array
  2277. * @todo Translate labels
  2278. */
  2279. public function get_iv_objectives_array($lp_iv_id = 0) {
  2280. $list = array();
  2281. $table = Database :: get_course_table(TABLE_LP_IV_OBJECTIVE);
  2282. $sql = "SELECT * FROM $table WHERE lp_iv_id = $lp_iv_id ORDER BY order_id ASC";
  2283. $res = Database::query($sql);
  2284. $num = Database :: num_rows($res);
  2285. if ($num > 0) {
  2286. $list[] = array (
  2287. 'order_id' => api_htmlentities(get_lang('Order'), ENT_QUOTES),
  2288. 'objective_id' => api_htmlentities(get_lang('ObjectiveID'), ENT_QUOTES),
  2289. 'score_raw' => api_htmlentities(get_lang('ObjectiveRawScore'), ENT_QUOTES),
  2290. 'score_max' => api_htmlentities(get_lang('ObjectiveMaxScore'), ENT_QUOTES),
  2291. 'score_min' => api_htmlentities(get_lang('ObjectiveMinScore'), ENT_QUOTES),
  2292. 'status' => api_htmlentities(get_lang('ObjectiveStatus'), ENT_QUOTES)
  2293. );
  2294. while ($row = Database :: fetch_array($res)) {
  2295. $list[] = array (
  2296. 'order_id' => ($row['order_id'] + 1),
  2297. 'objective_id' => urldecode($row['objective_id']), // urldecode() because they often have %2F or stuff like that.
  2298. 'score_raw' => $row['score_raw'],
  2299. 'score_max' => $row['score_max'],
  2300. 'score_min' => $row['score_min'],
  2301. 'status' => $row['status']
  2302. );
  2303. }
  2304. }
  2305. return $list;
  2306. }
  2307. /**
  2308. * Generate and return the table of contents for this learnpath. The (flat) table returned can be
  2309. * used by get_html_toc() to be ready to display
  2310. * @return array TOC as a table with 4 elements per row: title, link, status and level
  2311. */
  2312. public function get_toc() {
  2313. if ($this->debug > 0) {
  2314. error_log('New LP - In learnpath::get_toc()', 0);
  2315. }
  2316. $toc = array ();
  2317. //echo "<pre>".print_r($this->items,true)."</pre>";
  2318. foreach ($this->ordered_items as $item_id) {
  2319. if ($this->debug > 2) {
  2320. error_log('New LP - learnpath::get_toc(): getting info for item ' . $item_id, 0);
  2321. }
  2322. // TODO: Change this link generation and use new function instead.
  2323. $toc[] = array (
  2324. 'id' => $item_id,
  2325. 'title' => $this->items[$item_id]->get_title(),
  2326. //'link' => get_addedresource_link_in_learnpath('document', $item_id, 1),
  2327. 'status' => $this->items[$item_id]->get_status(),
  2328. 'level' => $this->items[$item_id]->get_level(),
  2329. 'type' => $this->items[$item_id]->get_type(),
  2330. 'description' => $this->items[$item_id]->get_description(),
  2331. 'path' => $this->items[$item_id]->get_path(),
  2332. );
  2333. }
  2334. if ($this->debug > 2) {
  2335. error_log('New LP - In learnpath::get_toc() - TOC array: ' . print_r($toc, true), 0);
  2336. }
  2337. return $toc;
  2338. }
  2339. /**
  2340. * Generate and return the table of contents for this learnpath. The JS
  2341. * table returned is used inside of scorm_api.php
  2342. * @return string A JS array vairiable construction
  2343. */
  2344. public function get_items_details_as_js($varname = 'olms.lms_item_types') {
  2345. if ($this->debug > 0) {
  2346. error_log('New LP - In learnpath::get_items_details_as_js()', 0);
  2347. }
  2348. $toc = $varname.' = new Array();';
  2349. //echo "<pre>".print_r($this->items,true)."</pre>";
  2350. foreach ($this->ordered_items as $item_id) {
  2351. if ($this->debug > 2) {
  2352. error_log('New LP - learnpath::get_items_details_as_js(): getting info for item ' . $item_id, 0);
  2353. }
  2354. $toc.= $varname."['i$item_id'] = '".$this->items[$item_id]->get_type()."';";
  2355. }
  2356. if ($this->debug > 2) {
  2357. error_log('New LP - In learnpath::get_items_details_as_js() - TOC array: ' . print_r($toc, true), 0);
  2358. }
  2359. return $toc;
  2360. }
  2361. /**
  2362. * Gets the learning path type
  2363. * @param boolean Return the name? If false, return the ID. Default is false.
  2364. * @return mixed Type ID or name, depending on the parameter
  2365. */
  2366. public function get_type($get_name = false) {
  2367. $res = false;
  2368. if ($this->debug > 0) {
  2369. error_log('New LP - In learnpath::get_type()', 0);
  2370. }
  2371. if (!empty ($this->type)) {
  2372. if ($get_name) {
  2373. // Get it from the lp_type table in main db.
  2374. } else {
  2375. $res = $this->type;
  2376. }
  2377. }
  2378. if ($this->debug > 2) {
  2379. error_log('New LP - In learnpath::get_type() - Returning ' . ($res ? $res : 'false'), 0);
  2380. }
  2381. return $res;
  2382. }
  2383. /**
  2384. * Gets the learning path type as static method
  2385. * @param boolean Return the name? If false, return the ID. Default is false.
  2386. * @return mixed Type ID or name, depending on the parameter
  2387. */
  2388. public function get_type_static($lp_id = 0) {
  2389. $tbl_lp = Database :: get_course_table(TABLE_LP_MAIN);
  2390. $sql = "SELECT lp_type FROM $tbl_lp WHERE id = '" . $lp_id . "'";
  2391. $res = Database::query($sql);
  2392. if ($res === false) {
  2393. return null;
  2394. }
  2395. if (Database :: num_rows($res) <= 0) {
  2396. return null;
  2397. }
  2398. $row = Database :: fetch_array($res);
  2399. return $row['lp_type'];
  2400. }
  2401. /**
  2402. * Gets a flat list of item IDs ordered for display (level by level ordered by order_display)
  2403. * This method can be used as abstract and is recursive
  2404. * @param integer Learnpath ID
  2405. * @param integer Parent ID of the items to look for
  2406. * @return mixed Ordered list of item IDs or false on error
  2407. */
  2408. public function get_flat_ordered_items_list($lp, $parent = 0, $course_db = '') {
  2409. //if ($this->debug > 0) { error_log('New LP - In learnpath::get_flat_ordered_items_list('.$lp.','.$parent.')', 0); }
  2410. $list = array();
  2411. if (empty ($lp)) {
  2412. return false;
  2413. }
  2414. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM, $course_db);
  2415. $sql = "SELECT * FROM $tbl_lp_item WHERE lp_id = $lp AND parent_item_id = $parent ORDER BY display_order";
  2416. $res = Database::query($sql);
  2417. while ($row = Database :: fetch_array($res)) {
  2418. $sublist = learnpath :: get_flat_ordered_items_list($lp, $row['id'], $course_db);
  2419. $list[] = $row['id'];
  2420. foreach ($sublist as $item) {
  2421. $list[] = $item;
  2422. }
  2423. }
  2424. return $list;
  2425. }
  2426. /**
  2427. * Uses the table generated by get_toc() and returns an HTML-formatted string ready to display
  2428. * @return string HTML TOC ready to display
  2429. */
  2430. public function get_html_toc() {
  2431. $is_allowed_to_edit = api_is_allowed_to_edit(null, true);
  2432. $charset = api_get_system_encoding();
  2433. $display_action_links_with_icons = false;
  2434. if ($this->debug > 0) {
  2435. error_log('New LP - In learnpath::get_html_toc()', 0);
  2436. }
  2437. $list = $this->get_toc();
  2438. //echo $this->current;
  2439. //$parent = $this->items[$this->current]->get_parent();
  2440. //if (empty($parent)) { $parent = $this->ordered_items[$this->items[$this->current]->get_previous_index()]; }
  2441. $html = '<div id="scorm_title" class="scorm_title"><div class="scorm_title_text">' . Security::remove_XSS($this->get_name()) . '</div></div>';
  2442. // Build, display.
  2443. if ($is_allowed_to_edit) {
  2444. $gradebook = Security :: remove_XSS($_GET['gradebook']);
  2445. //var_dump($this->get_lp_session_id());
  2446. if ($this->get_lp_session_id() == api_get_session_id()) {
  2447. $html .= '<div id="actions_lp" class="actions_lp">';
  2448. if ($display_action_links_with_icons) {
  2449. $html .= '<div style = "text-align:center;">';
  2450. $html .= "<a href='lp_controller.php?" . api_get_cidreq() . "&amp;action=build&amp;lp_id=" . $this->lp_id . "' target='_parent'>" . Display :: return_icon('build_learnpath.png', get_lang('Build'),'','32')."</a>";
  2451. $html .= "<a href='lp_controller.php?" . api_get_cidreq() . "&amp;action=admin_view&amp;lp_id=" . $this->lp_id . "' target='_parent'>" . Display :: return_icon('move_learnpath.png', get_lang('BasicOverview'),'','32')."</a>";
  2452. $html .= '<span>' . Display :: return_icon('view_remove_na.png', get_lang('Display'),'','32').'</span><br />';
  2453. $html .= '<a href="lp_controller.php?' . api_get_cidreq() . '">'. get_lang('ReturnToLPList') . '</a>';
  2454. $html .= '</div>';
  2455. } else {
  2456. $html .= '<div style = "text-align:center;">';
  2457. $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>";
  2458. $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>";
  2459. $html .= '<span><b>' . get_lang('Display') . '</b></span><br />';
  2460. $html .= '<a href="lp_controller.php?' . api_get_cidreq() . '">'. get_lang('ReturnToLPList') . '</a>';
  2461. $html .= '</div>';
  2462. }
  2463. $html .= '</div>';
  2464. }
  2465. }
  2466. $html .= '<div id="inner_lp_toc" class="inner_lp_toc">';
  2467. require_once 'resourcelinker.inc.php';
  2468. // Temporary variables.
  2469. $mycurrentitemid = $this->get_current_item_id();
  2470. $color_counter = 0;
  2471. $i = 0;
  2472. foreach ($list as $item) {
  2473. if ($this->debug > 2) {
  2474. error_log('New LP - learnpath::get_html_toc(): using item ' . $item['id'], 0);
  2475. }
  2476. // TODO: Complete this.
  2477. $icon_name = array (
  2478. 'not attempted' => '../img/notattempted.gif',
  2479. 'incomplete' => '../img/incomplete.png',
  2480. 'failed' => '../img/delete.png',
  2481. 'completed' => '../img/completed.png',
  2482. 'passed' => '../img/passed.png',
  2483. 'succeeded' => '../img/succeeded.png',
  2484. 'browsed' => '../img/completed.png',
  2485. );
  2486. $style = 'scorm_item';
  2487. $scorm_color_background = 'scorm_item';
  2488. $style_item = 'scorm_item';
  2489. $current = false;
  2490. if ($item['id'] == $this->current) {
  2491. $style = 'scorm_item_highlight';
  2492. $scorm_color_background = 'scorm_item_highlight';
  2493. } else
  2494. if ($color_counter % 2 == 0) {
  2495. $scorm_color_background = 'scorm_item_1';
  2496. } else {
  2497. $scorm_color_background = 'scorm_item_2';
  2498. }
  2499. if ($scorm_color_background != '') {
  2500. $html .= '<div id="toc_' . $item['id'] . '" class="' . $scorm_color_background . '">';
  2501. }
  2502. // The anchor will let us center the TOC on the currently viewed item &^D
  2503. if ($item['type'] != 'dokeos_module' && $item['type'] != 'dokeos_chapter') {
  2504. $html .= '<a name="atoc_' . $item['id'] . '" />';
  2505. $html .= '<div class="' . $style_item . '" style="padding-left: ' . ($item['level'] * 1.5) . 'em; padding-right:' . ($item['level'] / 2) . 'em" title="' . $item['description'] . '" >';
  2506. } else {
  2507. $html .= '<div class="' . $style_item . '" style="padding-left: ' . ($item['level'] * 2) . 'em; padding-right:' . ($item['level'] * 1.5) . 'em" title="' . $item['description'] . '" >';
  2508. }
  2509. $title = $item['title'];
  2510. if (empty ($title)) {
  2511. $title = rl_get_resource_name(api_get_course_id(), $this->get_id(), $item['id']);
  2512. }
  2513. $title = Security::remove_XSS($title);
  2514. if ($item['type'] != 'dokeos_chapter' && $item['type'] != 'dir' && $item['type'] != 'dokeos_module') {
  2515. //$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>" ;
  2516. $url = $this->get_link('http', $item['id']);
  2517. //$html .= '<a href="'.$url.'" target="content_name" onClick="top.load_item('.$item['id'].',\''.$url.'\');">'.$title.'</a>' ;
  2518. //$html .= '<a href="" onClick="top.load_item('.$item['id'].',\''.$url.'\');return false;">'.$title.'</a>' ;
  2519. //<img align="absbottom" width="13" height="13" src="../img/lp_document.png">&nbsp;background:#aaa;
  2520. $html .= '<a href="" onClick="switch_item(' .$mycurrentitemid . ',' .$item['id'] . ');' .'return false;" >' . stripslashes($title) . '</a>';
  2521. } elseif ($item['type'] == 'dokeos_module' || $item['type'] == 'dokeos_chapter') {
  2522. $html .= "<img align='absbottom' width='13' height='13' src='../img/lp_dokeos_module.png'>&nbsp;" . stripslashes($title);
  2523. } elseif ($item['type'] == 'dir') {
  2524. $html .= stripslashes($title);
  2525. }
  2526. $tbl_track_e_exercises = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
  2527. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  2528. $user_id = api_get_user_id();
  2529. $course_id = api_get_course_id();
  2530. $sql = "SELECT path FROM $tbl_track_e_exercises, $tbl_lp_item
  2531. WHERE path = '" . $item['path'] . "' AND exe_user_id = '$user_id' AND exe_cours_id = '$course_id' AND path = exe_exo_id AND status <> 'incomplete'";
  2532. $result = Database::query($sql);
  2533. $count = Database :: num_rows($result);
  2534. if ($item['type'] == 'quiz') {
  2535. if ($item['status'] == 'completed') {
  2536. $html .= "&nbsp;<img id='toc_img_" . $item['id'] . "' src='" . $icon_name[$item['status']] . "' alt='" . substr($item['status'], 0, 1) . "' width='14' />";
  2537. }
  2538. } else {
  2539. if ($item['type'] != 'dokeos_chapter' && $item['type'] != 'dokeos_module' && $item['type'] != 'dir') {
  2540. $html .= "&nbsp;<img id='toc_img_" . $item['id'] . "' src='" . $icon_name[$item['status']] . "' alt='" . substr($item['status'], 0, 1) . "' width='14' />";
  2541. }
  2542. }
  2543. $html .= "</div>";
  2544. if ($scorm_color_background != '') {
  2545. $html .= '</div>';
  2546. }
  2547. $color_counter++;
  2548. }
  2549. $html .= "</div>";
  2550. return $html;
  2551. }
  2552. /**
  2553. * Gets the learnpath maker name - generally the editor's name
  2554. * @return string Learnpath maker name
  2555. */
  2556. public function get_maker() {
  2557. if ($this->debug > 0) {
  2558. error_log('New LP - In learnpath::get_maker()', 0);
  2559. }
  2560. if (!empty ($this->maker)) {
  2561. return $this->maker;
  2562. } else {
  2563. return '';
  2564. }
  2565. }
  2566. /**
  2567. * Gets the user-friendly message stored in $this->message
  2568. * @return string Message
  2569. */
  2570. public function get_message() {
  2571. if ($this->debug > 0) {
  2572. error_log('New LP - In learnpath::get_message()', 0);
  2573. }
  2574. return $this->message;
  2575. }
  2576. /**
  2577. * Gets the learnpath name/title
  2578. * @return string Learnpath name/title
  2579. */
  2580. public function get_name() {
  2581. if ($this->debug > 0) {
  2582. error_log('New LP - In learnpath::get_name()', 0);
  2583. }
  2584. if (!empty ($this->name)) {
  2585. return $this->name;
  2586. } else {
  2587. return 'N/A';
  2588. }
  2589. }
  2590. /**
  2591. * Gets a link to the resource from the present location, depending on item ID.
  2592. * @param string Type of link expected
  2593. * @param integer Learnpath item ID
  2594. * @return string Link to the lp_item resource
  2595. */
  2596. public function get_link($type = 'http', $item_id = null) {
  2597. if ($this->debug > 0) {
  2598. error_log('New LP - In learnpath::get_link(' . $type . ',' . $item_id . ')', 0);
  2599. }
  2600. if (empty($item_id)) {
  2601. if ($this->debug > 2) {
  2602. error_log('New LP - In learnpath::get_link() - no item id given in learnpath::get_link(), using current: ' . $this->get_current_item_id(), 0);
  2603. }
  2604. $item_id = $this->get_current_item_id();
  2605. }
  2606. if (empty ($item_id)) {
  2607. if ($this->debug > 2) {
  2608. error_log('New LP - In learnpath::get_link() - no current item id found in learnpath object', 0);
  2609. }
  2610. //still empty, this means there was no item_id given and we are not in an object context or
  2611. //the object property is empty, return empty link
  2612. $item_id = $this->first();
  2613. return '';
  2614. }
  2615. $file = '';
  2616. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  2617. $lp_item_table = Database :: get_course_table(TABLE_LP_ITEM);
  2618. $lp_item_view_table = Database :: get_course_table(TABLE_LP_ITEM_VIEW);
  2619. $item_id = Database::escape_string($item_id);
  2620. $sel = "SELECT l.lp_type as ltype, l.path as lpath, li.item_type as litype, li.path as lipath, li.parameters as liparams " .
  2621. "FROM $lp_table l, $lp_item_table li WHERE li.id = $item_id AND li.lp_id = l.id";
  2622. if ($this->debug > 2) {
  2623. error_log('New LP - In learnpath::get_link() - selecting item ' . $sel, 0);
  2624. }
  2625. $res = Database::query($sel);
  2626. if (Database :: num_rows($res) > 0) {
  2627. $row = Database :: fetch_array($res);
  2628. //var_dump($row);
  2629. $lp_type = $row['ltype'];
  2630. $lp_path = $row['lpath'];
  2631. $lp_item_type = $row['litype'];
  2632. $lp_item_path = $row['lipath'];
  2633. $lp_item_params = $row['liparams'];
  2634. if (empty ($lp_item_params) && strpos($lp_item_path, '?') !== false) {
  2635. list ($lp_item_path, $lp_item_params) = explode('?', $lp_item_path);
  2636. }
  2637. //$lp_item_params = '?'.$lp_item_params;
  2638. //add ? if none - left commented to give freedom to scorm implementation
  2639. //if(substr($lp_item_params,0,1)!='?'){
  2640. // $lp_item_params = '?'.$lp_item_params;
  2641. //}
  2642. $sys_course_path = api_get_path(SYS_COURSE_PATH) . api_get_course_path();
  2643. if ($type == 'http') {
  2644. $course_path = api_get_path(WEB_COURSE_PATH) . api_get_course_path(); //web path
  2645. } else {
  2646. $course_path = $sys_course_path; //system path
  2647. }
  2648. // Fixed issue BT#1272 - If the item type is a Chamilo Item (quiz, link, etc), then change the lp type to thread it as a normal Chamilo LP not a SCO.
  2649. if (in_array($lp_item_type, array('quiz', 'document', 'link', 'forum', 'thread', 'student_publication'))) {
  2650. $lp_type = 1;
  2651. }
  2652. // Now go through the specific cases to get the end of the path.
  2653. // @todo Use constants instead of int values.
  2654. switch ($lp_type) {
  2655. case 1 :
  2656. if ($lp_item_type == 'dokeos_chapter') {
  2657. $file = 'lp_content.php?type=dir';
  2658. } else {
  2659. require_once 'resourcelinker.inc.php';
  2660. $file = rl_get_resource_link_for_learnpath(api_get_course_id(), $this->get_id(), $item_id);
  2661. //CEV CHANGE
  2662. if ($lp_item_type == 'link') {
  2663. require_once api_get_path(LIBRARY_PATH).'link.lib.php';
  2664. if (is_youtube_link($file)) {
  2665. $src = get_youtube_video_id($file);
  2666. $file = 'embed.php?type=youtube&src='.$src;
  2667. }
  2668. } else {
  2669. // check how much attempts of a exercise exits in lp
  2670. $lp_item_id = $this->get_current_item_id();
  2671. $lp_view_id = $this->get_view_id();
  2672. $prevent_reinit = $this->items[$this->current]->get_prevent_reinit();
  2673. $list = $this->get_toc();
  2674. $type_quiz = false;
  2675. foreach ($list as $toc) {
  2676. if ($toc['id'] == $lp_item_id && ($toc['type'] == 'quiz')) {
  2677. $type_quiz = true;
  2678. }
  2679. }
  2680. if ($type_quiz) {
  2681. $lp_item_id = Database :: escape_string($lp_item_id);
  2682. $lp_view_id = Database :: escape_string($lp_view_id);
  2683. $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'";
  2684. $result = Database::query($sql);
  2685. $row_count = Database :: fetch_row($result);
  2686. $count_item_view = (int) $row_count[0];
  2687. $not_multiple_attempt = 0;
  2688. if ($prevent_reinit === 1 && $count_item_view > 0) {
  2689. $not_multiple_attempt = 1;
  2690. }
  2691. $file .= '&not_multiple_attempt=' . $not_multiple_attempt;
  2692. }
  2693. $tmp_array = explode('/', $file);
  2694. $document_name = $tmp_array[count($tmp_array) - 1];
  2695. if (strpos($document_name, '_DELETED_')) {
  2696. $file = 'blank.php?error=document_deleted';
  2697. }
  2698. }
  2699. }
  2700. break;
  2701. case 2 :
  2702. if ($this->debug > 2) {
  2703. error_log('New LP - In learnpath::get_link() ' . __LINE__ . ' - Item type: ' . $lp_item_type, 0);
  2704. }
  2705. if ($lp_item_type != 'dir') {
  2706. // Quite complex here:
  2707. // We want to make sure 'http://' (and similar) links can
  2708. // be loaded as is (withouth the Chamilo path in front) but
  2709. // some contents use this form: resource.htm?resource=http://blablabla
  2710. // which means we have to find a protocol at the path's start, otherwise
  2711. // it should not be considered as an external URL.
  2712. //if ($this->prerequisites_match($item_id)) {
  2713. if (preg_match('#^[a-zA-Z]{2,5}://#', $lp_item_path) != 0) {
  2714. if ($this->debug > 2) {
  2715. error_log('New LP - In learnpath::get_link() ' . __LINE__ . ' - Found match for protocol in ' . $lp_item_path, 0);
  2716. }
  2717. // Distant url, return as is.
  2718. $file = $lp_item_path;
  2719. } else {
  2720. if ($this->debug > 2) {
  2721. error_log('New LP - In learnpath::get_link() ' . __LINE__ . ' - No starting protocol in ' . $lp_item_path, 0);
  2722. }
  2723. // Prevent getting untranslatable urls.
  2724. $lp_item_path = preg_replace('/%2F/', '/', $lp_item_path);
  2725. $lp_item_path = preg_replace('/%3A/', ':', $lp_item_path);
  2726. // Prepare the path.
  2727. $file = $course_path . '/scorm/' . $lp_path . '/' . $lp_item_path;
  2728. // TODO: Fix this for urls with protocol header.
  2729. $file = str_replace('//', '/', $file);
  2730. $file = str_replace(':/', '://', $file);
  2731. if (substr($lp_path, -1) == '/') {
  2732. $lp_path = substr($lp_path, 0, -1);
  2733. }
  2734. if (!is_file(realpath($sys_course_path . '/scorm/' . $lp_path . '/' . $lp_item_path))) {
  2735. // if file not found.
  2736. $decoded = html_entity_decode($lp_item_path);
  2737. list ($decoded) = explode('?', $decoded);
  2738. if (!is_file(realpath($sys_course_path . '/scorm/' . $lp_path . '/' . $decoded))) {
  2739. require_once 'resourcelinker.inc.php';
  2740. $file = rl_get_resource_link_for_learnpath(api_get_course_id(), $this->get_id(), $item_id);
  2741. if (empty($file)) {
  2742. $file = 'blank.php?error=document_not_found';
  2743. } else {
  2744. $tmp_array = explode('/', $file);
  2745. $document_name = $tmp_array[count($tmp_array) - 1];
  2746. if (strpos($document_name, '_DELETED_')) {
  2747. $file = 'blank.php?error=document_deleted';
  2748. } else {
  2749. $file = 'blank.php?error=document_not_found';
  2750. }
  2751. }
  2752. } else {
  2753. $file = $course_path . '/scorm/' . $lp_path . '/' . $decoded;
  2754. }
  2755. }
  2756. }
  2757. //}else{
  2758. //prerequisites did not match
  2759. //$file = 'blank.php';
  2760. //}
  2761. // We want to use parameters if they were defined in the imsmanifest.
  2762. if ($file != 'blank.php') {
  2763. $file .= (strstr($file, '?') === false ? '?' : '') . $lp_item_params;
  2764. }
  2765. } else {
  2766. $file = 'lp_content.php?type=dir';
  2767. }
  2768. break;
  2769. case 3 :
  2770. if ($this->debug > 2) {
  2771. error_log('New LP - In learnpath::get_link() ' . __LINE__ . ' - Item type: ' . $lp_item_type, 0);
  2772. }
  2773. // Formatting AICC HACP append URL.
  2774. $aicc_append = '?aicc_sid=' . urlencode(session_id()) . '&aicc_url=' . urlencode(api_get_path(WEB_CODE_PATH) . 'newscorm/aicc_hacp.php') . '&';
  2775. if ($lp_item_type != 'dir') {
  2776. // Quite complex here:
  2777. // We want to make sure 'http://' (and similar) links can
  2778. // be loaded as is (withouth the Chamilo path in front) but
  2779. // some contents use this form: resource.htm?resource=http://blablabla
  2780. // which means we have to find a protocol at the path's start, otherwise
  2781. // it should not be considered as an external URL.
  2782. if (preg_match('#^[a-zA-Z]{2,5}://#', $lp_item_path) != 0) {
  2783. if ($this->debug > 2) {
  2784. error_log('New LP - In learnpath::get_link() ' . __LINE__ . ' - Found match for protocol in ' . $lp_item_path, 0);
  2785. }
  2786. // Distant url, return as is.
  2787. $file = $lp_item_path;
  2788. // Enabled and modified by Ivan Tcholakov, 16-OCT-2008.
  2789. /*
  2790. if (stristr($file,'<servername>') !== false) {
  2791. $file = str_replace('<servername>', $course_path.'/scorm/'.$lp_path.'/', $lp_item_path);
  2792. }
  2793. */
  2794. if (stripos($file, '<servername>') !== false) {
  2795. //$file = str_replace('<servername>',$course_path.'/scorm/'.$lp_path.'/',$lp_item_path);
  2796. $web_course_path = str_replace('https://', '', str_replace('http://', '', $course_path));
  2797. $file = str_replace('<servername>', $web_course_path . '/scorm/' . $lp_path, $lp_item_path);
  2798. }
  2799. //
  2800. $file .= $aicc_append;
  2801. } else {
  2802. if ($this->debug > 2) {
  2803. error_log('New LP - In learnpath::get_link() ' . __LINE__ . ' - No starting protocol in ' . $lp_item_path, 0);
  2804. }
  2805. // Prevent getting untranslatable urls.
  2806. $lp_item_path = preg_replace('/%2F/', '/', $lp_item_path);
  2807. $lp_item_path = preg_replace('/%3A/', ':', $lp_item_path);
  2808. // Prepare the path - lp_path might be unusable because it includes the "aicc" subdir name.
  2809. $file = $course_path . '/scorm/' . $lp_path . '/' . $lp_item_path;
  2810. // TODO: Fix this for urls with protocol header.
  2811. $file = str_replace('//', '/', $file);
  2812. $file = str_replace(':/', '://', $file);
  2813. $file .= $aicc_append;
  2814. }
  2815. } else {
  2816. $file = 'lp_content.php?type=dir';
  2817. }
  2818. break;
  2819. case 4 :
  2820. break;
  2821. default :
  2822. break;
  2823. }
  2824. }
  2825. if ($this->debug > 2) {
  2826. error_log('New LP - In learnpath::get_link() - returning "' . $file . '" from get_link', 0);
  2827. }
  2828. return $file;
  2829. }
  2830. /**
  2831. * Gets the latest usable view or generate a new one
  2832. * @param integer Optional attempt number. If none given, takes the highest from the lp_view table
  2833. * @return integer DB lp_view id
  2834. */
  2835. public function get_view($attempt_num = 0) {
  2836. if ($this->debug > 0) {
  2837. error_log('New LP - In learnpath::get_view()', 0);
  2838. }
  2839. $search = '';
  2840. // Use $attempt_num to enable multi-views management (disabled so far).
  2841. if ($attempt_num != 0 AND intval(strval($attempt_num)) == $attempt_num) {
  2842. $search = 'AND view_count = ' . $attempt_num;
  2843. }
  2844. // When missing $attempt_num, search for a unique lp_view record for this lp and user.
  2845. $lp_view_table = Database :: get_course_table(TABLE_LP_VIEW);
  2846. $sql = "SELECT id, view_count FROM $lp_view_table " .
  2847. "WHERE lp_id = " . $this->get_id() . " " .
  2848. "AND user_id = " . $this->get_user_id() . " " .
  2849. $search .
  2850. " ORDER BY view_count DESC";
  2851. $res = Database::query($sql);
  2852. if (Database :: num_rows($res) > 0) {
  2853. $row = Database :: fetch_array($res);
  2854. $this->lp_view_id = $row['id'];
  2855. } else {
  2856. // There is no database record, create one.
  2857. $sql = "INSERT INTO $lp_view_table(lp_id,user_id,view_count)" .
  2858. "VALUES (" . $this->get_id() . "," . $this->get_user_id() . ",1)";
  2859. $res = Database::query($sql);
  2860. $id = Database :: insert_id();
  2861. $this->lp_view_id = $id;
  2862. }
  2863. return $this->lp_view_id;
  2864. }
  2865. /**
  2866. * Gets the current view id
  2867. * @return integer View ID (from lp_view)
  2868. */
  2869. public function get_view_id() {
  2870. if ($this->debug > 0) {
  2871. error_log('New LP - In learnpath::get_view_id()', 0);
  2872. }
  2873. if (!empty ($this->lp_view_id)) {
  2874. return $this->lp_view_id;
  2875. } else {
  2876. return 0;
  2877. }
  2878. }
  2879. /**
  2880. * Gets the update queue
  2881. * @return array Array containing IDs of items to be updated by JavaScript
  2882. */
  2883. public function get_update_queue() {
  2884. if ($this->debug > 0) {
  2885. error_log('New LP - In learnpath::get_update_queue()', 0);
  2886. }
  2887. return $this->update_queue;
  2888. }
  2889. /**
  2890. * Gets the user ID
  2891. * @return integer User ID
  2892. */
  2893. public function get_user_id() {
  2894. if ($this->debug > 0) {
  2895. error_log('New LP - In learnpath::get_user_id()', 0);
  2896. }
  2897. if (!empty ($this->user_id)) {
  2898. return $this->user_id;
  2899. } else {
  2900. return false;
  2901. }
  2902. }
  2903. /**
  2904. * Checks if any of the items has an audio element attached
  2905. * @return bool True or false
  2906. */
  2907. public function has_audio() {
  2908. if ($this->debug > 1) {
  2909. error_log('New LP - In learnpath::has_audio()', 0);
  2910. }
  2911. $has = false;
  2912. foreach ($this->items as $i => $item) {
  2913. if (!empty ($this->items[$i]->audio)) {
  2914. $has = true;
  2915. break;
  2916. }
  2917. }
  2918. return $has;
  2919. }
  2920. /**
  2921. * Logs a message into a file
  2922. * @param string Message to log
  2923. * @return boolean True on success, false on error or if msg empty
  2924. */
  2925. public function log($msg) {
  2926. if ($this->debug > 0) {
  2927. error_log('New LP - In learnpath::log()', 0);
  2928. }
  2929. // TODO
  2930. $this->error .= $msg;
  2931. return true;
  2932. }
  2933. /**
  2934. * Moves an item up and down at its level
  2935. * @param integer Item to move up and down
  2936. * @param string Direction 'up' or 'down'
  2937. * @return integer New display order, or false on error
  2938. */
  2939. public function move_item($id, $direction) {
  2940. if ($this->debug > 0) {
  2941. error_log('New LP - In learnpath::move_item(' . $id . ',' . $direction . ')', 0);
  2942. }
  2943. if (empty ($id) or empty ($direction)) {
  2944. return false;
  2945. }
  2946. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  2947. $sql_sel = "
  2948. SELECT *
  2949. FROM " . $tbl_lp_item . "
  2950. WHERE id = " . $id;
  2951. $res_sel = Database::query($sql_sel);
  2952. // Check if elem exists.
  2953. if (Database :: num_rows($res_sel) < 1) {
  2954. return false;
  2955. }
  2956. // Gather data.
  2957. $row = Database :: fetch_array($res_sel);
  2958. $previous = $row['previous_item_id'];
  2959. $next = $row['next_item_id'];
  2960. $display = $row['display_order'];
  2961. $parent = $row['parent_item_id'];
  2962. $lp = $row['lp_id'];
  2963. // Update the item (switch with previous/next one).
  2964. switch ($direction) {
  2965. case 'up' :
  2966. if ($this->debug > 2) {
  2967. error_log('Movement up detected', 0);
  2968. }
  2969. if ($display <= 1) { /*do nothing*/
  2970. } else {
  2971. $sql_sel2 = "SELECT *
  2972. FROM $tbl_lp_item
  2973. WHERE id = $previous";
  2974. if ($this->debug > 2) {
  2975. error_log('Selecting previous: ' . $sql_sel2, 0);
  2976. }
  2977. $res_sel2 = Database::query($sql_sel2);
  2978. if (Database :: num_rows($res_sel2) < 1) {
  2979. $previous_previous = 0;
  2980. }
  2981. // Gather data.
  2982. $row2 = Database :: fetch_array($res_sel2);
  2983. $previous_previous = $row2['previous_item_id'];
  2984. // Update previous_previous item (switch "next" with current).
  2985. if ($previous_previous != 0) {
  2986. $sql_upd2 = "UPDATE $tbl_lp_item SET next_item_id = $id WHERE id = $previous_previous";
  2987. if ($this->debug > 2) {
  2988. error_log($sql_upd2, 0);
  2989. }
  2990. $res_upd2 = Database::query($sql_upd2);
  2991. }
  2992. // Update previous item (switch with current).
  2993. if ($previous != 0) {
  2994. $sql_upd2 = "UPDATE $tbl_lp_item SET next_item_id = $next, previous_item_id = $id, display_order = display_order +1 WHERE id = $previous";
  2995. if ($this->debug > 2) {
  2996. error_log($sql_upd2, 0);
  2997. }
  2998. $res_upd2 = Database::query($sql_upd2);
  2999. }
  3000. // Update current item (switch with previous).
  3001. if ($id != 0) {
  3002. $sql_upd2 = "UPDATE $tbl_lp_item SET next_item_id = $previous, previous_item_id = $previous_previous, display_order = display_order-1 WHERE id = $id";
  3003. if ($this->debug > 2) {
  3004. error_log($sql_upd2, 0);
  3005. }
  3006. $res_upd2 = Database::query($sql_upd2);
  3007. }
  3008. // Update next item (new previous item).
  3009. if ($next != 0) {
  3010. $sql_upd2 = "UPDATE $tbl_lp_item SET previous_item_id = $previous WHERE id = $next";
  3011. if ($this->debug > 2) {
  3012. error_log($sql_upd2, 0);
  3013. }
  3014. $res_upd2 = Database::query($sql_upd2);
  3015. }
  3016. $display = $display -1;
  3017. }
  3018. break;
  3019. case 'down' :
  3020. if ($this->debug > 2) {
  3021. error_log('Movement down detected', 0);
  3022. }
  3023. if ($next == 0) { /* Do nothing. */
  3024. } else {
  3025. $sql_sel2 = "SELECT * FROM $tbl_lp_item WHERE id = $next";
  3026. if ($this->debug > 2) {
  3027. error_log('Selecting next: ' . $sql_sel2, 0);
  3028. }
  3029. $res_sel2 = Database::query($sql_sel2);
  3030. if (Database :: num_rows($res_sel2) < 1) {
  3031. $next_next = 0;
  3032. }
  3033. // Gather data.
  3034. $row2 = Database :: fetch_array($res_sel2);
  3035. $next_next = $row2['next_item_id'];
  3036. // Update previous item (switch with current).
  3037. if ($previous != 0) {
  3038. $sql_upd2 = "UPDATE $tbl_lp_item SET next_item_id = $next WHERE id = $previous";
  3039. $res_upd2 = Database::query($sql_upd2);
  3040. }
  3041. // Update current item (switch with previous).
  3042. if ($id != 0) {
  3043. $sql_upd2 = "UPDATE $tbl_lp_item SET previous_item_id = $next, next_item_id = $next_next, display_order = display_order+1 WHERE id = $id";
  3044. $res_upd2 = Database::query($sql_upd2);
  3045. }
  3046. // Update next item (new previous item).
  3047. if ($next != 0) {
  3048. $sql_upd2 = "UPDATE $tbl_lp_item SET previous_item_id = $previous, next_item_id = $id, display_order = display_order-1 WHERE id = $next";
  3049. $res_upd2 = Database::query($sql_upd2);
  3050. }
  3051. // Update next_next item (switch "previous" with current).
  3052. if ($next_next != 0) {
  3053. $sql_upd2 = "UPDATE $tbl_lp_item SET previous_item_id = $id WHERE id = $next_next";
  3054. $res_upd2 = Database::query($sql_upd2);
  3055. }
  3056. $display = $display +1;
  3057. }
  3058. break;
  3059. default :
  3060. return false;
  3061. }
  3062. return $display;
  3063. }
  3064. /**
  3065. * Move a learnpath up (display_order)
  3066. * @param integer Learnpath ID
  3067. */
  3068. public function move_up($lp_id) {
  3069. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3070. $sql = "SELECT * FROM $lp_table ORDER BY display_order";
  3071. $res = Database::query($sql);
  3072. if ($res === false)
  3073. return false;
  3074. $lps = array ();
  3075. $lp_order = array ();
  3076. $num = Database :: num_rows($res);
  3077. // First check the order is correct, globally (might be wrong because
  3078. // of versions < 1.8.4)
  3079. if ($num > 0) {
  3080. $i = 1;
  3081. while ($row = Database :: fetch_array($res)) {
  3082. if ($row['display_order'] != $i) { // If we find a gap in the order, we need to fix it.
  3083. $need_fix = true;
  3084. $sql_u = "UPDATE $lp_table SET display_order = $i WHERE id = " . $row['id'];
  3085. $res_u = Database::query($sql_u);
  3086. }
  3087. $row['display_order'] = $i;
  3088. $lps[$row['id']] = $row;
  3089. $lp_order[$i] = $row['id'];
  3090. $i++;
  3091. }
  3092. }
  3093. if ($num > 1) { // If there's only one element, no need to sort.
  3094. $order = $lps[$lp_id]['display_order'];
  3095. if ($order > 1) { // If it's the first element, no need to move up.
  3096. $sql_u1 = "UPDATE $lp_table SET display_order = $order WHERE id = " . $lp_order[$order - 1];
  3097. $res_u1 = Database::query($sql_u1);
  3098. $sql_u2 = "UPDATE $lp_table SET display_order = " . ($order - 1) . " WHERE id = " . $lp_id;
  3099. $res_u2 = Database::query($sql_u2);
  3100. }
  3101. }
  3102. }
  3103. /**
  3104. * Move a learnpath down (display_order)
  3105. * @param integer Learnpath ID
  3106. */
  3107. public function move_down($lp_id) {
  3108. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3109. $sql = "SELECT * FROM $lp_table ORDER BY display_order";
  3110. $res = Database::query($sql);
  3111. if ($res === false)
  3112. return false;
  3113. $lps = array ();
  3114. $lp_order = array ();
  3115. $num = Database :: num_rows($res);
  3116. $max = 0;
  3117. // First check the order is correct, globally (might be wrong because
  3118. // of versions < 1.8.4).
  3119. if ($num > 0) {
  3120. $i = 1;
  3121. while ($row = Database :: fetch_array($res)) {
  3122. $max = $i;
  3123. if ($row['display_order'] != $i) { // If we find a gap in the order, we need to fix it.
  3124. $need_fix = true;
  3125. $sql_u = "UPDATE $lp_table SET display_order = $i WHERE id = " . $row['id'];
  3126. $res_u = Database::query($sql_u);
  3127. }
  3128. $row['display_order'] = $i;
  3129. $lps[$row['id']] = $row;
  3130. $lp_order[$i] = $row['id'];
  3131. $i++;
  3132. }
  3133. }
  3134. if ($num > 1) { // If there's only one element, no need to sort.
  3135. $order = $lps[$lp_id]['display_order'];
  3136. if ($order < $max) { // If it's the first element, no need to move up.
  3137. $sql_u1 = "UPDATE $lp_table SET display_order = $order WHERE id = " . $lp_order[$order + 1];
  3138. $res_u1 = Database::query($sql_u1);
  3139. $sql_u2 = "UPDATE $lp_table SET display_order = " . ($order + 1) . " WHERE id = " . $lp_id;
  3140. $res_u2 = Database::query($sql_u2);
  3141. }
  3142. }
  3143. }
  3144. /**
  3145. * Updates learnpath attributes to point to the next element
  3146. * The last part is similar to set_current_item but processing the other way around
  3147. */
  3148. public function next() {
  3149. if ($this->debug > 0) {
  3150. error_log('New LP - In learnpath::next()', 0);
  3151. }
  3152. $this->last = $this->get_current_item_id();
  3153. $this->items[$this->last]->save(false, $this->prerequisites_match($this->last));
  3154. $this->autocomplete_parents($this->last);
  3155. $new_index = $this->get_next_index();
  3156. if ($this->debug > 2) {
  3157. error_log('New LP - New index: ' . $new_index, 0);
  3158. }
  3159. $this->index = $new_index;
  3160. if ($this->debug > 2) {
  3161. error_log('New LP - Now having orderedlist[' . $new_index . '] = ' . $this->ordered_items[$new_index], 0);
  3162. }
  3163. $this->current = $this->ordered_items[$new_index];
  3164. if ($this->debug > 2) {
  3165. error_log('New LP - new item id is ' . $this->current . '-' . $this->get_current_item_id(), 0);
  3166. }
  3167. }
  3168. /**
  3169. * Open a resource = initialise all local variables relative to this resource. Depending on the child
  3170. * class, this might be redefined to allow several behaviours depending on the document type.
  3171. * @param integer Resource ID
  3172. * @return boolean True on success, false otherwise
  3173. */
  3174. public function open($id) {
  3175. if ($this->debug > 0) {
  3176. error_log('New LP - In learnpath::open()', 0);
  3177. }
  3178. // TODO:
  3179. // set the current resource attribute to this resource
  3180. // switch on element type (redefine in child class?)
  3181. // set status for this item to "opened"
  3182. // start timer
  3183. // initialise score
  3184. $this->index = 0; //or = the last item seen (see $this->last)
  3185. }
  3186. /**
  3187. * Check that all prerequisites are fulfilled. Returns true and an empty string on succes, returns false
  3188. * and the prerequisite string on error.
  3189. * This function is based on the rules for aicc_script language as described in the SCORM 1.2 CAM documentation page 108.
  3190. * @param integer Optional item ID. If none given, uses the current open item.
  3191. * @return boolean True if prerequisites are matched, false otherwise
  3192. * @return string Empty string if true returned, prerequisites string otherwise.
  3193. */
  3194. public function prerequisites_match($item = null) {
  3195. if ($this->debug > 0) {
  3196. error_log('New LP - In learnpath::prerequisites_match()', 0);
  3197. }
  3198. if (empty ($item)) {
  3199. $item = $this->current;
  3200. }
  3201. if (is_object($this->items[$item])) {
  3202. $prereq_string = $this->items[$item]->get_prereq_string();
  3203. if (empty ($prereq_string)) {
  3204. return true;
  3205. }
  3206. // Clean spaces.
  3207. $prereq_string = str_replace(' ', '', $prereq_string);
  3208. if ($this->debug > 0) {
  3209. error_log('Found prereq_string: ' . $prereq_string, 0);
  3210. }
  3211. // Now send to the parse_prereq() function that will check this component's prerequisites.
  3212. $result = $this->items[$item]->parse_prereq($prereq_string, $this->items, $this->refs_list, $this->get_user_id());
  3213. if ($result === false) {
  3214. $this->set_error_msg($this->items[$item]->prereq_alert);
  3215. }
  3216. } else {
  3217. $result = true;
  3218. if ($this->debug > 1) {
  3219. error_log('New LP - $this->items[' . $item . '] was not an object', 0);
  3220. }
  3221. }
  3222. if ($this->debug > 1) {
  3223. error_log('New LP - End of prerequisites_match(). Error message is now ' . $this->error, 0);
  3224. }
  3225. return $result;
  3226. }
  3227. /**
  3228. * Updates learnpath attributes to point to the previous element
  3229. * The last part is similar to set_current_item but processing the other way around
  3230. */
  3231. public function previous() {
  3232. if ($this->debug > 0) {
  3233. error_log('New LP - In learnpath::previous()', 0);
  3234. }
  3235. $this->last = $this->get_current_item_id();
  3236. $this->items[$this->last]->save(false, $this->prerequisites_match($this->last));
  3237. $this->autocomplete_parents($this->last);
  3238. $new_index = $this->get_previous_index();
  3239. $this->index = $new_index;
  3240. $this->current = $this->ordered_items[$new_index];
  3241. }
  3242. /**
  3243. * Publishes a learnpath. This basically means show or hide the learnpath
  3244. * to normal users.
  3245. * Can be used as abstract
  3246. * @param integer Learnpath ID
  3247. * @param string New visibility
  3248. */
  3249. public function toggle_visibility($lp_id, $set_visibility = 1) {
  3250. //if ($this->debug > 0) { error_log('New LP - In learnpath::toggle_visibility()', 0); }
  3251. $action = 'visible';
  3252. if ($set_visibility != 1) {
  3253. $action = 'invisible';
  3254. }
  3255. return api_item_property_update(api_get_course_info(), TOOL_LEARNPATH, $lp_id, $action, api_get_user_id());
  3256. }
  3257. /**
  3258. * Publishes a learnpath. This basically means show or hide the learnpath
  3259. * on the course homepage
  3260. * Can be used as abstract
  3261. * @param integer Learnpath id
  3262. * @param string New visibility (v/s - visible/invisible)
  3263. */
  3264. public function toggle_publish($lp_id, $set_visibility = 'v') {
  3265. //if ($this->debug > 0) { error_log('New LP - In learnpath::toggle_publish()', 0); }
  3266. $tbl_lp = Database :: get_course_table(TABLE_LP_MAIN);
  3267. $sql = "SELECT * FROM $tbl_lp where id=$lp_id";
  3268. $result = Database::query($sql);
  3269. $row = Database :: fetch_array($result);
  3270. $name = domesticate($row['name']);
  3271. if ($set_visibility == 'i') {
  3272. $s = $name . " " . get_lang('_no_published');
  3273. $dialogBox = $s;
  3274. $v = 0;
  3275. }
  3276. if ($set_visibility == 'v') {
  3277. $s = $name . " " . get_lang('_published');
  3278. $dialogBox = $s;
  3279. $v = 1;
  3280. }
  3281. $session_id = api_get_session_id();
  3282. $session_condition = api_get_session_condition($session_id);
  3283. $tbl_tool = Database :: get_course_table(TABLE_TOOL_LIST);
  3284. $link = 'newscorm/lp_controller.php?action=view&lp_id=' . $lp_id.'&id_session='.$session_id;
  3285. $sql = "SELECT * FROM $tbl_tool where name='$name' and image='scormbuilder.gif' and link LIKE '$link%' $session_condition";
  3286. $result = Database::query($sql);
  3287. $num = Database :: num_rows($result);
  3288. $row2 = Database :: fetch_array($result);
  3289. //if ($this->debug > 2) { error_log('New LP - '.$sql.' - '.$num, 0); }
  3290. if (($set_visibility == 'i') && ($num > 0)) {
  3291. $sql = "DELETE FROM $tbl_tool WHERE (name='$name' and image='scormbuilder.gif' and link LIKE '$link%' $session_condition)";
  3292. } elseif (($set_visibility == 'v') && ($num == 0)) {
  3293. $sql = "INSERT INTO $tbl_tool (name, link, image, visibility, admin, address, added_tool, session_id) VALUES ('$name','$link','scormbuilder.gif','$v','0','pastillegris.gif',0, $session_id)";
  3294. } else {
  3295. // Parameter and database incompatible, do nothing.
  3296. }
  3297. $result = Database::query($sql);
  3298. //if ($this->debug > 2) { error_log('New LP - Leaving learnpath::toggle_visibility: '.$sql, 0); }
  3299. }
  3300. /**
  3301. * Restart the whole learnpath. Return the URL of the first element.
  3302. * Make sure the results are saved with anoter method. This method should probably be
  3303. * redefined in children classes.
  3304. * To use a similar method statically, use the create_new_attempt() method
  3305. * @return string URL to load in the viewer
  3306. */
  3307. public function restart() {
  3308. if ($this->debug > 0) {
  3309. error_log('New LP - In learnpath::restart()', 0);
  3310. }
  3311. // TODO
  3312. // Call autosave method to save the current progress.
  3313. //$this->index = 0;
  3314. $session_id = api_get_session_id();
  3315. $lp_view_table = Database :: get_course_table(TABLE_LP_VIEW);
  3316. $sql = "INSERT INTO $lp_view_table (lp_id, user_id, view_count, session_id) " .
  3317. "VALUES (" . $this->lp_id . "," . $this->get_user_id() . "," . ($this->attempt + 1) . ", $session_id)";
  3318. if ($this->debug > 2) {
  3319. error_log('New LP - Inserting new lp_view for restart: ' . $sql, 0);
  3320. }
  3321. $res = Database::query($sql);
  3322. if ($view_id = Database :: insert_id($res)) {
  3323. $this->lp_view_id = $view_id;
  3324. $this->attempt = $this->attempt + 1;
  3325. } else {
  3326. $this->error = 'Could not insert into item_view table...';
  3327. return false;
  3328. }
  3329. $this->autocomplete_parents($this->current);
  3330. foreach ($this->items as $index => $dummy) {
  3331. $this->items[$index]->restart();
  3332. $this->items[$index]->set_lp_view($this->lp_view_id);
  3333. }
  3334. $this->first();
  3335. return true;
  3336. }
  3337. /**
  3338. * Saves the current item
  3339. * @return boolean
  3340. */
  3341. public function save_current() {
  3342. if ($this->debug > 0) {
  3343. error_log('New LP - In learnpath::save_current()', 0);
  3344. }
  3345. // TODO: Do a better check on the index pointing to the right item (it is supposed to be working
  3346. // on $ordered_items[] but not sure it's always safe to use with $items[]).
  3347. if ($this->debug > 2) {
  3348. error_log('New LP - save_current() saving item ' . $this->current, 0);
  3349. }
  3350. if ($this->debug > 2) {
  3351. error_log('' . print_r($this->items, true), 0);
  3352. }
  3353. if (is_object($this->items[$this->current])) {
  3354. //$res = $this->items[$this->current]->save(false);
  3355. $res = $this->items[$this->current]->save(false, $this->prerequisites_match($this->current));
  3356. $this->autocomplete_parents($this->current);
  3357. $status = $this->items[$this->current]->get_status();
  3358. $this->append_message('new_item_status: ' . $status);
  3359. $this->update_queue[$this->current] = $status;
  3360. return $res;
  3361. }
  3362. return false;
  3363. }
  3364. /**
  3365. * Saves the given item
  3366. * @param integer Item ID. Optional (will take from $_REQUEST if null)
  3367. * @param boolean Save from url params (true) or from current attributes (false). Optional. Defaults to true
  3368. * @return boolean
  3369. */
  3370. public function save_item($item_id = null, $from_outside = true) {
  3371. if ($this->debug > 0) {
  3372. error_log('New LP - In learnpath::save_item(' . $item_id . ',' . $from_outside . ')', 0);
  3373. }
  3374. // TODO: Do a better check on the index pointing to the right item (it is supposed to be working
  3375. // on $ordered_items[] but not sure it's always safe to use with $items[]).
  3376. if (empty ($item_id)) {
  3377. $item_id = $this->escape_string($_REQUEST['id']);
  3378. }
  3379. if (empty ($item_id)) {
  3380. $item_id = $this->get_current_item_id();
  3381. }
  3382. if ($this->debug > 2) {
  3383. error_log('New LP - save_current() saving item ' . $item_id, 0);
  3384. }
  3385. if (is_object($this->items[$item_id])) {
  3386. $res = $this->items[$item_id]->save($from_outside, $this->prerequisites_match($item_id));
  3387. //$res = $this->items[$item_id]->save($from_outside);
  3388. $this->autocomplete_parents($item_id);
  3389. $status = $this->items[$item_id]->get_status();
  3390. $this->append_message('new_item_status: ' . $status);
  3391. $this->update_queue[$item_id] = $status;
  3392. return $res;
  3393. }
  3394. return false;
  3395. }
  3396. /**
  3397. * Saves the last item seen's ID only in case
  3398. */
  3399. public function save_last() {
  3400. if ($this->debug > 0) {
  3401. error_log('New LP - In learnpath::save_last()', 0);
  3402. }
  3403. $session_condition = api_get_session_condition(api_get_session_id(), true, false);
  3404. $table = Database :: get_course_table(TABLE_LP_VIEW);
  3405. if (isset ($this->current)) {
  3406. if ($this->debug > 2) {
  3407. error_log('New LP - Saving current item (' . $this->current . ') for later review', 0);
  3408. }
  3409. $sql = "UPDATE $table SET last_item = " . Database::escape_string($this->get_current_item_id()). " " .
  3410. "WHERE lp_id = " . $this->get_id() . " AND user_id = " . $this->get_user_id().' '.$session_condition;
  3411. if ($this->debug > 2) {
  3412. error_log('New LP - Saving last item seen : ' . $sql, 0);
  3413. }
  3414. $res = Database::query($sql);
  3415. }
  3416. // Save progress.
  3417. list($progress, $text) = $this->get_progress_bar_text('%');
  3418. if ($progress >= 0 && $progress <= 100) {
  3419. $progress = (int) $progress;
  3420. $sql = "UPDATE $table SET progress = $progress " .
  3421. "WHERE lp_id = " . $this->get_id() . " AND " .
  3422. "user_id = " . $this->get_user_id().' '.$session_condition;
  3423. $res = Database::query($sql); // Ignore errors as some tables might not have the progress field just yet.
  3424. $this->progress_db = $progress;
  3425. }
  3426. }
  3427. /**
  3428. * Sets the current item ID (checks if valid and authorized first)
  3429. * @param integer New item ID. If not given or not authorized, defaults to current
  3430. */
  3431. public function set_current_item($item_id = null) {
  3432. if ($this->debug > 0) {
  3433. error_log('New LP - In learnpath::set_current_item(' . $item_id . ')', 0);
  3434. }
  3435. if (empty ($item_id)) {
  3436. if ($this->debug > 2) {
  3437. error_log('New LP - No new current item given, ignore...', 0);
  3438. }
  3439. // Do nothing.
  3440. } else {
  3441. if ($this->debug > 2) {
  3442. error_log('New LP - New current item given is ' . $item_id . '...', 0);
  3443. }
  3444. if (is_numeric($item_id)) {
  3445. $item_id = $this->escape_string($item_id);
  3446. // TODO: Check in database here.
  3447. $this->last = $this->current;
  3448. $this->current = $item_id;
  3449. // TODO: Update $this->index as well.
  3450. foreach ($this->ordered_items as $index => $item) {
  3451. if ($item == $this->current) {
  3452. $this->index = $index;
  3453. break;
  3454. }
  3455. }
  3456. if ($this->debug > 2) {
  3457. error_log('New LP - set_current_item(' . $item_id . ') done. Index is now : ' . $this->index, 0);
  3458. }
  3459. } else {
  3460. error_log('New LP - set_current_item(' . $item_id . ') failed. Not a numeric value: ', 0);
  3461. }
  3462. }
  3463. }
  3464. /**
  3465. * Sets the encoding
  3466. * @param string New encoding
  3467. * TODO (as of Chamilo 1.8.8): Check in the future whether this method is needed.
  3468. */
  3469. public function set_encoding($enc = 'UTF-8') {
  3470. if ($this->debug > 0) {
  3471. error_log('New LP - In learnpath::set_encoding()', 0);
  3472. }
  3473. /* // Deprecated code (Chamilo 1.8.8).
  3474. $enc = strtoupper($enc);
  3475. $encodings = array (
  3476. 'UTF-8',
  3477. 'ISO-8859-1',
  3478. 'ISO-8859-15',
  3479. 'cp1251',
  3480. 'cp1252',
  3481. 'KOI8-R',
  3482. 'BIG5',
  3483. 'GB2312',
  3484. 'Shift_JIS',
  3485. 'EUC-JP',
  3486. ''
  3487. );
  3488. if (in_array($enc, $encodings)) { // TODO: Incorrect comparison, fix it.
  3489. $lp = $this->get_id();
  3490. if ($lp != 0) {
  3491. $tbl_lp = Database :: get_course_table(TABLE_LP_MAIN);
  3492. $sql = "UPDATE $tbl_lp SET default_encoding = '$enc' WHERE id = " . $lp;
  3493. $res = Database::query($sql);
  3494. return $res;
  3495. }
  3496. }
  3497. return false;
  3498. */
  3499. $enc = api_refine_encoding_id($enc);
  3500. if (empty($enc)) {
  3501. $enc = api_get_system_encoding();
  3502. }
  3503. if (api_is_encoding_supported($enc)) {
  3504. $lp = $this->get_id();
  3505. if ($lp != 0) {
  3506. $tbl_lp = Database :: get_course_table(TABLE_LP_MAIN);
  3507. $sql = "UPDATE $tbl_lp SET default_encoding = '$enc' WHERE id = " . $lp;
  3508. $res = Database::query($sql);
  3509. return $res;
  3510. }
  3511. }
  3512. return false;
  3513. }
  3514. /**
  3515. * Sets the JS lib setting in the database directly.
  3516. * This is the JavaScript library file this lp needs to load on startup
  3517. * @param string Proximity setting
  3518. * @return boolean True on update success. False otherwise.
  3519. */
  3520. public function set_jslib($lib = '') {
  3521. if ($this->debug > 0) {
  3522. error_log('New LP - In learnpath::set_jslib()', 0);
  3523. }
  3524. $lp = $this->get_id();
  3525. if ($lp != 0) {
  3526. $tbl_lp = Database :: get_course_table(TABLE_LP_MAIN);
  3527. $sql = "UPDATE $tbl_lp SET js_lib = '$lib' WHERE id = " . $lp;
  3528. $res = Database::query($sql);
  3529. return $res;
  3530. } else {
  3531. return false;
  3532. }
  3533. }
  3534. /**
  3535. * Sets the name of the LP maker (publisher) (and save)
  3536. * @param string Optional string giving the new content_maker of this learnpath
  3537. * @return boolean True
  3538. */
  3539. public function set_maker($name = '') {
  3540. if ($this->debug > 0) {
  3541. error_log('New LP - In learnpath::set_maker()', 0);
  3542. }
  3543. if (empty ($name))
  3544. return false;
  3545. $this->maker = $this->escape_string($name);
  3546. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3547. $lp_id = $this->get_id();
  3548. $sql = "UPDATE $lp_table SET content_maker = '" . $this->maker . "' WHERE id = '$lp_id'";
  3549. if ($this->debug > 2) {
  3550. error_log('New LP - lp updated with new content_maker : ' . $this->maker, 0);
  3551. }
  3552. $res = Database::query($sql);
  3553. return true;
  3554. }
  3555. /**
  3556. * Sets the name of the current learnpath (and save)
  3557. * @param string Optional string giving the new name of this learnpath
  3558. * @return boolean True/False
  3559. */
  3560. public function set_name($name = '') {
  3561. if ($this->debug > 0) {
  3562. error_log('New LP - In learnpath::set_name()', 0);
  3563. }
  3564. if (empty ($name))
  3565. return false;
  3566. $this->name = $this->escape_string($name);
  3567. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3568. $lp_id = $this->get_id();
  3569. $sql = "UPDATE $lp_table SET name = '" . $this->name . "' WHERE id = '$lp_id'";
  3570. if ($this->debug > 2) {
  3571. error_log('New LP - lp updated with new name : ' . $this->name, 0);
  3572. }
  3573. $res = Database::query($sql);
  3574. // If the lp is visible on the homepage, change his name there.
  3575. if (Database::affected_rows()) {
  3576. $table = Database :: get_course_table(TABLE_TOOL_LIST);
  3577. $sql = 'UPDATE ' . $table . ' SET
  3578. name = "' . $this->name . '"
  3579. WHERE link = "newscorm/lp_controller.php?action=view&lp_id=' . $lp_id . '"';
  3580. Database::query($sql);
  3581. }
  3582. return true;
  3583. }
  3584. /**
  3585. * Set index specified prefix terms for all items in this path
  3586. * @param string Comma-separated list of terms
  3587. * @param char Xapian term prefix
  3588. * @return boolean False on error, true otherwise
  3589. */
  3590. public function set_terms_by_prefix($terms_string, $prefix) {
  3591. if (api_get_setting('search_enabled') !== 'true')
  3592. return false;
  3593. if (!extension_loaded('xapian')) {
  3594. return false;
  3595. }
  3596. $terms_string = trim($terms_string);
  3597. $terms = explode(',', $terms_string);
  3598. array_walk($terms, 'trim_value');
  3599. $stored_terms = $this->get_common_index_terms_by_prefix($prefix);
  3600. //var_dump($stored_terms);
  3601. //var_dump($terms);
  3602. // Don't do anything if no change, verify only at DB, not the search engine.
  3603. if ((count(array_diff($terms, $stored_terms)) == 0) && (count(array_diff($stored_terms, $terms)) == 0))
  3604. return false;
  3605. require_once 'xapian.php'; // TODO: Try catch every xapian use or make wrappers on API.
  3606. require_once api_get_path(LIBRARY_PATH).'search/DokeosIndexer.class.php';
  3607. require_once api_get_path(LIBRARY_PATH).'search/xapian/XapianQuery.php';
  3608. require_once api_get_path(LIBRARY_PATH).'search/IndexableChunk.class.php';
  3609. $items_table = Database :: get_course_table(TABLE_LP_ITEM);
  3610. // TODO: Make query secure agains XSS : use member attr instead of post var.
  3611. $lp_id = intval($_POST['lp_id']);
  3612. $sql = "SELECT * FROM $items_table WHERE lp_id = $lp_id";
  3613. $result = Database::query($sql);
  3614. $di = new DokeosIndexer();
  3615. while ($lp_item = Database :: fetch_array($result)) {
  3616. // Get search_did.
  3617. $tbl_se_ref = Database :: get_main_table(TABLE_MAIN_SEARCH_ENGINE_REF);
  3618. $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';
  3619. $sql = sprintf($sql, $tbl_se_ref, $this->cc, TOOL_LEARNPATH, $lp_id, $lp_item['id']);
  3620. //echo $sql; echo '<br>';
  3621. $res = Database::query($sql);
  3622. if (Database::num_rows($res) > 0) {
  3623. $se_ref = Database :: fetch_array($res);
  3624. // Compare terms.
  3625. $doc = $di->get_document($se_ref['search_did']);
  3626. $xapian_terms = xapian_get_doc_terms($doc, $prefix);
  3627. $xterms = array ();
  3628. foreach ($xapian_terms as $xapian_term) {
  3629. $xterms[] = substr($xapian_term['name'], 1);
  3630. }
  3631. $dterms = $terms;
  3632. $missing_terms = array_diff($dterms, $xterms);
  3633. $deprecated_terms = array_diff($xterms, $dterms);
  3634. // Save it to search engine.
  3635. foreach ($missing_terms as $term) {
  3636. $doc->add_term($prefix . $term, 1);
  3637. }
  3638. foreach ($deprecated_terms as $term) {
  3639. $doc->remove_term($prefix . $term);
  3640. }
  3641. $di->getDb()->replace_document((int) $se_ref['search_did'], $doc);
  3642. $di->getDb()->flush();
  3643. } else {
  3644. //@todo What we should do here?
  3645. }
  3646. }
  3647. return true;
  3648. }
  3649. /**
  3650. * Sets the theme of the LP (local/remote) (and save)
  3651. * @param string Optional string giving the new theme of this learnpath
  3652. * @return bool Returns true if theme name is not empty
  3653. */
  3654. public function set_theme($name = '') {
  3655. if ($this->debug > 0) {
  3656. error_log('New LP - In learnpath::set_theme()', 0);
  3657. }
  3658. $this->theme = $this->escape_string($name);
  3659. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3660. $lp_id = $this->get_id();
  3661. $sql = "UPDATE $lp_table SET theme = '" . $this->theme . "' WHERE id = '$lp_id'";
  3662. if ($this->debug > 2) {
  3663. error_log('New LP - lp updated with new theme : ' . $this->theme, 0);
  3664. }
  3665. //$res = Database::query($sql);
  3666. $res = Database::query($sql);
  3667. return true;
  3668. }
  3669. /**
  3670. * Sets the image of an LP (and save)
  3671. * @param string Optional string giving the new image of this learnpath
  3672. * @return bool Returns true if theme name is not empty
  3673. */
  3674. public function set_preview_image($name = '') {
  3675. if ($this->debug > 0) {
  3676. error_log('New LP - In learnpath::set_preview_image()', 0);
  3677. }
  3678. $this->preview_image = $this->escape_string($name);
  3679. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3680. $lp_id = $this->get_id();
  3681. $sql = "UPDATE $lp_table SET preview_image = '" . $this->preview_image . "' WHERE id = '$lp_id'";
  3682. if ($this->debug > 2) {
  3683. error_log('New LP - lp updated with new preview image : ' . $this->preview_image, 0);
  3684. }
  3685. $res = Database::query($sql);
  3686. return true;
  3687. }
  3688. /**
  3689. * Sets the author of a LP (and save)
  3690. * @param string Optional string giving the new author of this learnpath
  3691. * @return bool Returns true if author's name is not empty
  3692. */
  3693. public function set_author($name = '') {
  3694. if ($this->debug > 0) {
  3695. error_log('New LP - In learnpath::set_author()', 0);
  3696. }
  3697. $this->author = $this->escape_string($name);
  3698. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3699. $lp_id = $this->get_id();
  3700. $sql = "UPDATE $lp_table SET author = '" . $this->author . "' WHERE id = '$lp_id'";
  3701. if ($this->debug > 2) {
  3702. error_log('New LP - lp updated with new preview author : ' . $this->author, 0);
  3703. }
  3704. $res = Database::query($sql);
  3705. return true;
  3706. }
  3707. /**
  3708. * Sets the prerequisite of a LP (and save)
  3709. * @param int integer giving the new prerequisite of this learnpath
  3710. * @return bool returns true if prerequisite is not empty
  3711. */
  3712. public function set_prerequisite($prerequisite) {
  3713. if ($this->debug > 0) {
  3714. error_log('New LP - In learnpath::set_prerequisite()', 0);
  3715. }
  3716. $this->prerequisite = intval($prerequisite);
  3717. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3718. $lp_id = $this->get_id();
  3719. $sql = "UPDATE $lp_table SET prerequisite = '".$this->prerequisite."' WHERE id = '$lp_id'";
  3720. if ($this->debug > 2) {
  3721. error_log('New LP - lp updated with new preview requisite : ' . $this->requisite, 0);
  3722. }
  3723. $res = Database::query($sql);
  3724. return true;
  3725. }
  3726. /**
  3727. * Sets the location/proximity of the LP (local/remote) (and save)
  3728. * @param string Optional string giving the new location of this learnpath
  3729. * @return boolean True on success / False on error
  3730. */
  3731. public function set_proximity($name = '') {
  3732. if ($this->debug > 0) {
  3733. error_log('New LP - In learnpath::set_proximity()', 0);
  3734. }
  3735. if (empty ($name))
  3736. return false;
  3737. $this->proximity = $this->escape_string($name);
  3738. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3739. $lp_id = $this->get_id();
  3740. $sql = "UPDATE $lp_table SET content_local = '" . $this->proximity . "' WHERE id = '$lp_id'";
  3741. if ($this->debug > 2) {
  3742. error_log('New LP - lp updated with new proximity : ' . $this->proximity, 0);
  3743. }
  3744. $res = Database::query($sql);
  3745. return true;
  3746. }
  3747. /**
  3748. * Sets the previous item ID to a given ID. Generally, this should be set to the previous 'current' item
  3749. * @param integer DB ID of the item
  3750. */
  3751. public function set_previous_item($id) {
  3752. if ($this->debug > 0) {
  3753. error_log('New LP - In learnpath::set_previous_item()', 0);
  3754. }
  3755. $this->last = $id;
  3756. }
  3757. /**
  3758. * Sets use_max_score
  3759. * @param string Optional string giving the new location of this learnpath
  3760. * @return boolean True on success / False on error
  3761. */
  3762. public function set_use_max_score($use_max_score = 1) {
  3763. if ($this->debug > 0) {
  3764. error_log('New LP - In learnpath::set_use_max_score()', 0);
  3765. }
  3766. $use_max_score = intval($use_max_score);
  3767. $this->use_max_score = $use_max_score;
  3768. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3769. $lp_id = $this->get_id();
  3770. $sql = "UPDATE $lp_table SET use_max_score = '" . $this->use_max_score . "' WHERE id = '$lp_id'";
  3771. if ($this->debug > 2) {
  3772. error_log('New LP - lp updated with new use_max_score : ' . $this->use_max_score, 0);
  3773. }
  3774. $res = Database::query($sql);
  3775. return true;
  3776. }
  3777. /**
  3778. * Sets and saves the expired_on date
  3779. * @param string Optional string giving the new author of this learnpath
  3780. * @return bool Returns true if author's name is not empty
  3781. */
  3782. public function set_expired_on($expired_on) {
  3783. if ($this->debug > 0) {
  3784. error_log('New LP - In learnpath::set_expired_on()', 0);
  3785. }
  3786. if (!empty($expired_on)) {
  3787. $this->expired_on = $this->escape_string(api_get_utc_datetime($expired_on));
  3788. } else {
  3789. $this->expired_on = '';
  3790. }
  3791. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3792. $lp_id = $this->get_id();
  3793. $sql = "UPDATE $lp_table SET expired_on = '" . $this->expired_on . "' WHERE id = '$lp_id'";
  3794. if ($this->debug > 2) {
  3795. error_log('New LP - lp updated with new expired_on : ' . $this->expired_on, 0);
  3796. }
  3797. $res = Database::query($sql);
  3798. return true;
  3799. }
  3800. /**
  3801. * Sets and saves the publicated_on date
  3802. * @param string Optional string giving the new author of this learnpath
  3803. * @return bool Returns true if author's name is not empty
  3804. */
  3805. public function set_publicated_on($publicated_on) {
  3806. if ($this->debug > 0) {
  3807. error_log('New LP - In learnpath::set_expired_on()', 0);
  3808. }
  3809. if (!empty($publicated_on)) {
  3810. $this->publicated_on = $this->escape_string(api_get_utc_datetime($publicated_on));
  3811. } else {
  3812. $this->publicated_on = '';
  3813. }
  3814. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3815. $lp_id = $this->get_id();
  3816. $sql = "UPDATE $lp_table SET publicated_on = '" . $this->publicated_on . "' WHERE id = '$lp_id'";
  3817. if ($this->debug > 2) {
  3818. error_log('New LP - lp updated with new publicated_on : ' . $this->publicated_on, 0);
  3819. }
  3820. $res = Database::query($sql);
  3821. return true;
  3822. }
  3823. /**
  3824. * Sets and saves the expired_on date
  3825. * @param string Optional string giving the new author of this learnpath
  3826. * @return bool Returns true if author's name is not empty
  3827. */
  3828. public function set_modified_on() {
  3829. if ($this->debug > 0) {
  3830. error_log('New LP - In learnpath::set_expired_on()', 0);
  3831. }
  3832. $this->modified_on = api_get_utc_datetime();
  3833. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3834. $lp_id = $this->get_id();
  3835. $sql = "UPDATE $lp_table SET modified_on = '" . $this->modified_on . "' WHERE id = '$lp_id'";
  3836. if ($this->debug > 2) {
  3837. error_log('New LP - lp updated with new expired_on : ' . $this->modified_on, 0);
  3838. }
  3839. $res = Database::query($sql);
  3840. return true;
  3841. }
  3842. /**
  3843. * Sets the object's error message
  3844. * @param string Error message. If empty, reinits the error string
  3845. * @return void
  3846. */
  3847. public function set_error_msg($error = '') {
  3848. if ($this->debug > 0) {
  3849. error_log('New LP - In learnpath::set_error_msg()', 0);
  3850. }
  3851. if (empty ($error)) {
  3852. $this->error = '';
  3853. } else {
  3854. $this->error .= $error;
  3855. }
  3856. }
  3857. /**
  3858. * Launches the current item if not 'sco' (starts timer and make sure there is a record ready in the DB)
  3859. * @param boolean Whether to allow a new attempt or not
  3860. * @return boolean True
  3861. */
  3862. public function start_current_item($allow_new_attempt = false) {
  3863. if ($this->debug > 0) {
  3864. error_log('New LP - In learnpath::start_current_item()', 0);
  3865. }
  3866. if ($this->current != 0 AND is_object($this->items[$this->current])) {
  3867. $type = $this->get_type();
  3868. $item_type = $this->items[$this->current]->get_type();
  3869. if (($type == 2 && $item_type != 'sco') OR ($type == 3 && $item_type != 'au') OR ($type == 1 && $item_type != TOOL_QUIZ && $item_type != TOOL_HOTPOTATOES)) {
  3870. $this->items[$this->current]->open($allow_new_attempt);
  3871. $this->autocomplete_parents($this->current);
  3872. $prereq_check = $this->prerequisites_match($this->current);
  3873. $this->items[$this->current]->save(false, $prereq_check);
  3874. //$this->update_queue[$this->last] = $this->items[$this->last]->get_status();
  3875. } else {
  3876. // If sco, then it is supposed to have been updated by some other call.
  3877. }
  3878. if ($item_type == 'sco') {
  3879. $this->items[$this->current]->restart();
  3880. }
  3881. }
  3882. if ($this->debug > 0) {
  3883. error_log('New LP - End of learnpath::start_current_item()', 0);
  3884. }
  3885. return true;
  3886. }
  3887. /**
  3888. * Stops the processing and counters for the old item (as held in $this->last)
  3889. * @return boolean True/False
  3890. */
  3891. public function stop_previous_item() {
  3892. if ($this->debug > 0) {
  3893. error_log('New LP - In learnpath::stop_previous_item()', 0);
  3894. }
  3895. if ($this->last != 0 && $this->last != $this->current && is_object($this->items[$this->last])) {
  3896. if ($this->debug > 2) {
  3897. error_log('New LP - In learnpath::stop_previous_item() - ' . $this->last . ' is object', 0);
  3898. }
  3899. switch ($this->get_type()) {
  3900. case '3' :
  3901. if ($this->items[$this->last]->get_type() != 'au') {
  3902. if ($this->debug > 2) {
  3903. error_log('New LP - In learnpath::stop_previous_item() - ' . $this->last . ' in lp_type 3 is <> au', 0);
  3904. }
  3905. $this->items[$this->last]->close();
  3906. //$this->autocomplete_parents($this->last);
  3907. //$this->update_queue[$this->last] = $this->items[$this->last]->get_status();
  3908. } else {
  3909. if ($this->debug > 2) {
  3910. error_log('New LP - In learnpath::stop_previous_item() - Item is an AU, saving is managed by AICC signals', 0);
  3911. }
  3912. }
  3913. case '2' :
  3914. if ($this->items[$this->last]->get_type() != 'sco') {
  3915. if ($this->debug > 2) {
  3916. error_log('New LP - In learnpath::stop_previous_item() - ' . $this->last . ' in lp_type 2 is <> sco', 0);
  3917. }
  3918. $this->items[$this->last]->close();
  3919. //$this->autocomplete_parents($this->last);
  3920. //$this->update_queue[$this->last] = $this->items[$this->last]->get_status();
  3921. } else {
  3922. if ($this->debug > 2) {
  3923. error_log('New LP - In learnpath::stop_previous_item() - Item is a SCO, saving is managed by SCO signals', 0);
  3924. }
  3925. }
  3926. break;
  3927. case '1' :
  3928. default :
  3929. if ($this->debug > 2) {
  3930. error_log('New LP - In learnpath::stop_previous_item() - ' . $this->last . ' in lp_type 1 is asset', 0);
  3931. }
  3932. $this->items[$this->last]->close();
  3933. break;
  3934. }
  3935. } else {
  3936. if ($this->debug > 2) {
  3937. error_log('New LP - In learnpath::stop_previous_item() - No previous element found, ignoring...', 0);
  3938. }
  3939. return false;
  3940. }
  3941. return true;
  3942. }
  3943. /**
  3944. * Updates the default view mode from fullscreen to embedded and inversely
  3945. * @return string The current default view mode ('fullscreen' or 'embedded')
  3946. */
  3947. public function update_default_view_mode() {
  3948. if ($this->debug > 0) {
  3949. error_log('New LP - In learnpath::update_default_view_mode()', 0);
  3950. }
  3951. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3952. $sql = "SELECT * FROM $lp_table WHERE id = " . $this->get_id();
  3953. $res = Database::query($sql);
  3954. if (Database :: num_rows($res) > 0) {
  3955. $row = Database :: fetch_array($res);
  3956. $view_mode = $row['default_view_mod'];
  3957. if ($view_mode == 'fullscreen') {
  3958. $view_mode = 'embedded';
  3959. } elseif ($view_mode == 'embedded') {
  3960. $view_mode = 'embedframe';
  3961. } elseif ($view_mode == 'embedframe') {
  3962. $view_mode = 'fullscreen';
  3963. }
  3964. $sql = "UPDATE $lp_table SET default_view_mod = '$view_mode' WHERE id = " . $this->get_id();
  3965. $res = Database::query($sql);
  3966. $this->mode = $view_mode;
  3967. return $view_mode;
  3968. } else {
  3969. if ($this->debug > 2) {
  3970. error_log('New LP - Problem in update_default_view() - could not find LP ' . $this->get_id() . ' in DB', 0);
  3971. }
  3972. }
  3973. return -1;
  3974. }
  3975. /**
  3976. * Updates the default behaviour about auto-commiting SCORM updates
  3977. * @return boolean True if auto-commit has been set to 'on', false otherwise
  3978. */
  3979. public function update_default_scorm_commit() {
  3980. if ($this->debug > 0) {
  3981. error_log('New LP - In learnpath::update_default_scorm_commit()', 0);
  3982. }
  3983. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3984. $sql = "SELECT * FROM $lp_table WHERE id = " . $this->get_id();
  3985. $res = Database::query($sql);
  3986. if (Database :: num_rows($res) > 0) {
  3987. $row = Database :: fetch_array($res);
  3988. $force = $row['force_commit'];
  3989. if ($force == 1) {
  3990. $force = 0;
  3991. $force_return = false;
  3992. } elseif ($force == 0) {
  3993. $force = 1;
  3994. $force_return = true;
  3995. }
  3996. $sql = "UPDATE $lp_table SET force_commit = $force WHERE id = " . $this->get_id();
  3997. $res = Database::query($sql);
  3998. $this->force_commit = $force_return;
  3999. return $force_return;
  4000. } else {
  4001. if ($this->debug > 2) {
  4002. error_log('New LP - Problem in update_default_scorm_commit() - could not find LP ' . $this->get_id() . ' in DB', 0);
  4003. }
  4004. }
  4005. return -1;
  4006. }
  4007. /**
  4008. * Updates the order of learning paths (goes through all of them by order and fills the gaps)
  4009. * @return bool True on success, false on failure
  4010. */
  4011. public function update_display_order() {
  4012. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  4013. $sql = "SELECT * FROM $lp_table ORDER BY display_order";
  4014. $res = Database::query($sql);
  4015. if ($res === false)
  4016. return false;
  4017. $lps = array ();
  4018. $lp_order = array ();
  4019. $num = Database :: num_rows($res);
  4020. // First check the order is correct, globally (might be wrong because
  4021. // of versions < 1.8.4).
  4022. if ($num > 0) {
  4023. $i = 1;
  4024. while ($row = Database :: fetch_array($res)) {
  4025. if ($row['display_order'] != $i) { // If we find a gap in the order, we need to fix it.
  4026. $need_fix = true;
  4027. $sql_u = "UPDATE $lp_table SET display_order = $i WHERE id = " . $row['id'];
  4028. $res_u = Database::query($sql_u);
  4029. }
  4030. $i++;
  4031. }
  4032. }
  4033. return true;
  4034. }
  4035. /**
  4036. * Updates the "prevent_reinit" value that enables control on reinitialising items on second view
  4037. * @return boolean True if prevent_reinit has been set to 'on', false otherwise (or 1 or 0 in this case)
  4038. */
  4039. public function update_reinit() {
  4040. if ($this->debug > 0) {
  4041. error_log('New LP - In learnpath::update_reinit()', 0);
  4042. }
  4043. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  4044. $sql = "SELECT * FROM $lp_table WHERE id = " . $this->get_id();
  4045. $res = Database::query($sql);
  4046. if (Database :: num_rows($res) > 0) {
  4047. $row = Database :: fetch_array($res);
  4048. $force = $row['prevent_reinit'];
  4049. if ($force == 1) {
  4050. $force = 0;
  4051. } elseif ($force == 0) {
  4052. $force = 1;
  4053. }
  4054. $sql = "UPDATE $lp_table SET prevent_reinit = $force WHERE id = " . $this->get_id();
  4055. $res = Database::query($sql);
  4056. $this->prevent_reinit = $force;
  4057. return $force;
  4058. } else {
  4059. if ($this->debug > 2) {
  4060. error_log('New LP - Problem in update_reinit() - could not find LP ' . $this->get_id() . ' in DB', 0);
  4061. }
  4062. }
  4063. return -1;
  4064. }
  4065. /**
  4066. * Updates the "scorm_debug" value that shows or hide the debug window
  4067. * @return boolean True if scorm_debug has been set to 'on', false otherwise (or 1 or 0 in this case)
  4068. */
  4069. public function update_scorm_debug() {
  4070. if ($this->debug > 0) {
  4071. error_log('New LP - In learnpath::update_scorm_debug()', 0);
  4072. }
  4073. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  4074. $sql = "SELECT * FROM $lp_table WHERE id = " . $this->get_id();
  4075. $res = Database::query($sql);
  4076. if (Database :: num_rows($res) > 0) {
  4077. $row = Database :: fetch_array($res);
  4078. $force = $row['debug'];
  4079. if ($force == 1) {
  4080. $force = 0;
  4081. } elseif ($force == 0) {
  4082. $force = 1;
  4083. }
  4084. $sql = "UPDATE $lp_table SET debug = $force WHERE id = " . $this->get_id();
  4085. $res = Database::query($sql);
  4086. $this->scorm_debug = $force;
  4087. return $force;
  4088. } else {
  4089. if ($this->debug > 2) {
  4090. error_log('New LP - Problem in update_scorm_debug() - could not find LP ' . $this->get_id() . ' in DB', 0);
  4091. }
  4092. }
  4093. return -1;
  4094. }
  4095. /**
  4096. * Function that makes a call to the function sort_tree_array and create_tree_array
  4097. * @author Kevin Van Den Haute
  4098. * @param array
  4099. */
  4100. public function tree_array($array) {
  4101. if ($this->debug > 1) {
  4102. error_log('New LP - In learnpath::tree_array()', 0);
  4103. }
  4104. $array = $this->sort_tree_array($array);
  4105. $this->create_tree_array($array);
  4106. }
  4107. /**
  4108. * Creates an array with the elements of the learning path tree in it
  4109. *
  4110. * @author Kevin Van Den Haute
  4111. * @param array $array
  4112. * @param int $parent
  4113. * @param int $depth
  4114. * @param array $tmp
  4115. */
  4116. public function create_tree_array($array, $parent = 0, $depth = -1, $tmp = array ()) {
  4117. if ($this->debug > 1) {
  4118. error_log('New LP - In learnpath::create_tree_array())', 0);
  4119. }
  4120. if (is_array($array)) {
  4121. for ($i = 0; $i < count($array); $i++) {
  4122. if ($array[$i]['parent_item_id'] == $parent) {
  4123. if (!in_array($array[$i]['parent_item_id'], $tmp)) {
  4124. $tmp[] = $array[$i]['parent_item_id'];
  4125. $depth++;
  4126. }
  4127. $preq = (empty($array[$i]['prerequisite']) ? '' : $array[$i]['prerequisite']);
  4128. $this->arrMenu[] = array (
  4129. 'id' => $array[$i]['id'],
  4130. 'item_type' => $array[$i]['item_type'],
  4131. 'title' => $array[$i]['title'],
  4132. 'path' => $array[$i]['path'],
  4133. 'description' => $array[$i]['description'],
  4134. 'parent_item_id' => $array[$i]['parent_item_id'],
  4135. 'previous_item_id' => $array[$i]['previous_item_id'],
  4136. 'next_item_id' => $array[$i]['next_item_id'],
  4137. 'min_score' => $array[$i]['min_score'],
  4138. 'max_score' => $array[$i]['max_score'],
  4139. 'mastery_score' => $array[$i]['mastery_score'],
  4140. 'display_order' => $array[$i]['display_order'],
  4141. 'prerequisite' => $preq,
  4142. 'depth' => $depth,
  4143. 'audio' => $array[$i]['audio']
  4144. );
  4145. $this->create_tree_array($array, $array[$i]['id'], $depth, $tmp);
  4146. }
  4147. }
  4148. }
  4149. }
  4150. /**
  4151. * Sorts a multi dimensional array by parent id and display order
  4152. * @author Kevin Van Den Haute
  4153. *
  4154. * @param array $array (array with al the learning path items in it)
  4155. *
  4156. * @return array
  4157. */
  4158. public function sort_tree_array($array) {
  4159. foreach ($array as $key => $row) {
  4160. $parent[$key] = $row['parent_item_id'];
  4161. $position[$key] = $row['display_order'];
  4162. }
  4163. if (count($array) > 0)
  4164. array_multisort($parent, SORT_ASC, $position, SORT_ASC, $array);
  4165. return $array;
  4166. }
  4167. /**
  4168. * Function that creates a table structure with a learning path his modules, chapters and documents.
  4169. * Also the actions for the modules, chapters and documents are in this table.
  4170. * @author Kevin Van Den Haute
  4171. * @param int $lp_id
  4172. * @return string
  4173. */
  4174. public function overview() {
  4175. $is_allowed_to_edit = api_is_allowed_to_edit(null,true);
  4176. if ($this->debug > 0) {
  4177. error_log('New LP - In learnpath::overview()', 0);
  4178. }
  4179. global $charset, $_course;
  4180. $_SESSION['gradebook'] = Security :: remove_XSS($_GET['gradebook']);
  4181. $return = '';
  4182. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  4183. $sql = "SELECT * FROM " . $tbl_lp_item . "
  4184. WHERE lp_id = " . $this->lp_id;
  4185. $result = Database::query($sql);
  4186. $arrLP = array ();
  4187. while ($row = Database :: fetch_array($result)) {
  4188. $row['title'] = Security :: remove_XSS($row['title']);
  4189. $row['description'] = Security :: remove_XSS($row['description']);
  4190. $arrLP[] = array (
  4191. 'id' => $row['id'],
  4192. 'item_type' => $row['item_type'],
  4193. 'title' => $row['title'],
  4194. 'path' => $row['path'],
  4195. 'description' => $row['description'],
  4196. 'parent_item_id' => $row['parent_item_id'],
  4197. 'previous_item_id' => $row['previous_item_id'],
  4198. 'next_item_id' => $row['next_item_id'],
  4199. 'max_score' => $row['max_score'],
  4200. 'min_score' => $row['min_score'],
  4201. 'mastery_score' => $row['mastery_score'],
  4202. 'prerequisite' => $row['prerequisite'],
  4203. 'display_order' => $row['display_order'],
  4204. 'audio' => $row['audio']
  4205. );
  4206. }
  4207. $this->tree_array($arrLP);
  4208. $arrLP = $this->arrMenu;
  4209. unset ($this->arrMenu);
  4210. if ($is_allowed_to_edit) {
  4211. $token = Security::get_token();
  4212. $gradebook = Security :: remove_XSS($_GET['gradebook']);
  4213. $return .= '<div class="actions">';
  4214. $return .= '<a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&amp;gradebook=' . $gradebook . '&amp;action=build&amp;lp_id=' . $this->lp_id . '" title="' . get_lang('Build') . '">' . Display :: return_icon('build_learnpath.png', get_lang('Build'),'','32').'</a>';
  4215. if ($_GET['updateaudio'] == 'true') {
  4216. $return .='<a href="lp_controller.php?cidReq='.Security::remove_XSS($_GET['cidReq']) .'&amp;gradebook='.$gradebook.'&amp;action=admin_view&amp;lp_id=' . $_SESSION['oLP']->lp_id . '" title="'.get_lang('BasicOverview').'">'.Display::return_icon('move_learnpath.png', get_lang('BasicOverview'),'','32').'</a>';
  4217. } else {
  4218. $return .= '<span>' . Display :: return_icon('move_learnpath_na.png', get_lang('BasicOverview'),'','32').'</span>';
  4219. }
  4220. $return .= '<a href="lp_controller.php?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&action=view&lp_id=' . $this->lp_id . '">' . Display :: return_icon('view_left_right.png', get_lang('Display'),'','32').'</a>';
  4221. $return .= ' '.Display :: return_icon('i.gif');
  4222. $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') . '">
  4223. '. Display :: return_icon('new_learnigpath_object.png', get_lang('NewStep'),'','32').'</a>';
  4224. $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') . '">
  4225. '. Display :: return_icon('add_learnpath_section.png', get_lang('NewChapter'),'','32').'</a>';
  4226. if ($_GET['updateaudio'] == 'true') {
  4227. $return .= Display::url(Display :: return_icon('upload_audio_na.png', get_lang('UpdateAllAudioFragments'),'','32'),'#');
  4228. } else {
  4229. $return .= '<a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&amp;action=' . Security :: remove_XSS($_GET['action']) . '&amp;lp_id=' . $_SESSION['oLP']->lp_id . '&amp;updateaudio=true">' . Display :: return_icon('upload_audio.png', get_lang('UpdateAllAudioFragments'),'','32').'</a>';
  4230. }
  4231. $return .= '<a href="lp_controller.php?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&amp;action=edit&amp;lp_id=' . $_SESSION['oLP']->lp_id . '">' . Display :: return_icon('settings.png', get_lang('CourseSettings'),'','32').'</a>';
  4232. $return .= '</div>';
  4233. }
  4234. // we need to start a form when we want to update all the mp3 files
  4235. if ($_GET['updateaudio'] == 'true' AND count($arrLP) <> 0) {
  4236. $return .= '<form action="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&amp;action=' . Security :: remove_XSS($_GET['action']) . '&amp;lp_id=' . $_SESSION['oLP']->lp_id . '" method="post" enctype="multipart/form-data" name="updatemp3" id="updatemp3">';
  4237. $return .= Display::return_message(get_lang('LeaveEmptyToKeepCurrentFile'), 'warning');
  4238. }
  4239. $return .= '<table class="data_table">';
  4240. $return .= '<tr>';
  4241. $return .= '<th width="60%">' . get_lang('Title') . '</th>';
  4242. //$return .= '<th>'.get_lang('Description').'</th>';
  4243. $return .= '<th>' . get_lang('Audio') . '</th>';
  4244. if (!$_GET['updateaudio'] OR $_GET['updateaudio'] <> 'true') {
  4245. $return .= '<th>' . get_lang('Move') . '</th>';
  4246. }
  4247. $return .= '<th>' . get_lang('Actions') . '</th>';
  4248. $return .= '</tr>';
  4249. for ($i = 0; $i < count($arrLP); $i++) {
  4250. $title = $arrLP[$i]['title'];
  4251. if ($arrLP[$i]['description'] == '')
  4252. $arrLP[$i]['description'] = '&nbsp;';
  4253. if (($i % 2) == 0) {
  4254. $oddclass = 'row_odd';
  4255. } else {
  4256. $oddclass = 'row_even';
  4257. }
  4258. $return .= '<tr class="' . $oddclass . '">';
  4259. $icon_name = str_replace(' ', '', $arrLP[$i]['item_type']);
  4260. if (file_exists('../img/lp_' . $icon_name . '.png')) {
  4261. $return .= '<td style="padding-left:' . $arrLP[$i]['depth'] * 10 . 'px;"><img align="left" src="../img/lp_' . $icon_name . '.png" style="margin-right:3px;" />' . $title . '</td>';
  4262. } else {
  4263. if (file_exists('../img/lp_' . $icon_name . '.gif')) {
  4264. $return .= '<td style="padding-left:' . $arrLP[$i]['depth'] * 10 . 'px;"><img align="left" src="../img/lp_' . $icon_name . '.gif" style="margin-right:3px;" />' . $title . '</td>';
  4265. } else {
  4266. //$return .= '<td style="padding-left:' . $arrLP[$i]['depth'] * 10 . 'px;">' . Display::display_icon('folder_document.gif','',array('style'=>'margin-right:3px;')) . $title . '</td>';
  4267. $return .= '<td style="padding-left:' . $arrLP[$i]['depth'] * 10 . 'px;"><img align="left" src="../img/folder_document.gif" style="margin-right:3px;" />' . $title . '</td>';
  4268. }
  4269. }
  4270. //$return .= '<td>' . stripslashes($arrLP[$i]['description']) . '</td>';
  4271. // The audio column.
  4272. $return .= '<td align="center">';
  4273. if (!$_GET['updateaudio'] OR $_GET['updateaudio'] <> 'true') {
  4274. if (!empty ($arrLP[$i]['audio'])) {
  4275. $return .= '<span id="container' . $i . '"><a href="http://www.macromedia.com/go/getflashplayer">Get the Flash Player</a> to see this player.</span>';
  4276. $return .= '<script type="text/javascript" src="../inc/lib/mediaplayer/swfobject.js"></script>';
  4277. $return .= '<script type="text/javascript">
  4278. var s1 = new SWFObject("../inc/lib/mediaplayer/player.swf","ply","250","20","9","#FFFFFF");
  4279. s1.addParam("allowscriptaccess","always");
  4280. s1.addParam("flashvars","file=../../courses/' . $_course['path'] . '/document/audio/' . $arrLP[$i]['audio'] . '");
  4281. s1.write("container' . $i . '");
  4282. </script>';
  4283. } else {
  4284. $return .= ' - ';
  4285. }
  4286. } else {
  4287. if ($arrLP[$i]['item_type'] != 'dokeos_chapter' && $arrLP[$i]['item_type'] != 'dokeos_module' && $arrLP[$i]['item_type'] != 'dir') {
  4288. $return .= ' <input type="file" name="mp3file' . $arrLP[$i]['id'] . '" id="mp3file" />';
  4289. if (!empty ($arrLP[$i]['audio'])) {
  4290. $return .= '<br />'.Security::remove_XSS($arrLP[$i]['audio']).'<input type="checkbox" name="removemp3' . $arrLP[$i]['id'] . '" id="checkbox' . $arrLP[$i]['id'] . '" />' . get_lang('RemoveAudio');
  4291. }
  4292. }
  4293. }
  4294. $return .= '</td>';
  4295. if ($is_allowed_to_edit) {
  4296. if (!$_GET['updateaudio'] OR $_GET['updateaudio'] <> 'true') {
  4297. $return .= '<td align="center">';
  4298. if ($arrLP[$i]['previous_item_id'] != 0) {
  4299. $return .= '<a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&amp;action=move_item&amp;direction=up&amp;id=' . $arrLP[$i]['id'] . '&amp;lp_id=' . $this->lp_id . '&amp;sec_token='.$token.'">';
  4300. $return .= '<img style="margin:1px;" alt="" src="../img/arrow_up_' . ($arrLP[$i]['depth'] % 3) . '.gif" title="' . get_lang('MoveUp') . '"/>';
  4301. $return .= '</a>';
  4302. } else {
  4303. $return .= '<img alt="" src="../img/blanco.png" title="" />';
  4304. }
  4305. if ($arrLP[$i]['next_item_id'] != 0) {
  4306. $return .= '<a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']). '&amp;action=move_item&amp;direction=down&amp;id=' . $arrLP[$i]['id'] . '&amp;lp_id=' . $this->lp_id . '&amp;sec_token='.$token.'">';
  4307. $return .= '<img style="margin:1px;" src="../img/arrow_down_' . ($arrLP[$i]['depth'] % 3) . '.gif" title="' . get_lang('MoveDown') . '" />';
  4308. $return .= '</a>';
  4309. } else
  4310. $return .= '<img alt="" src="../img/blanco.png" title="" />';
  4311. $return .= '</td>';
  4312. }
  4313. $return .= '<td align="center">';
  4314. if ($arrLP[$i]['item_type'] != 'dokeos_chapter' && $arrLP[$i]['item_type'] != 'dokeos_module') {
  4315. $return .= '<a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&amp;action=edit_item&amp;view=build&amp;id=' . $arrLP[$i]['id'] . '&amp;lp_id=' . $this->lp_id . '&amp;path_item=' . $arrLP[$i]['path'] . '">';
  4316. $return .= '<img style="margin:1px;" alt="" src="../img/edit.png" title="' . get_lang('_edit_learnpath_module') . '" />';
  4317. $return .= '</a>';
  4318. } else {
  4319. $return .= '<a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&amp;action=edit_item&amp;id=' . $arrLP[$i]['id'] . '&amp;lp_id=' . $this->lp_id . '&amp;path_item=' . $arrLP[$i]['path'] . '">';
  4320. $return .= '<img style="margin:1px;" alt="" src="../img/edit.png" title="' . get_lang('_edit_learnpath_module') . '" />';
  4321. $return .= '</a>';
  4322. }
  4323. $return .= '<a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&amp;action=delete_item&amp;id=' . $arrLP[$i]['id'] . '&amp;lp_id=' . $this->lp_id . '" onClick="return confirmation(\'' . addslashes($title) . '\');">';
  4324. $return .= '<img style="margin:1px;" alt="" src="../img/delete.png" title="' . get_lang('_delete_learnpath_module') . '" />';
  4325. $return .= '</a>';
  4326. $return .= '</td>';
  4327. }
  4328. $return .= '</tr>';
  4329. }
  4330. if (count($arrLP) == 0) {
  4331. $return .= '<tr>';
  4332. $return .= '<td colspan="4">' . get_lang('NoItemsInLp') . '</td>';
  4333. $return .= '</tr>';
  4334. }
  4335. $return .= '</table>';
  4336. // We need to close the form when we are updating the mp3 files.
  4337. if ($_GET['updateaudio'] == 'true') {
  4338. $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?
  4339. }
  4340. // We need to close the form when we are updating the mp3 files.
  4341. if ($_GET['updateaudio'] == 'true' && count($arrLP) != 0) {
  4342. $return .= '</form>';
  4343. }
  4344. return $return;
  4345. }
  4346. /**
  4347. * This function builds the action menu
  4348. * @return void
  4349. */
  4350. public function build_action_menu() {
  4351. $gradebook = Security :: remove_XSS($_GET['gradebook']);
  4352. echo '<div class="actions">';
  4353. //echo '<span>'.Display::return_icon('build_learnpath.png','-','','32').' '.get_lang('Build').'</span>';
  4354. echo '<span>' . Display :: return_icon('build_learnpath_na.png', get_lang('Build'),'','32').'</span>';
  4355. 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('move_learnpath.png', get_lang('BasicOverview'),'','32').'</a>';
  4356. 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('view_left_right.png', get_lang('Display'),'','32').'</a> ';
  4357. Display :: display_icon('i.gif');
  4358. 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_learnigpath_object.png', get_lang('NewStep'),'','32').'</a>';
  4359. 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('add_learnpath_section.png', get_lang('NewChapter'),'','32').'</a>';
  4360. echo '<a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&amp;action=admin_view&amp;lp_id=' . $_SESSION['oLP']->lp_id . '&amp;updateaudio=true">' . Display :: return_icon('upload_audio.png', get_lang('UpdateAllAudioFragments'),'','32').'</a>';
  4361. echo '<a href="lp_controller.php?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&amp;action=edit&amp;lp_id=' . $_SESSION['oLP']->lp_id . '">' . Display :: return_icon('settings.png', get_lang('CourseSettings'),'','32').'</a>';
  4362. echo '</div>';
  4363. }
  4364. /**
  4365. * This functions builds the LP tree based on data from the database.
  4366. * @return string
  4367. * @uses dtree.js :: necessary javascript for building this tree
  4368. */
  4369. public function build_tree() {
  4370. $return = "<script type=\"text/javascript\">\n";
  4371. $return .= "\tm = new dTree('m');\n\n";
  4372. $return .= "\tm.config.folderLinks = true;\n";
  4373. $return .= "\tm.config.useCookies = true;\n";
  4374. $return .= "\tm.config.useIcons = true;\n";
  4375. $return .= "\tm.config.useLines = true;\n";
  4376. $return .= "\tm.config.useSelection = true;\n";
  4377. $return .= "\tm.config.useStatustext = false;\n\n";
  4378. $menu = 0;
  4379. $parent = '';
  4380. $return .= "\tm.add(" . $menu . ", -1, '" . addslashes(Security::remove_XSS(($this->name))) . "');\n";
  4381. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  4382. $sql = " SELECT id, title, description, item_type, path, parent_item_id, previous_item_id, next_item_id, max_score, min_score, mastery_score, display_order
  4383. FROM $tbl_lp_item
  4384. WHERE lp_id = " . Database :: escape_string($this->lp_id);
  4385. $result = Database::query($sql);
  4386. $arrLP = array ();
  4387. while ($row = Database :: fetch_array($result)) {
  4388. $row['title'] = Security :: remove_XSS($row['title']);
  4389. $row['description'] = Security :: remove_XSS($row['description']);
  4390. $arrLP[] = array (
  4391. 'id' => $row['id'],
  4392. 'item_type' => $row['item_type'],
  4393. 'title' => $row['title'],
  4394. 'path' => $row['path'],
  4395. 'description' => $row['description'],
  4396. 'parent_item_id' => $row['parent_item_id'],
  4397. 'previous_item_id' => $row['previous_item_id'],
  4398. 'next_item_id' => $row['next_item_id'],
  4399. 'max_score' => $row['max_score'],
  4400. 'min_score' => $row['min_score'],
  4401. 'mastery_score' => $row['mastery_score'],
  4402. 'display_order' => $row['display_order']
  4403. );
  4404. }
  4405. $this->tree_array($arrLP);
  4406. $arrLP = $this->arrMenu;
  4407. unset ($this->arrMenu);
  4408. $title = '';
  4409. for ($i = 0; $i < count($arrLP); $i++) {
  4410. $title = addslashes($arrLP[$i]['title']);
  4411. $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;
  4412. $icon_name = str_replace(' ', '', $arrLP[$i]['item_type']);
  4413. if (file_exists('../img/lp_' . $icon_name . '.png')) {
  4414. $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";
  4415. } else
  4416. if (file_exists('../img/lp_' . $icon_name . '.gif')) {
  4417. $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";
  4418. } else {
  4419. $return .= "\tm.add(" . $arrLP[$i]['id'] . ", " . $arrLP[$i]['parent_item_id'] . ", '" . $title . "', '" . $menu_page . "', '', '', '../img/folder_document.gif', '../img/folder_document.gif');\n";
  4420. }
  4421. if ($menu < $arrLP[$i]['id'])
  4422. $menu = $arrLP[$i]['id'];
  4423. }
  4424. $return .= "\n\tdocument.write(m);\n";
  4425. $return .= "\t if(!m.selectedNode) m.s(1);";
  4426. $return .= "</script>\n";
  4427. return $return;
  4428. }
  4429. /**
  4430. * Create a new document //still needs some finetuning
  4431. * @param array $_course
  4432. * @return string
  4433. */
  4434. public function create_document($_course) {
  4435. global $charset;
  4436. $dir = isset ($_GET['dir']) ? $_GET['dir'] : $_POST['dir']; // Please, do not modify this dirname formatting.
  4437. if (strstr($dir, '..'))
  4438. $dir = '/';
  4439. if ($dir[0] == '.')
  4440. $dir = substr($dir, 1);
  4441. if ($dir[0] != '/')
  4442. $dir = '/' . $dir;
  4443. if ($dir[strlen($dir) - 1] != '/')
  4444. $dir .= '/';
  4445. $filepath = api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document' . $dir;
  4446. if (empty($_POST['dir']) && empty($_GET['dir'])) {
  4447. //Creating learning_path folder
  4448. $dir = '/learning_path';
  4449. $filepath = api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document';
  4450. $folder = null;
  4451. if (!is_dir($filepath.'/'.$dir)) {
  4452. $folder = create_unexisting_directory($_course, api_get_user_id(), api_get_session_id(), 0, 0, $filepath, $dir , get_lang('LearningPaths'));
  4453. } else {
  4454. $folder = true;
  4455. }
  4456. $dir = '/learning_path/';
  4457. //Creating LP folder
  4458. if ($folder) {
  4459. $title = replace_dangerous_char($this->name);
  4460. $dir = $dir.$title;
  4461. $filepath = api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document';
  4462. if (!is_dir($filepath.'/'.$dir)) {
  4463. $folder = create_unexisting_directory($_course, api_get_user_id(), api_get_session_id(), 0, 0, $filepath, $dir , $this->name);
  4464. } else {
  4465. $folder = true;
  4466. }
  4467. $dir = $dir.'/';
  4468. if ($folder) {
  4469. $filepath = api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document'.$dir;
  4470. }
  4471. }
  4472. }
  4473. if (!is_dir($filepath)) {
  4474. $filepath = api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document/';
  4475. $dir = '/';
  4476. }
  4477. // stripslashes() before calling replace_dangerous_char() because $_POST['title']
  4478. // is already escaped twice when it gets here.
  4479. $title = replace_dangerous_char(stripslashes($_POST['title']));
  4480. $title = disable_dangerous_file($title);
  4481. $filename = $title;
  4482. $content = $_POST['content_lp'];
  4483. $tmp_filename = $filename;
  4484. $i = 0;
  4485. while (file_exists($filepath . $tmp_filename . '.html'))
  4486. $tmp_filename = $filename . '_' . ++ $i;
  4487. $filename = $tmp_filename . '.html';
  4488. $content = stripslashes(text_filter($content));
  4489. $content = str_replace(api_get_path(WEB_COURSE_PATH), api_get_path(REL_PATH) . 'courses/', $content);
  4490. // Change the path of mp3 to absolute.
  4491. // The first regexp deals with ../../../ urls.
  4492. $content = preg_replace("|(flashvars=\"file=)(\.+/)+|", "$1" . api_get_path(REL_COURSE_PATH) . $_course['path'] . '/document/', $content);
  4493. // The second regexp deals with audio/ urls.
  4494. $content = preg_replace("|(flashvars=\"file=)([^/]+)/|", "$1" . api_get_path(REL_COURSE_PATH) . $_course['path'] . '/document/$2/', $content);
  4495. // For flv player: To prevent edition problem with firefox, we have to use a strange tip (don't blame me please).
  4496. $content = str_replace('</body>', '<style type="text/css">body{}</style></body>', $content);
  4497. if (!file_exists($filepath . $filename)) {
  4498. if ($fp = @ fopen($filepath . $filename, 'w')) {
  4499. fputs($fp, $content);
  4500. fclose($fp);
  4501. $file_size = filesize($filepath . $filename);
  4502. $save_file_path = $dir . $filename;
  4503. $document_id = add_document($_course, $save_file_path, 'file', $file_size, $filename . '.html');
  4504. if ($document_id) {
  4505. api_item_property_update($_course, TOOL_DOCUMENT, $document_id, 'DocumentAdded', api_get_user_id(), null, null, null, null, api_get_session_id());
  4506. // Update parent folders.
  4507. //item_property_update_on_folder($_course, $_GET['dir'], $_user['user_id']);
  4508. $new_comment = (isset($_POST['comment'])) ? trim($_POST['comment']) : '';
  4509. $new_title = (isset($_POST['title'])) ? trim($_POST['title']) : '';
  4510. if ($new_comment || $new_title) {
  4511. $tbl_doc = Database :: get_course_table(TABLE_DOCUMENT);
  4512. $ct = '';
  4513. if ($new_comment)
  4514. $ct .= ", comment='" . $new_comment . "'";
  4515. if ($new_title)
  4516. $ct .= ", title='" . Database :: escape_string(htmlspecialchars($new_title, ENT_QUOTES, $charset)) . ".html '";
  4517. $sql_update = "UPDATE " . $tbl_doc ." SET " . substr($ct, 1)." WHERE id = " . $document_id;
  4518. Database::query($sql_update);
  4519. }
  4520. }
  4521. return $document_id;
  4522. }
  4523. }
  4524. }
  4525. /**
  4526. * Edit a document based on $_POST and $_GET parameters 'dir' and 'path'
  4527. * @param array $_course array
  4528. * @return void
  4529. */
  4530. public function edit_document($_course) {
  4531. global $_configuration;
  4532. $dir = isset ($_GET['dir']) ? $_GET['dir'] : $_POST['dir']; // Please, do not modify this dirname formatting.
  4533. if (strstr($dir, '..'))
  4534. $dir = '/';
  4535. if ($dir[0] == '.')
  4536. $dir = substr($dir, 1);
  4537. if ($dir[0] != '/')
  4538. $dir = '/' . $dir;
  4539. if ($dir[strlen($dir) - 1] != '/')
  4540. $dir .= '/';
  4541. $filepath = api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document' . $dir;
  4542. if (!is_dir($filepath)) {
  4543. $filepath = api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document/';
  4544. $dir = '/';
  4545. }
  4546. $table_doc = Database :: get_course_table(TABLE_DOCUMENT);
  4547. if (isset($_POST['path']) && !empty($_POST['path'])) {
  4548. $sql = "SELECT path
  4549. FROM " . $table_doc . "
  4550. WHERE id = " . Database::escape_string($_POST['path']);
  4551. $res = Database::query($sql);
  4552. $row = Database :: fetch_array($res);
  4553. $content = stripslashes($_POST['content_lp']);
  4554. $file = $filepath . $row['path'];
  4555. if ($fp = @ fopen($file, 'w')) {
  4556. $content = text_filter($content);
  4557. $content = str_replace(api_get_path(WEB_COURSE_PATH), $_configuration['url_append'] . '/courses/', $content);
  4558. // Change the path of mp3 to absolute.
  4559. // The first regexp deals with ../../../ urls.
  4560. $content = preg_replace("|(flashvars=\"file=)(\.+/)+|", "$1" . api_get_path(REL_COURSE_PATH) . $_course['path'] . '/document/', $content);
  4561. // The second regexp deals with audio/ urls.
  4562. $content = preg_replace("|(flashvars=\"file=)([^/]+)/|", "$1" . api_get_path(REL_COURSE_PATH) . $_course['path'] . '/document/$2/', $content);
  4563. fputs($fp, $content);
  4564. fclose($fp);
  4565. }
  4566. }
  4567. }
  4568. /**
  4569. * Displays the selected item, with a panel for manipulating the item
  4570. * @param int $item_id
  4571. * @param string $msg
  4572. * @return string
  4573. */
  4574. public function display_item($item_id, $iframe = true, $msg = '') {
  4575. global $_course; // It will disappear.
  4576. $return = '';
  4577. if (is_numeric($item_id)) {
  4578. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  4579. $tbl_doc = Database :: get_course_table(TABLE_DOCUMENT);
  4580. $sql = "SELECT lp.* FROM " . $tbl_lp_item . " as lp
  4581. WHERE lp.id = " . Database :: escape_string($item_id);
  4582. $result = Database::query($sql);
  4583. while ($row = Database :: fetch_array($result)) {
  4584. $_SESSION['parent_item_id'] = ($row['item_type'] == 'dokeos_chapter' || $row['item_type'] == 'dokeos_module' || $row['item_type'] == 'dir') ? $item_id : 0;
  4585. // Prevents wrong parent selection for document, see Bug#1251.
  4586. if ($row['item_type'] != 'dokeos_chapter' || $row['item_type'] != 'dokeos_module') {
  4587. $_SESSION['parent_item_id'] = $row['parent_item_id'];
  4588. }
  4589. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4590. $return .= '<div style="padding:10px;">';
  4591. if ($msg != '')
  4592. $return .= $msg;
  4593. $return .= '<p class="lp_title">' . $row['title'] . '</p>';
  4594. //$return .= '<p class="lp_text">' . ((trim($row['description']) == '') ? 'no description' : stripslashes($row['description'])) . '</p>';
  4595. //$return .= '<hr />';
  4596. switch ($row['item_type']) {
  4597. case TOOL_QUIZ:
  4598. if (!empty($row['path'])) {
  4599. require_once api_get_path(SYS_CODE_PATH).'exercice/exercise.class.php';
  4600. $exercise = new Exercise();
  4601. $exercise->read($row['path']);
  4602. // $exercise_url = api_get_path(WEB_CODE_PATH).'exercice/admin.php?exerciseId='.$exercise->id.'&'.api_get_cidReq().'&id_session='.api_get_session_id();
  4603. $return .=$exercise->description.'<br />';
  4604. //$return .=Display::url($exercise_url, $exercise_url).'<br />';*/
  4605. }
  4606. break;
  4607. case TOOL_DOCUMENT:
  4608. $tbl_doc = Database :: get_course_table(TABLE_DOCUMENT);
  4609. $sql_doc = "SELECT path FROM " . $tbl_doc . " WHERE id = " . Database :: escape_string($row['path']);
  4610. $result = Database::query($sql_doc);
  4611. $path_file = Database :: result($result, 0, 0);
  4612. $path_parts = pathinfo($path_file);
  4613. // TODO: Correct the following naive comparisons, also, htm extension is missing.
  4614. if (in_array($path_parts['extension'], array (
  4615. 'html',
  4616. 'txt',
  4617. 'png',
  4618. 'jpg',
  4619. 'JPG',
  4620. 'jpeg',
  4621. 'JPEG',
  4622. 'gif',
  4623. 'swf'
  4624. ))) {
  4625. $return .= $this->display_document($row['path'], true, true);
  4626. }
  4627. break;
  4628. }
  4629. $return .= '</div>';
  4630. }
  4631. }
  4632. return $return;
  4633. }
  4634. /**
  4635. * Shows the needed forms for editing a specific item
  4636. * @param int $item_id
  4637. * @return string
  4638. */
  4639. public function display_edit_item($item_id) {
  4640. global $_course; // It will disappear.
  4641. $return = '';
  4642. if (is_numeric($item_id)) {
  4643. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  4644. $sql = "SELECT * FROM $tbl_lp_item WHERE id = " . Database :: escape_string($item_id);
  4645. $res = Database::query($sql);
  4646. $row = Database::fetch_array($res);
  4647. switch ($row['item_type']) {
  4648. case 'dokeos_chapter' :
  4649. case 'dir' :
  4650. case 'asset' :
  4651. case 'sco' :
  4652. if (isset ($_GET['view']) && $_GET['view'] == 'build') {
  4653. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4654. $return .= $this->display_item_form($row['item_type'], get_lang('EditCurrentChapter') . ' :', 'edit', $item_id, $row);
  4655. } else {
  4656. $return .= $this->display_item_small_form($row['item_type'], get_lang('EditCurrentChapter') . ' :', $row);
  4657. }
  4658. break;
  4659. case TOOL_DOCUMENT :
  4660. $tbl_doc = Database :: get_course_table(TABLE_DOCUMENT);
  4661. $sql_step = " SELECT lp.*, doc.path as dir
  4662. FROM " . $tbl_lp_item . " as lp
  4663. LEFT JOIN " . $tbl_doc . " as doc ON doc.id = lp.path
  4664. WHERE lp.id = " . Database :: escape_string($item_id);
  4665. $res_step = Database::query($sql_step);
  4666. $row_step = Database :: fetch_array($res_step);
  4667. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4668. $return .= $this->display_document_form('edit', $item_id, $row_step);
  4669. break;
  4670. case TOOL_LINK :
  4671. $link_id = (string) $row['path'];
  4672. if (ctype_digit($link_id)) {
  4673. $tbl_link = Database :: get_course_table(TABLE_LINK);
  4674. $sql_select = 'SELECT url FROM ' . $tbl_link . ' WHERE id = ' . Database :: escape_string($link_id);
  4675. $res_link = Database::query($sql_select);
  4676. $row_link = Database :: fetch_array($res_link);
  4677. if (is_array($row_link)) {
  4678. $row['url'] = $row_link['url'];
  4679. }
  4680. }
  4681. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4682. $return .= $this->display_link_form('edit', $item_id, $row);
  4683. break;
  4684. case 'dokeos_module' :
  4685. if (isset ($_GET['view']) && $_GET['view'] == 'build') {
  4686. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4687. $return .= $this->display_item_form($row['item_type'], get_lang('EditCurrentModule') . ' :', 'edit', $item_id, $row);
  4688. } else {
  4689. $return .= $this->display_item_small_form($row['item_type'], get_lang('EditCurrentModule') . ' :', $row);
  4690. }
  4691. break;
  4692. case TOOL_QUIZ :
  4693. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4694. $return .= $this->display_quiz_form('edit', $item_id, $row);
  4695. break;
  4696. case TOOL_HOTPOTATOES :
  4697. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4698. $return .= $this->display_hotpotatoes_form('edit', $item_id, $row);
  4699. break;
  4700. case TOOL_STUDENTPUBLICATION :
  4701. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4702. $return .= $this->display_student_publication_form('edit', $item_id, $row);
  4703. break;
  4704. case TOOL_FORUM :
  4705. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4706. $return .= $this->display_forum_form('edit', $item_id, $row);
  4707. break;
  4708. case TOOL_THREAD :
  4709. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4710. $return .= $this->display_thread_form('edit', $item_id, $row);
  4711. break;
  4712. }
  4713. }
  4714. return $return;
  4715. }
  4716. /**
  4717. * Function that displays a list with al the resources that could be added to the learning path
  4718. * @return string
  4719. */
  4720. public function display_resources() {
  4721. global $_course; // TODO: Don't use globals.
  4722. /*$return .= '<div class="sectiontitle">' . get_lang('CreateNewStep') . '</div>';
  4723. $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>';
  4724. $return .= '<div class="sectiontitle">' . get_lang('UseAnExistingResource') . '</div>';*/
  4725. //Get all the docs
  4726. $documents = $this->get_documents();
  4727. //Get all the exercises
  4728. $exercises = $this->get_exercises();
  4729. // Get all the links
  4730. $links = $this->get_links();
  4731. //Get al the student publications
  4732. $works = $this->get_student_publications();
  4733. //Get al the forums
  4734. $forums = $this->get_forums();
  4735. $headers = array( Display::return_icon('folder_document.png', get_lang('Documents'), array(), 64),
  4736. Display::return_icon('quiz.png', get_lang('Quiz'), array(), 64),
  4737. Display::return_icon('links.png', get_lang('Links'), array(), 64),
  4738. Display::return_icon('works.png', get_lang('Works'), array(), 64),
  4739. Display::return_icon('forum.png', get_lang('Forums'), array(), 64),
  4740. );
  4741. echo Display::tabs($headers, array($documents, $exercises, $links, $works, $forums), 'resource_tab');
  4742. return true;
  4743. }
  4744. /**
  4745. * Returns the extension of a document
  4746. * @param string filename
  4747. * @return string Extension (part after the last dot)
  4748. */
  4749. public function get_extension($filename) {
  4750. $explode = explode('.', $filename);
  4751. return $explode[count($explode) - 1];
  4752. }
  4753. /**
  4754. * Displays a document by id
  4755. *
  4756. * @param unknown_type $id
  4757. * @return unknown
  4758. */
  4759. public function display_document($id, $show_title = false, $iframe = true, $edit_link = false) {
  4760. global $_course; // It is temporary.
  4761. $return = '';
  4762. $tbl_doc = Database :: get_course_table(TABLE_DOCUMENT);
  4763. $sql_doc = "SELECT * FROM " . $tbl_doc . "
  4764. WHERE id = " . $id;
  4765. $res_doc = Database::query($sql_doc);
  4766. $row_doc = Database :: fetch_array($res_doc);
  4767. //if ($show_title)
  4768. //$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>';
  4769. // TODO: Add a path filter.
  4770. if ($iframe) {
  4771. $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>';
  4772. } else {
  4773. $return .= file_get_contents(api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document' . $row_doc['path']);
  4774. }
  4775. return $return;
  4776. }
  4777. /**
  4778. * Return HTML form to add/edit a quiz
  4779. * @param string Action (add/edit)
  4780. * @param integer Item ID if already exists
  4781. * @param mixed Extra information (quiz ID if integer)
  4782. * @return string HTML form
  4783. */
  4784. public function display_quiz_form($action = 'add', $id = 0, $extra_info = '') {
  4785. global $charset;
  4786. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  4787. $tbl_quiz = Database :: get_course_table(TABLE_QUIZ_TEST);
  4788. if ($id != 0 && is_array($extra_info)) {
  4789. $item_title = stripslashes($extra_info['title']);
  4790. $item_description = stripslashes($extra_info['description']);
  4791. }
  4792. elseif (is_numeric($extra_info)) {
  4793. $sql_quiz = "
  4794. SELECT
  4795. title,
  4796. description
  4797. FROM " . $tbl_quiz . "
  4798. WHERE id = " . $extra_info;
  4799. $result = Database::query($sql_quiz);
  4800. $row = Database :: fetch_array($result);
  4801. $item_title = $row['title'];
  4802. $item_description = $row['description'];
  4803. } else {
  4804. $item_title = '';
  4805. $item_description = '';
  4806. }
  4807. $return = ' <div class="row">
  4808. <div class="form_header">';
  4809. if ($id != 0 && is_array($extra_info))
  4810. $parent = $extra_info['parent_item_id'];
  4811. else
  4812. $parent = 0;
  4813. $sql = "
  4814. SELECT *
  4815. FROM " . $tbl_lp_item . "
  4816. WHERE
  4817. lp_id = " . $this->lp_id;
  4818. $result = Database::query($sql);
  4819. $arrLP = array ();
  4820. while ($row = Database :: fetch_array($result)) {
  4821. $arrLP[] = array (
  4822. 'id' => $row['id'],
  4823. 'item_type' => $row['item_type'],
  4824. 'title' => $row['title'],
  4825. 'path' => $row['path'],
  4826. 'description' => $row['description'],
  4827. 'parent_item_id' => $row['parent_item_id'],
  4828. 'previous_item_id' => $row['previous_item_id'],
  4829. 'next_item_id' => $row['next_item_id'],
  4830. 'display_order' => $row['display_order'],
  4831. 'max_score' => $row['max_score'],
  4832. 'min_score' => $row['min_score'],
  4833. 'mastery_score' => $row['mastery_score'],
  4834. 'prerequisite' => $row['prerequisite'],
  4835. 'max_time_allowed' => $row['max_time_allowed']
  4836. );
  4837. }
  4838. $this->tree_array($arrLP);
  4839. $arrLP = $this->arrMenu;
  4840. unset ($this->arrMenu);
  4841. if ($action == 'add')
  4842. $return .= get_lang('CreateTheExercise') . '&nbsp;:';
  4843. elseif ($action == 'move') $return .= get_lang('MoveTheCurrentExercise') . '&nbsp;:';
  4844. else
  4845. $return .= get_lang('EditCurrentExecice') . '&nbsp;:';
  4846. if (isset ($_GET['edit']) && $_GET['edit'] == 'true') {
  4847. $return .= Display :: return_warning_message('<p class="lp_title">' . get_lang('Warning') . ' !</p>' . get_lang('WarningEditingDocument'));
  4848. }
  4849. $return .= ' </div>
  4850. </div>';
  4851. $return .= '<div class="sectioncomment">';
  4852. $return .= '<form method="POST">';
  4853. $return .= '<table class="lp_form">';
  4854. if ($action != 'move') {
  4855. $return .= '<tr>';
  4856. $return .= '<td class="label"><label for="idTitle">' . get_lang('Title') . '</label></td>';
  4857. $return .= '<td class="input"><input id="idTitle" name="title" size="44" type="text" class="learnpath_item_form" value="' . $item_title . '" /></td>';
  4858. $return .= '</tr>';
  4859. }
  4860. $return .= '<tr>';
  4861. $return .= '<td class="label"><label for="idParent">' . get_lang('Parent') . '</label></td>';
  4862. $return .= '<td class="input">';
  4863. $return .= "\t\t\t\t" . '<select id="idParent" style="width:100%;" name="parent" onChange="javascript: load_cbo(this.value);" class="learnpath_item_form" size="1">';
  4864. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
  4865. $arrHide = array (
  4866. $id
  4867. );
  4868. //$parent_item_id = $_SESSION['parent_item_id'];
  4869. for ($i = 0; $i < count($arrLP); $i++) {
  4870. if ($action != 'add') {
  4871. 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)) {
  4872. $return .= "\t\t\t\t\t" . '<option ' . (($parent == $arrLP[$i]['id']) ? 'selected="selected" ' : '') . 'style="padding-left:' . ($arrLP[$i]['depth'] * 10) . 'px;" value="' . $arrLP[$i]['id'] . '">' . $arrLP[$i]['title'] . '</option>';
  4873. } else {
  4874. $arrHide[] = $arrLP[$i]['id'];
  4875. }
  4876. } else {
  4877. if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
  4878. $return .= "\t\t\t\t\t" . '<option ' . (($parent == $arrLP[$i]['id']) ? 'selected="selected" ' : '') . 'style="padding-left:' . ($arrLP[$i]['depth'] * 10) . 'px;" value="' . $arrLP[$i]['id'] . '">' . $arrLP[$i]['title'] . '</option>';
  4879. }
  4880. }
  4881. if (is_array($arrLP)) {
  4882. reset($arrLP);
  4883. }
  4884. $return .= '</select>';
  4885. $return .= '</td>';
  4886. $return .= '</tr>';
  4887. $return .= '<tr>';
  4888. $return .= '<td class="label"><label for="previous">' . get_lang('Position') . '</label></td>';
  4889. $return .= '<td class="input">';
  4890. $return .= "\t\t\t\t" . '<select class="learnpath_item_form" style="width:100%;" id="previous" name="previous" size="1">';
  4891. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . get_lang('FirstPosition') . '</option>';
  4892. for ($i = 0; $i < count($arrLP); $i++) {
  4893. if ($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) {
  4894. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  4895. $selected = 'selected="selected" ';
  4896. elseif ($action == 'add') $selected = 'selected="selected" ';
  4897. else
  4898. $selected = '';
  4899. $return .= "\t\t\t\t\t" . '<option ' . $selected . 'value="' . $arrLP[$i]['id'] . '">' . get_lang('After') . ' "' . $arrLP[$i]['title'] . '"</option>';
  4900. }
  4901. }
  4902. $return .= "\t\t\t\t" . '</select>';
  4903. $return .= '</td>';
  4904. $return .= '</tr>';
  4905. if ($action != 'move') {
  4906. $id_prerequisite = 0;
  4907. if (is_array($arrLP)) {
  4908. foreach ($arrLP as $key => $value) {
  4909. if ($value['id'] == $id) {
  4910. $id_prerequisite = $value['prerequisite'];
  4911. break;
  4912. }
  4913. }
  4914. }
  4915. $arrHide = array ();
  4916. for ($i = 0; $i < count($arrLP); $i++) {
  4917. if ($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter') {
  4918. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  4919. $s_selected_position = $arrLP[$i]['id'];
  4920. elseif ($action == 'add') $s_selected_position = 0;
  4921. $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
  4922. }
  4923. }
  4924. /*// Commented the prerequisites, only visible in edit (exercise).
  4925. $return .= '<tr>';
  4926. $return .= '<td class="label"><label for="idPrerequisites">'.get_lang('Prerequisites').'</label></td>';
  4927. $return .= '<td class="input"><select name="prerequisites" id="prerequisites" class="learnpath_item_form"><option value="0">'.get_lang('NoPrerequisites').'</option>';
  4928. foreach($arrHide as $key => $value){
  4929. if($key==$s_selected_position && $action == 'add'){
  4930. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  4931. }
  4932. elseif($key==$id_prerequisite && $action == 'edit'){
  4933. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  4934. }
  4935. else{
  4936. $return .= '<option value="'.$key.'">'.$value['value'].'</option>';
  4937. }
  4938. }
  4939. $return .= "</select></td>";
  4940. */
  4941. $return .= '</tr>';
  4942. /*$return .= '<tr>';
  4943. $return .= '<td class="label"><label for="maxTimeAllowed">' . get_lang('MaxTimeAllowed') . '</label></td>';
  4944. $return .= '<td class="input"><input name="maxTimeAllowed" style="width:98%;" id="maxTimeAllowed" value="' . $extra_info['max_time_allowed'] . '" /></td>';
  4945. // Remove temporarily the test description.
  4946. //$return .= '<td class="label"><label for="idDescription">'.get_lang('Description').' :</label></td>';
  4947. //$return .= '<td class="input"><textarea id="idDescription" name="description" rows="4">' . $item_description . '</textarea></td>';
  4948. $return .= '</tr>'; */
  4949. }
  4950. $return .= '<tr>';
  4951. if ($action == 'add') {
  4952. $return .= '<td>&nbsp;</td><td><button class="save" name="submit_button" type="submit">' . get_lang('AddExercise') . '</button></td>';
  4953. } else {
  4954. $return .= '<td>&nbsp;</td><td><button class="save" name="submit_button" type="submit">' . get_lang('EditCurrentExecice') . '</button></td>';
  4955. }
  4956. $return .= '</tr>';
  4957. $return .= '</table>';
  4958. if ($action == 'move') {
  4959. $return .= '<input name="title" type="hidden" value="' . $item_title . '" />';
  4960. $return .= '<input name="description" type="hidden" value="' . $item_description . '" />';
  4961. }
  4962. if (is_numeric($extra_info)) {
  4963. $return .= '<input name="path" type="hidden" value="' . $extra_info . '" />';
  4964. }
  4965. elseif (is_array($extra_info)) {
  4966. $return .= '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />';
  4967. }
  4968. $return .= '<input name="type" type="hidden" value="' . TOOL_QUIZ . '" />';
  4969. $return .= '<input name="post_time" type="hidden" value="' . time() . '" />';
  4970. $return .= '</form>';
  4971. $return .= '</div>';
  4972. return $return;
  4973. }
  4974. /**
  4975. * Addition of Hotpotatoes tests
  4976. * @param string Action
  4977. * @param integer Internal ID of the item
  4978. * @param mixed Extra information - can be an array with title and description indexes
  4979. * @return string HTML structure to display the hotpotatoes addition formular
  4980. */
  4981. public function display_hotpotatoes_form($action = 'add', $id = 0, $extra_info = '') {
  4982. global $charset;
  4983. $uploadPath = DIR_HOTPOTATOES; //defined in main_api
  4984. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  4985. if ($id != 0 && is_array($extra_info)) {
  4986. $item_title = stripslashes($extra_info['title']);
  4987. $item_description = stripslashes($extra_info['description']);
  4988. } elseif (is_numeric($extra_info)) {
  4989. $TBL_DOCUMENT = Database :: get_course_table(TABLE_DOCUMENT);
  4990. $sql_hot = "SELECT * FROM " . $TBL_DOCUMENT . "
  4991. WHERE path LIKE '" . $uploadPath . "/%/%htm%'
  4992. AND id = " . (int) $extra_info . " ORDER BY id ASC";
  4993. $res_hot = Database::query($sql_hot);
  4994. $row = Database::fetch_array($res_hot);
  4995. $item_title = $row['title'];
  4996. $item_description = $row['description'];
  4997. if (!empty ($row['comment'])) {
  4998. $item_title = $row['comment'];
  4999. }
  5000. } else {
  5001. $item_title = '';
  5002. $item_description = '';
  5003. }
  5004. if ($id != 0 && is_array($extra_info))
  5005. $parent = $extra_info['parent_item_id'];
  5006. else
  5007. $parent = 0;
  5008. $sql = "SELECT * FROM $tbl_lp_item WHERE lp_id = " . $this->lp_id;
  5009. $result = Database::query($sql);
  5010. $arrLP = array ();
  5011. while ($row = Database :: fetch_array($result)) {
  5012. $arrLP[] = array (
  5013. 'id' => $row['id'],
  5014. 'item_type' => $row['item_type'],
  5015. 'title' => $row['title'],
  5016. 'path' => $row['path'],
  5017. 'description' => $row['description'],
  5018. 'parent_item_id' => $row['parent_item_id'],
  5019. 'previous_item_id' => $row['previous_item_id'],
  5020. 'next_item_id' => $row['next_item_id'],
  5021. 'display_order' => $row['display_order'],
  5022. 'max_score' => $row['max_score'],
  5023. 'min_score' => $row['min_score'],
  5024. 'mastery_score' => $row['mastery_score'],
  5025. 'prerequisite' => $row['prerequisite'],
  5026. 'max_time_allowed' => $row['max_time_allowed']
  5027. );
  5028. }
  5029. /*
  5030. $this->tree_array($arrLP);
  5031. $arrLP = $this->arrMenu;
  5032. unset ($this->arrMenu);*/
  5033. if ($action == 'add')
  5034. $return .= '<div class="row"><div class="form_header">' . get_lang('CreateTheExercise') . '&nbsp;:</div></div>';
  5035. elseif ($action == 'move') $return .= '<p class="lp_title">' . get_lang('MoveTheCurrentExercise') . '&nbsp;:</p>';
  5036. else
  5037. //$return .= '<p class="form_header">' . get_lang('EditCurrentExecice') . '&nbsp;:</p>';
  5038. $return .= '<div class="row"><div class="form_header">' . get_lang('EditCurrentExecice') . '&nbsp;:</div></div>';
  5039. if (isset ($_GET['edit']) && $_GET['edit'] == 'true') {
  5040. $return .= Display :: return_warning_message('<p class="lp_title">' . get_lang('Warning') . ' !</p>' . get_lang('WarningEditingDocument'));
  5041. }
  5042. $return .= '<form method="POST">';
  5043. $return .= '<table cellpadding="0" cellspacing="0" class="lp_form">';
  5044. $return .= '<tr>';
  5045. $return .= '<td class="label"><label for="idParent">' . get_lang('Parent') . ' :</label></td>';
  5046. $return .= '<td class="input">';
  5047. $return .= "\t\t\t\t" . '<select id="idParent" name="parent" onChange="javascript: load_cbo(this.value);" size="1">';
  5048. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
  5049. $arrHide = array (
  5050. $id
  5051. );
  5052. if (count($arrLP) > 0) {
  5053. for ($i = 0; $i < count($arrLP); $i++) {
  5054. if ($action != 'add') {
  5055. 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)) {
  5056. $return .= "\t\t\t\t\t" . '<option ' . (($parent == $arrLP[$i]['id']) ? 'selected="selected" ' : '') . 'style="padding-left:' . ($arrLP[$i]['depth'] * 10) . 'px;" value="' . $arrLP[$i]['id'] . '">' . $arrLP[$i]['title'] . '</option>';
  5057. } else {
  5058. $arrHide[] = $arrLP[$i]['id'];
  5059. }
  5060. } else {
  5061. if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
  5062. $return .= "\t\t\t\t\t" . '<option ' . (($parent == $arrLP[$i]['id']) ? 'selected="selected" ' : '') . 'style="padding-left:' . ($arrLP[$i]['depth'] * 10) . 'px;" value="' . $arrLP[$i]['id'] . '">' . $arrLP[$i]['title'] . '</option>';
  5063. }
  5064. }
  5065. reset($arrLP);
  5066. }
  5067. $return .= "\t\t\t\t" . '</select>';
  5068. $return .= '</td>';
  5069. $return .= '</tr>';
  5070. $return .= '<tr>';
  5071. $return .= '<td class="label"><label for="previous">' . get_lang('Position') . ' :</label></td>';
  5072. $return .= '<td class="input">';
  5073. $return .= "\t\t\t\t" . '<select id="previous" name="previous" size="1">';
  5074. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . get_lang('FirstPosition') . '</option>';
  5075. for ($i = 0; $i < count($arrLP); $i++) {
  5076. if ($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) {
  5077. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5078. $selected = 'selected="selected" ';
  5079. elseif ($action == 'add') $selected = 'selected="selected" ';
  5080. else
  5081. $selected = '';
  5082. $return .= "\t\t\t\t\t" . '<option ' . $selected . 'value="' . $arrLP[$i]['id'] . '">' . get_lang('After') . ' "' . $arrLP[$i]['title'] . '"</option>';
  5083. }
  5084. }
  5085. $return .= "\t\t\t\t" . '</select>';
  5086. $return .= '</td>';
  5087. $return .= '</tr>';
  5088. if ($action != 'move') {
  5089. $return .= '<tr>';
  5090. $return .= '<td class="label"><label for="idTitle">' . get_lang('Title') . ' :</label></td>';
  5091. $return .= '<td class="input"><input id="idTitle" name="title" type="text" value="' . $item_title . '" /></td>';
  5092. $return .= '</tr>';
  5093. $id_prerequisite = 0;
  5094. if (is_array($arrLP) && count($arrLP) > 0) {
  5095. foreach ($arrLP as $key => $value) {
  5096. if ($value['id'] == $id) {
  5097. $id_prerequisite = $value['prerequisite'];
  5098. break;
  5099. }
  5100. }
  5101. $arrHide = array ();
  5102. for ($i = 0; $i < count($arrLP); $i++) {
  5103. if ($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter') {
  5104. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5105. $s_selected_position = $arrLP[$i]['id'];
  5106. elseif ($action == 'add') $s_selected_position = 0;
  5107. $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
  5108. }
  5109. }
  5110. }
  5111. //$return .= '<tr>';
  5112. //$return .= '<td class="label"><label for="idPrerequisites">'.get_lang('Prerequisites').' :</label></td>';
  5113. //$return .= '<td class="input"><select name="prerequisites" id="prerequisites"><option value="0">'.get_lang('NoPrerequisites').'</option>';
  5114. /*
  5115. foreach ($arrHide as $key => $value) {
  5116. if ($key == $s_selected_position && $action == 'add') {
  5117. $return .= '<option value="' . $key . '" selected="selected">' . $value['value'] . '</option>';
  5118. }
  5119. elseif ($key == $id_prerequisite && $action == 'edit') {
  5120. $return .= '<option value="' . $key . '" selected="selected">' . $value['value'] . '</option>';
  5121. } else {
  5122. $return .= '<option value="' . $key . '">' . $value['value'] . '</option>';
  5123. }
  5124. }
  5125. */
  5126. //$return .= "</select></td>";
  5127. //$return .= '</tr>';
  5128. //$return .= '<tr>';
  5129. //$return .= '</tr>';
  5130. }
  5131. $return .= '<tr>';
  5132. $return .= '<td>&nbsp; </td><td><button class="save" name="submit_button" action="edit" type="submit">' . get_lang('SaveHotpotatoes') . '</button></td>';
  5133. $return .= '</tr>';
  5134. $return .= '</table>';
  5135. if ($action == 'move') {
  5136. $return .= '<input name="title" type="hidden" value="' . $item_title . '" />';
  5137. $return .= '<input name="description" type="hidden" value="' . $item_description . '" />';
  5138. }
  5139. if (is_numeric($extra_info)) {
  5140. $return .= '<input name="path" type="hidden" value="' . $extra_info . '" />';
  5141. }
  5142. elseif (is_array($extra_info)) {
  5143. $return .= '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />';
  5144. }
  5145. $return .= '<input name="type" type="hidden" value="' . TOOL_HOTPOTATOES . '" />';
  5146. $return .= '<input name="post_time" type="hidden" value="' . time() . '" />';
  5147. $return .= '</form>';
  5148. return $return;
  5149. }
  5150. /**
  5151. * Return the form to display the forum edit/add option
  5152. * @param string Action (add/edit)
  5153. * @param integer ID of the lp_item if already exists
  5154. * @param mixed Forum ID or title
  5155. * @return string HTML form
  5156. */
  5157. public function display_forum_form($action = 'add', $id = 0, $extra_info = '') {
  5158. global $charset;
  5159. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  5160. $tbl_forum = Database :: get_course_table(TABLE_FORUM);
  5161. if ($id != 0 && is_array($extra_info)) {
  5162. $item_title = stripslashes($extra_info['title']);
  5163. }
  5164. elseif (is_numeric($extra_info)) {
  5165. $sql_forum = "
  5166. SELECT
  5167. forum_title as title, forum_comment as comment
  5168. FROM " . $tbl_forum . "
  5169. WHERE forum_id = " . $extra_info;
  5170. $result = Database::query($sql_forum);
  5171. $row = Database :: fetch_array($result);
  5172. $item_title = $row['title'];
  5173. $item_description = $row['comment'];
  5174. } else {
  5175. $item_title = '';
  5176. $item_description = '';
  5177. }
  5178. $return = ' <div class="row">
  5179. <div class="form_header">';
  5180. if ($id != 0 && is_array($extra_info))
  5181. $parent = $extra_info['parent_item_id'];
  5182. else
  5183. $parent = 0;
  5184. $sql = "
  5185. SELECT *
  5186. FROM " . $tbl_lp_item . "
  5187. WHERE
  5188. lp_id = " . $this->lp_id;
  5189. $result = Database::query($sql);
  5190. $arrLP = array ();
  5191. while ($row = Database :: fetch_array($result)) {
  5192. $arrLP[] = array (
  5193. 'id' => $row['id'],
  5194. 'item_type' => $row['item_type'],
  5195. 'title' => $row['title'],
  5196. 'path' => $row['path'],
  5197. 'description' => $row['description'],
  5198. 'parent_item_id' => $row['parent_item_id'],
  5199. 'previous_item_id' => $row['previous_item_id'],
  5200. 'next_item_id' => $row['next_item_id'],
  5201. 'display_order' => $row['display_order'],
  5202. 'max_score' => $row['max_score'],
  5203. 'min_score' => $row['min_score'],
  5204. 'mastery_score' => $row['mastery_score'],
  5205. 'prerequisite' => $row['prerequisite']
  5206. );
  5207. }
  5208. $this->tree_array($arrLP);
  5209. $arrLP = $this->arrMenu;
  5210. unset ($this->arrMenu);
  5211. if ($action == 'add')
  5212. $return .= get_lang('CreateTheForum') . '&nbsp;:';
  5213. elseif ($action == 'move') $return .= get_lang('MoveTheCurrentForum') . '&nbsp;:';
  5214. else
  5215. $return .= get_lang('EditCurrentForum') . '&nbsp;:';
  5216. $return .= ' </div>
  5217. </div>';
  5218. $return .= '<div class="sectioncomment">';
  5219. $return .= '<form method="POST">';
  5220. $return .= '<table class="lp_form">';
  5221. if ($action != 'move') {
  5222. $return .= '<tr>';
  5223. $return .= '<td class="label"><label for="idTitle">' . get_lang('Title') . '</label></td>';
  5224. $return .= '<td class="input"><input id="idTitle" size="44" name="title" type="text" value="' . $item_title . '" class="learnpath_item_form" /></td>';
  5225. $return .= '</tr>';
  5226. }
  5227. $return .= '<tr>';
  5228. $return .= '<td class="label"><label for="idParent">' . get_lang('Parent') . '</label></td>';
  5229. $return .= '<td class="input">';
  5230. $return .= "\t\t\t\t" . '<select id="idParent" style="width:100%;" name="parent" onChange="javascript: load_cbo(this.value);" class="learnpath_item_form" size="1">';
  5231. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
  5232. $arrHide = array (
  5233. $id
  5234. );
  5235. //$parent_item_id = $_SESSION['parent_item_id'];
  5236. for ($i = 0; $i < count($arrLP); $i++) {
  5237. if ($action != 'add') {
  5238. 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)) {
  5239. $return .= "\t\t\t\t\t" . '<option ' . (($parent == $arrLP[$i]['id']) ? 'selected="selected" ' : '') . 'style="padding-left:' . ($arrLP[$i]['depth'] * 10) . 'px;" value="' . $arrLP[$i]['id'] . '">' . $arrLP[$i]['title'] . '</option>';
  5240. } else {
  5241. $arrHide[] = $arrLP[$i]['id'];
  5242. }
  5243. } else {
  5244. if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
  5245. $return .= "\t\t\t\t\t" . '<option ' . (($parent == $arrLP[$i]['id']) ? 'selected="selected" ' : '') . 'style="padding-left:' . ($arrLP[$i]['depth'] * 10) . 'px;" value="' . $arrLP[$i]['id'] . '">' . $arrLP[$i]['title'] . '</option>';
  5246. }
  5247. }
  5248. if (is_array($arrLP)) {
  5249. reset($arrLP);
  5250. }
  5251. $return .= "\t\t\t\t" . '</select>';
  5252. $return .= '</td>';
  5253. $return .= '</tr>';
  5254. $return .= '<tr>';
  5255. $return .= '<td class="label"><label for="previous">' . get_lang('Position') . '</label></td>';
  5256. $return .= '<td class="input">';
  5257. $return .= "\t\t\t\t" . '<select id="previous" name="previous" style="width:100%;" size="1" class="learnpath_item_form">';
  5258. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . get_lang('FirstPosition') . '</option>';
  5259. for ($i = 0; $i < count($arrLP); $i++) {
  5260. if ($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) {
  5261. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5262. $selected = 'selected="selected" ';
  5263. elseif ($action == 'add') $selected = 'selected="selected" ';
  5264. else
  5265. $selected = '';
  5266. $return .= "\t\t\t\t\t" . '<option ' . $selected . 'value="' . $arrLP[$i]['id'] . '">' . get_lang('After') . ' "' . $arrLP[$i]['title'] . '"</option>';
  5267. }
  5268. }
  5269. $return .= "\t\t\t\t" . '</select>';
  5270. $return .= '</td>';
  5271. $return .= '</tr>';
  5272. if ($action != 'move') {
  5273. $return .= '<tr>';
  5274. $return .= '</tr>';
  5275. $id_prerequisite = 0;
  5276. if (is_array($arrLP)) {
  5277. foreach ($arrLP as $key => $value) {
  5278. if ($value['id'] == $id) {
  5279. $id_prerequisite = $value['prerequisite'];
  5280. break;
  5281. }
  5282. }
  5283. }
  5284. $arrHide = array ();
  5285. for ($i = 0; $i < count($arrLP); $i++) {
  5286. if ($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter') {
  5287. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5288. $s_selected_position = $arrLP[$i]['id'];
  5289. elseif ($action == 'add') $s_selected_position = 0;
  5290. $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
  5291. }
  5292. }
  5293. $return .= '</tr>';
  5294. }
  5295. $return .= '<tr>';
  5296. if ($action == 'add') {
  5297. $return .= '<td>&nbsp;</td><td><button class="save" name="submit_button" type="submit"> ' . get_lang('AddForumToCourse') . ' </button></td>';
  5298. } else {
  5299. $return .= '<td>&nbsp;</td><td><button class="save" name="submit_button" type="submit"> ' . get_lang('EditCurrentForum') . ' </button></td>';
  5300. }
  5301. $return .= '</tr>';
  5302. $return .= '</table>';
  5303. if ($action == 'move') {
  5304. $return .= '<input name="title" type="hidden" value="' . $item_title . '" />';
  5305. $return .= '<input name="description" type="hidden" value="' . $item_description . '" />';
  5306. }
  5307. if (is_numeric($extra_info)) {
  5308. $return .= '<input name="path" type="hidden" value="' . $extra_info . '" />';
  5309. }
  5310. elseif (is_array($extra_info)) {
  5311. $return .= '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />';
  5312. }
  5313. $return .= '<input name="type" type="hidden" value="' . TOOL_FORUM . '" />';
  5314. $return .= '<input name="post_time" type="hidden" value="' . time() . '" />';
  5315. $return .= '</form>';
  5316. $return .= '</div>';
  5317. return $return;
  5318. }
  5319. /**
  5320. * Return HTML form to add/edit forum threads
  5321. * @param string Action (add/edit)
  5322. * @param integer Item ID if already exists in learning path
  5323. * @param mixed Extra information (thread ID if integer)
  5324. * @return string HTML form
  5325. */
  5326. public function display_thread_form($action = 'add', $id = 0, $extra_info = '') {
  5327. global $charset;
  5328. echo '
  5329. <style>
  5330. div.row div.label {
  5331. width:110px;
  5332. }
  5333. div.row div.formw {
  5334. width: 82%;
  5335. }
  5336. </style>';
  5337. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  5338. $tbl_forum = Database :: get_course_table(TABLE_FORUM_THREAD);
  5339. if ($id != 0 && is_array($extra_info)) {
  5340. $item_title = stripslashes($extra_info['title']);
  5341. }
  5342. elseif (is_numeric($extra_info)) {
  5343. $sql_forum = "
  5344. SELECT
  5345. thread_title as title
  5346. FROM " . $tbl_forum . "
  5347. WHERE thread_id = " . $extra_info;
  5348. $result = Database::query($sql_forum);
  5349. $row = Database :: fetch_array($result);
  5350. $item_title = $row['title'];
  5351. $item_description = '';
  5352. } else {
  5353. $item_title = '';
  5354. $item_description = '';
  5355. }
  5356. $return = '<div style="margin:3px 12px;">';
  5357. if ($id != 0 && is_array($extra_info))
  5358. $parent = $extra_info['parent_item_id'];
  5359. else
  5360. $parent = 0;
  5361. $sql = "
  5362. SELECT *
  5363. FROM " . $tbl_lp_item . "
  5364. WHERE
  5365. lp_id = " . $this->lp_id;
  5366. $result = Database::query($sql);
  5367. $arrLP = array ();
  5368. while ($row = Database :: fetch_array($result)) {
  5369. $arrLP[] = array (
  5370. 'id' => $row['id'],
  5371. 'item_type' => $row['item_type'],
  5372. 'title' => $row['title'],
  5373. 'path' => $row['path'],
  5374. 'description' => $row['description'],
  5375. 'parent_item_id' => $row['parent_item_id'],
  5376. 'previous_item_id' => $row['previous_item_id'],
  5377. 'next_item_id' => $row['next_item_id'],
  5378. 'display_order' => $row['display_order'],
  5379. 'max_score' => $row['max_score'],
  5380. 'min_score' => $row['min_score'],
  5381. 'mastery_score' => $row['mastery_score'],
  5382. 'prerequisite' => $row['prerequisite']
  5383. );
  5384. }
  5385. $this->tree_array($arrLP);
  5386. $arrLP = $this->arrMenu;
  5387. unset ($this->arrMenu);
  5388. if ($action == 'add')
  5389. $return .= '<p class="lp_title">' . get_lang('CreateTheForum') . '&nbsp;:</p>';
  5390. elseif ($action == 'move') $return .= '<p class="lp_title">' . get_lang('MoveTheCurrentForum') . '&nbsp;:</p>';
  5391. else
  5392. $return .= '<p class="lp_title">' . get_lang('EditCurrentForum') . '&nbsp;:</p>';
  5393. $return .= '<form method="POST">';
  5394. $return .= '<table cellpadding="0" cellspacing="0" class="lp_form">';
  5395. $return .= '<tr>';
  5396. $return .= '<td class="label"><label for="idParent">' . get_lang('Parent') . '&nbsp;:</label></td>';
  5397. $return .= '<td class="input">';
  5398. $return .= "\t\t\t\t" . '<select id="idParent" name="parent" onChange="javascript: load_cbo(this.value);" size="1">';
  5399. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
  5400. $arrHide = array (
  5401. $id
  5402. );
  5403. for ($i = 0; $i < count($arrLP); $i++) {
  5404. if ($action != 'add') {
  5405. 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)) {
  5406. $return .= "\t\t\t\t\t" . '<option ' . (($parent == $arrLP[$i]['id']) ? 'selected="selected" ' : '') . 'style="padding-left:' . ($arrLP[$i]['depth'] * 10) . 'px;" value="' . $arrLP[$i]['id'] . '">' . $arrLP[$i]['title'] . '</option>';
  5407. } else {
  5408. $arrHide[] = $arrLP[$i]['id'];
  5409. }
  5410. } else {
  5411. if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
  5412. $return .= "\t\t\t\t\t" . '<option ' . (($parent == $arrLP[$i]['id']) ? 'selected="selected" ' : '') . 'style="padding-left:' . ($arrLP[$i]['depth'] * 10) . 'px;" value="' . $arrLP[$i]['id'] . '">' . $arrLP[$i]['title'] . '</option>';
  5413. }
  5414. }
  5415. if ($arrLP != null) {
  5416. reset($arrLP);
  5417. }
  5418. $return .= "\t\t\t\t" . '</select>';
  5419. $return .= '</td>';
  5420. $return .= '</tr>';
  5421. $return .= '<tr>';
  5422. $return .= '<td class="label"><label for="previous">' . get_lang('Position') . '&nbsp;:</label></td>';
  5423. $return .= '<td class="input">';
  5424. $return .= "\t\t\t\t" . '<select id="previous" name="previous" size="1">';
  5425. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . get_lang('FirstPosition') . '</option>';
  5426. for ($i = 0; $i < count($arrLP); $i++) {
  5427. if ($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) {
  5428. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5429. $selected = 'selected="selected" ';
  5430. elseif ($action == 'add') $selected = 'selected="selected" ';
  5431. else
  5432. $selected = '';
  5433. $return .= "\t\t\t\t\t" . '<option ' . $selected . 'value="' . $arrLP[$i]['id'] . '">' . get_lang('After') . ' "' . $arrLP[$i]['title'] . '"</option>';
  5434. }
  5435. }
  5436. $return .= "\t\t\t\t" . '</select>';
  5437. $return .= '</td>';
  5438. $return .= '</tr>';
  5439. if ($action != 'move') {
  5440. $return .= '<tr>';
  5441. $return .= '<td class="label"><label for="idTitle">' . get_lang('Title') . '&nbsp;:</label></td>';
  5442. $return .= '<td class="input"><input id="idTitle" name="title" type="text" value="' . $item_title . '" /></td>';
  5443. $return .= '</tr>';
  5444. $return .= '<tr>';
  5445. $return .= '</tr>';
  5446. $id_prerequisite = 0;
  5447. if ($arrLP != null) {
  5448. foreach ($arrLP as $key => $value) {
  5449. if ($value['id'] == $id) {
  5450. $id_prerequisite = $value['prerequisite'];
  5451. break;
  5452. }
  5453. }
  5454. }
  5455. $arrHide = array();
  5456. for ($i = 0; $i < count($arrLP); $i++) {
  5457. if ($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter') {
  5458. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5459. $s_selected_position = $arrLP[$i]['id'];
  5460. elseif ($action == 'add') $s_selected_position = 0;
  5461. $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
  5462. }
  5463. }
  5464. $return .= '<tr>';
  5465. $return .= '<td class="label"><label for="idPrerequisites">' . get_lang('Prerequisites') . '&nbsp;:</label></td>';
  5466. $return .= '<td class="input"><select name="prerequisites" id="prerequisites"><option value="0">' . get_lang('NoPrerequisites') . '</option>';
  5467. foreach ($arrHide as $key => $value) {
  5468. if ($key == $s_selected_position && $action == 'add') {
  5469. $return .= '<option value="' . $key . '" selected="selected">' . $value['value'] . '</option>';
  5470. }
  5471. elseif ($key == $id_prerequisite && $action == 'edit') {
  5472. $return .= '<option value="' . $key . '" selected="selected">' . $value['value'] . '</option>';
  5473. } else {
  5474. $return .= '<option value="' . $key . '">' . $value['value'] . '</option>';
  5475. }
  5476. }
  5477. $return .= "</select></td>";
  5478. $return .= '</tr>';
  5479. }
  5480. $return .= '<tr>';
  5481. $return .= '<td colspan="2">
  5482. <button class="save" name="submit_button" type="submit" value="'.get_lang('Ok').'" />'.get_lang('Ok').'</button></td>';
  5483. $return .= '</tr>';
  5484. $return .= '</table>';
  5485. if ($action == 'move') {
  5486. $return .= '<input name="title" type="hidden" value="' . $item_title . '" />';
  5487. $return .= '<input name="description" type="hidden" value="' . $item_description . '" />';
  5488. }
  5489. if (is_numeric($extra_info)) {
  5490. $return .= '<input name="path" type="hidden" value="' . $extra_info . '" />';
  5491. }
  5492. elseif (is_array($extra_info)) {
  5493. $return .= '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />';
  5494. }
  5495. $return .= '<input name="type" type="hidden" value="' . TOOL_THREAD . '" />';
  5496. $return .= '<input name="post_time" type="hidden" value="' . time() . '" />';
  5497. $return .= '</form>';
  5498. $return .= '</div>';
  5499. return $return;
  5500. }
  5501. /**
  5502. * Return the HTML form to display an item (generally a section/module item)
  5503. * @param string Item type (module/dokeos_module)
  5504. * @param string Title (optional, only when creating)
  5505. * @param string Action ('add'/'edit')
  5506. * @param integer lp_item ID
  5507. * @param mixed Extra info
  5508. * @return string HTML form
  5509. */
  5510. public function display_item_form($item_type, $title = '', $action = 'add', $id = 0, $extra_info = 'new') {
  5511. global $_course;
  5512. global $charset;
  5513. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  5514. if ($id != 0 && is_array($extra_info)) {
  5515. $item_title = $extra_info['title'];
  5516. $item_description = $extra_info['description'];
  5517. $item_path = api_get_path(WEB_COURSE_PATH) . $_course['path'] . '/scorm/' . $this->path . '/' . stripslashes($extra_info['path']);
  5518. } else {
  5519. $item_title = '';
  5520. $item_description = '';
  5521. }
  5522. $return = ' <div class="row">
  5523. <div class="form_header">';
  5524. if ($id != 0 && is_array($extra_info))
  5525. $parent = $extra_info['parent_item_id'];
  5526. else
  5527. $parent = 0;
  5528. $sql = "
  5529. SELECT *
  5530. FROM " . $tbl_lp_item . "
  5531. WHERE lp_id = " . $this->lp_id . " AND id != " . $id . " ";
  5532. if ($item_type == 'module')
  5533. $sql .= " AND parent_item_id = 0";
  5534. $result = Database::query($sql);
  5535. $arrLP = array ();
  5536. while ($row = Database :: fetch_array($result)) {
  5537. $arrLP[] = array (
  5538. 'id' => $row['id'],
  5539. 'item_type' => $row['item_type'],
  5540. 'title' => $row['title'],
  5541. 'path' => $row['path'],
  5542. 'description' => $row['description'],
  5543. 'parent_item_id' => $row['parent_item_id'],
  5544. 'previous_item_id' => $row['previous_item_id'],
  5545. 'next_item_id' => $row['next_item_id'],
  5546. 'max_score' => $row['max_score'],
  5547. 'min_score' => $row['min_score'],
  5548. 'mastery_score' => $row['mastery_score'],
  5549. 'prerequisite' => $row['prerequisite'],
  5550. 'display_order' => $row['display_order']
  5551. );
  5552. }
  5553. $this->tree_array($arrLP);
  5554. $arrLP = $this->arrMenu;
  5555. unset ($this->arrMenu);
  5556. $return .= $title;
  5557. $return .= ' </div>
  5558. </div>';
  5559. require_once api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php';
  5560. $form = new FormValidator('form', 'POST', api_get_self() . '?' . $_SERVER['QUERY_STRING']);
  5561. $defaults['title'] = api_html_entity_decode($item_title, ENT_QUOTES, $charset);
  5562. $defaults['description'] = $item_description;
  5563. $form->addElement('html', $return);
  5564. //$arrHide = array($id);
  5565. $arrHide[0]['value'] = Security :: remove_XSS($this->name);
  5566. $arrHide[0]['padding'] = 3;
  5567. $charset = api_get_system_encoding();
  5568. if ($item_type != 'module' && $item_type != 'dokeos_module') {
  5569. for ($i = 0; $i < count($arrLP); $i++) {
  5570. if ($action != 'add') {
  5571. 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)) {
  5572. $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
  5573. $arrHide[$arrLP[$i]['id']]['padding'] = 3 + $arrLP[$i]['depth'] * 10;
  5574. if ($parent == $arrLP[$i]['id']) {
  5575. $s_selected_parent = $arrHide[$arrLP[$i]['id']];
  5576. }
  5577. }
  5578. } else {
  5579. if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir') {
  5580. $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
  5581. $arrHide[$arrLP[$i]['id']]['padding'] = 3 + $arrLP[$i]['depth'] * 10;
  5582. if ($parent == $arrLP[$i]['id']) {
  5583. $s_selected_parent = $arrHide[$arrLP[$i]['id']];
  5584. }
  5585. }
  5586. }
  5587. }
  5588. if ($action != 'move') {
  5589. $form->addElement('text', 'title', get_lang('Title'), 'id="idTitle" class="learnpath_chapter_form" size="40%"');
  5590. $form->applyFilter('title', 'html_filter');
  5591. $form->addRule('title', '<div class="required">' . get_lang('ThisFieldIsRequired'), 'required');
  5592. //$form->addElement('textarea', 'description', get_lang('Description').' :', 'id="idDescription"');
  5593. } else {
  5594. $form->addElement('hidden', 'title');
  5595. }
  5596. $parent_select = & $form->addElement('select', 'parent', get_lang('Parent'), '', 'class="learnpath_chapter_form" style="width:37%;" id="idParent" onchange="javascript: load_cbo(this.value);"');
  5597. foreach ($arrHide as $key => $value) {
  5598. $parent_select->addOption($value['value'], $key, 'style="padding-left:' . $value['padding'] . 'px;"');
  5599. }
  5600. $parent_select->setSelected($s_selected_parent);
  5601. }
  5602. if (is_array($arrLP)) {
  5603. reset($arrLP);
  5604. }
  5605. $arrHide = array ();
  5606. // POSITION
  5607. for ($i = 0; $i < count($arrLP); $i++) {
  5608. if ($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) {
  5609. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5610. $s_selected_position = $arrLP[$i]['id'];
  5611. elseif ($action == 'add') $s_selected_position = $arrLP[$i]['id'];
  5612. $arrHide[$arrLP[$i]['id']]['value'] = get_lang('After') . ' "' . $arrLP[$i]['title'] . '"';
  5613. }
  5614. }
  5615. $position = & $form->addElement('select', 'previous', get_lang('Position'), '', 'id="previous" class="learnpath_chapter_form" style="width:37%;"');
  5616. $position->addOption(get_lang('FirstPosition'), 0, 'style="padding-left:' . $value['padding'] . 'px;"');
  5617. foreach ($arrHide as $key => $value) {
  5618. $position->addOption($value['value'] . '"', $key, 'style="padding-left:' . $value['padding'] . 'px;"');
  5619. }
  5620. if (!empty ($s_selected_position)) {
  5621. $position->setSelected($s_selected_position);
  5622. }
  5623. if (is_array($arrLP)) {
  5624. reset($arrLP);
  5625. }
  5626. $form->addElement('style_submit_button', 'submit_button', get_lang('SaveSection'), 'class="save"');
  5627. if ($item_type == 'module' || $item_type == 'dokeos_module') {
  5628. $form->addElement('hidden', 'parent', '0');
  5629. }
  5630. $extension = pathinfo($item_path, PATHINFO_EXTENSION);
  5631. if (($item_type == 'asset' || $item_type == 'sco') && ($extension == 'html' || $extension == 'htm')) {
  5632. if ($item_type == 'sco') {
  5633. $form->addElement('html', '<script type="text/javascript">alert("' . get_lang('WarningWhenEditingScorm') . '")</script>');
  5634. }
  5635. $renderer = $form->defaultRenderer();
  5636. $renderer->setElementTemplate('<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{label}<br />{element}', 'content_lp');
  5637. $form->addElement('html_editor', 'content_lp', '', null, array('ToolbarSet' => 'LearningPathDocuments', 'Width' => '100%', 'Height' => '400', 'FullPage' => true));
  5638. $defaults['content_lp'] = file_get_contents($item_path);
  5639. }
  5640. $form->addElement('hidden', 'type', 'dokeos_' . $item_type);
  5641. $form->addElement('hidden', 'post_time', time());
  5642. $form->setDefaults($defaults);
  5643. return $form->return_form();
  5644. }
  5645. /**
  5646. * Returns the form to update or create a document
  5647. * @param string Action (add/edit)
  5648. * @param integer ID of the lp_item (if already exists)
  5649. * @param mixed Integer if document ID, string if info ('new')
  5650. * @return string HTML form
  5651. */
  5652. public function display_document_form($action = 'add', $id = 0, $extra_info = 'new') {
  5653. global $charset;
  5654. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  5655. $tbl_doc = Database :: get_course_table(TABLE_DOCUMENT);
  5656. $path_parts = pathinfo($extra_info['dir']);
  5657. $no_display_edit_textarea = false;
  5658. //If action==edit document
  5659. //We don't display the document form if it's not an editable document (html or txt file)
  5660. if ($action == "edit") {
  5661. if (is_array($extra_info)) {
  5662. if ($path_parts['extension'] != "txt" && $path_parts['extension'] != "html") {
  5663. $no_display_edit_textarea = true;
  5664. }
  5665. }
  5666. }
  5667. $no_display_add = false;
  5668. // If action==add an existing document
  5669. // We don't display the document form if it's not an editable document (html or txt file).
  5670. if ($action == "add") {
  5671. if (is_numeric($extra_info)) {
  5672. $sql_doc = "SELECT path FROM " . $tbl_doc . "WHERE id = " . Database :: escape_string($extra_info);
  5673. $result = Database::query($sql_doc);
  5674. $path_file = Database :: result($result, 0, 0);
  5675. $path_parts = pathinfo($path_file);
  5676. if ($path_parts['extension'] != "txt" && $path_parts['extension'] != "html") {
  5677. $no_display_add = true;
  5678. }
  5679. }
  5680. }
  5681. if ($id != 0 && is_array($extra_info)) {
  5682. $item_title = stripslashes($extra_info['title']);
  5683. $item_description = stripslashes($extra_info['description']);
  5684. $item_terms = stripslashes($extra_info['terms']);
  5685. if (empty ($item_title)) {
  5686. $path_parts = pathinfo($extra_info['path']);
  5687. $item_title = stripslashes($path_parts['filename']);
  5688. }
  5689. } elseif (is_numeric($extra_info)) {
  5690. $sql_doc = "SELECT path, title FROM " . $tbl_doc . "
  5691. WHERE id = " . Database :: escape_string($extra_info);
  5692. $result = Database::query($sql_doc);
  5693. $row = Database :: fetch_array($result);
  5694. $explode = explode('.', $row['title']);
  5695. if (count($explode) > 1) {
  5696. for ($i = 0; $i < count($explode) - 1; $i++)
  5697. $item_title .= $explode[$i];
  5698. } else {
  5699. $item_title = $row['title'];
  5700. }
  5701. $item_title = str_replace('_', ' ', $item_title);
  5702. if (empty ($item_title)) {
  5703. $path_parts = pathinfo($row['path']);
  5704. $item_title = stripslashes($path_parts['filename']);
  5705. }
  5706. } else {
  5707. $item_title = '';
  5708. $item_description = '';
  5709. }
  5710. $return = ' <div class="row">
  5711. <div class="form_header">';
  5712. if ($id != 0 && is_array($extra_info))
  5713. $parent = $extra_info['parent_item_id'];
  5714. else
  5715. $parent = 0;
  5716. $sql = "SELECT * FROM " . $tbl_lp_item . "
  5717. WHERE lp_id = " . $this->lp_id;
  5718. $result = Database::query($sql);
  5719. $arrLP = array ();
  5720. while ($row = Database :: fetch_array($result)) {
  5721. $arrLP[] = array (
  5722. 'id' => $row['id'],
  5723. 'item_type' => $row['item_type'],
  5724. 'title' => $row['title'],
  5725. 'path' => $row['path'],
  5726. 'description' => $row['description'],
  5727. 'parent_item_id' => $row['parent_item_id'],
  5728. 'previous_item_id' => $row['previous_item_id'],
  5729. 'next_item_id' => $row['next_item_id'],
  5730. 'display_order' => $row['display_order'],
  5731. 'max_score' => $row['max_score'],
  5732. 'min_score' => $row['min_score'],
  5733. 'mastery_score' => $row['mastery_score'],
  5734. 'prerequisite' => $row['prerequisite']
  5735. );
  5736. }
  5737. $this->tree_array($arrLP);
  5738. $arrLP = $this->arrMenu;
  5739. unset ($this->arrMenu);
  5740. if ($action == 'add') {
  5741. $return .= get_lang('CreateTheDocument');
  5742. } elseif ($action == 'move') {
  5743. $return .= get_lang('MoveTheCurrentDocument');
  5744. } else {
  5745. $return .= get_lang('EditTheCurrentDocument');
  5746. }
  5747. $return .= '</div>
  5748. </div>';
  5749. if (isset ($_GET['edit']) && $_GET['edit'] == 'true') {
  5750. $return .= Display :: return_warning_message('<strong>' . get_lang('Warning') . ' !</strong><br />' . get_lang('WarningEditingDocument'), false);
  5751. }
  5752. require_once api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php';
  5753. $form = new FormValidator('form', 'POST', api_get_self() . '?' . $_SERVER['QUERY_STRING'], '', 'enctype="multipart/form-data"');
  5754. $defaults['title'] = Security :: remove_XSS($item_title);
  5755. if (empty($item_title)) {
  5756. $defaults['title'] = Security::remove_XSS($item_title);
  5757. }
  5758. $defaults['description'] = $item_description;
  5759. $form->addElement('html', $return);
  5760. if ($action != 'move') {
  5761. $form->addElement('text', 'title', get_lang('Title'), 'id="idTitle" class="learnpath_item_form" size=44%');
  5762. $form->applyFilter('title', 'html_filter');
  5763. }
  5764. //$arrHide = array($id);
  5765. $arrHide[0]['value'] = $this->name;
  5766. $arrHide[0]['padding'] = 3;
  5767. for ($i = 0; $i < count($arrLP); $i++) {
  5768. if ($action != 'add') {
  5769. 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)) {
  5770. $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
  5771. $arrHide[$arrLP[$i]['id']]['padding'] = 3 + $arrLP[$i]['depth'] * 10;
  5772. if ($parent == $arrLP[$i]['id']) {
  5773. $s_selected_parent = $arrHide[$arrLP[$i]['id']];
  5774. }
  5775. }
  5776. } else {
  5777. if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir') {
  5778. $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
  5779. $arrHide[$arrLP[$i]['id']]['padding'] = 3 + $arrLP[$i]['depth'] * 10;
  5780. if ($parent == $arrLP[$i]['id']) {
  5781. $s_selected_parent = $arrHide[$arrLP[$i]['id']];
  5782. }
  5783. }
  5784. }
  5785. }
  5786. $parent_select = & $form->addElement('select', 'parent', get_lang('Parent'), '', 'class="learnpath_item_form" id="idParent" style="width:40%;" onchange="javascript: load_cbo(this.value);"');
  5787. $my_count=0;
  5788. foreach ($arrHide as $key => $value) {
  5789. if ($my_count!=0) {
  5790. // The LP name is also the first section and is not in the same charset like the other sections.
  5791. $value['value'] = Security :: remove_XSS($value['value']);
  5792. $parent_select->addOption($value['value'], $key, 'style="padding-left:' . $value['padding'] . 'px;"');
  5793. } else {
  5794. $value['value'] = Security :: remove_XSS($value['value']);
  5795. $parent_select->addOption($value['value'], $key, 'style="padding-left:' . $value['padding'] . 'px;"');
  5796. }
  5797. $my_count++;
  5798. }
  5799. if (!empty($id)) {
  5800. $parent_select->setSelected($parent);
  5801. } else {
  5802. $parent_item_id = $_SESSION['parent_item_id'];
  5803. $parent_select->setSelected($parent_item_id);
  5804. }
  5805. if (is_array($arrLP)) {
  5806. reset($arrLP);
  5807. }
  5808. $arrHide = array ();
  5809. //POSITION
  5810. for ($i = 0; $i < count($arrLP); $i++) {
  5811. if ($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) {
  5812. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5813. $s_selected_position = $arrLP[$i]['id'];
  5814. elseif ($action == 'add') $s_selected_position = $arrLP[$i]['id'];
  5815. $arrHide[$arrLP[$i]['id']]['value'] = get_lang('After') . ' "' . $arrLP[$i]['title'] . '"';
  5816. }
  5817. }
  5818. $position = & $form->addElement('select', 'previous', get_lang('Position'), '', 'id="previous" class="learnpath_item_form" style="width:40%;"');
  5819. $position->addOption(get_lang('FirstPosition'), 0);
  5820. foreach ($arrHide as $key => $value) {
  5821. $position->addOption($value['value'], $key, 'style="padding-left:' . $value['padding'] . 'px;"');
  5822. }
  5823. $position->setSelected($s_selected_position);
  5824. if (is_array($arrLP)) {
  5825. reset($arrLP);
  5826. }
  5827. if ($action != 'move') {
  5828. $id_prerequisite = 0;
  5829. if (is_array($arrLP)) {
  5830. foreach ($arrLP as $key => $value) {
  5831. if ($value['id'] == $id) {
  5832. $id_prerequisite = $value['prerequisite'];
  5833. break;
  5834. }
  5835. }
  5836. }
  5837. // Commented the prerequisites, only visible in edit (new document).
  5838. //$select_prerequisites=$form->addElement('select', 'prerequisites', get_lang('Prerequisites'),null,'id="prerequisites" class="learnpath_item_form" style="width:263px;"');
  5839. //$select_prerequisites->addOption(get_lang('NoPrerequisites'), 0);
  5840. // Form element for uploading an mp3 file.
  5841. //$form->addElement('file','mp3',get_lang('UploadMp3audio'),'id="mp3" size="33"');
  5842. //$form->addRule('file', 'The extension of the Song file should be *.mp3', 'filename', '/^.*\.mp3$/');
  5843. /* Code deprecated - moved to lp level (not lp-item).
  5844. if (api_get_setting('search_enabled') === 'true') {
  5845. //add terms field
  5846. $terms = $form->addElement('text', 'terms', get_lang('SearchFeatureTerms').'&nbsp;:', 'id="idTerms" class="learnpath_item_form"');
  5847. $terms->setValue($item_terms);
  5848. }
  5849. */
  5850. $arrHide = array ();
  5851. for ($i = 0; $i < count($arrLP); $i++) {
  5852. if ($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter') {
  5853. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5854. $s_selected_position = $arrLP[$i]['id'];
  5855. elseif ($action == 'add') $s_selected_position = $arrLP[$i]['id'];
  5856. $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
  5857. }
  5858. }
  5859. /* foreach ($arrHide as $key => $value) {
  5860. $select_prerequisites->addOption($value['value'], $key, 'style="padding-left:'.$value['padding'].'px;"');
  5861. if ($key == $s_selected_position && $action == 'add') {
  5862. $select_prerequisites -> setSelected(0);
  5863. }
  5864. elseif ($key == $id_prerequisite && $action == 'edit') {
  5865. $select_prerequisites -> setSelected($id_prerequisite);
  5866. }
  5867. }
  5868. */
  5869. if (!$no_display_add) {
  5870. if (($extra_info == 'new' || $extra_info['item_type'] == TOOL_DOCUMENT || $_GET['edit'] == 'true')) {
  5871. if (isset ($_POST['content']))
  5872. $content = stripslashes($_POST['content']);
  5873. elseif (is_array($extra_info)) {
  5874. //If it's an html document or a text file
  5875. if (!$no_display_edit_textarea) {
  5876. $content = $this->display_document($extra_info['path'], false, false);
  5877. }
  5878. }
  5879. elseif (is_numeric($extra_info)) $content = $this->display_document($extra_info, false, false);
  5880. else
  5881. $content = '';
  5882. if (!$no_display_edit_textarea) {
  5883. // We need to claculate here some specific settings for the online editor.
  5884. // The calculated settings work for documents in the Documents tool
  5885. // (on the root or in subfolders).
  5886. // For documents in native scorm packages it is unclear whether the
  5887. // online editor should be activated or not.
  5888. $relative_path = $extra_info['dir'];
  5889. if ($relative_path == 'n/') {
  5890. // A new document, it is in the root of the repository.
  5891. $relative_path = '';
  5892. $relative_prefix = '';
  5893. } else {
  5894. // The document already exists. Whe have to determine its relative path towards the repository root.
  5895. $relative_path = explode('/', $relative_path);
  5896. $cnt = count($relative_path) - 2;
  5897. if ($cnt < 0) {
  5898. $cnt = 0;
  5899. }
  5900. $relative_prefix = str_repeat('../', $cnt);
  5901. $relative_path = array_slice($relative_path, 1, $cnt);
  5902. $relative_path = implode('/', $relative_path);
  5903. if (strlen($relative_path) > 0) {
  5904. $relative_path = $relative_path . '/';
  5905. }
  5906. }
  5907. $editor_config = array('ToolbarSet' => 'LearningPathDocuments', 'Width' => '100%', 'Height' => '700', 'FullPage' => true,
  5908. 'CreateDocumentDir' => $relative_prefix,
  5909. 'CreateDocumentWebDir' => api_get_path(WEB_COURSE_PATH) . api_get_course_path() . '/document/',
  5910. 'BaseHref' => api_get_path(WEB_COURSE_PATH) . api_get_course_path() . '/document/' . $relative_path
  5911. );
  5912. if ($_GET['action'] == 'add_item') {
  5913. $class = 'add';
  5914. $text = get_lang('LPCreateDocument');
  5915. } else
  5916. if ($_GET['action'] == 'edit_item') {
  5917. $class = 'save';
  5918. $text = get_lang('SaveDocument');
  5919. }
  5920. $form->addElement('style_submit_button', 'submit_button', $text, 'class="' . $class . '"');
  5921. $renderer = $form->defaultRenderer();
  5922. $renderer->setElementTemplate('<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{label}<br />{element}', 'content_lp');
  5923. $form->addElement('html', '<div style="margin:3px 12px">');
  5924. $form->addElement('html_editor', 'content_lp', '', null, $editor_config);
  5925. $form->addElement('html', '</div>');
  5926. $defaults['content_lp'] = $content;
  5927. }
  5928. }
  5929. elseif (is_numeric($extra_info)) {
  5930. $form->addElement('style_submit_button', 'submit_button', get_lang('SaveDocument'), 'class="save"');
  5931. $return = $this->display_document($extra_info, true, true, true);
  5932. $form->addElement('html', $return);
  5933. }
  5934. }
  5935. }
  5936. if ($action == 'move') {
  5937. $form->addElement('hidden', 'title', $item_title);
  5938. $form->addElement('hidden', 'description', $item_description);
  5939. }
  5940. if (is_numeric($extra_info)) {
  5941. $form->addElement('style_submit_button', 'submit_button', get_lang('SaveDocument'), 'value="submit_button", class="save"');
  5942. $form->addElement('hidden', 'path', $extra_info);
  5943. }
  5944. elseif (is_array($extra_info)) {
  5945. $form->addElement('style_submit_button', 'submit_button', get_lang('SaveDocument'), 'class="save"');
  5946. $form->addElement('hidden', 'path', $extra_info['path']);
  5947. }
  5948. $form->addElement('hidden', 'type', TOOL_DOCUMENT);
  5949. $form->addElement('hidden', 'post_time', time());
  5950. $form->setDefaults($defaults);
  5951. return $form->return_form();
  5952. }
  5953. /**
  5954. * Return HTML form to add/edit a link item
  5955. * @param string Action (add/edit)
  5956. * @param integer Item ID if exists
  5957. * @param mixed Extra info
  5958. * @return string HTML form
  5959. */
  5960. public function display_link_form($action = 'add', $id = 0, $extra_info = '') {
  5961. global $charset;
  5962. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  5963. $tbl_link = Database :: get_course_table(TABLE_LINK);
  5964. if ($id != 0 && is_array($extra_info)) {
  5965. $item_title = stripslashes($extra_info['title']);
  5966. $item_description = stripslashes($extra_info['description']);
  5967. $item_url = stripslashes($extra_info['url']);
  5968. } elseif (is_numeric($extra_info)) {
  5969. $sql_link = "SELECT title, description, url FROM " . $tbl_link . " WHERE id = " . $extra_info;
  5970. $result = Database::query($sql_link);
  5971. $row = Database :: fetch_array($result);
  5972. $item_title = $row['title'];
  5973. $item_description = $row['description'];
  5974. $item_url = $row['url'];
  5975. } else {
  5976. $item_title = '';
  5977. $item_description = '';
  5978. $item_url = '';
  5979. }
  5980. $return = ' <div class="row">
  5981. <div class="form_header">';
  5982. if ($id != 0 && is_array($extra_info))
  5983. $parent = $extra_info['parent_item_id'];
  5984. else
  5985. $parent = 0;
  5986. $sql = "SELECT * FROM " . $tbl_lp_item . " WHERE lp_id = " . $this->lp_id;
  5987. $result = Database::query($sql);
  5988. $arrLP = array ();
  5989. while ($row = Database :: fetch_array($result)) {
  5990. $arrLP[] = array (
  5991. 'id' => $row['id'],
  5992. 'item_type' => $row['item_type'],
  5993. 'title' => $row['title'],
  5994. 'path' => $row['path'],
  5995. 'description' => $row['description'],
  5996. 'parent_item_id' => $row['parent_item_id'],
  5997. 'previous_item_id' => $row['previous_item_id'],
  5998. 'next_item_id' => $row['next_item_id'],
  5999. 'display_order' => $row['display_order'],
  6000. 'max_score' => $row['max_score'],
  6001. 'min_score' => $row['min_score'],
  6002. 'mastery_score' => $row['mastery_score'],
  6003. 'prerequisite' => $row['prerequisite']
  6004. );
  6005. }
  6006. $this->tree_array($arrLP);
  6007. $arrLP = $this->arrMenu;
  6008. unset ($this->arrMenu);
  6009. if ($action == 'add')
  6010. $return .= get_lang('CreateTheLink') . '&nbsp;:';
  6011. elseif ($action == 'move') $return .= get_lang('MoveCurrentLink') . '&nbsp;:';
  6012. else
  6013. $return .= get_lang('EditCurrentLink') . '&nbsp;:';
  6014. $return .= ' </div>
  6015. </div>';
  6016. $return .= '<div class="sectioncomment">';
  6017. $return .= '<form method="POST">';
  6018. $return .= '<table>';
  6019. if ($action != 'move') {
  6020. $return .= '<tr>';
  6021. $return .= '<td class="label"><label for="idTitle">' . get_lang('Title') . '</label></td>';
  6022. $return .= '<td class="input"><input id="idTitle" name="title" size="44" type="text" value="' . $item_title . '" class="learnpath_item_form"/></td>';
  6023. $return .= '</tr>';
  6024. }
  6025. $return .= '<tr>';
  6026. $return .= '<td class="label"><label for="idParent">' . get_lang('Parent') . '</label></td>';
  6027. $return .= '<td class="input">';
  6028. $return .= '<select id="idParent" style="width:100%;" name="parent" onChange="javascript: load_cbo(this.value);" class="learnpath_item_form" size="1">';
  6029. $return .= '<option class="top" value="0">' . $this->name . '</option>';
  6030. $arrHide = array (
  6031. $id
  6032. );
  6033. $parent_item_id = $_SESSION['parent_item_id'];
  6034. for ($i = 0; $i < count($arrLP); $i++) {
  6035. if ($action != 'add') {
  6036. 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)) {
  6037. $return .= "\t\t\t\t\t" . '<option ' . (($parent == $arrLP[$i]['id']) ? 'selected="selected" ' : '') . 'style="padding-left:' . ($arrLP[$i]['depth'] * 10) . 'px;" value="' . $arrLP[$i]['id'] . '">' . $arrLP[$i]['title'] . '</option>';
  6038. } else {
  6039. $arrHide[] = $arrLP[$i]['id'];
  6040. }
  6041. } else {
  6042. if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
  6043. $return .= "\t\t\t\t\t" . '<option ' . (($parent_item_id == $arrLP[$i]['id']) ? 'selected="selected" ' : '') . 'style="padding-left:' . ($arrLP[$i]['depth'] * 10) . 'px;" value="' . $arrLP[$i]['id'] . '">' . $arrLP[$i]['title'] . '</option>';
  6044. }
  6045. }
  6046. if (is_array($arrLP)) {
  6047. reset($arrLP);
  6048. }
  6049. $return .= "\t\t\t\t" . '</select>';
  6050. $return .= '</td>';
  6051. $return .= '</tr>';
  6052. $return .= '<tr>';
  6053. $return .= '<td class="label"><label for="previous">' . get_lang('Position') . '</label></td>';
  6054. $return .= '<td class="input">';
  6055. $return .= "\t\t\t\t" . '<select id="previous" name="previous" style="width:100%;" size="1" class="learnpath_item_form">';
  6056. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . get_lang('FirstPosition') . '</option>';
  6057. for ($i = 0; $i < count($arrLP); $i++) {
  6058. if ($arrLP[$i]['parent_item_id'] == $parent_item_id && $arrLP[$i]['id'] != $id) {
  6059. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  6060. $selected = 'selected="selected" ';
  6061. elseif ($action == 'add')
  6062. $selected = 'selected="selected" ';
  6063. else
  6064. $selected = '';
  6065. $return .= '<option ' . $selected . 'value="' . $arrLP[$i]['id'] . '">' . get_lang('After') . ' "' . $arrLP[$i]['title'] . '"</option>';
  6066. }
  6067. }
  6068. $return .= '</select>';
  6069. $return .= '</td>';
  6070. $return .= '</tr>';
  6071. if ($action != 'move') {
  6072. $return .= '<tr>';
  6073. $return .= '<td class="label"><label for="idURL">' . get_lang('Url') . '</label></td>';
  6074. $return .= '<td class="input"><input' . (is_numeric($extra_info) ? ' disabled="disabled"' : '') . ' id="idURL" name="url" style="width:99%;" type="text" value="' . $item_url . '" class="learnpath_item_form" /></td>';
  6075. $return .= '</tr>';
  6076. $id_prerequisite = 0;
  6077. if (is_array($arrLP)) {
  6078. foreach ($arrLP as $key => $value) {
  6079. if ($value['id'] == $id) {
  6080. $id_prerequisite = $value['prerequisite'];
  6081. break;
  6082. }
  6083. }
  6084. }
  6085. $arrHide = array ();
  6086. for ($i = 0; $i < count($arrLP); $i++) {
  6087. if ($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter') {
  6088. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  6089. $s_selected_position = $arrLP[$i]['id'];
  6090. elseif ($action == 'add') $s_selected_position = 0;
  6091. $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
  6092. }
  6093. }
  6094. /*// Commented the prerequisites, only visible in edit (link).
  6095. $return .= '<tr>';
  6096. $return .= '<td class="label"><label for="idPrerequisites">'.get_lang('Prerequisites').'</label></td>';
  6097. $return .= '<td class="input"><select name="prerequisites" id="prerequisites" class="learnpath_item_form"><option value="0">'.get_lang('NoPrerequisites').'</option>';
  6098. foreach($arrHide as $key => $value) {
  6099. if ($key == $s_selected_position && $action == 'add') {
  6100. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  6101. }
  6102. elseif ($key == $id_prerequisite && $action == 'edit') {
  6103. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  6104. }
  6105. else {
  6106. $return .= '<option value="'.$key.'">'.$value['value'].'</option>';
  6107. }
  6108. }
  6109. $return .= "</select></td>";
  6110. */
  6111. $return .= '</tr>';
  6112. }
  6113. $return .= '<tr>';
  6114. if ($action == 'add') {
  6115. $return .= '<td>&nbsp;</td><td><button class="save" name="submit_button" type="submit">' . get_lang('AddLinkToCourse') . '</button></td>';
  6116. } else {
  6117. $return .= '<td>&nbsp;</td><td><button class="save" name="submit_button" type="submit">' . get_lang('EditCurrentLink') . '</button></td>';
  6118. }
  6119. $return .= '</tr>';
  6120. $return .= '</table>';
  6121. if ($action == 'move') {
  6122. $return .= '<input name="title" type="hidden" value="' . $item_title . '" />';
  6123. $return .= '<input name="description" type="hidden" value="' . $item_description . '" />';
  6124. }
  6125. if (is_numeric($extra_info)) {
  6126. $return .= '<input name="path" type="hidden" value="' . $extra_info . '" />';
  6127. }
  6128. elseif (is_array($extra_info)) {
  6129. $return .= '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />';
  6130. }
  6131. $return .= '<input name="type" type="hidden" value="' . TOOL_LINK . '" />';
  6132. $return .= '<input name="post_time" type="hidden" value="' . time() . '" />';
  6133. $return .= '</form>';
  6134. $return .= '</div>';
  6135. return $return;
  6136. }
  6137. /**
  6138. * Return HTML form to add/edit a student publication (work)
  6139. * @param string Action (add/edit)
  6140. * @param integer Item ID if already exists
  6141. * @param mixed Extra info (work ID if integer)
  6142. * @return string HTML form
  6143. */
  6144. public function display_student_publication_form($action = 'add', $id = 0, $extra_info = '') {
  6145. global $charset;
  6146. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  6147. $tbl_publication = Database :: get_course_table(TABLE_STUDENT_PUBLICATION);
  6148. if ($id != 0 && is_array($extra_info)) {
  6149. $item_title = stripslashes($extra_info['title']);
  6150. $item_description = stripslashes($extra_info['description']);
  6151. }
  6152. elseif (is_numeric($extra_info)) {
  6153. $sql_publication = "
  6154. SELECT
  6155. title,
  6156. description
  6157. FROM " . $tbl_publication . "
  6158. WHERE id = " . $extra_info;
  6159. $result = Database::query($sql_publication);
  6160. $row = Database :: fetch_array($result);
  6161. $item_title = $row['title'];
  6162. } else {
  6163. $item_title = get_lang('Student_publication');
  6164. }
  6165. $return = ' <div class="row">
  6166. <div class="form_header">';
  6167. if ($id != 0 && is_array($extra_info))
  6168. $parent = $extra_info['parent_item_id'];
  6169. else
  6170. $parent = 0;
  6171. $sql = "
  6172. SELECT *
  6173. FROM " . $tbl_lp_item . "
  6174. WHERE
  6175. lp_id = " . $this->lp_id;
  6176. $result = Database::query($sql);
  6177. $arrLP = array ();
  6178. while ($row = Database :: fetch_array($result)) {
  6179. $arrLP[] = array (
  6180. 'id' => $row['id'],
  6181. 'item_type' => $row['item_type'],
  6182. 'title' => $row['title'],
  6183. 'path' => $row['path'],
  6184. 'description' => $row['description'],
  6185. 'parent_item_id' => $row['parent_item_id'],
  6186. 'previous_item_id' => $row['previous_item_id'],
  6187. 'next_item_id' => $row['next_item_id'],
  6188. 'display_order' => $row['display_order'],
  6189. 'max_score' => $row['max_score'],
  6190. 'min_score' => $row['min_score'],
  6191. 'mastery_score' => $row['mastery_score'],
  6192. 'prerequisite' => $row['prerequisite']
  6193. );
  6194. }
  6195. $this->tree_array($arrLP);
  6196. $arrLP = $this->arrMenu;
  6197. unset ($this->arrMenu);
  6198. if ($action == 'add')
  6199. $return .= get_lang('Student_publication') . '&nbsp;:' . "\n";
  6200. elseif ($action == 'move') $return .= get_lang('MoveCurrentStudentPublication') . '&nbsp;:' . "\n";
  6201. else
  6202. $return .= get_lang('EditCurrentStudentPublication') . '&nbsp;:' . "\n";
  6203. $return .= ' </div>
  6204. </div>';
  6205. $return .= '<div class="sectioncomment">';
  6206. $return .= '<form method="POST">';
  6207. $return .= '<table class="lp_form">';
  6208. if ($action != 'move') {
  6209. $return .= '<tr>';
  6210. $return .= '<td class="label"><label for="idTitle">' . get_lang('Title') . '</label></td>';
  6211. $return .= '<td class="input"><input id="idTitle" name="title" size="44" type="text" value="' . $item_title . '" class="learnpath_item_form" /></td>';
  6212. $return .= '</tr>';
  6213. }
  6214. $return .= '<tr>';
  6215. $return .= '<td class="label"><label for="idParent">' . get_lang('Parent') . '</label></td>';
  6216. $return .= '<td class="input">';
  6217. $return .= "\t\t\t\t" . '<select id="idParent" name="parent" style="width:100%;" onChange="javascript: load_cbo(this.value);" class="learnpath_item_form" size="1">';
  6218. //$parent_item_id = $_SESSION['parent_item_id'];
  6219. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
  6220. $arrHide = array (
  6221. $id
  6222. );
  6223. for ($i = 0; $i < count($arrLP); $i++) {
  6224. if ($action != 'add') {
  6225. 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)) {
  6226. $return .= "\t\t\t\t\t" . '<option ' . (($parent == $arrLP[$i]['id']) ? 'selected="selected" ' : '') . 'style="padding-left:' . ($arrLP[$i]['depth'] * 10) . 'px;" value="' . $arrLP[$i]['id'] . '">' . $arrLP[$i]['title'] . '</option>';
  6227. } else {
  6228. $arrHide[] = $arrLP[$i]['id'];
  6229. }
  6230. } else {
  6231. if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
  6232. $return .= "\t\t\t\t\t" . '<option ' . (($parent == $arrLP[$i]['id']) ? 'selected="selected" ' : '') . 'style="padding-left:' . ($arrLP[$i]['depth'] * 10) . 'px;" value="' . $arrLP[$i]['id'] . '">' . $arrLP[$i]['title'] . '</option>';
  6233. }
  6234. }
  6235. if (is_array($arrLP)) {
  6236. reset($arrLP);
  6237. }
  6238. $return .= "\t\t\t\t" . '</select>';
  6239. $return .= '</td>';
  6240. $return .= '</tr>';
  6241. $return .= '<tr>';
  6242. $return .= '<td class="label"><label for="previous">' . get_lang('Position') . '</label></td>';
  6243. $return .= '<td class="input">';
  6244. $return .= "\t\t\t\t" . '<select id="previous" name="previous" style="width:100%;" size="1" class="learnpath_item_form">';
  6245. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . get_lang('FirstPosition') . '</option>';
  6246. for ($i = 0; $i < count($arrLP); $i++) {
  6247. if ($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) {
  6248. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  6249. $selected = 'selected="selected" ';
  6250. elseif ($action == 'add') $selected = 'selected="selected" ';
  6251. else
  6252. $selected = '';
  6253. $return .= "\t\t\t\t\t" . '<option ' . $selected . 'value="' . $arrLP[$i]['id'] . '">' . get_lang('After') . ' "' . $arrLP[$i]['title'] . '"</option>';
  6254. }
  6255. }
  6256. $return .= "\t\t\t\t" . '</select>';
  6257. $return .= '</td>';
  6258. $return .= '</tr>';
  6259. if ($action != 'move') {
  6260. $id_prerequisite = 0;
  6261. if (is_array($arrLP)) {
  6262. foreach ($arrLP as $key => $value) {
  6263. if ($value['id'] == $id) {
  6264. $id_prerequisite = $value['prerequisite'];
  6265. break;
  6266. }
  6267. }
  6268. }
  6269. $arrHide = array ();
  6270. for ($i = 0; $i < count($arrLP); $i++) {
  6271. if ($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter') {
  6272. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  6273. $s_selected_position = $arrLP[$i]['id'];
  6274. elseif ($action == 'add') $s_selected_position = 0;
  6275. $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
  6276. }
  6277. }
  6278. // Commented the prerequisites, only visible in edit (work).
  6279. /*
  6280. $return .= '<tr>';
  6281. $return .= '<td class="label"><label for="idPrerequisites">'.get_lang('Prerequisites').'</label></td>';
  6282. $return .= '<td class="input"><select name="prerequisites" id="prerequisites" class="learnpath_item_form"><option value="0">'.get_lang('NoPrerequisites').'</option>';
  6283. foreach($arrHide as $key => $value) {
  6284. if ($key == $s_selected_position && $action == 'add') {
  6285. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  6286. }
  6287. elseif ($key == $id_prerequisite && $action == 'edit') {
  6288. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  6289. }
  6290. else {
  6291. $return .= '<option value="'.$key.'">'.$value['value'].'</option>';
  6292. }
  6293. }
  6294. $return .= "</select></td>";
  6295. */
  6296. $return .= '</tr>';
  6297. }
  6298. $return .= '<tr>';
  6299. if ($action == 'add') {
  6300. $return .= '<td>&nbsp</td><td><button class="save" name="submit_button" type="submit">' . get_lang('AddAssignmentToCourse') . '</button></td>';
  6301. } else {
  6302. $return .= '<td>&nbsp</td><td><button class="save" name="submit_button" type="submit">' . get_lang('EditCurrentStudentPublication') . '</button></td>';
  6303. }
  6304. $return .= '</tr>';
  6305. $return .= '</table>';
  6306. if ($action == 'move') {
  6307. $return .= '<input name="title" type="hidden" value="' . $item_title . '" />';
  6308. $return .= '<input name="description" type="hidden" value="' . $item_description . '" />';
  6309. }
  6310. if (is_numeric($extra_info)) {
  6311. $return .= '<input name="path" type="hidden" value="' . $extra_info . '" />';
  6312. } elseif (is_array($extra_info)) {
  6313. $return .= '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />';
  6314. }
  6315. $return .= '<input name="type" type="hidden" value="' . TOOL_STUDENTPUBLICATION . '" />';
  6316. $return .= '<input name="post_time" type="hidden" value="' . time() . '" />';
  6317. $return .= '</form>';
  6318. $return .= '</div>';
  6319. return $return;
  6320. }
  6321. /**
  6322. * Displays the menu for manipulating a step
  6323. * @return string html
  6324. */
  6325. public function display_manipulate($item_id, $item_type = TOOL_DOCUMENT) {
  6326. global $charset, $_course;
  6327. $return = '<div class="actions">';
  6328. switch ($item_type) {
  6329. case 'dokeos_chapter' :
  6330. case 'chapter' :
  6331. // Commented the message cause should not show it.
  6332. //$lang = get_lang('TitleManipulateChapter');
  6333. break;
  6334. case 'dokeos_module' :
  6335. case 'module' :
  6336. // Commented the message cause should not show it.
  6337. //$lang = get_lang('TitleManipulateModule');
  6338. break;
  6339. case TOOL_DOCUMENT :
  6340. // Commented the message cause should not show it.
  6341. //$lang = get_lang('TitleManipulateDocument');
  6342. break;
  6343. case TOOL_LINK :
  6344. case 'link' :
  6345. // Commented the message cause should not show it.
  6346. //$lang = get_lang('TitleManipulateLink');
  6347. break;
  6348. case TOOL_QUIZ :
  6349. // Commented the message cause should not show it.
  6350. //$lang = get_lang('TitleManipulateQuiz');
  6351. break;
  6352. case TOOL_STUDENTPUBLICATION :
  6353. // Commented the message cause should not show it.
  6354. //$lang = get_lang('TitleManipulateStudentPublication');
  6355. break;
  6356. }
  6357. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  6358. $item_id = intval($item_id);
  6359. $sql = "SELECT * FROM " . $tbl_lp_item . " as lp WHERE lp.id = " . $item_id;
  6360. $result = Database::query($sql);
  6361. $row = Database::fetch_assoc($result);
  6362. $s_title = $row['title'];
  6363. // We display an audio player if needed.
  6364. if (!empty ($row['audio'])) {
  6365. $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>';
  6366. $return .= '<script type="text/javascript" src="../inc/lib/mediaplayer/swfobject.js"></script>';
  6367. $return .= '<script type="text/javascript">
  6368. var s1 = new SWFObject("../inc/lib/mediaplayer/player.swf","ply","250","20","9","#FFFFFF");
  6369. s1.addParam("allowscriptaccess","always");
  6370. s1.addParam("flashvars","file=../../courses/' . $_course['path'] . '/document/audio/' . $row['audio'] . '&autostart=true");
  6371. s1.write("container");
  6372. </script>';
  6373. }
  6374. // Commented ":" for message in step.
  6375. //$return .= $lang.': ';
  6376. $url = api_get_self() . '?cidReq='.Security::remove_XSS($_GET['cidReq']).'&view=build&id='.$item_id .'&lp_id='.$this->lp_id;
  6377. $return .= Display::url(Display::return_icon('edit.png', get_lang('Edit'), array(), 22), $url.'&action=edit_item&path_item=' . $row['path']);
  6378. $return .= Display::url(Display::return_icon('move.png', get_lang('Move'), array(), 22), $url.'&action=move_item');
  6379. // Commented for now as prerequisites cannot be added to chapters.
  6380. if ($item_type != 'dokeos_chapter' && $item_type != 'chapter') {
  6381. $return .= Display::url(Display::return_icon('accept.png', get_lang('Prerequisites'), array(), 22), $url.'&action=edit_item_prereq');
  6382. }
  6383. $return .= Display::url(Display::return_icon('delete.png', get_lang('Delete'), array(), 22), $url.'&action=delete_item');
  6384. // Get the audiorecorder. Use of ob_* functions since there are echos in the file.
  6385. ob_start();
  6386. $audio_recorder_studentview = 'false';
  6387. $audio_recorder_item_id = $item_id;
  6388. if (api_get_setting('service_visio', 'active') == 'true') {
  6389. include 'audiorecorder.inc.php';
  6390. }
  6391. $return .= ob_get_contents();
  6392. ob_end_clean();
  6393. // End of audiorecorder include
  6394. $return .= '</div>';
  6395. return $return;
  6396. }
  6397. /**
  6398. * Creates the javascript needed for filling up the checkboxes without page reload
  6399. *
  6400. * @return string
  6401. */
  6402. public function get_js_dropdown_array() {
  6403. $return = 'var child_name = new Array();' . "\n";
  6404. $return .= 'var child_value = new Array();' . "\n\n";
  6405. $return .= 'child_name[0] = new Array();' . "\n";
  6406. $return .= 'child_value[0] = new Array();' . "\n\n";
  6407. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  6408. $sql_zero = "
  6409. SELECT *
  6410. FROM " . $tbl_lp_item . "
  6411. WHERE
  6412. lp_id = " . $this->lp_id . " AND
  6413. parent_item_id = 0
  6414. ORDER BY display_order ASC";
  6415. $res_zero = Database::query($sql_zero);
  6416. global $charset;
  6417. $i = 0;
  6418. while ($row_zero = Database :: fetch_array($res_zero)) {
  6419. $return .= 'child_name[0][' . $i . '] = "' . get_lang('After') . ' \"' . $row_zero['title'] . '\"";' . "\n";
  6420. $return .= 'child_value[0][' . $i++ . '] = "' . $row_zero['id'] . '";' . "\n";
  6421. }
  6422. $return .= "\n";
  6423. $sql = "
  6424. SELECT *
  6425. FROM " . $tbl_lp_item . "
  6426. WHERE
  6427. lp_id = " . $this->lp_id;
  6428. $res = Database::query($sql);
  6429. while ($row = Database :: fetch_array($res)) {
  6430. $sql_parent = "
  6431. SELECT *
  6432. FROM " . $tbl_lp_item . "
  6433. WHERE parent_item_id = " . $row['id'] . "
  6434. ORDER BY display_order ASC";
  6435. $res_parent = Database::query($sql_parent);
  6436. $i = 0;
  6437. $return .= 'child_name[' . $row['id'] . '] = new Array();' . "\n";
  6438. $return .= 'child_value[' . $row['id'] . '] = new Array();' . "\n\n";
  6439. while ($row_parent = Database :: fetch_array($res_parent)) {
  6440. $return .= 'child_name[' . $row['id'] . '][' . $i . '] = "' . get_lang('After') . ' \"' . api_html_entity_decode($row_parent['title'], ENT_QUOTES) . '\"";' . "\n";
  6441. $return .= 'child_value[' . $row['id'] . '][' . $i++ . '] = "' . $row_parent['id'] . '";' . "\n";
  6442. }
  6443. $return .= "\n";
  6444. }
  6445. return $return;
  6446. }
  6447. /**
  6448. * Display the form to allow moving an item
  6449. * @param integer Item ID
  6450. * @return string HTML form
  6451. */
  6452. public function display_move_item($item_id) {
  6453. global $_course; //will disappear
  6454. global $charset;
  6455. $return = '';
  6456. if (is_numeric($item_id)) {
  6457. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  6458. $sql = "SELECT *
  6459. FROM " . $tbl_lp_item . "
  6460. WHERE id = " . $item_id;
  6461. $res = Database::query($sql);
  6462. $row = Database :: fetch_array($res);
  6463. switch ($row['item_type']) {
  6464. case 'dokeos_chapter' :
  6465. case 'dir' :
  6466. case 'asset' :
  6467. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6468. $return .= $this->display_item_form($row['item_type'], get_lang('MoveCurrentChapter'), 'move', $item_id, $row);
  6469. break;
  6470. case 'dokeos_module' :
  6471. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6472. $return .= $this->display_item_form($row['item_type'], 'Move th current module:', 'move', $item_id, $row);
  6473. break;
  6474. case TOOL_DOCUMENT :
  6475. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6476. $return .= $this->display_document_form('move', $item_id, $row);
  6477. break;
  6478. case TOOL_LINK :
  6479. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6480. $return .= $this->display_link_form('move', $item_id, $row);
  6481. break;
  6482. case TOOL_HOTPOTATOES :
  6483. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6484. $return .= $this->display_link_form('move', $item_id, $row);
  6485. break;
  6486. case TOOL_QUIZ :
  6487. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6488. $return .= $this->display_quiz_form('move', $item_id, $row);
  6489. break;
  6490. case TOOL_STUDENTPUBLICATION :
  6491. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6492. $return .= $this->display_student_publication_form('move', $item_id, $row);
  6493. break;
  6494. case TOOL_FORUM :
  6495. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6496. $return .= $this->display_forum_form('move', $item_id, $row);
  6497. break;
  6498. case TOOL_THREAD :
  6499. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6500. $return .= $this->display_forum_form('move', $item_id, $row);
  6501. break;
  6502. }
  6503. }
  6504. return $return;
  6505. }
  6506. /**
  6507. * Displays a basic form on the overview page for changing the item title and the item description.
  6508. * @param string $item_type
  6509. * @param string $title
  6510. * @param array $data
  6511. * @return string
  6512. */
  6513. public function display_item_small_form($item_type, $title = '', $data) {
  6514. global $charset;
  6515. $return .= '<div class="lp_small_form">';
  6516. $return .= '<p class="lp_title">' . $title . '</p>';
  6517. $return .= '<form method="post">';
  6518. $return .= '<table cellpadding="0" cellspacing="0" class="lp_form">';
  6519. $return .= '<tr>';
  6520. $return .= '<td class="label"><label for="idTitle">Title&nbsp;:</label></td>';
  6521. $return .= '<td class="input"><input class="small_form" id="idTitle" name="title" type="text" value="' . api_html_entity_decode($data['title'], ENT_QUOTES) . '" /></td>';
  6522. $return .= '</tr>';
  6523. // It said these lines of code - see SVN#11724 and SVN#10770
  6524. //$return .= '<tr>';
  6525. //$return .= '<td class="label"><label for="idDescription">Description&nbsp;:</label></td>';
  6526. //$return .= '<td class="input"><textarea class="small_form" id="idDescription" name="description" rows="4">' . $data['description'] . '</textarea></td>';
  6527. //$return .= '</tr>';
  6528. $return .= '<tr>';
  6529. $return .= '<td colspan="2"><button class="save" name="submit_button" type="submit">' . get_lang('Save') . '</button></td>';
  6530. $return .= '</tr>';
  6531. $return .= '</table>';
  6532. $return .= '<input name="parent" type="hidden" value="' . $data['parent_item_id'] . '"/>';
  6533. $return .= '<input name="previous" type="hidden" value="' . $data['previous_item_id'] . '"/>';
  6534. $return .= '</form>';
  6535. $return .= '</div>';
  6536. return $return;
  6537. }
  6538. /**
  6539. * Return HTML form to allow prerequisites selection
  6540. * @param integer Item ID
  6541. * @return string HTML form
  6542. */
  6543. public function display_item_prerequisites_form($item_id) {
  6544. global $charset;
  6545. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  6546. $item_id = intval($item_id);
  6547. /* Current prerequisite */
  6548. $sql = "SELECT * FROM $tbl_lp_item WHERE id = " . $item_id;
  6549. $result = Database::query($sql);
  6550. $row = Database::fetch_array($result);
  6551. $preq_id = $row['prerequisite'];
  6552. //$preq_mastery = $row['mastery_score'];
  6553. //$preq_max = $row['max_score'];
  6554. $return = $this->display_manipulate($item_id, TOOL_DOCUMENT);
  6555. $return = ' <div class="row">
  6556. <div class="form_header">';
  6557. $return .= get_lang('AddEditPrerequisites');
  6558. $return .= '</div></div>';
  6559. $return .= '<div class="sectioncomment">';
  6560. $return .= '<form method="POST">';
  6561. $return .= '<table class="data_table" style="width:650px">';
  6562. $return .= '<tr>';
  6563. $return .= '<th height="24">' . get_lang('Prerequisites') . '</th>';
  6564. $return .= '<th width="70" height="24">' . get_lang('Minimum') . '</th>';
  6565. $return .= '<th width="70" height="24">' . get_lang('Maximum') . '</th>';
  6566. $return .= '</tr>';
  6567. // Adding the none option to the prerequisites see http://www.chamilo.org/es/node/146
  6568. $return .= '<tr >';
  6569. $return .= '<td colspan="3" class="radio">';
  6570. $return .= '<input checked="checked" id="idNone" name="prerequisites" style="margin-left:0px; margin-right:10px;" type="radio" />';
  6571. $return .= '<label for="idNone">' . get_lang('None') . '</label>';
  6572. $return .= '</tr>';
  6573. $sql = "SELECT * FROM " . $tbl_lp_item . " WHERE lp_id = " . $this->lp_id;
  6574. $result = Database::query($sql);
  6575. $arrLP = array ();
  6576. while ($row = Database :: fetch_array($result)) {
  6577. $arrLP[] = array (
  6578. 'id' => $row['id'],
  6579. 'item_type' => $row['item_type'],
  6580. 'title' => $row['title'],
  6581. 'ref' => $row['ref'],
  6582. 'description' => $row['description'],
  6583. 'parent_item_id' => $row['parent_item_id'],
  6584. 'previous_item_id' => $row['previous_item_id'],
  6585. 'next_item_id' => $row['next_item_id'],
  6586. 'max_score' => $row['max_score'],
  6587. 'min_score' => $row['min_score'],
  6588. 'mastery_score' => $row['mastery_score'],
  6589. 'prerequisite' => $row['prerequisite'],
  6590. 'next_item_id' => $row['next_item_id'],
  6591. 'display_order' => $row['display_order']
  6592. );
  6593. if ($row['ref'] == $preq_id) {
  6594. $preq_mastery = $row['mastery_score'];
  6595. $preq_max = $row['max_score'];
  6596. }
  6597. }
  6598. $this->tree_array($arrLP);
  6599. $arrLP = $this->arrMenu;
  6600. unset ($this->arrMenu);
  6601. for ($i = 0; $i < count($arrLP); $i++) {
  6602. if ($arrLP[$i]['id'] == $item_id)
  6603. break;
  6604. $return .= '<tr>';
  6605. $return .= '<td class="radio"' . (($arrLP[$i]['item_type'] != TOOL_QUIZ && $arrLP[$i]['item_type'] != TOOL_HOTPOTATOES) ? ' colspan="3"' : '') . '>';
  6606. $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'] . '" />';
  6607. $icon_name = str_replace(' ', '', $arrLP[$i]['item_type']);
  6608. if (file_exists('../img/lp_' . $icon_name . '.png')) {
  6609. $return .= '<img alt="" src="../img/lp_' . $icon_name . '.png" style="margin-right:5px;" title="" />';
  6610. } else
  6611. if (file_exists('../img/lp_' . $icon_name . '.gif')) {
  6612. $return .= '<img alt="" src="../img/lp_' . $icon_name . '.gif" style="margin-right:5px;" title="" />';
  6613. } else {
  6614. $return .= Display::return_icon('folder_document.gif','',array('style'=>'margin-right:5px;'));
  6615. }
  6616. $return .= '<label for="id' . $arrLP[$i]['id'] . '">' . $arrLP[$i]['title'] . '</label>';
  6617. $return .= '</td>';
  6618. //$return .= '<td class="radio"' . (($arrLP[$i]['item_type'] != TOOL_HOTPOTATOES) ? ' colspan="3"' : '') . ' />';
  6619. if ($arrLP[$i]['item_type'] == TOOL_QUIZ) {
  6620. $return .= '<td class="exercise" style="border:1px solid #ccc;">';
  6621. $return .= '<center><input size="4" maxlength="3" name="min_' . $arrLP[$i]['id'] . '" type="text" value="' . (($arrLP[$i]['id'] == $preq_id) ? $preq_mastery : 0) . '" /></center>';
  6622. $return .= '</td>';
  6623. $return .= '<td class="exercise" style="border:1px solid #ccc;">';
  6624. $return .= '<center><input size="4" maxlength="3" name="max_' . $arrLP[$i]['id'] . '" type="text" value="' . $arrLP[$i]['max_score'] . '" disabled="true" /></center>';
  6625. $return .= '</td>';
  6626. }
  6627. if ($arrLP[$i]['item_type'] == TOOL_HOTPOTATOES) {
  6628. $return .= '<td class="exercise" style="border:1px solid #ccc;">';
  6629. $return .= '<center><input size="4" maxlength="3" name="min_' . $arrLP[$i]['id'] . '" type="text" value="' . (($arrLP[$i]['id'] == $preq_id) ? $preq_mastery : 0) . '" /></center>';
  6630. $return .= '</td>';
  6631. $return .= '<td class="exercise" style="border:1px solid #ccc;">';
  6632. $return .= '<center><input size="4" maxlength="3" name="max_' . $arrLP[$i]['id'] . '" type="text" value="' . $arrLP[$i]['max_score'] . '" disabled="true" /></center>';
  6633. $return .= '</td>';
  6634. }
  6635. $return .= '</tr>';
  6636. }
  6637. $return .= '<tr>';
  6638. $return .= '</tr>';
  6639. $return .= '</table>';
  6640. $return .= '<div style="padding-top:3px;">';
  6641. $return .= '<button class="save" name="submit_button" type="submit">' . get_lang('ModifyPrerequisites') . ' </button></td>';
  6642. $return .= '</div>';
  6643. $return .= '</form>';
  6644. $return .= '</div>';
  6645. return $return;
  6646. }
  6647. /**
  6648. * Return HTML list to allow prerequisites selection for lp
  6649. * @param integer Item ID
  6650. * @return string HTML form
  6651. */
  6652. public function display_lp_prerequisites_list() {
  6653. global $charset;
  6654. $lp_id = $this->lp_id;
  6655. $tbl_lp = Database :: get_course_table(TABLE_LP_MAIN);
  6656. // get current prerequisite
  6657. $sql = "SELECT * FROM $tbl_lp WHERE id = $lp_id ";
  6658. $result = Database::query($sql);
  6659. $row = Database :: fetch_array($result);
  6660. $preq_id = $row['prerequisite'];
  6661. $session_id = api_get_session_id();
  6662. $session_condition = api_get_session_condition($session_id, false);
  6663. $sql = "SELECT * FROM $tbl_lp $session_condition ORDER BY display_order ";
  6664. $rs = Database::query($sql);
  6665. $return = '';
  6666. $return .= '<select name="prerequisites" >';
  6667. $return .= '<option value="0">'.get_lang('None').'</option>';
  6668. if (Database::num_rows($rs) > 0) {
  6669. while ($row = Database::fetch_array($rs)) {
  6670. if ($row['id'] == $lp_id) {
  6671. continue;
  6672. }
  6673. $return .= '<option value="'.$row['id'].'" '.(($row['id']==$preq_id)?' selected ' : '').'>'.$row['name'].'</option>';
  6674. }
  6675. }
  6676. $return .= '</select>';
  6677. return $return;
  6678. }
  6679. /**
  6680. * Creates a list with all the documents in it
  6681. * @return string
  6682. */
  6683. public function get_documents() {
  6684. global $_course;
  6685. $tbl_doc = Database :: get_course_table(TABLE_DOCUMENT);
  6686. $tbl_item_prop = Database::get_course_table(TABLE_ITEM_PROPERTY);
  6687. $tbl_course = Database::get_main_table(TABLE_MAIN_COURSE);
  6688. $path = '/';
  6689. $path = Database::escape_string(str_replace('_', '\_', $path));
  6690. $added_slash = ($path == '/') ? '' : '/';
  6691. //condition for the session
  6692. $current_session_id = api_get_session_id();
  6693. $condition_session = " AND (id_session = '$current_session_id' OR (id_session = '0' AND insert_date <= (SELECT creation_date FROM $tbl_course WHERE code = '{$_course[id]}')))";
  6694. $sql_doc = "SELECT docs.*
  6695. FROM $tbl_item_prop AS last, $tbl_doc AS docs
  6696. WHERE docs.id = last.ref
  6697. AND docs.path LIKE '".$path.$added_slash."%'
  6698. AND docs.path NOT LIKE '%_DELETED_%'
  6699. AND last.tool = '".TOOL_DOCUMENT."' $condition_session ORDER BY docs.path ASC";
  6700. $res_doc = Database::query($sql_doc);
  6701. //$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>';
  6702. $return = '<div class="lp_resource">';
  6703. $resources = Database::store_result($res_doc);
  6704. $resources_sorted = array();
  6705. $return .= '<div class="lp_resource_element">';
  6706. $return .= Display::return_icon('new_doc.gif', '', array(), 22);
  6707. $return .= Display::url(get_lang('NewDocument') , api_get_self().'?'.api_get_cidreq().'&action=add_item&type='.TOOL_DOCUMENT.'&lp_id='.$_SESSION['oLP']->lp_id);
  6708. $return .= '</div>';
  6709. // If you want to debug it, I advise you to do "echo" on the eval statements.
  6710. foreach ($resources as $resource) {
  6711. $resource_paths = explode('/', $resource['path']);
  6712. array_shift($resource_paths);
  6713. $path_to_eval = $last_path = '';
  6714. $is_file = false;
  6715. foreach ($resource_paths as $key => $resource_path) {
  6716. if (strpos($resource_path, '.') === false && $key != count($resource_paths) - 1) { // It's a folder.
  6717. $path_to_eval .= '["' . $resource_path . '"]["files"]';
  6718. } else
  6719. if (strpos($resource_path, '.') !== false)
  6720. $is_file = true;
  6721. $last_path = $resource_path;
  6722. }
  6723. if ($is_file) {
  6724. //eval ('$resources_sorted' . $path_to_eval . '[' . $resource['id'] . '] = "' . $last_path . '";');
  6725. //for backward compatibility
  6726. if (empty($resource['title'])) {
  6727. $resource['title'] = basename($resource['path']);
  6728. }
  6729. eval ('$resources_sorted' . $path_to_eval . '[' . $resource['id'] . '] = "' .$resource['title']."/". $last_path. '";');
  6730. } else {
  6731. eval ('$resources_sorted' . $path_to_eval . '["' . $last_path . '"]["id"]=' . $resource['id'] . ';');
  6732. }
  6733. }
  6734. $label = get_lang('Documents');
  6735. $new_array[$label] = array('id' => 0, 'files'=>$resources_sorted);
  6736. $return .= $this->write_resources_tree($new_array);
  6737. /*if (Database :: num_rows($res_doc) == 0) {
  6738. $return .= '<div class="lp_resource_element">' . get_lang('NoDocuments') . '</div>';
  6739. }*/
  6740. $return .= '</div>';
  6741. return $return;
  6742. }
  6743. /**
  6744. * Generate and return an HTML list of resources based on a given array.
  6745. * This list is used to show the course creator a list of available resources to choose from
  6746. * when creating a learning path.
  6747. * @param array Array of elements to add to the list
  6748. * @param integer Enables the tree display by shifting the new elements a certain distance to the right
  6749. * @return string The HTML list
  6750. */
  6751. public function write_resources_tree($resources_sorted, $num = 0) {
  6752. require_once api_get_path(LIBRARY_PATH).'fileDisplay.lib.php';
  6753. if (count($resources_sorted) > 0) {
  6754. foreach ($resources_sorted as $key => $resource) {
  6755. if (is_int($resource['id'])) {
  6756. // It's a folder.
  6757. //hide some folders
  6758. if (in_array($key, array('shared_folder','chat_files', 'HotPotatoes_files', 'css', 'certificates'))){
  6759. continue;
  6760. } elseif(preg_match('/_groupdocs/', $key)){
  6761. continue;
  6762. } elseif(preg_match('/sf_user_/', $key)){
  6763. continue;
  6764. } elseif(preg_match('/shared_folder_session_/', $key)){
  6765. continue;
  6766. }
  6767. //trad some titles
  6768. if ($key=='images') {
  6769. $key=get_lang('Images');
  6770. } elseif($key=='gallery') {
  6771. $key=get_lang('Gallery');
  6772. } elseif($key=='flash') {
  6773. $key=get_lang('Flash');
  6774. } elseif($key=='audio'){
  6775. $key=get_lang('Audio');
  6776. } elseif($key=='video') {
  6777. $key=get_lang('Video');
  6778. }
  6779. $return .= '<div class="doc_resource"><div style="margin-left:' . ($num * 18) . 'px;margin-right:5px;"><img style="cursor: pointer;" src="../img/nolines_plus.gif" align="absmiddle" id="img_' . $resource['id'] . '" onClick="javascript: testResources(\'' . $resource['id'] . '\',\'img_' . $resource['id'] . '\')"><img alt="" src="../img/lp_folder.gif" title="" align="absmiddle" />&nbsp;<span onClick="javascript: testResources(\'' . $resource['id'] . '\',\'img_' . $resource['id'] . '\')" style="cursor: pointer;" >' . $key . '</span></div><div style="display: none;" id="' . $resource['id'] . '">';
  6780. $return .= $this->write_resources_tree($resource['files'], $num +1);
  6781. $return .= '</div></div>';
  6782. } else {
  6783. if (!is_array($resource)) {
  6784. // It's a file.
  6785. $icon = choose_image($resource);
  6786. $position = strrpos($icon, '.');
  6787. $icon = substr($icon, 0, $position) . '_small.gif';
  6788. $file_info = explode('/', $resource);
  6789. $my_file_title = $file_info[0];
  6790. $my_file_name = $file_info[1];
  6791. //$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>';
  6792. // Show the "image name" not the filename of the image.
  6793. $return .= '<div class="doc_resource"><div style="margin-left:' . (($num +1) * 18) . 'px;margin-right:5px;"><a href="' . api_get_self() . '?cidReq=' . Security::remove_XSS($_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;' . $my_file_title . "</a></div></div>\r\n"; }
  6794. }
  6795. }
  6796. }
  6797. return $return;
  6798. }
  6799. /**
  6800. * Creates a list with all the exercises (quiz) in it
  6801. * @return string
  6802. */
  6803. public function get_exercises() {
  6804. // New for hotpotatoes.
  6805. $uploadPath = DIR_HOTPOTATOES; //defined in main_api
  6806. $tbl_doc = Database :: get_course_table(TABLE_DOCUMENT);
  6807. $tbl_quiz = Database :: get_course_table(TABLE_QUIZ_TEST);
  6808. $session_id = api_get_session_id();
  6809. $condition_session = api_get_session_condition($session_id);
  6810. $sql_quiz = "SELECT * FROM $tbl_quiz WHERE active<>'-1' $condition_session ORDER BY title ASC";
  6811. $sql_hot = "SELECT * FROM $tbl_doc WHERE path LIKE '" . $uploadPath . "/%/%htm%' $condition_session ORDER BY id ASC";
  6812. $res_quiz = Database::query($sql_quiz);
  6813. $res_hot = Database::query($sql_hot);
  6814. //$return .= '<div class="lp_resource_header"' . " onclick=\"javascript: if(document.getElementById('resExercise').style.display == 'block') {document.getElementById('resExercise').style.display = 'none';} else {document.getElementById('resExercise').style.display = 'block';}\"" . ' ><img align="left" alt="" src="../img/lp_' . TOOL_QUIZ . '.gif" style="margin-right:5px;" title="" />' . get_lang('Quiz') . '</div>';
  6815. $return .= '<div class="lp_resource">';
  6816. $return .= '<div class="lp_resource_element">';
  6817. $return .= '<img alt="" src="../img/new_test_small.gif" style="margin-right:5px;" title="" />';
  6818. $return .= '<a href="' . api_get_path(REL_CODE_PATH) . 'exercice/exercise_admin.php?lp_id=' . $this->lp_id . '">' . get_lang('NewExercise') . '</a>';
  6819. $return .= '</div>';
  6820. while ($row_hot = Database :: fetch_array($res_hot)) {
  6821. $return .= '<div class="lp_resource_element">';
  6822. // Display quizhotpotatoes.
  6823. $return .= '<img alt="hp" src="../img/hotpotatoes_s.png" style="margin-right:5px;" title="" width="18px" height="18px" />';
  6824. $return .= '<a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&amp;action=add_item&amp;type=' . TOOL_HOTPOTATOES . '&amp;file=' . $row_hot['id'] . '&amp;lp_id=' . $this->lp_id . '">' . ((!empty ($row_hot['comment'])) ? $row_hot['comment'] : Security :: remove_XSS($row_hot['title'])) . '</a>';
  6825. //$return .= $row_quiz['title'];
  6826. $return .= '</div>';
  6827. }
  6828. while ($row_quiz = Database :: fetch_array($res_quiz)) {
  6829. $return .= '<div class="lp_resource_element">';
  6830. $return .= '<img alt="" src="../img/quizz_small.gif" style="margin-right:5px;" title="" />';
  6831. $return .= '<a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&amp;action=add_item&amp;type=' . TOOL_QUIZ . '&amp;file=' . $row_quiz['id'] . '&amp;lp_id=' . $this->lp_id . '">' . Security :: remove_XSS($row_quiz['title']) . '</a>';
  6832. //$return .= $row_quiz['title'];
  6833. $return .= '</div>';
  6834. }
  6835. /*if (Database :: num_rows($res_quiz) == 0) {
  6836. $return .= '<div class="lp_resource_element">' . get_lang('NoExercisesAvailable') . '</div>';
  6837. }*/
  6838. $return .= '</div>';
  6839. return $return;
  6840. }
  6841. /**
  6842. * Creates a list with all the links in it
  6843. * @return string
  6844. */
  6845. public function get_links() {
  6846. $tbl_link = Database :: get_course_table(TABLE_LINK);
  6847. $session_id = api_get_session_id();
  6848. $condition_session = api_get_session_condition($session_id,false);
  6849. $sql_link = "SELECT * FROM $tbl_link $condition_session ORDER BY title ASC";
  6850. $res_link = Database::query($sql_link);
  6851. //$return .= '<div class="lp_resource_header"' . " onclick=\"javascript: if(document.getElementById('resLink').style.display == 'block') {document.getElementById('resLink').style.display = 'none';} else {document.getElementById('resLink').style.display = 'block';}\"" . '><img alt="" src="../img/lp_' . TOOL_LINK . '.gif" style="margin-right:5px;" title="" />' . get_lang('Links') . '</div>';
  6852. $return .= '<div class="lp_resource">';
  6853. $return .= '<div class="lp_resource_element">';
  6854. $return .= '<img alt="" src="../img/linksnew.gif" style="margin-right:5px;width:16px" title="" />';
  6855. $return .= '<a href="' . api_get_path(REL_CODE_PATH) . 'link/link.php?' . api_get_cidreq() . '&action=addlink&amp;lp_id=' . $this->lp_id . '" title="' . get_lang('LinkAdd') . '">' . get_lang('LinkAdd') . '</a>';
  6856. $return .= '</div>';
  6857. while ($row_link = Database :: fetch_array($res_link)) {
  6858. $return .= '<div class="lp_resource_element">';
  6859. $return .= '<img alt="" src="../img/lp_link.gif" style="margin-right:5px;" title="" />';
  6860. $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>';
  6861. $return .= '</div>';
  6862. }
  6863. /*if (Database :: num_rows($res_link) == 0)
  6864. $return .= '<div class="lp_resource_element">' . get_lang('NoLinksAvailable') . '</div>';
  6865. */
  6866. $return .= '</div>';
  6867. return $return;
  6868. }
  6869. /**
  6870. * Creates a list with all the student publications in it
  6871. * @return unknown
  6872. */
  6873. public function get_student_publications() {
  6874. $tbl_student = Database :: get_course_table(TABLE_STUDENT_PUBLICATION);
  6875. $session_id = api_get_session_id();
  6876. $condition_session = api_get_session_condition($session_id, false);
  6877. $sql_student = "SELECT * FROM $tbl_student $condition_session ORDER BY title ASC";
  6878. $res_student = Database::query($sql_student);
  6879. //$return .= '<div class="lp_resource_header"' . " onclick=\"javascript: if(document.getElementById('resStudent').style.display == 'block') {document.getElementById('resStudent').style.display = 'none';} else {document.getElementById('resStudent').style.display = 'block';}\"" . '><img alt="" src="../img/lp_' . TOOL_STUDENTPUBLICATION . '.gif" style="margin-right:5px;" title="" />' . get_lang('Student_publication') . '</div>';
  6880. $return .= '<div class="lp_resource" >';
  6881. $return .= '<div class="lp_resource_element">';
  6882. $return .= '<img align="left" alt="" src="../img/works_small.gif" style="margin-right:5px;" title="" />';
  6883. $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>';
  6884. $return .= '</div>';
  6885. $return .= '</div>';
  6886. return $return;
  6887. }
  6888. /**
  6889. * Creates a list with all the forums in it
  6890. * @return string
  6891. */
  6892. public function get_forums() {
  6893. require_once '../forum/forumfunction.inc.php';
  6894. require_once '../forum/forumconfig.inc.php';
  6895. global $table_forums, $table_threads, $table_posts, $table_item_property, $table_users;
  6896. $table_forums = Database :: get_course_table(TABLE_FORUM);
  6897. $table_threads = Database :: get_course_table(TABLE_FORUM_THREAD);
  6898. $table_posts = Database :: get_course_table(TABLE_FORUM_POST);
  6899. $table_item_property = Database :: get_course_table(TABLE_ITEM_PROPERTY);
  6900. $table_users = Database :: get_main_table(TABLE_MAIN_USER);
  6901. $a_forums = get_forums();
  6902. //$return .= '<div class="lp_resource_header"' . " onclick=\"javascript: if(document.getElementById('forums').style.display == 'block') {document.getElementById('forums').style.display = 'none';} else {document.getElementById('forums').style.display = 'block';}\"" . '><img alt="" src="../img/lp_forum.gif" style="margin-right:5px;" title="" />' . get_lang('Forums') . '</div>';
  6903. $return .= '<div class="lp_resource">';
  6904. $return .= '<div class="lp_resource_element">';
  6905. $return .= '<img alt="" src="../img/forum_new_small.gif" style="margin-right:5px;" title="" />';
  6906. $return .= '<a href="' . api_get_path(REL_CODE_PATH) . 'forum/index.php?' . api_get_cidreq() . '&action=add&amp;content=forum&amp;origin=learnpath&amp;lp_id=' . $this->lp_id . '" title="' . get_lang('CreateANewForum') . '">' . get_lang('CreateANewForum') . '</a>';
  6907. $return .= '</div>';
  6908. foreach ($a_forums as $forum) {
  6909. $return .= '<div class="lp_resource_element_no_link">';
  6910. $return .= '<script type="text/javascript">
  6911. function toggle_forum(forum_id){
  6912. if(document.getElementById("forum_"+forum_id+"_content").style.display == "none"){
  6913. document.getElementById("forum_"+forum_id+"_content").style.display = "block";
  6914. document.getElementById("forum_"+forum_id+"_opener").src = "' . api_get_path(WEB_IMG_PATH) . 'remove.gif";
  6915. }
  6916. else {
  6917. document.getElementById("forum_"+forum_id+"_content").style.display = "none";
  6918. document.getElementById("forum_"+forum_id+"_opener").src = "' . api_get_path(WEB_IMG_PATH) . 'add.gif";
  6919. }
  6920. }
  6921. </script>';
  6922. if (!empty($forum['forum_id'])) {
  6923. $return .= '<img alt="" src="../img/lp_forum.gif" style="margin-right:5px;" title="" />';
  6924. $return .= '<a style="cursor:hand" onclick="javascript: toggle_forum(' . $forum['forum_id'] . ')" style="vertical-align:middle"><img src="' . api_get_path(WEB_IMG_PATH) . 'add.gif" id="forum_' . $forum['forum_id'] . '_opener" align="absbottom" /></a>
  6925. <a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&amp;action=add_item&amp;type=' . TOOL_FORUM . '&amp;forum_id=' . $forum['forum_id'] . '&amp;lp_id=' . $this->lp_id . '" style="vertical-align:middle">' . Security :: remove_XSS($forum['forum_title']) . '</a><ul style="display:none" id="forum_' . $forum['forum_id'] . '_content">';
  6926. }
  6927. $a_threads = get_threads($forum['forum_id']);
  6928. if (is_array($a_threads)) {
  6929. foreach ($a_threads as $thread) {
  6930. $return .= '<li><a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&amp;action=add_item&amp;type=' . TOOL_THREAD . '&amp;thread_id=' . $thread['thread_id'] . '&amp;lp_id=' . $this->lp_id . '">' . Security :: remove_XSS($thread['thread_title']) . '</a></li>';
  6931. }
  6932. }
  6933. $return .= '</ul></div>';
  6934. }
  6935. return $return;
  6936. }
  6937. /**
  6938. * // TODO: The output encoding should be equal to the system encoding.
  6939. *
  6940. * Exports the learning path as a SCORM package. This is the main function that
  6941. * gathers the content, transforms it, writes the imsmanifest.xml file, zips the
  6942. * whole thing and returns the zip.
  6943. *
  6944. * This method needs to be called in PHP5, as it will fail with non-adequate
  6945. * XML package (like the ones for PHP4), and it is *not* a static method, so
  6946. * you need to call it on a learnpath object.
  6947. * @TODO The method might be redefined later on in the scorm class itself to avoid
  6948. * creating a SCORM structure if there is one already. However, if the initial SCORM
  6949. * path has been modified, it should use the generic method here below.
  6950. * @TODO link this function with the export_lp() function in the same class
  6951. * @param string Optional name of zip file. If none, title of learnpath is
  6952. * domesticated and trailed with ".zip"
  6953. * @return string Returns the zip package string, or null if error
  6954. */
  6955. public function scorm_export() {
  6956. global $_course;
  6957. // Remove memory and time limits as much as possible as this might be a long process...
  6958. if (function_exists('ini_set')) {
  6959. $mem = ini_get('memory_limit');
  6960. if (substr($mem, -1, 1) == 'M') {
  6961. $mem_num = substr($mem, 0, -1);
  6962. if ($mem_num < 128) {
  6963. ini_set('memory_limit', '128M');
  6964. }
  6965. } else {
  6966. ini_set('memory_limit', '128M');
  6967. }
  6968. ini_set('max_execution_time', 600);
  6969. //} else {
  6970. //error_log('Scorm export: could not change memory and time limits', 0);
  6971. }
  6972. // Create the zip handler (this will remain available throughout the method).
  6973. $archive_path = api_get_path(SYS_ARCHIVE_PATH);
  6974. $sys_course_path = api_get_path(SYS_COURSE_PATH);
  6975. $temp_dir_short = uniqid();
  6976. $temp_zip_dir = $archive_path.'/'.$temp_dir_short;
  6977. $temp_zip_file = $temp_zip_dir.'/'.md5(time()).'.zip';
  6978. $zip_folder = new PclZip($temp_zip_file);
  6979. $current_course_path = api_get_path(SYS_COURSE_PATH).api_get_course_path();
  6980. $root_path = $main_path = api_get_path(SYS_PATH);
  6981. $files_cleanup = array();
  6982. // Place to temporarily stash the zipfiles.
  6983. // create the temp dir if it doesn't exist
  6984. // or do a cleanup befor creating the zipfile.
  6985. if (!is_dir($temp_zip_dir)) {
  6986. mkdir($temp_zip_dir, api_get_permissions_for_new_directories());
  6987. } else {
  6988. // Cleanup: Check the temp dir for old files and delete them.
  6989. $handle = opendir($temp_zip_dir);
  6990. while (false !== ($file = readdir($handle))) {
  6991. if ($file != '.' && $file != '..') {
  6992. unlink("$temp_zip_dir/$file");
  6993. }
  6994. }
  6995. closedir($handle);
  6996. }
  6997. $zip_files = $zip_files_abs = $zip_files_dist = array();
  6998. if (is_dir($current_course_path.'/scorm/'.$this->path) && is_file($current_course_path.'/scorm/'.$this->path.'/imsmanifest.xml')) {
  6999. // Remove the possible . at the end of the path.
  7000. $dest_path_to_lp = substr($this->path, -1) == '.' ? substr($this->path, 0, -1) : $this->path;
  7001. $dest_path_to_scorm_folder = str_replace('//','/',$temp_zip_dir.'/scorm/'.$dest_path_to_lp);
  7002. mkdir($dest_path_to_scorm_folder, api_get_permissions_for_new_directories(), true);
  7003. $zip_files_dist = copyr($current_course_path.'/scorm/'.$this->path, $dest_path_to_scorm_folder, array('imsmanifest'), $zip_files);
  7004. }
  7005. // Build a dummy imsmanifest structure. Do not add to the zip yet (we still need it).
  7006. // This structure is developed following regulations for SCORM 1.2 packaging in the SCORM 1.2 Content
  7007. // Aggregation Model official document, secion "2.3 Content Packaging".
  7008. $xmldoc = new DOMDocument('1.0'); // We are going to build a UTF-8 encoded manifest. Later we will recode it to the desired (and supported) encoding.
  7009. $root = $xmldoc->createElement('manifest');
  7010. $root->setAttribute('identifier', 'SingleCourseManifest');
  7011. $root->setAttribute('version', '1.1');
  7012. $root->setAttribute('xmlns', 'http://www.imsproject.org/xsd/imscp_rootv1p1p2');
  7013. $root->setAttribute('xmlns:adlcp', 'http://www.adlnet.org/xsd/adlcp_rootv1p2');
  7014. $root->setAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance');
  7015. $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');
  7016. // Build mandatory sub-root container elements.
  7017. $metadata = $xmldoc->createElement('metadata');
  7018. $md_schema = $xmldoc->createElement('schema', 'ADL SCORM');
  7019. $metadata->appendChild($md_schema);
  7020. $md_schemaversion = $xmldoc->createElement('schemaversion', '1.2');
  7021. $metadata->appendChild($md_schemaversion);
  7022. $root->appendChild($metadata);
  7023. $organizations = $xmldoc->createElement('organizations');
  7024. $resources = $xmldoc->createElement('resources');
  7025. // Build the only organization we will use in building our learnpaths.
  7026. $organizations->setAttribute('default', 'chamilo_scorm_export');
  7027. $organization = $xmldoc->createElement('organization');
  7028. $organization->setAttribute('identifier', 'chamilo_scorm_export');
  7029. // To set the title of the SCORM entity (=organization), we take the name given
  7030. // in Chamilo and convert it to HTML entities using the Chamilo charset (not the
  7031. // learning path charset) as it is the encoding that defines how it is stored
  7032. // in the database. Then we convert it to HTML entities again as the "&" character
  7033. // alone is not authorized in XML (must be &amp;).
  7034. // The title is then decoded twice when extracting (see scorm::parse_manifest).
  7035. $org_title = $xmldoc->createElement('title', api_utf8_encode($this->get_name()));
  7036. $organization->appendChild($org_title);
  7037. // For each element, add it to the imsmanifest structure, then add it to the zip.
  7038. // Always call the learnpathItem->scorm_export() method to change it to the SCORM format.
  7039. $link_updates = array();
  7040. foreach ($this->items as $index => $item) {
  7041. if (!in_array($item->type, array(TOOL_QUIZ, TOOL_FORUM, TOOL_THREAD, TOOL_LINK, TOOL_STUDENTPUBLICATION))) {
  7042. // Get included documents from this item.
  7043. if ($item->type == 'sco')
  7044. $inc_docs = $item->get_resources_from_source(null, api_get_path(SYS_COURSE_PATH).api_get_course_path().'/'.'scorm/'.$this->path.'/'.$item->get_path());
  7045. else
  7046. $inc_docs = $item->get_resources_from_source();
  7047. // Give a child element <item> to the <organization> element.
  7048. $my_item_id = $item->get_id();
  7049. $my_item = $xmldoc->createElement('item');
  7050. $my_item->setAttribute('identifier', 'ITEM_'.$my_item_id);
  7051. $my_item->setAttribute('identifierref', 'RESOURCE_'.$my_item_id);
  7052. $my_item->setAttribute('isvisible', 'true');
  7053. // Give a child element <title> to the <item> element.
  7054. $my_title = $xmldoc->createElement('title', htmlspecialchars(api_utf8_encode($item->get_title()), ENT_QUOTES, 'UTF-8'));
  7055. $my_item->appendChild($my_title);
  7056. // Give a child element <adlcp:prerequisites> to the <item> element.
  7057. $my_prereqs = $xmldoc->createElement('adlcp:prerequisites', $this->get_scorm_prereq_string($my_item_id));
  7058. $my_prereqs->setAttribute('type', 'aicc_script');
  7059. $my_item->appendChild($my_prereqs);
  7060. // Give a child element <adlcp:maxtimeallowed> to the <item> element - not yet supported.
  7061. //$xmldoc->createElement('adlcp:maxtimeallowed','');
  7062. // Give a child element <adlcp:timelimitaction> to the <item> element - not yet supported.
  7063. //$xmldoc->createElement('adlcp:timelimitaction','');
  7064. // Give a child element <adlcp:datafromlms> to the <item> element - not yet supported.
  7065. //$xmldoc->createElement('adlcp:datafromlms','');
  7066. // Give a child element <adlcp:masteryscore> to the <item> element.
  7067. $my_masteryscore = $xmldoc->createElement('adlcp:masteryscore', $item->get_mastery_score());
  7068. $my_item->appendChild($my_masteryscore);
  7069. // Attach this item to the organization element or hits parent if there is one.
  7070. if (!empty($item->parent) && $item->parent != 0) {
  7071. $children = $organization->childNodes;
  7072. $possible_parent = &$this->get_scorm_xml_node($children, 'ITEM_'.$item->parent);
  7073. if (is_object($possible_parent)) {
  7074. $possible_parent->appendChild($my_item);
  7075. } else {
  7076. if ($this->debug > 0) { error_log('Parent ITEM_'.$item->parent.' of item ITEM_'.$my_item_id.' not found'); }
  7077. }
  7078. } else {
  7079. if ($this->debug > 0) { error_log('No parent'); }
  7080. $organization->appendChild($my_item);
  7081. }
  7082. // Get the path of the file(s) from the course directory root.
  7083. $my_file_path = $item->get_file_path('scorm/'.$this->path.'/');
  7084. //$my_xml_file_path = api_htmlentities(api_utf8_encode($my_file_path), ENT_QUOTES, 'UTF-8');
  7085. $my_xml_file_path = $my_file_path;
  7086. $my_sub_dir = dirname($my_file_path);
  7087. $my_sub_dir = str_replace('\\', '/', $my_sub_dir);
  7088. //$my_xml_sub_dir = api_htmlentities(api_utf8_encode($my_sub_dir), ENT_QUOTES, 'UTF-8');
  7089. $my_xml_sub_dir = $my_sub_dir;
  7090. // Give a <resource> child to the <resources> element
  7091. $my_resource = $xmldoc->createElement('resource');
  7092. $my_resource->setAttribute('identifier', 'RESOURCE_'.$item->get_id());
  7093. $my_resource->setAttribute('type', 'webcontent');
  7094. $my_resource->setAttribute('href', $my_xml_file_path);
  7095. // adlcp:scormtype can be either 'sco' or 'asset'.
  7096. if ($item->type == 'sco') {
  7097. $my_resource->setAttribute('adlcp:scormtype', 'sco');
  7098. } else {
  7099. $my_resource->setAttribute('adlcp:scormtype', 'asset');
  7100. }
  7101. // xml:base is the base directory to find the files declared in this resource.
  7102. $my_resource->setAttribute('xml:base', '');
  7103. // Give a <file> child to the <resource> element.
  7104. $my_file = $xmldoc->createElement('file');
  7105. $my_file->setAttribute('href', $my_xml_file_path);
  7106. $my_resource->appendChild($my_file);
  7107. // Dependency to other files - not yet supported.
  7108. $i = 1;
  7109. foreach ($inc_docs as $doc_info) {
  7110. if (count($doc_info) < 1 || empty($doc_info[0])) { continue; }
  7111. $my_dep = $xmldoc->createElement('resource');
  7112. $res_id = 'RESOURCE_'.$item->get_id().'_'.$i;
  7113. $my_dep->setAttribute('identifier', $res_id);
  7114. $my_dep->setAttribute('type', 'webcontent');
  7115. $my_dep->setAttribute('adlcp:scormtype', 'asset');
  7116. $my_dep_file = $xmldoc->createElement('file');
  7117. // Check type of URL.
  7118. //error_log(__LINE__.'Now dealing with '.$doc_info[0].' of type '.$doc_info[1].'-'.$doc_info[2], 0);
  7119. if ($doc_info[1] == 'remote') {
  7120. // Remote file. Save url as is.
  7121. $my_dep_file->setAttribute('href', $doc_info[0]);
  7122. $my_dep->setAttribute('xml:base', '');
  7123. } elseif ($doc_info[1] == 'local') {
  7124. switch ($doc_info[2]) {
  7125. case 'url': // Local URL - save path as url for now, don't zip file.
  7126. $abs_path = api_get_path(SYS_PATH).str_replace(api_get_path(WEB_PATH), '', $doc_info[0]);
  7127. $current_dir = dirname($abs_path);
  7128. $current_dir = str_replace('\\', '/', $current_dir);
  7129. $file_path = realpath($abs_path);
  7130. $file_path = str_replace('\\', '/', $file_path);
  7131. $my_dep_file->setAttribute('href', $file_path);
  7132. $my_dep->setAttribute('xml:base', '');
  7133. if (strstr($file_path, $main_path) !== false) {
  7134. // The calculated real path is really inside Chamilo's root path.
  7135. // Reduce file path to what's under the DocumentRoot.
  7136. $file_path = substr($file_path, strlen($root_path) - 1);
  7137. //echo $file_path;echo '<br /><br />';
  7138. //error_log(__LINE__.'Reduced url path: '.$file_path, 0);
  7139. $zip_files_abs[] = $file_path;
  7140. $link_updates[$my_file_path][] = array('orig' => $doc_info[0], 'dest' => $file_path);
  7141. $my_dep_file->setAttribute('href', $file_path);
  7142. $my_dep->setAttribute('xml:base', '');
  7143. }
  7144. elseif (empty($file_path)) {
  7145. /*$document_root = substr(api_get_path(SYS_PATH), 0, strpos(api_get_path(SYS_PATH), api_get_path(REL_PATH)));
  7146. if (strpos($document_root, -1) == '/') {
  7147. $document_root = substr(0, -1, $document_root);
  7148. }*/
  7149. $file_path = $_SERVER['DOCUMENT_ROOT'].$abs_path;
  7150. $file_path = str_replace('//', '/', $file_path);
  7151. if (file_exists($file_path)) {
  7152. $file_path = substr($file_path, strlen($current_dir)); // We get the relative path.
  7153. $zip_files[] = $my_sub_dir.'/'.$file_path;
  7154. $link_updates[$my_file_path][] = array('orig' => $doc_info[0], 'dest' => $file_path);
  7155. $my_dep_file->setAttribute('href', $file_path);
  7156. $my_dep->setAttribute('xml:base', '');
  7157. }
  7158. }
  7159. break;
  7160. case 'abs': // Absolute path from DocumentRoot. Save file and leave path as is in the zip.
  7161. $my_dep_file->setAttribute('href', $doc_info[0]);
  7162. $my_dep->setAttribute('xml:base', '');
  7163. //$current_dir = str_replace('\\', '/', dirname($current_course_path.'/'.$item->get_file_path())).'/';
  7164. // The next lines fix a bug when using the "subdir" mode of Chamilo, whereas
  7165. // an image path would be constructed as /var/www/subdir/subdir/img/foo.bar
  7166. $abs_img_path_without_subdir = $doc_info[0];
  7167. $relp = api_get_path(REL_PATH); // The url-append config param.
  7168. $pos = strpos($abs_img_path_without_subdir, $relp);
  7169. if ($pos === 0) {
  7170. $abs_img_path_without_subdir = '/'.substr($abs_img_path_without_subdir, strlen($relp));
  7171. }
  7172. //$file_path = realpath(api_get_path(SYS_PATH).$doc_info[0]);
  7173. $file_path = realpath(api_get_path(SYS_PATH).$abs_img_path_without_subdir);
  7174. $file_path = str_replace('\\', '/', $file_path);
  7175. $file_path = str_replace('//', '/', $file_path);
  7176. //error_log(__LINE__.'Abs path: '.$file_path, 0);
  7177. // Prepare the current directory path (until just under 'document') with a trailing slash.
  7178. $cur_path = substr($current_course_path, -1) == '/' ? $current_course_path : $current_course_path.'/';
  7179. // Check if the current document is in that path.
  7180. if (strstr($file_path, $cur_path) !== false) {
  7181. // The document is in that path, now get the relative path
  7182. // to the containing document.
  7183. $orig_file_path = dirname($cur_path.$my_file_path).'/';
  7184. $orig_file_path = str_replace('\\', '/', $orig_file_path);
  7185. $relative_path = '';
  7186. if (strstr($file_path, $cur_path) !== false) {
  7187. $relative_path = substr($file_path, strlen($orig_file_path));
  7188. $file_path = substr($file_path, strlen($cur_path));
  7189. } else {
  7190. // This case is still a problem as it's difficult to calculate a relative path easily
  7191. // might still generate wrong links.
  7192. //$file_path = substr($file_path,strlen($cur_path));
  7193. // Calculate the directory path to the current file (without trailing slash).
  7194. $my_relative_path = dirname($file_path);
  7195. $my_relative_path = str_replace('\\', '/', $my_relative_path);
  7196. $my_relative_file = basename($file_path);
  7197. // Calculate the directory path to the containing file (without trailing slash).
  7198. $my_orig_file_path = substr($orig_file_path, 0, -1);
  7199. $dotdot = '';
  7200. $subdir = '';
  7201. while (strstr($my_relative_path, $my_orig_file_path) === false && (strlen($my_orig_file_path) > 1) && (strlen($my_relative_path) > 1)) {
  7202. $my_relative_path2 = dirname($my_relative_path);
  7203. $my_relative_path2 = str_replace('\\', '/', $my_relative_path2);
  7204. $my_orig_file_path = dirname($my_orig_file_path);
  7205. $my_orig_file_path = str_replace('\\', '/', $my_orig_file_path);
  7206. $subdir = substr($my_relative_path, strlen($my_relative_path2) + 1).'/'.$subdir;
  7207. $dotdot += '../';
  7208. $my_relative_path = $my_relative_path2;
  7209. }
  7210. $relative_path = $dotdot.$subdir.$my_relative_file;
  7211. }
  7212. // Put the current document in the zip (this array is the array
  7213. // that will manage documents already in the course folder - relative).
  7214. $zip_files[] = $file_path;
  7215. // Update the links to the current document in the containing document (make them relative).
  7216. $link_updates[$my_file_path][] = array('orig' => $doc_info[0], 'dest' => $relative_path);
  7217. $my_dep_file->setAttribute('href', $file_path);
  7218. $my_dep->setAttribute('xml:base', '');
  7219. }
  7220. elseif (strstr($file_path,$main_path) !== false) {
  7221. // The calculated real path is really inside Chamilo's root path.
  7222. // Reduce file path to what's under the DocumentRoot.
  7223. $file_path = substr($file_path, strlen($root_path));
  7224. //echo $file_path;echo '<br /><br />';
  7225. //error_log('Reduced path: '.$file_path, 0);
  7226. $zip_files_abs[] = $file_path;
  7227. $link_updates[$my_file_path][] = array('orig' => $doc_info[0], 'dest' => $file_path);
  7228. $my_dep_file->setAttribute('href', 'document/'.$file_path);
  7229. $my_dep->setAttribute('xml:base', '');
  7230. }
  7231. elseif (empty($file_path)) {
  7232. /*$document_root = substr(api_get_path(SYS_PATH), 0, strpos(api_get_path(SYS_PATH), api_get_path(REL_PATH)));
  7233. if(strpos($document_root,-1) == '/') {
  7234. $document_root = substr(0, -1, $document_root);
  7235. }*/
  7236. $file_path = $_SERVER['DOCUMENT_ROOT'].$doc_info[0];
  7237. $file_path = str_replace('//', '/', $file_path);
  7238. if (file_exists($file_path)) {
  7239. $file_path = substr($file_path,strlen($current_dir)); // We get the relative path.
  7240. $zip_files[] = $my_sub_dir.'/'.$file_path;
  7241. $link_updates[$my_file_path][] = array('orig' => $doc_info[0], 'dest' => $file_path);
  7242. $my_dep_file->setAttribute('href','document/'.$file_path);
  7243. $my_dep->setAttribute('xml:base', '');
  7244. }
  7245. }
  7246. break;
  7247. 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
  7248. if (substr($doc_info[0], 0, 2) == '..') {
  7249. // Relative path going up.
  7250. $current_dir = dirname($current_course_path.'/'.$item->get_file_path()).'/';
  7251. $current_dir = str_replace('\\', '/', $current_dir);
  7252. $file_path = realpath($current_dir.$doc_info[0]);
  7253. $file_path = str_replace('\\', '/', $file_path);
  7254. //error_log($file_path.' <-> '.$main_path,0);
  7255. if (strstr($file_path, $main_path) !== false) {
  7256. // The calculated real path is really inside Chamilo's root path.
  7257. // Reduce file path to what's under the DocumentRoot.
  7258. $file_path = substr($file_path, strlen($root_path));
  7259. //error_log('Reduced path: '.$file_path, 0);
  7260. $zip_files_abs[] = $file_path;
  7261. $link_updates[$my_file_path][] = array('orig' => $doc_info[0], 'dest' => $file_path);
  7262. $my_dep_file->setAttribute('href', 'document/'.$file_path);
  7263. $my_dep->setAttribute('xml:base', '');
  7264. }
  7265. } else {
  7266. $zip_files[] = $my_sub_dir.'/'.$doc_info[0];
  7267. $my_dep_file->setAttribute('href', $doc_info[0]);
  7268. $my_dep->setAttribute('xml:base', $my_xml_sub_dir);
  7269. }
  7270. break;
  7271. default:
  7272. $my_dep_file->setAttribute('href', $doc_info[0]);
  7273. $my_dep->setAttribute('xml:base', '');
  7274. break;
  7275. }
  7276. }
  7277. $my_dep->appendChild($my_dep_file);
  7278. $resources->appendChild($my_dep);
  7279. $dependency = $xmldoc->createElement('dependency');
  7280. $dependency->setAttribute('identifierref', $res_id);
  7281. $my_resource->appendChild($dependency);
  7282. $i++;
  7283. }
  7284. //$my_dependency = $xmldoc->createElement('dependency');
  7285. //$my_dependency->setAttribute('identifierref', '');
  7286. $resources->appendChild($my_resource);
  7287. $zip_files[] = $my_file_path;
  7288. //error_log('File '.$my_file_path. ' added to $zip_files', 0);
  7289. } else {
  7290. // If the item is a quiz or a link or whatever non-exportable, we include a step indicating it.
  7291. if ($item->type == TOOL_LINK) {
  7292. $my_item = $xmldoc->createElement('item');
  7293. $my_item->setAttribute('identifier', 'ITEM_'.$item->get_id());
  7294. $my_item->setAttribute('identifierref', 'RESOURCE_'.$item->get_id());
  7295. $my_item->setAttribute('isvisible', 'true');
  7296. // Give a child element <title> to the <item> element.
  7297. $my_title = $xmldoc->createElement('title', htmlspecialchars(api_utf8_encode($item->get_title()), ENT_QUOTES, 'UTF-8'));
  7298. $my_item->appendChild($my_title);
  7299. // Give a child element <adlcp:prerequisites> to the <item> element.
  7300. $my_prereqs = $xmldoc->createElement('adlcp:prerequisites', $item->get_prereq_string());
  7301. $my_prereqs->setAttribute('type', 'aicc_script');
  7302. $my_item->appendChild($my_prereqs);
  7303. // Give a child element <adlcp:maxtimeallowed> to the <item> element - not yet supported.
  7304. //$xmldoc->createElement('adlcp:maxtimeallowed', '');
  7305. // Give a child element <adlcp:timelimitaction> to the <item> element - not yet supported.
  7306. //$xmldoc->createElement('adlcp:timelimitaction', '');
  7307. // Give a child element <adlcp:datafromlms> to the <item> element - not yet supported.
  7308. //$xmldoc->createElement('adlcp:datafromlms', '');
  7309. // Give a child element <adlcp:masteryscore> to the <item> element.
  7310. $my_masteryscore = $xmldoc->createElement('adlcp:masteryscore', $item->get_mastery_score());
  7311. $my_item->appendChild($my_masteryscore);
  7312. // Attach this item to the organization element or its parent if there is one.
  7313. if (!empty($item->parent) && $item->parent != 0) {
  7314. $children = $organization->childNodes;
  7315. for ($i = 0; $i < $children->length; $i++) {
  7316. $item_temp = $children->item($i);
  7317. if ($item_temp -> nodeName == 'item') {
  7318. if ($item_temp->getAttribute('identifier') == 'ITEM_'.$item->parent) {
  7319. $item_temp -> appendChild($my_item);
  7320. }
  7321. }
  7322. }
  7323. } else {
  7324. $organization->appendChild($my_item);
  7325. }
  7326. $my_file_path = 'link_'.$item->get_id().'.html';
  7327. $sql = 'SELECT url, title FROM '.Database :: get_course_table(TABLE_LINK).' WHERE id='.$item->path;
  7328. $rs = Database::query($sql);
  7329. if ($link = Database :: fetch_array($rs)) {
  7330. $url = $link['url'];
  7331. $title = stripslashes($link['title']);
  7332. $links_to_create[$my_file_path] = array('title' => $title, 'url' => $url);
  7333. //$my_xml_file_path = api_htmlentities(api_utf8_encode($my_file_path), ENT_QUOTES, 'UTF-8');
  7334. $my_xml_file_path = $my_file_path;
  7335. $my_sub_dir = dirname($my_file_path);
  7336. $my_sub_dir = str_replace('\\', '/', $my_sub_dir);
  7337. //$my_xml_sub_dir = api_htmlentities(api_utf8_encode($my_sub_dir), ENT_QUOTES, 'UTF-8');
  7338. $my_xml_sub_dir = $my_sub_dir;
  7339. // Give a <resource> child to the <resources> element.
  7340. $my_resource = $xmldoc->createElement('resource');
  7341. $my_resource->setAttribute('identifier', 'RESOURCE_'.$item->get_id());
  7342. $my_resource->setAttribute('type', 'webcontent');
  7343. $my_resource->setAttribute('href', $my_xml_file_path);
  7344. // adlcp:scormtype can be either 'sco' or 'asset'.
  7345. $my_resource->setAttribute('adlcp:scormtype', 'asset');
  7346. // xml:base is the base directory to find the files declared in this resource.
  7347. $my_resource->setAttribute('xml:base', '');
  7348. // give a <file> child to the <resource> element.
  7349. $my_file = $xmldoc->createElement('file');
  7350. $my_file->setAttribute('href', $my_xml_file_path);
  7351. $my_resource->appendChild($my_file);
  7352. $resources->appendChild($my_resource);
  7353. }
  7354. }
  7355. elseif ($item->type == TOOL_QUIZ) {
  7356. require_once api_get_path(SYS_CODE_PATH).'exercice/exercise.class.php';
  7357. $exe_id = $item->path; // Should be using ref when everything will be cleaned up in this regard.
  7358. $exe = new Exercise();
  7359. $exe->read($exe_id);
  7360. $my_item = $xmldoc->createElement('item');
  7361. $my_item->setAttribute('identifier', 'ITEM_'.$item->get_id());
  7362. $my_item->setAttribute('identifierref', 'RESOURCE_'.$item->get_id());
  7363. $my_item->setAttribute('isvisible', 'true');
  7364. // Give a child element <title> to the <item> element.
  7365. $my_title = $xmldoc->createElement('title', htmlspecialchars(api_utf8_encode($item->get_title()), ENT_QUOTES, 'UTF-8'));
  7366. $my_item->appendChild($my_title);
  7367. $my_max_score = $xmldoc->createElement('max_score', $item->get_max());
  7368. //$my_item->appendChild($my_max_score);
  7369. // Give a child element <adlcp:prerequisites> to the <item> element.
  7370. $my_prereqs = $xmldoc->createElement('adlcp:prerequisites', $item->get_prereq_string());
  7371. $my_prereqs->setAttribute('type','aicc_script');
  7372. $my_item->appendChild($my_prereqs);
  7373. // Give a child element <adlcp:masteryscore> to the <item> element.
  7374. $my_masteryscore = $xmldoc->createElement('adlcp:masteryscore', $item->get_mastery_score());
  7375. $my_item->appendChild($my_masteryscore);
  7376. // Attach this item to the organization element or hits parent if there is one.
  7377. if (!empty($item->parent) && $item->parent != 0) {
  7378. $children = $organization->childNodes;
  7379. for ($i = 0; $i < $children->length; $i++) {
  7380. $item_temp = $children->item($i);
  7381. if ($item_temp -> nodeName == 'item') {
  7382. if ($item_temp->getAttribute('identifier') == 'ITEM_'.$item->parent) {
  7383. $item_temp -> appendChild($my_item);
  7384. }
  7385. }
  7386. }
  7387. } else {
  7388. $organization->appendChild($my_item);
  7389. }
  7390. // Include export scripts.
  7391. require_once api_get_path(SYS_CODE_PATH).'exercice/export/scorm/scorm_export.php';
  7392. // Get the path of the file(s) from the course directory root
  7393. //$my_file_path = $item->get_file_path('scorm/'.$this->path.'/');
  7394. $my_file_path = 'quiz_'.$item->get_id().'.html';
  7395. // Write the contents of the exported exercise into a (big) html file
  7396. // to later pack it into the exported SCORM. The file will be removed afterwards.
  7397. $contents = export_exercise($exe_id,true);
  7398. $tmp_file_path = $archive_path.$temp_dir_short.'/'.$my_file_path;
  7399. $res = file_put_contents($tmp_file_path, $contents);
  7400. if ($res === false) { error_log('Could not write into file '.$tmp_file_path.' '.__FILE__.' '.__LINE__, 0); }
  7401. $files_cleanup[] = $tmp_file_path;
  7402. //error_log($tmp_path); die();
  7403. //$my_xml_file_path = api_htmlentities(api_utf8_encode($my_file_path), ENT_QUOTES, 'UTF-8');
  7404. $my_xml_file_path = $my_file_path;
  7405. $my_sub_dir = dirname($my_file_path);
  7406. $my_sub_dir = str_replace('\\', '/', $my_sub_dir);
  7407. //$my_xml_sub_dir = api_htmlentities(api_utf8_encode($my_sub_dir), ENT_QUOTES, 'UTF-8');
  7408. $my_xml_sub_dir = $my_sub_dir;
  7409. // Give a <resource> child to the <resources> element.
  7410. $my_resource = $xmldoc->createElement('resource');
  7411. $my_resource->setAttribute('identifier', 'RESOURCE_'.$item->get_id());
  7412. $my_resource->setAttribute('type', 'webcontent');
  7413. $my_resource->setAttribute('href', $my_xml_file_path);
  7414. // adlcp:scormtype can be either 'sco' or 'asset'.
  7415. $my_resource->setAttribute('adlcp:scormtype', 'sco');
  7416. // xml:base is the base directory to find the files declared in this resource.
  7417. $my_resource->setAttribute('xml:base', '');
  7418. // Give a <file> child to the <resource> element.
  7419. $my_file = $xmldoc->createElement('file');
  7420. $my_file->setAttribute('href', $my_xml_file_path);
  7421. $my_resource->appendChild($my_file);
  7422. // Get included docs.
  7423. $inc_docs = $item->get_resources_from_source(null,$tmp_file_path);
  7424. // Dependency to other files - not yet supported.
  7425. $i = 1;
  7426. foreach ($inc_docs as $doc_info) {
  7427. if (count($doc_info) < 1 || empty($doc_info[0])) { continue; }
  7428. $my_dep = $xmldoc->createElement('resource');
  7429. $res_id = 'RESOURCE_'.$item->get_id().'_'.$i;
  7430. $my_dep->setAttribute('identifier', $res_id);
  7431. $my_dep->setAttribute('type', 'webcontent');
  7432. $my_dep->setAttribute('adlcp:scormtype', 'asset');
  7433. $my_dep_file = $xmldoc->createElement('file');
  7434. // Check type of URL.
  7435. //error_log(__LINE__.'Now dealing with '.$doc_info[0].' of type '.$doc_info[1].'-'.$doc_info[2], 0);
  7436. if ($doc_info[1] == 'remote') {
  7437. // Remote file. Save url as is.
  7438. $my_dep_file->setAttribute('href', $doc_info[0]);
  7439. $my_dep->setAttribute('xml:base', '');
  7440. } elseif ($doc_info[1] == 'local') {
  7441. switch ($doc_info[2]) {
  7442. case 'url': // Local URL - save path as url for now, don't zip file.
  7443. // Save file but as local file (retrieve from URL).
  7444. $abs_path = api_get_path(SYS_PATH).str_replace(api_get_path(WEB_PATH), '', $doc_info[0]);
  7445. $current_dir = dirname($abs_path);
  7446. $current_dir = str_replace('\\', '/', $current_dir);
  7447. $file_path = realpath($abs_path);
  7448. $file_path = str_replace('\\', '/', $file_path);
  7449. $my_dep_file->setAttribute('href', 'document/'.$file_path);
  7450. $my_dep->setAttribute('xml:base', '');
  7451. if (strstr($file_path, $main_path) !== false) {
  7452. // The calculated real path is really inside the chamilo root path.
  7453. // Reduce file path to what's under the DocumentRoot.
  7454. $file_path = substr($file_path, strlen($root_path));
  7455. //echo $file_path;echo '<br /><br />';
  7456. //error_log('Reduced path: '.$file_path, 0);
  7457. $zip_files_abs[] = $file_path;
  7458. $link_updates[$my_file_path][] = array('orig' => $doc_info[0], 'dest' => 'document/'.$file_path);
  7459. $my_dep_file->setAttribute('href', 'document/'.$file_path);
  7460. $my_dep->setAttribute('xml:base', '');
  7461. }
  7462. elseif (empty($file_path)) {
  7463. /*$document_root = substr(api_get_path(SYS_PATH), 0, strpos(api_get_path(SYS_PATH),api_get_path(REL_PATH)));
  7464. if (strpos($document_root,-1) == '/') {
  7465. $document_root = substr(0, -1, $document_root);
  7466. }*/
  7467. $file_path = $_SERVER['DOCUMENT_ROOT'].$abs_path;
  7468. $file_path = str_replace('//', '/', $file_path);
  7469. if (file_exists($file_path)) {
  7470. $file_path = substr($file_path, strlen($current_dir)); // We get the relative path.
  7471. $zip_files[] = $my_sub_dir.'/'.$file_path;
  7472. $link_updates[$my_file_path][] = array('orig' => $doc_info[0], 'dest' => 'document/'.$file_path);
  7473. $my_dep_file->setAttribute('href', 'document/'.$file_path);
  7474. $my_dep->setAttribute('xml:base', '');
  7475. }
  7476. }
  7477. break;
  7478. case 'abs': // Absolute path from DocumentRoot. Save file and leave path as is in the zip.
  7479. $current_dir = dirname($current_course_path.'/'.$item->get_file_path()).'/';
  7480. $current_dir = str_replace('\\', '/', $current_dir);
  7481. $file_path = realpath($doc_info[0]);
  7482. $file_path = str_replace('\\', '/', $file_path);
  7483. $my_dep_file->setAttribute('href', $file_path);
  7484. $my_dep->setAttribute('xml:base', '');
  7485. if (strstr($file_path,$main_path) !== false) {
  7486. // The calculated real path is really inside the chamilo root path.
  7487. // Reduce file path to what's under the DocumentRoot.
  7488. $file_path = substr($file_path, strlen($root_path));
  7489. //echo $file_path;echo '<br /><br />';
  7490. //error_log('Reduced path: '.$file_path, 0);
  7491. $zip_files_abs[] = $file_path;
  7492. $link_updates[$my_file_path][] = array('orig' => $doc_info[0], 'dest' => $file_path);
  7493. $my_dep_file->setAttribute('href', 'document/'.$file_path);
  7494. $my_dep->setAttribute('xml:base', '');
  7495. }
  7496. elseif (empty($file_path)) {
  7497. /*$document_root = substr(api_get_path(SYS_PATH), 0, strpos(api_get_path(SYS_PATH), api_get_path(REL_PATH)));
  7498. if (strpos($document_root,-1) == '/') {
  7499. $document_root = substr(0, -1, $document_root);
  7500. }*/
  7501. $file_path = $_SERVER['DOCUMENT_ROOT'].$doc_info[0];
  7502. $file_path = str_replace('//', '/', $file_path);
  7503. if (file_exists($file_path)) {
  7504. $file_path = substr($file_path,strlen($current_dir)); // We get the relative path.
  7505. $zip_files[] = $my_sub_dir.'/'.$file_path;
  7506. $link_updates[$my_file_path][] = array('orig' => $doc_info[0], 'dest' => $file_path);
  7507. $my_dep_file->setAttribute('href', 'document/'.$file_path);
  7508. $my_dep->setAttribute('xml:base', '');
  7509. }
  7510. }
  7511. break;
  7512. 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
  7513. if (substr($doc_info[0], 0, 2) == '..') {
  7514. // Relative path going up.
  7515. $current_dir = dirname($current_course_path.'/'.$item->get_file_path()).'/';
  7516. $current_dir = str_replace('\\', '/', $current_dir);
  7517. $file_path = realpath($current_dir.$doc_info[0]);
  7518. $file_path = str_replace('\\', '/', $file_path);
  7519. //error_log($file_path.' <-> '.$main_path, 0);
  7520. if (strstr($file_path, $main_path) !== false) {
  7521. // The calculated real path is really inside Chamilo's root path.
  7522. // Reduce file path to what's under the DocumentRoot.
  7523. $file_path = substr($file_path, strlen($root_path));
  7524. $file_path_dest = $file_path;
  7525. // File path is courses/CHAMILO/document/....
  7526. $info_file_path = explode('/', $file_path);
  7527. if ($info_file_path[0] == 'courses') { // Add character "/" in file path.
  7528. $file_path_dest = 'document/'.$file_path;
  7529. }
  7530. //error_log('Reduced path: '.$file_path, 0);
  7531. $zip_files_abs[] = $file_path;
  7532. $link_updates[$my_file_path][] = array('orig' => $doc_info[0], 'dest' => $file_path_dest);
  7533. $my_dep_file->setAttribute('href', 'document/'.$file_path);
  7534. $my_dep->setAttribute('xml:base', '');
  7535. }
  7536. } else {
  7537. $zip_files[] = $my_sub_dir.'/'.$doc_info[0];
  7538. $my_dep_file->setAttribute('href', $doc_info[0]);
  7539. $my_dep->setAttribute('xml:base', $my_xml_sub_dir);
  7540. }
  7541. break;
  7542. default:
  7543. $my_dep_file->setAttribute('href', $doc_info[0]); // ../../courses/
  7544. $my_dep->setAttribute('xml:base', '');
  7545. break;
  7546. }
  7547. }
  7548. $my_dep->appendChild($my_dep_file);
  7549. $resources->appendChild($my_dep);
  7550. $dependency = $xmldoc->createElement('dependency');
  7551. $dependency->setAttribute('identifierref', $res_id);
  7552. $my_resource->appendChild($dependency);
  7553. $i++;
  7554. }
  7555. $resources->appendChild($my_resource);
  7556. $zip_files[] = $my_file_path;
  7557. } else {
  7558. // Get the path of the file(s) from the course directory root
  7559. $my_file_path = 'non_exportable.html';
  7560. //$my_xml_file_path = api_htmlentities(api_utf8_encode($my_file_path), ENT_COMPAT, 'UTF-8');
  7561. $my_xml_file_path = $my_file_path;
  7562. $my_sub_dir = dirname($my_file_path);
  7563. $my_sub_dir = str_replace('\\', '/', $my_sub_dir);
  7564. //$my_xml_sub_dir = api_htmlentities(api_utf8_encode($my_sub_dir), ENT_COMPAT, 'UTF-8');
  7565. $my_xml_sub_dir = $my_sub_dir;
  7566. // Give a <resource> child to the <resources> element.
  7567. $my_resource = $xmldoc->createElement('resource');
  7568. $my_resource->setAttribute('identifier', 'RESOURCE_'.$item->get_id());
  7569. $my_resource->setAttribute('type', 'webcontent');
  7570. $my_resource->setAttribute('href', 'document/'.$my_xml_file_path);
  7571. // adlcp:scormtype can be either 'sco' or 'asset'.
  7572. $my_resource->setAttribute('adlcp:scormtype', 'asset');
  7573. // xml:base is the base directory to find the files declared in this resource.
  7574. $my_resource->setAttribute('xml:base', '');
  7575. // Give a <file> child to the <resource> element.
  7576. $my_file = $xmldoc->createElement('file');
  7577. $my_file->setAttribute('href', 'document/'.$my_xml_file_path);
  7578. $my_resource->appendChild($my_file);
  7579. $resources->appendChild($my_resource);
  7580. }
  7581. }
  7582. }
  7583. $organizations->appendChild($organization);
  7584. $root->appendChild($organizations);
  7585. $root->appendChild($resources);
  7586. $xmldoc->appendChild($root);
  7587. // TODO: Add a readme file here, with a short description and a link to the Reload player
  7588. // then add the file to the zip, then destroy the file (this is done automatically).
  7589. // http://www.reload.ac.uk/scormplayer.html - once done, don't forget to close FS#138
  7590. //error_log(print_r($zip_files,true), 0);
  7591. foreach ($zip_files as $file_path) {
  7592. if (empty($file_path)) { continue; }
  7593. //error_log(__LINE__.'getting document from '.$sys_course_path.$_course['path'].'/'.$file_path.' removing '.$sys_course_path.$_course['path'].'/',0);
  7594. $dest_file = $archive_path.$temp_dir_short.'/'.$file_path;
  7595. $this->create_path($dest_file);
  7596. //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);
  7597. //echo $main_path.$file_path.'<br />';
  7598. @copy($sys_course_path.$_course['path'].'/'.$file_path, $dest_file);
  7599. // Check if the file needs a link update.
  7600. if (in_array($file_path, array_keys($link_updates))) {
  7601. $string = file_get_contents($dest_file);
  7602. unlink($dest_file);
  7603. foreach ($link_updates[$file_path] as $old_new) {
  7604. //error_log('Replacing '.$old_new['orig'].' by '.$old_new['dest'].' in '.$file_path, 0);
  7605. // This is an ugly hack that allows .flv files to be found by the flv player that
  7606. // will be added in document/main/inc/lib/flv_player/flv_player.swf and that needs
  7607. // to find the flv to play in document/main/, so we replace main/ in the flv path by
  7608. // ../../.. to return from inc/lib/flv_player to the document/main path.
  7609. if (substr($old_new['dest'], -3) == 'flv' && substr($old_new['dest'], 0, 5) == 'main/') {
  7610. $old_new['dest'] = str_replace('main/', '../../../', $old_new['dest']);
  7611. }
  7612. elseif (substr($old_new['dest'], -3) == 'flv' && substr($old_new['dest'], 0, 6) == 'video/') {
  7613. $old_new['dest'] = str_replace('video/', '../../../../video/', $old_new['dest']);
  7614. }
  7615. $string = str_replace($old_new['orig'], $old_new['dest'], $string);
  7616. }
  7617. file_put_contents($dest_file, $string);
  7618. }
  7619. }
  7620. foreach ($zip_files_abs as $file_path) {
  7621. if (empty($file_path)) { continue; }
  7622. //error_log(__LINE__.'checking existence of '.$main_path.$file_path.'', 0);
  7623. if (!is_file($main_path.$file_path) || !is_readable($main_path.$file_path)) { continue; }
  7624. //error_log(__LINE__.'getting document from '.$main_path.$file_path.' removing '.api_get_path(SYS_COURSE_PATH).$_course['path'].'/', 0);
  7625. $dest_file = $archive_path.$temp_dir_short.'/document/'.$file_path;
  7626. $this->create_path($dest_file);
  7627. //error_log('Created path '.api_get_path(SYS_ARCHIVE_PATH).$temp_dir_short.'/document/'.$file_path, 0);
  7628. //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);
  7629. //echo $main_path.$file_path.' - '.$dest_file.'<br />';
  7630. copy($main_path.$file_path, $dest_file);
  7631. // Check if the file needs a link update.
  7632. if (in_array($file_path, array_keys($link_updates))) {
  7633. $string = file_get_contents($dest_file);
  7634. unlink($dest_file);
  7635. foreach ($link_updates[$file_path] as $old_new) {
  7636. //error_log('Replacing '.$old_new['orig'].' by '.$old_new['dest'].' in '.$file_path, 0);
  7637. // This is an ugly hack that allows .flv files to be found by the flv player that
  7638. // will be added in document/main/inc/lib/flv_player/flv_player.swf and that needs
  7639. // to find the flv to play in document/main/, so we replace main/ in the flv path by
  7640. // ../../.. to return from inc/lib/flv_player to the document/main path.
  7641. if (substr($old_new['dest'], -3) == 'flv' && substr($old_new['dest'], 0, 5) == 'main/') {
  7642. $old_new['dest'] = str_replace('main/', '../../../', $old_new['dest']);
  7643. }
  7644. $string = str_replace($old_new['orig'], $old_new['dest'], $string);
  7645. }
  7646. file_put_contents($dest_file, $string);
  7647. }
  7648. }
  7649. if (is_array($links_to_create)) {
  7650. foreach ($links_to_create as $file => $link) {
  7651. $file_content = '<!DOCTYPE html
  7652. PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  7653. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  7654. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="'.api_get_language_isocode().'" lang="'.api_get_language_isocode().'">
  7655. <head>
  7656. <title>'.$link['title'].'</title>
  7657. <meta http-equiv="Content-Type" content="text/html; charset='.api_get_system_encoding().'" />
  7658. </head>
  7659. <body dir="'.api_get_text_direction().'">
  7660. <div style="text-align:center"><a href="'.$link['url'].'">'.$link['title'].'</a></div>
  7661. </body>
  7662. </html>';
  7663. file_put_contents($archive_path.$temp_dir_short.'/'.$file, $file_content);
  7664. }
  7665. }
  7666. // Add non exportable message explanation.
  7667. $lang_not_exportable = get_lang('ThisItemIsNotExportable');
  7668. $file_content = '<!DOCTYPE html
  7669. PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  7670. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  7671. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="'.api_get_language_isocode().'" lang="'.api_get_language_isocode().'">
  7672. <head>
  7673. <title>'.$lang_not_exportable.'</title>
  7674. <meta http-equiv="Content-Type" content="text/html; charset='.api_get_system_encoding().'" />
  7675. </head>
  7676. <body dir="'.api_get_text_direction().'">
  7677. ';
  7678. $file_content .=
  7679. <<<EOD
  7680. <style>
  7681. .error-message {
  7682. font-family: arial, verdana, helvetica, sans-serif;
  7683. border-width: 1px;
  7684. border-style: solid;
  7685. left: 50%;
  7686. margin: 10px auto;
  7687. min-height: 30px;
  7688. padding: 5px;
  7689. right: 50%;
  7690. width: 500px;
  7691. background-color: #FFD1D1;
  7692. border-color: #FF0000;
  7693. color: #000;
  7694. }
  7695. </style>
  7696. <body>
  7697. <div class="error-message">
  7698. $lang_not_exportable
  7699. </div>
  7700. </body>
  7701. </html>
  7702. EOD;
  7703. if (!is_dir($archive_path.$temp_dir_short.'/document')) {
  7704. @mkdir($archive_path.$temp_dir_short.'/document', api_get_permissions_for_new_directories());
  7705. }
  7706. file_put_contents($archive_path.$temp_dir_short.'/document/non_exportable.html', $file_content);
  7707. // Add the extra files that go along with a SCORM package.
  7708. $main_code_path = api_get_path(SYS_CODE_PATH).'newscorm/packaging/';
  7709. $extra_files = scandir($main_code_path);
  7710. foreach ($extra_files as $extra_file) {
  7711. if (strpos($extra_file, '.') === 0)
  7712. continue;
  7713. else {
  7714. $dest_file = $archive_path . $temp_dir_short . '/' . $extra_file;
  7715. $this->create_path($dest_file);
  7716. copy($main_code_path.$extra_file, $dest_file);
  7717. }
  7718. }
  7719. // Finalize the imsmanifest structure, add to the zip, then return the zip.
  7720. $manifest = @$xmldoc->saveXML();
  7721. $manifest = api_utf8_decode_xml($manifest); // The manifest gets the system encoding now.
  7722. file_put_contents($archive_path.'/'.$temp_dir_short.'/imsmanifest.xml', $manifest);
  7723. $zip_folder->add($archive_path.'/'.$temp_dir_short, PCLZIP_OPT_REMOVE_PATH, $archive_path.'/'.$temp_dir_short.'/');
  7724. // Clean possible temporary files.
  7725. foreach ($files_cleanup as $file) {
  7726. $res = unlink($file);
  7727. if ($res === false) { error_log('Could not delete temp file '.$file.' '.__FILE__.' '.__LINE__, 0); }
  7728. }
  7729. // Send file to client.
  7730. //$name = 'scorm_export_'.$this->lp_id.'.zip';
  7731. require_once api_get_path(LIBRARY_PATH).'fileUpload.lib.php';
  7732. $name = replace_dangerous_char($this->get_name()).'.zip';
  7733. DocumentManager::file_send_for_download($temp_zip_file, true, $name);
  7734. }
  7735. public function scorm_export_to_pdf($lp_id) {
  7736. $lp_id = intval($lp_id);
  7737. $files_to_export = array();
  7738. $course_data = api_get_course_info($this->cc);
  7739. if (!empty($course_data)) {
  7740. $scorm_path = api_get_path(SYS_COURSE_PATH).$course_data['path'].'/scorm/'.$this->path;
  7741. require_once api_get_path(LIBRARY_PATH).'document.lib.php';
  7742. $list = $this->get_flat_ordered_items_list($lp_id);
  7743. foreach($list as $item_id) {
  7744. $item = $this->items[$item_id];
  7745. //Getting documents from a LP with chamilo documents
  7746. switch ($item->type) {
  7747. case 'document':
  7748. $file_data = DocumentManager::get_document_data_by_id($item->path, $this->cc);
  7749. $file_path = api_get_path(SYS_COURSE_PATH).$course_data['path'].'/document'.$file_data['path'];
  7750. if (file_exists($file_path)) {
  7751. $files_to_export[] = array('title'=>$item->get_title(),'path'=>$file_path);
  7752. }
  7753. break;
  7754. case 'sco':
  7755. $file_path = $scorm_path.'/'.$item->path;
  7756. if (file_exists($file_path)) {
  7757. $files_to_export[] = array('title'=>$item->get_title(),'path'=>$file_path);
  7758. }
  7759. break;
  7760. case 'dokeos_chapter':
  7761. case 'dir':
  7762. case 'chapter':
  7763. $files_to_export[] = array('title'=>$item->get_title(),'path'=>null);
  7764. break;
  7765. }
  7766. }
  7767. require_once api_get_path(LIBRARY_PATH).'pdf.lib.php';
  7768. $pdf = new PDF();
  7769. $result = $pdf->html_to_pdf($files_to_export, $this->name, $this->cc, true);
  7770. return $result;
  7771. }
  7772. return false;
  7773. }
  7774. /**
  7775. * Temp function to be moved in main_api or the best place around for this. Creates a file path
  7776. * if it doesn't exist
  7777. */
  7778. public function create_path($path) {
  7779. $path_bits = split('/', dirname($path));
  7780. // IS_WINDOWS_OS has been defined in main_api.lib.php
  7781. $path_built = IS_WINDOWS_OS ? '' : '/';
  7782. foreach ($path_bits as $bit) {
  7783. if (!empty ($bit)) {
  7784. $new_path = $path_built . $bit;
  7785. if (is_dir($new_path)) {
  7786. $path_built = $new_path . '/';
  7787. } else {
  7788. mkdir($new_path, api_get_permissions_for_new_directories());
  7789. $path_built = $new_path . '/';
  7790. }
  7791. }
  7792. }
  7793. }
  7794. /**
  7795. * Delete the image relative to this learning path. No parameter. Only works on instanciated object.
  7796. * @return boolean The results of the unlink function, or false if there was no image to start with
  7797. */
  7798. public function delete_lp_image() {
  7799. $img = $this->get_preview_image();
  7800. if ($img != '') {
  7801. $del_file = api_get_path(SYS_COURSE_PATH) . api_get_course_path() . '/upload/learning_path/images/' . $img;
  7802. $this->set_preview_image('');
  7803. return @ unlink($del_file);
  7804. } else {
  7805. return false;
  7806. }
  7807. }
  7808. /**
  7809. * Uploads an author image to the upload/learning_path/images directory
  7810. * @param array The image array, coming from the $_FILES superglobal
  7811. * @return boolean True on success, false on error
  7812. */
  7813. public function upload_image($image_array) {
  7814. $image_moved = false;
  7815. if (!empty ($image_array['name'])) {
  7816. $upload_ok = process_uploaded_file($image_array);
  7817. $has_attachment = true;
  7818. } else {
  7819. $image_moved = true;
  7820. }
  7821. if ($upload_ok) {
  7822. if ($has_attachment) {
  7823. $courseDir = api_get_course_path() . '/upload/learning_path/images';
  7824. $sys_course_path = api_get_path(SYS_COURSE_PATH);
  7825. $updir = $sys_course_path . $courseDir;
  7826. // Try to add an extension to the file if it hasn't one.
  7827. $new_file_name = add_ext_on_mime(stripslashes($image_array['name']), $image_array['type']);
  7828. if (!filter_extension($new_file_name)) {
  7829. //Display :: display_error_message(get_lang('UplUnableToSaveFileFilteredExtension'));
  7830. $image_moved = false;
  7831. } else {
  7832. $file_extension = explode('.', $image_array['name']);
  7833. $file_extension = strtolower($file_extension[sizeof($file_extension) - 1]);
  7834. $new_file_name = uniqid('') . '.' . $file_extension;
  7835. $new_path = $updir . '/' . $new_file_name;
  7836. // Resize the image.
  7837. $temp = new Image($image_array['tmp_name']);
  7838. $picture_infos = $temp->get_image_info();
  7839. if ($picture_infos['width'] > 104) {
  7840. $thumbwidth = 104;
  7841. } else {
  7842. $thumbwidth = $picture_infos['width'];
  7843. }
  7844. if ($picture_infos['height'] > 96) {
  7845. $new_height = 96;
  7846. } else {
  7847. $new_height = $picture_infos['height'];
  7848. }
  7849. $temp->resize($thumbwidth, $new_height, 0);
  7850. $result = $temp->send_image($new_path);
  7851. // Storing the image filename.
  7852. if ($result) {
  7853. $image_moved = true;
  7854. $this->set_preview_image($new_file_name);
  7855. return true;
  7856. }
  7857. }
  7858. }
  7859. }
  7860. return false;
  7861. }
  7862. public function set_autolunch($lp_id, $status) {
  7863. $lp_id = intval($lp_id);
  7864. $status = intval($status);
  7865. $lp_table = Database::get_course_table(TABLE_LP_MAIN);
  7866. //Setting everything to autolunch = 0
  7867. $attributes['autolunch'] = 0;
  7868. $where = array('session_id = ? '=> api_get_session_id());
  7869. Database::update($lp_table, $attributes,$where);
  7870. if ($status == 1) {
  7871. //Setting my lp_id to autolunch = 1
  7872. $attributes['autolunch'] = 1;
  7873. $where = array('id = ? AND session_id = ? '=> array($lp_id, api_get_session_id()));
  7874. Database::update($lp_table, $attributes, $where );
  7875. }
  7876. }
  7877. }
  7878. if (!function_exists('trim_value')) {
  7879. function trim_value(& $value) {
  7880. $value = trim($value);
  7881. }
  7882. }