learnpath.class.php 414 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706
  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. error_log('my_item_id->'.$my_item_id);
  234. $this->items[$my_item_id] = $oItem;
  235. $this->refs_list[$oItem->ref] = $my_item_id;
  236. if ($this->debug > 2) {
  237. error_log('New LP - object with id ' . $my_item_id . ' set in items[]', 0);
  238. }
  239. }
  240. break;
  241. case 1:
  242. default:
  243. require_once 'learnpathItem.class.php';
  244. $oItem = new learnpathItem($row['id'], $user_id, $course_db);
  245. if (is_object($oItem)) {
  246. $my_item_id = $oItem->get_id();
  247. //$oItem->set_lp_view($this->lp_view_id); // Moved down to when we are sure the item_view exists.
  248. $oItem->set_prevent_reinit($this->prevent_reinit);
  249. // Don't use reference here as the next loop will make the pointed object change.
  250. $this->items[$my_item_id] = $oItem;
  251. $this->refs_list[$my_item_id] = $my_item_id;
  252. if ($this->debug > 2) {
  253. error_log('New LP - learnpath::__construct() ' . __LINE__ . ' - object with id ' . $my_item_id . ' set in items[]', 0);
  254. }
  255. }
  256. break;
  257. }
  258. // Items is a list of pointers to all items, classified by DB ID, not SCO id.
  259. if ($row['parent_item_id'] == 0 || empty ($this->items[$row['parent_item_id']])) {
  260. if (is_object($this->items[$row['id']])) {
  261. $this->items[$row['id']]->set_level(0);
  262. }
  263. } else {
  264. $level = $this->items[$row['parent_item_id']]->get_level() + 1;
  265. $this->items[$row['id']]->set_level($level);
  266. if (is_object($this->items[$row['parent_item_id']])) {
  267. // Items is a list of pointers from item DB ids to item objects.
  268. $this->items[$row['parent_item_id']]->add_child($row['id']);
  269. } else {
  270. if ($this->debug > 2) {
  271. error_log('New LP - learnpath::__construct() ' . __LINE__ . ' - The parent item (' . $row['parent_item_id'] . ') of item ' . $row['id'] . ' could not be found', 0);
  272. }
  273. }
  274. }
  275. // Get last viewing vars.
  276. $lp_item_view_table = Database :: get_course_table(TABLE_LP_ITEM_VIEW, $course_db);
  277. // This query should only return one or zero result.
  278. $sql = "SELECT * " .
  279. "FROM $lp_item_view_table " .
  280. "WHERE lp_view_id = " . $this->lp_view_id . " " .
  281. "AND lp_item_id = " . $row['id'] . " ORDER BY view_count DESC ";
  282. if ($this->debug > 2) {
  283. error_log('New LP - learnpath::__construct() - Selecting item_views: ' . $sql, 0);
  284. }
  285. // Get the item status.
  286. $res2 = Database::query($sql);
  287. if (Database :: num_rows($res2) > 0) {
  288. // If this learnpath has already been used by this user, get his last attempt count and
  289. // the last item seen back into this object.
  290. //$max = 0;
  291. $row2 = Database :: fetch_array($res2);
  292. if ($this->debug > 2) {
  293. error_log('New LP - learnpath::__construct() - Got item_view: ' . print_r($row2, true), 0);
  294. }
  295. if (is_object($this->items[$row['id']])) {
  296. $this->items[$row['id']]->set_status($row2['status']);
  297. if (empty ($row2['status'])) {
  298. $this->items[$row['id']]->set_status($this->default_status);
  299. }
  300. }
  301. //$this->attempt = $row['view_count'];
  302. //$this->last_item = $row['id'];
  303. } else { // No item has been found in lp_item_view for this view.
  304. // The first attempt of this user. Set attempt to 1 and last_item to 0 (first item available).
  305. // TODO: If the learnpath has not got attempts activated, always use attempt '1'.
  306. //$this->attempt = 1;
  307. //$this->last_item = 0;
  308. if (is_object($this->items[$row['id']])) {
  309. $this->items[$row['id']]->set_status($this->default_status);
  310. }
  311. // Add that row to the lp_item_view table so that we have something to show in the stats page.
  312. $sql_ins = "INSERT INTO $lp_item_view_table " .
  313. "(lp_item_id, lp_view_id, view_count, status) VALUES " .
  314. "(" . $row['id'] . "," . $this->lp_view_id . ",1,'not attempted')";
  315. if ($this->debug > 2) {
  316. error_log('New LP - learnpath::__construct() ' . __LINE__ . ' - Inserting blank item_view : ' . $sql_ins, 0);
  317. }
  318. $res_ins = Database::query($sql_ins);
  319. }
  320. // Setting the view in the item object.
  321. if (is_object($this->items[$row['id']])) {
  322. $this->items[$row['id']]->set_lp_view($this->lp_view_id, $course_db);
  323. }
  324. }
  325. $this->ordered_items = $this->get_flat_ordered_items_list($this->get_id(), 0, $course_db);
  326. $this->max_ordered_items = 0;
  327. foreach ($this->ordered_items as $index => $dummy) {
  328. if ($index > $this->max_ordered_items && !empty($dummy)) {
  329. $this->max_ordered_items = $index;
  330. }
  331. }
  332. // TODO: Define the current item better.
  333. $this->first();
  334. if ($this->debug > 2) {
  335. error_log('New LP - learnpath::__construct() ' . __LINE__ . ' - End of learnpath constructor for learnpath ' . $this->get_id(), 0);
  336. }
  337. }
  338. /**
  339. * 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
  340. * I found it better to rewrite it. Old function is still available. Added also the possibility to add a description.
  341. *
  342. * @param int $parent
  343. * @param int $previous
  344. * @param string $type
  345. * @param int resource ID (ref)
  346. * @param string $title
  347. * @param string $description
  348. * @return int
  349. */
  350. public function add_item($parent, $previous, $type = 'dokeos_chapter', $id, $title, $description, $prerequisites = 0, $max_time_allowed = 0) {
  351. if ($this->debug > 0) {
  352. error_log('New LP - In learnpath::add_item(' . $parent . ',' . $previous . ',' . $type . ',' . $id . ',' . $title . ')', 0);
  353. }
  354. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  355. $parent = intval($parent);
  356. $previous = intval($previous);
  357. $type = $this->escape_string($type);
  358. $id = intval($id);
  359. $max_time_allowed = $this->escape_string(htmlentities($max_time_allowed));
  360. if (empty ($max_time_allowed)) {
  361. $max_time_allowed = 0;
  362. }
  363. $title = $this->escape_string($title);
  364. $description = $this->escape_string($description);
  365. $sql_count = " SELECT COUNT(id) AS num
  366. FROM " . $tbl_lp_item . "
  367. WHERE lp_id = " . $this->get_id() . " AND parent_item_id = " . $parent;
  368. $res_count = Database::query($sql_count);
  369. $row = Database :: fetch_array($res_count);
  370. $num = $row['num'];
  371. if ($num > 0) {
  372. if ($previous == 0) {
  373. $sql = "SELECT id, next_item_id, display_order
  374. FROM " . $tbl_lp_item . "
  375. WHERE
  376. lp_id = " . $this->get_id() . " AND
  377. parent_item_id = " . $parent . " AND
  378. previous_item_id = 0 OR previous_item_id=" . $parent;
  379. $result = Database::query($sql);
  380. $row = Database :: fetch_array($result);
  381. $tmp_previous = 0;
  382. $next = $row['id'];
  383. $display_order = 0;
  384. } else {
  385. $previous = (int) $previous;
  386. $sql = "
  387. SELECT
  388. id,
  389. previous_item_id,
  390. next_item_id,
  391. display_order
  392. FROM " . $tbl_lp_item . "
  393. WHERE
  394. lp_id = " . $this->get_id() . " AND
  395. id = " . $previous;
  396. $result = Database::query($sql);
  397. $row = Database :: fetch_array($result);
  398. $tmp_previous = $row['id'];
  399. $next = $row['next_item_id'];
  400. $display_order = $row['display_order'];
  401. }
  402. } else {
  403. $tmp_previous = 0;
  404. $next = 0;
  405. $display_order = 0;
  406. }
  407. $new_item_id = -1;
  408. $id = $this->escape_string($id);
  409. if ($type == 'quiz') {
  410. $sql = 'SELECT SUM(ponderation)
  411. FROM ' . Database :: get_course_table(TABLE_QUIZ_QUESTION) . ' as quiz_question
  412. INNER JOIN ' . Database :: get_course_table(TABLE_QUIZ_TEST_QUESTION) . ' as quiz_rel_question
  413. ON quiz_question.id = quiz_rel_question.question_id
  414. AND quiz_rel_question.exercice_id = ' . $id;
  415. $rsQuiz = Database::query($sql);
  416. $max_score = Database :: result($rsQuiz, 0, 0);
  417. } else {
  418. $max_score = 100;
  419. }
  420. if ($prerequisites != 0) {
  421. $sql_ins = "
  422. INSERT INTO " . $tbl_lp_item . " ( ".
  423. "lp_id, ".
  424. "item_type, ".
  425. "ref, ".
  426. "title, ".
  427. "description, ".
  428. "path, ".
  429. "max_score, ".
  430. "parent_item_id, ".
  431. "previous_item_id, ".
  432. "next_item_id, ".
  433. "display_order, ".
  434. "prerequisite, ".
  435. "max_time_allowed ".
  436. ") VALUES ( ".
  437. $this->get_id() . ", ".
  438. "'" . $type . "', ".
  439. "'', ".
  440. "'" . $title . "', ".
  441. "'" . $description . "', ".
  442. "'" . $id . "', ".
  443. "'" . $max_score . "', ".
  444. $parent . ", ".
  445. $previous . ", ".
  446. $next . ", ".
  447. ($display_order +1) . ", ".
  448. $prerequisites . ", ".
  449. $max_time_allowed .
  450. ")";
  451. } else {
  452. // Insert new item.
  453. $sql_ins = "
  454. INSERT INTO " . $tbl_lp_item . " ( ".
  455. "lp_id, ".
  456. "item_type, ".
  457. "ref, ".
  458. "title, ".
  459. "description, ".
  460. "path, ".
  461. "max_score, ".
  462. "parent_item_id, ".
  463. "previous_item_id, ".
  464. "next_item_id, ".
  465. "display_order, ".
  466. "max_time_allowed ".
  467. ") VALUES (".
  468. $this->get_id() . ",".
  469. "'" . $type . "',".
  470. "'',".
  471. "'" . $title . "',".
  472. "'" . $description . "',".
  473. "'" . $id . "',".
  474. "'" . $max_score . "',".
  475. $parent . ",".
  476. $previous . ",".
  477. $next . ",".
  478. ($display_order +1) . ",".
  479. $max_time_allowed .
  480. ")";
  481. }
  482. if ($this->debug > 2) {
  483. error_log('New LP - Inserting dokeos_chapter: ' . $sql_ins, 0);
  484. }
  485. $res_ins = Database::query($sql_ins);
  486. if ($res_ins > 0) {
  487. $new_item_id = Database :: insert_id($res_ins);
  488. // Update the item that should come after the new item.
  489. $sql_update_next = "
  490. UPDATE " . $tbl_lp_item . "
  491. SET previous_item_id = " . $new_item_id . "
  492. WHERE id = " . $next;
  493. $res_update_next = Database::query($sql_update_next);
  494. // Update the item that should be before the new item.
  495. $sql_update_previous = "
  496. UPDATE " . $tbl_lp_item . "
  497. SET next_item_id = " . $new_item_id . "
  498. WHERE id = " . $tmp_previous;
  499. $res_update_previous = Database::query($sql_update_previous);
  500. // Update all the items after the new item.
  501. $sql_update_order = "
  502. UPDATE " . $tbl_lp_item . "
  503. SET display_order = display_order + 1
  504. WHERE
  505. lp_id = " . $this->get_id() . " AND
  506. id <> " . $new_item_id . " AND
  507. parent_item_id = " . $parent . " AND
  508. display_order > " . $display_order;
  509. $res_update_previous = Database::query($sql_update_order);
  510. // Update the item that should come after the new item.
  511. $sql_update_ref = "
  512. UPDATE " . $tbl_lp_item . "
  513. SET ref = " . $new_item_id . "
  514. WHERE id = " . $new_item_id;
  515. Database::query($sql_update_ref);
  516. }
  517. // Upload audio.
  518. if (!empty ($_FILES['mp3']['name'])) {
  519. // Create the audio folder if it does not exist yet.
  520. global $_course;
  521. $filepath = api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document/';
  522. if (!is_dir($filepath . 'audio')) {
  523. mkdir($filepath . 'audio', api_get_permissions_for_new_directories());
  524. $audio_id = add_document($_course, '/audio', 'folder', 0, 'audio');
  525. api_item_property_update($_course, TOOL_DOCUMENT, $audio_id, 'FolderCreated', api_get_user_id(), null, null, null, null, api_get_session_id());
  526. }
  527. // Upload the file in the documents tool.
  528. include_once api_get_path(LIBRARY_PATH).'fileUpload.lib.php';
  529. $file_path = handle_uploaded_document($_course, $_FILES['mp3'], api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document', '/audio', api_get_user_id(), '', '', '', '', '', false);
  530. // Getting the filename only.
  531. $file_components = explode('/', $file_path);
  532. $file = $file_components[count($file_components) - 1];
  533. // Store the mp3 file in the lp_item table.
  534. $sql_insert_audio = "UPDATE $tbl_lp_item SET audio = '" . Database :: escape_string($file) . "' WHERE id = '" . Database :: escape_string($new_item_id) . "'";
  535. Database::query($sql_insert_audio);
  536. }
  537. return $new_item_id;
  538. }
  539. /**
  540. * Static admin function allowing addition of a learnpath to a course.
  541. * @param string Course code
  542. * @param string Learnpath name
  543. * @param string Learnpath description string, if provided
  544. * @param string Type of learnpath (default = 'guess', others = 'dokeos', 'aicc',...)
  545. * @param string Type of files origin (default = 'zip', others = 'dir','web_dir',...)
  546. * @param string Zip file containing the learnpath or directory containing the learnpath
  547. * @return integer The new learnpath ID on success, 0 on failure
  548. */
  549. public function add_lp($course, $name, $description = '', $learnpath = 'guess', $origin = 'zip', $zipname = '', $publicated_on = '', $expired_on = '') {
  550. global $charset;
  551. //if ($this->debug > 0) { error_log('New LP - In learnpath::add_lp()', 0); }
  552. $tbl_lp = Database :: get_course_table(TABLE_LP_MAIN);
  553. // Check course code exists.
  554. // Check lp_name doesn't exist, otherwise append something.
  555. $i = 0;
  556. $name = learnpath :: escape_string($name);
  557. // Session id.
  558. $session_id = api_get_session_id();
  559. $check_name = "SELECT * FROM $tbl_lp WHERE name = '$name'";
  560. //if ($this->debug > 2) { error_log('New LP - Checking the name for new LP: '.$check_name, 0); }
  561. $res_name = Database::query($check_name);
  562. if ($publicated_on == '0000-00-00 00:00:00' || empty($publicated_on)) {
  563. //by default the publication date is the same that the creation date
  564. $publicated_on = api_get_utc_datetime();
  565. } else {
  566. $publicated_on = Database::escape_string(api_get_utc_datetime($publicated_on));
  567. }
  568. if ($expired_on == '0000-00-00 00:00:00' || empty($expired_on)) {
  569. $expired_on = '';
  570. } else {
  571. $expired_on = Database::escape_string(api_get_utc_datetime($expired_on));
  572. }
  573. while (Database :: num_rows($res_name)) {
  574. // There is already one such name, update the current one a bit.
  575. $i++;
  576. $name = $name . ' - ' . $i;
  577. $check_name = "SELECT * FROM $tbl_lp WHERE name = '$name'";
  578. //if ($this->debug > 2) { error_log('New LP - Checking the name for new LP: '.$check_name, 0); }
  579. $res_name = Database::query($check_name);
  580. }
  581. // New name does not exist yet; keep it.
  582. // Escape description.
  583. $description = learnpath :: escape_string(api_htmlentities($description, ENT_QUOTES, $charset)); // Kevin: added htmlentities().
  584. $type = 1;
  585. switch ($learnpath) {
  586. case 'guess':
  587. break;
  588. case 'dokeos':
  589. case 'chamilo':
  590. $type = 1;
  591. break;
  592. case 'aicc':
  593. break;
  594. }
  595. switch ($origin) {
  596. case 'zip':
  597. // Check zipname string. If empty, we are currently creating a new Chamilo learnpath.
  598. break;
  599. case 'manual':
  600. default:
  601. $get_max = "SELECT MAX(display_order) FROM $tbl_lp";
  602. $res_max = Database::query($get_max);
  603. if (Database :: num_rows($res_max) < 1) {
  604. $dsp = 1;
  605. } else {
  606. $row = Database :: fetch_array($res_max);
  607. $dsp = $row[0] + 1;
  608. }
  609. $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) " .
  610. "VALUES ($type,'$name','$description','','embedded','UTF-8','$dsp','Chamilo','local','','".$session_id."', '".api_get_utc_datetime()."' , '".$publicated_on."' , '".$expired_on."')";
  611. //if ($this->debug > 2) { error_log('New LP - Inserting new lp '.$sql_insert, 0); }
  612. $res_insert = Database::query($sql_insert);
  613. $id = Database :: insert_id();
  614. if ($id > 0) {
  615. // Insert into item_property.
  616. api_item_property_update(api_get_course_info(), TOOL_LEARNPATH, $id, 'LearnpathAdded', api_get_user_id());
  617. return $id;
  618. }
  619. break;
  620. }
  621. }
  622. /**
  623. * Appends a message to the message attribute
  624. * @param string Message to append.
  625. */
  626. public function append_message($string) {
  627. if ($this->debug > 0) {
  628. error_log('New LP - In learnpath::append_message()', 0);
  629. }
  630. $this->message .= $string;
  631. }
  632. /**
  633. * Autocompletes the parents of an item in case it's been completed or passed
  634. * @param integer Optional ID of the item from which to look for parents
  635. */
  636. public function autocomplete_parents($item) {
  637. if ($this->debug > 0) {
  638. error_log('New LP - In learnpath::autocomplete_parents()', 0);
  639. }
  640. if (empty ($item)) {
  641. $item = $this->current;
  642. }
  643. $parent_id = $this->items[$item]->get_parent();
  644. if ($this->debug > 2) {
  645. error_log('New LP - autocompleting parent of item ' . $item . ' (item ' . $parent_id . ')', 0);
  646. }
  647. if (is_object($this->items[$item]) and !empty ($parent_id)) {
  648. // if $item points to an object and there is a parent.
  649. if ($this->debug > 2) {
  650. error_log('New LP - ' . $item . ' is an item, proceed', 0);
  651. }
  652. $current_item = & $this->items[$item];
  653. $parent = & $this->items[$parent_id]; // Get the parent.
  654. // New experiment including failed and browsed in completed status.
  655. $current_status = $current_item->get_status();
  656. if ($current_item->is_done() || $current_status == 'browsed' || $current_status == 'failed') {
  657. // If the current item is completed or passes or succeeded.
  658. $completed = true;
  659. if ($this->debug > 2) {
  660. error_log('New LP - Status of current item is alright', 0);
  661. }
  662. foreach ($parent->get_children() as $child) {
  663. // Check all his brothers (his parent's children) for completion status.
  664. if ($child != $item) {
  665. if ($this->debug > 2) {
  666. error_log('New LP - Looking at brother with ID ' . $child . ', status is ' . $this->items[$child]->get_status(), 0);
  667. }
  668. //if($this->items[$child]->status_is(array('completed','passed','succeeded')))
  669. // Trying completing parents of failed and browsed items as well.
  670. if ($this->items[$child]->status_is(array (
  671. 'completed',
  672. 'passed',
  673. 'succeeded',
  674. 'browsed',
  675. 'failed'
  676. ))) {
  677. // Keep completion status to true.
  678. } else {
  679. if ($this->debug > 2) {
  680. error_log('New LP - Found one incomplete child of ' . $parent_id . ': ' . $child . ' is ' . $this->items[$child]->get_status(), 0);
  681. }
  682. $completed = false;
  683. }
  684. }
  685. }
  686. if ($completed) { // If all the children were completed:
  687. $parent->set_status('completed');
  688. $parent->save(false, $this->prerequisites_match($parent->get_id()));
  689. $this->update_queue[$parent->get_id()] = $parent->get_status();
  690. if ($this->debug > 2) {
  691. error_log('New LP - Added parent to update queue ' . print_r($this->update_queue, true), 0);
  692. }
  693. $this->autocomplete_parents($parent->get_id()); // Recursive call.
  694. }
  695. } else {
  696. //error_log('New LP - status of current item is not enough to get bothered with it', 0);
  697. }
  698. }
  699. }
  700. /**
  701. * Autosaves the current results into the database for the whole learnpath
  702. */
  703. public function autosave() {
  704. if ($this->debug > 0) {
  705. error_log('New LP - In learnpath::autosave()', 0);
  706. }
  707. // TODO: Add save operations for the learnpath itself.
  708. }
  709. /**
  710. * Clears the message attribute
  711. */
  712. public function clear_message() {
  713. if ($this->debug > 0) {
  714. error_log('New LP - In learnpath::clear_message()', 0);
  715. }
  716. $this->message = '';
  717. }
  718. /**
  719. * Closes the current resource
  720. *
  721. * Stops the timer
  722. * Saves into the database if required
  723. * Clears the current resource data from this object
  724. * @return boolean True on success, false on failure
  725. */
  726. public function close() {
  727. if ($this->debug > 0) {
  728. error_log('New LP - In learnpath::close()', 0);
  729. }
  730. if (empty ($this->lp_id)) {
  731. $this->error = 'Trying to close this learnpath but no ID is set';
  732. return false;
  733. }
  734. $this->current_time_stop = time();
  735. if ($this->save) {
  736. $learnpath_view_table = Database :: get_course_table(TABLE_LP_VIEW);
  737. /*
  738. $sql = "UPDATE $learnpath_view_table " .
  739. "SET " .
  740. "stop_time = ".$this->current_time_stop.", " .
  741. "score = ".$this->current_score.", ".
  742. "WHERE learnpath_id = '".$this->lp_id."'";
  743. //$res = Database::query($sql);
  744. $res = Database::query($res);
  745. if (Database::affected_rows($res) < 1) {
  746. $this->error = 'Could not update learnpath_view table while closing learnpath';
  747. return false;
  748. }
  749. */
  750. }
  751. $this->ordered_items = array ();
  752. $this->index = 0;
  753. unset ($this->lp_id);
  754. //unset other stuff
  755. return true;
  756. }
  757. /**
  758. * Static admin function allowing removal of a learnpath
  759. * @param string Course code
  760. * @param integer Learnpath ID
  761. * @param string Whether to delete data or keep it (default: 'keep', others: 'remove')
  762. * @return boolean True on success, false on failure (might change that to return number of elements deleted)
  763. */
  764. public function delete($course = null, $id = null, $delete = 'keep') {
  765. // TODO: Implement a way of getting this to work when the current object is not set.
  766. // In clear: implement this in the item class as well (abstract class) and use the given ID in queries.
  767. //if (empty($course)) { $course = api_get_course_id(); }
  768. //if (empty($id)) { $id = $this->get_id(); }
  769. // If an ID is specifically given and the current LP is not the same, prevent delete.
  770. if (!empty ($id) && ($id != $this->lp_id)) {
  771. return false;
  772. }
  773. $lp = Database :: get_course_table(TABLE_LP_MAIN);
  774. $lp_item = Database :: get_course_table(TABLE_LP_ITEM); // Proposed by Christophe (clefevre), see below.
  775. $lp_view = Database :: get_course_table(TABLE_LP_VIEW);
  776. $lp_item_view = Database :: get_course_table(TABLE_LP_ITEM_VIEW);
  777. //if ($this->debug > 0) { error_log('New LP - In learnpath::delete()', 0); }
  778. // Delete lp item id.
  779. foreach ($this->items as $id => $dummy) {
  780. //$this->items[$id]->delete();
  781. $sql_del_view = "DELETE FROM $lp_item_view WHERE lp_item_id = '" . $id . "'";
  782. $res_del_item_view = Database::query($sql_del_view);
  783. }
  784. // Proposed by Christophe (nickname: clefevre), see http://www.dokeos.com/forum/viewtopic.php?t=29673
  785. $sql_del_item = "DELETE FROM $lp_item WHERE lp_id = " . $this->lp_id;
  786. $res_del_item = Database::query($sql_del_item);
  787. $sql_del_view = "DELETE FROM $lp_view WHERE lp_id = " . $this->lp_id;
  788. //if ($this->debug > 2) { error_log('New LP - Deleting views bound to lp '.$this->lp_id.': '.$sql_del_view, 0); }
  789. $res_del_view = Database::query($sql_del_view);
  790. $this->toggle_publish($this->lp_id, 'i');
  791. //if ($this->debug > 2) { error_log('New LP - Deleting lp '.$this->lp_id.' of type '.$this->type, 0); }
  792. if ($this->type == 2 || $this->type == 3) {
  793. // This is a scorm learning path, delete the files as well.
  794. $sql = "SELECT path FROM $lp WHERE id = " . $this->lp_id;
  795. $res = Database::query($sql);
  796. if (Database :: num_rows($res) > 0) {
  797. $row = Database :: fetch_array($res);
  798. $path = $row['path'];
  799. $sql = "SELECT id FROM $lp WHERE path = '$path' AND id != " . $this->lp_id;
  800. $res = Database::query($sql);
  801. if (Database :: num_rows($res) > 0) { // Another learning path uses this directory, so don't delete it.
  802. if ($this->debug > 2) {
  803. error_log('New LP - In learnpath::delete(), found other LP using path ' . $path . ', keeping directory', 0);
  804. }
  805. } else {
  806. // No other LP uses that directory, delete it.
  807. $course_rel_dir = api_get_course_path() . '/scorm/'; // scorm dir web path starting from /courses
  808. $course_scorm_dir = api_get_path(SYS_COURSE_PATH) . $course_rel_dir; // The absolute system path for this course.
  809. if ($delete == 'remove' && is_dir($course_scorm_dir . $path) and !empty ($course_scorm_dir)) {
  810. if ($this->debug > 2) {
  811. error_log('New LP - In learnpath::delete(), found SCORM, deleting directory: ' . $course_scorm_dir . $path, 0);
  812. }
  813. // Proposed by Christophe (clefevre).
  814. if (strcmp(substr($path, -2), "/.") == 0) {
  815. $path = substr($path, 0, -1); // Remove "." at the end.
  816. }
  817. //exec('rm -rf ' . $course_scorm_dir . $path); // See Bug #5208, this is not OS-portable way.
  818. rmdirr($course_scorm_dir . $path);
  819. }
  820. }
  821. }
  822. }
  823. $sql_del_lp = "DELETE FROM $lp WHERE id = " . $this->lp_id;
  824. //if ($this->debug > 2) { error_log('New LP - Deleting lp '.$this->lp_id.': '.$sql_del_lp, 0); }
  825. $res_del_lp = Database::query($sql_del_lp);
  826. $this->update_display_order(); // Updates the display order of all lps.
  827. api_item_property_update(api_get_course_info(), TOOL_LEARNPATH, $this->lp_id, 'delete', api_get_user_id());
  828. require_once '../gradebook/lib/be.inc.php';
  829. // Delete link of gradebook tool
  830. //$tbl_grade_link = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_LINK);
  831. /*$sql = 'SELECT gl.id FROM ' . $tbl_grade_link . ' gl WHERE gl.type="4" AND gl.ref_id="' . $id . '";';
  832. $result = Database::query($sql);
  833. $row = Database :: fetch_array($result, 'ASSOC');*/
  834. // Fixing gradebook link deleted see #5229.
  835. /*
  836. if (!empty($row['id'])) {
  837. $link = LinkFactory :: load($row['id']);
  838. if ($link[0] != null) {
  839. $link[0]->delete();
  840. }
  841. }*/
  842. require_once api_get_path(SYS_CODE_PATH).'gradebook/lib/gradebook_functions.inc.php';
  843. $link_id = is_resource_in_course_gradebook(api_get_course_id(), 4 , $id, api_get_session_id());
  844. if ($link_id !== false) {
  845. remove_resource_from_course_gradebook($link_id);
  846. }
  847. if (api_get_setting('search_enabled') == 'true') {
  848. require_once api_get_path(LIBRARY_PATH).'specific_fields_manager.lib.php';
  849. $r = delete_all_values_for_item($this->cc, TOOL_LEARNPATH, $this->lp_id);
  850. }
  851. }
  852. /**
  853. * Removes all the children of one item - dangerous!
  854. * @param integer Element ID of which children have to be removed
  855. * @return integer Total number of children removed
  856. */
  857. public function delete_children_items($id) {
  858. if ($this->debug > 0) {
  859. error_log('New LP - In learnpath::delete_children_items(' . $id . ')', 0);
  860. }
  861. $num = 0;
  862. if (empty ($id) || $id != strval(intval($id))) {
  863. return false;
  864. }
  865. $lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  866. $sql = "SELECT * FROM $lp_item WHERE parent_item_id = $id";
  867. $res = Database::query($sql);
  868. while ($row = Database :: fetch_array($res)) {
  869. $num += $this->delete_children_items($row['id']);
  870. $sql_del = "DELETE FROM $lp_item WHERE id = " . $row['id'];
  871. $res_del = Database::query($sql_del);
  872. $num++;
  873. }
  874. return $num;
  875. }
  876. /**
  877. * Removes an item from the current learnpath
  878. * @param integer Elem ID (0 if first)
  879. * @param integer Whether to remove the resource/data from the system or leave it (default: 'keep', others 'remove')
  880. * @return integer Number of elements moved
  881. * @todo implement resource removal
  882. */
  883. public function delete_item($id, $remove = 'keep') {
  884. if ($this->debug > 0) {
  885. error_log('New LP - In learnpath::delete_item()', 0);
  886. }
  887. // TODO: Implement the resource removal.
  888. if (empty ($id) || $id != strval(intval($id))) {
  889. return false;
  890. }
  891. // First select item to get previous, next, and display order.
  892. $lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  893. $sql_sel = "SELECT * FROM $lp_item WHERE id = $id";
  894. $res_sel = Database::query($sql_sel);
  895. if (Database :: num_rows($res_sel) < 1) {
  896. return false;
  897. }
  898. $row = Database :: fetch_array($res_sel);
  899. $previous = $row['previous_item_id'];
  900. $next = $row['next_item_id'];
  901. $display = $row['display_order'];
  902. $parent = $row['parent_item_id'];
  903. $lp = $row['lp_id'];
  904. // Delete children items.
  905. $num = $this->delete_children_items($id);
  906. if ($this->debug > 2) {
  907. error_log('New LP - learnpath::delete_item() - deleted ' . $num . ' children of element ' . $id, 0);
  908. }
  909. // Now delete the item.
  910. $sql_del = "DELETE FROM $lp_item WHERE id = $id";
  911. if ($this->debug > 2) {
  912. error_log('New LP - Deleting item: ' . $sql_del, 0);
  913. }
  914. $res_del = Database::query($sql_del);
  915. // Now update surrounding items.
  916. $sql_upd = "UPDATE $lp_item SET next_item_id = $next WHERE id = $previous";
  917. $res_upd = Database::query($sql_upd);
  918. $sql_upd = "UPDATE $lp_item SET previous_item_id = $previous WHERE id = $next";
  919. $res_upd = Database::query($sql_upd);
  920. // Now update all following items with new display order.
  921. $sql_all = "UPDATE $lp_item SET display_order = display_order-1 WHERE lp_id = $lp AND parent_item_id = $parent AND display_order > $display";
  922. $res_all = Database::query($sql_all);
  923. //Removing prerequisites since the item will not longer exist
  924. $sql_all = "UPDATE $lp_item SET prerequisite = '' WHERE prerequisite = $id";
  925. $res_all = Database::query($sql_all);
  926. // Remove from search engine if enabled.
  927. if (api_get_setting('search_enabled') == 'true') {
  928. $tbl_se_ref = Database :: get_main_table(TABLE_MAIN_SEARCH_ENGINE_REF);
  929. $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';
  930. $sql = sprintf($sql, $tbl_se_ref, $this->cc, TOOL_LEARNPATH, $lp, $id);
  931. $res = Database::query($sql);
  932. if (Database :: num_rows($res) > 0) {
  933. $row2 = Database :: fetch_array($res);
  934. require_once api_get_path(LIBRARY_PATH).'search/DokeosIndexer.class.php';
  935. $di = new DokeosIndexer();
  936. $di->remove_document((int) $row2['search_did']);
  937. }
  938. $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';
  939. $sql = sprintf($sql, $tbl_se_ref, $this->cc, TOOL_LEARNPATH, $lp, $id);
  940. Database::query($sql);
  941. }
  942. }
  943. /**
  944. * Updates an item's content in place
  945. * @param integer Element ID
  946. * @param integer Parent item ID
  947. * @param integer Previous item ID
  948. * @param string Item title
  949. * @param string Item description
  950. * @param string Prerequisites (optional)
  951. * @param string Indexing terms (optional)
  952. * @param array The array resulting of the $_FILES[mp3] element
  953. * @return boolean True on success, false on error
  954. */
  955. public function edit_item($id, $parent, $previous, $title, $description, $prerequisites = 0, $audio = null, $max_time_allowed = 0) {
  956. if ($this->debug > 0) {
  957. error_log('New LP - In learnpath::edit_item()', 0);
  958. }
  959. if (empty ($max_time_allowed)) {
  960. $max_time_allowed = 0;
  961. }
  962. if (empty ($id) || ($id != strval(intval($id))) || empty ($title)) {
  963. return false;
  964. }
  965. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  966. $sql_select = "SELECT * FROM " . $tbl_lp_item . " WHERE id = " . $id;
  967. $res_select = Database::query($sql_select);
  968. $row_select = Database :: fetch_array($res_select);
  969. $audio_update_sql = '';
  970. if (is_array($audio) && !empty ($audio['tmp_name']) && $audio['error'] === 0) {
  971. // Create the audio folder if it does not exist yet.
  972. global $_course;
  973. $filepath = api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document/';
  974. if (!is_dir($filepath . 'audio')) {
  975. mkdir($filepath . 'audio', api_get_permissions_for_new_directories());
  976. $audio_id = add_document($_course, '/audio', 'folder', 0, 'audio');
  977. api_item_property_update($_course, TOOL_DOCUMENT, $audio_id, 'FolderCreated', api_get_user_id(), null, null, null, null, api_get_session_id());
  978. }
  979. // Upload file in documents.
  980. $pi = pathinfo($audio['name']);
  981. if ($pi['extension'] == 'mp3') {
  982. $c_det = api_get_course_info($this->cc);
  983. $bp = api_get_path(SYS_COURSE_PATH) . $c_det['path'] . '/document';
  984. $path = handle_uploaded_document($c_det, $audio, $bp, '/audio', api_get_user_id(), 0, null, '', 0, 'rename', false, 0);
  985. $path = substr($path, 7);
  986. // Update reference in lp_item - audio path is the path from inside de document/audio/ dir.
  987. $audio_update_sql = ", audio = '" . Database :: escape_string($path) . "' ";
  988. }
  989. }
  990. $same_parent = ($row_select['parent_item_id'] == $parent) ? true : false;
  991. $same_previous = ($row_select['previous_item_id'] == $previous) ? true : false;
  992. // TODO: htmlspecialchars to be checked for encoding related problems.
  993. if ($same_parent && $same_previous) {
  994. // Only update title and description.
  995. $sql_update = " UPDATE " . $tbl_lp_item . "
  996. SET title = '" . $this->escape_string($title) . "',
  997. prerequisite = '" . $prerequisites . "',
  998. description = '" . $this->escape_string($description) . "'
  999. " . $audio_update_sql . ",
  1000. max_time_allowed = '" . $this->escape_string($max_time_allowed) . "'
  1001. WHERE id = " . $id;
  1002. $res_update = Database::query($sql_update);
  1003. } else {
  1004. $old_parent = $row_select['parent_item_id'];
  1005. $old_previous = $row_select['previous_item_id'];
  1006. $old_next = $row_select['next_item_id'];
  1007. $old_order = $row_select['display_order'];
  1008. $old_prerequisite = $row_select['prerequisite'];
  1009. $old_max_time_allowed = $row_select['max_time_allowed'];
  1010. /* BEGIN -- virtually remove the current item id */
  1011. /* for the next and previous item it is like the current item doesn't exist anymore */
  1012. if ($old_previous != 0) {
  1013. $sql_update_next = "
  1014. UPDATE " . $tbl_lp_item . "
  1015. SET next_item_id = " . $old_next . "
  1016. WHERE id = " . $old_previous;
  1017. $res_update_next = Database::query($sql_update_next);
  1018. //echo '<p>' . $sql_update_next . '</p>';
  1019. }
  1020. if ($old_next != 0) {
  1021. $sql_update_previous = "
  1022. UPDATE " . $tbl_lp_item . "
  1023. SET previous_item_id = " . $old_previous . "
  1024. WHERE id = " . $old_next;
  1025. $res_update_previous = Database::query($sql_update_previous);
  1026. //echo '<p>' . $sql_update_previous . '</p>';
  1027. }
  1028. // display_order - 1 for every item with a display_order bigger then the display_order of the current item.
  1029. $sql_update_order = "
  1030. UPDATE " . $tbl_lp_item . "
  1031. SET display_order = display_order - 1
  1032. WHERE
  1033. display_order > " . $old_order . " AND lp_id = " . $this->lp_id . " AND
  1034. parent_item_id = " . $old_parent;
  1035. $res_update_order = Database::query($sql_update_order);
  1036. //echo '<p>' . $sql_update_order . '</p>';
  1037. /* END -- virtually remove the current item id */
  1038. /* BEGIN -- update the current item id to his new location */
  1039. if ($previous == 0) {
  1040. // Select the data of the item that should come after the current item.
  1041. $sql_select_old = "
  1042. SELECT
  1043. id,
  1044. display_order
  1045. FROM " . $tbl_lp_item . "
  1046. WHERE
  1047. lp_id = " . $this->lp_id . " AND
  1048. parent_item_id = " . $parent . " AND
  1049. previous_item_id = " . $previous;
  1050. $res_select_old = Database::query($sql_select_old);
  1051. $row_select_old = Database :: fetch_array($res_select_old);
  1052. //echo '<p>' . $sql_select_old . '</p>';
  1053. // If the new parent didn't have children before.
  1054. if (Database :: num_rows($res_select_old) == 0) {
  1055. $new_next = 0;
  1056. $new_order = 1;
  1057. } else {
  1058. $new_next = $row_select_old['id'];
  1059. $new_order = $row_select_old['display_order'];
  1060. }
  1061. //echo 'New next_item_id of current item: ' . $new_next . '<br />';
  1062. //echo 'New previous_item_id of current item: ' . $previous . '<br />';
  1063. //echo 'New display_order of current item: ' . $new_order . '<br />';
  1064. } else {
  1065. // Select the data of the item that should come before the current item.
  1066. $sql_select_old = "
  1067. SELECT
  1068. next_item_id,
  1069. display_order
  1070. FROM " . $tbl_lp_item . "
  1071. WHERE id = " . $previous;
  1072. $res_select_old = Database::query($sql_select_old);
  1073. $row_select_old = Database :: fetch_array($res_select_old);
  1074. //echo '<p>' . $sql_select_old . '</p>';
  1075. //echo 'New next_item_id of current item: ' . $row_select_old['next_item_id'] . '<br />';
  1076. //echo 'New previous_item_id of current item: ' . $previous . '<br />';
  1077. //echo 'New display_order of current item: ' . ($row_select_old['display_order'] + 1) . '<br />';
  1078. $new_next = $row_select_old['next_item_id'];
  1079. $new_order = $row_select_old['display_order'] + 1;
  1080. }
  1081. // TODO: htmlspecialchars to be checked for encoding related problems.
  1082. // Update the current item with the new data.
  1083. $sql_update = "
  1084. UPDATE " . $tbl_lp_item . "
  1085. SET
  1086. title = '" . $this->escape_string($title) . "',
  1087. description = '" . $this->escape_string($description) . "',
  1088. parent_item_id = " . $parent . ",
  1089. previous_item_id = " . $previous . ",
  1090. next_item_id = " . $new_next . ",
  1091. display_order = " . $new_order . "
  1092. " . $audio_update_sql . "
  1093. WHERE id = " . $id;
  1094. $res_update_next = Database::query($sql_update);
  1095. //echo '<p>' . $sql_update . '</p>';
  1096. if ($previous != 0) {
  1097. // Update the previous item's next_item_id.
  1098. $sql_update_previous = "
  1099. UPDATE " . $tbl_lp_item . "
  1100. SET next_item_id = " . $id . "
  1101. WHERE id = " . $previous;
  1102. $res_update_next = Database::query($sql_update_previous);
  1103. //echo '<p>' . $sql_update_previous . '</p>';
  1104. }
  1105. if ($new_next != 0) {
  1106. // Update the next item's previous_item_id.
  1107. $sql_update_next = "
  1108. UPDATE " . $tbl_lp_item . "
  1109. SET previous_item_id = " . $id . "
  1110. WHERE id = " . $new_next;
  1111. $res_update_next = Database::query($sql_update_next);
  1112. //echo '<p>' . $sql_update_next . '</p>';
  1113. }
  1114. if ($old_prerequisite != $prerequisites) {
  1115. $sql_update_next = "
  1116. UPDATE " . $tbl_lp_item . "
  1117. SET prerequisite = " . $prerequisites . "
  1118. WHERE id = " . $id;
  1119. $res_update_next = Database::query($sql_update_next);
  1120. }
  1121. if ($old_max_time_allowed != $max_time_allowed) {
  1122. $sql_update_max_time_allowed = "
  1123. UPDATE " . $tbl_lp_item . "
  1124. SET max_time_allowed = " . $max_time_allowed . "
  1125. WHERE id = " . $id;
  1126. $res_update_max_time_allowed = Database::query($sql_update_max_time_allowed);
  1127. }
  1128. // Update all the items with the same or a bigger display_order than the current item.
  1129. $sql_update_order = "
  1130. UPDATE " . $tbl_lp_item . "
  1131. SET display_order = display_order + 1
  1132. WHERE
  1133. lp_id = " . $this->get_id() . " AND
  1134. id <> " . $id . " AND
  1135. parent_item_id = " . $parent . " AND
  1136. display_order >= " . $new_order;
  1137. $res_update_next = Database::query($sql_update_order);
  1138. }
  1139. }
  1140. /**
  1141. * Updates an item's prereq in place
  1142. * @param integer Element ID
  1143. * @param string Prerequisite Element ID
  1144. * @param string Prerequisite item type
  1145. * @param string Prerequisite min score
  1146. * @param string Prerequisite max score
  1147. * @return boolean True on success, false on error
  1148. */
  1149. public function edit_item_prereq($id, $prerequisite_id, $mastery_score = 0, $max_score = 100) {
  1150. if ($this->debug > 0) {
  1151. error_log('New LP - In learnpath::edit_item_prereq(' . $id . ',' . $prerequisite_id . ',' . $mastery_score . ',' . $max_score . ')', 0);
  1152. }
  1153. if (empty ($id) or ($id != strval(intval($id))) or empty ($prerequisite_id)) {
  1154. return false;
  1155. }
  1156. $prerequisite_id = $this->escape_string($prerequisite_id);
  1157. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  1158. if (!is_numeric($mastery_score) || $mastery_score < 0)
  1159. $mastery_score = 0;
  1160. if (!is_numeric($max_score) || $max_score < 0)
  1161. $max_score = 100;
  1162. if ($mastery_score > $max_score)
  1163. $max_score = $mastery_score;
  1164. if (!is_numeric($prerequisite_id))
  1165. $prerequisite_id = 'NULL';
  1166. $sql_upd = " UPDATE " . $tbl_lp_item . "
  1167. SET prerequisite = " . $prerequisite_id . " WHERE id = " . $id;
  1168. $res_upd = Database::query($sql_upd);
  1169. if ($prerequisite_id != 'NULL' && $prerequisite_id != '') {
  1170. $sql_upd = " UPDATE " . $tbl_lp_item . " SET
  1171. mastery_score = " . $mastery_score .
  1172. //", max_score = " . $max_score . " " . // Max score cannot be changed in the form anyway - see display_item_prerequisites_form().
  1173. " WHERE ref = '" . $prerequisite_id . "'"; // Will this be enough to ensure unicity?
  1174. $res_upd = Database::query($sql_upd);
  1175. }
  1176. // TODO: Update the item object (can be ignored for now because refreshed).
  1177. return true;
  1178. }
  1179. /**
  1180. * Escapes a string with the available database escape function
  1181. * @param string String to escape
  1182. * @return string String escaped
  1183. */
  1184. public function escape_string($string) {
  1185. //if ($this->debug > 0) { error_log('New LP - In learnpath::escape_string('.$string.')', 0); }
  1186. return Database :: escape_string($string);
  1187. }
  1188. /**
  1189. * Static admin function exporting a learnpath into a zip file
  1190. * @param string Export type (scorm, zip, cd)
  1191. * @param string Course code
  1192. * @param integer Learnpath ID
  1193. * @param string Zip file name
  1194. * @return string Zip file path (or false on error)
  1195. */
  1196. public function export_lp($type, $course, $id, $zipname) {
  1197. //if ($this->debug > 0) { error_log('New LP - In learnpath::export_lp()', 0); }
  1198. if (empty($type) || empty($course) || empty($id) || empty($zipname)) {
  1199. return false;
  1200. }
  1201. $url = '';
  1202. switch ($type) {
  1203. case 'scorm':
  1204. break;
  1205. case 'zip':
  1206. break;
  1207. case 'cdrom':
  1208. break;
  1209. }
  1210. return $url;
  1211. }
  1212. /**
  1213. * Gets all the chapters belonging to the same parent as the item/chapter given
  1214. * Can also be called as abstract method
  1215. * @param integer Item ID
  1216. * @return array A list of all the "brother items" (or an empty array on failure)
  1217. */
  1218. public function get_brother_chapters($id) {
  1219. if ($this->debug > 0) {
  1220. error_log('New LP - In learnpath::get_brother_chapters()', 0);
  1221. }
  1222. if (empty ($id) OR $id != strval(intval($id))) {
  1223. return array ();
  1224. }
  1225. $lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  1226. $sql_parent = "SELECT * FROM $lp_item WHERE id = $id AND item_type='dokeos_chapter'";
  1227. $res_parent = Database::query($sql_parent);
  1228. if (Database :: num_rows($res_parent) > 0) {
  1229. $row_parent = Database :: fetch_array($res_parent);
  1230. $parent = $row_parent['parent_item_id'];
  1231. $sql_bros = "SELECT * FROM $lp_item WHERE parent_item_id = $parent AND id = $id AND item_type='dokeos_chapter' ORDER BY display_order";
  1232. $res_bros = Database::query($sql_bros);
  1233. $list = array ();
  1234. while ($row_bro = Database :: fetch_array($res_bros)) {
  1235. $list[] = $row_bro;
  1236. }
  1237. return $list;
  1238. }
  1239. return array ();
  1240. }
  1241. /**
  1242. * Gets all the items belonging to the same parent as the item given
  1243. * Can also be called as abstract method
  1244. * @param integer Item ID
  1245. * @return array A list of all the "brother items" (or an empty array on failure)
  1246. */
  1247. public function get_brother_items($id) {
  1248. if ($this->debug > 0) {
  1249. error_log('New LP - In learnpath::get_brother_items(' . $id . ')', 0);
  1250. }
  1251. if (empty ($id) OR $id != strval(intval($id))) {
  1252. return array ();
  1253. }
  1254. $lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  1255. $sql_parent = "SELECT * FROM $lp_item WHERE id = $id";
  1256. $res_parent = Database::query($sql_parent);
  1257. if (Database :: num_rows($res_parent) > 0) {
  1258. $row_parent = Database :: fetch_array($res_parent);
  1259. $parent = $row_parent['parent_item_id'];
  1260. $sql_bros = "SELECT * FROM $lp_item WHERE parent_item_id = $parent ORDER BY display_order";
  1261. $res_bros = Database::query($sql_bros);
  1262. $list = array ();
  1263. while ($row_bro = Database :: fetch_array($res_bros)) {
  1264. $list[] = $row_bro;
  1265. }
  1266. return $list;
  1267. }
  1268. return array ();
  1269. }
  1270. /**
  1271. * Get the specific prefix index terms of this learning path
  1272. * @return array Array of terms
  1273. */
  1274. public function get_common_index_terms_by_prefix($prefix) {
  1275. require_once api_get_path(LIBRARY_PATH).'specific_fields_manager.lib.php';
  1276. $terms = get_specific_field_values_list_by_prefix($prefix, $this->cc, TOOL_LEARNPATH, $this->lp_id);
  1277. $prefix_terms = array();
  1278. if (!empty($terms)) {
  1279. foreach ($terms as $term) {
  1280. $prefix_terms[] = $term['value'];
  1281. }
  1282. }
  1283. return $prefix_terms;
  1284. }
  1285. /**
  1286. * Gets the number of items currently completed
  1287. * @return integer The number of items currently completed
  1288. */
  1289. public function get_complete_items_count() {
  1290. if ($this->debug > 0) {
  1291. error_log('New LP - In learnpath::get_complete_items_count()', 0);
  1292. }
  1293. $i = 0;
  1294. foreach ($this->items as $id => $dummy) {
  1295. // Trying failed and browsed considered "progressed" as well.
  1296. if ($this->items[$id]->status_is(array (
  1297. 'completed',
  1298. 'passed',
  1299. 'succeeded',
  1300. 'browsed',
  1301. 'failed'
  1302. )) && $this->items[$id]->get_type() != 'dokeos_chapter' && $this->items[$id]->get_type() != 'dir') {
  1303. $i++;
  1304. }
  1305. }
  1306. return $i;
  1307. }
  1308. /**
  1309. * Gets the current item ID
  1310. * @return integer The current learnpath item id
  1311. */
  1312. public function get_current_item_id() {
  1313. $current = 0;
  1314. if ($this->debug > 0) {
  1315. error_log('New LP - In learnpath::get_current_item_id()', 0);
  1316. }
  1317. if (!empty ($this->current)) {
  1318. $current = $this->current;
  1319. }
  1320. if ($this->debug > 2) {
  1321. error_log('New LP - In learnpath::get_current_item_id() - Returning ' . $current, 0);
  1322. }
  1323. return $current;
  1324. }
  1325. /**
  1326. * Force to get the first learnpath item id
  1327. * @return integer The current learnpath item id
  1328. */
  1329. public function get_first_item_id() {
  1330. $current = 0;
  1331. if (is_array($this->ordered_items)) {
  1332. $current = $this->ordered_items[0];
  1333. }
  1334. return $current;
  1335. }
  1336. /**
  1337. * Gets the total number of items available for viewing in this SCORM
  1338. * @return integer The total number of items
  1339. */
  1340. public function get_total_items_count() {
  1341. if ($this->debug > 0) {
  1342. error_log('New LP - In learnpath::get_total_items_count()', 0);
  1343. }
  1344. return count($this->items);
  1345. }
  1346. /**
  1347. * Gets the total number of items available for viewing in this SCORM but without chapters
  1348. * @return integer The total no-chapters number of items
  1349. */
  1350. public function get_total_items_count_without_chapters() {
  1351. if ($this->debug > 0) {
  1352. error_log('New LP - In learnpath::get_total_items_count_without_chapters()', 0);
  1353. }
  1354. $total = 0;
  1355. foreach ($this->items as $temp => $temp2) {
  1356. if (!in_array($temp2->get_type(), array (
  1357. 'dokeos_chapter',
  1358. 'chapter',
  1359. 'dir'
  1360. )))
  1361. $total++;
  1362. }
  1363. return $total;
  1364. }
  1365. /**
  1366. * Gets the first element URL.
  1367. * @return string URL to load into the viewer
  1368. */
  1369. public function first() {
  1370. if ($this->debug > 0) {
  1371. error_log('New LP - In learnpath::first()', 0);
  1372. }
  1373. // Test if the last_item_seen exists and is not a dir.
  1374. if (count($this->ordered_items) == 0) {
  1375. $this->index = 0;
  1376. }
  1377. 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()) {
  1378. if ($this->debug > 2) {
  1379. 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);
  1380. }
  1381. $index = -1;
  1382. foreach ($this->ordered_items as $myindex => $item_id) {
  1383. if ($item_id == $this->last_item_seen) {
  1384. $index = $myindex;
  1385. break;
  1386. }
  1387. }
  1388. if ($index == -1) {
  1389. // Index hasn't changed, so item not found - panic (this shouldn't happen).
  1390. if ($this->debug > 2) {
  1391. error_log('New LP - Last item (' . $this->last_item_seen . ') was found in items but not in ordered_items, panic!', 0);
  1392. }
  1393. return false;
  1394. } else {
  1395. $this->last = $this->last_item_seen;
  1396. $this->current = $this->last_item_seen;
  1397. $this->index = $index;
  1398. }
  1399. } else {
  1400. if ($this->debug > 2) {
  1401. error_log('New LP - In learnpath::first() - No last item seen', 0);
  1402. }
  1403. $index = 0;
  1404. // Loop through all ordered items and stop at the first item that is
  1405. // not a directory *and* that has not been completed yet.
  1406. 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) {
  1407. $index++;
  1408. }
  1409. $this->last = $this->current;
  1410. // current is
  1411. $this->current = $this->ordered_items[$index];
  1412. $this->index = $index;
  1413. if ($this->debug > 2) {
  1414. error_log('New LP - In learnpath::first() - No last item seen. New last = ' . $this->last . '(' . $this->ordered_items[$index] . ')', 0);
  1415. }
  1416. }
  1417. if ($this->debug > 2) {
  1418. error_log('New LP - In learnpath::first() - First item is ' . $this->get_current_item_id());
  1419. }
  1420. }
  1421. /**
  1422. * Gets the information about an item in a format usable as JavaScript to update
  1423. * the JS API by just printing this content into the <head> section of the message frame
  1424. * @param integer Item ID
  1425. * @return string
  1426. */
  1427. public function get_js_info($item_id = '') {
  1428. if ($this->debug > 0) {
  1429. error_log('New LP - In learnpath::get_js_info(' . $item_id . ')', 0);
  1430. }
  1431. $info = '';
  1432. $item_id = $this->escape_string($item_id);
  1433. if (!empty($item_id) && is_object($this->items[$item_id])) {
  1434. //if item is defined, return values from DB
  1435. $oItem = $this->items[$item_id];
  1436. $info .= '<script language="javascript">';
  1437. $info .= "top.set_score(" . $oItem->get_score() . ");\n";
  1438. $info .= "top.set_max(" . $oItem->get_max() . ");\n";
  1439. $info .= "top.set_min(" . $oItem->get_min() . ");\n";
  1440. $info .= "top.set_lesson_status('" . $oItem->get_status() . "');";
  1441. $info .= "top.set_session_time('" . $oItem->get_scorm_time('js') . "');";
  1442. $info .= "top.set_suspend_data('" . $oItem->get_suspend_data() . "');";
  1443. $info .= "top.set_saved_lesson_status('" . $oItem->get_status() . "');";
  1444. $info .= "top.set_flag_synchronized();";
  1445. $info .= '</script>';
  1446. if ($this->debug > 2) {
  1447. error_log('New LP - in learnpath::get_js_info(' . $item_id . ') - returning: ' . $info, 0);
  1448. }
  1449. return $info;
  1450. } else {
  1451. // If item_id is empty, just update to default SCORM data.
  1452. $info .= '<script language="javascript">';
  1453. $info .= "top.set_score(" . learnpathItem :: get_score() . ");\n";
  1454. $info .= "top.set_max(" . learnpathItem :: get_max() . ");\n";
  1455. $info .= "top.set_min(" . learnpathItem :: get_min() . ");\n";
  1456. $info .= "top.set_lesson_status('" . learnpathItem :: get_status() . "');";
  1457. $info .= "top.set_session_time('" . learnpathItem :: get_scorm_time('js') . "');";
  1458. $info .= "top.set_suspend_data('" . learnpathItem :: get_suspend_data() . "');";
  1459. $info .= "top.set_saved_lesson_status('" . learnpathItem :: get_status() . "');";
  1460. $info .= "top.set_flag_synchronized();";
  1461. $info .= '</script>';
  1462. if ($this->debug > 2) {
  1463. error_log('New LP - in learnpath::get_js_info(' . $item_id . ') - returning: ' . $info, 0);
  1464. }
  1465. return $info;
  1466. }
  1467. }
  1468. /**
  1469. * Gets the js library from the database
  1470. * @return string The name of the javascript library to be used
  1471. */
  1472. public function get_js_lib() {
  1473. $lib = '';
  1474. if (!empty ($this->js_lib)) {
  1475. $lib = $this->js_lib;
  1476. }
  1477. return $lib;
  1478. }
  1479. /**
  1480. * Gets the learnpath database ID
  1481. * @return integer Learnpath ID in the lp table
  1482. */
  1483. public function get_id() {
  1484. //if ($this->debug > 0) { error_log('New LP - In learnpath::get_id()', 0); }
  1485. if (!empty ($this->lp_id)) {
  1486. return $this->lp_id;
  1487. } else {
  1488. return 0;
  1489. }
  1490. }
  1491. /**
  1492. * Gets the last element URL.
  1493. * @return string URL to load into the viewer
  1494. */
  1495. public function get_last() {
  1496. if ($this->debug > 0) {
  1497. error_log('New LP - In learnpath::get_last()', 0);
  1498. }
  1499. $this->index = count($this->ordered_items) - 1;
  1500. return $this->ordered_items[$this->index];
  1501. }
  1502. /**
  1503. * Gets the navigation bar for the learnpath display screen
  1504. * @return string The HTML string to use as a navigation bar
  1505. */
  1506. public function get_navigation_bar() {
  1507. if ($this->debug > 0) {
  1508. error_log('New LP - In learnpath::get_navigation_bar()', 0);
  1509. }
  1510. // TODO: Find a good value for the following variables.
  1511. $file = '';
  1512. $openDir = '';
  1513. $edoceo = '';
  1514. $time = 0;
  1515. $navbar = '';
  1516. $RequestUri = '';
  1517. $mycurrentitemid = $this->get_current_item_id();
  1518. if ($this->mode == 'fullscreen') {
  1519. $navbar = '<table cellpadding="0" cellspacing="0" align="left">' . "\n" .
  1520. ' <tr> ' . "\n" .
  1521. ' <td>' . "\n" .
  1522. ' <div class="buttons">' . "\n" .
  1523. ' <a href="lp_controller.php?action=stats" onClick="window.parent.API.save_asset();return true;" target="content_name_blank" title="stats" id="stats_link"><img border="0" src="../img/lp_stats.gif" title="' . get_lang('Reporting') . '"></a>' . "\n" .
  1524. ' <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" .
  1525. ' <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" .
  1526. //' <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" .
  1527. //' <a href="lp_controller.php?action=list" target="_top" title="learnpaths list"><img border="0" src="../img/exit.png" title="Exit"></a>'."\n" .
  1528. ' </div>' . "\n" .
  1529. ' </td>' . "\n" .
  1530. ' </tr>' . "\n" .
  1531. '</table>';
  1532. } else {
  1533. $navbar = '<table cellpadding="0" cellspacing="0" align="left">' . "\n" .
  1534. ' <tr> ' . "\n" .
  1535. ' <td>' . "\n" .
  1536. ' <div class="buttons">' . "\n" .
  1537. ' <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" .
  1538. ' <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" .
  1539. ' <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" .
  1540. // ' <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" .
  1541. ' </div>' . "\n" .
  1542. ' </td>' . "\n" .
  1543. ' </tr>' . "\n" .
  1544. '</table>';
  1545. }
  1546. return $navbar;
  1547. }
  1548. /**
  1549. * Gets the next resource in queue (url).
  1550. * @return string URL to load into the viewer
  1551. */
  1552. public function get_next_index() {
  1553. if ($this->debug > 0) {
  1554. error_log('New LP - In learnpath::get_next_index()', 0);
  1555. }
  1556. // TODO
  1557. $index = $this->index;
  1558. $index++;
  1559. if ($this->debug > 2) {
  1560. error_log('New LP - Now looking at ordered_items[' . ($index) . '] - type is ' . $this->items[$this->ordered_items[$index]]->type, 0);
  1561. }
  1562. 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) {
  1563. $index++;
  1564. if ($index == $this->max_ordered_items){
  1565. if ($this->items[$this->ordered_items[$index]]->get_type() == 'dir' || $this->items[$this->ordered_items[$index]]->get_type() == 'dokeos_chapter') {
  1566. return $this->index;
  1567. } else {
  1568. return $index;
  1569. }
  1570. }
  1571. }
  1572. if (empty ($this->ordered_items[$index])) {
  1573. return $this->index;
  1574. }
  1575. if ($this->debug > 2) {
  1576. error_log('New LP - index is now ' . $index, 0);
  1577. }
  1578. return $index;
  1579. }
  1580. /**
  1581. * Gets item_id for the next element
  1582. * @return integer Next item (DB) ID
  1583. */
  1584. public function get_next_item_id() {
  1585. if ($this->debug > 0) {
  1586. error_log('New LP - In learnpath::get_next_item_id()', 0);
  1587. }
  1588. $new_index = $this->get_next_index();
  1589. if (!empty ($new_index)) {
  1590. if (isset ($this->ordered_items[$new_index])) {
  1591. if ($this->debug > 2) {
  1592. error_log('New LP - In learnpath::get_next_index() - Returning ' . $this->ordered_items[$new_index], 0);
  1593. }
  1594. return $this->ordered_items[$new_index];
  1595. }
  1596. }
  1597. if ($this->debug > 2) {
  1598. error_log('New LP - In learnpath::get_next_index() - Problem - Returning 0', 0);
  1599. }
  1600. return 0;
  1601. }
  1602. /**
  1603. * Returns the package type ('scorm','aicc','scorm2004','dokeos','ppt'...)
  1604. *
  1605. * Generally, the package provided is in the form of a zip file, so the function
  1606. * has been written to test a zip file. If not a zip, the function will return the
  1607. * default return value: ''
  1608. * @param string the path to the file
  1609. * @param string the original name of the file
  1610. * @return string 'scorm','aicc','scorm2004','dokeos' or '' if the package cannot be recognized
  1611. */
  1612. public function get_package_type($file_path, $file_name) {
  1613. // Get name of the zip file without the extension.
  1614. $file_info = pathinfo($file_name);
  1615. $filename = $file_info['basename']; // Name including extension.
  1616. $extension = $file_info['extension']; // Extension only.
  1617. if (!empty($_POST['ppt2lp']) && !in_array(strtolower($extension), array (
  1618. 'dll',
  1619. 'exe'
  1620. ))) {
  1621. return 'oogie';
  1622. }
  1623. if (!empty($_POST['woogie']) && !in_array(strtolower($extension), array (
  1624. 'dll',
  1625. 'exe'
  1626. ))) {
  1627. return 'woogie';
  1628. }
  1629. $file_base_name = str_replace('.' . $extension, '', $filename); // Filename without its extension.
  1630. $zipFile = new pclZip($file_path);
  1631. // Check the zip content (real size and file extension).
  1632. $zipContentArray = $zipFile->listContent();
  1633. $package_type = '';
  1634. $at_root = false;
  1635. $manifest = '';
  1636. // The following loop should be stopped as soon as we found the right imsmanifest.xml (how to recognize it?).
  1637. if (is_array($zipContentArray) && count($zipContentArray) > 0) {
  1638. foreach ($zipContentArray as $thisContent) {
  1639. if (preg_match('~.(php.*|phtml)$~i', $thisContent['filename'])) {
  1640. // New behaviour: Don't do anything. These files will be removed in scorm::import_package.
  1641. }
  1642. elseif (stristr($thisContent['filename'], 'imsmanifest.xml') !== false) {
  1643. $manifest = $thisContent['filename']; // Just the relative directory inside scorm/
  1644. $package_type = 'scorm';
  1645. break; // Exit the foreach loop.
  1646. }
  1647. elseif (preg_match('/aicc\//i', $thisContent['filename'])) {
  1648. // If found an aicc directory... (!= false means it cannot be false (error) or 0 (no match)).
  1649. $package_type = 'aicc';
  1650. //break; // Don't exit the loop, because if we find an imsmanifest afterwards, we want it, not the AICC.
  1651. } else {
  1652. $package_type = '';
  1653. }
  1654. }
  1655. }
  1656. return $package_type;
  1657. }
  1658. /**
  1659. * Gets the previous resource in queue (url). Also initialises time values for this viewing
  1660. * @return string URL to load into the viewer
  1661. */
  1662. public function get_previous_index() {
  1663. if ($this->debug > 0) {
  1664. error_log('New LP - In learnpath::get_previous_index()', 0);
  1665. }
  1666. $index = $this->index;
  1667. if (isset ($this->ordered_items[$index -1])) {
  1668. $index--;
  1669. 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')) {
  1670. $index--;
  1671. if ($index < 0) {
  1672. return $this->index;
  1673. }
  1674. }
  1675. } else {
  1676. if ($this->debug > 2) {
  1677. error_log('New LP - get_previous_index() - there was no previous index available, reusing ' . $index, 0);
  1678. }
  1679. // There is no previous item.
  1680. }
  1681. return $index;
  1682. }
  1683. /**
  1684. * Gets item_id for the next element
  1685. * @return integer Previous item (DB) ID
  1686. */
  1687. public function get_previous_item_id() {
  1688. if ($this->debug > 0) {
  1689. error_log('New LP - In learnpath::get_previous_item_id()', 0);
  1690. }
  1691. $new_index = $this->get_previous_index();
  1692. return $this->ordered_items[$new_index];
  1693. }
  1694. /**
  1695. * Gets the progress value from the progress_db attribute
  1696. * @return integer Current progress value
  1697. */
  1698. public function get_progress() {
  1699. if ($this->debug > 0) {
  1700. error_log('New LP - In learnpath::get_progress()', 0);
  1701. }
  1702. if (!empty ($this->progress_db)) {
  1703. return $this->progress_db;
  1704. }
  1705. return 0;
  1706. }
  1707. /**
  1708. * Gets the progress value from the progress field in the database (allows use as abstract method)
  1709. * @param integer Learnpath ID
  1710. * @param integer User ID
  1711. * @param string Mode of display ('%','abs' or 'both')
  1712. * @param string Course database name (optional, defaults to '')
  1713. * @param boolean Whether to return null if no record was found (true), or 0 (false) (optional, defaults to false)
  1714. * @return integer Current progress value as found in the database
  1715. */
  1716. public function get_db_progress($lp_id, $user_id, $mode = '%', $course_db = '', $sincere = false,$session_id = 0) {
  1717. //if ($this->debug > 0) { error_log('New LP - In learnpath::get_db_progress()', 0); }
  1718. $session_id = intval($session_id);
  1719. $session_condition = api_get_session_condition($session_id);
  1720. $table = Database :: get_course_table(TABLE_LP_VIEW, $course_db);
  1721. $sql = "SELECT * FROM $table WHERE lp_id = $lp_id AND user_id = $user_id $session_condition";
  1722. $res = Database::query($sql);
  1723. $view_id = 0;
  1724. if (Database :: num_rows($res) > 0) {
  1725. $row = Database :: fetch_array($res);
  1726. $progress = $row['progress'];
  1727. $view_id = $row['id'];
  1728. } else {
  1729. if ($sincere) {
  1730. return null;
  1731. }
  1732. }
  1733. if (empty ($progress)) {
  1734. $progress = '0';
  1735. }
  1736. if ($mode == '%') {
  1737. return $progress . '%';
  1738. } else {
  1739. // Get the number of items completed and the number of items total.
  1740. $tbl = Database :: get_course_table(TABLE_LP_ITEM, $course_db);
  1741. $sql = "SELECT count(*) FROM $tbl WHERE lp_id = " . $lp_id . "
  1742. AND item_type NOT IN('dokeos_chapter','chapter','dir')";
  1743. $res = Database::query($sql);
  1744. $row = Database :: fetch_array($res);
  1745. $total = $row[0];
  1746. $tbl_item_view = Database :: get_course_table(TABLE_LP_ITEM_VIEW, $course_db);
  1747. $tbl_item = Database :: get_course_table(TABLE_LP_ITEM, $course_db);
  1748. //$sql = "SELECT count(distinct(lp_item_id)) FROM $tbl WHERE lp_view_id = ".$view_id." AND status IN ('passed','completed','succeeded')";
  1749. // Trying as also counting browsed and failed items.
  1750. $sql = "SELECT count(distinct(lp_item_id))
  1751. FROM $tbl_item_view as item_view
  1752. INNER JOIN $tbl_item as item
  1753. ON item.id = item_view.lp_item_id
  1754. AND item_type NOT IN('dokeos_chapter','chapter','dir')
  1755. WHERE lp_view_id = " . $view_id . "
  1756. AND status IN ('passed','completed','succeeded','browsed','failed')"; //echo '<br />';
  1757. $res = Database::query($sql);
  1758. $row = Database :: fetch_array($res);
  1759. $completed = $row[0];
  1760. if ($mode == 'abs') {
  1761. return $completed . '/' . $total;
  1762. }
  1763. elseif ($mode == 'both') {
  1764. if ($progress < ($completed / ($total ? $total : 1))) {
  1765. $progress = number_format(($completed / ($total ? $total : 1)) * 100, 0);
  1766. }
  1767. return $progress . '% (' . $completed . '/' . $total . ')';
  1768. }
  1769. }
  1770. return $progress;
  1771. }
  1772. /**
  1773. * Returns the HTML necessary to print a mediaplayer block inside a page
  1774. * @return string The mediaplayer HTML
  1775. */
  1776. public function get_mediaplayer($autostart='true') {
  1777. global $_course;
  1778. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  1779. $tbl_lp_item_view = Database :: get_course_table(TABLE_LP_ITEM_VIEW);
  1780. // Getting all the information about the item.
  1781. $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 " .
  1782. "WHERE lp.id = '" . $_SESSION['oLP']->current . "'";
  1783. $result = Database::query($sql);
  1784. $row = Database::fetch_assoc($result);
  1785. $output = '';
  1786. if (!empty ($row['audio'])) {
  1787. $list = $_SESSION['oLP']->get_toc();
  1788. $type_quiz = false;
  1789. foreach($list as $toc) {
  1790. if ($toc['id'] == $_SESSION['oLP']->current && ($toc['type']=='quiz') ) {
  1791. $type_quiz = true;
  1792. }
  1793. }
  1794. if ($type_quiz) {
  1795. if ($_SESSION['oLP']->prevent_reinit == 1) {
  1796. $row['status'] === 'completed' ? $autostart_audio = 'false' : $autostart_audio = 'true';
  1797. } else {
  1798. $autostart_audio = $autostart;
  1799. }
  1800. } else {
  1801. $autostart_audio = 'true';
  1802. }
  1803. // The mp3 player.
  1804. $output = '<div id="container">';
  1805. $output .= '<script type="text/javascript" src="../inc/lib/mediaplayer/swfobject.js"></script>';
  1806. $output .= '<script type="text/javascript">
  1807. var s1 = new SWFObject("../inc/lib/mediaplayer/player.swf","ply","250","20","9","#FFFFFF");
  1808. s1.addParam("allowscriptaccess","always");
  1809. s1.addParam("flashvars","file=' . api_get_path(WEB_COURSE_PATH) . $_course['path'] . '/document/audio/' . $row['audio'] . '&autostart=' . $autostart_audio.'");
  1810. s1.write("container");
  1811. </script></div>';
  1812. }
  1813. return $output;
  1814. }
  1815. /**
  1816. * This function checks if the learnpath is visible for student after the progress of its prerequisite is completed, and considering time availability
  1817. * @param int Learnpath id
  1818. * @param int Student id
  1819. * @param string Course code (optional)
  1820. * @return bool True if
  1821. */
  1822. public function is_lp_visible_for_student($lp_id, $student_id, $course = null) {
  1823. $lp_id = (int)$lp_id;
  1824. $course = api_get_course_info($course);
  1825. $tbl_learnpath = Database :: get_course_table(TABLE_LP_MAIN,$course['dbName']);
  1826. // Get current prerequisite
  1827. $sql = "SELECT id, prerequisite, publicated_on, expired_on FROM $tbl_learnpath WHERE id = $lp_id";
  1828. $rs = Database::query($sql);
  1829. if (Database::num_rows($rs)>0) {
  1830. $row = Database::fetch_array($rs);
  1831. $prerequisite = $row['prerequisite'];
  1832. $find = array(' ','-',':');
  1833. $from = str_replace($find,'',api_get_local_time($row['publicated_on']));
  1834. $to = str_replace($find,'',api_get_local_time($row['expired_on']));
  1835. $is_visible = true;
  1836. $progress = 0;
  1837. if (!empty($prerequisite)) {
  1838. $progress = self::get_db_progress($prerequisite,$student_id,'%', '', false, api_get_session_id());
  1839. $progress = intval($progress);
  1840. if ($progress < 100) {
  1841. $is_visible = false;
  1842. }
  1843. }
  1844. // Also check the time availability of the learning path
  1845. if ($is_visible) {
  1846. $now = str_replace($find,'',api_get_local_time());
  1847. if ((($row['publicated_on']!='0000-00-00 00:00:00') && ($now<$from)) or (($row['expired_on']!='0000-00-00 00:00:00') && ($now>$to))) {
  1848. $is_visible = false;
  1849. }
  1850. }
  1851. return $is_visible;
  1852. }
  1853. return false;
  1854. }
  1855. /**
  1856. * Gets a progress bar for the learnpath by counting the number of items in it and the number of items
  1857. * completed so far.
  1858. * @param string Mode in which we want the values
  1859. * @param integer Progress value to display (optional but mandatory if used in abstract context)
  1860. * @param string Text to display near the progress value (optional but mandatory in abstract context)
  1861. * @param boolean true if it comes from a Diplay LP view
  1862. * @return string HTML string containing the progress bar
  1863. */
  1864. public function get_progress_bar($mode = '', $percentage = -1, $text_add = '', $from_lp = false) {
  1865. //if ($this->debug > 0) {error_log('New LP - In learnpath::get_progress_bar('.$mode.','.$percentage.','.$text_add.','.$from_lp.')', 0); }
  1866. global $lp_theme_css;
  1867. // Setting up the CSS path of the current style if exists.
  1868. if (!empty ($lp_theme_css)) {
  1869. $css_path = api_get_path(WEB_CODE_PATH) . 'css/' . $lp_theme_css . '/images/';
  1870. } else {
  1871. $css_path = '../img/';
  1872. }
  1873. //if ($this->debug > 0) { error_log('New LP - In learnpath::get_progress_bar()', 0); }
  1874. if (isset($this) && is_object($this) && ($percentage == '-1' OR $text_add == '')) {
  1875. list($percentage, $text_add) = $this->get_progress_bar_text($mode);
  1876. }
  1877. $text = $percentage . $text_add;
  1878. // Default progress bar config
  1879. // times that will be greater or shorter
  1880. $factor = 1.2;
  1881. if ($from_lp)
  1882. $progress_height = '26';
  1883. else
  1884. $progress_height = '16';
  1885. $size = str_replace('%', '', $percentage);
  1886. $output ='<div style="width:135px">' .
  1887. '<img id="progress_img_limit_left" src="' . $css_path . 'bar_1.gif" width="1" height="' . $progress_height . '">' .
  1888. '<img id="progress_img_full" src="' . $css_path . 'bar_1u.gif" width="' . $size * $factor . 'px" height="' . $progress_height . '" id="full_portion">' .
  1889. '<img id="progress_img_limit_middle" src="' . $css_path . 'bar_1m.gif" width="1" height="' . $progress_height . '">';
  1890. if ($percentage <= 98) {
  1891. $output .= '<img id="progress_img_empty" src="' . $css_path . 'bar_1r.gif" width="' . (100 - $size) * $factor . 'px" height="' . $progress_height . '" id="empty_portion">';
  1892. } else {
  1893. $output .= '<img id="progress_img_empty" src="' . $css_path . 'bar_1r.gif" width="0" height="' . $progress_height . '" id="empty_portion">';
  1894. }
  1895. $output .= '<img id="progress_bar_img_limit_right" src="' . $css_path . 'bar_1.gif" width="1" height="' . $progress_height . '"></div>' .
  1896. '<div class="progresstext" id="progress_text">' . $text . '</div>';
  1897. return $output;
  1898. }
  1899. /**
  1900. * Gets the progress bar info to display inside the progress bar. Also used by scorm_api.php
  1901. * @param string Mode of display (can be '%' or 'abs').abs means we display a number of completed elements per total elements
  1902. * @param integer Additional steps to fake as completed
  1903. * @return list Percentage or number and symbol (% or /xx)
  1904. */
  1905. public function get_progress_bar_text($mode = '', $add = 0) {
  1906. if ($this->debug > 0) {
  1907. error_log('New LP - In learnpath::get_progress_bar_text()', 0);
  1908. }
  1909. if (empty ($mode)) {
  1910. $mode = $this->progress_bar_mode;
  1911. }
  1912. $total_items = $this->get_total_items_count_without_chapters();
  1913. if ($this->debug > 2) {
  1914. error_log('New LP - Total items available in this learnpath: ' . $total_items, 0);
  1915. }
  1916. $i = $this->get_complete_items_count();
  1917. if ($this->debug > 2) {
  1918. error_log('New LP - Items completed so far: ' . $i, 0);
  1919. }
  1920. if ($add != 0) {
  1921. $i += $add;
  1922. if ($this->debug > 2) {
  1923. error_log('New LP - Items completed so far (+modifier): ' . $i, 0);
  1924. }
  1925. }
  1926. $text = '';
  1927. if ($i > $total_items) {
  1928. $i = $total_items;
  1929. }
  1930. if ($mode == '%') {
  1931. if ($total_items > 0) {
  1932. $percentage = ((float) $i / (float) $total_items) * 100;
  1933. } else {
  1934. $percentage = 0;
  1935. }
  1936. $percentage = number_format($percentage, 0);
  1937. $text = '%';
  1938. }
  1939. elseif ($mode == 'abs') {
  1940. $percentage = $i;
  1941. $text = '/' . $total_items;
  1942. }
  1943. return array (
  1944. $percentage,
  1945. $text
  1946. );
  1947. }
  1948. /**
  1949. * Gets the progress bar mode
  1950. * @return string The progress bar mode attribute
  1951. */
  1952. public function get_progress_bar_mode() {
  1953. if ($this->debug > 0) {
  1954. error_log('New LP - In learnpath::get_progress_bar_mode()', 0);
  1955. }
  1956. if (!empty ($this->progress_bar_mode)) {
  1957. return $this->progress_bar_mode;
  1958. } else {
  1959. return '%';
  1960. }
  1961. }
  1962. /**
  1963. * Gets the learnpath proximity (remote or local)
  1964. * @return string Learnpath proximity
  1965. */
  1966. public function get_proximity() {
  1967. if ($this->debug > 0) {
  1968. error_log('New LP - In learnpath::get_proximity()', 0);
  1969. }
  1970. if (!empty ($this->proximity)) {
  1971. return $this->proximity;
  1972. } else {
  1973. return '';
  1974. }
  1975. }
  1976. /**
  1977. * Gets the learnpath theme (remote or local)
  1978. * @return string Learnpath theme
  1979. */
  1980. public function get_theme() {
  1981. if ($this->debug > 0) {
  1982. error_log('New LP - In learnpath::get_theme()', 0);
  1983. }
  1984. if (!empty ($this->theme)) {
  1985. return $this->theme;
  1986. } else {
  1987. return '';
  1988. }
  1989. }
  1990. /**
  1991. * Gets the learnpath session id
  1992. * @return string Learnpath theme
  1993. */
  1994. public function get_lp_session_id() {
  1995. if ($this->debug > 0) {
  1996. error_log('New LP - In learnpath::get_lp_session_id()', 0);
  1997. }
  1998. if (!empty ($this->lp_session_id)) {
  1999. return $this->lp_session_id;
  2000. } else {
  2001. return 0;
  2002. }
  2003. }
  2004. /**
  2005. * Gets the learnpath image
  2006. * @return string Web URL of the LP image
  2007. */
  2008. public function get_preview_image() {
  2009. if ($this->debug > 0) {
  2010. error_log('New LP - In learnpath::get_preview_image()', 0);
  2011. }
  2012. if (!empty ($this->preview_image)) {
  2013. return $this->preview_image;
  2014. } else {
  2015. return '';
  2016. }
  2017. }
  2018. /**
  2019. * Gets the learnpath author
  2020. * @return string LP's author
  2021. */
  2022. public function get_author() {
  2023. if ($this->debug > 0) {
  2024. error_log('New LP - In learnpath::get_author()', 0);
  2025. }
  2026. if (!empty ($this->author)) {
  2027. return $this->author;
  2028. } else {
  2029. return '';
  2030. }
  2031. }
  2032. /**
  2033. * Generate a new prerequisites string for a given item. If this item was a sco and
  2034. * its prerequisites were strings (instead of IDs), then transform those strings into
  2035. * IDs, knowing that SCORM IDs are kept in the "ref" field of the lp_item table.
  2036. * Prefix all item IDs that end-up in the prerequisites string by "ITEM_" to use the
  2037. * same rule as the scorm_export() method
  2038. * @param integer Item ID
  2039. * @return string Prerequisites string ready for the export as SCORM
  2040. */
  2041. public function get_scorm_prereq_string($item_id) {
  2042. if ($this->debug > 0) {
  2043. error_log('New LP - In learnpath::get_scorm_prereq_string()', 0);
  2044. }
  2045. if (!is_object($this->items[$item_id])) {
  2046. return false;
  2047. }
  2048. $oItem = $this->items[$item_id];
  2049. $prereq = $oItem->get_prereq_string();
  2050. if (empty ($prereq)) {
  2051. return '';
  2052. }
  2053. 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,
  2054. // then simply return it (with the ITEM_ prefix).
  2055. return 'ITEM_' . $prereq;
  2056. } else {
  2057. if (isset ($this->refs_list[$prereq])) {
  2058. // It's a simple string item from which the ID can be found in the refs list,
  2059. // so we can transform it directly to an ID for export.
  2060. return 'ITEM_' . $this->refs_list[$prereq];
  2061. } else {
  2062. // The last case, if it's a complex form, then find all the IDs (SCORM strings)
  2063. // and replace them, one by one, by the internal IDs (chamilo db)
  2064. // TODO: Modify the '*' replacement to replace the multiplier in front of it
  2065. // by a space as well.
  2066. $find = array (
  2067. '&',
  2068. '|',
  2069. '~',
  2070. '=',
  2071. '<>',
  2072. '{',
  2073. '}',
  2074. '*',
  2075. '(',
  2076. ')'
  2077. );
  2078. $replace = array (
  2079. ' ',
  2080. ' ',
  2081. ' ',
  2082. ' ',
  2083. ' ',
  2084. ' ',
  2085. ' ',
  2086. ' ',
  2087. ' ',
  2088. ' '
  2089. );
  2090. $prereq_mod = str_replace($find, $replace, $prereq);
  2091. $ids = split(' ', $prereq_mod);
  2092. foreach ($ids as $id) {
  2093. $id = trim($id);
  2094. if (isset ($this->refs_list[$id])) {
  2095. $prereq = preg_replace('/[^a-zA-Z_0-9](' . $id . ')[^a-zA-Z_0-9]/', 'ITEM_' . $this->refs_list[$id], $prereq);
  2096. }
  2097. }
  2098. error_log('New LP - In learnpath::get_scorm_prereq_string(): returning modified string: ' . $prereq, 0);
  2099. return $prereq;
  2100. }
  2101. }
  2102. }
  2103. /**
  2104. * Returns the XML DOM document's node
  2105. * @param resource Reference to a list of objects to search for the given ITEM_*
  2106. * @param string The identifier to look for
  2107. * @return mixed The reference to the element found with that identifier. False if not found
  2108. */
  2109. public function get_scorm_xml_node(& $children, $id) {
  2110. for ($i = 0; $i < $children->length; $i++) {
  2111. $item_temp = $children->item($i);
  2112. if ($item_temp->nodeName == 'item') {
  2113. if ($item_temp->getAttribute('identifier') == $id) {
  2114. return $item_temp;
  2115. }
  2116. }
  2117. $subchildren = $item_temp->childNodes;
  2118. if ($subchildren->length > 0) {
  2119. $val = $this->get_scorm_xml_node($subchildren, $id);
  2120. if (is_object($val)) {
  2121. return $val;
  2122. }
  2123. }
  2124. }
  2125. return false;
  2126. }
  2127. /**
  2128. * Returns a usable array of stats related to the current learnpath and user
  2129. * @return array Well-formatted array containing status for the current learnpath
  2130. */
  2131. public function get_stats() {
  2132. if ($this->debug > 0) {
  2133. error_log('New LP - In learnpath::get_stats()', 0);
  2134. }
  2135. // TODO
  2136. }
  2137. /**
  2138. * Static method. Can be re-implemented by children. Gives an array of statistics for
  2139. * the given course (for all learnpaths and all users)
  2140. * @param string Course code
  2141. * @return array Well-formatted array containing status for the course's learnpaths
  2142. */
  2143. public function get_stats_course($course) {
  2144. //if ($this->debug > 0) { error_log('New LP - In learnpath::get_stats_course()', 0); }
  2145. // TODO
  2146. }
  2147. /**
  2148. * Static method. Can be re-implemented by children. Gives an array of statistics for
  2149. * the given course and learnpath (for all users)
  2150. * @param string Course code
  2151. * @param integer Learnpath ID
  2152. * @return array Well-formatted array containing status for the specified learnpath
  2153. */
  2154. public function get_stats_lp($course, $lp) {
  2155. //if ($this->debug > 0) { error_log('New LP - In learnpath::get_stats_lp()', 0); }
  2156. // TODO
  2157. }
  2158. /**
  2159. * Static method. Can be re-implemented by children. Gives an array of statistics for
  2160. * the given course, learnpath and user.
  2161. * @param string Course code
  2162. * @param integer Learnpath ID
  2163. * @param integer User ID
  2164. * @return array Well-formatted array containing status for the specified learnpath and user
  2165. */
  2166. public function get_stats_lp_user($course, $lp, $user) {
  2167. //if ($this->debug > 0) { error_log('New LP - In learnpath::get_stats_lp_user()', 0); }
  2168. // TODO
  2169. }
  2170. /**
  2171. * Static method. Can be re-implemented by children. Gives an array of statistics for
  2172. * the given course and learnpath (for all users)
  2173. * @param string Course code
  2174. * @param integer User ID
  2175. * @return array Well-formatted array containing status for the user's learnpaths
  2176. */
  2177. public function get_stats_user($course, $user) {
  2178. //if ($this->debug > 0) { error_log('New LP - In learnpath::get_stats_user()', 0); }
  2179. // TODO
  2180. }
  2181. /**
  2182. * Gets the status list for all LP's items
  2183. * @return array Array of [index] => [item ID => current status]
  2184. */
  2185. public function get_items_status_list() {
  2186. if ($this->debug > 0) {
  2187. error_log('New LP - In learnpath::get_items_status_list()', 0);
  2188. }
  2189. $list = array ();
  2190. foreach ($this->ordered_items as $item_id) {
  2191. $list[] = array (
  2192. $item_id => $this->items[$item_id]->get_status()
  2193. );
  2194. }
  2195. return $list;
  2196. }
  2197. /**
  2198. * Return the number of interactions for the given learnpath Item View ID.
  2199. * This method can be used as static.
  2200. * @param integer Item View ID
  2201. * @return integer Number of interactions
  2202. */
  2203. public function get_interactions_count_from_db($lp_iv_id = 0, $course_code = null) {
  2204. if (empty ($lp_iv_id)) {
  2205. return -1;
  2206. }
  2207. $course_info = api_get_course_info($course_code);
  2208. $table = Database :: get_course_table(TABLE_LP_IV_INTERACTION, $course_info['db_name']);
  2209. $sql = "SELECT count(*) FROM $table WHERE lp_iv_id = $lp_iv_id";
  2210. $res = Database::query($sql);
  2211. $row = Database :: fetch_array($res);
  2212. $num = $row[0];
  2213. return $num;
  2214. }
  2215. /**
  2216. * Return the interactions as an array for the given lp_iv_id.
  2217. * This method can be used as static.
  2218. * @param integer Learnpath Item View ID
  2219. * @return array
  2220. * @todo Transcode labels instead of switching to HTML (which requires to know the encoding of the LP)
  2221. */
  2222. public function get_iv_interactions_array($lp_iv_id = 0) {
  2223. $list = array ();
  2224. $table = Database :: get_course_table(TABLE_LP_IV_INTERACTION);
  2225. $sql = "SELECT * FROM $table WHERE lp_iv_id = $lp_iv_id ORDER BY order_id ASC";
  2226. $res = Database::query($sql);
  2227. $num = Database :: num_rows($res);
  2228. if ($num > 0) {
  2229. $list[] = array (
  2230. 'order_id' => api_htmlentities(get_lang('Order'), ENT_QUOTES),
  2231. 'id' => api_htmlentities(get_lang('InteractionID'), ENT_QUOTES),
  2232. 'type' => api_htmlentities(get_lang('Type'), ENT_QUOTES),
  2233. 'time' => api_htmlentities(get_lang('TimeFinished'), ENT_QUOTES),
  2234. 'correct_responses' => api_htmlentities(get_lang('CorrectAnswers'), ENT_QUOTES),
  2235. 'student_response' => api_htmlentities(get_lang('StudentResponse'), ENT_QUOTES),
  2236. 'result' => api_htmlentities(get_lang('Result'), ENT_QUOTES),
  2237. 'latency' => api_htmlentities(get_lang('LatencyTimeSpent'), ENT_QUOTES)
  2238. );
  2239. while ($row = Database :: fetch_array($res)) {
  2240. $list[] = array (
  2241. 'order_id' => ($row['order_id'] + 1),
  2242. 'id' => urldecode($row['interaction_id']), //urldecode because they often have %2F or stuff like that
  2243. 'type' => $row['interaction_type'],
  2244. 'time' => $row['completion_time'],
  2245. //'correct_responses' => $row['correct_responses'],
  2246. 'correct_responses' => '', // Hide correct responses from students.
  2247. 'student_response' => $row['student_response'],
  2248. 'result' => $row['result'],
  2249. 'latency' => $row['latency']
  2250. );
  2251. }
  2252. }
  2253. return $list;
  2254. }
  2255. /**
  2256. * Return the number of objectives for the given learnpath Item View ID.
  2257. * This method can be used as static.
  2258. * @param integer Item View ID
  2259. * @return integer Number of objectives
  2260. */
  2261. public function get_objectives_count_from_db($lp_iv_id = 0, $course_code = null) {
  2262. if (empty ($lp_iv_id)) {
  2263. return -1;
  2264. }
  2265. $course_info = api_get_course_info($course_code);
  2266. $table = Database :: get_course_table(TABLE_LP_IV_OBJECTIVE, $course_info['db_name']);
  2267. $sql = "SELECT count(*) FROM $table WHERE lp_iv_id = $lp_iv_id";
  2268. $res = Database::query($sql);
  2269. $row = Database :: fetch_array($res);
  2270. $num = $row[0];
  2271. return $num;
  2272. }
  2273. /**
  2274. * Return the objectives as an array for the given lp_iv_id.
  2275. * This method can be used as static.
  2276. * @param integer Learnpath Item View ID
  2277. * @return array
  2278. * @todo Translate labels
  2279. */
  2280. public function get_iv_objectives_array($lp_iv_id = 0) {
  2281. $list = array();
  2282. $table = Database :: get_course_table(TABLE_LP_IV_OBJECTIVE);
  2283. $sql = "SELECT * FROM $table WHERE lp_iv_id = $lp_iv_id ORDER BY order_id ASC";
  2284. $res = Database::query($sql);
  2285. $num = Database :: num_rows($res);
  2286. if ($num > 0) {
  2287. $list[] = array (
  2288. 'order_id' => api_htmlentities(get_lang('Order'), ENT_QUOTES),
  2289. 'objective_id' => api_htmlentities(get_lang('ObjectiveID'), ENT_QUOTES),
  2290. 'score_raw' => api_htmlentities(get_lang('ObjectiveRawScore'), ENT_QUOTES),
  2291. 'score_max' => api_htmlentities(get_lang('ObjectiveMaxScore'), ENT_QUOTES),
  2292. 'score_min' => api_htmlentities(get_lang('ObjectiveMinScore'), ENT_QUOTES),
  2293. 'status' => api_htmlentities(get_lang('ObjectiveStatus'), ENT_QUOTES)
  2294. );
  2295. while ($row = Database :: fetch_array($res)) {
  2296. $list[] = array (
  2297. 'order_id' => ($row['order_id'] + 1),
  2298. 'objective_id' => urldecode($row['objective_id']), // urldecode() because they often have %2F or stuff like that.
  2299. 'score_raw' => $row['score_raw'],
  2300. 'score_max' => $row['score_max'],
  2301. 'score_min' => $row['score_min'],
  2302. 'status' => $row['status']
  2303. );
  2304. }
  2305. }
  2306. return $list;
  2307. }
  2308. /**
  2309. * Generate and return the table of contents for this learnpath. The (flat) table returned can be
  2310. * used by get_html_toc() to be ready to display
  2311. * @return array TOC as a table with 4 elements per row: title, link, status and level
  2312. */
  2313. public function get_toc() {
  2314. if ($this->debug > 0) {
  2315. error_log('New LP - In learnpath::get_toc()', 0);
  2316. }
  2317. $toc = array ();
  2318. //echo "<pre>".print_r($this->items,true)."</pre>";
  2319. foreach ($this->ordered_items as $item_id) {
  2320. if ($this->debug > 2) {
  2321. error_log('New LP - learnpath::get_toc(): getting info for item ' . $item_id, 0);
  2322. }
  2323. // TODO: Change this link generation and use new function instead.
  2324. $toc[] = array (
  2325. 'id' => $item_id,
  2326. 'title' => $this->items[$item_id]->get_title(),
  2327. //'link' => get_addedresource_link_in_learnpath('document', $item_id, 1),
  2328. 'status' => $this->items[$item_id]->get_status(),
  2329. 'level' => $this->items[$item_id]->get_level(),
  2330. 'type' => $this->items[$item_id]->get_type(),
  2331. 'description' => $this->items[$item_id]->get_description(),
  2332. 'path' => $this->items[$item_id]->get_path(),
  2333. );
  2334. }
  2335. if ($this->debug > 2) {
  2336. error_log('New LP - In learnpath::get_toc() - TOC array: ' . print_r($toc, true), 0);
  2337. }
  2338. return $toc;
  2339. }
  2340. /**
  2341. * Generate and return the table of contents for this learnpath. The JS
  2342. * table returned is used inside of scorm_api.php
  2343. * @return string A JS array vairiable construction
  2344. */
  2345. public function get_items_details_as_js($varname = 'olms.lms_item_types') {
  2346. if ($this->debug > 0) {
  2347. error_log('New LP - In learnpath::get_items_details_as_js()', 0);
  2348. }
  2349. $toc = $varname.' = new Array();';
  2350. //echo "<pre>".print_r($this->items,true)."</pre>";
  2351. foreach ($this->ordered_items as $item_id) {
  2352. if ($this->debug > 2) {
  2353. error_log('New LP - learnpath::get_items_details_as_js(): getting info for item ' . $item_id, 0);
  2354. }
  2355. $toc.= $varname."['i$item_id'] = '".$this->items[$item_id]->get_type()."';";
  2356. }
  2357. if ($this->debug > 2) {
  2358. error_log('New LP - In learnpath::get_items_details_as_js() - TOC array: ' . print_r($toc, true), 0);
  2359. }
  2360. return $toc;
  2361. }
  2362. /**
  2363. * Gets the learning path type
  2364. * @param boolean Return the name? If false, return the ID. Default is false.
  2365. * @return mixed Type ID or name, depending on the parameter
  2366. */
  2367. public function get_type($get_name = false) {
  2368. $res = false;
  2369. if ($this->debug > 0) {
  2370. error_log('New LP - In learnpath::get_type()', 0);
  2371. }
  2372. if (!empty ($this->type)) {
  2373. if ($get_name) {
  2374. // Get it from the lp_type table in main db.
  2375. } else {
  2376. $res = $this->type;
  2377. }
  2378. }
  2379. if ($this->debug > 2) {
  2380. error_log('New LP - In learnpath::get_type() - Returning ' . ($res ? $res : 'false'), 0);
  2381. }
  2382. return $res;
  2383. }
  2384. /**
  2385. * Gets the learning path type as static method
  2386. * @param boolean Return the name? If false, return the ID. Default is false.
  2387. * @return mixed Type ID or name, depending on the parameter
  2388. */
  2389. public function get_type_static($lp_id = 0) {
  2390. $tbl_lp = Database :: get_course_table(TABLE_LP_MAIN);
  2391. $sql = "SELECT lp_type FROM $tbl_lp WHERE id = '" . $lp_id . "'";
  2392. $res = Database::query($sql);
  2393. if ($res === false) {
  2394. return null;
  2395. }
  2396. if (Database :: num_rows($res) <= 0) {
  2397. return null;
  2398. }
  2399. $row = Database :: fetch_array($res);
  2400. return $row['lp_type'];
  2401. }
  2402. /**
  2403. * Gets a flat list of item IDs ordered for display (level by level ordered by order_display)
  2404. * This method can be used as abstract and is recursive
  2405. * @param integer Learnpath ID
  2406. * @param integer Parent ID of the items to look for
  2407. * @return mixed Ordered list of item IDs or false on error
  2408. */
  2409. public function get_flat_ordered_items_list($lp, $parent = 0, $course_db = '') {
  2410. //if ($this->debug > 0) { error_log('New LP - In learnpath::get_flat_ordered_items_list('.$lp.','.$parent.')', 0); }
  2411. $list = array();
  2412. if (empty ($lp)) {
  2413. return false;
  2414. }
  2415. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM, $course_db);
  2416. $sql = "SELECT * FROM $tbl_lp_item WHERE lp_id = $lp AND parent_item_id = $parent ORDER BY display_order";
  2417. $res = Database::query($sql);
  2418. while ($row = Database :: fetch_array($res)) {
  2419. $sublist = learnpath :: get_flat_ordered_items_list($lp, $row['id'], $course_db);
  2420. $list[] = $row['id'];
  2421. foreach ($sublist as $item) {
  2422. $list[] = $item;
  2423. }
  2424. }
  2425. return $list;
  2426. }
  2427. /**
  2428. * Uses the table generated by get_toc() and returns an HTML-formatted string ready to display
  2429. * @return string HTML TOC ready to display
  2430. */
  2431. public function get_html_toc() {
  2432. $is_allowed_to_edit = api_is_allowed_to_edit(null, true);
  2433. $charset = api_get_system_encoding();
  2434. $display_action_links_with_icons = false;
  2435. if ($this->debug > 0) {
  2436. error_log('New LP - In learnpath::get_html_toc()', 0);
  2437. }
  2438. $list = $this->get_toc();
  2439. //echo $this->current;
  2440. //$parent = $this->items[$this->current]->get_parent();
  2441. //if (empty($parent)) { $parent = $this->ordered_items[$this->items[$this->current]->get_previous_index()]; }
  2442. $html = '<div id="scorm_title" class="scorm_title"><div class="scorm_title_text">' . Security::remove_XSS($this->get_name()) . '</div></div>';
  2443. // Build, display.
  2444. if ($is_allowed_to_edit) {
  2445. $gradebook = Security :: remove_XSS($_GET['gradebook']);
  2446. //var_dump($this->get_lp_session_id());
  2447. if ($this->get_lp_session_id() == api_get_session_id()) {
  2448. $html .= '<div id="actions_lp" class="actions_lp">';
  2449. if ($display_action_links_with_icons) {
  2450. $html .= '<div style = "text-align:center;">';
  2451. $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>";
  2452. $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>";
  2453. $html .= '<span>' . Display :: return_icon('view_remove_na.png', get_lang('Display'),'','32').'</span><br />';
  2454. $html .= '<a href="lp_controller.php?' . api_get_cidreq() . '">'. get_lang('ReturnToLPList') . '</a>';
  2455. $html .= '</div>';
  2456. } else {
  2457. $html .= '<div style = "text-align:center;">';
  2458. $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>";
  2459. $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>";
  2460. $html .= '<span><b>' . get_lang('Display') . '</b></span><br />';
  2461. $html .= '<a href="lp_controller.php?' . api_get_cidreq() . '">'. get_lang('ReturnToLPList') . '</a>';
  2462. $html .= '</div>';
  2463. }
  2464. $html .= '</div>';
  2465. }
  2466. }
  2467. $html .= '<div id="inner_lp_toc" class="inner_lp_toc">';
  2468. require_once 'resourcelinker.inc.php';
  2469. // Temporary variables.
  2470. $mycurrentitemid = $this->get_current_item_id();
  2471. $color_counter = 0;
  2472. $i = 0;
  2473. foreach ($list as $item) {
  2474. if ($this->debug > 2) {
  2475. error_log('New LP - learnpath::get_html_toc(): using item ' . $item['id'], 0);
  2476. }
  2477. // TODO: Complete this.
  2478. $icon_name = array (
  2479. 'not attempted' => '../img/notattempted.gif',
  2480. 'incomplete' => '../img/incomplete.png',
  2481. 'failed' => '../img/delete.png',
  2482. 'completed' => '../img/completed.png',
  2483. 'passed' => '../img/passed.png',
  2484. 'succeeded' => '../img/succeeded.png',
  2485. 'browsed' => '../img/completed.png',
  2486. );
  2487. $style = 'scorm_item';
  2488. $scorm_color_background = 'scorm_item';
  2489. $style_item = 'scorm_item';
  2490. $current = false;
  2491. if ($item['id'] == $this->current) {
  2492. $style = 'scorm_item_highlight';
  2493. $scorm_color_background = 'scorm_item_highlight';
  2494. } else
  2495. if ($color_counter % 2 == 0) {
  2496. $scorm_color_background = 'scorm_item_1';
  2497. } else {
  2498. $scorm_color_background = 'scorm_item_2';
  2499. }
  2500. if ($scorm_color_background != '') {
  2501. $html .= '<div id="toc_' . $item['id'] . '" class="' . $scorm_color_background . '">';
  2502. }
  2503. // The anchor will let us center the TOC on the currently viewed item &^D
  2504. if ($item['type'] != 'dokeos_module' && $item['type'] != 'dokeos_chapter') {
  2505. $html .= '<a name="atoc_' . $item['id'] . '" />';
  2506. $html .= '<div class="' . $style_item . '" style="padding-left: ' . ($item['level'] * 1.5) . 'em; padding-right:' . ($item['level'] / 2) . 'em" title="' . $item['description'] . '" >';
  2507. } else {
  2508. $html .= '<div class="' . $style_item . '" style="padding-left: ' . ($item['level'] * 2) . 'em; padding-right:' . ($item['level'] * 1.5) . 'em" title="' . $item['description'] . '" >';
  2509. }
  2510. $title = $item['title'];
  2511. if (empty ($title)) {
  2512. $title = rl_get_resource_name(api_get_course_id(), $this->get_id(), $item['id']);
  2513. }
  2514. $title = Security::remove_XSS($title);
  2515. if ($item['type'] != 'dokeos_chapter' && $item['type'] != 'dir' && $item['type'] != 'dokeos_module') {
  2516. //$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>" ;
  2517. $url = $this->get_link('http', $item['id']);
  2518. //$html .= '<a href="'.$url.'" target="content_name" onClick="top.load_item('.$item['id'].',\''.$url.'\');">'.$title.'</a>' ;
  2519. //$html .= '<a href="" onClick="top.load_item('.$item['id'].',\''.$url.'\');return false;">'.$title.'</a>' ;
  2520. //<img align="absbottom" width="13" height="13" src="../img/lp_document.png">&nbsp;background:#aaa;
  2521. $html .= '<a href="" onClick="switch_item(' .$mycurrentitemid . ',' .$item['id'] . ');' .'return false;" >' . stripslashes($title) . '</a>';
  2522. } elseif ($item['type'] == 'dokeos_module' || $item['type'] == 'dokeos_chapter') {
  2523. $html .= "<img align='absbottom' width='13' height='13' src='../img/lp_dokeos_module.png'>&nbsp;" . stripslashes($title);
  2524. } elseif ($item['type'] == 'dir') {
  2525. $html .= stripslashes($title);
  2526. }
  2527. $tbl_track_e_exercises = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
  2528. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  2529. $user_id = api_get_user_id();
  2530. $course_id = api_get_course_id();
  2531. $sql = "SELECT path FROM $tbl_track_e_exercises, $tbl_lp_item
  2532. WHERE path = '" . $item['path'] . "' AND exe_user_id = '$user_id' AND exe_cours_id = '$course_id' AND path = exe_exo_id AND status <> 'incomplete'";
  2533. $result = Database::query($sql);
  2534. $count = Database :: num_rows($result);
  2535. if ($item['type'] == 'quiz') {
  2536. if ($item['status'] == 'completed') {
  2537. $html .= "&nbsp;<img id='toc_img_" . $item['id'] . "' src='" . $icon_name[$item['status']] . "' alt='" . substr($item['status'], 0, 1) . "' width='14' />";
  2538. }
  2539. } else {
  2540. if ($item['type'] != 'dokeos_chapter' && $item['type'] != 'dokeos_module' && $item['type'] != 'dir') {
  2541. $html .= "&nbsp;<img id='toc_img_" . $item['id'] . "' src='" . $icon_name[$item['status']] . "' alt='" . substr($item['status'], 0, 1) . "' width='14' />";
  2542. }
  2543. }
  2544. $html .= "</div>";
  2545. if ($scorm_color_background != '') {
  2546. $html .= '</div>';
  2547. }
  2548. $color_counter++;
  2549. }
  2550. $html .= "</div>";
  2551. return $html;
  2552. }
  2553. /**
  2554. * Gets the learnpath maker name - generally the editor's name
  2555. * @return string Learnpath maker name
  2556. */
  2557. public function get_maker() {
  2558. if ($this->debug > 0) {
  2559. error_log('New LP - In learnpath::get_maker()', 0);
  2560. }
  2561. if (!empty ($this->maker)) {
  2562. return $this->maker;
  2563. } else {
  2564. return '';
  2565. }
  2566. }
  2567. /**
  2568. * Gets the user-friendly message stored in $this->message
  2569. * @return string Message
  2570. */
  2571. public function get_message() {
  2572. if ($this->debug > 0) {
  2573. error_log('New LP - In learnpath::get_message()', 0);
  2574. }
  2575. return $this->message;
  2576. }
  2577. /**
  2578. * Gets the learnpath name/title
  2579. * @return string Learnpath name/title
  2580. */
  2581. public function get_name() {
  2582. if ($this->debug > 0) {
  2583. error_log('New LP - In learnpath::get_name()', 0);
  2584. }
  2585. if (!empty ($this->name)) {
  2586. return $this->name;
  2587. } else {
  2588. return 'N/A';
  2589. }
  2590. }
  2591. /**
  2592. * Gets a link to the resource from the present location, depending on item ID.
  2593. * @param string Type of link expected
  2594. * @param integer Learnpath item ID
  2595. * @return string Link to the lp_item resource
  2596. */
  2597. public function get_link($type = 'http', $item_id = null) {
  2598. if ($this->debug > 0) {
  2599. error_log('New LP - In learnpath::get_link(' . $type . ',' . $item_id . ')', 0);
  2600. }
  2601. if (empty($item_id)) {
  2602. if ($this->debug > 2) {
  2603. error_log('New LP - In learnpath::get_link() - no item id given in learnpath::get_link(), using current: ' . $this->get_current_item_id(), 0);
  2604. }
  2605. $item_id = $this->get_current_item_id();
  2606. }
  2607. if (empty ($item_id)) {
  2608. if ($this->debug > 2) {
  2609. error_log('New LP - In learnpath::get_link() - no current item id found in learnpath object', 0);
  2610. }
  2611. //still empty, this means there was no item_id given and we are not in an object context or
  2612. //the object property is empty, return empty link
  2613. $item_id = $this->first();
  2614. return '';
  2615. }
  2616. $file = '';
  2617. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  2618. $lp_item_table = Database :: get_course_table(TABLE_LP_ITEM);
  2619. $lp_item_view_table = Database :: get_course_table(TABLE_LP_ITEM_VIEW);
  2620. $item_id = Database::escape_string($item_id);
  2621. $sel = "SELECT l.lp_type as ltype, l.path as lpath, li.item_type as litype, li.path as lipath, li.parameters as liparams " .
  2622. "FROM $lp_table l, $lp_item_table li WHERE li.id = $item_id AND li.lp_id = l.id";
  2623. if ($this->debug > 2) {
  2624. error_log('New LP - In learnpath::get_link() - selecting item ' . $sel, 0);
  2625. }
  2626. $res = Database::query($sel);
  2627. if (Database :: num_rows($res) > 0) {
  2628. $row = Database :: fetch_array($res);
  2629. //var_dump($row);
  2630. $lp_type = $row['ltype'];
  2631. $lp_path = $row['lpath'];
  2632. $lp_item_type = $row['litype'];
  2633. $lp_item_path = $row['lipath'];
  2634. $lp_item_params = $row['liparams'];
  2635. if (empty ($lp_item_params) && strpos($lp_item_path, '?') !== false) {
  2636. list ($lp_item_path, $lp_item_params) = explode('?', $lp_item_path);
  2637. }
  2638. //$lp_item_params = '?'.$lp_item_params;
  2639. //add ? if none - left commented to give freedom to scorm implementation
  2640. //if(substr($lp_item_params,0,1)!='?'){
  2641. // $lp_item_params = '?'.$lp_item_params;
  2642. //}
  2643. $sys_course_path = api_get_path(SYS_COURSE_PATH) . api_get_course_path();
  2644. if ($type == 'http') {
  2645. $course_path = api_get_path(WEB_COURSE_PATH) . api_get_course_path(); //web path
  2646. } else {
  2647. $course_path = $sys_course_path; //system path
  2648. }
  2649. // 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.
  2650. if (in_array($lp_item_type, array('quiz', 'document', 'link', 'forum', 'thread', 'student_publication'))) {
  2651. $lp_type = 1;
  2652. }
  2653. // Now go through the specific cases to get the end of the path.
  2654. // @todo Use constants instead of int values.
  2655. switch ($lp_type) {
  2656. case 1 :
  2657. if ($lp_item_type == 'dokeos_chapter') {
  2658. $file = 'lp_content.php?type=dir';
  2659. } else {
  2660. require_once 'resourcelinker.inc.php';
  2661. $file = rl_get_resource_link_for_learnpath(api_get_course_id(), $this->get_id(), $item_id);
  2662. //CEV CHANGE
  2663. if ($lp_item_type == 'link') {
  2664. require_once api_get_path(LIBRARY_PATH).'link.lib.php';
  2665. if (is_youtube_link($file)) {
  2666. $src = get_youtube_video_id($file);
  2667. $file = 'embed.php?type=youtube&src='.$src;
  2668. }
  2669. } else {
  2670. // check how much attempts of a exercise exits in lp
  2671. $lp_item_id = $this->get_current_item_id();
  2672. $lp_view_id = $this->get_view_id();
  2673. $prevent_reinit = $this->items[$this->current]->get_prevent_reinit();
  2674. $list = $this->get_toc();
  2675. $type_quiz = false;
  2676. foreach ($list as $toc) {
  2677. if ($toc['id'] == $lp_item_id && ($toc['type'] == 'quiz')) {
  2678. $type_quiz = true;
  2679. }
  2680. }
  2681. if ($type_quiz) {
  2682. $lp_item_id = Database :: escape_string($lp_item_id);
  2683. $lp_view_id = Database :: escape_string($lp_view_id);
  2684. $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'";
  2685. $result = Database::query($sql);
  2686. $row_count = Database :: fetch_row($result);
  2687. $count_item_view = (int) $row_count[0];
  2688. $not_multiple_attempt = 0;
  2689. if ($prevent_reinit === 1 && $count_item_view > 0) {
  2690. $not_multiple_attempt = 1;
  2691. }
  2692. $file .= '&not_multiple_attempt=' . $not_multiple_attempt;
  2693. }
  2694. $tmp_array = explode('/', $file);
  2695. $document_name = $tmp_array[count($tmp_array) - 1];
  2696. if (strpos($document_name, '_DELETED_')) {
  2697. $file = 'blank.php?error=document_deleted';
  2698. }
  2699. }
  2700. }
  2701. break;
  2702. case 2 :
  2703. if ($this->debug > 2) {
  2704. error_log('New LP - In learnpath::get_link() ' . __LINE__ . ' - Item type: ' . $lp_item_type, 0);
  2705. }
  2706. if ($lp_item_type != 'dir') {
  2707. // Quite complex here:
  2708. // We want to make sure 'http://' (and similar) links can
  2709. // be loaded as is (withouth the Chamilo path in front) but
  2710. // some contents use this form: resource.htm?resource=http://blablabla
  2711. // which means we have to find a protocol at the path's start, otherwise
  2712. // it should not be considered as an external URL.
  2713. //if ($this->prerequisites_match($item_id)) {
  2714. if (preg_match('#^[a-zA-Z]{2,5}://#', $lp_item_path) != 0) {
  2715. if ($this->debug > 2) {
  2716. error_log('New LP - In learnpath::get_link() ' . __LINE__ . ' - Found match for protocol in ' . $lp_item_path, 0);
  2717. }
  2718. // Distant url, return as is.
  2719. $file = $lp_item_path;
  2720. } else {
  2721. if ($this->debug > 2) {
  2722. error_log('New LP - In learnpath::get_link() ' . __LINE__ . ' - No starting protocol in ' . $lp_item_path, 0);
  2723. }
  2724. // Prevent getting untranslatable urls.
  2725. $lp_item_path = preg_replace('/%2F/', '/', $lp_item_path);
  2726. $lp_item_path = preg_replace('/%3A/', ':', $lp_item_path);
  2727. // Prepare the path.
  2728. $file = $course_path . '/scorm/' . $lp_path . '/' . $lp_item_path;
  2729. // TODO: Fix this for urls with protocol header.
  2730. $file = str_replace('//', '/', $file);
  2731. $file = str_replace(':/', '://', $file);
  2732. if (substr($lp_path, -1) == '/') {
  2733. $lp_path = substr($lp_path, 0, -1);
  2734. }
  2735. if (!is_file(realpath($sys_course_path . '/scorm/' . $lp_path . '/' . $lp_item_path))) {
  2736. // if file not found.
  2737. $decoded = html_entity_decode($lp_item_path);
  2738. list ($decoded) = explode('?', $decoded);
  2739. if (!is_file(realpath($sys_course_path . '/scorm/' . $lp_path . '/' . $decoded))) {
  2740. require_once 'resourcelinker.inc.php';
  2741. $file = rl_get_resource_link_for_learnpath(api_get_course_id(), $this->get_id(), $item_id);
  2742. if (empty($file)) {
  2743. $file = 'blank.php?error=document_not_found';
  2744. } else {
  2745. $tmp_array = explode('/', $file);
  2746. $document_name = $tmp_array[count($tmp_array) - 1];
  2747. if (strpos($document_name, '_DELETED_')) {
  2748. $file = 'blank.php?error=document_deleted';
  2749. } else {
  2750. $file = 'blank.php?error=document_not_found';
  2751. }
  2752. }
  2753. } else {
  2754. $file = $course_path . '/scorm/' . $lp_path . '/' . $decoded;
  2755. }
  2756. }
  2757. }
  2758. //}else{
  2759. //prerequisites did not match
  2760. //$file = 'blank.php';
  2761. //}
  2762. // We want to use parameters if they were defined in the imsmanifest.
  2763. if ($file != 'blank.php') {
  2764. $file .= (strstr($file, '?') === false ? '?' : '') . $lp_item_params;
  2765. }
  2766. } else {
  2767. $file = 'lp_content.php?type=dir';
  2768. }
  2769. break;
  2770. case 3 :
  2771. if ($this->debug > 2) {
  2772. error_log('New LP - In learnpath::get_link() ' . __LINE__ . ' - Item type: ' . $lp_item_type, 0);
  2773. }
  2774. // Formatting AICC HACP append URL.
  2775. $aicc_append = '?aicc_sid=' . urlencode(session_id()) . '&aicc_url=' . urlencode(api_get_path(WEB_CODE_PATH) . 'newscorm/aicc_hacp.php') . '&';
  2776. if ($lp_item_type != 'dir') {
  2777. // Quite complex here:
  2778. // We want to make sure 'http://' (and similar) links can
  2779. // be loaded as is (withouth the Chamilo path in front) but
  2780. // some contents use this form: resource.htm?resource=http://blablabla
  2781. // which means we have to find a protocol at the path's start, otherwise
  2782. // it should not be considered as an external URL.
  2783. if (preg_match('#^[a-zA-Z]{2,5}://#', $lp_item_path) != 0) {
  2784. if ($this->debug > 2) {
  2785. error_log('New LP - In learnpath::get_link() ' . __LINE__ . ' - Found match for protocol in ' . $lp_item_path, 0);
  2786. }
  2787. // Distant url, return as is.
  2788. $file = $lp_item_path;
  2789. // Enabled and modified by Ivan Tcholakov, 16-OCT-2008.
  2790. /*
  2791. if (stristr($file,'<servername>') !== false) {
  2792. $file = str_replace('<servername>', $course_path.'/scorm/'.$lp_path.'/', $lp_item_path);
  2793. }
  2794. */
  2795. if (stripos($file, '<servername>') !== false) {
  2796. //$file = str_replace('<servername>',$course_path.'/scorm/'.$lp_path.'/',$lp_item_path);
  2797. $web_course_path = str_replace('https://', '', str_replace('http://', '', $course_path));
  2798. $file = str_replace('<servername>', $web_course_path . '/scorm/' . $lp_path, $lp_item_path);
  2799. }
  2800. //
  2801. $file .= $aicc_append;
  2802. } else {
  2803. if ($this->debug > 2) {
  2804. error_log('New LP - In learnpath::get_link() ' . __LINE__ . ' - No starting protocol in ' . $lp_item_path, 0);
  2805. }
  2806. // Prevent getting untranslatable urls.
  2807. $lp_item_path = preg_replace('/%2F/', '/', $lp_item_path);
  2808. $lp_item_path = preg_replace('/%3A/', ':', $lp_item_path);
  2809. // Prepare the path - lp_path might be unusable because it includes the "aicc" subdir name.
  2810. $file = $course_path . '/scorm/' . $lp_path . '/' . $lp_item_path;
  2811. // TODO: Fix this for urls with protocol header.
  2812. $file = str_replace('//', '/', $file);
  2813. $file = str_replace(':/', '://', $file);
  2814. $file .= $aicc_append;
  2815. }
  2816. } else {
  2817. $file = 'lp_content.php?type=dir';
  2818. }
  2819. break;
  2820. case 4 :
  2821. break;
  2822. default :
  2823. break;
  2824. }
  2825. }
  2826. if ($this->debug > 2) {
  2827. error_log('New LP - In learnpath::get_link() - returning "' . $file . '" from get_link', 0);
  2828. }
  2829. return $file;
  2830. }
  2831. /**
  2832. * Gets the latest usable view or generate a new one
  2833. * @param integer Optional attempt number. If none given, takes the highest from the lp_view table
  2834. * @return integer DB lp_view id
  2835. */
  2836. public function get_view($attempt_num = 0) {
  2837. if ($this->debug > 0) {
  2838. error_log('New LP - In learnpath::get_view()', 0);
  2839. }
  2840. $search = '';
  2841. // Use $attempt_num to enable multi-views management (disabled so far).
  2842. if ($attempt_num != 0 AND intval(strval($attempt_num)) == $attempt_num) {
  2843. $search = 'AND view_count = ' . $attempt_num;
  2844. }
  2845. // When missing $attempt_num, search for a unique lp_view record for this lp and user.
  2846. $lp_view_table = Database :: get_course_table(TABLE_LP_VIEW);
  2847. $sql = "SELECT id, view_count FROM $lp_view_table " .
  2848. "WHERE lp_id = " . $this->get_id() . " " .
  2849. "AND user_id = " . $this->get_user_id() . " " .
  2850. $search .
  2851. " ORDER BY view_count DESC";
  2852. $res = Database::query($sql);
  2853. if (Database :: num_rows($res) > 0) {
  2854. $row = Database :: fetch_array($res);
  2855. $this->lp_view_id = $row['id'];
  2856. } else {
  2857. // There is no database record, create one.
  2858. $sql = "INSERT INTO $lp_view_table(lp_id,user_id,view_count)" .
  2859. "VALUES (" . $this->get_id() . "," . $this->get_user_id() . ",1)";
  2860. $res = Database::query($sql);
  2861. $id = Database :: insert_id();
  2862. $this->lp_view_id = $id;
  2863. }
  2864. return $this->lp_view_id;
  2865. }
  2866. /**
  2867. * Gets the current view id
  2868. * @return integer View ID (from lp_view)
  2869. */
  2870. public function get_view_id() {
  2871. if ($this->debug > 0) {
  2872. error_log('New LP - In learnpath::get_view_id()', 0);
  2873. }
  2874. if (!empty ($this->lp_view_id)) {
  2875. return $this->lp_view_id;
  2876. } else {
  2877. return 0;
  2878. }
  2879. }
  2880. /**
  2881. * Gets the update queue
  2882. * @return array Array containing IDs of items to be updated by JavaScript
  2883. */
  2884. public function get_update_queue() {
  2885. if ($this->debug > 0) {
  2886. error_log('New LP - In learnpath::get_update_queue()', 0);
  2887. }
  2888. return $this->update_queue;
  2889. }
  2890. /**
  2891. * Gets the user ID
  2892. * @return integer User ID
  2893. */
  2894. public function get_user_id() {
  2895. if ($this->debug > 0) {
  2896. error_log('New LP - In learnpath::get_user_id()', 0);
  2897. }
  2898. if (!empty ($this->user_id)) {
  2899. return $this->user_id;
  2900. } else {
  2901. return false;
  2902. }
  2903. }
  2904. /**
  2905. * Checks if any of the items has an audio element attached
  2906. * @return bool True or false
  2907. */
  2908. public function has_audio() {
  2909. if ($this->debug > 1) {
  2910. error_log('New LP - In learnpath::has_audio()', 0);
  2911. }
  2912. $has = false;
  2913. foreach ($this->items as $i => $item) {
  2914. if (!empty ($this->items[$i]->audio)) {
  2915. $has = true;
  2916. break;
  2917. }
  2918. }
  2919. return $has;
  2920. }
  2921. /**
  2922. * Logs a message into a file
  2923. * @param string Message to log
  2924. * @return boolean True on success, false on error or if msg empty
  2925. */
  2926. public function log($msg) {
  2927. if ($this->debug > 0) {
  2928. error_log('New LP - In learnpath::log()', 0);
  2929. }
  2930. // TODO
  2931. $this->error .= $msg;
  2932. return true;
  2933. }
  2934. /**
  2935. * Moves an item up and down at its level
  2936. * @param integer Item to move up and down
  2937. * @param string Direction 'up' or 'down'
  2938. * @return integer New display order, or false on error
  2939. */
  2940. public function move_item($id, $direction) {
  2941. if ($this->debug > 0) {
  2942. error_log('New LP - In learnpath::move_item(' . $id . ',' . $direction . ')', 0);
  2943. }
  2944. if (empty ($id) or empty ($direction)) {
  2945. return false;
  2946. }
  2947. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  2948. $sql_sel = "
  2949. SELECT *
  2950. FROM " . $tbl_lp_item . "
  2951. WHERE id = " . $id;
  2952. $res_sel = Database::query($sql_sel);
  2953. // Check if elem exists.
  2954. if (Database :: num_rows($res_sel) < 1) {
  2955. return false;
  2956. }
  2957. // Gather data.
  2958. $row = Database :: fetch_array($res_sel);
  2959. $previous = $row['previous_item_id'];
  2960. $next = $row['next_item_id'];
  2961. $display = $row['display_order'];
  2962. $parent = $row['parent_item_id'];
  2963. $lp = $row['lp_id'];
  2964. // Update the item (switch with previous/next one).
  2965. switch ($direction) {
  2966. case 'up' :
  2967. if ($this->debug > 2) {
  2968. error_log('Movement up detected', 0);
  2969. }
  2970. if ($display <= 1) { /*do nothing*/
  2971. } else {
  2972. $sql_sel2 = "SELECT *
  2973. FROM $tbl_lp_item
  2974. WHERE id = $previous";
  2975. if ($this->debug > 2) {
  2976. error_log('Selecting previous: ' . $sql_sel2, 0);
  2977. }
  2978. $res_sel2 = Database::query($sql_sel2);
  2979. if (Database :: num_rows($res_sel2) < 1) {
  2980. $previous_previous = 0;
  2981. }
  2982. // Gather data.
  2983. $row2 = Database :: fetch_array($res_sel2);
  2984. $previous_previous = $row2['previous_item_id'];
  2985. // Update previous_previous item (switch "next" with current).
  2986. if ($previous_previous != 0) {
  2987. $sql_upd2 = "UPDATE $tbl_lp_item SET next_item_id = $id WHERE id = $previous_previous";
  2988. if ($this->debug > 2) {
  2989. error_log($sql_upd2, 0);
  2990. }
  2991. $res_upd2 = Database::query($sql_upd2);
  2992. }
  2993. // Update previous item (switch with current).
  2994. if ($previous != 0) {
  2995. $sql_upd2 = "UPDATE $tbl_lp_item SET next_item_id = $next, previous_item_id = $id, display_order = display_order +1 WHERE id = $previous";
  2996. if ($this->debug > 2) {
  2997. error_log($sql_upd2, 0);
  2998. }
  2999. $res_upd2 = Database::query($sql_upd2);
  3000. }
  3001. // Update current item (switch with previous).
  3002. if ($id != 0) {
  3003. $sql_upd2 = "UPDATE $tbl_lp_item SET next_item_id = $previous, previous_item_id = $previous_previous, display_order = display_order-1 WHERE id = $id";
  3004. if ($this->debug > 2) {
  3005. error_log($sql_upd2, 0);
  3006. }
  3007. $res_upd2 = Database::query($sql_upd2);
  3008. }
  3009. // Update next item (new previous item).
  3010. if ($next != 0) {
  3011. $sql_upd2 = "UPDATE $tbl_lp_item SET previous_item_id = $previous WHERE id = $next";
  3012. if ($this->debug > 2) {
  3013. error_log($sql_upd2, 0);
  3014. }
  3015. $res_upd2 = Database::query($sql_upd2);
  3016. }
  3017. $display = $display -1;
  3018. }
  3019. break;
  3020. case 'down' :
  3021. if ($this->debug > 2) {
  3022. error_log('Movement down detected', 0);
  3023. }
  3024. if ($next == 0) { /* Do nothing. */
  3025. } else {
  3026. $sql_sel2 = "SELECT * FROM $tbl_lp_item WHERE id = $next";
  3027. if ($this->debug > 2) {
  3028. error_log('Selecting next: ' . $sql_sel2, 0);
  3029. }
  3030. $res_sel2 = Database::query($sql_sel2);
  3031. if (Database :: num_rows($res_sel2) < 1) {
  3032. $next_next = 0;
  3033. }
  3034. // Gather data.
  3035. $row2 = Database :: fetch_array($res_sel2);
  3036. $next_next = $row2['next_item_id'];
  3037. // Update previous item (switch with current).
  3038. if ($previous != 0) {
  3039. $sql_upd2 = "UPDATE $tbl_lp_item SET next_item_id = $next WHERE id = $previous";
  3040. $res_upd2 = Database::query($sql_upd2);
  3041. }
  3042. // Update current item (switch with previous).
  3043. if ($id != 0) {
  3044. $sql_upd2 = "UPDATE $tbl_lp_item SET previous_item_id = $next, next_item_id = $next_next, display_order = display_order+1 WHERE id = $id";
  3045. $res_upd2 = Database::query($sql_upd2);
  3046. }
  3047. // Update next item (new previous item).
  3048. if ($next != 0) {
  3049. $sql_upd2 = "UPDATE $tbl_lp_item SET previous_item_id = $previous, next_item_id = $id, display_order = display_order-1 WHERE id = $next";
  3050. $res_upd2 = Database::query($sql_upd2);
  3051. }
  3052. // Update next_next item (switch "previous" with current).
  3053. if ($next_next != 0) {
  3054. $sql_upd2 = "UPDATE $tbl_lp_item SET previous_item_id = $id WHERE id = $next_next";
  3055. $res_upd2 = Database::query($sql_upd2);
  3056. }
  3057. $display = $display +1;
  3058. }
  3059. break;
  3060. default :
  3061. return false;
  3062. }
  3063. return $display;
  3064. }
  3065. /**
  3066. * Move a learnpath up (display_order)
  3067. * @param integer Learnpath ID
  3068. */
  3069. public function move_up($lp_id) {
  3070. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3071. $sql = "SELECT * FROM $lp_table ORDER BY display_order";
  3072. $res = Database::query($sql);
  3073. if ($res === false)
  3074. return false;
  3075. $lps = array ();
  3076. $lp_order = array ();
  3077. $num = Database :: num_rows($res);
  3078. // First check the order is correct, globally (might be wrong because
  3079. // of versions < 1.8.4)
  3080. if ($num > 0) {
  3081. $i = 1;
  3082. while ($row = Database :: fetch_array($res)) {
  3083. if ($row['display_order'] != $i) { // If we find a gap in the order, we need to fix it.
  3084. $need_fix = true;
  3085. $sql_u = "UPDATE $lp_table SET display_order = $i WHERE id = " . $row['id'];
  3086. $res_u = Database::query($sql_u);
  3087. }
  3088. $row['display_order'] = $i;
  3089. $lps[$row['id']] = $row;
  3090. $lp_order[$i] = $row['id'];
  3091. $i++;
  3092. }
  3093. }
  3094. if ($num > 1) { // If there's only one element, no need to sort.
  3095. $order = $lps[$lp_id]['display_order'];
  3096. if ($order > 1) { // If it's the first element, no need to move up.
  3097. $sql_u1 = "UPDATE $lp_table SET display_order = $order WHERE id = " . $lp_order[$order - 1];
  3098. $res_u1 = Database::query($sql_u1);
  3099. $sql_u2 = "UPDATE $lp_table SET display_order = " . ($order - 1) . " WHERE id = " . $lp_id;
  3100. $res_u2 = Database::query($sql_u2);
  3101. }
  3102. }
  3103. }
  3104. /**
  3105. * Move a learnpath down (display_order)
  3106. * @param integer Learnpath ID
  3107. */
  3108. public function move_down($lp_id) {
  3109. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3110. $sql = "SELECT * FROM $lp_table ORDER BY display_order";
  3111. $res = Database::query($sql);
  3112. if ($res === false)
  3113. return false;
  3114. $lps = array ();
  3115. $lp_order = array ();
  3116. $num = Database :: num_rows($res);
  3117. $max = 0;
  3118. // First check the order is correct, globally (might be wrong because
  3119. // of versions < 1.8.4).
  3120. if ($num > 0) {
  3121. $i = 1;
  3122. while ($row = Database :: fetch_array($res)) {
  3123. $max = $i;
  3124. if ($row['display_order'] != $i) { // If we find a gap in the order, we need to fix it.
  3125. $need_fix = true;
  3126. $sql_u = "UPDATE $lp_table SET display_order = $i WHERE id = " . $row['id'];
  3127. $res_u = Database::query($sql_u);
  3128. }
  3129. $row['display_order'] = $i;
  3130. $lps[$row['id']] = $row;
  3131. $lp_order[$i] = $row['id'];
  3132. $i++;
  3133. }
  3134. }
  3135. if ($num > 1) { // If there's only one element, no need to sort.
  3136. $order = $lps[$lp_id]['display_order'];
  3137. if ($order < $max) { // If it's the first element, no need to move up.
  3138. $sql_u1 = "UPDATE $lp_table SET display_order = $order WHERE id = " . $lp_order[$order + 1];
  3139. $res_u1 = Database::query($sql_u1);
  3140. $sql_u2 = "UPDATE $lp_table SET display_order = " . ($order + 1) . " WHERE id = " . $lp_id;
  3141. $res_u2 = Database::query($sql_u2);
  3142. }
  3143. }
  3144. }
  3145. /**
  3146. * Updates learnpath attributes to point to the next element
  3147. * The last part is similar to set_current_item but processing the other way around
  3148. */
  3149. public function next() {
  3150. if ($this->debug > 0) {
  3151. error_log('New LP - In learnpath::next()', 0);
  3152. }
  3153. $this->last = $this->get_current_item_id();
  3154. $this->items[$this->last]->save(false, $this->prerequisites_match($this->last));
  3155. $this->autocomplete_parents($this->last);
  3156. $new_index = $this->get_next_index();
  3157. if ($this->debug > 2) {
  3158. error_log('New LP - New index: ' . $new_index, 0);
  3159. }
  3160. $this->index = $new_index;
  3161. if ($this->debug > 2) {
  3162. error_log('New LP - Now having orderedlist[' . $new_index . '] = ' . $this->ordered_items[$new_index], 0);
  3163. }
  3164. $this->current = $this->ordered_items[$new_index];
  3165. if ($this->debug > 2) {
  3166. error_log('New LP - new item id is ' . $this->current . '-' . $this->get_current_item_id(), 0);
  3167. }
  3168. }
  3169. /**
  3170. * Open a resource = initialise all local variables relative to this resource. Depending on the child
  3171. * class, this might be redefined to allow several behaviours depending on the document type.
  3172. * @param integer Resource ID
  3173. * @return boolean True on success, false otherwise
  3174. */
  3175. public function open($id) {
  3176. if ($this->debug > 0) {
  3177. error_log('New LP - In learnpath::open()', 0);
  3178. }
  3179. // TODO:
  3180. // set the current resource attribute to this resource
  3181. // switch on element type (redefine in child class?)
  3182. // set status for this item to "opened"
  3183. // start timer
  3184. // initialise score
  3185. $this->index = 0; //or = the last item seen (see $this->last)
  3186. }
  3187. /**
  3188. * Check that all prerequisites are fulfilled. Returns true and an empty string on succes, returns false
  3189. * and the prerequisite string on error.
  3190. * This function is based on the rules for aicc_script language as described in the SCORM 1.2 CAM documentation page 108.
  3191. * @param integer Optional item ID. If none given, uses the current open item.
  3192. * @return boolean True if prerequisites are matched, false otherwise
  3193. * @return string Empty string if true returned, prerequisites string otherwise.
  3194. */
  3195. public function prerequisites_match($item = null) {
  3196. if ($this->debug > 0) {
  3197. error_log('New LP - In learnpath::prerequisites_match()', 0);
  3198. }
  3199. if (empty ($item)) {
  3200. $item = $this->current;
  3201. }
  3202. if (is_object($this->items[$item])) {
  3203. $prereq_string = $this->items[$item]->get_prereq_string();
  3204. if (empty ($prereq_string)) {
  3205. return true;
  3206. }
  3207. // Clean spaces.
  3208. $prereq_string = str_replace(' ', '', $prereq_string);
  3209. if ($this->debug > 0) {
  3210. error_log('Found prereq_string: ' . $prereq_string, 0);
  3211. }
  3212. // Now send to the parse_prereq() function that will check this component's prerequisites.
  3213. $result = $this->items[$item]->parse_prereq($prereq_string, $this->items, $this->refs_list, $this->get_user_id());
  3214. if ($result === false) {
  3215. $this->set_error_msg($this->items[$item]->prereq_alert);
  3216. }
  3217. } else {
  3218. $result = true;
  3219. if ($this->debug > 1) {
  3220. error_log('New LP - $this->items[' . $item . '] was not an object', 0);
  3221. }
  3222. }
  3223. if ($this->debug > 1) {
  3224. error_log('New LP - End of prerequisites_match(). Error message is now ' . $this->error, 0);
  3225. }
  3226. return $result;
  3227. }
  3228. /**
  3229. * Updates learnpath attributes to point to the previous element
  3230. * The last part is similar to set_current_item but processing the other way around
  3231. */
  3232. public function previous() {
  3233. if ($this->debug > 0) {
  3234. error_log('New LP - In learnpath::previous()', 0);
  3235. }
  3236. $this->last = $this->get_current_item_id();
  3237. $this->items[$this->last]->save(false, $this->prerequisites_match($this->last));
  3238. $this->autocomplete_parents($this->last);
  3239. $new_index = $this->get_previous_index();
  3240. $this->index = $new_index;
  3241. $this->current = $this->ordered_items[$new_index];
  3242. }
  3243. /**
  3244. * Publishes a learnpath. This basically means show or hide the learnpath
  3245. * to normal users.
  3246. * Can be used as abstract
  3247. * @param integer Learnpath ID
  3248. * @param string New visibility
  3249. */
  3250. public function toggle_visibility($lp_id, $set_visibility = 1) {
  3251. //if ($this->debug > 0) { error_log('New LP - In learnpath::toggle_visibility()', 0); }
  3252. $action = 'visible';
  3253. if ($set_visibility != 1) {
  3254. $action = 'invisible';
  3255. }
  3256. return api_item_property_update(api_get_course_info(), TOOL_LEARNPATH, $lp_id, $action, api_get_user_id());
  3257. }
  3258. /**
  3259. * Publishes a learnpath. This basically means show or hide the learnpath
  3260. * on the course homepage
  3261. * Can be used as abstract
  3262. * @param integer Learnpath id
  3263. * @param string New visibility (v/s - visible/invisible)
  3264. */
  3265. public function toggle_publish($lp_id, $set_visibility = 'v') {
  3266. //if ($this->debug > 0) { error_log('New LP - In learnpath::toggle_publish()', 0); }
  3267. $tbl_lp = Database :: get_course_table(TABLE_LP_MAIN);
  3268. $sql = "SELECT * FROM $tbl_lp where id=$lp_id";
  3269. $result = Database::query($sql);
  3270. $row = Database :: fetch_array($result);
  3271. $name = domesticate($row['name']);
  3272. if ($set_visibility == 'i') {
  3273. $s = $name . " " . get_lang('_no_published');
  3274. $dialogBox = $s;
  3275. $v = 0;
  3276. }
  3277. if ($set_visibility == 'v') {
  3278. $s = $name . " " . get_lang('_published');
  3279. $dialogBox = $s;
  3280. $v = 1;
  3281. }
  3282. $session_id = api_get_session_id();
  3283. $session_condition = api_get_session_condition($session_id);
  3284. $tbl_tool = Database :: get_course_table(TABLE_TOOL_LIST);
  3285. $link = 'newscorm/lp_controller.php?action=view&lp_id=' . $lp_id.'&id_session='.$session_id;
  3286. $sql = "SELECT * FROM $tbl_tool where name='$name' and image='scormbuilder.gif' and link LIKE '$link%' $session_condition";
  3287. $result = Database::query($sql);
  3288. $num = Database :: num_rows($result);
  3289. $row2 = Database :: fetch_array($result);
  3290. //if ($this->debug > 2) { error_log('New LP - '.$sql.' - '.$num, 0); }
  3291. if (($set_visibility == 'i') && ($num > 0)) {
  3292. $sql = "DELETE FROM $tbl_tool WHERE (name='$name' and image='scormbuilder.gif' and link LIKE '$link%' $session_condition)";
  3293. } elseif (($set_visibility == 'v') && ($num == 0)) {
  3294. $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)";
  3295. } else {
  3296. // Parameter and database incompatible, do nothing.
  3297. }
  3298. $result = Database::query($sql);
  3299. //if ($this->debug > 2) { error_log('New LP - Leaving learnpath::toggle_visibility: '.$sql, 0); }
  3300. }
  3301. /**
  3302. * Restart the whole learnpath. Return the URL of the first element.
  3303. * Make sure the results are saved with anoter method. This method should probably be
  3304. * redefined in children classes.
  3305. * To use a similar method statically, use the create_new_attempt() method
  3306. * @return string URL to load in the viewer
  3307. */
  3308. public function restart() {
  3309. if ($this->debug > 0) {
  3310. error_log('New LP - In learnpath::restart()', 0);
  3311. }
  3312. // TODO
  3313. // Call autosave method to save the current progress.
  3314. //$this->index = 0;
  3315. $session_id = api_get_session_id();
  3316. $lp_view_table = Database :: get_course_table(TABLE_LP_VIEW);
  3317. $sql = "INSERT INTO $lp_view_table (lp_id, user_id, view_count, session_id) " .
  3318. "VALUES (" . $this->lp_id . "," . $this->get_user_id() . "," . ($this->attempt + 1) . ", $session_id)";
  3319. if ($this->debug > 2) {
  3320. error_log('New LP - Inserting new lp_view for restart: ' . $sql, 0);
  3321. }
  3322. $res = Database::query($sql);
  3323. if ($view_id = Database :: insert_id($res)) {
  3324. $this->lp_view_id = $view_id;
  3325. $this->attempt = $this->attempt + 1;
  3326. } else {
  3327. $this->error = 'Could not insert into item_view table...';
  3328. return false;
  3329. }
  3330. $this->autocomplete_parents($this->current);
  3331. foreach ($this->items as $index => $dummy) {
  3332. $this->items[$index]->restart();
  3333. $this->items[$index]->set_lp_view($this->lp_view_id);
  3334. }
  3335. $this->first();
  3336. return true;
  3337. }
  3338. /**
  3339. * Saves the current item
  3340. * @return boolean
  3341. */
  3342. public function save_current() {
  3343. if ($this->debug > 0) {
  3344. error_log('New LP - In learnpath::save_current()', 0);
  3345. }
  3346. // TODO: Do a better check on the index pointing to the right item (it is supposed to be working
  3347. // on $ordered_items[] but not sure it's always safe to use with $items[]).
  3348. if ($this->debug > 2) {
  3349. error_log('New LP - save_current() saving item ' . $this->current, 0);
  3350. }
  3351. if ($this->debug > 2) {
  3352. error_log('' . print_r($this->items, true), 0);
  3353. }
  3354. if (is_object($this->items[$this->current])) {
  3355. //$res = $this->items[$this->current]->save(false);
  3356. $res = $this->items[$this->current]->save(false, $this->prerequisites_match($this->current));
  3357. $this->autocomplete_parents($this->current);
  3358. $status = $this->items[$this->current]->get_status();
  3359. $this->append_message('new_item_status: ' . $status);
  3360. $this->update_queue[$this->current] = $status;
  3361. return $res;
  3362. }
  3363. return false;
  3364. }
  3365. /**
  3366. * Saves the given item
  3367. * @param integer Item ID. Optional (will take from $_REQUEST if null)
  3368. * @param boolean Save from url params (true) or from current attributes (false). Optional. Defaults to true
  3369. * @return boolean
  3370. */
  3371. public function save_item($item_id = null, $from_outside = true) {
  3372. if ($this->debug > 0) {
  3373. error_log('New LP - In learnpath::save_item(' . $item_id . ',' . $from_outside . ')', 0);
  3374. }
  3375. // TODO: Do a better check on the index pointing to the right item (it is supposed to be working
  3376. // on $ordered_items[] but not sure it's always safe to use with $items[]).
  3377. if (empty ($item_id)) {
  3378. $item_id = $this->escape_string($_REQUEST['id']);
  3379. }
  3380. if (empty ($item_id)) {
  3381. $item_id = $this->get_current_item_id();
  3382. }
  3383. if ($this->debug > 2) {
  3384. error_log('New LP - save_current() saving item ' . $item_id, 0);
  3385. }
  3386. if (is_object($this->items[$item_id])) {
  3387. $res = $this->items[$item_id]->save($from_outside, $this->prerequisites_match($item_id));
  3388. //$res = $this->items[$item_id]->save($from_outside);
  3389. $this->autocomplete_parents($item_id);
  3390. $status = $this->items[$item_id]->get_status();
  3391. $this->append_message('new_item_status: ' . $status);
  3392. $this->update_queue[$item_id] = $status;
  3393. return $res;
  3394. }
  3395. return false;
  3396. }
  3397. /**
  3398. * Saves the last item seen's ID only in case
  3399. */
  3400. public function save_last() {
  3401. if ($this->debug > 0) {
  3402. error_log('New LP - In learnpath::save_last()', 0);
  3403. }
  3404. $session_condition = api_get_session_condition(api_get_session_id(), true, false);
  3405. $table = Database :: get_course_table(TABLE_LP_VIEW);
  3406. if (isset ($this->current)) {
  3407. if ($this->debug > 2) {
  3408. error_log('New LP - Saving current item (' . $this->current . ') for later review', 0);
  3409. }
  3410. $sql = "UPDATE $table SET last_item = " . Database::escape_string($this->get_current_item_id()). " " .
  3411. "WHERE lp_id = " . $this->get_id() . " AND user_id = " . $this->get_user_id().' '.$session_condition;
  3412. if ($this->debug > 2) {
  3413. error_log('New LP - Saving last item seen : ' . $sql, 0);
  3414. }
  3415. $res = Database::query($sql);
  3416. }
  3417. // Save progress.
  3418. list($progress, $text) = $this->get_progress_bar_text('%');
  3419. if ($progress >= 0 && $progress <= 100) {
  3420. $progress = (int) $progress;
  3421. $sql = "UPDATE $table SET progress = $progress " .
  3422. "WHERE lp_id = " . $this->get_id() . " AND " .
  3423. "user_id = " . $this->get_user_id().' '.$session_condition;
  3424. $res = Database::query($sql); // Ignore errors as some tables might not have the progress field just yet.
  3425. $this->progress_db = $progress;
  3426. }
  3427. }
  3428. /**
  3429. * Sets the current item ID (checks if valid and authorized first)
  3430. * @param integer New item ID. If not given or not authorized, defaults to current
  3431. */
  3432. public function set_current_item($item_id = null) {
  3433. if ($this->debug > 0) {
  3434. error_log('New LP - In learnpath::set_current_item(' . $item_id . ')', 0);
  3435. }
  3436. if (empty ($item_id)) {
  3437. if ($this->debug > 2) {
  3438. error_log('New LP - No new current item given, ignore...', 0);
  3439. }
  3440. // Do nothing.
  3441. } else {
  3442. if ($this->debug > 2) {
  3443. error_log('New LP - New current item given is ' . $item_id . '...', 0);
  3444. }
  3445. if (is_numeric($item_id)) {
  3446. $item_id = $this->escape_string($item_id);
  3447. // TODO: Check in database here.
  3448. $this->last = $this->current;
  3449. $this->current = $item_id;
  3450. // TODO: Update $this->index as well.
  3451. foreach ($this->ordered_items as $index => $item) {
  3452. if ($item == $this->current) {
  3453. $this->index = $index;
  3454. break;
  3455. }
  3456. }
  3457. if ($this->debug > 2) {
  3458. error_log('New LP - set_current_item(' . $item_id . ') done. Index is now : ' . $this->index, 0);
  3459. }
  3460. } else {
  3461. error_log('New LP - set_current_item(' . $item_id . ') failed. Not a numeric value: ', 0);
  3462. }
  3463. }
  3464. }
  3465. /**
  3466. * Sets the encoding
  3467. * @param string New encoding
  3468. * TODO (as of Chamilo 1.8.8): Check in the future whether this method is needed.
  3469. */
  3470. public function set_encoding($enc = 'UTF-8') {
  3471. if ($this->debug > 0) {
  3472. error_log('New LP - In learnpath::set_encoding()', 0);
  3473. }
  3474. /* // Deprecated code (Chamilo 1.8.8).
  3475. $enc = strtoupper($enc);
  3476. $encodings = array (
  3477. 'UTF-8',
  3478. 'ISO-8859-1',
  3479. 'ISO-8859-15',
  3480. 'cp1251',
  3481. 'cp1252',
  3482. 'KOI8-R',
  3483. 'BIG5',
  3484. 'GB2312',
  3485. 'Shift_JIS',
  3486. 'EUC-JP',
  3487. ''
  3488. );
  3489. if (in_array($enc, $encodings)) { // TODO: Incorrect comparison, fix it.
  3490. $lp = $this->get_id();
  3491. if ($lp != 0) {
  3492. $tbl_lp = Database :: get_course_table(TABLE_LP_MAIN);
  3493. $sql = "UPDATE $tbl_lp SET default_encoding = '$enc' WHERE id = " . $lp;
  3494. $res = Database::query($sql);
  3495. return $res;
  3496. }
  3497. }
  3498. return false;
  3499. */
  3500. $enc = api_refine_encoding_id($enc);
  3501. if (empty($enc)) {
  3502. $enc = api_get_system_encoding();
  3503. }
  3504. if (api_is_encoding_supported($enc)) {
  3505. $lp = $this->get_id();
  3506. if ($lp != 0) {
  3507. $tbl_lp = Database :: get_course_table(TABLE_LP_MAIN);
  3508. $sql = "UPDATE $tbl_lp SET default_encoding = '$enc' WHERE id = " . $lp;
  3509. $res = Database::query($sql);
  3510. return $res;
  3511. }
  3512. }
  3513. return false;
  3514. }
  3515. /**
  3516. * Sets the JS lib setting in the database directly.
  3517. * This is the JavaScript library file this lp needs to load on startup
  3518. * @param string Proximity setting
  3519. * @return boolean True on update success. False otherwise.
  3520. */
  3521. public function set_jslib($lib = '') {
  3522. if ($this->debug > 0) {
  3523. error_log('New LP - In learnpath::set_jslib()', 0);
  3524. }
  3525. $lp = $this->get_id();
  3526. if ($lp != 0) {
  3527. $tbl_lp = Database :: get_course_table(TABLE_LP_MAIN);
  3528. $sql = "UPDATE $tbl_lp SET js_lib = '$lib' WHERE id = " . $lp;
  3529. $res = Database::query($sql);
  3530. return $res;
  3531. } else {
  3532. return false;
  3533. }
  3534. }
  3535. /**
  3536. * Sets the name of the LP maker (publisher) (and save)
  3537. * @param string Optional string giving the new content_maker of this learnpath
  3538. * @return boolean True
  3539. */
  3540. public function set_maker($name = '') {
  3541. if ($this->debug > 0) {
  3542. error_log('New LP - In learnpath::set_maker()', 0);
  3543. }
  3544. if (empty ($name))
  3545. return false;
  3546. $this->maker = $this->escape_string($name);
  3547. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3548. $lp_id = $this->get_id();
  3549. $sql = "UPDATE $lp_table SET content_maker = '" . $this->maker . "' WHERE id = '$lp_id'";
  3550. if ($this->debug > 2) {
  3551. error_log('New LP - lp updated with new content_maker : ' . $this->maker, 0);
  3552. }
  3553. $res = Database::query($sql);
  3554. return true;
  3555. }
  3556. /**
  3557. * Sets the name of the current learnpath (and save)
  3558. * @param string Optional string giving the new name of this learnpath
  3559. * @return boolean True/False
  3560. */
  3561. public function set_name($name = '') {
  3562. if ($this->debug > 0) {
  3563. error_log('New LP - In learnpath::set_name()', 0);
  3564. }
  3565. if (empty ($name))
  3566. return false;
  3567. $this->name = $this->escape_string($name);
  3568. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3569. $lp_id = $this->get_id();
  3570. $sql = "UPDATE $lp_table SET name = '" . $this->name . "' WHERE id = '$lp_id'";
  3571. if ($this->debug > 2) {
  3572. error_log('New LP - lp updated with new name : ' . $this->name, 0);
  3573. }
  3574. $res = Database::query($sql);
  3575. // If the lp is visible on the homepage, change his name there.
  3576. if (Database::affected_rows()) {
  3577. $table = Database :: get_course_table(TABLE_TOOL_LIST);
  3578. $sql = 'UPDATE ' . $table . ' SET
  3579. name = "' . $this->name . '"
  3580. WHERE link = "newscorm/lp_controller.php?action=view&lp_id=' . $lp_id . '"';
  3581. Database::query($sql);
  3582. }
  3583. return true;
  3584. }
  3585. /**
  3586. * Set index specified prefix terms for all items in this path
  3587. * @param string Comma-separated list of terms
  3588. * @param char Xapian term prefix
  3589. * @return boolean False on error, true otherwise
  3590. */
  3591. public function set_terms_by_prefix($terms_string, $prefix) {
  3592. if (api_get_setting('search_enabled') !== 'true')
  3593. return false;
  3594. if (!extension_loaded('xapian')) {
  3595. return false;
  3596. }
  3597. $terms_string = trim($terms_string);
  3598. $terms = explode(',', $terms_string);
  3599. array_walk($terms, 'trim_value');
  3600. $stored_terms = $this->get_common_index_terms_by_prefix($prefix);
  3601. //var_dump($stored_terms);
  3602. //var_dump($terms);
  3603. // Don't do anything if no change, verify only at DB, not the search engine.
  3604. if ((count(array_diff($terms, $stored_terms)) == 0) && (count(array_diff($stored_terms, $terms)) == 0))
  3605. return false;
  3606. require_once 'xapian.php'; // TODO: Try catch every xapian use or make wrappers on API.
  3607. require_once api_get_path(LIBRARY_PATH).'search/DokeosIndexer.class.php';
  3608. require_once api_get_path(LIBRARY_PATH).'search/xapian/XapianQuery.php';
  3609. require_once api_get_path(LIBRARY_PATH).'search/IndexableChunk.class.php';
  3610. $items_table = Database :: get_course_table(TABLE_LP_ITEM);
  3611. // TODO: Make query secure agains XSS : use member attr instead of post var.
  3612. $lp_id = intval($_POST['lp_id']);
  3613. $sql = "SELECT * FROM $items_table WHERE lp_id = $lp_id";
  3614. $result = Database::query($sql);
  3615. $di = new DokeosIndexer();
  3616. while ($lp_item = Database :: fetch_array($result)) {
  3617. // Get search_did.
  3618. $tbl_se_ref = Database :: get_main_table(TABLE_MAIN_SEARCH_ENGINE_REF);
  3619. $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';
  3620. $sql = sprintf($sql, $tbl_se_ref, $this->cc, TOOL_LEARNPATH, $lp_id, $lp_item['id']);
  3621. //echo $sql; echo '<br>';
  3622. $res = Database::query($sql);
  3623. if (Database::num_rows($res) > 0) {
  3624. $se_ref = Database :: fetch_array($res);
  3625. // Compare terms.
  3626. $doc = $di->get_document($se_ref['search_did']);
  3627. $xapian_terms = xapian_get_doc_terms($doc, $prefix);
  3628. $xterms = array ();
  3629. foreach ($xapian_terms as $xapian_term) {
  3630. $xterms[] = substr($xapian_term['name'], 1);
  3631. }
  3632. $dterms = $terms;
  3633. $missing_terms = array_diff($dterms, $xterms);
  3634. $deprecated_terms = array_diff($xterms, $dterms);
  3635. // Save it to search engine.
  3636. foreach ($missing_terms as $term) {
  3637. $doc->add_term($prefix . $term, 1);
  3638. }
  3639. foreach ($deprecated_terms as $term) {
  3640. $doc->remove_term($prefix . $term);
  3641. }
  3642. $di->getDb()->replace_document((int) $se_ref['search_did'], $doc);
  3643. $di->getDb()->flush();
  3644. } else {
  3645. //@todo What we should do here?
  3646. }
  3647. }
  3648. return true;
  3649. }
  3650. /**
  3651. * Sets the theme of the LP (local/remote) (and save)
  3652. * @param string Optional string giving the new theme of this learnpath
  3653. * @return bool Returns true if theme name is not empty
  3654. */
  3655. public function set_theme($name = '') {
  3656. if ($this->debug > 0) {
  3657. error_log('New LP - In learnpath::set_theme()', 0);
  3658. }
  3659. $this->theme = $this->escape_string($name);
  3660. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3661. $lp_id = $this->get_id();
  3662. $sql = "UPDATE $lp_table SET theme = '" . $this->theme . "' WHERE id = '$lp_id'";
  3663. if ($this->debug > 2) {
  3664. error_log('New LP - lp updated with new theme : ' . $this->theme, 0);
  3665. }
  3666. //$res = Database::query($sql);
  3667. $res = Database::query($sql);
  3668. return true;
  3669. }
  3670. /**
  3671. * Sets the image of an LP (and save)
  3672. * @param string Optional string giving the new image of this learnpath
  3673. * @return bool Returns true if theme name is not empty
  3674. */
  3675. public function set_preview_image($name = '') {
  3676. if ($this->debug > 0) {
  3677. error_log('New LP - In learnpath::set_preview_image()', 0);
  3678. }
  3679. $this->preview_image = $this->escape_string($name);
  3680. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3681. $lp_id = $this->get_id();
  3682. $sql = "UPDATE $lp_table SET preview_image = '" . $this->preview_image . "' WHERE id = '$lp_id'";
  3683. if ($this->debug > 2) {
  3684. error_log('New LP - lp updated with new preview image : ' . $this->preview_image, 0);
  3685. }
  3686. $res = Database::query($sql);
  3687. return true;
  3688. }
  3689. /**
  3690. * Sets the author of a LP (and save)
  3691. * @param string Optional string giving the new author of this learnpath
  3692. * @return bool Returns true if author's name is not empty
  3693. */
  3694. public function set_author($name = '') {
  3695. if ($this->debug > 0) {
  3696. error_log('New LP - In learnpath::set_author()', 0);
  3697. }
  3698. $this->author = $this->escape_string($name);
  3699. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3700. $lp_id = $this->get_id();
  3701. $sql = "UPDATE $lp_table SET author = '" . $this->author . "' WHERE id = '$lp_id'";
  3702. if ($this->debug > 2) {
  3703. error_log('New LP - lp updated with new preview author : ' . $this->author, 0);
  3704. }
  3705. $res = Database::query($sql);
  3706. return true;
  3707. }
  3708. /**
  3709. * Sets the prerequisite of a LP (and save)
  3710. * @param int integer giving the new prerequisite of this learnpath
  3711. * @return bool returns true if prerequisite is not empty
  3712. */
  3713. public function set_prerequisite($prerequisite) {
  3714. if ($this->debug > 0) {
  3715. error_log('New LP - In learnpath::set_prerequisite()', 0);
  3716. }
  3717. $this->prerequisite = intval($prerequisite);
  3718. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3719. $lp_id = $this->get_id();
  3720. $sql = "UPDATE $lp_table SET prerequisite = '".$this->prerequisite."' WHERE id = '$lp_id'";
  3721. if ($this->debug > 2) {
  3722. error_log('New LP - lp updated with new preview requisite : ' . $this->requisite, 0);
  3723. }
  3724. $res = Database::query($sql);
  3725. return true;
  3726. }
  3727. /**
  3728. * Sets the location/proximity of the LP (local/remote) (and save)
  3729. * @param string Optional string giving the new location of this learnpath
  3730. * @return boolean True on success / False on error
  3731. */
  3732. public function set_proximity($name = '') {
  3733. if ($this->debug > 0) {
  3734. error_log('New LP - In learnpath::set_proximity()', 0);
  3735. }
  3736. if (empty ($name))
  3737. return false;
  3738. $this->proximity = $this->escape_string($name);
  3739. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3740. $lp_id = $this->get_id();
  3741. $sql = "UPDATE $lp_table SET content_local = '" . $this->proximity . "' WHERE id = '$lp_id'";
  3742. if ($this->debug > 2) {
  3743. error_log('New LP - lp updated with new proximity : ' . $this->proximity, 0);
  3744. }
  3745. $res = Database::query($sql);
  3746. return true;
  3747. }
  3748. /**
  3749. * Sets the previous item ID to a given ID. Generally, this should be set to the previous 'current' item
  3750. * @param integer DB ID of the item
  3751. */
  3752. public function set_previous_item($id) {
  3753. if ($this->debug > 0) {
  3754. error_log('New LP - In learnpath::set_previous_item()', 0);
  3755. }
  3756. $this->last = $id;
  3757. }
  3758. /**
  3759. * Sets use_max_score
  3760. * @param string Optional string giving the new location of this learnpath
  3761. * @return boolean True on success / False on error
  3762. */
  3763. public function set_use_max_score($use_max_score = 1) {
  3764. if ($this->debug > 0) {
  3765. error_log('New LP - In learnpath::set_use_max_score()', 0);
  3766. }
  3767. $use_max_score = intval($use_max_score);
  3768. $this->use_max_score = $use_max_score;
  3769. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3770. $lp_id = $this->get_id();
  3771. $sql = "UPDATE $lp_table SET use_max_score = '" . $this->use_max_score . "' WHERE id = '$lp_id'";
  3772. if ($this->debug > 2) {
  3773. error_log('New LP - lp updated with new use_max_score : ' . $this->use_max_score, 0);
  3774. }
  3775. $res = Database::query($sql);
  3776. return true;
  3777. }
  3778. /**
  3779. * Sets and saves the expired_on date
  3780. * @param string Optional string giving the new author of this learnpath
  3781. * @return bool Returns true if author's name is not empty
  3782. */
  3783. public function set_expired_on($expired_on) {
  3784. if ($this->debug > 0) {
  3785. error_log('New LP - In learnpath::set_expired_on()', 0);
  3786. }
  3787. if (!empty($expired_on)) {
  3788. $this->expired_on = $this->escape_string(api_get_utc_datetime($expired_on));
  3789. } else {
  3790. $this->expired_on = '';
  3791. }
  3792. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3793. $lp_id = $this->get_id();
  3794. $sql = "UPDATE $lp_table SET expired_on = '" . $this->expired_on . "' WHERE id = '$lp_id'";
  3795. if ($this->debug > 2) {
  3796. error_log('New LP - lp updated with new expired_on : ' . $this->expired_on, 0);
  3797. }
  3798. $res = Database::query($sql);
  3799. return true;
  3800. }
  3801. /**
  3802. * Sets and saves the publicated_on date
  3803. * @param string Optional string giving the new author of this learnpath
  3804. * @return bool Returns true if author's name is not empty
  3805. */
  3806. public function set_publicated_on($publicated_on) {
  3807. if ($this->debug > 0) {
  3808. error_log('New LP - In learnpath::set_expired_on()', 0);
  3809. }
  3810. if (!empty($publicated_on)) {
  3811. $this->publicated_on = $this->escape_string(api_get_utc_datetime($publicated_on));
  3812. } else {
  3813. $this->publicated_on = '';
  3814. }
  3815. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3816. $lp_id = $this->get_id();
  3817. $sql = "UPDATE $lp_table SET publicated_on = '" . $this->publicated_on . "' WHERE id = '$lp_id'";
  3818. if ($this->debug > 2) {
  3819. error_log('New LP - lp updated with new publicated_on : ' . $this->publicated_on, 0);
  3820. }
  3821. $res = Database::query($sql);
  3822. return true;
  3823. }
  3824. /**
  3825. * Sets and saves the expired_on date
  3826. * @param string Optional string giving the new author of this learnpath
  3827. * @return bool Returns true if author's name is not empty
  3828. */
  3829. public function set_modified_on() {
  3830. if ($this->debug > 0) {
  3831. error_log('New LP - In learnpath::set_expired_on()', 0);
  3832. }
  3833. $this->modified_on = api_get_utc_datetime();
  3834. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3835. $lp_id = $this->get_id();
  3836. $sql = "UPDATE $lp_table SET modified_on = '" . $this->modified_on . "' WHERE id = '$lp_id'";
  3837. if ($this->debug > 2) {
  3838. error_log('New LP - lp updated with new expired_on : ' . $this->modified_on, 0);
  3839. }
  3840. $res = Database::query($sql);
  3841. return true;
  3842. }
  3843. /**
  3844. * Sets the object's error message
  3845. * @param string Error message. If empty, reinits the error string
  3846. * @return void
  3847. */
  3848. public function set_error_msg($error = '') {
  3849. if ($this->debug > 0) {
  3850. error_log('New LP - In learnpath::set_error_msg()', 0);
  3851. }
  3852. if (empty ($error)) {
  3853. $this->error = '';
  3854. } else {
  3855. $this->error .= $error;
  3856. }
  3857. }
  3858. /**
  3859. * Launches the current item if not 'sco' (starts timer and make sure there is a record ready in the DB)
  3860. * @param boolean Whether to allow a new attempt or not
  3861. * @return boolean True
  3862. */
  3863. public function start_current_item($allow_new_attempt = false) {
  3864. if ($this->debug > 0) {
  3865. error_log('New LP - In learnpath::start_current_item()', 0);
  3866. }
  3867. if ($this->current != 0 AND is_object($this->items[$this->current])) {
  3868. $type = $this->get_type();
  3869. $item_type = $this->items[$this->current]->get_type();
  3870. if (($type == 2 && $item_type != 'sco') OR ($type == 3 && $item_type != 'au') OR ($type == 1 && $item_type != TOOL_QUIZ && $item_type != TOOL_HOTPOTATOES)) {
  3871. $this->items[$this->current]->open($allow_new_attempt);
  3872. $this->autocomplete_parents($this->current);
  3873. $prereq_check = $this->prerequisites_match($this->current);
  3874. $this->items[$this->current]->save(false, $prereq_check);
  3875. //$this->update_queue[$this->last] = $this->items[$this->last]->get_status();
  3876. } else {
  3877. // If sco, then it is supposed to have been updated by some other call.
  3878. }
  3879. if ($item_type == 'sco') {
  3880. $this->items[$this->current]->restart();
  3881. }
  3882. }
  3883. if ($this->debug > 0) {
  3884. error_log('New LP - End of learnpath::start_current_item()', 0);
  3885. }
  3886. return true;
  3887. }
  3888. /**
  3889. * Stops the processing and counters for the old item (as held in $this->last)
  3890. * @return boolean True/False
  3891. */
  3892. public function stop_previous_item() {
  3893. if ($this->debug > 0) {
  3894. error_log('New LP - In learnpath::stop_previous_item()', 0);
  3895. }
  3896. if ($this->last != 0 && $this->last != $this->current && is_object($this->items[$this->last])) {
  3897. if ($this->debug > 2) {
  3898. error_log('New LP - In learnpath::stop_previous_item() - ' . $this->last . ' is object', 0);
  3899. }
  3900. switch ($this->get_type()) {
  3901. case '3' :
  3902. if ($this->items[$this->last]->get_type() != 'au') {
  3903. if ($this->debug > 2) {
  3904. error_log('New LP - In learnpath::stop_previous_item() - ' . $this->last . ' in lp_type 3 is <> au', 0);
  3905. }
  3906. $this->items[$this->last]->close();
  3907. //$this->autocomplete_parents($this->last);
  3908. //$this->update_queue[$this->last] = $this->items[$this->last]->get_status();
  3909. } else {
  3910. if ($this->debug > 2) {
  3911. error_log('New LP - In learnpath::stop_previous_item() - Item is an AU, saving is managed by AICC signals', 0);
  3912. }
  3913. }
  3914. case '2' :
  3915. if ($this->items[$this->last]->get_type() != 'sco') {
  3916. if ($this->debug > 2) {
  3917. error_log('New LP - In learnpath::stop_previous_item() - ' . $this->last . ' in lp_type 2 is <> sco', 0);
  3918. }
  3919. $this->items[$this->last]->close();
  3920. //$this->autocomplete_parents($this->last);
  3921. //$this->update_queue[$this->last] = $this->items[$this->last]->get_status();
  3922. } else {
  3923. if ($this->debug > 2) {
  3924. error_log('New LP - In learnpath::stop_previous_item() - Item is a SCO, saving is managed by SCO signals', 0);
  3925. }
  3926. }
  3927. break;
  3928. case '1' :
  3929. default :
  3930. if ($this->debug > 2) {
  3931. error_log('New LP - In learnpath::stop_previous_item() - ' . $this->last . ' in lp_type 1 is asset', 0);
  3932. }
  3933. $this->items[$this->last]->close();
  3934. break;
  3935. }
  3936. } else {
  3937. if ($this->debug > 2) {
  3938. error_log('New LP - In learnpath::stop_previous_item() - No previous element found, ignoring...', 0);
  3939. }
  3940. return false;
  3941. }
  3942. return true;
  3943. }
  3944. /**
  3945. * Updates the default view mode from fullscreen to embedded and inversely
  3946. * @return string The current default view mode ('fullscreen' or 'embedded')
  3947. */
  3948. public function update_default_view_mode() {
  3949. if ($this->debug > 0) {
  3950. error_log('New LP - In learnpath::update_default_view_mode()', 0);
  3951. }
  3952. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3953. $sql = "SELECT * FROM $lp_table WHERE id = " . $this->get_id();
  3954. $res = Database::query($sql);
  3955. if (Database :: num_rows($res) > 0) {
  3956. $row = Database :: fetch_array($res);
  3957. $view_mode = $row['default_view_mod'];
  3958. if ($view_mode == 'fullscreen') {
  3959. $view_mode = 'embedded';
  3960. } elseif ($view_mode == 'embedded') {
  3961. $view_mode = 'embedframe';
  3962. } elseif ($view_mode == 'embedframe') {
  3963. $view_mode = 'fullscreen';
  3964. }
  3965. $sql = "UPDATE $lp_table SET default_view_mod = '$view_mode' WHERE id = " . $this->get_id();
  3966. $res = Database::query($sql);
  3967. $this->mode = $view_mode;
  3968. return $view_mode;
  3969. } else {
  3970. if ($this->debug > 2) {
  3971. error_log('New LP - Problem in update_default_view() - could not find LP ' . $this->get_id() . ' in DB', 0);
  3972. }
  3973. }
  3974. return -1;
  3975. }
  3976. /**
  3977. * Updates the default behaviour about auto-commiting SCORM updates
  3978. * @return boolean True if auto-commit has been set to 'on', false otherwise
  3979. */
  3980. public function update_default_scorm_commit() {
  3981. if ($this->debug > 0) {
  3982. error_log('New LP - In learnpath::update_default_scorm_commit()', 0);
  3983. }
  3984. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3985. $sql = "SELECT * FROM $lp_table WHERE id = " . $this->get_id();
  3986. $res = Database::query($sql);
  3987. if (Database :: num_rows($res) > 0) {
  3988. $row = Database :: fetch_array($res);
  3989. $force = $row['force_commit'];
  3990. if ($force == 1) {
  3991. $force = 0;
  3992. $force_return = false;
  3993. } elseif ($force == 0) {
  3994. $force = 1;
  3995. $force_return = true;
  3996. }
  3997. $sql = "UPDATE $lp_table SET force_commit = $force WHERE id = " . $this->get_id();
  3998. $res = Database::query($sql);
  3999. $this->force_commit = $force_return;
  4000. return $force_return;
  4001. } else {
  4002. if ($this->debug > 2) {
  4003. error_log('New LP - Problem in update_default_scorm_commit() - could not find LP ' . $this->get_id() . ' in DB', 0);
  4004. }
  4005. }
  4006. return -1;
  4007. }
  4008. /**
  4009. * Updates the order of learning paths (goes through all of them by order and fills the gaps)
  4010. * @return bool True on success, false on failure
  4011. */
  4012. public function update_display_order() {
  4013. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  4014. $sql = "SELECT * FROM $lp_table ORDER BY display_order";
  4015. $res = Database::query($sql);
  4016. if ($res === false)
  4017. return false;
  4018. $lps = array ();
  4019. $lp_order = array ();
  4020. $num = Database :: num_rows($res);
  4021. // First check the order is correct, globally (might be wrong because
  4022. // of versions < 1.8.4).
  4023. if ($num > 0) {
  4024. $i = 1;
  4025. while ($row = Database :: fetch_array($res)) {
  4026. if ($row['display_order'] != $i) { // If we find a gap in the order, we need to fix it.
  4027. $need_fix = true;
  4028. $sql_u = "UPDATE $lp_table SET display_order = $i WHERE id = " . $row['id'];
  4029. $res_u = Database::query($sql_u);
  4030. }
  4031. $i++;
  4032. }
  4033. }
  4034. return true;
  4035. }
  4036. /**
  4037. * Updates the "prevent_reinit" value that enables control on reinitialising items on second view
  4038. * @return boolean True if prevent_reinit has been set to 'on', false otherwise (or 1 or 0 in this case)
  4039. */
  4040. public function update_reinit() {
  4041. if ($this->debug > 0) {
  4042. error_log('New LP - In learnpath::update_reinit()', 0);
  4043. }
  4044. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  4045. $sql = "SELECT * FROM $lp_table WHERE id = " . $this->get_id();
  4046. $res = Database::query($sql);
  4047. if (Database :: num_rows($res) > 0) {
  4048. $row = Database :: fetch_array($res);
  4049. $force = $row['prevent_reinit'];
  4050. if ($force == 1) {
  4051. $force = 0;
  4052. } elseif ($force == 0) {
  4053. $force = 1;
  4054. }
  4055. $sql = "UPDATE $lp_table SET prevent_reinit = $force WHERE id = " . $this->get_id();
  4056. $res = Database::query($sql);
  4057. $this->prevent_reinit = $force;
  4058. return $force;
  4059. } else {
  4060. if ($this->debug > 2) {
  4061. error_log('New LP - Problem in update_reinit() - could not find LP ' . $this->get_id() . ' in DB', 0);
  4062. }
  4063. }
  4064. return -1;
  4065. }
  4066. /**
  4067. * Updates the "scorm_debug" value that shows or hide the debug window
  4068. * @return boolean True if scorm_debug has been set to 'on', false otherwise (or 1 or 0 in this case)
  4069. */
  4070. public function update_scorm_debug() {
  4071. if ($this->debug > 0) {
  4072. error_log('New LP - In learnpath::update_scorm_debug()', 0);
  4073. }
  4074. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  4075. $sql = "SELECT * FROM $lp_table WHERE id = " . $this->get_id();
  4076. $res = Database::query($sql);
  4077. if (Database :: num_rows($res) > 0) {
  4078. $row = Database :: fetch_array($res);
  4079. $force = $row['debug'];
  4080. if ($force == 1) {
  4081. $force = 0;
  4082. } elseif ($force == 0) {
  4083. $force = 1;
  4084. }
  4085. $sql = "UPDATE $lp_table SET debug = $force WHERE id = " . $this->get_id();
  4086. $res = Database::query($sql);
  4087. $this->scorm_debug = $force;
  4088. return $force;
  4089. } else {
  4090. if ($this->debug > 2) {
  4091. error_log('New LP - Problem in update_scorm_debug() - could not find LP ' . $this->get_id() . ' in DB', 0);
  4092. }
  4093. }
  4094. return -1;
  4095. }
  4096. /**
  4097. * Function that makes a call to the function sort_tree_array and create_tree_array
  4098. * @author Kevin Van Den Haute
  4099. * @param array
  4100. */
  4101. public function tree_array($array) {
  4102. if ($this->debug > 1) {
  4103. error_log('New LP - In learnpath::tree_array()', 0);
  4104. }
  4105. $array = $this->sort_tree_array($array);
  4106. $this->create_tree_array($array);
  4107. }
  4108. /**
  4109. * Creates an array with the elements of the learning path tree in it
  4110. *
  4111. * @author Kevin Van Den Haute
  4112. * @param array $array
  4113. * @param int $parent
  4114. * @param int $depth
  4115. * @param array $tmp
  4116. */
  4117. public function create_tree_array($array, $parent = 0, $depth = -1, $tmp = array ()) {
  4118. if ($this->debug > 1) {
  4119. error_log('New LP - In learnpath::create_tree_array())', 0);
  4120. }
  4121. if (is_array($array)) {
  4122. for ($i = 0; $i < count($array); $i++) {
  4123. if ($array[$i]['parent_item_id'] == $parent) {
  4124. if (!in_array($array[$i]['parent_item_id'], $tmp)) {
  4125. $tmp[] = $array[$i]['parent_item_id'];
  4126. $depth++;
  4127. }
  4128. $preq = (empty($array[$i]['prerequisite']) ? '' : $array[$i]['prerequisite']);
  4129. $this->arrMenu[] = array (
  4130. 'id' => $array[$i]['id'],
  4131. 'item_type' => $array[$i]['item_type'],
  4132. 'title' => $array[$i]['title'],
  4133. 'path' => $array[$i]['path'],
  4134. 'description' => $array[$i]['description'],
  4135. 'parent_item_id' => $array[$i]['parent_item_id'],
  4136. 'previous_item_id' => $array[$i]['previous_item_id'],
  4137. 'next_item_id' => $array[$i]['next_item_id'],
  4138. 'min_score' => $array[$i]['min_score'],
  4139. 'max_score' => $array[$i]['max_score'],
  4140. 'mastery_score' => $array[$i]['mastery_score'],
  4141. 'display_order' => $array[$i]['display_order'],
  4142. 'prerequisite' => $preq,
  4143. 'depth' => $depth,
  4144. 'audio' => $array[$i]['audio']
  4145. );
  4146. $this->create_tree_array($array, $array[$i]['id'], $depth, $tmp);
  4147. }
  4148. }
  4149. }
  4150. }
  4151. /**
  4152. * Sorts a multi dimensional array by parent id and display order
  4153. * @author Kevin Van Den Haute
  4154. *
  4155. * @param array $array (array with al the learning path items in it)
  4156. *
  4157. * @return array
  4158. */
  4159. public function sort_tree_array($array) {
  4160. foreach ($array as $key => $row) {
  4161. $parent[$key] = $row['parent_item_id'];
  4162. $position[$key] = $row['display_order'];
  4163. }
  4164. if (count($array) > 0)
  4165. array_multisort($parent, SORT_ASC, $position, SORT_ASC, $array);
  4166. return $array;
  4167. }
  4168. /**
  4169. * Function that creates a table structure with a learning path his modules, chapters and documents.
  4170. * Also the actions for the modules, chapters and documents are in this table.
  4171. * @author Kevin Van Den Haute
  4172. * @param int $lp_id
  4173. * @return string
  4174. */
  4175. public function overview() {
  4176. $is_allowed_to_edit = api_is_allowed_to_edit(null,true);
  4177. if ($this->debug > 0) {
  4178. error_log('New LP - In learnpath::overview()', 0);
  4179. }
  4180. global $charset, $_course;
  4181. $_SESSION['gradebook'] = Security :: remove_XSS($_GET['gradebook']);
  4182. $return = '';
  4183. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  4184. $sql = "SELECT * FROM " . $tbl_lp_item . "
  4185. WHERE lp_id = " . $this->lp_id;
  4186. $result = Database::query($sql);
  4187. $arrLP = array ();
  4188. while ($row = Database :: fetch_array($result)) {
  4189. $row['title'] = Security :: remove_XSS($row['title']);
  4190. $row['description'] = Security :: remove_XSS($row['description']);
  4191. $arrLP[] = array (
  4192. 'id' => $row['id'],
  4193. 'item_type' => $row['item_type'],
  4194. 'title' => $row['title'],
  4195. 'path' => $row['path'],
  4196. 'description' => $row['description'],
  4197. 'parent_item_id' => $row['parent_item_id'],
  4198. 'previous_item_id' => $row['previous_item_id'],
  4199. 'next_item_id' => $row['next_item_id'],
  4200. 'max_score' => $row['max_score'],
  4201. 'min_score' => $row['min_score'],
  4202. 'mastery_score' => $row['mastery_score'],
  4203. 'prerequisite' => $row['prerequisite'],
  4204. 'display_order' => $row['display_order'],
  4205. 'audio' => $row['audio']
  4206. );
  4207. }
  4208. $this->tree_array($arrLP);
  4209. $arrLP = $this->arrMenu;
  4210. unset ($this->arrMenu);
  4211. if ($is_allowed_to_edit) {
  4212. $token = Security::get_token();
  4213. $gradebook = Security :: remove_XSS($_GET['gradebook']);
  4214. $return .= '<div class="actions">';
  4215. $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>';
  4216. if ($_GET['updateaudio'] == 'true') {
  4217. $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>';
  4218. } else {
  4219. $return .= '<span>' . Display :: return_icon('move_learnpath_na.png', get_lang('BasicOverview'),'','32').'</span>';
  4220. }
  4221. $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>';
  4222. $return .= ' '.Display :: return_icon('i.gif');
  4223. $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') . '">
  4224. '. Display :: return_icon('new_learnigpath_object.png', get_lang('NewStep'),'','32').'</a>';
  4225. $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') . '">
  4226. '. Display :: return_icon('add_learnpath_section.png', get_lang('NewChapter'),'','32').'</a>';
  4227. if ($_GET['updateaudio'] == 'true') {
  4228. $return .= Display::url(Display :: return_icon('upload_audio_na.png', get_lang('UpdateAllAudioFragments'),'','32'),'#');
  4229. } else {
  4230. $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>';
  4231. }
  4232. $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>';
  4233. $return .= '</div>';
  4234. }
  4235. // we need to start a form when we want to update all the mp3 files
  4236. if ($_GET['updateaudio'] == 'true' AND count($arrLP) <> 0) {
  4237. $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">';
  4238. $return .= Display::return_message(get_lang('LeaveEmptyToKeepCurrentFile'), 'warning');
  4239. }
  4240. $return .= '<table class="data_table">';
  4241. $return .= '<tr>';
  4242. $return .= '<th width="60%">' . get_lang('Title') . '</th>';
  4243. //$return .= '<th>'.get_lang('Description').'</th>';
  4244. $return .= '<th>' . get_lang('Audio') . '</th>';
  4245. if (!$_GET['updateaudio'] OR $_GET['updateaudio'] <> 'true') {
  4246. $return .= '<th>' . get_lang('Move') . '</th>';
  4247. }
  4248. $return .= '<th>' . get_lang('Actions') . '</th>';
  4249. $return .= '</tr>';
  4250. for ($i = 0; $i < count($arrLP); $i++) {
  4251. $title = $arrLP[$i]['title'];
  4252. if ($arrLP[$i]['description'] == '')
  4253. $arrLP[$i]['description'] = '&nbsp;';
  4254. if (($i % 2) == 0) {
  4255. $oddclass = 'row_odd';
  4256. } else {
  4257. $oddclass = 'row_even';
  4258. }
  4259. $return .= '<tr class="' . $oddclass . '">';
  4260. $icon_name = str_replace(' ', '', $arrLP[$i]['item_type']);
  4261. if (file_exists('../img/lp_' . $icon_name . '.png')) {
  4262. $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>';
  4263. } else {
  4264. if (file_exists('../img/lp_' . $icon_name . '.gif')) {
  4265. $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>';
  4266. } else {
  4267. //$return .= '<td style="padding-left:' . $arrLP[$i]['depth'] * 10 . 'px;">' . Display::display_icon('folder_document.gif','',array('style'=>'margin-right:3px;')) . $title . '</td>';
  4268. $return .= '<td style="padding-left:' . $arrLP[$i]['depth'] * 10 . 'px;"><img align="left" src="../img/folder_document.gif" style="margin-right:3px;" />' . $title . '</td>';
  4269. }
  4270. }
  4271. //$return .= '<td>' . stripslashes($arrLP[$i]['description']) . '</td>';
  4272. // The audio column.
  4273. $return .= '<td align="center">';
  4274. if (!$_GET['updateaudio'] OR $_GET['updateaudio'] <> 'true') {
  4275. if (!empty ($arrLP[$i]['audio'])) {
  4276. $return .= '<span id="container' . $i . '"><a href="http://www.macromedia.com/go/getflashplayer">Get the Flash Player</a> to see this player.</span>';
  4277. $return .= '<script type="text/javascript" src="../inc/lib/mediaplayer/swfobject.js"></script>';
  4278. $return .= '<script type="text/javascript">
  4279. var s1 = new SWFObject("../inc/lib/mediaplayer/player.swf","ply","250","20","9","#FFFFFF");
  4280. s1.addParam("allowscriptaccess","always");
  4281. s1.addParam("flashvars","file=../../courses/' . $_course['path'] . '/document/audio/' . $arrLP[$i]['audio'] . '");
  4282. s1.write("container' . $i . '");
  4283. </script>';
  4284. } else {
  4285. $return .= ' - ';
  4286. }
  4287. } else {
  4288. if ($arrLP[$i]['item_type'] != 'dokeos_chapter' && $arrLP[$i]['item_type'] != 'dokeos_module' && $arrLP[$i]['item_type'] != 'dir') {
  4289. $return .= ' <input type="file" name="mp3file' . $arrLP[$i]['id'] . '" id="mp3file" />';
  4290. if (!empty ($arrLP[$i]['audio'])) {
  4291. $return .= '<br />'.Security::remove_XSS($arrLP[$i]['audio']).'<input type="checkbox" name="removemp3' . $arrLP[$i]['id'] . '" id="checkbox' . $arrLP[$i]['id'] . '" />' . get_lang('RemoveAudio');
  4292. }
  4293. }
  4294. }
  4295. $return .= '</td>';
  4296. if ($is_allowed_to_edit) {
  4297. if (!$_GET['updateaudio'] OR $_GET['updateaudio'] <> 'true') {
  4298. $return .= '<td align="center">';
  4299. if ($arrLP[$i]['previous_item_id'] != 0) {
  4300. $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.'">';
  4301. $return .= '<img style="margin:1px;" alt="" src="../img/arrow_up_' . ($arrLP[$i]['depth'] % 3) . '.gif" title="' . get_lang('MoveUp') . '"/>';
  4302. $return .= '</a>';
  4303. } else {
  4304. $return .= '<img alt="" src="../img/blanco.png" title="" />';
  4305. }
  4306. if ($arrLP[$i]['next_item_id'] != 0) {
  4307. $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.'">';
  4308. $return .= '<img style="margin:1px;" src="../img/arrow_down_' . ($arrLP[$i]['depth'] % 3) . '.gif" title="' . get_lang('MoveDown') . '" />';
  4309. $return .= '</a>';
  4310. } else
  4311. $return .= '<img alt="" src="../img/blanco.png" title="" />';
  4312. $return .= '</td>';
  4313. }
  4314. $return .= '<td align="center">';
  4315. if ($arrLP[$i]['item_type'] != 'dokeos_chapter' && $arrLP[$i]['item_type'] != 'dokeos_module') {
  4316. $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'] . '">';
  4317. $return .= '<img style="margin:1px;" alt="" src="../img/edit.png" title="' . get_lang('_edit_learnpath_module') . '" />';
  4318. $return .= '</a>';
  4319. } else {
  4320. $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'] . '">';
  4321. $return .= '<img style="margin:1px;" alt="" src="../img/edit.png" title="' . get_lang('_edit_learnpath_module') . '" />';
  4322. $return .= '</a>';
  4323. }
  4324. $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) . '\');">';
  4325. $return .= '<img style="margin:1px;" alt="" src="../img/delete.png" title="' . get_lang('_delete_learnpath_module') . '" />';
  4326. $return .= '</a>';
  4327. $return .= '</td>';
  4328. }
  4329. $return .= '</tr>';
  4330. }
  4331. if (count($arrLP) == 0) {
  4332. $return .= '<tr>';
  4333. $return .= '<td colspan="4">' . get_lang('NoItemsInLp') . '</td>';
  4334. $return .= '</tr>';
  4335. }
  4336. $return .= '</table>';
  4337. // We need to close the form when we are updating the mp3 files.
  4338. if ($_GET['updateaudio'] == 'true') {
  4339. $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?
  4340. }
  4341. // We need to close the form when we are updating the mp3 files.
  4342. if ($_GET['updateaudio'] == 'true' && count($arrLP) != 0) {
  4343. $return .= '</form>';
  4344. }
  4345. return $return;
  4346. }
  4347. /**
  4348. * This function builds the action menu
  4349. * @return void
  4350. */
  4351. public function build_action_menu() {
  4352. $gradebook = Security :: remove_XSS($_GET['gradebook']);
  4353. echo '<div class="actions">';
  4354. //echo '<span>'.Display::return_icon('build_learnpath.png','-','','32').' '.get_lang('Build').'</span>';
  4355. echo '<span>' . Display :: return_icon('build_learnpath_na.png', get_lang('Build'),'','32').'</span>';
  4356. 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>';
  4357. 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> ';
  4358. Display :: display_icon('i.gif');
  4359. 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>';
  4360. 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>';
  4361. 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>';
  4362. 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>';
  4363. echo '</div>';
  4364. }
  4365. /**
  4366. * This functions builds the LP tree based on data from the database.
  4367. * @return string
  4368. * @uses dtree.js :: necessary javascript for building this tree
  4369. */
  4370. public function build_tree() {
  4371. $return = "<script type=\"text/javascript\">\n";
  4372. $return .= "\tm = new dTree('m');\n\n";
  4373. $return .= "\tm.config.folderLinks = true;\n";
  4374. $return .= "\tm.config.useCookies = true;\n";
  4375. $return .= "\tm.config.useIcons = true;\n";
  4376. $return .= "\tm.config.useLines = true;\n";
  4377. $return .= "\tm.config.useSelection = true;\n";
  4378. $return .= "\tm.config.useStatustext = false;\n\n";
  4379. $menu = 0;
  4380. $parent = '';
  4381. $return .= "\tm.add(" . $menu . ", -1, '" . addslashes(Security::remove_XSS(($this->name))) . "');\n";
  4382. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  4383. $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
  4384. FROM $tbl_lp_item
  4385. WHERE lp_id = " . Database :: escape_string($this->lp_id);
  4386. $result = Database::query($sql);
  4387. $arrLP = array ();
  4388. while ($row = Database :: fetch_array($result)) {
  4389. $row['title'] = Security :: remove_XSS($row['title']);
  4390. $row['description'] = Security :: remove_XSS($row['description']);
  4391. $arrLP[] = array (
  4392. 'id' => $row['id'],
  4393. 'item_type' => $row['item_type'],
  4394. 'title' => $row['title'],
  4395. 'path' => $row['path'],
  4396. 'description' => $row['description'],
  4397. 'parent_item_id' => $row['parent_item_id'],
  4398. 'previous_item_id' => $row['previous_item_id'],
  4399. 'next_item_id' => $row['next_item_id'],
  4400. 'max_score' => $row['max_score'],
  4401. 'min_score' => $row['min_score'],
  4402. 'mastery_score' => $row['mastery_score'],
  4403. 'display_order' => $row['display_order']
  4404. );
  4405. }
  4406. $this->tree_array($arrLP);
  4407. $arrLP = $this->arrMenu;
  4408. unset ($this->arrMenu);
  4409. $title = '';
  4410. for ($i = 0; $i < count($arrLP); $i++) {
  4411. $title = addslashes($arrLP[$i]['title']);
  4412. $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;
  4413. $icon_name = str_replace(' ', '', $arrLP[$i]['item_type']);
  4414. if (file_exists('../img/lp_' . $icon_name . '.png')) {
  4415. $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";
  4416. } else
  4417. if (file_exists('../img/lp_' . $icon_name . '.gif')) {
  4418. $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";
  4419. } else {
  4420. $return .= "\tm.add(" . $arrLP[$i]['id'] . ", " . $arrLP[$i]['parent_item_id'] . ", '" . $title . "', '" . $menu_page . "', '', '', '../img/folder_document.gif', '../img/folder_document.gif');\n";
  4421. }
  4422. if ($menu < $arrLP[$i]['id'])
  4423. $menu = $arrLP[$i]['id'];
  4424. }
  4425. $return .= "\n\tdocument.write(m);\n";
  4426. $return .= "\t if(!m.selectedNode) m.s(1);";
  4427. $return .= "</script>\n";
  4428. return $return;
  4429. }
  4430. /**
  4431. * Create a new document //still needs some finetuning
  4432. * @param array $_course
  4433. * @return string
  4434. */
  4435. public function create_document($_course) {
  4436. global $charset;
  4437. $dir = isset ($_GET['dir']) ? $_GET['dir'] : $_POST['dir']; // Please, do not modify this dirname formatting.
  4438. if (strstr($dir, '..'))
  4439. $dir = '/';
  4440. if ($dir[0] == '.')
  4441. $dir = substr($dir, 1);
  4442. if ($dir[0] != '/')
  4443. $dir = '/' . $dir;
  4444. if ($dir[strlen($dir) - 1] != '/')
  4445. $dir .= '/';
  4446. $filepath = api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document' . $dir;
  4447. if (!is_dir($filepath)) {
  4448. $filepath = api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document/';
  4449. $dir = '/';
  4450. }
  4451. // stripslashes() before calling replace_dangerous_char() because $_POST['title']
  4452. // is already escaped twice when it gets here.
  4453. $title = replace_dangerous_char(stripslashes($_POST['title']));
  4454. $title = disable_dangerous_file($title);
  4455. $filename = $title;
  4456. $content = $_POST['content_lp'];
  4457. $tmp_filename = $filename;
  4458. $i = 0;
  4459. while (file_exists($filepath . $tmp_filename . '.html'))
  4460. $tmp_filename = $filename . '_' . ++ $i;
  4461. $filename = $tmp_filename . '.html';
  4462. $content = stripslashes(text_filter($content));
  4463. $content = str_replace(api_get_path(WEB_COURSE_PATH), api_get_path(REL_PATH) . 'courses/', $content);
  4464. // Change the path of mp3 to absolute.
  4465. // The first regexp deals with ../../../ urls.
  4466. $content = preg_replace("|(flashvars=\"file=)(\.+/)+|", "$1" . api_get_path(REL_COURSE_PATH) . $_course['path'] . '/document/', $content);
  4467. // The second regexp deals with audio/ urls.
  4468. $content = preg_replace("|(flashvars=\"file=)([^/]+)/|", "$1" . api_get_path(REL_COURSE_PATH) . $_course['path'] . '/document/$2/', $content);
  4469. // For flv player: To prevent edition problem with firefox, we have to use a strange tip (don't blame me please).
  4470. $content = str_replace('</body>', '<style type="text/css">body{}</style></body>', $content);
  4471. if (!file_exists($filepath . $filename)) {
  4472. if ($fp = @ fopen($filepath . $filename, 'w')) {
  4473. fputs($fp, $content);
  4474. fclose($fp);
  4475. $file_size = filesize($filepath . $filename);
  4476. $save_file_path = $dir . $filename;
  4477. $document_id = add_document($_course, $save_file_path, 'file', $file_size, $filename . '.html');
  4478. if ($document_id) {
  4479. api_item_property_update($_course, TOOL_DOCUMENT, $document_id, 'DocumentAdded', api_get_user_id(), null, null, null, null, api_get_session_id());
  4480. // Update parent folders.
  4481. //item_property_update_on_folder($_course, $_GET['dir'], $_user['user_id']);
  4482. $new_comment = (isset($_POST['comment'])) ? trim($_POST['comment']) : '';
  4483. $new_title = (isset($_POST['title'])) ? trim($_POST['title']) : '';
  4484. if ($new_comment || $new_title) {
  4485. $tbl_doc = Database :: get_course_table(TABLE_DOCUMENT);
  4486. $ct = '';
  4487. if ($new_comment)
  4488. $ct .= ", comment='" . $new_comment . "'";
  4489. if ($new_title)
  4490. $ct .= ", title='" . Database :: escape_string(htmlspecialchars($new_title, ENT_QUOTES, $charset)) . ".html '";
  4491. $sql_update = "
  4492. UPDATE " . $tbl_doc . "
  4493. SET " . substr($ct, 1) . "
  4494. WHERE id = " . $document_id;
  4495. Database::query($sql_update);
  4496. }
  4497. }
  4498. return $document_id;
  4499. }
  4500. }
  4501. }
  4502. /**
  4503. * Edit a document based on $_POST and $_GET parameters 'dir' and 'path'
  4504. * @param array $_course array
  4505. * @return void
  4506. */
  4507. public function edit_document($_course) {
  4508. global $_configuration;
  4509. $dir = isset ($_GET['dir']) ? $_GET['dir'] : $_POST['dir']; // Please, do not modify this dirname formatting.
  4510. if (strstr($dir, '..'))
  4511. $dir = '/';
  4512. if ($dir[0] == '.')
  4513. $dir = substr($dir, 1);
  4514. if ($dir[0] != '/')
  4515. $dir = '/' . $dir;
  4516. if ($dir[strlen($dir) - 1] != '/')
  4517. $dir .= '/';
  4518. $filepath = api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document' . $dir;
  4519. if (!is_dir($filepath)) {
  4520. $filepath = api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document/';
  4521. $dir = '/';
  4522. }
  4523. $table_doc = Database :: get_course_table(TABLE_DOCUMENT);
  4524. if (isset($_POST['path']) && !empty($_POST['path'])) {
  4525. $sql = "SELECT path
  4526. FROM " . $table_doc . "
  4527. WHERE id = " . Database::escape_string($_POST['path']);
  4528. $res = Database::query($sql);
  4529. $row = Database :: fetch_array($res);
  4530. $content = stripslashes($_POST['content_lp']);
  4531. $file = $filepath . $row['path'];
  4532. if ($fp = @ fopen($file, 'w')) {
  4533. $content = text_filter($content);
  4534. $content = str_replace(api_get_path(WEB_COURSE_PATH), $_configuration['url_append'] . '/courses/', $content);
  4535. // Change the path of mp3 to absolute.
  4536. // The first regexp deals with ../../../ urls.
  4537. $content = preg_replace("|(flashvars=\"file=)(\.+/)+|", "$1" . api_get_path(REL_COURSE_PATH) . $_course['path'] . '/document/', $content);
  4538. // The second regexp deals with audio/ urls.
  4539. $content = preg_replace("|(flashvars=\"file=)([^/]+)/|", "$1" . api_get_path(REL_COURSE_PATH) . $_course['path'] . '/document/$2/', $content);
  4540. fputs($fp, $content);
  4541. fclose($fp);
  4542. }
  4543. }
  4544. }
  4545. /**
  4546. * Displays the selected item, with a panel for manipulating the item
  4547. * @param int $item_id
  4548. * @param string $msg
  4549. * @return string
  4550. */
  4551. public function display_item($item_id, $iframe = true, $msg = '') {
  4552. global $_course; // It will disappear.
  4553. $return = '';
  4554. if (is_numeric($item_id)) {
  4555. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  4556. $tbl_doc = Database :: get_course_table(TABLE_DOCUMENT);
  4557. $sql = "SELECT lp.* FROM " . $tbl_lp_item . " as lp
  4558. WHERE lp.id = " . Database :: escape_string($item_id);
  4559. $result = Database::query($sql);
  4560. while ($row = Database :: fetch_array($result)) {
  4561. $_SESSION['parent_item_id'] = ($row['item_type'] == 'dokeos_chapter' || $row['item_type'] == 'dokeos_module' || $row['item_type'] == 'dir') ? $item_id : 0;
  4562. // Prevents wrong parent selection for document, see Bug#1251.
  4563. if ($row['item_type'] != 'dokeos_chapter' || $row['item_type'] != 'dokeos_module') {
  4564. $_SESSION['parent_item_id'] = $row['parent_item_id'];
  4565. }
  4566. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4567. $return .= '<div style="padding:10px;">';
  4568. if ($msg != '')
  4569. $return .= $msg;
  4570. $return .= '<p class="lp_title">' . $row['title'] . '</p>';
  4571. //$return .= '<p class="lp_text">' . ((trim($row['description']) == '') ? 'no description' : stripslashes($row['description'])) . '</p>';
  4572. //$return .= '<hr />';
  4573. switch ($row['item_type']) {
  4574. case TOOL_QUIZ:
  4575. if (!empty($row['path'])) {
  4576. require_once api_get_path(SYS_CODE_PATH).'exercice/exercise.class.php';
  4577. $exercise = new Exercise();
  4578. $exercise->read($row['path']);
  4579. // $exercise_url = api_get_path(WEB_CODE_PATH).'exercice/admin.php?exerciseId='.$exercise->id.'&'.api_get_cidReq().'&id_session='.api_get_session_id();
  4580. $return .=$exercise->description.'<br />';
  4581. //$return .=Display::url($exercise_url, $exercise_url).'<br />';*/
  4582. }
  4583. break;
  4584. case TOOL_DOCUMENT:
  4585. $tbl_doc = Database :: get_course_table(TABLE_DOCUMENT);
  4586. $sql_doc = "SELECT path FROM " . $tbl_doc . " WHERE id = " . Database :: escape_string($row['path']);
  4587. $result = Database::query($sql_doc);
  4588. $path_file = Database :: result($result, 0, 0);
  4589. $path_parts = pathinfo($path_file);
  4590. // TODO: Correct the following naive comparisons, also, htm extension is missing.
  4591. if (in_array($path_parts['extension'], array (
  4592. 'html',
  4593. 'txt',
  4594. 'png',
  4595. 'jpg',
  4596. 'JPG',
  4597. 'jpeg',
  4598. 'JPEG',
  4599. 'gif',
  4600. 'swf'
  4601. ))) {
  4602. $return .= $this->display_document($row['path'], true, true);
  4603. }
  4604. break;
  4605. }
  4606. $return .= '</div>';
  4607. }
  4608. }
  4609. return $return;
  4610. }
  4611. /**
  4612. * Shows the needed forms for editing a specific item
  4613. * @param int $item_id
  4614. * @return string
  4615. */
  4616. public function display_edit_item($item_id) {
  4617. global $_course; // It will disappear.
  4618. $return = '';
  4619. if (is_numeric($item_id)) {
  4620. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  4621. $sql = "SELECT * FROM $tbl_lp_item WHERE id = " . Database :: escape_string($item_id);
  4622. $res = Database::query($sql);
  4623. $row = Database::fetch_array($res);
  4624. switch ($row['item_type']) {
  4625. case 'dokeos_chapter' :
  4626. case 'dir' :
  4627. case 'asset' :
  4628. case 'sco' :
  4629. if (isset ($_GET['view']) && $_GET['view'] == 'build') {
  4630. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4631. $return .= $this->display_item_form($row['item_type'], get_lang('EditCurrentChapter') . ' :', 'edit', $item_id, $row);
  4632. } else {
  4633. $return .= $this->display_item_small_form($row['item_type'], get_lang('EditCurrentChapter') . ' :', $row);
  4634. }
  4635. break;
  4636. case TOOL_DOCUMENT :
  4637. $tbl_doc = Database :: get_course_table(TABLE_DOCUMENT);
  4638. $sql_step = " SELECT lp.*, doc.path as dir
  4639. FROM " . $tbl_lp_item . " as lp
  4640. LEFT JOIN " . $tbl_doc . " as doc ON doc.id = lp.path
  4641. WHERE lp.id = " . Database :: escape_string($item_id);
  4642. $res_step = Database::query($sql_step);
  4643. $row_step = Database :: fetch_array($res_step);
  4644. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4645. $return .= $this->display_document_form('edit', $item_id, $row_step);
  4646. break;
  4647. case TOOL_LINK :
  4648. $link_id = (string) $row['path'];
  4649. if (ctype_digit($link_id)) {
  4650. $tbl_link = Database :: get_course_table(TABLE_LINK);
  4651. $sql_select = 'SELECT url FROM ' . $tbl_link . ' WHERE id = ' . Database :: escape_string($link_id);
  4652. $res_link = Database::query($sql_select);
  4653. $row_link = Database :: fetch_array($res_link);
  4654. if (is_array($row_link)) {
  4655. $row['url'] = $row_link['url'];
  4656. }
  4657. }
  4658. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4659. $return .= $this->display_link_form('edit', $item_id, $row);
  4660. break;
  4661. case 'dokeos_module' :
  4662. if (isset ($_GET['view']) && $_GET['view'] == 'build') {
  4663. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4664. $return .= $this->display_item_form($row['item_type'], get_lang('EditCurrentModule') . ' :', 'edit', $item_id, $row);
  4665. } else {
  4666. $return .= $this->display_item_small_form($row['item_type'], get_lang('EditCurrentModule') . ' :', $row);
  4667. }
  4668. break;
  4669. case TOOL_QUIZ :
  4670. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4671. $return .= $this->display_quiz_form('edit', $item_id, $row);
  4672. break;
  4673. case TOOL_HOTPOTATOES :
  4674. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4675. $return .= $this->display_hotpotatoes_form('edit', $item_id, $row);
  4676. break;
  4677. case TOOL_STUDENTPUBLICATION :
  4678. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4679. $return .= $this->display_student_publication_form('edit', $item_id, $row);
  4680. break;
  4681. case TOOL_FORUM :
  4682. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4683. $return .= $this->display_forum_form('edit', $item_id, $row);
  4684. break;
  4685. case TOOL_THREAD :
  4686. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4687. $return .= $this->display_thread_form('edit', $item_id, $row);
  4688. break;
  4689. }
  4690. }
  4691. return $return;
  4692. }
  4693. /**
  4694. * Function that displays a list with al the resources that could be added to the learning path
  4695. * @return string
  4696. */
  4697. public function display_resources() {
  4698. global $_course; // TODO: Don't use globals.
  4699. /*$return .= '<div class="sectiontitle">' . get_lang('CreateNewStep') . '</div>';
  4700. $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>';
  4701. $return .= '<div class="sectiontitle">' . get_lang('UseAnExistingResource') . '</div>';*/
  4702. //Get all the docs
  4703. $documents = $this->get_documents();
  4704. //Get all the exercises
  4705. $exercises = $this->get_exercises();
  4706. // Get all the links
  4707. $links = $this->get_links();
  4708. //Get al the student publications
  4709. $works = $this->get_student_publications();
  4710. //Get al the forums
  4711. $forums = $this->get_forums();
  4712. $headers = array( Display::return_icon('folder_document.png', get_lang('Documents'), array(), 64),
  4713. Display::return_icon('quiz.png', get_lang('Exercises'), array(), 64),
  4714. Display::return_icon('links.png', get_lang('Links'), array(), 64),
  4715. Display::return_icon('works.png', get_lang('Works'), array(), 64),
  4716. Display::return_icon('forum.png', get_lang('Forums'), array(), 64),
  4717. );
  4718. echo Display::tabs($headers, array($documents, $exercises, $links, $works, $forums), 'resource_tab');
  4719. return true;
  4720. }
  4721. /**
  4722. * Returns the extension of a document
  4723. * @param string filename
  4724. * @return string Extension (part after the last dot)
  4725. */
  4726. public function get_extension($filename) {
  4727. $explode = explode('.', $filename);
  4728. return $explode[count($explode) - 1];
  4729. }
  4730. /**
  4731. * Displays a document by id
  4732. *
  4733. * @param unknown_type $id
  4734. * @return unknown
  4735. */
  4736. public function display_document($id, $show_title = false, $iframe = true, $edit_link = false) {
  4737. global $_course; // It is temporary.
  4738. $return = '';
  4739. $tbl_doc = Database :: get_course_table(TABLE_DOCUMENT);
  4740. $sql_doc = "SELECT * FROM " . $tbl_doc . "
  4741. WHERE id = " . $id;
  4742. $res_doc = Database::query($sql_doc);
  4743. $row_doc = Database :: fetch_array($res_doc);
  4744. //if ($show_title)
  4745. //$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>';
  4746. // TODO: Add a path filter.
  4747. if ($iframe) {
  4748. $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>';
  4749. } else {
  4750. $return .= file_get_contents(api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document' . $row_doc['path']);
  4751. }
  4752. return $return;
  4753. }
  4754. /**
  4755. * Return HTML form to add/edit a quiz
  4756. * @param string Action (add/edit)
  4757. * @param integer Item ID if already exists
  4758. * @param mixed Extra information (quiz ID if integer)
  4759. * @return string HTML form
  4760. */
  4761. public function display_quiz_form($action = 'add', $id = 0, $extra_info = '') {
  4762. global $charset;
  4763. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  4764. $tbl_quiz = Database :: get_course_table(TABLE_QUIZ_TEST);
  4765. if ($id != 0 && is_array($extra_info)) {
  4766. $item_title = stripslashes($extra_info['title']);
  4767. $item_description = stripslashes($extra_info['description']);
  4768. }
  4769. elseif (is_numeric($extra_info)) {
  4770. $sql_quiz = "
  4771. SELECT
  4772. title,
  4773. description
  4774. FROM " . $tbl_quiz . "
  4775. WHERE id = " . $extra_info;
  4776. $result = Database::query($sql_quiz);
  4777. $row = Database :: fetch_array($result);
  4778. $item_title = $row['title'];
  4779. $item_description = $row['description'];
  4780. } else {
  4781. $item_title = '';
  4782. $item_description = '';
  4783. }
  4784. $return = ' <div class="row">
  4785. <div class="form_header">';
  4786. if ($id != 0 && is_array($extra_info))
  4787. $parent = $extra_info['parent_item_id'];
  4788. else
  4789. $parent = 0;
  4790. $sql = "
  4791. SELECT *
  4792. FROM " . $tbl_lp_item . "
  4793. WHERE
  4794. lp_id = " . $this->lp_id;
  4795. $result = Database::query($sql);
  4796. $arrLP = array ();
  4797. while ($row = Database :: fetch_array($result)) {
  4798. $arrLP[] = array (
  4799. 'id' => $row['id'],
  4800. 'item_type' => $row['item_type'],
  4801. 'title' => $row['title'],
  4802. 'path' => $row['path'],
  4803. 'description' => $row['description'],
  4804. 'parent_item_id' => $row['parent_item_id'],
  4805. 'previous_item_id' => $row['previous_item_id'],
  4806. 'next_item_id' => $row['next_item_id'],
  4807. 'display_order' => $row['display_order'],
  4808. 'max_score' => $row['max_score'],
  4809. 'min_score' => $row['min_score'],
  4810. 'mastery_score' => $row['mastery_score'],
  4811. 'prerequisite' => $row['prerequisite'],
  4812. 'max_time_allowed' => $row['max_time_allowed']
  4813. );
  4814. }
  4815. $this->tree_array($arrLP);
  4816. $arrLP = $this->arrMenu;
  4817. unset ($this->arrMenu);
  4818. if ($action == 'add')
  4819. $return .= get_lang('CreateTheExercise') . '&nbsp;:';
  4820. elseif ($action == 'move') $return .= get_lang('MoveTheCurrentExercise') . '&nbsp;:';
  4821. else
  4822. $return .= get_lang('EditCurrentExecice') . '&nbsp;:';
  4823. if (isset ($_GET['edit']) && $_GET['edit'] == 'true') {
  4824. $return .= Display :: return_warning_message('<p class="lp_title">' . get_lang('Warning') . ' !</p>' . get_lang('WarningEditingDocument'));
  4825. }
  4826. $return .= ' </div>
  4827. </div>';
  4828. $return .= '<div class="sectioncomment">';
  4829. $return .= '<form method="POST">';
  4830. $return .= '<table class="lp_form">';
  4831. if ($action != 'move') {
  4832. $return .= '<tr>';
  4833. $return .= '<td class="label"><label for="idTitle">' . get_lang('Title') . '</label></td>';
  4834. $return .= '<td class="input"><input id="idTitle" name="title" size="44" type="text" class="learnpath_item_form" value="' . $item_title . '" /></td>';
  4835. $return .= '</tr>';
  4836. }
  4837. $return .= '<tr>';
  4838. $return .= '<td class="label"><label for="idParent">' . get_lang('Parent') . '</label></td>';
  4839. $return .= '<td class="input">';
  4840. $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">';
  4841. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
  4842. $arrHide = array (
  4843. $id
  4844. );
  4845. //$parent_item_id = $_SESSION['parent_item_id'];
  4846. for ($i = 0; $i < count($arrLP); $i++) {
  4847. if ($action != 'add') {
  4848. 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)) {
  4849. $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>';
  4850. } else {
  4851. $arrHide[] = $arrLP[$i]['id'];
  4852. }
  4853. } else {
  4854. if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
  4855. $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>';
  4856. }
  4857. }
  4858. if (is_array($arrLP)) {
  4859. reset($arrLP);
  4860. }
  4861. $return .= '</select>';
  4862. $return .= '</td>';
  4863. $return .= '</tr>';
  4864. $return .= '<tr>';
  4865. $return .= '<td class="label"><label for="previous">' . get_lang('Position') . '</label></td>';
  4866. $return .= '<td class="input">';
  4867. $return .= "\t\t\t\t" . '<select class="learnpath_item_form" style="width:100%;" id="previous" name="previous" size="1">';
  4868. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . get_lang('FirstPosition') . '</option>';
  4869. for ($i = 0; $i < count($arrLP); $i++) {
  4870. if ($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) {
  4871. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  4872. $selected = 'selected="selected" ';
  4873. elseif ($action == 'add') $selected = 'selected="selected" ';
  4874. else
  4875. $selected = '';
  4876. $return .= "\t\t\t\t\t" . '<option ' . $selected . 'value="' . $arrLP[$i]['id'] . '">' . get_lang('After') . ' "' . $arrLP[$i]['title'] . '"</option>';
  4877. }
  4878. }
  4879. $return .= "\t\t\t\t" . '</select>';
  4880. $return .= '</td>';
  4881. $return .= '</tr>';
  4882. if ($action != 'move') {
  4883. $id_prerequisite = 0;
  4884. if (is_array($arrLP)) {
  4885. foreach ($arrLP as $key => $value) {
  4886. if ($value['id'] == $id) {
  4887. $id_prerequisite = $value['prerequisite'];
  4888. break;
  4889. }
  4890. }
  4891. }
  4892. $arrHide = array ();
  4893. for ($i = 0; $i < count($arrLP); $i++) {
  4894. if ($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter') {
  4895. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  4896. $s_selected_position = $arrLP[$i]['id'];
  4897. elseif ($action == 'add') $s_selected_position = 0;
  4898. $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
  4899. }
  4900. }
  4901. /*// Commented the prerequisites, only visible in edit (exercise).
  4902. $return .= '<tr>';
  4903. $return .= '<td class="label"><label for="idPrerequisites">'.get_lang('Prerequisites').'</label></td>';
  4904. $return .= '<td class="input"><select name="prerequisites" id="prerequisites" class="learnpath_item_form"><option value="0">'.get_lang('NoPrerequisites').'</option>';
  4905. foreach($arrHide as $key => $value){
  4906. if($key==$s_selected_position && $action == 'add'){
  4907. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  4908. }
  4909. elseif($key==$id_prerequisite && $action == 'edit'){
  4910. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  4911. }
  4912. else{
  4913. $return .= '<option value="'.$key.'">'.$value['value'].'</option>';
  4914. }
  4915. }
  4916. $return .= "</select></td>";
  4917. */
  4918. $return .= '</tr>';
  4919. /*$return .= '<tr>';
  4920. $return .= '<td class="label"><label for="maxTimeAllowed">' . get_lang('MaxTimeAllowed') . '</label></td>';
  4921. $return .= '<td class="input"><input name="maxTimeAllowed" style="width:98%;" id="maxTimeAllowed" value="' . $extra_info['max_time_allowed'] . '" /></td>';
  4922. // Remove temporarily the test description.
  4923. //$return .= '<td class="label"><label for="idDescription">'.get_lang('Description').' :</label></td>';
  4924. //$return .= '<td class="input"><textarea id="idDescription" name="description" rows="4">' . $item_description . '</textarea></td>';
  4925. $return .= '</tr>'; */
  4926. }
  4927. $return .= '<tr>';
  4928. if ($action == 'add') {
  4929. $return .= '<td>&nbsp;</td><td><button class="save" name="submit_button" type="submit">' . get_lang('AddExercise') . '</button></td>';
  4930. } else {
  4931. $return .= '<td>&nbsp;</td><td><button class="save" name="submit_button" type="submit">' . get_lang('EditCurrentExecice') . '</button></td>';
  4932. }
  4933. $return .= '</tr>';
  4934. $return .= '</table>';
  4935. if ($action == 'move') {
  4936. $return .= '<input name="title" type="hidden" value="' . $item_title . '" />';
  4937. $return .= '<input name="description" type="hidden" value="' . $item_description . '" />';
  4938. }
  4939. if (is_numeric($extra_info)) {
  4940. $return .= '<input name="path" type="hidden" value="' . $extra_info . '" />';
  4941. }
  4942. elseif (is_array($extra_info)) {
  4943. $return .= '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />';
  4944. }
  4945. $return .= '<input name="type" type="hidden" value="' . TOOL_QUIZ . '" />';
  4946. $return .= '<input name="post_time" type="hidden" value="' . time() . '" />';
  4947. $return .= '</form>';
  4948. $return .= '</div>';
  4949. return $return;
  4950. }
  4951. /**
  4952. * Addition of Hotpotatoes tests
  4953. * @param string Action
  4954. * @param integer Internal ID of the item
  4955. * @param mixed Extra information - can be an array with title and description indexes
  4956. * @return string HTML structure to display the hotpotatoes addition formular
  4957. */
  4958. public function display_hotpotatoes_form($action = 'add', $id = 0, $extra_info = '') {
  4959. global $charset;
  4960. $uploadPath = DIR_HOTPOTATOES; //defined in main_api
  4961. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  4962. if ($id != 0 && is_array($extra_info)) {
  4963. $item_title = stripslashes($extra_info['title']);
  4964. $item_description = stripslashes($extra_info['description']);
  4965. } elseif (is_numeric($extra_info)) {
  4966. $TBL_DOCUMENT = Database :: get_course_table(TABLE_DOCUMENT);
  4967. $sql_hot = "SELECT * FROM " . $TBL_DOCUMENT . "
  4968. WHERE path LIKE '" . $uploadPath . "/%/%htm%'
  4969. AND id = " . (int) $extra_info . " ORDER BY id ASC";
  4970. $res_hot = Database::query($sql_hot);
  4971. $row = Database::fetch_array($res_hot);
  4972. $item_title = $row['title'];
  4973. $item_description = $row['description'];
  4974. if (!empty ($row['comment'])) {
  4975. $item_title = $row['comment'];
  4976. }
  4977. } else {
  4978. $item_title = '';
  4979. $item_description = '';
  4980. }
  4981. if ($id != 0 && is_array($extra_info))
  4982. $parent = $extra_info['parent_item_id'];
  4983. else
  4984. $parent = 0;
  4985. $sql = "SELECT * FROM $tbl_lp_item WHERE lp_id = " . $this->lp_id;
  4986. $result = Database::query($sql);
  4987. $arrLP = array ();
  4988. while ($row = Database :: fetch_array($result)) {
  4989. $arrLP[] = array (
  4990. 'id' => $row['id'],
  4991. 'item_type' => $row['item_type'],
  4992. 'title' => $row['title'],
  4993. 'path' => $row['path'],
  4994. 'description' => $row['description'],
  4995. 'parent_item_id' => $row['parent_item_id'],
  4996. 'previous_item_id' => $row['previous_item_id'],
  4997. 'next_item_id' => $row['next_item_id'],
  4998. 'display_order' => $row['display_order'],
  4999. 'max_score' => $row['max_score'],
  5000. 'min_score' => $row['min_score'],
  5001. 'mastery_score' => $row['mastery_score'],
  5002. 'prerequisite' => $row['prerequisite'],
  5003. 'max_time_allowed' => $row['max_time_allowed']
  5004. );
  5005. }
  5006. /*
  5007. $this->tree_array($arrLP);
  5008. $arrLP = $this->arrMenu;
  5009. unset ($this->arrMenu);*/
  5010. if ($action == 'add')
  5011. $return .= '<div class="row"><div class="form_header">' . get_lang('CreateTheExercise') . '&nbsp;:</div></div>';
  5012. elseif ($action == 'move') $return .= '<p class="lp_title">' . get_lang('MoveTheCurrentExercise') . '&nbsp;:</p>';
  5013. else
  5014. //$return .= '<p class="form_header">' . get_lang('EditCurrentExecice') . '&nbsp;:</p>';
  5015. $return .= '<div class="row"><div class="form_header">' . get_lang('EditCurrentExecice') . '&nbsp;:</div></div>';
  5016. if (isset ($_GET['edit']) && $_GET['edit'] == 'true') {
  5017. $return .= Display :: return_warning_message('<p class="lp_title">' . get_lang('Warning') . ' !</p>' . get_lang('WarningEditingDocument'));
  5018. }
  5019. $return .= '<form method="POST">';
  5020. $return .= '<table cellpadding="0" cellspacing="0" class="lp_form">';
  5021. $return .= '<tr>';
  5022. $return .= '<td class="label"><label for="idParent">' . get_lang('Parent') . ' :</label></td>';
  5023. $return .= '<td class="input">';
  5024. $return .= "\t\t\t\t" . '<select id="idParent" name="parent" onChange="javascript: load_cbo(this.value);" size="1">';
  5025. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
  5026. $arrHide = array (
  5027. $id
  5028. );
  5029. if (count($arrLP) > 0) {
  5030. for ($i = 0; $i < count($arrLP); $i++) {
  5031. if ($action != 'add') {
  5032. 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)) {
  5033. $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>';
  5034. } else {
  5035. $arrHide[] = $arrLP[$i]['id'];
  5036. }
  5037. } else {
  5038. if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
  5039. $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>';
  5040. }
  5041. }
  5042. reset($arrLP);
  5043. }
  5044. $return .= "\t\t\t\t" . '</select>';
  5045. $return .= '</td>';
  5046. $return .= '</tr>';
  5047. $return .= '<tr>';
  5048. $return .= '<td class="label"><label for="previous">' . get_lang('Position') . ' :</label></td>';
  5049. $return .= '<td class="input">';
  5050. $return .= "\t\t\t\t" . '<select id="previous" name="previous" size="1">';
  5051. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . get_lang('FirstPosition') . '</option>';
  5052. for ($i = 0; $i < count($arrLP); $i++) {
  5053. if ($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) {
  5054. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5055. $selected = 'selected="selected" ';
  5056. elseif ($action == 'add') $selected = 'selected="selected" ';
  5057. else
  5058. $selected = '';
  5059. $return .= "\t\t\t\t\t" . '<option ' . $selected . 'value="' . $arrLP[$i]['id'] . '">' . get_lang('After') . ' "' . $arrLP[$i]['title'] . '"</option>';
  5060. }
  5061. }
  5062. $return .= "\t\t\t\t" . '</select>';
  5063. $return .= '</td>';
  5064. $return .= '</tr>';
  5065. if ($action != 'move') {
  5066. $return .= '<tr>';
  5067. $return .= '<td class="label"><label for="idTitle">' . get_lang('Title') . ' :</label></td>';
  5068. $return .= '<td class="input"><input id="idTitle" name="title" type="text" value="' . $item_title . '" /></td>';
  5069. $return .= '</tr>';
  5070. $id_prerequisite = 0;
  5071. if (is_array($arrLP) && count($arrLP) > 0) {
  5072. foreach ($arrLP as $key => $value) {
  5073. if ($value['id'] == $id) {
  5074. $id_prerequisite = $value['prerequisite'];
  5075. break;
  5076. }
  5077. }
  5078. $arrHide = array ();
  5079. for ($i = 0; $i < count($arrLP); $i++) {
  5080. if ($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter') {
  5081. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5082. $s_selected_position = $arrLP[$i]['id'];
  5083. elseif ($action == 'add') $s_selected_position = 0;
  5084. $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
  5085. }
  5086. }
  5087. }
  5088. //$return .= '<tr>';
  5089. //$return .= '<td class="label"><label for="idPrerequisites">'.get_lang('Prerequisites').' :</label></td>';
  5090. //$return .= '<td class="input"><select name="prerequisites" id="prerequisites"><option value="0">'.get_lang('NoPrerequisites').'</option>';
  5091. /*
  5092. foreach ($arrHide as $key => $value) {
  5093. if ($key == $s_selected_position && $action == 'add') {
  5094. $return .= '<option value="' . $key . '" selected="selected">' . $value['value'] . '</option>';
  5095. }
  5096. elseif ($key == $id_prerequisite && $action == 'edit') {
  5097. $return .= '<option value="' . $key . '" selected="selected">' . $value['value'] . '</option>';
  5098. } else {
  5099. $return .= '<option value="' . $key . '">' . $value['value'] . '</option>';
  5100. }
  5101. }
  5102. */
  5103. //$return .= "</select></td>";
  5104. //$return .= '</tr>';
  5105. //$return .= '<tr>';
  5106. //$return .= '</tr>';
  5107. }
  5108. $return .= '<tr>';
  5109. $return .= '<td>&nbsp; </td><td><button class="save" name="submit_button" action="edit" type="submit">' . get_lang('SaveHotpotatoes') . '</button></td>';
  5110. $return .= '</tr>';
  5111. $return .= '</table>';
  5112. if ($action == 'move') {
  5113. $return .= '<input name="title" type="hidden" value="' . $item_title . '" />';
  5114. $return .= '<input name="description" type="hidden" value="' . $item_description . '" />';
  5115. }
  5116. if (is_numeric($extra_info)) {
  5117. $return .= '<input name="path" type="hidden" value="' . $extra_info . '" />';
  5118. }
  5119. elseif (is_array($extra_info)) {
  5120. $return .= '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />';
  5121. }
  5122. $return .= '<input name="type" type="hidden" value="' . TOOL_HOTPOTATOES . '" />';
  5123. $return .= '<input name="post_time" type="hidden" value="' . time() . '" />';
  5124. $return .= '</form>';
  5125. return $return;
  5126. }
  5127. /**
  5128. * Return the form to display the forum edit/add option
  5129. * @param string Action (add/edit)
  5130. * @param integer ID of the lp_item if already exists
  5131. * @param mixed Forum ID or title
  5132. * @return string HTML form
  5133. */
  5134. public function display_forum_form($action = 'add', $id = 0, $extra_info = '') {
  5135. global $charset;
  5136. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  5137. $tbl_forum = Database :: get_course_table(TABLE_FORUM);
  5138. if ($id != 0 && is_array($extra_info)) {
  5139. $item_title = stripslashes($extra_info['title']);
  5140. }
  5141. elseif (is_numeric($extra_info)) {
  5142. $sql_forum = "
  5143. SELECT
  5144. forum_title as title, forum_comment as comment
  5145. FROM " . $tbl_forum . "
  5146. WHERE forum_id = " . $extra_info;
  5147. $result = Database::query($sql_forum);
  5148. $row = Database :: fetch_array($result);
  5149. $item_title = $row['title'];
  5150. $item_description = $row['comment'];
  5151. } else {
  5152. $item_title = '';
  5153. $item_description = '';
  5154. }
  5155. $return = ' <div class="row">
  5156. <div class="form_header">';
  5157. if ($id != 0 && is_array($extra_info))
  5158. $parent = $extra_info['parent_item_id'];
  5159. else
  5160. $parent = 0;
  5161. $sql = "
  5162. SELECT *
  5163. FROM " . $tbl_lp_item . "
  5164. WHERE
  5165. lp_id = " . $this->lp_id;
  5166. $result = Database::query($sql);
  5167. $arrLP = array ();
  5168. while ($row = Database :: fetch_array($result)) {
  5169. $arrLP[] = array (
  5170. 'id' => $row['id'],
  5171. 'item_type' => $row['item_type'],
  5172. 'title' => $row['title'],
  5173. 'path' => $row['path'],
  5174. 'description' => $row['description'],
  5175. 'parent_item_id' => $row['parent_item_id'],
  5176. 'previous_item_id' => $row['previous_item_id'],
  5177. 'next_item_id' => $row['next_item_id'],
  5178. 'display_order' => $row['display_order'],
  5179. 'max_score' => $row['max_score'],
  5180. 'min_score' => $row['min_score'],
  5181. 'mastery_score' => $row['mastery_score'],
  5182. 'prerequisite' => $row['prerequisite']
  5183. );
  5184. }
  5185. $this->tree_array($arrLP);
  5186. $arrLP = $this->arrMenu;
  5187. unset ($this->arrMenu);
  5188. if ($action == 'add')
  5189. $return .= get_lang('CreateTheForum') . '&nbsp;:';
  5190. elseif ($action == 'move') $return .= get_lang('MoveTheCurrentForum') . '&nbsp;:';
  5191. else
  5192. $return .= get_lang('EditCurrentForum') . '&nbsp;:';
  5193. $return .= ' </div>
  5194. </div>';
  5195. $return .= '<div class="sectioncomment">';
  5196. $return .= '<form method="POST">';
  5197. $return .= '<table class="lp_form">';
  5198. if ($action != 'move') {
  5199. $return .= '<tr>';
  5200. $return .= '<td class="label"><label for="idTitle">' . get_lang('Title') . '</label></td>';
  5201. $return .= '<td class="input"><input id="idTitle" size="44" name="title" type="text" value="' . $item_title . '" class="learnpath_item_form" /></td>';
  5202. $return .= '</tr>';
  5203. }
  5204. $return .= '<tr>';
  5205. $return .= '<td class="label"><label for="idParent">' . get_lang('Parent') . '</label></td>';
  5206. $return .= '<td class="input">';
  5207. $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">';
  5208. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
  5209. $arrHide = array (
  5210. $id
  5211. );
  5212. //$parent_item_id = $_SESSION['parent_item_id'];
  5213. for ($i = 0; $i < count($arrLP); $i++) {
  5214. if ($action != 'add') {
  5215. 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)) {
  5216. $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>';
  5217. } else {
  5218. $arrHide[] = $arrLP[$i]['id'];
  5219. }
  5220. } else {
  5221. if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
  5222. $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>';
  5223. }
  5224. }
  5225. if (is_array($arrLP)) {
  5226. reset($arrLP);
  5227. }
  5228. $return .= "\t\t\t\t" . '</select>';
  5229. $return .= '</td>';
  5230. $return .= '</tr>';
  5231. $return .= '<tr>';
  5232. $return .= '<td class="label"><label for="previous">' . get_lang('Position') . '</label></td>';
  5233. $return .= '<td class="input">';
  5234. $return .= "\t\t\t\t" . '<select id="previous" name="previous" style="width:100%;" size="1" class="learnpath_item_form">';
  5235. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . get_lang('FirstPosition') . '</option>';
  5236. for ($i = 0; $i < count($arrLP); $i++) {
  5237. if ($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) {
  5238. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5239. $selected = 'selected="selected" ';
  5240. elseif ($action == 'add') $selected = 'selected="selected" ';
  5241. else
  5242. $selected = '';
  5243. $return .= "\t\t\t\t\t" . '<option ' . $selected . 'value="' . $arrLP[$i]['id'] . '">' . get_lang('After') . ' "' . $arrLP[$i]['title'] . '"</option>';
  5244. }
  5245. }
  5246. $return .= "\t\t\t\t" . '</select>';
  5247. $return .= '</td>';
  5248. $return .= '</tr>';
  5249. if ($action != 'move') {
  5250. $return .= '<tr>';
  5251. $return .= '</tr>';
  5252. $id_prerequisite = 0;
  5253. if (is_array($arrLP)) {
  5254. foreach ($arrLP as $key => $value) {
  5255. if ($value['id'] == $id) {
  5256. $id_prerequisite = $value['prerequisite'];
  5257. break;
  5258. }
  5259. }
  5260. }
  5261. $arrHide = array ();
  5262. for ($i = 0; $i < count($arrLP); $i++) {
  5263. if ($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter') {
  5264. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5265. $s_selected_position = $arrLP[$i]['id'];
  5266. elseif ($action == 'add') $s_selected_position = 0;
  5267. $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
  5268. }
  5269. }
  5270. $return .= '</tr>';
  5271. }
  5272. $return .= '<tr>';
  5273. if ($action == 'add') {
  5274. $return .= '<td>&nbsp;</td><td><button class="save" name="submit_button" type="submit"> ' . get_lang('AddForumToCourse') . ' </button></td>';
  5275. } else {
  5276. $return .= '<td>&nbsp;</td><td><button class="save" name="submit_button" type="submit"> ' . get_lang('EditCurrentForum') . ' </button></td>';
  5277. }
  5278. $return .= '</tr>';
  5279. $return .= '</table>';
  5280. if ($action == 'move') {
  5281. $return .= '<input name="title" type="hidden" value="' . $item_title . '" />';
  5282. $return .= '<input name="description" type="hidden" value="' . $item_description . '" />';
  5283. }
  5284. if (is_numeric($extra_info)) {
  5285. $return .= '<input name="path" type="hidden" value="' . $extra_info . '" />';
  5286. }
  5287. elseif (is_array($extra_info)) {
  5288. $return .= '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />';
  5289. }
  5290. $return .= '<input name="type" type="hidden" value="' . TOOL_FORUM . '" />';
  5291. $return .= '<input name="post_time" type="hidden" value="' . time() . '" />';
  5292. $return .= '</form>';
  5293. $return .= '</div>';
  5294. return $return;
  5295. }
  5296. /**
  5297. * Return HTML form to add/edit forum threads
  5298. * @param string Action (add/edit)
  5299. * @param integer Item ID if already exists in learning path
  5300. * @param mixed Extra information (thread ID if integer)
  5301. * @return string HTML form
  5302. */
  5303. public function display_thread_form($action = 'add', $id = 0, $extra_info = '') {
  5304. global $charset;
  5305. echo '
  5306. <style>
  5307. div.row div.label {
  5308. width:110px;
  5309. }
  5310. div.row div.formw {
  5311. width: 82%;
  5312. }
  5313. </style>';
  5314. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  5315. $tbl_forum = Database :: get_course_table(TABLE_FORUM_THREAD);
  5316. if ($id != 0 && is_array($extra_info)) {
  5317. $item_title = stripslashes($extra_info['title']);
  5318. }
  5319. elseif (is_numeric($extra_info)) {
  5320. $sql_forum = "
  5321. SELECT
  5322. thread_title as title
  5323. FROM " . $tbl_forum . "
  5324. WHERE thread_id = " . $extra_info;
  5325. $result = Database::query($sql_forum);
  5326. $row = Database :: fetch_array($result);
  5327. $item_title = $row['title'];
  5328. $item_description = '';
  5329. } else {
  5330. $item_title = '';
  5331. $item_description = '';
  5332. }
  5333. $return = '<div style="margin:3px 12px;">';
  5334. if ($id != 0 && is_array($extra_info))
  5335. $parent = $extra_info['parent_item_id'];
  5336. else
  5337. $parent = 0;
  5338. $sql = "
  5339. SELECT *
  5340. FROM " . $tbl_lp_item . "
  5341. WHERE
  5342. lp_id = " . $this->lp_id;
  5343. $result = Database::query($sql);
  5344. $arrLP = array ();
  5345. while ($row = Database :: fetch_array($result)) {
  5346. $arrLP[] = array (
  5347. 'id' => $row['id'],
  5348. 'item_type' => $row['item_type'],
  5349. 'title' => $row['title'],
  5350. 'path' => $row['path'],
  5351. 'description' => $row['description'],
  5352. 'parent_item_id' => $row['parent_item_id'],
  5353. 'previous_item_id' => $row['previous_item_id'],
  5354. 'next_item_id' => $row['next_item_id'],
  5355. 'display_order' => $row['display_order'],
  5356. 'max_score' => $row['max_score'],
  5357. 'min_score' => $row['min_score'],
  5358. 'mastery_score' => $row['mastery_score'],
  5359. 'prerequisite' => $row['prerequisite']
  5360. );
  5361. }
  5362. $this->tree_array($arrLP);
  5363. $arrLP = $this->arrMenu;
  5364. unset ($this->arrMenu);
  5365. if ($action == 'add')
  5366. $return .= '<p class="lp_title">' . get_lang('CreateTheForum') . '&nbsp;:</p>';
  5367. elseif ($action == 'move') $return .= '<p class="lp_title">' . get_lang('MoveTheCurrentForum') . '&nbsp;:</p>';
  5368. else
  5369. $return .= '<p class="lp_title">' . get_lang('EditCurrentForum') . '&nbsp;:</p>';
  5370. $return .= '<form method="POST">';
  5371. $return .= '<table cellpadding="0" cellspacing="0" class="lp_form">';
  5372. $return .= '<tr>';
  5373. $return .= '<td class="label"><label for="idParent">' . get_lang('Parent') . '&nbsp;:</label></td>';
  5374. $return .= '<td class="input">';
  5375. $return .= "\t\t\t\t" . '<select id="idParent" name="parent" onChange="javascript: load_cbo(this.value);" size="1">';
  5376. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
  5377. $arrHide = array (
  5378. $id
  5379. );
  5380. for ($i = 0; $i < count($arrLP); $i++) {
  5381. if ($action != 'add') {
  5382. 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)) {
  5383. $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>';
  5384. } else {
  5385. $arrHide[] = $arrLP[$i]['id'];
  5386. }
  5387. } else {
  5388. if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
  5389. $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>';
  5390. }
  5391. }
  5392. if ($arrLP != null) {
  5393. reset($arrLP);
  5394. }
  5395. $return .= "\t\t\t\t" . '</select>';
  5396. $return .= '</td>';
  5397. $return .= '</tr>';
  5398. $return .= '<tr>';
  5399. $return .= '<td class="label"><label for="previous">' . get_lang('Position') . '&nbsp;:</label></td>';
  5400. $return .= '<td class="input">';
  5401. $return .= "\t\t\t\t" . '<select id="previous" name="previous" size="1">';
  5402. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . get_lang('FirstPosition') . '</option>';
  5403. for ($i = 0; $i < count($arrLP); $i++) {
  5404. if ($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) {
  5405. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5406. $selected = 'selected="selected" ';
  5407. elseif ($action == 'add') $selected = 'selected="selected" ';
  5408. else
  5409. $selected = '';
  5410. $return .= "\t\t\t\t\t" . '<option ' . $selected . 'value="' . $arrLP[$i]['id'] . '">' . get_lang('After') . ' "' . $arrLP[$i]['title'] . '"</option>';
  5411. }
  5412. }
  5413. $return .= "\t\t\t\t" . '</select>';
  5414. $return .= '</td>';
  5415. $return .= '</tr>';
  5416. if ($action != 'move') {
  5417. $return .= '<tr>';
  5418. $return .= '<td class="label"><label for="idTitle">' . get_lang('Title') . '&nbsp;:</label></td>';
  5419. $return .= '<td class="input"><input id="idTitle" name="title" type="text" value="' . $item_title . '" /></td>';
  5420. $return .= '</tr>';
  5421. $return .= '<tr>';
  5422. $return .= '</tr>';
  5423. $id_prerequisite = 0;
  5424. if ($arrLP != null) {
  5425. foreach ($arrLP as $key => $value) {
  5426. if ($value['id'] == $id) {
  5427. $id_prerequisite = $value['prerequisite'];
  5428. break;
  5429. }
  5430. }
  5431. }
  5432. $arrHide = array();
  5433. for ($i = 0; $i < count($arrLP); $i++) {
  5434. if ($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter') {
  5435. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5436. $s_selected_position = $arrLP[$i]['id'];
  5437. elseif ($action == 'add') $s_selected_position = 0;
  5438. $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
  5439. }
  5440. }
  5441. $return .= '<tr>';
  5442. $return .= '<td class="label"><label for="idPrerequisites">' . get_lang('Prerequisites') . '&nbsp;:</label></td>';
  5443. $return .= '<td class="input"><select name="prerequisites" id="prerequisites"><option value="0">' . get_lang('NoPrerequisites') . '</option>';
  5444. foreach ($arrHide as $key => $value) {
  5445. if ($key == $s_selected_position && $action == 'add') {
  5446. $return .= '<option value="' . $key . '" selected="selected">' . $value['value'] . '</option>';
  5447. }
  5448. elseif ($key == $id_prerequisite && $action == 'edit') {
  5449. $return .= '<option value="' . $key . '" selected="selected">' . $value['value'] . '</option>';
  5450. } else {
  5451. $return .= '<option value="' . $key . '">' . $value['value'] . '</option>';
  5452. }
  5453. }
  5454. $return .= "</select></td>";
  5455. $return .= '</tr>';
  5456. }
  5457. $return .= '<tr>';
  5458. $return .= '<td colspan="2">
  5459. <button class="save" name="submit_button" type="submit" value="'.get_lang('Ok').'" />'.get_lang('Ok').'</button></td>';
  5460. $return .= '</tr>';
  5461. $return .= '</table>';
  5462. if ($action == 'move') {
  5463. $return .= '<input name="title" type="hidden" value="' . $item_title . '" />';
  5464. $return .= '<input name="description" type="hidden" value="' . $item_description . '" />';
  5465. }
  5466. if (is_numeric($extra_info)) {
  5467. $return .= '<input name="path" type="hidden" value="' . $extra_info . '" />';
  5468. }
  5469. elseif (is_array($extra_info)) {
  5470. $return .= '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />';
  5471. }
  5472. $return .= '<input name="type" type="hidden" value="' . TOOL_THREAD . '" />';
  5473. $return .= '<input name="post_time" type="hidden" value="' . time() . '" />';
  5474. $return .= '</form>';
  5475. $return .= '</div>';
  5476. return $return;
  5477. }
  5478. /**
  5479. * Return the HTML form to display an item (generally a section/module item)
  5480. * @param string Item type (module/dokeos_module)
  5481. * @param string Title (optional, only when creating)
  5482. * @param string Action ('add'/'edit')
  5483. * @param integer lp_item ID
  5484. * @param mixed Extra info
  5485. * @return string HTML form
  5486. */
  5487. public function display_item_form($item_type, $title = '', $action = 'add', $id = 0, $extra_info = 'new') {
  5488. global $_course;
  5489. global $charset;
  5490. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  5491. if ($id != 0 && is_array($extra_info)) {
  5492. $item_title = $extra_info['title'];
  5493. $item_description = $extra_info['description'];
  5494. $item_path = api_get_path(WEB_COURSE_PATH) . $_course['path'] . '/scorm/' . $this->path . '/' . stripslashes($extra_info['path']);
  5495. } else {
  5496. $item_title = '';
  5497. $item_description = '';
  5498. }
  5499. $return = ' <div class="row">
  5500. <div class="form_header">';
  5501. if ($id != 0 && is_array($extra_info))
  5502. $parent = $extra_info['parent_item_id'];
  5503. else
  5504. $parent = 0;
  5505. $sql = "
  5506. SELECT *
  5507. FROM " . $tbl_lp_item . "
  5508. WHERE lp_id = " . $this->lp_id . " AND id != " . $id . " ";
  5509. if ($item_type == 'module')
  5510. $sql .= " AND parent_item_id = 0";
  5511. $result = Database::query($sql);
  5512. $arrLP = array ();
  5513. while ($row = Database :: fetch_array($result)) {
  5514. $arrLP[] = array (
  5515. 'id' => $row['id'],
  5516. 'item_type' => $row['item_type'],
  5517. 'title' => $row['title'],
  5518. 'path' => $row['path'],
  5519. 'description' => $row['description'],
  5520. 'parent_item_id' => $row['parent_item_id'],
  5521. 'previous_item_id' => $row['previous_item_id'],
  5522. 'next_item_id' => $row['next_item_id'],
  5523. 'max_score' => $row['max_score'],
  5524. 'min_score' => $row['min_score'],
  5525. 'mastery_score' => $row['mastery_score'],
  5526. 'prerequisite' => $row['prerequisite'],
  5527. 'display_order' => $row['display_order']
  5528. );
  5529. }
  5530. $this->tree_array($arrLP);
  5531. $arrLP = $this->arrMenu;
  5532. unset ($this->arrMenu);
  5533. $return .= $title;
  5534. $return .= ' </div>
  5535. </div>';
  5536. require_once api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php';
  5537. $form = new FormValidator('form', 'POST', api_get_self() . '?' . $_SERVER['QUERY_STRING']);
  5538. $defaults['title'] = api_html_entity_decode($item_title, ENT_QUOTES, $charset);
  5539. $defaults['description'] = $item_description;
  5540. $form->addElement('html', $return);
  5541. //$arrHide = array($id);
  5542. $arrHide[0]['value'] = Security :: remove_XSS($this->name);
  5543. $arrHide[0]['padding'] = 3;
  5544. $charset = api_get_system_encoding();
  5545. if ($item_type != 'module' && $item_type != 'dokeos_module') {
  5546. for ($i = 0; $i < count($arrLP); $i++) {
  5547. if ($action != 'add') {
  5548. 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)) {
  5549. $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
  5550. $arrHide[$arrLP[$i]['id']]['padding'] = 3 + $arrLP[$i]['depth'] * 10;
  5551. if ($parent == $arrLP[$i]['id']) {
  5552. $s_selected_parent = $arrHide[$arrLP[$i]['id']];
  5553. }
  5554. }
  5555. } else {
  5556. if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir') {
  5557. $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
  5558. $arrHide[$arrLP[$i]['id']]['padding'] = 3 + $arrLP[$i]['depth'] * 10;
  5559. if ($parent == $arrLP[$i]['id']) {
  5560. $s_selected_parent = $arrHide[$arrLP[$i]['id']];
  5561. }
  5562. }
  5563. }
  5564. }
  5565. if ($action != 'move') {
  5566. $form->addElement('text', 'title', get_lang('Title'), 'id="idTitle" class="learnpath_chapter_form" size="40%"');
  5567. $form->applyFilter('title', 'html_filter');
  5568. $form->addRule('title', '<div class="required">' . get_lang('ThisFieldIsRequired'), 'required');
  5569. //$form->addElement('textarea', 'description', get_lang('Description').' :', 'id="idDescription"');
  5570. } else {
  5571. $form->addElement('hidden', 'title');
  5572. }
  5573. $parent_select = & $form->addElement('select', 'parent', get_lang('Parent'), '', 'class="learnpath_chapter_form" style="width:37%;" id="idParent" onchange="javascript: load_cbo(this.value);"');
  5574. foreach ($arrHide as $key => $value) {
  5575. $parent_select->addOption($value['value'], $key, 'style="padding-left:' . $value['padding'] . 'px;"');
  5576. }
  5577. $parent_select->setSelected($s_selected_parent);
  5578. }
  5579. if (is_array($arrLP)) {
  5580. reset($arrLP);
  5581. }
  5582. $arrHide = array ();
  5583. // POSITION
  5584. for ($i = 0; $i < count($arrLP); $i++) {
  5585. if ($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) {
  5586. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5587. $s_selected_position = $arrLP[$i]['id'];
  5588. elseif ($action == 'add') $s_selected_position = $arrLP[$i]['id'];
  5589. $arrHide[$arrLP[$i]['id']]['value'] = get_lang('After') . ' "' . $arrLP[$i]['title'] . '"';
  5590. }
  5591. }
  5592. $position = & $form->addElement('select', 'previous', get_lang('Position'), '', 'id="previous" class="learnpath_chapter_form" style="width:37%;"');
  5593. $position->addOption(get_lang('FirstPosition'), 0, 'style="padding-left:' . $value['padding'] . 'px;"');
  5594. foreach ($arrHide as $key => $value) {
  5595. $position->addOption($value['value'] . '"', $key, 'style="padding-left:' . $value['padding'] . 'px;"');
  5596. }
  5597. if (!empty ($s_selected_position)) {
  5598. $position->setSelected($s_selected_position);
  5599. }
  5600. if (is_array($arrLP)) {
  5601. reset($arrLP);
  5602. }
  5603. $form->addElement('style_submit_button', 'submit_button', get_lang('SaveSection'), 'class="save"');
  5604. if ($item_type == 'module' || $item_type == 'dokeos_module') {
  5605. $form->addElement('hidden', 'parent', '0');
  5606. }
  5607. $extension = pathinfo($item_path, PATHINFO_EXTENSION);
  5608. if (($item_type == 'asset' || $item_type == 'sco') && ($extension == 'html' || $extension == 'htm')) {
  5609. if ($item_type == 'sco') {
  5610. $form->addElement('html', '<script type="text/javascript">alert("' . get_lang('WarningWhenEditingScorm') . '")</script>');
  5611. }
  5612. $renderer = $form->defaultRenderer();
  5613. $renderer->setElementTemplate('<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{label}<br />{element}', 'content_lp');
  5614. $form->addElement('html_editor', 'content_lp', '', null, array('ToolbarSet' => 'LearningPathDocuments', 'Width' => '100%', 'Height' => '400', 'FullPage' => true));
  5615. $defaults['content_lp'] = file_get_contents($item_path);
  5616. }
  5617. $form->addElement('hidden', 'type', 'dokeos_' . $item_type);
  5618. $form->addElement('hidden', 'post_time', time());
  5619. $form->setDefaults($defaults);
  5620. return $form->return_form();
  5621. }
  5622. /**
  5623. * Returns the form to update or create a document
  5624. * @param string Action (add/edit)
  5625. * @param integer ID of the lp_item (if already exists)
  5626. * @param mixed Integer if document ID, string if info ('new')
  5627. * @return string HTML form
  5628. */
  5629. public function display_document_form($action = 'add', $id = 0, $extra_info = 'new') {
  5630. global $charset;
  5631. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  5632. $tbl_doc = Database :: get_course_table(TABLE_DOCUMENT);
  5633. $path_parts = pathinfo($extra_info['dir']);
  5634. $no_display_edit_textarea = false;
  5635. //If action==edit document
  5636. //We don't display the document form if it's not an editable document (html or txt file)
  5637. if ($action == "edit") {
  5638. if (is_array($extra_info)) {
  5639. if ($path_parts['extension'] != "txt" && $path_parts['extension'] != "html") {
  5640. $no_display_edit_textarea = true;
  5641. }
  5642. }
  5643. }
  5644. $no_display_add = false;
  5645. // If action==add an existing document
  5646. // We don't display the document form if it's not an editable document (html or txt file).
  5647. if ($action == "add") {
  5648. if (is_numeric($extra_info)) {
  5649. $sql_doc = "SELECT path FROM " . $tbl_doc . "WHERE id = " . Database :: escape_string($extra_info);
  5650. $result = Database::query($sql_doc);
  5651. $path_file = Database :: result($result, 0, 0);
  5652. $path_parts = pathinfo($path_file);
  5653. if ($path_parts['extension'] != "txt" && $path_parts['extension'] != "html") {
  5654. $no_display_add = true;
  5655. }
  5656. }
  5657. }
  5658. if ($id != 0 && is_array($extra_info)) {
  5659. $item_title = stripslashes($extra_info['title']);
  5660. $item_description = stripslashes($extra_info['description']);
  5661. $item_terms = stripslashes($extra_info['terms']);
  5662. if (empty ($item_title)) {
  5663. $path_parts = pathinfo($extra_info['path']);
  5664. $item_title = stripslashes($path_parts['filename']);
  5665. }
  5666. } elseif (is_numeric($extra_info)) {
  5667. $sql_doc = "SELECT path, title FROM " . $tbl_doc . "
  5668. WHERE id = " . Database :: escape_string($extra_info);
  5669. $result = Database::query($sql_doc);
  5670. $row = Database :: fetch_array($result);
  5671. $explode = explode('.', $row['title']);
  5672. if (count($explode) > 1) {
  5673. for ($i = 0; $i < count($explode) - 1; $i++)
  5674. $item_title .= $explode[$i];
  5675. } else {
  5676. $item_title = $row['title'];
  5677. }
  5678. $item_title = str_replace('_', ' ', $item_title);
  5679. if (empty ($item_title)) {
  5680. $path_parts = pathinfo($row['path']);
  5681. $item_title = stripslashes($path_parts['filename']);
  5682. }
  5683. } else {
  5684. $item_title = '';
  5685. $item_description = '';
  5686. }
  5687. $return = ' <div class="row">
  5688. <div class="form_header">';
  5689. if ($id != 0 && is_array($extra_info))
  5690. $parent = $extra_info['parent_item_id'];
  5691. else
  5692. $parent = 0;
  5693. $sql = "SELECT * FROM " . $tbl_lp_item . "
  5694. WHERE lp_id = " . $this->lp_id;
  5695. $result = Database::query($sql);
  5696. $arrLP = array ();
  5697. while ($row = Database :: fetch_array($result)) {
  5698. $arrLP[] = array (
  5699. 'id' => $row['id'],
  5700. 'item_type' => $row['item_type'],
  5701. 'title' => $row['title'],
  5702. 'path' => $row['path'],
  5703. 'description' => $row['description'],
  5704. 'parent_item_id' => $row['parent_item_id'],
  5705. 'previous_item_id' => $row['previous_item_id'],
  5706. 'next_item_id' => $row['next_item_id'],
  5707. 'display_order' => $row['display_order'],
  5708. 'max_score' => $row['max_score'],
  5709. 'min_score' => $row['min_score'],
  5710. 'mastery_score' => $row['mastery_score'],
  5711. 'prerequisite' => $row['prerequisite']
  5712. );
  5713. }
  5714. $this->tree_array($arrLP);
  5715. $arrLP = $this->arrMenu;
  5716. unset ($this->arrMenu);
  5717. if ($action == 'add') {
  5718. $return .= get_lang('CreateTheDocument');
  5719. }
  5720. elseif ($action == 'move') {
  5721. $return .= get_lang('MoveTheCurrentDocument');
  5722. } else {
  5723. $return .= get_lang('EditTheCurrentDocument');
  5724. }
  5725. $return .= '</div>
  5726. </div>';
  5727. if (isset ($_GET['edit']) && $_GET['edit'] == 'true') {
  5728. $return .= Display :: return_warning_message('<strong>' . get_lang('Warning') . ' !</strong><br />' . get_lang('WarningEditingDocument'), false);
  5729. }
  5730. require_once api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php';
  5731. $form = new FormValidator('form', 'POST', api_get_self() . '?' . $_SERVER['QUERY_STRING'], '', 'enctype="multipart/form-data"');
  5732. $defaults['title'] = Security :: remove_XSS($item_title);
  5733. if (empty($item_title)) {
  5734. $defaults['title'] = Security::remove_XSS($item_title);
  5735. }
  5736. $defaults['description'] = $item_description;
  5737. $form->addElement('html', $return);
  5738. if ($action != 'move') {
  5739. $form->addElement('text', 'title', get_lang('Title'), 'id="idTitle" class="learnpath_item_form" size=44%');
  5740. $form->applyFilter('title', 'html_filter');
  5741. }
  5742. //$arrHide = array($id);
  5743. $arrHide[0]['value'] = $this->name;
  5744. $arrHide[0]['padding'] = 3;
  5745. for ($i = 0; $i < count($arrLP); $i++) {
  5746. if ($action != 'add') {
  5747. 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)) {
  5748. $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
  5749. $arrHide[$arrLP[$i]['id']]['padding'] = 3 + $arrLP[$i]['depth'] * 10;
  5750. if ($parent == $arrLP[$i]['id']) {
  5751. $s_selected_parent = $arrHide[$arrLP[$i]['id']];
  5752. }
  5753. }
  5754. } else {
  5755. if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir') {
  5756. $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
  5757. $arrHide[$arrLP[$i]['id']]['padding'] = 3 + $arrLP[$i]['depth'] * 10;
  5758. if ($parent == $arrLP[$i]['id']) {
  5759. $s_selected_parent = $arrHide[$arrLP[$i]['id']];
  5760. }
  5761. }
  5762. }
  5763. }
  5764. $parent_select = & $form->addElement('select', 'parent', get_lang('Parent'), '', 'class="learnpath_item_form" id="idParent" style="width:40%;" onchange="javascript: load_cbo(this.value);"');
  5765. $my_count=0;
  5766. foreach ($arrHide as $key => $value) {
  5767. if ($my_count!=0) {
  5768. // The LP name is also the first section and is not in the same charset like the other sections.
  5769. $value['value'] = Security :: remove_XSS($value['value']);
  5770. $parent_select->addOption($value['value'], $key, 'style="padding-left:' . $value['padding'] . 'px;"');
  5771. } else {
  5772. $value['value'] = Security :: remove_XSS($value['value']);
  5773. $parent_select->addOption($value['value'], $key, 'style="padding-left:' . $value['padding'] . 'px;"');
  5774. }
  5775. $my_count++;
  5776. }
  5777. if (!empty($id)) {
  5778. $parent_select->setSelected($parent);
  5779. } else {
  5780. $parent_item_id = $_SESSION['parent_item_id'];
  5781. $parent_select->setSelected($parent_item_id);
  5782. }
  5783. if (is_array($arrLP)) {
  5784. reset($arrLP);
  5785. }
  5786. $arrHide = array ();
  5787. //POSITION
  5788. for ($i = 0; $i < count($arrLP); $i++) {
  5789. if ($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) {
  5790. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5791. $s_selected_position = $arrLP[$i]['id'];
  5792. elseif ($action == 'add') $s_selected_position = $arrLP[$i]['id'];
  5793. $arrHide[$arrLP[$i]['id']]['value'] = get_lang('After') . ' "' . $arrLP[$i]['title'] . '"';
  5794. }
  5795. }
  5796. $position = & $form->addElement('select', 'previous', get_lang('Position'), '', 'id="previous" class="learnpath_item_form" style="width:40%;"');
  5797. $position->addOption(get_lang('FirstPosition'), 0);
  5798. foreach ($arrHide as $key => $value) {
  5799. $position->addOption($value['value'], $key, 'style="padding-left:' . $value['padding'] . 'px;"');
  5800. }
  5801. $position->setSelected($s_selected_position);
  5802. if (is_array($arrLP)) {
  5803. reset($arrLP);
  5804. }
  5805. if ($action != 'move') {
  5806. $id_prerequisite = 0;
  5807. if (is_array($arrLP)) {
  5808. foreach ($arrLP as $key => $value) {
  5809. if ($value['id'] == $id) {
  5810. $id_prerequisite = $value['prerequisite'];
  5811. break;
  5812. }
  5813. }
  5814. }
  5815. // Commented the prerequisites, only visible in edit (new document).
  5816. //$select_prerequisites=$form->addElement('select', 'prerequisites', get_lang('Prerequisites'),null,'id="prerequisites" class="learnpath_item_form" style="width:263px;"');
  5817. //$select_prerequisites->addOption(get_lang('NoPrerequisites'), 0);
  5818. // Form element for uploading an mp3 file.
  5819. //$form->addElement('file','mp3',get_lang('UploadMp3audio'),'id="mp3" size="33"');
  5820. //$form->addRule('file', 'The extension of the Song file should be *.mp3', 'filename', '/^.*\.mp3$/');
  5821. /* Code deprecated - moved to lp level (not lp-item).
  5822. if (api_get_setting('search_enabled') === 'true') {
  5823. //add terms field
  5824. $terms = $form->addElement('text', 'terms', get_lang('SearchFeatureTerms').'&nbsp;:', 'id="idTerms" class="learnpath_item_form"');
  5825. $terms->setValue($item_terms);
  5826. }
  5827. */
  5828. $arrHide = array ();
  5829. for ($i = 0; $i < count($arrLP); $i++) {
  5830. if ($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter') {
  5831. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5832. $s_selected_position = $arrLP[$i]['id'];
  5833. elseif ($action == 'add') $s_selected_position = $arrLP[$i]['id'];
  5834. $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
  5835. }
  5836. }
  5837. /* foreach ($arrHide as $key => $value) {
  5838. $select_prerequisites->addOption($value['value'], $key, 'style="padding-left:'.$value['padding'].'px;"');
  5839. if ($key == $s_selected_position && $action == 'add') {
  5840. $select_prerequisites -> setSelected(0);
  5841. }
  5842. elseif ($key == $id_prerequisite && $action == 'edit') {
  5843. $select_prerequisites -> setSelected($id_prerequisite);
  5844. }
  5845. }
  5846. */
  5847. if (!$no_display_add) {
  5848. if (($extra_info == 'new' || $extra_info['item_type'] == TOOL_DOCUMENT || $_GET['edit'] == 'true')) {
  5849. if (isset ($_POST['content']))
  5850. $content = stripslashes($_POST['content']);
  5851. elseif (is_array($extra_info)) {
  5852. //If it's an html document or a text file
  5853. if (!$no_display_edit_textarea) {
  5854. $content = $this->display_document($extra_info['path'], false, false);
  5855. }
  5856. }
  5857. elseif (is_numeric($extra_info)) $content = $this->display_document($extra_info, false, false);
  5858. else
  5859. $content = '';
  5860. if (!$no_display_edit_textarea) {
  5861. // We need to claculate here some specific settings for the online editor.
  5862. // The calculated settings work for documents in the Documents tool
  5863. // (on the root or in subfolders).
  5864. // For documents in native scorm packages it is unclear whether the
  5865. // online editor should be activated or not.
  5866. $relative_path = $extra_info['dir'];
  5867. if ($relative_path == 'n/') {
  5868. // A new document, it is in the root of the repository.
  5869. $relative_path = '';
  5870. $relative_prefix = '';
  5871. } else {
  5872. // The document already exists. Whe have to determine its relative path towards the repository root.
  5873. $relative_path = explode('/', $relative_path);
  5874. $cnt = count($relative_path) - 2;
  5875. if ($cnt < 0) {
  5876. $cnt = 0;
  5877. }
  5878. $relative_prefix = str_repeat('../', $cnt);
  5879. $relative_path = array_slice($relative_path, 1, $cnt);
  5880. $relative_path = implode('/', $relative_path);
  5881. if (strlen($relative_path) > 0) {
  5882. $relative_path = $relative_path . '/';
  5883. }
  5884. }
  5885. $editor_config = array('ToolbarSet' => 'LearningPathDocuments', 'Width' => '100%', 'Height' => '700', 'FullPage' => true,
  5886. 'CreateDocumentDir' => $relative_prefix,
  5887. 'CreateDocumentWebDir' => api_get_path(WEB_COURSE_PATH) . api_get_course_path() . '/document/',
  5888. 'BaseHref' => api_get_path(WEB_COURSE_PATH) . api_get_course_path() . '/document/' . $relative_path
  5889. );
  5890. if ($_GET['action'] == 'add_item') {
  5891. $class = 'add';
  5892. $text = get_lang('LPCreateDocument');
  5893. } else
  5894. if ($_GET['action'] == 'edit_item') {
  5895. $class = 'save';
  5896. $text = get_lang('SaveDocument');
  5897. }
  5898. $form->addElement('style_submit_button', 'submit_button', $text, 'class="' . $class . '"');
  5899. $renderer = $form->defaultRenderer();
  5900. $renderer->setElementTemplate('<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{label}<br />{element}', 'content_lp');
  5901. $form->addElement('html', '<div style="margin:3px 12px">');
  5902. $form->addElement('html_editor', 'content_lp', '', null, $editor_config);
  5903. $form->addElement('html', '</div>');
  5904. $defaults['content_lp'] = $content;
  5905. }
  5906. }
  5907. elseif (is_numeric($extra_info)) {
  5908. $form->addElement('style_submit_button', 'submit_button', get_lang('SaveDocument'), 'class="save"');
  5909. $return = $this->display_document($extra_info, true, true, true);
  5910. $form->addElement('html', $return);
  5911. }
  5912. }
  5913. }
  5914. if ($action == 'move') {
  5915. $form->addElement('hidden', 'title', $item_title);
  5916. $form->addElement('hidden', 'description', $item_description);
  5917. }
  5918. if (is_numeric($extra_info)) {
  5919. $form->addElement('style_submit_button', 'submit_button', get_lang('SaveDocument'), 'value="submit_button", class="save"');
  5920. $form->addElement('hidden', 'path', $extra_info);
  5921. }
  5922. elseif (is_array($extra_info)) {
  5923. $form->addElement('style_submit_button', 'submit_button', get_lang('SaveDocument'), 'class="save"');
  5924. $form->addElement('hidden', 'path', $extra_info['path']);
  5925. }
  5926. $form->addElement('hidden', 'type', TOOL_DOCUMENT);
  5927. $form->addElement('hidden', 'post_time', time());
  5928. $form->setDefaults($defaults);
  5929. return $form->return_form();
  5930. }
  5931. /**
  5932. * Return HTML form to add/edit a link item
  5933. * @param string Action (add/edit)
  5934. * @param integer Item ID if exists
  5935. * @param mixed Extra info
  5936. * @return string HTML form
  5937. */
  5938. public function display_link_form($action = 'add', $id = 0, $extra_info = '') {
  5939. global $charset;
  5940. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  5941. $tbl_link = Database :: get_course_table(TABLE_LINK);
  5942. if ($id != 0 && is_array($extra_info)) {
  5943. $item_title = stripslashes($extra_info['title']);
  5944. $item_description = stripslashes($extra_info['description']);
  5945. $item_url = stripslashes($extra_info['url']);
  5946. } elseif (is_numeric($extra_info)) {
  5947. $sql_link = "SELECT title, description, url FROM " . $tbl_link . " WHERE id = " . $extra_info;
  5948. $result = Database::query($sql_link);
  5949. $row = Database :: fetch_array($result);
  5950. $item_title = $row['title'];
  5951. $item_description = $row['description'];
  5952. $item_url = $row['url'];
  5953. } else {
  5954. $item_title = '';
  5955. $item_description = '';
  5956. $item_url = '';
  5957. }
  5958. $return = ' <div class="row">
  5959. <div class="form_header">';
  5960. if ($id != 0 && is_array($extra_info))
  5961. $parent = $extra_info['parent_item_id'];
  5962. else
  5963. $parent = 0;
  5964. $sql = "SELECT * FROM " . $tbl_lp_item . " WHERE lp_id = " . $this->lp_id;
  5965. $result = Database::query($sql);
  5966. $arrLP = array ();
  5967. while ($row = Database :: fetch_array($result)) {
  5968. $arrLP[] = array (
  5969. 'id' => $row['id'],
  5970. 'item_type' => $row['item_type'],
  5971. 'title' => $row['title'],
  5972. 'path' => $row['path'],
  5973. 'description' => $row['description'],
  5974. 'parent_item_id' => $row['parent_item_id'],
  5975. 'previous_item_id' => $row['previous_item_id'],
  5976. 'next_item_id' => $row['next_item_id'],
  5977. 'display_order' => $row['display_order'],
  5978. 'max_score' => $row['max_score'],
  5979. 'min_score' => $row['min_score'],
  5980. 'mastery_score' => $row['mastery_score'],
  5981. 'prerequisite' => $row['prerequisite']
  5982. );
  5983. }
  5984. $this->tree_array($arrLP);
  5985. $arrLP = $this->arrMenu;
  5986. unset ($this->arrMenu);
  5987. if ($action == 'add')
  5988. $return .= get_lang('CreateTheLink') . '&nbsp;:';
  5989. elseif ($action == 'move') $return .= get_lang('MoveCurrentLink') . '&nbsp;:';
  5990. else
  5991. $return .= get_lang('EditCurrentLink') . '&nbsp;:';
  5992. $return .= ' </div>
  5993. </div>';
  5994. $return .= '<div class="sectioncomment">';
  5995. $return .= '<form method="POST">';
  5996. $return .= '<table>';
  5997. if ($action != 'move') {
  5998. $return .= '<tr>';
  5999. $return .= '<td class="label"><label for="idTitle">' . get_lang('Title') . '</label></td>';
  6000. $return .= '<td class="input"><input id="idTitle" name="title" size="44" type="text" value="' . $item_title . '" class="learnpath_item_form"/></td>';
  6001. $return .= '</tr>';
  6002. }
  6003. $return .= '<tr>';
  6004. $return .= '<td class="label"><label for="idParent">' . get_lang('Parent') . '</label></td>';
  6005. $return .= '<td class="input">';
  6006. $return .= '<select id="idParent" style="width:100%;" name="parent" onChange="javascript: load_cbo(this.value);" class="learnpath_item_form" size="1">';
  6007. $return .= '<option class="top" value="0">' . $this->name . '</option>';
  6008. $arrHide = array (
  6009. $id
  6010. );
  6011. $parent_item_id = $_SESSION['parent_item_id'];
  6012. for ($i = 0; $i < count($arrLP); $i++) {
  6013. if ($action != 'add') {
  6014. 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)) {
  6015. $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>';
  6016. } else {
  6017. $arrHide[] = $arrLP[$i]['id'];
  6018. }
  6019. } else {
  6020. if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
  6021. $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>';
  6022. }
  6023. }
  6024. if (is_array($arrLP)) {
  6025. reset($arrLP);
  6026. }
  6027. $return .= "\t\t\t\t" . '</select>';
  6028. $return .= '</td>';
  6029. $return .= '</tr>';
  6030. $return .= '<tr>';
  6031. $return .= '<td class="label"><label for="previous">' . get_lang('Position') . '</label></td>';
  6032. $return .= '<td class="input">';
  6033. $return .= "\t\t\t\t" . '<select id="previous" name="previous" style="width:100%;" size="1" class="learnpath_item_form">';
  6034. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . get_lang('FirstPosition') . '</option>';
  6035. for ($i = 0; $i < count($arrLP); $i++) {
  6036. if ($arrLP[$i]['parent_item_id'] == $parent_item_id && $arrLP[$i]['id'] != $id) {
  6037. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  6038. $selected = 'selected="selected" ';
  6039. elseif ($action == 'add')
  6040. $selected = 'selected="selected" ';
  6041. else
  6042. $selected = '';
  6043. $return .= '<option ' . $selected . 'value="' . $arrLP[$i]['id'] . '">' . get_lang('After') . ' "' . $arrLP[$i]['title'] . '"</option>';
  6044. }
  6045. }
  6046. $return .= '</select>';
  6047. $return .= '</td>';
  6048. $return .= '</tr>';
  6049. if ($action != 'move') {
  6050. $return .= '<tr>';
  6051. $return .= '<td class="label"><label for="idURL">' . get_lang('Url') . '</label></td>';
  6052. $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>';
  6053. $return .= '</tr>';
  6054. $id_prerequisite = 0;
  6055. if (is_array($arrLP)) {
  6056. foreach ($arrLP as $key => $value) {
  6057. if ($value['id'] == $id) {
  6058. $id_prerequisite = $value['prerequisite'];
  6059. break;
  6060. }
  6061. }
  6062. }
  6063. $arrHide = array ();
  6064. for ($i = 0; $i < count($arrLP); $i++) {
  6065. if ($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter') {
  6066. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  6067. $s_selected_position = $arrLP[$i]['id'];
  6068. elseif ($action == 'add') $s_selected_position = 0;
  6069. $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
  6070. }
  6071. }
  6072. /*// Commented the prerequisites, only visible in edit (link).
  6073. $return .= '<tr>';
  6074. $return .= '<td class="label"><label for="idPrerequisites">'.get_lang('Prerequisites').'</label></td>';
  6075. $return .= '<td class="input"><select name="prerequisites" id="prerequisites" class="learnpath_item_form"><option value="0">'.get_lang('NoPrerequisites').'</option>';
  6076. foreach($arrHide as $key => $value) {
  6077. if ($key == $s_selected_position && $action == 'add') {
  6078. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  6079. }
  6080. elseif ($key == $id_prerequisite && $action == 'edit') {
  6081. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  6082. }
  6083. else {
  6084. $return .= '<option value="'.$key.'">'.$value['value'].'</option>';
  6085. }
  6086. }
  6087. $return .= "</select></td>";
  6088. */
  6089. $return .= '</tr>';
  6090. }
  6091. $return .= '<tr>';
  6092. if ($action == 'add') {
  6093. $return .= '<td>&nbsp;</td><td><button class="save" name="submit_button" type="submit">' . get_lang('AddLinkToCourse') . '</button></td>';
  6094. } else {
  6095. $return .= '<td>&nbsp;</td><td><button class="save" name="submit_button" type="submit">' . get_lang('EditCurrentLink') . '</button></td>';
  6096. }
  6097. $return .= '</tr>';
  6098. $return .= '</table>';
  6099. if ($action == 'move') {
  6100. $return .= '<input name="title" type="hidden" value="' . $item_title . '" />';
  6101. $return .= '<input name="description" type="hidden" value="' . $item_description . '" />';
  6102. }
  6103. if (is_numeric($extra_info)) {
  6104. $return .= '<input name="path" type="hidden" value="' . $extra_info . '" />';
  6105. }
  6106. elseif (is_array($extra_info)) {
  6107. $return .= '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />';
  6108. }
  6109. $return .= '<input name="type" type="hidden" value="' . TOOL_LINK . '" />';
  6110. $return .= '<input name="post_time" type="hidden" value="' . time() . '" />';
  6111. $return .= '</form>';
  6112. $return .= '</div>';
  6113. return $return;
  6114. }
  6115. /**
  6116. * Return HTML form to add/edit a student publication (work)
  6117. * @param string Action (add/edit)
  6118. * @param integer Item ID if already exists
  6119. * @param mixed Extra info (work ID if integer)
  6120. * @return string HTML form
  6121. */
  6122. public function display_student_publication_form($action = 'add', $id = 0, $extra_info = '') {
  6123. global $charset;
  6124. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  6125. $tbl_publication = Database :: get_course_table(TABLE_STUDENT_PUBLICATION);
  6126. if ($id != 0 && is_array($extra_info)) {
  6127. $item_title = stripslashes($extra_info['title']);
  6128. $item_description = stripslashes($extra_info['description']);
  6129. }
  6130. elseif (is_numeric($extra_info)) {
  6131. $sql_publication = "
  6132. SELECT
  6133. title,
  6134. description
  6135. FROM " . $tbl_publication . "
  6136. WHERE id = " . $extra_info;
  6137. $result = Database::query($sql_publication);
  6138. $row = Database :: fetch_array($result);
  6139. $item_title = $row['title'];
  6140. } else {
  6141. $item_title = get_lang('Student_publication');
  6142. }
  6143. $return = ' <div class="row">
  6144. <div class="form_header">';
  6145. if ($id != 0 && is_array($extra_info))
  6146. $parent = $extra_info['parent_item_id'];
  6147. else
  6148. $parent = 0;
  6149. $sql = "
  6150. SELECT *
  6151. FROM " . $tbl_lp_item . "
  6152. WHERE
  6153. lp_id = " . $this->lp_id;
  6154. $result = Database::query($sql);
  6155. $arrLP = array ();
  6156. while ($row = Database :: fetch_array($result)) {
  6157. $arrLP[] = array (
  6158. 'id' => $row['id'],
  6159. 'item_type' => $row['item_type'],
  6160. 'title' => $row['title'],
  6161. 'path' => $row['path'],
  6162. 'description' => $row['description'],
  6163. 'parent_item_id' => $row['parent_item_id'],
  6164. 'previous_item_id' => $row['previous_item_id'],
  6165. 'next_item_id' => $row['next_item_id'],
  6166. 'display_order' => $row['display_order'],
  6167. 'max_score' => $row['max_score'],
  6168. 'min_score' => $row['min_score'],
  6169. 'mastery_score' => $row['mastery_score'],
  6170. 'prerequisite' => $row['prerequisite']
  6171. );
  6172. }
  6173. $this->tree_array($arrLP);
  6174. $arrLP = $this->arrMenu;
  6175. unset ($this->arrMenu);
  6176. if ($action == 'add')
  6177. $return .= get_lang('Student_publication') . '&nbsp;:' . "\n";
  6178. elseif ($action == 'move') $return .= get_lang('MoveCurrentStudentPublication') . '&nbsp;:' . "\n";
  6179. else
  6180. $return .= get_lang('EditCurrentStudentPublication') . '&nbsp;:' . "\n";
  6181. $return .= ' </div>
  6182. </div>';
  6183. $return .= '<div class="sectioncomment">';
  6184. $return .= '<form method="POST">';
  6185. $return .= '<table class="lp_form">';
  6186. if ($action != 'move') {
  6187. $return .= '<tr>';
  6188. $return .= '<td class="label"><label for="idTitle">' . get_lang('Title') . '</label></td>';
  6189. $return .= '<td class="input"><input id="idTitle" name="title" size="44" type="text" value="' . $item_title . '" class="learnpath_item_form" /></td>';
  6190. $return .= '</tr>';
  6191. }
  6192. $return .= '<tr>';
  6193. $return .= '<td class="label"><label for="idParent">' . get_lang('Parent') . '</label></td>';
  6194. $return .= '<td class="input">';
  6195. $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">';
  6196. //$parent_item_id = $_SESSION['parent_item_id'];
  6197. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
  6198. $arrHide = array (
  6199. $id
  6200. );
  6201. for ($i = 0; $i < count($arrLP); $i++) {
  6202. if ($action != 'add') {
  6203. 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)) {
  6204. $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>';
  6205. } else {
  6206. $arrHide[] = $arrLP[$i]['id'];
  6207. }
  6208. } else {
  6209. if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
  6210. $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>';
  6211. }
  6212. }
  6213. if (is_array($arrLP)) {
  6214. reset($arrLP);
  6215. }
  6216. $return .= "\t\t\t\t" . '</select>';
  6217. $return .= '</td>';
  6218. $return .= '</tr>';
  6219. $return .= '<tr>';
  6220. $return .= '<td class="label"><label for="previous">' . get_lang('Position') . '</label></td>';
  6221. $return .= '<td class="input">';
  6222. $return .= "\t\t\t\t" . '<select id="previous" name="previous" style="width:100%;" size="1" class="learnpath_item_form">';
  6223. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . get_lang('FirstPosition') . '</option>';
  6224. for ($i = 0; $i < count($arrLP); $i++) {
  6225. if ($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) {
  6226. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  6227. $selected = 'selected="selected" ';
  6228. elseif ($action == 'add') $selected = 'selected="selected" ';
  6229. else
  6230. $selected = '';
  6231. $return .= "\t\t\t\t\t" . '<option ' . $selected . 'value="' . $arrLP[$i]['id'] . '">' . get_lang('After') . ' "' . $arrLP[$i]['title'] . '"</option>';
  6232. }
  6233. }
  6234. $return .= "\t\t\t\t" . '</select>';
  6235. $return .= '</td>';
  6236. $return .= '</tr>';
  6237. if ($action != 'move') {
  6238. $id_prerequisite = 0;
  6239. if (is_array($arrLP)) {
  6240. foreach ($arrLP as $key => $value) {
  6241. if ($value['id'] == $id) {
  6242. $id_prerequisite = $value['prerequisite'];
  6243. break;
  6244. }
  6245. }
  6246. }
  6247. $arrHide = array ();
  6248. for ($i = 0; $i < count($arrLP); $i++) {
  6249. if ($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter') {
  6250. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  6251. $s_selected_position = $arrLP[$i]['id'];
  6252. elseif ($action == 'add') $s_selected_position = 0;
  6253. $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
  6254. }
  6255. }
  6256. // Commented the prerequisites, only visible in edit (work).
  6257. /*
  6258. $return .= '<tr>';
  6259. $return .= '<td class="label"><label for="idPrerequisites">'.get_lang('Prerequisites').'</label></td>';
  6260. $return .= '<td class="input"><select name="prerequisites" id="prerequisites" class="learnpath_item_form"><option value="0">'.get_lang('NoPrerequisites').'</option>';
  6261. foreach($arrHide as $key => $value) {
  6262. if ($key == $s_selected_position && $action == 'add') {
  6263. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  6264. }
  6265. elseif ($key == $id_prerequisite && $action == 'edit') {
  6266. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  6267. }
  6268. else {
  6269. $return .= '<option value="'.$key.'">'.$value['value'].'</option>';
  6270. }
  6271. }
  6272. $return .= "</select></td>";
  6273. */
  6274. $return .= '</tr>';
  6275. }
  6276. $return .= '<tr>';
  6277. if ($action == 'add') {
  6278. $return .= '<td>&nbsp</td><td><button class="save" name="submit_button" type="submit">' . get_lang('AddAssignmentToCourse') . '</button></td>';
  6279. } else {
  6280. $return .= '<td>&nbsp</td><td><button class="save" name="submit_button" type="submit">' . get_lang('EditCurrentStudentPublication') . '</button></td>';
  6281. }
  6282. $return .= '</tr>';
  6283. $return .= '</table>';
  6284. if ($action == 'move') {
  6285. $return .= '<input name="title" type="hidden" value="' . $item_title . '" />';
  6286. $return .= '<input name="description" type="hidden" value="' . $item_description . '" />';
  6287. }
  6288. if (is_numeric($extra_info)) {
  6289. $return .= '<input name="path" type="hidden" value="' . $extra_info . '" />';
  6290. } elseif (is_array($extra_info)) {
  6291. $return .= '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />';
  6292. }
  6293. $return .= '<input name="type" type="hidden" value="' . TOOL_STUDENTPUBLICATION . '" />';
  6294. $return .= '<input name="post_time" type="hidden" value="' . time() . '" />';
  6295. $return .= '</form>';
  6296. $return .= '</div>';
  6297. return $return;
  6298. }
  6299. /**
  6300. * Displays the menu for manipulating a step
  6301. * @return string html
  6302. */
  6303. public function display_manipulate($item_id, $item_type = TOOL_DOCUMENT) {
  6304. global $charset, $_course;
  6305. $return = '<div class="actions">';
  6306. switch ($item_type) {
  6307. case 'dokeos_chapter' :
  6308. case 'chapter' :
  6309. // Commented the message cause should not show it.
  6310. //$lang = get_lang('TitleManipulateChapter');
  6311. break;
  6312. case 'dokeos_module' :
  6313. case 'module' :
  6314. // Commented the message cause should not show it.
  6315. //$lang = get_lang('TitleManipulateModule');
  6316. break;
  6317. case TOOL_DOCUMENT :
  6318. // Commented the message cause should not show it.
  6319. //$lang = get_lang('TitleManipulateDocument');
  6320. break;
  6321. case TOOL_LINK :
  6322. case 'link' :
  6323. // Commented the message cause should not show it.
  6324. //$lang = get_lang('TitleManipulateLink');
  6325. break;
  6326. case TOOL_QUIZ :
  6327. // Commented the message cause should not show it.
  6328. //$lang = get_lang('TitleManipulateQuiz');
  6329. break;
  6330. case TOOL_STUDENTPUBLICATION :
  6331. // Commented the message cause should not show it.
  6332. //$lang = get_lang('TitleManipulateStudentPublication');
  6333. break;
  6334. }
  6335. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  6336. $item_id = intval($item_id);
  6337. $sql = "SELECT * FROM " . $tbl_lp_item . " as lp WHERE lp.id = " . $item_id;
  6338. $result = Database::query($sql);
  6339. $row = Database::fetch_assoc($result);
  6340. $s_title = $row['title'];
  6341. // We display an audio player if needed.
  6342. if (!empty ($row['audio'])) {
  6343. $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>';
  6344. $return .= '<script type="text/javascript" src="../inc/lib/mediaplayer/swfobject.js"></script>';
  6345. $return .= '<script type="text/javascript">
  6346. var s1 = new SWFObject("../inc/lib/mediaplayer/player.swf","ply","250","20","9","#FFFFFF");
  6347. s1.addParam("allowscriptaccess","always");
  6348. s1.addParam("flashvars","file=../../courses/' . $_course['path'] . '/document/audio/' . $row['audio'] . '&autostart=true");
  6349. s1.write("container");
  6350. </script>';
  6351. }
  6352. // Commented ":" for message in step.
  6353. //$return .= $lang.': ';
  6354. $url = api_get_self() . '?cidReq='.Security::remove_XSS($_GET['cidReq']).'&view=build&id='.$item_id .'&lp_id='.$this->lp_id;
  6355. $return .= Display::url(Display::return_icon('edit.png', get_lang('Edit'), array(), 22), $url.'&action=edit_item&path_item=' . $row['path']);
  6356. $return .= Display::url(Display::return_icon('move.png', get_lang('Move'), array(), 22), $url.'&action=move_item');
  6357. // Commented for now as prerequisites cannot be added to chapters.
  6358. if ($item_type != 'dokeos_chapter' && $item_type != 'chapter') {
  6359. $return .= Display::url(Display::return_icon('accept.png', get_lang('Prerequisites'), array(), 22), $url.'&action=edit_item_prereq');
  6360. }
  6361. $return .= Display::url(Display::return_icon('delete.png', get_lang('Delete'), array(), 22), $url.'&action=delete_item');
  6362. // Get the audiorecorder. Use of ob_* functions since there are echos in the file.
  6363. ob_start();
  6364. $audio_recorder_studentview = 'false';
  6365. $audio_recorder_item_id = $item_id;
  6366. if (api_get_setting('service_visio', 'active') == 'true') {
  6367. include 'audiorecorder.inc.php';
  6368. }
  6369. $return .= ob_get_contents();
  6370. ob_end_clean();
  6371. // End of audiorecorder include
  6372. $return .= '</div>';
  6373. return $return;
  6374. }
  6375. /**
  6376. * Creates the javascript needed for filling up the checkboxes without page reload
  6377. *
  6378. * @return string
  6379. */
  6380. public function get_js_dropdown_array() {
  6381. $return = 'var child_name = new Array();' . "\n";
  6382. $return .= 'var child_value = new Array();' . "\n\n";
  6383. $return .= 'child_name[0] = new Array();' . "\n";
  6384. $return .= 'child_value[0] = new Array();' . "\n\n";
  6385. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  6386. $sql_zero = "
  6387. SELECT *
  6388. FROM " . $tbl_lp_item . "
  6389. WHERE
  6390. lp_id = " . $this->lp_id . " AND
  6391. parent_item_id = 0
  6392. ORDER BY display_order ASC";
  6393. $res_zero = Database::query($sql_zero);
  6394. global $charset;
  6395. $i = 0;
  6396. while ($row_zero = Database :: fetch_array($res_zero)) {
  6397. $return .= 'child_name[0][' . $i . '] = "' . get_lang('After') . ' \"' . $row_zero['title'] . '\"";' . "\n";
  6398. $return .= 'child_value[0][' . $i++ . '] = "' . $row_zero['id'] . '";' . "\n";
  6399. }
  6400. $return .= "\n";
  6401. $sql = "
  6402. SELECT *
  6403. FROM " . $tbl_lp_item . "
  6404. WHERE
  6405. lp_id = " . $this->lp_id;
  6406. $res = Database::query($sql);
  6407. while ($row = Database :: fetch_array($res)) {
  6408. $sql_parent = "
  6409. SELECT *
  6410. FROM " . $tbl_lp_item . "
  6411. WHERE parent_item_id = " . $row['id'] . "
  6412. ORDER BY display_order ASC";
  6413. $res_parent = Database::query($sql_parent);
  6414. $i = 0;
  6415. $return .= 'child_name[' . $row['id'] . '] = new Array();' . "\n";
  6416. $return .= 'child_value[' . $row['id'] . '] = new Array();' . "\n\n";
  6417. while ($row_parent = Database :: fetch_array($res_parent)) {
  6418. $return .= 'child_name[' . $row['id'] . '][' . $i . '] = "' . get_lang('After') . ' \"' . api_html_entity_decode($row_parent['title'], ENT_QUOTES) . '\"";' . "\n";
  6419. $return .= 'child_value[' . $row['id'] . '][' . $i++ . '] = "' . $row_parent['id'] . '";' . "\n";
  6420. }
  6421. $return .= "\n";
  6422. }
  6423. return $return;
  6424. }
  6425. /**
  6426. * Display the form to allow moving an item
  6427. * @param integer Item ID
  6428. * @return string HTML form
  6429. */
  6430. public function display_move_item($item_id) {
  6431. global $_course; //will disappear
  6432. global $charset;
  6433. $return = '';
  6434. if (is_numeric($item_id)) {
  6435. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  6436. $sql = "SELECT *
  6437. FROM " . $tbl_lp_item . "
  6438. WHERE id = " . $item_id;
  6439. $res = Database::query($sql);
  6440. $row = Database :: fetch_array($res);
  6441. switch ($row['item_type']) {
  6442. case 'dokeos_chapter' :
  6443. case 'dir' :
  6444. case 'asset' :
  6445. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6446. $return .= $this->display_item_form($row['item_type'], get_lang('MoveCurrentChapter'), 'move', $item_id, $row);
  6447. break;
  6448. case 'dokeos_module' :
  6449. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6450. $return .= $this->display_item_form($row['item_type'], 'Move th current module:', 'move', $item_id, $row);
  6451. break;
  6452. case TOOL_DOCUMENT :
  6453. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6454. $return .= $this->display_document_form('move', $item_id, $row);
  6455. break;
  6456. case TOOL_LINK :
  6457. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6458. $return .= $this->display_link_form('move', $item_id, $row);
  6459. break;
  6460. case TOOL_HOTPOTATOES :
  6461. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6462. $return .= $this->display_link_form('move', $item_id, $row);
  6463. break;
  6464. case TOOL_QUIZ :
  6465. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6466. $return .= $this->display_quiz_form('move', $item_id, $row);
  6467. break;
  6468. case TOOL_STUDENTPUBLICATION :
  6469. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6470. $return .= $this->display_student_publication_form('move', $item_id, $row);
  6471. break;
  6472. case TOOL_FORUM :
  6473. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6474. $return .= $this->display_forum_form('move', $item_id, $row);
  6475. break;
  6476. case TOOL_THREAD :
  6477. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6478. $return .= $this->display_forum_form('move', $item_id, $row);
  6479. break;
  6480. }
  6481. }
  6482. return $return;
  6483. }
  6484. /**
  6485. * Displays a basic form on the overview page for changing the item title and the item description.
  6486. * @param string $item_type
  6487. * @param string $title
  6488. * @param array $data
  6489. * @return string
  6490. */
  6491. public function display_item_small_form($item_type, $title = '', $data) {
  6492. global $charset;
  6493. $return .= '<div class="lp_small_form">';
  6494. $return .= '<p class="lp_title">' . $title . '</p>';
  6495. $return .= '<form method="post">';
  6496. $return .= '<table cellpadding="0" cellspacing="0" class="lp_form">';
  6497. $return .= '<tr>';
  6498. $return .= '<td class="label"><label for="idTitle">Title&nbsp;:</label></td>';
  6499. $return .= '<td class="input"><input class="small_form" id="idTitle" name="title" type="text" value="' . api_html_entity_decode($data['title'], ENT_QUOTES) . '" /></td>';
  6500. $return .= '</tr>';
  6501. // It said these lines of code - see SVN#11724 and SVN#10770
  6502. //$return .= '<tr>';
  6503. //$return .= '<td class="label"><label for="idDescription">Description&nbsp;:</label></td>';
  6504. //$return .= '<td class="input"><textarea class="small_form" id="idDescription" name="description" rows="4">' . $data['description'] . '</textarea></td>';
  6505. //$return .= '</tr>';
  6506. $return .= '<tr>';
  6507. $return .= '<td colspan="2"><button class="save" name="submit_button" type="submit">' . get_lang('Save') . '</button></td>';
  6508. $return .= '</tr>';
  6509. $return .= '</table>';
  6510. $return .= '<input name="parent" type="hidden" value="' . $data['parent_item_id'] . '"/>';
  6511. $return .= '<input name="previous" type="hidden" value="' . $data['previous_item_id'] . '"/>';
  6512. $return .= '</form>';
  6513. $return .= '</div>';
  6514. return $return;
  6515. }
  6516. /**
  6517. * Return HTML form to allow prerequisites selection
  6518. * @param integer Item ID
  6519. * @return string HTML form
  6520. */
  6521. public function display_item_prerequisites_form($item_id) {
  6522. global $charset;
  6523. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  6524. $item_id = intval($item_id);
  6525. /* Current prerequisite */
  6526. $sql = "SELECT * FROM $tbl_lp_item WHERE id = " . $item_id;
  6527. $result = Database::query($sql);
  6528. $row = Database::fetch_array($result);
  6529. $preq_id = $row['prerequisite'];
  6530. //$preq_mastery = $row['mastery_score'];
  6531. //$preq_max = $row['max_score'];
  6532. $return = $this->display_manipulate($item_id, TOOL_DOCUMENT);
  6533. $return = ' <div class="row">
  6534. <div class="form_header">';
  6535. $return .= get_lang('AddEditPrerequisites');
  6536. $return .= '</div></div>';
  6537. $return .= '<div class="sectioncomment">';
  6538. $return .= '<form method="POST">';
  6539. $return .= '<table class="data_table" style="width:650px">';
  6540. $return .= '<tr>';
  6541. $return .= '<th height="24">' . get_lang('Prerequisites') . '</th>';
  6542. $return .= '<th width="70" height="24">' . get_lang('Minimum') . '</th>';
  6543. $return .= '<th width="70" height="24">' . get_lang('Maximum') . '</th>';
  6544. $return .= '</tr>';
  6545. // Adding the none option to the prerequisites see http://www.chamilo.org/es/node/146
  6546. $return .= '<tr >';
  6547. $return .= '<td colspan="3" class="radio">';
  6548. $return .= '<input checked="checked" id="idNone" name="prerequisites" style="margin-left:0px; margin-right:10px;" type="radio" />';
  6549. $return .= '<label for="idNone">' . get_lang('None') . '</label>';
  6550. $return .= '</tr>';
  6551. $sql = "SELECT * FROM " . $tbl_lp_item . " WHERE lp_id = " . $this->lp_id;
  6552. $result = Database::query($sql);
  6553. $arrLP = array ();
  6554. while ($row = Database :: fetch_array($result)) {
  6555. $arrLP[] = array (
  6556. 'id' => $row['id'],
  6557. 'item_type' => $row['item_type'],
  6558. 'title' => $row['title'],
  6559. 'ref' => $row['ref'],
  6560. 'description' => $row['description'],
  6561. 'parent_item_id' => $row['parent_item_id'],
  6562. 'previous_item_id' => $row['previous_item_id'],
  6563. 'next_item_id' => $row['next_item_id'],
  6564. 'max_score' => $row['max_score'],
  6565. 'min_score' => $row['min_score'],
  6566. 'mastery_score' => $row['mastery_score'],
  6567. 'prerequisite' => $row['prerequisite'],
  6568. 'next_item_id' => $row['next_item_id'],
  6569. 'display_order' => $row['display_order']
  6570. );
  6571. if ($row['ref'] == $preq_id) {
  6572. $preq_mastery = $row['mastery_score'];
  6573. $preq_max = $row['max_score'];
  6574. }
  6575. }
  6576. $this->tree_array($arrLP);
  6577. $arrLP = $this->arrMenu;
  6578. unset ($this->arrMenu);
  6579. for ($i = 0; $i < count($arrLP); $i++) {
  6580. if ($arrLP[$i]['id'] == $item_id)
  6581. break;
  6582. $return .= '<tr>';
  6583. $return .= '<td class="radio"' . (($arrLP[$i]['item_type'] != TOOL_QUIZ && $arrLP[$i]['item_type'] != TOOL_HOTPOTATOES) ? ' colspan="3"' : '') . '>';
  6584. $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'] . '" />';
  6585. $icon_name = str_replace(' ', '', $arrLP[$i]['item_type']);
  6586. if (file_exists('../img/lp_' . $icon_name . '.png')) {
  6587. $return .= '<img alt="" src="../img/lp_' . $icon_name . '.png" style="margin-right:5px;" title="" />';
  6588. } else
  6589. if (file_exists('../img/lp_' . $icon_name . '.gif')) {
  6590. $return .= '<img alt="" src="../img/lp_' . $icon_name . '.gif" style="margin-right:5px;" title="" />';
  6591. } else {
  6592. $return .= Display::return_icon('folder_document.gif','',array('style'=>'margin-right:5px;'));
  6593. }
  6594. $return .= '<label for="id' . $arrLP[$i]['id'] . '">' . $arrLP[$i]['title'] . '</label>';
  6595. $return .= '</td>';
  6596. //$return .= '<td class="radio"' . (($arrLP[$i]['item_type'] != TOOL_HOTPOTATOES) ? ' colspan="3"' : '') . ' />';
  6597. if ($arrLP[$i]['item_type'] == TOOL_QUIZ) {
  6598. $return .= '<td class="exercise" style="border:1px solid #ccc;">';
  6599. $return .= '<center><input size="4" maxlength="3" name="min_' . $arrLP[$i]['id'] . '" type="text" value="' . (($arrLP[$i]['id'] == $preq_id) ? $preq_mastery : 0) . '" /></center>';
  6600. $return .= '</td>';
  6601. $return .= '<td class="exercise" style="border:1px solid #ccc;">';
  6602. $return .= '<center><input size="4" maxlength="3" name="max_' . $arrLP[$i]['id'] . '" type="text" value="' . $arrLP[$i]['max_score'] . '" disabled="true" /></center>';
  6603. $return .= '</td>';
  6604. }
  6605. if ($arrLP[$i]['item_type'] == TOOL_HOTPOTATOES) {
  6606. $return .= '<td class="exercise" style="border:1px solid #ccc;">';
  6607. $return .= '<center><input size="4" maxlength="3" name="min_' . $arrLP[$i]['id'] . '" type="text" value="' . (($arrLP[$i]['id'] == $preq_id) ? $preq_mastery : 0) . '" /></center>';
  6608. $return .= '</td>';
  6609. $return .= '<td class="exercise" style="border:1px solid #ccc;">';
  6610. $return .= '<center><input size="4" maxlength="3" name="max_' . $arrLP[$i]['id'] . '" type="text" value="' . $arrLP[$i]['max_score'] . '" disabled="true" /></center>';
  6611. $return .= '</td>';
  6612. }
  6613. $return .= '</tr>';
  6614. }
  6615. $return .= '<tr>';
  6616. $return .= '</tr>';
  6617. $return .= '</table>';
  6618. $return .= '<div style="padding-top:3px;">';
  6619. $return .= '<button class="save" name="submit_button" type="submit">' . get_lang('ModifyPrerequisites') . ' </button></td>';
  6620. $return .= '</div>';
  6621. $return .= '</form>';
  6622. $return .= '</div>';
  6623. return $return;
  6624. }
  6625. /**
  6626. * Return HTML list to allow prerequisites selection for lp
  6627. * @param integer Item ID
  6628. * @return string HTML form
  6629. */
  6630. public function display_lp_prerequisites_list() {
  6631. global $charset;
  6632. $lp_id = $this->lp_id;
  6633. $tbl_lp = Database :: get_course_table(TABLE_LP_MAIN);
  6634. // get current prerequisite
  6635. $sql = "SELECT * FROM $tbl_lp WHERE id = $lp_id ";
  6636. $result = Database::query($sql);
  6637. $row = Database :: fetch_array($result);
  6638. $preq_id = $row['prerequisite'];
  6639. $session_id = api_get_session_id();
  6640. $session_condition = api_get_session_condition($session_id, false);
  6641. $sql = "SELECT * FROM $tbl_lp $session_condition ORDER BY display_order ";
  6642. $rs = Database::query($sql);
  6643. $return = '';
  6644. $return .= '<select name="prerequisites" >';
  6645. $return .= '<option value="0">'.get_lang('None').'</option>';
  6646. if (Database::num_rows($rs) > 0) {
  6647. while ($row = Database::fetch_array($rs)) {
  6648. if ($row['id'] == $lp_id) {
  6649. continue;
  6650. }
  6651. $return .= '<option value="'.$row['id'].'" '.(($row['id']==$preq_id)?' selected ' : '').'>'.$row['name'].'</option>';
  6652. }
  6653. }
  6654. $return .= '</select>';
  6655. return $return;
  6656. }
  6657. /**
  6658. * Creates a list with all the documents in it
  6659. * @return string
  6660. */
  6661. public function get_documents() {
  6662. global $_course;
  6663. $tbl_doc = Database :: get_course_table(TABLE_DOCUMENT);
  6664. $tbl_item_prop = Database::get_course_table(TABLE_ITEM_PROPERTY);
  6665. $tbl_course = Database::get_main_table(TABLE_MAIN_COURSE);
  6666. $path = '/';
  6667. $path = Database::escape_string(str_replace('_', '\_', $path));
  6668. $added_slash = ($path == '/') ? '' : '/';
  6669. //condition for the session
  6670. $current_session_id = api_get_session_id();
  6671. $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]}')))";
  6672. $sql_doc = "SELECT docs.*
  6673. FROM $tbl_item_prop AS last, $tbl_doc AS docs
  6674. WHERE docs.id = last.ref
  6675. AND docs.path LIKE '".$path.$added_slash."%'
  6676. AND docs.path NOT LIKE '%_DELETED_%'
  6677. AND last.tool = '".TOOL_DOCUMENT."' $condition_session ORDER BY docs.path ASC";
  6678. $res_doc = Database::query($sql_doc);
  6679. //$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>';
  6680. $return = '<div class="lp_resource">';
  6681. $resources = Database::store_result($res_doc);
  6682. $resources_sorted = array();
  6683. $return .= '<div class="lp_resource_element">';
  6684. $return .= Display::return_icon('new_doc.gif', '', array(), 22);
  6685. $return .= Display::url(get_lang('NewDocument') , api_get_self().'?'.api_get_cidreq().'&action=add_item&type='.TOOL_DOCUMENT.'&lp_id='.$_SESSION['oLP']->lp_id);
  6686. $return .= '</div>';
  6687. // If you want to debug it, I advise you to do "echo" on the eval statements.
  6688. foreach ($resources as $resource) {
  6689. $resource_paths = explode('/', $resource['path']);
  6690. array_shift($resource_paths);
  6691. $path_to_eval = $last_path = '';
  6692. $is_file = false;
  6693. foreach ($resource_paths as $key => $resource_path) {
  6694. if (strpos($resource_path, '.') === false && $key != count($resource_paths) - 1) { // It's a folder.
  6695. $path_to_eval .= '["' . $resource_path . '"]["files"]';
  6696. } else
  6697. if (strpos($resource_path, '.') !== false)
  6698. $is_file = true;
  6699. $last_path = $resource_path;
  6700. }
  6701. if ($is_file) {
  6702. //eval ('$resources_sorted' . $path_to_eval . '[' . $resource['id'] . '] = "' . $last_path . '";');
  6703. //for backward compatibility
  6704. if (empty($resource['title'])) {
  6705. $resource['title'] = basename($resource['path']);
  6706. }
  6707. eval ('$resources_sorted' . $path_to_eval . '[' . $resource['id'] . '] = "' .$resource['title']."/". $last_path. '";');
  6708. } else {
  6709. eval ('$resources_sorted' . $path_to_eval . '["' . $last_path . '"]["id"]=' . $resource['id'] . ';');
  6710. }
  6711. }
  6712. $label = get_lang('Documents');
  6713. $new_array[$label] = array('id' => 0, 'files'=>$resources_sorted);
  6714. $return .= $this->write_resources_tree($new_array);
  6715. /*if (Database :: num_rows($res_doc) == 0) {
  6716. $return .= '<div class="lp_resource_element">' . get_lang('NoDocuments') . '</div>';
  6717. }*/
  6718. $return .= '</div>';
  6719. return $return;
  6720. }
  6721. /**
  6722. * Generate and return an HTML list of resources based on a given array.
  6723. * This list is used to show the course creator a list of available resources to choose from
  6724. * when creating a learning path.
  6725. * @param array Array of elements to add to the list
  6726. * @param integer Enables the tree display by shifting the new elements a certain distance to the right
  6727. * @return string The HTML list
  6728. */
  6729. public function write_resources_tree($resources_sorted, $num = 0) {
  6730. require_once api_get_path(LIBRARY_PATH).'fileDisplay.lib.php';
  6731. if (count($resources_sorted) > 0) {
  6732. foreach ($resources_sorted as $key => $resource) {
  6733. if (is_int($resource['id'])) {
  6734. // It's a folder.
  6735. //hide some folders
  6736. if (in_array($key, array('shared_folder','chat_files', 'HotPotatoes_files', 'css', 'certificates'))){
  6737. continue;
  6738. } elseif(preg_match('/_groupdocs/', $key)){
  6739. continue;
  6740. } elseif(preg_match('/sf_user_/', $key)){
  6741. continue;
  6742. } elseif(preg_match('/shared_folder_session_/', $key)){
  6743. continue;
  6744. }
  6745. //trad some titles
  6746. if ($key=='images') {
  6747. $key=get_lang('Images');
  6748. } elseif($key=='gallery') {
  6749. $key=get_lang('Gallery');
  6750. } elseif($key=='flash') {
  6751. $key=get_lang('Flash');
  6752. } elseif($key=='audio'){
  6753. $key=get_lang('Audio');
  6754. } elseif($key=='video') {
  6755. $key=get_lang('Video');
  6756. }
  6757. $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'] . '">';
  6758. $return .= $this->write_resources_tree($resource['files'], $num +1);
  6759. $return .= '</div></div>';
  6760. } else {
  6761. if (!is_array($resource)) {
  6762. // It's a file.
  6763. $icon = choose_image($resource);
  6764. $position = strrpos($icon, '.');
  6765. $icon = substr($icon, 0, $position) . '_small.gif';
  6766. $file_info = explode('/', $resource);
  6767. $my_file_title = $file_info[0];
  6768. $my_file_name = $file_info[1];
  6769. //$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>';
  6770. // Show the "image name" not the filename of the image.
  6771. $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"; }
  6772. }
  6773. }
  6774. }
  6775. return $return;
  6776. }
  6777. /**
  6778. * Creates a list with all the exercises (quiz) in it
  6779. * @return string
  6780. */
  6781. public function get_exercises() {
  6782. // New for hotpotatoes.
  6783. $uploadPath = DIR_HOTPOTATOES; //defined in main_api
  6784. $tbl_doc = Database :: get_course_table(TABLE_DOCUMENT);
  6785. $tbl_quiz = Database :: get_course_table(TABLE_QUIZ_TEST);
  6786. $session_id = api_get_session_id();
  6787. $condition_session = api_get_session_condition($session_id);
  6788. $sql_quiz = "SELECT * FROM $tbl_quiz WHERE active<>'-1' $condition_session ORDER BY title ASC";
  6789. $sql_hot = "SELECT * FROM $tbl_doc WHERE path LIKE '" . $uploadPath . "/%/%htm%' $condition_session ORDER BY id ASC";
  6790. $res_quiz = Database::query($sql_quiz);
  6791. $res_hot = Database::query($sql_hot);
  6792. //$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>';
  6793. $return .= '<div class="lp_resource">';
  6794. $return .= '<div class="lp_resource_element">';
  6795. $return .= '<img alt="" src="../img/new_test_small.gif" style="margin-right:5px;" title="" />';
  6796. $return .= '<a href="' . api_get_path(REL_CODE_PATH) . 'exercice/exercise_admin.php?lp_id=' . $this->lp_id . '">' . get_lang('NewExercise') . '</a>';
  6797. $return .= '</div>';
  6798. while ($row_hot = Database :: fetch_array($res_hot)) {
  6799. $return .= '<div class="lp_resource_element">';
  6800. // Display quizhotpotatoes.
  6801. $return .= '<img alt="hp" src="../img/hotpotatoes_s.png" style="margin-right:5px;" title="" width="18px" height="18px" />';
  6802. $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>';
  6803. //$return .= $row_quiz['title'];
  6804. $return .= '</div>';
  6805. }
  6806. while ($row_quiz = Database :: fetch_array($res_quiz)) {
  6807. $return .= '<div class="lp_resource_element">';
  6808. $return .= '<img alt="" src="../img/quizz_small.gif" style="margin-right:5px;" title="" />';
  6809. $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>';
  6810. //$return .= $row_quiz['title'];
  6811. $return .= '</div>';
  6812. }
  6813. /*if (Database :: num_rows($res_quiz) == 0) {
  6814. $return .= '<div class="lp_resource_element">' . get_lang('NoExercisesAvailable') . '</div>';
  6815. }*/
  6816. $return .= '</div>';
  6817. return $return;
  6818. }
  6819. /**
  6820. * Creates a list with all the links in it
  6821. * @return string
  6822. */
  6823. public function get_links() {
  6824. $tbl_link = Database :: get_course_table(TABLE_LINK);
  6825. $session_id = api_get_session_id();
  6826. $condition_session = api_get_session_condition($session_id,false);
  6827. $sql_link = "SELECT * FROM $tbl_link $condition_session ORDER BY title ASC";
  6828. $res_link = Database::query($sql_link);
  6829. //$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>';
  6830. $return .= '<div class="lp_resource">';
  6831. $return .= '<div class="lp_resource_element">';
  6832. $return .= '<img alt="" src="../img/linksnew.gif" style="margin-right:5px;width:16px" title="" />';
  6833. $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>';
  6834. $return .= '</div>';
  6835. while ($row_link = Database :: fetch_array($res_link)) {
  6836. $return .= '<div class="lp_resource_element">';
  6837. $return .= '<img alt="" src="../img/lp_link.gif" style="margin-right:5px;" title="" />';
  6838. $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>';
  6839. $return .= '</div>';
  6840. }
  6841. /*if (Database :: num_rows($res_link) == 0)
  6842. $return .= '<div class="lp_resource_element">' . get_lang('NoLinksAvailable') . '</div>';
  6843. */
  6844. $return .= '</div>';
  6845. return $return;
  6846. }
  6847. /**
  6848. * Creates a list with all the student publications in it
  6849. * @return unknown
  6850. */
  6851. public function get_student_publications() {
  6852. $tbl_student = Database :: get_course_table(TABLE_STUDENT_PUBLICATION);
  6853. $session_id = api_get_session_id();
  6854. $condition_session = api_get_session_condition($session_id, false);
  6855. $sql_student = "SELECT * FROM $tbl_student $condition_session ORDER BY title ASC";
  6856. $res_student = Database::query($sql_student);
  6857. //$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>';
  6858. $return .= '<div class="lp_resource" >';
  6859. $return .= '<div class="lp_resource_element">';
  6860. $return .= '<img align="left" alt="" src="../img/works_small.gif" style="margin-right:5px;" title="" />';
  6861. $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>';
  6862. $return .= '</div>';
  6863. $return .= '</div>';
  6864. return $return;
  6865. }
  6866. /**
  6867. * Creates a list with all the forums in it
  6868. * @return string
  6869. */
  6870. public function get_forums() {
  6871. require_once '../forum/forumfunction.inc.php';
  6872. require_once '../forum/forumconfig.inc.php';
  6873. global $table_forums, $table_threads, $table_posts, $table_item_property, $table_users;
  6874. $table_forums = Database :: get_course_table(TABLE_FORUM);
  6875. $table_threads = Database :: get_course_table(TABLE_FORUM_THREAD);
  6876. $table_posts = Database :: get_course_table(TABLE_FORUM_POST);
  6877. $table_item_property = Database :: get_course_table(TABLE_ITEM_PROPERTY);
  6878. $table_users = Database :: get_main_table(TABLE_MAIN_USER);
  6879. $a_forums = get_forums();
  6880. //$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>';
  6881. $return .= '<div class="lp_resource">';
  6882. $return .= '<div class="lp_resource_element">';
  6883. $return .= '<img alt="" src="../img/forum_new_small.gif" style="margin-right:5px;" title="" />';
  6884. $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>';
  6885. $return .= '</div>';
  6886. foreach ($a_forums as $forum) {
  6887. $return .= '<div class="lp_resource_element_no_link">';
  6888. $return .= '<script type="text/javascript">
  6889. function toggle_forum(forum_id){
  6890. if(document.getElementById("forum_"+forum_id+"_content").style.display == "none"){
  6891. document.getElementById("forum_"+forum_id+"_content").style.display = "block";
  6892. document.getElementById("forum_"+forum_id+"_opener").src = "' . api_get_path(WEB_IMG_PATH) . 'remove.gif";
  6893. }
  6894. else {
  6895. document.getElementById("forum_"+forum_id+"_content").style.display = "none";
  6896. document.getElementById("forum_"+forum_id+"_opener").src = "' . api_get_path(WEB_IMG_PATH) . 'add.gif";
  6897. }
  6898. }
  6899. </script>';
  6900. if (!empty($forum['forum_id'])) {
  6901. $return .= '<img alt="" src="../img/lp_forum.gif" style="margin-right:5px;" title="" />';
  6902. $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>
  6903. <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">';
  6904. }
  6905. $a_threads = get_threads($forum['forum_id']);
  6906. if (is_array($a_threads)) {
  6907. foreach ($a_threads as $thread) {
  6908. $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>';
  6909. }
  6910. }
  6911. $return .= '</ul></div>';
  6912. }
  6913. return $return;
  6914. }
  6915. /**
  6916. * // TODO: The output encoding should be equal to the system encoding.
  6917. *
  6918. * Exports the learning path as a SCORM package. This is the main function that
  6919. * gathers the content, transforms it, writes the imsmanifest.xml file, zips the
  6920. * whole thing and returns the zip.
  6921. *
  6922. * This method needs to be called in PHP5, as it will fail with non-adequate
  6923. * XML package (like the ones for PHP4), and it is *not* a static method, so
  6924. * you need to call it on a learnpath object.
  6925. * @TODO The method might be redefined later on in the scorm class itself to avoid
  6926. * creating a SCORM structure if there is one already. However, if the initial SCORM
  6927. * path has been modified, it should use the generic method here below.
  6928. * @TODO link this function with the export_lp() function in the same class
  6929. * @param string Optional name of zip file. If none, title of learnpath is
  6930. * domesticated and trailed with ".zip"
  6931. * @return string Returns the zip package string, or null if error
  6932. */
  6933. public function scorm_export() {
  6934. global $_course;
  6935. // Remove memory and time limits as much as possible as this might be a long process...
  6936. if (function_exists('ini_set')) {
  6937. $mem = ini_get('memory_limit');
  6938. if (substr($mem, -1, 1) == 'M') {
  6939. $mem_num = substr($mem, 0, -1);
  6940. if ($mem_num < 128) {
  6941. ini_set('memory_limit', '128M');
  6942. }
  6943. } else {
  6944. ini_set('memory_limit', '128M');
  6945. }
  6946. ini_set('max_execution_time', 600);
  6947. //} else {
  6948. //error_log('Scorm export: could not change memory and time limits', 0);
  6949. }
  6950. // Create the zip handler (this will remain available throughout the method).
  6951. $archive_path = api_get_path(SYS_ARCHIVE_PATH);
  6952. $sys_course_path = api_get_path(SYS_COURSE_PATH);
  6953. $temp_dir_short = uniqid();
  6954. $temp_zip_dir = $archive_path.'/'.$temp_dir_short;
  6955. $temp_zip_file = $temp_zip_dir.'/'.md5(time()).'.zip';
  6956. $zip_folder = new PclZip($temp_zip_file);
  6957. $current_course_path = api_get_path(SYS_COURSE_PATH).api_get_course_path();
  6958. $root_path = $main_path = api_get_path(SYS_PATH);
  6959. $files_cleanup = array();
  6960. // Place to temporarily stash the zipfiles.
  6961. // create the temp dir if it doesn't exist
  6962. // or do a cleanup befor creating the zipfile.
  6963. if (!is_dir($temp_zip_dir)) {
  6964. mkdir($temp_zip_dir, api_get_permissions_for_new_directories());
  6965. } else {
  6966. // Cleanup: Check the temp dir for old files and delete them.
  6967. $handle = opendir($temp_zip_dir);
  6968. while (false !== ($file = readdir($handle))) {
  6969. if ($file != '.' && $file != '..') {
  6970. unlink("$temp_zip_dir/$file");
  6971. }
  6972. }
  6973. closedir($handle);
  6974. }
  6975. $zip_files = $zip_files_abs = $zip_files_dist = array();
  6976. if (is_dir($current_course_path.'/scorm/'.$this->path) && is_file($current_course_path.'/scorm/'.$this->path.'/imsmanifest.xml')) {
  6977. // Remove the possible . at the end of the path.
  6978. $dest_path_to_lp = substr($this->path, -1) == '.' ? substr($this->path, 0, -1) : $this->path;
  6979. $dest_path_to_scorm_folder = str_replace('//','/',$temp_zip_dir.'/scorm/'.$dest_path_to_lp);
  6980. mkdir($dest_path_to_scorm_folder, api_get_permissions_for_new_directories(), true);
  6981. $zip_files_dist = copyr($current_course_path.'/scorm/'.$this->path, $dest_path_to_scorm_folder, array('imsmanifest'), $zip_files);
  6982. }
  6983. // Build a dummy imsmanifest structure. Do not add to the zip yet (we still need it).
  6984. // This structure is developed following regulations for SCORM 1.2 packaging in the SCORM 1.2 Content
  6985. // Aggregation Model official document, secion "2.3 Content Packaging".
  6986. $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.
  6987. $root = $xmldoc->createElement('manifest');
  6988. $root->setAttribute('identifier', 'SingleCourseManifest');
  6989. $root->setAttribute('version', '1.1');
  6990. $root->setAttribute('xmlns', 'http://www.imsproject.org/xsd/imscp_rootv1p1p2');
  6991. $root->setAttribute('xmlns:adlcp', 'http://www.adlnet.org/xsd/adlcp_rootv1p2');
  6992. $root->setAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance');
  6993. $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');
  6994. // Build mandatory sub-root container elements.
  6995. $metadata = $xmldoc->createElement('metadata');
  6996. $md_schema = $xmldoc->createElement('schema', 'ADL SCORM');
  6997. $metadata->appendChild($md_schema);
  6998. $md_schemaversion = $xmldoc->createElement('schemaversion', '1.2');
  6999. $metadata->appendChild($md_schemaversion);
  7000. $root->appendChild($metadata);
  7001. $organizations = $xmldoc->createElement('organizations');
  7002. $resources = $xmldoc->createElement('resources');
  7003. // Build the only organization we will use in building our learnpaths.
  7004. $organizations->setAttribute('default', 'chamilo_scorm_export');
  7005. $organization = $xmldoc->createElement('organization');
  7006. $organization->setAttribute('identifier', 'chamilo_scorm_export');
  7007. // To set the title of the SCORM entity (=organization), we take the name given
  7008. // in Chamilo and convert it to HTML entities using the Chamilo charset (not the
  7009. // learning path charset) as it is the encoding that defines how it is stored
  7010. // in the database. Then we convert it to HTML entities again as the "&" character
  7011. // alone is not authorized in XML (must be &amp;).
  7012. // The title is then decoded twice when extracting (see scorm::parse_manifest).
  7013. $org_title = $xmldoc->createElement('title', api_utf8_encode($this->get_name()));
  7014. $organization->appendChild($org_title);
  7015. // For each element, add it to the imsmanifest structure, then add it to the zip.
  7016. // Always call the learnpathItem->scorm_export() method to change it to the SCORM format.
  7017. $link_updates = array();
  7018. foreach ($this->items as $index => $item) {
  7019. if (!in_array($item->type, array(TOOL_QUIZ, TOOL_FORUM, TOOL_THREAD, TOOL_LINK, TOOL_STUDENTPUBLICATION))) {
  7020. // Get included documents from this item.
  7021. if ($item->type == 'sco')
  7022. $inc_docs = $item->get_resources_from_source(null, api_get_path(SYS_COURSE_PATH).api_get_course_path().'/'.'scorm/'.$this->path.'/'.$item->get_path());
  7023. else
  7024. $inc_docs = $item->get_resources_from_source();
  7025. // Give a child element <item> to the <organization> element.
  7026. $my_item_id = $item->get_id();
  7027. $my_item = $xmldoc->createElement('item');
  7028. $my_item->setAttribute('identifier', 'ITEM_'.$my_item_id);
  7029. $my_item->setAttribute('identifierref', 'RESOURCE_'.$my_item_id);
  7030. $my_item->setAttribute('isvisible', 'true');
  7031. // Give a child element <title> to the <item> element.
  7032. $my_title = $xmldoc->createElement('title', htmlspecialchars(api_utf8_encode($item->get_title()), ENT_QUOTES, 'UTF-8'));
  7033. $my_item->appendChild($my_title);
  7034. // Give a child element <adlcp:prerequisites> to the <item> element.
  7035. $my_prereqs = $xmldoc->createElement('adlcp:prerequisites', $this->get_scorm_prereq_string($my_item_id));
  7036. $my_prereqs->setAttribute('type', 'aicc_script');
  7037. $my_item->appendChild($my_prereqs);
  7038. // Give a child element <adlcp:maxtimeallowed> to the <item> element - not yet supported.
  7039. //$xmldoc->createElement('adlcp:maxtimeallowed','');
  7040. // Give a child element <adlcp:timelimitaction> to the <item> element - not yet supported.
  7041. //$xmldoc->createElement('adlcp:timelimitaction','');
  7042. // Give a child element <adlcp:datafromlms> to the <item> element - not yet supported.
  7043. //$xmldoc->createElement('adlcp:datafromlms','');
  7044. // Give a child element <adlcp:masteryscore> to the <item> element.
  7045. $my_masteryscore = $xmldoc->createElement('adlcp:masteryscore', $item->get_mastery_score());
  7046. $my_item->appendChild($my_masteryscore);
  7047. // Attach this item to the organization element or hits parent if there is one.
  7048. if (!empty($item->parent) && $item->parent != 0) {
  7049. $children = $organization->childNodes;
  7050. $possible_parent = &$this->get_scorm_xml_node($children, 'ITEM_'.$item->parent);
  7051. if (is_object($possible_parent)) {
  7052. $possible_parent->appendChild($my_item);
  7053. } else {
  7054. if ($this->debug > 0) { error_log('Parent ITEM_'.$item->parent.' of item ITEM_'.$my_item_id.' not found'); }
  7055. }
  7056. } else {
  7057. if ($this->debug > 0) { error_log('No parent'); }
  7058. $organization->appendChild($my_item);
  7059. }
  7060. // Get the path of the file(s) from the course directory root.
  7061. $my_file_path = $item->get_file_path('scorm/'.$this->path.'/');
  7062. //$my_xml_file_path = api_htmlentities(api_utf8_encode($my_file_path), ENT_QUOTES, 'UTF-8');
  7063. $my_xml_file_path = $my_file_path;
  7064. $my_sub_dir = dirname($my_file_path);
  7065. $my_sub_dir = str_replace('\\', '/', $my_sub_dir);
  7066. //$my_xml_sub_dir = api_htmlentities(api_utf8_encode($my_sub_dir), ENT_QUOTES, 'UTF-8');
  7067. $my_xml_sub_dir = $my_sub_dir;
  7068. // Give a <resource> child to the <resources> element
  7069. $my_resource = $xmldoc->createElement('resource');
  7070. $my_resource->setAttribute('identifier', 'RESOURCE_'.$item->get_id());
  7071. $my_resource->setAttribute('type', 'webcontent');
  7072. $my_resource->setAttribute('href', $my_xml_file_path);
  7073. // adlcp:scormtype can be either 'sco' or 'asset'.
  7074. if ($item->type == 'sco') {
  7075. $my_resource->setAttribute('adlcp:scormtype', 'sco');
  7076. } else {
  7077. $my_resource->setAttribute('adlcp:scormtype', 'asset');
  7078. }
  7079. // xml:base is the base directory to find the files declared in this resource.
  7080. $my_resource->setAttribute('xml:base', '');
  7081. // Give a <file> child to the <resource> element.
  7082. $my_file = $xmldoc->createElement('file');
  7083. $my_file->setAttribute('href', $my_xml_file_path);
  7084. $my_resource->appendChild($my_file);
  7085. // Dependency to other files - not yet supported.
  7086. $i = 1;
  7087. foreach ($inc_docs as $doc_info) {
  7088. if (count($doc_info) < 1 || empty($doc_info[0])) { continue; }
  7089. $my_dep = $xmldoc->createElement('resource');
  7090. $res_id = 'RESOURCE_'.$item->get_id().'_'.$i;
  7091. $my_dep->setAttribute('identifier', $res_id);
  7092. $my_dep->setAttribute('type', 'webcontent');
  7093. $my_dep->setAttribute('adlcp:scormtype', 'asset');
  7094. $my_dep_file = $xmldoc->createElement('file');
  7095. // Check type of URL.
  7096. //error_log(__LINE__.'Now dealing with '.$doc_info[0].' of type '.$doc_info[1].'-'.$doc_info[2], 0);
  7097. if ($doc_info[1] == 'remote') {
  7098. // Remote file. Save url as is.
  7099. $my_dep_file->setAttribute('href', $doc_info[0]);
  7100. $my_dep->setAttribute('xml:base', '');
  7101. } elseif ($doc_info[1] == 'local') {
  7102. switch ($doc_info[2]) {
  7103. case 'url': // Local URL - save path as url for now, don't zip file.
  7104. $abs_path = api_get_path(SYS_PATH).str_replace(api_get_path(WEB_PATH), '', $doc_info[0]);
  7105. $current_dir = dirname($abs_path);
  7106. $current_dir = str_replace('\\', '/', $current_dir);
  7107. $file_path = realpath($abs_path);
  7108. $file_path = str_replace('\\', '/', $file_path);
  7109. $my_dep_file->setAttribute('href', $file_path);
  7110. $my_dep->setAttribute('xml:base', '');
  7111. if (strstr($file_path, $main_path) !== false) {
  7112. // The calculated real path is really inside Chamilo's root path.
  7113. // Reduce file path to what's under the DocumentRoot.
  7114. $file_path = substr($file_path, strlen($root_path) - 1);
  7115. //echo $file_path;echo '<br /><br />';
  7116. //error_log(__LINE__.'Reduced url path: '.$file_path, 0);
  7117. $zip_files_abs[] = $file_path;
  7118. $link_updates[$my_file_path][] = array('orig' => $doc_info[0], 'dest' => $file_path);
  7119. $my_dep_file->setAttribute('href', $file_path);
  7120. $my_dep->setAttribute('xml:base', '');
  7121. }
  7122. elseif (empty($file_path)) {
  7123. /*$document_root = substr(api_get_path(SYS_PATH), 0, strpos(api_get_path(SYS_PATH), api_get_path(REL_PATH)));
  7124. if (strpos($document_root, -1) == '/') {
  7125. $document_root = substr(0, -1, $document_root);
  7126. }*/
  7127. $file_path = $_SERVER['DOCUMENT_ROOT'].$abs_path;
  7128. $file_path = str_replace('//', '/', $file_path);
  7129. if (file_exists($file_path)) {
  7130. $file_path = substr($file_path, strlen($current_dir)); // We get the relative path.
  7131. $zip_files[] = $my_sub_dir.'/'.$file_path;
  7132. $link_updates[$my_file_path][] = array('orig' => $doc_info[0], 'dest' => $file_path);
  7133. $my_dep_file->setAttribute('href', $file_path);
  7134. $my_dep->setAttribute('xml:base', '');
  7135. }
  7136. }
  7137. break;
  7138. case 'abs': // Absolute path from DocumentRoot. Save file and leave path as is in the zip.
  7139. $my_dep_file->setAttribute('href', $doc_info[0]);
  7140. $my_dep->setAttribute('xml:base', '');
  7141. //$current_dir = str_replace('\\', '/', dirname($current_course_path.'/'.$item->get_file_path())).'/';
  7142. // The next lines fix a bug when using the "subdir" mode of Chamilo, whereas
  7143. // an image path would be constructed as /var/www/subdir/subdir/img/foo.bar
  7144. $abs_img_path_without_subdir = $doc_info[0];
  7145. $relp = api_get_path(REL_PATH); // The url-append config param.
  7146. $pos = strpos($abs_img_path_without_subdir, $relp);
  7147. if ($pos === 0) {
  7148. $abs_img_path_without_subdir = '/'.substr($abs_img_path_without_subdir, strlen($relp));
  7149. }
  7150. //$file_path = realpath(api_get_path(SYS_PATH).$doc_info[0]);
  7151. $file_path = realpath(api_get_path(SYS_PATH).$abs_img_path_without_subdir);
  7152. $file_path = str_replace('\\', '/', $file_path);
  7153. $file_path = str_replace('//', '/', $file_path);
  7154. //error_log(__LINE__.'Abs path: '.$file_path, 0);
  7155. // Prepare the current directory path (until just under 'document') with a trailing slash.
  7156. $cur_path = substr($current_course_path, -1) == '/' ? $current_course_path : $current_course_path.'/';
  7157. // Check if the current document is in that path.
  7158. if (strstr($file_path, $cur_path) !== false) {
  7159. // The document is in that path, now get the relative path
  7160. // to the containing document.
  7161. $orig_file_path = dirname($cur_path.$my_file_path).'/';
  7162. $orig_file_path = str_replace('\\', '/', $orig_file_path);
  7163. $relative_path = '';
  7164. if (strstr($file_path, $cur_path) !== false) {
  7165. $relative_path = substr($file_path, strlen($orig_file_path));
  7166. $file_path = substr($file_path, strlen($cur_path));
  7167. } else {
  7168. // This case is still a problem as it's difficult to calculate a relative path easily
  7169. // might still generate wrong links.
  7170. //$file_path = substr($file_path,strlen($cur_path));
  7171. // Calculate the directory path to the current file (without trailing slash).
  7172. $my_relative_path = dirname($file_path);
  7173. $my_relative_path = str_replace('\\', '/', $my_relative_path);
  7174. $my_relative_file = basename($file_path);
  7175. // Calculate the directory path to the containing file (without trailing slash).
  7176. $my_orig_file_path = substr($orig_file_path, 0, -1);
  7177. $dotdot = '';
  7178. $subdir = '';
  7179. while (strstr($my_relative_path, $my_orig_file_path) === false && (strlen($my_orig_file_path) > 1) && (strlen($my_relative_path) > 1)) {
  7180. $my_relative_path2 = dirname($my_relative_path);
  7181. $my_relative_path2 = str_replace('\\', '/', $my_relative_path2);
  7182. $my_orig_file_path = dirname($my_orig_file_path);
  7183. $my_orig_file_path = str_replace('\\', '/', $my_orig_file_path);
  7184. $subdir = substr($my_relative_path, strlen($my_relative_path2) + 1).'/'.$subdir;
  7185. $dotdot += '../';
  7186. $my_relative_path = $my_relative_path2;
  7187. }
  7188. $relative_path = $dotdot.$subdir.$my_relative_file;
  7189. }
  7190. // Put the current document in the zip (this array is the array
  7191. // that will manage documents already in the course folder - relative).
  7192. $zip_files[] = $file_path;
  7193. // Update the links to the current document in the containing document (make them relative).
  7194. $link_updates[$my_file_path][] = array('orig' => $doc_info[0], 'dest' => $relative_path);
  7195. $my_dep_file->setAttribute('href', $file_path);
  7196. $my_dep->setAttribute('xml:base', '');
  7197. }
  7198. elseif (strstr($file_path,$main_path) !== false) {
  7199. // The calculated real path is really inside Chamilo's root path.
  7200. // Reduce file path to what's under the DocumentRoot.
  7201. $file_path = substr($file_path, strlen($root_path));
  7202. //echo $file_path;echo '<br /><br />';
  7203. //error_log('Reduced path: '.$file_path, 0);
  7204. $zip_files_abs[] = $file_path;
  7205. $link_updates[$my_file_path][] = array('orig' => $doc_info[0], 'dest' => $file_path);
  7206. $my_dep_file->setAttribute('href', 'document/'.$file_path);
  7207. $my_dep->setAttribute('xml:base', '');
  7208. }
  7209. elseif (empty($file_path)) {
  7210. /*$document_root = substr(api_get_path(SYS_PATH), 0, strpos(api_get_path(SYS_PATH), api_get_path(REL_PATH)));
  7211. if(strpos($document_root,-1) == '/') {
  7212. $document_root = substr(0, -1, $document_root);
  7213. }*/
  7214. $file_path = $_SERVER['DOCUMENT_ROOT'].$doc_info[0];
  7215. $file_path = str_replace('//', '/', $file_path);
  7216. if (file_exists($file_path)) {
  7217. $file_path = substr($file_path,strlen($current_dir)); // We get the relative path.
  7218. $zip_files[] = $my_sub_dir.'/'.$file_path;
  7219. $link_updates[$my_file_path][] = array('orig' => $doc_info[0], 'dest' => $file_path);
  7220. $my_dep_file->setAttribute('href','document/'.$file_path);
  7221. $my_dep->setAttribute('xml:base', '');
  7222. }
  7223. }
  7224. break;
  7225. 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
  7226. if (substr($doc_info[0], 0, 2) == '..') {
  7227. // Relative path going up.
  7228. $current_dir = dirname($current_course_path.'/'.$item->get_file_path()).'/';
  7229. $current_dir = str_replace('\\', '/', $current_dir);
  7230. $file_path = realpath($current_dir.$doc_info[0]);
  7231. $file_path = str_replace('\\', '/', $file_path);
  7232. //error_log($file_path.' <-> '.$main_path,0);
  7233. if (strstr($file_path, $main_path) !== false) {
  7234. // The calculated real path is really inside Chamilo's root path.
  7235. // Reduce file path to what's under the DocumentRoot.
  7236. $file_path = substr($file_path, strlen($root_path));
  7237. //error_log('Reduced path: '.$file_path, 0);
  7238. $zip_files_abs[] = $file_path;
  7239. $link_updates[$my_file_path][] = array('orig' => $doc_info[0], 'dest' => $file_path);
  7240. $my_dep_file->setAttribute('href', 'document/'.$file_path);
  7241. $my_dep->setAttribute('xml:base', '');
  7242. }
  7243. } else {
  7244. $zip_files[] = $my_sub_dir.'/'.$doc_info[0];
  7245. $my_dep_file->setAttribute('href', $doc_info[0]);
  7246. $my_dep->setAttribute('xml:base', $my_xml_sub_dir);
  7247. }
  7248. break;
  7249. default:
  7250. $my_dep_file->setAttribute('href', $doc_info[0]);
  7251. $my_dep->setAttribute('xml:base', '');
  7252. break;
  7253. }
  7254. }
  7255. $my_dep->appendChild($my_dep_file);
  7256. $resources->appendChild($my_dep);
  7257. $dependency = $xmldoc->createElement('dependency');
  7258. $dependency->setAttribute('identifierref', $res_id);
  7259. $my_resource->appendChild($dependency);
  7260. $i++;
  7261. }
  7262. //$my_dependency = $xmldoc->createElement('dependency');
  7263. //$my_dependency->setAttribute('identifierref', '');
  7264. $resources->appendChild($my_resource);
  7265. $zip_files[] = $my_file_path;
  7266. //error_log('File '.$my_file_path. ' added to $zip_files', 0);
  7267. } else {
  7268. // If the item is a quiz or a link or whatever non-exportable, we include a step indicating it.
  7269. if ($item->type == TOOL_LINK) {
  7270. $my_item = $xmldoc->createElement('item');
  7271. $my_item->setAttribute('identifier', 'ITEM_'.$item->get_id());
  7272. $my_item->setAttribute('identifierref', 'RESOURCE_'.$item->get_id());
  7273. $my_item->setAttribute('isvisible', 'true');
  7274. // Give a child element <title> to the <item> element.
  7275. $my_title = $xmldoc->createElement('title', htmlspecialchars(api_utf8_encode($item->get_title()), ENT_QUOTES, 'UTF-8'));
  7276. $my_item->appendChild($my_title);
  7277. // Give a child element <adlcp:prerequisites> to the <item> element.
  7278. $my_prereqs = $xmldoc->createElement('adlcp:prerequisites', $item->get_prereq_string());
  7279. $my_prereqs->setAttribute('type', 'aicc_script');
  7280. $my_item->appendChild($my_prereqs);
  7281. // Give a child element <adlcp:maxtimeallowed> to the <item> element - not yet supported.
  7282. //$xmldoc->createElement('adlcp:maxtimeallowed', '');
  7283. // Give a child element <adlcp:timelimitaction> to the <item> element - not yet supported.
  7284. //$xmldoc->createElement('adlcp:timelimitaction', '');
  7285. // Give a child element <adlcp:datafromlms> to the <item> element - not yet supported.
  7286. //$xmldoc->createElement('adlcp:datafromlms', '');
  7287. // Give a child element <adlcp:masteryscore> to the <item> element.
  7288. $my_masteryscore = $xmldoc->createElement('adlcp:masteryscore', $item->get_mastery_score());
  7289. $my_item->appendChild($my_masteryscore);
  7290. // Attach this item to the organization element or its parent if there is one.
  7291. if (!empty($item->parent) && $item->parent != 0) {
  7292. $children = $organization->childNodes;
  7293. for ($i = 0; $i < $children->length; $i++) {
  7294. $item_temp = $children->item($i);
  7295. if ($item_temp -> nodeName == 'item') {
  7296. if ($item_temp->getAttribute('identifier') == 'ITEM_'.$item->parent) {
  7297. $item_temp -> appendChild($my_item);
  7298. }
  7299. }
  7300. }
  7301. } else {
  7302. $organization->appendChild($my_item);
  7303. }
  7304. $my_file_path = 'link_'.$item->get_id().'.html';
  7305. $sql = 'SELECT url, title FROM '.Database :: get_course_table(TABLE_LINK).' WHERE id='.$item->path;
  7306. $rs = Database::query($sql);
  7307. if ($link = Database :: fetch_array($rs)) {
  7308. $url = $link['url'];
  7309. $title = stripslashes($link['title']);
  7310. $links_to_create[$my_file_path] = array('title' => $title, 'url' => $url);
  7311. //$my_xml_file_path = api_htmlentities(api_utf8_encode($my_file_path), ENT_QUOTES, 'UTF-8');
  7312. $my_xml_file_path = $my_file_path;
  7313. $my_sub_dir = dirname($my_file_path);
  7314. $my_sub_dir = str_replace('\\', '/', $my_sub_dir);
  7315. //$my_xml_sub_dir = api_htmlentities(api_utf8_encode($my_sub_dir), ENT_QUOTES, 'UTF-8');
  7316. $my_xml_sub_dir = $my_sub_dir;
  7317. // Give a <resource> child to the <resources> element.
  7318. $my_resource = $xmldoc->createElement('resource');
  7319. $my_resource->setAttribute('identifier', 'RESOURCE_'.$item->get_id());
  7320. $my_resource->setAttribute('type', 'webcontent');
  7321. $my_resource->setAttribute('href', $my_xml_file_path);
  7322. // adlcp:scormtype can be either 'sco' or 'asset'.
  7323. $my_resource->setAttribute('adlcp:scormtype', 'asset');
  7324. // xml:base is the base directory to find the files declared in this resource.
  7325. $my_resource->setAttribute('xml:base', '');
  7326. // give a <file> child to the <resource> element.
  7327. $my_file = $xmldoc->createElement('file');
  7328. $my_file->setAttribute('href', $my_xml_file_path);
  7329. $my_resource->appendChild($my_file);
  7330. $resources->appendChild($my_resource);
  7331. }
  7332. }
  7333. elseif ($item->type == TOOL_QUIZ) {
  7334. require_once api_get_path(SYS_CODE_PATH).'exercice/exercise.class.php';
  7335. $exe_id = $item->path; // Should be using ref when everything will be cleaned up in this regard.
  7336. $exe = new Exercise();
  7337. $exe->read($exe_id);
  7338. $my_item = $xmldoc->createElement('item');
  7339. $my_item->setAttribute('identifier', 'ITEM_'.$item->get_id());
  7340. $my_item->setAttribute('identifierref', 'RESOURCE_'.$item->get_id());
  7341. $my_item->setAttribute('isvisible', 'true');
  7342. // Give a child element <title> to the <item> element.
  7343. $my_title = $xmldoc->createElement('title', htmlspecialchars(api_utf8_encode($item->get_title()), ENT_QUOTES, 'UTF-8'));
  7344. $my_item->appendChild($my_title);
  7345. $my_max_score = $xmldoc->createElement('max_score', $item->get_max());
  7346. //$my_item->appendChild($my_max_score);
  7347. // Give a child element <adlcp:prerequisites> to the <item> element.
  7348. $my_prereqs = $xmldoc->createElement('adlcp:prerequisites', $item->get_prereq_string());
  7349. $my_prereqs->setAttribute('type','aicc_script');
  7350. $my_item->appendChild($my_prereqs);
  7351. // Give a child element <adlcp:masteryscore> to the <item> element.
  7352. $my_masteryscore = $xmldoc->createElement('adlcp:masteryscore', $item->get_mastery_score());
  7353. $my_item->appendChild($my_masteryscore);
  7354. // Attach this item to the organization element or hits parent if there is one.
  7355. if (!empty($item->parent) && $item->parent != 0) {
  7356. $children = $organization->childNodes;
  7357. for ($i = 0; $i < $children->length; $i++) {
  7358. $item_temp = $children->item($i);
  7359. if ($item_temp -> nodeName == 'item') {
  7360. if ($item_temp->getAttribute('identifier') == 'ITEM_'.$item->parent) {
  7361. $item_temp -> appendChild($my_item);
  7362. }
  7363. }
  7364. }
  7365. } else {
  7366. $organization->appendChild($my_item);
  7367. }
  7368. // Include export scripts.
  7369. require_once api_get_path(SYS_CODE_PATH).'exercice/export/scorm/scorm_export.php';
  7370. // Get the path of the file(s) from the course directory root
  7371. //$my_file_path = $item->get_file_path('scorm/'.$this->path.'/');
  7372. $my_file_path = 'quiz_'.$item->get_id().'.html';
  7373. // Write the contents of the exported exercise into a (big) html file
  7374. // to later pack it into the exported SCORM. The file will be removed afterwards.
  7375. $contents = export_exercise($exe_id,true);
  7376. $tmp_file_path = $archive_path.$temp_dir_short.'/'.$my_file_path;
  7377. $res = file_put_contents($tmp_file_path, $contents);
  7378. if ($res === false) { error_log('Could not write into file '.$tmp_file_path.' '.__FILE__.' '.__LINE__, 0); }
  7379. $files_cleanup[] = $tmp_file_path;
  7380. //error_log($tmp_path); die();
  7381. //$my_xml_file_path = api_htmlentities(api_utf8_encode($my_file_path), ENT_QUOTES, 'UTF-8');
  7382. $my_xml_file_path = $my_file_path;
  7383. $my_sub_dir = dirname($my_file_path);
  7384. $my_sub_dir = str_replace('\\', '/', $my_sub_dir);
  7385. //$my_xml_sub_dir = api_htmlentities(api_utf8_encode($my_sub_dir), ENT_QUOTES, 'UTF-8');
  7386. $my_xml_sub_dir = $my_sub_dir;
  7387. // Give a <resource> child to the <resources> element.
  7388. $my_resource = $xmldoc->createElement('resource');
  7389. $my_resource->setAttribute('identifier', 'RESOURCE_'.$item->get_id());
  7390. $my_resource->setAttribute('type', 'webcontent');
  7391. $my_resource->setAttribute('href', $my_xml_file_path);
  7392. // adlcp:scormtype can be either 'sco' or 'asset'.
  7393. $my_resource->setAttribute('adlcp:scormtype', 'sco');
  7394. // xml:base is the base directory to find the files declared in this resource.
  7395. $my_resource->setAttribute('xml:base', '');
  7396. // Give a <file> child to the <resource> element.
  7397. $my_file = $xmldoc->createElement('file');
  7398. $my_file->setAttribute('href', $my_xml_file_path);
  7399. $my_resource->appendChild($my_file);
  7400. // Get included docs.
  7401. $inc_docs = $item->get_resources_from_source(null,$tmp_file_path);
  7402. // Dependency to other files - not yet supported.
  7403. $i = 1;
  7404. foreach ($inc_docs as $doc_info) {
  7405. if (count($doc_info) < 1 || empty($doc_info[0])) { continue; }
  7406. $my_dep = $xmldoc->createElement('resource');
  7407. $res_id = 'RESOURCE_'.$item->get_id().'_'.$i;
  7408. $my_dep->setAttribute('identifier', $res_id);
  7409. $my_dep->setAttribute('type', 'webcontent');
  7410. $my_dep->setAttribute('adlcp:scormtype', 'asset');
  7411. $my_dep_file = $xmldoc->createElement('file');
  7412. // Check type of URL.
  7413. //error_log(__LINE__.'Now dealing with '.$doc_info[0].' of type '.$doc_info[1].'-'.$doc_info[2], 0);
  7414. if ($doc_info[1] == 'remote') {
  7415. // Remote file. Save url as is.
  7416. $my_dep_file->setAttribute('href', $doc_info[0]);
  7417. $my_dep->setAttribute('xml:base', '');
  7418. } elseif ($doc_info[1] == 'local') {
  7419. switch ($doc_info[2]) {
  7420. case 'url': // Local URL - save path as url for now, don't zip file.
  7421. // Save file but as local file (retrieve from URL).
  7422. $abs_path = api_get_path(SYS_PATH).str_replace(api_get_path(WEB_PATH), '', $doc_info[0]);
  7423. $current_dir = dirname($abs_path);
  7424. $current_dir = str_replace('\\', '/', $current_dir);
  7425. $file_path = realpath($abs_path);
  7426. $file_path = str_replace('\\', '/', $file_path);
  7427. $my_dep_file->setAttribute('href', 'document/'.$file_path);
  7428. $my_dep->setAttribute('xml:base', '');
  7429. if (strstr($file_path, $main_path) !== false) {
  7430. // The calculated real path is really inside the chamilo root path.
  7431. // Reduce file path to what's under the DocumentRoot.
  7432. $file_path = substr($file_path, strlen($root_path));
  7433. //echo $file_path;echo '<br /><br />';
  7434. //error_log('Reduced path: '.$file_path, 0);
  7435. $zip_files_abs[] = $file_path;
  7436. $link_updates[$my_file_path][] = array('orig' => $doc_info[0], 'dest' => 'document/'.$file_path);
  7437. $my_dep_file->setAttribute('href', 'document/'.$file_path);
  7438. $my_dep->setAttribute('xml:base', '');
  7439. }
  7440. elseif (empty($file_path)) {
  7441. /*$document_root = substr(api_get_path(SYS_PATH), 0, strpos(api_get_path(SYS_PATH),api_get_path(REL_PATH)));
  7442. if (strpos($document_root,-1) == '/') {
  7443. $document_root = substr(0, -1, $document_root);
  7444. }*/
  7445. $file_path = $_SERVER['DOCUMENT_ROOT'].$abs_path;
  7446. $file_path = str_replace('//', '/', $file_path);
  7447. if (file_exists($file_path)) {
  7448. $file_path = substr($file_path, strlen($current_dir)); // We get the relative path.
  7449. $zip_files[] = $my_sub_dir.'/'.$file_path;
  7450. $link_updates[$my_file_path][] = array('orig' => $doc_info[0], 'dest' => 'document/'.$file_path);
  7451. $my_dep_file->setAttribute('href', 'document/'.$file_path);
  7452. $my_dep->setAttribute('xml:base', '');
  7453. }
  7454. }
  7455. break;
  7456. case 'abs': // Absolute path from DocumentRoot. Save file and leave path as is in the zip.
  7457. $current_dir = dirname($current_course_path.'/'.$item->get_file_path()).'/';
  7458. $current_dir = str_replace('\\', '/', $current_dir);
  7459. $file_path = realpath($doc_info[0]);
  7460. $file_path = str_replace('\\', '/', $file_path);
  7461. $my_dep_file->setAttribute('href', $file_path);
  7462. $my_dep->setAttribute('xml:base', '');
  7463. if (strstr($file_path,$main_path) !== false) {
  7464. // The calculated real path is really inside the chamilo root path.
  7465. // Reduce file path to what's under the DocumentRoot.
  7466. $file_path = substr($file_path, strlen($root_path));
  7467. //echo $file_path;echo '<br /><br />';
  7468. //error_log('Reduced path: '.$file_path, 0);
  7469. $zip_files_abs[] = $file_path;
  7470. $link_updates[$my_file_path][] = array('orig' => $doc_info[0], 'dest' => $file_path);
  7471. $my_dep_file->setAttribute('href', 'document/'.$file_path);
  7472. $my_dep->setAttribute('xml:base', '');
  7473. }
  7474. elseif (empty($file_path)) {
  7475. /*$document_root = substr(api_get_path(SYS_PATH), 0, strpos(api_get_path(SYS_PATH), api_get_path(REL_PATH)));
  7476. if (strpos($document_root,-1) == '/') {
  7477. $document_root = substr(0, -1, $document_root);
  7478. }*/
  7479. $file_path = $_SERVER['DOCUMENT_ROOT'].$doc_info[0];
  7480. $file_path = str_replace('//', '/', $file_path);
  7481. if (file_exists($file_path)) {
  7482. $file_path = substr($file_path,strlen($current_dir)); // We get the relative path.
  7483. $zip_files[] = $my_sub_dir.'/'.$file_path;
  7484. $link_updates[$my_file_path][] = array('orig' => $doc_info[0], 'dest' => $file_path);
  7485. $my_dep_file->setAttribute('href', 'document/'.$file_path);
  7486. $my_dep->setAttribute('xml:base', '');
  7487. }
  7488. }
  7489. break;
  7490. 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
  7491. if (substr($doc_info[0], 0, 2) == '..') {
  7492. // Relative path going up.
  7493. $current_dir = dirname($current_course_path.'/'.$item->get_file_path()).'/';
  7494. $current_dir = str_replace('\\', '/', $current_dir);
  7495. $file_path = realpath($current_dir.$doc_info[0]);
  7496. $file_path = str_replace('\\', '/', $file_path);
  7497. //error_log($file_path.' <-> '.$main_path, 0);
  7498. if (strstr($file_path, $main_path) !== false) {
  7499. // The calculated real path is really inside Chamilo's root path.
  7500. // Reduce file path to what's under the DocumentRoot.
  7501. $file_path = substr($file_path, strlen($root_path));
  7502. $file_path_dest = $file_path;
  7503. // File path is courses/CHAMILO/document/....
  7504. $info_file_path = explode('/', $file_path);
  7505. if ($info_file_path[0] == 'courses') { // Add character "/" in file path.
  7506. $file_path_dest = 'document/'.$file_path;
  7507. }
  7508. //error_log('Reduced path: '.$file_path, 0);
  7509. $zip_files_abs[] = $file_path;
  7510. $link_updates[$my_file_path][] = array('orig' => $doc_info[0], 'dest' => $file_path_dest);
  7511. $my_dep_file->setAttribute('href', 'document/'.$file_path);
  7512. $my_dep->setAttribute('xml:base', '');
  7513. }
  7514. } else {
  7515. $zip_files[] = $my_sub_dir.'/'.$doc_info[0];
  7516. $my_dep_file->setAttribute('href', $doc_info[0]);
  7517. $my_dep->setAttribute('xml:base', $my_xml_sub_dir);
  7518. }
  7519. break;
  7520. default:
  7521. $my_dep_file->setAttribute('href', $doc_info[0]); // ../../courses/
  7522. $my_dep->setAttribute('xml:base', '');
  7523. break;
  7524. }
  7525. }
  7526. $my_dep->appendChild($my_dep_file);
  7527. $resources->appendChild($my_dep);
  7528. $dependency = $xmldoc->createElement('dependency');
  7529. $dependency->setAttribute('identifierref', $res_id);
  7530. $my_resource->appendChild($dependency);
  7531. $i++;
  7532. }
  7533. $resources->appendChild($my_resource);
  7534. $zip_files[] = $my_file_path;
  7535. } else {
  7536. // Get the path of the file(s) from the course directory root
  7537. $my_file_path = 'non_exportable.html';
  7538. //$my_xml_file_path = api_htmlentities(api_utf8_encode($my_file_path), ENT_COMPAT, 'UTF-8');
  7539. $my_xml_file_path = $my_file_path;
  7540. $my_sub_dir = dirname($my_file_path);
  7541. $my_sub_dir = str_replace('\\', '/', $my_sub_dir);
  7542. //$my_xml_sub_dir = api_htmlentities(api_utf8_encode($my_sub_dir), ENT_COMPAT, 'UTF-8');
  7543. $my_xml_sub_dir = $my_sub_dir;
  7544. // Give a <resource> child to the <resources> element.
  7545. $my_resource = $xmldoc->createElement('resource');
  7546. $my_resource->setAttribute('identifier', 'RESOURCE_'.$item->get_id());
  7547. $my_resource->setAttribute('type', 'webcontent');
  7548. $my_resource->setAttribute('href', 'document/'.$my_xml_file_path);
  7549. // adlcp:scormtype can be either 'sco' or 'asset'.
  7550. $my_resource->setAttribute('adlcp:scormtype', 'asset');
  7551. // xml:base is the base directory to find the files declared in this resource.
  7552. $my_resource->setAttribute('xml:base', '');
  7553. // Give a <file> child to the <resource> element.
  7554. $my_file = $xmldoc->createElement('file');
  7555. $my_file->setAttribute('href', 'document/'.$my_xml_file_path);
  7556. $my_resource->appendChild($my_file);
  7557. $resources->appendChild($my_resource);
  7558. }
  7559. }
  7560. }
  7561. $organizations->appendChild($organization);
  7562. $root->appendChild($organizations);
  7563. $root->appendChild($resources);
  7564. $xmldoc->appendChild($root);
  7565. // TODO: Add a readme file here, with a short description and a link to the Reload player
  7566. // then add the file to the zip, then destroy the file (this is done automatically).
  7567. // http://www.reload.ac.uk/scormplayer.html - once done, don't forget to close FS#138
  7568. //error_log(print_r($zip_files,true), 0);
  7569. foreach ($zip_files as $file_path) {
  7570. if (empty($file_path)) { continue; }
  7571. //error_log(__LINE__.'getting document from '.$sys_course_path.$_course['path'].'/'.$file_path.' removing '.$sys_course_path.$_course['path'].'/',0);
  7572. $dest_file = $archive_path.$temp_dir_short.'/'.$file_path;
  7573. $this->create_path($dest_file);
  7574. //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);
  7575. //echo $main_path.$file_path.'<br />';
  7576. @copy($sys_course_path.$_course['path'].'/'.$file_path, $dest_file);
  7577. // Check if the file needs a link update.
  7578. if (in_array($file_path, array_keys($link_updates))) {
  7579. $string = file_get_contents($dest_file);
  7580. unlink($dest_file);
  7581. foreach ($link_updates[$file_path] as $old_new) {
  7582. //error_log('Replacing '.$old_new['orig'].' by '.$old_new['dest'].' in '.$file_path, 0);
  7583. // This is an ugly hack that allows .flv files to be found by the flv player that
  7584. // will be added in document/main/inc/lib/flv_player/flv_player.swf and that needs
  7585. // to find the flv to play in document/main/, so we replace main/ in the flv path by
  7586. // ../../.. to return from inc/lib/flv_player to the document/main path.
  7587. if (substr($old_new['dest'], -3) == 'flv' && substr($old_new['dest'], 0, 5) == 'main/') {
  7588. $old_new['dest'] = str_replace('main/', '../../../', $old_new['dest']);
  7589. }
  7590. elseif (substr($old_new['dest'], -3) == 'flv' && substr($old_new['dest'], 0, 6) == 'video/') {
  7591. $old_new['dest'] = str_replace('video/', '../../../../video/', $old_new['dest']);
  7592. }
  7593. $string = str_replace($old_new['orig'], $old_new['dest'], $string);
  7594. }
  7595. file_put_contents($dest_file, $string);
  7596. }
  7597. }
  7598. foreach ($zip_files_abs as $file_path) {
  7599. if (empty($file_path)) { continue; }
  7600. //error_log(__LINE__.'checking existence of '.$main_path.$file_path.'', 0);
  7601. if (!is_file($main_path.$file_path) || !is_readable($main_path.$file_path)) { continue; }
  7602. //error_log(__LINE__.'getting document from '.$main_path.$file_path.' removing '.api_get_path(SYS_COURSE_PATH).$_course['path'].'/', 0);
  7603. $dest_file = $archive_path.$temp_dir_short.'/document/'.$file_path;
  7604. $this->create_path($dest_file);
  7605. //error_log('Created path '.api_get_path(SYS_ARCHIVE_PATH).$temp_dir_short.'/document/'.$file_path, 0);
  7606. //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);
  7607. //echo $main_path.$file_path.' - '.$dest_file.'<br />';
  7608. copy($main_path.$file_path, $dest_file);
  7609. // Check if the file needs a link update.
  7610. if (in_array($file_path, array_keys($link_updates))) {
  7611. $string = file_get_contents($dest_file);
  7612. unlink($dest_file);
  7613. foreach ($link_updates[$file_path] as $old_new) {
  7614. //error_log('Replacing '.$old_new['orig'].' by '.$old_new['dest'].' in '.$file_path, 0);
  7615. // This is an ugly hack that allows .flv files to be found by the flv player that
  7616. // will be added in document/main/inc/lib/flv_player/flv_player.swf and that needs
  7617. // to find the flv to play in document/main/, so we replace main/ in the flv path by
  7618. // ../../.. to return from inc/lib/flv_player to the document/main path.
  7619. if (substr($old_new['dest'], -3) == 'flv' && substr($old_new['dest'], 0, 5) == 'main/') {
  7620. $old_new['dest'] = str_replace('main/', '../../../', $old_new['dest']);
  7621. }
  7622. $string = str_replace($old_new['orig'], $old_new['dest'], $string);
  7623. }
  7624. file_put_contents($dest_file, $string);
  7625. }
  7626. }
  7627. if (is_array($links_to_create)) {
  7628. foreach ($links_to_create as $file => $link) {
  7629. $file_content = '<!DOCTYPE html
  7630. PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  7631. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  7632. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="'.api_get_language_isocode().'" lang="'.api_get_language_isocode().'">
  7633. <head>
  7634. <title>'.$link['title'].'</title>
  7635. <meta http-equiv="Content-Type" content="text/html; charset='.api_get_system_encoding().'" />
  7636. </head>
  7637. <body dir="'.api_get_text_direction().'">
  7638. <div style="text-align:center"><a href="'.$link['url'].'">'.$link['title'].'</a></div>
  7639. </body>
  7640. </html>';
  7641. file_put_contents($archive_path.$temp_dir_short.'/'.$file, $file_content);
  7642. }
  7643. }
  7644. // Add non exportable message explanation.
  7645. $lang_not_exportable = get_lang('ThisItemIsNotExportable');
  7646. $file_content = '<!DOCTYPE html
  7647. PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  7648. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  7649. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="'.api_get_language_isocode().'" lang="'.api_get_language_isocode().'">
  7650. <head>
  7651. <title>'.$lang_not_exportable.'</title>
  7652. <meta http-equiv="Content-Type" content="text/html; charset='.api_get_system_encoding().'" />
  7653. </head>
  7654. <body dir="'.api_get_text_direction().'">
  7655. ';
  7656. $file_content .=
  7657. <<<EOD
  7658. <style>
  7659. .error-message {
  7660. font-family: arial, verdana, helvetica, sans-serif;
  7661. border-width: 1px;
  7662. border-style: solid;
  7663. left: 50%;
  7664. margin: 10px auto;
  7665. min-height: 30px;
  7666. padding: 5px;
  7667. right: 50%;
  7668. width: 500px;
  7669. background-color: #FFD1D1;
  7670. border-color: #FF0000;
  7671. color: #000;
  7672. }
  7673. </style>
  7674. <body>
  7675. <div class="error-message">
  7676. $lang_not_exportable
  7677. </div>
  7678. </body>
  7679. </html>
  7680. EOD;
  7681. if (!is_dir($archive_path.$temp_dir_short.'/document')) {
  7682. @mkdir($archive_path.$temp_dir_short.'/document', api_get_permissions_for_new_directories());
  7683. }
  7684. file_put_contents($archive_path.$temp_dir_short.'/document/non_exportable.html', $file_content);
  7685. // Add the extra files that go along with a SCORM package.
  7686. $main_code_path = api_get_path(SYS_CODE_PATH).'newscorm/packaging/';
  7687. $extra_files = scandir($main_code_path);
  7688. foreach ($extra_files as $extra_file) {
  7689. if (strpos($extra_file, '.') === 0)
  7690. continue;
  7691. else {
  7692. $dest_file = $archive_path . $temp_dir_short . '/' . $extra_file;
  7693. $this->create_path($dest_file);
  7694. copy($main_code_path.$extra_file, $dest_file);
  7695. }
  7696. }
  7697. // Finalize the imsmanifest structure, add to the zip, then return the zip.
  7698. $manifest = @$xmldoc->saveXML();
  7699. $manifest = api_utf8_decode_xml($manifest); // The manifest gets the system encoding now.
  7700. file_put_contents($archive_path.'/'.$temp_dir_short.'/imsmanifest.xml', $manifest);
  7701. $zip_folder->add($archive_path.'/'.$temp_dir_short, PCLZIP_OPT_REMOVE_PATH, $archive_path.'/'.$temp_dir_short.'/');
  7702. // Clean possible temporary files.
  7703. foreach ($files_cleanup as $file) {
  7704. $res = unlink($file);
  7705. if ($res === false) { error_log('Could not delete temp file '.$file.' '.__FILE__.' '.__LINE__, 0); }
  7706. }
  7707. // Send file to client.
  7708. //$name = 'scorm_export_'.$this->lp_id.'.zip';
  7709. require_once api_get_path(LIBRARY_PATH).'fileUpload.lib.php';
  7710. $name = replace_dangerous_char($this->get_name()).'.zip';
  7711. DocumentManager::file_send_for_download($temp_zip_file, true, $name);
  7712. }
  7713. public function scorm_export_to_pdf($lp_id) {
  7714. $lp_id = intval($lp_id);
  7715. $files_to_export = array();
  7716. $course_data = api_get_course_info($this->cc);
  7717. if (!empty($course_data)) {
  7718. $scorm_path = api_get_path(SYS_COURSE_PATH).$course_data['path'].'/scorm/'.$this->path;
  7719. require_once api_get_path(LIBRARY_PATH).'document.lib.php';
  7720. $list = $this->get_flat_ordered_items_list($lp_id);
  7721. foreach($list as $item_id) {
  7722. $item = $this->items[$item_id];
  7723. //Getting documents from a LP with chamilo documents
  7724. switch ($item->type) {
  7725. case 'document':
  7726. $file_data = DocumentManager::get_document_data_by_id($item->path, $this->cc);
  7727. $file_path = api_get_path(SYS_COURSE_PATH).$course_data['path'].'/document'.$file_data['path'];
  7728. if (file_exists($file_path)) {
  7729. $files_to_export[] = array('title'=>$item->get_title(),'path'=>$file_path);
  7730. }
  7731. break;
  7732. case 'sco':
  7733. $file_path = $scorm_path.'/'.$item->path;
  7734. if (file_exists($file_path)) {
  7735. $files_to_export[] = array('title'=>$item->get_title(),'path'=>$file_path);
  7736. }
  7737. break;
  7738. case 'dokeos_chapter':
  7739. case 'dir':
  7740. case 'chapter':
  7741. $files_to_export[] = array('title'=>$item->get_title(),'path'=>null);
  7742. break;
  7743. }
  7744. }
  7745. require_once api_get_path(LIBRARY_PATH).'pdf.lib.php';
  7746. $pdf = new PDF();
  7747. $result = $pdf->html_to_pdf($files_to_export, $this->name, $this->cc, true);
  7748. return $result;
  7749. }
  7750. return false;
  7751. }
  7752. /**
  7753. * Temp function to be moved in main_api or the best place around for this. Creates a file path
  7754. * if it doesn't exist
  7755. */
  7756. public function create_path($path) {
  7757. $path_bits = split('/', dirname($path));
  7758. // IS_WINDOWS_OS has been defined in main_api.lib.php
  7759. $path_built = IS_WINDOWS_OS ? '' : '/';
  7760. foreach ($path_bits as $bit) {
  7761. if (!empty ($bit)) {
  7762. $new_path = $path_built . $bit;
  7763. if (is_dir($new_path)) {
  7764. $path_built = $new_path . '/';
  7765. } else {
  7766. mkdir($new_path, api_get_permissions_for_new_directories());
  7767. $path_built = $new_path . '/';
  7768. }
  7769. }
  7770. }
  7771. }
  7772. /**
  7773. * Delete the image relative to this learning path. No parameter. Only works on instanciated object.
  7774. * @return boolean The results of the unlink function, or false if there was no image to start with
  7775. */
  7776. public function delete_lp_image() {
  7777. $img = $this->get_preview_image();
  7778. if ($img != '') {
  7779. $del_file = api_get_path(SYS_COURSE_PATH) . api_get_course_path() . '/upload/learning_path/images/' . $img;
  7780. $this->set_preview_image('');
  7781. return @ unlink($del_file);
  7782. } else {
  7783. return false;
  7784. }
  7785. }
  7786. /**
  7787. * Uploads an author image to the upload/learning_path/images directory
  7788. * @param array The image array, coming from the $_FILES superglobal
  7789. * @return boolean True on success, false on error
  7790. */
  7791. public function upload_image($image_array) {
  7792. $image_moved = false;
  7793. if (!empty ($image_array['name'])) {
  7794. $upload_ok = process_uploaded_file($image_array);
  7795. $has_attachment = true;
  7796. } else {
  7797. $image_moved = true;
  7798. }
  7799. if ($upload_ok) {
  7800. if ($has_attachment) {
  7801. $courseDir = api_get_course_path() . '/upload/learning_path/images';
  7802. $sys_course_path = api_get_path(SYS_COURSE_PATH);
  7803. $updir = $sys_course_path . $courseDir;
  7804. // Try to add an extension to the file if it hasn't one.
  7805. $new_file_name = add_ext_on_mime(stripslashes($image_array['name']), $image_array['type']);
  7806. if (!filter_extension($new_file_name)) {
  7807. //Display :: display_error_message(get_lang('UplUnableToSaveFileFilteredExtension'));
  7808. $image_moved = false;
  7809. } else {
  7810. $file_extension = explode('.', $image_array['name']);
  7811. $file_extension = strtolower($file_extension[sizeof($file_extension) - 1]);
  7812. $new_file_name = uniqid('') . '.' . $file_extension;
  7813. $new_path = $updir . '/' . $new_file_name;
  7814. //$result = @move_uploaded_file($image_array['tmp_name'], $new_path);
  7815. // Resize the image.
  7816. include_once api_get_path(LIBRARY_PATH).'image.lib.php';
  7817. $temp = new image($image_array['tmp_name']);
  7818. $picture_infos = @getimagesize($image_array['tmp_name']); // $picture_infos[0]-> width
  7819. if ($picture_infos[0] > 104) {
  7820. $thumbwidth = 104;
  7821. } else {
  7822. $thumbwidth = $picture_infos[0];
  7823. }
  7824. if ($picture_infos[1] > 96) {
  7825. $new_height = 96;
  7826. } else {
  7827. $new_height = $picture_infos[1];
  7828. }
  7829. //$new_height = round(($thumbwidth/$picture_infos[0])*$picture_infos[1]);
  7830. $temp->resize($thumbwidth,$new_height, 0);
  7831. $type = $picture_infos[2];
  7832. $result = false;
  7833. switch ($type) {
  7834. case 2 :
  7835. $result = $temp->send_image('JPG', $new_path);
  7836. break;
  7837. case 3 :
  7838. $result = $temp->send_image('PNG', $new_path);
  7839. break;
  7840. case 1 :
  7841. $result = $temp->send_image('GIF', $new_path);
  7842. break;
  7843. }
  7844. $temp->resize($thumbwidth, $new_height, 0);
  7845. $type = $picture_infos[2];
  7846. $result = false;
  7847. switch ($type) {
  7848. case 2 :
  7849. $result = $temp->send_image('JPG', $new_path);
  7850. break;
  7851. case 3 :
  7852. $result = $temp->send_image('PNG', $new_path);
  7853. break;
  7854. case 1 :
  7855. $result = $temp->send_image('GIF', $new_path);
  7856. break;
  7857. }
  7858. // Storing the image filename.
  7859. if ($result) {
  7860. $image_moved = true;
  7861. $this->set_preview_image($new_file_name);
  7862. return true;
  7863. }
  7864. }
  7865. }
  7866. }
  7867. return false;
  7868. }
  7869. public function set_autolunch($lp_id, $status) {
  7870. $lp_id = intval($lp_id);
  7871. $status = intval($status);
  7872. $lp_table = Database::get_course_table(TABLE_LP_MAIN);
  7873. //Setting everything to autolunch = 0
  7874. $attributes['autolunch'] = 0;
  7875. $where = array('session_id = ? '=> api_get_session_id());
  7876. Database::update($lp_table, $attributes,$where);
  7877. if ($status == 1) {
  7878. //Setting my lp_id to autolunch = 1
  7879. $attributes['autolunch'] = 1;
  7880. $where = array('id = ? AND session_id = ? '=> array($lp_id, api_get_session_id()));
  7881. Database::update($lp_table, $attributes, $where );
  7882. }
  7883. }
  7884. }
  7885. if (!function_exists('trim_value')) {
  7886. function trim_value(& $value) {
  7887. $value = trim($value);
  7888. }
  7889. }