learnpath.class.php 424 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * This class defines the parent attributes and methods for Chamilo learnpaths and SCORM
  5. * learnpaths. It is used by the scorm class.
  6. *
  7. * @package chamilo.learnpath
  8. * @author Yannick Warnier <ywarnier@beeznest.org>
  9. * @author Julio Montoya <gugli100@gmail.com> Several improvements and fixes
  10. */
  11. /**
  12. * Defines the learnpath parent class
  13. * @package chamilo.learnpath
  14. */
  15. class learnpath {
  16. public $attempt = 0; // The number for the current ID view.
  17. public $cc; // Course (code) this learnpath is located in. @todo change name for something more comprensible ...
  18. public $current; // Id of the current item the user is viewing.
  19. public $current_score; // The score of the current item.
  20. public $current_time_start; // The time the user loaded this resource (this does not mean he can see it yet).
  21. public $current_time_stop; // The time the user closed this resource.
  22. public $default_status = 'not attempted';
  23. public $encoding = 'UTF-8';
  24. public $error = '';
  25. public $extra_information = ''; // This string can be used by proprietary SCORM contents to store data about the current learnpath.
  26. public $force_commit = false; // For SCORM only - if set to true, will send a scorm LMSCommit() request on each LMSSetValue().
  27. public $index; // The index of the active learnpath_item in $ordered_items array.
  28. public $items = array();
  29. public $last; // item_id of last item viewed in the learning path.
  30. public $last_item_seen = 0; // In case we have already come in this learnpath, reuse the last item seen if authorized.
  31. public $license; // Which license this course has been given - not used yet on 20060522.
  32. public $lp_id; // DB ID for this learnpath.
  33. public $lp_view_id; // DB ID for lp_view
  34. public $log_file; // File where to log learnpath API msg.
  35. public $maker; // Which maker has conceived the content (ENI, Articulate, ...).
  36. public $message = '';
  37. public $mode = 'embedded'; // Holds the video display mode (fullscreen or embedded).
  38. public $name; // Learnpath name (they generally have one).
  39. public $ordered_items = array(); // List of the learnpath items in the order they are to be read.
  40. public $path = ''; // Path inside the scorm directory (if scorm).
  41. public $theme; // The current theme of the learning path.
  42. public $preview_image; // The current image of the learning path.
  43. // Tells if all the items of the learnpath can be tried again. Defaults to "no" (=1).
  44. public $prevent_reinit = 1;
  45. // Describes the mode of progress bar display.
  46. public $seriousgame_mode = 0;
  47. public $progress_bar_mode = '%';
  48. // Percentage progress as saved in the db.
  49. public $progress_db = '0';
  50. public $proximity; // Wether the content is distant or local or unknown.
  51. public $refs_list = array (); //list of items by ref => db_id. Used only for prerequisites match.
  52. // !!!This array (refs_list) is built differently depending on the nature of the LP.
  53. // If SCORM, uses ref, if Chamilo, uses id to keep a unique value.
  54. public $type; //type of learnpath. Could be 'dokeos', 'scorm', 'scorm2004', 'aicc', ...
  55. // TODO: Check if this type variable is useful here (instead of just in the controller script).
  56. public $user_id; //ID of the user that is viewing/using the course
  57. public $update_queue = array();
  58. public $scorm_debug = 0;
  59. public $arrMenu = array(); // Array for the menu items.
  60. public $debug = 0; // Logging level.
  61. public $lp_session_id =0;
  62. public $lp_view_session_id =0; // The specific view might be bound to a session.
  63. public $prerequisite = 0;
  64. public $use_max_score = 1; // 1 or 0
  65. public $created_on = '';
  66. public $modified_on = '';
  67. public $publicated_on = '';
  68. public $expired_on = '';
  69. /**
  70. * Class constructor. Needs a database handler, a course code and a learnpath id from the database.
  71. * Also builds the list of items into $this->items.
  72. * @param string Course code
  73. * @param integer Learnpath ID
  74. * @param integer User ID
  75. * @return boolean True on success, false on error
  76. */
  77. public function __construct($course, $lp_id, $user_id) {
  78. $this->encoding = api_get_system_encoding(); // Chamilo 1.8.8: We intend always to use the system encoding.
  79. // Check params.
  80. // Check course code.
  81. $course_db = '';
  82. $course_id = api_get_course_int_id();
  83. if ($this->debug > 0) {error_log('New LP - In learnpath::__construct('.$course.','.$lp_id.','.$user_id.')', 0); }
  84. if (empty($course)) {
  85. $this->error = 'Course code is empty';
  86. return false;
  87. } else {
  88. $main_table = Database::get_main_table(TABLE_MAIN_COURSE);
  89. $course = $this->escape_string($course);
  90. $sql = "SELECT * FROM $main_table WHERE code = '$course'";
  91. if ($this->debug > 2) { error_log('New LP - learnpath::__construct() '.__LINE__.' - Querying course: '.$sql, 0); }
  92. $res = Database::query($sql);
  93. if (Database::num_rows($res) > 0) {
  94. $this->cc = $course;
  95. $row_course = Database::fetch_array($res);
  96. $course_id = $row_course['id'];
  97. $course_db = $row_course['db_name'];
  98. } else {
  99. $this->error = 'Course code does not exist in database ('.$sql.')';
  100. return false;
  101. }
  102. }
  103. // Check learnpath ID.
  104. if (empty($lp_id)) {
  105. $this->error = 'Learnpath ID is empty';
  106. return false;
  107. } else {
  108. // TODO: Make it flexible to use any course_code (still using env course code here).
  109. $lp_table = Database::get_course_table(TABLE_LP_MAIN);
  110. //$id = Database::escape_integer($id);
  111. $lp_id = $this->escape_string($lp_id);
  112. $sql = "SELECT * FROM $lp_table WHERE id = '$lp_id' AND c_id = $course_id";
  113. if ($this->debug > 2) { error_log('New LP - learnpath::__construct() '.__LINE__.' - Querying lp: '.$sql, 0); }
  114. $res = Database::query($sql);
  115. if (Database::num_rows($res) > 0) {
  116. $this->lp_id = $lp_id;
  117. $row = Database::fetch_array($res);
  118. $this->type = $row['lp_type'];
  119. $this->name = stripslashes($row['name']);
  120. //$this->encoding = $row['default_encoding']; // Chamilo 1.8.8: We intend not to use 'default_encoding' field anymore.
  121. $this->proximity = $row['content_local'];
  122. $this->theme = $row['theme'];
  123. $this->maker = $row['content_maker'];
  124. $this->prevent_reinit = $row['prevent_reinit'];
  125. $this->seriousgame_mode = $row['seriousgame_mode'];
  126. $this->license = $row['content_license'];
  127. $this->scorm_debug = $row['debug'];
  128. $this->js_lib = $row['js_lib'];
  129. $this->path = $row['path'];
  130. $this->preview_image = $row['preview_image'];
  131. $this->author = $row['author'];
  132. $this->hide_toc_frame = $row['hide_toc_frame'];
  133. $this->lp_session_id = $row['session_id'];
  134. $this->use_max_score = $row['use_max_score'];
  135. $this->created_on = $row['created_on'];
  136. $this->modified_on = $row['modified_on'];
  137. if ($row['publicated_on'] != '0000-00-00 00:00:00') {
  138. $this->publicated_on = $row['publicated_on'];
  139. }
  140. if ($row['expired_on'] != '0000-00-00 00:00:00') {
  141. $this->expired_on = $row['expired_on'];
  142. }
  143. if ($this->type == 2) {
  144. if ($row['force_commit'] == 1) {
  145. $this->force_commit = true;
  146. }
  147. }
  148. $this->mode = $row['default_view_mod'];
  149. } else {
  150. $this->error = 'Learnpath ID does not exist in database ('.$sql.')';
  151. return false;
  152. }
  153. }
  154. // Check user ID.
  155. if (empty($user_id)) {
  156. $this->error = 'User ID is empty';
  157. return false;
  158. } else {
  159. //$main_table = Database::get_main_user_table();
  160. $main_table = Database::get_main_table(TABLE_MAIN_USER);
  161. //$user_id = Database::escape_integer($user_id);
  162. $user_id = $this->escape_string($user_id);
  163. $sql = "SELECT * FROM $main_table WHERE user_id = '$user_id'";
  164. if ($this->debug > 2) { error_log('New LP - learnpath::__construct() '.__LINE__.' - Querying user: '.$sql, 0); }
  165. $res = Database::query($sql);
  166. if (Database::num_rows($res) > 0) {
  167. $this->user_id = $user_id;
  168. } else {
  169. $this->error = 'User ID does not exist in database ('.$sql.')';
  170. return false;
  171. }
  172. }
  173. // End of variables checking.
  174. $session_id = api_get_session_id();
  175. // Get the session condition for learning paths of the base + session.
  176. $session = api_get_session_condition($session_id);
  177. // Now get the latest attempt from this user on this LP, if available, otherwise create a new one.
  178. $lp_table = Database::get_course_table(TABLE_LP_VIEW);
  179. // Selecting by view_count descending allows to get the highest view_count first.
  180. $sql = "SELECT * FROM $lp_table WHERE c_id = '.$course_id.' AND lp_id = '$lp_id' AND user_id = '$user_id' $session ORDER BY view_count DESC";
  181. if ($this->debug > 2) { error_log('New LP - learnpath::__construct() ' . __LINE__ . ' - querying lp_view: ' . $sql, 0); }
  182. $res = Database::query($sql);
  183. $view_id = 0; // Used later to query lp_item_view.
  184. if (Database :: num_rows($res) > 0) {
  185. if ($this->debug > 2) {
  186. error_log('New LP - learnpath::__construct() ' . __LINE__ . ' - Found previous view', 0);
  187. }
  188. $row = Database :: fetch_array($res);
  189. $this->attempt = $row['view_count'];
  190. $this->lp_view_id = $row['id'];
  191. $this->last_item_seen = $row['last_item'];
  192. $this->progress_db = $row['progress'];
  193. $this->lp_view_session_id = $row['session_id'];
  194. } else {
  195. if ($this->debug > 2) {
  196. error_log('New LP - learnpath::__construct() ' . __LINE__ . ' - NOT Found previous view', 0);
  197. }
  198. $this->attempt = 1;
  199. $sql_ins = "INSERT INTO $lp_table (c_id, lp_id,user_id,view_count, session_id) VALUES ($course_id, $lp_id, $user_id, 1, $session_id)";
  200. $res_ins = Database::query($sql_ins);
  201. $this->lp_view_id = Database :: insert_id();
  202. if ($this->debug > 2) {
  203. error_log('New LP - learnpath::__construct() ' . __LINE__ . ' - inserting new lp_view: ' . $sql_ins, 0);
  204. }
  205. }
  206. // Initialise items.
  207. $lp_item_table = Database::get_course_table(TABLE_LP_ITEM);
  208. $sql = "SELECT * FROM $lp_item_table WHERE c_id = $course_id AND lp_id = '".$this->lp_id."' ORDER BY parent_item_id, display_order";
  209. $res = Database::query($sql);
  210. while ($row = Database::fetch_array($res)) {
  211. $oItem = '';
  212. //$this->ordered_items[] = $row['id'];
  213. switch ($this->type) {
  214. case 3: //aicc
  215. $oItem = new aiccItem('db', $row['id'], $course_db);
  216. if (is_object($oItem)) {
  217. $my_item_id = $oItem->get_id();
  218. $oItem->set_lp_view($this->lp_view_id, $course_id);
  219. $oItem->set_prevent_reinit($this->prevent_reinit);
  220. // Don't use reference here as the next loop will make the pointed object change.
  221. $this->items[$my_item_id] = $oItem;
  222. $this->refs_list[$oItem->ref] = $my_item_id;
  223. if ($this->debug > 2) {
  224. error_log('New LP - learnpath::__construct() - aicc object with id ' . $my_item_id . ' set in items[]', 0);
  225. }
  226. }
  227. break;
  228. case 2:
  229. require_once 'scorm.class.php';
  230. require_once 'scormItem.class.php';
  231. $oItem = new scormItem('db', $row['id'], $course_db);
  232. if (is_object($oItem)) {
  233. $my_item_id = $oItem->get_id();
  234. $oItem->set_lp_view($this->lp_view_id, $course_id);
  235. $oItem->set_prevent_reinit($this->prevent_reinit);
  236. // Don't use reference here as the next loop will make the pointed object change.
  237. $this->items[$my_item_id] = $oItem;
  238. $this->refs_list[$oItem->ref] = $my_item_id;
  239. if ($this->debug > 2) {
  240. error_log('New LP - object with id ' . $my_item_id . ' set in items[]', 0);
  241. }
  242. }
  243. break;
  244. case 1:
  245. default:
  246. require_once 'learnpathItem.class.php';
  247. $oItem = new learnpathItem($row['id'], $user_id, $course_id);
  248. if (is_object($oItem)) {
  249. $my_item_id = $oItem->get_id();
  250. //$oItem->set_lp_view($this->lp_view_id); // Moved down to when we are sure the item_view exists.
  251. $oItem->set_prevent_reinit($this->prevent_reinit);
  252. // Don't use reference here as the next loop will make the pointed object change.
  253. $this->items[$my_item_id] = $oItem;
  254. $this->refs_list[$my_item_id] = $my_item_id;
  255. if ($this->debug > 2) {
  256. error_log('New LP - learnpath::__construct() ' . __LINE__ . ' - object with id ' . $my_item_id . ' set in items[]', 0);
  257. }
  258. }
  259. break;
  260. }
  261. // Items is a list of pointers to all items, classified by DB ID, not SCO id.
  262. if ($row['parent_item_id'] == 0 || empty ($this->items[$row['parent_item_id']])) {
  263. if (is_object($this->items[$row['id']])) {
  264. $this->items[$row['id']]->set_level(0);
  265. }
  266. } else {
  267. $level = $this->items[$row['parent_item_id']]->get_level() + 1;
  268. $this->items[$row['id']]->set_level($level);
  269. if (is_object($this->items[$row['parent_item_id']])) {
  270. // Items is a list of pointers from item DB ids to item objects.
  271. $this->items[$row['parent_item_id']]->add_child($row['id']);
  272. } else {
  273. if ($this->debug > 2) {
  274. error_log('New LP - learnpath::__construct() ' . __LINE__ . ' - The parent item (' . $row['parent_item_id'] . ') of item ' . $row['id'] . ' could not be found', 0);
  275. }
  276. }
  277. }
  278. // Get last viewing vars.
  279. $lp_item_view_table = Database :: get_course_table(TABLE_LP_ITEM_VIEW);
  280. // This query should only return one or zero result.
  281. $sql = "SELECT * " .
  282. "FROM $lp_item_view_table " .
  283. "WHERE c_id = ".$course_id." AND lp_view_id = " . $this->lp_view_id . " " .
  284. "AND lp_item_id = " . $row['id'] . " ORDER BY view_count DESC ";
  285. if ($this->debug > 2) {
  286. error_log('New LP - learnpath::__construct() - Selecting item_views: ' . $sql, 0);
  287. }
  288. // Get the item status.
  289. $res2 = Database::query($sql);
  290. if (Database :: num_rows($res2) > 0) {
  291. // If this learnpath has already been used by this user, get his last attempt count and
  292. // the last item seen back into this object.
  293. //$max = 0;
  294. $row2 = Database :: fetch_array($res2);
  295. if ($this->debug > 2) {
  296. error_log('New LP - learnpath::__construct() - Got item_view: ' . print_r($row2, true), 0);
  297. }
  298. if (is_object($this->items[$row['id']])) {
  299. $this->items[$row['id']]->set_status($row2['status']);
  300. if (empty ($row2['status'])) {
  301. $this->items[$row['id']]->set_status($this->default_status);
  302. }
  303. }
  304. //$this->attempt = $row['view_count'];
  305. //$this->last_item = $row['id'];
  306. } else { // No item has been found in lp_item_view for this view.
  307. // The first attempt of this user. Set attempt to 1 and last_item to 0 (first item available).
  308. // TODO: If the learnpath has not got attempts activated, always use attempt '1'.
  309. //$this->attempt = 1;
  310. //$this->last_item = 0;
  311. if (is_object($this->items[$row['id']])) {
  312. $this->items[$row['id']]->set_status($this->default_status);
  313. }
  314. // Add that row to the lp_item_view table so that we have something to show in the stats page.
  315. $sql_ins = "INSERT INTO $lp_item_view_table (c_id, lp_item_id, lp_view_id, view_count, status)
  316. VALUES ($course_id, ".$row['id'] . "," . $this->lp_view_id . ",1,'not attempted')";
  317. if ($this->debug > 2) {
  318. error_log('New LP - learnpath::__construct() ' . __LINE__ . ' - Inserting blank item_view : ' . $sql_ins, 0);
  319. }
  320. $res_ins = Database::query($sql_ins);
  321. }
  322. // Setting the view in the item object.
  323. if (is_object($this->items[$row['id']])) {
  324. $this->items[$row['id']]->set_lp_view($this->lp_view_id, $course_id);
  325. }
  326. }
  327. $this->ordered_items = $this->get_flat_ordered_items_list($this->get_id(), 0, $course_id);
  328. $this->max_ordered_items = 0;
  329. foreach ($this->ordered_items as $index => $dummy) {
  330. if ($index > $this->max_ordered_items && !empty($dummy)) {
  331. $this->max_ordered_items = $index;
  332. }
  333. }
  334. // TODO: Define the current item better.
  335. $this->first();
  336. if ($this->debug > 2) {
  337. error_log('New LP - learnpath::__construct() ' . __LINE__ . ' - End of learnpath constructor for learnpath ' . $this->get_id(), 0);
  338. }
  339. }
  340. /**
  341. * 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
  342. * I found it better to rewrite it. Old function is still available. Added also the possibility to add a description.
  343. *
  344. * @param int $parent
  345. * @param int $previous
  346. * @param string $type
  347. * @param int resource ID (ref)
  348. * @param string $title
  349. * @param string $description
  350. * @return int
  351. */
  352. public function add_item($parent, $previous, $type = 'dokeos_chapter', $id, $title, $description, $prerequisites = 0, $max_time_allowed = 0) {
  353. $course_id = api_get_course_int_id();
  354. if ($this->debug > 0) {
  355. error_log('New LP - In learnpath::add_item(' . $parent . ',' . $previous . ',' . $type . ',' . $id . ',' . $title . ')', 0);
  356. }
  357. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  358. $parent = intval($parent);
  359. $previous = intval($previous);
  360. $type = $this->escape_string($type);
  361. $id = intval($id);
  362. $max_time_allowed = $this->escape_string(htmlentities($max_time_allowed));
  363. if (empty ($max_time_allowed)) {
  364. $max_time_allowed = 0;
  365. }
  366. $title = $this->escape_string($title);
  367. $description = $this->escape_string($description);
  368. $sql_count = " SELECT COUNT(id) AS num
  369. FROM " . $tbl_lp_item . "
  370. WHERE c_id = ".$course_id." AND lp_id = " . $this->get_id() . " AND parent_item_id = " . $parent;
  371. $res_count = Database::query($sql_count);
  372. $row = Database :: fetch_array($res_count);
  373. $num = $row['num'];
  374. if ($num > 0) {
  375. if ($previous == 0) {
  376. $sql = "SELECT id, next_item_id, display_order
  377. FROM " . $tbl_lp_item . "
  378. WHERE c_id = ".$course_id." AND
  379. lp_id = " . $this->get_id() . " AND
  380. parent_item_id = " . $parent . " AND
  381. previous_item_id = 0 OR previous_item_id=" . $parent;
  382. $result = Database::query($sql);
  383. $row = Database :: fetch_array($result);
  384. $tmp_previous = 0;
  385. $next = $row['id'];
  386. $display_order = 0;
  387. } else {
  388. $previous = (int) $previous;
  389. $sql = "SELECT id, previous_item_id, next_item_id, display_order
  390. FROM " . $tbl_lp_item . "
  391. WHERE c_id = ".$course_id." AND lp_id = " . $this->get_id() . " AND id = " . $previous;
  392. $result = Database::query($sql);
  393. $row = Database :: fetch_array($result);
  394. $tmp_previous = $row['id'];
  395. $next = $row['next_item_id'];
  396. $display_order = $row['display_order'];
  397. }
  398. } else {
  399. $tmp_previous = 0;
  400. $next = 0;
  401. $display_order = 0;
  402. }
  403. $new_item_id = -1;
  404. $id = $this->escape_string($id);
  405. if ($type == 'quiz') {
  406. $sql = 'SELECT SUM(ponderation)
  407. FROM ' . Database :: get_course_table(TABLE_QUIZ_QUESTION) . ' as quiz_question
  408. INNER JOIN ' . Database :: get_course_table(TABLE_QUIZ_TEST_QUESTION) . ' as quiz_rel_question
  409. ON quiz_question.id = quiz_rel_question.question_id
  410. WHERE quiz_rel_question.exercice_id = ' . $id." AND
  411. quiz_question.c_id = $course_id AND
  412. quiz_rel_question.c_id = $course_id ";
  413. $rsQuiz = Database::query($sql);
  414. $max_score = Database :: result($rsQuiz, 0, 0);
  415. } else {
  416. $max_score = 100;
  417. }
  418. if ($prerequisites != 0) {
  419. $sql_ins = "INSERT INTO " . $tbl_lp_item . " (
  420. c_id,
  421. lp_id, ".
  422. "item_type, ".
  423. "ref, ".
  424. "title, ".
  425. "description, ".
  426. "path, ".
  427. "max_score, ".
  428. "parent_item_id, ".
  429. "previous_item_id, ".
  430. "next_item_id, ".
  431. "display_order, ".
  432. "prerequisite, ".
  433. "max_time_allowed ".
  434. ") VALUES (
  435. $course_id ,
  436. ".$this->get_id() . ", ".
  437. "'" . $type . "', ".
  438. "'', ".
  439. "'" . $title . "', ".
  440. "'" . $description . "', ".
  441. "'" . $id . "', ".
  442. "'" . $max_score . "', ".
  443. $parent . ", ".
  444. $previous . ", ".
  445. $next . ", ".
  446. ($display_order +1) . ", ".
  447. $prerequisites . ", ".
  448. $max_time_allowed .
  449. ")";
  450. } else {
  451. // Insert new item.
  452. $sql_ins = "
  453. INSERT INTO " . $tbl_lp_item . " ( ".
  454. "c_id, ".
  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. $course_id. ",".
  469. $this->get_id() . ",".
  470. "'" . $type . "',".
  471. "'',".
  472. "'" . $title . "',".
  473. "'" . $description . "',".
  474. "'" . $id . "',".
  475. "'" . $max_score . "',".
  476. $parent . ",".
  477. $previous . ",".
  478. $next . ",".
  479. ($display_order +1) . ",".
  480. $max_time_allowed .
  481. ")";
  482. }
  483. if ($this->debug > 2) {
  484. error_log('New LP - Inserting dokeos_chapter: ' . $sql_ins, 0);
  485. }
  486. $res_ins = Database::query($sql_ins);
  487. if ($res_ins > 0) {
  488. $new_item_id = Database :: insert_id($res_ins);
  489. // Update the item that should come after the new item.
  490. $sql_update_next = "
  491. UPDATE " . $tbl_lp_item . "
  492. SET previous_item_id = " . $new_item_id . "
  493. WHERE c_id = $course_id AND id = " . $next;
  494. $res_update_next = Database::query($sql_update_next);
  495. // Update the item that should be before the new item.
  496. $sql_update_previous = "
  497. UPDATE " . $tbl_lp_item . "
  498. SET next_item_id = " . $new_item_id . "
  499. WHERE c_id = $course_id AND id = " . $tmp_previous;
  500. $res_update_previous = Database::query($sql_update_previous);
  501. // Update all the items after the new item.
  502. $sql_update_order = "
  503. UPDATE " . $tbl_lp_item . "
  504. SET display_order = display_order + 1
  505. WHERE
  506. c_id = $course_id AND
  507. lp_id = " . $this->get_id() . " AND
  508. id <> " . $new_item_id . " AND
  509. parent_item_id = " . $parent . " AND
  510. display_order > " . $display_order;
  511. $res_update_previous = Database::query($sql_update_order);
  512. // Update the item that should come after the new item.
  513. $sql_update_ref = "UPDATE " . $tbl_lp_item . "
  514. SET ref = " . $new_item_id . "
  515. WHERE c_id = $course_id AND id = " . $new_item_id;
  516. Database::query($sql_update_ref);
  517. }
  518. // Upload audio.
  519. if (!empty ($_FILES['mp3']['name'])) {
  520. // Create the audio folder if it does not exist yet.
  521. global $_course;
  522. $filepath = api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document/';
  523. if (!is_dir($filepath . 'audio')) {
  524. mkdir($filepath . 'audio', api_get_permissions_for_new_directories());
  525. $audio_id = add_document($_course, '/audio', 'folder', 0, 'audio');
  526. api_item_property_update($_course, TOOL_DOCUMENT, $audio_id, 'FolderCreated', api_get_user_id(), null, null, null, null, api_get_session_id());
  527. }
  528. // Upload the file in the documents tool.
  529. include_once api_get_path(LIBRARY_PATH).'fileUpload.lib.php';
  530. $file_path = handle_uploaded_document($_course, $_FILES['mp3'], api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document', '/audio', api_get_user_id(), '', '', '', '', '', false);
  531. // Getting the filename only.
  532. $file_components = explode('/', $file_path);
  533. $file = $file_components[count($file_components) - 1];
  534. // Store the mp3 file in the lp_item table.
  535. $sql_insert_audio = "UPDATE $tbl_lp_item SET audio = '" . Database :: escape_string($file) . "' WHERE id = '" . Database :: escape_string($new_item_id) . "'";
  536. Database::query($sql_insert_audio);
  537. }
  538. return $new_item_id;
  539. }
  540. /**
  541. * Static admin function allowing addition of a learnpath to a course.
  542. * @param string Course code
  543. * @param string Learnpath name
  544. * @param string Learnpath description string, if provided
  545. * @param string Type of learnpath (default = 'guess', others = 'dokeos', 'aicc',...)
  546. * @param string Type of files origin (default = 'zip', others = 'dir','web_dir',...)
  547. * @param string Zip file containing the learnpath or directory containing the learnpath
  548. * @return integer The new learnpath ID on success, 0 on failure
  549. */
  550. public function add_lp($course, $name, $description = '', $learnpath = 'guess', $origin = 'zip', $zipname = '', $publicated_on = '', $expired_on = '') {
  551. global $charset;
  552. $course_id = api_get_course_int_id();
  553. $tbl_lp = Database :: get_course_table(TABLE_LP_MAIN);
  554. // Check course code exists.
  555. // Check lp_name doesn't exist, otherwise append something.
  556. $i = 0;
  557. $name = learnpath :: escape_string($name);
  558. // Session id.
  559. $session_id = api_get_session_id();
  560. $check_name = "SELECT * FROM $tbl_lp WHERE c_id = ".$course_id." AND name = '$name'";
  561. //if ($this->debug > 2) { error_log('New LP - Checking the name for new LP: '.$check_name, 0); }
  562. $res_name = Database::query($check_name);
  563. if ($publicated_on == '0000-00-00 00:00:00' || empty($publicated_on)) {
  564. //by default the publication date is the same that the creation date
  565. //The behaviour above was changed due BT#2800
  566. global $_custom;
  567. if (isset($_custom['lps_hidden_when_no_start_date']) && $_custom['lps_hidden_when_no_start_date']) {
  568. $publicated_on = '';
  569. } else {
  570. $publicated_on = api_get_utc_datetime();
  571. }
  572. } else {
  573. $publicated_on = Database::escape_string(api_get_utc_datetime($publicated_on));
  574. }
  575. if ($expired_on == '0000-00-00 00:00:00' || empty($expired_on)) {
  576. $expired_on = '';
  577. } else {
  578. $expired_on = Database::escape_string(api_get_utc_datetime($expired_on));
  579. }
  580. while (Database :: num_rows($res_name)) {
  581. // There is already one such name, update the current one a bit.
  582. $i++;
  583. $name = $name . ' - ' . $i;
  584. $check_name = "SELECT * FROM $tbl_lp WHERE c_id = ".$course_id." AND name = '$name'";
  585. //if ($this->debug > 2) { error_log('New LP - Checking the name for new LP: '.$check_name, 0); }
  586. $res_name = Database::query($check_name);
  587. }
  588. // New name does not exist yet; keep it.
  589. // Escape description.
  590. $description = learnpath :: escape_string(api_htmlentities($description, ENT_QUOTES, $charset)); // Kevin: added htmlentities().
  591. $type = 1;
  592. switch ($learnpath) {
  593. case 'guess':
  594. break;
  595. case 'dokeos':
  596. case 'chamilo':
  597. $type = 1;
  598. break;
  599. case 'aicc':
  600. break;
  601. }
  602. switch ($origin) {
  603. case 'zip':
  604. // Check zipname string. If empty, we are currently creating a new Chamilo learnpath.
  605. break;
  606. case 'manual':
  607. default:
  608. $get_max = "SELECT MAX(display_order) FROM $tbl_lp WHERE c_id = ".$course_id." ";
  609. $res_max = Database::query($get_max);
  610. if (Database :: num_rows($res_max) < 1) {
  611. $dsp = 1;
  612. } else {
  613. $row = Database :: fetch_array($res_max);
  614. $dsp = $row[0] + 1;
  615. }
  616. $sql_insert = "INSERT INTO $tbl_lp (c_id, 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) " .
  617. "VALUES ($course_id, $type,'$name','$description','','embedded','UTF-8','$dsp','Chamilo','local','','".$session_id."', '".api_get_utc_datetime()."' , '".$publicated_on."' , '".$expired_on."')";
  618. $res_insert = Database::query($sql_insert);
  619. $id = Database :: insert_id();
  620. if ($id > 0) {
  621. // Insert into item_property.
  622. api_item_property_update(api_get_course_info(), TOOL_LEARNPATH, $id, 'LearnpathAdded', api_get_user_id());
  623. return $id;
  624. }
  625. break;
  626. }
  627. }
  628. /**
  629. * Appends a message to the message attribute
  630. * @param string Message to append.
  631. */
  632. public function append_message($string) {
  633. if ($this->debug > 0) {
  634. error_log('New LP - In learnpath::append_message()', 0);
  635. }
  636. $this->message .= $string;
  637. }
  638. /**
  639. * Autocompletes the parents of an item in case it's been completed or passed
  640. * @param integer Optional ID of the item from which to look for parents
  641. */
  642. public function autocomplete_parents($item) {
  643. $course_id = api_get_course_int_id();
  644. if ($this->debug > 0) {
  645. error_log('New LP - In learnpath::autocomplete_parents()', 0);
  646. }
  647. if (empty ($item)) {
  648. $item = $this->current;
  649. }
  650. $parent_id = $this->items[$item]->get_parent();
  651. if ($this->debug > 2) {
  652. error_log('New LP - autocompleting parent of item ' . $item . ' (item ' . $parent_id . ')', 0);
  653. }
  654. if (is_object($this->items[$item]) and !empty ($parent_id)) {
  655. // if $item points to an object and there is a parent.
  656. if ($this->debug > 2) {
  657. error_log('New LP - ' . $item . ' is an item, proceed', 0);
  658. }
  659. $current_item = & $this->items[$item];
  660. $parent = & $this->items[$parent_id]; // Get the parent.
  661. // New experiment including failed and browsed in completed status.
  662. $current_status = $current_item->get_status();
  663. if ($current_item->is_done() || $current_status == 'browsed' || $current_status == 'failed') {
  664. // If the current item is completed or passes or succeeded.
  665. $completed = true;
  666. if ($this->debug > 2) {
  667. error_log('New LP - Status of current item is alright', 0);
  668. }
  669. foreach ($parent->get_children() as $child) {
  670. // Check all his brothers (his parent's children) for completion status.
  671. if ($child != $item) {
  672. if ($this->debug > 2) {
  673. error_log('New LP - Looking at brother with ID ' . $child . ', status is ' . $this->items[$child]->get_status(), 0);
  674. }
  675. //if($this->items[$child]->status_is(array('completed','passed','succeeded')))
  676. // Trying completing parents of failed and browsed items as well.
  677. if ($this->items[$child]->status_is(array (
  678. 'completed',
  679. 'passed',
  680. 'succeeded',
  681. 'browsed',
  682. 'failed'
  683. ))) {
  684. // Keep completion status to true.
  685. } else {
  686. if ($this->debug > 2) {
  687. error_log('New LP - Found one incomplete child of ' . $parent_id . ': ' . $child . ' is ' . $this->items[$child]->get_status(), 0);
  688. }
  689. $completed = false;
  690. }
  691. }
  692. }
  693. if ($completed) { // If all the children were completed:
  694. $parent->set_status('completed');
  695. $parent->save(false, $this->prerequisites_match($parent->get_id()));
  696. $this->update_queue[$parent->get_id()] = $parent->get_status();
  697. if ($this->debug > 2) {
  698. error_log('New LP - Added parent to update queue ' . print_r($this->update_queue, true), 0);
  699. }
  700. $this->autocomplete_parents($parent->get_id()); // Recursive call.
  701. }
  702. } else {
  703. //error_log('New LP - status of current item is not enough to get bothered with it', 0);
  704. }
  705. }
  706. }
  707. /**
  708. * Autosaves the current results into the database for the whole learnpath
  709. */
  710. public function autosave() {
  711. if ($this->debug > 0) {
  712. error_log('New LP - In learnpath::autosave()', 0);
  713. }
  714. // TODO: Add save operations for the learnpath itself.
  715. }
  716. /**
  717. * Clears the message attribute
  718. */
  719. public function clear_message() {
  720. if ($this->debug > 0) {
  721. error_log('New LP - In learnpath::clear_message()', 0);
  722. }
  723. $this->message = '';
  724. }
  725. /**
  726. * Closes the current resource
  727. *
  728. * Stops the timer
  729. * Saves into the database if required
  730. * Clears the current resource data from this object
  731. * @return boolean True on success, false on failure
  732. */
  733. public function close() {
  734. $course_id = api_get_course_int_id();
  735. if ($this->debug > 0) {
  736. error_log('New LP - In learnpath::close()', 0);
  737. }
  738. if (empty ($this->lp_id)) {
  739. $this->error = 'Trying to close this learnpath but no ID is set';
  740. return false;
  741. }
  742. $this->current_time_stop = time();
  743. if ($this->save) {
  744. $learnpath_view_table = Database :: get_course_table(TABLE_LP_VIEW);
  745. /*
  746. $sql = "UPDATE $learnpath_view_table " .
  747. "SET " .
  748. "stop_time = ".$this->current_time_stop.", " .
  749. "score = ".$this->current_score.", ".
  750. "WHERE learnpath_id = '".$this->lp_id."'";
  751. //$res = Database::query($sql);
  752. $res = Database::query($res);
  753. if (Database::affected_rows($res) < 1) {
  754. $this->error = 'Could not update learnpath_view table while closing learnpath';
  755. return false;
  756. }
  757. */
  758. }
  759. $this->ordered_items = array ();
  760. $this->index = 0;
  761. unset ($this->lp_id);
  762. //unset other stuff
  763. return true;
  764. }
  765. /**
  766. * Static admin function allowing removal of a learnpath
  767. * @param string Course code
  768. * @param integer Learnpath ID
  769. * @param string Whether to delete data or keep it (default: 'keep', others: 'remove')
  770. * @return boolean True on success, false on failure (might change that to return number of elements deleted)
  771. */
  772. public function delete($course = null, $id = null, $delete = 'keep') {
  773. $course_id = api_get_course_int_id();
  774. // TODO: Implement a way of getting this to work when the current object is not set.
  775. // In clear: implement this in the item class as well (abstract class) and use the given ID in queries.
  776. //if (empty($course)) { $course = api_get_course_id(); }
  777. //if (empty($id)) { $id = $this->get_id(); }
  778. // If an ID is specifically given and the current LP is not the same, prevent delete.
  779. if (!empty ($id) && ($id != $this->lp_id)) {
  780. return false;
  781. }
  782. $lp = Database :: get_course_table(TABLE_LP_MAIN);
  783. $lp_item = Database :: get_course_table(TABLE_LP_ITEM); // Proposed by Christophe (clefevre), see below.
  784. $lp_view = Database :: get_course_table(TABLE_LP_VIEW);
  785. $lp_item_view = Database :: get_course_table(TABLE_LP_ITEM_VIEW);
  786. //if ($this->debug > 0) { error_log('New LP - In learnpath::delete()', 0); }
  787. // Delete lp item id.
  788. foreach ($this->items as $id => $dummy) {
  789. //$this->items[$id]->delete();
  790. $sql_del_view = "DELETE FROM $lp_item_view WHERE c_id = $course_id AND lp_item_id = '" . $id . "'";
  791. $res_del_item_view = Database::query($sql_del_view);
  792. }
  793. // Proposed by Christophe (nickname: clefevre), see http://www.dokeos.com/forum/viewtopic.php?t=29673
  794. $sql_del_item = "DELETE FROM $lp_item WHERE c_id = ".$course_id." AND lp_id = " . $this->lp_id;
  795. $res_del_item = Database::query($sql_del_item);
  796. $sql_del_view = "DELETE FROM $lp_view WHERE c_id = ".$course_id." AND lp_id = " . $this->lp_id;
  797. //if ($this->debug > 2) { error_log('New LP - Deleting views bound to lp '.$this->lp_id.': '.$sql_del_view, 0); }
  798. $res_del_view = Database::query($sql_del_view);
  799. $this->toggle_publish($this->lp_id, 'i');
  800. //if ($this->debug > 2) { error_log('New LP - Deleting lp '.$this->lp_id.' of type '.$this->type, 0); }
  801. if ($this->type == 2 || $this->type == 3) {
  802. // This is a scorm learning path, delete the files as well.
  803. $sql = "SELECT path FROM $lp WHERE c_id = ".$course_id." AND id = " . $this->lp_id;
  804. $res = Database::query($sql);
  805. if (Database :: num_rows($res) > 0) {
  806. $row = Database :: fetch_array($res);
  807. $path = $row['path'];
  808. $sql = "SELECT id FROM $lp WHERE c_id = ".$course_id." AND path = '$path' AND id != " . $this->lp_id;
  809. $res = Database::query($sql);
  810. if (Database :: num_rows($res) > 0) { // Another learning path uses this directory, so don't delete it.
  811. if ($this->debug > 2) {
  812. error_log('New LP - In learnpath::delete(), found other LP using path ' . $path . ', keeping directory', 0);
  813. }
  814. } else {
  815. // No other LP uses that directory, delete it.
  816. $course_rel_dir = api_get_course_path() . '/scorm/'; // scorm dir web path starting from /courses
  817. $course_scorm_dir = api_get_path(SYS_COURSE_PATH) . $course_rel_dir; // The absolute system path for this course.
  818. if ($delete == 'remove' && is_dir($course_scorm_dir . $path) and !empty ($course_scorm_dir)) {
  819. if ($this->debug > 2) {
  820. error_log('New LP - In learnpath::delete(), found SCORM, deleting directory: ' . $course_scorm_dir . $path, 0);
  821. }
  822. // Proposed by Christophe (clefevre).
  823. if (strcmp(substr($path, -2), "/.") == 0) {
  824. $path = substr($path, 0, -1); // Remove "." at the end.
  825. }
  826. //exec('rm -rf ' . $course_scorm_dir . $path); // See Bug #5208, this is not OS-portable way.
  827. rmdirr($course_scorm_dir . $path);
  828. }
  829. }
  830. }
  831. }
  832. $sql_del_lp = "DELETE FROM $lp WHERE c_id = ".$course_id." AND id = " . $this->lp_id;
  833. //if ($this->debug > 2) { error_log('New LP - Deleting lp '.$this->lp_id.': '.$sql_del_lp, 0); }
  834. $res_del_lp = Database::query($sql_del_lp);
  835. $this->update_display_order(); // Updates the display order of all lps.
  836. api_item_property_update(api_get_course_info(), TOOL_LEARNPATH, $this->lp_id, 'delete', api_get_user_id());
  837. require_once '../gradebook/lib/be.inc.php';
  838. // Delete link of gradebook tool
  839. //$tbl_grade_link = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_LINK);
  840. /*$sql = 'SELECT gl.id FROM ' . $tbl_grade_link . ' gl WHERE gl.type="4" AND gl.ref_id="' . $id . '";';
  841. $result = Database::query($sql);
  842. $row = Database :: fetch_array($result, 'ASSOC');*/
  843. // Fixing gradebook link deleted see #5229.
  844. /*
  845. if (!empty($row['id'])) {
  846. $link = LinkFactory :: load($row['id']);
  847. if ($link[0] != null) {
  848. $link[0]->delete();
  849. }
  850. }*/
  851. require_once api_get_path(SYS_CODE_PATH).'gradebook/lib/gradebook_functions.inc.php';
  852. $link_id = is_resource_in_course_gradebook(api_get_course_id(), 4 , $id, api_get_session_id());
  853. if ($link_id !== false) {
  854. remove_resource_from_course_gradebook($link_id);
  855. }
  856. if (api_get_setting('search_enabled') == 'true') {
  857. require_once api_get_path(LIBRARY_PATH).'specific_fields_manager.lib.php';
  858. $r = delete_all_values_for_item($this->cc, TOOL_LEARNPATH, $this->lp_id);
  859. }
  860. }
  861. /**
  862. * Removes all the children of one item - dangerous!
  863. * @param integer Element ID of which children have to be removed
  864. * @return integer Total number of children removed
  865. */
  866. public function delete_children_items($id) {
  867. $course_id = api_get_course_int_id();
  868. if ($this->debug > 0) {
  869. error_log('New LP - In learnpath::delete_children_items(' . $id . ')', 0);
  870. }
  871. $num = 0;
  872. if (empty ($id) || $id != strval(intval($id))) {
  873. return false;
  874. }
  875. $lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  876. $sql = "SELECT * FROM $lp_item WHERE c_id = ".$course_id." AND parent_item_id = $id";
  877. $res = Database::query($sql);
  878. while ($row = Database :: fetch_array($res)) {
  879. $num += $this->delete_children_items($row['id']);
  880. $sql_del = "DELETE FROM $lp_item WHERE c_id = ".$course_id." AND id = " . $row['id'];
  881. $res_del = Database::query($sql_del);
  882. $num++;
  883. }
  884. return $num;
  885. }
  886. /**
  887. * Removes an item from the current learnpath
  888. * @param integer Elem ID (0 if first)
  889. * @param integer Whether to remove the resource/data from the system or leave it (default: 'keep', others 'remove')
  890. * @return integer Number of elements moved
  891. * @todo implement resource removal
  892. */
  893. public function delete_item($id, $remove = 'keep') {
  894. $course_id = api_get_course_int_id();
  895. if ($this->debug > 0) {
  896. error_log('New LP - In learnpath::delete_item()', 0);
  897. }
  898. // TODO: Implement the resource removal.
  899. if (empty ($id) || $id != strval(intval($id))) {
  900. return false;
  901. }
  902. // First select item to get previous, next, and display order.
  903. $lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  904. $sql_sel = "SELECT * FROM $lp_item WHERE c_id = ".$course_id." AND id = $id";
  905. $res_sel = Database::query($sql_sel);
  906. if (Database :: num_rows($res_sel) < 1) {
  907. return false;
  908. }
  909. $row = Database :: fetch_array($res_sel);
  910. $previous = $row['previous_item_id'];
  911. $next = $row['next_item_id'];
  912. $display = $row['display_order'];
  913. $parent = $row['parent_item_id'];
  914. $lp = $row['lp_id'];
  915. // Delete children items.
  916. $num = $this->delete_children_items($id);
  917. if ($this->debug > 2) {
  918. error_log('New LP - learnpath::delete_item() - deleted ' . $num . ' children of element ' . $id, 0);
  919. }
  920. // Now delete the item.
  921. $sql_del = "DELETE FROM $lp_item WHERE c_id = $course_id AND id = $id";
  922. if ($this->debug > 2) {
  923. error_log('New LP - Deleting item: ' . $sql_del, 0);
  924. }
  925. $res_del = Database::query($sql_del);
  926. // Now update surrounding items.
  927. $sql_upd = "UPDATE $lp_item SET next_item_id = $next WHERE c_id = ".$course_id." AND id = $previous";
  928. $res_upd = Database::query($sql_upd);
  929. $sql_upd = "UPDATE $lp_item SET previous_item_id = $previous WHERE c_id = ".$course_id." AND id = $next";
  930. $res_upd = Database::query($sql_upd);
  931. // Now update all following items with new display order.
  932. $sql_all = "UPDATE $lp_item SET display_order = display_order-1 WHERE c_id = ".$course_id." AND lp_id = $lp AND parent_item_id = $parent AND display_order > $display";
  933. $res_all = Database::query($sql_all);
  934. //Removing prerequisites since the item will not longer exist
  935. $sql_all = "UPDATE $lp_item SET prerequisite = '' WHERE c_id = ".$course_id." AND prerequisite = $id";
  936. $res_all = Database::query($sql_all);
  937. // Remove from search engine if enabled.
  938. if (api_get_setting('search_enabled') == 'true') {
  939. $tbl_se_ref = Database :: get_main_table(TABLE_MAIN_SEARCH_ENGINE_REF);
  940. $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';
  941. $sql = sprintf($sql, $tbl_se_ref, $this->cc, TOOL_LEARNPATH, $lp, $id);
  942. $res = Database::query($sql);
  943. if (Database :: num_rows($res) > 0) {
  944. $row2 = Database :: fetch_array($res);
  945. require_once api_get_path(LIBRARY_PATH).'search/DokeosIndexer.class.php';
  946. $di = new DokeosIndexer();
  947. $di->remove_document((int) $row2['search_did']);
  948. }
  949. $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';
  950. $sql = sprintf($sql, $tbl_se_ref, $this->cc, TOOL_LEARNPATH, $lp, $id);
  951. Database::query($sql);
  952. }
  953. }
  954. /**
  955. * Updates an item's content in place
  956. * @param integer Element ID
  957. * @param integer Parent item ID
  958. * @param integer Previous item ID
  959. * @param string Item title
  960. * @param string Item description
  961. * @param string Prerequisites (optional)
  962. * @param string Indexing terms (optional)
  963. * @param array The array resulting of the $_FILES[mp3] element
  964. * @return boolean True on success, false on error
  965. */
  966. public function edit_item($id, $parent, $previous, $title, $description, $prerequisites = 0, $audio = null, $max_time_allowed = 0) {
  967. $course_id = api_get_course_int_id();
  968. if ($this->debug > 0) {
  969. error_log('New LP - In learnpath::edit_item()', 0);
  970. }
  971. if (empty ($max_time_allowed)) {
  972. $max_time_allowed = 0;
  973. }
  974. if (empty ($id) || ($id != strval(intval($id))) || empty ($title)) {
  975. return false;
  976. }
  977. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  978. $sql_select = "SELECT * FROM " . $tbl_lp_item . " WHERE c_id = ".$course_id." AND id = " . $id;
  979. $res_select = Database::query($sql_select);
  980. $row_select = Database :: fetch_array($res_select);
  981. $audio_update_sql = '';
  982. if (is_array($audio) && !empty ($audio['tmp_name']) && $audio['error'] === 0) {
  983. // Create the audio folder if it does not exist yet.
  984. global $_course;
  985. $filepath = api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document/';
  986. if (!is_dir($filepath . 'audio')) {
  987. mkdir($filepath . 'audio', api_get_permissions_for_new_directories());
  988. $audio_id = add_document($_course, '/audio', 'folder', 0, 'audio');
  989. api_item_property_update($_course, TOOL_DOCUMENT, $audio_id, 'FolderCreated', api_get_user_id(), null, null, null, null, api_get_session_id());
  990. }
  991. // Upload file in documents.
  992. $pi = pathinfo($audio['name']);
  993. if ($pi['extension'] == 'mp3') {
  994. $c_det = api_get_course_info($this->cc);
  995. $bp = api_get_path(SYS_COURSE_PATH) . $c_det['path'] . '/document';
  996. $path = handle_uploaded_document($c_det, $audio, $bp, '/audio', api_get_user_id(), 0, null, '', 0, 'rename', false, 0);
  997. $path = substr($path, 7);
  998. // Update reference in lp_item - audio path is the path from inside de document/audio/ dir.
  999. $audio_update_sql = ", audio = '" . Database :: escape_string($path) . "' ";
  1000. }
  1001. }
  1002. $same_parent = ($row_select['parent_item_id'] == $parent) ? true : false;
  1003. $same_previous = ($row_select['previous_item_id'] == $previous) ? true : false;
  1004. // TODO: htmlspecialchars to be checked for encoding related problems.
  1005. if ($same_parent && $same_previous) {
  1006. // Only update title and description.
  1007. $sql_update = " UPDATE " . $tbl_lp_item . "
  1008. SET title = '" . $this->escape_string($title) . "',
  1009. prerequisite = '" . $prerequisites . "',
  1010. description = '" . $this->escape_string($description) . "'
  1011. " . $audio_update_sql . ",
  1012. max_time_allowed = '" . $this->escape_string($max_time_allowed) . "'
  1013. WHERE c_id = ".$course_id." AND id = " . $id;
  1014. $res_update = Database::query($sql_update);
  1015. } else {
  1016. $old_parent = $row_select['parent_item_id'];
  1017. $old_previous = $row_select['previous_item_id'];
  1018. $old_next = $row_select['next_item_id'];
  1019. $old_order = $row_select['display_order'];
  1020. $old_prerequisite = $row_select['prerequisite'];
  1021. $old_max_time_allowed = $row_select['max_time_allowed'];
  1022. /* BEGIN -- virtually remove the current item id */
  1023. /* for the next and previous item it is like the current item doesn't exist anymore */
  1024. if ($old_previous != 0) {
  1025. $sql_update_next = "
  1026. UPDATE " . $tbl_lp_item . "
  1027. SET next_item_id = " . $old_next . "
  1028. WHERE c_id = ".$course_id." AND id = " . $old_previous;
  1029. $res_update_next = Database::query($sql_update_next);
  1030. //echo '<p>' . $sql_update_next . '</p>';
  1031. }
  1032. if ($old_next != 0) {
  1033. $sql_update_previous = "
  1034. UPDATE " . $tbl_lp_item . "
  1035. SET previous_item_id = " . $old_previous . "
  1036. WHERE c_id = ".$course_id." AND id = " . $old_next;
  1037. $res_update_previous = Database::query($sql_update_previous);
  1038. //echo '<p>' . $sql_update_previous . '</p>';
  1039. }
  1040. // display_order - 1 for every item with a display_order bigger then the display_order of the current item.
  1041. $sql_update_order = "
  1042. UPDATE " . $tbl_lp_item . "
  1043. SET display_order = display_order - 1
  1044. WHERE
  1045. c_id = ".$course_id." AND
  1046. display_order > " . $old_order . " AND lp_id = " . $this->lp_id . " AND
  1047. parent_item_id = " . $old_parent;
  1048. $res_update_order = Database::query($sql_update_order);
  1049. //echo '<p>' . $sql_update_order . '</p>';
  1050. /* END -- virtually remove the current item id */
  1051. /* BEGIN -- update the current item id to his new location */
  1052. if ($previous == 0) {
  1053. // Select the data of the item that should come after the current item.
  1054. $sql_select_old = "SELECT id, display_order
  1055. FROM " . $tbl_lp_item . "
  1056. WHERE
  1057. c_id = ".$course_id." AND
  1058. lp_id = " . $this->lp_id . " AND
  1059. parent_item_id = " . $parent . " AND
  1060. previous_item_id = " . $previous;
  1061. $res_select_old = Database::query($sql_select_old);
  1062. $row_select_old = Database :: fetch_array($res_select_old);
  1063. //echo '<p>' . $sql_select_old . '</p>';
  1064. // If the new parent didn't have children before.
  1065. if (Database :: num_rows($res_select_old) == 0) {
  1066. $new_next = 0;
  1067. $new_order = 1;
  1068. } else {
  1069. $new_next = $row_select_old['id'];
  1070. $new_order = $row_select_old['display_order'];
  1071. }
  1072. //echo 'New next_item_id of current item: ' . $new_next . '<br />';
  1073. //echo 'New previous_item_id of current item: ' . $previous . '<br />';
  1074. //echo 'New display_order of current item: ' . $new_order . '<br />';
  1075. } else {
  1076. // Select the data of the item that should come before the current item.
  1077. $sql_select_old = " SELECT next_item_id, display_order
  1078. FROM " . $tbl_lp_item . "
  1079. WHERE c_id = ".$course_id." AND id = " . $previous;
  1080. $res_select_old = Database::query($sql_select_old);
  1081. $row_select_old = Database :: fetch_array($res_select_old);
  1082. //echo '<p>' . $sql_select_old . '</p>';
  1083. //echo 'New next_item_id of current item: ' . $row_select_old['next_item_id'] . '<br />';
  1084. //echo 'New previous_item_id of current item: ' . $previous . '<br />';
  1085. //echo 'New display_order of current item: ' . ($row_select_old['display_order'] + 1) . '<br />';
  1086. $new_next = $row_select_old['next_item_id'];
  1087. $new_order = $row_select_old['display_order'] + 1;
  1088. }
  1089. // TODO: htmlspecialchars to be checked for encoding related problems.
  1090. // Update the current item with the new data.
  1091. $sql_update = "UPDATE " . $tbl_lp_item . "
  1092. SET
  1093. title = '" . $this->escape_string($title) . "',
  1094. description = '" . $this->escape_string($description) . "',
  1095. parent_item_id = " . $parent . ",
  1096. previous_item_id = " . $previous . ",
  1097. next_item_id = " . $new_next . ",
  1098. display_order = " . $new_order . "
  1099. " . $audio_update_sql . "
  1100. WHERE c_id = ".$course_id." AND id = " . $id;
  1101. $res_update_next = Database::query($sql_update);
  1102. //echo '<p>' . $sql_update . '</p>';
  1103. if ($previous != 0) {
  1104. // Update the previous item's next_item_id.
  1105. $sql_update_previous = "
  1106. UPDATE " . $tbl_lp_item . "
  1107. SET next_item_id = " . $id . "
  1108. WHERE c_id = ".$course_id." AND id = " . $previous;
  1109. $res_update_next = Database::query($sql_update_previous);
  1110. //echo '<p>' . $sql_update_previous . '</p>';
  1111. }
  1112. if ($new_next != 0) {
  1113. // Update the next item's previous_item_id.
  1114. $sql_update_next = "
  1115. UPDATE " . $tbl_lp_item . "
  1116. SET previous_item_id = " . $id . "
  1117. WHERE c_id = ".$course_id." AND id = " . $new_next;
  1118. $res_update_next = Database::query($sql_update_next);
  1119. //echo '<p>' . $sql_update_next . '</p>';
  1120. }
  1121. if ($old_prerequisite != $prerequisites) {
  1122. $sql_update_next = "
  1123. UPDATE " . $tbl_lp_item . "
  1124. SET prerequisite = " . $prerequisites . "
  1125. WHERE c_id = ".$course_id." AND id = " . $id;
  1126. $res_update_next = Database::query($sql_update_next);
  1127. }
  1128. if ($old_max_time_allowed != $max_time_allowed) {
  1129. $sql_update_max_time_allowed = "
  1130. UPDATE " . $tbl_lp_item . "
  1131. SET max_time_allowed = " . $max_time_allowed . "
  1132. WHERE c_id = ".$course_id." AND id = " . $id;
  1133. $res_update_max_time_allowed = Database::query($sql_update_max_time_allowed);
  1134. }
  1135. // Update all the items with the same or a bigger display_order than the current item.
  1136. $sql_update_order = "
  1137. UPDATE " . $tbl_lp_item . "
  1138. SET display_order = display_order + 1
  1139. WHERE
  1140. c_id = ".$course_id." AND
  1141. lp_id = " . $this->get_id() . " AND
  1142. id <> " . $id . " AND
  1143. parent_item_id = " . $parent . " AND
  1144. display_order >= " . $new_order;
  1145. $res_update_next = Database::query($sql_update_order);
  1146. }
  1147. }
  1148. /**
  1149. * Updates an item's prereq in place
  1150. * @param integer Element ID
  1151. * @param string Prerequisite Element ID
  1152. * @param string Prerequisite item type
  1153. * @param string Prerequisite min score
  1154. * @param string Prerequisite max score
  1155. * @return boolean True on success, false on error
  1156. */
  1157. public function edit_item_prereq($id, $prerequisite_id, $mastery_score = 0, $max_score = 100) {
  1158. $course_id = api_get_course_int_id();
  1159. if ($this->debug > 0) {
  1160. error_log('New LP - In learnpath::edit_item_prereq(' . $id . ',' . $prerequisite_id . ',' . $mastery_score . ',' . $max_score . ')', 0);
  1161. }
  1162. if (empty ($id) or ($id != strval(intval($id))) or empty ($prerequisite_id)) {
  1163. return false;
  1164. }
  1165. $prerequisite_id = $this->escape_string($prerequisite_id);
  1166. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  1167. if (!is_numeric($mastery_score) || $mastery_score < 0)
  1168. $mastery_score = 0;
  1169. if (!is_numeric($max_score) || $max_score < 0)
  1170. $max_score = 100;
  1171. if ($mastery_score > $max_score)
  1172. $max_score = $mastery_score;
  1173. if (!is_numeric($prerequisite_id))
  1174. $prerequisite_id = 'NULL';
  1175. $sql_upd = " UPDATE " . $tbl_lp_item . "
  1176. SET prerequisite = " . $prerequisite_id . " WHERE c_id = ".$course_id." AND id = " . $id;
  1177. $res_upd = Database::query($sql_upd);
  1178. if ($prerequisite_id != 'NULL' && $prerequisite_id != '') {
  1179. $sql_upd = " UPDATE " . $tbl_lp_item . " SET
  1180. mastery_score = " . $mastery_score .
  1181. //", max_score = " . $max_score . " " . // Max score cannot be changed in the form anyway - see display_item_prerequisites_form().
  1182. " WHERE c_id = ".$course_id." AND ref = '" . $prerequisite_id . "'"; // Will this be enough to ensure unicity?
  1183. $res_upd = Database::query($sql_upd);
  1184. }
  1185. // TODO: Update the item object (can be ignored for now because refreshed).
  1186. return true;
  1187. }
  1188. /**
  1189. * Escapes a string with the available database escape function
  1190. * @param string String to escape
  1191. * @return string String escaped
  1192. */
  1193. public function escape_string($string) {
  1194. //if ($this->debug > 0) { error_log('New LP - In learnpath::escape_string('.$string.')', 0); }
  1195. return Database :: escape_string($string);
  1196. }
  1197. /**
  1198. * Static admin function exporting a learnpath into a zip file
  1199. * @param string Export type (scorm, zip, cd)
  1200. * @param string Course code
  1201. * @param integer Learnpath ID
  1202. * @param string Zip file name
  1203. * @return string Zip file path (or false on error)
  1204. */
  1205. public function export_lp($type, $course, $id, $zipname) {
  1206. $course_id = api_get_course_int_id();
  1207. //if ($this->debug > 0) { error_log('New LP - In learnpath::export_lp()', 0); }
  1208. if (empty($type) || empty($course) || empty($id) || empty($zipname)) {
  1209. return false;
  1210. }
  1211. $url = '';
  1212. switch ($type) {
  1213. case 'scorm':
  1214. break;
  1215. case 'zip':
  1216. break;
  1217. case 'cdrom':
  1218. break;
  1219. }
  1220. return $url;
  1221. }
  1222. /**
  1223. * Gets all the chapters belonging to the same parent as the item/chapter given
  1224. * Can also be called as abstract method
  1225. * @param integer Item ID
  1226. * @return array A list of all the "brother items" (or an empty array on failure)
  1227. */
  1228. public function get_brother_chapters($id) {
  1229. $course_id = api_get_course_int_id();
  1230. if ($this->debug > 0) {
  1231. error_log('New LP - In learnpath::get_brother_chapters()', 0);
  1232. }
  1233. if (empty ($id) OR $id != strval(intval($id))) {
  1234. return array ();
  1235. }
  1236. $lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  1237. $sql_parent = "SELECT * FROM $lp_item WHERE c_id = ".$course_id." AND id = $id AND item_type='dokeos_chapter'";
  1238. $res_parent = Database::query($sql_parent);
  1239. if (Database :: num_rows($res_parent) > 0) {
  1240. $row_parent = Database :: fetch_array($res_parent);
  1241. $parent = $row_parent['parent_item_id'];
  1242. $sql_bros = "SELECT * FROM $lp_item WHERE c_id = ".$course_id." AND parent_item_id = $parent AND id = $id AND item_type='dokeos_chapter' ORDER BY display_order";
  1243. $res_bros = Database::query($sql_bros);
  1244. $list = array ();
  1245. while ($row_bro = Database :: fetch_array($res_bros)) {
  1246. $list[] = $row_bro;
  1247. }
  1248. return $list;
  1249. }
  1250. return array ();
  1251. }
  1252. /**
  1253. * Gets all the items belonging to the same parent as the item given
  1254. * Can also be called as abstract method
  1255. * @param integer Item ID
  1256. * @return array A list of all the "brother items" (or an empty array on failure)
  1257. */
  1258. public function get_brother_items($id) {
  1259. $course_id = api_get_course_int_id();
  1260. if ($this->debug > 0) {
  1261. error_log('New LP - In learnpath::get_brother_items(' . $id . ')', 0);
  1262. }
  1263. if (empty ($id) OR $id != strval(intval($id))) {
  1264. return array ();
  1265. }
  1266. $lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  1267. $sql_parent = "SELECT * FROM $lp_item WHERE c_id = $course_id AND id = $id";
  1268. $res_parent = Database::query($sql_parent);
  1269. if (Database :: num_rows($res_parent) > 0) {
  1270. $row_parent = Database :: fetch_array($res_parent);
  1271. $parent = $row_parent['parent_item_id'];
  1272. $sql_bros = "SELECT * FROM $lp_item WHERE c_id = ".$course_id." AND parent_item_id = $parent ORDER BY display_order";
  1273. $res_bros = Database::query($sql_bros);
  1274. $list = array ();
  1275. while ($row_bro = Database :: fetch_array($res_bros)) {
  1276. $list[] = $row_bro;
  1277. }
  1278. return $list;
  1279. }
  1280. return array ();
  1281. }
  1282. /**
  1283. * Get the specific prefix index terms of this learning path
  1284. * @return array Array of terms
  1285. */
  1286. public function get_common_index_terms_by_prefix($prefix) {
  1287. require_once api_get_path(LIBRARY_PATH).'specific_fields_manager.lib.php';
  1288. $terms = get_specific_field_values_list_by_prefix($prefix, $this->cc, TOOL_LEARNPATH, $this->lp_id);
  1289. $prefix_terms = array();
  1290. if (!empty($terms)) {
  1291. foreach ($terms as $term) {
  1292. $prefix_terms[] = $term['value'];
  1293. }
  1294. }
  1295. return $prefix_terms;
  1296. }
  1297. /**
  1298. * Gets the number of items currently completed
  1299. * @return integer The number of items currently completed
  1300. */
  1301. public function get_complete_items_count() {
  1302. if ($this->debug > 0) {
  1303. error_log('New LP - In learnpath::get_complete_items_count()', 0);
  1304. }
  1305. $i = 0;
  1306. foreach ($this->items as $id => $dummy) {
  1307. // Trying failed and browsed considered "progressed" as well.
  1308. if ($this->items[$id]->status_is(array (
  1309. 'completed',
  1310. 'passed',
  1311. 'succeeded',
  1312. 'browsed',
  1313. 'failed'
  1314. )) && $this->items[$id]->get_type() != 'dokeos_chapter' && $this->items[$id]->get_type() != 'dir') {
  1315. $i++;
  1316. }
  1317. }
  1318. return $i;
  1319. }
  1320. /**
  1321. * Gets the current item ID
  1322. * @return integer The current learnpath item id
  1323. */
  1324. public function get_current_item_id() {
  1325. $current = 0;
  1326. if ($this->debug > 0) {
  1327. error_log('New LP - In learnpath::get_current_item_id()', 0);
  1328. }
  1329. if (!empty ($this->current)) {
  1330. $current = $this->current;
  1331. }
  1332. if ($this->debug > 2) {
  1333. error_log('New LP - In learnpath::get_current_item_id() - Returning ' . $current, 0);
  1334. }
  1335. return $current;
  1336. }
  1337. /**
  1338. * Force to get the first learnpath item id
  1339. * @return integer The current learnpath item id
  1340. */
  1341. public function get_first_item_id() {
  1342. $current = 0;
  1343. if (is_array($this->ordered_items)) {
  1344. $current = $this->ordered_items[0];
  1345. }
  1346. return $current;
  1347. }
  1348. /**
  1349. * Gets the total number of items available for viewing in this SCORM
  1350. * @return integer The total number of items
  1351. */
  1352. public function get_total_items_count() {
  1353. if ($this->debug > 0) {
  1354. error_log('New LP - In learnpath::get_total_items_count()', 0);
  1355. }
  1356. return count($this->items);
  1357. }
  1358. /**
  1359. * Gets the total number of items available for viewing in this SCORM but without chapters
  1360. * @return integer The total no-chapters number of items
  1361. */
  1362. public function get_total_items_count_without_chapters() {
  1363. if ($this->debug > 0) {
  1364. error_log('New LP - In learnpath::get_total_items_count_without_chapters()', 0);
  1365. }
  1366. $total = 0;
  1367. foreach ($this->items as $temp => $temp2) {
  1368. if (!in_array($temp2->get_type(), array (
  1369. 'dokeos_chapter',
  1370. 'chapter',
  1371. 'dir'
  1372. )))
  1373. $total++;
  1374. }
  1375. return $total;
  1376. }
  1377. /**
  1378. * Gets the first element URL.
  1379. * @return string URL to load into the viewer
  1380. */
  1381. public function first() {
  1382. if ($this->debug > 0) {
  1383. error_log('New LP - In learnpath::first()', 0);
  1384. }
  1385. // Test if the last_item_seen exists and is not a dir.
  1386. if (count($this->ordered_items) == 0) {
  1387. $this->index = 0;
  1388. }
  1389. 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()) {
  1390. if ($this->debug > 2) {
  1391. 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);
  1392. }
  1393. $index = -1;
  1394. foreach ($this->ordered_items as $myindex => $item_id) {
  1395. if ($item_id == $this->last_item_seen) {
  1396. $index = $myindex;
  1397. break;
  1398. }
  1399. }
  1400. if ($index == -1) {
  1401. // Index hasn't changed, so item not found - panic (this shouldn't happen).
  1402. if ($this->debug > 2) {
  1403. error_log('New LP - Last item (' . $this->last_item_seen . ') was found in items but not in ordered_items, panic!', 0);
  1404. }
  1405. return false;
  1406. } else {
  1407. $this->last = $this->last_item_seen;
  1408. $this->current = $this->last_item_seen;
  1409. $this->index = $index;
  1410. }
  1411. } else {
  1412. if ($this->debug > 2) {
  1413. error_log('New LP - In learnpath::first() - No last item seen', 0);
  1414. }
  1415. $index = 0;
  1416. // Loop through all ordered items and stop at the first item that is
  1417. // not a directory *and* that has not been completed yet.
  1418. 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) {
  1419. $index++;
  1420. }
  1421. $this->last = $this->current;
  1422. // current is
  1423. $this->current = $this->ordered_items[$index];
  1424. $this->index = $index;
  1425. if ($this->debug > 2) {
  1426. error_log('New LP - In learnpath::first() - No last item seen. New last = ' . $this->last . '(' . $this->ordered_items[$index] . ')', 0);
  1427. }
  1428. }
  1429. if ($this->debug > 2) {
  1430. error_log('New LP - In learnpath::first() - First item is ' . $this->get_current_item_id());
  1431. }
  1432. }
  1433. /**
  1434. * Gets the information about an item in a format usable as JavaScript to update
  1435. * the JS API by just printing this content into the <head> section of the message frame
  1436. * @param integer Item ID
  1437. * @return string
  1438. */
  1439. public function get_js_info($item_id = '') {
  1440. if ($this->debug > 0) {
  1441. error_log('New LP - In learnpath::get_js_info(' . $item_id . ')', 0);
  1442. }
  1443. $info = '';
  1444. $item_id = $this->escape_string($item_id);
  1445. if (!empty($item_id) && is_object($this->items[$item_id])) {
  1446. //if item is defined, return values from DB
  1447. $oItem = $this->items[$item_id];
  1448. $info .= '<script language="javascript">';
  1449. $info .= "top.set_score(" . $oItem->get_score() . ");\n";
  1450. $info .= "top.set_max(" . $oItem->get_max() . ");\n";
  1451. $info .= "top.set_min(" . $oItem->get_min() . ");\n";
  1452. $info .= "top.set_lesson_status('" . $oItem->get_status() . "');";
  1453. $info .= "top.set_session_time('" . $oItem->get_scorm_time('js') . "');";
  1454. $info .= "top.set_suspend_data('" . $oItem->get_suspend_data() . "');";
  1455. $info .= "top.set_saved_lesson_status('" . $oItem->get_status() . "');";
  1456. $info .= "top.set_flag_synchronized();";
  1457. $info .= '</script>';
  1458. if ($this->debug > 2) {
  1459. error_log('New LP - in learnpath::get_js_info(' . $item_id . ') - returning: ' . $info, 0);
  1460. }
  1461. return $info;
  1462. } else {
  1463. // If item_id is empty, just update to default SCORM data.
  1464. $info .= '<script language="javascript">';
  1465. $info .= "top.set_score(" . learnpathItem :: get_score() . ");\n";
  1466. $info .= "top.set_max(" . learnpathItem :: get_max() . ");\n";
  1467. $info .= "top.set_min(" . learnpathItem :: get_min() . ");\n";
  1468. $info .= "top.set_lesson_status('" . learnpathItem :: get_status() . "');";
  1469. $info .= "top.set_session_time('" . learnpathItem :: get_scorm_time('js') . "');";
  1470. $info .= "top.set_suspend_data('" . learnpathItem :: get_suspend_data() . "');";
  1471. $info .= "top.set_saved_lesson_status('" . learnpathItem :: get_status() . "');";
  1472. $info .= "top.set_flag_synchronized();";
  1473. $info .= '</script>';
  1474. if ($this->debug > 2) {
  1475. error_log('New LP - in learnpath::get_js_info(' . $item_id . ') - returning: ' . $info, 0);
  1476. }
  1477. return $info;
  1478. }
  1479. }
  1480. /**
  1481. * Gets the js library from the database
  1482. * @return string The name of the javascript library to be used
  1483. */
  1484. public function get_js_lib() {
  1485. $lib = '';
  1486. if (!empty ($this->js_lib)) {
  1487. $lib = $this->js_lib;
  1488. }
  1489. return $lib;
  1490. }
  1491. /**
  1492. * Gets the learnpath database ID
  1493. * @return integer Learnpath ID in the lp table
  1494. */
  1495. public function get_id() {
  1496. //if ($this->debug > 0) { error_log('New LP - In learnpath::get_id()', 0); }
  1497. if (!empty ($this->lp_id)) {
  1498. return $this->lp_id;
  1499. } else {
  1500. return 0;
  1501. }
  1502. }
  1503. /**
  1504. * Gets the last element URL.
  1505. * @return string URL to load into the viewer
  1506. */
  1507. public function get_last() {
  1508. if ($this->debug > 0) {
  1509. error_log('New LP - In learnpath::get_last()', 0);
  1510. }
  1511. $this->index = count($this->ordered_items) - 1;
  1512. return $this->ordered_items[$this->index];
  1513. }
  1514. /**
  1515. * Gets the navigation bar for the learnpath display screen
  1516. * @return string The HTML string to use as a navigation bar
  1517. */
  1518. public function get_navigation_bar() {
  1519. if ($this->debug > 0) {
  1520. error_log('New LP - In learnpath::get_navigation_bar()', 0);
  1521. }
  1522. // TODO: Find a good value for the following variables.
  1523. $file = '';
  1524. $openDir = '';
  1525. $edoceo = '';
  1526. $time = 0;
  1527. $navbar = '';
  1528. $RequestUri = '';
  1529. $mycurrentitemid = $this->get_current_item_id();
  1530. if ($this->mode == 'fullscreen') {
  1531. $navbar = '<table cellpadding="0" cellspacing="0" align="left">' . "\n" .
  1532. ' <tr> ' . "\n" .
  1533. ' <td>' . "\n" .
  1534. ' <div class="buttons">' . "\n" .
  1535. ' <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" .
  1536. ' <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" .
  1537. ' <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" .
  1538. //' <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" .
  1539. //' <a href="lp_controller.php?action=list" target="_top" title="learnpaths list"><img border="0" src="../img/exit.png" title="Exit"></a>'."\n" .
  1540. ' </div>' . "\n" .
  1541. ' </td>' . "\n" .
  1542. ' </tr>' . "\n" .
  1543. '</table>';
  1544. } else {
  1545. $navbar = '<table cellpadding="0" cellspacing="0" align="left">' . "\n" .
  1546. ' <tr> ' . "\n" .
  1547. ' <td>' . "\n" .
  1548. ' <div class="buttons">' . "\n" .
  1549. ' <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" .
  1550. ' <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" .
  1551. ' <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" .
  1552. // ' <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" .
  1553. ' </div>' . "\n" .
  1554. ' </td>' . "\n" .
  1555. ' </tr>' . "\n" .
  1556. '</table>';
  1557. }
  1558. return $navbar;
  1559. }
  1560. /**
  1561. * Gets the next resource in queue (url).
  1562. * @return string URL to load into the viewer
  1563. */
  1564. public function get_next_index() {
  1565. if ($this->debug > 0) {
  1566. error_log('New LP - In learnpath::get_next_index()', 0);
  1567. }
  1568. // TODO
  1569. $index = $this->index;
  1570. $index++;
  1571. if ($this->debug > 2) {
  1572. error_log('New LP - Now looking at ordered_items[' . ($index) . '] - type is ' . $this->items[$this->ordered_items[$index]]->type, 0);
  1573. }
  1574. 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) {
  1575. $index++;
  1576. if ($index == $this->max_ordered_items){
  1577. if ($this->items[$this->ordered_items[$index]]->get_type() == 'dir' || $this->items[$this->ordered_items[$index]]->get_type() == 'dokeos_chapter') {
  1578. return $this->index;
  1579. } else {
  1580. return $index;
  1581. }
  1582. }
  1583. }
  1584. if (empty ($this->ordered_items[$index])) {
  1585. return $this->index;
  1586. }
  1587. if ($this->debug > 2) {
  1588. error_log('New LP - index is now ' . $index, 0);
  1589. }
  1590. return $index;
  1591. }
  1592. /**
  1593. * Gets item_id for the next element
  1594. * @return integer Next item (DB) ID
  1595. */
  1596. public function get_next_item_id() {
  1597. if ($this->debug > 0) {
  1598. error_log('New LP - In learnpath::get_next_item_id()', 0);
  1599. }
  1600. $new_index = $this->get_next_index();
  1601. if (!empty ($new_index)) {
  1602. if (isset ($this->ordered_items[$new_index])) {
  1603. if ($this->debug > 2) {
  1604. error_log('New LP - In learnpath::get_next_index() - Returning ' . $this->ordered_items[$new_index], 0);
  1605. }
  1606. return $this->ordered_items[$new_index];
  1607. }
  1608. }
  1609. if ($this->debug > 2) {
  1610. error_log('New LP - In learnpath::get_next_index() - Problem - Returning 0', 0);
  1611. }
  1612. return 0;
  1613. }
  1614. /**
  1615. * Returns the package type ('scorm','aicc','scorm2004','dokeos','ppt'...)
  1616. *
  1617. * Generally, the package provided is in the form of a zip file, so the function
  1618. * has been written to test a zip file. If not a zip, the function will return the
  1619. * default return value: ''
  1620. * @param string the path to the file
  1621. * @param string the original name of the file
  1622. * @return string 'scorm','aicc','scorm2004','dokeos' or '' if the package cannot be recognized
  1623. */
  1624. public function get_package_type($file_path, $file_name) {
  1625. // Get name of the zip file without the extension.
  1626. $file_info = pathinfo($file_name);
  1627. $filename = $file_info['basename']; // Name including extension.
  1628. $extension = $file_info['extension']; // Extension only.
  1629. if (!empty($_POST['ppt2lp']) && !in_array(strtolower($extension), array (
  1630. 'dll',
  1631. 'exe'
  1632. ))) {
  1633. return 'oogie';
  1634. }
  1635. if (!empty($_POST['woogie']) && !in_array(strtolower($extension), array (
  1636. 'dll',
  1637. 'exe'
  1638. ))) {
  1639. return 'woogie';
  1640. }
  1641. $file_base_name = str_replace('.' . $extension, '', $filename); // Filename without its extension.
  1642. $zipFile = new pclZip($file_path);
  1643. // Check the zip content (real size and file extension).
  1644. $zipContentArray = $zipFile->listContent();
  1645. $package_type = '';
  1646. $at_root = false;
  1647. $manifest = '';
  1648. // The following loop should be stopped as soon as we found the right imsmanifest.xml (how to recognize it?).
  1649. if (is_array($zipContentArray) && count($zipContentArray) > 0) {
  1650. foreach ($zipContentArray as $thisContent) {
  1651. if (preg_match('~.(php.*|phtml)$~i', $thisContent['filename'])) {
  1652. // New behaviour: Don't do anything. These files will be removed in scorm::import_package.
  1653. }
  1654. elseif (stristr($thisContent['filename'], 'imsmanifest.xml') !== false) {
  1655. $manifest = $thisContent['filename']; // Just the relative directory inside scorm/
  1656. $package_type = 'scorm';
  1657. break; // Exit the foreach loop.
  1658. }
  1659. elseif (preg_match('/aicc\//i', $thisContent['filename'])) {
  1660. // If found an aicc directory... (!= false means it cannot be false (error) or 0 (no match)).
  1661. $package_type = 'aicc';
  1662. //break; // Don't exit the loop, because if we find an imsmanifest afterwards, we want it, not the AICC.
  1663. } else {
  1664. $package_type = '';
  1665. }
  1666. }
  1667. }
  1668. return $package_type;
  1669. }
  1670. /**
  1671. * Gets the previous resource in queue (url). Also initialises time values for this viewing
  1672. * @return string URL to load into the viewer
  1673. */
  1674. public function get_previous_index() {
  1675. if ($this->debug > 0) {
  1676. error_log('New LP - In learnpath::get_previous_index()', 0);
  1677. }
  1678. $index = $this->index;
  1679. if (isset ($this->ordered_items[$index -1])) {
  1680. $index--;
  1681. 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')) {
  1682. $index--;
  1683. if ($index < 0) {
  1684. return $this->index;
  1685. }
  1686. }
  1687. } else {
  1688. if ($this->debug > 2) {
  1689. error_log('New LP - get_previous_index() - there was no previous index available, reusing ' . $index, 0);
  1690. }
  1691. // There is no previous item.
  1692. }
  1693. return $index;
  1694. }
  1695. /**
  1696. * Gets item_id for the next element
  1697. * @return integer Previous item (DB) ID
  1698. */
  1699. public function get_previous_item_id() {
  1700. if ($this->debug > 0) {
  1701. error_log('New LP - In learnpath::get_previous_item_id()', 0);
  1702. }
  1703. $new_index = $this->get_previous_index();
  1704. return $this->ordered_items[$new_index];
  1705. }
  1706. /**
  1707. * Gets the progress value from the progress_db attribute
  1708. * @return integer Current progress value
  1709. */
  1710. public function get_progress() {
  1711. if ($this->debug > 0) {
  1712. error_log('New LP - In learnpath::get_progress()', 0);
  1713. }
  1714. if (!empty ($this->progress_db)) {
  1715. return $this->progress_db;
  1716. }
  1717. return 0;
  1718. }
  1719. /**
  1720. * Gets the progress value from the progress field in the database (allows use as abstract method)
  1721. * @param integer Learnpath ID
  1722. * @param integer User ID
  1723. * @param string Mode of display ('%','abs' or 'both')
  1724. * @param string Course database name (optional, defaults to '')
  1725. * @param boolean Whether to return null if no record was found (true), or 0 (false) (optional, defaults to false)
  1726. * @return integer Current progress value as found in the database
  1727. */
  1728. public function get_db_progress($lp_id, $user_id, $mode = '%', $course_code = '', $sincere = false,$session_id = 0) {
  1729. //if ($this->debug > 0) { error_log('New LP - In learnpath::get_db_progress()', 0); }
  1730. $session_id = intval($session_id);
  1731. $course_info = api_get_course_info($course_code);
  1732. $session_condition = api_get_session_condition($session_id);
  1733. $course_id = $course_info['real_id'];
  1734. $table = Database :: get_course_table(TABLE_LP_VIEW);
  1735. $sql = "SELECT * FROM $table WHERE c_id = ".$course_id." AND lp_id = $lp_id AND user_id = $user_id $session_condition";
  1736. $res = Database::query($sql);
  1737. $view_id = 0;
  1738. if (Database :: num_rows($res) > 0) {
  1739. $row = Database :: fetch_array($res);
  1740. $progress = $row['progress'];
  1741. $view_id = $row['id'];
  1742. } else {
  1743. if ($sincere) {
  1744. return null;
  1745. }
  1746. }
  1747. if (empty ($progress)) {
  1748. $progress = '0';
  1749. }
  1750. if ($mode == '%') {
  1751. return $progress . '%';
  1752. } else {
  1753. // Get the number of items completed and the number of items total.
  1754. $tbl = Database :: get_course_table(TABLE_LP_ITEM);
  1755. $sql = "SELECT count(*) FROM $tbl
  1756. WHERE c_id = $course_id AND c_id = ".$course_id." AND lp_id = " . $lp_id . " AND item_type NOT IN('dokeos_chapter','chapter','dir')";
  1757. $res = Database::query($sql);
  1758. $row = Database :: fetch_array($res);
  1759. $total = $row[0];
  1760. $tbl_item_view = Database :: get_course_table(TABLE_LP_ITEM_VIEW);
  1761. $tbl_item = Database :: get_course_table(TABLE_LP_ITEM);
  1762. //$sql = "SELECT count(distinct(lp_item_id)) FROM $tbl WHERE lp_view_id = ".$view_id." AND status IN ('passed','completed','succeeded')";
  1763. // Trying as also counting browsed and failed items.
  1764. $sql = "SELECT count(distinct(lp_item_id))
  1765. FROM $tbl_item_view as item_view
  1766. INNER JOIN $tbl_item as item
  1767. ON item.id = item_view.lp_item_id
  1768. AND item_type NOT IN('dokeos_chapter','chapter','dir')
  1769. WHERE
  1770. item_view.c_id = $course_id AND
  1771. item.c_id = $course_id AND
  1772. lp_view_id = " . $view_id . " AND
  1773. status IN ('passed','completed','succeeded','browsed','failed')"; //echo '<br />';
  1774. $res = Database::query($sql);
  1775. $row = Database :: fetch_array($res);
  1776. $completed = $row[0];
  1777. if ($mode == 'abs') {
  1778. return $completed . '/' . $total;
  1779. } elseif ($mode == 'both') {
  1780. if ($progress < ($completed / ($total ? $total : 1))) {
  1781. $progress = number_format(($completed / ($total ? $total : 1)) * 100, 0);
  1782. }
  1783. return $progress . '% (' . $completed . '/' . $total . ')';
  1784. }
  1785. }
  1786. return $progress;
  1787. }
  1788. /**
  1789. * Returns the HTML necessary to print a mediaplayer block inside a page
  1790. * @return string The mediaplayer HTML
  1791. */
  1792. public function get_mediaplayer($autostart='true') {
  1793. $course_id = api_get_course_int_id();
  1794. global $_course;
  1795. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  1796. $tbl_lp_item_view = Database :: get_course_table(TABLE_LP_ITEM_VIEW);
  1797. // Getting all the information about the item.
  1798. $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 " .
  1799. "WHERE lp.id = '" . $_SESSION['oLP']->current . "' AND
  1800. lp.c_id = $course_id AND
  1801. lp_view.c_id = $course_id";
  1802. $result = Database::query($sql);
  1803. $row = Database::fetch_assoc($result);
  1804. $output = '';
  1805. if (!empty ($row['audio'])) {
  1806. $list = $_SESSION['oLP']->get_toc();
  1807. $type_quiz = false;
  1808. foreach($list as $toc) {
  1809. if ($toc['id'] == $_SESSION['oLP']->current && ($toc['type']=='quiz') ) {
  1810. $type_quiz = true;
  1811. }
  1812. }
  1813. if ($type_quiz) {
  1814. if ($_SESSION['oLP']->prevent_reinit == 1) {
  1815. $row['status'] === 'completed' ? $autostart_audio = 'false' : $autostart_audio = 'true';
  1816. } else {
  1817. $autostart_audio = $autostart;
  1818. }
  1819. } else {
  1820. $autostart_audio = 'true';
  1821. }
  1822. // The mp3 player.
  1823. $output = '<div id="container">';
  1824. $output .= '<script type="text/javascript" src="../inc/lib/mediaplayer/swfobject.js"></script>';
  1825. $output .= '<script type="text/javascript">
  1826. var s1 = new SWFObject("../inc/lib/mediaplayer/player.swf","ply","250","20","9","#FFFFFF");
  1827. s1.addParam("allowscriptaccess","always");
  1828. s1.addParam("flashvars","file=' . api_get_path(WEB_COURSE_PATH) . $_course['path'] . '/document/audio/' . $row['audio'] . '&autostart=' . $autostart_audio.'");
  1829. s1.write("container");
  1830. </script></div>';
  1831. }
  1832. return $output;
  1833. }
  1834. /**
  1835. * This function checks if the learnpath is visible for student after the progress of its prerequisite is completed, and considering time availability
  1836. * @param int Learnpath id
  1837. * @param int Student id
  1838. * @param string Course code (optional)
  1839. * @return bool True if
  1840. */
  1841. public function is_lp_visible_for_student($lp_id, $student_id, $course = null) {
  1842. $lp_id = (int)$lp_id;
  1843. $course = api_get_course_info($course);
  1844. $tbl_learnpath = Database :: get_course_table(TABLE_LP_MAIN);
  1845. // Get current prerequisite
  1846. $sql = "SELECT id, prerequisite, publicated_on, expired_on FROM $tbl_learnpath WHERE c_id = ".$course['real_id']." AND id = $lp_id";
  1847. $rs = Database::query($sql);
  1848. $now = time();
  1849. if (Database::num_rows($rs)>0) {
  1850. $row = Database::fetch_array($rs, 'ASSOC');
  1851. $prerequisite = $row['prerequisite'];
  1852. $is_visible = true;
  1853. $progress = 0;
  1854. if (!empty($prerequisite)) {
  1855. $progress = self::get_db_progress($prerequisite,$student_id,'%', '', false, api_get_session_id());
  1856. $progress = intval($progress);
  1857. if ($progress < 100) {
  1858. $is_visible = false;
  1859. }
  1860. }
  1861. // Also check the time availability of the LP
  1862. if ($is_visible) {
  1863. //Adding visibility reestrinctions
  1864. if (!empty($row['publicated_on']) && $row['publicated_on'] != '0000-00-00 00:00:00') {
  1865. if ($now < api_strtotime($row['publicated_on'], 'UTC')) {
  1866. //api_not_allowed();
  1867. $is_visible = false;
  1868. }
  1869. }
  1870. //Blocking empty start times see BT#2800
  1871. global $_custom;
  1872. if (isset($_custom['lps_hidden_when_no_start_date']) && $_custom['lps_hidden_when_no_start_date']) {
  1873. if (empty($row['publicated_on']) || $row['publicated_on'] == '0000-00-00 00:00:00') {
  1874. //api_not_allowed();
  1875. $is_visible = false;
  1876. }
  1877. }
  1878. if (!empty($row['expired_on']) && $row['expired_on'] != '0000-00-00 00:00:00') {
  1879. if ($now > api_strtotime($row['expired_on'], 'UTC')) {
  1880. //api_not_allowed();
  1881. $is_visible = false;
  1882. }
  1883. }
  1884. }
  1885. return $is_visible;
  1886. }
  1887. return false;
  1888. }
  1889. /**
  1890. * Gets a progress bar for the learnpath by counting the number of items in it and the number of items
  1891. * completed so far.
  1892. * @param string Mode in which we want the values
  1893. * @param integer Progress value to display (optional but mandatory if used in abstract context)
  1894. * @param string Text to display near the progress value (optional but mandatory in abstract context)
  1895. * @param boolean true if it comes from a Diplay LP view
  1896. * @return string HTML string containing the progress bar
  1897. */
  1898. public function get_progress_bar($mode = '', $percentage = -1, $text_add = '', $from_lp = false) {
  1899. //if ($this->debug > 0) {error_log('New LP - In learnpath::get_progress_bar('.$mode.','.$percentage.','.$text_add.','.$from_lp.')', 0); }
  1900. global $lp_theme_css;
  1901. // Setting up the CSS path of the current style if exists.
  1902. if (!empty ($lp_theme_css)) {
  1903. $css_path = api_get_path(WEB_CODE_PATH) . 'css/' . $lp_theme_css . '/images/';
  1904. } else {
  1905. $css_path = '../img/';
  1906. }
  1907. //if ($this->debug > 0) { error_log('New LP - In learnpath::get_progress_bar()', 0); }
  1908. if (isset($this) && is_object($this) && ($percentage == '-1' OR $text_add == '')) {
  1909. list($percentage, $text_add) = $this->get_progress_bar_text($mode);
  1910. }
  1911. $text = $percentage . $text_add;
  1912. // Default progress bar config
  1913. // times that will be greater or shorter
  1914. $factor = 1.2;
  1915. if ($from_lp)
  1916. $progress_height = '26';
  1917. else
  1918. $progress_height = '16';
  1919. $size = str_replace('%', '', $percentage);
  1920. $output ='<div style="width:135px">' .
  1921. '<img id="progress_img_limit_left" src="' . $css_path . 'bar_1.gif" width="1" height="' . $progress_height . '">' .
  1922. '<img id="progress_img_full" src="' . $css_path . 'bar_1u.gif" width="' . $size * $factor . 'px" height="' . $progress_height . '" id="full_portion">' .
  1923. '<img id="progress_img_limit_middle" src="' . $css_path . 'bar_1m.gif" width="1" height="' . $progress_height . '">';
  1924. if ($percentage <= 98) {
  1925. $output .= '<img id="progress_img_empty" src="' . $css_path . 'bar_1r.gif" width="' . (100 - $size) * $factor . 'px" height="' . $progress_height . '" id="empty_portion">';
  1926. } else {
  1927. $output .= '<img id="progress_img_empty" src="' . $css_path . 'bar_1r.gif" width="0" height="' . $progress_height . '" id="empty_portion">';
  1928. }
  1929. $output .= '<img id="progress_bar_img_limit_right" src="' . $css_path . 'bar_1.gif" width="1" height="' . $progress_height . '"></div>' .
  1930. '<div class="progresstext" id="progress_text">' . $text . '</div>';
  1931. return $output;
  1932. }
  1933. /**
  1934. * Gets the progress bar info to display inside the progress bar. Also used by scorm_api.php
  1935. * @param string Mode of display (can be '%' or 'abs').abs means we display a number of completed elements per total elements
  1936. * @param integer Additional steps to fake as completed
  1937. * @return list Percentage or number and symbol (% or /xx)
  1938. */
  1939. public function get_progress_bar_text($mode = '', $add = 0) {
  1940. if ($this->debug > 0) {
  1941. error_log('New LP - In learnpath::get_progress_bar_text()', 0);
  1942. }
  1943. if (empty ($mode)) {
  1944. $mode = $this->progress_bar_mode;
  1945. }
  1946. $total_items = $this->get_total_items_count_without_chapters();
  1947. if ($this->debug > 2) {
  1948. error_log('New LP - Total items available in this learnpath: ' . $total_items, 0);
  1949. }
  1950. $i = $this->get_complete_items_count();
  1951. if ($this->debug > 2) {
  1952. error_log('New LP - Items completed so far: ' . $i, 0);
  1953. }
  1954. if ($add != 0) {
  1955. $i += $add;
  1956. if ($this->debug > 2) {
  1957. error_log('New LP - Items completed so far (+modifier): ' . $i, 0);
  1958. }
  1959. }
  1960. $text = '';
  1961. if ($i > $total_items) {
  1962. $i = $total_items;
  1963. }
  1964. if ($mode == '%') {
  1965. if ($total_items > 0) {
  1966. $percentage = ((float) $i / (float) $total_items) * 100;
  1967. } else {
  1968. $percentage = 0;
  1969. }
  1970. $percentage = number_format($percentage, 0);
  1971. $text = '%';
  1972. }
  1973. elseif ($mode == 'abs') {
  1974. $percentage = $i;
  1975. $text = '/' . $total_items;
  1976. }
  1977. return array (
  1978. $percentage,
  1979. $text
  1980. );
  1981. }
  1982. /**
  1983. * Gets the progress bar mode
  1984. * @return string The progress bar mode attribute
  1985. */
  1986. public function get_progress_bar_mode() {
  1987. if ($this->debug > 0) {
  1988. error_log('New LP - In learnpath::get_progress_bar_mode()', 0);
  1989. }
  1990. if (!empty ($this->progress_bar_mode)) {
  1991. return $this->progress_bar_mode;
  1992. } else {
  1993. return '%';
  1994. }
  1995. }
  1996. /**
  1997. * Gets the learnpath proximity (remote or local)
  1998. * @return string Learnpath proximity
  1999. */
  2000. public function get_proximity() {
  2001. if ($this->debug > 0) {
  2002. error_log('New LP - In learnpath::get_proximity()', 0);
  2003. }
  2004. if (!empty ($this->proximity)) {
  2005. return $this->proximity;
  2006. } else {
  2007. return '';
  2008. }
  2009. }
  2010. /**
  2011. * Gets the learnpath theme (remote or local)
  2012. * @return string Learnpath theme
  2013. */
  2014. public function get_theme() {
  2015. if ($this->debug > 0) {
  2016. error_log('New LP - In learnpath::get_theme()', 0);
  2017. }
  2018. if (!empty ($this->theme)) {
  2019. return $this->theme;
  2020. } else {
  2021. return '';
  2022. }
  2023. }
  2024. /**
  2025. * Gets the learnpath session id
  2026. * @return string Learnpath theme
  2027. */
  2028. public function get_lp_session_id() {
  2029. if ($this->debug > 0) {
  2030. error_log('New LP - In learnpath::get_lp_session_id()', 0);
  2031. }
  2032. if (!empty ($this->lp_session_id)) {
  2033. return $this->lp_session_id;
  2034. } else {
  2035. return 0;
  2036. }
  2037. }
  2038. /**
  2039. * Gets the learnpath image
  2040. * @return string Web URL of the LP image
  2041. */
  2042. public function get_preview_image() {
  2043. if ($this->debug > 0) {
  2044. error_log('New LP - In learnpath::get_preview_image()', 0);
  2045. }
  2046. if (!empty ($this->preview_image)) {
  2047. return $this->preview_image;
  2048. } else {
  2049. return '';
  2050. }
  2051. }
  2052. /**
  2053. * Gets the learnpath author
  2054. * @return string LP's author
  2055. */
  2056. public function get_author() {
  2057. if ($this->debug > 0) {
  2058. error_log('New LP - In learnpath::get_author()', 0);
  2059. }
  2060. if (!empty ($this->author)) {
  2061. return $this->author;
  2062. } else {
  2063. return '';
  2064. }
  2065. }
  2066. /**
  2067. * Gets the learnpath author
  2068. * @return string LP's author
  2069. */
  2070. public function get_hide_toc_frame() {
  2071. if ($this->debug > 0) {
  2072. error_log('New LP - In learnpath::get_author()', 0);
  2073. }
  2074. if (!empty ($this->hide_toc_frame)) {
  2075. return $this->hide_toc_frame;
  2076. } else {
  2077. return '';
  2078. }
  2079. }
  2080. /**
  2081. * Generate a new prerequisites string for a given item. If this item was a sco and
  2082. * its prerequisites were strings (instead of IDs), then transform those strings into
  2083. * IDs, knowing that SCORM IDs are kept in the "ref" field of the lp_item table.
  2084. * Prefix all item IDs that end-up in the prerequisites string by "ITEM_" to use the
  2085. * same rule as the scorm_export() method
  2086. * @param integer Item ID
  2087. * @return string Prerequisites string ready for the export as SCORM
  2088. */
  2089. public function get_scorm_prereq_string($item_id) {
  2090. if ($this->debug > 0) {
  2091. error_log('New LP - In learnpath::get_scorm_prereq_string()', 0);
  2092. }
  2093. if (!is_object($this->items[$item_id])) {
  2094. return false;
  2095. }
  2096. $oItem = $this->items[$item_id];
  2097. $prereq = $oItem->get_prereq_string();
  2098. if (empty ($prereq)) {
  2099. return '';
  2100. }
  2101. 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,
  2102. // then simply return it (with the ITEM_ prefix).
  2103. return 'ITEM_' . $prereq;
  2104. } else {
  2105. if (isset ($this->refs_list[$prereq])) {
  2106. // It's a simple string item from which the ID can be found in the refs list,
  2107. // so we can transform it directly to an ID for export.
  2108. return 'ITEM_' . $this->refs_list[$prereq];
  2109. } else {
  2110. // The last case, if it's a complex form, then find all the IDs (SCORM strings)
  2111. // and replace them, one by one, by the internal IDs (chamilo db)
  2112. // TODO: Modify the '*' replacement to replace the multiplier in front of it
  2113. // by a space as well.
  2114. $find = array (
  2115. '&',
  2116. '|',
  2117. '~',
  2118. '=',
  2119. '<>',
  2120. '{',
  2121. '}',
  2122. '*',
  2123. '(',
  2124. ')'
  2125. );
  2126. $replace = array (
  2127. ' ',
  2128. ' ',
  2129. ' ',
  2130. ' ',
  2131. ' ',
  2132. ' ',
  2133. ' ',
  2134. ' ',
  2135. ' ',
  2136. ' '
  2137. );
  2138. $prereq_mod = str_replace($find, $replace, $prereq);
  2139. $ids = split(' ', $prereq_mod);
  2140. foreach ($ids as $id) {
  2141. $id = trim($id);
  2142. if (isset ($this->refs_list[$id])) {
  2143. $prereq = preg_replace('/[^a-zA-Z_0-9](' . $id . ')[^a-zA-Z_0-9]/', 'ITEM_' . $this->refs_list[$id], $prereq);
  2144. }
  2145. }
  2146. error_log('New LP - In learnpath::get_scorm_prereq_string(): returning modified string: ' . $prereq, 0);
  2147. return $prereq;
  2148. }
  2149. }
  2150. }
  2151. /**
  2152. * Returns the XML DOM document's node
  2153. * @param resource Reference to a list of objects to search for the given ITEM_*
  2154. * @param string The identifier to look for
  2155. * @return mixed The reference to the element found with that identifier. False if not found
  2156. */
  2157. public function get_scorm_xml_node(& $children, $id) {
  2158. for ($i = 0; $i < $children->length; $i++) {
  2159. $item_temp = $children->item($i);
  2160. if ($item_temp->nodeName == 'item') {
  2161. if ($item_temp->getAttribute('identifier') == $id) {
  2162. return $item_temp;
  2163. }
  2164. }
  2165. $subchildren = $item_temp->childNodes;
  2166. if ($subchildren->length > 0) {
  2167. $val = $this->get_scorm_xml_node($subchildren, $id);
  2168. if (is_object($val)) {
  2169. return $val;
  2170. }
  2171. }
  2172. }
  2173. return false;
  2174. }
  2175. /**
  2176. * Returns a usable array of stats related to the current learnpath and user
  2177. * @return array Well-formatted array containing status for the current learnpath
  2178. */
  2179. public function get_stats() {
  2180. if ($this->debug > 0) {
  2181. error_log('New LP - In learnpath::get_stats()', 0);
  2182. }
  2183. // TODO
  2184. }
  2185. /**
  2186. * Static method. Can be re-implemented by children. Gives an array of statistics for
  2187. * the given course (for all learnpaths and all users)
  2188. * @param string Course code
  2189. * @return array Well-formatted array containing status for the course's learnpaths
  2190. */
  2191. public function get_stats_course($course) {
  2192. //if ($this->debug > 0) { error_log('New LP - In learnpath::get_stats_course()', 0); }
  2193. // TODO
  2194. }
  2195. /**
  2196. * Static method. Can be re-implemented by children. Gives an array of statistics for
  2197. * the given course and learnpath (for all users)
  2198. * @param string Course code
  2199. * @param integer Learnpath ID
  2200. * @return array Well-formatted array containing status for the specified learnpath
  2201. */
  2202. public function get_stats_lp($course, $lp) {
  2203. //if ($this->debug > 0) { error_log('New LP - In learnpath::get_stats_lp()', 0); }
  2204. // TODO
  2205. }
  2206. /**
  2207. * Static method. Can be re-implemented by children. Gives an array of statistics for
  2208. * the given course, learnpath and user.
  2209. * @param string Course code
  2210. * @param integer Learnpath ID
  2211. * @param integer User ID
  2212. * @return array Well-formatted array containing status for the specified learnpath and user
  2213. */
  2214. public function get_stats_lp_user($course, $lp, $user) {
  2215. //if ($this->debug > 0) { error_log('New LP - In learnpath::get_stats_lp_user()', 0); }
  2216. // TODO
  2217. }
  2218. /**
  2219. * Static method. Can be re-implemented by children. Gives an array of statistics for
  2220. * the given course and learnpath (for all users)
  2221. * @param string Course code
  2222. * @param integer User ID
  2223. * @return array Well-formatted array containing status for the user's learnpaths
  2224. */
  2225. public function get_stats_user($course, $user) {
  2226. //if ($this->debug > 0) { error_log('New LP - In learnpath::get_stats_user()', 0); }
  2227. // TODO
  2228. }
  2229. /**
  2230. * Gets the status list for all LP's items
  2231. * @return array Array of [index] => [item ID => current status]
  2232. */
  2233. public function get_items_status_list() {
  2234. if ($this->debug > 0) {
  2235. error_log('New LP - In learnpath::get_items_status_list()', 0);
  2236. }
  2237. $list = array ();
  2238. foreach ($this->ordered_items as $item_id) {
  2239. $list[] = array (
  2240. $item_id => $this->items[$item_id]->get_status()
  2241. );
  2242. }
  2243. return $list;
  2244. }
  2245. /**
  2246. * Return the number of interactions for the given learnpath Item View ID.
  2247. * This method can be used as static.
  2248. * @param integer Item View ID
  2249. * @param integer course id
  2250. * @return integer Number of interactions
  2251. */
  2252. public function get_interactions_count_from_db($lp_iv_id, $course_id) {
  2253. $table = Database :: get_course_table(TABLE_LP_IV_INTERACTION);
  2254. $lp_iv_id = intval($lp_iv_id);
  2255. $course_id = intval($course_id);
  2256. $sql = "SELECT count(*) FROM $table WHERE c_id = $course_id AND lp_iv_id = $lp_iv_id";
  2257. $res = Database::query($sql);
  2258. $res = 0;
  2259. if (Database::num_rows($res)) {
  2260. $row = Database::fetch_array($res);
  2261. $num = $row[0];
  2262. }
  2263. return $num;
  2264. }
  2265. /**
  2266. * Return the interactions as an array for the given lp_iv_id.
  2267. * This method can be used as static.
  2268. * @param integer Learnpath Item View ID
  2269. * @return array
  2270. * @todo Transcode labels instead of switching to HTML (which requires to know the encoding of the LP)
  2271. */
  2272. public function get_iv_interactions_array($lp_iv_id = 0) {
  2273. $course_id = api_get_course_int_id();
  2274. $list = array ();
  2275. $table = Database :: get_course_table(TABLE_LP_IV_INTERACTION);
  2276. $sql = "SELECT * FROM $table WHERE c_id = ".$course_id." AND lp_iv_id = $lp_iv_id ORDER BY order_id ASC";
  2277. $res = Database::query($sql);
  2278. $num = Database :: num_rows($res);
  2279. if ($num > 0) {
  2280. $list[] = array (
  2281. 'order_id' => api_htmlentities(get_lang('Order'), ENT_QUOTES),
  2282. 'id' => api_htmlentities(get_lang('InteractionID'), ENT_QUOTES),
  2283. 'type' => api_htmlentities(get_lang('Type'), ENT_QUOTES),
  2284. 'time' => api_htmlentities(get_lang('TimeFinished'), ENT_QUOTES),
  2285. 'correct_responses' => api_htmlentities(get_lang('CorrectAnswers'), ENT_QUOTES),
  2286. 'student_response' => api_htmlentities(get_lang('StudentResponse'), ENT_QUOTES),
  2287. 'result' => api_htmlentities(get_lang('Result'), ENT_QUOTES),
  2288. 'latency' => api_htmlentities(get_lang('LatencyTimeSpent'), ENT_QUOTES)
  2289. );
  2290. while ($row = Database :: fetch_array($res)) {
  2291. $list[] = array (
  2292. 'order_id' => ($row['order_id'] + 1),
  2293. 'id' => urldecode($row['interaction_id']), //urldecode because they often have %2F or stuff like that
  2294. 'type' => $row['interaction_type'],
  2295. 'time' => $row['completion_time'],
  2296. //'correct_responses' => $row['correct_responses'],
  2297. 'correct_responses' => '', // Hide correct responses from students.
  2298. 'student_response' => $row['student_response'],
  2299. 'result' => $row['result'],
  2300. 'latency' => $row['latency']
  2301. );
  2302. }
  2303. }
  2304. return $list;
  2305. }
  2306. /**
  2307. * Return the number of objectives for the given learnpath Item View ID.
  2308. * This method can be used as static.
  2309. * @param integer Item View ID
  2310. * @return integer Number of objectives
  2311. */
  2312. public function get_objectives_count_from_db($lp_iv_id, $course_id) {
  2313. $table = Database :: get_course_table(TABLE_LP_IV_OBJECTIVE);
  2314. $course_id = intval($course_id);
  2315. $lp_iv_id = intval($lp_iv_id);
  2316. $sql = "SELECT count(*) FROM $table WHERE c_id = $course_id AND lp_iv_id = $lp_iv_id";
  2317. $res = Database::query($sql);
  2318. $res = 0;
  2319. if (Database::num_rows($res)) {
  2320. $row = Database :: fetch_array($res);
  2321. $num = $row[0];
  2322. }
  2323. return $num;
  2324. }
  2325. /**
  2326. * Return the objectives as an array for the given lp_iv_id.
  2327. * This method can be used as static.
  2328. * @param integer Learnpath Item View ID
  2329. * @return array
  2330. * @todo Translate labels
  2331. */
  2332. public function get_iv_objectives_array($lp_iv_id = 0) {
  2333. $course_id = api_get_course_int_id();
  2334. $list = array();
  2335. $table = Database :: get_course_table(TABLE_LP_IV_OBJECTIVE);
  2336. $sql = "SELECT * FROM $table WHERE c_id = ".$course_id." AND lp_iv_id = $lp_iv_id ORDER BY order_id ASC";
  2337. $res = Database::query($sql);
  2338. $num = Database :: num_rows($res);
  2339. if ($num > 0) {
  2340. $list[] = array (
  2341. 'order_id' => api_htmlentities(get_lang('Order'), ENT_QUOTES),
  2342. 'objective_id' => api_htmlentities(get_lang('ObjectiveID'), ENT_QUOTES),
  2343. 'score_raw' => api_htmlentities(get_lang('ObjectiveRawScore'), ENT_QUOTES),
  2344. 'score_max' => api_htmlentities(get_lang('ObjectiveMaxScore'), ENT_QUOTES),
  2345. 'score_min' => api_htmlentities(get_lang('ObjectiveMinScore'), ENT_QUOTES),
  2346. 'status' => api_htmlentities(get_lang('ObjectiveStatus'), ENT_QUOTES)
  2347. );
  2348. while ($row = Database :: fetch_array($res)) {
  2349. $list[] = array (
  2350. 'order_id' => ($row['order_id'] + 1),
  2351. 'objective_id' => urldecode($row['objective_id']), // urldecode() because they often have %2F or stuff like that.
  2352. 'score_raw' => $row['score_raw'],
  2353. 'score_max' => $row['score_max'],
  2354. 'score_min' => $row['score_min'],
  2355. 'status' => $row['status']
  2356. );
  2357. }
  2358. }
  2359. return $list;
  2360. }
  2361. /**
  2362. * Generate and return the table of contents for this learnpath. The (flat) table returned can be
  2363. * used by get_html_toc() to be ready to display
  2364. * @return array TOC as a table with 4 elements per row: title, link, status and level
  2365. */
  2366. public function get_toc() {
  2367. if ($this->debug > 0) {
  2368. error_log('New LP - In learnpath::get_toc()', 0);
  2369. }
  2370. $toc = array ();
  2371. //echo "<pre>".print_r($this->items,true)."</pre>";
  2372. foreach ($this->ordered_items as $item_id) {
  2373. if ($this->debug > 2) {
  2374. error_log('New LP - learnpath::get_toc(): getting info for item ' . $item_id, 0);
  2375. }
  2376. // TODO: Change this link generation and use new function instead.
  2377. $toc[] = array (
  2378. 'id' => $item_id,
  2379. 'title' => $this->items[$item_id]->get_title(),
  2380. //'link' => get_addedresource_link_in_learnpath('document', $item_id, 1),
  2381. 'status' => $this->items[$item_id]->get_status(),
  2382. 'level' => $this->items[$item_id]->get_level(),
  2383. 'type' => $this->items[$item_id]->get_type(),
  2384. 'description' => $this->items[$item_id]->get_description(),
  2385. 'path' => $this->items[$item_id]->get_path(),
  2386. );
  2387. }
  2388. if ($this->debug > 2) {
  2389. error_log('New LP - In learnpath::get_toc() - TOC array: ' . print_r($toc, true), 0);
  2390. }
  2391. return $toc;
  2392. }
  2393. /**
  2394. * Generate and return the table of contents for this learnpath. The JS
  2395. * table returned is used inside of scorm_api.php
  2396. * @return string A JS array vairiable construction
  2397. */
  2398. public function get_items_details_as_js($varname = 'olms.lms_item_types') {
  2399. if ($this->debug > 0) {
  2400. error_log('New LP - In learnpath::get_items_details_as_js()', 0);
  2401. }
  2402. $toc = $varname.' = new Array();';
  2403. //echo "<pre>".print_r($this->items,true)."</pre>";
  2404. foreach ($this->ordered_items as $item_id) {
  2405. if ($this->debug > 2) {
  2406. error_log('New LP - learnpath::get_items_details_as_js(): getting info for item ' . $item_id, 0);
  2407. }
  2408. $toc.= $varname."['i$item_id'] = '".$this->items[$item_id]->get_type()."';";
  2409. }
  2410. if ($this->debug > 2) {
  2411. error_log('New LP - In learnpath::get_items_details_as_js() - TOC array: ' . print_r($toc, true), 0);
  2412. }
  2413. return $toc;
  2414. }
  2415. /**
  2416. * Gets the learning path type
  2417. * @param boolean Return the name? If false, return the ID. Default is false.
  2418. * @return mixed Type ID or name, depending on the parameter
  2419. */
  2420. public function get_type($get_name = false) {
  2421. $res = false;
  2422. if ($this->debug > 0) {
  2423. error_log('New LP - In learnpath::get_type()', 0);
  2424. }
  2425. if (!empty ($this->type)) {
  2426. if ($get_name) {
  2427. // Get it from the lp_type table in main db.
  2428. } else {
  2429. $res = $this->type;
  2430. }
  2431. }
  2432. if ($this->debug > 2) {
  2433. error_log('New LP - In learnpath::get_type() - Returning ' . ($res ? $res : 'false'), 0);
  2434. }
  2435. return $res;
  2436. }
  2437. /**
  2438. * Gets the learning path type as static method
  2439. * @param boolean Return the name? If false, return the ID. Default is false.
  2440. * @return mixed Type ID or name, depending on the parameter
  2441. */
  2442. public function get_type_static($lp_id = 0) {
  2443. $course_id = api_get_course_int_id();
  2444. $tbl_lp = Database :: get_course_table(TABLE_LP_MAIN);
  2445. $sql = "SELECT lp_type FROM $tbl_lp WHERE c_id = ".$course_id." AND id = '" . $lp_id . "'";
  2446. $res = Database::query($sql);
  2447. if ($res === false) {
  2448. return null;
  2449. }
  2450. if (Database :: num_rows($res) <= 0) {
  2451. return null;
  2452. }
  2453. $row = Database :: fetch_array($res);
  2454. return $row['lp_type'];
  2455. }
  2456. /**
  2457. * Gets a flat list of item IDs ordered for display (level by level ordered by order_display)
  2458. * This method can be used as abstract and is recursive
  2459. * @param integer Learnpath ID
  2460. * @param integer Parent ID of the items to look for
  2461. * @return mixed Ordered list of item IDs or false on error
  2462. */
  2463. public function get_flat_ordered_items_list($lp, $parent = 0, $course_id = null) {
  2464. if (empty($course_id)) {
  2465. $course_id = api_get_course_int_id();
  2466. } else {
  2467. $course_id = intval($course_id);
  2468. }
  2469. $list = array();
  2470. if (empty ($lp)) {
  2471. return false;
  2472. }
  2473. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  2474. $sql = "SELECT * FROM $tbl_lp_item WHERE c_id = $course_id AND lp_id = $lp AND parent_item_id = $parent ORDER BY display_order";
  2475. $res = Database::query($sql);
  2476. while ($row = Database :: fetch_array($res)) {
  2477. $sublist = learnpath :: get_flat_ordered_items_list($lp, $row['id'], $course_id);
  2478. $list[] = $row['id'];
  2479. foreach ($sublist as $item) {
  2480. $list[] = $item;
  2481. }
  2482. }
  2483. return $list;
  2484. }
  2485. /**
  2486. * Uses the table generated by get_toc() and returns an HTML-formatted string ready to display
  2487. * @return string HTML TOC ready to display
  2488. */
  2489. public function get_html_toc() {
  2490. $course_id = api_get_course_int_id();
  2491. $course_code = api_get_course_id();
  2492. $is_allowed_to_edit = api_is_allowed_to_edit(null, true);
  2493. $charset = api_get_system_encoding();
  2494. $display_action_links_with_icons = false;
  2495. if ($this->debug > 0) {
  2496. error_log('New LP - In learnpath::get_html_toc()', 0);
  2497. }
  2498. $list = $this->get_toc();
  2499. //echo $this->current;
  2500. //$parent = $this->items[$this->current]->get_parent();
  2501. //if (empty($parent)) { $parent = $this->ordered_items[$this->items[$this->current]->get_previous_index()]; }
  2502. $html = '<div id="scorm_title" class="scorm_title"><div class="scorm_title_text">' . Security::remove_XSS($this->get_name()) . '</div></div>';
  2503. // Build, display.
  2504. if ($is_allowed_to_edit) {
  2505. $gradebook = Security :: remove_XSS($_GET['gradebook']);
  2506. if ($this->get_lp_session_id() == api_get_session_id()) {
  2507. $html .= '<div id="actions_lp" class="actions_lp">';
  2508. if ($display_action_links_with_icons) {
  2509. $html .= '<div style = "text-align:center;">';
  2510. $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'),'',ICON_SIZE_MEDIUM)."</a>";
  2511. $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'),'',ICON_SIZE_MEDIUM)."</a>";
  2512. $html .= '<span>' . Display :: return_icon('view_remove_na.png', get_lang('Display'),'',ICON_SIZE_MEDIUM).'</span><br />';
  2513. $html .= '<a href="lp_controller.php?' . api_get_cidreq() . '">'. get_lang('ReturnToLPList') . '</a>';
  2514. $html .= '</div>';
  2515. } else {
  2516. $html .= '<div style = "text-align:center;">';
  2517. $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>";
  2518. $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>";
  2519. $html .= '<span><b>' . get_lang('Display') . '</b></span><br />';
  2520. $html .= '<a href="lp_controller.php?' . api_get_cidreq() . '">'. get_lang('ReturnToLPList') . '</a>';
  2521. $html .= '</div>';
  2522. }
  2523. $html .= '</div>';
  2524. }
  2525. }
  2526. $html .= '<div id="inner_lp_toc" class="inner_lp_toc">';
  2527. require_once 'resourcelinker.inc.php';
  2528. // Temporary variables.
  2529. $mycurrentitemid = $this->get_current_item_id();
  2530. $color_counter = 0;
  2531. $i = 0;
  2532. foreach ($list as $item) {
  2533. if ($this->debug > 2) {
  2534. error_log('New LP - learnpath::get_html_toc(): using item ' . $item['id'], 0);
  2535. }
  2536. // TODO: Complete this.
  2537. $icon_name = array (
  2538. 'not attempted' => '../img/notattempted.gif',
  2539. 'incomplete' => '../img/incomplete.png',
  2540. 'failed' => '../img/delete.png',
  2541. 'completed' => '../img/completed.png',
  2542. 'passed' => '../img/passed.png',
  2543. 'succeeded' => '../img/succeeded.png',
  2544. 'browsed' => '../img/completed.png',
  2545. );
  2546. $style = 'scorm_item';
  2547. $scorm_color_background = 'scorm_item';
  2548. $style_item = 'scorm_item';
  2549. $current = false;
  2550. if ($item['id'] == $this->current) {
  2551. $style = 'scorm_item_highlight';
  2552. $scorm_color_background = 'scorm_item_highlight';
  2553. } else {
  2554. if ($color_counter % 2 == 0) {
  2555. $scorm_color_background = 'scorm_item_1';
  2556. } else {
  2557. $scorm_color_background = 'scorm_item_2';
  2558. }
  2559. if ($item['type'] == 'dokeos_module' || $item['type'] == 'dokeos_chapter') {
  2560. $scorm_color_background =' scorm_item_section ';
  2561. }
  2562. }
  2563. if ($scorm_color_background != '') {
  2564. $html .= '<div id="toc_' . $item['id'] . '" class="' . $scorm_color_background . '">';
  2565. }
  2566. // The anchor will let us center the TOC on the currently viewed item &^D
  2567. if ($item['type'] != 'dokeos_module' && $item['type'] != 'dokeos_chapter') {
  2568. $html .= '<a name="atoc_' . $item['id'] . '" />';
  2569. $html .= '<div class="' . $style_item . '" style="padding-left: ' . ($item['level'] * 1.5) . 'em; padding-right:' . ($item['level'] / 2) . 'em" title="' . $item['description'] . '" >';
  2570. } else {
  2571. $html .= '<div class="' . $style_item . '" style="padding-left: ' . ($item['level'] * 2) . 'em; padding-right:' . ($item['level'] * 1.5) . 'em" title="' . $item['description'] . '" >';
  2572. }
  2573. $title = $item['title'];
  2574. if (empty ($title)) {
  2575. $title = rl_get_resource_name(api_get_course_id(), $this->get_id(), $item['id']);
  2576. }
  2577. $title = Security::remove_XSS($title);
  2578. if ($item['type'] != 'dokeos_chapter' && $item['type'] != 'dir' && $item['type'] != 'dokeos_module') {
  2579. //$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>" ;
  2580. $url = $this->get_link('http', $item['id']);
  2581. //$html .= '<a href="'.$url.'" target="content_name" onClick="top.load_item('.$item['id'].',\''.$url.'\');">'.$title.'</a>' ;
  2582. //$html .= '<a href="" onClick="top.load_item('.$item['id'].',\''.$url.'\');return false;">'.$title.'</a>' ;
  2583. //<img align="absbottom" width="13" height="13" src="../img/lp_document.png">&nbsp;background:#aaa;
  2584. $html .= '<a href="" onClick="switch_item(' .$mycurrentitemid . ',' .$item['id'] . ');' .'return false;" >' . stripslashes($title) . '</a>';
  2585. } elseif ($item['type'] == 'dokeos_module' || $item['type'] == 'dokeos_chapter') {
  2586. $html .= "<img align='absbottom' width='13' height='13' src='../img/lp_dokeos_module.png'>&nbsp;" . stripslashes($title);
  2587. } elseif ($item['type'] == 'dir') {
  2588. $html .= stripslashes($title);
  2589. }
  2590. $tbl_track_e_exercises = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
  2591. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  2592. $user_id = api_get_user_id();
  2593. $sql = "SELECT path FROM $tbl_track_e_exercises, $tbl_lp_item
  2594. WHERE c_id = $course_id AND
  2595. path = '" . $item['path'] . "' AND
  2596. exe_user_id = '$user_id' AND
  2597. exe_cours_id = '$course_code' AND
  2598. path = exe_exo_id AND
  2599. status <> 'incomplete'";
  2600. $result = Database::query($sql);
  2601. $count = Database :: num_rows($result);
  2602. if ($item['type'] == 'quiz') {
  2603. if ($item['status'] == 'completed') {
  2604. $html .= "&nbsp;<img id='toc_img_" . $item['id'] . "' src='" . $icon_name[$item['status']] . "' alt='" . substr($item['status'], 0, 1) . "' width='14' />";
  2605. }
  2606. } else {
  2607. if ($item['type'] != 'dokeos_chapter' && $item['type'] != 'dokeos_module' && $item['type'] != 'dir') {
  2608. $html .= "&nbsp;<img id='toc_img_" . $item['id'] . "' src='" . $icon_name[$item['status']] . "' alt='" . substr($item['status'], 0, 1) . "' width='14' />";
  2609. }
  2610. }
  2611. $html .= "</div>";
  2612. if ($scorm_color_background != '') {
  2613. $html .= '</div>';
  2614. }
  2615. $color_counter++;
  2616. }
  2617. $html .= "</div>";
  2618. return $html;
  2619. }
  2620. /**
  2621. * Gets the learnpath maker name - generally the editor's name
  2622. * @return string Learnpath maker name
  2623. */
  2624. public function get_maker() {
  2625. if ($this->debug > 0) {
  2626. error_log('New LP - In learnpath::get_maker()', 0);
  2627. }
  2628. if (!empty ($this->maker)) {
  2629. return $this->maker;
  2630. } else {
  2631. return '';
  2632. }
  2633. }
  2634. /**
  2635. * Gets the user-friendly message stored in $this->message
  2636. * @return string Message
  2637. */
  2638. public function get_message() {
  2639. if ($this->debug > 0) {
  2640. error_log('New LP - In learnpath::get_message()', 0);
  2641. }
  2642. return $this->message;
  2643. }
  2644. /**
  2645. * Gets the learnpath name/title
  2646. * @return string Learnpath name/title
  2647. */
  2648. public function get_name() {
  2649. if ($this->debug > 0) {
  2650. error_log('New LP - In learnpath::get_name()', 0);
  2651. }
  2652. if (!empty ($this->name)) {
  2653. return $this->name;
  2654. } else {
  2655. return 'N/A';
  2656. }
  2657. }
  2658. /**
  2659. * Gets a link to the resource from the present location, depending on item ID.
  2660. * @param string Type of link expected
  2661. * @param integer Learnpath item ID
  2662. * @return string Link to the lp_item resource
  2663. */
  2664. public function get_link($type = 'http', $item_id = null) {
  2665. $course_id = api_get_course_int_id();
  2666. if ($this->debug > 0) {
  2667. error_log('New LP - In learnpath::get_link(' . $type . ',' . $item_id . ')', 0);
  2668. }
  2669. if (empty($item_id)) {
  2670. if ($this->debug > 2) {
  2671. error_log('New LP - In learnpath::get_link() - no item id given in learnpath::get_link(), using current: ' . $this->get_current_item_id(), 0);
  2672. }
  2673. $item_id = $this->get_current_item_id();
  2674. }
  2675. if (empty ($item_id)) {
  2676. if ($this->debug > 2) {
  2677. error_log('New LP - In learnpath::get_link() - no current item id found in learnpath object', 0);
  2678. }
  2679. //still empty, this means there was no item_id given and we are not in an object context or
  2680. //the object property is empty, return empty link
  2681. $item_id = $this->first();
  2682. return '';
  2683. }
  2684. $file = '';
  2685. $lp_table = Database::get_course_table(TABLE_LP_MAIN);
  2686. $lp_item_table = Database::get_course_table(TABLE_LP_ITEM);
  2687. $lp_item_view_table = Database::get_course_table(TABLE_LP_ITEM_VIEW);
  2688. $item_id = Database::escape_string($item_id);
  2689. $sel = "SELECT l.lp_type as ltype, l.path as lpath, li.item_type as litype, li.path as lipath, li.parameters as liparams
  2690. FROM $lp_table l, $lp_item_table li
  2691. WHERE l.c_id = $course_id AND
  2692. li.c_id = $course_id AND
  2693. li.id = $item_id AND
  2694. li.lp_id = l.id";
  2695. if ($this->debug > 2) {
  2696. error_log('New LP - In learnpath::get_link() - selecting item ' . $sel, 0);
  2697. }
  2698. $res = Database::query($sel);
  2699. if (Database :: num_rows($res) > 0) {
  2700. $row = Database :: fetch_array($res);
  2701. $lp_type = $row['ltype'];
  2702. $lp_path = $row['lpath'];
  2703. $lp_item_type = $row['litype'];
  2704. $lp_item_path = $row['lipath'];
  2705. $lp_item_params = $row['liparams'];
  2706. if (empty ($lp_item_params) && strpos($lp_item_path, '?') !== false) {
  2707. list ($lp_item_path, $lp_item_params) = explode('?', $lp_item_path);
  2708. }
  2709. //$lp_item_params = '?'.$lp_item_params;
  2710. //add ? if none - left commented to give freedom to scorm implementation
  2711. //if(substr($lp_item_params,0,1)!='?'){
  2712. // $lp_item_params = '?'.$lp_item_params;
  2713. //}
  2714. $sys_course_path = api_get_path(SYS_COURSE_PATH) . api_get_course_path();
  2715. if ($type == 'http') {
  2716. $course_path = api_get_path(WEB_COURSE_PATH) . api_get_course_path(); //web path
  2717. } else {
  2718. $course_path = $sys_course_path; //system path
  2719. }
  2720. // 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.
  2721. if (in_array($lp_item_type, array('quiz', 'document', 'link', 'forum', 'thread', 'student_publication'))) {
  2722. $lp_type = 1;
  2723. }
  2724. // Now go through the specific cases to get the end of the path.
  2725. // @todo Use constants instead of int values.
  2726. switch ($lp_type) {
  2727. case 1 :
  2728. if ($lp_item_type == 'dokeos_chapter') {
  2729. $file = 'lp_content.php?type=dir';
  2730. } else {
  2731. require_once 'resourcelinker.inc.php';
  2732. $file = rl_get_resource_link_for_learnpath(api_get_course_id(), $this->get_id(), $item_id);
  2733. if ($lp_item_type == 'link') {
  2734. require_once api_get_path(LIBRARY_PATH).'link.lib.php';
  2735. if (is_youtube_link($file)) {
  2736. $src = get_youtube_video_id($file);
  2737. $file = 'embed.php?type=youtube&src='.$src;
  2738. }
  2739. } else {
  2740. // check how much attempts of a exercise exits in lp
  2741. $lp_item_id = $this->get_current_item_id();
  2742. $lp_view_id = $this->get_view_id();
  2743. $prevent_reinit = $this->items[$this->current]->get_prevent_reinit();
  2744. $list = $this->get_toc();
  2745. $type_quiz = false;
  2746. foreach ($list as $toc) {
  2747. if ($toc['id'] == $lp_item_id && ($toc['type'] == 'quiz')) {
  2748. $type_quiz = true;
  2749. }
  2750. }
  2751. if ($type_quiz) {
  2752. $lp_item_id = Database :: escape_string($lp_item_id);
  2753. $lp_view_id = Database :: escape_string($lp_view_id);
  2754. $sql = "SELECT count(*) FROM $lp_item_view_table
  2755. WHERE c_id = $course_id AND lp_item_id='" . (int) $lp_item_id . "' AND lp_view_id ='" . (int) $lp_view_id . "' AND status='completed'";
  2756. $result = Database::query($sql);
  2757. $row_count = Database :: fetch_row($result);
  2758. $count_item_view = (int) $row_count[0];
  2759. $not_multiple_attempt = 0;
  2760. if ($prevent_reinit === 1 && $count_item_view > 0) {
  2761. $not_multiple_attempt = 1;
  2762. }
  2763. $file .= '&not_multiple_attempt=' . $not_multiple_attempt;
  2764. }
  2765. $tmp_array = explode('/', $file);
  2766. $document_name = $tmp_array[count($tmp_array) - 1];
  2767. if (strpos($document_name, '_DELETED_')) {
  2768. $file = 'blank.php?error=document_deleted';
  2769. }
  2770. }
  2771. }
  2772. break;
  2773. case 2 :
  2774. if ($this->debug > 2) {
  2775. error_log('New LP - In learnpath::get_link() ' . __LINE__ . ' - Item type: ' . $lp_item_type, 0);
  2776. }
  2777. if ($lp_item_type != 'dir') {
  2778. // Quite complex here:
  2779. // We want to make sure 'http://' (and similar) links can
  2780. // be loaded as is (withouth the Chamilo path in front) but
  2781. // some contents use this form: resource.htm?resource=http://blablabla
  2782. // which means we have to find a protocol at the path's start, otherwise
  2783. // it should not be considered as an external URL.
  2784. //if ($this->prerequisites_match($item_id)) {
  2785. if (preg_match('#^[a-zA-Z]{2,5}://#', $lp_item_path) != 0) {
  2786. if ($this->debug > 2) {
  2787. error_log('New LP - In learnpath::get_link() ' . __LINE__ . ' - Found match for protocol in ' . $lp_item_path, 0);
  2788. }
  2789. // Distant url, return as is.
  2790. $file = $lp_item_path;
  2791. } else {
  2792. if ($this->debug > 2) {
  2793. error_log('New LP - In learnpath::get_link() ' . __LINE__ . ' - No starting protocol in ' . $lp_item_path, 0);
  2794. }
  2795. // Prevent getting untranslatable urls.
  2796. $lp_item_path = preg_replace('/%2F/', '/', $lp_item_path);
  2797. $lp_item_path = preg_replace('/%3A/', ':', $lp_item_path);
  2798. // Prepare the path.
  2799. $file = $course_path . '/scorm/' . $lp_path . '/' . $lp_item_path;
  2800. // TODO: Fix this for urls with protocol header.
  2801. $file = str_replace('//', '/', $file);
  2802. $file = str_replace(':/', '://', $file);
  2803. if (substr($lp_path, -1) == '/') {
  2804. $lp_path = substr($lp_path, 0, -1);
  2805. }
  2806. if (!is_file(realpath($sys_course_path . '/scorm/' . $lp_path . '/' . $lp_item_path))) {
  2807. // if file not found.
  2808. $decoded = html_entity_decode($lp_item_path);
  2809. list ($decoded) = explode('?', $decoded);
  2810. if (!is_file(realpath($sys_course_path . '/scorm/' . $lp_path . '/' . $decoded))) {
  2811. require_once 'resourcelinker.inc.php';
  2812. $file = rl_get_resource_link_for_learnpath(api_get_course_id(), $this->get_id(), $item_id);
  2813. if (empty($file)) {
  2814. $file = 'blank.php?error=document_not_found';
  2815. } else {
  2816. $tmp_array = explode('/', $file);
  2817. $document_name = $tmp_array[count($tmp_array) - 1];
  2818. if (strpos($document_name, '_DELETED_')) {
  2819. $file = 'blank.php?error=document_deleted';
  2820. } else {
  2821. $file = 'blank.php?error=document_not_found';
  2822. }
  2823. }
  2824. } else {
  2825. $file = $course_path . '/scorm/' . $lp_path . '/' . $decoded;
  2826. }
  2827. }
  2828. }
  2829. //}else{
  2830. //prerequisites did not match
  2831. //$file = 'blank.php';
  2832. //}
  2833. // We want to use parameters if they were defined in the imsmanifest.
  2834. if ($file != 'blank.php') {
  2835. $file .= (strstr($file, '?') === false ? '?' : '') . $lp_item_params;
  2836. }
  2837. } else {
  2838. $file = 'lp_content.php?type=dir';
  2839. }
  2840. break;
  2841. case 3 :
  2842. if ($this->debug > 2) {
  2843. error_log('New LP - In learnpath::get_link() ' . __LINE__ . ' - Item type: ' . $lp_item_type, 0);
  2844. }
  2845. // Formatting AICC HACP append URL.
  2846. $aicc_append = '?aicc_sid=' . urlencode(session_id()) . '&aicc_url=' . urlencode(api_get_path(WEB_CODE_PATH) . 'newscorm/aicc_hacp.php') . '&';
  2847. if ($lp_item_type != 'dir') {
  2848. // Quite complex here:
  2849. // We want to make sure 'http://' (and similar) links can
  2850. // be loaded as is (withouth the Chamilo path in front) but
  2851. // some contents use this form: resource.htm?resource=http://blablabla
  2852. // which means we have to find a protocol at the path's start, otherwise
  2853. // it should not be considered as an external URL.
  2854. if (preg_match('#^[a-zA-Z]{2,5}://#', $lp_item_path) != 0) {
  2855. if ($this->debug > 2) {
  2856. error_log('New LP - In learnpath::get_link() ' . __LINE__ . ' - Found match for protocol in ' . $lp_item_path, 0);
  2857. }
  2858. // Distant url, return as is.
  2859. $file = $lp_item_path;
  2860. // Enabled and modified by Ivan Tcholakov, 16-OCT-2008.
  2861. /*
  2862. if (stristr($file,'<servername>') !== false) {
  2863. $file = str_replace('<servername>', $course_path.'/scorm/'.$lp_path.'/', $lp_item_path);
  2864. }
  2865. */
  2866. if (stripos($file, '<servername>') !== false) {
  2867. //$file = str_replace('<servername>',$course_path.'/scorm/'.$lp_path.'/',$lp_item_path);
  2868. $web_course_path = str_replace('https://', '', str_replace('http://', '', $course_path));
  2869. $file = str_replace('<servername>', $web_course_path . '/scorm/' . $lp_path, $lp_item_path);
  2870. }
  2871. //
  2872. $file .= $aicc_append;
  2873. } else {
  2874. if ($this->debug > 2) {
  2875. error_log('New LP - In learnpath::get_link() ' . __LINE__ . ' - No starting protocol in ' . $lp_item_path, 0);
  2876. }
  2877. // Prevent getting untranslatable urls.
  2878. $lp_item_path = preg_replace('/%2F/', '/', $lp_item_path);
  2879. $lp_item_path = preg_replace('/%3A/', ':', $lp_item_path);
  2880. // Prepare the path - lp_path might be unusable because it includes the "aicc" subdir name.
  2881. $file = $course_path . '/scorm/' . $lp_path . '/' . $lp_item_path;
  2882. // TODO: Fix this for urls with protocol header.
  2883. $file = str_replace('//', '/', $file);
  2884. $file = str_replace(':/', '://', $file);
  2885. $file .= $aicc_append;
  2886. }
  2887. } else {
  2888. $file = 'lp_content.php?type=dir';
  2889. }
  2890. break;
  2891. case 4 :
  2892. break;
  2893. default :
  2894. break;
  2895. }
  2896. }
  2897. if ($this->debug > 2) {
  2898. error_log('New LP - In learnpath::get_link() - returning "' . $file . '" from get_link', 0);
  2899. }
  2900. return $file;
  2901. }
  2902. /**
  2903. * Gets the latest usable view or generate a new one
  2904. * @param integer Optional attempt number. If none given, takes the highest from the lp_view table
  2905. * @return integer DB lp_view id
  2906. */
  2907. public function get_view($attempt_num = 0) {
  2908. if ($this->debug > 0) {
  2909. error_log('New LP - In learnpath::get_view()', 0);
  2910. }
  2911. $search = '';
  2912. // Use $attempt_num to enable multi-views management (disabled so far).
  2913. if ($attempt_num != 0 AND intval(strval($attempt_num)) == $attempt_num) {
  2914. $search = 'AND view_count = ' . $attempt_num;
  2915. }
  2916. // When missing $attempt_num, search for a unique lp_view record for this lp and user.
  2917. $lp_view_table = Database :: get_course_table(TABLE_LP_VIEW);
  2918. $course_id = api_get_course_int_id();
  2919. $sql = "SELECT id, view_count FROM $lp_view_table
  2920. WHERE c_id = ".$course_id." AND lp_id = " . $this->get_id() ." AND user_id = " . $this->get_user_id() . " " .$search .
  2921. " ORDER BY view_count DESC";
  2922. $res = Database::query($sql);
  2923. if (Database :: num_rows($res) > 0) {
  2924. $row = Database :: fetch_array($res);
  2925. $this->lp_view_id = $row['id'];
  2926. } else {
  2927. // There is no database record, create one.
  2928. $sql = "INSERT INTO $lp_view_table (c_id, lp_id,user_id,view_count) VALUES
  2929. ($course_id, " . $this->get_id() . "," . $this->get_user_id() . ",1)";
  2930. $res = Database::query($sql);
  2931. $id = Database :: insert_id();
  2932. $this->lp_view_id = $id;
  2933. }
  2934. return $this->lp_view_id;
  2935. }
  2936. /**
  2937. * Gets the current view id
  2938. * @return integer View ID (from lp_view)
  2939. */
  2940. public function get_view_id() {
  2941. if ($this->debug > 0) {
  2942. error_log('New LP - In learnpath::get_view_id()', 0);
  2943. }
  2944. if (!empty ($this->lp_view_id)) {
  2945. return $this->lp_view_id;
  2946. } else {
  2947. return 0;
  2948. }
  2949. }
  2950. /**
  2951. * Gets the update queue
  2952. * @return array Array containing IDs of items to be updated by JavaScript
  2953. */
  2954. public function get_update_queue() {
  2955. if ($this->debug > 0) {
  2956. error_log('New LP - In learnpath::get_update_queue()', 0);
  2957. }
  2958. return $this->update_queue;
  2959. }
  2960. /**
  2961. * Gets the user ID
  2962. * @return integer User ID
  2963. */
  2964. public function get_user_id() {
  2965. if ($this->debug > 0) {
  2966. error_log('New LP - In learnpath::get_user_id()', 0);
  2967. }
  2968. if (!empty ($this->user_id)) {
  2969. return $this->user_id;
  2970. } else {
  2971. return false;
  2972. }
  2973. }
  2974. /**
  2975. * Checks if any of the items has an audio element attached
  2976. * @return bool True or false
  2977. */
  2978. public function has_audio() {
  2979. if ($this->debug > 1) {
  2980. error_log('New LP - In learnpath::has_audio()', 0);
  2981. }
  2982. $has = false;
  2983. foreach ($this->items as $i => $item) {
  2984. if (!empty ($this->items[$i]->audio)) {
  2985. $has = true;
  2986. break;
  2987. }
  2988. }
  2989. return $has;
  2990. }
  2991. /**
  2992. * Logs a message into a file
  2993. * @param string Message to log
  2994. * @return boolean True on success, false on error or if msg empty
  2995. */
  2996. public function log($msg) {
  2997. if ($this->debug > 0) {
  2998. error_log('New LP - In learnpath::log()', 0);
  2999. }
  3000. // TODO
  3001. $this->error .= $msg;
  3002. return true;
  3003. }
  3004. /**
  3005. * Moves an item up and down at its level
  3006. * @param integer Item to move up and down
  3007. * @param string Direction 'up' or 'down'
  3008. * @return integer New display order, or false on error
  3009. */
  3010. public function move_item($id, $direction) {
  3011. $course_id = api_get_course_int_id();
  3012. if ($this->debug > 0) {
  3013. error_log('New LP - In learnpath::move_item(' . $id . ',' . $direction . ')', 0);
  3014. }
  3015. if (empty ($id) or empty ($direction)) {
  3016. return false;
  3017. }
  3018. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  3019. $sql_sel = "SELECT *
  3020. FROM " . $tbl_lp_item . "
  3021. WHERE c_id = ".$course_id." AND id = " . $id;
  3022. $res_sel = Database::query($sql_sel);
  3023. // Check if elem exists.
  3024. if (Database :: num_rows($res_sel) < 1) {
  3025. return false;
  3026. }
  3027. // Gather data.
  3028. $row = Database :: fetch_array($res_sel);
  3029. $previous = $row['previous_item_id'];
  3030. $next = $row['next_item_id'];
  3031. $display = $row['display_order'];
  3032. $parent = $row['parent_item_id'];
  3033. $lp = $row['lp_id'];
  3034. // Update the item (switch with previous/next one).
  3035. switch ($direction) {
  3036. case 'up' :
  3037. if ($this->debug > 2) {
  3038. error_log('Movement up detected', 0);
  3039. }
  3040. if ($display <= 1) { /*do nothing*/
  3041. } else {
  3042. $sql_sel2 = "SELECT * FROM $tbl_lp_item
  3043. WHERE c_id = ".$course_id." AND id = $previous";
  3044. if ($this->debug > 2) {
  3045. error_log('Selecting previous: ' . $sql_sel2, 0);
  3046. }
  3047. $res_sel2 = Database::query($sql_sel2);
  3048. if (Database :: num_rows($res_sel2) < 1) {
  3049. $previous_previous = 0;
  3050. }
  3051. // Gather data.
  3052. $row2 = Database :: fetch_array($res_sel2);
  3053. $previous_previous = $row2['previous_item_id'];
  3054. // Update previous_previous item (switch "next" with current).
  3055. if ($previous_previous != 0) {
  3056. $sql_upd2 = "UPDATE $tbl_lp_item SET next_item_id = $id WHERE c_id = ".$course_id." AND id = $previous_previous";
  3057. if ($this->debug > 2) {
  3058. error_log($sql_upd2, 0);
  3059. }
  3060. $res_upd2 = Database::query($sql_upd2);
  3061. }
  3062. // Update previous item (switch with current).
  3063. if ($previous != 0) {
  3064. $sql_upd2 = "UPDATE $tbl_lp_item SET next_item_id = $next, previous_item_id = $id, display_order = display_order +1
  3065. WHERE c_id = ".$course_id." AND id = $previous";
  3066. if ($this->debug > 2) {
  3067. error_log($sql_upd2, 0);
  3068. }
  3069. $res_upd2 = Database::query($sql_upd2);
  3070. }
  3071. // Update current item (switch with previous).
  3072. if ($id != 0) {
  3073. $sql_upd2 = "UPDATE $tbl_lp_item SET next_item_id = $previous, previous_item_id = $previous_previous, display_order = display_order-1
  3074. WHERE c_id = ".$course_id." AND id = $id";
  3075. if ($this->debug > 2) {
  3076. error_log($sql_upd2, 0);
  3077. }
  3078. $res_upd2 = Database::query($sql_upd2);
  3079. }
  3080. // Update next item (new previous item).
  3081. if ($next != 0) {
  3082. $sql_upd2 = "UPDATE $tbl_lp_item SET previous_item_id = $previous
  3083. WHERE c_id = ".$course_id." AND id = $next";
  3084. if ($this->debug > 2) {
  3085. error_log($sql_upd2, 0);
  3086. }
  3087. $res_upd2 = Database::query($sql_upd2);
  3088. }
  3089. $display = $display -1;
  3090. }
  3091. break;
  3092. case 'down' :
  3093. if ($this->debug > 2) {
  3094. error_log('Movement down detected', 0);
  3095. }
  3096. if ($next == 0) { /* Do nothing. */
  3097. } else {
  3098. $sql_sel2 = "SELECT * FROM $tbl_lp_item WHERE c_id = ".$course_id." AND id = $next";
  3099. if ($this->debug > 2) {
  3100. error_log('Selecting next: ' . $sql_sel2, 0);
  3101. }
  3102. $res_sel2 = Database::query($sql_sel2);
  3103. if (Database :: num_rows($res_sel2) < 1) {
  3104. $next_next = 0;
  3105. }
  3106. // Gather data.
  3107. $row2 = Database :: fetch_array($res_sel2);
  3108. $next_next = $row2['next_item_id'];
  3109. // Update previous item (switch with current).
  3110. if ($previous != 0) {
  3111. $sql_upd2 = "UPDATE $tbl_lp_item SET next_item_id = $next
  3112. WHERE c_id = ".$course_id." AND id = $previous";
  3113. $res_upd2 = Database::query($sql_upd2);
  3114. }
  3115. // Update current item (switch with previous).
  3116. if ($id != 0) {
  3117. $sql_upd2 = "UPDATE $tbl_lp_item SET previous_item_id = $next, next_item_id = $next_next, display_order = display_order+1
  3118. WHERE c_id = ".$course_id." AND id = $id";
  3119. $res_upd2 = Database::query($sql_upd2);
  3120. }
  3121. // Update next item (new previous item).
  3122. if ($next != 0) {
  3123. $sql_upd2 = "UPDATE $tbl_lp_item SET previous_item_id = $previous, next_item_id = $id, display_order = display_order-1
  3124. WHERE c_id = ".$course_id." AND id = $next";
  3125. $res_upd2 = Database::query($sql_upd2);
  3126. }
  3127. // Update next_next item (switch "previous" with current).
  3128. if ($next_next != 0) {
  3129. $sql_upd2 = "UPDATE $tbl_lp_item SET previous_item_id = $id
  3130. WHERE c_id = ".$course_id." AND id = $next_next";
  3131. $res_upd2 = Database::query($sql_upd2);
  3132. }
  3133. $display = $display +1;
  3134. }
  3135. break;
  3136. default :
  3137. return false;
  3138. }
  3139. return $display;
  3140. }
  3141. /**
  3142. * Move a learnpath up (display_order)
  3143. * @param integer Learnpath ID
  3144. */
  3145. public function move_up($lp_id) {
  3146. $course_id = api_get_course_int_id();
  3147. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3148. $sql = "SELECT * FROM $lp_table WHERE c_id = ".$course_id." ORDER BY display_order";
  3149. $res = Database::query($sql);
  3150. if ($res === false)
  3151. return false;
  3152. $lps = array ();
  3153. $lp_order = array ();
  3154. $num = Database :: num_rows($res);
  3155. // First check the order is correct, globally (might be wrong because
  3156. // of versions < 1.8.4)
  3157. if ($num > 0) {
  3158. $i = 1;
  3159. while ($row = Database :: fetch_array($res)) {
  3160. if ($row['display_order'] != $i) { // If we find a gap in the order, we need to fix it.
  3161. $need_fix = true;
  3162. $sql_u = "UPDATE $lp_table SET display_order = $i WHERE c_id = ".$course_id." AND id = " . $row['id'];
  3163. $res_u = Database::query($sql_u);
  3164. }
  3165. $row['display_order'] = $i;
  3166. $lps[$row['id']] = $row;
  3167. $lp_order[$i] = $row['id'];
  3168. $i++;
  3169. }
  3170. }
  3171. if ($num > 1) { // If there's only one element, no need to sort.
  3172. $order = $lps[$lp_id]['display_order'];
  3173. if ($order > 1) { // If it's the first element, no need to move up.
  3174. $sql_u1 = "UPDATE $lp_table SET display_order = $order WHERE c_id = ".$course_id." AND id = " . $lp_order[$order - 1];
  3175. $res_u1 = Database::query($sql_u1);
  3176. $sql_u2 = "UPDATE $lp_table SET display_order = " . ($order - 1) . " WHERE c_id = ".$course_id." AND id = " . $lp_id;
  3177. $res_u2 = Database::query($sql_u2);
  3178. }
  3179. }
  3180. }
  3181. /**
  3182. * Move a learnpath down (display_order)
  3183. * @param integer Learnpath ID
  3184. */
  3185. public function move_down($lp_id) {
  3186. $course_id = api_get_course_int_id();
  3187. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3188. $sql = "SELECT * FROM $lp_table WHERE c_id = ".$course_id." ORDER BY display_order";
  3189. $res = Database::query($sql);
  3190. if ($res === false)
  3191. return false;
  3192. $lps = array ();
  3193. $lp_order = array ();
  3194. $num = Database :: num_rows($res);
  3195. $max = 0;
  3196. // First check the order is correct, globally (might be wrong because
  3197. // of versions < 1.8.4).
  3198. if ($num > 0) {
  3199. $i = 1;
  3200. while ($row = Database :: fetch_array($res)) {
  3201. $max = $i;
  3202. if ($row['display_order'] != $i) { // If we find a gap in the order, we need to fix it.
  3203. $need_fix = true;
  3204. $sql_u = "UPDATE $lp_table SET display_order = $i
  3205. WHERE c_id = ".$course_id." AND id = " . $row['id'];
  3206. $res_u = Database::query($sql_u);
  3207. }
  3208. $row['display_order'] = $i;
  3209. $lps[$row['id']] = $row;
  3210. $lp_order[$i] = $row['id'];
  3211. $i++;
  3212. }
  3213. }
  3214. if ($num > 1) { // If there's only one element, no need to sort.
  3215. $order = $lps[$lp_id]['display_order'];
  3216. if ($order < $max) { // If it's the first element, no need to move up.
  3217. $sql_u1 = "UPDATE $lp_table SET display_order = $order
  3218. WHERE c_id = ".$course_id." AND id = " . $lp_order[$order + 1];
  3219. $res_u1 = Database::query($sql_u1);
  3220. $sql_u2 = "UPDATE $lp_table SET display_order = " . ($order + 1) . "
  3221. WHERE c_id = ".$course_id." AND id = " . $lp_id;
  3222. $res_u2 = Database::query($sql_u2);
  3223. }
  3224. }
  3225. }
  3226. /**
  3227. * Updates learnpath attributes to point to the next element
  3228. * The last part is similar to set_current_item but processing the other way around
  3229. */
  3230. public function next() {
  3231. if ($this->debug > 0) {
  3232. error_log('New LP - In learnpath::next()', 0);
  3233. }
  3234. $this->last = $this->get_current_item_id();
  3235. $this->items[$this->last]->save(false, $this->prerequisites_match($this->last));
  3236. $this->autocomplete_parents($this->last);
  3237. $new_index = $this->get_next_index();
  3238. if ($this->debug > 2) {
  3239. error_log('New LP - New index: ' . $new_index, 0);
  3240. }
  3241. $this->index = $new_index;
  3242. if ($this->debug > 2) {
  3243. error_log('New LP - Now having orderedlist[' . $new_index . '] = ' . $this->ordered_items[$new_index], 0);
  3244. }
  3245. $this->current = $this->ordered_items[$new_index];
  3246. if ($this->debug > 2) {
  3247. error_log('New LP - new item id is ' . $this->current . '-' . $this->get_current_item_id(), 0);
  3248. }
  3249. }
  3250. /**
  3251. * Open a resource = initialise all local variables relative to this resource. Depending on the child
  3252. * class, this might be redefined to allow several behaviours depending on the document type.
  3253. * @param integer Resource ID
  3254. * @return boolean True on success, false otherwise
  3255. */
  3256. public function open($id) {
  3257. if ($this->debug > 0) {
  3258. error_log('New LP - In learnpath::open()', 0);
  3259. }
  3260. // TODO:
  3261. // set the current resource attribute to this resource
  3262. // switch on element type (redefine in child class?)
  3263. // set status for this item to "opened"
  3264. // start timer
  3265. // initialise score
  3266. $this->index = 0; //or = the last item seen (see $this->last)
  3267. }
  3268. /**
  3269. * Check that all prerequisites are fulfilled. Returns true and an empty string on succes, returns false
  3270. * and the prerequisite string on error.
  3271. * This function is based on the rules for aicc_script language as described in the SCORM 1.2 CAM documentation page 108.
  3272. * @param integer Optional item ID. If none given, uses the current open item.
  3273. * @return boolean True if prerequisites are matched, false otherwise - Empty string if true returned, prerequisites string otherwise.
  3274. */
  3275. public function prerequisites_match($item = null) {
  3276. if ($this->debug > 0) {
  3277. error_log('New LP - In learnpath::prerequisites_match()', 0);
  3278. }
  3279. if (empty ($item)) {
  3280. $item = $this->current;
  3281. }
  3282. if (is_object($this->items[$item])) {
  3283. $prereq_string = $this->items[$item]->get_prereq_string();
  3284. if (empty ($prereq_string)) {
  3285. return true;
  3286. }
  3287. // Clean spaces.
  3288. $prereq_string = str_replace(' ', '', $prereq_string);
  3289. if ($this->debug > 0) {
  3290. error_log('Found prereq_string: ' . $prereq_string, 0);
  3291. }
  3292. // Now send to the parse_prereq() function that will check this component's prerequisites.
  3293. $result = $this->items[$item]->parse_prereq($prereq_string, $this->items, $this->refs_list, $this->get_user_id());
  3294. if ($result === false) {
  3295. $this->set_error_msg($this->items[$item]->prereq_alert);
  3296. }
  3297. } else {
  3298. $result = true;
  3299. if ($this->debug > 1) {
  3300. error_log('New LP - $this->items[' . $item . '] was not an object', 0);
  3301. }
  3302. }
  3303. if ($this->debug > 1) {
  3304. error_log('New LP - End of prerequisites_match(). Error message is now ' . $this->error, 0);
  3305. }
  3306. return $result;
  3307. }
  3308. /**
  3309. * Updates learnpath attributes to point to the previous element
  3310. * The last part is similar to set_current_item but processing the other way around
  3311. */
  3312. public function previous() {
  3313. if ($this->debug > 0) {
  3314. error_log('New LP - In learnpath::previous()', 0);
  3315. }
  3316. $this->last = $this->get_current_item_id();
  3317. $this->items[$this->last]->save(false, $this->prerequisites_match($this->last));
  3318. $this->autocomplete_parents($this->last);
  3319. $new_index = $this->get_previous_index();
  3320. $this->index = $new_index;
  3321. $this->current = $this->ordered_items[$new_index];
  3322. }
  3323. /**
  3324. * Publishes a learnpath. This basically means show or hide the learnpath
  3325. * to normal users.
  3326. * Can be used as abstract
  3327. * @param integer Learnpath ID
  3328. * @param string New visibility
  3329. */
  3330. public function toggle_visibility($lp_id, $set_visibility = 1) {
  3331. //if ($this->debug > 0) { error_log('New LP - In learnpath::toggle_visibility()', 0); }
  3332. $action = 'visible';
  3333. if ($set_visibility != 1) {
  3334. $action = 'invisible';
  3335. }
  3336. return api_item_property_update(api_get_course_info(), TOOL_LEARNPATH, $lp_id, $action, api_get_user_id());
  3337. }
  3338. /**
  3339. * Publishes a learnpath. This basically means show or hide the learnpath
  3340. * on the course homepage
  3341. * Can be used as abstract
  3342. * @param integer Learnpath id
  3343. * @param string New visibility (v/s - visible/invisible)
  3344. */
  3345. public function toggle_publish($lp_id, $set_visibility = 'v') {
  3346. //if ($this->debug > 0) { error_log('New LP - In learnpath::toggle_publish()', 0); }
  3347. $course_id = api_get_course_int_id();
  3348. $tbl_lp = Database :: get_course_table(TABLE_LP_MAIN);
  3349. $sql = "SELECT * FROM $tbl_lp where c_id = ".$course_id." AND id=$lp_id";
  3350. $result = Database::query($sql);
  3351. $row = Database :: fetch_array($result);
  3352. $name = domesticate($row['name']);
  3353. if ($set_visibility == 'i') {
  3354. $s = $name . " " . get_lang('_no_published');
  3355. $dialogBox = $s;
  3356. $v = 0;
  3357. }
  3358. if ($set_visibility == 'v') {
  3359. $s = $name . " " . get_lang('_published');
  3360. $dialogBox = $s;
  3361. $v = 1;
  3362. }
  3363. $session_id = api_get_session_id();
  3364. $session_condition = api_get_session_condition($session_id);
  3365. $tbl_tool = Database :: get_course_table(TABLE_TOOL_LIST);
  3366. $course_id = api_get_course_int_id();
  3367. $link = 'newscorm/lp_controller.php?action=view&lp_id=' . $lp_id.'&id_session='.$session_id;
  3368. $sql = "SELECT * FROM $tbl_tool WHERE c_id = ".$course_id." AND name='$name' and image='scormbuilder.gif' and link LIKE '$link%' $session_condition";
  3369. $result = Database::query($sql);
  3370. $num = Database :: num_rows($result);
  3371. $row2 = Database :: fetch_array($result);
  3372. //if ($this->debug > 2) { error_log('New LP - '.$sql.' - '.$num, 0); }
  3373. if (($set_visibility == 'i') && ($num > 0)) {
  3374. $sql = "DELETE FROM $tbl_tool WHERE c_id = ".$course_id." AND (name='$name' and image='scormbuilder.gif' and link LIKE '$link%' $session_condition)";
  3375. } elseif (($set_visibility == 'v') && ($num == 0)) {
  3376. $sql = "INSERT INTO $tbl_tool (c_id, name, link, image, visibility, admin, address, added_tool, session_id) VALUES
  3377. ($course_id, '$name','$link','scormbuilder.gif','$v','0','pastillegris.gif',0, $session_id)";
  3378. } else {
  3379. // Parameter and database incompatible, do nothing.
  3380. }
  3381. $result = Database::query($sql);
  3382. //if ($this->debug > 2) { error_log('New LP - Leaving learnpath::toggle_visibility: '.$sql, 0); }
  3383. }
  3384. /**
  3385. * Restart the whole learnpath. Return the URL of the first element.
  3386. * Make sure the results are saved with anoter method. This method should probably be
  3387. * redefined in children classes.
  3388. * To use a similar method statically, use the create_new_attempt() method
  3389. * @return string URL to load in the viewer
  3390. */
  3391. public function restart() {
  3392. if ($this->debug > 0) {
  3393. error_log('New LP - In learnpath::restart()', 0);
  3394. }
  3395. // TODO
  3396. // Call autosave method to save the current progress.
  3397. //$this->index = 0;
  3398. $session_id = api_get_session_id();
  3399. $course_id = api_get_course_int_id();
  3400. $lp_view_table = Database :: get_course_table(TABLE_LP_VIEW);
  3401. $sql = "INSERT INTO $lp_view_table (c_id, lp_id, user_id, view_count, session_id) " .
  3402. "VALUES ($course_id, " . $this->lp_id . "," . $this->get_user_id() . "," . ($this->attempt + 1) . ", $session_id)";
  3403. if ($this->debug > 2) {
  3404. error_log('New LP - Inserting new lp_view for restart: ' . $sql, 0);
  3405. }
  3406. $res = Database::query($sql);
  3407. if ($view_id = Database :: insert_id($res)) {
  3408. $this->lp_view_id = $view_id;
  3409. $this->attempt = $this->attempt + 1;
  3410. } else {
  3411. $this->error = 'Could not insert into item_view table...';
  3412. return false;
  3413. }
  3414. $this->autocomplete_parents($this->current);
  3415. foreach ($this->items as $index => $dummy) {
  3416. $this->items[$index]->restart();
  3417. $this->items[$index]->set_lp_view($this->lp_view_id);
  3418. }
  3419. $this->first();
  3420. return true;
  3421. }
  3422. /**
  3423. * Saves the current item
  3424. * @return boolean
  3425. */
  3426. public function save_current() {
  3427. if ($this->debug > 0) {
  3428. error_log('New LP - In learnpath::save_current()', 0);
  3429. }
  3430. // TODO: Do a better check on the index pointing to the right item (it is supposed to be working
  3431. // on $ordered_items[] but not sure it's always safe to use with $items[]).
  3432. if ($this->debug > 2) {
  3433. error_log('New LP - save_current() saving item ' . $this->current, 0);
  3434. }
  3435. if ($this->debug > 2) {
  3436. error_log('' . print_r($this->items, true), 0);
  3437. }
  3438. if (is_object($this->items[$this->current])) {
  3439. //$res = $this->items[$this->current]->save(false);
  3440. $res = $this->items[$this->current]->save(false, $this->prerequisites_match($this->current));
  3441. $this->autocomplete_parents($this->current);
  3442. $status = $this->items[$this->current]->get_status();
  3443. $this->append_message('new_item_status: ' . $status);
  3444. $this->update_queue[$this->current] = $status;
  3445. return $res;
  3446. }
  3447. return false;
  3448. }
  3449. /**
  3450. * Saves the given item
  3451. * @param integer Item ID. Optional (will take from $_REQUEST if null)
  3452. * @param boolean Save from url params (true) or from current attributes (false). Optional. Defaults to true
  3453. * @return boolean
  3454. */
  3455. public function save_item($item_id = null, $from_outside = true) {
  3456. $course_id = api_get_course_int_id();
  3457. if ($this->debug > 0) {
  3458. error_log('New LP - In learnpath::save_item(' . $item_id . ',' . $from_outside . ')', 0);
  3459. }
  3460. // TODO: Do a better check on the index pointing to the right item (it is supposed to be working
  3461. // on $ordered_items[] but not sure it's always safe to use with $items[]).
  3462. if (empty ($item_id)) {
  3463. $item_id = $this->escape_string($_REQUEST['id']);
  3464. }
  3465. if (empty ($item_id)) {
  3466. $item_id = $this->get_current_item_id();
  3467. }
  3468. if ($this->debug > 2) {
  3469. error_log('New LP - save_current() saving item ' . $item_id, 0);
  3470. }
  3471. if (is_object($this->items[$item_id])) {
  3472. $res = $this->items[$item_id]->save($from_outside, $this->prerequisites_match($item_id));
  3473. //$res = $this->items[$item_id]->save($from_outside);
  3474. $this->autocomplete_parents($item_id);
  3475. $status = $this->items[$item_id]->get_status();
  3476. $this->append_message('new_item_status: ' . $status);
  3477. $this->update_queue[$item_id] = $status;
  3478. return $res;
  3479. }
  3480. return false;
  3481. }
  3482. /**
  3483. * Saves the last item seen's ID only in case
  3484. */
  3485. public function save_last() {
  3486. $course_id = api_get_course_int_id();
  3487. if ($this->debug > 0) {
  3488. error_log('New LP - In learnpath::save_last()', 0);
  3489. }
  3490. $session_condition = api_get_session_condition(api_get_session_id(), true, false);
  3491. $table = Database :: get_course_table(TABLE_LP_VIEW);
  3492. if (isset ($this->current)) {
  3493. if ($this->debug > 2) {
  3494. error_log('New LP - Saving current item (' . $this->current . ') for later review', 0);
  3495. }
  3496. $sql = "UPDATE $table SET last_item = " . Database::escape_string($this->get_current_item_id()). " " .
  3497. "WHERE c_id = ".$course_id." AND lp_id = " . $this->get_id() . " AND user_id = " . $this->get_user_id().' '.$session_condition;
  3498. if ($this->debug > 2) {
  3499. error_log('New LP - Saving last item seen : ' . $sql, 0);
  3500. }
  3501. $res = Database::query($sql);
  3502. }
  3503. // Save progress.
  3504. list($progress, $text) = $this->get_progress_bar_text('%');
  3505. if ($progress >= 0 && $progress <= 100) {
  3506. $progress = (int) $progress;
  3507. $sql = "UPDATE $table SET progress = $progress " .
  3508. "WHERE c_id = ".$course_id." AND lp_id = " . $this->get_id() . " AND " .
  3509. "user_id = " . $this->get_user_id().' '.$session_condition;
  3510. $res = Database::query($sql); // Ignore errors as some tables might not have the progress field just yet.
  3511. $this->progress_db = $progress;
  3512. }
  3513. }
  3514. /**
  3515. * Sets the current item ID (checks if valid and authorized first)
  3516. * @param integer New item ID. If not given or not authorized, defaults to current
  3517. */
  3518. public function set_current_item($item_id = null) {
  3519. if ($this->debug > 0) {
  3520. error_log('New LP - In learnpath::set_current_item(' . $item_id . ')', 0);
  3521. }
  3522. if (empty ($item_id)) {
  3523. if ($this->debug > 2) {
  3524. error_log('New LP - No new current item given, ignore...', 0);
  3525. }
  3526. // Do nothing.
  3527. } else {
  3528. if ($this->debug > 2) {
  3529. error_log('New LP - New current item given is ' . $item_id . '...', 0);
  3530. }
  3531. if (is_numeric($item_id)) {
  3532. $item_id = $this->escape_string($item_id);
  3533. // TODO: Check in database here.
  3534. $this->last = $this->current;
  3535. $this->current = $item_id;
  3536. // TODO: Update $this->index as well.
  3537. foreach ($this->ordered_items as $index => $item) {
  3538. if ($item == $this->current) {
  3539. $this->index = $index;
  3540. break;
  3541. }
  3542. }
  3543. if ($this->debug > 2) {
  3544. error_log('New LP - set_current_item(' . $item_id . ') done. Index is now : ' . $this->index, 0);
  3545. }
  3546. } else {
  3547. error_log('New LP - set_current_item(' . $item_id . ') failed. Not a numeric value: ', 0);
  3548. }
  3549. }
  3550. }
  3551. /**
  3552. * Sets the encoding
  3553. * @param string New encoding
  3554. * TODO (as of Chamilo 1.8.8): Check in the future whether this method is needed.
  3555. */
  3556. public function set_encoding($enc = 'UTF-8') {
  3557. if ($this->debug > 0) {
  3558. error_log('New LP - In learnpath::set_encoding()', 0);
  3559. }
  3560. $course_id = api_get_course_int_id();
  3561. /* // Deprecated code (Chamilo 1.8.8).
  3562. $enc = strtoupper($enc);
  3563. $encodings = array (
  3564. 'UTF-8',
  3565. 'ISO-8859-1',
  3566. 'ISO-8859-15',
  3567. 'cp1251',
  3568. 'cp1252',
  3569. 'KOI8-R',
  3570. 'BIG5',
  3571. 'GB2312',
  3572. 'Shift_JIS',
  3573. 'EUC-JP',
  3574. ''
  3575. );
  3576. if (in_array($enc, $encodings)) { // TODO: Incorrect comparison, fix it.
  3577. $lp = $this->get_id();
  3578. if ($lp != 0) {
  3579. $tbl_lp = Database :: get_course_table(TABLE_LP_MAIN);
  3580. $sql = "UPDATE $tbl_lp SET default_encoding = '$enc' WHERE id = " . $lp;
  3581. $res = Database::query($sql);
  3582. return $res;
  3583. }
  3584. }
  3585. return false;
  3586. */
  3587. $enc = api_refine_encoding_id($enc);
  3588. if (empty($enc)) {
  3589. $enc = api_get_system_encoding();
  3590. }
  3591. if (api_is_encoding_supported($enc)) {
  3592. $lp = $this->get_id();
  3593. if ($lp != 0) {
  3594. $tbl_lp = Database :: get_course_table(TABLE_LP_MAIN);
  3595. $sql = "UPDATE $tbl_lp SET default_encoding = '$enc' WHERE c_id = ".$course_id." AND id = " . $lp;
  3596. $res = Database::query($sql);
  3597. return $res;
  3598. }
  3599. }
  3600. return false;
  3601. }
  3602. /**
  3603. * Sets the JS lib setting in the database directly.
  3604. * This is the JavaScript library file this lp needs to load on startup
  3605. * @param string Proximity setting
  3606. * @return boolean True on update success. False otherwise.
  3607. */
  3608. public function set_jslib($lib = '') {
  3609. if ($this->debug > 0) {
  3610. error_log('New LP - In learnpath::set_jslib()', 0);
  3611. }
  3612. $lp = $this->get_id();
  3613. $course_id = api_get_course_int_id();
  3614. if ($lp != 0) {
  3615. $tbl_lp = Database :: get_course_table(TABLE_LP_MAIN);
  3616. $sql = "UPDATE $tbl_lp SET js_lib = '$lib' WHERE c_id = ".$course_id." AND id = " . $lp;
  3617. $res = Database::query($sql);
  3618. return $res;
  3619. } else {
  3620. return false;
  3621. }
  3622. }
  3623. /**
  3624. * Sets the name of the LP maker (publisher) (and save)
  3625. * @param string Optional string giving the new content_maker of this learnpath
  3626. * @return boolean True
  3627. */
  3628. public function set_maker($name = '') {
  3629. if ($this->debug > 0) {
  3630. error_log('New LP - In learnpath::set_maker()', 0);
  3631. }
  3632. if (empty ($name))
  3633. return false;
  3634. $this->maker = $this->escape_string($name);
  3635. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3636. $course_id = api_get_course_int_id();
  3637. $lp_id = $this->get_id();
  3638. $sql = "UPDATE $lp_table SET content_maker = '" . $this->maker . "' WHERE c_id = ".$course_id." AND id = '$lp_id'";
  3639. if ($this->debug > 2) {
  3640. error_log('New LP - lp updated with new content_maker : ' . $this->maker, 0);
  3641. }
  3642. $res = Database::query($sql);
  3643. return true;
  3644. }
  3645. /**
  3646. * Sets the name of the current learnpath (and save)
  3647. * @param string Optional string giving the new name of this learnpath
  3648. * @return boolean True/False
  3649. */
  3650. public function set_name($name = '') {
  3651. if ($this->debug > 0) {
  3652. error_log('New LP - In learnpath::set_name()', 0);
  3653. }
  3654. if (empty ($name))
  3655. return false;
  3656. $this->name = $this->escape_string($name);
  3657. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3658. $lp_id = $this->get_id();
  3659. $course_id = api_get_course_int_id();
  3660. $sql = "UPDATE $lp_table SET name = '" . $this->name . "' WHERE c_id = ".$course_id." AND id = '$lp_id'";
  3661. if ($this->debug > 2) {
  3662. error_log('New LP - lp updated with new name : ' . $this->name, 0);
  3663. }
  3664. $res = Database::query($sql);
  3665. // If the lp is visible on the homepage, change his name there.
  3666. if (Database::affected_rows()) {
  3667. $table = Database :: get_course_table(TABLE_TOOL_LIST);
  3668. $sql = 'UPDATE ' . $table . ' SET
  3669. name = "' . $this->name . '"
  3670. WHERE c_id = '.$course_id.' AND link = "newscorm/lp_controller.php?action=view&lp_id=' . $lp_id . '"';
  3671. Database::query($sql);
  3672. }
  3673. return true;
  3674. }
  3675. /**
  3676. * Set index specified prefix terms for all items in this path
  3677. * @param string Comma-separated list of terms
  3678. * @param char Xapian term prefix
  3679. * @return boolean False on error, true otherwise
  3680. */
  3681. public function set_terms_by_prefix($terms_string, $prefix) {
  3682. $course_id = api_get_course_int_id();
  3683. if (api_get_setting('search_enabled') !== 'true')
  3684. return false;
  3685. if (!extension_loaded('xapian')) {
  3686. return false;
  3687. }
  3688. $terms_string = trim($terms_string);
  3689. $terms = explode(',', $terms_string);
  3690. array_walk($terms, 'trim_value');
  3691. $stored_terms = $this->get_common_index_terms_by_prefix($prefix);
  3692. // Don't do anything if no change, verify only at DB, not the search engine.
  3693. if ((count(array_diff($terms, $stored_terms)) == 0) && (count(array_diff($stored_terms, $terms)) == 0))
  3694. return false;
  3695. require_once 'xapian.php'; // TODO: Try catch every xapian use or make wrappers on API.
  3696. require_once api_get_path(LIBRARY_PATH).'search/DokeosIndexer.class.php';
  3697. require_once api_get_path(LIBRARY_PATH).'search/xapian/XapianQuery.php';
  3698. require_once api_get_path(LIBRARY_PATH).'search/IndexableChunk.class.php';
  3699. $items_table = Database :: get_course_table(TABLE_LP_ITEM);
  3700. // TODO: Make query secure agains XSS : use member attr instead of post var.
  3701. $lp_id = intval($_POST['lp_id']);
  3702. $sql = "SELECT * FROM $items_table WHERE c_id = $course_id AND lp_id = $lp_id";
  3703. $result = Database::query($sql);
  3704. $di = new DokeosIndexer();
  3705. while ($lp_item = Database :: fetch_array($result)) {
  3706. // Get search_did.
  3707. $tbl_se_ref = Database :: get_main_table(TABLE_MAIN_SEARCH_ENGINE_REF);
  3708. $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';
  3709. $sql = sprintf($sql, $tbl_se_ref, $this->cc, TOOL_LEARNPATH, $lp_id, $lp_item['id']);
  3710. //echo $sql; echo '<br>';
  3711. $res = Database::query($sql);
  3712. if (Database::num_rows($res) > 0) {
  3713. $se_ref = Database :: fetch_array($res);
  3714. // Compare terms.
  3715. $doc = $di->get_document($se_ref['search_did']);
  3716. $xapian_terms = xapian_get_doc_terms($doc, $prefix);
  3717. $xterms = array ();
  3718. foreach ($xapian_terms as $xapian_term) {
  3719. $xterms[] = substr($xapian_term['name'], 1);
  3720. }
  3721. $dterms = $terms;
  3722. $missing_terms = array_diff($dterms, $xterms);
  3723. $deprecated_terms = array_diff($xterms, $dterms);
  3724. // Save it to search engine.
  3725. foreach ($missing_terms as $term) {
  3726. $doc->add_term($prefix . $term, 1);
  3727. }
  3728. foreach ($deprecated_terms as $term) {
  3729. $doc->remove_term($prefix . $term);
  3730. }
  3731. $di->getDb()->replace_document((int) $se_ref['search_did'], $doc);
  3732. $di->getDb()->flush();
  3733. } else {
  3734. //@todo What we should do here?
  3735. }
  3736. }
  3737. return true;
  3738. }
  3739. /**
  3740. * Sets the theme of the LP (local/remote) (and save)
  3741. * @param string Optional string giving the new theme of this learnpath
  3742. * @return bool Returns true if theme name is not empty
  3743. */
  3744. public function set_theme($name = '') {
  3745. $course_id = api_get_course_int_id();
  3746. if ($this->debug > 0) {
  3747. error_log('New LP - In learnpath::set_theme()', 0);
  3748. }
  3749. $this->theme = $this->escape_string($name);
  3750. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3751. $lp_id = $this->get_id();
  3752. $sql = "UPDATE $lp_table SET theme = '" . $this->theme . "' WHERE c_id = ".$course_id." AND id = '$lp_id'";
  3753. if ($this->debug > 2) {
  3754. error_log('New LP - lp updated with new theme : ' . $this->theme, 0);
  3755. }
  3756. //$res = Database::query($sql);
  3757. $res = Database::query($sql);
  3758. return true;
  3759. }
  3760. /**
  3761. * Sets the image of an LP (and save)
  3762. * @param string Optional string giving the new image of this learnpath
  3763. * @return bool Returns true if theme name is not empty
  3764. */
  3765. public function set_preview_image($name = '') {
  3766. $course_id = api_get_course_int_id();
  3767. if ($this->debug > 0) {
  3768. error_log('New LP - In learnpath::set_preview_image()', 0);
  3769. }
  3770. $this->preview_image = $this->escape_string($name);
  3771. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3772. $lp_id = $this->get_id();
  3773. $sql = "UPDATE $lp_table SET preview_image = '" . $this->preview_image . "' WHERE c_id = ".$course_id." AND id = '$lp_id'";
  3774. if ($this->debug > 2) {
  3775. error_log('New LP - lp updated with new preview image : ' . $this->preview_image, 0);
  3776. }
  3777. $res = Database::query($sql);
  3778. return true;
  3779. }
  3780. /**
  3781. * Sets the author of a LP (and save)
  3782. * @param string Optional string giving the new author of this learnpath
  3783. * @return bool Returns true if author's name is not empty
  3784. */
  3785. public function set_author($name = '') {
  3786. $course_id = api_get_course_int_id();
  3787. if ($this->debug > 0) {
  3788. error_log('New LP - In learnpath::set_author()', 0);
  3789. }
  3790. $this->author = $this->escape_string($name);
  3791. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3792. $lp_id = $this->get_id();
  3793. $sql = "UPDATE $lp_table SET author = '" . $this->author . "' WHERE c_id = ".$course_id." AND id = '$lp_id'";
  3794. if ($this->debug > 2) {
  3795. error_log('New LP - lp updated with new preview author : ' . $this->author, 0);
  3796. }
  3797. $res = Database::query($sql);
  3798. return true;
  3799. }
  3800. /**
  3801. * Sets the hide_toc_frame parameter of a LP (and save)
  3802. * @param int 1 if frame is hiddent 0 thenelse
  3803. * @return bool Returns true if author's name is not empty
  3804. */
  3805. public function set_hide_toc_frame($hide) {
  3806. $course_id = api_get_course_int_id();
  3807. if ($this->debug > 0) {
  3808. error_log('New LP - In learnpath::set_hide_toc_frame()', 0);
  3809. }
  3810. if (intval($hide) == $hide){
  3811. $this->hide_toc_frame = $hide;
  3812. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3813. $lp_id = $this->get_id();
  3814. $sql = "UPDATE $lp_table SET hide_toc_frame = '" . $this->hide_toc_frame . "'
  3815. WHERE c_id = ".$course_id." AND id = '$lp_id'";
  3816. if ($this->debug > 2) {
  3817. error_log('New LP - lp updated with new preview hide_toc_frame : ' . $this->author, 0);
  3818. }
  3819. $res = Database::query($sql);
  3820. return true;
  3821. } else {
  3822. return false;
  3823. }
  3824. }
  3825. /**
  3826. * Sets the prerequisite of a LP (and save)
  3827. * @param int integer giving the new prerequisite of this learnpath
  3828. * @return bool returns true if prerequisite is not empty
  3829. */
  3830. public function set_prerequisite($prerequisite) {
  3831. $course_id = api_get_course_int_id();
  3832. if ($this->debug > 0) {
  3833. error_log('New LP - In learnpath::set_prerequisite()', 0);
  3834. }
  3835. $this->prerequisite = intval($prerequisite);
  3836. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3837. $lp_id = $this->get_id();
  3838. $sql = "UPDATE $lp_table SET prerequisite = '".$this->prerequisite."'
  3839. WHERE c_id = ".$course_id." AND id = '$lp_id'";
  3840. if ($this->debug > 2) {
  3841. error_log('New LP - lp updated with new preview requisite : ' . $this->requisite, 0);
  3842. }
  3843. $res = Database::query($sql);
  3844. return true;
  3845. }
  3846. /**
  3847. * Sets the location/proximity of the LP (local/remote) (and save)
  3848. * @param string Optional string giving the new location of this learnpath
  3849. * @return boolean True on success / False on error
  3850. */
  3851. public function set_proximity($name = '') {
  3852. $course_id = api_get_course_int_id();
  3853. if ($this->debug > 0) {
  3854. error_log('New LP - In learnpath::set_proximity()', 0);
  3855. }
  3856. if (empty ($name))
  3857. return false;
  3858. $this->proximity = $this->escape_string($name);
  3859. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3860. $lp_id = $this->get_id();
  3861. $sql = "UPDATE $lp_table SET content_local = '" . $this->proximity . "'
  3862. WHERE c_id = ".$course_id." AND id = '$lp_id'";
  3863. if ($this->debug > 2) {
  3864. error_log('New LP - lp updated with new proximity : ' . $this->proximity, 0);
  3865. }
  3866. $res = Database::query($sql);
  3867. return true;
  3868. }
  3869. /**
  3870. * Sets the previous item ID to a given ID. Generally, this should be set to the previous 'current' item
  3871. * @param integer DB ID of the item
  3872. */
  3873. public function set_previous_item($id) {
  3874. if ($this->debug > 0) {
  3875. error_log('New LP - In learnpath::set_previous_item()', 0);
  3876. }
  3877. $this->last = $id;
  3878. }
  3879. /**
  3880. * Sets use_max_score
  3881. * @param string Optional string giving the new location of this learnpath
  3882. * @return boolean True on success / False on error
  3883. */
  3884. public function set_use_max_score($use_max_score = 1) {
  3885. $course_id = api_get_course_int_id();
  3886. if ($this->debug > 0) {
  3887. error_log('New LP - In learnpath::set_use_max_score()', 0);
  3888. }
  3889. $use_max_score = intval($use_max_score);
  3890. $this->use_max_score = $use_max_score;
  3891. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3892. $lp_id = $this->get_id();
  3893. $sql = "UPDATE $lp_table SET use_max_score = '" . $this->use_max_score . "' WHERE c_id = ".$course_id." AND id = '$lp_id'";
  3894. if ($this->debug > 2) {
  3895. error_log('New LP - lp updated with new use_max_score : ' . $this->use_max_score, 0);
  3896. }
  3897. $res = Database::query($sql);
  3898. return true;
  3899. }
  3900. /**
  3901. * Sets and saves the expired_on date
  3902. * @param string Optional string giving the new author of this learnpath
  3903. * @return bool Returns true if author's name is not empty
  3904. */
  3905. public function set_expired_on($expired_on) {
  3906. $course_id = api_get_course_int_id();
  3907. if ($this->debug > 0) {
  3908. error_log('New LP - In learnpath::set_expired_on()', 0);
  3909. }
  3910. if (!empty($expired_on)) {
  3911. $this->expired_on = $this->escape_string(api_get_utc_datetime($expired_on));
  3912. } else {
  3913. $this->expired_on = '';
  3914. }
  3915. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3916. $lp_id = $this->get_id();
  3917. $sql = "UPDATE $lp_table SET expired_on = '" . $this->expired_on . "' WHERE c_id = ".$course_id." AND id = '$lp_id'";
  3918. if ($this->debug > 2) {
  3919. error_log('New LP - lp updated with new expired_on : ' . $this->expired_on, 0);
  3920. }
  3921. $res = Database::query($sql);
  3922. return true;
  3923. }
  3924. /**
  3925. * Sets and saves the publicated_on date
  3926. * @param string Optional string giving the new author of this learnpath
  3927. * @return bool Returns true if author's name is not empty
  3928. */
  3929. public function set_publicated_on($publicated_on) {
  3930. $course_id = api_get_course_int_id();
  3931. if ($this->debug > 0) {
  3932. error_log('New LP - In learnpath::set_expired_on()', 0);
  3933. }
  3934. if (!empty($publicated_on)) {
  3935. $this->publicated_on = $this->escape_string(api_get_utc_datetime($publicated_on));
  3936. } else {
  3937. $this->publicated_on = '';
  3938. }
  3939. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3940. $lp_id = $this->get_id();
  3941. $sql = "UPDATE $lp_table SET publicated_on = '" . $this->publicated_on . "' WHERE c_id = ".$course_id." AND id = '$lp_id'";
  3942. if ($this->debug > 2) {
  3943. error_log('New LP - lp updated with new publicated_on : ' . $this->publicated_on, 0);
  3944. }
  3945. $res = Database::query($sql);
  3946. return true;
  3947. }
  3948. /**
  3949. * Sets and saves the expired_on date
  3950. * @param string Optional string giving the new author of this learnpath
  3951. * @return bool Returns true if author's name is not empty
  3952. */
  3953. public function set_modified_on() {
  3954. $course_id = api_get_course_int_id();
  3955. if ($this->debug > 0) {
  3956. error_log('New LP - In learnpath::set_expired_on()', 0);
  3957. }
  3958. $this->modified_on = api_get_utc_datetime();
  3959. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3960. $lp_id = $this->get_id();
  3961. $sql = "UPDATE $lp_table SET modified_on = '" . $this->modified_on . "' WHERE c_id = ".$course_id." AND id = '$lp_id'";
  3962. if ($this->debug > 2) {
  3963. error_log('New LP - lp updated with new expired_on : ' . $this->modified_on, 0);
  3964. }
  3965. $res = Database::query($sql);
  3966. return true;
  3967. }
  3968. /**
  3969. * Sets the object's error message
  3970. * @param string Error message. If empty, reinits the error string
  3971. * @return void
  3972. */
  3973. public function set_error_msg($error = '') {
  3974. if ($this->debug > 0) {
  3975. error_log('New LP - In learnpath::set_error_msg()', 0);
  3976. }
  3977. if (empty ($error)) {
  3978. $this->error = '';
  3979. } else {
  3980. $this->error .= $error;
  3981. }
  3982. }
  3983. /**
  3984. * Launches the current item if not 'sco' (starts timer and make sure there is a record ready in the DB)
  3985. * @param boolean Whether to allow a new attempt or not
  3986. * @return boolean True
  3987. */
  3988. public function start_current_item($allow_new_attempt = false) {
  3989. if ($this->debug > 0) {
  3990. error_log('New LP - In learnpath::start_current_item()', 0);
  3991. }
  3992. if ($this->current != 0 AND is_object($this->items[$this->current])) {
  3993. $type = $this->get_type();
  3994. $item_type = $this->items[$this->current]->get_type();
  3995. if (($type == 2 && $item_type != 'sco') OR ($type == 3 && $item_type != 'au') OR ($type == 1 && $item_type != TOOL_QUIZ && $item_type != TOOL_HOTPOTATOES)) {
  3996. $this->items[$this->current]->open($allow_new_attempt);
  3997. $this->autocomplete_parents($this->current);
  3998. $prereq_check = $this->prerequisites_match($this->current);
  3999. $this->items[$this->current]->save(false, $prereq_check);
  4000. //$this->update_queue[$this->last] = $this->items[$this->last]->get_status();
  4001. } else {
  4002. // If sco, then it is supposed to have been updated by some other call.
  4003. }
  4004. if ($item_type == 'sco') {
  4005. $this->items[$this->current]->restart();
  4006. }
  4007. }
  4008. if ($this->debug > 0) {
  4009. error_log('New LP - End of learnpath::start_current_item()', 0);
  4010. }
  4011. return true;
  4012. }
  4013. /**
  4014. * Stops the processing and counters for the old item (as held in $this->last)
  4015. * @return boolean True/False
  4016. */
  4017. public function stop_previous_item() {
  4018. if ($this->debug > 0) {
  4019. error_log('New LP - In learnpath::stop_previous_item()', 0);
  4020. }
  4021. if ($this->last != 0 && $this->last != $this->current && is_object($this->items[$this->last])) {
  4022. if ($this->debug > 2) {
  4023. error_log('New LP - In learnpath::stop_previous_item() - ' . $this->last . ' is object', 0);
  4024. }
  4025. switch ($this->get_type()) {
  4026. case '3' :
  4027. if ($this->items[$this->last]->get_type() != 'au') {
  4028. if ($this->debug > 2) {
  4029. error_log('New LP - In learnpath::stop_previous_item() - ' . $this->last . ' in lp_type 3 is <> au', 0);
  4030. }
  4031. $this->items[$this->last]->close();
  4032. //$this->autocomplete_parents($this->last);
  4033. //$this->update_queue[$this->last] = $this->items[$this->last]->get_status();
  4034. } else {
  4035. if ($this->debug > 2) {
  4036. error_log('New LP - In learnpath::stop_previous_item() - Item is an AU, saving is managed by AICC signals', 0);
  4037. }
  4038. }
  4039. case '2' :
  4040. if ($this->items[$this->last]->get_type() != 'sco') {
  4041. if ($this->debug > 2) {
  4042. error_log('New LP - In learnpath::stop_previous_item() - ' . $this->last . ' in lp_type 2 is <> sco', 0);
  4043. }
  4044. $this->items[$this->last]->close();
  4045. //$this->autocomplete_parents($this->last);
  4046. //$this->update_queue[$this->last] = $this->items[$this->last]->get_status();
  4047. } else {
  4048. if ($this->debug > 2) {
  4049. error_log('New LP - In learnpath::stop_previous_item() - Item is a SCO, saving is managed by SCO signals', 0);
  4050. }
  4051. }
  4052. break;
  4053. case '1' :
  4054. default :
  4055. if ($this->debug > 2) {
  4056. error_log('New LP - In learnpath::stop_previous_item() - ' . $this->last . ' in lp_type 1 is asset', 0);
  4057. }
  4058. $this->items[$this->last]->close();
  4059. break;
  4060. }
  4061. } else {
  4062. if ($this->debug > 2) {
  4063. error_log('New LP - In learnpath::stop_previous_item() - No previous element found, ignoring...', 0);
  4064. }
  4065. return false;
  4066. }
  4067. return true;
  4068. }
  4069. /**
  4070. * Updates the default view mode from fullscreen to embedded and inversely
  4071. * @return string The current default view mode ('fullscreen' or 'embedded')
  4072. */
  4073. public function update_default_view_mode() {
  4074. $course_id = api_get_course_int_id();
  4075. if ($this->debug > 0) {
  4076. error_log('New LP - In learnpath::update_default_view_mode()', 0);
  4077. }
  4078. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  4079. $sql = "SELECT * FROM $lp_table WHERE c_id = ".$course_id." AND id = " . $this->get_id();
  4080. $res = Database::query($sql);
  4081. if (Database :: num_rows($res) > 0) {
  4082. $row = Database :: fetch_array($res);
  4083. $view_mode = $row['default_view_mod'];
  4084. if ($view_mode == 'fullscreen') {
  4085. $view_mode = 'embedded';
  4086. } elseif ($view_mode == 'embedded') {
  4087. $view_mode = 'embedframe';
  4088. } elseif ($view_mode == 'embedframe') {
  4089. $view_mode = 'fullscreen';
  4090. }
  4091. $sql = "UPDATE $lp_table SET default_view_mod = '$view_mode' WHERE c_id = ".$course_id." AND id = " . $this->get_id();
  4092. $res = Database::query($sql);
  4093. $this->mode = $view_mode;
  4094. return $view_mode;
  4095. } else {
  4096. if ($this->debug > 2) {
  4097. error_log('New LP - Problem in update_default_view() - could not find LP ' . $this->get_id() . ' in DB', 0);
  4098. }
  4099. }
  4100. return -1;
  4101. }
  4102. /**
  4103. * Updates the default behaviour about auto-commiting SCORM updates
  4104. * @return boolean True if auto-commit has been set to 'on', false otherwise
  4105. */
  4106. public function update_default_scorm_commit() {
  4107. $course_id = api_get_course_int_id();
  4108. if ($this->debug > 0) {
  4109. error_log('New LP - In learnpath::update_default_scorm_commit()', 0);
  4110. }
  4111. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  4112. $sql = "SELECT * FROM $lp_table WHERE c_id = ".$course_id." AND id = " . $this->get_id();
  4113. $res = Database::query($sql);
  4114. if (Database :: num_rows($res) > 0) {
  4115. $row = Database :: fetch_array($res);
  4116. $force = $row['force_commit'];
  4117. if ($force == 1) {
  4118. $force = 0;
  4119. $force_return = false;
  4120. } elseif ($force == 0) {
  4121. $force = 1;
  4122. $force_return = true;
  4123. }
  4124. $sql = "UPDATE $lp_table SET force_commit = $force WHERE c_id = ".$course_id." AND id = " . $this->get_id();
  4125. $res = Database::query($sql);
  4126. $this->force_commit = $force_return;
  4127. return $force_return;
  4128. } else {
  4129. if ($this->debug > 2) {
  4130. error_log('New LP - Problem in update_default_scorm_commit() - could not find LP ' . $this->get_id() . ' in DB', 0);
  4131. }
  4132. }
  4133. return -1;
  4134. }
  4135. /**
  4136. * Updates the order of learning paths (goes through all of them by order and fills the gaps)
  4137. * @return bool True on success, false on failure
  4138. */
  4139. public function update_display_order() {
  4140. $course_id = api_get_course_int_id();
  4141. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  4142. $sql = "SELECT * FROM $lp_table WHERE c_id = ".$course_id." ORDER BY display_order";
  4143. $res = Database::query($sql);
  4144. if ($res === false)
  4145. return false;
  4146. $lps = array ();
  4147. $lp_order = array ();
  4148. $num = Database :: num_rows($res);
  4149. // First check the order is correct, globally (might be wrong because
  4150. // of versions < 1.8.4).
  4151. if ($num > 0) {
  4152. $i = 1;
  4153. while ($row = Database :: fetch_array($res)) {
  4154. if ($row['display_order'] != $i) { // If we find a gap in the order, we need to fix it.
  4155. $need_fix = true;
  4156. $sql_u = "UPDATE $lp_table SET display_order = $i WHERE c_id = ".$course_id." AND id = " . $row['id'];
  4157. $res_u = Database::query($sql_u);
  4158. }
  4159. $i++;
  4160. }
  4161. }
  4162. return true;
  4163. }
  4164. /**
  4165. * Updates the "prevent_reinit" value that enables control on reinitialising items on second view
  4166. * @return boolean True if prevent_reinit has been set to 'on', false otherwise (or 1 or 0 in this case)
  4167. */
  4168. public function update_reinit() {
  4169. $course_id = api_get_course_int_id();
  4170. if ($this->debug > 0) {
  4171. error_log('New LP - In learnpath::update_reinit()', 0);
  4172. }
  4173. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  4174. $sql = "SELECT * FROM $lp_table WHERE c_id = ".$course_id." AND id = " . $this->get_id();
  4175. $res = Database::query($sql);
  4176. if (Database :: num_rows($res) > 0) {
  4177. $row = Database :: fetch_array($res);
  4178. $force = $row['prevent_reinit'];
  4179. if ($force == 1) {
  4180. $force = 0;
  4181. } elseif ($force == 0) {
  4182. $force = 1;
  4183. }
  4184. $sql = "UPDATE $lp_table SET prevent_reinit = $force WHERE c_id = ".$course_id." AND id = " . $this->get_id();
  4185. $res = Database::query($sql);
  4186. $this->prevent_reinit = $force;
  4187. return $force;
  4188. } else {
  4189. if ($this->debug > 2) {
  4190. error_log('New LP - Problem in update_reinit() - could not find LP ' . $this->get_id() . ' in DB', 0);
  4191. }
  4192. }
  4193. return -1;
  4194. }
  4195. /**
  4196. * Determine the attempt_mode thanks to prevent_reinit and seriousgame_mode db flag
  4197. *
  4198. * @return string 'single', 'multi' or 'seriousgame'
  4199. * @author ndiechburg <noel@cblue.be>
  4200. **/
  4201. public function get_attempt_mode() {
  4202. if (!isset($this->seriousgame_mode)) { //Set default value for seriousgame_mode
  4203. $this->seriousgame_mode=0;
  4204. }
  4205. if (!isset($this->prevent_reinit)) { // Set default value for prevent_reinit
  4206. $this->prevent_reinit =1;
  4207. }
  4208. if ($this->seriousgame_mode == 1 && $this->prevent_reinit == 1) {
  4209. return 'seriousgame';
  4210. }
  4211. if ($this->seriousgame_mode == 0 && $this->prevent_reinit == 1) {
  4212. return 'single';
  4213. }
  4214. if ($this->seriousgame_mode == 0 && $this->prevent_reinit == 0) {
  4215. return 'multiple';
  4216. }
  4217. return 'single';
  4218. }
  4219. /**
  4220. * Register the attempt mode into db thanks to flags prevent_reinit and seriousgame_mode flags
  4221. *
  4222. * @param string 'seriousgame', 'single' or 'multiple'
  4223. * @return boolean
  4224. * @author ndiechburg <noel@cblue.be>
  4225. **/
  4226. public function set_attempt_mode($mode) {
  4227. $course_id = api_get_course_int_id();
  4228. switch ($mode) {
  4229. case 'seriousgame' :
  4230. $sg_mode = 1;
  4231. $prevent_reinit = 1;
  4232. break;
  4233. case 'single' :
  4234. $sg_mode = 0;
  4235. $prevent_reinit = 1;
  4236. break;
  4237. case 'multiple' :
  4238. $sg_mode = 0;
  4239. $prevent_reinit = 0;
  4240. break;
  4241. default :
  4242. $sg_mode = 0;
  4243. $prevent_reinit = 0;
  4244. break;
  4245. }
  4246. $this->prevent_reinit = $prevent_reinit;
  4247. $this->seriousgame_mode = $sg_mode;
  4248. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  4249. $sql = "UPDATE $lp_table SET prevent_reinit = $prevent_reinit , seriousgame_mode = $sg_mode WHERE c_id = ".$course_id." AND id = " . $this->get_id();
  4250. $res = Database::query($sql);
  4251. if ($res) {
  4252. return true;
  4253. }
  4254. else {
  4255. return false;
  4256. }
  4257. }
  4258. /**
  4259. * switch between multiple attempt, single attempt or serious_game mode (only for scorm)
  4260. *
  4261. * @return boolean
  4262. * @author ndiechburg <noel@cblue.be>
  4263. **/
  4264. public function switch_attempt_mode() {
  4265. if ($this->debug > 0) {
  4266. error_log('New LP - In learnpath::switch_attempt_mode()', 0);
  4267. }
  4268. $mode = $this->get_attempt_mode();
  4269. switch ($mode) {
  4270. case 'single' :
  4271. $next_mode = 'multiple';
  4272. break;
  4273. case 'multiple' :
  4274. $next_mode = 'seriousgame';
  4275. break;
  4276. case 'seriousgame' :
  4277. $next_mode = 'single';
  4278. break;
  4279. default :
  4280. $next_mode = 'single';
  4281. break;
  4282. }
  4283. $this->set_attempt_mode($next_mode);
  4284. }
  4285. /**
  4286. * Swithc the lp in ktm mode. This is a special scorm mode with unique attempt but possibility to do again a completed item.
  4287. *
  4288. * @return boolean true if seriousgame_mode has been set to 1, false otherwise
  4289. * @author ndiechburg <noel@cblue.be>
  4290. **/
  4291. public function set_seriousgame_mode() {
  4292. $course_id = api_get_course_int_id();
  4293. if ($this->debug > 0) {
  4294. error_log('New LP - In learnpath::set_seriousgame_mode()', 0);
  4295. }
  4296. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  4297. $sql = "SELECT * FROM $lp_table WHERE c_id = ".$course_id." AND id = " . $this->get_id();
  4298. $res = Database::query($sql);
  4299. if (Database :: num_rows($res) > 0) {
  4300. $row = Database :: fetch_array($res);
  4301. $force = $row['seriousgame_mode'];
  4302. if ($force == 1) {
  4303. $force = 0;
  4304. } elseif ($force == 0) {
  4305. $force = 1;
  4306. }
  4307. $sql = "UPDATE $lp_table SET seriousgame_mode = $force WHERE c_id = ".$course_id." AND id = " . $this->get_id();
  4308. $res = Database::query($sql);
  4309. $this->seriousgame_mode = $force;
  4310. return $force;
  4311. } else {
  4312. if ($this->debug > 2) {
  4313. error_log('New LP - Problem in set_seriousgame_mode() - could not find LP ' . $this->get_id() . ' in DB', 0);
  4314. }
  4315. }
  4316. return -1;
  4317. }
  4318. /**
  4319. * Updates the "scorm_debug" value that shows or hide the debug window
  4320. * @return boolean True if scorm_debug has been set to 'on', false otherwise (or 1 or 0 in this case)
  4321. */
  4322. public function update_scorm_debug() {
  4323. $course_id = api_get_course_int_id();
  4324. if ($this->debug > 0) {
  4325. error_log('New LP - In learnpath::update_scorm_debug()', 0);
  4326. }
  4327. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  4328. $sql = "SELECT * FROM $lp_table WHERE c_id = ".$course_id." AND id = " . $this->get_id();
  4329. $res = Database::query($sql);
  4330. if (Database :: num_rows($res) > 0) {
  4331. $row = Database :: fetch_array($res);
  4332. $force = $row['debug'];
  4333. if ($force == 1) {
  4334. $force = 0;
  4335. } elseif ($force == 0) {
  4336. $force = 1;
  4337. }
  4338. $sql = "UPDATE $lp_table SET debug = $force WHERE c_id = ".$course_id." AND id = " . $this->get_id();
  4339. $res = Database::query($sql);
  4340. $this->scorm_debug = $force;
  4341. return $force;
  4342. } else {
  4343. if ($this->debug > 2) {
  4344. error_log('New LP - Problem in update_scorm_debug() - could not find LP ' . $this->get_id() . ' in DB', 0);
  4345. }
  4346. }
  4347. return -1;
  4348. }
  4349. /**
  4350. * Function that makes a call to the function sort_tree_array and create_tree_array
  4351. * @author Kevin Van Den Haute
  4352. * @param array
  4353. */
  4354. public function tree_array($array) {
  4355. if ($this->debug > 1) {
  4356. error_log('New LP - In learnpath::tree_array()', 0);
  4357. }
  4358. $array = $this->sort_tree_array($array);
  4359. $this->create_tree_array($array);
  4360. }
  4361. /**
  4362. * Creates an array with the elements of the learning path tree in it
  4363. *
  4364. * @author Kevin Van Den Haute
  4365. * @param array $array
  4366. * @param int $parent
  4367. * @param int $depth
  4368. * @param array $tmp
  4369. */
  4370. public function create_tree_array($array, $parent = 0, $depth = -1, $tmp = array ()) {
  4371. if ($this->debug > 1) {
  4372. error_log('New LP - In learnpath::create_tree_array())', 0);
  4373. }
  4374. if (is_array($array)) {
  4375. for ($i = 0; $i < count($array); $i++) {
  4376. if ($array[$i]['parent_item_id'] == $parent) {
  4377. if (!in_array($array[$i]['parent_item_id'], $tmp)) {
  4378. $tmp[] = $array[$i]['parent_item_id'];
  4379. $depth++;
  4380. }
  4381. $preq = (empty($array[$i]['prerequisite']) ? '' : $array[$i]['prerequisite']);
  4382. $audio = isset($array[$i]['audio']) ? $array[$i]['audio'] : null;
  4383. $this->arrMenu[] = array (
  4384. 'id' => $array[$i]['id'],
  4385. 'item_type' => $array[$i]['item_type'],
  4386. 'title' => $array[$i]['title'],
  4387. 'path' => $array[$i]['path'],
  4388. 'description' => $array[$i]['description'],
  4389. 'parent_item_id' => $array[$i]['parent_item_id'],
  4390. 'previous_item_id' => $array[$i]['previous_item_id'],
  4391. 'next_item_id' => $array[$i]['next_item_id'],
  4392. 'min_score' => $array[$i]['min_score'],
  4393. 'max_score' => $array[$i]['max_score'],
  4394. 'mastery_score' => $array[$i]['mastery_score'],
  4395. 'display_order' => $array[$i]['display_order'],
  4396. 'prerequisite' => $preq,
  4397. 'depth' => $depth,
  4398. 'audio' => $audio
  4399. );
  4400. $this->create_tree_array($array, $array[$i]['id'], $depth, $tmp);
  4401. }
  4402. }
  4403. }
  4404. }
  4405. /**
  4406. * Sorts a multi dimensional array by parent id and display order
  4407. * @author Kevin Van Den Haute
  4408. *
  4409. * @param array $array (array with al the learning path items in it)
  4410. *
  4411. * @return array
  4412. */
  4413. public function sort_tree_array($array) {
  4414. foreach ($array as $key => $row) {
  4415. $parent[$key] = $row['parent_item_id'];
  4416. $position[$key] = $row['display_order'];
  4417. }
  4418. if (count($array) > 0)
  4419. array_multisort($parent, SORT_ASC, $position, SORT_ASC, $array);
  4420. return $array;
  4421. }
  4422. /**
  4423. * Function that creates a table structure with a learning path his modules, chapters and documents.
  4424. * Also the actions for the modules, chapters and documents are in this table.
  4425. * @author Kevin Van Den Haute
  4426. * @param int $lp_id
  4427. * @return string
  4428. */
  4429. public function overview() {
  4430. $course_id = api_get_course_int_id();
  4431. $is_allowed_to_edit = api_is_allowed_to_edit(null,true);
  4432. if ($this->debug > 0) {
  4433. error_log('New LP - In learnpath::overview()', 0);
  4434. }
  4435. global $charset, $_course;
  4436. $_SESSION['gradebook'] = isset($_GET['gradebook']) ? Security :: remove_XSS($_GET['gradebook']) : null;
  4437. $return = '';
  4438. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  4439. $sql = "SELECT * FROM " . $tbl_lp_item . "
  4440. WHERE c_id = ".$course_id." AND lp_id = " . $this->lp_id;
  4441. $result = Database::query($sql);
  4442. $arrLP = array ();
  4443. while ($row = Database :: fetch_array($result)) {
  4444. $row['title'] = Security :: remove_XSS($row['title']);
  4445. $row['description'] = Security :: remove_XSS($row['description']);
  4446. $arrLP[] = array (
  4447. 'id' => $row['id'],
  4448. 'item_type' => $row['item_type'],
  4449. 'title' => $row['title'],
  4450. 'path' => $row['path'],
  4451. 'description' => $row['description'],
  4452. 'parent_item_id' => $row['parent_item_id'],
  4453. 'previous_item_id' => $row['previous_item_id'],
  4454. 'next_item_id' => $row['next_item_id'],
  4455. 'max_score' => $row['max_score'],
  4456. 'min_score' => $row['min_score'],
  4457. 'mastery_score' => $row['mastery_score'],
  4458. 'prerequisite' => $row['prerequisite'],
  4459. 'display_order' => $row['display_order'],
  4460. 'audio' => $row['audio']
  4461. );
  4462. }
  4463. $this->tree_array($arrLP);
  4464. $arrLP = $this->arrMenu;
  4465. unset ($this->arrMenu);
  4466. $update_audio = isset($_GET['updateaudio']) ? $_GET['updateaudio'] : null;
  4467. if ($is_allowed_to_edit) {
  4468. $token = Security::get_token();
  4469. $gradebook = isset($_GET['gradebook']) ? Security :: remove_XSS($_GET['gradebook']) : null;
  4470. $return .= '<div class="actions">';
  4471. $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'),'',ICON_SIZE_MEDIUM).'</a>';
  4472. if ($update_audio == 'true') {
  4473. $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'),'',ICON_SIZE_MEDIUM).'</a>';
  4474. } else {
  4475. $return .= Display :: return_icon('move_learnpath_na.png', get_lang('BasicOverview'),'',ICON_SIZE_MEDIUM);
  4476. }
  4477. $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'),'',ICON_SIZE_MEDIUM).'</a>';
  4478. $return .= ' '.Display :: return_icon('i.gif');
  4479. $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') . '">
  4480. '. Display :: return_icon('add.png', get_lang('NewStep'),'',ICON_SIZE_MEDIUM).'</a>';
  4481. /*$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') . '">
  4482. '. Display :: return_icon('add_learnpath_section.png', get_lang('NewChapter'),'',ICON_SIZE_MEDIUM).'</a>';*/
  4483. if ($update_audio == 'true') {
  4484. $return .= Display::url(Display :: return_icon('upload_audio_na.png', get_lang('UpdateAllAudioFragments'),'',ICON_SIZE_MEDIUM),'#');
  4485. } else {
  4486. $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'),'',ICON_SIZE_MEDIUM).'</a>';
  4487. }
  4488. $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'),'',ICON_SIZE_MEDIUM).'</a>';
  4489. $return .= '</div>';
  4490. }
  4491. // we need to start a form when we want to update all the mp3 files
  4492. if ($update_audio == 'true' AND count($arrLP) <> 0) {
  4493. $return .= '<form action="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&amp;updateaudio=' . Security :: remove_XSS($_GET['updateaudio']) .'&amp;action=' . Security :: remove_XSS($_GET['action']) . '&amp;lp_id=' . $_SESSION['oLP']->lp_id . '" method="post" enctype="multipart/form-data" name="updatemp3" id="updatemp3">';
  4494. //$return .= Display::return_message(get_lang('LeaveEmptyToKeepCurrentFile'), 'warning');
  4495. }
  4496. $return .= '<div id="message"></div>';
  4497. $return_audio = '<table class="data_table">';
  4498. $return_audio .= '<tr>';
  4499. $return_audio .= '<th width="60%">' . get_lang('Title') . '</th>';
  4500. $return_audio .= '<th>' . get_lang('Audio') . '</th>';
  4501. //$return_audio .= '<th>' . get_lang('Actions') . '</th>';
  4502. $return_audio .= '</tr>';
  4503. $elements = array();
  4504. for ($i = 0; $i < count($arrLP); $i++) {
  4505. $title = $arrLP[$i]['title'];
  4506. if (($i % 2) == 0) {
  4507. $oddclass = 'row_odd';
  4508. } else {
  4509. $oddclass = 'row_even';
  4510. }
  4511. $return_audio .= '<tr id ="lp_item_'.$arrLP[$i]['id'] .'" class="' . $oddclass . '">';
  4512. // "lp_item_'.$i.' is important for the drag and drop otherwise the LP will not work
  4513. $icon_name = str_replace(' ', '', $arrLP[$i]['item_type']);
  4514. /*
  4515. if (file_exists('../img/lp_' . $icon_name . '.png')) {
  4516. $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>';
  4517. } else {
  4518. if (file_exists('../img/lp_' . $icon_name . '.gif')) {
  4519. $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>';
  4520. } else {
  4521. //$return .= '<td style="padding-left:' . $arrLP[$i]['depth'] * 10 . 'px;">' . Display::display_icon('folder_document.gif','',array('style'=>'margin-right:3px;')) . $title . '</td>';
  4522. $return .= '<td style="padding-left:' . $arrLP[$i]['depth'] * 10 . 'px;"><img align="left" src="../img/folder_document.gif" style="margin-right:3px;" />' . $title . '</td>';
  4523. }
  4524. }*/
  4525. $icon = '';
  4526. if (file_exists('../img/lp_' . $icon_name . '.png')) {
  4527. $icon = '<img align="left" src="../img/lp_' . $icon_name . '.png" style="margin-right:3px;" />';
  4528. } else {
  4529. if (file_exists('../img/lp_' . $icon_name . '.gif')) {
  4530. $icon = '<img align="left" src="../img/lp_' . $icon_name . '.gif" style="margin-right:3px;" />';
  4531. } else {
  4532. $icon = '<img align="left" src="../img/folder_document.gif" style="margin-right:3px;" />';
  4533. }
  4534. }
  4535. // The audio column.
  4536. $return_audio .= '<td align="center">';
  4537. $audio = '';
  4538. if (!$update_audio OR $update_audio <> 'true') {
  4539. if (!empty ($arrLP[$i]['audio'])) {
  4540. $audio .= '<span id="container'.$i.'"><a href="http://www.macromedia.com/go/getflashplayer">Get the Flash Player</a> to see this player.</span>';
  4541. $audio .= '<script type="text/javascript" src="../inc/lib/mediaplayer/swfobject.js"></script>';
  4542. $audio .= '<script type="text/javascript">
  4543. var s1 = new SWFObject("../inc/lib/mediaplayer/player.swf","ply","250","20","9","#FFFFFF");
  4544. s1.addParam("allowscriptaccess","always");
  4545. s1.addParam("flashvars","file=../../courses/' . $_course['path'] . '/document/audio/' . $arrLP[$i]['audio'] . '");
  4546. s1.write("container' . $i . '");
  4547. </script>';
  4548. } else {
  4549. $audio .= '';
  4550. }
  4551. } else {
  4552. if ($arrLP[$i]['item_type'] != 'dokeos_chapter' && $arrLP[$i]['item_type'] != 'dokeos_module' && $arrLP[$i]['item_type'] != 'dir') {
  4553. $audio .= '<input type="file" name="mp3file' . $arrLP[$i]['id'] . '" id="mp3file" />';
  4554. if (!empty ($arrLP[$i]['audio'])) {
  4555. $audio .= '<br />'.Security::remove_XSS($arrLP[$i]['audio']).'<br /><input type="checkbox" name="removemp3' . $arrLP[$i]['id'] . '" id="checkbox' . $arrLP[$i]['id'] . '" />' . get_lang('RemoveAudio');
  4556. }
  4557. }
  4558. }
  4559. $return_audio .= Display::span($title.$icon).Display::tag('td', $audio, array('style'=>'text-align:right'));
  4560. $return_audio .= '</td>';
  4561. $move_icon = '';
  4562. $edit_icon = '';
  4563. $delete_icon = '';
  4564. if ($is_allowed_to_edit) {
  4565. if (!$update_audio OR $update_audio <> 'true') {
  4566. $move_icon .= '<a class="moved" href="#">';
  4567. $move_icon .= Display::return_icon('move.png', get_lang('Move'), array(), 24);
  4568. $move_icon .= '</a>';
  4569. }
  4570. if ($arrLP[$i]['item_type'] != 'dokeos_chapter' && $arrLP[$i]['item_type'] != 'dokeos_module') {
  4571. $edit_icon .= '<a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&amp;action=edit_item&amp;view=build&amp;id=' . $arrLP[$i]['id'] . '&amp;lp_id=' . $this->lp_id . '&amp;path_item=' . $arrLP[$i]['path'] . '">';
  4572. $edit_icon .= '<img style="margin:1px;" alt="" src="../img/edit.png" title="' . get_lang('_edit_learnpath_module') . '" />';
  4573. $edit_icon .= '</a>';
  4574. } else {
  4575. $edit_icon .= '<a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&amp;action=edit_item&amp;id=' . $arrLP[$i]['id'] . '&amp;lp_id=' . $this->lp_id . '&amp;path_item=' . $arrLP[$i]['path'] . '">';
  4576. $edit_icon .= '<img style="margin:1px;" alt="" src="../img/edit.png" title="' . get_lang('_edit_learnpath_module') . '" />';
  4577. $edit_icon .= '</a>';
  4578. }
  4579. $delete_icon .= '<a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&amp;action=delete_item&amp;id=' . $arrLP[$i]['id'] . '&amp;lp_id=' . $this->lp_id . '" onClick="return confirmation(\'' . addslashes($title) . '\');">';
  4580. $delete_icon .= '<img style="margin:1px;" alt="" src="../img/delete.png" title="' . get_lang('_delete_learnpath_module') . '" />';
  4581. $delete_icon .= '</a>';
  4582. }
  4583. if ($update_audio != 'true') {
  4584. $row = $move_icon.Display::span($title.$icon).Display::span($audio.$edit_icon.$delete_icon, array('class'=>'button_actions'));
  4585. } else {
  4586. $row = Display::span($title.$icon).Display::span($audio, array('class'=>'button_actions'));
  4587. }
  4588. $parent_id = $arrLP[$i]['parent_item_id'];
  4589. $default_data[$arrLP[$i]['id']] = $row;
  4590. $default_content[$arrLP[$i]['id']] = $arrLP[$i];
  4591. if (empty($parent_id)) {
  4592. $elements[$arrLP[$i]['id']]['data'] = $row;
  4593. $elements[$arrLP[$i]['id']]['type'] = $arrLP[$i]['item_type'];
  4594. } else {
  4595. $parent_arrays = array();
  4596. if ($arrLP[$i]['depth'] > 1) {
  4597. //Getting list of parents
  4598. for($j = 0; $j < $arrLP[$i]['depth']; $j++) {
  4599. foreach($arrLP as $item) {
  4600. if ($item['id'] == $parent_id) {
  4601. if ($item['parent_item_id'] == 0) {
  4602. $parent_id = $item['id'];
  4603. //$parent_arrays[] = $parent_id;
  4604. break;
  4605. } else {
  4606. $parent_id = $item['parent_item_id'];
  4607. if (empty($parent_arrays)) {
  4608. $parent_arrays[] = intval($item['id']);
  4609. }
  4610. $parent_arrays[] = $parent_id;
  4611. break;
  4612. }
  4613. }
  4614. }
  4615. }
  4616. }
  4617. if (!empty($parent_arrays)) {
  4618. $parent_arrays = array_reverse($parent_arrays);
  4619. $value_to_insert = array();
  4620. $val = '$elements';
  4621. $x = 0;
  4622. foreach($parent_arrays as $item) {
  4623. if ($x != count($parent_arrays) -1) {
  4624. $val .= '["'.$item.'"]["children"]';
  4625. } else {
  4626. $val .= '["'.$item.'"]["children"]';
  4627. }
  4628. $x++;
  4629. }
  4630. $val .= "";
  4631. $generated_array = null;
  4632. $code_str = $val."[".$arrLP[$i]['id']."][\"load_data\"] = '".$arrLP[$i]['id']."' ; ";
  4633. eval($code_str);
  4634. } else {
  4635. $elements[$parent_id]['children'][$arrLP[$i]['id']]['data'] = $row;
  4636. $elements[$parent_id]['children'][$arrLP[$i]['id']]['type'] = $arrLP[$i]['item_type'];
  4637. }
  4638. }
  4639. }
  4640. //@todo move this somewhere else
  4641. function print_recursive($elements, $default_data, $default_content) {
  4642. $return = '';
  4643. foreach($elements as $key => $item) {
  4644. if (isset($item['load_data']) || empty($item['data'])) {
  4645. $item['data'] = $default_data[$item['load_data']];
  4646. $item['type'] = $default_content[$item['load_data']]['item_type'];
  4647. }
  4648. $sub_list = '';
  4649. if (isset($item['type']) && $item['type'] == 'dokeos_chapter') {
  4650. $sub_list = Display::tag('li', '', array('class'=>'sub_item empty')); // empty value
  4651. }
  4652. if (empty($item['children'])) {
  4653. $sub_list = Display::tag('ul', $sub_list, array('id'=>'UL_'.$key, 'class'=>'record container'));
  4654. $return .= Display::tag('li', Display::div($item['data'], array('class'=>'item_data')).$sub_list, array('id'=>$key, 'class'=>'record container'));
  4655. } else {
  4656. //sections
  4657. if (isset($item['children'])) {
  4658. $data = print_recursive($item['children'], $default_data, $default_content);
  4659. }
  4660. /*foreach($item['children'] as $my_key => $sub_item) {
  4661. $sub_list .= Display::tag('li', $sub_item['data'], array('id'=>$my_key,'class'=>'record item'));
  4662. }*/
  4663. $sub_list = Display::tag('ul', $sub_list.$data, array('id'=>'UL_'.$key, 'class'=>'record container'));
  4664. $return .= Display::tag('li', Display::div($item['data'], array('class'=>'item_data')).$sub_list, array('id'=>$key, 'class'=>'record container'));
  4665. }
  4666. }
  4667. return $return;
  4668. }
  4669. if ($update_audio != 'true') {
  4670. $return .= '<div style="width:90%;"><ul id="lp_item_list">';
  4671. $return .= print_recursive($elements, $default_data, $default_content);
  4672. $return .='</ul></div>';
  4673. $return .= Display::div(Display::url(get_lang('Save'), '#', array('id'=>'listSubmit', 'class'=>'a_button orange medium')), array('style'=>'float:left; margin-top:15px;width:100%'));
  4674. } else {
  4675. $return .= $return_audio.'</table>';
  4676. }
  4677. /*
  4678. if (count($arrLP) == 0) {
  4679. $return .= '<tr>';
  4680. $return .= '<td colspan="4">' . get_lang('NoItemsInLp') . '</td>';
  4681. $return .= '</tr>';
  4682. }*/
  4683. // We need to close the form when we are updating the mp3 files.
  4684. if ($update_audio == 'true') {
  4685. $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?
  4686. }
  4687. // We need to close the form when we are updating the mp3 files.
  4688. if ($update_audio == 'true' && count($arrLP) != 0) {
  4689. $return .= '</form>';
  4690. }
  4691. return $return;
  4692. }
  4693. /**
  4694. * This function builds the action menu
  4695. * @return void
  4696. */
  4697. public function build_action_menu() {
  4698. $gradebook = isset($_GET['gradebook']) ? Security :: remove_XSS($_GET['gradebook']) : null;
  4699. echo '<div class="actions">';
  4700. echo Display :: return_icon('build_learnpath_na.png', get_lang('Build'),'',ICON_SIZE_MEDIUM);
  4701. echo '<a href="' . api_get_self().'?'.api_get_cidreq().'&amp;gradebook=' . $gradebook . '&amp;action=admin_view&amp;lp_id=' . $_SESSION['oLP']->lp_id . '" title="' . get_lang('BasicOverview') . '">' . Display :: return_icon('move_learnpath.png', get_lang('BasicOverview'),'',ICON_SIZE_MEDIUM).'</a>';
  4702. echo '<a href="lp_controller.php?'.api_get_cidreq().'&amp;gradebook=' . $gradebook . '&action=view&lp_id=' . $_SESSION['oLP']->lp_id . '">' . Display :: return_icon('view_left_right.png', get_lang('Display'),'',ICON_SIZE_MEDIUM).'</a> ';
  4703. Display :: display_icon('i.gif');
  4704. echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&amp;gradebook=' . $gradebook . '&amp;action=add_item&amp;type=step&amp;lp_id=' . $_SESSION['oLP']->lp_id . '" title="' . get_lang('NewStep') . '">' . Display :: return_icon('add.png', get_lang('NewStep'),'',ICON_SIZE_MEDIUM).'</a>';
  4705. // echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&amp;gradebook=' . $gradebook . '&amp;action=add_item&amp;type=chapter&amp;lp_id=' . $_SESSION['oLP']->lp_id . '" title="' . get_lang('NewChapter') . '">' . Display :: return_icon('add_learnpath_section.png', get_lang('NewChapter'),'',ICON_SIZE_MEDIUM).'</a>';
  4706. echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&amp;action=admin_view&amp;lp_id=' . $_SESSION['oLP']->lp_id . '&amp;updateaudio=true">' . Display :: return_icon('upload_audio.png', get_lang('UpdateAllAudioFragments'),'',ICON_SIZE_MEDIUM).'</a>';
  4707. echo '<a href="lp_controller.php?'.api_get_cidreq().'&amp;action=edit&amp;lp_id=' . $_SESSION['oLP']->lp_id . '">' . Display :: return_icon('settings.png', get_lang('CourseSettings'),'',ICON_SIZE_MEDIUM).'</a>';
  4708. echo '</div>';
  4709. }
  4710. /**
  4711. * This functions builds the LP tree based on data from the database.
  4712. * @return string
  4713. * @uses dtree.js :: necessary javascript for building this tree
  4714. */
  4715. public function build_tree() {
  4716. $course_id = api_get_course_int_id();
  4717. $return = "<script type=\"text/javascript\">\n";
  4718. $return .= "\tm = new dTree('m');\n\n";
  4719. $return .= "\tm.config.folderLinks = true;\n";
  4720. $return .= "\tm.config.useCookies = true;\n";
  4721. $return .= "\tm.config.useIcons = true;\n";
  4722. $return .= "\tm.config.useLines = true;\n";
  4723. $return .= "\tm.config.useSelection = true;\n";
  4724. $return .= "\tm.config.useStatustext = false;\n\n";
  4725. $menu = 0;
  4726. $parent = '';
  4727. $return .= "\tm.add(" . $menu . ", -1, '" . addslashes(Security::remove_XSS(($this->name))) . "');\n";
  4728. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  4729. $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
  4730. FROM $tbl_lp_item
  4731. WHERE c_id = ".$course_id." AND lp_id = " . Database :: escape_string($this->lp_id);
  4732. $result = Database::query($sql);
  4733. $arrLP = array ();
  4734. while ($row = Database :: fetch_array($result)) {
  4735. $row['title'] = Security :: remove_XSS($row['title']);
  4736. $row['description'] = Security :: remove_XSS($row['description']);
  4737. $arrLP[] = array (
  4738. 'id' => $row['id'],
  4739. 'item_type' => $row['item_type'],
  4740. 'title' => $row['title'],
  4741. 'path' => $row['path'],
  4742. 'description' => $row['description'],
  4743. 'parent_item_id' => $row['parent_item_id'],
  4744. 'previous_item_id' => $row['previous_item_id'],
  4745. 'next_item_id' => $row['next_item_id'],
  4746. 'max_score' => $row['max_score'],
  4747. 'min_score' => $row['min_score'],
  4748. 'mastery_score' => $row['mastery_score'],
  4749. 'display_order' => $row['display_order']
  4750. );
  4751. }
  4752. $this->tree_array($arrLP);
  4753. $arrLP = $this->arrMenu;
  4754. unset ($this->arrMenu);
  4755. $title = '';
  4756. for ($i = 0; $i < count($arrLP); $i++) {
  4757. $title = addslashes($arrLP[$i]['title']);
  4758. $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;
  4759. $icon_name = str_replace(' ', '', $arrLP[$i]['item_type']);
  4760. if (file_exists('../img/lp_' . $icon_name . '.png')) {
  4761. $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";
  4762. } else
  4763. if (file_exists('../img/lp_' . $icon_name . '.gif')) {
  4764. $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";
  4765. } else {
  4766. $return .= "\tm.add(" . $arrLP[$i]['id'] . ", " . $arrLP[$i]['parent_item_id'] . ", '" . $title . "', '" . $menu_page . "', '', '', '../img/folder_document.gif', '../img/folder_document.gif');\n";
  4767. }
  4768. if ($menu < $arrLP[$i]['id'])
  4769. $menu = $arrLP[$i]['id'];
  4770. }
  4771. $return .= "\n\tdocument.write(m);\n";
  4772. $return .= "\t if(!m.selectedNode) m.s(1);";
  4773. $return .= "</script>\n";
  4774. return $return;
  4775. }
  4776. public function generate_lp_folder($course, $dir) {
  4777. $filepath = '';
  4778. //Creating learning_path folder
  4779. $dir = '/learning_path';
  4780. $filepath = api_get_path(SYS_COURSE_PATH) . $course['path'] . '/document';
  4781. $folder = null;
  4782. if (!is_dir($filepath.'/'.$dir)) {
  4783. $folder = create_unexisting_directory($course, api_get_user_id(), api_get_session_id(), 0, 0, $filepath, $dir , get_lang('LearningPaths'));
  4784. } else {
  4785. $folder = true;
  4786. }
  4787. $dir = '/learning_path/';
  4788. //Creating LP folder
  4789. if ($folder) {
  4790. //Limits title size
  4791. $title = api_substr(replace_dangerous_char($this->name), 0 , 80);
  4792. $dir = $dir.$title;
  4793. $filepath = api_get_path(SYS_COURSE_PATH) . $course['path'] . '/document';
  4794. if (!is_dir($filepath.'/'.$dir)) {
  4795. $folder = create_unexisting_directory($course, api_get_user_id(), api_get_session_id(), 0, 0, $filepath, $dir , $this->name);
  4796. } else {
  4797. $folder = true;
  4798. }
  4799. $dir = $dir.'/';
  4800. if ($folder) {
  4801. $filepath = api_get_path(SYS_COURSE_PATH) . $course['path'] . '/document'.$dir;
  4802. }
  4803. }
  4804. $array = array('dir' => $dir, 'filepath' => $filepath);
  4805. return $array;
  4806. }
  4807. /**
  4808. * Create a new document //still needs some finetuning
  4809. * @param array $_course
  4810. * @return string
  4811. */
  4812. public function create_document($_course) {
  4813. $course_id = api_get_course_int_id();
  4814. global $charset;
  4815. $dir = isset ($_GET['dir']) ? $_GET['dir'] : $_POST['dir']; // Please, do not modify this dirname formatting.
  4816. if (strstr($dir, '..'))
  4817. $dir = '/';
  4818. if ($dir[0] == '.')
  4819. $dir = substr($dir, 1);
  4820. if ($dir[0] != '/')
  4821. $dir = '/' . $dir;
  4822. if ($dir[strlen($dir) - 1] != '/')
  4823. $dir .= '/';
  4824. $filepath = api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document' . $dir;
  4825. if (empty($_POST['dir']) && empty($_GET['dir'])) {
  4826. $result = $this->generate_lp_folder($_course, $dir);
  4827. $dir = $result['dir'];
  4828. $filepath = $result['filepath'];
  4829. }
  4830. if (!is_dir($filepath)) {
  4831. $filepath = api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document/';
  4832. $dir = '/';
  4833. }
  4834. // stripslashes() before calling replace_dangerous_char() because $_POST['title']
  4835. // is already escaped twice when it gets here.
  4836. $title = replace_dangerous_char(stripslashes($_POST['title']));
  4837. $title = disable_dangerous_file($title);
  4838. $filename = $title;
  4839. $content = $_POST['content_lp'];
  4840. $tmp_filename = $filename;
  4841. $i = 0;
  4842. while (file_exists($filepath . $tmp_filename . '.html'))
  4843. $tmp_filename = $filename . '_' . ++ $i;
  4844. $filename = $tmp_filename . '.html';
  4845. $content = stripslashes($content);
  4846. $content = str_replace(api_get_path(WEB_COURSE_PATH), api_get_path(REL_PATH).'courses/', $content);
  4847. // Change the path of mp3 to absolute.
  4848. // The first regexp deals with ../../../ urls.
  4849. $content = preg_replace("|(flashvars=\"file=)(\.+/)+|", "$1" . api_get_path(REL_COURSE_PATH) . $_course['path'] . '/document/', $content);
  4850. // The second regexp deals with audio/ urls.
  4851. $content = preg_replace("|(flashvars=\"file=)([^/]+)/|", "$1" . api_get_path(REL_COURSE_PATH) . $_course['path'] . '/document/$2/', $content);
  4852. // For flv player: To prevent edition problem with firefox, we have to use a strange tip (don't blame me please).
  4853. $content = str_replace('</body>', '<style type="text/css">body{}</style></body>', $content);
  4854. if (!file_exists($filepath . $filename)) {
  4855. if ($fp = @ fopen($filepath . $filename, 'w')) {
  4856. fputs($fp, $content);
  4857. fclose($fp);
  4858. $file_size = filesize($filepath . $filename);
  4859. $save_file_path = $dir.$filename;
  4860. $document_id = add_document($_course, $save_file_path, 'file', $file_size, $tmp_filename);
  4861. if ($document_id) {
  4862. api_item_property_update($_course, TOOL_DOCUMENT, $document_id, 'DocumentAdded', api_get_user_id(), null, null, null, null, api_get_session_id());
  4863. $new_comment = (isset($_POST['comment'])) ? trim($_POST['comment']) : '';
  4864. $new_title = (isset($_POST['title'])) ? trim($_POST['title']) : '';
  4865. if ($new_comment || $new_title) {
  4866. $tbl_doc = Database :: get_course_table(TABLE_DOCUMENT);
  4867. $ct = '';
  4868. if ($new_comment)
  4869. $ct .= ", comment='" . Database::escape_string($new_comment). "'";
  4870. if ($new_title)
  4871. $ct .= ", title='" . Database :: escape_string(htmlspecialchars($new_title, ENT_QUOTES, $charset))."' ";
  4872. $sql_update = "UPDATE " . $tbl_doc ." SET " . substr($ct, 1)." WHERE c_id = ".$course_id." AND id = " . $document_id;
  4873. Database::query($sql_update);
  4874. }
  4875. }
  4876. return $document_id;
  4877. }
  4878. }
  4879. }
  4880. /**
  4881. * Edit a document based on $_POST and $_GET parameters 'dir' and 'path'
  4882. * @param array $_course array
  4883. * @return void
  4884. */
  4885. public function edit_document($_course) {
  4886. $course_id = api_get_course_int_id();
  4887. global $_configuration;
  4888. $dir = isset ($_GET['dir']) ? $_GET['dir'] : $_POST['dir']; // Please, do not modify this dirname formatting.
  4889. if (strstr($dir, '..'))
  4890. $dir = '/';
  4891. if ($dir[0] == '.')
  4892. $dir = substr($dir, 1);
  4893. if ($dir[0] != '/')
  4894. $dir = '/' . $dir;
  4895. if ($dir[strlen($dir) - 1] != '/')
  4896. $dir .= '/';
  4897. $filepath = api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document' . $dir;
  4898. if (!is_dir($filepath)) {
  4899. $filepath = api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document/';
  4900. $dir = '/';
  4901. }
  4902. $table_doc = Database :: get_course_table(TABLE_DOCUMENT);
  4903. if (isset($_POST['path']) && !empty($_POST['path'])) {
  4904. $document_id = intval($_POST['path']);
  4905. $sql = "SELECT path FROM " . $table_doc . " WHERE c_id = $course_id AND id = " . $document_id;
  4906. $res = Database::query($sql);
  4907. $row = Database :: fetch_array($res);
  4908. $content = stripslashes($_POST['content_lp']);
  4909. $file = $filepath . $row['path'];
  4910. if ($fp = @ fopen($file, 'w')) {
  4911. $content = text_filter($content);
  4912. $content = str_replace(api_get_path(WEB_COURSE_PATH), $_configuration['url_append'] . '/courses/', $content);
  4913. // Change the path of mp3 to absolute.
  4914. // The first regexp deals with ../../../ urls.
  4915. $content = preg_replace("|(flashvars=\"file=)(\.+/)+|", "$1" . api_get_path(REL_COURSE_PATH) . $_course['path'] . '/document/', $content);
  4916. // The second regexp deals with audio/ urls.
  4917. $content = preg_replace("|(flashvars=\"file=)([^/]+)/|", "$1" . api_get_path(REL_COURSE_PATH) . $_course['path'] . '/document/$2/', $content);
  4918. fputs($fp, $content);
  4919. fclose($fp);
  4920. $sql_update = "UPDATE " . $table_doc ." SET title='".Database::escape_string($_POST['title'])."' WHERE c_id = ".$course_id." AND id = " . $document_id;
  4921. Database::query($sql_update);
  4922. }
  4923. }
  4924. }
  4925. /**
  4926. * Displays the selected item, with a panel for manipulating the item
  4927. * @param int $item_id
  4928. * @param string $msg
  4929. * @return string
  4930. */
  4931. public function display_item($item_id, $iframe = true, $msg = '') {
  4932. $course_id = api_get_course_int_id();
  4933. global $_course; // It will disappear.
  4934. $return = '';
  4935. if (is_numeric($item_id)) {
  4936. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  4937. $tbl_doc = Database :: get_course_table(TABLE_DOCUMENT);
  4938. $sql = "SELECT lp.* FROM " . $tbl_lp_item . " as lp
  4939. WHERE c_id = ".$course_id." AND lp.id = " . Database :: escape_string($item_id);
  4940. $result = Database::query($sql);
  4941. while ($row = Database :: fetch_array($result,'ASSOC')) {
  4942. $_SESSION['parent_item_id'] = ($row['item_type'] == 'dokeos_chapter' || $row['item_type'] == 'dokeos_module' || $row['item_type'] == 'dir') ? $item_id : 0;
  4943. // Prevents wrong parent selection for document, see Bug#1251.
  4944. if ($row['item_type'] != 'dokeos_chapter' || $row['item_type'] != 'dokeos_module') {
  4945. $_SESSION['parent_item_id'] = $row['parent_item_id'];
  4946. }
  4947. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4948. $return .= '<div style="padding:10px;">';
  4949. if ($msg != '')
  4950. $return .= $msg;
  4951. $return .= '<h3>'.$row['title'].'</h3>';
  4952. //var_dump($row);
  4953. switch ($row['item_type']) {
  4954. case TOOL_QUIZ:
  4955. if (!empty($row['path'])) {
  4956. require_once api_get_path(SYS_CODE_PATH).'exercice/exercise.class.php';
  4957. $exercise = new Exercise();
  4958. $exercise->read($row['path']);
  4959. $return .= $exercise->description.'<br />';
  4960. }
  4961. break;
  4962. case TOOL_DOCUMENT:
  4963. $tbl_doc = Database :: get_course_table(TABLE_DOCUMENT);
  4964. $sql_doc = "SELECT path FROM " . $tbl_doc . " WHERE c_id = ".$course_id." AND id = " . Database :: escape_string($row['path']);
  4965. $result = Database::query($sql_doc);
  4966. $path_file = Database::result($result, 0, 0);
  4967. $path_parts = pathinfo($path_file);
  4968. // TODO: Correct the following naive comparisons, also, htm extension is missing.
  4969. if (in_array($path_parts['extension'], array (
  4970. 'html',
  4971. 'txt',
  4972. 'png',
  4973. 'jpg',
  4974. 'JPG',
  4975. 'jpeg',
  4976. 'JPEG',
  4977. 'gif',
  4978. 'swf'
  4979. ))) {
  4980. $return .= $this->display_document($row['path'], true, true);
  4981. }
  4982. break;
  4983. }
  4984. $return .= '</div>';
  4985. }
  4986. }
  4987. return $return;
  4988. }
  4989. /**
  4990. * Shows the needed forms for editing a specific item
  4991. * @param int $item_id
  4992. * @return string
  4993. */
  4994. public function display_edit_item($item_id) {
  4995. global $_course; // It will disappear.
  4996. $course_id = api_get_course_int_id();
  4997. $return = '';
  4998. if (is_numeric($item_id)) {
  4999. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  5000. $sql = "SELECT * FROM $tbl_lp_item WHERE c_id = ".$course_id." AND id = " . Database :: escape_string($item_id);
  5001. $res = Database::query($sql);
  5002. $row = Database::fetch_array($res);
  5003. switch ($row['item_type']) {
  5004. case 'dokeos_chapter' :
  5005. case 'dir' :
  5006. case 'asset' :
  5007. case 'sco' :
  5008. if (isset ($_GET['view']) && $_GET['view'] == 'build') {
  5009. $return .= $this->display_manipulate($item_id, $row['item_type']);
  5010. $return .= $this->display_item_form($row['item_type'], get_lang('EditCurrentChapter') . ' :', 'edit', $item_id, $row);
  5011. } else {
  5012. $return .= $this->display_item_small_form($row['item_type'], get_lang('EditCurrentChapter') . ' :', $row);
  5013. }
  5014. break;
  5015. case TOOL_DOCUMENT :
  5016. $tbl_doc = Database :: get_course_table(TABLE_DOCUMENT);
  5017. $sql_step = " SELECT lp.*, doc.path as dir
  5018. FROM " . $tbl_lp_item . " as lp
  5019. LEFT JOIN " . $tbl_doc . " as doc ON doc.id = lp.path
  5020. WHERE lp.c_id = $course_id AND
  5021. doc.c_id = $course_id AND
  5022. lp.id = " . Database :: escape_string($item_id);
  5023. $res_step = Database::query($sql_step);
  5024. $row_step = Database :: fetch_array($res_step);
  5025. $return .= $this->display_manipulate($item_id, $row['item_type']);
  5026. $return .= $this->display_document_form('edit', $item_id, $row_step);
  5027. break;
  5028. case TOOL_LINK :
  5029. $link_id = (string) $row['path'];
  5030. if (ctype_digit($link_id)) {
  5031. $tbl_link = Database :: get_course_table(TABLE_LINK);
  5032. $sql_select = 'SELECT url FROM ' . $tbl_link . ' WHERE c_id = '.$course_id.' AND id = ' . Database :: escape_string($link_id);
  5033. $res_link = Database::query($sql_select);
  5034. $row_link = Database :: fetch_array($res_link);
  5035. if (is_array($row_link)) {
  5036. $row['url'] = $row_link['url'];
  5037. }
  5038. }
  5039. $return .= $this->display_manipulate($item_id, $row['item_type']);
  5040. $return .= $this->display_link_form('edit', $item_id, $row);
  5041. break;
  5042. case 'dokeos_module' :
  5043. if (isset ($_GET['view']) && $_GET['view'] == 'build') {
  5044. $return .= $this->display_manipulate($item_id, $row['item_type']);
  5045. $return .= $this->display_item_form($row['item_type'], get_lang('EditCurrentModule') . ' :', 'edit', $item_id, $row);
  5046. } else {
  5047. $return .= $this->display_item_small_form($row['item_type'], get_lang('EditCurrentModule') . ' :', $row);
  5048. }
  5049. break;
  5050. case TOOL_QUIZ :
  5051. $return .= $this->display_manipulate($item_id, $row['item_type']);
  5052. $return .= $this->display_quiz_form('edit', $item_id, $row);
  5053. break;
  5054. case TOOL_HOTPOTATOES :
  5055. $return .= $this->display_manipulate($item_id, $row['item_type']);
  5056. $return .= $this->display_hotpotatoes_form('edit', $item_id, $row);
  5057. break;
  5058. case TOOL_STUDENTPUBLICATION :
  5059. $return .= $this->display_manipulate($item_id, $row['item_type']);
  5060. $return .= $this->display_student_publication_form('edit', $item_id, $row);
  5061. break;
  5062. case TOOL_FORUM :
  5063. $return .= $this->display_manipulate($item_id, $row['item_type']);
  5064. $return .= $this->display_forum_form('edit', $item_id, $row);
  5065. break;
  5066. case TOOL_THREAD :
  5067. $return .= $this->display_manipulate($item_id, $row['item_type']);
  5068. $return .= $this->display_thread_form('edit', $item_id, $row);
  5069. break;
  5070. }
  5071. }
  5072. return $return;
  5073. }
  5074. /**
  5075. * Function that displays a list with al the resources that could be added to the learning path
  5076. * @return string
  5077. */
  5078. public function display_resources() {
  5079. global $_course; // TODO: Don't use globals.
  5080. $course_code = api_get_course_id();
  5081. //Get all the docs
  5082. $documents = $this->get_documents();
  5083. //Get all the exercises
  5084. $exercises = $this->get_exercises();
  5085. // Get all the links
  5086. $links = $this->get_links();
  5087. //Get al the student publications
  5088. $works = $this->get_student_publications();
  5089. //Get al the forums
  5090. $forums = $this->get_forums(null, $course_code);
  5091. $headers = array( Display::return_icon('folder_document.png', get_lang('Documents'), array(), 64),
  5092. Display::return_icon('quiz.png', get_lang('Quiz'), array(), 64),
  5093. Display::return_icon('links.png', get_lang('Links'), array(), 64),
  5094. Display::return_icon('works.png', get_lang('Works'), array(), 64),
  5095. Display::return_icon('forum.png', get_lang('Forums'), array(), 64),
  5096. Display::return_icon('add_learnpath_section.png', get_lang('NewChapter'), array(), 64)
  5097. );
  5098. $chapter = $_SESSION['oLP']->display_item_form('chapter', get_lang('EnterDataNewChapter'), 'add_item');
  5099. echo Display::tabs($headers, array($documents, $exercises, $links, $works, $forums, $chapter), 'resource_tab');
  5100. return true;
  5101. }
  5102. /**
  5103. * Returns the extension of a document
  5104. * @param string filename
  5105. * @return string Extension (part after the last dot)
  5106. */
  5107. public function get_extension($filename) {
  5108. $explode = explode('.', $filename);
  5109. return $explode[count($explode) - 1];
  5110. }
  5111. /**
  5112. * Displays a document by id
  5113. *
  5114. * @param unknown_type $id
  5115. * @return unknown
  5116. */
  5117. public function display_document($id, $show_title = false, $iframe = true, $edit_link = false) {
  5118. global $_course; // It is temporary.
  5119. $course_id = api_get_course_int_id();
  5120. $return = '';
  5121. $tbl_doc = Database :: get_course_table(TABLE_DOCUMENT);
  5122. $sql_doc = "SELECT * FROM " . $tbl_doc . "
  5123. WHERE c_id = ".$course_id." AND id = " . $id;
  5124. $res_doc = Database::query($sql_doc);
  5125. $row_doc = Database :: fetch_array($res_doc);
  5126. //if ($show_title)
  5127. //$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>';
  5128. // TODO: Add a path filter.
  5129. if ($iframe) {
  5130. $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>';
  5131. } else {
  5132. $return .= file_get_contents(api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document' . $row_doc['path']);
  5133. }
  5134. return $return;
  5135. }
  5136. /**
  5137. * Return HTML form to add/edit a quiz
  5138. * @param string Action (add/edit)
  5139. * @param integer Item ID if already exists
  5140. * @param mixed Extra information (quiz ID if integer)
  5141. * @return string HTML form
  5142. */
  5143. public function display_quiz_form($action = 'add', $id = 0, $extra_info = '') {
  5144. $course_id = api_get_course_int_id();
  5145. global $charset;
  5146. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  5147. $tbl_quiz = Database :: get_course_table(TABLE_QUIZ_TEST);
  5148. if ($id != 0 && is_array($extra_info)) {
  5149. $item_title = $extra_info['title'];
  5150. $item_description = $extra_info['description'];
  5151. } elseif (is_numeric($extra_info)) {
  5152. $sql_quiz = "SELECT title, description FROM " . $tbl_quiz . " WHERE c_id = ".$course_id." AND id = " . $extra_info;
  5153. $result = Database::query($sql_quiz);
  5154. $row = Database :: fetch_array($result);
  5155. $item_title = $row['title'];
  5156. $item_description = $row['description'];
  5157. } else {
  5158. $item_title = '';
  5159. $item_description = '';
  5160. }
  5161. $item_title = Security::remove_XSS($item_title);
  5162. $item_description = Security::remove_XSS($item_description);
  5163. $legend = '<legend>';
  5164. if ($id != 0 && is_array($extra_info))
  5165. $parent = $extra_info['parent_item_id'];
  5166. else
  5167. $parent = 0;
  5168. $sql = "SELECT * FROM " . $tbl_lp_item . " WHERE c_id = ".$course_id." AND lp_id = " . $this->lp_id;
  5169. $result = Database::query($sql);
  5170. $arrLP = array ();
  5171. while ($row = Database :: fetch_array($result)) {
  5172. $arrLP[] = array (
  5173. 'id' => $row['id'],
  5174. 'item_type' => $row['item_type'],
  5175. 'title' => $row['title'],
  5176. 'path' => $row['path'],
  5177. 'description' => $row['description'],
  5178. 'parent_item_id' => $row['parent_item_id'],
  5179. 'previous_item_id' => $row['previous_item_id'],
  5180. 'next_item_id' => $row['next_item_id'],
  5181. 'display_order' => $row['display_order'],
  5182. 'max_score' => $row['max_score'],
  5183. 'min_score' => $row['min_score'],
  5184. 'mastery_score' => $row['mastery_score'],
  5185. 'prerequisite' => $row['prerequisite'],
  5186. 'max_time_allowed' => $row['max_time_allowed']
  5187. );
  5188. }
  5189. $this->tree_array($arrLP);
  5190. $arrLP = $this->arrMenu;
  5191. unset ($this->arrMenu);
  5192. if ($action == 'add')
  5193. $legend .= get_lang('CreateTheExercise') . '&nbsp;:';
  5194. elseif ($action == 'move') $legend .= get_lang('MoveTheCurrentExercise') . '&nbsp;:';
  5195. else
  5196. $legend .= get_lang('EditCurrentExecice') . '&nbsp;:';
  5197. if (isset ($_GET['edit']) && $_GET['edit'] == 'true') {
  5198. $legend .= Display :: return_warning_message(get_lang('Warning') . ' ! ' . get_lang('WarningEditingDocument'));
  5199. }
  5200. $legend .= '</legend>';
  5201. $return .= '<div class="sectioncomment">';
  5202. $return .= '<form method="POST">';
  5203. $return .= $legend;
  5204. $return .= '<table class="lp_form">';
  5205. if ($action != 'move') {
  5206. $return .= '<tr>';
  5207. $return .= '<td class="label"><label for="idTitle">' . get_lang('Title') . '</label></td>';
  5208. $return .= '<td class="input"><input id="idTitle" name="title" size="44" type="text" class="learnpath_item_form" value="' . $item_title . '" /></td>';
  5209. $return .= '</tr>';
  5210. }
  5211. $return .= '<tr>';
  5212. $return .= '<td class="label"><label for="idParent">' . get_lang('Parent') . '</label></td>';
  5213. $return .= '<td class="input">';
  5214. $return .= '<select id="idParent" style="width:100%;" name="parent" onChange="javascript: load_cbo(this.value);" class="learnpath_item_form" size="1">';
  5215. $return .= '<option class="top" value="0">' . $this->name . '</option>';
  5216. $arrHide = array (
  5217. $id
  5218. );
  5219. //$parent_item_id = $_SESSION['parent_item_id'];
  5220. for ($i = 0; $i < count($arrLP); $i++) {
  5221. if ($action != 'add') {
  5222. 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)) {
  5223. $return .= '<option ' . (($parent == $arrLP[$i]['id']) ? 'selected="selected" ' : '') . 'style="padding-left:' . ($arrLP[$i]['depth'] * 10) . 'px;" value="' . $arrLP[$i]['id'] . '">' . $arrLP[$i]['title'] . '</option>';
  5224. } else {
  5225. $arrHide[] = $arrLP[$i]['id'];
  5226. }
  5227. } else {
  5228. if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
  5229. $return .= '<option ' . (($parent == $arrLP[$i]['id']) ? 'selected="selected" ' : '') . 'style="padding-left:' . ($arrLP[$i]['depth'] * 10) . 'px;" value="' . $arrLP[$i]['id'] . '">' . $arrLP[$i]['title'] . '</option>';
  5230. }
  5231. }
  5232. if (is_array($arrLP)) {
  5233. reset($arrLP);
  5234. }
  5235. $return .= '</select>';
  5236. $return .= '</td>';
  5237. $return .= '</tr>';
  5238. $return .= '<tr>';
  5239. $return .= '<td class="label"><label for="previous">' . get_lang('Position') . '</label></td>';
  5240. $return .= '<td class="input">';
  5241. $return .= '<select class="learnpath_item_form" style="width:100%;" id="previous" name="previous" size="1">';
  5242. $return .= '<option class="top" value="0">' . get_lang('FirstPosition') . '</option>';
  5243. for ($i = 0; $i < count($arrLP); $i++) {
  5244. if ($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) {
  5245. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5246. $selected = 'selected="selected" ';
  5247. elseif ($action == 'add') $selected = 'selected="selected" ';
  5248. else
  5249. $selected = '';
  5250. $return .= '<option ' . $selected . 'value="' . $arrLP[$i]['id'] . '">' . get_lang('After') . ' "' . $arrLP[$i]['title'] . '"</option>';
  5251. }
  5252. }
  5253. $return .= '</select>';
  5254. $return .= '</td>';
  5255. $return .= '</tr>';
  5256. if ($action != 'move') {
  5257. $id_prerequisite = 0;
  5258. if (is_array($arrLP)) {
  5259. foreach ($arrLP as $key => $value) {
  5260. if ($value['id'] == $id) {
  5261. $id_prerequisite = $value['prerequisite'];
  5262. break;
  5263. }
  5264. }
  5265. }
  5266. $arrHide = array ();
  5267. for ($i = 0; $i < count($arrLP); $i++) {
  5268. if ($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter') {
  5269. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5270. $s_selected_position = $arrLP[$i]['id'];
  5271. elseif ($action == 'add') $s_selected_position = 0;
  5272. $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
  5273. }
  5274. }
  5275. /*// Commented the prerequisites, only visible in edit (exercise).
  5276. $return .= '<tr>';
  5277. $return .= '<td class="label"><label for="idPrerequisites">'.get_lang('Prerequisites').'</label></td>';
  5278. $return .= '<td class="input"><select name="prerequisites" id="prerequisites" class="learnpath_item_form"><option value="0">'.get_lang('NoPrerequisites').'</option>';
  5279. foreach($arrHide as $key => $value){
  5280. if($key==$s_selected_position && $action == 'add'){
  5281. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  5282. }
  5283. elseif($key==$id_prerequisite && $action == 'edit'){
  5284. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  5285. }
  5286. else{
  5287. $return .= '<option value="'.$key.'">'.$value['value'].'</option>';
  5288. }
  5289. }
  5290. $return .= "</select></td>";
  5291. */
  5292. $return .= '</tr>';
  5293. /*$return .= '<tr>';
  5294. $return .= '<td class="label"><label for="maxTimeAllowed">' . get_lang('MaxTimeAllowed') . '</label></td>';
  5295. $return .= '<td class="input"><input name="maxTimeAllowed" style="width:98%;" id="maxTimeAllowed" value="' . $extra_info['max_time_allowed'] . '" /></td>';
  5296. // Remove temporarily the test description.
  5297. //$return .= '<td class="label"><label for="idDescription">'.get_lang('Description').' :</label></td>';
  5298. //$return .= '<td class="input"><textarea id="idDescription" name="description" rows="4">' . $item_description . '</textarea></td>';
  5299. $return .= '</tr>'; */
  5300. }
  5301. $return .= '<tr>';
  5302. if ($action == 'add') {
  5303. $return .= '<td>&nbsp;</td><td><button class="save" name="submit_button" type="submit">' . get_lang('AddExercise') . '</button></td>';
  5304. } else {
  5305. $return .= '<td>&nbsp;</td><td><button class="save" name="submit_button" type="submit">' . get_lang('EditCurrentExecice') . '</button></td>';
  5306. }
  5307. $return .= '</tr>';
  5308. $return .= '</table>';
  5309. if ($action == 'move') {
  5310. $return .= '<input name="title" type="hidden" value="' . $item_title . '" />';
  5311. $return .= '<input name="description" type="hidden" value="' . $item_description . '" />';
  5312. }
  5313. if (is_numeric($extra_info)) {
  5314. $return .= '<input name="path" type="hidden" value="' . $extra_info . '" />';
  5315. }
  5316. elseif (is_array($extra_info)) {
  5317. $return .= '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />';
  5318. }
  5319. $return .= '<input name="type" type="hidden" value="' . TOOL_QUIZ . '" />';
  5320. $return .= '<input name="post_time" type="hidden" value="' . time() . '" />';
  5321. $return .= '</form>';
  5322. $return .= '</div>';
  5323. return $return;
  5324. }
  5325. /**
  5326. * Addition of Hotpotatoes tests
  5327. * @param string Action
  5328. * @param integer Internal ID of the item
  5329. * @param mixed Extra information - can be an array with title and description indexes
  5330. * @return string HTML structure to display the hotpotatoes addition formular
  5331. */
  5332. public function display_hotpotatoes_form($action = 'add', $id = 0, $extra_info = '') {
  5333. $course_id = api_get_course_int_id();
  5334. global $charset;
  5335. $uploadPath = DIR_HOTPOTATOES; //defined in main_api
  5336. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  5337. if ($id != 0 && is_array($extra_info)) {
  5338. $item_title = stripslashes($extra_info['title']);
  5339. $item_description = stripslashes($extra_info['description']);
  5340. } elseif (is_numeric($extra_info)) {
  5341. $TBL_DOCUMENT = Database :: get_course_table(TABLE_DOCUMENT);
  5342. $sql_hot = "SELECT * FROM " . $TBL_DOCUMENT . "
  5343. WHERE c_id = ".$course_id." AND
  5344. path LIKE '" . $uploadPath . "/%/%htm%' AND
  5345. id = " . (int) $extra_info . "
  5346. ORDER BY id ASC";
  5347. $res_hot = Database::query($sql_hot);
  5348. $row = Database::fetch_array($res_hot);
  5349. $item_title = $row['title'];
  5350. $item_description = $row['description'];
  5351. if (!empty ($row['comment'])) {
  5352. $item_title = $row['comment'];
  5353. }
  5354. } else {
  5355. $item_title = '';
  5356. $item_description = '';
  5357. }
  5358. if ($id != 0 && is_array($extra_info))
  5359. $parent = $extra_info['parent_item_id'];
  5360. else
  5361. $parent = 0;
  5362. $sql = "SELECT * FROM $tbl_lp_item WHERE c_id = ".$course_id." AND lp_id = " . $this->lp_id;
  5363. $result = Database::query($sql);
  5364. $arrLP = array ();
  5365. while ($row = Database :: fetch_array($result)) {
  5366. $arrLP[] = array (
  5367. 'id' => $row['id'],
  5368. 'item_type' => $row['item_type'],
  5369. 'title' => $row['title'],
  5370. 'path' => $row['path'],
  5371. 'description' => $row['description'],
  5372. 'parent_item_id' => $row['parent_item_id'],
  5373. 'previous_item_id' => $row['previous_item_id'],
  5374. 'next_item_id' => $row['next_item_id'],
  5375. 'display_order' => $row['display_order'],
  5376. 'max_score' => $row['max_score'],
  5377. 'min_score' => $row['min_score'],
  5378. 'mastery_score' => $row['mastery_score'],
  5379. 'prerequisite' => $row['prerequisite'],
  5380. 'max_time_allowed' => $row['max_time_allowed']
  5381. );
  5382. }
  5383. $legend = '<legend>';
  5384. if ($action == 'add')
  5385. $legend .= get_lang('CreateTheExercise');
  5386. elseif ($action == 'move') $legend .= get_lang('MoveTheCurrentExercise');
  5387. else
  5388. $legend .= get_lang('EditCurrentExecice');
  5389. if (isset ($_GET['edit']) && $_GET['edit'] == 'true') {
  5390. $legend .= Display :: return_warning_message(get_lang('Warning') . ' ! ' . get_lang('WarningEditingDocument'));
  5391. }
  5392. $legend .= '</legend>';
  5393. $return .= '<form method="POST">';
  5394. $return .= $legend;
  5395. $return .= '<table cellpadding="0" cellspacing="0" class="lp_form">';
  5396. $return .= '<tr>';
  5397. $return .= '<td class="label"><label for="idParent">' . get_lang('Parent') . ' :</label></td>';
  5398. $return .= '<td class="input">';
  5399. $return .= '<select id="idParent" name="parent" onChange="javascript: load_cbo(this.value);" size="1">';
  5400. $return .= '<option class="top" value="0">' . $this->name . '</option>';
  5401. $arrHide = array (
  5402. $id
  5403. );
  5404. if (count($arrLP) > 0) {
  5405. for ($i = 0; $i < count($arrLP); $i++) {
  5406. if ($action != 'add') {
  5407. 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)) {
  5408. $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>';
  5409. } else {
  5410. $arrHide[] = $arrLP[$i]['id'];
  5411. }
  5412. } else {
  5413. if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
  5414. $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>';
  5415. }
  5416. }
  5417. reset($arrLP);
  5418. }
  5419. $return .= "\t\t\t\t" . '</select>';
  5420. $return .= '</td>';
  5421. $return .= '</tr>';
  5422. $return .= '<tr>';
  5423. $return .= '<td class="label"><label for="previous">' . get_lang('Position') . ' :</label></td>';
  5424. $return .= '<td class="input">';
  5425. $return .= "\t\t\t\t" . '<select id="previous" name="previous" size="1">';
  5426. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . get_lang('FirstPosition') . '</option>';
  5427. for ($i = 0; $i < count($arrLP); $i++) {
  5428. if ($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) {
  5429. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5430. $selected = 'selected="selected" ';
  5431. elseif ($action == 'add') $selected = 'selected="selected" ';
  5432. else
  5433. $selected = '';
  5434. $return .= "\t\t\t\t\t" . '<option ' . $selected . 'value="' . $arrLP[$i]['id'] . '">' . get_lang('After') . ' "' . $arrLP[$i]['title'] . '"</option>';
  5435. }
  5436. }
  5437. $return .= "\t\t\t\t" . '</select>';
  5438. $return .= '</td>';
  5439. $return .= '</tr>';
  5440. if ($action != 'move') {
  5441. $return .= '<tr>';
  5442. $return .= '<td class="label"><label for="idTitle">' . get_lang('Title') . ' :</label></td>';
  5443. $return .= '<td class="input"><input id="idTitle" name="title" type="text" value="' . $item_title . '" /></td>';
  5444. $return .= '</tr>';
  5445. $id_prerequisite = 0;
  5446. if (is_array($arrLP) && count($arrLP) > 0) {
  5447. foreach ($arrLP as $key => $value) {
  5448. if ($value['id'] == $id) {
  5449. $id_prerequisite = $value['prerequisite'];
  5450. break;
  5451. }
  5452. }
  5453. $arrHide = array ();
  5454. for ($i = 0; $i < count($arrLP); $i++) {
  5455. if ($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter') {
  5456. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5457. $s_selected_position = $arrLP[$i]['id'];
  5458. elseif ($action == 'add') $s_selected_position = 0;
  5459. $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
  5460. }
  5461. }
  5462. }
  5463. //$return .= '<tr>';
  5464. //$return .= '<td class="label"><label for="idPrerequisites">'.get_lang('Prerequisites').' :</label></td>';
  5465. //$return .= '<td class="input"><select name="prerequisites" id="prerequisites"><option value="0">'.get_lang('NoPrerequisites').'</option>';
  5466. /*
  5467. foreach ($arrHide as $key => $value) {
  5468. if ($key == $s_selected_position && $action == 'add') {
  5469. $return .= '<option value="' . $key . '" selected="selected">' . $value['value'] . '</option>';
  5470. }
  5471. elseif ($key == $id_prerequisite && $action == 'edit') {
  5472. $return .= '<option value="' . $key . '" selected="selected">' . $value['value'] . '</option>';
  5473. } else {
  5474. $return .= '<option value="' . $key . '">' . $value['value'] . '</option>';
  5475. }
  5476. }
  5477. */
  5478. //$return .= "</select></td>";
  5479. //$return .= '</tr>';
  5480. //$return .= '<tr>';
  5481. //$return .= '</tr>';
  5482. }
  5483. $return .= '<tr>';
  5484. $return .= '<td>&nbsp; </td><td><button class="save" name="submit_button" action="edit" type="submit">' . get_lang('SaveHotpotatoes') . '</button></td>';
  5485. $return .= '</tr>';
  5486. $return .= '</table>';
  5487. if ($action == 'move') {
  5488. $return .= '<input name="title" type="hidden" value="' . $item_title . '" />';
  5489. $return .= '<input name="description" type="hidden" value="' . $item_description . '" />';
  5490. }
  5491. if (is_numeric($extra_info)) {
  5492. $return .= '<input name="path" type="hidden" value="' . $extra_info . '" />';
  5493. }
  5494. elseif (is_array($extra_info)) {
  5495. $return .= '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />';
  5496. }
  5497. $return .= '<input name="type" type="hidden" value="' . TOOL_HOTPOTATOES . '" />';
  5498. $return .= '<input name="post_time" type="hidden" value="' . time() . '" />';
  5499. $return .= '</form>';
  5500. return $return;
  5501. }
  5502. /**
  5503. * Return the form to display the forum edit/add option
  5504. * @param string Action (add/edit)
  5505. * @param integer ID of the lp_item if already exists
  5506. * @param mixed Forum ID or title
  5507. * @return string HTML form
  5508. */
  5509. public function display_forum_form($action = 'add', $id = 0, $extra_info = '') {
  5510. $course_id = api_get_course_int_id();
  5511. global $charset;
  5512. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  5513. $tbl_forum = Database :: get_course_table(TABLE_FORUM);
  5514. if ($id != 0 && is_array($extra_info)) {
  5515. $item_title = stripslashes($extra_info['title']);
  5516. }
  5517. elseif (is_numeric($extra_info)) {
  5518. $sql_forum = "SELECT forum_title as title, forum_comment as comment
  5519. FROM " . $tbl_forum . "
  5520. WHERE c_id = ".$course_id." AND forum_id = " . $extra_info;
  5521. $result = Database::query($sql_forum);
  5522. $row = Database :: fetch_array($result);
  5523. $item_title = $row['title'];
  5524. $item_description = $row['comment'];
  5525. } else {
  5526. $item_title = '';
  5527. $item_description = '';
  5528. }
  5529. $legend = '<legend>';
  5530. if ($id != 0 && is_array($extra_info))
  5531. $parent = $extra_info['parent_item_id'];
  5532. else
  5533. $parent = 0;
  5534. $sql = "SELECT * FROM " . $tbl_lp_item . "
  5535. WHERE c_id = ".$course_id." AND
  5536. lp_id = " . $this->lp_id;
  5537. $result = Database::query($sql);
  5538. $arrLP = array ();
  5539. while ($row = Database :: fetch_array($result)) {
  5540. $arrLP[] = array (
  5541. 'id' => $row['id'],
  5542. 'item_type' => $row['item_type'],
  5543. 'title' => $row['title'],
  5544. 'path' => $row['path'],
  5545. 'description' => $row['description'],
  5546. 'parent_item_id' => $row['parent_item_id'],
  5547. 'previous_item_id' => $row['previous_item_id'],
  5548. 'next_item_id' => $row['next_item_id'],
  5549. 'display_order' => $row['display_order'],
  5550. 'max_score' => $row['max_score'],
  5551. 'min_score' => $row['min_score'],
  5552. 'mastery_score' => $row['mastery_score'],
  5553. 'prerequisite' => $row['prerequisite']
  5554. );
  5555. }
  5556. $this->tree_array($arrLP);
  5557. $arrLP = $this->arrMenu;
  5558. unset ($this->arrMenu);
  5559. if ($action == 'add')
  5560. $legend .= get_lang('CreateTheForum') . '&nbsp;:';
  5561. elseif ($action == 'move') $legend .= get_lang('MoveTheCurrentForum') . '&nbsp;:';
  5562. else
  5563. $legend .= get_lang('EditCurrentForum') . '&nbsp;:';
  5564. $legend .= '</legend>';
  5565. $return .= '<div class="sectioncomment">';
  5566. $return .= '<form method="POST">';
  5567. $return .= $legend;
  5568. $return .= '<table class="lp_form">';
  5569. if ($action != 'move') {
  5570. $return .= '<tr>';
  5571. $return .= '<td class="label"><label for="idTitle">' . get_lang('Title') . '</label></td>';
  5572. $return .= '<td class="input"><input id="idTitle" size="44" name="title" type="text" value="' . $item_title . '" class="learnpath_item_form" /></td>';
  5573. $return .= '</tr>';
  5574. }
  5575. $return .= '<tr>';
  5576. $return .= '<td class="label"><label for="idParent">' . get_lang('Parent') . '</label></td>';
  5577. $return .= '<td class="input">';
  5578. $return .= '<select id="idParent" style="width:100%;" name="parent" onChange="javascript: load_cbo(this.value);" class="learnpath_item_form" size="1">';
  5579. $return .= '<option class="top" value="0">' . $this->name . '</option>';
  5580. $arrHide = array (
  5581. $id
  5582. );
  5583. //$parent_item_id = $_SESSION['parent_item_id'];
  5584. for ($i = 0; $i < count($arrLP); $i++) {
  5585. if ($action != 'add') {
  5586. 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)) {
  5587. $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>';
  5588. } else {
  5589. $arrHide[] = $arrLP[$i]['id'];
  5590. }
  5591. } else {
  5592. if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
  5593. $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>';
  5594. }
  5595. }
  5596. if (is_array($arrLP)) {
  5597. reset($arrLP);
  5598. }
  5599. $return .= "\t\t\t\t" . '</select>';
  5600. $return .= '</td>';
  5601. $return .= '</tr>';
  5602. $return .= '<tr>';
  5603. $return .= '<td class="label"><label for="previous">' . get_lang('Position') . '</label></td>';
  5604. $return .= '<td class="input">';
  5605. $return .= "\t\t\t\t" . '<select id="previous" name="previous" style="width:100%;" size="1" class="learnpath_item_form">';
  5606. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . get_lang('FirstPosition') . '</option>';
  5607. for ($i = 0; $i < count($arrLP); $i++) {
  5608. if ($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) {
  5609. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5610. $selected = 'selected="selected" ';
  5611. elseif ($action == 'add') $selected = 'selected="selected" ';
  5612. else
  5613. $selected = '';
  5614. $return .= "\t\t\t\t\t" . '<option ' . $selected . 'value="' . $arrLP[$i]['id'] . '">' . get_lang('After') . ' "' . $arrLP[$i]['title'] . '"</option>';
  5615. }
  5616. }
  5617. $return .= "\t\t\t\t" . '</select>';
  5618. $return .= '</td>';
  5619. $return .= '</tr>';
  5620. if ($action != 'move') {
  5621. $return .= '<tr>';
  5622. $return .= '</tr>';
  5623. $id_prerequisite = 0;
  5624. if (is_array($arrLP)) {
  5625. foreach ($arrLP as $key => $value) {
  5626. if ($value['id'] == $id) {
  5627. $id_prerequisite = $value['prerequisite'];
  5628. break;
  5629. }
  5630. }
  5631. }
  5632. $arrHide = array ();
  5633. for ($i = 0; $i < count($arrLP); $i++) {
  5634. if ($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter') {
  5635. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5636. $s_selected_position = $arrLP[$i]['id'];
  5637. elseif ($action == 'add') $s_selected_position = 0;
  5638. $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
  5639. }
  5640. }
  5641. $return .= '</tr>';
  5642. }
  5643. $return .= '<tr>';
  5644. if ($action == 'add') {
  5645. $return .= '<td>&nbsp;</td><td><button class="save" name="submit_button" type="submit"> ' . get_lang('AddForumToCourse') . ' </button></td>';
  5646. } else {
  5647. $return .= '<td>&nbsp;</td><td><button class="save" name="submit_button" type="submit"> ' . get_lang('EditCurrentForum') . ' </button></td>';
  5648. }
  5649. $return .= '</tr>';
  5650. $return .= '</table>';
  5651. if ($action == 'move') {
  5652. $return .= '<input name="title" type="hidden" value="' . $item_title . '" />';
  5653. $return .= '<input name="description" type="hidden" value="' . $item_description . '" />';
  5654. }
  5655. if (is_numeric($extra_info)) {
  5656. $return .= '<input name="path" type="hidden" value="' . $extra_info . '" />';
  5657. }
  5658. elseif (is_array($extra_info)) {
  5659. $return .= '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />';
  5660. }
  5661. $return .= '<input name="type" type="hidden" value="' . TOOL_FORUM . '" />';
  5662. $return .= '<input name="post_time" type="hidden" value="' . time() . '" />';
  5663. $return .= '</form>';
  5664. $return .= '</div>';
  5665. return $return;
  5666. }
  5667. /**
  5668. * Return HTML form to add/edit forum threads
  5669. * @param string Action (add/edit)
  5670. * @param integer Item ID if already exists in learning path
  5671. * @param mixed Extra information (thread ID if integer)
  5672. * @return string HTML form
  5673. */
  5674. public function display_thread_form($action = 'add', $id = 0, $extra_info = '') {
  5675. $course_id = api_get_course_int_id();
  5676. global $charset;
  5677. echo '<style>
  5678. div.row div.label {
  5679. width:110px;
  5680. }
  5681. div.row div.formw {
  5682. width: 82%;
  5683. }
  5684. </style>';
  5685. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  5686. $tbl_forum = Database :: get_course_table(TABLE_FORUM_THREAD);
  5687. if ($id != 0 && is_array($extra_info)) {
  5688. $item_title = stripslashes($extra_info['title']);
  5689. }
  5690. elseif (is_numeric($extra_info)) {
  5691. $sql_forum = "SELECT thread_title as title
  5692. FROM " . $tbl_forum . "
  5693. WHERE c_id = ".$course_id." AND thread_id = " . $extra_info;
  5694. $result = Database::query($sql_forum);
  5695. $row = Database :: fetch_array($result);
  5696. $item_title = $row['title'];
  5697. $item_description = '';
  5698. } else {
  5699. $item_title = '';
  5700. $item_description = '';
  5701. }
  5702. $return = '<div style="margin:3px 12px;">';
  5703. if ($id != 0 && is_array($extra_info))
  5704. $parent = $extra_info['parent_item_id'];
  5705. else
  5706. $parent = 0;
  5707. $sql = "SELECT * FROM " . $tbl_lp_item . "
  5708. WHERE c_id = ".$course_id." AND lp_id = " . $this->lp_id;
  5709. $result = Database::query($sql);
  5710. $arrLP = array ();
  5711. while ($row = Database :: fetch_array($result)) {
  5712. $arrLP[] = array (
  5713. 'id' => $row['id'],
  5714. 'item_type' => $row['item_type'],
  5715. 'title' => $row['title'],
  5716. 'path' => $row['path'],
  5717. 'description' => $row['description'],
  5718. 'parent_item_id' => $row['parent_item_id'],
  5719. 'previous_item_id' => $row['previous_item_id'],
  5720. 'next_item_id' => $row['next_item_id'],
  5721. 'display_order' => $row['display_order'],
  5722. 'max_score' => $row['max_score'],
  5723. 'min_score' => $row['min_score'],
  5724. 'mastery_score' => $row['mastery_score'],
  5725. 'prerequisite' => $row['prerequisite']
  5726. );
  5727. }
  5728. $this->tree_array($arrLP);
  5729. $arrLP = $this->arrMenu;
  5730. unset ($this->arrMenu);
  5731. if ($action == 'add')
  5732. $return .= '<p class="lp_title">' . get_lang('CreateTheForum') . '&nbsp;:</p>';
  5733. elseif ($action == 'move') $return .= '<p class="lp_title">' . get_lang('MoveTheCurrentForum') . '&nbsp;:</p>';
  5734. else
  5735. $return .= '<p class="lp_title">' . get_lang('EditCurrentForum') . '&nbsp;:</p>';
  5736. $return .= '<form method="POST">';
  5737. $return .= '<table cellpadding="0" cellspacing="0" class="lp_form">';
  5738. $return .= '<tr>';
  5739. $return .= '<td class="label"><label for="idParent">' . get_lang('Parent') . '&nbsp;:</label></td>';
  5740. $return .= '<td class="input">';
  5741. $return .= "\t\t\t\t" . '<select id="idParent" name="parent" onChange="javascript: load_cbo(this.value);" size="1">';
  5742. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
  5743. $arrHide = array (
  5744. $id
  5745. );
  5746. for ($i = 0; $i < count($arrLP); $i++) {
  5747. if ($action != 'add') {
  5748. 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)) {
  5749. $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>';
  5750. } else {
  5751. $arrHide[] = $arrLP[$i]['id'];
  5752. }
  5753. } else {
  5754. if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
  5755. $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>';
  5756. }
  5757. }
  5758. if ($arrLP != null) {
  5759. reset($arrLP);
  5760. }
  5761. $return .= "\t\t\t\t" . '</select>';
  5762. $return .= '</td>';
  5763. $return .= '</tr>';
  5764. $return .= '<tr>';
  5765. $return .= '<td class="label"><label for="previous">' . get_lang('Position') . '&nbsp;:</label></td>';
  5766. $return .= '<td class="input">';
  5767. $return .= "\t\t\t\t" . '<select id="previous" name="previous" size="1">';
  5768. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . get_lang('FirstPosition') . '</option>';
  5769. for ($i = 0; $i < count($arrLP); $i++) {
  5770. if ($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) {
  5771. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5772. $selected = 'selected="selected" ';
  5773. elseif ($action == 'add') $selected = 'selected="selected" ';
  5774. else
  5775. $selected = '';
  5776. $return .= "\t\t\t\t\t" . '<option ' . $selected . 'value="' . $arrLP[$i]['id'] . '">' . get_lang('After') . ' "' . $arrLP[$i]['title'] . '"</option>';
  5777. }
  5778. }
  5779. $return .= "\t\t\t\t" . '</select>';
  5780. $return .= '</td>';
  5781. $return .= '</tr>';
  5782. if ($action != 'move') {
  5783. $return .= '<tr>';
  5784. $return .= '<td class="label"><label for="idTitle">' . get_lang('Title') . '&nbsp;:</label></td>';
  5785. $return .= '<td class="input"><input id="idTitle" name="title" type="text" value="' . $item_title . '" /></td>';
  5786. $return .= '</tr>';
  5787. $return .= '<tr>';
  5788. $return .= '</tr>';
  5789. $id_prerequisite = 0;
  5790. if ($arrLP != null) {
  5791. foreach ($arrLP as $key => $value) {
  5792. if ($value['id'] == $id) {
  5793. $id_prerequisite = $value['prerequisite'];
  5794. break;
  5795. }
  5796. }
  5797. }
  5798. $arrHide = array();
  5799. for ($i = 0; $i < count($arrLP); $i++) {
  5800. if ($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter') {
  5801. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5802. $s_selected_position = $arrLP[$i]['id'];
  5803. elseif ($action == 'add') $s_selected_position = 0;
  5804. $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
  5805. }
  5806. }
  5807. $return .= '<tr>';
  5808. $return .= '<td class="label"><label for="idPrerequisites">' . get_lang('Prerequisites') . '&nbsp;:</label></td>';
  5809. $return .= '<td class="input"><select name="prerequisites" id="prerequisites"><option value="0">' . get_lang('NoPrerequisites') . '</option>';
  5810. foreach ($arrHide as $key => $value) {
  5811. if ($key == $s_selected_position && $action == 'add') {
  5812. $return .= '<option value="' . $key . '" selected="selected">' . $value['value'] . '</option>';
  5813. }
  5814. elseif ($key == $id_prerequisite && $action == 'edit') {
  5815. $return .= '<option value="' . $key . '" selected="selected">' . $value['value'] . '</option>';
  5816. } else {
  5817. $return .= '<option value="' . $key . '">' . $value['value'] . '</option>';
  5818. }
  5819. }
  5820. $return .= "</select></td>";
  5821. $return .= '</tr>';
  5822. }
  5823. $return .= '<tr>';
  5824. $return .= '<td colspan="2">
  5825. <button class="save" name="submit_button" type="submit" value="'.get_lang('Ok').'" />'.get_lang('Ok').'</button></td>';
  5826. $return .= '</tr>';
  5827. $return .= '</table>';
  5828. if ($action == 'move') {
  5829. $return .= '<input name="title" type="hidden" value="' . $item_title . '" />';
  5830. $return .= '<input name="description" type="hidden" value="' . $item_description . '" />';
  5831. }
  5832. if (is_numeric($extra_info)) {
  5833. $return .= '<input name="path" type="hidden" value="' . $extra_info . '" />';
  5834. }
  5835. elseif (is_array($extra_info)) {
  5836. $return .= '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />';
  5837. }
  5838. $return .= '<input name="type" type="hidden" value="' . TOOL_THREAD . '" />';
  5839. $return .= '<input name="post_time" type="hidden" value="' . time() . '" />';
  5840. $return .= '</form>';
  5841. $return .= '</div>';
  5842. return $return;
  5843. }
  5844. /**
  5845. * Return the HTML form to display an item (generally a section/module item)
  5846. * @param string Item type (module/dokeos_module)
  5847. * @param string Title (optional, only when creating)
  5848. * @param string Action ('add'/'edit')
  5849. * @param integer lp_item ID
  5850. * @param mixed Extra info
  5851. * @return string HTML form
  5852. */
  5853. public function display_item_form($item_type, $title = '', $action = 'add_item', $id = 0, $extra_info = 'new') {
  5854. $course_id = api_get_course_int_id();
  5855. global $_course;
  5856. global $charset;
  5857. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  5858. if ($id != 0 && is_array($extra_info)) {
  5859. $item_title = $extra_info['title'];
  5860. $item_description = $extra_info['description'];
  5861. $item_path = api_get_path(WEB_COURSE_PATH) . $_course['path'] . '/scorm/' . $this->path . '/' . stripslashes($extra_info['path']);
  5862. $item_path_fck = '/scorm/' . $this->path . '/' . stripslashes($extra_info['path']);
  5863. } else {
  5864. $item_title = '';
  5865. $item_description = '';
  5866. $item_path_fck = '';
  5867. }
  5868. $legend = '<legend>';
  5869. if ($id != 0 && is_array($extra_info))
  5870. $parent = $extra_info['parent_item_id'];
  5871. else
  5872. $parent = 0;
  5873. $id = intval($id);
  5874. $sql = "SELECT * FROM " . $tbl_lp_item . "
  5875. WHERE c_id = ".$course_id." AND lp_id = " . $this->lp_id . " AND id != $id";
  5876. if ($item_type == 'module')
  5877. $sql .= " AND parent_item_id = 0";
  5878. $result = Database::query($sql);
  5879. $arrLP = array ();
  5880. while ($row = Database :: fetch_array($result)) {
  5881. $arrLP[] = array (
  5882. 'id' => $row['id'],
  5883. 'item_type' => $row['item_type'],
  5884. 'title' => $row['title'],
  5885. 'path' => $row['path'],
  5886. 'description' => $row['description'],
  5887. 'parent_item_id' => $row['parent_item_id'],
  5888. 'previous_item_id' => $row['previous_item_id'],
  5889. 'next_item_id' => $row['next_item_id'],
  5890. 'max_score' => $row['max_score'],
  5891. 'min_score' => $row['min_score'],
  5892. 'mastery_score' => $row['mastery_score'],
  5893. 'prerequisite' => $row['prerequisite'],
  5894. 'display_order' => $row['display_order']
  5895. );
  5896. }
  5897. $this->tree_array($arrLP);
  5898. $arrLP = $this->arrMenu;
  5899. unset ($this->arrMenu);
  5900. $legend .= $title;
  5901. $legend .= '</legend>';
  5902. $gradebook = isset($_GET['gradebook']) ? Security :: remove_XSS($_GET['gradebook']) : null;
  5903. $url = api_get_self() . '?' .api_get_cidreq().'&gradeboook='.$gradebook.'&action='.$action.'&type='.$item_type.'&lp_id='.$this->lp_id;
  5904. $form = new FormValidator('form', 'POST', $url);
  5905. $defaults['title'] = api_html_entity_decode($item_title, ENT_QUOTES, $charset);
  5906. $defaults['description'] = $item_description;
  5907. $form->addElement('html', $legend);
  5908. //$arrHide = array($id);
  5909. $arrHide[0]['value'] = Security :: remove_XSS($this->name);
  5910. $arrHide[0]['padding'] = 3;
  5911. $charset = api_get_system_encoding();
  5912. if ($item_type != 'module' && $item_type != 'dokeos_module') {
  5913. for ($i = 0; $i < count($arrLP); $i++) {
  5914. if ($action != 'add') {
  5915. 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)) {
  5916. $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
  5917. $arrHide[$arrLP[$i]['id']]['padding'] = 3 + $arrLP[$i]['depth'] * 10;
  5918. if ($parent == $arrLP[$i]['id']) {
  5919. $s_selected_parent = $arrHide[$arrLP[$i]['id']];
  5920. }
  5921. }
  5922. } else {
  5923. if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir') {
  5924. $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
  5925. $arrHide[$arrLP[$i]['id']]['padding'] = 3 + $arrLP[$i]['depth'] * 10;
  5926. if ($parent == $arrLP[$i]['id']) {
  5927. $s_selected_parent = $arrHide[$arrLP[$i]['id']];
  5928. }
  5929. }
  5930. }
  5931. }
  5932. if ($action != 'move') {
  5933. $form->addElement('text', 'title', get_lang('Title'), 'id="idTitle" class="learnpath_chapter_form" size="40%"');
  5934. $form->applyFilter('title', 'html_filter');
  5935. $form->addRule('title', '<div class="required">' . get_lang('ThisFieldIsRequired'), 'required');
  5936. //$form->addElement('textarea', 'description', get_lang('Description').' :', 'id="idDescription"');
  5937. } else {
  5938. $form->addElement('hidden', 'title');
  5939. }
  5940. $parent_select = & $form->addElement('select', 'parent', get_lang('Parent'), '', 'class="learnpath_chapter_form" style="width:37%;" id="idParent" onchange="javascript: load_cbo(this.value);"');
  5941. foreach ($arrHide as $key => $value) {
  5942. $parent_select->addOption($value['value'], $key, 'style="padding-left:' . $value['padding'] . 'px;"');
  5943. }
  5944. if (!empty($s_selected_parent)) {
  5945. $parent_select->setSelected($s_selected_parent);
  5946. }
  5947. }
  5948. if (is_array($arrLP)) {
  5949. reset($arrLP);
  5950. }
  5951. $arrHide = array();
  5952. // POSITION
  5953. for ($i = 0; $i < count($arrLP); $i++) {
  5954. if ($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) {
  5955. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5956. $s_selected_position = $arrLP[$i]['id'];
  5957. elseif ($action == 'add') $s_selected_position = $arrLP[$i]['id'];
  5958. $arrHide[$arrLP[$i]['id']]['value'] = get_lang('After') . ' "' . $arrLP[$i]['title'] . '"';
  5959. }
  5960. }
  5961. $position = & $form->addElement('select', 'previous', get_lang('Position'), '', 'id="previous" class="learnpath_chapter_form" style="width:37%;"');
  5962. $padding = isset($value['padding']) ? $value['padding'] : 0;
  5963. $position->addOption(get_lang('FirstPosition'), 0, 'style="padding-left:' . $padding . 'px;"');
  5964. foreach ($arrHide as $key => $value) {
  5965. $position->addOption($value['value'] . '"', $key, 'style="padding-left:' . $padding . 'px;"');
  5966. }
  5967. if (!empty ($s_selected_position)) {
  5968. $position->setSelected($s_selected_position);
  5969. }
  5970. if (is_array($arrLP)) {
  5971. reset($arrLP);
  5972. }
  5973. $form->addElement('style_submit_button', 'submit_button', get_lang('SaveSection'), 'class="save"');
  5974. if ($item_type == 'module' || $item_type == 'dokeos_module') {
  5975. $form->addElement('hidden', 'parent', '0');
  5976. }
  5977. //fix in order to use the tab
  5978. if ($item_type == 'chapter') {
  5979. $form->addElement('hidden', 'type', 'chapter');
  5980. }
  5981. $extension = null;
  5982. if (!empty($item_path)) {
  5983. $extension = pathinfo($item_path, PATHINFO_EXTENSION);
  5984. }
  5985. if (($item_type == 'asset' || $item_type == 'sco') && ($extension == 'html' || $extension == 'htm')) {
  5986. if ($item_type == 'sco') {
  5987. $form->addElement('html', '<script type="text/javascript">alert("' . get_lang('WarningWhenEditingScorm') . '")</script>');
  5988. }
  5989. $renderer = $form->defaultRenderer();
  5990. $renderer->setElementTemplate('<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{label}<br />{element}', 'content_lp');
  5991. $relative_prefix = '';
  5992. $editor_config = array( 'ToolbarSet' => 'LearningPathDocuments',
  5993. 'Width' => '100%',
  5994. 'Height' => '500',
  5995. 'FullPage' => true,
  5996. 'CreateDocumentDir' => $relative_prefix,
  5997. 'CreateDocumentWebDir' => api_get_path(WEB_COURSE_PATH) . api_get_course_path().'/scorm/',
  5998. 'BaseHref' => api_get_path(WEB_COURSE_PATH) . api_get_course_path().$item_path_fck
  5999. );
  6000. $form->addElement('html_editor', 'content_lp', '', null, $editor_config);
  6001. $defaults['content_lp'] = file_get_contents($item_path);
  6002. }
  6003. $form->addElement('hidden', 'type', 'dokeos_' . $item_type);
  6004. $form->addElement('hidden', 'post_time', time());
  6005. $form->setDefaults($defaults);
  6006. return $form->return_form();
  6007. }
  6008. /**
  6009. * Returns the form to update or create a document
  6010. * @param string Action (add/edit)
  6011. * @param integer ID of the lp_item (if already exists)
  6012. * @param mixed Integer if document ID, string if info ('new')
  6013. * @return string HTML form
  6014. */
  6015. public function display_document_form($action = 'add', $id = 0, $extra_info = 'new') {
  6016. $course_id = api_get_course_int_id();
  6017. global $charset;
  6018. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  6019. $tbl_doc = Database :: get_course_table(TABLE_DOCUMENT);
  6020. $path_parts = pathinfo($extra_info['dir']);
  6021. $no_display_edit_textarea = false;
  6022. //If action==edit document
  6023. //We don't display the document form if it's not an editable document (html or txt file)
  6024. if ($action == "edit") {
  6025. if (is_array($extra_info)) {
  6026. if ($path_parts['extension'] != "txt" && $path_parts['extension'] != "html") {
  6027. $no_display_edit_textarea = true;
  6028. }
  6029. }
  6030. }
  6031. $no_display_add = false;
  6032. // If action==add an existing document
  6033. // We don't display the document form if it's not an editable document (html or txt file).
  6034. if ($action == "add") {
  6035. if (is_numeric($extra_info)) {
  6036. $sql_doc = "SELECT path FROM " . $tbl_doc . " WHERE c_id = ".$course_id." AND id = " . Database :: escape_string($extra_info);
  6037. $result = Database::query($sql_doc);
  6038. $path_file = Database :: result($result, 0, 0);
  6039. $path_parts = pathinfo($path_file);
  6040. if ($path_parts['extension'] != "txt" && $path_parts['extension'] != "html") {
  6041. $no_display_add = true;
  6042. }
  6043. }
  6044. }
  6045. if ($id != 0 && is_array($extra_info)) {
  6046. $item_title = stripslashes($extra_info['title']);
  6047. $item_description = stripslashes($extra_info['description']);
  6048. $item_terms = stripslashes($extra_info['terms']);
  6049. if (empty ($item_title)) {
  6050. $path_parts = pathinfo($extra_info['path']);
  6051. $item_title = stripslashes($path_parts['filename']);
  6052. }
  6053. } elseif (is_numeric($extra_info)) {
  6054. $sql_doc = "SELECT path, title FROM " . $tbl_doc . "
  6055. WHERE c_id = ".$course_id." AND id = " . Database :: escape_string($extra_info);
  6056. $result = Database::query($sql_doc);
  6057. $row = Database::fetch_array($result);
  6058. $explode = explode('.', $row['title']);
  6059. if (count($explode) > 1) {
  6060. for ($i = 0; $i < count($explode) - 1; $i++)
  6061. $item_title .= $explode[$i];
  6062. } else {
  6063. $item_title = $row['title'];
  6064. }
  6065. $item_title = str_replace('_', ' ', $item_title);
  6066. if (empty ($item_title)) {
  6067. $path_parts = pathinfo($row['path']);
  6068. $item_title = stripslashes($path_parts['filename']);
  6069. }
  6070. } else {
  6071. $item_title = '';
  6072. $item_description = '';
  6073. }
  6074. $return = '<legend>';
  6075. if ($id != 0 && is_array($extra_info))
  6076. $parent = $extra_info['parent_item_id'];
  6077. else
  6078. $parent = 0;
  6079. $sql = "SELECT * FROM " . $tbl_lp_item . "
  6080. WHERE c_id = ".$course_id." AND lp_id = " . $this->lp_id;
  6081. $result = Database::query($sql);
  6082. $arrLP = array ();
  6083. while ($row = Database :: fetch_array($result)) {
  6084. $arrLP[] = array (
  6085. 'id' => $row['id'],
  6086. 'item_type' => $row['item_type'],
  6087. 'title' => $row['title'],
  6088. 'path' => $row['path'],
  6089. 'description' => $row['description'],
  6090. 'parent_item_id' => $row['parent_item_id'],
  6091. 'previous_item_id' => $row['previous_item_id'],
  6092. 'next_item_id' => $row['next_item_id'],
  6093. 'display_order' => $row['display_order'],
  6094. 'max_score' => $row['max_score'],
  6095. 'min_score' => $row['min_score'],
  6096. 'mastery_score' => $row['mastery_score'],
  6097. 'prerequisite' => $row['prerequisite']
  6098. );
  6099. }
  6100. $this->tree_array($arrLP);
  6101. $arrLP = $this->arrMenu;
  6102. unset ($this->arrMenu);
  6103. if ($action == 'add') {
  6104. $return .= get_lang('CreateTheDocument');
  6105. } elseif ($action == 'move') {
  6106. $return .= get_lang('MoveTheCurrentDocument');
  6107. } else {
  6108. $return .= get_lang('EditTheCurrentDocument');
  6109. }
  6110. $return .= '</legend>';
  6111. if (isset ($_GET['edit']) && $_GET['edit'] == 'true') {
  6112. $return .= Display :: return_warning_message('<strong>' . get_lang('Warning') . ' !</strong><br />' . get_lang('WarningEditingDocument'), false);
  6113. }
  6114. require_once api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php';
  6115. $form = new FormValidator('form', 'POST', api_get_self() . '?' . $_SERVER['QUERY_STRING'], '', 'enctype="multipart/form-data"');
  6116. $defaults['title'] = Security :: remove_XSS($item_title);
  6117. if (empty($item_title)) {
  6118. $defaults['title'] = Security::remove_XSS($item_title);
  6119. }
  6120. $defaults['description'] = $item_description;
  6121. $form->addElement('html', $return);
  6122. if ($action != 'move') {
  6123. $form->addElement('text', 'title', get_lang('Title'), 'id="idTitle" class="learnpath_item_form" size=44%');
  6124. $form->applyFilter('title', 'html_filter');
  6125. }
  6126. //$arrHide = array($id);
  6127. $arrHide[0]['value'] = $this->name;
  6128. $arrHide[0]['padding'] = 3;
  6129. for ($i = 0; $i < count($arrLP); $i++) {
  6130. if ($action != 'add') {
  6131. 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)) {
  6132. $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
  6133. $arrHide[$arrLP[$i]['id']]['padding'] = 3 + $arrLP[$i]['depth'] * 10;
  6134. if ($parent == $arrLP[$i]['id']) {
  6135. $s_selected_parent = $arrHide[$arrLP[$i]['id']];
  6136. }
  6137. }
  6138. } else {
  6139. if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir') {
  6140. $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
  6141. $arrHide[$arrLP[$i]['id']]['padding'] = 3 + $arrLP[$i]['depth'] * 10;
  6142. if ($parent == $arrLP[$i]['id']) {
  6143. $s_selected_parent = $arrHide[$arrLP[$i]['id']];
  6144. }
  6145. }
  6146. }
  6147. }
  6148. $parent_select = & $form->addElement('select', 'parent', get_lang('Parent'), '', 'class="learnpath_item_form" id="idParent" style="width:40%;" onchange="javascript: load_cbo(this.value);"');
  6149. $my_count=0;
  6150. foreach ($arrHide as $key => $value) {
  6151. if ($my_count!=0) {
  6152. // The LP name is also the first section and is not in the same charset like the other sections.
  6153. $value['value'] = Security :: remove_XSS($value['value']);
  6154. $parent_select->addOption($value['value'], $key, 'style="padding-left:' . $value['padding'] . 'px;"');
  6155. } else {
  6156. $value['value'] = Security :: remove_XSS($value['value']);
  6157. $parent_select->addOption($value['value'], $key, 'style="padding-left:' . $value['padding'] . 'px;"');
  6158. }
  6159. $my_count++;
  6160. }
  6161. if (!empty($id)) {
  6162. $parent_select->setSelected($parent);
  6163. } else {
  6164. $parent_item_id = $_SESSION['parent_item_id'];
  6165. $parent_select->setSelected($parent_item_id);
  6166. }
  6167. if (is_array($arrLP)) {
  6168. reset($arrLP);
  6169. }
  6170. $arrHide = array ();
  6171. //POSITION
  6172. for ($i = 0; $i < count($arrLP); $i++) {
  6173. if ($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) {
  6174. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  6175. $s_selected_position = $arrLP[$i]['id'];
  6176. elseif ($action == 'add') $s_selected_position = $arrLP[$i]['id'];
  6177. $arrHide[$arrLP[$i]['id']]['value'] = get_lang('After') . ' "' . $arrLP[$i]['title'] . '"';
  6178. }
  6179. }
  6180. $position = & $form->addElement('select', 'previous', get_lang('Position'), '', 'id="previous" class="learnpath_item_form" style="width:40%;"');
  6181. $position->addOption(get_lang('FirstPosition'), 0);
  6182. foreach ($arrHide as $key => $value) {
  6183. $padding = isset($value['padding']) ? $value['padding']: 0;
  6184. $position->addOption($value['value'], $key, 'style="padding-left:' . $padding . 'px;"');
  6185. }
  6186. $position->setSelected($s_selected_position);
  6187. if (is_array($arrLP)) {
  6188. reset($arrLP);
  6189. }
  6190. if ($action != 'move') {
  6191. $id_prerequisite = 0;
  6192. if (is_array($arrLP)) {
  6193. foreach ($arrLP as $key => $value) {
  6194. if ($value['id'] == $id) {
  6195. $id_prerequisite = $value['prerequisite'];
  6196. break;
  6197. }
  6198. }
  6199. }
  6200. $arrHide = array ();
  6201. for ($i = 0; $i < count($arrLP); $i++) {
  6202. if ($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter') {
  6203. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  6204. $s_selected_position = $arrLP[$i]['id'];
  6205. elseif ($action == 'add') $s_selected_position = $arrLP[$i]['id'];
  6206. $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
  6207. }
  6208. }
  6209. if (!$no_display_add) {
  6210. if (($extra_info == 'new' || $extra_info['item_type'] == TOOL_DOCUMENT || $_GET['edit'] == 'true')) {
  6211. if (isset ($_POST['content']))
  6212. $content = stripslashes($_POST['content']);
  6213. elseif (is_array($extra_info)) {
  6214. //If it's an html document or a text file
  6215. if (!$no_display_edit_textarea) {
  6216. $content = $this->display_document($extra_info['path'], false, false);
  6217. }
  6218. } elseif (is_numeric($extra_info))
  6219. $content = $this->display_document($extra_info, false, false);
  6220. else
  6221. $content = '';
  6222. if (!$no_display_edit_textarea) {
  6223. // We need to calculate here some specific settings for the online editor.
  6224. // The calculated settings work for documents in the Documents tool
  6225. // (on the root or in subfolders).
  6226. // For documents in native scorm packages it is unclear whether the
  6227. // online editor should be activated or not.
  6228. // A new document, it is in the root of the repository.
  6229. $relative_path = '';
  6230. $relative_prefix = '';
  6231. if (is_array($extra_info) && $extra_info != 'new') {
  6232. // The document already exists. Whe have to determine its relative path towards the repository root.
  6233. $relative_path = explode('/', $extra_info['dir']);
  6234. $cnt = count($relative_path) - 2;
  6235. if ($cnt < 0) {
  6236. $cnt = 0;
  6237. }
  6238. $relative_prefix = str_repeat('../', $cnt);
  6239. $relative_path = array_slice($relative_path, 1, $cnt);
  6240. $relative_path = implode('/', $relative_path);
  6241. if (strlen($relative_path) > 0) {
  6242. $relative_path = $relative_path . '/';
  6243. }
  6244. } else {
  6245. global $_course;
  6246. $result = $this->generate_lp_folder($_course, '');
  6247. $relative_path = api_substr($result['dir'], 1, strlen($result['dir']));
  6248. $relative_prefix = '../../';
  6249. }
  6250. $editor_config = array( 'ToolbarSet' => 'LearningPathDocuments',
  6251. 'Width' => '100%',
  6252. 'Height' => '500',
  6253. 'FullPage' => true,
  6254. 'CreateDocumentDir' => $relative_prefix,
  6255. 'CreateDocumentWebDir' => api_get_path(WEB_COURSE_PATH) . api_get_course_path().'/document/',
  6256. 'BaseHref' => api_get_path(WEB_COURSE_PATH) . api_get_course_path().'/document/'.$relative_path
  6257. );
  6258. if ($_GET['action'] == 'add_item') {
  6259. $class = 'add';
  6260. $text = get_lang('LPCreateDocument');
  6261. } else
  6262. if ($_GET['action'] == 'edit_item') {
  6263. $class = 'save';
  6264. $text = get_lang('SaveDocument');
  6265. }
  6266. $form->addElement('style_submit_button', 'submit_button', $text, 'class="' . $class . '"');
  6267. $renderer = $form->defaultRenderer();
  6268. $renderer->setElementTemplate('<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{label}<br />{element}', 'content_lp');
  6269. $form->addElement('html', '<div style="margin:3px 12px">');
  6270. $form->addElement('html_editor', 'content_lp', '', null, $editor_config);
  6271. $form->addElement('html', '</div>');
  6272. $defaults['content_lp'] = $content;
  6273. }
  6274. } elseif (is_numeric($extra_info)) {
  6275. $form->addElement('style_submit_button', 'submit_button', get_lang('SaveDocument'), 'class="save"');
  6276. $return = $this->display_document($extra_info, true, true, true);
  6277. $form->addElement('html', $return);
  6278. }
  6279. }
  6280. }
  6281. if ($action == 'move') {
  6282. $form->addElement('hidden', 'title', $item_title);
  6283. $form->addElement('hidden', 'description', $item_description);
  6284. }
  6285. if (is_numeric($extra_info)) {
  6286. $form->addElement('style_submit_button', 'submit_button', get_lang('SaveDocument'), 'value="submit_button", class="save"');
  6287. $form->addElement('hidden', 'path', $extra_info);
  6288. }
  6289. elseif (is_array($extra_info)) {
  6290. $form->addElement('style_submit_button', 'submit_button', get_lang('SaveDocument'), 'class="save"');
  6291. $form->addElement('hidden', 'path', $extra_info['path']);
  6292. }
  6293. $form->addElement('hidden', 'type', TOOL_DOCUMENT);
  6294. $form->addElement('hidden', 'post_time', time());
  6295. $form->setDefaults($defaults);
  6296. return $form->return_form();
  6297. }
  6298. /**
  6299. * Return HTML form to add/edit a link item
  6300. * @param string Action (add/edit)
  6301. * @param integer Item ID if exists
  6302. * @param mixed Extra info
  6303. * @return string HTML form
  6304. */
  6305. public function display_link_form($action = 'add', $id = 0, $extra_info = '') {
  6306. $course_id = api_get_course_int_id();
  6307. global $charset;
  6308. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  6309. $tbl_link = Database :: get_course_table(TABLE_LINK);
  6310. if ($id != 0 && is_array($extra_info)) {
  6311. $item_title = stripslashes($extra_info['title']);
  6312. $item_description = stripslashes($extra_info['description']);
  6313. $item_url = stripslashes($extra_info['url']);
  6314. } elseif (is_numeric($extra_info)) {
  6315. $sql_link = "SELECT title, description, url FROM " . $tbl_link . " WHERE c_id = ".$course_id." AND id = " . $extra_info;
  6316. $result = Database::query($sql_link);
  6317. $row = Database :: fetch_array($result);
  6318. $item_title = $row['title'];
  6319. $item_description = $row['description'];
  6320. $item_url = $row['url'];
  6321. } else {
  6322. $item_title = '';
  6323. $item_description = '';
  6324. $item_url = '';
  6325. }
  6326. $legend = '<legend>';
  6327. if ($id != 0 && is_array($extra_info))
  6328. $parent = $extra_info['parent_item_id'];
  6329. else
  6330. $parent = 0;
  6331. $sql = "SELECT * FROM " . $tbl_lp_item . " WHERE c_id = ".$course_id." AND lp_id = " . $this->lp_id;
  6332. $result = Database::query($sql);
  6333. $arrLP = array ();
  6334. while ($row = Database :: fetch_array($result)) {
  6335. $arrLP[] = array (
  6336. 'id' => $row['id'],
  6337. 'item_type' => $row['item_type'],
  6338. 'title' => $row['title'],
  6339. 'path' => $row['path'],
  6340. 'description' => $row['description'],
  6341. 'parent_item_id' => $row['parent_item_id'],
  6342. 'previous_item_id' => $row['previous_item_id'],
  6343. 'next_item_id' => $row['next_item_id'],
  6344. 'display_order' => $row['display_order'],
  6345. 'max_score' => $row['max_score'],
  6346. 'min_score' => $row['min_score'],
  6347. 'mastery_score' => $row['mastery_score'],
  6348. 'prerequisite' => $row['prerequisite']
  6349. );
  6350. }
  6351. $this->tree_array($arrLP);
  6352. $arrLP = $this->arrMenu;
  6353. unset ($this->arrMenu);
  6354. if ($action == 'add')
  6355. $legend .= get_lang('CreateTheLink') . '&nbsp;:';
  6356. elseif ($action == 'move') $legend .= get_lang('MoveCurrentLink') . '&nbsp;:';
  6357. else
  6358. $legend .= get_lang('EditCurrentLink') . '&nbsp;:';
  6359. $legend .= '</legend>';
  6360. $return .= '<div class="sectioncomment">';
  6361. $return .= '<form method="POST">';
  6362. $return .= $legend;
  6363. $return .= '<table>';
  6364. if ($action != 'move') {
  6365. $return .= '<tr>';
  6366. $return .= '<td class="label"><label for="idTitle">' . get_lang('Title') . '</label></td>';
  6367. $return .= '<td class="input"><input id="idTitle" name="title" size="44" type="text" value="' . $item_title . '" class="learnpath_item_form"/></td>';
  6368. $return .= '</tr>';
  6369. }
  6370. $return .= '<tr>';
  6371. $return .= '<td class="label"><label for="idParent">' . get_lang('Parent') . '</label></td>';
  6372. $return .= '<td class="input">';
  6373. $return .= '<select id="idParent" style="width:100%;" name="parent" onChange="javascript: load_cbo(this.value);" class="learnpath_item_form" size="1">';
  6374. $return .= '<option class="top" value="0">' . $this->name . '</option>';
  6375. $arrHide = array (
  6376. $id
  6377. );
  6378. $parent_item_id = $_SESSION['parent_item_id'];
  6379. for ($i = 0; $i < count($arrLP); $i++) {
  6380. if ($action != 'add') {
  6381. 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)) {
  6382. $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>';
  6383. } else {
  6384. $arrHide[] = $arrLP[$i]['id'];
  6385. }
  6386. } else {
  6387. if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
  6388. $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>';
  6389. }
  6390. }
  6391. if (is_array($arrLP)) {
  6392. reset($arrLP);
  6393. }
  6394. $return .= "\t\t\t\t" . '</select>';
  6395. $return .= '</td>';
  6396. $return .= '</tr>';
  6397. $return .= '<tr>';
  6398. $return .= '<td class="label"><label for="previous">' . get_lang('Position') . '</label></td>';
  6399. $return .= '<td class="input">';
  6400. $return .= "\t\t\t\t" . '<select id="previous" name="previous" style="width:100%;" size="1" class="learnpath_item_form">';
  6401. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . get_lang('FirstPosition') . '</option>';
  6402. for ($i = 0; $i < count($arrLP); $i++) {
  6403. if ($arrLP[$i]['parent_item_id'] == $parent_item_id && $arrLP[$i]['id'] != $id) {
  6404. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  6405. $selected = 'selected="selected" ';
  6406. elseif ($action == 'add')
  6407. $selected = 'selected="selected" ';
  6408. else
  6409. $selected = '';
  6410. $return .= '<option ' . $selected . 'value="' . $arrLP[$i]['id'] . '">' . get_lang('After') . ' "' . $arrLP[$i]['title'] . '"</option>';
  6411. }
  6412. }
  6413. $return .= '</select>';
  6414. $return .= '</td>';
  6415. $return .= '</tr>';
  6416. if ($action != 'move') {
  6417. $return .= '<tr>';
  6418. $return .= '<td class="label"><label for="idURL">' . get_lang('Url') . '</label></td>';
  6419. $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>';
  6420. $return .= '</tr>';
  6421. $id_prerequisite = 0;
  6422. if (is_array($arrLP)) {
  6423. foreach ($arrLP as $key => $value) {
  6424. if ($value['id'] == $id) {
  6425. $id_prerequisite = $value['prerequisite'];
  6426. break;
  6427. }
  6428. }
  6429. }
  6430. $arrHide = array ();
  6431. for ($i = 0; $i < count($arrLP); $i++) {
  6432. if ($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter') {
  6433. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  6434. $s_selected_position = $arrLP[$i]['id'];
  6435. elseif ($action == 'add') $s_selected_position = 0;
  6436. $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
  6437. }
  6438. }
  6439. /*// Commented the prerequisites, only visible in edit (link).
  6440. $return .= '<tr>';
  6441. $return .= '<td class="label"><label for="idPrerequisites">'.get_lang('Prerequisites').'</label></td>';
  6442. $return .= '<td class="input"><select name="prerequisites" id="prerequisites" class="learnpath_item_form"><option value="0">'.get_lang('NoPrerequisites').'</option>';
  6443. foreach($arrHide as $key => $value) {
  6444. if ($key == $s_selected_position && $action == 'add') {
  6445. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  6446. }
  6447. elseif ($key == $id_prerequisite && $action == 'edit') {
  6448. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  6449. }
  6450. else {
  6451. $return .= '<option value="'.$key.'">'.$value['value'].'</option>';
  6452. }
  6453. }
  6454. $return .= "</select></td>";
  6455. */
  6456. $return .= '</tr>';
  6457. }
  6458. $return .= '<tr>';
  6459. if ($action == 'add') {
  6460. $return .= '<td>&nbsp;</td><td><button class="save" name="submit_button" type="submit">' . get_lang('AddLinkToCourse') . '</button></td>';
  6461. } else {
  6462. $return .= '<td>&nbsp;</td><td><button class="save" name="submit_button" type="submit">' . get_lang('EditCurrentLink') . '</button></td>';
  6463. }
  6464. $return .= '</tr>';
  6465. $return .= '</table>';
  6466. if ($action == 'move') {
  6467. $return .= '<input name="title" type="hidden" value="' . $item_title . '" />';
  6468. $return .= '<input name="description" type="hidden" value="' . $item_description . '" />';
  6469. }
  6470. if (is_numeric($extra_info)) {
  6471. $return .= '<input name="path" type="hidden" value="' . $extra_info . '" />';
  6472. }
  6473. elseif (is_array($extra_info)) {
  6474. $return .= '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />';
  6475. }
  6476. $return .= '<input name="type" type="hidden" value="' . TOOL_LINK . '" />';
  6477. $return .= '<input name="post_time" type="hidden" value="' . time() . '" />';
  6478. $return .= '</form>';
  6479. $return .= '</div>';
  6480. return $return;
  6481. }
  6482. /**
  6483. * Return HTML form to add/edit a student publication (work)
  6484. * @param string Action (add/edit)
  6485. * @param integer Item ID if already exists
  6486. * @param mixed Extra info (work ID if integer)
  6487. * @return string HTML form
  6488. */
  6489. public function display_student_publication_form($action = 'add', $id = 0, $extra_info = '') {
  6490. $course_id = api_get_course_int_id();
  6491. global $charset;
  6492. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  6493. $tbl_publication = Database :: get_course_table(TABLE_STUDENT_PUBLICATION);
  6494. if ($id != 0 && is_array($extra_info)) {
  6495. $item_title = stripslashes($extra_info['title']);
  6496. $item_description = stripslashes($extra_info['description']);
  6497. }
  6498. elseif (is_numeric($extra_info)) {
  6499. $sql_publication = "SELECT title, description FROM " . $tbl_publication . "
  6500. WHERE c_id = ".$course_id." AND id = " . $extra_info;
  6501. $result = Database::query($sql_publication);
  6502. $row = Database :: fetch_array($result);
  6503. $item_title = $row['title'];
  6504. } else {
  6505. $item_title = get_lang('Student_publication');
  6506. }
  6507. $legend = '<legend>';
  6508. if ($id != 0 && is_array($extra_info))
  6509. $parent = $extra_info['parent_item_id'];
  6510. else
  6511. $parent = 0;
  6512. $sql = "SELECT * FROM " . $tbl_lp_item . "
  6513. WHERE c_id = ".$course_id." AND lp_id = " . $this->lp_id;
  6514. $result = Database::query($sql);
  6515. $arrLP = array ();
  6516. while ($row = Database :: fetch_array($result)) {
  6517. $arrLP[] = array (
  6518. 'id' => $row['id'],
  6519. 'item_type' => $row['item_type'],
  6520. 'title' => $row['title'],
  6521. 'path' => $row['path'],
  6522. 'description' => $row['description'],
  6523. 'parent_item_id' => $row['parent_item_id'],
  6524. 'previous_item_id' => $row['previous_item_id'],
  6525. 'next_item_id' => $row['next_item_id'],
  6526. 'display_order' => $row['display_order'],
  6527. 'max_score' => $row['max_score'],
  6528. 'min_score' => $row['min_score'],
  6529. 'mastery_score' => $row['mastery_score'],
  6530. 'prerequisite' => $row['prerequisite']
  6531. );
  6532. }
  6533. $this->tree_array($arrLP);
  6534. $arrLP = $this->arrMenu;
  6535. unset ($this->arrMenu);
  6536. if ($action == 'add')
  6537. $legend .= get_lang('Student_publication') . '&nbsp;:' . "\n";
  6538. elseif ($action == 'move') $legend .= get_lang('MoveCurrentStudentPublication') . '&nbsp;:' . "\n";
  6539. else
  6540. $legend .= get_lang('EditCurrentStudentPublication') . '&nbsp;:' . "\n";
  6541. $legend .= '</legend>';
  6542. $return .= '<div class="sectioncomment">';
  6543. $return .= '<form method="POST">';
  6544. $return .= $legend;
  6545. $return .= '<table class="lp_form">';
  6546. if ($action != 'move') {
  6547. $return .= '<tr>';
  6548. $return .= '<td class="label"><label for="idTitle">' . get_lang('Title') . '</label></td>';
  6549. $return .= '<td class="input"><input id="idTitle" name="title" size="44" type="text" value="' . $item_title . '" class="learnpath_item_form" /></td>';
  6550. $return .= '</tr>';
  6551. }
  6552. $return .= '<tr>';
  6553. $return .= '<td class="label"><label for="idParent">' . get_lang('Parent') . '</label></td>';
  6554. $return .= '<td class="input">';
  6555. $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">';
  6556. //$parent_item_id = $_SESSION['parent_item_id'];
  6557. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
  6558. $arrHide = array (
  6559. $id
  6560. );
  6561. for ($i = 0; $i < count($arrLP); $i++) {
  6562. if ($action != 'add') {
  6563. 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)) {
  6564. $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>';
  6565. } else {
  6566. $arrHide[] = $arrLP[$i]['id'];
  6567. }
  6568. } else {
  6569. if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
  6570. $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>';
  6571. }
  6572. }
  6573. if (is_array($arrLP)) {
  6574. reset($arrLP);
  6575. }
  6576. $return .= "\t\t\t\t" . '</select>';
  6577. $return .= '</td>';
  6578. $return .= '</tr>';
  6579. $return .= '<tr>';
  6580. $return .= '<td class="label"><label for="previous">' . get_lang('Position') . '</label></td>';
  6581. $return .= '<td class="input">';
  6582. $return .= "\t\t\t\t" . '<select id="previous" name="previous" style="width:100%;" size="1" class="learnpath_item_form">';
  6583. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . get_lang('FirstPosition') . '</option>';
  6584. for ($i = 0; $i < count($arrLP); $i++) {
  6585. if ($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) {
  6586. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  6587. $selected = 'selected="selected" ';
  6588. elseif ($action == 'add') $selected = 'selected="selected" ';
  6589. else
  6590. $selected = '';
  6591. $return .= "\t\t\t\t\t" . '<option ' . $selected . 'value="' . $arrLP[$i]['id'] . '">' . get_lang('After') . ' "' . $arrLP[$i]['title'] . '"</option>';
  6592. }
  6593. }
  6594. $return .= "\t\t\t\t" . '</select>';
  6595. $return .= '</td>';
  6596. $return .= '</tr>';
  6597. if ($action != 'move') {
  6598. $id_prerequisite = 0;
  6599. if (is_array($arrLP)) {
  6600. foreach ($arrLP as $key => $value) {
  6601. if ($value['id'] == $id) {
  6602. $id_prerequisite = $value['prerequisite'];
  6603. break;
  6604. }
  6605. }
  6606. }
  6607. $arrHide = array ();
  6608. for ($i = 0; $i < count($arrLP); $i++) {
  6609. if ($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter') {
  6610. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  6611. $s_selected_position = $arrLP[$i]['id'];
  6612. elseif ($action == 'add') $s_selected_position = 0;
  6613. $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
  6614. }
  6615. }
  6616. // Commented the prerequisites, only visible in edit (work).
  6617. /*
  6618. $return .= '<tr>';
  6619. $return .= '<td class="label"><label for="idPrerequisites">'.get_lang('Prerequisites').'</label></td>';
  6620. $return .= '<td class="input"><select name="prerequisites" id="prerequisites" class="learnpath_item_form"><option value="0">'.get_lang('NoPrerequisites').'</option>';
  6621. foreach($arrHide as $key => $value) {
  6622. if ($key == $s_selected_position && $action == 'add') {
  6623. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  6624. }
  6625. elseif ($key == $id_prerequisite && $action == 'edit') {
  6626. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  6627. }
  6628. else {
  6629. $return .= '<option value="'.$key.'">'.$value['value'].'</option>';
  6630. }
  6631. }
  6632. $return .= "</select></td>";
  6633. */
  6634. $return .= '</tr>';
  6635. }
  6636. $return .= '<tr>';
  6637. if ($action == 'add') {
  6638. $return .= '<td>&nbsp</td><td><button class="save" name="submit_button" type="submit">' . get_lang('AddAssignmentToCourse') . '</button></td>';
  6639. } else {
  6640. $return .= '<td>&nbsp</td><td><button class="save" name="submit_button" type="submit">' . get_lang('EditCurrentStudentPublication') . '</button></td>';
  6641. }
  6642. $return .= '</tr>';
  6643. $return .= '</table>';
  6644. if ($action == 'move') {
  6645. $return .= '<input name="title" type="hidden" value="' . $item_title . '" />';
  6646. $return .= '<input name="description" type="hidden" value="' . $item_description . '" />';
  6647. }
  6648. if (is_numeric($extra_info)) {
  6649. $return .= '<input name="path" type="hidden" value="' . $extra_info . '" />';
  6650. } elseif (is_array($extra_info)) {
  6651. $return .= '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />';
  6652. }
  6653. $return .= '<input name="type" type="hidden" value="' . TOOL_STUDENTPUBLICATION . '" />';
  6654. $return .= '<input name="post_time" type="hidden" value="' . time() . '" />';
  6655. $return .= '</form>';
  6656. $return .= '</div>';
  6657. return $return;
  6658. }
  6659. /**
  6660. * Displays the menu for manipulating a step
  6661. * @return string html
  6662. */
  6663. public function display_manipulate($item_id, $item_type = TOOL_DOCUMENT) {
  6664. $course_id = api_get_course_int_id();
  6665. global $charset, $_course;
  6666. $return = '<div class="actions">';
  6667. switch ($item_type) {
  6668. case 'dokeos_chapter' :
  6669. case 'chapter' :
  6670. // Commented the message cause should not show it.
  6671. //$lang = get_lang('TitleManipulateChapter');
  6672. break;
  6673. case 'dokeos_module' :
  6674. case 'module' :
  6675. // Commented the message cause should not show it.
  6676. //$lang = get_lang('TitleManipulateModule');
  6677. break;
  6678. case TOOL_DOCUMENT :
  6679. // Commented the message cause should not show it.
  6680. //$lang = get_lang('TitleManipulateDocument');
  6681. break;
  6682. case TOOL_LINK :
  6683. case 'link' :
  6684. // Commented the message cause should not show it.
  6685. //$lang = get_lang('TitleManipulateLink');
  6686. break;
  6687. case TOOL_QUIZ :
  6688. // Commented the message cause should not show it.
  6689. //$lang = get_lang('TitleManipulateQuiz');
  6690. break;
  6691. case TOOL_STUDENTPUBLICATION :
  6692. // Commented the message cause should not show it.
  6693. //$lang = get_lang('TitleManipulateStudentPublication');
  6694. break;
  6695. }
  6696. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  6697. $item_id = intval($item_id);
  6698. $sql = "SELECT * FROM " . $tbl_lp_item . " as lp WHERE lp.c_id = ".$course_id." AND lp.id = " . $item_id;
  6699. $result = Database::query($sql);
  6700. $row = Database::fetch_assoc($result);
  6701. $s_title = $row['title'];
  6702. // We display an audio player if needed.
  6703. if (!empty ($row['audio'])) {
  6704. $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>';
  6705. $return .= '<script type="text/javascript" src="../inc/lib/mediaplayer/swfobject.js"></script>';
  6706. $return .= '<script type="text/javascript">
  6707. var s1 = new SWFObject("../inc/lib/mediaplayer/player.swf","ply","250","20","9","#FFFFFF");
  6708. s1.addParam("allowscriptaccess","always");
  6709. s1.addParam("flashvars","file=../../courses/' . $_course['path'] . '/document/audio/' . $row['audio'] . '&autostart=true");
  6710. s1.write("container");
  6711. </script>';
  6712. }
  6713. // Commented ":" for message in step.
  6714. //$return .= $lang.': ';
  6715. $url = api_get_self() . '?cidReq='.Security::remove_XSS($_GET['cidReq']).'&view=build&id='.$item_id .'&lp_id='.$this->lp_id;
  6716. $return .= Display::url(Display::return_icon('edit.png', get_lang('Edit'), array(), ICON_SIZE_SMALL), $url.'&action=edit_item&path_item=' . $row['path']);
  6717. $return .= Display::url(Display::return_icon('move.png', get_lang('Move'), array(), ICON_SIZE_SMALL), $url.'&action=move_item');
  6718. // Commented for now as prerequisites cannot be added to chapters.
  6719. if ($item_type != 'dokeos_chapter' && $item_type != 'chapter') {
  6720. $return .= Display::url(Display::return_icon('accept.png', get_lang('Prerequisites'), array(), ICON_SIZE_SMALL), $url.'&action=edit_item_prereq');
  6721. }
  6722. $return .= Display::url(Display::return_icon('delete.png', get_lang('Delete'), array(), ICON_SIZE_SMALL), $url.'&action=delete_item');
  6723. /*
  6724. // Get the audiorecorder. Use of ob_* functions since there are echos in the file.
  6725. ob_start();
  6726. $audio_recorder_studentview = 'false';
  6727. $audio_recorder_item_id = $item_id;
  6728. if (api_get_setting('service_visio', 'active') == 'true') {
  6729. require_once 'audiorecorder.inc.php';
  6730. }
  6731. $return .= ob_get_contents();
  6732. ob_end_clean();
  6733. // End of audiorecorder include
  6734. */
  6735. $return .= '</div>';
  6736. return $return;
  6737. }
  6738. /**
  6739. * Creates the javascript needed for filling up the checkboxes without page reload
  6740. *
  6741. * @return string
  6742. */
  6743. public function get_js_dropdown_array() {
  6744. $course_id = api_get_course_int_id();
  6745. $return = 'var child_name = new Array();' . "\n";
  6746. $return .= 'var child_value = new Array();' . "\n\n";
  6747. $return .= 'child_name[0] = new Array();' . "\n";
  6748. $return .= 'child_value[0] = new Array();' . "\n\n";
  6749. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  6750. $sql_zero = "SELECT * FROM " . $tbl_lp_item . "
  6751. WHERE c_id = ".$course_id." AND lp_id = " . $this->lp_id . " AND parent_item_id = 0
  6752. ORDER BY display_order ASC";
  6753. $res_zero = Database::query($sql_zero);
  6754. global $charset;
  6755. $i = 0;
  6756. while ($row_zero = Database :: fetch_array($res_zero)) {
  6757. $js_var = json_encode(get_lang('After').' '.$row_zero['title']);
  6758. $return .= 'child_name[0][' . $i . '] = '.$js_var.' ;' . "\n";
  6759. $return .= 'child_value[0][' . $i++ . '] = "' . $row_zero['id'] . '";' . "\n";
  6760. }
  6761. $return .= "\n";
  6762. $sql = "SELECT * FROM " . $tbl_lp_item . " WHERE c_id = ".$course_id." AND lp_id = " . $this->lp_id;
  6763. $res = Database::query($sql);
  6764. while ($row = Database :: fetch_array($res)) {
  6765. $sql_parent = "
  6766. SELECT * FROM " . $tbl_lp_item . "
  6767. WHERE c_id = ".$course_id." AND parent_item_id = " . $row['id'] . "
  6768. ORDER BY display_order ASC";
  6769. $res_parent = Database::query($sql_parent);
  6770. $i = 0;
  6771. $return .= 'child_name[' . $row['id'] . '] = new Array();' . "\n";
  6772. $return .= 'child_value[' . $row['id'] . '] = new Array();' . "\n\n";
  6773. while ($row_parent = Database :: fetch_array($res_parent)) {
  6774. $js_var = json_encode(get_lang('After').' '.$row_parent['title']);
  6775. $return .= 'child_name[' . $row['id'] . '][' . $i . '] = '.$js_var.' ;' . "\n";
  6776. $return .= 'child_value[' . $row['id'] . '][' . $i++ . '] = "' . $row_parent['id'] . '";' . "\n";
  6777. }
  6778. $return .= "\n";
  6779. }
  6780. return $return;
  6781. }
  6782. /**
  6783. * Display the form to allow moving an item
  6784. * @param integer Item ID
  6785. * @return string HTML form
  6786. */
  6787. public function display_move_item($item_id) {
  6788. $course_id = api_get_course_int_id();
  6789. global $_course; //will disappear
  6790. global $charset;
  6791. $return = '';
  6792. if (is_numeric($item_id)) {
  6793. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  6794. $sql = "SELECT *
  6795. FROM " . $tbl_lp_item . "
  6796. WHERE c_id = ".$course_id." AND id = " . $item_id;
  6797. $res = Database::query($sql);
  6798. $row = Database :: fetch_array($res);
  6799. switch ($row['item_type']) {
  6800. case 'dokeos_chapter' :
  6801. case 'dir' :
  6802. case 'asset' :
  6803. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6804. $return .= $this->display_item_form($row['item_type'], get_lang('MoveCurrentChapter'), 'move', $item_id, $row);
  6805. break;
  6806. case 'dokeos_module' :
  6807. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6808. $return .= $this->display_item_form($row['item_type'], 'Move th current module:', 'move', $item_id, $row);
  6809. break;
  6810. case TOOL_DOCUMENT :
  6811. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6812. $return .= $this->display_document_form('move', $item_id, $row);
  6813. break;
  6814. case TOOL_LINK :
  6815. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6816. $return .= $this->display_link_form('move', $item_id, $row);
  6817. break;
  6818. case TOOL_HOTPOTATOES :
  6819. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6820. $return .= $this->display_link_form('move', $item_id, $row);
  6821. break;
  6822. case TOOL_QUIZ :
  6823. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6824. $return .= $this->display_quiz_form('move', $item_id, $row);
  6825. break;
  6826. case TOOL_STUDENTPUBLICATION :
  6827. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6828. $return .= $this->display_student_publication_form('move', $item_id, $row);
  6829. break;
  6830. case TOOL_FORUM :
  6831. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6832. $return .= $this->display_forum_form('move', $item_id, $row);
  6833. break;
  6834. case TOOL_THREAD :
  6835. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6836. $return .= $this->display_forum_form('move', $item_id, $row);
  6837. break;
  6838. }
  6839. }
  6840. return $return;
  6841. }
  6842. /**
  6843. * Displays a basic form on the overview page for changing the item title and the item description.
  6844. * @param string $item_type
  6845. * @param string $title
  6846. * @param array $data
  6847. * @return string
  6848. */
  6849. public function display_item_small_form($item_type, $title = '', $data) {
  6850. $return = '<div class="lp_small_form">';
  6851. $return .= '<p class="lp_title">' . $title . '</p>';
  6852. $return .= '<form method="post">';
  6853. $return .= '<table cellpadding="0" cellspacing="0" class="lp_form">';
  6854. $return .= '<tr>';
  6855. $return .= '<td class="label"><label for="idTitle">Title&nbsp;:</label></td>';
  6856. $return .= '<td class="input"><input class="small_form" id="idTitle" name="title" type="text" value="' . api_html_entity_decode($data['title'], ENT_QUOTES) . '" /></td>';
  6857. $return .= '</tr>';
  6858. // It said these lines of code - see SVN#11724 and SVN#10770
  6859. //$return .= '<tr>';
  6860. //$return .= '<td class="label"><label for="idDescription">Description&nbsp;:</label></td>';
  6861. //$return .= '<td class="input"><textarea class="small_form" id="idDescription" name="description" rows="4">' . $data['description'] . '</textarea></td>';
  6862. //$return .= '</tr>';
  6863. $return .= '<tr>';
  6864. $return .= '<td colspan="2"><button class="save" name="submit_button" type="submit">' . get_lang('Save') . '</button></td>';
  6865. $return .= '</tr>';
  6866. $return .= '</table>';
  6867. $return .= '<input name="parent" type="hidden" value="' . $data['parent_item_id'] . '"/>';
  6868. $return .= '<input name="previous" type="hidden" value="' . $data['previous_item_id'] . '"/>';
  6869. $return .= '</form>';
  6870. $return .= '</div>';
  6871. return $return;
  6872. }
  6873. /**
  6874. * Return HTML form to allow prerequisites selection
  6875. * @param integer Item ID
  6876. * @return string HTML form
  6877. */
  6878. public function display_item_prerequisites_form($item_id) {
  6879. $course_id = api_get_course_int_id();
  6880. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  6881. $item_id = intval($item_id);
  6882. /* Current prerequisite */
  6883. $sql = "SELECT * FROM $tbl_lp_item WHERE c_id = $course_id AND id = " . $item_id;
  6884. $result = Database::query($sql);
  6885. $row = Database::fetch_array($result);
  6886. $preq_id = $row['prerequisite'];
  6887. //$preq_mastery = $row['mastery_score'];
  6888. //$preq_max = $row['max_score'];
  6889. $return = $this->display_manipulate($item_id, TOOL_DOCUMENT);
  6890. $return .= '<div class="sectioncomment">';
  6891. $return .= '<form method="POST">';
  6892. $return = '<legend>';
  6893. $return .= get_lang('AddEditPrerequisites');
  6894. $return .= '</legend>';
  6895. $return .= '<table class="data_table" style="width:650px">';
  6896. $return .= '<tr>';
  6897. $return .= '<th height="24">' . get_lang('Prerequisites') . '</th>';
  6898. $return .= '<th width="70" height="24">' . get_lang('Minimum') . '</th>';
  6899. $return .= '<th width="70" height="24">' . get_lang('Maximum') . '</th>';
  6900. $return .= '</tr>';
  6901. // Adding the none option to the prerequisites see http://www.chamilo.org/es/node/146
  6902. $return .= '<tr >';
  6903. $return .= '<td colspan="3" class="radio">';
  6904. $return .= '<input checked="checked" id="idNone" name="prerequisites" style="margin-left:0px; margin-right:10px;" type="radio" />';
  6905. $return .= '<label for="idNone">' . get_lang('None') . '</label>';
  6906. $return .= '</tr>';
  6907. $sql = "SELECT * FROM " . $tbl_lp_item . " WHERE c_id = $course_id AND lp_id = " . $this->lp_id;
  6908. $result = Database::query($sql);
  6909. $arrLP = array ();
  6910. while ($row = Database :: fetch_array($result)) {
  6911. $arrLP[] = array (
  6912. 'id' => $row['id'],
  6913. 'item_type' => $row['item_type'],
  6914. 'title' => $row['title'],
  6915. 'ref' => $row['ref'],
  6916. 'description' => $row['description'],
  6917. 'parent_item_id' => $row['parent_item_id'],
  6918. 'previous_item_id' => $row['previous_item_id'],
  6919. 'next_item_id' => $row['next_item_id'],
  6920. 'max_score' => $row['max_score'],
  6921. 'min_score' => $row['min_score'],
  6922. 'mastery_score' => $row['mastery_score'],
  6923. 'prerequisite' => $row['prerequisite'],
  6924. 'next_item_id' => $row['next_item_id'],
  6925. 'display_order' => $row['display_order']
  6926. );
  6927. if ($row['ref'] == $preq_id) {
  6928. $preq_mastery = $row['mastery_score'];
  6929. $preq_max = $row['max_score'];
  6930. }
  6931. }
  6932. $this->tree_array($arrLP);
  6933. $arrLP = $this->arrMenu;
  6934. unset ($this->arrMenu);
  6935. for ($i = 0; $i < count($arrLP); $i++) {
  6936. if ($arrLP[$i]['id'] == $item_id)
  6937. break;
  6938. $return .= '<tr>';
  6939. $return .= '<td class="radio"' . (($arrLP[$i]['item_type'] != TOOL_QUIZ && $arrLP[$i]['item_type'] != TOOL_HOTPOTATOES) ? ' colspan="3"' : '') . '>';
  6940. $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'] . '" />';
  6941. $icon_name = str_replace(' ', '', $arrLP[$i]['item_type']);
  6942. if (file_exists('../img/lp_' . $icon_name . '.png')) {
  6943. $return .= '<img alt="" src="../img/lp_' . $icon_name . '.png" style="margin-right:5px;" title="" />';
  6944. } else
  6945. if (file_exists('../img/lp_' . $icon_name . '.gif')) {
  6946. $return .= '<img alt="" src="../img/lp_' . $icon_name . '.gif" style="margin-right:5px;" title="" />';
  6947. } else {
  6948. $return .= Display::return_icon('folder_document.gif','',array('style'=>'margin-right:5px;'));
  6949. }
  6950. $return .= '<label for="id' . $arrLP[$i]['id'] . '">' . $arrLP[$i]['title'] . '</label>';
  6951. $return .= '</td>';
  6952. //$return .= '<td class="radio"' . (($arrLP[$i]['item_type'] != TOOL_HOTPOTATOES) ? ' colspan="3"' : '') . ' />';
  6953. if ($arrLP[$i]['item_type'] == TOOL_QUIZ) {
  6954. $return .= '<td class="exercise" style="border:1px solid #ccc;">';
  6955. $return .= '<center><input size="4" maxlength="3" name="min_' . $arrLP[$i]['id'] . '" type="text" value="' . (($arrLP[$i]['id'] == $preq_id) ? $preq_mastery : 0) . '" /></center>';
  6956. $return .= '</td>';
  6957. $return .= '<td class="exercise" style="border:1px solid #ccc;">';
  6958. $return .= '<center><input size="4" maxlength="3" name="max_' . $arrLP[$i]['id'] . '" type="text" value="' . $arrLP[$i]['max_score'] . '" disabled="true" /></center>';
  6959. $return .= '</td>';
  6960. }
  6961. if ($arrLP[$i]['item_type'] == TOOL_HOTPOTATOES) {
  6962. $return .= '<td class="exercise" style="border:1px solid #ccc;">';
  6963. $return .= '<center><input size="4" maxlength="3" name="min_' . $arrLP[$i]['id'] . '" type="text" value="' . (($arrLP[$i]['id'] == $preq_id) ? $preq_mastery : 0) . '" /></center>';
  6964. $return .= '</td>';
  6965. $return .= '<td class="exercise" style="border:1px solid #ccc;">';
  6966. $return .= '<center><input size="4" maxlength="3" name="max_' . $arrLP[$i]['id'] . '" type="text" value="' . $arrLP[$i]['max_score'] . '" disabled="true" /></center>';
  6967. $return .= '</td>';
  6968. }
  6969. $return .= '</tr>';
  6970. }
  6971. $return .= '<tr>';
  6972. $return .= '</tr>';
  6973. $return .= '</table>';
  6974. $return .= '<div style="padding-top:3px;">';
  6975. $return .= '<button class="save" name="submit_button" type="submit">' . get_lang('ModifyPrerequisites') . ' </button></td>';
  6976. $return .= '</div>';
  6977. $return .= '</form>';
  6978. $return .= '</div>';
  6979. return $return;
  6980. }
  6981. /**
  6982. * Return HTML list to allow prerequisites selection for lp
  6983. * @param integer Item ID
  6984. * @return string HTML form
  6985. */
  6986. public function display_lp_prerequisites_list() {
  6987. $course_id = api_get_course_int_id();
  6988. $lp_id = $this->lp_id;
  6989. $tbl_lp = Database :: get_course_table(TABLE_LP_MAIN);
  6990. // get current prerequisite
  6991. $sql = "SELECT * FROM $tbl_lp WHERE c_id = $course_id AND id = $lp_id ";
  6992. $result = Database::query($sql);
  6993. $row = Database :: fetch_array($result);
  6994. $preq_id = $row['prerequisite'];
  6995. $session_id = api_get_session_id();
  6996. $session_condition = api_get_session_condition($session_id);
  6997. $sql = "SELECT * FROM $tbl_lp WHERE c_id = $course_id $session_condition ORDER BY display_order ";
  6998. $rs = Database::query($sql);
  6999. $return = '';
  7000. $return .= '<select name="prerequisites" >';
  7001. $return .= '<option value="0">'.get_lang('None').'</option>';
  7002. if (Database::num_rows($rs) > 0) {
  7003. while ($row = Database::fetch_array($rs)) {
  7004. if ($row['id'] == $lp_id) {
  7005. continue;
  7006. }
  7007. $return .= '<option value="'.$row['id'].'" '.(($row['id']==$preq_id)?' selected ' : '').'>'.$row['name'].'</option>';
  7008. }
  7009. }
  7010. $return .= '</select>';
  7011. return $return;
  7012. }
  7013. /**
  7014. * Creates a list with all the documents in it
  7015. * @return string
  7016. */
  7017. public function get_documents() {
  7018. $course_info = api_get_course_info();
  7019. require_once api_get_path(LIBRARY_PATH).'document.lib.php';
  7020. $document_tree = DocumentManager::get_document_preview($course_info, $this->lp_id);
  7021. return $document_tree;
  7022. }
  7023. /**
  7024. * Creates a list with all the exercises (quiz) in it
  7025. * @return string
  7026. */
  7027. public function get_exercises() {
  7028. $course_id = api_get_course_int_id();
  7029. // New for hotpotatoes.
  7030. $uploadPath = DIR_HOTPOTATOES; //defined in main_api
  7031. $tbl_doc = Database :: get_course_table(TABLE_DOCUMENT);
  7032. $tbl_quiz = Database :: get_course_table(TABLE_QUIZ_TEST);
  7033. $session_id = api_get_session_id();
  7034. $condition_session = api_get_session_condition($session_id);
  7035. $sql_quiz = "SELECT * FROM $tbl_quiz WHERE c_id = $course_id AND active<>'-1' $condition_session ORDER BY title ASC";
  7036. $sql_hot = "SELECT * FROM $tbl_doc WHERE c_id = $course_id AND path LIKE '" . $uploadPath . "/%/%htm%' $condition_session ORDER BY id ASC";
  7037. $res_quiz = Database::query($sql_quiz);
  7038. $res_hot = Database::query($sql_hot);
  7039. $return = '<div class="lp_resource">';
  7040. $return .= '<div class="lp_resource_element">';
  7041. //$return .= Display::return_icon('new_exercice.png', '', array(), 32); //'<img alt="" src="../img/icons/ICON_SIZE_SMALL/exercise.gif" style="margin-right:5px;" title="" />';
  7042. $return .= '<img alt="" src="../img/new_test_small.gif" style="margin-right:5px;" title="" />';
  7043. $return .= '<a href="' . api_get_path(REL_CODE_PATH) . 'exercice/exercise_admin.php?lp_id=' . $this->lp_id . '">' . get_lang('NewExercise') . '</a>';
  7044. $return .= '</div>';
  7045. while ($row_hot = Database :: fetch_array($res_hot)) {
  7046. $return .= '<div class="lp_resource_element">';
  7047. // Display quizhotpotatoes.
  7048. $return .= '<img alt="hp" src="../img/hotpotatoes_s.png" style="margin-right:5px;" title="" width="18px" height="18px" />';
  7049. $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>';
  7050. $return .= '</div>';
  7051. }
  7052. while ($row_quiz = Database :: fetch_array($res_quiz)) {
  7053. $return .= '<div class="lp_resource_element">';
  7054. $return .= '<img alt="" src="../img/quizz_small.gif" style="margin-right:5px;" title="" />';
  7055. //$return .= Display::return_icon('quiz.png', '', array(), 32); //'<img alt="" src="../img/icons/22/exercise.gif" style="margin-right:5px;" title="" />';
  7056. $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 . '">' .
  7057. Security :: remove_XSS(cut($row_quiz['title'], 80)).'</a>';
  7058. //$return .= $row_quiz['title'];
  7059. $return .= '</div>';
  7060. }
  7061. $return .= '</div>';
  7062. return $return;
  7063. }
  7064. /**
  7065. * Creates a list with all the links in it
  7066. * @return string
  7067. */
  7068. public function get_links() {
  7069. $course_id = api_get_course_int_id();
  7070. $tbl_link = Database :: get_course_table(TABLE_LINK);
  7071. $session_id = api_get_session_id();
  7072. $condition_session = api_get_session_condition($session_id);
  7073. $sql_link = "SELECT * FROM $tbl_link WHERE c_id = ".$course_id." $condition_session ORDER BY title ASC";
  7074. $res_link = Database::query($sql_link);
  7075. //$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>';
  7076. $return = '<div class="lp_resource">';
  7077. $return .= '<div class="lp_resource_element">';
  7078. $return .= '<img alt="" src="../img/linksnew.gif" style="margin-right:5px;width:16px" title="" />';
  7079. $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>';
  7080. $return .= '</div>';
  7081. while ($row_link = Database :: fetch_array($res_link)) {
  7082. $return .= '<div class="lp_resource_element">';
  7083. $return .= '<img alt="" src="../img/lp_link.gif" style="margin-right:5px;" title="" />';
  7084. $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>';
  7085. $return .= '</div>';
  7086. }
  7087. /*if (Database :: num_rows($res_link) == 0)
  7088. $return .= '<div class="lp_resource_element">' . get_lang('NoLinksAvailable') . '</div>';
  7089. */
  7090. $return .= '</div>';
  7091. return $return;
  7092. }
  7093. /**
  7094. * Creates a list with all the student publications in it
  7095. * @return unknown
  7096. */
  7097. public function get_student_publications() {
  7098. $course_id = api_get_course_int_id();
  7099. $tbl_student = Database :: get_course_table(TABLE_STUDENT_PUBLICATION);
  7100. $session_id = api_get_session_id();
  7101. $condition_session = api_get_session_condition($session_id);
  7102. $sql_student = "SELECT * FROM $tbl_student WHERE c_id = ".$course_id." $condition_session ORDER BY title ASC";
  7103. $res_student = Database::query($sql_student);
  7104. //$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>';
  7105. $return = '<div class="lp_resource" >';
  7106. $return .= '<div class="lp_resource_element">';
  7107. $return .= '<img align="left" alt="" src="../img/works_small.gif" style="margin-right:5px;" title="" />';
  7108. $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>';
  7109. $return .= '</div>';
  7110. $return .= '</div>';
  7111. return $return;
  7112. }
  7113. /**
  7114. * Creates a list with all the forums in it
  7115. * @return string
  7116. */
  7117. public function get_forums() {
  7118. require_once '../forum/forumfunction.inc.php';
  7119. require_once '../forum/forumconfig.inc.php';
  7120. $a_forums = get_forums();
  7121. //$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>';
  7122. $return = '<div class="lp_resource">';
  7123. $return .= '<div class="lp_resource_element">';
  7124. $return .= '<img alt="" src="../img/forum_new_small.gif" style="margin-right:5px;" title="" />';
  7125. $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>';
  7126. $return .= '</div>';
  7127. foreach ($a_forums as $forum) {
  7128. $return .= '<div class="lp_resource_element_no_link">';
  7129. $return .= '<script type="text/javascript">
  7130. function toggle_forum(forum_id){
  7131. if(document.getElementById("forum_"+forum_id+"_content").style.display == "none"){
  7132. document.getElementById("forum_"+forum_id+"_content").style.display = "block";
  7133. document.getElementById("forum_"+forum_id+"_opener").src = "' . api_get_path(WEB_IMG_PATH) . 'remove.gif";
  7134. } else {
  7135. document.getElementById("forum_"+forum_id+"_content").style.display = "none";
  7136. document.getElementById("forum_"+forum_id+"_opener").src = "' . api_get_path(WEB_IMG_PATH) . 'add.gif";
  7137. }
  7138. }
  7139. </script>';
  7140. if (!empty($forum['forum_id'])) {
  7141. $return .= '<img alt="" src="../img/lp_forum.gif" style="margin-right:5px;" title="" />';
  7142. $return .= '<a style="cursor:hand" onclick="javascript: toggle_forum(' . $forum['forum_id'] . ')" style="vertical-align:middle">
  7143. <img src="' . api_get_path(WEB_IMG_PATH) . 'add.gif" id="forum_' . $forum['forum_id'] . '_opener" align="absbottom" />
  7144. </a>
  7145. <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>
  7146. <ul style="display:none" id="forum_' . $forum['forum_id'] . '_content">';
  7147. }
  7148. $a_threads = get_threads($forum['forum_id']);
  7149. if (is_array($a_threads)) {
  7150. foreach ($a_threads as $thread) {
  7151. $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>';
  7152. }
  7153. }
  7154. $return .= '</ul></div>';
  7155. }
  7156. $return .= '</div>';
  7157. return $return;
  7158. }
  7159. /**
  7160. * // TODO: The output encoding should be equal to the system encoding.
  7161. *
  7162. * Exports the learning path as a SCORM package. This is the main function that
  7163. * gathers the content, transforms it, writes the imsmanifest.xml file, zips the
  7164. * whole thing and returns the zip.
  7165. *
  7166. * This method needs to be called in PHP5, as it will fail with non-adequate
  7167. * XML package (like the ones for PHP4), and it is *not* a static method, so
  7168. * you need to call it on a learnpath object.
  7169. * @TODO The method might be redefined later on in the scorm class itself to avoid
  7170. * creating a SCORM structure if there is one already. However, if the initial SCORM
  7171. * path has been modified, it should use the generic method here below.
  7172. * @TODO link this function with the export_lp() function in the same class
  7173. * @param string Optional name of zip file. If none, title of learnpath is
  7174. * domesticated and trailed with ".zip"
  7175. * @return string Returns the zip package string, or null if error
  7176. */
  7177. public function scorm_export() {
  7178. global $_course;
  7179. $course_id = api_get_course_int_id();
  7180. // Remove memory and time limits as much as possible as this might be a long process...
  7181. if (function_exists('ini_set')) {
  7182. $mem = ini_get('memory_limit');
  7183. if (substr($mem, -1, 1) == 'M') {
  7184. $mem_num = substr($mem, 0, -1);
  7185. if ($mem_num < 128) {
  7186. ini_set('memory_limit', '128M');
  7187. }
  7188. } else {
  7189. ini_set('memory_limit', '128M');
  7190. }
  7191. ini_set('max_execution_time', 600);
  7192. //} else {
  7193. //error_log('Scorm export: could not change memory and time limits', 0);
  7194. }
  7195. // Create the zip handler (this will remain available throughout the method).
  7196. $archive_path = api_get_path(SYS_ARCHIVE_PATH);
  7197. $sys_course_path = api_get_path(SYS_COURSE_PATH);
  7198. $temp_dir_short = uniqid();
  7199. $temp_zip_dir = $archive_path.'/'.$temp_dir_short;
  7200. $temp_zip_file = $temp_zip_dir.'/'.md5(time()).'.zip';
  7201. $zip_folder = new PclZip($temp_zip_file);
  7202. $current_course_path = api_get_path(SYS_COURSE_PATH).api_get_course_path();
  7203. $root_path = $main_path = api_get_path(SYS_PATH);
  7204. $files_cleanup = array();
  7205. // Place to temporarily stash the zipfiles.
  7206. // create the temp dir if it doesn't exist
  7207. // or do a cleanup befor creating the zipfile.
  7208. if (!is_dir($temp_zip_dir)) {
  7209. mkdir($temp_zip_dir, api_get_permissions_for_new_directories());
  7210. } else {
  7211. // Cleanup: Check the temp dir for old files and delete them.
  7212. $handle = opendir($temp_zip_dir);
  7213. while (false !== ($file = readdir($handle))) {
  7214. if ($file != '.' && $file != '..') {
  7215. unlink("$temp_zip_dir/$file");
  7216. }
  7217. }
  7218. closedir($handle);
  7219. }
  7220. $zip_files = $zip_files_abs = $zip_files_dist = array();
  7221. if (is_dir($current_course_path.'/scorm/'.$this->path) && is_file($current_course_path.'/scorm/'.$this->path.'/imsmanifest.xml')) {
  7222. // Remove the possible . at the end of the path.
  7223. $dest_path_to_lp = substr($this->path, -1) == '.' ? substr($this->path, 0, -1) : $this->path;
  7224. $dest_path_to_scorm_folder = str_replace('//','/',$temp_zip_dir.'/scorm/'.$dest_path_to_lp);
  7225. mkdir($dest_path_to_scorm_folder, api_get_permissions_for_new_directories(), true);
  7226. $zip_files_dist = copyr($current_course_path.'/scorm/'.$this->path, $dest_path_to_scorm_folder, array('imsmanifest'), $zip_files);
  7227. }
  7228. // Build a dummy imsmanifest structure. Do not add to the zip yet (we still need it).
  7229. // This structure is developed following regulations for SCORM 1.2 packaging in the SCORM 1.2 Content
  7230. // Aggregation Model official document, secion "2.3 Content Packaging".
  7231. $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.
  7232. $root = $xmldoc->createElement('manifest');
  7233. $root->setAttribute('identifier', 'SingleCourseManifest');
  7234. $root->setAttribute('version', '1.1');
  7235. $root->setAttribute('xmlns', 'http://www.imsproject.org/xsd/imscp_rootv1p1p2');
  7236. $root->setAttribute('xmlns:adlcp', 'http://www.adlnet.org/xsd/adlcp_rootv1p2');
  7237. $root->setAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance');
  7238. $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');
  7239. // Build mandatory sub-root container elements.
  7240. $metadata = $xmldoc->createElement('metadata');
  7241. $md_schema = $xmldoc->createElement('schema', 'ADL SCORM');
  7242. $metadata->appendChild($md_schema);
  7243. $md_schemaversion = $xmldoc->createElement('schemaversion', '1.2');
  7244. $metadata->appendChild($md_schemaversion);
  7245. $root->appendChild($metadata);
  7246. $organizations = $xmldoc->createElement('organizations');
  7247. $resources = $xmldoc->createElement('resources');
  7248. // Build the only organization we will use in building our learnpaths.
  7249. $organizations->setAttribute('default', 'chamilo_scorm_export');
  7250. $organization = $xmldoc->createElement('organization');
  7251. $organization->setAttribute('identifier', 'chamilo_scorm_export');
  7252. // To set the title of the SCORM entity (=organization), we take the name given
  7253. // in Chamilo and convert it to HTML entities using the Chamilo charset (not the
  7254. // learning path charset) as it is the encoding that defines how it is stored
  7255. // in the database. Then we convert it to HTML entities again as the "&" character
  7256. // alone is not authorized in XML (must be &amp;).
  7257. // The title is then decoded twice when extracting (see scorm::parse_manifest).
  7258. $org_title = $xmldoc->createElement('title', api_utf8_encode($this->get_name()));
  7259. $organization->appendChild($org_title);
  7260. // For each element, add it to the imsmanifest structure, then add it to the zip.
  7261. // Always call the learnpathItem->scorm_export() method to change it to the SCORM format.
  7262. $link_updates = array();
  7263. foreach ($this->items as $index => $item) {
  7264. if (!in_array($item->type, array(TOOL_QUIZ, TOOL_FORUM, TOOL_THREAD, TOOL_LINK, TOOL_STUDENTPUBLICATION))) {
  7265. // Get included documents from this item.
  7266. if ($item->type == 'sco')
  7267. $inc_docs = $item->get_resources_from_source(null, api_get_path(SYS_COURSE_PATH).api_get_course_path().'/'.'scorm/'.$this->path.'/'.$item->get_path());
  7268. else
  7269. $inc_docs = $item->get_resources_from_source();
  7270. // Give a child element <item> to the <organization> element.
  7271. $my_item_id = $item->get_id();
  7272. $my_item = $xmldoc->createElement('item');
  7273. $my_item->setAttribute('identifier', 'ITEM_'.$my_item_id);
  7274. $my_item->setAttribute('identifierref', 'RESOURCE_'.$my_item_id);
  7275. $my_item->setAttribute('isvisible', 'true');
  7276. // Give a child element <title> to the <item> element.
  7277. $my_title = $xmldoc->createElement('title', htmlspecialchars(api_utf8_encode($item->get_title()), ENT_QUOTES, 'UTF-8'));
  7278. $my_item->appendChild($my_title);
  7279. // Give a child element <adlcp:prerequisites> to the <item> element.
  7280. $my_prereqs = $xmldoc->createElement('adlcp:prerequisites', $this->get_scorm_prereq_string($my_item_id));
  7281. $my_prereqs->setAttribute('type', 'aicc_script');
  7282. $my_item->appendChild($my_prereqs);
  7283. // Give a child element <adlcp:maxtimeallowed> to the <item> element - not yet supported.
  7284. //$xmldoc->createElement('adlcp:maxtimeallowed','');
  7285. // Give a child element <adlcp:timelimitaction> to the <item> element - not yet supported.
  7286. //$xmldoc->createElement('adlcp:timelimitaction','');
  7287. // Give a child element <adlcp:datafromlms> to the <item> element - not yet supported.
  7288. //$xmldoc->createElement('adlcp:datafromlms','');
  7289. // Give a child element <adlcp:masteryscore> to the <item> element.
  7290. $my_masteryscore = $xmldoc->createElement('adlcp:masteryscore', $item->get_mastery_score());
  7291. $my_item->appendChild($my_masteryscore);
  7292. // Attach this item to the organization element or hits parent if there is one.
  7293. if (!empty($item->parent) && $item->parent != 0) {
  7294. $children = $organization->childNodes;
  7295. $possible_parent = &$this->get_scorm_xml_node($children, 'ITEM_'.$item->parent);
  7296. if (is_object($possible_parent)) {
  7297. $possible_parent->appendChild($my_item);
  7298. } else {
  7299. if ($this->debug > 0) { error_log('Parent ITEM_'.$item->parent.' of item ITEM_'.$my_item_id.' not found'); }
  7300. }
  7301. } else {
  7302. if ($this->debug > 0) { error_log('No parent'); }
  7303. $organization->appendChild($my_item);
  7304. }
  7305. // Get the path of the file(s) from the course directory root.
  7306. $my_file_path = $item->get_file_path('scorm/'.$this->path.'/');
  7307. //$my_xml_file_path = api_htmlentities(api_utf8_encode($my_file_path), ENT_QUOTES, 'UTF-8');
  7308. $my_xml_file_path = $my_file_path;
  7309. $my_sub_dir = dirname($my_file_path);
  7310. $my_sub_dir = str_replace('\\', '/', $my_sub_dir);
  7311. //$my_xml_sub_dir = api_htmlentities(api_utf8_encode($my_sub_dir), ENT_QUOTES, 'UTF-8');
  7312. $my_xml_sub_dir = $my_sub_dir;
  7313. // Give a <resource> child to the <resources> element
  7314. $my_resource = $xmldoc->createElement('resource');
  7315. $my_resource->setAttribute('identifier', 'RESOURCE_'.$item->get_id());
  7316. $my_resource->setAttribute('type', 'webcontent');
  7317. $my_resource->setAttribute('href', $my_xml_file_path);
  7318. // adlcp:scormtype can be either 'sco' or 'asset'.
  7319. if ($item->type == 'sco') {
  7320. $my_resource->setAttribute('adlcp:scormtype', 'sco');
  7321. } else {
  7322. $my_resource->setAttribute('adlcp:scormtype', 'asset');
  7323. }
  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. // Dependency to other files - not yet supported.
  7331. $i = 1;
  7332. foreach ($inc_docs as $doc_info) {
  7333. if (count($doc_info) < 1 || empty($doc_info[0])) { continue; }
  7334. $my_dep = $xmldoc->createElement('resource');
  7335. $res_id = 'RESOURCE_'.$item->get_id().'_'.$i;
  7336. $my_dep->setAttribute('identifier', $res_id);
  7337. $my_dep->setAttribute('type', 'webcontent');
  7338. $my_dep->setAttribute('adlcp:scormtype', 'asset');
  7339. $my_dep_file = $xmldoc->createElement('file');
  7340. // Check type of URL.
  7341. //error_log(__LINE__.'Now dealing with '.$doc_info[0].' of type '.$doc_info[1].'-'.$doc_info[2], 0);
  7342. if ($doc_info[1] == 'remote') {
  7343. // Remote file. Save url as is.
  7344. $my_dep_file->setAttribute('href', $doc_info[0]);
  7345. $my_dep->setAttribute('xml:base', '');
  7346. } elseif ($doc_info[1] == 'local') {
  7347. switch ($doc_info[2]) {
  7348. case 'url': // Local URL - save path as url for now, don't zip file.
  7349. $abs_path = api_get_path(SYS_PATH).str_replace(api_get_path(WEB_PATH), '', $doc_info[0]);
  7350. $current_dir = dirname($abs_path);
  7351. $current_dir = str_replace('\\', '/', $current_dir);
  7352. $file_path = realpath($abs_path);
  7353. $file_path = str_replace('\\', '/', $file_path);
  7354. $my_dep_file->setAttribute('href', $file_path);
  7355. $my_dep->setAttribute('xml:base', '');
  7356. if (strstr($file_path, $main_path) !== false) {
  7357. // The calculated real path is really inside Chamilo's root path.
  7358. // Reduce file path to what's under the DocumentRoot.
  7359. $file_path = substr($file_path, strlen($root_path) - 1);
  7360. //echo $file_path;echo '<br /><br />';
  7361. //error_log(__LINE__.'Reduced url path: '.$file_path, 0);
  7362. $zip_files_abs[] = $file_path;
  7363. $link_updates[$my_file_path][] = array('orig' => $doc_info[0], 'dest' => $file_path);
  7364. $my_dep_file->setAttribute('href', $file_path);
  7365. $my_dep->setAttribute('xml:base', '');
  7366. }
  7367. elseif (empty($file_path)) {
  7368. /*$document_root = substr(api_get_path(SYS_PATH), 0, strpos(api_get_path(SYS_PATH), api_get_path(REL_PATH)));
  7369. if (strpos($document_root, -1) == '/') {
  7370. $document_root = substr(0, -1, $document_root);
  7371. }*/
  7372. $file_path = $_SERVER['DOCUMENT_ROOT'].$abs_path;
  7373. $file_path = str_replace('//', '/', $file_path);
  7374. if (file_exists($file_path)) {
  7375. $file_path = substr($file_path, strlen($current_dir)); // We get the relative path.
  7376. $zip_files[] = $my_sub_dir.'/'.$file_path;
  7377. $link_updates[$my_file_path][] = array('orig' => $doc_info[0], 'dest' => $file_path);
  7378. $my_dep_file->setAttribute('href', $file_path);
  7379. $my_dep->setAttribute('xml:base', '');
  7380. }
  7381. }
  7382. break;
  7383. case 'abs': // Absolute path from DocumentRoot. Save file and leave path as is in the zip.
  7384. $my_dep_file->setAttribute('href', $doc_info[0]);
  7385. $my_dep->setAttribute('xml:base', '');
  7386. //$current_dir = str_replace('\\', '/', dirname($current_course_path.'/'.$item->get_file_path())).'/';
  7387. // The next lines fix a bug when using the "subdir" mode of Chamilo, whereas
  7388. // an image path would be constructed as /var/www/subdir/subdir/img/foo.bar
  7389. $abs_img_path_without_subdir = $doc_info[0];
  7390. $relp = api_get_path(REL_PATH); // The url-append config param.
  7391. $pos = strpos($abs_img_path_without_subdir, $relp);
  7392. if ($pos === 0) {
  7393. $abs_img_path_without_subdir = '/'.substr($abs_img_path_without_subdir, strlen($relp));
  7394. }
  7395. //$file_path = realpath(api_get_path(SYS_PATH).$doc_info[0]);
  7396. $file_path = realpath(api_get_path(SYS_PATH).$abs_img_path_without_subdir);
  7397. $file_path = str_replace('\\', '/', $file_path);
  7398. $file_path = str_replace('//', '/', $file_path);
  7399. //error_log(__LINE__.'Abs path: '.$file_path, 0);
  7400. // Prepare the current directory path (until just under 'document') with a trailing slash.
  7401. $cur_path = substr($current_course_path, -1) == '/' ? $current_course_path : $current_course_path.'/';
  7402. // Check if the current document is in that path.
  7403. if (strstr($file_path, $cur_path) !== false) {
  7404. // The document is in that path, now get the relative path
  7405. // to the containing document.
  7406. $orig_file_path = dirname($cur_path.$my_file_path).'/';
  7407. $orig_file_path = str_replace('\\', '/', $orig_file_path);
  7408. $relative_path = '';
  7409. if (strstr($file_path, $cur_path) !== false) {
  7410. $relative_path = substr($file_path, strlen($orig_file_path));
  7411. $file_path = substr($file_path, strlen($cur_path));
  7412. } else {
  7413. // This case is still a problem as it's difficult to calculate a relative path easily
  7414. // might still generate wrong links.
  7415. //$file_path = substr($file_path,strlen($cur_path));
  7416. // Calculate the directory path to the current file (without trailing slash).
  7417. $my_relative_path = dirname($file_path);
  7418. $my_relative_path = str_replace('\\', '/', $my_relative_path);
  7419. $my_relative_file = basename($file_path);
  7420. // Calculate the directory path to the containing file (without trailing slash).
  7421. $my_orig_file_path = substr($orig_file_path, 0, -1);
  7422. $dotdot = '';
  7423. $subdir = '';
  7424. while (strstr($my_relative_path, $my_orig_file_path) === false && (strlen($my_orig_file_path) > 1) && (strlen($my_relative_path) > 1)) {
  7425. $my_relative_path2 = dirname($my_relative_path);
  7426. $my_relative_path2 = str_replace('\\', '/', $my_relative_path2);
  7427. $my_orig_file_path = dirname($my_orig_file_path);
  7428. $my_orig_file_path = str_replace('\\', '/', $my_orig_file_path);
  7429. $subdir = substr($my_relative_path, strlen($my_relative_path2) + 1).'/'.$subdir;
  7430. $dotdot += '../';
  7431. $my_relative_path = $my_relative_path2;
  7432. }
  7433. $relative_path = $dotdot.$subdir.$my_relative_file;
  7434. }
  7435. // Put the current document in the zip (this array is the array
  7436. // that will manage documents already in the course folder - relative).
  7437. $zip_files[] = $file_path;
  7438. // Update the links to the current document in the containing document (make them relative).
  7439. $link_updates[$my_file_path][] = array('orig' => $doc_info[0], 'dest' => $relative_path);
  7440. $my_dep_file->setAttribute('href', $file_path);
  7441. $my_dep->setAttribute('xml:base', '');
  7442. }
  7443. elseif (strstr($file_path,$main_path) !== false) {
  7444. // The calculated real path is really inside Chamilo's root path.
  7445. // Reduce file path to what's under the DocumentRoot.
  7446. $file_path = substr($file_path, strlen($root_path));
  7447. //echo $file_path;echo '<br /><br />';
  7448. //error_log('Reduced path: '.$file_path, 0);
  7449. $zip_files_abs[] = $file_path;
  7450. $link_updates[$my_file_path][] = array('orig' => $doc_info[0], 'dest' => $file_path);
  7451. $my_dep_file->setAttribute('href', 'document/'.$file_path);
  7452. $my_dep->setAttribute('xml:base', '');
  7453. }
  7454. elseif (empty($file_path)) {
  7455. /*$document_root = substr(api_get_path(SYS_PATH), 0, strpos(api_get_path(SYS_PATH), api_get_path(REL_PATH)));
  7456. if(strpos($document_root,-1) == '/') {
  7457. $document_root = substr(0, -1, $document_root);
  7458. }*/
  7459. $file_path = $_SERVER['DOCUMENT_ROOT'].$doc_info[0];
  7460. $file_path = str_replace('//', '/', $file_path);
  7461. if (file_exists($file_path)) {
  7462. $file_path = substr($file_path,strlen($current_dir)); // We get the relative path.
  7463. $zip_files[] = $my_sub_dir.'/'.$file_path;
  7464. $link_updates[$my_file_path][] = array('orig' => $doc_info[0], 'dest' => $file_path);
  7465. $my_dep_file->setAttribute('href','document/'.$file_path);
  7466. $my_dep->setAttribute('xml:base', '');
  7467. }
  7468. }
  7469. break;
  7470. 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
  7471. if (substr($doc_info[0], 0, 2) == '..') {
  7472. // Relative path going up.
  7473. $current_dir = dirname($current_course_path.'/'.$item->get_file_path()).'/';
  7474. $current_dir = str_replace('\\', '/', $current_dir);
  7475. $file_path = realpath($current_dir.$doc_info[0]);
  7476. $file_path = str_replace('\\', '/', $file_path);
  7477. //error_log($file_path.' <-> '.$main_path,0);
  7478. if (strstr($file_path, $main_path) !== false) {
  7479. // The calculated real path is really inside Chamilo's root path.
  7480. // Reduce file path to what's under the DocumentRoot.
  7481. $file_path = substr($file_path, strlen($root_path));
  7482. //error_log('Reduced path: '.$file_path, 0);
  7483. $zip_files_abs[] = $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. } else {
  7489. $zip_files[] = $my_sub_dir.'/'.$doc_info[0];
  7490. $my_dep_file->setAttribute('href', $doc_info[0]);
  7491. $my_dep->setAttribute('xml:base', $my_xml_sub_dir);
  7492. }
  7493. break;
  7494. default:
  7495. $my_dep_file->setAttribute('href', $doc_info[0]);
  7496. $my_dep->setAttribute('xml:base', '');
  7497. break;
  7498. }
  7499. }
  7500. $my_dep->appendChild($my_dep_file);
  7501. $resources->appendChild($my_dep);
  7502. $dependency = $xmldoc->createElement('dependency');
  7503. $dependency->setAttribute('identifierref', $res_id);
  7504. $my_resource->appendChild($dependency);
  7505. $i++;
  7506. }
  7507. //$my_dependency = $xmldoc->createElement('dependency');
  7508. //$my_dependency->setAttribute('identifierref', '');
  7509. $resources->appendChild($my_resource);
  7510. $zip_files[] = $my_file_path;
  7511. //error_log('File '.$my_file_path. ' added to $zip_files', 0);
  7512. } else {
  7513. // If the item is a quiz or a link or whatever non-exportable, we include a step indicating it.
  7514. if ($item->type == TOOL_LINK) {
  7515. $my_item = $xmldoc->createElement('item');
  7516. $my_item->setAttribute('identifier', 'ITEM_'.$item->get_id());
  7517. $my_item->setAttribute('identifierref', 'RESOURCE_'.$item->get_id());
  7518. $my_item->setAttribute('isvisible', 'true');
  7519. // Give a child element <title> to the <item> element.
  7520. $my_title = $xmldoc->createElement('title', htmlspecialchars(api_utf8_encode($item->get_title()), ENT_QUOTES, 'UTF-8'));
  7521. $my_item->appendChild($my_title);
  7522. // Give a child element <adlcp:prerequisites> to the <item> element.
  7523. $my_prereqs = $xmldoc->createElement('adlcp:prerequisites', $item->get_prereq_string());
  7524. $my_prereqs->setAttribute('type', 'aicc_script');
  7525. $my_item->appendChild($my_prereqs);
  7526. // Give a child element <adlcp:maxtimeallowed> to the <item> element - not yet supported.
  7527. //$xmldoc->createElement('adlcp:maxtimeallowed', '');
  7528. // Give a child element <adlcp:timelimitaction> to the <item> element - not yet supported.
  7529. //$xmldoc->createElement('adlcp:timelimitaction', '');
  7530. // Give a child element <adlcp:datafromlms> to the <item> element - not yet supported.
  7531. //$xmldoc->createElement('adlcp:datafromlms', '');
  7532. // Give a child element <adlcp:masteryscore> to the <item> element.
  7533. $my_masteryscore = $xmldoc->createElement('adlcp:masteryscore', $item->get_mastery_score());
  7534. $my_item->appendChild($my_masteryscore);
  7535. // Attach this item to the organization element or its parent if there is one.
  7536. if (!empty($item->parent) && $item->parent != 0) {
  7537. $children = $organization->childNodes;
  7538. for ($i = 0; $i < $children->length; $i++) {
  7539. $item_temp = $children->item($i);
  7540. if ($item_temp -> nodeName == 'item') {
  7541. if ($item_temp->getAttribute('identifier') == 'ITEM_'.$item->parent) {
  7542. $item_temp -> appendChild($my_item);
  7543. }
  7544. }
  7545. }
  7546. } else {
  7547. $organization->appendChild($my_item);
  7548. }
  7549. $my_file_path = 'link_'.$item->get_id().'.html';
  7550. $sql = 'SELECT url, title FROM '.Database :: get_course_table(TABLE_LINK).' WHERE c_id = '.$course_id.' AND id='.$item->path;
  7551. $rs = Database::query($sql);
  7552. if ($link = Database :: fetch_array($rs)) {
  7553. $url = $link['url'];
  7554. $title = stripslashes($link['title']);
  7555. $links_to_create[$my_file_path] = array('title' => $title, 'url' => $url);
  7556. //$my_xml_file_path = api_htmlentities(api_utf8_encode($my_file_path), ENT_QUOTES, 'UTF-8');
  7557. $my_xml_file_path = $my_file_path;
  7558. $my_sub_dir = dirname($my_file_path);
  7559. $my_sub_dir = str_replace('\\', '/', $my_sub_dir);
  7560. //$my_xml_sub_dir = api_htmlentities(api_utf8_encode($my_sub_dir), ENT_QUOTES, 'UTF-8');
  7561. $my_xml_sub_dir = $my_sub_dir;
  7562. // Give a <resource> child to the <resources> element.
  7563. $my_resource = $xmldoc->createElement('resource');
  7564. $my_resource->setAttribute('identifier', 'RESOURCE_'.$item->get_id());
  7565. $my_resource->setAttribute('type', 'webcontent');
  7566. $my_resource->setAttribute('href', $my_xml_file_path);
  7567. // adlcp:scormtype can be either 'sco' or 'asset'.
  7568. $my_resource->setAttribute('adlcp:scormtype', 'asset');
  7569. // xml:base is the base directory to find the files declared in this resource.
  7570. $my_resource->setAttribute('xml:base', '');
  7571. // give a <file> child to the <resource> element.
  7572. $my_file = $xmldoc->createElement('file');
  7573. $my_file->setAttribute('href', $my_xml_file_path);
  7574. $my_resource->appendChild($my_file);
  7575. $resources->appendChild($my_resource);
  7576. }
  7577. }
  7578. elseif ($item->type == TOOL_QUIZ) {
  7579. require_once api_get_path(SYS_CODE_PATH).'exercice/exercise.class.php';
  7580. $exe_id = $item->path; // Should be using ref when everything will be cleaned up in this regard.
  7581. $exe = new Exercise();
  7582. $exe->read($exe_id);
  7583. $my_item = $xmldoc->createElement('item');
  7584. $my_item->setAttribute('identifier', 'ITEM_'.$item->get_id());
  7585. $my_item->setAttribute('identifierref', 'RESOURCE_'.$item->get_id());
  7586. $my_item->setAttribute('isvisible', 'true');
  7587. // Give a child element <title> to the <item> element.
  7588. $my_title = $xmldoc->createElement('title', htmlspecialchars(api_utf8_encode($item->get_title()), ENT_QUOTES, 'UTF-8'));
  7589. $my_item->appendChild($my_title);
  7590. $my_max_score = $xmldoc->createElement('max_score', $item->get_max());
  7591. //$my_item->appendChild($my_max_score);
  7592. // Give a child element <adlcp:prerequisites> to the <item> element.
  7593. $my_prereqs = $xmldoc->createElement('adlcp:prerequisites', $item->get_prereq_string());
  7594. $my_prereqs->setAttribute('type','aicc_script');
  7595. $my_item->appendChild($my_prereqs);
  7596. // Give a child element <adlcp:masteryscore> to the <item> element.
  7597. $my_masteryscore = $xmldoc->createElement('adlcp:masteryscore', $item->get_mastery_score());
  7598. $my_item->appendChild($my_masteryscore);
  7599. // Attach this item to the organization element or hits parent if there is one.
  7600. if (!empty($item->parent) && $item->parent != 0) {
  7601. $children = $organization->childNodes;
  7602. for ($i = 0; $i < $children->length; $i++) {
  7603. $item_temp = $children->item($i);
  7604. if ($item_temp -> nodeName == 'item') {
  7605. if ($item_temp->getAttribute('identifier') == 'ITEM_'.$item->parent) {
  7606. $item_temp -> appendChild($my_item);
  7607. }
  7608. }
  7609. }
  7610. } else {
  7611. $organization->appendChild($my_item);
  7612. }
  7613. // Include export scripts.
  7614. require_once api_get_path(SYS_CODE_PATH).'exercice/export/scorm/scorm_export.php';
  7615. // Get the path of the file(s) from the course directory root
  7616. //$my_file_path = $item->get_file_path('scorm/'.$this->path.'/');
  7617. $my_file_path = 'quiz_'.$item->get_id().'.html';
  7618. // Write the contents of the exported exercise into a (big) html file
  7619. // to later pack it into the exported SCORM. The file will be removed afterwards.
  7620. $contents = export_exercise($exe_id,true);
  7621. $tmp_file_path = $archive_path.$temp_dir_short.'/'.$my_file_path;
  7622. $res = file_put_contents($tmp_file_path, $contents);
  7623. if ($res === false) { error_log('Could not write into file '.$tmp_file_path.' '.__FILE__.' '.__LINE__, 0); }
  7624. $files_cleanup[] = $tmp_file_path;
  7625. //error_log($tmp_path); die();
  7626. //$my_xml_file_path = api_htmlentities(api_utf8_encode($my_file_path), ENT_QUOTES, 'UTF-8');
  7627. $my_xml_file_path = $my_file_path;
  7628. $my_sub_dir = dirname($my_file_path);
  7629. $my_sub_dir = str_replace('\\', '/', $my_sub_dir);
  7630. //$my_xml_sub_dir = api_htmlentities(api_utf8_encode($my_sub_dir), ENT_QUOTES, 'UTF-8');
  7631. $my_xml_sub_dir = $my_sub_dir;
  7632. // Give a <resource> child to the <resources> element.
  7633. $my_resource = $xmldoc->createElement('resource');
  7634. $my_resource->setAttribute('identifier', 'RESOURCE_'.$item->get_id());
  7635. $my_resource->setAttribute('type', 'webcontent');
  7636. $my_resource->setAttribute('href', $my_xml_file_path);
  7637. // adlcp:scormtype can be either 'sco' or 'asset'.
  7638. $my_resource->setAttribute('adlcp:scormtype', 'sco');
  7639. // xml:base is the base directory to find the files declared in this resource.
  7640. $my_resource->setAttribute('xml:base', '');
  7641. // Give a <file> child to the <resource> element.
  7642. $my_file = $xmldoc->createElement('file');
  7643. $my_file->setAttribute('href', $my_xml_file_path);
  7644. $my_resource->appendChild($my_file);
  7645. // Get included docs.
  7646. $inc_docs = $item->get_resources_from_source(null,$tmp_file_path);
  7647. // Dependency to other files - not yet supported.
  7648. $i = 1;
  7649. foreach ($inc_docs as $doc_info) {
  7650. if (count($doc_info) < 1 || empty($doc_info[0])) { continue; }
  7651. $my_dep = $xmldoc->createElement('resource');
  7652. $res_id = 'RESOURCE_'.$item->get_id().'_'.$i;
  7653. $my_dep->setAttribute('identifier', $res_id);
  7654. $my_dep->setAttribute('type', 'webcontent');
  7655. $my_dep->setAttribute('adlcp:scormtype', 'asset');
  7656. $my_dep_file = $xmldoc->createElement('file');
  7657. // Check type of URL.
  7658. //error_log(__LINE__.'Now dealing with '.$doc_info[0].' of type '.$doc_info[1].'-'.$doc_info[2], 0);
  7659. if ($doc_info[1] == 'remote') {
  7660. // Remote file. Save url as is.
  7661. $my_dep_file->setAttribute('href', $doc_info[0]);
  7662. $my_dep->setAttribute('xml:base', '');
  7663. } elseif ($doc_info[1] == 'local') {
  7664. switch ($doc_info[2]) {
  7665. case 'url': // Local URL - save path as url for now, don't zip file.
  7666. // Save file but as local file (retrieve from URL).
  7667. $abs_path = api_get_path(SYS_PATH).str_replace(api_get_path(WEB_PATH), '', $doc_info[0]);
  7668. $current_dir = dirname($abs_path);
  7669. $current_dir = str_replace('\\', '/', $current_dir);
  7670. $file_path = realpath($abs_path);
  7671. $file_path = str_replace('\\', '/', $file_path);
  7672. $my_dep_file->setAttribute('href', 'document/'.$file_path);
  7673. $my_dep->setAttribute('xml:base', '');
  7674. if (strstr($file_path, $main_path) !== false) {
  7675. // The calculated real path is really inside the chamilo root path.
  7676. // Reduce file path to what's under the DocumentRoot.
  7677. $file_path = substr($file_path, strlen($root_path));
  7678. //echo $file_path;echo '<br /><br />';
  7679. //error_log('Reduced path: '.$file_path, 0);
  7680. $zip_files_abs[] = $file_path;
  7681. $link_updates[$my_file_path][] = array('orig' => $doc_info[0], 'dest' => 'document/'.$file_path);
  7682. $my_dep_file->setAttribute('href', 'document/'.$file_path);
  7683. $my_dep->setAttribute('xml:base', '');
  7684. }
  7685. elseif (empty($file_path)) {
  7686. /*$document_root = substr(api_get_path(SYS_PATH), 0, strpos(api_get_path(SYS_PATH),api_get_path(REL_PATH)));
  7687. if (strpos($document_root,-1) == '/') {
  7688. $document_root = substr(0, -1, $document_root);
  7689. }*/
  7690. $file_path = $_SERVER['DOCUMENT_ROOT'].$abs_path;
  7691. $file_path = str_replace('//', '/', $file_path);
  7692. if (file_exists($file_path)) {
  7693. $file_path = substr($file_path, strlen($current_dir)); // We get the relative path.
  7694. $zip_files[] = $my_sub_dir.'/'.$file_path;
  7695. $link_updates[$my_file_path][] = array('orig' => $doc_info[0], 'dest' => 'document/'.$file_path);
  7696. $my_dep_file->setAttribute('href', 'document/'.$file_path);
  7697. $my_dep->setAttribute('xml:base', '');
  7698. }
  7699. }
  7700. break;
  7701. case 'abs': // Absolute path from DocumentRoot. Save file and leave path as is in the zip.
  7702. $current_dir = dirname($current_course_path.'/'.$item->get_file_path()).'/';
  7703. $current_dir = str_replace('\\', '/', $current_dir);
  7704. $file_path = realpath($doc_info[0]);
  7705. $file_path = str_replace('\\', '/', $file_path);
  7706. $my_dep_file->setAttribute('href', $file_path);
  7707. $my_dep->setAttribute('xml:base', '');
  7708. if (strstr($file_path,$main_path) !== false) {
  7709. // The calculated real path is really inside the chamilo root path.
  7710. // Reduce file path to what's under the DocumentRoot.
  7711. $file_path = substr($file_path, strlen($root_path));
  7712. //echo $file_path;echo '<br /><br />';
  7713. //error_log('Reduced path: '.$file_path, 0);
  7714. $zip_files_abs[] = $file_path;
  7715. $link_updates[$my_file_path][] = array('orig' => $doc_info[0], 'dest' => $file_path);
  7716. $my_dep_file->setAttribute('href', 'document/'.$file_path);
  7717. $my_dep->setAttribute('xml:base', '');
  7718. }
  7719. elseif (empty($file_path)) {
  7720. /*$document_root = substr(api_get_path(SYS_PATH), 0, strpos(api_get_path(SYS_PATH), api_get_path(REL_PATH)));
  7721. if (strpos($document_root,-1) == '/') {
  7722. $document_root = substr(0, -1, $document_root);
  7723. }*/
  7724. $file_path = $_SERVER['DOCUMENT_ROOT'].$doc_info[0];
  7725. $file_path = str_replace('//', '/', $file_path);
  7726. if (file_exists($file_path)) {
  7727. $file_path = substr($file_path,strlen($current_dir)); // We get the relative path.
  7728. $zip_files[] = $my_sub_dir.'/'.$file_path;
  7729. $link_updates[$my_file_path][] = array('orig' => $doc_info[0], 'dest' => $file_path);
  7730. $my_dep_file->setAttribute('href', 'document/'.$file_path);
  7731. $my_dep->setAttribute('xml:base', '');
  7732. }
  7733. }
  7734. break;
  7735. 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
  7736. if (substr($doc_info[0], 0, 2) == '..') {
  7737. // Relative path going up.
  7738. $current_dir = dirname($current_course_path.'/'.$item->get_file_path()).'/';
  7739. $current_dir = str_replace('\\', '/', $current_dir);
  7740. $file_path = realpath($current_dir.$doc_info[0]);
  7741. $file_path = str_replace('\\', '/', $file_path);
  7742. //error_log($file_path.' <-> '.$main_path, 0);
  7743. if (strstr($file_path, $main_path) !== false) {
  7744. // The calculated real path is really inside Chamilo's root path.
  7745. // Reduce file path to what's under the DocumentRoot.
  7746. $file_path = substr($file_path, strlen($root_path));
  7747. $file_path_dest = $file_path;
  7748. // File path is courses/CHAMILO/document/....
  7749. $info_file_path = explode('/', $file_path);
  7750. if ($info_file_path[0] == 'courses') { // Add character "/" in file path.
  7751. $file_path_dest = 'document/'.$file_path;
  7752. }
  7753. //error_log('Reduced path: '.$file_path, 0);
  7754. $zip_files_abs[] = $file_path;
  7755. $link_updates[$my_file_path][] = array('orig' => $doc_info[0], 'dest' => $file_path_dest);
  7756. $my_dep_file->setAttribute('href', 'document/'.$file_path);
  7757. $my_dep->setAttribute('xml:base', '');
  7758. }
  7759. } else {
  7760. $zip_files[] = $my_sub_dir.'/'.$doc_info[0];
  7761. $my_dep_file->setAttribute('href', $doc_info[0]);
  7762. $my_dep->setAttribute('xml:base', $my_xml_sub_dir);
  7763. }
  7764. break;
  7765. default:
  7766. $my_dep_file->setAttribute('href', $doc_info[0]); // ../../courses/
  7767. $my_dep->setAttribute('xml:base', '');
  7768. break;
  7769. }
  7770. }
  7771. $my_dep->appendChild($my_dep_file);
  7772. $resources->appendChild($my_dep);
  7773. $dependency = $xmldoc->createElement('dependency');
  7774. $dependency->setAttribute('identifierref', $res_id);
  7775. $my_resource->appendChild($dependency);
  7776. $i++;
  7777. }
  7778. $resources->appendChild($my_resource);
  7779. $zip_files[] = $my_file_path;
  7780. } else {
  7781. // Get the path of the file(s) from the course directory root
  7782. $my_file_path = 'non_exportable.html';
  7783. //$my_xml_file_path = api_htmlentities(api_utf8_encode($my_file_path), ENT_COMPAT, 'UTF-8');
  7784. $my_xml_file_path = $my_file_path;
  7785. $my_sub_dir = dirname($my_file_path);
  7786. $my_sub_dir = str_replace('\\', '/', $my_sub_dir);
  7787. //$my_xml_sub_dir = api_htmlentities(api_utf8_encode($my_sub_dir), ENT_COMPAT, 'UTF-8');
  7788. $my_xml_sub_dir = $my_sub_dir;
  7789. // Give a <resource> child to the <resources> element.
  7790. $my_resource = $xmldoc->createElement('resource');
  7791. $my_resource->setAttribute('identifier', 'RESOURCE_'.$item->get_id());
  7792. $my_resource->setAttribute('type', 'webcontent');
  7793. $my_resource->setAttribute('href', 'document/'.$my_xml_file_path);
  7794. // adlcp:scormtype can be either 'sco' or 'asset'.
  7795. $my_resource->setAttribute('adlcp:scormtype', 'asset');
  7796. // xml:base is the base directory to find the files declared in this resource.
  7797. $my_resource->setAttribute('xml:base', '');
  7798. // Give a <file> child to the <resource> element.
  7799. $my_file = $xmldoc->createElement('file');
  7800. $my_file->setAttribute('href', 'document/'.$my_xml_file_path);
  7801. $my_resource->appendChild($my_file);
  7802. $resources->appendChild($my_resource);
  7803. }
  7804. }
  7805. }
  7806. $organizations->appendChild($organization);
  7807. $root->appendChild($organizations);
  7808. $root->appendChild($resources);
  7809. $xmldoc->appendChild($root);
  7810. // TODO: Add a readme file here, with a short description and a link to the Reload player
  7811. // then add the file to the zip, then destroy the file (this is done automatically).
  7812. // http://www.reload.ac.uk/scormplayer.html - once done, don't forget to close FS#138
  7813. //error_log(print_r($zip_files,true), 0);
  7814. foreach ($zip_files as $file_path) {
  7815. if (empty($file_path)) { continue; }
  7816. //error_log(__LINE__.'getting document from '.$sys_course_path.$_course['path'].'/'.$file_path.' removing '.$sys_course_path.$_course['path'].'/',0);
  7817. $dest_file = $archive_path.$temp_dir_short.'/'.$file_path;
  7818. $this->create_path($dest_file);
  7819. //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);
  7820. //echo $main_path.$file_path.'<br />';
  7821. @copy($sys_course_path.$_course['path'].'/'.$file_path, $dest_file);
  7822. // Check if the file needs a link update.
  7823. if (in_array($file_path, array_keys($link_updates))) {
  7824. $string = file_get_contents($dest_file);
  7825. unlink($dest_file);
  7826. foreach ($link_updates[$file_path] as $old_new) {
  7827. //error_log('Replacing '.$old_new['orig'].' by '.$old_new['dest'].' in '.$file_path, 0);
  7828. // This is an ugly hack that allows .flv files to be found by the flv player that
  7829. // will be added in document/main/inc/lib/flv_player/flv_player.swf and that needs
  7830. // to find the flv to play in document/main/, so we replace main/ in the flv path by
  7831. // ../../.. to return from inc/lib/flv_player to the document/main path.
  7832. if (substr($old_new['dest'], -3) == 'flv' && substr($old_new['dest'], 0, 5) == 'main/') {
  7833. $old_new['dest'] = str_replace('main/', '../../../', $old_new['dest']);
  7834. }
  7835. elseif (substr($old_new['dest'], -3) == 'flv' && substr($old_new['dest'], 0, 6) == 'video/') {
  7836. $old_new['dest'] = str_replace('video/', '../../../../video/', $old_new['dest']);
  7837. }
  7838. $string = str_replace($old_new['orig'], $old_new['dest'], $string);
  7839. }
  7840. file_put_contents($dest_file, $string);
  7841. }
  7842. }
  7843. foreach ($zip_files_abs as $file_path) {
  7844. if (empty($file_path)) { continue; }
  7845. //error_log(__LINE__.'checking existence of '.$main_path.$file_path.'', 0);
  7846. if (!is_file($main_path.$file_path) || !is_readable($main_path.$file_path)) { continue; }
  7847. //error_log(__LINE__.'getting document from '.$main_path.$file_path.' removing '.api_get_path(SYS_COURSE_PATH).$_course['path'].'/', 0);
  7848. $dest_file = $archive_path.$temp_dir_short.'/document/'.$file_path;
  7849. $this->create_path($dest_file);
  7850. //error_log('Created path '.api_get_path(SYS_ARCHIVE_PATH).$temp_dir_short.'/document/'.$file_path, 0);
  7851. //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);
  7852. //echo $main_path.$file_path.' - '.$dest_file.'<br />';
  7853. copy($main_path.$file_path, $dest_file);
  7854. // Check if the file needs a link update.
  7855. if (in_array($file_path, array_keys($link_updates))) {
  7856. $string = file_get_contents($dest_file);
  7857. unlink($dest_file);
  7858. foreach ($link_updates[$file_path] as $old_new) {
  7859. //error_log('Replacing '.$old_new['orig'].' by '.$old_new['dest'].' in '.$file_path, 0);
  7860. // This is an ugly hack that allows .flv files to be found by the flv player that
  7861. // will be added in document/main/inc/lib/flv_player/flv_player.swf and that needs
  7862. // to find the flv to play in document/main/, so we replace main/ in the flv path by
  7863. // ../../.. to return from inc/lib/flv_player to the document/main path.
  7864. if (substr($old_new['dest'], -3) == 'flv' && substr($old_new['dest'], 0, 5) == 'main/') {
  7865. $old_new['dest'] = str_replace('main/', '../../../', $old_new['dest']);
  7866. }
  7867. $string = str_replace($old_new['orig'], $old_new['dest'], $string);
  7868. }
  7869. file_put_contents($dest_file, $string);
  7870. }
  7871. }
  7872. if (is_array($links_to_create)) {
  7873. foreach ($links_to_create as $file => $link) {
  7874. $file_content = '<!DOCTYPE html
  7875. PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  7876. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  7877. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="'.api_get_language_isocode().'" lang="'.api_get_language_isocode().'">
  7878. <head>
  7879. <title>'.$link['title'].'</title>
  7880. <meta http-equiv="Content-Type" content="text/html; charset='.api_get_system_encoding().'" />
  7881. </head>
  7882. <body dir="'.api_get_text_direction().'">
  7883. <div style="text-align:center"><a href="'.$link['url'].'">'.$link['title'].'</a></div>
  7884. </body>
  7885. </html>';
  7886. file_put_contents($archive_path.$temp_dir_short.'/'.$file, $file_content);
  7887. }
  7888. }
  7889. // Add non exportable message explanation.
  7890. $lang_not_exportable = get_lang('ThisItemIsNotExportable');
  7891. $file_content = '<!DOCTYPE html
  7892. PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  7893. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  7894. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="'.api_get_language_isocode().'" lang="'.api_get_language_isocode().'">
  7895. <head>
  7896. <title>'.$lang_not_exportable.'</title>
  7897. <meta http-equiv="Content-Type" content="text/html; charset='.api_get_system_encoding().'" />
  7898. </head>
  7899. <body dir="'.api_get_text_direction().'">
  7900. ';
  7901. $file_content .=
  7902. <<<EOD
  7903. <style>
  7904. .error-message {
  7905. font-family: arial, verdana, helvetica, sans-serif;
  7906. border-width: 1px;
  7907. border-style: solid;
  7908. left: 50%;
  7909. margin: 10px auto;
  7910. min-height: 30px;
  7911. padding: 5px;
  7912. right: 50%;
  7913. width: 500px;
  7914. background-color: #FFD1D1;
  7915. border-color: #FF0000;
  7916. color: #000;
  7917. }
  7918. </style>
  7919. <body>
  7920. <div class="error-message">
  7921. $lang_not_exportable
  7922. </div>
  7923. </body>
  7924. </html>
  7925. EOD;
  7926. if (!is_dir($archive_path.$temp_dir_short.'/document')) {
  7927. @mkdir($archive_path.$temp_dir_short.'/document', api_get_permissions_for_new_directories());
  7928. }
  7929. file_put_contents($archive_path.$temp_dir_short.'/document/non_exportable.html', $file_content);
  7930. // Add the extra files that go along with a SCORM package.
  7931. $main_code_path = api_get_path(SYS_CODE_PATH).'newscorm/packaging/';
  7932. $extra_files = scandir($main_code_path);
  7933. foreach ($extra_files as $extra_file) {
  7934. if (strpos($extra_file, '.') === 0)
  7935. continue;
  7936. else {
  7937. $dest_file = $archive_path . $temp_dir_short . '/' . $extra_file;
  7938. $this->create_path($dest_file);
  7939. copy($main_code_path.$extra_file, $dest_file);
  7940. }
  7941. }
  7942. // Finalize the imsmanifest structure, add to the zip, then return the zip.
  7943. $manifest = @$xmldoc->saveXML();
  7944. $manifest = api_utf8_decode_xml($manifest); // The manifest gets the system encoding now.
  7945. file_put_contents($archive_path.'/'.$temp_dir_short.'/imsmanifest.xml', $manifest);
  7946. $zip_folder->add($archive_path.'/'.$temp_dir_short, PCLZIP_OPT_REMOVE_PATH, $archive_path.'/'.$temp_dir_short.'/');
  7947. // Clean possible temporary files.
  7948. foreach ($files_cleanup as $file) {
  7949. $res = unlink($file);
  7950. if ($res === false) { error_log('Could not delete temp file '.$file.' '.__FILE__.' '.__LINE__, 0); }
  7951. }
  7952. // Send file to client.
  7953. //$name = 'scorm_export_'.$this->lp_id.'.zip';
  7954. require_once api_get_path(LIBRARY_PATH).'fileUpload.lib.php';
  7955. $name = replace_dangerous_char($this->get_name()).'.zip';
  7956. DocumentManager::file_send_for_download($temp_zip_file, true, $name);
  7957. }
  7958. public function scorm_export_to_pdf($lp_id) {
  7959. $lp_id = intval($lp_id);
  7960. $files_to_export = array();
  7961. $course_data = api_get_course_info($this->cc);
  7962. if (!empty($course_data)) {
  7963. $scorm_path = api_get_path(SYS_COURSE_PATH).$course_data['path'].'/scorm/'.$this->path;
  7964. require_once api_get_path(LIBRARY_PATH).'document.lib.php';
  7965. $list = $this->get_flat_ordered_items_list($lp_id);
  7966. foreach($list as $item_id) {
  7967. $item = $this->items[$item_id];
  7968. //Getting documents from a LP with chamilo documents
  7969. switch ($item->type) {
  7970. case 'document':
  7971. $file_data = DocumentManager::get_document_data_by_id($item->path, $this->cc);
  7972. $file_path = api_get_path(SYS_COURSE_PATH).$course_data['path'].'/document'.$file_data['path'];
  7973. if (file_exists($file_path)) {
  7974. $files_to_export[] = array('title'=>$item->get_title(),'path'=>$file_path);
  7975. }
  7976. break;
  7977. case 'sco':
  7978. $file_path = $scorm_path.'/'.$item->path;
  7979. if (file_exists($file_path)) {
  7980. $files_to_export[] = array('title'=>$item->get_title(),'path'=>$file_path);
  7981. }
  7982. break;
  7983. case 'dokeos_chapter':
  7984. case 'dir':
  7985. case 'chapter':
  7986. $files_to_export[] = array('title'=>$item->get_title(),'path'=>null);
  7987. break;
  7988. }
  7989. }
  7990. require_once api_get_path(LIBRARY_PATH).'pdf.lib.php';
  7991. $pdf = new PDF();
  7992. $result = $pdf->html_to_pdf($files_to_export, $this->name, $this->cc, true);
  7993. return $result;
  7994. }
  7995. return false;
  7996. }
  7997. /**
  7998. * Temp function to be moved in main_api or the best place around for this. Creates a file path
  7999. * if it doesn't exist
  8000. */
  8001. public function create_path($path) {
  8002. $path_bits = split('/', dirname($path));
  8003. // IS_WINDOWS_OS has been defined in main_api.lib.php
  8004. $path_built = IS_WINDOWS_OS ? '' : '/';
  8005. foreach ($path_bits as $bit) {
  8006. if (!empty ($bit)) {
  8007. $new_path = $path_built . $bit;
  8008. if (is_dir($new_path)) {
  8009. $path_built = $new_path . '/';
  8010. } else {
  8011. mkdir($new_path, api_get_permissions_for_new_directories());
  8012. $path_built = $new_path . '/';
  8013. }
  8014. }
  8015. }
  8016. }
  8017. /**
  8018. * Delete the image relative to this learning path. No parameter. Only works on instanciated object.
  8019. * @return boolean The results of the unlink function, or false if there was no image to start with
  8020. */
  8021. public function delete_lp_image() {
  8022. $img = $this->get_preview_image();
  8023. if ($img != '') {
  8024. $del_file = api_get_path(SYS_COURSE_PATH) . api_get_course_path() . '/upload/learning_path/images/' . $img;
  8025. $this->set_preview_image('');
  8026. return @ unlink($del_file);
  8027. } else {
  8028. return false;
  8029. }
  8030. }
  8031. /**
  8032. * Uploads an author image to the upload/learning_path/images directory
  8033. * @param array The image array, coming from the $_FILES superglobal
  8034. * @return boolean True on success, false on error
  8035. */
  8036. public function upload_image($image_array) {
  8037. $image_moved = false;
  8038. if (!empty ($image_array['name'])) {
  8039. $upload_ok = process_uploaded_file($image_array);
  8040. $has_attachment = true;
  8041. } else {
  8042. $image_moved = true;
  8043. }
  8044. if ($upload_ok) {
  8045. if ($has_attachment) {
  8046. $courseDir = api_get_course_path() . '/upload/learning_path/images';
  8047. $sys_course_path = api_get_path(SYS_COURSE_PATH);
  8048. $updir = $sys_course_path . $courseDir;
  8049. // Try to add an extension to the file if it hasn't one.
  8050. $new_file_name = add_ext_on_mime(stripslashes($image_array['name']), $image_array['type']);
  8051. if (!filter_extension($new_file_name)) {
  8052. //Display :: display_error_message(get_lang('UplUnableToSaveFileFilteredExtension'));
  8053. $image_moved = false;
  8054. } else {
  8055. $file_extension = explode('.', $image_array['name']);
  8056. $file_extension = strtolower($file_extension[sizeof($file_extension) - 1]);
  8057. $new_file_name = uniqid('') . '.' . $file_extension;
  8058. $new_path = $updir . '/' . $new_file_name;
  8059. // Resize the image.
  8060. $temp = new Image($image_array['tmp_name']);
  8061. $picture_infos = $temp->get_image_info();
  8062. if ($picture_infos['width'] > 104) {
  8063. $thumbwidth = 104;
  8064. } else {
  8065. $thumbwidth = $picture_infos['width'];
  8066. }
  8067. if ($picture_infos['height'] > 96) {
  8068. $new_height = 96;
  8069. } else {
  8070. $new_height = $picture_infos['height'];
  8071. }
  8072. $temp->resize($thumbwidth, $new_height, 0);
  8073. $result = $temp->send_image($new_path);
  8074. // Storing the image filename.
  8075. if ($result) {
  8076. $image_moved = true;
  8077. $this->set_preview_image($new_file_name);
  8078. return true;
  8079. }
  8080. }
  8081. }
  8082. }
  8083. return false;
  8084. }
  8085. public function set_autolunch($lp_id, $status) {
  8086. $course_id = api_get_course_int_id();
  8087. $lp_id = intval($lp_id);
  8088. $status = intval($status);
  8089. $lp_table = Database::get_course_table(TABLE_LP_MAIN);
  8090. //Setting everything to autolunch = 0
  8091. $attributes['autolunch'] = 0;
  8092. $where = array('session_id = ? AND c_id = ? '=> array(api_get_session_id(), $course_id));
  8093. Database::update($lp_table, $attributes, $where);
  8094. if ($status == 1) {
  8095. //Setting my lp_id to autolunch = 1
  8096. $attributes['autolunch'] = 1;
  8097. $where = array('id = ? AND session_id = ? AND c_id = ?'=> array($lp_id, api_get_session_id(), $course_id));
  8098. Database::update($lp_table, $attributes, $where );
  8099. }
  8100. }
  8101. /**
  8102. * Gets previous_item_id for the next element of the lp_item table
  8103. * @author Isaac flores paz
  8104. * @return integer Previous item ID
  8105. */
  8106. function select_previous_item_id() {
  8107. $course_id = api_get_course_int_id();
  8108. if ($this->debug > 0) {
  8109. error_log('New LP - In learnpath::select_previous_item_id()', 0);
  8110. }
  8111. $table_lp_item = Database::get_course_table(TABLE_LP_ITEM);
  8112. // Get the max order of the items
  8113. $sql_max_order = "SELECT max(display_order) AS display_order FROM $table_lp_item WHERE c_id = $course_id AND lp_id = '" . $this->lp_id . "'";
  8114. $rs_max_order = Database::query($sql_max_order);
  8115. $row_max_order = Database::fetch_object($rs_max_order);
  8116. $max_order = $row_max_order->display_order;
  8117. // Get the previous item ID
  8118. $sql_max = "SELECT id as previous FROM $table_lp_item WHERE c_id = $course_id AND lp_id = '" . $this->lp_id . "' AND display_order = '".$max_order."' ";
  8119. $rs_max = Database::query($sql_max, __FILE__, __LINE__);
  8120. $row_max = Database::fetch_object($rs_max);
  8121. // Return the previous item ID
  8122. return $row_max->previous;
  8123. }
  8124. function copy() {
  8125. $main_path = api_get_path(SYS_CODE_PATH);
  8126. require_once $main_path.'coursecopy/classes/CourseBuilder.class.php';
  8127. require_once $main_path.'coursecopy/classes/CourseArchiver.class.php';
  8128. require_once $main_path.'coursecopy/classes/CourseRestorer.class.php';
  8129. require_once $main_path.'coursecopy/classes/CourseSelectForm.class.php';
  8130. //Course builder
  8131. $cb = new CourseBuilder();
  8132. //Setting tools that will be copied
  8133. $cb->set_tools_to_build(array('learnpaths'));
  8134. //Setting elements that will be copied
  8135. $cb->set_tools_specific_id_list(array('learnpaths' => array($this->lp_id)));
  8136. $course = $cb->build();
  8137. //Course restorer
  8138. $course_restorer = new CourseRestorer($course);
  8139. $course_restorer->set_add_text_in_items(true);
  8140. $course_restorer->set_tool_copy_settings(array('learnpaths' => array('reset_dates' => true)));
  8141. $course_restorer->restore(api_get_course_id(), api_get_session_id(), false, false);
  8142. }
  8143. }
  8144. if (!function_exists('trim_value')) {
  8145. function trim_value(& $value) {
  8146. $value = trim($value);
  8147. }
  8148. }