123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706 |
- <?php
- class learnpath {
- public $attempt = 0;
- public $cc;
- public $current;
- public $current_score;
- public $current_time_start;
- public $current_time_stop;
- public $default_status = 'not attempted';
- public $encoding = 'UTF-8';
- public $error = '';
- public $extra_information = '';
- public $force_commit = false;
- public $index;
- public $items = array();
- public $last;
- public $last_item_seen = 0;
- public $license;
- public $lp_id;
- public $lp_view_id;
- public $log_file;
- public $maker;
- public $message = '';
- public $mode = 'embedded';
- public $name;
- public $ordered_items = array();
- public $path = '';
- public $theme;
- public $preview_image;
-
- public $prevent_reinit = 1;
-
- public $progress_bar_mode = '%';
-
- public $progress_db = '0';
- public $proximity;
- public $refs_list = array ();
-
-
- public $type;
-
- public $user_id;
- public $update_queue = array();
- public $scorm_debug = 0;
- public $arrMenu = array();
- public $debug = 0;
- public $lp_session_id =0;
- public $lp_view_session_id =0;
- public $prerequisite = 0;
- public $use_max_score = 1;
- public $created_on = '';
- public $modified_on = '';
- public $publicated_on = '';
- public $expired_on = '';
-
- public function __construct($course, $lp_id, $user_id) {
- $this->encoding = api_get_system_encoding();
-
-
- $course_db = '';
- if ($this->debug > 0) {error_log('New LP - In learnpath::__construct('.$course.','.$lp_id.','.$user_id.')', 0); }
- if (empty($course)) {
- $this->error = 'Course code is empty';
- return false;
- } else {
- $main_table = Database::get_main_table(TABLE_MAIN_COURSE);
-
- $course = $this->escape_string($course);
- $sql = "SELECT * FROM $main_table WHERE code = '$course'";
- if ($this->debug > 2) { error_log('New LP - learnpath::__construct() '.__LINE__.' - Querying course: '.$sql, 0); }
- $res = Database::query($sql);
- if (Database::num_rows($res) > 0) {
- $this->cc = $course;
- $row_course = Database::fetch_array($res);
- $course_db = $row_course['db_name'];
- } else {
- $this->error = 'Course code does not exist in database ('.$sql.')';
- return false;
- }
- }
-
- if (empty($lp_id)) {
- $this->error = 'Learnpath ID is empty';
- return false;
- } else {
-
- $lp_table = Database::get_course_table(TABLE_LP_MAIN, $course_db);
-
- $lp_id = $this->escape_string($lp_id);
- $sql = "SELECT * FROM $lp_table WHERE id = '$lp_id'";
- if ($this->debug > 2) { error_log('New LP - learnpath::__construct() '.__LINE__.' - Querying lp: '.$sql, 0); }
- $res = Database::query($sql);
- if (Database::num_rows($res) > 0) {
- $this->lp_id = $lp_id;
- $row = Database::fetch_array($res);
- $this->type = $row['lp_type'];
- $this->name = stripslashes($row['name']);
-
- $this->proximity = $row['content_local'];
- $this->theme = $row['theme'];
- $this->maker = $row['content_maker'];
- $this->prevent_reinit = $row['prevent_reinit'];
- $this->license = $row['content_license'];
- $this->scorm_debug = $row['debug'];
- $this->js_lib = $row['js_lib'];
- $this->path = $row['path'];
- $this->preview_image = $row['preview_image'];
- $this->author = $row['author'];
- $this->lp_session_id = $row['session_id'];
- $this->use_max_score = $row['use_max_score'];
- $this->created_on = $row['created_on'];
- $this->modified_on = $row['modified_on'];
- if ($row['publicated_on'] != '0000-00-00 00:00:00') {
- $this->publicated_on = $row['publicated_on'];
- }
- if ($row['expired_on'] != '0000-00-00 00:00:00') {
- $this->expired_on = $row['expired_on'];
- }
- if ($this->type == 2) {
- if ($row['force_commit'] == 1) {
- $this->force_commit = true;
- }
- }
- $this->mode = $row['default_view_mod'];
- } else {
- $this->error = 'Learnpath ID does not exist in database ('.$sql.')';
- return false;
- }
- }
-
- if (empty($user_id)) {
- $this->error = 'User ID is empty';
- return false;
- } else {
-
- $main_table = Database::get_main_table(TABLE_MAIN_USER);
-
- $user_id = $this->escape_string($user_id);
- $sql = "SELECT * FROM $main_table WHERE user_id = '$user_id'";
- if ($this->debug > 2) { error_log('New LP - learnpath::__construct() '.__LINE__.' - Querying user: '.$sql, 0); }
- $res = Database::query($sql);
- if (Database::num_rows($res) > 0) {
- $this->user_id = $user_id;
- } else {
- $this->error = 'User ID does not exist in database ('.$sql.')';
- return false;
- }
- }
-
- $session_id = api_get_session_id();
-
- $session = api_get_session_condition($session_id);
-
- $lp_table = Database::get_course_table(TABLE_LP_VIEW, $course_db);
-
- $sql = "SELECT * FROM $lp_table WHERE lp_id = '$lp_id' AND user_id = '$user_id' $session ORDER BY view_count DESC";
- if ($this->debug > 2) { error_log('New LP - learnpath::__construct() ' . __LINE__ . ' - querying lp_view: ' . $sql, 0); }
- $res = Database::query($sql);
- $view_id = 0;
- if (Database :: num_rows($res) > 0) {
- if ($this->debug > 2) {
- error_log('New LP - learnpath::__construct() ' . __LINE__ . ' - Found previous view', 0);
- }
- $row = Database :: fetch_array($res);
- $this->attempt = $row['view_count'];
- $this->lp_view_id = $row['id'];
- $this->last_item_seen = $row['last_item'];
- $this->progress_db = $row['progress'];
- $this->lp_view_session_id = $row['session_id'];
- } else {
- if ($this->debug > 2) {
- error_log('New LP - learnpath::__construct() ' . __LINE__ . ' - NOT Found previous view', 0);
- }
- $this->attempt = 1;
- $sql_ins = "INSERT INTO $lp_table (lp_id,user_id,view_count, session_id) VALUES ($lp_id,$user_id,1,$session_id)";
- $res_ins = Database::query($sql_ins);
- $this->lp_view_id = Database :: insert_id();
- if ($this->debug > 2) {
- error_log('New LP - learnpath::__construct() ' . __LINE__ . ' - inserting new lp_view: ' . $sql_ins, 0);
- }
- }
-
- $lp_item_table = Database::get_course_table(TABLE_LP_ITEM, $course_db);
- $sql = "SELECT * FROM $lp_item_table WHERE lp_id = '".$this->lp_id."' ORDER BY parent_item_id, display_order";
- $res = Database::query($sql);
- while ($row = Database::fetch_array($res)) {
- $oItem = '';
-
- switch ($this->type) {
- case 3:
- $oItem = new aiccItem('db', $row['id'], $course_db);
- if (is_object($oItem)) {
- $my_item_id = $oItem->get_id();
- $oItem->set_lp_view($this->lp_view_id, $course_db);
- $oItem->set_prevent_reinit($this->prevent_reinit);
-
- $this->items[$my_item_id] = $oItem;
- $this->refs_list[$oItem->ref] = $my_item_id;
- if ($this->debug > 2) {
- error_log('New LP - learnpath::__construct() - aicc object with id ' . $my_item_id . ' set in items[]', 0);
- }
- }
- break;
- case 2:
- require_once 'scorm.class.php';
- require_once 'scormItem.class.php';
- $oItem = new scormItem('db', $row['id'], $course_db);
- if (is_object($oItem)) {
- $my_item_id = $oItem->get_id();
- $oItem->set_lp_view($this->lp_view_id, $course_db);
- $oItem->set_prevent_reinit($this->prevent_reinit);
-
- error_log('my_item_id->'.$my_item_id);
- $this->items[$my_item_id] = $oItem;
- $this->refs_list[$oItem->ref] = $my_item_id;
- if ($this->debug > 2) {
- error_log('New LP - object with id ' . $my_item_id . ' set in items[]', 0);
- }
- }
- break;
- case 1:
- default:
- require_once 'learnpathItem.class.php';
- $oItem = new learnpathItem($row['id'], $user_id, $course_db);
- if (is_object($oItem)) {
- $my_item_id = $oItem->get_id();
-
- $oItem->set_prevent_reinit($this->prevent_reinit);
-
- $this->items[$my_item_id] = $oItem;
- $this->refs_list[$my_item_id] = $my_item_id;
- if ($this->debug > 2) {
- error_log('New LP - learnpath::__construct() ' . __LINE__ . ' - object with id ' . $my_item_id . ' set in items[]', 0);
- }
- }
- break;
- }
-
- if ($row['parent_item_id'] == 0 || empty ($this->items[$row['parent_item_id']])) {
- if (is_object($this->items[$row['id']])) {
- $this->items[$row['id']]->set_level(0);
- }
- } else {
- $level = $this->items[$row['parent_item_id']]->get_level() + 1;
- $this->items[$row['id']]->set_level($level);
- if (is_object($this->items[$row['parent_item_id']])) {
-
- $this->items[$row['parent_item_id']]->add_child($row['id']);
- } else {
- if ($this->debug > 2) {
- error_log('New LP - learnpath::__construct() ' . __LINE__ . ' - The parent item (' . $row['parent_item_id'] . ') of item ' . $row['id'] . ' could not be found', 0);
- }
- }
- }
-
- $lp_item_view_table = Database :: get_course_table(TABLE_LP_ITEM_VIEW, $course_db);
-
- $sql = "SELECT * " .
- "FROM $lp_item_view_table " .
- "WHERE lp_view_id = " . $this->lp_view_id . " " .
- "AND lp_item_id = " . $row['id'] . " ORDER BY view_count DESC ";
- if ($this->debug > 2) {
- error_log('New LP - learnpath::__construct() - Selecting item_views: ' . $sql, 0);
- }
-
- $res2 = Database::query($sql);
- if (Database :: num_rows($res2) > 0) {
-
-
-
- $row2 = Database :: fetch_array($res2);
- if ($this->debug > 2) {
- error_log('New LP - learnpath::__construct() - Got item_view: ' . print_r($row2, true), 0);
- }
- if (is_object($this->items[$row['id']])) {
- $this->items[$row['id']]->set_status($row2['status']);
- if (empty ($row2['status'])) {
- $this->items[$row['id']]->set_status($this->default_status);
- }
- }
-
-
- } else {
-
-
-
-
- if (is_object($this->items[$row['id']])) {
- $this->items[$row['id']]->set_status($this->default_status);
- }
-
- $sql_ins = "INSERT INTO $lp_item_view_table " .
- "(lp_item_id, lp_view_id, view_count, status) VALUES " .
- "(" . $row['id'] . "," . $this->lp_view_id . ",1,'not attempted')";
- if ($this->debug > 2) {
- error_log('New LP - learnpath::__construct() ' . __LINE__ . ' - Inserting blank item_view : ' . $sql_ins, 0);
- }
- $res_ins = Database::query($sql_ins);
- }
-
- if (is_object($this->items[$row['id']])) {
- $this->items[$row['id']]->set_lp_view($this->lp_view_id, $course_db);
- }
- }
- $this->ordered_items = $this->get_flat_ordered_items_list($this->get_id(), 0, $course_db);
- $this->max_ordered_items = 0;
- foreach ($this->ordered_items as $index => $dummy) {
- if ($index > $this->max_ordered_items && !empty($dummy)) {
- $this->max_ordered_items = $index;
- }
- }
-
- $this->first();
- if ($this->debug > 2) {
- error_log('New LP - learnpath::__construct() ' . __LINE__ . ' - End of learnpath constructor for learnpath ' . $this->get_id(), 0);
- }
- }
-
- public function add_item($parent, $previous, $type = 'dokeos_chapter', $id, $title, $description, $prerequisites = 0, $max_time_allowed = 0) {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::add_item(' . $parent . ',' . $previous . ',' . $type . ',' . $id . ',' . $title . ')', 0);
- }
- $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
- $parent = intval($parent);
- $previous = intval($previous);
- $type = $this->escape_string($type);
- $id = intval($id);
- $max_time_allowed = $this->escape_string(htmlentities($max_time_allowed));
- if (empty ($max_time_allowed)) {
- $max_time_allowed = 0;
- }
- $title = $this->escape_string($title);
- $description = $this->escape_string($description);
- $sql_count = " SELECT COUNT(id) AS num
- FROM " . $tbl_lp_item . "
- WHERE lp_id = " . $this->get_id() . " AND parent_item_id = " . $parent;
- $res_count = Database::query($sql_count);
- $row = Database :: fetch_array($res_count);
- $num = $row['num'];
- if ($num > 0) {
- if ($previous == 0) {
- $sql = "SELECT id, next_item_id, display_order
- FROM " . $tbl_lp_item . "
- WHERE
- lp_id = " . $this->get_id() . " AND
- parent_item_id = " . $parent . " AND
- previous_item_id = 0 OR previous_item_id=" . $parent;
- $result = Database::query($sql);
- $row = Database :: fetch_array($result);
- $tmp_previous = 0;
- $next = $row['id'];
- $display_order = 0;
- } else {
- $previous = (int) $previous;
- $sql = "
- SELECT
- id,
- previous_item_id,
- next_item_id,
- display_order
- FROM " . $tbl_lp_item . "
- WHERE
- lp_id = " . $this->get_id() . " AND
- id = " . $previous;
- $result = Database::query($sql);
- $row = Database :: fetch_array($result);
- $tmp_previous = $row['id'];
- $next = $row['next_item_id'];
- $display_order = $row['display_order'];
- }
- } else {
- $tmp_previous = 0;
- $next = 0;
- $display_order = 0;
- }
- $new_item_id = -1;
- $id = $this->escape_string($id);
- if ($type == 'quiz') {
- $sql = 'SELECT SUM(ponderation)
- FROM ' . Database :: get_course_table(TABLE_QUIZ_QUESTION) . ' as quiz_question
- INNER JOIN ' . Database :: get_course_table(TABLE_QUIZ_TEST_QUESTION) . ' as quiz_rel_question
- ON quiz_question.id = quiz_rel_question.question_id
- AND quiz_rel_question.exercice_id = ' . $id;
- $rsQuiz = Database::query($sql);
- $max_score = Database :: result($rsQuiz, 0, 0);
- } else {
- $max_score = 100;
- }
- if ($prerequisites != 0) {
- $sql_ins = "
- INSERT INTO " . $tbl_lp_item . " ( ".
- "lp_id, ".
- "item_type, ".
- "ref, ".
- "title, ".
- "description, ".
- "path, ".
- "max_score, ".
- "parent_item_id, ".
- "previous_item_id, ".
- "next_item_id, ".
- "display_order, ".
- "prerequisite, ".
- "max_time_allowed ".
- ") VALUES ( ".
- $this->get_id() . ", ".
- "'" . $type . "', ".
- "'', ".
- "'" . $title . "', ".
- "'" . $description . "', ".
- "'" . $id . "', ".
- "'" . $max_score . "', ".
- $parent . ", ".
- $previous . ", ".
- $next . ", ".
- ($display_order +1) . ", ".
- $prerequisites . ", ".
- $max_time_allowed .
- ")";
- } else {
-
- $sql_ins = "
- INSERT INTO " . $tbl_lp_item . " ( ".
- "lp_id, ".
- "item_type, ".
- "ref, ".
- "title, ".
- "description, ".
- "path, ".
- "max_score, ".
- "parent_item_id, ".
- "previous_item_id, ".
- "next_item_id, ".
- "display_order, ".
- "max_time_allowed ".
- ") VALUES (".
- $this->get_id() . ",".
- "'" . $type . "',".
- "'',".
- "'" . $title . "',".
- "'" . $description . "',".
- "'" . $id . "',".
- "'" . $max_score . "',".
- $parent . ",".
- $previous . ",".
- $next . ",".
- ($display_order +1) . ",".
- $max_time_allowed .
- ")";
- }
- if ($this->debug > 2) {
- error_log('New LP - Inserting dokeos_chapter: ' . $sql_ins, 0);
- }
- $res_ins = Database::query($sql_ins);
- if ($res_ins > 0) {
- $new_item_id = Database :: insert_id($res_ins);
-
- $sql_update_next = "
- UPDATE " . $tbl_lp_item . "
- SET previous_item_id = " . $new_item_id . "
- WHERE id = " . $next;
- $res_update_next = Database::query($sql_update_next);
-
- $sql_update_previous = "
- UPDATE " . $tbl_lp_item . "
- SET next_item_id = " . $new_item_id . "
- WHERE id = " . $tmp_previous;
- $res_update_previous = Database::query($sql_update_previous);
-
- $sql_update_order = "
- UPDATE " . $tbl_lp_item . "
- SET display_order = display_order + 1
- WHERE
- lp_id = " . $this->get_id() . " AND
- id <> " . $new_item_id . " AND
- parent_item_id = " . $parent . " AND
- display_order > " . $display_order;
- $res_update_previous = Database::query($sql_update_order);
-
- $sql_update_ref = "
- UPDATE " . $tbl_lp_item . "
- SET ref = " . $new_item_id . "
- WHERE id = " . $new_item_id;
- Database::query($sql_update_ref);
- }
-
- if (!empty ($_FILES['mp3']['name'])) {
-
- global $_course;
- $filepath = api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document/';
- if (!is_dir($filepath . 'audio')) {
- mkdir($filepath . 'audio', api_get_permissions_for_new_directories());
- $audio_id = add_document($_course, '/audio', 'folder', 0, 'audio');
- api_item_property_update($_course, TOOL_DOCUMENT, $audio_id, 'FolderCreated', api_get_user_id(), null, null, null, null, api_get_session_id());
- }
-
- include_once api_get_path(LIBRARY_PATH).'fileUpload.lib.php';
- $file_path = handle_uploaded_document($_course, $_FILES['mp3'], api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document', '/audio', api_get_user_id(), '', '', '', '', '', false);
-
- $file_components = explode('/', $file_path);
- $file = $file_components[count($file_components) - 1];
-
- $sql_insert_audio = "UPDATE $tbl_lp_item SET audio = '" . Database :: escape_string($file) . "' WHERE id = '" . Database :: escape_string($new_item_id) . "'";
- Database::query($sql_insert_audio);
- }
- return $new_item_id;
- }
-
- public function add_lp($course, $name, $description = '', $learnpath = 'guess', $origin = 'zip', $zipname = '', $publicated_on = '', $expired_on = '') {
- global $charset;
-
- $tbl_lp = Database :: get_course_table(TABLE_LP_MAIN);
-
-
- $i = 0;
- $name = learnpath :: escape_string($name);
-
- $session_id = api_get_session_id();
- $check_name = "SELECT * FROM $tbl_lp WHERE name = '$name'";
-
- $res_name = Database::query($check_name);
- if ($publicated_on == '0000-00-00 00:00:00' || empty($publicated_on)) {
-
- $publicated_on = api_get_utc_datetime();
- } else {
- $publicated_on = Database::escape_string(api_get_utc_datetime($publicated_on));
- }
- if ($expired_on == '0000-00-00 00:00:00' || empty($expired_on)) {
- $expired_on = '';
- } else {
- $expired_on = Database::escape_string(api_get_utc_datetime($expired_on));
- }
- while (Database :: num_rows($res_name)) {
-
- $i++;
- $name = $name . ' - ' . $i;
- $check_name = "SELECT * FROM $tbl_lp WHERE name = '$name'";
-
- $res_name = Database::query($check_name);
- }
-
-
- $description = learnpath :: escape_string(api_htmlentities($description, ENT_QUOTES, $charset));
- $type = 1;
- switch ($learnpath) {
- case 'guess':
- break;
- case 'dokeos':
- case 'chamilo':
- $type = 1;
- break;
- case 'aicc':
- break;
- }
- switch ($origin) {
- case 'zip':
-
- break;
- case 'manual':
- default:
- $get_max = "SELECT MAX(display_order) FROM $tbl_lp";
- $res_max = Database::query($get_max);
- if (Database :: num_rows($res_max) < 1) {
- $dsp = 1;
- } else {
- $row = Database :: fetch_array($res_max);
- $dsp = $row[0] + 1;
- }
- $sql_insert = "INSERT INTO $tbl_lp (lp_type,name,description,path,default_view_mod, default_encoding,display_order,content_maker,content_local,js_lib,session_id, created_on, publicated_on, expired_on) " .
- "VALUES ($type,'$name','$description','','embedded','UTF-8','$dsp','Chamilo','local','','".$session_id."', '".api_get_utc_datetime()."' , '".$publicated_on."' , '".$expired_on."')";
-
- $res_insert = Database::query($sql_insert);
- $id = Database :: insert_id();
- if ($id > 0) {
-
- api_item_property_update(api_get_course_info(), TOOL_LEARNPATH, $id, 'LearnpathAdded', api_get_user_id());
- return $id;
- }
- break;
- }
- }
-
- public function append_message($string) {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::append_message()', 0);
- }
- $this->message .= $string;
- }
-
- public function autocomplete_parents($item) {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::autocomplete_parents()', 0);
- }
- if (empty ($item)) {
- $item = $this->current;
- }
- $parent_id = $this->items[$item]->get_parent();
- if ($this->debug > 2) {
- error_log('New LP - autocompleting parent of item ' . $item . ' (item ' . $parent_id . ')', 0);
- }
- if (is_object($this->items[$item]) and !empty ($parent_id)) {
-
- if ($this->debug > 2) {
- error_log('New LP - ' . $item . ' is an item, proceed', 0);
- }
- $current_item = & $this->items[$item];
- $parent = & $this->items[$parent_id];
-
- $current_status = $current_item->get_status();
- if ($current_item->is_done() || $current_status == 'browsed' || $current_status == 'failed') {
-
- $completed = true;
- if ($this->debug > 2) {
- error_log('New LP - Status of current item is alright', 0);
- }
- foreach ($parent->get_children() as $child) {
-
- if ($child != $item) {
- if ($this->debug > 2) {
- error_log('New LP - Looking at brother with ID ' . $child . ', status is ' . $this->items[$child]->get_status(), 0);
- }
-
-
- if ($this->items[$child]->status_is(array (
- 'completed',
- 'passed',
- 'succeeded',
- 'browsed',
- 'failed'
- ))) {
-
- } else {
- if ($this->debug > 2) {
- error_log('New LP - Found one incomplete child of ' . $parent_id . ': ' . $child . ' is ' . $this->items[$child]->get_status(), 0);
- }
- $completed = false;
- }
- }
- }
- if ($completed) {
- $parent->set_status('completed');
- $parent->save(false, $this->prerequisites_match($parent->get_id()));
- $this->update_queue[$parent->get_id()] = $parent->get_status();
- if ($this->debug > 2) {
- error_log('New LP - Added parent to update queue ' . print_r($this->update_queue, true), 0);
- }
- $this->autocomplete_parents($parent->get_id());
- }
- } else {
-
- }
- }
- }
-
- public function autosave() {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::autosave()', 0);
- }
-
- }
-
- public function clear_message() {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::clear_message()', 0);
- }
- $this->message = '';
- }
-
- public function close() {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::close()', 0);
- }
- if (empty ($this->lp_id)) {
- $this->error = 'Trying to close this learnpath but no ID is set';
- return false;
- }
- $this->current_time_stop = time();
- if ($this->save) {
- $learnpath_view_table = Database :: get_course_table(TABLE_LP_VIEW);
-
- }
- $this->ordered_items = array ();
- $this->index = 0;
- unset ($this->lp_id);
-
- return true;
- }
-
- public function delete($course = null, $id = null, $delete = 'keep') {
-
-
-
-
-
- if (!empty ($id) && ($id != $this->lp_id)) {
- return false;
- }
- $lp = Database :: get_course_table(TABLE_LP_MAIN);
- $lp_item = Database :: get_course_table(TABLE_LP_ITEM);
- $lp_view = Database :: get_course_table(TABLE_LP_VIEW);
- $lp_item_view = Database :: get_course_table(TABLE_LP_ITEM_VIEW);
-
-
- foreach ($this->items as $id => $dummy) {
-
- $sql_del_view = "DELETE FROM $lp_item_view WHERE lp_item_id = '" . $id . "'";
- $res_del_item_view = Database::query($sql_del_view);
- }
-
- $sql_del_item = "DELETE FROM $lp_item WHERE lp_id = " . $this->lp_id;
- $res_del_item = Database::query($sql_del_item);
- $sql_del_view = "DELETE FROM $lp_view WHERE lp_id = " . $this->lp_id;
-
- $res_del_view = Database::query($sql_del_view);
- $this->toggle_publish($this->lp_id, 'i');
-
- if ($this->type == 2 || $this->type == 3) {
-
- $sql = "SELECT path FROM $lp WHERE id = " . $this->lp_id;
- $res = Database::query($sql);
- if (Database :: num_rows($res) > 0) {
- $row = Database :: fetch_array($res);
- $path = $row['path'];
- $sql = "SELECT id FROM $lp WHERE path = '$path' AND id != " . $this->lp_id;
- $res = Database::query($sql);
- if (Database :: num_rows($res) > 0) {
- if ($this->debug > 2) {
- error_log('New LP - In learnpath::delete(), found other LP using path ' . $path . ', keeping directory', 0);
- }
- } else {
-
- $course_rel_dir = api_get_course_path() . '/scorm/';
- $course_scorm_dir = api_get_path(SYS_COURSE_PATH) . $course_rel_dir;
- if ($delete == 'remove' && is_dir($course_scorm_dir . $path) and !empty ($course_scorm_dir)) {
- if ($this->debug > 2) {
- error_log('New LP - In learnpath::delete(), found SCORM, deleting directory: ' . $course_scorm_dir . $path, 0);
- }
-
- if (strcmp(substr($path, -2), "/.") == 0) {
- $path = substr($path, 0, -1);
- }
-
- rmdirr($course_scorm_dir . $path);
- }
- }
- }
- }
- $sql_del_lp = "DELETE FROM $lp WHERE id = " . $this->lp_id;
-
- $res_del_lp = Database::query($sql_del_lp);
- $this->update_display_order();
- api_item_property_update(api_get_course_info(), TOOL_LEARNPATH, $this->lp_id, 'delete', api_get_user_id());
- require_once '../gradebook/lib/be.inc.php';
-
-
-
-
-
-
-
- require_once api_get_path(SYS_CODE_PATH).'gradebook/lib/gradebook_functions.inc.php';
- $link_id = is_resource_in_course_gradebook(api_get_course_id(), 4 , $id, api_get_session_id());
- if ($link_id !== false) {
- remove_resource_from_course_gradebook($link_id);
- }
- if (api_get_setting('search_enabled') == 'true') {
- require_once api_get_path(LIBRARY_PATH).'specific_fields_manager.lib.php';
- $r = delete_all_values_for_item($this->cc, TOOL_LEARNPATH, $this->lp_id);
- }
- }
-
- public function delete_children_items($id) {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::delete_children_items(' . $id . ')', 0);
- }
- $num = 0;
- if (empty ($id) || $id != strval(intval($id))) {
- return false;
- }
- $lp_item = Database :: get_course_table(TABLE_LP_ITEM);
- $sql = "SELECT * FROM $lp_item WHERE parent_item_id = $id";
- $res = Database::query($sql);
- while ($row = Database :: fetch_array($res)) {
- $num += $this->delete_children_items($row['id']);
- $sql_del = "DELETE FROM $lp_item WHERE id = " . $row['id'];
- $res_del = Database::query($sql_del);
- $num++;
- }
- return $num;
- }
-
- public function delete_item($id, $remove = 'keep') {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::delete_item()', 0);
- }
-
- if (empty ($id) || $id != strval(intval($id))) {
- return false;
- }
-
- $lp_item = Database :: get_course_table(TABLE_LP_ITEM);
- $sql_sel = "SELECT * FROM $lp_item WHERE id = $id";
- $res_sel = Database::query($sql_sel);
- if (Database :: num_rows($res_sel) < 1) {
- return false;
- }
- $row = Database :: fetch_array($res_sel);
- $previous = $row['previous_item_id'];
- $next = $row['next_item_id'];
- $display = $row['display_order'];
- $parent = $row['parent_item_id'];
- $lp = $row['lp_id'];
-
- $num = $this->delete_children_items($id);
- if ($this->debug > 2) {
- error_log('New LP - learnpath::delete_item() - deleted ' . $num . ' children of element ' . $id, 0);
- }
-
- $sql_del = "DELETE FROM $lp_item WHERE id = $id";
- if ($this->debug > 2) {
- error_log('New LP - Deleting item: ' . $sql_del, 0);
- }
- $res_del = Database::query($sql_del);
-
- $sql_upd = "UPDATE $lp_item SET next_item_id = $next WHERE id = $previous";
- $res_upd = Database::query($sql_upd);
- $sql_upd = "UPDATE $lp_item SET previous_item_id = $previous WHERE id = $next";
- $res_upd = Database::query($sql_upd);
-
- $sql_all = "UPDATE $lp_item SET display_order = display_order-1 WHERE lp_id = $lp AND parent_item_id = $parent AND display_order > $display";
- $res_all = Database::query($sql_all);
-
- $sql_all = "UPDATE $lp_item SET prerequisite = '' WHERE prerequisite = $id";
- $res_all = Database::query($sql_all);
-
- if (api_get_setting('search_enabled') == 'true') {
- $tbl_se_ref = Database :: get_main_table(TABLE_MAIN_SEARCH_ENGINE_REF);
- $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';
- $sql = sprintf($sql, $tbl_se_ref, $this->cc, TOOL_LEARNPATH, $lp, $id);
- $res = Database::query($sql);
- if (Database :: num_rows($res) > 0) {
- $row2 = Database :: fetch_array($res);
- require_once api_get_path(LIBRARY_PATH).'search/DokeosIndexer.class.php';
- $di = new DokeosIndexer();
- $di->remove_document((int) $row2['search_did']);
- }
- $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';
- $sql = sprintf($sql, $tbl_se_ref, $this->cc, TOOL_LEARNPATH, $lp, $id);
- Database::query($sql);
- }
- }
-
- public function edit_item($id, $parent, $previous, $title, $description, $prerequisites = 0, $audio = null, $max_time_allowed = 0) {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::edit_item()', 0);
- }
- if (empty ($max_time_allowed)) {
- $max_time_allowed = 0;
- }
- if (empty ($id) || ($id != strval(intval($id))) || empty ($title)) {
- return false;
- }
- $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
- $sql_select = "SELECT * FROM " . $tbl_lp_item . " WHERE id = " . $id;
- $res_select = Database::query($sql_select);
- $row_select = Database :: fetch_array($res_select);
- $audio_update_sql = '';
- if (is_array($audio) && !empty ($audio['tmp_name']) && $audio['error'] === 0) {
-
- global $_course;
- $filepath = api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document/';
- if (!is_dir($filepath . 'audio')) {
- mkdir($filepath . 'audio', api_get_permissions_for_new_directories());
- $audio_id = add_document($_course, '/audio', 'folder', 0, 'audio');
- api_item_property_update($_course, TOOL_DOCUMENT, $audio_id, 'FolderCreated', api_get_user_id(), null, null, null, null, api_get_session_id());
- }
-
- $pi = pathinfo($audio['name']);
- if ($pi['extension'] == 'mp3') {
- $c_det = api_get_course_info($this->cc);
- $bp = api_get_path(SYS_COURSE_PATH) . $c_det['path'] . '/document';
- $path = handle_uploaded_document($c_det, $audio, $bp, '/audio', api_get_user_id(), 0, null, '', 0, 'rename', false, 0);
- $path = substr($path, 7);
-
- $audio_update_sql = ", audio = '" . Database :: escape_string($path) . "' ";
- }
- }
- $same_parent = ($row_select['parent_item_id'] == $parent) ? true : false;
- $same_previous = ($row_select['previous_item_id'] == $previous) ? true : false;
-
- if ($same_parent && $same_previous) {
-
- $sql_update = " UPDATE " . $tbl_lp_item . "
- SET title = '" . $this->escape_string($title) . "',
- prerequisite = '" . $prerequisites . "',
- description = '" . $this->escape_string($description) . "'
- " . $audio_update_sql . ",
- max_time_allowed = '" . $this->escape_string($max_time_allowed) . "'
- WHERE id = " . $id;
- $res_update = Database::query($sql_update);
- } else {
- $old_parent = $row_select['parent_item_id'];
- $old_previous = $row_select['previous_item_id'];
- $old_next = $row_select['next_item_id'];
- $old_order = $row_select['display_order'];
- $old_prerequisite = $row_select['prerequisite'];
- $old_max_time_allowed = $row_select['max_time_allowed'];
-
-
- if ($old_previous != 0) {
- $sql_update_next = "
- UPDATE " . $tbl_lp_item . "
- SET next_item_id = " . $old_next . "
- WHERE id = " . $old_previous;
- $res_update_next = Database::query($sql_update_next);
-
- }
- if ($old_next != 0) {
- $sql_update_previous = "
- UPDATE " . $tbl_lp_item . "
- SET previous_item_id = " . $old_previous . "
- WHERE id = " . $old_next;
- $res_update_previous = Database::query($sql_update_previous);
-
- }
-
- $sql_update_order = "
- UPDATE " . $tbl_lp_item . "
- SET display_order = display_order - 1
- WHERE
- display_order > " . $old_order . " AND lp_id = " . $this->lp_id . " AND
- parent_item_id = " . $old_parent;
- $res_update_order = Database::query($sql_update_order);
-
-
-
- if ($previous == 0) {
-
- $sql_select_old = "
- SELECT
- id,
- display_order
- FROM " . $tbl_lp_item . "
- WHERE
- lp_id = " . $this->lp_id . " AND
- parent_item_id = " . $parent . " AND
- previous_item_id = " . $previous;
- $res_select_old = Database::query($sql_select_old);
- $row_select_old = Database :: fetch_array($res_select_old);
-
-
- if (Database :: num_rows($res_select_old) == 0) {
- $new_next = 0;
- $new_order = 1;
- } else {
- $new_next = $row_select_old['id'];
- $new_order = $row_select_old['display_order'];
- }
-
-
-
- } else {
-
- $sql_select_old = "
- SELECT
- next_item_id,
- display_order
- FROM " . $tbl_lp_item . "
- WHERE id = " . $previous;
- $res_select_old = Database::query($sql_select_old);
- $row_select_old = Database :: fetch_array($res_select_old);
-
-
-
-
- $new_next = $row_select_old['next_item_id'];
- $new_order = $row_select_old['display_order'] + 1;
- }
-
-
- $sql_update = "
- UPDATE " . $tbl_lp_item . "
- SET
- title = '" . $this->escape_string($title) . "',
- description = '" . $this->escape_string($description) . "',
- parent_item_id = " . $parent . ",
- previous_item_id = " . $previous . ",
- next_item_id = " . $new_next . ",
- display_order = " . $new_order . "
- " . $audio_update_sql . "
- WHERE id = " . $id;
- $res_update_next = Database::query($sql_update);
-
- if ($previous != 0) {
-
- $sql_update_previous = "
- UPDATE " . $tbl_lp_item . "
- SET next_item_id = " . $id . "
- WHERE id = " . $previous;
- $res_update_next = Database::query($sql_update_previous);
-
- }
- if ($new_next != 0) {
-
- $sql_update_next = "
- UPDATE " . $tbl_lp_item . "
- SET previous_item_id = " . $id . "
- WHERE id = " . $new_next;
- $res_update_next = Database::query($sql_update_next);
-
- }
- if ($old_prerequisite != $prerequisites) {
- $sql_update_next = "
- UPDATE " . $tbl_lp_item . "
- SET prerequisite = " . $prerequisites . "
- WHERE id = " . $id;
- $res_update_next = Database::query($sql_update_next);
- }
- if ($old_max_time_allowed != $max_time_allowed) {
- $sql_update_max_time_allowed = "
- UPDATE " . $tbl_lp_item . "
- SET max_time_allowed = " . $max_time_allowed . "
- WHERE id = " . $id;
- $res_update_max_time_allowed = Database::query($sql_update_max_time_allowed);
- }
-
- $sql_update_order = "
- UPDATE " . $tbl_lp_item . "
- SET display_order = display_order + 1
- WHERE
- lp_id = " . $this->get_id() . " AND
- id <> " . $id . " AND
- parent_item_id = " . $parent . " AND
- display_order >= " . $new_order;
- $res_update_next = Database::query($sql_update_order);
- }
- }
-
- public function edit_item_prereq($id, $prerequisite_id, $mastery_score = 0, $max_score = 100) {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::edit_item_prereq(' . $id . ',' . $prerequisite_id . ',' . $mastery_score . ',' . $max_score . ')', 0);
- }
- if (empty ($id) or ($id != strval(intval($id))) or empty ($prerequisite_id)) {
- return false;
- }
- $prerequisite_id = $this->escape_string($prerequisite_id);
- $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
- if (!is_numeric($mastery_score) || $mastery_score < 0)
- $mastery_score = 0;
- if (!is_numeric($max_score) || $max_score < 0)
- $max_score = 100;
- if ($mastery_score > $max_score)
- $max_score = $mastery_score;
- if (!is_numeric($prerequisite_id))
- $prerequisite_id = 'NULL';
- $sql_upd = " UPDATE " . $tbl_lp_item . "
- SET prerequisite = " . $prerequisite_id . " WHERE id = " . $id;
- $res_upd = Database::query($sql_upd);
- if ($prerequisite_id != 'NULL' && $prerequisite_id != '') {
- $sql_upd = " UPDATE " . $tbl_lp_item . " SET
- mastery_score = " . $mastery_score .
-
- " WHERE ref = '" . $prerequisite_id . "'";
- $res_upd = Database::query($sql_upd);
- }
-
- return true;
- }
-
- public function escape_string($string) {
-
- return Database :: escape_string($string);
- }
-
- public function export_lp($type, $course, $id, $zipname) {
-
- if (empty($type) || empty($course) || empty($id) || empty($zipname)) {
- return false;
- }
- $url = '';
- switch ($type) {
- case 'scorm':
- break;
- case 'zip':
- break;
- case 'cdrom':
- break;
- }
- return $url;
- }
-
- public function get_brother_chapters($id) {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::get_brother_chapters()', 0);
- }
- if (empty ($id) OR $id != strval(intval($id))) {
- return array ();
- }
- $lp_item = Database :: get_course_table(TABLE_LP_ITEM);
- $sql_parent = "SELECT * FROM $lp_item WHERE id = $id AND item_type='dokeos_chapter'";
- $res_parent = Database::query($sql_parent);
- if (Database :: num_rows($res_parent) > 0) {
- $row_parent = Database :: fetch_array($res_parent);
- $parent = $row_parent['parent_item_id'];
- $sql_bros = "SELECT * FROM $lp_item WHERE parent_item_id = $parent AND id = $id AND item_type='dokeos_chapter' ORDER BY display_order";
- $res_bros = Database::query($sql_bros);
- $list = array ();
- while ($row_bro = Database :: fetch_array($res_bros)) {
- $list[] = $row_bro;
- }
- return $list;
- }
- return array ();
- }
-
- public function get_brother_items($id) {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::get_brother_items(' . $id . ')', 0);
- }
- if (empty ($id) OR $id != strval(intval($id))) {
- return array ();
- }
- $lp_item = Database :: get_course_table(TABLE_LP_ITEM);
- $sql_parent = "SELECT * FROM $lp_item WHERE id = $id";
- $res_parent = Database::query($sql_parent);
- if (Database :: num_rows($res_parent) > 0) {
- $row_parent = Database :: fetch_array($res_parent);
- $parent = $row_parent['parent_item_id'];
- $sql_bros = "SELECT * FROM $lp_item WHERE parent_item_id = $parent ORDER BY display_order";
- $res_bros = Database::query($sql_bros);
- $list = array ();
- while ($row_bro = Database :: fetch_array($res_bros)) {
- $list[] = $row_bro;
- }
- return $list;
- }
- return array ();
- }
-
- public function get_common_index_terms_by_prefix($prefix) {
- require_once api_get_path(LIBRARY_PATH).'specific_fields_manager.lib.php';
- $terms = get_specific_field_values_list_by_prefix($prefix, $this->cc, TOOL_LEARNPATH, $this->lp_id);
- $prefix_terms = array();
- if (!empty($terms)) {
- foreach ($terms as $term) {
- $prefix_terms[] = $term['value'];
- }
- }
- return $prefix_terms;
- }
-
- public function get_complete_items_count() {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::get_complete_items_count()', 0);
- }
- $i = 0;
- foreach ($this->items as $id => $dummy) {
-
- if ($this->items[$id]->status_is(array (
- 'completed',
- 'passed',
- 'succeeded',
- 'browsed',
- 'failed'
- )) && $this->items[$id]->get_type() != 'dokeos_chapter' && $this->items[$id]->get_type() != 'dir') {
- $i++;
- }
- }
- return $i;
- }
-
- public function get_current_item_id() {
- $current = 0;
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::get_current_item_id()', 0);
- }
- if (!empty ($this->current)) {
- $current = $this->current;
- }
- if ($this->debug > 2) {
- error_log('New LP - In learnpath::get_current_item_id() - Returning ' . $current, 0);
- }
- return $current;
- }
-
- public function get_first_item_id() {
- $current = 0;
- if (is_array($this->ordered_items)) {
- $current = $this->ordered_items[0];
- }
- return $current;
- }
-
- public function get_total_items_count() {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::get_total_items_count()', 0);
- }
- return count($this->items);
- }
-
- public function get_total_items_count_without_chapters() {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::get_total_items_count_without_chapters()', 0);
- }
- $total = 0;
- foreach ($this->items as $temp => $temp2) {
- if (!in_array($temp2->get_type(), array (
- 'dokeos_chapter',
- 'chapter',
- 'dir'
- )))
- $total++;
- }
- return $total;
- }
-
- public function first() {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::first()', 0);
- }
-
- if (count($this->ordered_items) == 0) {
- $this->index = 0;
- }
- 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()) {
- if ($this->debug > 2) {
- 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);
- }
- $index = -1;
- foreach ($this->ordered_items as $myindex => $item_id) {
- if ($item_id == $this->last_item_seen) {
- $index = $myindex;
- break;
- }
- }
- if ($index == -1) {
-
- if ($this->debug > 2) {
- error_log('New LP - Last item (' . $this->last_item_seen . ') was found in items but not in ordered_items, panic!', 0);
- }
- return false;
- } else {
- $this->last = $this->last_item_seen;
- $this->current = $this->last_item_seen;
- $this->index = $index;
- }
- } else {
- if ($this->debug > 2) {
- error_log('New LP - In learnpath::first() - No last item seen', 0);
- }
- $index = 0;
-
-
- 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) {
- $index++;
- }
- $this->last = $this->current;
-
- $this->current = $this->ordered_items[$index];
- $this->index = $index;
- if ($this->debug > 2) {
- error_log('New LP - In learnpath::first() - No last item seen. New last = ' . $this->last . '(' . $this->ordered_items[$index] . ')', 0);
- }
- }
- if ($this->debug > 2) {
- error_log('New LP - In learnpath::first() - First item is ' . $this->get_current_item_id());
- }
- }
-
- public function get_js_info($item_id = '') {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::get_js_info(' . $item_id . ')', 0);
- }
- $info = '';
- $item_id = $this->escape_string($item_id);
- if (!empty($item_id) && is_object($this->items[$item_id])) {
-
- $oItem = $this->items[$item_id];
- $info .= '<script language="javascript">';
- $info .= "top.set_score(" . $oItem->get_score() . ");\n";
- $info .= "top.set_max(" . $oItem->get_max() . ");\n";
- $info .= "top.set_min(" . $oItem->get_min() . ");\n";
- $info .= "top.set_lesson_status('" . $oItem->get_status() . "');";
- $info .= "top.set_session_time('" . $oItem->get_scorm_time('js') . "');";
- $info .= "top.set_suspend_data('" . $oItem->get_suspend_data() . "');";
- $info .= "top.set_saved_lesson_status('" . $oItem->get_status() . "');";
- $info .= "top.set_flag_synchronized();";
- $info .= '</script>';
- if ($this->debug > 2) {
- error_log('New LP - in learnpath::get_js_info(' . $item_id . ') - returning: ' . $info, 0);
- }
- return $info;
- } else {
-
- $info .= '<script language="javascript">';
- $info .= "top.set_score(" . learnpathItem :: get_score() . ");\n";
- $info .= "top.set_max(" . learnpathItem :: get_max() . ");\n";
- $info .= "top.set_min(" . learnpathItem :: get_min() . ");\n";
- $info .= "top.set_lesson_status('" . learnpathItem :: get_status() . "');";
- $info .= "top.set_session_time('" . learnpathItem :: get_scorm_time('js') . "');";
- $info .= "top.set_suspend_data('" . learnpathItem :: get_suspend_data() . "');";
- $info .= "top.set_saved_lesson_status('" . learnpathItem :: get_status() . "');";
- $info .= "top.set_flag_synchronized();";
- $info .= '</script>';
- if ($this->debug > 2) {
- error_log('New LP - in learnpath::get_js_info(' . $item_id . ') - returning: ' . $info, 0);
- }
- return $info;
- }
- }
-
- public function get_js_lib() {
- $lib = '';
- if (!empty ($this->js_lib)) {
- $lib = $this->js_lib;
- }
- return $lib;
- }
-
- public function get_id() {
-
- if (!empty ($this->lp_id)) {
- return $this->lp_id;
- } else {
- return 0;
- }
- }
-
- public function get_last() {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::get_last()', 0);
- }
- $this->index = count($this->ordered_items) - 1;
- return $this->ordered_items[$this->index];
- }
-
- public function get_navigation_bar() {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::get_navigation_bar()', 0);
- }
-
- $file = '';
- $openDir = '';
- $edoceo = '';
- $time = 0;
- $navbar = '';
- $RequestUri = '';
- $mycurrentitemid = $this->get_current_item_id();
- if ($this->mode == 'fullscreen') {
- $navbar = '<table cellpadding="0" cellspacing="0" align="left">' . "\n" .
- ' <tr> ' . "\n" .
- ' <td>' . "\n" .
- ' <div class="buttons">' . "\n" .
- ' <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" .
- ' <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" .
- ' <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" .
-
-
- ' </div>' . "\n" .
- ' </td>' . "\n" .
- ' </tr>' . "\n" .
- '</table>';
- } else {
- $navbar = '<table cellpadding="0" cellspacing="0" align="left">' . "\n" .
- ' <tr> ' . "\n" .
- ' <td>' . "\n" .
- ' <div class="buttons">' . "\n" .
- ' <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" .
- ' <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" .
- ' <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" .
-
- ' </div>' . "\n" .
- ' </td>' . "\n" .
- ' </tr>' . "\n" .
- '</table>';
- }
- return $navbar;
- }
-
- public function get_next_index() {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::get_next_index()', 0);
- }
-
- $index = $this->index;
- $index++;
- if ($this->debug > 2) {
- error_log('New LP - Now looking at ordered_items[' . ($index) . '] - type is ' . $this->items[$this->ordered_items[$index]]->type, 0);
- }
- 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) {
- $index++;
- if ($index == $this->max_ordered_items){
- if ($this->items[$this->ordered_items[$index]]->get_type() == 'dir' || $this->items[$this->ordered_items[$index]]->get_type() == 'dokeos_chapter') {
- return $this->index;
- } else {
- return $index;
- }
- }
- }
- if (empty ($this->ordered_items[$index])) {
- return $this->index;
- }
- if ($this->debug > 2) {
- error_log('New LP - index is now ' . $index, 0);
- }
- return $index;
- }
-
- public function get_next_item_id() {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::get_next_item_id()', 0);
- }
- $new_index = $this->get_next_index();
- if (!empty ($new_index)) {
- if (isset ($this->ordered_items[$new_index])) {
- if ($this->debug > 2) {
- error_log('New LP - In learnpath::get_next_index() - Returning ' . $this->ordered_items[$new_index], 0);
- }
- return $this->ordered_items[$new_index];
- }
- }
- if ($this->debug > 2) {
- error_log('New LP - In learnpath::get_next_index() - Problem - Returning 0', 0);
- }
- return 0;
- }
-
- public function get_package_type($file_path, $file_name) {
-
- $file_info = pathinfo($file_name);
- $filename = $file_info['basename'];
- $extension = $file_info['extension'];
- if (!empty($_POST['ppt2lp']) && !in_array(strtolower($extension), array (
- 'dll',
- 'exe'
- ))) {
- return 'oogie';
- }
- if (!empty($_POST['woogie']) && !in_array(strtolower($extension), array (
- 'dll',
- 'exe'
- ))) {
- return 'woogie';
- }
- $file_base_name = str_replace('.' . $extension, '', $filename);
- $zipFile = new pclZip($file_path);
-
- $zipContentArray = $zipFile->listContent();
- $package_type = '';
- $at_root = false;
- $manifest = '';
-
- if (is_array($zipContentArray) && count($zipContentArray) > 0) {
- foreach ($zipContentArray as $thisContent) {
- if (preg_match('~.(php.*|phtml)$~i', $thisContent['filename'])) {
-
- }
- elseif (stristr($thisContent['filename'], 'imsmanifest.xml') !== false) {
- $manifest = $thisContent['filename'];
- $package_type = 'scorm';
- break;
- }
- elseif (preg_match('/aicc\//i', $thisContent['filename'])) {
-
- $package_type = 'aicc';
-
- } else {
- $package_type = '';
- }
- }
- }
- return $package_type;
- }
-
- public function get_previous_index() {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::get_previous_index()', 0);
- }
- $index = $this->index;
- if (isset ($this->ordered_items[$index -1])) {
- $index--;
- 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')) {
- $index--;
- if ($index < 0) {
- return $this->index;
- }
- }
- } else {
- if ($this->debug > 2) {
- error_log('New LP - get_previous_index() - there was no previous index available, reusing ' . $index, 0);
- }
-
- }
- return $index;
- }
-
- public function get_previous_item_id() {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::get_previous_item_id()', 0);
- }
- $new_index = $this->get_previous_index();
- return $this->ordered_items[$new_index];
- }
-
- public function get_progress() {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::get_progress()', 0);
- }
- if (!empty ($this->progress_db)) {
- return $this->progress_db;
- }
- return 0;
- }
-
- public function get_db_progress($lp_id, $user_id, $mode = '%', $course_db = '', $sincere = false,$session_id = 0) {
-
- $session_id = intval($session_id);
- $session_condition = api_get_session_condition($session_id);
- $table = Database :: get_course_table(TABLE_LP_VIEW, $course_db);
- $sql = "SELECT * FROM $table WHERE lp_id = $lp_id AND user_id = $user_id $session_condition";
- $res = Database::query($sql);
- $view_id = 0;
- if (Database :: num_rows($res) > 0) {
- $row = Database :: fetch_array($res);
- $progress = $row['progress'];
- $view_id = $row['id'];
- } else {
- if ($sincere) {
- return null;
- }
- }
- if (empty ($progress)) {
- $progress = '0';
- }
- if ($mode == '%') {
- return $progress . '%';
- } else {
-
- $tbl = Database :: get_course_table(TABLE_LP_ITEM, $course_db);
- $sql = "SELECT count(*) FROM $tbl WHERE lp_id = " . $lp_id . "
- AND item_type NOT IN('dokeos_chapter','chapter','dir')";
- $res = Database::query($sql);
- $row = Database :: fetch_array($res);
- $total = $row[0];
- $tbl_item_view = Database :: get_course_table(TABLE_LP_ITEM_VIEW, $course_db);
- $tbl_item = Database :: get_course_table(TABLE_LP_ITEM, $course_db);
-
-
- $sql = "SELECT count(distinct(lp_item_id))
- FROM $tbl_item_view as item_view
- INNER JOIN $tbl_item as item
- ON item.id = item_view.lp_item_id
- AND item_type NOT IN('dokeos_chapter','chapter','dir')
- WHERE lp_view_id = " . $view_id . "
- AND status IN ('passed','completed','succeeded','browsed','failed')";
- $res = Database::query($sql);
- $row = Database :: fetch_array($res);
- $completed = $row[0];
- if ($mode == 'abs') {
- return $completed . '/' . $total;
- }
- elseif ($mode == 'both') {
- if ($progress < ($completed / ($total ? $total : 1))) {
- $progress = number_format(($completed / ($total ? $total : 1)) * 100, 0);
- }
- return $progress . '% (' . $completed . '/' . $total . ')';
- }
- }
- return $progress;
- }
-
- public function get_mediaplayer($autostart='true') {
- global $_course;
- $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
- $tbl_lp_item_view = Database :: get_course_table(TABLE_LP_ITEM_VIEW);
-
- $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 " .
- "WHERE lp.id = '" . $_SESSION['oLP']->current . "'";
- $result = Database::query($sql);
- $row = Database::fetch_assoc($result);
- $output = '';
- if (!empty ($row['audio'])) {
- $list = $_SESSION['oLP']->get_toc();
- $type_quiz = false;
- foreach($list as $toc) {
- if ($toc['id'] == $_SESSION['oLP']->current && ($toc['type']=='quiz') ) {
- $type_quiz = true;
- }
- }
- if ($type_quiz) {
- if ($_SESSION['oLP']->prevent_reinit == 1) {
- $row['status'] === 'completed' ? $autostart_audio = 'false' : $autostart_audio = 'true';
- } else {
- $autostart_audio = $autostart;
- }
- } else {
- $autostart_audio = 'true';
- }
-
- $output = '<div id="container">';
- $output .= '<script type="text/javascript" src="../inc/lib/mediaplayer/swfobject.js"></script>';
- $output .= '<script type="text/javascript">
- var s1 = new SWFObject("../inc/lib/mediaplayer/player.swf","ply","250","20","9","#FFFFFF");
- s1.addParam("allowscriptaccess","always");
- s1.addParam("flashvars","file=' . api_get_path(WEB_COURSE_PATH) . $_course['path'] . '/document/audio/' . $row['audio'] . '&autostart=' . $autostart_audio.'");
- s1.write("container");
- </script></div>';
- }
- return $output;
- }
-
- public function is_lp_visible_for_student($lp_id, $student_id, $course = null) {
- $lp_id = (int)$lp_id;
- $course = api_get_course_info($course);
- $tbl_learnpath = Database :: get_course_table(TABLE_LP_MAIN,$course['dbName']);
-
- $sql = "SELECT id, prerequisite, publicated_on, expired_on FROM $tbl_learnpath WHERE id = $lp_id";
- $rs = Database::query($sql);
- if (Database::num_rows($rs)>0) {
- $row = Database::fetch_array($rs);
- $prerequisite = $row['prerequisite'];
- $find = array(' ','-',':');
- $from = str_replace($find,'',api_get_local_time($row['publicated_on']));
- $to = str_replace($find,'',api_get_local_time($row['expired_on']));
- $is_visible = true;
- $progress = 0;
-
- if (!empty($prerequisite)) {
- $progress = self::get_db_progress($prerequisite,$student_id,'%', '', false, api_get_session_id());
- $progress = intval($progress);
- if ($progress < 100) {
- $is_visible = false;
- }
- }
-
- if ($is_visible) {
- $now = str_replace($find,'',api_get_local_time());
- if ((($row['publicated_on']!='0000-00-00 00:00:00') && ($now<$from)) or (($row['expired_on']!='0000-00-00 00:00:00') && ($now>$to))) {
- $is_visible = false;
- }
- }
- return $is_visible;
- }
- return false;
- }
-
- public function get_progress_bar($mode = '', $percentage = -1, $text_add = '', $from_lp = false) {
-
- global $lp_theme_css;
-
- if (!empty ($lp_theme_css)) {
- $css_path = api_get_path(WEB_CODE_PATH) . 'css/' . $lp_theme_css . '/images/';
- } else {
- $css_path = '../img/';
- }
-
- if (isset($this) && is_object($this) && ($percentage == '-1' OR $text_add == '')) {
- list($percentage, $text_add) = $this->get_progress_bar_text($mode);
- }
- $text = $percentage . $text_add;
-
-
- $factor = 1.2;
- if ($from_lp)
- $progress_height = '26';
- else
- $progress_height = '16';
- $size = str_replace('%', '', $percentage);
- $output ='<div style="width:135px">' .
- '<img id="progress_img_limit_left" src="' . $css_path . 'bar_1.gif" width="1" height="' . $progress_height . '">' .
- '<img id="progress_img_full" src="' . $css_path . 'bar_1u.gif" width="' . $size * $factor . 'px" height="' . $progress_height . '" id="full_portion">' .
- '<img id="progress_img_limit_middle" src="' . $css_path . 'bar_1m.gif" width="1" height="' . $progress_height . '">';
- if ($percentage <= 98) {
- $output .= '<img id="progress_img_empty" src="' . $css_path . 'bar_1r.gif" width="' . (100 - $size) * $factor . 'px" height="' . $progress_height . '" id="empty_portion">';
- } else {
- $output .= '<img id="progress_img_empty" src="' . $css_path . 'bar_1r.gif" width="0" height="' . $progress_height . '" id="empty_portion">';
- }
- $output .= '<img id="progress_bar_img_limit_right" src="' . $css_path . 'bar_1.gif" width="1" height="' . $progress_height . '"></div>' .
- '<div class="progresstext" id="progress_text">' . $text . '</div>';
- return $output;
- }
-
- public function get_progress_bar_text($mode = '', $add = 0) {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::get_progress_bar_text()', 0);
- }
- if (empty ($mode)) {
- $mode = $this->progress_bar_mode;
- }
- $total_items = $this->get_total_items_count_without_chapters();
- if ($this->debug > 2) {
- error_log('New LP - Total items available in this learnpath: ' . $total_items, 0);
- }
- $i = $this->get_complete_items_count();
- if ($this->debug > 2) {
- error_log('New LP - Items completed so far: ' . $i, 0);
- }
- if ($add != 0) {
- $i += $add;
- if ($this->debug > 2) {
- error_log('New LP - Items completed so far (+modifier): ' . $i, 0);
- }
- }
- $text = '';
- if ($i > $total_items) {
- $i = $total_items;
- }
- if ($mode == '%') {
- if ($total_items > 0) {
- $percentage = ((float) $i / (float) $total_items) * 100;
- } else {
- $percentage = 0;
- }
- $percentage = number_format($percentage, 0);
- $text = '%';
- }
- elseif ($mode == 'abs') {
- $percentage = $i;
- $text = '/' . $total_items;
- }
- return array (
- $percentage,
- $text
- );
- }
-
- public function get_progress_bar_mode() {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::get_progress_bar_mode()', 0);
- }
- if (!empty ($this->progress_bar_mode)) {
- return $this->progress_bar_mode;
- } else {
- return '%';
- }
- }
-
- public function get_proximity() {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::get_proximity()', 0);
- }
- if (!empty ($this->proximity)) {
- return $this->proximity;
- } else {
- return '';
- }
- }
-
- public function get_theme() {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::get_theme()', 0);
- }
- if (!empty ($this->theme)) {
- return $this->theme;
- } else {
- return '';
- }
- }
-
- public function get_lp_session_id() {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::get_lp_session_id()', 0);
- }
- if (!empty ($this->lp_session_id)) {
- return $this->lp_session_id;
- } else {
- return 0;
- }
- }
-
- public function get_preview_image() {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::get_preview_image()', 0);
- }
- if (!empty ($this->preview_image)) {
- return $this->preview_image;
- } else {
- return '';
- }
- }
-
- public function get_author() {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::get_author()', 0);
- }
- if (!empty ($this->author)) {
- return $this->author;
- } else {
- return '';
- }
- }
-
- public function get_scorm_prereq_string($item_id) {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::get_scorm_prereq_string()', 0);
- }
- if (!is_object($this->items[$item_id])) {
- return false;
- }
- $oItem = $this->items[$item_id];
- $prereq = $oItem->get_prereq_string();
- if (empty ($prereq)) {
- return '';
- }
- if (preg_match('/^\d+$/', $prereq) && is_object($this->items[$prereq])) {
-
- return 'ITEM_' . $prereq;
- } else {
- if (isset ($this->refs_list[$prereq])) {
-
-
- return 'ITEM_' . $this->refs_list[$prereq];
- } else {
-
-
-
-
- $find = array (
- '&',
- '|',
- '~',
- '=',
- '<>',
- '{',
- '}',
- '*',
- '(',
- ')'
- );
- $replace = array (
- ' ',
- ' ',
- ' ',
- ' ',
- ' ',
- ' ',
- ' ',
- ' ',
- ' ',
- ' '
- );
- $prereq_mod = str_replace($find, $replace, $prereq);
- $ids = split(' ', $prereq_mod);
- foreach ($ids as $id) {
- $id = trim($id);
- if (isset ($this->refs_list[$id])) {
- $prereq = preg_replace('/[^a-zA-Z_0-9](' . $id . ')[^a-zA-Z_0-9]/', 'ITEM_' . $this->refs_list[$id], $prereq);
- }
- }
- error_log('New LP - In learnpath::get_scorm_prereq_string(): returning modified string: ' . $prereq, 0);
- return $prereq;
- }
- }
- }
-
- public function get_scorm_xml_node(& $children, $id) {
- for ($i = 0; $i < $children->length; $i++) {
- $item_temp = $children->item($i);
- if ($item_temp->nodeName == 'item') {
- if ($item_temp->getAttribute('identifier') == $id) {
- return $item_temp;
- }
- }
- $subchildren = $item_temp->childNodes;
- if ($subchildren->length > 0) {
- $val = $this->get_scorm_xml_node($subchildren, $id);
- if (is_object($val)) {
- return $val;
- }
- }
- }
- return false;
- }
-
- public function get_stats() {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::get_stats()', 0);
- }
-
- }
-
- public function get_stats_course($course) {
-
-
- }
-
- public function get_stats_lp($course, $lp) {
-
-
- }
-
- public function get_stats_lp_user($course, $lp, $user) {
-
-
- }
-
- public function get_stats_user($course, $user) {
-
-
- }
-
- public function get_items_status_list() {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::get_items_status_list()', 0);
- }
- $list = array ();
- foreach ($this->ordered_items as $item_id) {
- $list[] = array (
- $item_id => $this->items[$item_id]->get_status()
- );
- }
- return $list;
- }
-
- public function get_interactions_count_from_db($lp_iv_id = 0, $course_code = null) {
- if (empty ($lp_iv_id)) {
- return -1;
- }
- $course_info = api_get_course_info($course_code);
- $table = Database :: get_course_table(TABLE_LP_IV_INTERACTION, $course_info['db_name']);
- $sql = "SELECT count(*) FROM $table WHERE lp_iv_id = $lp_iv_id";
- $res = Database::query($sql);
- $row = Database :: fetch_array($res);
- $num = $row[0];
- return $num;
- }
-
- public function get_iv_interactions_array($lp_iv_id = 0) {
- $list = array ();
- $table = Database :: get_course_table(TABLE_LP_IV_INTERACTION);
- $sql = "SELECT * FROM $table WHERE lp_iv_id = $lp_iv_id ORDER BY order_id ASC";
- $res = Database::query($sql);
- $num = Database :: num_rows($res);
- if ($num > 0) {
- $list[] = array (
- 'order_id' => api_htmlentities(get_lang('Order'), ENT_QUOTES),
- 'id' => api_htmlentities(get_lang('InteractionID'), ENT_QUOTES),
- 'type' => api_htmlentities(get_lang('Type'), ENT_QUOTES),
- 'time' => api_htmlentities(get_lang('TimeFinished'), ENT_QUOTES),
- 'correct_responses' => api_htmlentities(get_lang('CorrectAnswers'), ENT_QUOTES),
- 'student_response' => api_htmlentities(get_lang('StudentResponse'), ENT_QUOTES),
- 'result' => api_htmlentities(get_lang('Result'), ENT_QUOTES),
- 'latency' => api_htmlentities(get_lang('LatencyTimeSpent'), ENT_QUOTES)
- );
- while ($row = Database :: fetch_array($res)) {
- $list[] = array (
- 'order_id' => ($row['order_id'] + 1),
- 'id' => urldecode($row['interaction_id']),
- 'type' => $row['interaction_type'],
- 'time' => $row['completion_time'],
-
- 'correct_responses' => '',
- 'student_response' => $row['student_response'],
- 'result' => $row['result'],
- 'latency' => $row['latency']
- );
- }
- }
- return $list;
- }
-
- public function get_objectives_count_from_db($lp_iv_id = 0, $course_code = null) {
- if (empty ($lp_iv_id)) {
- return -1;
- }
- $course_info = api_get_course_info($course_code);
- $table = Database :: get_course_table(TABLE_LP_IV_OBJECTIVE, $course_info['db_name']);
- $sql = "SELECT count(*) FROM $table WHERE lp_iv_id = $lp_iv_id";
- $res = Database::query($sql);
- $row = Database :: fetch_array($res);
- $num = $row[0];
- return $num;
- }
-
- public function get_iv_objectives_array($lp_iv_id = 0) {
- $list = array();
- $table = Database :: get_course_table(TABLE_LP_IV_OBJECTIVE);
- $sql = "SELECT * FROM $table WHERE lp_iv_id = $lp_iv_id ORDER BY order_id ASC";
- $res = Database::query($sql);
- $num = Database :: num_rows($res);
- if ($num > 0) {
- $list[] = array (
- 'order_id' => api_htmlentities(get_lang('Order'), ENT_QUOTES),
- 'objective_id' => api_htmlentities(get_lang('ObjectiveID'), ENT_QUOTES),
- 'score_raw' => api_htmlentities(get_lang('ObjectiveRawScore'), ENT_QUOTES),
- 'score_max' => api_htmlentities(get_lang('ObjectiveMaxScore'), ENT_QUOTES),
- 'score_min' => api_htmlentities(get_lang('ObjectiveMinScore'), ENT_QUOTES),
- 'status' => api_htmlentities(get_lang('ObjectiveStatus'), ENT_QUOTES)
- );
- while ($row = Database :: fetch_array($res)) {
- $list[] = array (
- 'order_id' => ($row['order_id'] + 1),
- 'objective_id' => urldecode($row['objective_id']),
- 'score_raw' => $row['score_raw'],
- 'score_max' => $row['score_max'],
- 'score_min' => $row['score_min'],
- 'status' => $row['status']
- );
- }
- }
- return $list;
- }
-
- public function get_toc() {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::get_toc()', 0);
- }
- $toc = array ();
-
- foreach ($this->ordered_items as $item_id) {
- if ($this->debug > 2) {
- error_log('New LP - learnpath::get_toc(): getting info for item ' . $item_id, 0);
- }
-
- $toc[] = array (
- 'id' => $item_id,
- 'title' => $this->items[$item_id]->get_title(),
-
- 'status' => $this->items[$item_id]->get_status(),
- 'level' => $this->items[$item_id]->get_level(),
- 'type' => $this->items[$item_id]->get_type(),
- 'description' => $this->items[$item_id]->get_description(),
- 'path' => $this->items[$item_id]->get_path(),
- );
- }
- if ($this->debug > 2) {
- error_log('New LP - In learnpath::get_toc() - TOC array: ' . print_r($toc, true), 0);
- }
- return $toc;
- }
-
- public function get_items_details_as_js($varname = 'olms.lms_item_types') {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::get_items_details_as_js()', 0);
- }
- $toc = $varname.' = new Array();';
-
- foreach ($this->ordered_items as $item_id) {
- if ($this->debug > 2) {
- error_log('New LP - learnpath::get_items_details_as_js(): getting info for item ' . $item_id, 0);
- }
- $toc.= $varname."['i$item_id'] = '".$this->items[$item_id]->get_type()."';";
- }
- if ($this->debug > 2) {
- error_log('New LP - In learnpath::get_items_details_as_js() - TOC array: ' . print_r($toc, true), 0);
- }
- return $toc;
- }
-
- public function get_type($get_name = false) {
- $res = false;
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::get_type()', 0);
- }
- if (!empty ($this->type)) {
- if ($get_name) {
-
- } else {
- $res = $this->type;
- }
- }
- if ($this->debug > 2) {
- error_log('New LP - In learnpath::get_type() - Returning ' . ($res ? $res : 'false'), 0);
- }
- return $res;
- }
-
- public function get_type_static($lp_id = 0) {
- $tbl_lp = Database :: get_course_table(TABLE_LP_MAIN);
- $sql = "SELECT lp_type FROM $tbl_lp WHERE id = '" . $lp_id . "'";
- $res = Database::query($sql);
- if ($res === false) {
- return null;
- }
- if (Database :: num_rows($res) <= 0) {
- return null;
- }
- $row = Database :: fetch_array($res);
- return $row['lp_type'];
- }
-
- public function get_flat_ordered_items_list($lp, $parent = 0, $course_db = '') {
-
- $list = array();
- if (empty ($lp)) {
- return false;
- }
- $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM, $course_db);
- $sql = "SELECT * FROM $tbl_lp_item WHERE lp_id = $lp AND parent_item_id = $parent ORDER BY display_order";
- $res = Database::query($sql);
- while ($row = Database :: fetch_array($res)) {
- $sublist = learnpath :: get_flat_ordered_items_list($lp, $row['id'], $course_db);
- $list[] = $row['id'];
- foreach ($sublist as $item) {
- $list[] = $item;
- }
- }
- return $list;
- }
-
- public function get_html_toc() {
- $is_allowed_to_edit = api_is_allowed_to_edit(null, true);
- $charset = api_get_system_encoding();
- $display_action_links_with_icons = false;
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::get_html_toc()', 0);
- }
- $list = $this->get_toc();
-
-
-
- $html = '<div id="scorm_title" class="scorm_title"><div class="scorm_title_text">' . Security::remove_XSS($this->get_name()) . '</div></div>';
-
- if ($is_allowed_to_edit) {
- $gradebook = Security :: remove_XSS($_GET['gradebook']);
-
- if ($this->get_lp_session_id() == api_get_session_id()) {
- $html .= '<div id="actions_lp" class="actions_lp">';
- if ($display_action_links_with_icons) {
- $html .= '<div style = "text-align:center;">';
- $html .= "<a href='lp_controller.php?" . api_get_cidreq() . "&action=build&lp_id=" . $this->lp_id . "' target='_parent'>" . Display :: return_icon('build_learnpath.png', get_lang('Build'),'','32')."</a>";
- $html .= "<a href='lp_controller.php?" . api_get_cidreq() . "&action=admin_view&lp_id=" . $this->lp_id . "' target='_parent'>" . Display :: return_icon('move_learnpath.png', get_lang('BasicOverview'),'','32')."</a>";
- $html .= '<span>' . Display :: return_icon('view_remove_na.png', get_lang('Display'),'','32').'</span><br />';
- $html .= '<a href="lp_controller.php?' . api_get_cidreq() . '">'. get_lang('ReturnToLPList') . '</a>';
- $html .= '</div>';
- } else {
- $html .= '<div style = "text-align:center;">';
- $html .= "<a href='lp_controller.php?" . api_get_cidreq() . "&gradebook=$gradebook&action=build&lp_id=" . $this->lp_id . "' target='_parent'>" . get_lang('Build') . "</a>";
- $html .= "<a href='lp_controller.php?" . api_get_cidreq() . "&action=admin_view&lp_id=" . $this->lp_id . "' target='_parent'>" . get_lang('BasicOverview') . "</a>";
- $html .= '<span><b>' . get_lang('Display') . '</b></span><br />';
- $html .= '<a href="lp_controller.php?' . api_get_cidreq() . '">'. get_lang('ReturnToLPList') . '</a>';
- $html .= '</div>';
- }
- $html .= '</div>';
- }
- }
- $html .= '<div id="inner_lp_toc" class="inner_lp_toc">';
- require_once 'resourcelinker.inc.php';
-
- $mycurrentitemid = $this->get_current_item_id();
- $color_counter = 0;
- $i = 0;
- foreach ($list as $item) {
- if ($this->debug > 2) {
- error_log('New LP - learnpath::get_html_toc(): using item ' . $item['id'], 0);
- }
-
- $icon_name = array (
- 'not attempted' => '../img/notattempted.gif',
- 'incomplete' => '../img/incomplete.png',
- 'failed' => '../img/delete.png',
- 'completed' => '../img/completed.png',
- 'passed' => '../img/passed.png',
- 'succeeded' => '../img/succeeded.png',
- 'browsed' => '../img/completed.png',
- );
- $style = 'scorm_item';
- $scorm_color_background = 'scorm_item';
- $style_item = 'scorm_item';
- $current = false;
- if ($item['id'] == $this->current) {
- $style = 'scorm_item_highlight';
- $scorm_color_background = 'scorm_item_highlight';
- } else
- if ($color_counter % 2 == 0) {
- $scorm_color_background = 'scorm_item_1';
- } else {
- $scorm_color_background = 'scorm_item_2';
- }
- if ($scorm_color_background != '') {
- $html .= '<div id="toc_' . $item['id'] . '" class="' . $scorm_color_background . '">';
- }
-
- if ($item['type'] != 'dokeos_module' && $item['type'] != 'dokeos_chapter') {
- $html .= '<a name="atoc_' . $item['id'] . '" />';
- $html .= '<div class="' . $style_item . '" style="padding-left: ' . ($item['level'] * 1.5) . 'em; padding-right:' . ($item['level'] / 2) . 'em" title="' . $item['description'] . '" >';
- } else {
- $html .= '<div class="' . $style_item . '" style="padding-left: ' . ($item['level'] * 2) . 'em; padding-right:' . ($item['level'] * 1.5) . 'em" title="' . $item['description'] . '" >';
- }
- $title = $item['title'];
- if (empty ($title)) {
- $title = rl_get_resource_name(api_get_course_id(), $this->get_id(), $item['id']);
- }
- $title = Security::remove_XSS($title);
- if ($item['type'] != 'dokeos_chapter' && $item['type'] != 'dir' && $item['type'] != 'dokeos_module') {
-
- $url = $this->get_link('http', $item['id']);
-
-
-
- $html .= '<a href="" onClick="switch_item(' .$mycurrentitemid . ',' .$item['id'] . ');' .'return false;" >' . stripslashes($title) . '</a>';
- } elseif ($item['type'] == 'dokeos_module' || $item['type'] == 'dokeos_chapter') {
- $html .= "<img align='absbottom' width='13' height='13' src='../img/lp_dokeos_module.png'> " . stripslashes($title);
- } elseif ($item['type'] == 'dir') {
- $html .= stripslashes($title);
- }
- $tbl_track_e_exercises = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
- $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
- $user_id = api_get_user_id();
- $course_id = api_get_course_id();
- $sql = "SELECT path FROM $tbl_track_e_exercises, $tbl_lp_item
- WHERE path = '" . $item['path'] . "' AND exe_user_id = '$user_id' AND exe_cours_id = '$course_id' AND path = exe_exo_id AND status <> 'incomplete'";
- $result = Database::query($sql);
- $count = Database :: num_rows($result);
- if ($item['type'] == 'quiz') {
- if ($item['status'] == 'completed') {
- $html .= " <img id='toc_img_" . $item['id'] . "' src='" . $icon_name[$item['status']] . "' alt='" . substr($item['status'], 0, 1) . "' width='14' />";
- }
- } else {
- if ($item['type'] != 'dokeos_chapter' && $item['type'] != 'dokeos_module' && $item['type'] != 'dir') {
- $html .= " <img id='toc_img_" . $item['id'] . "' src='" . $icon_name[$item['status']] . "' alt='" . substr($item['status'], 0, 1) . "' width='14' />";
- }
- }
- $html .= "</div>";
- if ($scorm_color_background != '') {
- $html .= '</div>';
- }
- $color_counter++;
- }
- $html .= "</div>";
- return $html;
- }
-
- public function get_maker() {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::get_maker()', 0);
- }
- if (!empty ($this->maker)) {
- return $this->maker;
- } else {
- return '';
- }
- }
-
- public function get_message() {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::get_message()', 0);
- }
- return $this->message;
- }
-
- public function get_name() {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::get_name()', 0);
- }
- if (!empty ($this->name)) {
- return $this->name;
- } else {
- return 'N/A';
- }
- }
-
- public function get_link($type = 'http', $item_id = null) {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::get_link(' . $type . ',' . $item_id . ')', 0);
- }
- if (empty($item_id)) {
- if ($this->debug > 2) {
- error_log('New LP - In learnpath::get_link() - no item id given in learnpath::get_link(), using current: ' . $this->get_current_item_id(), 0);
- }
- $item_id = $this->get_current_item_id();
- }
- if (empty ($item_id)) {
- if ($this->debug > 2) {
- error_log('New LP - In learnpath::get_link() - no current item id found in learnpath object', 0);
- }
-
-
- $item_id = $this->first();
- return '';
- }
- $file = '';
- $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
- $lp_item_table = Database :: get_course_table(TABLE_LP_ITEM);
- $lp_item_view_table = Database :: get_course_table(TABLE_LP_ITEM_VIEW);
- $item_id = Database::escape_string($item_id);
- $sel = "SELECT l.lp_type as ltype, l.path as lpath, li.item_type as litype, li.path as lipath, li.parameters as liparams " .
- "FROM $lp_table l, $lp_item_table li WHERE li.id = $item_id AND li.lp_id = l.id";
- if ($this->debug > 2) {
- error_log('New LP - In learnpath::get_link() - selecting item ' . $sel, 0);
- }
- $res = Database::query($sel);
- if (Database :: num_rows($res) > 0) {
- $row = Database :: fetch_array($res);
-
- $lp_type = $row['ltype'];
- $lp_path = $row['lpath'];
- $lp_item_type = $row['litype'];
- $lp_item_path = $row['lipath'];
- $lp_item_params = $row['liparams'];
- if (empty ($lp_item_params) && strpos($lp_item_path, '?') !== false) {
- list ($lp_item_path, $lp_item_params) = explode('?', $lp_item_path);
- }
-
-
-
-
-
- $sys_course_path = api_get_path(SYS_COURSE_PATH) . api_get_course_path();
- if ($type == 'http') {
- $course_path = api_get_path(WEB_COURSE_PATH) . api_get_course_path();
- } else {
- $course_path = $sys_course_path;
- }
-
- if (in_array($lp_item_type, array('quiz', 'document', 'link', 'forum', 'thread', 'student_publication'))) {
- $lp_type = 1;
- }
-
-
-
- switch ($lp_type) {
- case 1 :
- if ($lp_item_type == 'dokeos_chapter') {
- $file = 'lp_content.php?type=dir';
- } else {
- require_once 'resourcelinker.inc.php';
- $file = rl_get_resource_link_for_learnpath(api_get_course_id(), $this->get_id(), $item_id);
-
-
- if ($lp_item_type == 'link') {
- require_once api_get_path(LIBRARY_PATH).'link.lib.php';
- if (is_youtube_link($file)) {
- $src = get_youtube_video_id($file);
- $file = 'embed.php?type=youtube&src='.$src;
- }
- } else {
-
- $lp_item_id = $this->get_current_item_id();
- $lp_view_id = $this->get_view_id();
- $prevent_reinit = $this->items[$this->current]->get_prevent_reinit();
- $list = $this->get_toc();
- $type_quiz = false;
-
- foreach ($list as $toc) {
- if ($toc['id'] == $lp_item_id && ($toc['type'] == 'quiz')) {
- $type_quiz = true;
- }
- }
-
- if ($type_quiz) {
- $lp_item_id = Database :: escape_string($lp_item_id);
- $lp_view_id = Database :: escape_string($lp_view_id);
- $sql = "SELECT count(*) FROM $lp_item_view_table WHERE lp_item_id='" . (int) $lp_item_id . "' AND lp_view_id ='" . (int) $lp_view_id . "' AND status='completed'";
- $result = Database::query($sql);
- $row_count = Database :: fetch_row($result);
- $count_item_view = (int) $row_count[0];
- $not_multiple_attempt = 0;
- if ($prevent_reinit === 1 && $count_item_view > 0) {
- $not_multiple_attempt = 1;
- }
- $file .= '¬_multiple_attempt=' . $not_multiple_attempt;
- }
-
- $tmp_array = explode('/', $file);
- $document_name = $tmp_array[count($tmp_array) - 1];
- if (strpos($document_name, '_DELETED_')) {
- $file = 'blank.php?error=document_deleted';
- }
- }
- }
- break;
- case 2 :
- if ($this->debug > 2) {
- error_log('New LP - In learnpath::get_link() ' . __LINE__ . ' - Item type: ' . $lp_item_type, 0);
- }
- if ($lp_item_type != 'dir') {
-
-
-
-
-
-
-
- if (preg_match('#^[a-zA-Z]{2,5}://#', $lp_item_path) != 0) {
- if ($this->debug > 2) {
- error_log('New LP - In learnpath::get_link() ' . __LINE__ . ' - Found match for protocol in ' . $lp_item_path, 0);
- }
-
- $file = $lp_item_path;
- } else {
- if ($this->debug > 2) {
- error_log('New LP - In learnpath::get_link() ' . __LINE__ . ' - No starting protocol in ' . $lp_item_path, 0);
- }
-
- $lp_item_path = preg_replace('/%2F/', '/', $lp_item_path);
- $lp_item_path = preg_replace('/%3A/', ':', $lp_item_path);
-
- $file = $course_path . '/scorm/' . $lp_path . '/' . $lp_item_path;
-
- $file = str_replace('//', '/', $file);
- $file = str_replace(':/', '://', $file);
- if (substr($lp_path, -1) == '/') {
- $lp_path = substr($lp_path, 0, -1);
- }
- if (!is_file(realpath($sys_course_path . '/scorm/' . $lp_path . '/' . $lp_item_path))) {
-
- $decoded = html_entity_decode($lp_item_path);
- list ($decoded) = explode('?', $decoded);
- if (!is_file(realpath($sys_course_path . '/scorm/' . $lp_path . '/' . $decoded))) {
- require_once 'resourcelinker.inc.php';
- $file = rl_get_resource_link_for_learnpath(api_get_course_id(), $this->get_id(), $item_id);
- if (empty($file)) {
- $file = 'blank.php?error=document_not_found';
- } else {
- $tmp_array = explode('/', $file);
- $document_name = $tmp_array[count($tmp_array) - 1];
- if (strpos($document_name, '_DELETED_')) {
- $file = 'blank.php?error=document_deleted';
- } else {
- $file = 'blank.php?error=document_not_found';
- }
- }
- } else {
- $file = $course_path . '/scorm/' . $lp_path . '/' . $decoded;
- }
- }
- }
-
-
-
-
-
- if ($file != 'blank.php') {
- $file .= (strstr($file, '?') === false ? '?' : '') . $lp_item_params;
- }
- } else {
- $file = 'lp_content.php?type=dir';
- }
- break;
- case 3 :
- if ($this->debug > 2) {
- error_log('New LP - In learnpath::get_link() ' . __LINE__ . ' - Item type: ' . $lp_item_type, 0);
- }
-
- $aicc_append = '?aicc_sid=' . urlencode(session_id()) . '&aicc_url=' . urlencode(api_get_path(WEB_CODE_PATH) . 'newscorm/aicc_hacp.php') . '&';
- if ($lp_item_type != 'dir') {
-
-
-
-
-
-
- if (preg_match('#^[a-zA-Z]{2,5}://#', $lp_item_path) != 0) {
- if ($this->debug > 2) {
- error_log('New LP - In learnpath::get_link() ' . __LINE__ . ' - Found match for protocol in ' . $lp_item_path, 0);
- }
-
- $file = $lp_item_path;
-
-
- if (stripos($file, '<servername>') !== false) {
-
- $web_course_path = str_replace('https://', '', str_replace('http://', '', $course_path));
- $file = str_replace('<servername>', $web_course_path . '/scorm/' . $lp_path, $lp_item_path);
- }
-
- $file .= $aicc_append;
- } else {
- if ($this->debug > 2) {
- error_log('New LP - In learnpath::get_link() ' . __LINE__ . ' - No starting protocol in ' . $lp_item_path, 0);
- }
-
- $lp_item_path = preg_replace('/%2F/', '/', $lp_item_path);
- $lp_item_path = preg_replace('/%3A/', ':', $lp_item_path);
-
- $file = $course_path . '/scorm/' . $lp_path . '/' . $lp_item_path;
-
- $file = str_replace('//', '/', $file);
- $file = str_replace(':/', '://', $file);
- $file .= $aicc_append;
- }
- } else {
- $file = 'lp_content.php?type=dir';
- }
- break;
- case 4 :
- break;
- default :
- break;
- }
- }
- if ($this->debug > 2) {
- error_log('New LP - In learnpath::get_link() - returning "' . $file . '" from get_link', 0);
- }
- return $file;
- }
-
- public function get_view($attempt_num = 0) {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::get_view()', 0);
- }
- $search = '';
-
- if ($attempt_num != 0 AND intval(strval($attempt_num)) == $attempt_num) {
- $search = 'AND view_count = ' . $attempt_num;
- }
-
- $lp_view_table = Database :: get_course_table(TABLE_LP_VIEW);
- $sql = "SELECT id, view_count FROM $lp_view_table " .
- "WHERE lp_id = " . $this->get_id() . " " .
- "AND user_id = " . $this->get_user_id() . " " .
- $search .
- " ORDER BY view_count DESC";
- $res = Database::query($sql);
- if (Database :: num_rows($res) > 0) {
- $row = Database :: fetch_array($res);
- $this->lp_view_id = $row['id'];
- } else {
-
- $sql = "INSERT INTO $lp_view_table(lp_id,user_id,view_count)" .
- "VALUES (" . $this->get_id() . "," . $this->get_user_id() . ",1)";
- $res = Database::query($sql);
- $id = Database :: insert_id();
- $this->lp_view_id = $id;
- }
- return $this->lp_view_id;
- }
-
- public function get_view_id() {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::get_view_id()', 0);
- }
- if (!empty ($this->lp_view_id)) {
- return $this->lp_view_id;
- } else {
- return 0;
- }
- }
-
- public function get_update_queue() {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::get_update_queue()', 0);
- }
- return $this->update_queue;
- }
-
- public function get_user_id() {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::get_user_id()', 0);
- }
- if (!empty ($this->user_id)) {
- return $this->user_id;
- } else {
- return false;
- }
- }
-
- public function has_audio() {
- if ($this->debug > 1) {
- error_log('New LP - In learnpath::has_audio()', 0);
- }
- $has = false;
- foreach ($this->items as $i => $item) {
- if (!empty ($this->items[$i]->audio)) {
- $has = true;
- break;
- }
- }
- return $has;
- }
-
- public function log($msg) {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::log()', 0);
- }
-
- $this->error .= $msg;
- return true;
- }
-
- public function move_item($id, $direction) {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::move_item(' . $id . ',' . $direction . ')', 0);
- }
- if (empty ($id) or empty ($direction)) {
- return false;
- }
- $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
- $sql_sel = "
- SELECT *
- FROM " . $tbl_lp_item . "
- WHERE id = " . $id;
- $res_sel = Database::query($sql_sel);
-
- if (Database :: num_rows($res_sel) < 1) {
- return false;
- }
-
- $row = Database :: fetch_array($res_sel);
- $previous = $row['previous_item_id'];
- $next = $row['next_item_id'];
- $display = $row['display_order'];
- $parent = $row['parent_item_id'];
- $lp = $row['lp_id'];
-
- switch ($direction) {
- case 'up' :
- if ($this->debug > 2) {
- error_log('Movement up detected', 0);
- }
- if ($display <= 1) {
- } else {
- $sql_sel2 = "SELECT *
- FROM $tbl_lp_item
- WHERE id = $previous";
- if ($this->debug > 2) {
- error_log('Selecting previous: ' . $sql_sel2, 0);
- }
- $res_sel2 = Database::query($sql_sel2);
- if (Database :: num_rows($res_sel2) < 1) {
- $previous_previous = 0;
- }
-
- $row2 = Database :: fetch_array($res_sel2);
- $previous_previous = $row2['previous_item_id'];
-
- if ($previous_previous != 0) {
- $sql_upd2 = "UPDATE $tbl_lp_item SET next_item_id = $id WHERE id = $previous_previous";
- if ($this->debug > 2) {
- error_log($sql_upd2, 0);
- }
- $res_upd2 = Database::query($sql_upd2);
- }
-
- if ($previous != 0) {
- $sql_upd2 = "UPDATE $tbl_lp_item SET next_item_id = $next, previous_item_id = $id, display_order = display_order +1 WHERE id = $previous";
- if ($this->debug > 2) {
- error_log($sql_upd2, 0);
- }
- $res_upd2 = Database::query($sql_upd2);
- }
-
- if ($id != 0) {
- $sql_upd2 = "UPDATE $tbl_lp_item SET next_item_id = $previous, previous_item_id = $previous_previous, display_order = display_order-1 WHERE id = $id";
- if ($this->debug > 2) {
- error_log($sql_upd2, 0);
- }
- $res_upd2 = Database::query($sql_upd2);
- }
-
- if ($next != 0) {
- $sql_upd2 = "UPDATE $tbl_lp_item SET previous_item_id = $previous WHERE id = $next";
- if ($this->debug > 2) {
- error_log($sql_upd2, 0);
- }
- $res_upd2 = Database::query($sql_upd2);
- }
- $display = $display -1;
- }
- break;
- case 'down' :
- if ($this->debug > 2) {
- error_log('Movement down detected', 0);
- }
- if ($next == 0) {
- } else {
- $sql_sel2 = "SELECT * FROM $tbl_lp_item WHERE id = $next";
- if ($this->debug > 2) {
- error_log('Selecting next: ' . $sql_sel2, 0);
- }
- $res_sel2 = Database::query($sql_sel2);
- if (Database :: num_rows($res_sel2) < 1) {
- $next_next = 0;
- }
-
- $row2 = Database :: fetch_array($res_sel2);
- $next_next = $row2['next_item_id'];
-
- if ($previous != 0) {
- $sql_upd2 = "UPDATE $tbl_lp_item SET next_item_id = $next WHERE id = $previous";
- $res_upd2 = Database::query($sql_upd2);
- }
-
- if ($id != 0) {
- $sql_upd2 = "UPDATE $tbl_lp_item SET previous_item_id = $next, next_item_id = $next_next, display_order = display_order+1 WHERE id = $id";
- $res_upd2 = Database::query($sql_upd2);
- }
-
- if ($next != 0) {
- $sql_upd2 = "UPDATE $tbl_lp_item SET previous_item_id = $previous, next_item_id = $id, display_order = display_order-1 WHERE id = $next";
- $res_upd2 = Database::query($sql_upd2);
- }
-
- if ($next_next != 0) {
- $sql_upd2 = "UPDATE $tbl_lp_item SET previous_item_id = $id WHERE id = $next_next";
- $res_upd2 = Database::query($sql_upd2);
- }
- $display = $display +1;
- }
- break;
- default :
- return false;
- }
- return $display;
- }
-
- public function move_up($lp_id) {
- $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
- $sql = "SELECT * FROM $lp_table ORDER BY display_order";
- $res = Database::query($sql);
- if ($res === false)
- return false;
- $lps = array ();
- $lp_order = array ();
- $num = Database :: num_rows($res);
-
-
- if ($num > 0) {
- $i = 1;
- while ($row = Database :: fetch_array($res)) {
- if ($row['display_order'] != $i) {
- $need_fix = true;
- $sql_u = "UPDATE $lp_table SET display_order = $i WHERE id = " . $row['id'];
- $res_u = Database::query($sql_u);
- }
- $row['display_order'] = $i;
- $lps[$row['id']] = $row;
- $lp_order[$i] = $row['id'];
- $i++;
- }
- }
- if ($num > 1) {
- $order = $lps[$lp_id]['display_order'];
- if ($order > 1) {
- $sql_u1 = "UPDATE $lp_table SET display_order = $order WHERE id = " . $lp_order[$order - 1];
- $res_u1 = Database::query($sql_u1);
- $sql_u2 = "UPDATE $lp_table SET display_order = " . ($order - 1) . " WHERE id = " . $lp_id;
- $res_u2 = Database::query($sql_u2);
- }
- }
- }
-
- public function move_down($lp_id) {
- $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
- $sql = "SELECT * FROM $lp_table ORDER BY display_order";
- $res = Database::query($sql);
- if ($res === false)
- return false;
- $lps = array ();
- $lp_order = array ();
- $num = Database :: num_rows($res);
- $max = 0;
-
-
- if ($num > 0) {
- $i = 1;
- while ($row = Database :: fetch_array($res)) {
- $max = $i;
- if ($row['display_order'] != $i) {
- $need_fix = true;
- $sql_u = "UPDATE $lp_table SET display_order = $i WHERE id = " . $row['id'];
- $res_u = Database::query($sql_u);
- }
- $row['display_order'] = $i;
- $lps[$row['id']] = $row;
- $lp_order[$i] = $row['id'];
- $i++;
- }
- }
- if ($num > 1) {
- $order = $lps[$lp_id]['display_order'];
- if ($order < $max) {
- $sql_u1 = "UPDATE $lp_table SET display_order = $order WHERE id = " . $lp_order[$order + 1];
- $res_u1 = Database::query($sql_u1);
- $sql_u2 = "UPDATE $lp_table SET display_order = " . ($order + 1) . " WHERE id = " . $lp_id;
- $res_u2 = Database::query($sql_u2);
- }
- }
- }
-
- public function next() {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::next()', 0);
- }
- $this->last = $this->get_current_item_id();
- $this->items[$this->last]->save(false, $this->prerequisites_match($this->last));
- $this->autocomplete_parents($this->last);
- $new_index = $this->get_next_index();
- if ($this->debug > 2) {
- error_log('New LP - New index: ' . $new_index, 0);
- }
- $this->index = $new_index;
- if ($this->debug > 2) {
- error_log('New LP - Now having orderedlist[' . $new_index . '] = ' . $this->ordered_items[$new_index], 0);
- }
- $this->current = $this->ordered_items[$new_index];
- if ($this->debug > 2) {
- error_log('New LP - new item id is ' . $this->current . '-' . $this->get_current_item_id(), 0);
- }
- }
-
- public function open($id) {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::open()', 0);
- }
-
-
-
-
-
-
- $this->index = 0;
- }
-
- public function prerequisites_match($item = null) {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::prerequisites_match()', 0);
- }
- if (empty ($item)) {
- $item = $this->current;
- }
- if (is_object($this->items[$item])) {
- $prereq_string = $this->items[$item]->get_prereq_string();
- if (empty ($prereq_string)) {
- return true;
- }
-
- $prereq_string = str_replace(' ', '', $prereq_string);
- if ($this->debug > 0) {
- error_log('Found prereq_string: ' . $prereq_string, 0);
- }
-
- $result = $this->items[$item]->parse_prereq($prereq_string, $this->items, $this->refs_list, $this->get_user_id());
- if ($result === false) {
- $this->set_error_msg($this->items[$item]->prereq_alert);
- }
- } else {
- $result = true;
- if ($this->debug > 1) {
- error_log('New LP - $this->items[' . $item . '] was not an object', 0);
- }
- }
- if ($this->debug > 1) {
- error_log('New LP - End of prerequisites_match(). Error message is now ' . $this->error, 0);
- }
- return $result;
- }
-
- public function previous() {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::previous()', 0);
- }
- $this->last = $this->get_current_item_id();
- $this->items[$this->last]->save(false, $this->prerequisites_match($this->last));
- $this->autocomplete_parents($this->last);
- $new_index = $this->get_previous_index();
- $this->index = $new_index;
- $this->current = $this->ordered_items[$new_index];
- }
-
- public function toggle_visibility($lp_id, $set_visibility = 1) {
-
- $action = 'visible';
- if ($set_visibility != 1) {
- $action = 'invisible';
- }
- return api_item_property_update(api_get_course_info(), TOOL_LEARNPATH, $lp_id, $action, api_get_user_id());
- }
-
- public function toggle_publish($lp_id, $set_visibility = 'v') {
-
- $tbl_lp = Database :: get_course_table(TABLE_LP_MAIN);
- $sql = "SELECT * FROM $tbl_lp where id=$lp_id";
- $result = Database::query($sql);
- $row = Database :: fetch_array($result);
- $name = domesticate($row['name']);
- if ($set_visibility == 'i') {
- $s = $name . " " . get_lang('_no_published');
- $dialogBox = $s;
- $v = 0;
- }
- if ($set_visibility == 'v') {
- $s = $name . " " . get_lang('_published');
- $dialogBox = $s;
- $v = 1;
- }
- $session_id = api_get_session_id();
- $session_condition = api_get_session_condition($session_id);
- $tbl_tool = Database :: get_course_table(TABLE_TOOL_LIST);
- $link = 'newscorm/lp_controller.php?action=view&lp_id=' . $lp_id.'&id_session='.$session_id;
- $sql = "SELECT * FROM $tbl_tool where name='$name' and image='scormbuilder.gif' and link LIKE '$link%' $session_condition";
- $result = Database::query($sql);
- $num = Database :: num_rows($result);
- $row2 = Database :: fetch_array($result);
-
- if (($set_visibility == 'i') && ($num > 0)) {
- $sql = "DELETE FROM $tbl_tool WHERE (name='$name' and image='scormbuilder.gif' and link LIKE '$link%' $session_condition)";
- } elseif (($set_visibility == 'v') && ($num == 0)) {
- $sql = "INSERT INTO $tbl_tool (name, link, image, visibility, admin, address, added_tool, session_id) VALUES ('$name','$link','scormbuilder.gif','$v','0','pastillegris.gif',0, $session_id)";
- } else {
-
- }
- $result = Database::query($sql);
-
- }
-
- public function restart() {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::restart()', 0);
- }
-
-
-
- $session_id = api_get_session_id();
- $lp_view_table = Database :: get_course_table(TABLE_LP_VIEW);
- $sql = "INSERT INTO $lp_view_table (lp_id, user_id, view_count, session_id) " .
- "VALUES (" . $this->lp_id . "," . $this->get_user_id() . "," . ($this->attempt + 1) . ", $session_id)";
- if ($this->debug > 2) {
- error_log('New LP - Inserting new lp_view for restart: ' . $sql, 0);
- }
- $res = Database::query($sql);
- if ($view_id = Database :: insert_id($res)) {
- $this->lp_view_id = $view_id;
- $this->attempt = $this->attempt + 1;
- } else {
- $this->error = 'Could not insert into item_view table...';
- return false;
- }
- $this->autocomplete_parents($this->current);
- foreach ($this->items as $index => $dummy) {
- $this->items[$index]->restart();
- $this->items[$index]->set_lp_view($this->lp_view_id);
- }
- $this->first();
- return true;
- }
-
- public function save_current() {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::save_current()', 0);
- }
-
-
- if ($this->debug > 2) {
- error_log('New LP - save_current() saving item ' . $this->current, 0);
- }
- if ($this->debug > 2) {
- error_log('' . print_r($this->items, true), 0);
- }
- if (is_object($this->items[$this->current])) {
-
- $res = $this->items[$this->current]->save(false, $this->prerequisites_match($this->current));
- $this->autocomplete_parents($this->current);
- $status = $this->items[$this->current]->get_status();
- $this->append_message('new_item_status: ' . $status);
- $this->update_queue[$this->current] = $status;
- return $res;
- }
- return false;
- }
-
- public function save_item($item_id = null, $from_outside = true) {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::save_item(' . $item_id . ',' . $from_outside . ')', 0);
- }
-
-
- if (empty ($item_id)) {
- $item_id = $this->escape_string($_REQUEST['id']);
- }
- if (empty ($item_id)) {
- $item_id = $this->get_current_item_id();
- }
- if ($this->debug > 2) {
- error_log('New LP - save_current() saving item ' . $item_id, 0);
- }
- if (is_object($this->items[$item_id])) {
- $res = $this->items[$item_id]->save($from_outside, $this->prerequisites_match($item_id));
-
- $this->autocomplete_parents($item_id);
- $status = $this->items[$item_id]->get_status();
- $this->append_message('new_item_status: ' . $status);
- $this->update_queue[$item_id] = $status;
- return $res;
- }
- return false;
- }
-
- public function save_last() {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::save_last()', 0);
- }
- $session_condition = api_get_session_condition(api_get_session_id(), true, false);
- $table = Database :: get_course_table(TABLE_LP_VIEW);
- if (isset ($this->current)) {
- if ($this->debug > 2) {
- error_log('New LP - Saving current item (' . $this->current . ') for later review', 0);
- }
- $sql = "UPDATE $table SET last_item = " . Database::escape_string($this->get_current_item_id()). " " .
- "WHERE lp_id = " . $this->get_id() . " AND user_id = " . $this->get_user_id().' '.$session_condition;
- if ($this->debug > 2) {
- error_log('New LP - Saving last item seen : ' . $sql, 0);
- }
- $res = Database::query($sql);
- }
-
- list($progress, $text) = $this->get_progress_bar_text('%');
- if ($progress >= 0 && $progress <= 100) {
- $progress = (int) $progress;
- $sql = "UPDATE $table SET progress = $progress " .
- "WHERE lp_id = " . $this->get_id() . " AND " .
- "user_id = " . $this->get_user_id().' '.$session_condition;
- $res = Database::query($sql);
- $this->progress_db = $progress;
- }
- }
-
- public function set_current_item($item_id = null) {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::set_current_item(' . $item_id . ')', 0);
- }
- if (empty ($item_id)) {
- if ($this->debug > 2) {
- error_log('New LP - No new current item given, ignore...', 0);
- }
-
- } else {
- if ($this->debug > 2) {
- error_log('New LP - New current item given is ' . $item_id . '...', 0);
- }
- if (is_numeric($item_id)) {
- $item_id = $this->escape_string($item_id);
-
- $this->last = $this->current;
- $this->current = $item_id;
-
- foreach ($this->ordered_items as $index => $item) {
- if ($item == $this->current) {
- $this->index = $index;
- break;
- }
- }
- if ($this->debug > 2) {
- error_log('New LP - set_current_item(' . $item_id . ') done. Index is now : ' . $this->index, 0);
- }
- } else {
- error_log('New LP - set_current_item(' . $item_id . ') failed. Not a numeric value: ', 0);
- }
- }
- }
-
- public function set_encoding($enc = 'UTF-8') {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::set_encoding()', 0);
- }
-
- $enc = api_refine_encoding_id($enc);
- if (empty($enc)) {
- $enc = api_get_system_encoding();
- }
- if (api_is_encoding_supported($enc)) {
- $lp = $this->get_id();
- if ($lp != 0) {
- $tbl_lp = Database :: get_course_table(TABLE_LP_MAIN);
- $sql = "UPDATE $tbl_lp SET default_encoding = '$enc' WHERE id = " . $lp;
- $res = Database::query($sql);
- return $res;
- }
- }
- return false;
- }
-
- public function set_jslib($lib = '') {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::set_jslib()', 0);
- }
- $lp = $this->get_id();
- if ($lp != 0) {
- $tbl_lp = Database :: get_course_table(TABLE_LP_MAIN);
- $sql = "UPDATE $tbl_lp SET js_lib = '$lib' WHERE id = " . $lp;
- $res = Database::query($sql);
- return $res;
- } else {
- return false;
- }
- }
-
- public function set_maker($name = '') {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::set_maker()', 0);
- }
- if (empty ($name))
- return false;
- $this->maker = $this->escape_string($name);
- $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
- $lp_id = $this->get_id();
- $sql = "UPDATE $lp_table SET content_maker = '" . $this->maker . "' WHERE id = '$lp_id'";
- if ($this->debug > 2) {
- error_log('New LP - lp updated with new content_maker : ' . $this->maker, 0);
- }
- $res = Database::query($sql);
- return true;
- }
-
- public function set_name($name = '') {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::set_name()', 0);
- }
- if (empty ($name))
- return false;
- $this->name = $this->escape_string($name);
- $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
- $lp_id = $this->get_id();
- $sql = "UPDATE $lp_table SET name = '" . $this->name . "' WHERE id = '$lp_id'";
- if ($this->debug > 2) {
- error_log('New LP - lp updated with new name : ' . $this->name, 0);
- }
- $res = Database::query($sql);
-
- if (Database::affected_rows()) {
- $table = Database :: get_course_table(TABLE_TOOL_LIST);
- $sql = 'UPDATE ' . $table . ' SET
- name = "' . $this->name . '"
- WHERE link = "newscorm/lp_controller.php?action=view&lp_id=' . $lp_id . '"';
- Database::query($sql);
- }
- return true;
- }
-
- public function set_terms_by_prefix($terms_string, $prefix) {
- if (api_get_setting('search_enabled') !== 'true')
- return false;
-
- if (!extension_loaded('xapian')) {
- return false;
- }
- $terms_string = trim($terms_string);
- $terms = explode(',', $terms_string);
- array_walk($terms, 'trim_value');
- $stored_terms = $this->get_common_index_terms_by_prefix($prefix);
-
-
-
- if ((count(array_diff($terms, $stored_terms)) == 0) && (count(array_diff($stored_terms, $terms)) == 0))
- return false;
- require_once 'xapian.php';
- require_once api_get_path(LIBRARY_PATH).'search/DokeosIndexer.class.php';
- require_once api_get_path(LIBRARY_PATH).'search/xapian/XapianQuery.php';
- require_once api_get_path(LIBRARY_PATH).'search/IndexableChunk.class.php';
- $items_table = Database :: get_course_table(TABLE_LP_ITEM);
-
- $lp_id = intval($_POST['lp_id']);
- $sql = "SELECT * FROM $items_table WHERE lp_id = $lp_id";
- $result = Database::query($sql);
- $di = new DokeosIndexer();
- while ($lp_item = Database :: fetch_array($result)) {
-
- $tbl_se_ref = Database :: get_main_table(TABLE_MAIN_SEARCH_ENGINE_REF);
- $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';
- $sql = sprintf($sql, $tbl_se_ref, $this->cc, TOOL_LEARNPATH, $lp_id, $lp_item['id']);
-
- $res = Database::query($sql);
- if (Database::num_rows($res) > 0) {
- $se_ref = Database :: fetch_array($res);
-
- $doc = $di->get_document($se_ref['search_did']);
- $xapian_terms = xapian_get_doc_terms($doc, $prefix);
-
- $xterms = array ();
- foreach ($xapian_terms as $xapian_term) {
- $xterms[] = substr($xapian_term['name'], 1);
- }
- $dterms = $terms;
- $missing_terms = array_diff($dterms, $xterms);
- $deprecated_terms = array_diff($xterms, $dterms);
-
- foreach ($missing_terms as $term) {
- $doc->add_term($prefix . $term, 1);
- }
- foreach ($deprecated_terms as $term) {
- $doc->remove_term($prefix . $term);
- }
- $di->getDb()->replace_document((int) $se_ref['search_did'], $doc);
- $di->getDb()->flush();
- } else {
-
- }
- }
- return true;
- }
-
- public function set_theme($name = '') {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::set_theme()', 0);
- }
- $this->theme = $this->escape_string($name);
- $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
- $lp_id = $this->get_id();
- $sql = "UPDATE $lp_table SET theme = '" . $this->theme . "' WHERE id = '$lp_id'";
- if ($this->debug > 2) {
- error_log('New LP - lp updated with new theme : ' . $this->theme, 0);
- }
-
- $res = Database::query($sql);
- return true;
- }
-
- public function set_preview_image($name = '') {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::set_preview_image()', 0);
- }
- $this->preview_image = $this->escape_string($name);
- $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
- $lp_id = $this->get_id();
- $sql = "UPDATE $lp_table SET preview_image = '" . $this->preview_image . "' WHERE id = '$lp_id'";
- if ($this->debug > 2) {
- error_log('New LP - lp updated with new preview image : ' . $this->preview_image, 0);
- }
- $res = Database::query($sql);
- return true;
- }
-
- public function set_author($name = '') {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::set_author()', 0);
- }
- $this->author = $this->escape_string($name);
- $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
- $lp_id = $this->get_id();
- $sql = "UPDATE $lp_table SET author = '" . $this->author . "' WHERE id = '$lp_id'";
- if ($this->debug > 2) {
- error_log('New LP - lp updated with new preview author : ' . $this->author, 0);
- }
- $res = Database::query($sql);
- return true;
- }
-
- public function set_prerequisite($prerequisite) {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::set_prerequisite()', 0);
- }
- $this->prerequisite = intval($prerequisite);
- $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
- $lp_id = $this->get_id();
- $sql = "UPDATE $lp_table SET prerequisite = '".$this->prerequisite."' WHERE id = '$lp_id'";
- if ($this->debug > 2) {
- error_log('New LP - lp updated with new preview requisite : ' . $this->requisite, 0);
- }
- $res = Database::query($sql);
- return true;
- }
-
- public function set_proximity($name = '') {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::set_proximity()', 0);
- }
- if (empty ($name))
- return false;
- $this->proximity = $this->escape_string($name);
- $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
- $lp_id = $this->get_id();
- $sql = "UPDATE $lp_table SET content_local = '" . $this->proximity . "' WHERE id = '$lp_id'";
- if ($this->debug > 2) {
- error_log('New LP - lp updated with new proximity : ' . $this->proximity, 0);
- }
- $res = Database::query($sql);
- return true;
- }
-
- public function set_previous_item($id) {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::set_previous_item()', 0);
- }
- $this->last = $id;
- }
-
- public function set_use_max_score($use_max_score = 1) {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::set_use_max_score()', 0);
- }
- $use_max_score = intval($use_max_score);
- $this->use_max_score = $use_max_score;
- $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
- $lp_id = $this->get_id();
- $sql = "UPDATE $lp_table SET use_max_score = '" . $this->use_max_score . "' WHERE id = '$lp_id'";
-
- if ($this->debug > 2) {
- error_log('New LP - lp updated with new use_max_score : ' . $this->use_max_score, 0);
- }
- $res = Database::query($sql);
- return true;
- }
-
- public function set_expired_on($expired_on) {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::set_expired_on()', 0);
- }
- if (!empty($expired_on)) {
- $this->expired_on = $this->escape_string(api_get_utc_datetime($expired_on));
- } else {
- $this->expired_on = '';
- }
- $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
- $lp_id = $this->get_id();
- $sql = "UPDATE $lp_table SET expired_on = '" . $this->expired_on . "' WHERE id = '$lp_id'";
- if ($this->debug > 2) {
- error_log('New LP - lp updated with new expired_on : ' . $this->expired_on, 0);
- }
- $res = Database::query($sql);
- return true;
- }
-
- public function set_publicated_on($publicated_on) {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::set_expired_on()', 0);
- }
- if (!empty($publicated_on)) {
- $this->publicated_on = $this->escape_string(api_get_utc_datetime($publicated_on));
- } else {
- $this->publicated_on = '';
- }
- $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
- $lp_id = $this->get_id();
- $sql = "UPDATE $lp_table SET publicated_on = '" . $this->publicated_on . "' WHERE id = '$lp_id'";
- if ($this->debug > 2) {
- error_log('New LP - lp updated with new publicated_on : ' . $this->publicated_on, 0);
- }
- $res = Database::query($sql);
- return true;
- }
-
- public function set_modified_on() {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::set_expired_on()', 0);
- }
- $this->modified_on = api_get_utc_datetime();
- $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
- $lp_id = $this->get_id();
- $sql = "UPDATE $lp_table SET modified_on = '" . $this->modified_on . "' WHERE id = '$lp_id'";
- if ($this->debug > 2) {
- error_log('New LP - lp updated with new expired_on : ' . $this->modified_on, 0);
- }
- $res = Database::query($sql);
- return true;
- }
-
- public function set_error_msg($error = '') {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::set_error_msg()', 0);
- }
- if (empty ($error)) {
- $this->error = '';
- } else {
- $this->error .= $error;
- }
- }
-
- public function start_current_item($allow_new_attempt = false) {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::start_current_item()', 0);
- }
- if ($this->current != 0 AND is_object($this->items[$this->current])) {
- $type = $this->get_type();
- $item_type = $this->items[$this->current]->get_type();
- if (($type == 2 && $item_type != 'sco') OR ($type == 3 && $item_type != 'au') OR ($type == 1 && $item_type != TOOL_QUIZ && $item_type != TOOL_HOTPOTATOES)) {
- $this->items[$this->current]->open($allow_new_attempt);
- $this->autocomplete_parents($this->current);
- $prereq_check = $this->prerequisites_match($this->current);
- $this->items[$this->current]->save(false, $prereq_check);
-
- } else {
-
- }
- if ($item_type == 'sco') {
- $this->items[$this->current]->restart();
- }
- }
- if ($this->debug > 0) {
- error_log('New LP - End of learnpath::start_current_item()', 0);
- }
- return true;
- }
-
- public function stop_previous_item() {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::stop_previous_item()', 0);
- }
- if ($this->last != 0 && $this->last != $this->current && is_object($this->items[$this->last])) {
- if ($this->debug > 2) {
- error_log('New LP - In learnpath::stop_previous_item() - ' . $this->last . ' is object', 0);
- }
- switch ($this->get_type()) {
- case '3' :
- if ($this->items[$this->last]->get_type() != 'au') {
- if ($this->debug > 2) {
- error_log('New LP - In learnpath::stop_previous_item() - ' . $this->last . ' in lp_type 3 is <> au', 0);
- }
- $this->items[$this->last]->close();
-
-
- } else {
- if ($this->debug > 2) {
- error_log('New LP - In learnpath::stop_previous_item() - Item is an AU, saving is managed by AICC signals', 0);
- }
- }
- case '2' :
- if ($this->items[$this->last]->get_type() != 'sco') {
- if ($this->debug > 2) {
- error_log('New LP - In learnpath::stop_previous_item() - ' . $this->last . ' in lp_type 2 is <> sco', 0);
- }
- $this->items[$this->last]->close();
-
-
- } else {
- if ($this->debug > 2) {
- error_log('New LP - In learnpath::stop_previous_item() - Item is a SCO, saving is managed by SCO signals', 0);
- }
- }
- break;
- case '1' :
- default :
- if ($this->debug > 2) {
- error_log('New LP - In learnpath::stop_previous_item() - ' . $this->last . ' in lp_type 1 is asset', 0);
- }
- $this->items[$this->last]->close();
- break;
- }
- } else {
- if ($this->debug > 2) {
- error_log('New LP - In learnpath::stop_previous_item() - No previous element found, ignoring...', 0);
- }
- return false;
- }
- return true;
- }
-
- public function update_default_view_mode() {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::update_default_view_mode()', 0);
- }
- $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
- $sql = "SELECT * FROM $lp_table WHERE id = " . $this->get_id();
- $res = Database::query($sql);
- if (Database :: num_rows($res) > 0) {
- $row = Database :: fetch_array($res);
- $view_mode = $row['default_view_mod'];
- if ($view_mode == 'fullscreen') {
- $view_mode = 'embedded';
- } elseif ($view_mode == 'embedded') {
- $view_mode = 'embedframe';
- } elseif ($view_mode == 'embedframe') {
- $view_mode = 'fullscreen';
- }
- $sql = "UPDATE $lp_table SET default_view_mod = '$view_mode' WHERE id = " . $this->get_id();
- $res = Database::query($sql);
- $this->mode = $view_mode;
- return $view_mode;
- } else {
- if ($this->debug > 2) {
- error_log('New LP - Problem in update_default_view() - could not find LP ' . $this->get_id() . ' in DB', 0);
- }
- }
- return -1;
- }
-
- public function update_default_scorm_commit() {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::update_default_scorm_commit()', 0);
- }
- $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
- $sql = "SELECT * FROM $lp_table WHERE id = " . $this->get_id();
- $res = Database::query($sql);
- if (Database :: num_rows($res) > 0) {
- $row = Database :: fetch_array($res);
- $force = $row['force_commit'];
- if ($force == 1) {
- $force = 0;
- $force_return = false;
- } elseif ($force == 0) {
- $force = 1;
- $force_return = true;
- }
- $sql = "UPDATE $lp_table SET force_commit = $force WHERE id = " . $this->get_id();
- $res = Database::query($sql);
- $this->force_commit = $force_return;
- return $force_return;
- } else {
- if ($this->debug > 2) {
- error_log('New LP - Problem in update_default_scorm_commit() - could not find LP ' . $this->get_id() . ' in DB', 0);
- }
- }
- return -1;
- }
-
- public function update_display_order() {
- $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
- $sql = "SELECT * FROM $lp_table ORDER BY display_order";
- $res = Database::query($sql);
- if ($res === false)
- return false;
- $lps = array ();
- $lp_order = array ();
- $num = Database :: num_rows($res);
-
-
- if ($num > 0) {
- $i = 1;
- while ($row = Database :: fetch_array($res)) {
- if ($row['display_order'] != $i) {
- $need_fix = true;
- $sql_u = "UPDATE $lp_table SET display_order = $i WHERE id = " . $row['id'];
- $res_u = Database::query($sql_u);
- }
- $i++;
- }
- }
- return true;
- }
-
- public function update_reinit() {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::update_reinit()', 0);
- }
- $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
- $sql = "SELECT * FROM $lp_table WHERE id = " . $this->get_id();
- $res = Database::query($sql);
- if (Database :: num_rows($res) > 0) {
- $row = Database :: fetch_array($res);
- $force = $row['prevent_reinit'];
- if ($force == 1) {
- $force = 0;
- } elseif ($force == 0) {
- $force = 1;
- }
- $sql = "UPDATE $lp_table SET prevent_reinit = $force WHERE id = " . $this->get_id();
- $res = Database::query($sql);
- $this->prevent_reinit = $force;
- return $force;
- } else {
- if ($this->debug > 2) {
- error_log('New LP - Problem in update_reinit() - could not find LP ' . $this->get_id() . ' in DB', 0);
- }
- }
- return -1;
- }
-
- public function update_scorm_debug() {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::update_scorm_debug()', 0);
- }
- $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
- $sql = "SELECT * FROM $lp_table WHERE id = " . $this->get_id();
- $res = Database::query($sql);
- if (Database :: num_rows($res) > 0) {
- $row = Database :: fetch_array($res);
- $force = $row['debug'];
- if ($force == 1) {
- $force = 0;
- } elseif ($force == 0) {
- $force = 1;
- }
- $sql = "UPDATE $lp_table SET debug = $force WHERE id = " . $this->get_id();
- $res = Database::query($sql);
- $this->scorm_debug = $force;
- return $force;
- } else {
- if ($this->debug > 2) {
- error_log('New LP - Problem in update_scorm_debug() - could not find LP ' . $this->get_id() . ' in DB', 0);
- }
- }
- return -1;
- }
-
- public function tree_array($array) {
- if ($this->debug > 1) {
- error_log('New LP - In learnpath::tree_array()', 0);
- }
- $array = $this->sort_tree_array($array);
- $this->create_tree_array($array);
- }
-
- public function create_tree_array($array, $parent = 0, $depth = -1, $tmp = array ()) {
- if ($this->debug > 1) {
- error_log('New LP - In learnpath::create_tree_array())', 0);
- }
- if (is_array($array)) {
- for ($i = 0; $i < count($array); $i++) {
- if ($array[$i]['parent_item_id'] == $parent) {
- if (!in_array($array[$i]['parent_item_id'], $tmp)) {
- $tmp[] = $array[$i]['parent_item_id'];
- $depth++;
- }
- $preq = (empty($array[$i]['prerequisite']) ? '' : $array[$i]['prerequisite']);
- $this->arrMenu[] = array (
- 'id' => $array[$i]['id'],
- 'item_type' => $array[$i]['item_type'],
- 'title' => $array[$i]['title'],
- 'path' => $array[$i]['path'],
- 'description' => $array[$i]['description'],
- 'parent_item_id' => $array[$i]['parent_item_id'],
- 'previous_item_id' => $array[$i]['previous_item_id'],
- 'next_item_id' => $array[$i]['next_item_id'],
- 'min_score' => $array[$i]['min_score'],
- 'max_score' => $array[$i]['max_score'],
- 'mastery_score' => $array[$i]['mastery_score'],
- 'display_order' => $array[$i]['display_order'],
- 'prerequisite' => $preq,
- 'depth' => $depth,
- 'audio' => $array[$i]['audio']
- );
- $this->create_tree_array($array, $array[$i]['id'], $depth, $tmp);
- }
- }
- }
- }
-
- public function sort_tree_array($array) {
- foreach ($array as $key => $row) {
- $parent[$key] = $row['parent_item_id'];
- $position[$key] = $row['display_order'];
- }
- if (count($array) > 0)
- array_multisort($parent, SORT_ASC, $position, SORT_ASC, $array);
- return $array;
- }
-
- public function overview() {
- $is_allowed_to_edit = api_is_allowed_to_edit(null,true);
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::overview()', 0);
- }
- global $charset, $_course;
- $_SESSION['gradebook'] = Security :: remove_XSS($_GET['gradebook']);
- $return = '';
- $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
- $sql = "SELECT * FROM " . $tbl_lp_item . "
- WHERE lp_id = " . $this->lp_id;
- $result = Database::query($sql);
- $arrLP = array ();
- while ($row = Database :: fetch_array($result)) {
- $row['title'] = Security :: remove_XSS($row['title']);
- $row['description'] = Security :: remove_XSS($row['description']);
- $arrLP[] = array (
- 'id' => $row['id'],
- 'item_type' => $row['item_type'],
- 'title' => $row['title'],
- 'path' => $row['path'],
- 'description' => $row['description'],
- 'parent_item_id' => $row['parent_item_id'],
- 'previous_item_id' => $row['previous_item_id'],
- 'next_item_id' => $row['next_item_id'],
- 'max_score' => $row['max_score'],
- 'min_score' => $row['min_score'],
- 'mastery_score' => $row['mastery_score'],
- 'prerequisite' => $row['prerequisite'],
- 'display_order' => $row['display_order'],
- 'audio' => $row['audio']
- );
- }
- $this->tree_array($arrLP);
- $arrLP = $this->arrMenu;
- unset ($this->arrMenu);
- if ($is_allowed_to_edit) {
- $token = Security::get_token();
- $gradebook = Security :: remove_XSS($_GET['gradebook']);
- $return .= '<div class="actions">';
- $return .= '<a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&gradebook=' . $gradebook . '&action=build&lp_id=' . $this->lp_id . '" title="' . get_lang('Build') . '">' . Display :: return_icon('build_learnpath.png', get_lang('Build'),'','32').'</a>';
- if ($_GET['updateaudio'] == 'true') {
- $return .='<a href="lp_controller.php?cidReq='.Security::remove_XSS($_GET['cidReq']) .'&gradebook='.$gradebook.'&action=admin_view&lp_id=' . $_SESSION['oLP']->lp_id . '" title="'.get_lang('BasicOverview').'">'.Display::return_icon('move_learnpath.png', get_lang('BasicOverview'),'','32').'</a>';
- } else {
- $return .= '<span>' . Display :: return_icon('move_learnpath_na.png', get_lang('BasicOverview'),'','32').'</span>';
- }
-
- $return .= '<a href="lp_controller.php?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&action=view&lp_id=' . $this->lp_id . '">' . Display :: return_icon('view_left_right.png', get_lang('Display'),'','32').'</a>';
- $return .= ' '.Display :: return_icon('i.gif');
- $return .= '<a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&gradebook=' . $gradebook . '&action=add_item&type=step&lp_id=' . $_SESSION['oLP']->lp_id . '" title="' . get_lang('NewStep') . '">
- '. Display :: return_icon('new_learnigpath_object.png', get_lang('NewStep'),'','32').'</a>';
- $return .= '<a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&gradebook=' . $gradebook . '&action=add_item&type=chapter&lp_id=' . $_SESSION['oLP']->lp_id . '" title="' . get_lang('NewChapter') . '">
- '. Display :: return_icon('add_learnpath_section.png', get_lang('NewChapter'),'','32').'</a>';
- if ($_GET['updateaudio'] == 'true') {
- $return .= Display::url(Display :: return_icon('upload_audio_na.png', get_lang('UpdateAllAudioFragments'),'','32'),'#');
- } else {
- $return .= '<a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&action=' . Security :: remove_XSS($_GET['action']) . '&lp_id=' . $_SESSION['oLP']->lp_id . '&updateaudio=true">' . Display :: return_icon('upload_audio.png', get_lang('UpdateAllAudioFragments'),'','32').'</a>';
- }
- $return .= '<a href="lp_controller.php?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&action=edit&lp_id=' . $_SESSION['oLP']->lp_id . '">' . Display :: return_icon('settings.png', get_lang('CourseSettings'),'','32').'</a>';
- $return .= '</div>';
- }
-
- if ($_GET['updateaudio'] == 'true' AND count($arrLP) <> 0) {
- $return .= '<form action="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&action=' . Security :: remove_XSS($_GET['action']) . '&lp_id=' . $_SESSION['oLP']->lp_id . '" method="post" enctype="multipart/form-data" name="updatemp3" id="updatemp3">';
- $return .= Display::return_message(get_lang('LeaveEmptyToKeepCurrentFile'), 'warning');
- }
- $return .= '<table class="data_table">';
- $return .= '<tr>';
- $return .= '<th width="60%">' . get_lang('Title') . '</th>';
-
- $return .= '<th>' . get_lang('Audio') . '</th>';
- if (!$_GET['updateaudio'] OR $_GET['updateaudio'] <> 'true') {
- $return .= '<th>' . get_lang('Move') . '</th>';
- }
- $return .= '<th>' . get_lang('Actions') . '</th>';
- $return .= '</tr>';
- for ($i = 0; $i < count($arrLP); $i++) {
- $title = $arrLP[$i]['title'];
- if ($arrLP[$i]['description'] == '')
- $arrLP[$i]['description'] = ' ';
- if (($i % 2) == 0) {
- $oddclass = 'row_odd';
- } else {
- $oddclass = 'row_even';
- }
- $return .= '<tr class="' . $oddclass . '">';
- $icon_name = str_replace(' ', '', $arrLP[$i]['item_type']);
- if (file_exists('../img/lp_' . $icon_name . '.png')) {
- $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>';
- } else {
- if (file_exists('../img/lp_' . $icon_name . '.gif')) {
- $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>';
- } else {
-
- $return .= '<td style="padding-left:' . $arrLP[$i]['depth'] * 10 . 'px;"><img align="left" src="../img/folder_document.gif" style="margin-right:3px;" />' . $title . '</td>';
- }
- }
-
-
- $return .= '<td align="center">';
- if (!$_GET['updateaudio'] OR $_GET['updateaudio'] <> 'true') {
- if (!empty ($arrLP[$i]['audio'])) {
- $return .= '<span id="container' . $i . '"><a href="http://www.macromedia.com/go/getflashplayer">Get the Flash Player</a> to see this player.</span>';
- $return .= '<script type="text/javascript" src="../inc/lib/mediaplayer/swfobject.js"></script>';
- $return .= '<script type="text/javascript">
- var s1 = new SWFObject("../inc/lib/mediaplayer/player.swf","ply","250","20","9","#FFFFFF");
- s1.addParam("allowscriptaccess","always");
- s1.addParam("flashvars","file=../../courses/' . $_course['path'] . '/document/audio/' . $arrLP[$i]['audio'] . '");
- s1.write("container' . $i . '");
- </script>';
- } else {
- $return .= ' - ';
- }
- } else {
- if ($arrLP[$i]['item_type'] != 'dokeos_chapter' && $arrLP[$i]['item_type'] != 'dokeos_module' && $arrLP[$i]['item_type'] != 'dir') {
- $return .= ' <input type="file" name="mp3file' . $arrLP[$i]['id'] . '" id="mp3file" />';
- if (!empty ($arrLP[$i]['audio'])) {
- $return .= '<br />'.Security::remove_XSS($arrLP[$i]['audio']).'<input type="checkbox" name="removemp3' . $arrLP[$i]['id'] . '" id="checkbox' . $arrLP[$i]['id'] . '" />' . get_lang('RemoveAudio');
- }
- }
- }
- $return .= '</td>';
- if ($is_allowed_to_edit) {
- if (!$_GET['updateaudio'] OR $_GET['updateaudio'] <> 'true') {
- $return .= '<td align="center">';
-
- if ($arrLP[$i]['previous_item_id'] != 0) {
- $return .= '<a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&action=move_item&direction=up&id=' . $arrLP[$i]['id'] . '&lp_id=' . $this->lp_id . '&sec_token='.$token.'">';
- $return .= '<img style="margin:1px;" alt="" src="../img/arrow_up_' . ($arrLP[$i]['depth'] % 3) . '.gif" title="' . get_lang('MoveUp') . '"/>';
- $return .= '</a>';
- } else {
- $return .= '<img alt="" src="../img/blanco.png" title="" />';
- }
-
- if ($arrLP[$i]['next_item_id'] != 0) {
- $return .= '<a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']). '&action=move_item&direction=down&id=' . $arrLP[$i]['id'] . '&lp_id=' . $this->lp_id . '&sec_token='.$token.'">';
- $return .= '<img style="margin:1px;" src="../img/arrow_down_' . ($arrLP[$i]['depth'] % 3) . '.gif" title="' . get_lang('MoveDown') . '" />';
-
- $return .= '</a>';
- } else
- $return .= '<img alt="" src="../img/blanco.png" title="" />';
-
- $return .= '</td>';
- }
- $return .= '<td align="center">';
- if ($arrLP[$i]['item_type'] != 'dokeos_chapter' && $arrLP[$i]['item_type'] != 'dokeos_module') {
- $return .= '<a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&action=edit_item&view=build&id=' . $arrLP[$i]['id'] . '&lp_id=' . $this->lp_id . '&path_item=' . $arrLP[$i]['path'] . '">';
- $return .= '<img style="margin:1px;" alt="" src="../img/edit.png" title="' . get_lang('_edit_learnpath_module') . '" />';
- $return .= '</a>';
- } else {
- $return .= '<a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&action=edit_item&id=' . $arrLP[$i]['id'] . '&lp_id=' . $this->lp_id . '&path_item=' . $arrLP[$i]['path'] . '">';
- $return .= '<img style="margin:1px;" alt="" src="../img/edit.png" title="' . get_lang('_edit_learnpath_module') . '" />';
- $return .= '</a>';
- }
- $return .= '<a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&action=delete_item&id=' . $arrLP[$i]['id'] . '&lp_id=' . $this->lp_id . '" onClick="return confirmation(\'' . addslashes($title) . '\');">';
- $return .= '<img style="margin:1px;" alt="" src="../img/delete.png" title="' . get_lang('_delete_learnpath_module') . '" />';
- $return .= '</a>';
- $return .= '</td>';
- }
- $return .= '</tr>';
- }
- if (count($arrLP) == 0) {
- $return .= '<tr>';
- $return .= '<td colspan="4">' . get_lang('NoItemsInLp') . '</td>';
- $return .= '</tr>';
- }
- $return .= '</table>';
-
- if ($_GET['updateaudio'] == 'true') {
- $return .= '<div style="margin:40px 0; float:right;"><button class="save" type="submit" name="save_audio" id="save_audio">' . get_lang('SaveAudioAndOrganization') . '</button></div>';
- }
-
- if ($_GET['updateaudio'] == 'true' && count($arrLP) != 0) {
- $return .= '</form>';
- }
- return $return;
- }
-
- public function build_action_menu() {
- $gradebook = Security :: remove_XSS($_GET['gradebook']);
- echo '<div class="actions">';
-
- echo '<span>' . Display :: return_icon('build_learnpath_na.png', get_lang('Build'),'','32').'</span>';
- echo '<a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&gradebook=' . $gradebook . '&action=admin_view&lp_id=' . $_SESSION['oLP']->lp_id . '" title="' . get_lang('BasicOverview') . '">' . Display :: return_icon('move_learnpath.png', get_lang('BasicOverview'),'','32').'</a>';
- echo '<a href="lp_controller.php?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&gradebook=' . $gradebook . '&action=view&lp_id=' . $_SESSION['oLP']->lp_id . '">' . Display :: return_icon('view_left_right.png', get_lang('Display'),'','32').'</a> ';
- Display :: display_icon('i.gif');
- echo '<a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&gradebook=' . $gradebook . '&action=add_item&type=step&lp_id=' . $_SESSION['oLP']->lp_id . '" title="' . get_lang('NewStep') . '">' . Display :: return_icon('new_learnigpath_object.png', get_lang('NewStep'),'','32').'</a>';
-
- echo '<a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&gradebook=' . $gradebook . '&action=add_item&type=chapter&lp_id=' . $_SESSION['oLP']->lp_id . '" title="' . get_lang('NewChapter') . '">' . Display :: return_icon('add_learnpath_section.png', get_lang('NewChapter'),'','32').'</a>';
- echo '<a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&action=admin_view&lp_id=' . $_SESSION['oLP']->lp_id . '&updateaudio=true">' . Display :: return_icon('upload_audio.png', get_lang('UpdateAllAudioFragments'),'','32').'</a>';
- echo '<a href="lp_controller.php?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&action=edit&lp_id=' . $_SESSION['oLP']->lp_id . '">' . Display :: return_icon('settings.png', get_lang('CourseSettings'),'','32').'</a>';
- echo '</div>';
- }
-
- public function build_tree() {
- $return = "<script type=\"text/javascript\">\n";
- $return .= "\tm = new dTree('m');\n\n";
- $return .= "\tm.config.folderLinks = true;\n";
- $return .= "\tm.config.useCookies = true;\n";
- $return .= "\tm.config.useIcons = true;\n";
- $return .= "\tm.config.useLines = true;\n";
- $return .= "\tm.config.useSelection = true;\n";
- $return .= "\tm.config.useStatustext = false;\n\n";
- $menu = 0;
- $parent = '';
- $return .= "\tm.add(" . $menu . ", -1, '" . addslashes(Security::remove_XSS(($this->name))) . "');\n";
- $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
- $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
- FROM $tbl_lp_item
- WHERE lp_id = " . Database :: escape_string($this->lp_id);
- $result = Database::query($sql);
- $arrLP = array ();
- while ($row = Database :: fetch_array($result)) {
- $row['title'] = Security :: remove_XSS($row['title']);
- $row['description'] = Security :: remove_XSS($row['description']);
- $arrLP[] = array (
- 'id' => $row['id'],
- 'item_type' => $row['item_type'],
- 'title' => $row['title'],
- 'path' => $row['path'],
- 'description' => $row['description'],
- 'parent_item_id' => $row['parent_item_id'],
- 'previous_item_id' => $row['previous_item_id'],
- 'next_item_id' => $row['next_item_id'],
- 'max_score' => $row['max_score'],
- 'min_score' => $row['min_score'],
- 'mastery_score' => $row['mastery_score'],
- 'display_order' => $row['display_order']
- );
- }
- $this->tree_array($arrLP);
- $arrLP = $this->arrMenu;
- unset ($this->arrMenu);
- $title = '';
- for ($i = 0; $i < count($arrLP); $i++) {
- $title = addslashes($arrLP[$i]['title']);
- $menu_page = api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&action=view_item&id=' . $arrLP[$i]['id'] . '&lp_id=' . $_SESSION['oLP']->lp_id;
- $icon_name = str_replace(' ', '', $arrLP[$i]['item_type']);
- if (file_exists('../img/lp_' . $icon_name . '.png')) {
- $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";
- } else
- if (file_exists('../img/lp_' . $icon_name . '.gif')) {
- $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";
- } else {
- $return .= "\tm.add(" . $arrLP[$i]['id'] . ", " . $arrLP[$i]['parent_item_id'] . ", '" . $title . "', '" . $menu_page . "', '', '', '../img/folder_document.gif', '../img/folder_document.gif');\n";
- }
- if ($menu < $arrLP[$i]['id'])
- $menu = $arrLP[$i]['id'];
- }
- $return .= "\n\tdocument.write(m);\n";
- $return .= "\t if(!m.selectedNode) m.s(1);";
- $return .= "</script>\n";
- return $return;
- }
-
- public function create_document($_course) {
- global $charset;
- $dir = isset ($_GET['dir']) ? $_GET['dir'] : $_POST['dir'];
- if (strstr($dir, '..'))
- $dir = '/';
- if ($dir[0] == '.')
- $dir = substr($dir, 1);
- if ($dir[0] != '/')
- $dir = '/' . $dir;
- if ($dir[strlen($dir) - 1] != '/')
- $dir .= '/';
- $filepath = api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document' . $dir;
- if (!is_dir($filepath)) {
- $filepath = api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document/';
- $dir = '/';
- }
-
-
- $title = replace_dangerous_char(stripslashes($_POST['title']));
- $title = disable_dangerous_file($title);
- $filename = $title;
- $content = $_POST['content_lp'];
- $tmp_filename = $filename;
- $i = 0;
- while (file_exists($filepath . $tmp_filename . '.html'))
- $tmp_filename = $filename . '_' . ++ $i;
- $filename = $tmp_filename . '.html';
- $content = stripslashes(text_filter($content));
- $content = str_replace(api_get_path(WEB_COURSE_PATH), api_get_path(REL_PATH) . 'courses/', $content);
-
-
- $content = preg_replace("|(flashvars=\"file=)(\.+/)+|", "$1" . api_get_path(REL_COURSE_PATH) . $_course['path'] . '/document/', $content);
-
- $content = preg_replace("|(flashvars=\"file=)([^/]+)/|", "$1" . api_get_path(REL_COURSE_PATH) . $_course['path'] . '/document/$2/', $content);
-
- $content = str_replace('</body>', '<style type="text/css">body{}</style></body>', $content);
- if (!file_exists($filepath . $filename)) {
- if ($fp = @ fopen($filepath . $filename, 'w')) {
- fputs($fp, $content);
- fclose($fp);
- $file_size = filesize($filepath . $filename);
- $save_file_path = $dir . $filename;
- $document_id = add_document($_course, $save_file_path, 'file', $file_size, $filename . '.html');
- if ($document_id) {
- api_item_property_update($_course, TOOL_DOCUMENT, $document_id, 'DocumentAdded', api_get_user_id(), null, null, null, null, api_get_session_id());
-
-
- $new_comment = (isset($_POST['comment'])) ? trim($_POST['comment']) : '';
- $new_title = (isset($_POST['title'])) ? trim($_POST['title']) : '';
- if ($new_comment || $new_title) {
- $tbl_doc = Database :: get_course_table(TABLE_DOCUMENT);
- $ct = '';
- if ($new_comment)
- $ct .= ", comment='" . $new_comment . "'";
- if ($new_title)
- $ct .= ", title='" . Database :: escape_string(htmlspecialchars($new_title, ENT_QUOTES, $charset)) . ".html '";
- $sql_update = "
- UPDATE " . $tbl_doc . "
- SET " . substr($ct, 1) . "
- WHERE id = " . $document_id;
- Database::query($sql_update);
- }
- }
- return $document_id;
- }
- }
- }
-
- public function edit_document($_course) {
- global $_configuration;
- $dir = isset ($_GET['dir']) ? $_GET['dir'] : $_POST['dir'];
- if (strstr($dir, '..'))
- $dir = '/';
- if ($dir[0] == '.')
- $dir = substr($dir, 1);
- if ($dir[0] != '/')
- $dir = '/' . $dir;
- if ($dir[strlen($dir) - 1] != '/')
- $dir .= '/';
- $filepath = api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document' . $dir;
- if (!is_dir($filepath)) {
- $filepath = api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document/';
- $dir = '/';
- }
- $table_doc = Database :: get_course_table(TABLE_DOCUMENT);
- if (isset($_POST['path']) && !empty($_POST['path'])) {
- $sql = "SELECT path
- FROM " . $table_doc . "
- WHERE id = " . Database::escape_string($_POST['path']);
- $res = Database::query($sql);
- $row = Database :: fetch_array($res);
- $content = stripslashes($_POST['content_lp']);
- $file = $filepath . $row['path'];
- if ($fp = @ fopen($file, 'w')) {
- $content = text_filter($content);
- $content = str_replace(api_get_path(WEB_COURSE_PATH), $_configuration['url_append'] . '/courses/', $content);
-
-
- $content = preg_replace("|(flashvars=\"file=)(\.+/)+|", "$1" . api_get_path(REL_COURSE_PATH) . $_course['path'] . '/document/', $content);
-
- $content = preg_replace("|(flashvars=\"file=)([^/]+)/|", "$1" . api_get_path(REL_COURSE_PATH) . $_course['path'] . '/document/$2/', $content);
- fputs($fp, $content);
- fclose($fp);
- }
- }
- }
-
- public function display_item($item_id, $iframe = true, $msg = '') {
- global $_course;
- $return = '';
- if (is_numeric($item_id)) {
- $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
- $tbl_doc = Database :: get_course_table(TABLE_DOCUMENT);
- $sql = "SELECT lp.* FROM " . $tbl_lp_item . " as lp
- WHERE lp.id = " . Database :: escape_string($item_id);
- $result = Database::query($sql);
- while ($row = Database :: fetch_array($result)) {
- $_SESSION['parent_item_id'] = ($row['item_type'] == 'dokeos_chapter' || $row['item_type'] == 'dokeos_module' || $row['item_type'] == 'dir') ? $item_id : 0;
-
- if ($row['item_type'] != 'dokeos_chapter' || $row['item_type'] != 'dokeos_module') {
- $_SESSION['parent_item_id'] = $row['parent_item_id'];
- }
- $return .= $this->display_manipulate($item_id, $row['item_type']);
- $return .= '<div style="padding:10px;">';
- if ($msg != '')
- $return .= $msg;
- $return .= '<p class="lp_title">' . $row['title'] . '</p>';
-
-
- switch ($row['item_type']) {
- case TOOL_QUIZ:
- if (!empty($row['path'])) {
- require_once api_get_path(SYS_CODE_PATH).'exercice/exercise.class.php';
- $exercise = new Exercise();
- $exercise->read($row['path']);
-
- $return .=$exercise->description.'<br />';
-
- }
- break;
- case TOOL_DOCUMENT:
- $tbl_doc = Database :: get_course_table(TABLE_DOCUMENT);
- $sql_doc = "SELECT path FROM " . $tbl_doc . " WHERE id = " . Database :: escape_string($row['path']);
- $result = Database::query($sql_doc);
- $path_file = Database :: result($result, 0, 0);
- $path_parts = pathinfo($path_file);
-
- if (in_array($path_parts['extension'], array (
- 'html',
- 'txt',
- 'png',
- 'jpg',
- 'JPG',
- 'jpeg',
- 'JPEG',
- 'gif',
- 'swf'
- ))) {
- $return .= $this->display_document($row['path'], true, true);
- }
- break;
- }
- $return .= '</div>';
- }
- }
- return $return;
- }
-
- public function display_edit_item($item_id) {
- global $_course;
- $return = '';
- if (is_numeric($item_id)) {
- $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
- $sql = "SELECT * FROM $tbl_lp_item WHERE id = " . Database :: escape_string($item_id);
- $res = Database::query($sql);
- $row = Database::fetch_array($res);
-
- switch ($row['item_type']) {
- case 'dokeos_chapter' :
- case 'dir' :
- case 'asset' :
- case 'sco' :
- if (isset ($_GET['view']) && $_GET['view'] == 'build') {
- $return .= $this->display_manipulate($item_id, $row['item_type']);
- $return .= $this->display_item_form($row['item_type'], get_lang('EditCurrentChapter') . ' :', 'edit', $item_id, $row);
- } else {
- $return .= $this->display_item_small_form($row['item_type'], get_lang('EditCurrentChapter') . ' :', $row);
- }
- break;
- case TOOL_DOCUMENT :
- $tbl_doc = Database :: get_course_table(TABLE_DOCUMENT);
- $sql_step = " SELECT lp.*, doc.path as dir
- FROM " . $tbl_lp_item . " as lp
- LEFT JOIN " . $tbl_doc . " as doc ON doc.id = lp.path
- WHERE lp.id = " . Database :: escape_string($item_id);
- $res_step = Database::query($sql_step);
- $row_step = Database :: fetch_array($res_step);
- $return .= $this->display_manipulate($item_id, $row['item_type']);
- $return .= $this->display_document_form('edit', $item_id, $row_step);
- break;
- case TOOL_LINK :
- $link_id = (string) $row['path'];
- if (ctype_digit($link_id)) {
- $tbl_link = Database :: get_course_table(TABLE_LINK);
- $sql_select = 'SELECT url FROM ' . $tbl_link . ' WHERE id = ' . Database :: escape_string($link_id);
- $res_link = Database::query($sql_select);
- $row_link = Database :: fetch_array($res_link);
- if (is_array($row_link)) {
- $row['url'] = $row_link['url'];
- }
- }
- $return .= $this->display_manipulate($item_id, $row['item_type']);
- $return .= $this->display_link_form('edit', $item_id, $row);
- break;
- case 'dokeos_module' :
- if (isset ($_GET['view']) && $_GET['view'] == 'build') {
- $return .= $this->display_manipulate($item_id, $row['item_type']);
- $return .= $this->display_item_form($row['item_type'], get_lang('EditCurrentModule') . ' :', 'edit', $item_id, $row);
- } else {
- $return .= $this->display_item_small_form($row['item_type'], get_lang('EditCurrentModule') . ' :', $row);
- }
- break;
- case TOOL_QUIZ :
- $return .= $this->display_manipulate($item_id, $row['item_type']);
- $return .= $this->display_quiz_form('edit', $item_id, $row);
- break;
- case TOOL_HOTPOTATOES :
- $return .= $this->display_manipulate($item_id, $row['item_type']);
- $return .= $this->display_hotpotatoes_form('edit', $item_id, $row);
- break;
- case TOOL_STUDENTPUBLICATION :
- $return .= $this->display_manipulate($item_id, $row['item_type']);
- $return .= $this->display_student_publication_form('edit', $item_id, $row);
- break;
- case TOOL_FORUM :
- $return .= $this->display_manipulate($item_id, $row['item_type']);
- $return .= $this->display_forum_form('edit', $item_id, $row);
- break;
- case TOOL_THREAD :
- $return .= $this->display_manipulate($item_id, $row['item_type']);
- $return .= $this->display_thread_form('edit', $item_id, $row);
- break;
- }
- }
- return $return;
- }
-
- public function display_resources() {
- global $_course;
-
-
-
-
- $documents = $this->get_documents();
-
- $exercises = $this->get_exercises();
-
- $links = $this->get_links();
-
- $works = $this->get_student_publications();
-
- $forums = $this->get_forums();
- $headers = array( Display::return_icon('folder_document.png', get_lang('Documents'), array(), 64),
- Display::return_icon('quiz.png', get_lang('Exercises'), array(), 64),
- Display::return_icon('links.png', get_lang('Links'), array(), 64),
- Display::return_icon('works.png', get_lang('Works'), array(), 64),
- Display::return_icon('forum.png', get_lang('Forums'), array(), 64),
- );
-
- echo Display::tabs($headers, array($documents, $exercises, $links, $works, $forums), 'resource_tab');
- return true;
- }
-
- public function get_extension($filename) {
- $explode = explode('.', $filename);
- return $explode[count($explode) - 1];
- }
-
- public function display_document($id, $show_title = false, $iframe = true, $edit_link = false) {
- global $_course;
- $return = '';
- $tbl_doc = Database :: get_course_table(TABLE_DOCUMENT);
- $sql_doc = "SELECT * FROM " . $tbl_doc . "
- WHERE id = " . $id;
- $res_doc = Database::query($sql_doc);
- $row_doc = Database :: fetch_array($res_doc);
-
-
-
- if ($iframe) {
- $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>';
- } else {
- $return .= file_get_contents(api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document' . $row_doc['path']);
- }
- return $return;
- }
-
- public function display_quiz_form($action = 'add', $id = 0, $extra_info = '') {
- global $charset;
- $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
- $tbl_quiz = Database :: get_course_table(TABLE_QUIZ_TEST);
- if ($id != 0 && is_array($extra_info)) {
- $item_title = stripslashes($extra_info['title']);
- $item_description = stripslashes($extra_info['description']);
- }
- elseif (is_numeric($extra_info)) {
- $sql_quiz = "
- SELECT
- title,
- description
- FROM " . $tbl_quiz . "
- WHERE id = " . $extra_info;
- $result = Database::query($sql_quiz);
- $row = Database :: fetch_array($result);
- $item_title = $row['title'];
- $item_description = $row['description'];
- } else {
- $item_title = '';
- $item_description = '';
- }
- $return = ' <div class="row">
- <div class="form_header">';
- if ($id != 0 && is_array($extra_info))
- $parent = $extra_info['parent_item_id'];
- else
- $parent = 0;
- $sql = "
- SELECT *
- FROM " . $tbl_lp_item . "
- WHERE
- lp_id = " . $this->lp_id;
- $result = Database::query($sql);
- $arrLP = array ();
- while ($row = Database :: fetch_array($result)) {
- $arrLP[] = array (
- 'id' => $row['id'],
- 'item_type' => $row['item_type'],
- 'title' => $row['title'],
- 'path' => $row['path'],
- 'description' => $row['description'],
- 'parent_item_id' => $row['parent_item_id'],
- 'previous_item_id' => $row['previous_item_id'],
- 'next_item_id' => $row['next_item_id'],
- 'display_order' => $row['display_order'],
- 'max_score' => $row['max_score'],
- 'min_score' => $row['min_score'],
- 'mastery_score' => $row['mastery_score'],
- 'prerequisite' => $row['prerequisite'],
- 'max_time_allowed' => $row['max_time_allowed']
- );
- }
- $this->tree_array($arrLP);
- $arrLP = $this->arrMenu;
- unset ($this->arrMenu);
- if ($action == 'add')
- $return .= get_lang('CreateTheExercise') . ' :';
- elseif ($action == 'move') $return .= get_lang('MoveTheCurrentExercise') . ' :';
- else
- $return .= get_lang('EditCurrentExecice') . ' :';
- if (isset ($_GET['edit']) && $_GET['edit'] == 'true') {
- $return .= Display :: return_warning_message('<p class="lp_title">' . get_lang('Warning') . ' !</p>' . get_lang('WarningEditingDocument'));
- }
- $return .= ' </div>
- </div>';
- $return .= '<div class="sectioncomment">';
- $return .= '<form method="POST">';
- $return .= '<table class="lp_form">';
- if ($action != 'move') {
- $return .= '<tr>';
- $return .= '<td class="label"><label for="idTitle">' . get_lang('Title') . '</label></td>';
- $return .= '<td class="input"><input id="idTitle" name="title" size="44" type="text" class="learnpath_item_form" value="' . $item_title . '" /></td>';
- $return .= '</tr>';
- }
- $return .= '<tr>';
- $return .= '<td class="label"><label for="idParent">' . get_lang('Parent') . '</label></td>';
- $return .= '<td class="input">';
- $return .= "\t\t\t\t" . '<select id="idParent" style="width:100%;" name="parent" onChange="javascript: load_cbo(this.value);" class="learnpath_item_form" size="1">';
- $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
- $arrHide = array (
- $id
- );
-
- for ($i = 0; $i < count($arrLP); $i++) {
- if ($action != 'add') {
- 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)) {
- $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>';
- } else {
- $arrHide[] = $arrLP[$i]['id'];
- }
- } else {
- if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
- $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>';
- }
- }
- if (is_array($arrLP)) {
- reset($arrLP);
- }
- $return .= '</select>';
- $return .= '</td>';
- $return .= '</tr>';
- $return .= '<tr>';
- $return .= '<td class="label"><label for="previous">' . get_lang('Position') . '</label></td>';
- $return .= '<td class="input">';
- $return .= "\t\t\t\t" . '<select class="learnpath_item_form" style="width:100%;" id="previous" name="previous" size="1">';
- $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . get_lang('FirstPosition') . '</option>';
- for ($i = 0; $i < count($arrLP); $i++) {
- if ($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) {
- if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
- $selected = 'selected="selected" ';
- elseif ($action == 'add') $selected = 'selected="selected" ';
- else
- $selected = '';
- $return .= "\t\t\t\t\t" . '<option ' . $selected . 'value="' . $arrLP[$i]['id'] . '">' . get_lang('After') . ' "' . $arrLP[$i]['title'] . '"</option>';
- }
- }
- $return .= "\t\t\t\t" . '</select>';
- $return .= '</td>';
- $return .= '</tr>';
- if ($action != 'move') {
- $id_prerequisite = 0;
- if (is_array($arrLP)) {
- foreach ($arrLP as $key => $value) {
- if ($value['id'] == $id) {
- $id_prerequisite = $value['prerequisite'];
- break;
- }
- }
- }
- $arrHide = array ();
- for ($i = 0; $i < count($arrLP); $i++) {
- if ($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter') {
- if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
- $s_selected_position = $arrLP[$i]['id'];
- elseif ($action == 'add') $s_selected_position = 0;
- $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
- }
- }
-
- $return .= '</tr>';
-
- }
- $return .= '<tr>';
- if ($action == 'add') {
- $return .= '<td> </td><td><button class="save" name="submit_button" type="submit">' . get_lang('AddExercise') . '</button></td>';
- } else {
- $return .= '<td> </td><td><button class="save" name="submit_button" type="submit">' . get_lang('EditCurrentExecice') . '</button></td>';
- }
- $return .= '</tr>';
- $return .= '</table>';
- if ($action == 'move') {
- $return .= '<input name="title" type="hidden" value="' . $item_title . '" />';
- $return .= '<input name="description" type="hidden" value="' . $item_description . '" />';
- }
- if (is_numeric($extra_info)) {
- $return .= '<input name="path" type="hidden" value="' . $extra_info . '" />';
- }
- elseif (is_array($extra_info)) {
- $return .= '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />';
- }
- $return .= '<input name="type" type="hidden" value="' . TOOL_QUIZ . '" />';
- $return .= '<input name="post_time" type="hidden" value="' . time() . '" />';
- $return .= '</form>';
- $return .= '</div>';
- return $return;
- }
-
- public function display_hotpotatoes_form($action = 'add', $id = 0, $extra_info = '') {
- global $charset;
- $uploadPath = DIR_HOTPOTATOES;
- $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
- if ($id != 0 && is_array($extra_info)) {
- $item_title = stripslashes($extra_info['title']);
- $item_description = stripslashes($extra_info['description']);
- } elseif (is_numeric($extra_info)) {
- $TBL_DOCUMENT = Database :: get_course_table(TABLE_DOCUMENT);
-
- $sql_hot = "SELECT * FROM " . $TBL_DOCUMENT . "
- WHERE path LIKE '" . $uploadPath . "/%/%htm%'
- AND id = " . (int) $extra_info . " ORDER BY id ASC";
- $res_hot = Database::query($sql_hot);
- $row = Database::fetch_array($res_hot);
- $item_title = $row['title'];
- $item_description = $row['description'];
- if (!empty ($row['comment'])) {
- $item_title = $row['comment'];
- }
- } else {
- $item_title = '';
- $item_description = '';
- }
-
- if ($id != 0 && is_array($extra_info))
- $parent = $extra_info['parent_item_id'];
- else
- $parent = 0;
- $sql = "SELECT * FROM $tbl_lp_item WHERE lp_id = " . $this->lp_id;
- $result = Database::query($sql);
- $arrLP = array ();
- while ($row = Database :: fetch_array($result)) {
- $arrLP[] = array (
- 'id' => $row['id'],
- 'item_type' => $row['item_type'],
- 'title' => $row['title'],
- 'path' => $row['path'],
- 'description' => $row['description'],
- 'parent_item_id' => $row['parent_item_id'],
- 'previous_item_id' => $row['previous_item_id'],
- 'next_item_id' => $row['next_item_id'],
- 'display_order' => $row['display_order'],
- 'max_score' => $row['max_score'],
- 'min_score' => $row['min_score'],
- 'mastery_score' => $row['mastery_score'],
- 'prerequisite' => $row['prerequisite'],
- 'max_time_allowed' => $row['max_time_allowed']
- );
- }
- if ($action == 'add')
- $return .= '<div class="row"><div class="form_header">' . get_lang('CreateTheExercise') . ' :</div></div>';
- elseif ($action == 'move') $return .= '<p class="lp_title">' . get_lang('MoveTheCurrentExercise') . ' :</p>';
- else
-
- $return .= '<div class="row"><div class="form_header">' . get_lang('EditCurrentExecice') . ' :</div></div>';
- if (isset ($_GET['edit']) && $_GET['edit'] == 'true') {
- $return .= Display :: return_warning_message('<p class="lp_title">' . get_lang('Warning') . ' !</p>' . get_lang('WarningEditingDocument'));
- }
- $return .= '<form method="POST">';
- $return .= '<table cellpadding="0" cellspacing="0" class="lp_form">';
- $return .= '<tr>';
- $return .= '<td class="label"><label for="idParent">' . get_lang('Parent') . ' :</label></td>';
- $return .= '<td class="input">';
- $return .= "\t\t\t\t" . '<select id="idParent" name="parent" onChange="javascript: load_cbo(this.value);" size="1">';
- $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
- $arrHide = array (
- $id
- );
- if (count($arrLP) > 0) {
- for ($i = 0; $i < count($arrLP); $i++) {
- if ($action != 'add') {
- 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)) {
- $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>';
- } else {
- $arrHide[] = $arrLP[$i]['id'];
- }
- } else {
- if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
- $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>';
- }
- }
- reset($arrLP);
- }
- $return .= "\t\t\t\t" . '</select>';
- $return .= '</td>';
- $return .= '</tr>';
- $return .= '<tr>';
- $return .= '<td class="label"><label for="previous">' . get_lang('Position') . ' :</label></td>';
- $return .= '<td class="input">';
- $return .= "\t\t\t\t" . '<select id="previous" name="previous" size="1">';
- $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . get_lang('FirstPosition') . '</option>';
- for ($i = 0; $i < count($arrLP); $i++) {
- if ($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) {
- if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
- $selected = 'selected="selected" ';
- elseif ($action == 'add') $selected = 'selected="selected" ';
- else
- $selected = '';
- $return .= "\t\t\t\t\t" . '<option ' . $selected . 'value="' . $arrLP[$i]['id'] . '">' . get_lang('After') . ' "' . $arrLP[$i]['title'] . '"</option>';
- }
- }
- $return .= "\t\t\t\t" . '</select>';
- $return .= '</td>';
- $return .= '</tr>';
-
- if ($action != 'move') {
- $return .= '<tr>';
- $return .= '<td class="label"><label for="idTitle">' . get_lang('Title') . ' :</label></td>';
- $return .= '<td class="input"><input id="idTitle" name="title" type="text" value="' . $item_title . '" /></td>';
- $return .= '</tr>';
- $id_prerequisite = 0;
- if (is_array($arrLP) && count($arrLP) > 0) {
- foreach ($arrLP as $key => $value) {
- if ($value['id'] == $id) {
- $id_prerequisite = $value['prerequisite'];
- break;
- }
- }
- $arrHide = array ();
- for ($i = 0; $i < count($arrLP); $i++) {
- if ($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter') {
- if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
- $s_selected_position = $arrLP[$i]['id'];
- elseif ($action == 'add') $s_selected_position = 0;
- $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
- }
- }
- }
-
-
-
-
-
-
-
- }
- $return .= '<tr>';
- $return .= '<td> </td><td><button class="save" name="submit_button" action="edit" type="submit">' . get_lang('SaveHotpotatoes') . '</button></td>';
- $return .= '</tr>';
- $return .= '</table>';
- if ($action == 'move') {
- $return .= '<input name="title" type="hidden" value="' . $item_title . '" />';
- $return .= '<input name="description" type="hidden" value="' . $item_description . '" />';
- }
- if (is_numeric($extra_info)) {
- $return .= '<input name="path" type="hidden" value="' . $extra_info . '" />';
- }
- elseif (is_array($extra_info)) {
- $return .= '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />';
- }
- $return .= '<input name="type" type="hidden" value="' . TOOL_HOTPOTATOES . '" />';
- $return .= '<input name="post_time" type="hidden" value="' . time() . '" />';
- $return .= '</form>';
-
- return $return;
- }
-
- public function display_forum_form($action = 'add', $id = 0, $extra_info = '') {
- global $charset;
- $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
- $tbl_forum = Database :: get_course_table(TABLE_FORUM);
- if ($id != 0 && is_array($extra_info)) {
- $item_title = stripslashes($extra_info['title']);
- }
- elseif (is_numeric($extra_info)) {
- $sql_forum = "
- SELECT
- forum_title as title, forum_comment as comment
- FROM " . $tbl_forum . "
- WHERE forum_id = " . $extra_info;
- $result = Database::query($sql_forum);
- $row = Database :: fetch_array($result);
- $item_title = $row['title'];
- $item_description = $row['comment'];
- } else {
- $item_title = '';
- $item_description = '';
- }
- $return = ' <div class="row">
- <div class="form_header">';
- if ($id != 0 && is_array($extra_info))
- $parent = $extra_info['parent_item_id'];
- else
- $parent = 0;
- $sql = "
- SELECT *
- FROM " . $tbl_lp_item . "
- WHERE
- lp_id = " . $this->lp_id;
- $result = Database::query($sql);
- $arrLP = array ();
- while ($row = Database :: fetch_array($result)) {
- $arrLP[] = array (
- 'id' => $row['id'],
- 'item_type' => $row['item_type'],
- 'title' => $row['title'],
- 'path' => $row['path'],
- 'description' => $row['description'],
- 'parent_item_id' => $row['parent_item_id'],
- 'previous_item_id' => $row['previous_item_id'],
- 'next_item_id' => $row['next_item_id'],
- 'display_order' => $row['display_order'],
- 'max_score' => $row['max_score'],
- 'min_score' => $row['min_score'],
- 'mastery_score' => $row['mastery_score'],
- 'prerequisite' => $row['prerequisite']
- );
- }
- $this->tree_array($arrLP);
- $arrLP = $this->arrMenu;
- unset ($this->arrMenu);
- if ($action == 'add')
- $return .= get_lang('CreateTheForum') . ' :';
- elseif ($action == 'move') $return .= get_lang('MoveTheCurrentForum') . ' :';
- else
- $return .= get_lang('EditCurrentForum') . ' :';
- $return .= ' </div>
- </div>';
- $return .= '<div class="sectioncomment">';
- $return .= '<form method="POST">';
- $return .= '<table class="lp_form">';
- if ($action != 'move') {
- $return .= '<tr>';
- $return .= '<td class="label"><label for="idTitle">' . get_lang('Title') . '</label></td>';
- $return .= '<td class="input"><input id="idTitle" size="44" name="title" type="text" value="' . $item_title . '" class="learnpath_item_form" /></td>';
- $return .= '</tr>';
- }
- $return .= '<tr>';
- $return .= '<td class="label"><label for="idParent">' . get_lang('Parent') . '</label></td>';
- $return .= '<td class="input">';
- $return .= "\t\t\t\t" . '<select id="idParent" style="width:100%;" name="parent" onChange="javascript: load_cbo(this.value);" class="learnpath_item_form" size="1">';
- $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
- $arrHide = array (
- $id
- );
-
- for ($i = 0; $i < count($arrLP); $i++) {
- if ($action != 'add') {
- 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)) {
- $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>';
- } else {
- $arrHide[] = $arrLP[$i]['id'];
- }
- } else {
- if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
- $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>';
- }
- }
- if (is_array($arrLP)) {
- reset($arrLP);
- }
- $return .= "\t\t\t\t" . '</select>';
- $return .= '</td>';
- $return .= '</tr>';
- $return .= '<tr>';
- $return .= '<td class="label"><label for="previous">' . get_lang('Position') . '</label></td>';
- $return .= '<td class="input">';
- $return .= "\t\t\t\t" . '<select id="previous" name="previous" style="width:100%;" size="1" class="learnpath_item_form">';
- $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . get_lang('FirstPosition') . '</option>';
- for ($i = 0; $i < count($arrLP); $i++) {
- if ($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) {
- if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
- $selected = 'selected="selected" ';
- elseif ($action == 'add') $selected = 'selected="selected" ';
- else
- $selected = '';
- $return .= "\t\t\t\t\t" . '<option ' . $selected . 'value="' . $arrLP[$i]['id'] . '">' . get_lang('After') . ' "' . $arrLP[$i]['title'] . '"</option>';
- }
- }
- $return .= "\t\t\t\t" . '</select>';
- $return .= '</td>';
- $return .= '</tr>';
- if ($action != 'move') {
- $return .= '<tr>';
- $return .= '</tr>';
- $id_prerequisite = 0;
- if (is_array($arrLP)) {
- foreach ($arrLP as $key => $value) {
- if ($value['id'] == $id) {
- $id_prerequisite = $value['prerequisite'];
- break;
- }
- }
- }
- $arrHide = array ();
- for ($i = 0; $i < count($arrLP); $i++) {
- if ($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter') {
- if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
- $s_selected_position = $arrLP[$i]['id'];
- elseif ($action == 'add') $s_selected_position = 0;
- $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
- }
- }
- $return .= '</tr>';
- }
- $return .= '<tr>';
- if ($action == 'add') {
- $return .= '<td> </td><td><button class="save" name="submit_button" type="submit"> ' . get_lang('AddForumToCourse') . ' </button></td>';
- } else {
- $return .= '<td> </td><td><button class="save" name="submit_button" type="submit"> ' . get_lang('EditCurrentForum') . ' </button></td>';
- }
- $return .= '</tr>';
- $return .= '</table>';
- if ($action == 'move') {
- $return .= '<input name="title" type="hidden" value="' . $item_title . '" />';
- $return .= '<input name="description" type="hidden" value="' . $item_description . '" />';
- }
- if (is_numeric($extra_info)) {
- $return .= '<input name="path" type="hidden" value="' . $extra_info . '" />';
- }
- elseif (is_array($extra_info)) {
- $return .= '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />';
- }
- $return .= '<input name="type" type="hidden" value="' . TOOL_FORUM . '" />';
- $return .= '<input name="post_time" type="hidden" value="' . time() . '" />';
- $return .= '</form>';
- $return .= '</div>';
- return $return;
- }
-
- public function display_thread_form($action = 'add', $id = 0, $extra_info = '') {
- global $charset;
- echo '
- <style>
- div.row div.label {
- width:110px;
- }
- div.row div.formw {
- width: 82%;
- }
- </style>';
- $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
- $tbl_forum = Database :: get_course_table(TABLE_FORUM_THREAD);
- if ($id != 0 && is_array($extra_info)) {
- $item_title = stripslashes($extra_info['title']);
- }
- elseif (is_numeric($extra_info)) {
- $sql_forum = "
- SELECT
- thread_title as title
- FROM " . $tbl_forum . "
- WHERE thread_id = " . $extra_info;
- $result = Database::query($sql_forum);
- $row = Database :: fetch_array($result);
- $item_title = $row['title'];
- $item_description = '';
- } else {
- $item_title = '';
- $item_description = '';
- }
- $return = '<div style="margin:3px 12px;">';
- if ($id != 0 && is_array($extra_info))
- $parent = $extra_info['parent_item_id'];
- else
- $parent = 0;
- $sql = "
- SELECT *
- FROM " . $tbl_lp_item . "
- WHERE
- lp_id = " . $this->lp_id;
- $result = Database::query($sql);
- $arrLP = array ();
- while ($row = Database :: fetch_array($result)) {
- $arrLP[] = array (
- 'id' => $row['id'],
- 'item_type' => $row['item_type'],
- 'title' => $row['title'],
- 'path' => $row['path'],
- 'description' => $row['description'],
- 'parent_item_id' => $row['parent_item_id'],
- 'previous_item_id' => $row['previous_item_id'],
- 'next_item_id' => $row['next_item_id'],
- 'display_order' => $row['display_order'],
- 'max_score' => $row['max_score'],
- 'min_score' => $row['min_score'],
- 'mastery_score' => $row['mastery_score'],
- 'prerequisite' => $row['prerequisite']
- );
- }
- $this->tree_array($arrLP);
- $arrLP = $this->arrMenu;
- unset ($this->arrMenu);
- if ($action == 'add')
- $return .= '<p class="lp_title">' . get_lang('CreateTheForum') . ' :</p>';
- elseif ($action == 'move') $return .= '<p class="lp_title">' . get_lang('MoveTheCurrentForum') . ' :</p>';
- else
- $return .= '<p class="lp_title">' . get_lang('EditCurrentForum') . ' :</p>';
- $return .= '<form method="POST">';
- $return .= '<table cellpadding="0" cellspacing="0" class="lp_form">';
- $return .= '<tr>';
- $return .= '<td class="label"><label for="idParent">' . get_lang('Parent') . ' :</label></td>';
- $return .= '<td class="input">';
- $return .= "\t\t\t\t" . '<select id="idParent" name="parent" onChange="javascript: load_cbo(this.value);" size="1">';
- $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
- $arrHide = array (
- $id
- );
- for ($i = 0; $i < count($arrLP); $i++) {
- if ($action != 'add') {
- 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)) {
- $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>';
- } else {
- $arrHide[] = $arrLP[$i]['id'];
- }
- } else {
- if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
- $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>';
- }
- }
- if ($arrLP != null) {
- reset($arrLP);
- }
- $return .= "\t\t\t\t" . '</select>';
- $return .= '</td>';
- $return .= '</tr>';
- $return .= '<tr>';
- $return .= '<td class="label"><label for="previous">' . get_lang('Position') . ' :</label></td>';
- $return .= '<td class="input">';
- $return .= "\t\t\t\t" . '<select id="previous" name="previous" size="1">';
- $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . get_lang('FirstPosition') . '</option>';
- for ($i = 0; $i < count($arrLP); $i++) {
- if ($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) {
- if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
- $selected = 'selected="selected" ';
- elseif ($action == 'add') $selected = 'selected="selected" ';
- else
- $selected = '';
- $return .= "\t\t\t\t\t" . '<option ' . $selected . 'value="' . $arrLP[$i]['id'] . '">' . get_lang('After') . ' "' . $arrLP[$i]['title'] . '"</option>';
- }
- }
- $return .= "\t\t\t\t" . '</select>';
- $return .= '</td>';
- $return .= '</tr>';
- if ($action != 'move') {
- $return .= '<tr>';
- $return .= '<td class="label"><label for="idTitle">' . get_lang('Title') . ' :</label></td>';
- $return .= '<td class="input"><input id="idTitle" name="title" type="text" value="' . $item_title . '" /></td>';
- $return .= '</tr>';
- $return .= '<tr>';
- $return .= '</tr>';
- $id_prerequisite = 0;
- if ($arrLP != null) {
- foreach ($arrLP as $key => $value) {
- if ($value['id'] == $id) {
- $id_prerequisite = $value['prerequisite'];
- break;
- }
- }
- }
- $arrHide = array();
- for ($i = 0; $i < count($arrLP); $i++) {
- if ($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter') {
- if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
- $s_selected_position = $arrLP[$i]['id'];
- elseif ($action == 'add') $s_selected_position = 0;
- $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
- }
- }
- $return .= '<tr>';
- $return .= '<td class="label"><label for="idPrerequisites">' . get_lang('Prerequisites') . ' :</label></td>';
- $return .= '<td class="input"><select name="prerequisites" id="prerequisites"><option value="0">' . get_lang('NoPrerequisites') . '</option>';
- foreach ($arrHide as $key => $value) {
- if ($key == $s_selected_position && $action == 'add') {
- $return .= '<option value="' . $key . '" selected="selected">' . $value['value'] . '</option>';
- }
- elseif ($key == $id_prerequisite && $action == 'edit') {
- $return .= '<option value="' . $key . '" selected="selected">' . $value['value'] . '</option>';
- } else {
- $return .= '<option value="' . $key . '">' . $value['value'] . '</option>';
- }
- }
- $return .= "</select></td>";
- $return .= '</tr>';
- }
- $return .= '<tr>';
- $return .= '<td colspan="2">
- <button class="save" name="submit_button" type="submit" value="'.get_lang('Ok').'" />'.get_lang('Ok').'</button></td>';
- $return .= '</tr>';
- $return .= '</table>';
- if ($action == 'move') {
- $return .= '<input name="title" type="hidden" value="' . $item_title . '" />';
- $return .= '<input name="description" type="hidden" value="' . $item_description . '" />';
- }
- if (is_numeric($extra_info)) {
- $return .= '<input name="path" type="hidden" value="' . $extra_info . '" />';
- }
- elseif (is_array($extra_info)) {
- $return .= '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />';
- }
- $return .= '<input name="type" type="hidden" value="' . TOOL_THREAD . '" />';
- $return .= '<input name="post_time" type="hidden" value="' . time() . '" />';
- $return .= '</form>';
- $return .= '</div>';
- return $return;
- }
-
- public function display_item_form($item_type, $title = '', $action = 'add', $id = 0, $extra_info = 'new') {
- global $_course;
- global $charset;
- $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
- if ($id != 0 && is_array($extra_info)) {
- $item_title = $extra_info['title'];
- $item_description = $extra_info['description'];
- $item_path = api_get_path(WEB_COURSE_PATH) . $_course['path'] . '/scorm/' . $this->path . '/' . stripslashes($extra_info['path']);
- } else {
- $item_title = '';
- $item_description = '';
- }
- $return = ' <div class="row">
- <div class="form_header">';
- if ($id != 0 && is_array($extra_info))
- $parent = $extra_info['parent_item_id'];
- else
- $parent = 0;
- $sql = "
- SELECT *
- FROM " . $tbl_lp_item . "
- WHERE lp_id = " . $this->lp_id . " AND id != " . $id . " ";
- if ($item_type == 'module')
- $sql .= " AND parent_item_id = 0";
- $result = Database::query($sql);
- $arrLP = array ();
- while ($row = Database :: fetch_array($result)) {
- $arrLP[] = array (
- 'id' => $row['id'],
- 'item_type' => $row['item_type'],
- 'title' => $row['title'],
- 'path' => $row['path'],
- 'description' => $row['description'],
- 'parent_item_id' => $row['parent_item_id'],
- 'previous_item_id' => $row['previous_item_id'],
- 'next_item_id' => $row['next_item_id'],
- 'max_score' => $row['max_score'],
- 'min_score' => $row['min_score'],
- 'mastery_score' => $row['mastery_score'],
- 'prerequisite' => $row['prerequisite'],
- 'display_order' => $row['display_order']
- );
- }
- $this->tree_array($arrLP);
- $arrLP = $this->arrMenu;
- unset ($this->arrMenu);
- $return .= $title;
- $return .= ' </div>
- </div>';
- require_once api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php';
- $form = new FormValidator('form', 'POST', api_get_self() . '?' . $_SERVER['QUERY_STRING']);
- $defaults['title'] = api_html_entity_decode($item_title, ENT_QUOTES, $charset);
- $defaults['description'] = $item_description;
- $form->addElement('html', $return);
-
- $arrHide[0]['value'] = Security :: remove_XSS($this->name);
- $arrHide[0]['padding'] = 3;
- $charset = api_get_system_encoding();
- if ($item_type != 'module' && $item_type != 'dokeos_module') {
- for ($i = 0; $i < count($arrLP); $i++) {
- if ($action != 'add') {
- 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)) {
- $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
- $arrHide[$arrLP[$i]['id']]['padding'] = 3 + $arrLP[$i]['depth'] * 10;
- if ($parent == $arrLP[$i]['id']) {
- $s_selected_parent = $arrHide[$arrLP[$i]['id']];
- }
- }
- } else {
- if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir') {
- $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
- $arrHide[$arrLP[$i]['id']]['padding'] = 3 + $arrLP[$i]['depth'] * 10;
- if ($parent == $arrLP[$i]['id']) {
- $s_selected_parent = $arrHide[$arrLP[$i]['id']];
- }
- }
- }
- }
- if ($action != 'move') {
- $form->addElement('text', 'title', get_lang('Title'), 'id="idTitle" class="learnpath_chapter_form" size="40%"');
- $form->applyFilter('title', 'html_filter');
- $form->addRule('title', '<div class="required">' . get_lang('ThisFieldIsRequired'), 'required');
-
- } else {
- $form->addElement('hidden', 'title');
- }
- $parent_select = & $form->addElement('select', 'parent', get_lang('Parent'), '', 'class="learnpath_chapter_form" style="width:37%;" id="idParent" onchange="javascript: load_cbo(this.value);"');
- foreach ($arrHide as $key => $value) {
- $parent_select->addOption($value['value'], $key, 'style="padding-left:' . $value['padding'] . 'px;"');
- }
- $parent_select->setSelected($s_selected_parent);
- }
- if (is_array($arrLP)) {
- reset($arrLP);
- }
- $arrHide = array ();
-
- for ($i = 0; $i < count($arrLP); $i++) {
- if ($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) {
- if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
- $s_selected_position = $arrLP[$i]['id'];
- elseif ($action == 'add') $s_selected_position = $arrLP[$i]['id'];
- $arrHide[$arrLP[$i]['id']]['value'] = get_lang('After') . ' "' . $arrLP[$i]['title'] . '"';
- }
- }
- $position = & $form->addElement('select', 'previous', get_lang('Position'), '', 'id="previous" class="learnpath_chapter_form" style="width:37%;"');
- $position->addOption(get_lang('FirstPosition'), 0, 'style="padding-left:' . $value['padding'] . 'px;"');
- foreach ($arrHide as $key => $value) {
- $position->addOption($value['value'] . '"', $key, 'style="padding-left:' . $value['padding'] . 'px;"');
- }
- if (!empty ($s_selected_position)) {
- $position->setSelected($s_selected_position);
- }
- if (is_array($arrLP)) {
- reset($arrLP);
- }
- $form->addElement('style_submit_button', 'submit_button', get_lang('SaveSection'), 'class="save"');
- if ($item_type == 'module' || $item_type == 'dokeos_module') {
- $form->addElement('hidden', 'parent', '0');
- }
- $extension = pathinfo($item_path, PATHINFO_EXTENSION);
- if (($item_type == 'asset' || $item_type == 'sco') && ($extension == 'html' || $extension == 'htm')) {
- if ($item_type == 'sco') {
- $form->addElement('html', '<script type="text/javascript">alert("' . get_lang('WarningWhenEditingScorm') . '")</script>');
- }
- $renderer = $form->defaultRenderer();
- $renderer->setElementTemplate('<br /> {label}<br />{element}', 'content_lp');
- $form->addElement('html_editor', 'content_lp', '', null, array('ToolbarSet' => 'LearningPathDocuments', 'Width' => '100%', 'Height' => '400', 'FullPage' => true));
- $defaults['content_lp'] = file_get_contents($item_path);
- }
- $form->addElement('hidden', 'type', 'dokeos_' . $item_type);
- $form->addElement('hidden', 'post_time', time());
- $form->setDefaults($defaults);
- return $form->return_form();
- }
-
- public function display_document_form($action = 'add', $id = 0, $extra_info = 'new') {
- global $charset;
- $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
- $tbl_doc = Database :: get_course_table(TABLE_DOCUMENT);
- $path_parts = pathinfo($extra_info['dir']);
- $no_display_edit_textarea = false;
-
-
- if ($action == "edit") {
- if (is_array($extra_info)) {
- if ($path_parts['extension'] != "txt" && $path_parts['extension'] != "html") {
- $no_display_edit_textarea = true;
- }
- }
- }
- $no_display_add = false;
-
-
- if ($action == "add") {
- if (is_numeric($extra_info)) {
- $sql_doc = "SELECT path FROM " . $tbl_doc . "WHERE id = " . Database :: escape_string($extra_info);
- $result = Database::query($sql_doc);
- $path_file = Database :: result($result, 0, 0);
- $path_parts = pathinfo($path_file);
- if ($path_parts['extension'] != "txt" && $path_parts['extension'] != "html") {
- $no_display_add = true;
- }
- }
- }
- if ($id != 0 && is_array($extra_info)) {
- $item_title = stripslashes($extra_info['title']);
- $item_description = stripslashes($extra_info['description']);
- $item_terms = stripslashes($extra_info['terms']);
- if (empty ($item_title)) {
- $path_parts = pathinfo($extra_info['path']);
- $item_title = stripslashes($path_parts['filename']);
- }
- } elseif (is_numeric($extra_info)) {
- $sql_doc = "SELECT path, title FROM " . $tbl_doc . "
- WHERE id = " . Database :: escape_string($extra_info);
- $result = Database::query($sql_doc);
- $row = Database :: fetch_array($result);
- $explode = explode('.', $row['title']);
- if (count($explode) > 1) {
- for ($i = 0; $i < count($explode) - 1; $i++)
- $item_title .= $explode[$i];
- } else {
- $item_title = $row['title'];
- }
- $item_title = str_replace('_', ' ', $item_title);
- if (empty ($item_title)) {
- $path_parts = pathinfo($row['path']);
- $item_title = stripslashes($path_parts['filename']);
- }
- } else {
- $item_title = '';
- $item_description = '';
- }
- $return = ' <div class="row">
- <div class="form_header">';
- if ($id != 0 && is_array($extra_info))
- $parent = $extra_info['parent_item_id'];
- else
- $parent = 0;
-
- $sql = "SELECT * FROM " . $tbl_lp_item . "
- WHERE lp_id = " . $this->lp_id;
- $result = Database::query($sql);
- $arrLP = array ();
- while ($row = Database :: fetch_array($result)) {
- $arrLP[] = array (
- 'id' => $row['id'],
- 'item_type' => $row['item_type'],
- 'title' => $row['title'],
- 'path' => $row['path'],
- 'description' => $row['description'],
- 'parent_item_id' => $row['parent_item_id'],
- 'previous_item_id' => $row['previous_item_id'],
- 'next_item_id' => $row['next_item_id'],
- 'display_order' => $row['display_order'],
- 'max_score' => $row['max_score'],
- 'min_score' => $row['min_score'],
- 'mastery_score' => $row['mastery_score'],
- 'prerequisite' => $row['prerequisite']
- );
- }
- $this->tree_array($arrLP);
- $arrLP = $this->arrMenu;
- unset ($this->arrMenu);
- if ($action == 'add') {
- $return .= get_lang('CreateTheDocument');
- }
- elseif ($action == 'move') {
- $return .= get_lang('MoveTheCurrentDocument');
- } else {
- $return .= get_lang('EditTheCurrentDocument');
- }
- $return .= '</div>
- </div>';
- if (isset ($_GET['edit']) && $_GET['edit'] == 'true') {
- $return .= Display :: return_warning_message('<strong>' . get_lang('Warning') . ' !</strong><br />' . get_lang('WarningEditingDocument'), false);
- }
- require_once api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php';
- $form = new FormValidator('form', 'POST', api_get_self() . '?' . $_SERVER['QUERY_STRING'], '', 'enctype="multipart/form-data"');
- $defaults['title'] = Security :: remove_XSS($item_title);
- if (empty($item_title)) {
- $defaults['title'] = Security::remove_XSS($item_title);
- }
- $defaults['description'] = $item_description;
- $form->addElement('html', $return);
- if ($action != 'move') {
- $form->addElement('text', 'title', get_lang('Title'), 'id="idTitle" class="learnpath_item_form" size=44%');
- $form->applyFilter('title', 'html_filter');
- }
-
- $arrHide[0]['value'] = $this->name;
- $arrHide[0]['padding'] = 3;
- for ($i = 0; $i < count($arrLP); $i++) {
- if ($action != 'add') {
- 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)) {
- $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
- $arrHide[$arrLP[$i]['id']]['padding'] = 3 + $arrLP[$i]['depth'] * 10;
- if ($parent == $arrLP[$i]['id']) {
- $s_selected_parent = $arrHide[$arrLP[$i]['id']];
- }
- }
- } else {
- if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir') {
- $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
- $arrHide[$arrLP[$i]['id']]['padding'] = 3 + $arrLP[$i]['depth'] * 10;
- if ($parent == $arrLP[$i]['id']) {
- $s_selected_parent = $arrHide[$arrLP[$i]['id']];
- }
- }
- }
- }
- $parent_select = & $form->addElement('select', 'parent', get_lang('Parent'), '', 'class="learnpath_item_form" id="idParent" style="width:40%;" onchange="javascript: load_cbo(this.value);"');
- $my_count=0;
- foreach ($arrHide as $key => $value) {
- if ($my_count!=0) {
-
- $value['value'] = Security :: remove_XSS($value['value']);
- $parent_select->addOption($value['value'], $key, 'style="padding-left:' . $value['padding'] . 'px;"');
- } else {
- $value['value'] = Security :: remove_XSS($value['value']);
- $parent_select->addOption($value['value'], $key, 'style="padding-left:' . $value['padding'] . 'px;"');
- }
- $my_count++;
- }
- if (!empty($id)) {
- $parent_select->setSelected($parent);
- } else {
- $parent_item_id = $_SESSION['parent_item_id'];
- $parent_select->setSelected($parent_item_id);
- }
- if (is_array($arrLP)) {
- reset($arrLP);
- }
- $arrHide = array ();
-
- for ($i = 0; $i < count($arrLP); $i++) {
- if ($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) {
- if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
- $s_selected_position = $arrLP[$i]['id'];
- elseif ($action == 'add') $s_selected_position = $arrLP[$i]['id'];
- $arrHide[$arrLP[$i]['id']]['value'] = get_lang('After') . ' "' . $arrLP[$i]['title'] . '"';
- }
- }
- $position = & $form->addElement('select', 'previous', get_lang('Position'), '', 'id="previous" class="learnpath_item_form" style="width:40%;"');
- $position->addOption(get_lang('FirstPosition'), 0);
- foreach ($arrHide as $key => $value) {
- $position->addOption($value['value'], $key, 'style="padding-left:' . $value['padding'] . 'px;"');
- }
- $position->setSelected($s_selected_position);
- if (is_array($arrLP)) {
- reset($arrLP);
- }
- if ($action != 'move') {
- $id_prerequisite = 0;
- if (is_array($arrLP)) {
- foreach ($arrLP as $key => $value) {
- if ($value['id'] == $id) {
- $id_prerequisite = $value['prerequisite'];
- break;
- }
- }
- }
-
-
-
-
-
-
-
- $arrHide = array ();
- for ($i = 0; $i < count($arrLP); $i++) {
- if ($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter') {
- if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
- $s_selected_position = $arrLP[$i]['id'];
- elseif ($action == 'add') $s_selected_position = $arrLP[$i]['id'];
- $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
- }
- }
-
- if (!$no_display_add) {
- if (($extra_info == 'new' || $extra_info['item_type'] == TOOL_DOCUMENT || $_GET['edit'] == 'true')) {
- if (isset ($_POST['content']))
- $content = stripslashes($_POST['content']);
- elseif (is_array($extra_info)) {
-
- if (!$no_display_edit_textarea) {
- $content = $this->display_document($extra_info['path'], false, false);
- }
- }
- elseif (is_numeric($extra_info)) $content = $this->display_document($extra_info, false, false);
- else
- $content = '';
- if (!$no_display_edit_textarea) {
-
-
-
-
-
- $relative_path = $extra_info['dir'];
- if ($relative_path == 'n/') {
-
- $relative_path = '';
- $relative_prefix = '';
- } else {
-
- $relative_path = explode('/', $relative_path);
- $cnt = count($relative_path) - 2;
- if ($cnt < 0) {
- $cnt = 0;
- }
- $relative_prefix = str_repeat('../', $cnt);
- $relative_path = array_slice($relative_path, 1, $cnt);
- $relative_path = implode('/', $relative_path);
- if (strlen($relative_path) > 0) {
- $relative_path = $relative_path . '/';
- }
- }
- $editor_config = array('ToolbarSet' => 'LearningPathDocuments', 'Width' => '100%', 'Height' => '700', 'FullPage' => true,
- 'CreateDocumentDir' => $relative_prefix,
- 'CreateDocumentWebDir' => api_get_path(WEB_COURSE_PATH) . api_get_course_path() . '/document/',
- 'BaseHref' => api_get_path(WEB_COURSE_PATH) . api_get_course_path() . '/document/' . $relative_path
- );
- if ($_GET['action'] == 'add_item') {
- $class = 'add';
- $text = get_lang('LPCreateDocument');
- } else
- if ($_GET['action'] == 'edit_item') {
- $class = 'save';
- $text = get_lang('SaveDocument');
- }
- $form->addElement('style_submit_button', 'submit_button', $text, 'class="' . $class . '"');
- $renderer = $form->defaultRenderer();
- $renderer->setElementTemplate('<br /> {label}<br />{element}', 'content_lp');
- $form->addElement('html', '<div style="margin:3px 12px">');
- $form->addElement('html_editor', 'content_lp', '', null, $editor_config);
- $form->addElement('html', '</div>');
- $defaults['content_lp'] = $content;
- }
- }
- elseif (is_numeric($extra_info)) {
- $form->addElement('style_submit_button', 'submit_button', get_lang('SaveDocument'), 'class="save"');
- $return = $this->display_document($extra_info, true, true, true);
- $form->addElement('html', $return);
- }
- }
- }
- if ($action == 'move') {
- $form->addElement('hidden', 'title', $item_title);
- $form->addElement('hidden', 'description', $item_description);
- }
- if (is_numeric($extra_info)) {
- $form->addElement('style_submit_button', 'submit_button', get_lang('SaveDocument'), 'value="submit_button", class="save"');
- $form->addElement('hidden', 'path', $extra_info);
- }
- elseif (is_array($extra_info)) {
- $form->addElement('style_submit_button', 'submit_button', get_lang('SaveDocument'), 'class="save"');
- $form->addElement('hidden', 'path', $extra_info['path']);
- }
- $form->addElement('hidden', 'type', TOOL_DOCUMENT);
- $form->addElement('hidden', 'post_time', time());
- $form->setDefaults($defaults);
- return $form->return_form();
- }
-
- public function display_link_form($action = 'add', $id = 0, $extra_info = '') {
- global $charset;
- $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
- $tbl_link = Database :: get_course_table(TABLE_LINK);
- if ($id != 0 && is_array($extra_info)) {
- $item_title = stripslashes($extra_info['title']);
- $item_description = stripslashes($extra_info['description']);
- $item_url = stripslashes($extra_info['url']);
- } elseif (is_numeric($extra_info)) {
- $sql_link = "SELECT title, description, url FROM " . $tbl_link . " WHERE id = " . $extra_info;
- $result = Database::query($sql_link);
- $row = Database :: fetch_array($result);
- $item_title = $row['title'];
- $item_description = $row['description'];
- $item_url = $row['url'];
- } else {
- $item_title = '';
- $item_description = '';
- $item_url = '';
- }
- $return = ' <div class="row">
- <div class="form_header">';
- if ($id != 0 && is_array($extra_info))
- $parent = $extra_info['parent_item_id'];
- else
- $parent = 0;
- $sql = "SELECT * FROM " . $tbl_lp_item . " WHERE lp_id = " . $this->lp_id;
- $result = Database::query($sql);
- $arrLP = array ();
- while ($row = Database :: fetch_array($result)) {
- $arrLP[] = array (
- 'id' => $row['id'],
- 'item_type' => $row['item_type'],
- 'title' => $row['title'],
- 'path' => $row['path'],
- 'description' => $row['description'],
- 'parent_item_id' => $row['parent_item_id'],
- 'previous_item_id' => $row['previous_item_id'],
- 'next_item_id' => $row['next_item_id'],
- 'display_order' => $row['display_order'],
- 'max_score' => $row['max_score'],
- 'min_score' => $row['min_score'],
- 'mastery_score' => $row['mastery_score'],
- 'prerequisite' => $row['prerequisite']
- );
- }
- $this->tree_array($arrLP);
- $arrLP = $this->arrMenu;
- unset ($this->arrMenu);
- if ($action == 'add')
- $return .= get_lang('CreateTheLink') . ' :';
- elseif ($action == 'move') $return .= get_lang('MoveCurrentLink') . ' :';
- else
- $return .= get_lang('EditCurrentLink') . ' :';
- $return .= ' </div>
- </div>';
- $return .= '<div class="sectioncomment">';
- $return .= '<form method="POST">';
- $return .= '<table>';
- if ($action != 'move') {
- $return .= '<tr>';
- $return .= '<td class="label"><label for="idTitle">' . get_lang('Title') . '</label></td>';
- $return .= '<td class="input"><input id="idTitle" name="title" size="44" type="text" value="' . $item_title . '" class="learnpath_item_form"/></td>';
- $return .= '</tr>';
- }
- $return .= '<tr>';
- $return .= '<td class="label"><label for="idParent">' . get_lang('Parent') . '</label></td>';
- $return .= '<td class="input">';
- $return .= '<select id="idParent" style="width:100%;" name="parent" onChange="javascript: load_cbo(this.value);" class="learnpath_item_form" size="1">';
- $return .= '<option class="top" value="0">' . $this->name . '</option>';
- $arrHide = array (
- $id
- );
- $parent_item_id = $_SESSION['parent_item_id'];
- for ($i = 0; $i < count($arrLP); $i++) {
- if ($action != 'add') {
- 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)) {
- $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>';
- } else {
- $arrHide[] = $arrLP[$i]['id'];
- }
- } else {
- if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
- $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>';
- }
- }
- if (is_array($arrLP)) {
- reset($arrLP);
- }
- $return .= "\t\t\t\t" . '</select>';
- $return .= '</td>';
- $return .= '</tr>';
- $return .= '<tr>';
- $return .= '<td class="label"><label for="previous">' . get_lang('Position') . '</label></td>';
- $return .= '<td class="input">';
-
- $return .= "\t\t\t\t" . '<select id="previous" name="previous" style="width:100%;" size="1" class="learnpath_item_form">';
- $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . get_lang('FirstPosition') . '</option>';
- for ($i = 0; $i < count($arrLP); $i++) {
- if ($arrLP[$i]['parent_item_id'] == $parent_item_id && $arrLP[$i]['id'] != $id) {
- if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
- $selected = 'selected="selected" ';
- elseif ($action == 'add')
- $selected = 'selected="selected" ';
- else
- $selected = '';
- $return .= '<option ' . $selected . 'value="' . $arrLP[$i]['id'] . '">' . get_lang('After') . ' "' . $arrLP[$i]['title'] . '"</option>';
- }
- }
- $return .= '</select>';
- $return .= '</td>';
- $return .= '</tr>';
- if ($action != 'move') {
- $return .= '<tr>';
- $return .= '<td class="label"><label for="idURL">' . get_lang('Url') . '</label></td>';
- $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>';
- $return .= '</tr>';
- $id_prerequisite = 0;
- if (is_array($arrLP)) {
- foreach ($arrLP as $key => $value) {
- if ($value['id'] == $id) {
- $id_prerequisite = $value['prerequisite'];
- break;
- }
- }
- }
- $arrHide = array ();
- for ($i = 0; $i < count($arrLP); $i++) {
- if ($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter') {
- if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
- $s_selected_position = $arrLP[$i]['id'];
- elseif ($action == 'add') $s_selected_position = 0;
- $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
- }
- }
-
- $return .= '</tr>';
- }
- $return .= '<tr>';
- if ($action == 'add') {
- $return .= '<td> </td><td><button class="save" name="submit_button" type="submit">' . get_lang('AddLinkToCourse') . '</button></td>';
- } else {
- $return .= '<td> </td><td><button class="save" name="submit_button" type="submit">' . get_lang('EditCurrentLink') . '</button></td>';
- }
- $return .= '</tr>';
- $return .= '</table>';
- if ($action == 'move') {
- $return .= '<input name="title" type="hidden" value="' . $item_title . '" />';
- $return .= '<input name="description" type="hidden" value="' . $item_description . '" />';
- }
- if (is_numeric($extra_info)) {
- $return .= '<input name="path" type="hidden" value="' . $extra_info . '" />';
- }
- elseif (is_array($extra_info)) {
- $return .= '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />';
- }
- $return .= '<input name="type" type="hidden" value="' . TOOL_LINK . '" />';
- $return .= '<input name="post_time" type="hidden" value="' . time() . '" />';
- $return .= '</form>';
- $return .= '</div>';
- return $return;
- }
-
- public function display_student_publication_form($action = 'add', $id = 0, $extra_info = '') {
- global $charset;
- $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
- $tbl_publication = Database :: get_course_table(TABLE_STUDENT_PUBLICATION);
- if ($id != 0 && is_array($extra_info)) {
- $item_title = stripslashes($extra_info['title']);
- $item_description = stripslashes($extra_info['description']);
- }
- elseif (is_numeric($extra_info)) {
- $sql_publication = "
- SELECT
- title,
- description
- FROM " . $tbl_publication . "
- WHERE id = " . $extra_info;
- $result = Database::query($sql_publication);
- $row = Database :: fetch_array($result);
- $item_title = $row['title'];
- } else {
- $item_title = get_lang('Student_publication');
- }
- $return = ' <div class="row">
- <div class="form_header">';
- if ($id != 0 && is_array($extra_info))
- $parent = $extra_info['parent_item_id'];
- else
- $parent = 0;
- $sql = "
- SELECT *
- FROM " . $tbl_lp_item . "
- WHERE
- lp_id = " . $this->lp_id;
- $result = Database::query($sql);
- $arrLP = array ();
- while ($row = Database :: fetch_array($result)) {
- $arrLP[] = array (
- 'id' => $row['id'],
- 'item_type' => $row['item_type'],
- 'title' => $row['title'],
- 'path' => $row['path'],
- 'description' => $row['description'],
- 'parent_item_id' => $row['parent_item_id'],
- 'previous_item_id' => $row['previous_item_id'],
- 'next_item_id' => $row['next_item_id'],
- 'display_order' => $row['display_order'],
- 'max_score' => $row['max_score'],
- 'min_score' => $row['min_score'],
- 'mastery_score' => $row['mastery_score'],
- 'prerequisite' => $row['prerequisite']
- );
- }
- $this->tree_array($arrLP);
- $arrLP = $this->arrMenu;
- unset ($this->arrMenu);
- if ($action == 'add')
- $return .= get_lang('Student_publication') . ' :' . "\n";
- elseif ($action == 'move') $return .= get_lang('MoveCurrentStudentPublication') . ' :' . "\n";
- else
- $return .= get_lang('EditCurrentStudentPublication') . ' :' . "\n";
- $return .= ' </div>
- </div>';
- $return .= '<div class="sectioncomment">';
- $return .= '<form method="POST">';
- $return .= '<table class="lp_form">';
- if ($action != 'move') {
- $return .= '<tr>';
- $return .= '<td class="label"><label for="idTitle">' . get_lang('Title') . '</label></td>';
- $return .= '<td class="input"><input id="idTitle" name="title" size="44" type="text" value="' . $item_title . '" class="learnpath_item_form" /></td>';
- $return .= '</tr>';
- }
- $return .= '<tr>';
- $return .= '<td class="label"><label for="idParent">' . get_lang('Parent') . '</label></td>';
- $return .= '<td class="input">';
- $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">';
-
- $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
- $arrHide = array (
- $id
- );
- for ($i = 0; $i < count($arrLP); $i++) {
- if ($action != 'add') {
- 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)) {
- $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>';
- } else {
- $arrHide[] = $arrLP[$i]['id'];
- }
- } else {
- if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
- $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>';
- }
- }
- if (is_array($arrLP)) {
- reset($arrLP);
- }
- $return .= "\t\t\t\t" . '</select>';
- $return .= '</td>';
- $return .= '</tr>';
- $return .= '<tr>';
- $return .= '<td class="label"><label for="previous">' . get_lang('Position') . '</label></td>';
- $return .= '<td class="input">';
- $return .= "\t\t\t\t" . '<select id="previous" name="previous" style="width:100%;" size="1" class="learnpath_item_form">';
- $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . get_lang('FirstPosition') . '</option>';
- for ($i = 0; $i < count($arrLP); $i++) {
- if ($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) {
- if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
- $selected = 'selected="selected" ';
- elseif ($action == 'add') $selected = 'selected="selected" ';
- else
- $selected = '';
- $return .= "\t\t\t\t\t" . '<option ' . $selected . 'value="' . $arrLP[$i]['id'] . '">' . get_lang('After') . ' "' . $arrLP[$i]['title'] . '"</option>';
- }
- }
- $return .= "\t\t\t\t" . '</select>';
- $return .= '</td>';
- $return .= '</tr>';
- if ($action != 'move') {
- $id_prerequisite = 0;
- if (is_array($arrLP)) {
- foreach ($arrLP as $key => $value) {
- if ($value['id'] == $id) {
- $id_prerequisite = $value['prerequisite'];
- break;
- }
- }
- }
- $arrHide = array ();
- for ($i = 0; $i < count($arrLP); $i++) {
- if ($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter') {
- if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
- $s_selected_position = $arrLP[$i]['id'];
- elseif ($action == 'add') $s_selected_position = 0;
- $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
- }
- }
-
-
- $return .= '</tr>';
- }
- $return .= '<tr>';
- if ($action == 'add') {
- $return .= '<td> </td><td><button class="save" name="submit_button" type="submit">' . get_lang('AddAssignmentToCourse') . '</button></td>';
- } else {
- $return .= '<td> </td><td><button class="save" name="submit_button" type="submit">' . get_lang('EditCurrentStudentPublication') . '</button></td>';
- }
- $return .= '</tr>';
- $return .= '</table>';
- if ($action == 'move') {
- $return .= '<input name="title" type="hidden" value="' . $item_title . '" />';
- $return .= '<input name="description" type="hidden" value="' . $item_description . '" />';
- }
- if (is_numeric($extra_info)) {
- $return .= '<input name="path" type="hidden" value="' . $extra_info . '" />';
- } elseif (is_array($extra_info)) {
- $return .= '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />';
- }
- $return .= '<input name="type" type="hidden" value="' . TOOL_STUDENTPUBLICATION . '" />';
- $return .= '<input name="post_time" type="hidden" value="' . time() . '" />';
- $return .= '</form>';
- $return .= '</div>';
- return $return;
- }
-
- public function display_manipulate($item_id, $item_type = TOOL_DOCUMENT) {
- global $charset, $_course;
- $return = '<div class="actions">';
- switch ($item_type) {
- case 'dokeos_chapter' :
- case 'chapter' :
-
-
- break;
- case 'dokeos_module' :
- case 'module' :
-
-
- break;
- case TOOL_DOCUMENT :
-
-
- break;
- case TOOL_LINK :
- case 'link' :
-
-
- break;
- case TOOL_QUIZ :
-
-
- break;
- case TOOL_STUDENTPUBLICATION :
-
-
- break;
- }
- $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
- $item_id = intval($item_id);
- $sql = "SELECT * FROM " . $tbl_lp_item . " as lp WHERE lp.id = " . $item_id;
- $result = Database::query($sql);
- $row = Database::fetch_assoc($result);
- $s_title = $row['title'];
-
- if (!empty ($row['audio'])) {
- $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>';
- $return .= '<script type="text/javascript" src="../inc/lib/mediaplayer/swfobject.js"></script>';
- $return .= '<script type="text/javascript">
- var s1 = new SWFObject("../inc/lib/mediaplayer/player.swf","ply","250","20","9","#FFFFFF");
- s1.addParam("allowscriptaccess","always");
- s1.addParam("flashvars","file=../../courses/' . $_course['path'] . '/document/audio/' . $row['audio'] . '&autostart=true");
- s1.write("container");
- </script>';
- }
-
-
- $url = api_get_self() . '?cidReq='.Security::remove_XSS($_GET['cidReq']).'&view=build&id='.$item_id .'&lp_id='.$this->lp_id;
-
- $return .= Display::url(Display::return_icon('edit.png', get_lang('Edit'), array(), 22), $url.'&action=edit_item&path_item=' . $row['path']);
- $return .= Display::url(Display::return_icon('move.png', get_lang('Move'), array(), 22), $url.'&action=move_item');
-
-
- if ($item_type != 'dokeos_chapter' && $item_type != 'chapter') {
- $return .= Display::url(Display::return_icon('accept.png', get_lang('Prerequisites'), array(), 22), $url.'&action=edit_item_prereq');
- }
- $return .= Display::url(Display::return_icon('delete.png', get_lang('Delete'), array(), 22), $url.'&action=delete_item');
-
- ob_start();
- $audio_recorder_studentview = 'false';
- $audio_recorder_item_id = $item_id;
- if (api_get_setting('service_visio', 'active') == 'true') {
- include 'audiorecorder.inc.php';
- }
- $return .= ob_get_contents();
- ob_end_clean();
-
- $return .= '</div>';
- return $return;
- }
-
- public function get_js_dropdown_array() {
- $return = 'var child_name = new Array();' . "\n";
- $return .= 'var child_value = new Array();' . "\n\n";
- $return .= 'child_name[0] = new Array();' . "\n";
- $return .= 'child_value[0] = new Array();' . "\n\n";
- $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
- $sql_zero = "
- SELECT *
- FROM " . $tbl_lp_item . "
- WHERE
- lp_id = " . $this->lp_id . " AND
- parent_item_id = 0
- ORDER BY display_order ASC";
- $res_zero = Database::query($sql_zero);
- global $charset;
- $i = 0;
- while ($row_zero = Database :: fetch_array($res_zero)) {
- $return .= 'child_name[0][' . $i . '] = "' . get_lang('After') . ' \"' . $row_zero['title'] . '\"";' . "\n";
- $return .= 'child_value[0][' . $i++ . '] = "' . $row_zero['id'] . '";' . "\n";
- }
- $return .= "\n";
- $sql = "
- SELECT *
- FROM " . $tbl_lp_item . "
- WHERE
- lp_id = " . $this->lp_id;
- $res = Database::query($sql);
- while ($row = Database :: fetch_array($res)) {
- $sql_parent = "
- SELECT *
- FROM " . $tbl_lp_item . "
- WHERE parent_item_id = " . $row['id'] . "
- ORDER BY display_order ASC";
- $res_parent = Database::query($sql_parent);
- $i = 0;
- $return .= 'child_name[' . $row['id'] . '] = new Array();' . "\n";
- $return .= 'child_value[' . $row['id'] . '] = new Array();' . "\n\n";
- while ($row_parent = Database :: fetch_array($res_parent)) {
- $return .= 'child_name[' . $row['id'] . '][' . $i . '] = "' . get_lang('After') . ' \"' . api_html_entity_decode($row_parent['title'], ENT_QUOTES) . '\"";' . "\n";
- $return .= 'child_value[' . $row['id'] . '][' . $i++ . '] = "' . $row_parent['id'] . '";' . "\n";
- }
- $return .= "\n";
- }
- return $return;
- }
-
- public function display_move_item($item_id) {
- global $_course;
- global $charset;
- $return = '';
- if (is_numeric($item_id)) {
- $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
- $sql = "SELECT *
- FROM " . $tbl_lp_item . "
- WHERE id = " . $item_id;
- $res = Database::query($sql);
- $row = Database :: fetch_array($res);
- switch ($row['item_type']) {
- case 'dokeos_chapter' :
- case 'dir' :
- case 'asset' :
- $return .= $this->display_manipulate($item_id, $row['item_type']);
- $return .= $this->display_item_form($row['item_type'], get_lang('MoveCurrentChapter'), 'move', $item_id, $row);
- break;
- case 'dokeos_module' :
- $return .= $this->display_manipulate($item_id, $row['item_type']);
- $return .= $this->display_item_form($row['item_type'], 'Move th current module:', 'move', $item_id, $row);
- break;
- case TOOL_DOCUMENT :
- $return .= $this->display_manipulate($item_id, $row['item_type']);
- $return .= $this->display_document_form('move', $item_id, $row);
- break;
- case TOOL_LINK :
- $return .= $this->display_manipulate($item_id, $row['item_type']);
- $return .= $this->display_link_form('move', $item_id, $row);
- break;
- case TOOL_HOTPOTATOES :
- $return .= $this->display_manipulate($item_id, $row['item_type']);
- $return .= $this->display_link_form('move', $item_id, $row);
- break;
- case TOOL_QUIZ :
- $return .= $this->display_manipulate($item_id, $row['item_type']);
- $return .= $this->display_quiz_form('move', $item_id, $row);
- break;
- case TOOL_STUDENTPUBLICATION :
- $return .= $this->display_manipulate($item_id, $row['item_type']);
- $return .= $this->display_student_publication_form('move', $item_id, $row);
- break;
- case TOOL_FORUM :
- $return .= $this->display_manipulate($item_id, $row['item_type']);
- $return .= $this->display_forum_form('move', $item_id, $row);
- break;
- case TOOL_THREAD :
- $return .= $this->display_manipulate($item_id, $row['item_type']);
- $return .= $this->display_forum_form('move', $item_id, $row);
- break;
- }
- }
- return $return;
- }
-
- public function display_item_small_form($item_type, $title = '', $data) {
- global $charset;
- $return .= '<div class="lp_small_form">';
- $return .= '<p class="lp_title">' . $title . '</p>';
- $return .= '<form method="post">';
- $return .= '<table cellpadding="0" cellspacing="0" class="lp_form">';
- $return .= '<tr>';
- $return .= '<td class="label"><label for="idTitle">Title :</label></td>';
- $return .= '<td class="input"><input class="small_form" id="idTitle" name="title" type="text" value="' . api_html_entity_decode($data['title'], ENT_QUOTES) . '" /></td>';
- $return .= '</tr>';
-
-
-
-
-
- $return .= '<tr>';
- $return .= '<td colspan="2"><button class="save" name="submit_button" type="submit">' . get_lang('Save') . '</button></td>';
- $return .= '</tr>';
- $return .= '</table>';
- $return .= '<input name="parent" type="hidden" value="' . $data['parent_item_id'] . '"/>';
- $return .= '<input name="previous" type="hidden" value="' . $data['previous_item_id'] . '"/>';
- $return .= '</form>';
- $return .= '</div>';
- return $return;
- }
-
- public function display_item_prerequisites_form($item_id) {
- global $charset;
- $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
- $item_id = intval($item_id);
-
- $sql = "SELECT * FROM $tbl_lp_item WHERE id = " . $item_id;
- $result = Database::query($sql);
- $row = Database::fetch_array($result);
- $preq_id = $row['prerequisite'];
-
-
- $return = $this->display_manipulate($item_id, TOOL_DOCUMENT);
- $return = ' <div class="row">
- <div class="form_header">';
- $return .= get_lang('AddEditPrerequisites');
- $return .= '</div></div>';
- $return .= '<div class="sectioncomment">';
- $return .= '<form method="POST">';
- $return .= '<table class="data_table" style="width:650px">';
- $return .= '<tr>';
- $return .= '<th height="24">' . get_lang('Prerequisites') . '</th>';
- $return .= '<th width="70" height="24">' . get_lang('Minimum') . '</th>';
- $return .= '<th width="70" height="24">' . get_lang('Maximum') . '</th>';
- $return .= '</tr>';
-
- $return .= '<tr >';
- $return .= '<td colspan="3" class="radio">';
- $return .= '<input checked="checked" id="idNone" name="prerequisites" style="margin-left:0px; margin-right:10px;" type="radio" />';
- $return .= '<label for="idNone">' . get_lang('None') . '</label>';
- $return .= '</tr>';
- $sql = "SELECT * FROM " . $tbl_lp_item . " WHERE lp_id = " . $this->lp_id;
- $result = Database::query($sql);
- $arrLP = array ();
- while ($row = Database :: fetch_array($result)) {
- $arrLP[] = array (
- 'id' => $row['id'],
- 'item_type' => $row['item_type'],
- 'title' => $row['title'],
- 'ref' => $row['ref'],
- 'description' => $row['description'],
- 'parent_item_id' => $row['parent_item_id'],
- 'previous_item_id' => $row['previous_item_id'],
- 'next_item_id' => $row['next_item_id'],
- 'max_score' => $row['max_score'],
- 'min_score' => $row['min_score'],
- 'mastery_score' => $row['mastery_score'],
- 'prerequisite' => $row['prerequisite'],
- 'next_item_id' => $row['next_item_id'],
- 'display_order' => $row['display_order']
- );
- if ($row['ref'] == $preq_id) {
- $preq_mastery = $row['mastery_score'];
- $preq_max = $row['max_score'];
- }
- }
- $this->tree_array($arrLP);
- $arrLP = $this->arrMenu;
- unset ($this->arrMenu);
- for ($i = 0; $i < count($arrLP); $i++) {
- if ($arrLP[$i]['id'] == $item_id)
- break;
- $return .= '<tr>';
- $return .= '<td class="radio"' . (($arrLP[$i]['item_type'] != TOOL_QUIZ && $arrLP[$i]['item_type'] != TOOL_HOTPOTATOES) ? ' colspan="3"' : '') . '>';
- $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'] . '" />';
- $icon_name = str_replace(' ', '', $arrLP[$i]['item_type']);
- if (file_exists('../img/lp_' . $icon_name . '.png')) {
- $return .= '<img alt="" src="../img/lp_' . $icon_name . '.png" style="margin-right:5px;" title="" />';
- } else
- if (file_exists('../img/lp_' . $icon_name . '.gif')) {
- $return .= '<img alt="" src="../img/lp_' . $icon_name . '.gif" style="margin-right:5px;" title="" />';
- } else {
- $return .= Display::return_icon('folder_document.gif','',array('style'=>'margin-right:5px;'));
- }
- $return .= '<label for="id' . $arrLP[$i]['id'] . '">' . $arrLP[$i]['title'] . '</label>';
- $return .= '</td>';
-
- if ($arrLP[$i]['item_type'] == TOOL_QUIZ) {
- $return .= '<td class="exercise" style="border:1px solid #ccc;">';
- $return .= '<center><input size="4" maxlength="3" name="min_' . $arrLP[$i]['id'] . '" type="text" value="' . (($arrLP[$i]['id'] == $preq_id) ? $preq_mastery : 0) . '" /></center>';
- $return .= '</td>';
- $return .= '<td class="exercise" style="border:1px solid #ccc;">';
- $return .= '<center><input size="4" maxlength="3" name="max_' . $arrLP[$i]['id'] . '" type="text" value="' . $arrLP[$i]['max_score'] . '" disabled="true" /></center>';
- $return .= '</td>';
- }
- if ($arrLP[$i]['item_type'] == TOOL_HOTPOTATOES) {
- $return .= '<td class="exercise" style="border:1px solid #ccc;">';
- $return .= '<center><input size="4" maxlength="3" name="min_' . $arrLP[$i]['id'] . '" type="text" value="' . (($arrLP[$i]['id'] == $preq_id) ? $preq_mastery : 0) . '" /></center>';
- $return .= '</td>';
- $return .= '<td class="exercise" style="border:1px solid #ccc;">';
- $return .= '<center><input size="4" maxlength="3" name="max_' . $arrLP[$i]['id'] . '" type="text" value="' . $arrLP[$i]['max_score'] . '" disabled="true" /></center>';
- $return .= '</td>';
- }
- $return .= '</tr>';
- }
- $return .= '<tr>';
- $return .= '</tr>';
- $return .= '</table>';
- $return .= '<div style="padding-top:3px;">';
- $return .= '<button class="save" name="submit_button" type="submit">' . get_lang('ModifyPrerequisites') . ' </button></td>';
- $return .= '</div>';
- $return .= '</form>';
- $return .= '</div>';
- return $return;
- }
-
- public function display_lp_prerequisites_list() {
- global $charset;
- $lp_id = $this->lp_id;
- $tbl_lp = Database :: get_course_table(TABLE_LP_MAIN);
-
- $sql = "SELECT * FROM $tbl_lp WHERE id = $lp_id ";
- $result = Database::query($sql);
- $row = Database :: fetch_array($result);
- $preq_id = $row['prerequisite'];
- $session_id = api_get_session_id();
- $session_condition = api_get_session_condition($session_id, false);
- $sql = "SELECT * FROM $tbl_lp $session_condition ORDER BY display_order ";
- $rs = Database::query($sql);
- $return = '';
- $return .= '<select name="prerequisites" >';
- $return .= '<option value="0">'.get_lang('None').'</option>';
- if (Database::num_rows($rs) > 0) {
- while ($row = Database::fetch_array($rs)) {
- if ($row['id'] == $lp_id) {
- continue;
- }
- $return .= '<option value="'.$row['id'].'" '.(($row['id']==$preq_id)?' selected ' : '').'>'.$row['name'].'</option>';
- }
- }
- $return .= '</select>';
- return $return;
- }
-
- public function get_documents() {
- global $_course;
- $tbl_doc = Database :: get_course_table(TABLE_DOCUMENT);
- $tbl_item_prop = Database::get_course_table(TABLE_ITEM_PROPERTY);
- $tbl_course = Database::get_main_table(TABLE_MAIN_COURSE);
- $path = '/';
- $path = Database::escape_string(str_replace('_', '\_', $path));
- $added_slash = ($path == '/') ? '' : '/';
-
- $current_session_id = api_get_session_id();
- $condition_session = " AND (id_session = '$current_session_id' OR (id_session = '0' AND insert_date <= (SELECT creation_date FROM $tbl_course WHERE code = '{$_course[id]}')))";
- $sql_doc = "SELECT docs.*
- FROM $tbl_item_prop AS last, $tbl_doc AS docs
- WHERE docs.id = last.ref
- AND docs.path LIKE '".$path.$added_slash."%'
- AND docs.path NOT LIKE '%_DELETED_%'
- AND last.tool = '".TOOL_DOCUMENT."' $condition_session ORDER BY docs.path ASC";
- $res_doc = Database::query($sql_doc);
-
- $return = '<div class="lp_resource">';
- $resources = Database::store_result($res_doc);
- $resources_sorted = array();
-
- $return .= '<div class="lp_resource_element">';
- $return .= Display::return_icon('new_doc.gif', '', array(), 22);
- $return .= Display::url(get_lang('NewDocument') , api_get_self().'?'.api_get_cidreq().'&action=add_item&type='.TOOL_DOCUMENT.'&lp_id='.$_SESSION['oLP']->lp_id);
- $return .= '</div>';
-
-
- foreach ($resources as $resource) {
- $resource_paths = explode('/', $resource['path']);
- array_shift($resource_paths);
- $path_to_eval = $last_path = '';
- $is_file = false;
- foreach ($resource_paths as $key => $resource_path) {
- if (strpos($resource_path, '.') === false && $key != count($resource_paths) - 1) {
- $path_to_eval .= '["' . $resource_path . '"]["files"]';
- } else
- if (strpos($resource_path, '.') !== false)
- $is_file = true;
-
- $last_path = $resource_path;
- }
- if ($is_file) {
-
-
- if (empty($resource['title'])) {
- $resource['title'] = basename($resource['path']);
- }
- eval ('$resources_sorted' . $path_to_eval . '[' . $resource['id'] . '] = "' .$resource['title']."/". $last_path. '";');
- } else {
- eval ('$resources_sorted' . $path_to_eval . '["' . $last_path . '"]["id"]=' . $resource['id'] . ';');
- }
- }
- $label = get_lang('Documents');
- $new_array[$label] = array('id' => 0, 'files'=>$resources_sorted);
- $return .= $this->write_resources_tree($new_array);
-
- $return .= '</div>';
- return $return;
- }
-
- public function write_resources_tree($resources_sorted, $num = 0) {
- require_once api_get_path(LIBRARY_PATH).'fileDisplay.lib.php';
- if (count($resources_sorted) > 0) {
- foreach ($resources_sorted as $key => $resource) {
- if (is_int($resource['id'])) {
-
-
- if (in_array($key, array('shared_folder','chat_files', 'HotPotatoes_files', 'css', 'certificates'))){
- continue;
- } elseif(preg_match('/_groupdocs/', $key)){
- continue;
- } elseif(preg_match('/sf_user_/', $key)){
- continue;
- } elseif(preg_match('/shared_folder_session_/', $key)){
- continue;
- }
-
- if ($key=='images') {
- $key=get_lang('Images');
- } elseif($key=='gallery') {
- $key=get_lang('Gallery');
- } elseif($key=='flash') {
- $key=get_lang('Flash');
- } elseif($key=='audio'){
- $key=get_lang('Audio');
- } elseif($key=='video') {
- $key=get_lang('Video');
- }
- $return .= '<div class="doc_resource"><div style="margin-left:' . ($num * 18) . 'px;margin-right:5px;"><img style="cursor: pointer;" src="../img/nolines_plus.gif" align="absmiddle" id="img_' . $resource['id'] . '" onClick="javascript: testResources(\'' . $resource['id'] . '\',\'img_' . $resource['id'] . '\')"><img alt="" src="../img/lp_folder.gif" title="" align="absmiddle" /> <span onClick="javascript: testResources(\'' . $resource['id'] . '\',\'img_' . $resource['id'] . '\')" style="cursor: pointer;" >' . $key . '</span></div><div style="display: none;" id="' . $resource['id'] . '">';
- $return .= $this->write_resources_tree($resource['files'], $num +1);
- $return .= '</div></div>';
- } else {
- if (!is_array($resource)) {
-
- $icon = choose_image($resource);
- $position = strrpos($icon, '.');
- $icon = substr($icon, 0, $position) . '_small.gif';
- $file_info = explode('/', $resource);
- $my_file_title = $file_info[0];
- $my_file_name = $file_info[1];
-
-
- $return .= '<div class="doc_resource"><div style="margin-left:' . (($num +1) * 18) . 'px;margin-right:5px;"><a href="' . api_get_self() . '?cidReq=' . Security::remove_XSS($_GET['cidReq']) . '&action=add_item&type=' . TOOL_DOCUMENT . '&file=' . $key . '&lp_id=' . $this->lp_id . '"><img alt="" src="../img/' . $icon . '" title="" /> ' . $my_file_title . "</a></div></div>\r\n"; }
- }
- }
- }
- return $return;
- }
-
- public function get_exercises() {
-
- $uploadPath = DIR_HOTPOTATOES;
- $tbl_doc = Database :: get_course_table(TABLE_DOCUMENT);
- $tbl_quiz = Database :: get_course_table(TABLE_QUIZ_TEST);
- $session_id = api_get_session_id();
- $condition_session = api_get_session_condition($session_id);
- $sql_quiz = "SELECT * FROM $tbl_quiz WHERE active<>'-1' $condition_session ORDER BY title ASC";
- $sql_hot = "SELECT * FROM $tbl_doc WHERE path LIKE '" . $uploadPath . "/%/%htm%' $condition_session ORDER BY id ASC";
- $res_quiz = Database::query($sql_quiz);
- $res_hot = Database::query($sql_hot);
-
- $return .= '<div class="lp_resource">';
-
- $return .= '<div class="lp_resource_element">';
- $return .= '<img alt="" src="../img/new_test_small.gif" style="margin-right:5px;" title="" />';
- $return .= '<a href="' . api_get_path(REL_CODE_PATH) . 'exercice/exercise_admin.php?lp_id=' . $this->lp_id . '">' . get_lang('NewExercise') . '</a>';
- $return .= '</div>';
-
- while ($row_hot = Database :: fetch_array($res_hot)) {
- $return .= '<div class="lp_resource_element">';
-
- $return .= '<img alt="hp" src="../img/hotpotatoes_s.png" style="margin-right:5px;" title="" width="18px" height="18px" />';
- $return .= '<a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&action=add_item&type=' . TOOL_HOTPOTATOES . '&file=' . $row_hot['id'] . '&lp_id=' . $this->lp_id . '">' . ((!empty ($row_hot['comment'])) ? $row_hot['comment'] : Security :: remove_XSS($row_hot['title'])) . '</a>';
-
- $return .= '</div>';
- }
- while ($row_quiz = Database :: fetch_array($res_quiz)) {
- $return .= '<div class="lp_resource_element">';
- $return .= '<img alt="" src="../img/quizz_small.gif" style="margin-right:5px;" title="" />';
- $return .= '<a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&action=add_item&type=' . TOOL_QUIZ . '&file=' . $row_quiz['id'] . '&lp_id=' . $this->lp_id . '">' . Security :: remove_XSS($row_quiz['title']) . '</a>';
-
- $return .= '</div>';
- }
-
-
- $return .= '</div>';
- return $return;
- }
-
- public function get_links() {
- $tbl_link = Database :: get_course_table(TABLE_LINK);
- $session_id = api_get_session_id();
- $condition_session = api_get_session_condition($session_id,false);
- $sql_link = "SELECT * FROM $tbl_link $condition_session ORDER BY title ASC";
- $res_link = Database::query($sql_link);
-
- $return .= '<div class="lp_resource">';
-
- $return .= '<div class="lp_resource_element">';
- $return .= '<img alt="" src="../img/linksnew.gif" style="margin-right:5px;width:16px" title="" />';
- $return .= '<a href="' . api_get_path(REL_CODE_PATH) . 'link/link.php?' . api_get_cidreq() . '&action=addlink&lp_id=' . $this->lp_id . '" title="' . get_lang('LinkAdd') . '">' . get_lang('LinkAdd') . '</a>';
- $return .= '</div>';
- while ($row_link = Database :: fetch_array($res_link)) {
- $return .= '<div class="lp_resource_element">';
- $return .= '<img alt="" src="../img/lp_link.gif" style="margin-right:5px;" title="" />';
- $return .= '<a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&action=add_item&type=' . TOOL_LINK . '&file=' . $row_link['id'] . '&lp_id=' . $this->lp_id . '">' . $row_link['title'] . '</a>';
- $return .= '</div>';
- }
-
- $return .= '</div>';
- return $return;
- }
-
- public function get_student_publications() {
- $tbl_student = Database :: get_course_table(TABLE_STUDENT_PUBLICATION);
- $session_id = api_get_session_id();
- $condition_session = api_get_session_condition($session_id, false);
- $sql_student = "SELECT * FROM $tbl_student $condition_session ORDER BY title ASC";
- $res_student = Database::query($sql_student);
-
- $return .= '<div class="lp_resource" >';
- $return .= '<div class="lp_resource_element">';
- $return .= '<img align="left" alt="" src="../img/works_small.gif" style="margin-right:5px;" title="" />';
- $return .= '<a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&action=add_item&type=' . TOOL_STUDENTPUBLICATION . '&lp_id=' . $this->lp_id . '">' . get_lang('AddAssignmentPage') . '</a>';
- $return .= '</div>';
- $return .= '</div>';
- return $return;
- }
-
- public function get_forums() {
- require_once '../forum/forumfunction.inc.php';
- require_once '../forum/forumconfig.inc.php';
- global $table_forums, $table_threads, $table_posts, $table_item_property, $table_users;
- $table_forums = Database :: get_course_table(TABLE_FORUM);
- $table_threads = Database :: get_course_table(TABLE_FORUM_THREAD);
- $table_posts = Database :: get_course_table(TABLE_FORUM_POST);
- $table_item_property = Database :: get_course_table(TABLE_ITEM_PROPERTY);
- $table_users = Database :: get_main_table(TABLE_MAIN_USER);
- $a_forums = get_forums();
-
- $return .= '<div class="lp_resource">';
-
- $return .= '<div class="lp_resource_element">';
- $return .= '<img alt="" src="../img/forum_new_small.gif" style="margin-right:5px;" title="" />';
- $return .= '<a href="' . api_get_path(REL_CODE_PATH) . 'forum/index.php?' . api_get_cidreq() . '&action=add&content=forum&origin=learnpath&lp_id=' . $this->lp_id . '" title="' . get_lang('CreateANewForum') . '">' . get_lang('CreateANewForum') . '</a>';
- $return .= '</div>';
- foreach ($a_forums as $forum) {
- $return .= '<div class="lp_resource_element_no_link">';
- $return .= '<script type="text/javascript">
- function toggle_forum(forum_id){
- if(document.getElementById("forum_"+forum_id+"_content").style.display == "none"){
- document.getElementById("forum_"+forum_id+"_content").style.display = "block";
- document.getElementById("forum_"+forum_id+"_opener").src = "' . api_get_path(WEB_IMG_PATH) . 'remove.gif";
- }
- else {
- document.getElementById("forum_"+forum_id+"_content").style.display = "none";
- document.getElementById("forum_"+forum_id+"_opener").src = "' . api_get_path(WEB_IMG_PATH) . 'add.gif";
- }
- }
- </script>';
- if (!empty($forum['forum_id'])) {
- $return .= '<img alt="" src="../img/lp_forum.gif" style="margin-right:5px;" title="" />';
- $return .= '<a style="cursor:hand" onclick="javascript: toggle_forum(' . $forum['forum_id'] . ')" style="vertical-align:middle"><img src="' . api_get_path(WEB_IMG_PATH) . 'add.gif" id="forum_' . $forum['forum_id'] . '_opener" align="absbottom" /></a>
- <a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&action=add_item&type=' . TOOL_FORUM . '&forum_id=' . $forum['forum_id'] . '&lp_id=' . $this->lp_id . '" style="vertical-align:middle">' . Security :: remove_XSS($forum['forum_title']) . '</a><ul style="display:none" id="forum_' . $forum['forum_id'] . '_content">';
- }
- $a_threads = get_threads($forum['forum_id']);
- if (is_array($a_threads)) {
- foreach ($a_threads as $thread) {
- $return .= '<li><a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&action=add_item&type=' . TOOL_THREAD . '&thread_id=' . $thread['thread_id'] . '&lp_id=' . $this->lp_id . '">' . Security :: remove_XSS($thread['thread_title']) . '</a></li>';
- }
- }
- $return .= '</ul></div>';
- }
- return $return;
- }
-
- public function scorm_export() {
- global $_course;
-
- if (function_exists('ini_set')) {
- $mem = ini_get('memory_limit');
- if (substr($mem, -1, 1) == 'M') {
- $mem_num = substr($mem, 0, -1);
- if ($mem_num < 128) {
- ini_set('memory_limit', '128M');
- }
- } else {
- ini_set('memory_limit', '128M');
- }
- ini_set('max_execution_time', 600);
-
-
- }
-
- $archive_path = api_get_path(SYS_ARCHIVE_PATH);
- $sys_course_path = api_get_path(SYS_COURSE_PATH);
- $temp_dir_short = uniqid();
- $temp_zip_dir = $archive_path.'/'.$temp_dir_short;
- $temp_zip_file = $temp_zip_dir.'/'.md5(time()).'.zip';
- $zip_folder = new PclZip($temp_zip_file);
- $current_course_path = api_get_path(SYS_COURSE_PATH).api_get_course_path();
- $root_path = $main_path = api_get_path(SYS_PATH);
- $files_cleanup = array();
-
-
-
- if (!is_dir($temp_zip_dir)) {
- mkdir($temp_zip_dir, api_get_permissions_for_new_directories());
- } else {
-
- $handle = opendir($temp_zip_dir);
- while (false !== ($file = readdir($handle))) {
- if ($file != '.' && $file != '..') {
- unlink("$temp_zip_dir/$file");
- }
- }
- closedir($handle);
- }
- $zip_files = $zip_files_abs = $zip_files_dist = array();
- if (is_dir($current_course_path.'/scorm/'.$this->path) && is_file($current_course_path.'/scorm/'.$this->path.'/imsmanifest.xml')) {
-
- $dest_path_to_lp = substr($this->path, -1) == '.' ? substr($this->path, 0, -1) : $this->path;
- $dest_path_to_scorm_folder = str_replace('//','/',$temp_zip_dir.'/scorm/'.$dest_path_to_lp);
- mkdir($dest_path_to_scorm_folder, api_get_permissions_for_new_directories(), true);
- $zip_files_dist = copyr($current_course_path.'/scorm/'.$this->path, $dest_path_to_scorm_folder, array('imsmanifest'), $zip_files);
- }
-
-
-
- $xmldoc = new DOMDocument('1.0');
- $root = $xmldoc->createElement('manifest');
- $root->setAttribute('identifier', 'SingleCourseManifest');
- $root->setAttribute('version', '1.1');
- $root->setAttribute('xmlns', 'http://www.imsproject.org/xsd/imscp_rootv1p1p2');
- $root->setAttribute('xmlns:adlcp', 'http://www.adlnet.org/xsd/adlcp_rootv1p2');
- $root->setAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance');
- $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');
-
- $metadata = $xmldoc->createElement('metadata');
- $md_schema = $xmldoc->createElement('schema', 'ADL SCORM');
- $metadata->appendChild($md_schema);
- $md_schemaversion = $xmldoc->createElement('schemaversion', '1.2');
- $metadata->appendChild($md_schemaversion);
- $root->appendChild($metadata);
- $organizations = $xmldoc->createElement('organizations');
- $resources = $xmldoc->createElement('resources');
-
- $organizations->setAttribute('default', 'chamilo_scorm_export');
- $organization = $xmldoc->createElement('organization');
- $organization->setAttribute('identifier', 'chamilo_scorm_export');
-
-
-
-
-
-
- $org_title = $xmldoc->createElement('title', api_utf8_encode($this->get_name()));
- $organization->appendChild($org_title);
-
-
- $link_updates = array();
- foreach ($this->items as $index => $item) {
- if (!in_array($item->type, array(TOOL_QUIZ, TOOL_FORUM, TOOL_THREAD, TOOL_LINK, TOOL_STUDENTPUBLICATION))) {
-
- if ($item->type == 'sco')
- $inc_docs = $item->get_resources_from_source(null, api_get_path(SYS_COURSE_PATH).api_get_course_path().'/'.'scorm/'.$this->path.'/'.$item->get_path());
- else
- $inc_docs = $item->get_resources_from_source();
-
- $my_item_id = $item->get_id();
- $my_item = $xmldoc->createElement('item');
- $my_item->setAttribute('identifier', 'ITEM_'.$my_item_id);
- $my_item->setAttribute('identifierref', 'RESOURCE_'.$my_item_id);
- $my_item->setAttribute('isvisible', 'true');
-
- $my_title = $xmldoc->createElement('title', htmlspecialchars(api_utf8_encode($item->get_title()), ENT_QUOTES, 'UTF-8'));
- $my_item->appendChild($my_title);
-
- $my_prereqs = $xmldoc->createElement('adlcp:prerequisites', $this->get_scorm_prereq_string($my_item_id));
- $my_prereqs->setAttribute('type', 'aicc_script');
- $my_item->appendChild($my_prereqs);
-
-
-
-
-
-
-
- $my_masteryscore = $xmldoc->createElement('adlcp:masteryscore', $item->get_mastery_score());
- $my_item->appendChild($my_masteryscore);
-
- if (!empty($item->parent) && $item->parent != 0) {
- $children = $organization->childNodes;
- $possible_parent = &$this->get_scorm_xml_node($children, 'ITEM_'.$item->parent);
- if (is_object($possible_parent)) {
- $possible_parent->appendChild($my_item);
- } else {
- if ($this->debug > 0) { error_log('Parent ITEM_'.$item->parent.' of item ITEM_'.$my_item_id.' not found'); }
- }
- } else {
- if ($this->debug > 0) { error_log('No parent'); }
- $organization->appendChild($my_item);
- }
-
- $my_file_path = $item->get_file_path('scorm/'.$this->path.'/');
-
- $my_xml_file_path = $my_file_path;
- $my_sub_dir = dirname($my_file_path);
- $my_sub_dir = str_replace('\\', '/', $my_sub_dir);
-
- $my_xml_sub_dir = $my_sub_dir;
-
- $my_resource = $xmldoc->createElement('resource');
- $my_resource->setAttribute('identifier', 'RESOURCE_'.$item->get_id());
- $my_resource->setAttribute('type', 'webcontent');
- $my_resource->setAttribute('href', $my_xml_file_path);
-
- if ($item->type == 'sco') {
- $my_resource->setAttribute('adlcp:scormtype', 'sco');
- } else {
- $my_resource->setAttribute('adlcp:scormtype', 'asset');
- }
-
- $my_resource->setAttribute('xml:base', '');
-
- $my_file = $xmldoc->createElement('file');
- $my_file->setAttribute('href', $my_xml_file_path);
- $my_resource->appendChild($my_file);
-
- $i = 1;
- foreach ($inc_docs as $doc_info) {
- if (count($doc_info) < 1 || empty($doc_info[0])) { continue; }
- $my_dep = $xmldoc->createElement('resource');
- $res_id = 'RESOURCE_'.$item->get_id().'_'.$i;
- $my_dep->setAttribute('identifier', $res_id);
- $my_dep->setAttribute('type', 'webcontent');
- $my_dep->setAttribute('adlcp:scormtype', 'asset');
- $my_dep_file = $xmldoc->createElement('file');
-
-
- if ($doc_info[1] == 'remote') {
-
- $my_dep_file->setAttribute('href', $doc_info[0]);
- $my_dep->setAttribute('xml:base', '');
- } elseif ($doc_info[1] == 'local') {
- switch ($doc_info[2]) {
- case 'url':
- $abs_path = api_get_path(SYS_PATH).str_replace(api_get_path(WEB_PATH), '', $doc_info[0]);
- $current_dir = dirname($abs_path);
- $current_dir = str_replace('\\', '/', $current_dir);
- $file_path = realpath($abs_path);
- $file_path = str_replace('\\', '/', $file_path);
- $my_dep_file->setAttribute('href', $file_path);
- $my_dep->setAttribute('xml:base', '');
- if (strstr($file_path, $main_path) !== false) {
-
-
- $file_path = substr($file_path, strlen($root_path) - 1);
-
-
- $zip_files_abs[] = $file_path;
- $link_updates[$my_file_path][] = array('orig' => $doc_info[0], 'dest' => $file_path);
- $my_dep_file->setAttribute('href', $file_path);
- $my_dep->setAttribute('xml:base', '');
- }
- elseif (empty($file_path)) {
-
- $file_path = $_SERVER['DOCUMENT_ROOT'].$abs_path;
- $file_path = str_replace('//', '/', $file_path);
- if (file_exists($file_path)) {
- $file_path = substr($file_path, strlen($current_dir));
- $zip_files[] = $my_sub_dir.'/'.$file_path;
- $link_updates[$my_file_path][] = array('orig' => $doc_info[0], 'dest' => $file_path);
- $my_dep_file->setAttribute('href', $file_path);
- $my_dep->setAttribute('xml:base', '');
- }
- }
- break;
- case 'abs':
- $my_dep_file->setAttribute('href', $doc_info[0]);
- $my_dep->setAttribute('xml:base', '');
-
-
-
- $abs_img_path_without_subdir = $doc_info[0];
- $relp = api_get_path(REL_PATH);
- $pos = strpos($abs_img_path_without_subdir, $relp);
- if ($pos === 0) {
- $abs_img_path_without_subdir = '/'.substr($abs_img_path_without_subdir, strlen($relp));
- }
-
- $file_path = realpath(api_get_path(SYS_PATH).$abs_img_path_without_subdir);
- $file_path = str_replace('\\', '/', $file_path);
- $file_path = str_replace('//', '/', $file_path);
-
-
- $cur_path = substr($current_course_path, -1) == '/' ? $current_course_path : $current_course_path.'/';
-
- if (strstr($file_path, $cur_path) !== false) {
-
-
- $orig_file_path = dirname($cur_path.$my_file_path).'/';
- $orig_file_path = str_replace('\\', '/', $orig_file_path);
- $relative_path = '';
- if (strstr($file_path, $cur_path) !== false) {
- $relative_path = substr($file_path, strlen($orig_file_path));
- $file_path = substr($file_path, strlen($cur_path));
- } else {
-
-
-
-
- $my_relative_path = dirname($file_path);
- $my_relative_path = str_replace('\\', '/', $my_relative_path);
- $my_relative_file = basename($file_path);
-
- $my_orig_file_path = substr($orig_file_path, 0, -1);
- $dotdot = '';
- $subdir = '';
- while (strstr($my_relative_path, $my_orig_file_path) === false && (strlen($my_orig_file_path) > 1) && (strlen($my_relative_path) > 1)) {
- $my_relative_path2 = dirname($my_relative_path);
- $my_relative_path2 = str_replace('\\', '/', $my_relative_path2);
- $my_orig_file_path = dirname($my_orig_file_path);
- $my_orig_file_path = str_replace('\\', '/', $my_orig_file_path);
- $subdir = substr($my_relative_path, strlen($my_relative_path2) + 1).'/'.$subdir;
- $dotdot += '../';
- $my_relative_path = $my_relative_path2;
- }
- $relative_path = $dotdot.$subdir.$my_relative_file;
- }
-
-
- $zip_files[] = $file_path;
-
- $link_updates[$my_file_path][] = array('orig' => $doc_info[0], 'dest' => $relative_path);
- $my_dep_file->setAttribute('href', $file_path);
- $my_dep->setAttribute('xml:base', '');
- }
- elseif (strstr($file_path,$main_path) !== false) {
-
-
- $file_path = substr($file_path, strlen($root_path));
-
-
- $zip_files_abs[] = $file_path;
- $link_updates[$my_file_path][] = array('orig' => $doc_info[0], 'dest' => $file_path);
- $my_dep_file->setAttribute('href', 'document/'.$file_path);
- $my_dep->setAttribute('xml:base', '');
- }
- elseif (empty($file_path)) {
-
- $file_path = $_SERVER['DOCUMENT_ROOT'].$doc_info[0];
- $file_path = str_replace('//', '/', $file_path);
- if (file_exists($file_path)) {
- $file_path = substr($file_path,strlen($current_dir));
- $zip_files[] = $my_sub_dir.'/'.$file_path;
- $link_updates[$my_file_path][] = array('orig' => $doc_info[0], 'dest' => $file_path);
- $my_dep_file->setAttribute('href','document/'.$file_path);
- $my_dep->setAttribute('xml:base', '');
- }
- }
- break;
- case 'rel':
- if (substr($doc_info[0], 0, 2) == '..') {
-
- $current_dir = dirname($current_course_path.'/'.$item->get_file_path()).'/';
- $current_dir = str_replace('\\', '/', $current_dir);
- $file_path = realpath($current_dir.$doc_info[0]);
- $file_path = str_replace('\\', '/', $file_path);
-
- if (strstr($file_path, $main_path) !== false) {
-
-
- $file_path = substr($file_path, strlen($root_path));
-
- $zip_files_abs[] = $file_path;
- $link_updates[$my_file_path][] = array('orig' => $doc_info[0], 'dest' => $file_path);
- $my_dep_file->setAttribute('href', 'document/'.$file_path);
- $my_dep->setAttribute('xml:base', '');
- }
- } else {
- $zip_files[] = $my_sub_dir.'/'.$doc_info[0];
- $my_dep_file->setAttribute('href', $doc_info[0]);
- $my_dep->setAttribute('xml:base', $my_xml_sub_dir);
- }
- break;
- default:
- $my_dep_file->setAttribute('href', $doc_info[0]);
- $my_dep->setAttribute('xml:base', '');
- break;
- }
- }
- $my_dep->appendChild($my_dep_file);
- $resources->appendChild($my_dep);
- $dependency = $xmldoc->createElement('dependency');
- $dependency->setAttribute('identifierref', $res_id);
- $my_resource->appendChild($dependency);
- $i++;
- }
-
-
- $resources->appendChild($my_resource);
- $zip_files[] = $my_file_path;
-
- } else {
-
- if ($item->type == TOOL_LINK) {
- $my_item = $xmldoc->createElement('item');
- $my_item->setAttribute('identifier', 'ITEM_'.$item->get_id());
- $my_item->setAttribute('identifierref', 'RESOURCE_'.$item->get_id());
- $my_item->setAttribute('isvisible', 'true');
-
- $my_title = $xmldoc->createElement('title', htmlspecialchars(api_utf8_encode($item->get_title()), ENT_QUOTES, 'UTF-8'));
- $my_item->appendChild($my_title);
-
- $my_prereqs = $xmldoc->createElement('adlcp:prerequisites', $item->get_prereq_string());
- $my_prereqs->setAttribute('type', 'aicc_script');
- $my_item->appendChild($my_prereqs);
-
-
-
-
-
-
-
- $my_masteryscore = $xmldoc->createElement('adlcp:masteryscore', $item->get_mastery_score());
- $my_item->appendChild($my_masteryscore);
-
- if (!empty($item->parent) && $item->parent != 0) {
- $children = $organization->childNodes;
- for ($i = 0; $i < $children->length; $i++) {
- $item_temp = $children->item($i);
- if ($item_temp -> nodeName == 'item') {
- if ($item_temp->getAttribute('identifier') == 'ITEM_'.$item->parent) {
- $item_temp -> appendChild($my_item);
- }
- }
- }
- } else {
- $organization->appendChild($my_item);
- }
- $my_file_path = 'link_'.$item->get_id().'.html';
- $sql = 'SELECT url, title FROM '.Database :: get_course_table(TABLE_LINK).' WHERE id='.$item->path;
- $rs = Database::query($sql);
- if ($link = Database :: fetch_array($rs)) {
- $url = $link['url'];
- $title = stripslashes($link['title']);
- $links_to_create[$my_file_path] = array('title' => $title, 'url' => $url);
-
- $my_xml_file_path = $my_file_path;
- $my_sub_dir = dirname($my_file_path);
- $my_sub_dir = str_replace('\\', '/', $my_sub_dir);
-
- $my_xml_sub_dir = $my_sub_dir;
-
- $my_resource = $xmldoc->createElement('resource');
- $my_resource->setAttribute('identifier', 'RESOURCE_'.$item->get_id());
- $my_resource->setAttribute('type', 'webcontent');
- $my_resource->setAttribute('href', $my_xml_file_path);
-
- $my_resource->setAttribute('adlcp:scormtype', 'asset');
-
- $my_resource->setAttribute('xml:base', '');
-
- $my_file = $xmldoc->createElement('file');
- $my_file->setAttribute('href', $my_xml_file_path);
- $my_resource->appendChild($my_file);
- $resources->appendChild($my_resource);
- }
- }
- elseif ($item->type == TOOL_QUIZ) {
- require_once api_get_path(SYS_CODE_PATH).'exercice/exercise.class.php';
- $exe_id = $item->path;
- $exe = new Exercise();
- $exe->read($exe_id);
- $my_item = $xmldoc->createElement('item');
- $my_item->setAttribute('identifier', 'ITEM_'.$item->get_id());
- $my_item->setAttribute('identifierref', 'RESOURCE_'.$item->get_id());
- $my_item->setAttribute('isvisible', 'true');
-
- $my_title = $xmldoc->createElement('title', htmlspecialchars(api_utf8_encode($item->get_title()), ENT_QUOTES, 'UTF-8'));
- $my_item->appendChild($my_title);
- $my_max_score = $xmldoc->createElement('max_score', $item->get_max());
-
-
- $my_prereqs = $xmldoc->createElement('adlcp:prerequisites', $item->get_prereq_string());
- $my_prereqs->setAttribute('type','aicc_script');
- $my_item->appendChild($my_prereqs);
-
- $my_masteryscore = $xmldoc->createElement('adlcp:masteryscore', $item->get_mastery_score());
- $my_item->appendChild($my_masteryscore);
-
- if (!empty($item->parent) && $item->parent != 0) {
- $children = $organization->childNodes;
- for ($i = 0; $i < $children->length; $i++) {
- $item_temp = $children->item($i);
- if ($item_temp -> nodeName == 'item') {
- if ($item_temp->getAttribute('identifier') == 'ITEM_'.$item->parent) {
- $item_temp -> appendChild($my_item);
- }
- }
- }
- } else {
- $organization->appendChild($my_item);
- }
-
- require_once api_get_path(SYS_CODE_PATH).'exercice/export/scorm/scorm_export.php';
-
-
- $my_file_path = 'quiz_'.$item->get_id().'.html';
-
-
- $contents = export_exercise($exe_id,true);
- $tmp_file_path = $archive_path.$temp_dir_short.'/'.$my_file_path;
- $res = file_put_contents($tmp_file_path, $contents);
- if ($res === false) { error_log('Could not write into file '.$tmp_file_path.' '.__FILE__.' '.__LINE__, 0); }
- $files_cleanup[] = $tmp_file_path;
-
-
- $my_xml_file_path = $my_file_path;
- $my_sub_dir = dirname($my_file_path);
- $my_sub_dir = str_replace('\\', '/', $my_sub_dir);
-
- $my_xml_sub_dir = $my_sub_dir;
-
- $my_resource = $xmldoc->createElement('resource');
- $my_resource->setAttribute('identifier', 'RESOURCE_'.$item->get_id());
- $my_resource->setAttribute('type', 'webcontent');
- $my_resource->setAttribute('href', $my_xml_file_path);
-
- $my_resource->setAttribute('adlcp:scormtype', 'sco');
-
- $my_resource->setAttribute('xml:base', '');
-
- $my_file = $xmldoc->createElement('file');
- $my_file->setAttribute('href', $my_xml_file_path);
- $my_resource->appendChild($my_file);
-
- $inc_docs = $item->get_resources_from_source(null,$tmp_file_path);
-
- $i = 1;
- foreach ($inc_docs as $doc_info) {
- if (count($doc_info) < 1 || empty($doc_info[0])) { continue; }
- $my_dep = $xmldoc->createElement('resource');
- $res_id = 'RESOURCE_'.$item->get_id().'_'.$i;
- $my_dep->setAttribute('identifier', $res_id);
- $my_dep->setAttribute('type', 'webcontent');
- $my_dep->setAttribute('adlcp:scormtype', 'asset');
- $my_dep_file = $xmldoc->createElement('file');
-
-
- if ($doc_info[1] == 'remote') {
-
- $my_dep_file->setAttribute('href', $doc_info[0]);
- $my_dep->setAttribute('xml:base', '');
- } elseif ($doc_info[1] == 'local') {
- switch ($doc_info[2]) {
- case 'url':
-
- $abs_path = api_get_path(SYS_PATH).str_replace(api_get_path(WEB_PATH), '', $doc_info[0]);
- $current_dir = dirname($abs_path);
- $current_dir = str_replace('\\', '/', $current_dir);
- $file_path = realpath($abs_path);
- $file_path = str_replace('\\', '/', $file_path);
- $my_dep_file->setAttribute('href', 'document/'.$file_path);
- $my_dep->setAttribute('xml:base', '');
- if (strstr($file_path, $main_path) !== false) {
-
-
- $file_path = substr($file_path, strlen($root_path));
-
-
- $zip_files_abs[] = $file_path;
- $link_updates[$my_file_path][] = array('orig' => $doc_info[0], 'dest' => 'document/'.$file_path);
- $my_dep_file->setAttribute('href', 'document/'.$file_path);
- $my_dep->setAttribute('xml:base', '');
- }
- elseif (empty($file_path)) {
-
- $file_path = $_SERVER['DOCUMENT_ROOT'].$abs_path;
- $file_path = str_replace('//', '/', $file_path);
- if (file_exists($file_path)) {
- $file_path = substr($file_path, strlen($current_dir));
- $zip_files[] = $my_sub_dir.'/'.$file_path;
- $link_updates[$my_file_path][] = array('orig' => $doc_info[0], 'dest' => 'document/'.$file_path);
- $my_dep_file->setAttribute('href', 'document/'.$file_path);
- $my_dep->setAttribute('xml:base', '');
- }
- }
- break;
- case 'abs':
- $current_dir = dirname($current_course_path.'/'.$item->get_file_path()).'/';
- $current_dir = str_replace('\\', '/', $current_dir);
- $file_path = realpath($doc_info[0]);
- $file_path = str_replace('\\', '/', $file_path);
- $my_dep_file->setAttribute('href', $file_path);
- $my_dep->setAttribute('xml:base', '');
- if (strstr($file_path,$main_path) !== false) {
-
-
- $file_path = substr($file_path, strlen($root_path));
-
-
- $zip_files_abs[] = $file_path;
- $link_updates[$my_file_path][] = array('orig' => $doc_info[0], 'dest' => $file_path);
- $my_dep_file->setAttribute('href', 'document/'.$file_path);
- $my_dep->setAttribute('xml:base', '');
- }
- elseif (empty($file_path)) {
-
- $file_path = $_SERVER['DOCUMENT_ROOT'].$doc_info[0];
- $file_path = str_replace('//', '/', $file_path);
- if (file_exists($file_path)) {
- $file_path = substr($file_path,strlen($current_dir));
- $zip_files[] = $my_sub_dir.'/'.$file_path;
- $link_updates[$my_file_path][] = array('orig' => $doc_info[0], 'dest' => $file_path);
- $my_dep_file->setAttribute('href', 'document/'.$file_path);
- $my_dep->setAttribute('xml:base', '');
- }
- }
- break;
- case 'rel':
- if (substr($doc_info[0], 0, 2) == '..') {
-
- $current_dir = dirname($current_course_path.'/'.$item->get_file_path()).'/';
- $current_dir = str_replace('\\', '/', $current_dir);
- $file_path = realpath($current_dir.$doc_info[0]);
- $file_path = str_replace('\\', '/', $file_path);
-
- if (strstr($file_path, $main_path) !== false) {
-
-
- $file_path = substr($file_path, strlen($root_path));
- $file_path_dest = $file_path;
-
- $info_file_path = explode('/', $file_path);
- if ($info_file_path[0] == 'courses') {
- $file_path_dest = 'document/'.$file_path;
- }
-
- $zip_files_abs[] = $file_path;
- $link_updates[$my_file_path][] = array('orig' => $doc_info[0], 'dest' => $file_path_dest);
- $my_dep_file->setAttribute('href', 'document/'.$file_path);
- $my_dep->setAttribute('xml:base', '');
- }
- } else {
- $zip_files[] = $my_sub_dir.'/'.$doc_info[0];
- $my_dep_file->setAttribute('href', $doc_info[0]);
- $my_dep->setAttribute('xml:base', $my_xml_sub_dir);
- }
- break;
- default:
- $my_dep_file->setAttribute('href', $doc_info[0]);
- $my_dep->setAttribute('xml:base', '');
- break;
- }
- }
- $my_dep->appendChild($my_dep_file);
- $resources->appendChild($my_dep);
- $dependency = $xmldoc->createElement('dependency');
- $dependency->setAttribute('identifierref', $res_id);
- $my_resource->appendChild($dependency);
- $i++;
- }
- $resources->appendChild($my_resource);
- $zip_files[] = $my_file_path;
- } else {
-
- $my_file_path = 'non_exportable.html';
-
- $my_xml_file_path = $my_file_path;
- $my_sub_dir = dirname($my_file_path);
- $my_sub_dir = str_replace('\\', '/', $my_sub_dir);
-
- $my_xml_sub_dir = $my_sub_dir;
-
- $my_resource = $xmldoc->createElement('resource');
- $my_resource->setAttribute('identifier', 'RESOURCE_'.$item->get_id());
- $my_resource->setAttribute('type', 'webcontent');
- $my_resource->setAttribute('href', 'document/'.$my_xml_file_path);
-
- $my_resource->setAttribute('adlcp:scormtype', 'asset');
-
- $my_resource->setAttribute('xml:base', '');
-
- $my_file = $xmldoc->createElement('file');
- $my_file->setAttribute('href', 'document/'.$my_xml_file_path);
- $my_resource->appendChild($my_file);
- $resources->appendChild($my_resource);
- }
- }
- }
- $organizations->appendChild($organization);
- $root->appendChild($organizations);
- $root->appendChild($resources);
- $xmldoc->appendChild($root);
-
-
-
-
- foreach ($zip_files as $file_path) {
- if (empty($file_path)) { continue; }
-
- $dest_file = $archive_path.$temp_dir_short.'/'.$file_path;
- $this->create_path($dest_file);
-
-
- @copy($sys_course_path.$_course['path'].'/'.$file_path, $dest_file);
-
- if (in_array($file_path, array_keys($link_updates))) {
- $string = file_get_contents($dest_file);
- unlink($dest_file);
- foreach ($link_updates[$file_path] as $old_new) {
-
-
-
-
-
- if (substr($old_new['dest'], -3) == 'flv' && substr($old_new['dest'], 0, 5) == 'main/') {
- $old_new['dest'] = str_replace('main/', '../../../', $old_new['dest']);
- }
- elseif (substr($old_new['dest'], -3) == 'flv' && substr($old_new['dest'], 0, 6) == 'video/') {
- $old_new['dest'] = str_replace('video/', '../../../../video/', $old_new['dest']);
- }
- $string = str_replace($old_new['orig'], $old_new['dest'], $string);
- }
- file_put_contents($dest_file, $string);
- }
- }
- foreach ($zip_files_abs as $file_path) {
- if (empty($file_path)) { continue; }
-
- if (!is_file($main_path.$file_path) || !is_readable($main_path.$file_path)) { continue; }
-
- $dest_file = $archive_path.$temp_dir_short.'/document/'.$file_path;
- $this->create_path($dest_file);
-
-
-
- copy($main_path.$file_path, $dest_file);
-
- if (in_array($file_path, array_keys($link_updates))) {
- $string = file_get_contents($dest_file);
- unlink($dest_file);
- foreach ($link_updates[$file_path] as $old_new) {
-
-
-
-
-
- if (substr($old_new['dest'], -3) == 'flv' && substr($old_new['dest'], 0, 5) == 'main/') {
- $old_new['dest'] = str_replace('main/', '../../../', $old_new['dest']);
- }
- $string = str_replace($old_new['orig'], $old_new['dest'], $string);
- }
- file_put_contents($dest_file, $string);
- }
- }
- if (is_array($links_to_create)) {
- foreach ($links_to_create as $file => $link) {
- $file_content = '<!DOCTYPE html
- PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="'.api_get_language_isocode().'" lang="'.api_get_language_isocode().'">
- <head>
- <title>'.$link['title'].'</title>
- <meta http-equiv="Content-Type" content="text/html; charset='.api_get_system_encoding().'" />
- </head>
- <body dir="'.api_get_text_direction().'">
- <div style="text-align:center"><a href="'.$link['url'].'">'.$link['title'].'</a></div>
- </body>
- </html>';
- file_put_contents($archive_path.$temp_dir_short.'/'.$file, $file_content);
- }
- }
-
- $lang_not_exportable = get_lang('ThisItemIsNotExportable');
- $file_content = '<!DOCTYPE html
- PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="'.api_get_language_isocode().'" lang="'.api_get_language_isocode().'">
- <head>
- <title>'.$lang_not_exportable.'</title>
- <meta http-equiv="Content-Type" content="text/html; charset='.api_get_system_encoding().'" />
- </head>
- <body dir="'.api_get_text_direction().'">
- ';
- $file_content .=
- <<<EOD
- <style>
- .error-message {
- font-family: arial, verdana, helvetica, sans-serif;
- border-width: 1px;
- border-style: solid;
- left: 50%;
- margin: 10px auto;
- min-height: 30px;
- padding: 5px;
- right: 50%;
- width: 500px;
- background-color: #FFD1D1;
- border-color: #FF0000;
- color: #000;
- }
- </style>
- <body>
- <div class="error-message">
- $lang_not_exportable
- </div>
- </body>
- </html>
- EOD;
- if (!is_dir($archive_path.$temp_dir_short.'/document')) {
- @mkdir($archive_path.$temp_dir_short.'/document', api_get_permissions_for_new_directories());
- }
- file_put_contents($archive_path.$temp_dir_short.'/document/non_exportable.html', $file_content);
-
- $main_code_path = api_get_path(SYS_CODE_PATH).'newscorm/packaging/';
- $extra_files = scandir($main_code_path);
- foreach ($extra_files as $extra_file) {
- if (strpos($extra_file, '.') === 0)
- continue;
- else {
- $dest_file = $archive_path . $temp_dir_short . '/' . $extra_file;
- $this->create_path($dest_file);
- copy($main_code_path.$extra_file, $dest_file);
- }
- }
-
- $manifest = @$xmldoc->saveXML();
- $manifest = api_utf8_decode_xml($manifest);
- file_put_contents($archive_path.'/'.$temp_dir_short.'/imsmanifest.xml', $manifest);
- $zip_folder->add($archive_path.'/'.$temp_dir_short, PCLZIP_OPT_REMOVE_PATH, $archive_path.'/'.$temp_dir_short.'/');
-
- foreach ($files_cleanup as $file) {
- $res = unlink($file);
- if ($res === false) { error_log('Could not delete temp file '.$file.' '.__FILE__.' '.__LINE__, 0); }
- }
-
-
- require_once api_get_path(LIBRARY_PATH).'fileUpload.lib.php';
- $name = replace_dangerous_char($this->get_name()).'.zip';
- DocumentManager::file_send_for_download($temp_zip_file, true, $name);
- }
- public function scorm_export_to_pdf($lp_id) {
- $lp_id = intval($lp_id);
- $files_to_export = array();
- $course_data = api_get_course_info($this->cc);
- if (!empty($course_data)) {
- $scorm_path = api_get_path(SYS_COURSE_PATH).$course_data['path'].'/scorm/'.$this->path;
- require_once api_get_path(LIBRARY_PATH).'document.lib.php';
- $list = $this->get_flat_ordered_items_list($lp_id);
-
- foreach($list as $item_id) {
- $item = $this->items[$item_id];
-
-
- switch ($item->type) {
- case 'document':
- $file_data = DocumentManager::get_document_data_by_id($item->path, $this->cc);
- $file_path = api_get_path(SYS_COURSE_PATH).$course_data['path'].'/document'.$file_data['path'];
- if (file_exists($file_path)) {
- $files_to_export[] = array('title'=>$item->get_title(),'path'=>$file_path);
- }
- break;
- case 'sco':
- $file_path = $scorm_path.'/'.$item->path;
- if (file_exists($file_path)) {
- $files_to_export[] = array('title'=>$item->get_title(),'path'=>$file_path);
- }
- break;
- case 'dokeos_chapter':
- case 'dir':
- case 'chapter':
- $files_to_export[] = array('title'=>$item->get_title(),'path'=>null);
- break;
- }
- }
- require_once api_get_path(LIBRARY_PATH).'pdf.lib.php';
- $pdf = new PDF();
- $result = $pdf->html_to_pdf($files_to_export, $this->name, $this->cc, true);
- return $result;
- }
- return false;
- }
-
- public function create_path($path) {
- $path_bits = split('/', dirname($path));
-
- $path_built = IS_WINDOWS_OS ? '' : '/';
- foreach ($path_bits as $bit) {
- if (!empty ($bit)) {
- $new_path = $path_built . $bit;
- if (is_dir($new_path)) {
- $path_built = $new_path . '/';
- } else {
- mkdir($new_path, api_get_permissions_for_new_directories());
- $path_built = $new_path . '/';
- }
- }
- }
- }
-
- public function delete_lp_image() {
- $img = $this->get_preview_image();
- if ($img != '') {
- $del_file = api_get_path(SYS_COURSE_PATH) . api_get_course_path() . '/upload/learning_path/images/' . $img;
- $this->set_preview_image('');
- return @ unlink($del_file);
- } else {
- return false;
- }
- }
-
- public function upload_image($image_array) {
- $image_moved = false;
- if (!empty ($image_array['name'])) {
- $upload_ok = process_uploaded_file($image_array);
- $has_attachment = true;
- } else {
- $image_moved = true;
- }
- if ($upload_ok) {
- if ($has_attachment) {
- $courseDir = api_get_course_path() . '/upload/learning_path/images';
- $sys_course_path = api_get_path(SYS_COURSE_PATH);
- $updir = $sys_course_path . $courseDir;
-
- $new_file_name = add_ext_on_mime(stripslashes($image_array['name']), $image_array['type']);
- if (!filter_extension($new_file_name)) {
-
- $image_moved = false;
- } else {
- $file_extension = explode('.', $image_array['name']);
- $file_extension = strtolower($file_extension[sizeof($file_extension) - 1]);
- $new_file_name = uniqid('') . '.' . $file_extension;
- $new_path = $updir . '/' . $new_file_name;
-
-
- include_once api_get_path(LIBRARY_PATH).'image.lib.php';
- $temp = new image($image_array['tmp_name']);
- $picture_infos = @getimagesize($image_array['tmp_name']);
- if ($picture_infos[0] > 104) {
- $thumbwidth = 104;
- } else {
- $thumbwidth = $picture_infos[0];
- }
- if ($picture_infos[1] > 96) {
- $new_height = 96;
- } else {
- $new_height = $picture_infos[1];
- }
-
- $temp->resize($thumbwidth,$new_height, 0);
- $type = $picture_infos[2];
- $result = false;
- switch ($type) {
- case 2 :
- $result = $temp->send_image('JPG', $new_path);
- break;
- case 3 :
- $result = $temp->send_image('PNG', $new_path);
- break;
- case 1 :
- $result = $temp->send_image('GIF', $new_path);
- break;
- }
- $temp->resize($thumbwidth, $new_height, 0);
- $type = $picture_infos[2];
- $result = false;
- switch ($type) {
- case 2 :
- $result = $temp->send_image('JPG', $new_path);
- break;
- case 3 :
- $result = $temp->send_image('PNG', $new_path);
- break;
- case 1 :
- $result = $temp->send_image('GIF', $new_path);
- break;
- }
-
- if ($result) {
- $image_moved = true;
- $this->set_preview_image($new_file_name);
- return true;
- }
- }
- }
- }
- return false;
- }
- public function set_autolunch($lp_id, $status) {
- $lp_id = intval($lp_id);
- $status = intval($status);
- $lp_table = Database::get_course_table(TABLE_LP_MAIN);
-
- $attributes['autolunch'] = 0;
- $where = array('session_id = ? '=> api_get_session_id());
- Database::update($lp_table, $attributes,$where);
- if ($status == 1) {
-
- $attributes['autolunch'] = 1;
- $where = array('id = ? AND session_id = ? '=> array($lp_id, api_get_session_id()));
- Database::update($lp_table, $attributes, $where );
- }
- }
- }
- if (!function_exists('trim_value')) {
- function trim_value(& $value) {
- $value = trim($value);
- }
- }
|