learnpath.class.php 298 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197
  1. <?php //$id:$
  2. /**
  3. * This (abstract?) class defines the parent attributes and methods for the dokeos learnpaths and scorm
  4. * learnpaths. It is used by the scorm class as well as the dokeos_lp class.
  5. * @package dokeos.learnpath
  6. * @author Yannick Warnier <ywarnier@beeznest.org>
  7. * @license GNU/GPL - See Dokeos license directory for details
  8. */
  9. /**
  10. * Defines the learnpath parent class
  11. * @package dokeos.learnpath
  12. */
  13. class learnpath {
  14. var $attempt = 0; //the number for the current ID view
  15. var $cc; //course (code) this learnpath is located in
  16. var $current; //id of the current item the user is viewing
  17. var $current_score; //the score of the current item
  18. var $current_time_start; //the time the user loaded this resource (this does not mean he can see it yet)
  19. var $current_time_stop; //the time the user closed this resource
  20. var $default_status = 'not attempted';
  21. var $encoding = 'ISO-8859-1';
  22. var $error = '';
  23. var $extra_information = ''; //this string can be used by proprietary SCORM contents to store data about the current learnpath
  24. var $force_commit = false; //for SCORM only - if set to true, will send a scorm LMSCommit() request on each LMSSetValue()
  25. var $index; //the index of the active learnpath_item in $ordered_items array
  26. var $items = array();
  27. var $last; //item_id of last item viewed in the learning path
  28. var $last_item_seen = 0; //in case we have already come in this learnpath, reuse the last item seen if authorized
  29. var $license; //which license this course has been given - not used yet on 20060522
  30. var $lp_id; //DB ID for this learnpath
  31. var $lp_view_id; //DB ID for lp_view
  32. var $log_file; //file where to log learnpath API msg
  33. var $maker; //which maker has conceived the content (ENI, Articulate, ...)
  34. var $message = '';
  35. var $mode='embedded'; //holds the video display mode (fullscreen or embedded)
  36. var $name; //learnpath name (they generally have one)
  37. var $ordered_items = array(); //list of the learnpath items in the order they are to be read
  38. var $path = ''; //path inside the scorm directory (if scorm)
  39. var $theme; // the current theme of the learning path
  40. // Tells if all the items of the learnpath can be tried again. Defaults to "no" (=1)
  41. var $prevent_reinit = 1;
  42. // Describes the mode of progress bar display
  43. var $progress_bar_mode = '%';
  44. // Percentage progress as saved in the db
  45. var $progress_db = '0';
  46. var $proximity; //wether the content is distant or local or unknown
  47. var $refs_list = array(); //list of items by ref => db_id. Used only for prerequisites match.
  48. //!!!This array (refs_list) is built differently depending on the nature of the LP.
  49. //If SCORM, uses ref, if Dokeos, uses id to keep a unique value
  50. var $type; //type of learnpath. Could be 'dokeos', 'scorm', 'scorm2004', 'aicc', ...
  51. //TODO check if this type variable is useful here (instead of just in the controller script)
  52. var $user_id; //ID of the user that is viewing/using the course
  53. var $update_queue = array();
  54. var $scorm_debug = 0;
  55. var $arrMenu = array(); //array for the menu items
  56. var $debug = 0; //logging level
  57. /**
  58. * Class constructor. Needs a database handler, a course code and a learnpath id from the database.
  59. * Also builds the list of items into $this->items.
  60. * @param string Course code
  61. * @param integer Learnpath ID
  62. * @param integer User ID
  63. * @return boolean True on success, false on error
  64. */
  65. function learnpath($course, $lp_id, $user_id) {
  66. //check params
  67. //check course code
  68. if($this->debug>0){error_log('New LP - In learnpath::learnpath('.$course.','.$lp_id.','.$user_id.')',0);}
  69. if(empty($course)){
  70. $this->error = 'Course code is empty';
  71. return false;
  72. }
  73. else
  74. {
  75. $main_table = Database::get_main_table(TABLE_MAIN_COURSE);
  76. //$course = Database::escape_string($course);
  77. $course = $this->escape_string($course);
  78. $sql = "SELECT * FROM $main_table WHERE code = '$course'";
  79. if($this->debug>2){error_log('New LP - learnpath::learnpath() '.__LINE__.' - Querying course: '.$sql,0);}
  80. //$res = Database::query($sql);
  81. $res = api_sql_query($sql);
  82. if(Database::num_rows($res)>0)
  83. {
  84. $this->cc = $course;
  85. }
  86. else
  87. {
  88. $this->error = 'Course code does not exist in database ('.$sql.')';
  89. return false;
  90. }
  91. }
  92. //check learnpath ID
  93. if(empty($lp_id))
  94. {
  95. $this->error = 'Learnpath ID is empty';
  96. return false;
  97. }
  98. else
  99. {
  100. //TODO make it flexible to use any course_code (still using env course code here)
  101. $lp_table = Database::get_course_table('lp');
  102. //$id = Database::escape_integer($id);
  103. $lp_id = $this->escape_string($lp_id);
  104. $sql = "SELECT * FROM $lp_table WHERE id = '$lp_id'";
  105. if($this->debug>2){error_log('New LP - learnpath::learnpath() '.__LINE__.' - Querying lp: '.$sql,0);}
  106. //$res = Database::query($sql);
  107. $res = api_sql_query($sql);
  108. if(Database::num_rows($res)>0)
  109. {
  110. $this->lp_id = $lp_id;
  111. $row = Database::fetch_array($res);
  112. $this->type = $row['lp_type'];
  113. $this->name = stripslashes($row['name']);
  114. $this->encoding = $row['default_encoding'];
  115. $this->proximity = $row['content_local'];
  116. $this->theme = $row['theme'];
  117. $this->maker = $row['content_maker'];
  118. $this->prevent_reinit = $row['prevent_reinit'];
  119. $this->license = $row['content_license'];
  120. $this->scorm_debug = $row['debug'];
  121. $this->js_lib = $row['js_lib'];
  122. $this->path = $row['path'];
  123. if($this->type == 2){
  124. if($row['force_commit'] == 1){
  125. $this->force_commit = true;
  126. }
  127. }
  128. $this->mode = $row['default_view_mod'];
  129. }
  130. else
  131. {
  132. $this->error = 'Learnpath ID does not exist in database ('.$sql.')';
  133. return false;
  134. }
  135. }
  136. //check user ID
  137. if(empty($user_id)){
  138. $this->error = 'User ID is empty';
  139. return false;
  140. }
  141. else
  142. {
  143. //$main_table = Database::get_main_user_table();
  144. $main_table = Database::get_main_table(TABLE_MAIN_USER);
  145. //$user_id = Database::escape_integer($user_id);
  146. $user_id = $this->escape_string($user_id);
  147. $sql = "SELECT * FROM $main_table WHERE user_id = '$user_id'";
  148. if($this->debug>2){error_log('New LP - learnpath::learnpath() '.__LINE__.' - Querying user: '.$sql,0);}
  149. //$res = Database::query($sql);
  150. $res = api_sql_query($sql);
  151. if(Database::num_rows($res)>0)
  152. {
  153. $this->user_id = $user_id;
  154. }
  155. else
  156. {
  157. $this->error = 'User ID does not exist in database ('.$sql.')';
  158. return false;
  159. }
  160. }
  161. //end of variables checking
  162. //now get the latest attempt from this user on this LP, if available, otherwise create a new one
  163. $lp_table = Database::get_course_table(TABLE_LP_VIEW);
  164. //selecting by view_count descending allows to get the highest view_count first
  165. $sql = "SELECT * FROM $lp_table WHERE lp_id = '$lp_id' AND user_id = '$user_id' ORDER BY view_count DESC";
  166. if($this->debug>2){error_log('New LP - learnpath::learnpath() '.__LINE__.' - querying lp_view: '.$sql,0);}
  167. //$res = Database::query($sql);
  168. $res = api_sql_query($sql);
  169. $view_id = 0; //used later to query lp_item_view
  170. if(Database::num_rows($res)>0)
  171. {
  172. if($this->debug>2){error_log('New LP - learnpath::learnpath() '.__LINE__.' - Found previous view',0);}
  173. $row = Database::fetch_array($res);
  174. $this->attempt = $row['view_count'];
  175. $this->lp_view_id = $row['id'];
  176. $this->last_item_seen = $row['last_item'];
  177. $this->progress_db = $row['progress'];
  178. }
  179. else
  180. {
  181. if($this->debug>2){error_log('New LP - learnpath::learnpath() '.__LINE__.' - NOT Found previous view',0);}
  182. $this->attempt = 1;
  183. $sql_ins = "INSERT INTO $lp_table (lp_id,user_id,view_count) VALUES ($lp_id,$user_id,1)";
  184. $res_ins = api_sql_query($sql_ins);
  185. $this->lp_view_id = Database::get_last_insert_id();
  186. if($this->debug>2){error_log('New LP - learnpath::learnpath() '.__LINE__.' - inserting new lp_view: '.$sql_ins,0);}
  187. }
  188. //initialise items
  189. $lp_item_table = Database::get_course_table(TABLE_LP_ITEM);
  190. $sql = "SELECT * FROM $lp_item_table WHERE lp_id = '".$this->lp_id."' ORDER BY parent_item_id, display_order";
  191. $res = api_sql_query($sql);
  192. while($row = Database::fetch_array($res))
  193. {
  194. $oItem = '';
  195. //$this->ordered_items[] = $row['id'];
  196. switch($this->type){
  197. case 3: //aicc
  198. $oItem = new aiccItem('db',$row['id']);
  199. if(is_object($oItem)){
  200. $my_item_id = $oItem->get_id();
  201. $oItem->set_lp_view($this->lp_view_id);
  202. $oItem->set_prevent_reinit($this->prevent_reinit);
  203. // Don't use reference here as the next loop will make the pointed object change
  204. $this->items[$my_item_id] = $oItem;
  205. $this->refs_list[$oItem->ref]=$my_item_id;
  206. if($this->debug>2){error_log('New LP - learnpath::learnpath() - aicc object with id '.$my_item_id.' set in items[]',0);}
  207. }
  208. break;
  209. case 2:
  210. require_once('scorm.class.php');
  211. require_once('scormItem.class.php');
  212. $oItem = new scormItem('db',$row['id']);
  213. if(is_object($oItem)){
  214. $my_item_id = $oItem->get_id();
  215. $oItem->set_lp_view($this->lp_view_id);
  216. $oItem->set_prevent_reinit($this->prevent_reinit);
  217. // Don't use reference here as the next loop will make the pointed object change
  218. $this->items[$my_item_id] = $oItem;
  219. $this->refs_list[$oItem->ref]=$my_item_id;
  220. if($this->debug>2){error_log('New LP - object with id '.$my_item_id.' set in items[]',0);}
  221. }
  222. break;
  223. case 1:
  224. default:
  225. require_once('learnpathItem.class.php');
  226. $oItem = new learnpathItem($row['id'],$user_id);
  227. if(is_object($oItem)){
  228. $my_item_id = $oItem->get_id();
  229. //$oItem->set_lp_view($this->lp_view_id); moved down to when we are sure the item_view exists
  230. $oItem->set_prevent_reinit($this->prevent_reinit);
  231. // Don't use reference here as the next loop will make the pointed object change
  232. $this->items[$my_item_id] = $oItem;
  233. $this->refs_list[$my_item_id]=$my_item_id;
  234. if($this->debug>2){error_log('New LP - learnpath::learnpath() '.__LINE__.' - object with id '.$my_item_id.' set in items[]',0);}
  235. }
  236. break;
  237. }
  238. //items is a list of pointers to all items, classified by DB ID, not SCO id
  239. if($row['parent_item_id'] == 0 OR empty($this->items[$row['parent_item_id']])){
  240. $this->items[$row['id']]->set_level(0);
  241. }else{
  242. $level = $this->items[$row['parent_item_id']]->get_level()+1;
  243. $this->items[$row['id']]->set_level($level);
  244. if(is_object($this->items[$row['parent_item_id']])){
  245. //items is a list of pointers from item DB ids to item objects
  246. $this->items[$row['parent_item_id']]->add_child($row['id']);
  247. }else{
  248. if($this->debug>2){error_log('New LP - learnpath::learnpath() '.__LINE__.' - The parent item ('.$row['parent_item_id'].') of item '.$row['id'].' could not be found',0);}
  249. }
  250. }
  251. //get last viewing vars
  252. $lp_item_view_table = Database::get_course_table(TABLE_LP_ITEM_VIEW);
  253. //this query should only return one or zero result
  254. $sql = "SELECT * " .
  255. "FROM $lp_item_view_table " .
  256. "WHERE lp_view_id = ".$this->lp_view_id." " .
  257. "AND lp_item_id = ".$row['id']." ORDER BY view_count DESC ";
  258. if($this->debug>2){error_log('New LP - learnpath::learnpath() - Selecting item_views: '.$sql,0);}
  259. //get the item status
  260. $res2 = api_sql_query($sql);
  261. if(Database::num_rows($res2)>0)
  262. {
  263. //if this learnpath has already been used by this user, get his last attempt count and
  264. //the last item seen back into this object
  265. //$max = 0;
  266. $row2 = Database::fetch_array($res2);
  267. if($this->debug>2){error_log('New LP - learnpath::learnpath() - Got item_view: '.print_r($row2,true),0);}
  268. $this->items[$row['id']]->set_status($row2['status']);
  269. if(empty($row2['status'])){
  270. $this->items[$row['id']]->set_status($this->default_status);
  271. }
  272. //$this->attempt = $row['view_count'];
  273. //$this->last_item = $row['id'];
  274. }
  275. else //no item found in lp_item_view for this view
  276. {
  277. //first attempt from this user. Set attempt to 1 and last_item to 0 (first item available)
  278. //TODO if the learnpath has not got attempts activated, always use attempt '1'
  279. //$this->attempt = 1;
  280. //$this->last_item = 0;
  281. $this->items[$row['id']]->set_status($this->default_status);
  282. //Add that row to the lp_item_view table so that we have something to show in the stats page
  283. $sql_ins = "INSERT INTO $lp_item_view_table " .
  284. "(lp_item_id, lp_view_id, view_count, status) VALUES " .
  285. "(".$row['id'].",".$this->lp_view_id.",1,'not attempted')";
  286. if($this->debug>2){error_log('New LP - learnpath::learnpath() '.__LINE__.' - Inserting blank item_view : '.$sql_ins,0);}
  287. $res_ins = api_sql_query($sql_ins);
  288. }
  289. //setting the view in the item object
  290. $this->items[$row['id']]->set_lp_view($this->lp_view_id);
  291. }
  292. $this->ordered_items = $this->get_flat_ordered_items_list($this->get_id(),0);
  293. $this->max_ordered_items = 0;
  294. foreach($this->ordered_items as $index=>$dummy){
  295. if($index > $this->max_ordered_items AND !empty($dummy)){
  296. $this->max_ordered_items = $index;
  297. }
  298. }
  299. //TODO define the current item better
  300. $this->first();
  301. if($this->debug>2){error_log('New LP - learnpath::learnpath() '.__LINE__.' - End of learnpath constructor for learnpath '.$this->get_id(),0);}
  302. }
  303. /**
  304. * Function rewritten based on old_add_item() from Yannick Warnier. Due the fact that users can decide where the item should come, I had to overlook this function and
  305. * I found it better to rewrite it. Old function is still available. Added also the possibility to add a description.
  306. *
  307. * @param int $parent
  308. * @param int $previous
  309. * @param string $type
  310. * @param int $id
  311. * @param string $title
  312. * @param string $description
  313. * @return int
  314. */
  315. function add_item($parent, $previous, $type = 'dokeos_chapter', $id, $title, $description, $prerequisites=0)
  316. {
  317. if($this->debug>0){error_log('New LP - In learnpath::add_item('.$parent.','.$previous.','.$type.','.$id.','.$title.')',0);}
  318. $tbl_lp_item = Database::get_course_table('lp_item');
  319. $parent = intval($parent);
  320. $previous = intval($previous);
  321. $type = $this->escape_string($type);
  322. $id = intval($id);
  323. $title = $this->escape_string(htmlentities($title));
  324. $description = $this->escape_string(htmlentities($description));
  325. $sql_count = "
  326. SELECT COUNT(id) AS num
  327. FROM " . $tbl_lp_item . "
  328. WHERE
  329. lp_id = " . $this->get_id() . " AND
  330. parent_item_id = " . $parent;
  331. $res_count = api_sql_query($sql_count, __FILE__, __LINE__);
  332. $row = Database::fetch_array($res_count);
  333. $num = $row['num'];
  334. if($num > 0)
  335. {
  336. if($previous == 0)
  337. {
  338. $sql = "
  339. SELECT
  340. id,
  341. next_item_id,
  342. display_order
  343. FROM " . $tbl_lp_item . "
  344. WHERE
  345. lp_id = " . $this->get_id() . " AND
  346. parent_item_id = " . $parent . " AND
  347. previous_item_id = 0 OR previous_item_id=".$parent;
  348. $result = api_sql_query($sql, __FILE__, __LINE__);
  349. $row = Database::fetch_array($result);
  350. $tmp_previous = 0;
  351. $next = $row['id'];
  352. $display_order = 0;
  353. }
  354. else
  355. {
  356. $previous = (int) $previous;
  357. $sql = "
  358. SELECT
  359. id,
  360. previous_item_id,
  361. next_item_id,
  362. display_order
  363. FROM " . $tbl_lp_item . "
  364. WHERE
  365. lp_id = " . $this->get_id() . " AND
  366. id = " . $previous;
  367. $result = api_sql_query($sql, __FILE__, __LINE__);
  368. $row = Database::fetch_array($result);
  369. $tmp_previous = $row['id'];
  370. $next = $row['next_item_id'];
  371. $display_order = $row['display_order'];
  372. }
  373. }
  374. else
  375. {
  376. $tmp_previous = 0;
  377. $next = 0;
  378. $display_order = 0;
  379. }
  380. $new_item_id = -1;
  381. $id = $this->escape_string($id);
  382. if($type == 'quiz')
  383. {
  384. $sql = 'SELECT SUM(ponderation)
  385. FROM '.Database :: get_course_table(TABLE_QUIZ_QUESTION).' as quiz_question
  386. INNER JOIN '.Database :: get_course_table(TABLE_QUIZ_TEST_QUESTION).' as quiz_rel_question
  387. ON quiz_question.id = quiz_rel_question.question_id
  388. AND quiz_rel_question.exercice_id = '.$id;
  389. $rsQuiz = api_sql_query($sql, __FILE__, __LINE__);
  390. $max_score = mysql_result($rsQuiz, 0, 0);
  391. }
  392. else
  393. {
  394. $max_score = 100;
  395. }
  396. if($prerequisites!=0){
  397. $sql_ins = "
  398. INSERT INTO " . $tbl_lp_item . " (
  399. lp_id,
  400. item_type,
  401. ref,
  402. title,
  403. description,
  404. path,
  405. max_score,
  406. parent_item_id,
  407. previous_item_id,
  408. next_item_id,
  409. display_order,
  410. prerequisite
  411. ) VALUES (
  412. " . $this->get_id() . ",
  413. '" . $type . "',
  414. '',
  415. '" . $title . "',
  416. '" . $description . "',
  417. '" . $id . "',
  418. '" . $max_score. "',
  419. " . $parent . ",
  420. " . $previous . ",
  421. " . $next . ",
  422. " . ($display_order + 1) . ",
  423. " . $prerequisites . "
  424. )";
  425. }
  426. else{
  427. //insert new item
  428. $sql_ins = "
  429. INSERT INTO " . $tbl_lp_item . " (
  430. lp_id,
  431. item_type,
  432. ref,
  433. title,
  434. description,
  435. path,
  436. max_score,
  437. parent_item_id,
  438. previous_item_id,
  439. next_item_id,
  440. display_order
  441. ) VALUES (
  442. " . $this->get_id() . ",
  443. '" . $type . "',
  444. '',
  445. '" . $title . "',
  446. '" . $description . "',
  447. '" . $id . "',
  448. '" . $max_score. "',
  449. " . $parent . ",
  450. " . $previous . ",
  451. " . $next . ",
  452. " . ($display_order + 1) . "
  453. )";
  454. }
  455. if($this->debug>2){error_log('New LP - Inserting dokeos_chapter: '.$sql_ins,0);}
  456. $res_ins = api_sql_query($sql_ins, __FILE__, __LINE__);
  457. if($res_ins > 0)
  458. {
  459. $new_item_id = Database::get_last_insert_id($res_ins);
  460. //update the item that should come after the new item
  461. $sql_update_next = "
  462. UPDATE " . $tbl_lp_item . "
  463. SET previous_item_id = " . $new_item_id . "
  464. WHERE id = " . $next;
  465. $res_update_next = api_sql_query($sql_update_next, __FILE__, __LINE__);
  466. //update the item that should be before the new item
  467. $sql_update_previous = "
  468. UPDATE " . $tbl_lp_item . "
  469. SET next_item_id = " . $new_item_id . "
  470. WHERE id = " . $tmp_previous;
  471. $res_update_previous = api_sql_query($sql_update_previous, __FILE__, __LINE__);
  472. //update all the items after the new item
  473. $sql_update_order = "
  474. UPDATE " . $tbl_lp_item . "
  475. SET display_order = display_order + 1
  476. WHERE
  477. lp_id = " . $this->get_id() . " AND
  478. id <> " . $new_item_id . " AND
  479. parent_item_id = " . $parent . " AND
  480. display_order > " . $display_order;
  481. $res_update_previous = api_sql_query($sql_update_order, __FILE__, __LINE__);
  482. //update the item that should come after the new item
  483. $sql_update_ref = "
  484. UPDATE " . $tbl_lp_item . "
  485. SET ref = " . $new_item_id . "
  486. WHERE id = " . $new_item_id;
  487. api_sql_query($sql_update_ref, __FILE__, __LINE__);
  488. }
  489. return $new_item_id;
  490. }
  491. /**
  492. * Static admin function allowing addition of a learnpath to a course.
  493. * @param string Course code
  494. * @param string Learnpath name
  495. * @param string Learnpath description string, if provided
  496. * @param string Type of learnpath (default = 'guess', others = 'dokeos', 'aicc',...)
  497. * @param string Type of files origin (default = 'zip', others = 'dir','web_dir',...)
  498. * @param string Zip file containing the learnpath or directory containing the learnpath
  499. * @return integer The new learnpath ID on success, 0 on failure
  500. */
  501. function add_lp($course,$name,$description='',$learnpath='guess',$origin='zip',$zipname='')
  502. {
  503. //if($this->debug>0){error_log('New LP - In learnpath::add_lp()',0);}
  504. //TODO
  505. $tbl_lp = Database::get_course_table('lp');
  506. //check course code exists
  507. //check lp_name doesn't exist, otherwise append something
  508. $i = 0;
  509. $name = learnpath::escape_string(htmlentities($name)); //Kevin Van Den Haute: added htmlentities()
  510. $check_name = "SELECT * FROM $tbl_lp WHERE name = '$name'";
  511. //if($this->debug>2){error_log('New LP - Checking the name for new LP: '.$check_name,0);}
  512. $res_name = api_sql_query($check_name);
  513. while(Database::num_rows($res_name)){
  514. //there is already one such name, update the current one a bit
  515. $i++;
  516. $name = $name.' - '.$i;
  517. $check_name = "SELECT * FROM $tbl_lp WHERE name = '$name'";
  518. //if($this->debug>2){error_log('New LP - Checking the name for new LP: '.$check_name,0);}
  519. $res_name = api_sql_query($check_name);
  520. }
  521. //new name does not exist yet; keep it
  522. //escape description
  523. $description = learnpath::escape_string(htmlentities($description)); //Kevin: added htmlentities()
  524. $type = 1;
  525. switch($learnpath){
  526. case 'guess':
  527. break;
  528. case 'dokeos':
  529. $type = 1;
  530. break;
  531. case 'aicc':
  532. break;
  533. }
  534. switch($origin){
  535. case 'zip':
  536. //check zipname string. If empty, we are currently creating a new Dokeos learnpath
  537. break;
  538. case 'manual':
  539. default:
  540. $get_max = "SELECT MAX(display_order) FROM $tbl_lp";
  541. $res_max = api_sql_query($get_max);
  542. if(Database::num_rows($res_max)<1){
  543. $dsp = 1;
  544. }else{
  545. $row = Database::fetch_array($res_max);
  546. $dsp = $row[0]+1;
  547. }
  548. $sql_insert = "INSERT INTO $tbl_lp " .
  549. "(lp_type,name,description,path,default_view_mod," .
  550. "default_encoding,display_order,content_maker," .
  551. "content_local,js_lib) " .
  552. "VALUES ($type,'$name','$description','','embedded'," .
  553. "'UTF-8','$dsp','Dokeos'," .
  554. "'local','')";
  555. //if($this->debug>2){error_log('New LP - Inserting new lp '.$sql_insert,0);}
  556. $res_insert = api_sql_query($sql_insert);
  557. $id = Database::get_last_insert_id();
  558. if($id>0){
  559. //insert into item_property
  560. api_item_property_update(api_get_course_info(),TOOL_LEARNPATH,$id,'LearnpathAdded',api_get_user_id());
  561. return $id;
  562. }
  563. break;
  564. }
  565. }
  566. /**
  567. * Appends a message to the message attribute
  568. * @param string Message to append.
  569. */
  570. function append_message($string)
  571. {
  572. if($this->debug>0){error_log('New LP - In learnpath::append_message()',0);}
  573. $this->message .= $string;
  574. }
  575. /**
  576. * Autocompletes the parents of an item in case it's been completed or passed
  577. * @param integer Optional ID of the item from which to look for parents
  578. */
  579. function autocomplete_parents($item)
  580. {
  581. if($this->debug>0){error_log('New LP - In learnpath::autocomplete_parents()',0);}
  582. if(empty($item)){
  583. $item = $this->current;
  584. }
  585. $parent_id = $this->items[$item]->get_parent();
  586. if($this->debug>2){error_log('New LP - autocompleting parent of item '.$item.' (item '.$parent_id.')',0);}
  587. if(is_object($this->items[$item]) and !empty($parent_id))
  588. {//if $item points to an object and there is a parent
  589. if($this->debug>2){error_log('New LP - '.$item.' is an item, proceed',0);}
  590. $current_item =& $this->items[$item];
  591. $parent =& $this->items[$parent_id]; //get the parent
  592. //new experiment including failed and browsed in completed status
  593. $current_status = $current_item->get_status();
  594. if($current_item->is_done() || $current_status=='browsed' || $current_status=='failed')
  595. {
  596. //if the current item is completed or passes or succeeded
  597. $completed = true;
  598. if($this->debug>2){error_log('New LP - Status of current item is alright',0);}
  599. foreach($parent->get_children() as $child)
  600. {
  601. //check all his brothers (his parent's children) for completion status
  602. if($child!= $item)
  603. {
  604. if($this->debug>2){error_log('New LP - Looking at brother with ID '.$child.', status is '.$this->items[$child]->get_status(),0);}
  605. //if($this->items[$child]->status_is(array('completed','passed','succeeded')))
  606. //Trying completing parents of failed and browsed items as well
  607. if($this->items[$child]->status_is(array('completed','passed','succeeded','browsed','failed')))
  608. {
  609. //keep completion status to true
  610. }else{
  611. if($this->debug>2){error_log('New LP - Found one incomplete child of '.$parent_id.': '.$child.' is '.$this->items[$child]->get_status(),0);}
  612. $completed = false;
  613. }
  614. }
  615. }
  616. if($completed == true)
  617. { //if all the children were completed
  618. $parent->set_status('completed');
  619. $parent->save(false,$this->prerequisites_match($parent->get_id()));
  620. $this->update_queue[$parent->get_id()] = $parent->get_status();
  621. if($this->debug>2){error_log('New LP - Added parent to update queue '.print_r($this->update_queue,true),0);}
  622. $this->autocomplete_parents($parent->get_id()); //recursive call
  623. }
  624. }else{
  625. //error_log('New LP - status of current item is not enough to get bothered with it',0);
  626. }
  627. }
  628. }
  629. /**
  630. * Autosaves the current results into the database for the whole learnpath
  631. */
  632. function autosave()
  633. {
  634. if($this->debug>0){error_log('New LP - In learnpath::autosave()',0);}
  635. //TODO add aditionnal save operations for the learnpath itself
  636. }
  637. /**
  638. * Clears the message attribute
  639. */
  640. function clear_message()
  641. {
  642. if($this->debug>0){error_log('New LP - In learnpath::clear_message()',0);}
  643. $this->message = '';
  644. }
  645. /**
  646. * Closes the current resource
  647. *
  648. * Stops the timer
  649. * Saves into the database if required
  650. * Clears the current resource data from this object
  651. * @return boolean True on success, false on failure
  652. */
  653. function close()
  654. {
  655. if($this->debug>0){error_log('New LP - In learnpath::close()',0);}
  656. if(empty($this->lp_id))
  657. {
  658. $this->error = 'Trying to close this learnpath but no ID is set';
  659. return false;
  660. }
  661. $this->current_time_stop = time();
  662. if($this->save)
  663. {
  664. $learnpath_view_table = Database::get_course_table(TABLE_LP_VIEW);
  665. /*
  666. $sql = "UPDATE $learnpath_view_table " .
  667. "SET " .
  668. "stop_time = ".$this->current_time_stop.", " .
  669. "score = ".$this->current_score.", ".
  670. "WHERE learnpath_id = '".$this->lp_id."'";
  671. //$res = Database::query($sql);
  672. $res = api_sql_query($res);
  673. if(mysql_affected_rows($res)<1)
  674. {
  675. $this->error = 'Could not update learnpath_view table while closing learnpath';
  676. return false;
  677. }
  678. */
  679. }
  680. $this->ordered_items = array();
  681. $this->index=0;
  682. unset($this->lp_id);
  683. //unset other stuff
  684. return true;
  685. }
  686. /**
  687. * Static admin function allowing removal of a learnpath
  688. * @param string Course code
  689. * @param integer Learnpath ID
  690. * @param string Whether to delete data or keep it (default: 'keep', others: 'remove')
  691. * @return boolean True on success, false on failure (might change that to return number of elements deleted)
  692. */
  693. function delete($course=null,$id=null,$delete='keep')
  694. {
  695. //TODO implement a way of getting this to work when the current object is not set
  696. //In clear: implement this in the item class as well (abstract class) and use the given ID in queries
  697. //if(empty($course)){$course = api_get_course_id();}
  698. //if(empty($id)){$id = $this->get_id();}
  699. //If an ID is specifically given and the current LP is not the same,
  700. //prevent delete
  701. if(!empty($id) && ($id != $this->lp_id)){return false;}
  702. //if($this->debug>0){error_log('New LP - In learnpath::delete()',0);}
  703. foreach($this->items as $id => $dummy)
  704. {
  705. $this->items[$id]->delete();
  706. }
  707. $lp = Database::get_course_table('lp');
  708. $lp_view = Database::get_course_table('lp_view');
  709. $sql_del_view = "DELETE FROM $lp_view WHERE lp_id = ".$this->lp_id;
  710. //if($this->debug>2){error_log('New LP - Deleting views bound to lp '.$this->lp_id.': '.$sql_del_view,0);}
  711. $res_del_view = api_sql_query($sql_del_view);
  712. $this->toggle_publish($this->lp_id,'i');
  713. //if($this->debug>2){error_log('New LP - Deleting lp '.$this->lp_id.' of type '.$this->type,0);}
  714. if($this->type == 2 OR $this->type==3){
  715. //this is a scorm learning path, delete the files as well
  716. $sql = "SELECT path FROM $lp WHERE id = ".$this->lp_id;
  717. $res = api_sql_query($sql);
  718. if(Database::num_rows($res)>0){
  719. $row = Database::fetch_array($res);
  720. $path = $row['path'];
  721. $sql = "SELECT id FROM $lp WHERE path = '$path' AND id != ".$this->lp_id;
  722. $res = api_sql_query($sql);
  723. if(Database::num_rows($res)>0)
  724. { //another learning path uses this directory, so don't delete it
  725. if($this->debug>2){error_log('New LP - In learnpath::delete(), found other LP using path '.$path.', keeping directory',0);}
  726. }else{
  727. //no other LP uses that directory, delete it
  728. $course_rel_dir = api_get_course_path().'/scorm/'; //scorm dir web path starting from /courses
  729. $course_scorm_dir = api_get_path(SYS_COURSE_PATH).$course_rel_dir; //absolute system path for this course
  730. if($delete == 'remove' && is_dir($course_scorm_dir.$path) and !empty($course_scorm_dir)){
  731. if($this->debug>2){error_log('New LP - In learnpath::delete(), found SCORM, deleting directory: '.$course_scorm_dir.$path,0);}
  732. exec('rm -rf '.$course_scorm_dir.$path);
  733. }
  734. }
  735. }
  736. }
  737. $sql_del_lp = "DELETE FROM $lp WHERE id = ".$this->lp_id;
  738. //if($this->debug>2){error_log('New LP - Deleting lp '.$this->lp_id.': '.$sql_del_lp,0);}
  739. $res_del_lp = api_sql_query($sql_del_lp);
  740. $this->update_display_order();//updates the display order of all lps
  741. api_item_property_update(api_get_course_info(),TOOL_LEARNPATH,$this->lp_id,'delete',api_get_user_id());
  742. //TODO: also delete items and item-views
  743. }
  744. /**
  745. * Removes all the children of one item - dangerous!
  746. * @param integer Element ID of which children have to be removed
  747. * @return integer Total number of children removed
  748. */
  749. function delete_children_items($id){
  750. if($this->debug>0){error_log('New LP - In learnpath::delete_children_items('.$id.')',0);}
  751. $num = 0;
  752. if(empty($id) || $id != strval(intval($id))){return false;}
  753. $lp_item = Database::get_course_table('lp_item');
  754. $sql = "SELECT * FROM $lp_item WHERE parent_item_id = $id";
  755. $res = api_sql_query($sql);
  756. while($row = Database::fetch_array($res)){
  757. $num += $this->delete_children_items($row['id']);
  758. $sql_del = "DELETE FROM $lp_item WHERE id = ".$row['id'];
  759. $res_del = api_sql_query($sql_del);
  760. $num++;
  761. }
  762. return $num;
  763. }
  764. /**
  765. * Removes an item from the current learnpath
  766. * @param integer Elem ID (0 if first)
  767. * @param integer Whether to remove the resource/data from the system or leave it (default: 'keep', others 'remove')
  768. * @return integer Number of elements moved
  769. * @todo implement resource removal
  770. */
  771. function delete_item($id, $remove='keep')
  772. {
  773. if($this->debug>0){error_log('New LP - In learnpath::delete_item()',0);}
  774. //TODO - implement the resource removal
  775. if(empty($id) || $id != strval(intval($id))){return false;}
  776. //first select item to get previous, next, and display order
  777. $lp_item = Database::get_course_table('lp_item');
  778. $sql_sel = "SELECT * FROM $lp_item WHERE id = $id";
  779. $res_sel = api_sql_query($sql_sel,__FILE__,__LINE__);
  780. if(Database::num_rows($res_sel)<1){return false;}
  781. $row = Database::fetch_array($res_sel);
  782. $previous = $row['previous_item_id'];
  783. $next = $row['next_item_id'];
  784. $display = $row['display_order'];
  785. $parent = $row['parent_item_id'];
  786. $lp = $row['lp_id'];
  787. //delete children items
  788. $num = $this->delete_children_items($id);
  789. if($this->debug>2){error_log('New LP - learnpath::delete_item() - deleted '.$num.' children of element '.$id,0);}
  790. //now delete the item
  791. $sql_del = "DELETE FROM $lp_item WHERE id = $id";
  792. if($this->debug>2){error_log('New LP - Deleting item: '.$sql_del,0);}
  793. $res_del = api_sql_query($sql_del,__FILE__,__LINE__);
  794. //now update surrounding items
  795. $sql_upd = "UPDATE $lp_item SET next_item_id = $next WHERE id = $previous";
  796. $res_upd = api_sql_query($sql_upd,__FILE__,__LINE__);
  797. $sql_upd = "UPDATE $lp_item SET previous_item_id = $previous WHERE id = $next";
  798. $res_upd = api_sql_query($sql_upd,__FILE__,__LINE__);
  799. //now update all following items with new display order
  800. $sql_all = "UPDATE $lp_item SET display_order = display_order-1 WHERE lp_id = $lp AND parent_item_id = $parent AND display_order > $display";
  801. $res_all = api_sql_query($sql_all,__FILE__,__LINE__);
  802. }
  803. /**
  804. * Updates an item's content in place
  805. * @param integer Element ID
  806. * @param string New content
  807. * @return boolean True on success, false on error
  808. */
  809. function edit_item($id, $parent, $previous, $title, $description, $prerequisites=0)
  810. {
  811. if($this->debug > 0){error_log('New LP - In learnpath::edit_item()', 0);}
  812. if(empty($id) or ($id != strval(intval($id))) or empty($title)){ return false; }
  813. $tbl_lp_item = Database::get_course_table('lp_item');
  814. $sql_select = "
  815. SELECT *
  816. FROM " . $tbl_lp_item . "
  817. WHERE id = " . $id;
  818. $res_select = api_sql_query($sql_select, __FILE__, __LINE__);
  819. $row_select = Database::fetch_array($res_select);
  820. $same_parent = ($row_select['parent_item_id'] == $parent) ? true : false;
  821. $same_previous = ($row_select['previous_item_id'] == $previous) ? true : false;
  822. if($same_parent && $same_previous)
  823. {
  824. //only update title and description
  825. $sql_update = "
  826. UPDATE " . $tbl_lp_item . "
  827. SET
  828. title = '" . $this->escape_string(htmlentities($title)) . "',
  829. prerequisite = '".$prerequisites."',
  830. description = '" . $this->escape_string(htmlentities($description)) . "'
  831. WHERE id = " . $id;
  832. $res_update = api_sql_query($sql_update, __FILE__, __LINE__);
  833. }
  834. else
  835. {
  836. $old_parent = $row_select['parent_item_id'];
  837. $old_previous = $row_select['previous_item_id'];
  838. $old_next = $row_select['next_item_id'];
  839. $old_order = $row_select['display_order'];
  840. $old_prerequisite= $row_select['prerequisite'];
  841. /* BEGIN -- virtually remove the current item id */
  842. /* for the next and previous item it is like the current item doesn't exist anymore */
  843. if($old_previous != 0)
  844. {
  845. $sql_update_next = "
  846. UPDATE " . $tbl_lp_item . "
  847. SET next_item_id = " . $old_next . "
  848. WHERE id = " . $old_previous;
  849. $res_update_next = api_sql_query($sql_update_next, __FILE__, __LINE__);
  850. //echo '<p>' . $sql_update_next . '</p>';
  851. }
  852. if($old_next != 0)
  853. {
  854. $sql_update_previous = "
  855. UPDATE " . $tbl_lp_item . "
  856. SET previous_item_id = " . $old_previous . "
  857. WHERE id = " . $old_next;
  858. $res_update_previous = api_sql_query($sql_update_previous, __FILE__, __LINE__);
  859. //echo '<p>' . $sql_update_previous . '</p>';
  860. }
  861. //display_order - 1 for every item with a display_order bigger then the display_order of the current item
  862. $sql_update_order = "
  863. UPDATE " . $tbl_lp_item . "
  864. SET display_order = display_order - 1
  865. WHERE
  866. display_order > " . $old_order . " AND
  867. parent_item_id = " . $old_parent;
  868. $res_update_order = api_sql_query($sql_update_order, __FILE__, __LINE__);
  869. //echo '<p>' . $sql_update_order . '</p>';
  870. /* END -- virtually remove the current item id */
  871. /* BEGIN -- update the current item id to his new location */
  872. if($previous == 0)
  873. {
  874. //select the data of the item that should come after the current item
  875. $sql_select_old = "
  876. SELECT
  877. id,
  878. display_order
  879. FROM " . $tbl_lp_item . "
  880. WHERE
  881. lp_id = " . $this->lp_id . " AND
  882. parent_item_id = " . $parent . " AND
  883. previous_item_id = " . $previous;
  884. $res_select_old = api_sql_query($sql_select_old, __FILE__, __LINE__);
  885. $row_select_old = Database::fetch_array($res_select_old);
  886. //echo '<p>' . $sql_select_old . '</p>';
  887. //if the new parent didn't have children before
  888. if(Database::num_rows($res_select_old) == 0)
  889. {
  890. $new_next = 0;
  891. $new_order = 1;
  892. }
  893. else
  894. {
  895. $new_next = $row_select_old['id'];
  896. $new_order = $row_select_old['display_order'];
  897. }
  898. //echo 'New next_item_id of current item: ' . $new_next . '<br />';
  899. //echo 'New previous_item_id of current item: ' . $previous . '<br />';
  900. //echo 'New display_order of current item: ' . $new_order . '<br />';
  901. }
  902. else
  903. {
  904. //select the data of the item that should come before the current item
  905. $sql_select_old = "
  906. SELECT
  907. next_item_id,
  908. display_order
  909. FROM " . $tbl_lp_item . "
  910. WHERE id = " . $previous;
  911. $res_select_old = api_sql_query($sql_select_old, __FILE__, __LINE__);
  912. $row_select_old = Database::fetch_array($res_select_old);
  913. //echo '<p>' . $sql_select_old . '</p>';
  914. //echo 'New next_item_id of current item: ' . $row_select_old['next_item_id'] . '<br />';
  915. //echo 'New previous_item_id of current item: ' . $previous . '<br />';
  916. //echo 'New display_order of current item: ' . ($row_select_old['display_order'] + 1) . '<br />';
  917. $new_next = $row_select_old['next_item_id'];
  918. $new_order = $row_select_old['display_order'] + 1;
  919. }
  920. //update the current item with the new data
  921. $sql_update = "
  922. UPDATE " . $tbl_lp_item . "
  923. SET
  924. title = '" . $this->escape_string(htmlentities($title)) . "',
  925. description = '" . $this->escape_string(htmlentities($description)) . "',
  926. parent_item_id = " . $parent . ",
  927. previous_item_id = " . $previous . ",
  928. next_item_id = " . $new_next . ",
  929. display_order = " . $new_order . "
  930. WHERE id = " . $id;
  931. $res_update_next = api_sql_query($sql_update, __FILE__, __LINE__);
  932. //echo '<p>' . $sql_update . '</p>';
  933. if($previous != 0)
  934. {
  935. //update the previous item's next_item_id
  936. $sql_update_previous = "
  937. UPDATE " . $tbl_lp_item . "
  938. SET next_item_id = " . $id . "
  939. WHERE id = " . $previous;
  940. $res_update_next = api_sql_query($sql_update_previous, __FILE__, __LINE__);
  941. //echo '<p>' . $sql_update_previous . '</p>';
  942. }
  943. if($new_next != 0)
  944. {
  945. //update the next item's previous_item_id
  946. $sql_update_next = "
  947. UPDATE " . $tbl_lp_item . "
  948. SET previous_item_id = " . $id . "
  949. WHERE id = " . $new_next;
  950. $res_update_next = api_sql_query($sql_update_next, __FILE__, __LINE__);
  951. //echo '<p>' . $sql_update_next . '</p>';
  952. }
  953. if($old_prerequisite!=$prerequisites){
  954. $sql_update_next = "
  955. UPDATE " . $tbl_lp_item . "
  956. SET prerequisite = " . $prerequisites . "
  957. WHERE id = " . $id;
  958. $res_update_next = api_sql_query($sql_update_next, __FILE__, __LINE__);
  959. }
  960. //update all the items with the same or a bigger display_order than
  961. //the current item
  962. $sql_update_order = "
  963. UPDATE " . $tbl_lp_item . "
  964. SET display_order = display_order + 1
  965. WHERE
  966. lp_id = " . $this->get_id() . " AND
  967. id <> " . $id . " AND
  968. parent_item_id = " . $parent . " AND
  969. display_order >= " . $new_order;
  970. $res_update_next = api_sql_query($sql_update_order, __FILE__, __LINE__);
  971. //echo '<p>' . $sql_update_order . '</p>';
  972. /* END -- update the current item id to his new location */
  973. }
  974. }
  975. /**
  976. * Updates an item's prereq in place
  977. * @param integer Element ID
  978. * @param string Prerequisite Element ID
  979. *
  980. * @param string Prerequisite item type
  981. *
  982. * @param string Prerequisite min score
  983. *
  984. * @param string Prerequisite max score
  985. * @return boolean True on success, false on error
  986. */
  987. function edit_item_prereq($id, $prerequisite_id, $mastery_score = 0, $max_score = 100)
  988. {
  989. if($this->debug>0){error_log('New LP - In learnpath::edit_item_prereq('.$id.','.$prerequisite_id.','.$mastery_score.','.$max_score.')',0);}
  990. if(empty($id) or ($id != strval(intval($id))) or empty($prerequisite_id)){ return false; }
  991. $prerequisite_id = $this->escape_string($prerequisite_id);
  992. $tbl_lp_item = Database::get_course_table('lp_item');
  993. if(!is_numeric($mastery_score) || $mastery_score < 0)
  994. $mastery_score = 0;
  995. if(!is_numeric($max_score) || $max_score < 0)
  996. $max_score = 100;
  997. if($mastery_score > $max_score)
  998. $max_score = $mastery_score;
  999. if(!is_numeric($prerequisite_id))
  1000. $prerequisite_id = 'NULL';
  1001. $sql_upd = "
  1002. UPDATE " . $tbl_lp_item . "
  1003. SET prerequisite = ".$prerequisite_id." WHERE id = ".$id;
  1004. $res_upd = api_sql_query($sql_upd ,__FILE__, __LINE__);
  1005. if($prerequisite_id!='NULL' && $prerequisite_id!='')
  1006. {
  1007. $sql_upd = " UPDATE ".$tbl_lp_item." SET
  1008. mastery_score = " . $mastery_score .
  1009. //", max_score = " . $max_score . " " . //max score cannot be changed in the form anyway - see display_item_prerequisites_form()
  1010. " WHERE ref = '" . $prerequisite_id."'" ; //will this be enough to ensure unicity?
  1011. $res_upd = api_sql_query($sql_upd ,__FILE__, __LINE__);
  1012. }
  1013. //TODO update the item object (can be ignored for now because refreshed)
  1014. return true;
  1015. }
  1016. /**
  1017. * Escapes a string with the available database escape function
  1018. * @param string String to escape
  1019. * @return string String escaped
  1020. */
  1021. function escape_string($string){
  1022. //if($this->debug>0){error_log('New LP - In learnpath::escape_string('.$string.')',0);}
  1023. return mysql_real_escape_string($string);
  1024. }
  1025. /**
  1026. * Static admin function exporting a learnpath into a zip file
  1027. * @param string Export type (scorm, zip, cd)
  1028. * @param string Course code
  1029. * @param integer Learnpath ID
  1030. * @param string Zip file name
  1031. * @return string Zip file path (or false on error)
  1032. */
  1033. function export_lp($type, $course, $id, $zipname)
  1034. {
  1035. //if($this->debug>0){error_log('New LP - In learnpath::export_lp()',0);}
  1036. //TODO
  1037. if(empty($type) OR empty($course) OR empty($id) OR empty($zipname)){return false;}
  1038. $url = '';
  1039. switch($type){
  1040. case 'scorm':
  1041. break;
  1042. case 'zip':
  1043. break;
  1044. case 'cdrom':
  1045. break;
  1046. }
  1047. return $url;
  1048. }
  1049. /**
  1050. * Gets all the chapters belonging to the same parent as the item/chapter given
  1051. * Can also be called as abstract method
  1052. * @param integer Item ID
  1053. * @return array A list of all the "brother items" (or an empty array on failure)
  1054. */
  1055. function get_brother_chapters($id){
  1056. if($this->debug>0){error_log('New LP - In learnpath::get_brother_chapters()',0);}
  1057. if(empty($id) OR $id != strval(intval($id))){ return array();}
  1058. $lp_item = Database::get_course_table('lp_item');
  1059. $sql_parent = "SELECT * FROM $lp_item WHERE id = $id AND item_type='dokeos_chapter'";
  1060. $res_parent = api_sql_query($sql_parent,__FILE__,__LINE__);
  1061. if(Database::num_rows($res_parent)>0){
  1062. $row_parent = Database::fetch_array($res_parent);
  1063. $parent = $row_parent['parent_item_id'];
  1064. $sql_bros = "SELECT * FROM $lp_item WHERE parent_item_id = $parent AND id = $id AND item_type='dokeos_chapter' ORDER BY display_order";
  1065. $res_bros = api_sql_query($sql_bros,__FILE__,__LINE__);
  1066. $list = array();
  1067. while ($row_bro = Database::fetch_array($res_bros)){
  1068. $list[] = $row_bro;
  1069. }
  1070. return $list;
  1071. }
  1072. return array();
  1073. }
  1074. /**
  1075. * Gets all the items belonging to the same parent as the item given
  1076. * Can also be called as abstract method
  1077. * @param integer Item ID
  1078. * @return array A list of all the "brother items" (or an empty array on failure)
  1079. */
  1080. function get_brother_items($id){
  1081. if($this->debug>0){error_log('New LP - In learnpath::get_brother_items('.$id.')',0);}
  1082. if(empty($id) OR $id != strval(intval($id))){ return array();}
  1083. $lp_item = Database::get_course_table('lp_item');
  1084. $sql_parent = "SELECT * FROM $lp_item WHERE id = $id";
  1085. $res_parent = api_sql_query($sql_parent,__FILE__,__LINE__);
  1086. if(Database::num_rows($res_parent)>0){
  1087. $row_parent = Database::fetch_array($res_parent);
  1088. $parent = $row_parent['parent_item_id'];
  1089. $sql_bros = "SELECT * FROM $lp_item WHERE parent_item_id = $parent ORDER BY display_order";
  1090. $res_bros = api_sql_query($sql_bros,__FILE__,__LINE__);
  1091. $list = array();
  1092. while ($row_bro = Database::fetch_array($res_bros)){
  1093. $list[] = $row_bro;
  1094. }
  1095. return $list;
  1096. }
  1097. return array();
  1098. }
  1099. /**
  1100. * Gets the number of items currently completed
  1101. * @return integer The number of items currently completed
  1102. */
  1103. function get_complete_items_count()
  1104. {
  1105. if($this->debug>0){error_log('New LP - In learnpath::get_complete_items_count()',0);}
  1106. $i = 0;
  1107. foreach($this->items as $id => $dummy){
  1108. //if($this->items[$id]->status_is(array('completed','passed','succeeded'))){
  1109. //Trying failed and browsed considered "progressed" as well
  1110. 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'){
  1111. $i++;
  1112. }
  1113. }
  1114. return $i;
  1115. }
  1116. /**
  1117. * Gets the current item ID
  1118. * @return integer The current learnpath item id
  1119. */
  1120. function get_current_item_id()
  1121. {
  1122. $current = 0;
  1123. if($this->debug>0){error_log('New LP - In learnpath::get_current_item_id()',0);}
  1124. if(!empty($this->current))
  1125. {
  1126. $current = $this->current;
  1127. }
  1128. if($this->debug>2){error_log('New LP - In learnpath::get_current_item_id() - Returning '.$current,0);}
  1129. return $current;
  1130. }
  1131. /**
  1132. * Gets the total number of items available for viewing in this SCORM
  1133. * @return integer The total number of items
  1134. */
  1135. function get_total_items_count()
  1136. {
  1137. if($this->debug>0){error_log('New LP - In learnpath::get_total_items_count()',0);}
  1138. return count($this->items);
  1139. }
  1140. /**
  1141. * Gets the total number of items available for viewing in this SCORM but without chapters
  1142. * @return integer The total no-chapters number of items
  1143. */
  1144. function get_total_items_count_without_chapters()
  1145. {
  1146. if($this->debug>0){error_log('New LP - In learnpath::get_total_items_count_without_chapters()',0);}
  1147. $total=0;
  1148. foreach($this->items as $temp=>$temp2){
  1149. if(!in_array($temp2->get_type(), array('dokeos_chapter','chapter','dir'))) $total++;
  1150. }
  1151. return $total;
  1152. }
  1153. /**
  1154. * Gets the first element URL.
  1155. * @return string URL to load into the viewer
  1156. */
  1157. function first()
  1158. {
  1159. if($this->debug>0){error_log('New LP - In learnpath::first()',0);}
  1160. //test if the last_item_seen exists and is not a dir
  1161. if(!empty($this->last_item_seen)
  1162. && !empty($this->items[$this->last_item_seen])
  1163. && $this->items[$this->last_item_seen]->get_type() != 'dir'
  1164. && $this->items[$this->last_item_seen]->get_type() != 'dokeos_chapter'
  1165. && $this->items[$this->last_item_seen]->is_done() != true
  1166. ){
  1167. 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);}
  1168. $index = -1;
  1169. foreach($this->ordered_items as $myindex => $item_id){
  1170. if($item_id == $this->last_item_seen){
  1171. $index = $myindex;
  1172. break;
  1173. }
  1174. }
  1175. if($index==-1){
  1176. //index hasn't changed, so item not found - panic (this shouldn't happen)
  1177. 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);}
  1178. return false;
  1179. }else{
  1180. $this->last = $this->last_item_seen;
  1181. $this->current = $this->last_item_seen;
  1182. $this->index = $index;
  1183. }
  1184. }else{
  1185. if($this->debug>2){error_log('New LP - In learnpath::first() - No last item seen',0);}
  1186. $index = 0;
  1187. //loop through all ordered items and stop at the first item that is
  1188. //not a directory *and* that has not been completed yet
  1189. while (!empty($this->ordered_items[$index])
  1190. AND
  1191. is_a($this->items[$this->ordered_items[$index]],'learnpathItem')
  1192. AND
  1193. (
  1194. $this->items[$this->ordered_items[$index]]->get_type() == 'dir'
  1195. OR $this->items[$this->ordered_items[$index]]->get_type() == 'dokeos_chapter'
  1196. OR $this->items[$this->ordered_items[$index]]->is_done() === true
  1197. )
  1198. AND $index < $this->max_ordered_items)
  1199. {
  1200. $index ++;
  1201. }
  1202. $this->last = $this->current;
  1203. //current is
  1204. $this->current = $this->ordered_items[$index];
  1205. $this->index = $index;
  1206. if($this->debug>2){error_log('New LP - In learnpath::first() - No last item seen. New last = '.$this->last.'('.$this->ordered_items[$index].')',0);}
  1207. }
  1208. if($this->debug>2){error_log('New LP - In learnpath::first() - First item is '.$this->get_current_item_id());}
  1209. }
  1210. /**
  1211. * Gets the information about an item in a format usable as JavaScript to update
  1212. * the JS API by just printing this content into the <head> section of the message frame
  1213. * @param integer Item ID
  1214. * @return string
  1215. */
  1216. function get_js_info($item_id=''){
  1217. if($this->debug>0){error_log('New LP - In learnpath::get_js_info('.$item_id.')',0);}
  1218. $info = '';
  1219. $item_id = $this->escape_string($item_id);
  1220. if(!empty($item_id) && is_object($this->items[$item_id])){
  1221. //if item is defined, return values from DB
  1222. $oItem = $this->items[$item_id];
  1223. $info .= '<script language="javascript">';
  1224. $info .= "top.set_score(".$oItem->get_score().");\n";
  1225. $info .= "top.set_max(".$oItem->get_max().");\n";
  1226. $info .= "top.set_min(".$oItem->get_min().");\n";
  1227. $info .= "top.set_lesson_status('".$oItem->get_status()."');";
  1228. $info .= "top.set_session_time('".$oItem->get_scorm_time('js')."');";
  1229. $info .= "top.set_suspend_data('".$oItem->get_suspend_data()."');";
  1230. $info .= "top.set_saved_lesson_status('".$oItem->get_status()."');";
  1231. $info .= "top.set_flag_synchronized();";
  1232. $info .= '</script>';
  1233. if($this->debug>2){error_log('New LP - in learnpath::get_js_info('.$item_id.') - returning: '.$info,0);}
  1234. return $info;
  1235. }else{
  1236. //if item_id is empty, just update to default SCORM data
  1237. $info .= '<script language="javascript">';
  1238. $info .= "top.set_score(".learnpathItem::get_score().");\n";
  1239. $info .= "top.set_max(".learnpathItem::get_max().");\n";
  1240. $info .= "top.set_min(".learnpathItem::get_min().");\n";
  1241. $info .= "top.set_lesson_status('".learnpathItem::get_status()."');";
  1242. $info .= "top.set_session_time('".learnpathItem::get_scorm_time('js')."');";
  1243. $info .= "top.set_suspend_data('".learnpathItem::get_suspend_data()."');";
  1244. $info .= "top.set_saved_lesson_status('".learnpathItem::get_status()."');";
  1245. $info .= "top.set_flag_synchronized();";
  1246. $info .= '</script>';
  1247. if($this->debug>2){error_log('New LP - in learnpath::get_js_info('.$item_id.') - returning: '.$info,0);}
  1248. return $info;
  1249. }
  1250. }
  1251. /**
  1252. * Gets the js library from the database
  1253. * @return string The name of the javascript library to be used
  1254. */
  1255. function get_js_lib(){
  1256. $lib = '';
  1257. if(!empty($this->js_lib)){
  1258. $lib = $this->js_lib;
  1259. }
  1260. return $lib;
  1261. }
  1262. /**
  1263. * Gets the learnpath database ID
  1264. * @return integer Learnpath ID in the lp table
  1265. */
  1266. function get_id()
  1267. {
  1268. if($this->debug>0){error_log('New LP - In learnpath::get_id()',0);}
  1269. if(!empty($this->lp_id))
  1270. {
  1271. return $this->lp_id;
  1272. }else{
  1273. return 0;
  1274. }
  1275. }
  1276. /**
  1277. * Gets the last element URL.
  1278. * @return string URL to load into the viewer
  1279. */
  1280. function get_last()
  1281. {
  1282. if($this->debug>0){error_log('New LP - In learnpath::get_last()',0);}
  1283. $this->index = count($this->ordered_items)-1;
  1284. return $this->ordered_items[$this->index];
  1285. }
  1286. /**
  1287. * Gets the navigation bar for the learnpath display screen
  1288. * @return string The HTML string to use as a navigation bar
  1289. */
  1290. function get_navigation_bar()
  1291. {
  1292. if($this->debug>0){error_log('New LP - In learnpath::get_navigation_bar()',0);}
  1293. //TODO find a good value for the following variables
  1294. $file = '';
  1295. $openDir = '';
  1296. $edoceo = '';
  1297. $time = 0;
  1298. $navbar = '';
  1299. $RequestUri = '';
  1300. $mycurrentitemid = $this->get_current_item_id();
  1301. if($this->mode == 'fullscreen'){
  1302. $navbar = '<table cellpadding="0" cellspacing="0" align="left">'."\n".
  1303. ' <tr> '."\n" .
  1304. ' <td>'."\n" .
  1305. ' <div class="buttons">'."\n" .
  1306. ' <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('ScormMystatus').'"></a>&nbsp;'."\n" .
  1307. ' <a href="" onclick="dokeos_xajax_handler.switch_item('.$mycurrentitemid.',\'previous\');return false;" title="previous"><img border="0" src="../img/lp_leftarrow.gif" title="'.get_lang('ScormPrevious').'"></a>&nbsp;'."\n" .
  1308. ' <a href="" onclick="dokeos_xajax_handler.switch_item('.$mycurrentitemid.',\'next\');return false;" title="next" ><img border="0" src="../img/lp_rightarrow.gif" title="'.get_lang('ScormNext').'"></a>&nbsp;'."\n" .
  1309. ' <a href="lp_controller.php?action=mode&mode=embedded" target="_top" title="embedded mode"><img border="0" src="../img/view_choose.gif" title="'.get_lang('ScormExitFullScreen').'"></a>'."\n" .
  1310. //' <a href="lp_controller.php?action=list" target="_top" title="learnpaths list"><img border="0" src="../img/exit.png" title="Exit"></a>'."\n" .
  1311. ' </div>'."\n" .
  1312. ' </td>'."\n" .
  1313. ' </tr>'."\n" .
  1314. '</table>'."\n" ;
  1315. }else{
  1316. $navbar = '<table cellpadding="0" cellspacing="0" align="left">'."\n".
  1317. ' <tr> '."\n" .
  1318. ' <td>'."\n" .
  1319. ' <div class="buttons">'."\n" .
  1320. ' <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('ScormMystatus').'"></a>&nbsp;'."\n" .
  1321. ' <a href="" onclick="dokeos_xajax_handler.switch_item('.$mycurrentitemid.',\'previous\');return false;" title="previous"><img border="0" src="../img/lp_leftarrow.gif" title="'.get_lang('ScormPrevious').'"></a>&nbsp;'."\n" .
  1322. ' <a href="" onclick="dokeos_xajax_handler.switch_item('.$mycurrentitemid.',\'next\');return false;" title="next" ><img border="0" src="../img/lp_rightarrow.gif" title="'.get_lang('ScormNext').'"></a>&nbsp;'."\n" .
  1323. ' <a href="lp_controller.php?action=mode&mode=fullscreen" target="_top" title="fullscreen"><img border="0" src="../img/view_fullscreen.gif" width="18" height="18" title="'.get_lang('ScormFullScreen').'"></a>'."\n" .
  1324. ' </div>'."\n" .
  1325. ' </td>'."\n" .
  1326. ' </tr>'."\n" .
  1327. '</table>'."\n" ;
  1328. }
  1329. return $navbar;
  1330. }
  1331. /**
  1332. * Gets the next resource in queue (url).
  1333. * @return string URL to load into the viewer
  1334. */
  1335. function get_next_index()
  1336. {
  1337. if($this->debug>0){error_log('New LP - In learnpath::get_next_index()',0);}
  1338. //TODO
  1339. $index = $this->index;
  1340. $index ++;
  1341. if($this->debug>2){error_log('New LP - Now looking at ordered_items['.($index).'] - type is '.$this->items[$this->ordered_items[$index]]->type,0);}
  1342. 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)
  1343. {
  1344. $index ++;
  1345. if($index == $this->max_ordered_items)
  1346. {
  1347. return $this->index;
  1348. }
  1349. }
  1350. if(empty($this->ordered_items[$index])){
  1351. return $this->index;
  1352. }
  1353. if($this->debug>2){error_log('New LP - index is now '.$index,0);}
  1354. return $index;
  1355. }
  1356. /**
  1357. * Gets item_id for the next element
  1358. * @return integer Next item (DB) ID
  1359. */
  1360. function get_next_item_id()
  1361. {
  1362. if($this->debug>0){error_log('New LP - In learnpath::get_next_item_id()',0);}
  1363. $new_index = $this->get_next_index();
  1364. if(!empty($new_index))
  1365. {
  1366. if(isset($this->ordered_items[$new_index]))
  1367. {
  1368. if($this->debug>2){error_log('New LP - In learnpath::get_next_index() - Returning '.$this->ordered_items[$new_index],0);}
  1369. return $this->ordered_items[$new_index];
  1370. }
  1371. }
  1372. if($this->debug>2){error_log('New LP - In learnpath::get_next_index() - Problem - Returning 0',0);}
  1373. return 0;
  1374. }
  1375. /**
  1376. * Returns the package type ('scorm','aicc','scorm2004','dokeos','ppt'...)
  1377. *
  1378. * Generally, the package provided is in the form of a zip file, so the function
  1379. * has been written to test a zip file. If not a zip, the function will return the
  1380. * default return value: ''
  1381. * @param string the path to the file
  1382. * @param string the original name of the file
  1383. * @return string 'scorm','aicc','scorm2004','dokeos' or '' if the package cannot be recognized
  1384. */
  1385. function get_package_type($file_path,$file_name){
  1386. //get name of the zip file without the extension
  1387. $file_info = pathinfo($file_name);
  1388. $filename = $file_info['basename'];//name including extension
  1389. $extension = $file_info['extension'];//extension only
  1390. if(!empty($_POST['ppt2lp']) && !in_array($extension,array('dll','exe')))
  1391. {
  1392. return 'oogie';
  1393. }
  1394. if(!empty($_POST['woogie']) && !in_array($extension,array('dll','exe')))
  1395. {
  1396. return 'woogie';
  1397. }
  1398. $file_base_name = str_replace('.'.$extension,'',$filename); //filename without its extension
  1399. $zipFile = new pclZip($file_path);
  1400. // Check the zip content (real size and file extension)
  1401. $zipContentArray = $zipFile->listContent();
  1402. $package_type='';
  1403. $at_root = false;
  1404. $manifest = '';
  1405. //the following loop should be stopped as soon as we found the right imsmanifest.xml (how to recognize it?)
  1406. foreach($zipContentArray as $thisContent)
  1407. {
  1408. if ( preg_match('~.(php.*|phtml)$~i', $thisContent['filename']) )
  1409. {
  1410. //New behaviour: Don't do anything. These files will be removed in scorm::import_package
  1411. }
  1412. elseif(stristr($thisContent['filename'],'imsmanifest.xml')!==FALSE)
  1413. {
  1414. $manifest = $thisContent['filename']; //just the relative directory inside scorm/
  1415. $package_type = 'scorm';
  1416. break;//exit the foreach loop
  1417. }
  1418. elseif(preg_match('/aicc\//i',$thisContent['filename'])!=false)
  1419. {//if found an aicc directory... (!= false means it cannot be false (error) or 0 (no match))
  1420. $package_type='aicc';
  1421. //break;//don't exit the loop, because if we find an imsmanifest afterwards, we want it, not the AICC
  1422. }
  1423. else
  1424. {
  1425. $package_type = '';
  1426. }
  1427. }
  1428. return $package_type;
  1429. }
  1430. /**
  1431. * Gets the previous resource in queue (url). Also initialises time values for this viewing
  1432. * @return string URL to load into the viewer
  1433. */
  1434. function get_previous_index()
  1435. {
  1436. if($this->debug>0){error_log('New LP - In learnpath::get_previous_index()',0);}
  1437. $index = $this->index;
  1438. if(isset($this->ordered_items[$index-1])){
  1439. $index --;
  1440. 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'))
  1441. {
  1442. $index --;
  1443. if($index < 0){
  1444. return $this->index;
  1445. }
  1446. }
  1447. }else{
  1448. if($this->debug>2){error_log('New LP - get_previous_index() - there was no previous index available, reusing '.$index,0);}
  1449. //no previous item
  1450. }
  1451. return $index;
  1452. }
  1453. /**
  1454. * Gets item_id for the next element
  1455. * @return integer Previous item (DB) ID
  1456. */
  1457. function get_previous_item_id()
  1458. {
  1459. $new_index = $this->get_previous_index();
  1460. return $this->ordered_items[$new_index];
  1461. }
  1462. /**
  1463. * Gets the progress value from the progress_db attribute
  1464. * @return integer Current progress value
  1465. */
  1466. function get_progress()
  1467. {
  1468. if($this->debug>0){error_log('New LP - In learnpath::get_progress()',0);}
  1469. if(!empty($this->progress_db))
  1470. {
  1471. return $this->progress_db;
  1472. }
  1473. return 0;
  1474. }
  1475. /**
  1476. * Gets the progress value from the progress field in the database (allows use as abstract method)
  1477. * @param integer Learnpath ID
  1478. * @param integer User ID
  1479. * @param string Mode of display ('%','abs' or 'both')
  1480. * @return integer Current progress value as found in the database
  1481. */
  1482. function get_db_progress($lp_id,$user_id,$mode='%', $course_db='')
  1483. {
  1484. //if($this->debug>0){error_log('New LP - In learnpath::get_db_progress()',0);}
  1485. $table = Database::get_course_table('lp_view', $course_db);
  1486. $sql = "SELECT * FROM $table WHERE lp_id = $lp_id AND user_id = $user_id";
  1487. $res = api_sql_query($sql,__FILE__,__LINE__);
  1488. $view_id = 0;
  1489. if(Database::num_rows($res)>0)
  1490. {
  1491. $row = Database::fetch_array($res);
  1492. $progress = $row['progress'];
  1493. $view_id = $row['id'];
  1494. }
  1495. if(!$progress)
  1496. {
  1497. $progress = '0';
  1498. }
  1499. if($mode == '%')
  1500. {
  1501. return $progress.'%';
  1502. }
  1503. else
  1504. {
  1505. //get the number of items completed and the number of items total
  1506. $tbl = Database::get_course_table('lp_item', $course_db);
  1507. $sql = "SELECT count(*) FROM $tbl WHERE lp_id = ".$lp_id."
  1508. AND item_type NOT IN('dokeos_chapter','chapter','dir')";
  1509. $res = api_sql_query($sql);
  1510. $row = Database::fetch_array($res);
  1511. $total = $row[0];
  1512. $tbl_item_view = Database::get_course_table('lp_item_view', $course_db);
  1513. $tbl_item = Database::get_course_table('lp_item', $course_db);
  1514. //$sql = "SELECT count(distinct(lp_item_id)) FROM $tbl WHERE lp_view_id = ".$view_id." AND status IN ('passed','completed','succeeded')";
  1515. //trying as also counting browsed and failed items
  1516. $sql = "SELECT count(distinct(lp_item_id))
  1517. FROM $tbl_item_view as item_view
  1518. INNER JOIN $tbl_item as item
  1519. ON item.id = item_view.lp_item_id
  1520. AND item_type NOT IN('dokeos_chapter','chapter','dir')
  1521. WHERE lp_view_id = ".$view_id."
  1522. AND status IN ('passed','completed','succeeded','browsed','failed')";
  1523. $res = api_sql_query($sql, __FILE__, __LINE__);
  1524. $row = Database::fetch_array($res);
  1525. $completed = $row[0];
  1526. if($mode == 'abs')
  1527. {
  1528. return $completed.'/'.$total;
  1529. }
  1530. elseif($mode == 'both')
  1531. {
  1532. if($progress<($completed/($total?$total:1)))
  1533. {
  1534. $progress = number_format(($completed/($total?$total:1))*100,0);
  1535. }
  1536. return $progress.'% ('.$completed.'/'.$total.')';
  1537. }
  1538. }
  1539. return $progress;
  1540. }
  1541. /**
  1542. * Gets a progress bar for the learnpath by counting the number of items in it and the number of items
  1543. * completed so far.
  1544. * @param string Mode in which we want the values
  1545. * @param integer Progress value to display (optional but mandatory if used in abstract context)
  1546. * @param string Text to display near the progress value (optional but mandatory in abstract context)
  1547. * @return string HTML string containing the progress bar
  1548. */
  1549. function get_progress_bar($mode='',$percentage=-1,$text_add='')
  1550. {
  1551. global $lp_theme_css;
  1552. // Setting up the CSS path of the current style if exists
  1553. if (!empty($lp_theme_css))
  1554. {
  1555. $css_path=api_get_path(WEB_CODE_PATH).'css/'.$lp_theme_css.'/images/';
  1556. }
  1557. else
  1558. {
  1559. $css_path='../img/';
  1560. }
  1561. //if($this->debug>0){error_log('New LP - In learnpath::get_progress_bar()',0);}
  1562. if(is_object($this) && ($percentage=='-1' OR $text_add==''))
  1563. {
  1564. list ($percentage, $text_add) = $this->get_progress_bar_text($mode);
  1565. }
  1566. $text = $percentage.$text_add;
  1567. $size = str_replace('%','',$percentage);
  1568. $output = ''
  1569. //.htmlentities(get_lang('ScormCompstatus'),ENT_QUOTES,'ISO-8859-1')."<br />"
  1570. .'<table border="0" cellpadding="0" cellspacing="0"><tr><td>'
  1571. .'<img id="progress_img_limit_left" src="'.$css_path.'bar_1.gif" width="1" height="12">'
  1572. .'<img id="progress_img_full" src="'.$css_path.'bar_1u.gif" width="'.$size.'px" height="12" id="full_portion">'
  1573. .'<img id="progress_img_limit_middle" src="'.$css_path.'bar_1m.gif" width="1" height="12">';
  1574. if($percentage <= 98)
  1575. {
  1576. $output .= '<img id="progress_img_empty" src="'.$css_path.'bar_1r.gif" width="'.(100-$size).'px" height="12" id="empty_portion">';
  1577. }
  1578. else
  1579. {
  1580. $output .= '<img id="progress_img_empty" src="'.$css_path.'bar_1r.gif" width="0" height="12" id="empty_portion">';
  1581. }
  1582. $output .= '<img id="progress_bar_img_limit_right" src="'.$css_path.'bar_1.gif" width="1" height="12"></td></tr></table>'
  1583. .'<div class="progresstext" id="progress_text">'.$text.'</div>';
  1584. return $output;
  1585. }
  1586. /**
  1587. * Gets the progress bar info to display inside the progress bar. Also used by scorm_api.php
  1588. * @param string Mode of display (can be '%' or 'abs').abs means we display a number of completed elements per total elements
  1589. * //@param integer Additional steps to fake as completed
  1590. * @return list Percentage or number and symbol (% or /xx)
  1591. */
  1592. function get_progress_bar_text($mode='',$add=0)
  1593. {
  1594. if($this->debug>0){error_log('New LP - In learnpath::get_progress_bar_text()',0);}
  1595. if(empty($mode)){$mode = $this->progress_bar_mode;}
  1596. $total_items = $this->get_total_items_count_without_chapters();
  1597. if($this->debug>2){error_log('New LP - Total items available in this learnpath: '.$total_items,0);}
  1598. $i = $this->get_complete_items_count();
  1599. if($this->debug>2){error_log('New LP - Items completed so far: '.$i,0);}
  1600. if($add != 0){
  1601. $i += $add;
  1602. if($this->debug>2){error_log('New LP - Items completed so far (+modifier): '.$i,0);}
  1603. }
  1604. $text = '';
  1605. if($i>$total_items){
  1606. $i = $total_items;
  1607. }
  1608. if($mode == '%'){
  1609. if($total_items>0){
  1610. $percentage = ((float)$i/(float)$total_items)*100;
  1611. }
  1612. else
  1613. {
  1614. $percentage = 0;
  1615. }
  1616. $percentage = number_format($percentage,0);
  1617. $text = '%';
  1618. }elseif($mode == 'abs'){
  1619. $percentage = $i;
  1620. $text = '/'.$total_items;
  1621. }
  1622. return array($percentage,$text);
  1623. }
  1624. /**
  1625. * Gets the progress bar mode
  1626. * @return string The progress bar mode attribute
  1627. */
  1628. function get_progress_bar_mode()
  1629. {
  1630. if($this->debug>0){error_log('New LP - In learnpath::get_progress_bar_mode()',0);}
  1631. if(!empty($this->progress_bar_mode))
  1632. {
  1633. return $this->progress_bar_mode;
  1634. }else{
  1635. return '%';
  1636. }
  1637. }
  1638. /**
  1639. * Gets the learnpath proximity (remote or local)
  1640. * @return string Learnpath proximity
  1641. */
  1642. function get_proximity()
  1643. {
  1644. if($this->debug>0){error_log('New LP - In learnpath::get_proximity()',0);}
  1645. if(!empty($this->proximity)){return $this->proximity;}else{return '';}
  1646. }
  1647. /**
  1648. * Gets the learnpath theme (remote or local)
  1649. * @return string Learnpath theme
  1650. */
  1651. function get_theme()
  1652. {
  1653. if($this->debug>0){error_log('New LP - In learnpath::get_theme()',0);}
  1654. if(!empty($this->theme)){return $this->theme;}else{return '';}
  1655. }
  1656. /**
  1657. * Generate a new prerequisites string for a given item. If this item was a sco and
  1658. * its prerequisites were strings (instead of IDs), then transform those strings into
  1659. * IDs, knowing that SCORM IDs are kept in the "ref" field of the lp_item table.
  1660. * Prefix all item IDs that end-up in the prerequisites string by "ITEM_" to use the
  1661. * same rule as the scorm_export() method
  1662. * @param integer Item ID
  1663. * @return string Prerequisites string ready for the export as SCORM
  1664. */
  1665. function get_scorm_prereq_string($item_id)
  1666. {
  1667. if($this->debug>0){error_log('New LP - In learnpath::get_scorm_prereq_string()',0);}
  1668. if(!is_object($this->items[$item_id])){return false;}
  1669. $oItem = $this->items[$item_id];
  1670. $prereq = $oItem->get_prereq_string();
  1671. if(empty($prereq))
  1672. {
  1673. return '';
  1674. }
  1675. if(preg_match('/^\d+$/',$prereq) && is_object($this->items[$prereq]))
  1676. { //if the prerequisite is a simple integer ID and this ID exists as an item ID,
  1677. //then simply return it (with the ITEM_ prefix)
  1678. return 'ITEM_'.$prereq;
  1679. }
  1680. else
  1681. {
  1682. if(isset($this->refs_list[$prereq]))
  1683. {
  1684. //it's a simple string item from which the ID can be found in the refs list
  1685. //so we can transform it directly to an ID for export
  1686. return 'ITEM_'.$this->refs_list[$prereq];
  1687. }
  1688. else
  1689. {
  1690. //last case, if it's a complex form, then find all the IDs (SCORM strings)
  1691. //and replace them, one by one, by the internal IDs (dokeos db)
  1692. //TODO modify the '*' replacement to replace the multiplier in front of it
  1693. //by a space as well
  1694. $find = array('&','|','~','=','<>','{','}','*','(',')');
  1695. $replace = array(' ',' ',' ',' ',' ',' ',' ',' ',' ',' ');
  1696. $prereq_mod = str_replace($find,$replace,$prereq);
  1697. $ids = split(' ',$prereq_mod);
  1698. foreach($ids as $id)
  1699. {
  1700. $id = trim($id);
  1701. if(isset($this->refs_list[$id]))
  1702. {
  1703. $prereq = preg_replace('/[^a-zA-Z_0-9]('.$id.')[^a-zA-Z_0-9]/','ITEM_'.$this->refs_list[$id],$prereq);
  1704. }
  1705. }
  1706. error_log('New LP - In learnpath::get_scorm_prereq_string(): returning modified string: '.$prereq,0);
  1707. return $prereq;
  1708. }
  1709. }
  1710. }
  1711. /**
  1712. * Returns the XML DOM document's node
  1713. * @param resource Reference to a list of objects to search for the given ITEM_*
  1714. * @param string The identifier to look for
  1715. * @return mixed The reference to the element found with that identifier. False if not found
  1716. */
  1717. function get_scorm_xml_node(&$children,$id)
  1718. {
  1719. for($i=0;$i<$children->length;$i++){
  1720. $item_temp = $children->item($i);
  1721. if ($item_temp -> nodeName == 'item')
  1722. {
  1723. if($item_temp->getAttribute('identifier') == $id)
  1724. {
  1725. return $item_temp;
  1726. }
  1727. }
  1728. $subchildren = $item_temp->childNodes;
  1729. if($subchildren->length>0)
  1730. {
  1731. $val = $this->get_scorm_xml_node($subchildren,$id);
  1732. if(is_object($val))
  1733. {
  1734. return $val;
  1735. }
  1736. }
  1737. }
  1738. return false;
  1739. }
  1740. /**
  1741. * Returns a usable array of stats related to the current learnpath and user
  1742. * @return array Well-formatted array containing status for the current learnpath
  1743. */
  1744. function get_stats()
  1745. {
  1746. if($this->debug>0){error_log('New LP - In learnpath::get_stats()',0);}
  1747. //TODO
  1748. }
  1749. /**
  1750. * Static method. Can be re-implemented by children. Gives an array of statistics for
  1751. * the given course (for all learnpaths and all users)
  1752. * @param string Course code
  1753. * @return array Well-formatted array containing status for the course's learnpaths
  1754. */
  1755. function get_stats_course($course)
  1756. {
  1757. //if($this->debug>0){error_log('New LP - In learnpath::get_stats_course()',0);}
  1758. //TODO
  1759. }
  1760. /**
  1761. * Static method. Can be re-implemented by children. Gives an array of statistics for
  1762. * the given course and learnpath (for all users)
  1763. * @param string Course code
  1764. * @param integer Learnpath ID
  1765. * @return array Well-formatted array containing status for the specified learnpath
  1766. */
  1767. function get_stats_lp($course,$lp)
  1768. {
  1769. //if($this->debug>0){error_log('New LP - In learnpath::get_stats_lp()',0);}
  1770. //TODO
  1771. }
  1772. /**
  1773. * Static method. Can be re-implemented by children. Gives an array of statistics for
  1774. * the given course, learnpath and user.
  1775. * @param string Course code
  1776. * @param integer Learnpath ID
  1777. * @param integer User ID
  1778. * @return array Well-formatted array containing status for the specified learnpath and user
  1779. */
  1780. function get_stats_lp_user($course,$lp,$user)
  1781. {
  1782. //if($this->debug>0){error_log('New LP - In learnpath::get_stats_lp_user()',0);}
  1783. //TODO
  1784. }
  1785. /**
  1786. * Static method. Can be re-implemented by children. Gives an array of statistics for
  1787. * the given course and learnpath (for all users)
  1788. * @param string Course code
  1789. * @param integer User ID
  1790. * @return array Well-formatted array containing status for the user's learnpaths
  1791. */
  1792. function get_stats_user($course,$user)
  1793. {
  1794. //if($this->debug>0){error_log('New LP - In learnpath::get_stats_user()',0);}
  1795. //TODO
  1796. }
  1797. /**
  1798. * Gets the status list for all LP's items
  1799. * @return array Array of [index] => [item ID => current status]
  1800. */
  1801. function get_items_status_list(){
  1802. if($this->debug>0){error_log('New LP - In learnpath::get_items_status_list()',0);}
  1803. $list = array();
  1804. foreach($this->ordered_items as $item_id)
  1805. {
  1806. $list[]= array($item_id => $this->items[$item_id]->get_status());
  1807. }
  1808. return $list;
  1809. }
  1810. /**
  1811. * Return the number of interactions for the given learnpath Item View ID.
  1812. * This method can be used as static.
  1813. * @param integer Item View ID
  1814. * @return integer Number of interactions
  1815. */
  1816. function get_interactions_count_from_db($lp_iv_id=0){
  1817. if(empty($lp_iv_id)){return -1;}
  1818. $table = Database::get_course_table('lp_iv_interaction');
  1819. $sql = "SELECT count(*) FROM $table WHERE lp_iv_id = $lp_iv_id";
  1820. $res = api_sql_query($sql,__FILE__,__LINE__);
  1821. $row = Database::fetch_array($res);
  1822. $num = $row[0];
  1823. return $num;
  1824. }
  1825. /**
  1826. * Return the interactions as an array for the given lp_iv_id.
  1827. * This method can be used as static.
  1828. * @param integer Learnpath Item View ID
  1829. * @return array
  1830. * @todo Translate labels
  1831. */
  1832. function get_iv_interactions_array($lp_iv_id=0){
  1833. $list = array();
  1834. $table = Database::get_course_table('lp_iv_interaction');
  1835. $sql = "SELECT * FROM $table WHERE lp_iv_id = $lp_iv_id ORDER BY order_id ASC";
  1836. $res = api_sql_query($sql,__FILE__,__LINE__);
  1837. $num = Database::num_rows($res);
  1838. if($num>0){
  1839. $list[] = array(
  1840. "order_id"=>htmlentities(get_lang('Order')),
  1841. "id"=>htmlentities(get_lang('InteractionID')),
  1842. "type"=>htmlentities(get_lang('Type')),
  1843. "time"=>htmlentities(get_lang('TimeFinished')),
  1844. "correct_responses"=>htmlentities(get_lang('CorrectAnswers')),
  1845. "student_response"=>htmlentities(get_lang('StudentResponse')),
  1846. "result"=>htmlentities(get_lang('Result')),
  1847. "latency"=>htmlentities(get_lang('LatencyTimeSpent')));
  1848. while ($row = Database::fetch_array($res)){
  1849. $list[] = array(
  1850. "order_id"=>($row['order_id']+1),
  1851. "id"=>urldecode($row['interaction_id']),//urldecode because they often have %2F or stuff like that
  1852. "type"=>$row['interaction_type'],
  1853. "time"=>$row['completion_time'],
  1854. //"correct_responses"=>$row['correct_responses'],
  1855. //hide correct responses from students
  1856. "correct_responses"=>'',
  1857. "student_response"=>$row['student_response'],
  1858. "result"=>$row['result'],
  1859. "latency"=>$row['latency']);
  1860. }
  1861. }
  1862. return $list;
  1863. }
  1864. /**
  1865. * Return the number of objectives for the given learnpath Item View ID.
  1866. * This method can be used as static.
  1867. * @param integer Item View ID
  1868. * @return integer Number of objectives
  1869. */
  1870. function get_objectives_count_from_db($lp_iv_id=0){
  1871. if(empty($lp_iv_id)){return -1;}
  1872. $table = Database::get_course_table('lp_iv_objective');
  1873. $sql = "SELECT count(*) FROM $table WHERE lp_iv_id = $lp_iv_id";
  1874. $res = api_sql_query($sql,__FILE__,__LINE__);
  1875. $row = Database::fetch_array($res);
  1876. $num = $row[0];
  1877. return $num;
  1878. }
  1879. /**
  1880. * Return the objectives as an array for the given lp_iv_id.
  1881. * This method can be used as static.
  1882. * @param integer Learnpath Item View ID
  1883. * @return array
  1884. * @todo Translate labels
  1885. */
  1886. function get_iv_objectives_array($lp_iv_id=0){
  1887. $list = array();
  1888. $table = Database::get_course_table('lp_iv_objective');
  1889. $sql = "SELECT * FROM $table WHERE lp_iv_id = $lp_iv_id ORDER BY order_id ASC";
  1890. $res = api_sql_query($sql,__FILE__,__LINE__);
  1891. $num = Database::num_rows($res);
  1892. if($num>0){
  1893. $list[] = array(
  1894. "order_id"=>htmlentities(get_lang('Order')),
  1895. "objective_id"=>htmlentities(get_lang('ObjectiveID')),
  1896. "score_raw"=>htmlentities(get_lang('ObjectiveRawScore')),
  1897. "score_max"=>htmlentities(get_lang('ObjectiveMaxScore')),
  1898. "score_min"=>htmlentities(get_lang('ObjectiveMinScore')),
  1899. "status"=>htmlentities(get_lang('ObjectiveStatus')));
  1900. while ($row = Database::fetch_array($res)){
  1901. $list[] = array(
  1902. "order_id"=>($row['order_id']+1),
  1903. "objective_id"=>urldecode($row['objective_id']),//urldecode because they often have %2F or stuff like that
  1904. "score_raw"=>$row['score_raw'],
  1905. "score_max"=>$row['score_max'],
  1906. "score_min"=>$row['score_min'],
  1907. "status"=>$row['status']);
  1908. }
  1909. }
  1910. return $list;
  1911. }
  1912. /**
  1913. * Generate and return the table of contents for this learnpath. The (flat) table returned can be
  1914. * used by get_html_toc() to be ready to display
  1915. * @return array TOC as a table with 4 elements per row: title, link, status and level
  1916. */
  1917. function get_toc()
  1918. {
  1919. if($this->debug>0){error_log('New LP - In learnpath::get_toc()',0);}
  1920. $toc = array();
  1921. //echo "<pre>".print_r($this->items,true)."</pre>";
  1922. foreach($this->ordered_items as $item_id)
  1923. {
  1924. if($this->debug>2){error_log('New LP - learnpath::get_toc(): getting info for item '.$item_id,0);}
  1925. //TODO change this link generation and use new function instead
  1926. $toc[] = array(
  1927. 'id'=>$item_id,
  1928. 'title'=>$this->items[$item_id]->get_title(),
  1929. //'link'=>get_addedresource_link_in_learnpath('document',$item_id,1),
  1930. 'status'=>$this->items[$item_id]->get_status(),
  1931. 'level'=>$this->items[$item_id]->get_level(),
  1932. 'type' =>$this->items[$item_id]->get_type(),
  1933. 'description'=>$this->items[$item_id]->get_description(),
  1934. );
  1935. }
  1936. if($this->debug>2){error_log('New LP - In learnpath::get_toc() - TOC array: '.print_r($toc,true),0);}
  1937. return $toc;
  1938. }
  1939. /**
  1940. * Gets the learning path type
  1941. * @param boolean Return the name? If false, return the ID. Default is false.
  1942. * @return mixed Type ID or name, depending on the parameter
  1943. */
  1944. function get_type($get_name = false)
  1945. {
  1946. $res = false;
  1947. if($this->debug>0){error_log('New LP - In learnpath::get_type()',0);}
  1948. if(!empty($this->type))
  1949. {
  1950. if($get_name)
  1951. {
  1952. //get it from the lp_type table in main db
  1953. }else{
  1954. $res = $this->type;
  1955. }
  1956. }
  1957. if($this->debug>2){error_log('New LP - In learnpath::get_type() - Returning '.($res==false?'false':$res),0);}
  1958. return $res;
  1959. }
  1960. /**
  1961. * Gets the learning path type as static method
  1962. * @param boolean Return the name? If false, return the ID. Default is false.
  1963. * @return mixed Type ID or name, depending on the parameter
  1964. */
  1965. function get_type_static($lp_id=0)
  1966. {
  1967. $tbl_lp = Database::get_course_table('lp');
  1968. $sql = "SELECT lp_type FROM $tbl_lp WHERE id = '".$lp_id."'";
  1969. $res = api_sql_query($sql);
  1970. if($res===false){ return null;}
  1971. if(Database::num_rows($res)<=0){return null;}
  1972. $row = Database::fetch_array($res);
  1973. return $row['lp_type'];
  1974. }
  1975. /**
  1976. * Gets a flat list of item IDs ordered for display (level by level ordered by order_display)
  1977. * This method can be used as abstract and is recursive
  1978. * @param integer Learnpath ID
  1979. * @param integer Parent ID of the items to look for
  1980. * @return mixed Ordered list of item IDs or false on error
  1981. */
  1982. function get_flat_ordered_items_list($lp,$parent=0){
  1983. //if($this->debug>0){error_log('New LP - In learnpath::get_flat_ordered_items_list('.$lp.','.$parent.')',0);}
  1984. $list = array();
  1985. if(empty($lp)){return false;}
  1986. $tbl_lp_item = Database::get_course_table('lp_item');
  1987. $sql = "SELECT * FROM $tbl_lp_item WHERE lp_id = $lp AND parent_item_id = $parent ORDER BY display_order";
  1988. $res = api_sql_query($sql,__FILE__,__LINE__);
  1989. while($row = Database::fetch_array($res)){
  1990. $sublist = learnpath::get_flat_ordered_items_list($lp,$row['id']);
  1991. $list[] = $row['id'];
  1992. foreach($sublist as $item){
  1993. $list[] = $item;
  1994. }
  1995. }
  1996. return $list;
  1997. }
  1998. /**
  1999. * Uses the table generated by get_toc() and returns an HTML-formatted string ready to display
  2000. * @return string HTML TOC ready to display
  2001. */
  2002. /*function get_html_toc()
  2003. {
  2004. if($this->debug>0){error_log('New LP - In learnpath::get_html_toc()',0);}
  2005. $list = $this->get_toc();
  2006. //echo $this->current;
  2007. //$parent = $this->items[$this->current]->get_parent();
  2008. //if(empty($parent)){$parent = $this->ordered_items[$this->items[$this->current]->get_previous_index()];}
  2009. $html = '<div class="inner_lp_toc">'."\n" ;
  2010. // " onchange=\"javascript:document.getElementById('toc_$parent').focus();\">\n";
  2011. require_once('resourcelinker.inc.php');
  2012. //temp variables
  2013. $mycurrentitemid = $this->get_current_item_id();
  2014. foreach($list as $item)
  2015. {
  2016. if($this->debug>2){error_log('New LP - learnpath::get_html_toc(): using item '.$item['id'],0);}
  2017. //TODO complete this
  2018. $icon_name = array('not attempted' => 'notattempted.png',
  2019. 'incomplete' => 'incomplete.png',
  2020. 'failed' => 'failed.png',
  2021. 'completed' => 'completed.png',
  2022. 'passed' => 'passed.png',
  2023. 'succeeded' => 'succeeded.png',
  2024. 'browsed' => 'completed.png');
  2025. $style = 'scorm_item';
  2026. if($item['id'] == $this->current){
  2027. $style = 'scorm_item_highlight';
  2028. }
  2029. //the anchor will let us center the TOC on the currently viewed item &^D
  2030. $html .= '<a name="atoc_'.$item['id'].'" /><div class="'.$style.'" style="padding-left: '.($item['level']/2).'em; padding-right:'.($item['level']/2).'em" id="toc_'.$item['id'].'" >' .
  2031. '<img id="toc_img_'.$item['id'].'" class="scorm_status_img" src="'.$icon_name[$item['status']].'" alt="'.substr($item['status'],0,1).'" />';
  2032. //$title = htmlspecialchars($item['title'],ENT_QUOTES,$this->encoding);
  2033. $title = $item['title'];
  2034. if(empty($title)){
  2035. $title = rl_get_resource_name(api_get_course_id(),$this->get_id(),$item['id']);
  2036. $title = htmlspecialchars($title,ENT_QUOTES,$this->encoding);
  2037. }
  2038. if(empty($title))$title = '-';
  2039. if($item['type']!='dokeos_chapter' and $item['type']!='dir'){
  2040. //$html .= "<a href='lp_controller.php?".api_get_cidReq()."&action=content&lp_id=".$this->get_id()."&item_id=".$item['id']."' target='lp_content_frame_name'>".$title."</a>" ;
  2041. $url = $this->get_link('http',$item['id']);
  2042. //$html .= '<a href="'.$url.'" target="content_name" onclick="top.load_item('.$item['id'].',\''.$url.'\');">'.$title.'</a>' ;
  2043. //$html .= '<a href="" onclick="top.load_item('.$item['id'].',\''.$url.'\');return false;">'.$title.'</a>' ;
  2044. $html .= '<a href="" onclick="dokeos_xajax_handler.switch_item(' .
  2045. $mycurrentitemid.',' .
  2046. $item['id'].');' .
  2047. 'return false;" >'.$title.'</a>' ;
  2048. }else{
  2049. $html .= $title;
  2050. }
  2051. $html .= "</div>\n";
  2052. }
  2053. $html .= "</div>\n";
  2054. return $html;
  2055. }*/
  2056. /**
  2057. * Uses the table generated by get_toc() and returns an HTML-formatted string ready to display
  2058. * @return string HTML TOC ready to display
  2059. */
  2060. function get_html_toc()
  2061. {
  2062. if($this->debug>0){error_log('New LP - In learnpath::get_html_toc()',0);}
  2063. $list = $this->get_toc();
  2064. //echo $this->current;
  2065. //$parent = $this->items[$this->current]->get_parent();
  2066. //if(empty($parent)){$parent = $this->ordered_items[$this->items[$this->current]->get_previous_index()];}
  2067. $html .= '<div class="inner_lp_toc">'."\n" ;
  2068. if(api_is_allowed_to_edit()){
  2069. $mych = api_get_setting('platform_charset');
  2070. $html.="<a href='lp_controller.php?".api_get_cidreq()."&action=build&lp_id=".$this->lp_id."' style='font-size: 11px' target='_parent'>".mb_convert_encoding(get_lang("Build"),$this->encoding,$mych)."</a>&#124;<a style='font-size: 11px' href='lp_controller.php?".api_get_cidreq()."&action=admin_view&lp_id=".$this->lp_id."' target='_parent'>".mb_convert_encoding(get_lang("BasicOverview"),$this->encoding,$mych)."</a>&#124;".mb_convert_encoding(get_lang("Display"),$this->encoding,$mych)."<br/><br/>";
  2071. unset($mych);
  2072. }
  2073. // " onchange=\"javascript:document.getElementById('toc_$parent').focus();\">\n";
  2074. require_once('resourcelinker.inc.php');
  2075. //temp variables
  2076. $mycurrentitemid = $this->get_current_item_id();
  2077. foreach($list as $item)
  2078. {
  2079. if($this->debug>2){error_log('New LP - learnpath::get_html_toc(): using item '.$item['id'],0);}
  2080. //TODO complete this
  2081. $icon_name = array('not attempted' => 'notattempted.png',
  2082. 'incomplete' => 'incomplete.png',
  2083. 'failed' => 'failed.png',
  2084. 'completed' => 'completed.png',
  2085. 'passed' => 'passed.png',
  2086. 'succeeded' => 'succeeded.png',
  2087. 'browsed' => 'completed.png');
  2088. $style = 'scorm_item';
  2089. if($item['id'] == $this->current){
  2090. $style = 'scorm_item_highlight';
  2091. }
  2092. //the anchor will let us center the TOC on the currently viewed item &^D
  2093. if($item['type']!='dokeos_module' AND $item['type']!='dokeos_chapter'){
  2094. $html .= '<a name="atoc_'.$item['id'].'" /><div class="'.$style.'" style="padding-left: '.($item['level']*1.5).'em; padding-right:'.($item['level']/2).'em" id="toc_'.$item['id'].'" title="'.$item['description'].'" >' .
  2095. '';
  2096. }
  2097. else{
  2098. $html .= '<div class="'.$style.'" style="padding-left: '.($item['level']*2).'em; padding-right:'.($item['level']*1.5).'em" id="toc_'.$item['id'].'" title="'.$item['description'].'" >' .
  2099. '';
  2100. }
  2101. //$title = htmlspecialchars($item['title'],ENT_QUOTES,$this->encoding);
  2102. $title = $item['title'];
  2103. if(empty($title)){
  2104. $title = rl_get_resource_name(api_get_course_id(),$this->get_id(),$item['id']);
  2105. $title = htmlspecialchars($title,ENT_QUOTES,$this->encoding);
  2106. }
  2107. if(empty($title))$title = '-';
  2108. if($item['type']!='dokeos_chapter' and $item['type']!='dir' AND $item['type']!='dokeos_module'){
  2109. //$html .= "<a href='lp_controller.php?".api_get_cidreq()."&action=content&lp_id=".$this->get_id()."&item_id=".$item['id']."' target='lp_content_frame_name'>".$title."</a>" ;
  2110. $url = $this->get_link('http',$item['id']);
  2111. //$html .= '<a href="'.$url.'" target="content_name" onclick="top.load_item('.$item['id'].',\''.$url.'\');">'.$title.'</a>' ;
  2112. //$html .= '<a href="" onclick="top.load_item('.$item['id'].',\''.$url.'\');return false;">'.$title.'</a>' ;
  2113. $html .= '<a href="" onclick="dokeos_xajax_handler.switch_item(' .
  2114. $mycurrentitemid.',' .
  2115. $item['id'].');' .
  2116. 'return false;" ><img align="absbottom" width="13" height="13" src="../img/lp_document.png">&nbsp;'.stripslashes($title).'</a>' ;
  2117. }
  2118. elseif($item['type']=='dokeos_module' || $item['type']=='dokeos_chapter'){
  2119. $html .= "<img align='absbottom' width='13' height='13' src='../img/lp_dokeos_module.png'>&nbsp;".stripslashes($title);
  2120. }
  2121. elseif($item['type']=='dir'){
  2122. $html .= stripslashes($title);
  2123. }
  2124. $html .= "<img id='toc_img_".$item['id']."' src='".$icon_name[$item['status']]."' alt='".substr($item['status'],0,1)."' /></div>\n";
  2125. }
  2126. $html .= "</div>\n";
  2127. return $html;
  2128. }
  2129. /**
  2130. * Gets the learnpath maker name - generally the editor's name
  2131. * @return string Learnpath maker name
  2132. */
  2133. function get_maker()
  2134. {
  2135. if($this->debug>0){error_log('New LP - In learnpath::get_maker()',0);}
  2136. if(!empty($this->maker)){return $this->maker;}else{return '';}
  2137. }
  2138. /**
  2139. * Gets the user-friendly message stored in $this->message
  2140. * @return string Message
  2141. */
  2142. function get_message(){
  2143. if($this->debug>0){error_log('New LP - In learnpath::get_message()',0);}
  2144. return $this->message;
  2145. }
  2146. /**
  2147. * Gets the learnpath name/title
  2148. * @return string Learnpath name/title
  2149. */
  2150. function get_name()
  2151. {
  2152. if($this->debug>0){error_log('New LP - In learnpath::get_name()',0);}
  2153. if(!empty($this->name)){return $this->name;}else{return 'N/A';}
  2154. }
  2155. /**
  2156. * Gets a link to the resource from the present location, depending on item ID.
  2157. * @param string Type of link expected
  2158. * @param integer Learnpath item ID
  2159. * @return string Link to the lp_item resource
  2160. */
  2161. function get_link($type='http',$item_id=null)
  2162. {
  2163. if($this->debug>0){error_log('New LP - In learnpath::get_link('.$type.','.$item_id.')',0);}
  2164. if(empty($item_id))
  2165. {
  2166. 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);}
  2167. $item_id = $this->get_current_item_id();
  2168. }
  2169. if(empty($item_id)){
  2170. if($this->debug>2){error_log('New LP - In learnpath::get_link() - no current item id found in learnpath object',0);}
  2171. //still empty, this means there was no item_id given and we are not in an object context or
  2172. //the object property is empty, return empty link
  2173. $item_id = $this->first();
  2174. return '';
  2175. }
  2176. $file = '';
  2177. $lp_table = Database::get_course_table(TABLE_LP_MAIN);
  2178. $lp_item_table = Database::get_course_table(TABLE_LP_ITEM);
  2179. $sel = "SELECT l.lp_type as ltype, l.path as lpath, li.item_type as litype, li.path as lipath, li.parameters as liparams " .
  2180. "FROM $lp_table l, $lp_item_table li WHERE li.id = $item_id AND li.lp_id = l.id";
  2181. if($this->debug>2){error_log('New LP - In learnpath::get_link() - selecting item '.$sel,0);}
  2182. $res = api_sql_query($sel);
  2183. if(Database::num_rows($res)>0)
  2184. {
  2185. $row = Database::fetch_array($res);
  2186. //var_dump($row);
  2187. $lp_type = $row['ltype'];
  2188. $lp_path = $row['lpath'];
  2189. $lp_item_type = $row['litype'];
  2190. $lp_item_path = $row['lipath'];
  2191. $lp_item_params = $row['liparams'];
  2192. if(empty($lp_item_params))
  2193. {
  2194. list($lp_item_path,$lp_item_params) = explode('?',$lp_item_path);
  2195. }
  2196. //$lp_item_params = '?'.$lp_item_params;
  2197. //add ? if none - left commented to give freedom to scorm implementation
  2198. //if(substr($lp_item_params,0,1)!='?'){
  2199. // $lp_item_params = '?'.$lp_item_params;
  2200. //}
  2201. $sys_course_path = api_get_path(SYS_COURSE_PATH).api_get_course_path();
  2202. if($type == 'http'){
  2203. $course_path = api_get_path(WEB_COURSE_PATH).api_get_course_path(); //web path
  2204. }else{
  2205. $course_path = $sys_course_path; //system path
  2206. }
  2207. //now go through the specific cases to get the end of the path
  2208. switch($lp_type){
  2209. case 1:
  2210. if($lp_item_type == 'dokeos_chapter'){
  2211. $file = 'lp_content.php?type=dir';
  2212. }else{
  2213. require_once('resourcelinker.inc.php');
  2214. $file = rl_get_resource_link_for_learnpath(api_get_course_id(),$this->get_id(),$item_id);
  2215. $tmp_array=explode("/",$file);
  2216. $document_name=$tmp_array[count($tmp_array)-1];
  2217. if(strpos($document_name,'_DELETED_')){
  2218. $file = 'blank.php?error=document_deleted';
  2219. }
  2220. }
  2221. break;
  2222. case 2:
  2223. if($this->debug>2){error_log('New LP - In learnpath::get_link() '.__LINE__.' - Item type: '.$lp_item_type,0);}
  2224. if($lp_item_type!='dir'){
  2225. //Quite complex here:
  2226. //we want to make sure 'http://' (and similar) links can
  2227. //be loaded as is (withouth the Dokeos path in front) but
  2228. //some contents use this form: resource.htm?resource=http://blablabla
  2229. //which means we have to find a protocol at the path's start, otherwise
  2230. //it should not be considered as an external URL
  2231. //if($this->prerequisites_match($item_id)){
  2232. if(preg_match('#^[a-zA-Z]{2,5}://#',$lp_item_path)!=0){
  2233. if($this->debug>2){error_log('New LP - In learnpath::get_link() '.__LINE__.' - Found match for protocol in '.$lp_item_path,0);}
  2234. //distant url, return as is
  2235. $file = $lp_item_path;
  2236. }else{
  2237. if($this->debug>2){error_log('New LP - In learnpath::get_link() '.__LINE__.' - No starting protocol in '.$lp_item_path,0);}
  2238. //prevent getting untranslatable urls
  2239. $lp_item_path = preg_replace('/%2F/','/',$lp_item_path);
  2240. $lp_item_path = preg_replace('/%3A/',':',$lp_item_path);
  2241. //prepare the path
  2242. $file = $course_path.'/scorm/'.$lp_path.'/'.$lp_item_path;
  2243. //TODO fix this for urls with protocol header
  2244. $file = str_replace('//','/',$file);
  2245. $file = str_replace(':/','://',$file);
  2246. if(substr($lp_path,-1)=='/')
  2247. {
  2248. $lp_path = substr($lp_path,0,-1);
  2249. }
  2250. if(!is_file(realpath($sys_course_path.'/scorm/'.$lp_path.'/'.$lp_item_path)))
  2251. {//if file not found
  2252. $decoded = html_entity_decode($lp_item_path);
  2253. list($decoded) = explode('?',$decoded);
  2254. if(!is_file(realpath($sys_course_path.'/scorm/'.$lp_path.'/'.$decoded)))
  2255. {
  2256. require_once('resourcelinker.inc.php');
  2257. $file = rl_get_resource_link_for_learnpath(api_get_course_id(),$this->get_id(),$item_id);
  2258. $tmp_array=explode("/",$file);
  2259. $document_name=$tmp_array[count($tmp_array)-1];
  2260. if(strpos($document_name,'_DELETED_')){
  2261. $file = 'blank.php?error=document_deleted';
  2262. }
  2263. }
  2264. else
  2265. {
  2266. $file = $course_path.'/scorm/'.$lp_path.'/'.$decoded;
  2267. }
  2268. }
  2269. }
  2270. //}else{
  2271. //prerequisites did not match
  2272. //$file = 'blank.php';
  2273. //}
  2274. //We want to use parameters if they were defined in the imsmanifest
  2275. if($file!='blank.php')
  2276. {
  2277. $file.= $lp_item_params;
  2278. }
  2279. }else{
  2280. $file = 'lp_content.php?type=dir';
  2281. }
  2282. break;
  2283. case 3:
  2284. if($this->debug>2){error_log('New LP - In learnpath::get_link() '.__LINE__.' - Item type: '.$lp_item_type,0);}
  2285. //formatting AICC HACP append URL
  2286. $aicc_append = '?aicc_sid='.urlencode(session_id()).'&aicc_url='.urlencode(api_get_path(WEB_CODE_PATH).'newscorm/aicc_hacp.php').'&';
  2287. if($lp_item_type!='dir'){
  2288. //Quite complex here:
  2289. //we want to make sure 'http://' (and similar) links can
  2290. //be loaded as is (withouth the Dokeos path in front) but
  2291. //some contents use this form: resource.htm?resource=http://blablabla
  2292. //which means we have to find a protocol at the path's start, otherwise
  2293. //it should not be considered as an external URL
  2294. if(preg_match('#^[a-zA-Z]{2,5}://#',$lp_item_path)!=0){
  2295. if($this->debug>2){error_log('New LP - In learnpath::get_link() '.__LINE__.' - Found match for protocol in '.$lp_item_path,0);}
  2296. //distant url, return as is
  2297. $file = $lp_item_path;
  2298. /*
  2299. if(stristr($file,'<servername>')!==false){
  2300. $file = str_replace('<servername>',$course_path.'/scorm/'.$lp_path.'/',$lp_item_path);
  2301. }
  2302. */
  2303. $file .= $aicc_append;
  2304. }else{
  2305. if($this->debug>2){error_log('New LP - In learnpath::get_link() '.__LINE__.' - No starting protocol in '.$lp_item_path,0);}
  2306. //prevent getting untranslatable urls
  2307. $lp_item_path = preg_replace('/%2F/','/',$lp_item_path);
  2308. $lp_item_path = preg_replace('/%3A/',':',$lp_item_path);
  2309. //prepare the path - lp_path might be unusable because it includes the "aicc" subdir name
  2310. $file = $course_path.'/scorm/'.$lp_path.'/'.$lp_item_path;
  2311. //TODO fix this for urls with protocol header
  2312. $file = str_replace('//','/',$file);
  2313. $file = str_replace(':/','://',$file);
  2314. $file .= $aicc_append;
  2315. }
  2316. }else{
  2317. $file = 'lp_content.php?type=dir';
  2318. }
  2319. break;
  2320. case 4:
  2321. break;
  2322. default:
  2323. break;
  2324. }
  2325. }
  2326. if($this->debug>2){error_log('New LP - In learnpath::get_link() - returning "'.$file.'" from get_link',0);}
  2327. return $file;
  2328. }
  2329. /**
  2330. * Gets the latest usable view or generate a new one
  2331. * @param integer Optional attempt number. If none given, takes the highest from the lp_view table
  2332. * @return integer DB lp_view id
  2333. */
  2334. function get_view($attempt_num=0)
  2335. {
  2336. if($this->debug>0){error_log('New LP - In learnpath::get_view()',0);}
  2337. $search = '';
  2338. //use $attempt_num to enable multi-views management (disabled so far)
  2339. if($attempt_num != 0 AND intval(strval($attempt_num)) == $attempt_num)
  2340. {
  2341. $search = 'AND view_count = '.$attempt_num;
  2342. }
  2343. //when missing $attempt_num, search for a unique lp_view record for this lp and user
  2344. $lp_view_table = Database::get_course_table('lp_view');
  2345. $sql = "SELECT id, view_count FROM $lp_view_table " .
  2346. "WHERE lp_id = ".$this->get_id()." " .
  2347. "AND user_id = ".$this->get_user_id()." " .
  2348. $search .
  2349. " ORDER BY view_count DESC";
  2350. $res = api_sql_query($sql);
  2351. if(Database::num_rows($res)>0)
  2352. {
  2353. $row = Database::fetch_array($res);
  2354. $this->lp_view_id = $row['id'];
  2355. }else{
  2356. //no database record, create one
  2357. $sql = "INSERT INTO $lp_view_table(lp_id,user_id,view_count)" .
  2358. "VALUES (".$this->get_id().",".$this->get_user_id().",1)";
  2359. $res = api_sql_query($sql);
  2360. $id = Database::get_last_insert_id();
  2361. $this->lp_view_id = $id;
  2362. }
  2363. return $this->lp_view_id;
  2364. }
  2365. /**
  2366. * Gets the current view id
  2367. * @return integer View ID (from lp_view)
  2368. */
  2369. function get_view_id()
  2370. {
  2371. if($this->debug>0){error_log('New LP - In learnpath::get_view_id()',0);}
  2372. if(!empty($this->lp_view_id))
  2373. {
  2374. return $this->lp_view_id;
  2375. }else{
  2376. return 0;
  2377. }
  2378. }
  2379. /**
  2380. * Gets the update queue
  2381. * @return array Array containing IDs of items to be updated by JavaScript
  2382. */
  2383. function get_update_queue()
  2384. {
  2385. if($this->debug>0){error_log('New LP - In learnpath::get_update_queue()',0);}
  2386. return $this->update_queue;
  2387. }
  2388. /**
  2389. * Gets the user ID
  2390. * @return integer User ID
  2391. */
  2392. function get_user_id()
  2393. {
  2394. if($this->debug>0){error_log('New LP - In learnpath::get_user_id()',0);}
  2395. if(!empty($this->user_id))
  2396. {
  2397. return $this->user_id;
  2398. }else{
  2399. return false;
  2400. }
  2401. }
  2402. /**
  2403. * Logs a message into a file
  2404. * @param string Message to log
  2405. * @return boolean True on success, false on error or if msg empty
  2406. */
  2407. function log($msg)
  2408. {
  2409. if($this->debug>0){error_log('New LP - In learnpath::log()',0);}
  2410. //TODO
  2411. $this->error .= $msg."\n";
  2412. return true;
  2413. }
  2414. /**
  2415. * Moves an item up and down at its level
  2416. * @param integer Item to move up and down
  2417. * @param string Direction 'up' or 'down'
  2418. * @return integer New display order, or false on error
  2419. */
  2420. function move_item($id, $direction){
  2421. if($this->debug>0){error_log('New LP - In learnpath::move_item('.$id.','.$direction.')',0);}
  2422. if(empty($id) or empty($direction)){return false;}
  2423. $tbl_lp_item = Database::get_course_table('lp_item');
  2424. $sql_sel = "
  2425. SELECT *
  2426. FROM " . $tbl_lp_item . "
  2427. WHERE id = " . $id;
  2428. $res_sel = api_sql_query($sql_sel,__FILE__,__LINE__);
  2429. //check if elem exists
  2430. if(Database::num_rows($res_sel)<1){return false;}
  2431. //gather data
  2432. $row = Database::fetch_array($res_sel);
  2433. $previous = $row['previous_item_id'];
  2434. $next = $row['next_item_id'];
  2435. $display = $row['display_order'];
  2436. $parent = $row['parent_item_id'];
  2437. $lp = $row['lp_id'];
  2438. //update the item (switch with previous/next one)
  2439. switch($direction)
  2440. {
  2441. case 'up':
  2442. if($this->debug>2){error_log('Movement up detected',0);}
  2443. if($display <= 1){/*do nothing*/}
  2444. else{
  2445. $sql_sel2 = "SELECT *
  2446. FROM $tbl_lp_item
  2447. WHERE id = $previous";
  2448. if($this->debug>2){error_log('Selecting previous: '.$sql_sel2,0);}
  2449. $res_sel2 = api_sql_query($sql_sel2,__FILE__,__LINE__);
  2450. if(Database::num_rows($res_sel2)<1){$previous_previous = 0;}
  2451. //gather data
  2452. $row2 = Database::fetch_array($res_sel2);
  2453. $previous_previous = $row2['previous_item_id'];
  2454. //update previous_previous item (switch "next" with current)
  2455. if($previous_previous != 0)
  2456. {
  2457. $sql_upd2 = "UPDATE $tbl_lp_item SET next_item_id = $id WHERE id = $previous_previous";
  2458. if($this->debug>2){error_log($sql_upd2,0);}
  2459. $res_upd2 = api_sql_query($sql_upd2);
  2460. }
  2461. //update previous item (switch with current)
  2462. if($previous != 0)
  2463. {
  2464. $sql_upd2 = "UPDATE $tbl_lp_item SET next_item_id = $next, previous_item_id = $id, display_order = display_order +1 WHERE id = $previous";
  2465. if($this->debug>2){error_log($sql_upd2,0);}
  2466. $res_upd2 = api_sql_query($sql_upd2);
  2467. }
  2468. //update current item (switch with previous)
  2469. if($id != 0){
  2470. $sql_upd2 = "UPDATE $tbl_lp_item SET next_item_id = $previous, previous_item_id = $previous_previous, display_order = display_order-1 WHERE id = $id";
  2471. if($this->debug>2){error_log($sql_upd2,0);}
  2472. $res_upd2 = api_sql_query($sql_upd2);
  2473. }
  2474. //update next item (new previous item)
  2475. if($next != 0){
  2476. $sql_upd2 = "UPDATE $tbl_lp_item SET previous_item_id = $previous WHERE id = $next";
  2477. if($this->debug>2){error_log($sql_upd2,0);}
  2478. $res_upd2 = api_sql_query($sql_upd2);
  2479. }
  2480. $display = $display-1;
  2481. }
  2482. break;
  2483. case 'down':
  2484. if($this->debug>2){error_log('Movement down detected',0);}
  2485. if($next == 0){/*do nothing*/}
  2486. else{
  2487. $sql_sel2 = "SELECT * FROM $tbl_lp_item WHERE id = $next";
  2488. if($this->debug>2){error_log('Selecting next: '.$sql_sel2,0);}
  2489. $res_sel2 = api_sql_query($sql_sel2,__FILE__,__LINE__);
  2490. if(Database::num_rows($res_sel2)<1){$next_next = 0;}
  2491. //gather data
  2492. $row2 = Database::fetch_array($res_sel2);
  2493. $next_next = $row2['next_item_id'];
  2494. //update previous item (switch with current)
  2495. if($previous != 0)
  2496. {
  2497. $sql_upd2 = "UPDATE $tbl_lp_item SET next_item_id = $next WHERE id = $previous";
  2498. $res_upd2 = api_sql_query($sql_upd2);
  2499. }
  2500. //update current item (switch with previous)
  2501. if($id != 0)
  2502. {
  2503. $sql_upd2 = "UPDATE $tbl_lp_item SET previous_item_id = $next, next_item_id = $next_next, display_order = display_order+1 WHERE id = $id";
  2504. $res_upd2 = api_sql_query($sql_upd2);
  2505. }
  2506. //update next item (new previous item)
  2507. if($next != 0)
  2508. {
  2509. $sql_upd2 = "UPDATE $tbl_lp_item SET previous_item_id = $previous, next_item_id = $id, display_order = display_order-1 WHERE id = $next";
  2510. $res_upd2 = api_sql_query($sql_upd2);
  2511. }
  2512. //update next_next item (switch "previous" with current)
  2513. if($next_next != 0)
  2514. {
  2515. $sql_upd2 = "UPDATE $tbl_lp_item SET previous_item_id = $id WHERE id = $next_next";
  2516. $res_upd2 = api_sql_query($sql_upd2);
  2517. }
  2518. $display = $display+1;
  2519. }
  2520. break;
  2521. default:
  2522. return false;
  2523. }
  2524. return $display;
  2525. }
  2526. /**
  2527. * Move a learnpath up (display_order)
  2528. * @param integer Learnpath ID
  2529. */
  2530. function move_up($lp_id)
  2531. {
  2532. $lp_table = Database::get_course_table(TABLE_LP_MAIN);
  2533. $sql = "SELECT * FROM $lp_table ORDER BY display_order";
  2534. $res = api_sql_query($sql);
  2535. if($res === false) return false;
  2536. $lps = array();
  2537. $lp_order = array();
  2538. $num = Database::num_rows($res);
  2539. //first check the order is correct, globally (might be wrong because
  2540. //of versions < 1.8.4)
  2541. if($num>0)
  2542. {
  2543. $i = 1;
  2544. while($row = Database::fetch_array($res))
  2545. {
  2546. if($row['display_order'] != $i)
  2547. { //if we find a gap in the order, we need to fix it
  2548. $need_fix = true;
  2549. $sql_u = "UPDATE $lp_table SET display_order = $i WHERE id = ".$row['id'];
  2550. $res_u = api_sql_query($sql_u);
  2551. }
  2552. $row['display_order'] = $i;
  2553. $lps[$row['id']] = $row;
  2554. $lp_order[$i] = $row['id'];
  2555. $i++;
  2556. }
  2557. }
  2558. if($num>1) //if there's only one element, no need to sort
  2559. {
  2560. $order = $lps[$lp_id]['display_order'];
  2561. if($order>1) //if it's the first element, no need to move up
  2562. {
  2563. $sql_u1 = "UPDATE $lp_table SET display_order = $order WHERE id = ".$lp_order[$order-1];
  2564. $res_u1 = api_sql_query($sql_u1);
  2565. $sql_u2 = "UPDATE $lp_table SET display_order = ".($order-1)." WHERE id = ".$lp_id;
  2566. $res_u2 = api_sql_query($sql_u2);
  2567. }
  2568. }
  2569. }
  2570. /**
  2571. * Move a learnpath down (display_order)
  2572. * @param integer Learnpath ID
  2573. */
  2574. function move_down($lp_id)
  2575. {
  2576. $lp_table = Database::get_course_table(TABLE_LP_MAIN);
  2577. $sql = "SELECT * FROM $lp_table ORDER BY display_order";
  2578. $res = api_sql_query($sql);
  2579. if($res === false) return false;
  2580. $lps = array();
  2581. $lp_order = array();
  2582. $num = Database::num_rows($res);
  2583. $max = 0;
  2584. //first check the order is correct, globally (might be wrong because
  2585. //of versions < 1.8.4)
  2586. if($num>0)
  2587. {
  2588. $i = 1;
  2589. while($row = Database::fetch_array($res))
  2590. {
  2591. $max = $i;
  2592. if($row['display_order'] != $i)
  2593. { //if we find a gap in the order, we need to fix it
  2594. $need_fix = true;
  2595. $sql_u = "UPDATE $lp_table SET display_order = $i WHERE id = ".$row['id'];
  2596. $res_u = api_sql_query($sql_u);
  2597. }
  2598. $row['display_order'] = $i;
  2599. $lps[$row['id']] = $row;
  2600. $lp_order[$i] = $row['id'];
  2601. $i++;
  2602. }
  2603. }
  2604. if($num>1) //if there's only one element, no need to sort
  2605. {
  2606. $order = $lps[$lp_id]['display_order'];
  2607. if($order<$max) //if it's the first element, no need to move up
  2608. {
  2609. $sql_u1 = "UPDATE $lp_table SET display_order = $order WHERE id = ".$lp_order[$order+1];
  2610. $res_u1 = api_sql_query($sql_u1);
  2611. $sql_u2 = "UPDATE $lp_table SET display_order = ".($order+1)." WHERE id = ".$lp_id;
  2612. $res_u2 = api_sql_query($sql_u2);
  2613. }
  2614. }
  2615. }
  2616. /**
  2617. * Updates learnpath attributes to point to the next element
  2618. * The last part is similar to set_current_item but processing the other way around
  2619. */
  2620. function next()
  2621. {
  2622. if($this->debug>0){error_log('New LP - In learnpath::next()',0);}
  2623. $this->last = $this->get_current_item_id();
  2624. $this->items[$this->last]->save(false,$this->prerequisites_match($this->last));
  2625. $this->autocomplete_parents($this->last);
  2626. $new_index = $this->get_next_index();
  2627. if($this->debug>2){error_log('New LP - New index: '.$new_index,0);}
  2628. $this->index = $new_index;
  2629. if($this->debug>2){error_log('New LP - Now having orderedlist['.$new_index.'] = '. $this->ordered_items[$new_index],0);}
  2630. $this->current = $this->ordered_items[$new_index];
  2631. if($this->debug>2){error_log('New LP - new item id is '.$this->current.'-'.$this->get_current_item_id(),0);}
  2632. }
  2633. /**
  2634. * Open a resource = initialise all local variables relative to this resource. Depending on the child
  2635. * class, this might be redefined to allow several behaviours depending on the document type.
  2636. * @param integer Resource ID
  2637. * @return boolean True on success, false otherwise
  2638. */
  2639. function open($id)
  2640. {
  2641. if($this->debug>0){error_log('New LP - In learnpath::open()',0);}
  2642. //TODO
  2643. //set the current resource attribute to this resource
  2644. //switch on element type (redefine in child class?)
  2645. //set status for this item to "opened"
  2646. //start timer
  2647. //initialise score
  2648. $this->index = 0; //or = the last item seen (see $this->last)
  2649. }
  2650. /**
  2651. * Check that all prerequisites are fulfilled. Returns true and an empty string on succes, returns false
  2652. * and the prerequisite string on error.
  2653. * This function is based on the rules for aicc_script language as described in the SCORM 1.2 CAM documentation page 108.
  2654. * @param integer Optional item ID. If none given, uses the current open item.
  2655. * @return boolean True if prerequisites are matched, false otherwise
  2656. * @return string Empty string if true returned, prerequisites string otherwise.
  2657. */
  2658. function prerequisites_match($item = null)
  2659. {
  2660. if($this->debug>0){error_log('New LP - In learnpath::prerequisites_match()',0);}
  2661. if(empty($item)){$item = $this->current;}
  2662. if(is_object($this->items[$item]))
  2663. {
  2664. $prereq_string = $this->items[$item]->get_prereq_string();
  2665. if(empty($prereq_string)){return true;}
  2666. //clean spaces
  2667. $prereq_string = str_replace(' ','',$prereq_string);
  2668. if($this->debug>0){error_log('Found prereq_string: '.$prereq_string,0);}
  2669. //now send to the parse_prereq() function that will check this component's prerequisites
  2670. $result = $this->items[$item]->parse_prereq($prereq_string,$this->items,$this->refs_list,$this->get_user_id());
  2671. if($result === false)
  2672. {
  2673. $this->set_error_msg($this->items[$item]->prereq_alert);
  2674. }
  2675. }else{
  2676. $result = true;
  2677. if($this->debug>1){error_log('New LP - $this->items['.$item.'] was not an object',0);}
  2678. }
  2679. if($this->debug>1){error_log('New LP - End of prerequisites_match(). Error message is now '.$this->error,0);}
  2680. return $result;
  2681. }
  2682. /**
  2683. * Updates learnpath attributes to point to the previous element
  2684. * The last part is similar to set_current_item but processing the other way around
  2685. */
  2686. function previous()
  2687. {
  2688. if($this->debug>0){error_log('New LP - In learnpath::previous()',0);}
  2689. $this->last = $this->get_current_item_id();
  2690. $this->items[$this->last]->save(false,$this->prerequisites_match($this->last));
  2691. $this->autocomplete_parents($this->last);
  2692. $new_index = $this->get_previous_index();
  2693. $this->index = $new_index;
  2694. $this->current = $this->ordered_items[$new_index];
  2695. }
  2696. /**
  2697. * Publishes a learnpath. This basically means show or hide the learnpath
  2698. * to normal users.
  2699. * Can be used as abstract
  2700. * @param integer Learnpath ID
  2701. * @param string New visibility
  2702. */
  2703. function toggle_visibility($lp_id,$set_visibility=1)
  2704. {
  2705. //if($this->debug>0){error_log('New LP - In learnpath::toggle_visibility()',0);}
  2706. $action = 'visible';
  2707. if($set_visibility != 1)
  2708. {
  2709. $action = 'invisible';
  2710. }
  2711. return api_item_property_update(api_get_course_info(),TOOL_LEARNPATH,$lp_id,$action,api_get_user_id());
  2712. }
  2713. /**
  2714. * Publishes a learnpath. This basically means show or hide the learnpath
  2715. * on the course homepage
  2716. * Can be used as abstract
  2717. * @param integer Learnpath ID
  2718. * @param string New visibility
  2719. */
  2720. function toggle_publish($lp_id,$set_visibility='v')
  2721. {
  2722. //if($this->debug>0){error_log('New LP - In learnpath::toggle_publish()',0);}
  2723. $tbl_lp = Database::get_course_table('lp');
  2724. $sql="SELECT * FROM $tbl_lp where id=$lp_id";
  2725. $result=api_sql_query($sql,__FILE__,__LINE__);
  2726. $row=Database::fetch_array($result);
  2727. $name=domesticate($row['name']);
  2728. if($set_visibility == 'i') {
  2729. $s=$name." ".get_lang('_no_published');
  2730. $dialogBox=$s;
  2731. $v=0;
  2732. }
  2733. if($set_visibility == 'v')
  2734. {
  2735. $s=$name." ".get_lang('_published');
  2736. $dialogBox=$s;
  2737. $v=1;
  2738. }
  2739. $tbl_tool = Database::get_course_table(TABLE_TOOL_LIST);
  2740. $link = 'newscorm/lp_controller.php?action=view&lp_id='.$lp_id;
  2741. $sql="SELECT * FROM $tbl_tool where name='$name' and image='scormbuilder.gif' and link LIKE '$link%'";
  2742. $result=api_sql_query($sql,__FILE__,__LINE__);
  2743. $num=Database::num_rows($result);
  2744. $row2=Database::fetch_array($result);
  2745. //if($this->debug>2){error_log('New LP - '.$sql.' - '.$num,0);}
  2746. if(($set_visibility == 'i') && ($num>0))
  2747. {
  2748. $sql ="DELETE FROM $tbl_tool WHERE (name='$name' and image='scormbuilder.gif' and link LIKE '$link%')";
  2749. }
  2750. elseif(($set_visibility == 'v') && ($num==0))
  2751. {
  2752. $sql ="INSERT INTO $tbl_tool (name, link, image, visibility, admin, address, added_tool) VALUES ('$name','newscorm/lp_controller.php?action=view&lp_id=$lp_id','scormbuilder.gif','$v','0','pastillegris.gif',0)";
  2753. }
  2754. else
  2755. {
  2756. //parameter and database incompatible, do nothing
  2757. }
  2758. $result=api_sql_query($sql,__FILE__,__LINE__);
  2759. //if($this->debug>2){error_log('New LP - Leaving learnpath::toggle_visibility: '.$sql,0);}
  2760. }
  2761. /**
  2762. * Restart the whole learnpath. Return the URL of the first element.
  2763. * Make sure the results are saved with anoter method. This method should probably be
  2764. * redefined in children classes.
  2765. * @return string URL to load in the viewer
  2766. */
  2767. function restart()
  2768. {
  2769. if($this->debug>0){error_log('New LP - In learnpath::restart()',0);}
  2770. //TODO
  2771. //call autosave method to save the current progress
  2772. //$this->index = 0;
  2773. $lp_view_table = Database::get_course_table('lp_view');
  2774. $sql = "INSERT INTO $lp_view_table (lp_id, user_id, view_count) " .
  2775. "VALUES (".$this->lp_id.",".$this->get_user_id().",".($this->attempt+1).")";
  2776. if($this->debug>2){error_log('New LP - Inserting new lp_view for restart: '.$sql,0);}
  2777. $res = api_sql_query($sql);
  2778. if($view_id = Database::get_last_insert_id($res))
  2779. {
  2780. $this->lp_view_id = $view_id;
  2781. $this->attempt = $this->attempt+1;
  2782. }else{
  2783. $this->error = 'Could not insert into item_view table...';
  2784. return false;
  2785. }
  2786. $this->autocomplete_parents($this->current);
  2787. foreach($this->items as $index=>$dummy){
  2788. $this->items[$index]->restart();
  2789. $this->items[$index]->set_lp_view($this->lp_view_id);
  2790. }
  2791. $this->first();
  2792. return true;
  2793. }
  2794. /**
  2795. * Saves the current item
  2796. * @return boolean
  2797. */
  2798. function save_current(){
  2799. if($this->debug>0){error_log('New LP - In learnpath::save_current()',0);}
  2800. //TODO do a better check on the index pointing to the right item (it is supposed to be working
  2801. // on $ordered_items[] but not sure it's always safe to use with $items[])
  2802. if($this->debug>2){error_log('New LP - save_current() saving item '.$this->current,0);}
  2803. if($this->debug>2){error_log(''.print_r($this->items,true),0);}
  2804. if(is_object($this->items[$this->current])){
  2805. //$res = $this->items[$this->current]->save(false);
  2806. $res = $this->items[$this->current]->save(false,$this->prerequisites_match($this->current));
  2807. $this->autocomplete_parents($this->current);
  2808. $status = $this->items[$this->current]->get_status();
  2809. $this->append_message('new_item_status: '.$status);
  2810. $this->update_queue[$this->current] = $status;
  2811. return $res;
  2812. }
  2813. return false;
  2814. }
  2815. /**
  2816. * Saves the given item
  2817. * @param integer Item ID. Optional (will take from $_REQUEST if null)
  2818. * @param boolean Save from url params (true) or from current attributes (false). Optional. Defaults to true
  2819. * @return boolean
  2820. */
  2821. function save_item($item_id=null,$from_outside=true){
  2822. if($this->debug>0){error_log('New LP - In learnpath::save_item('.$item_id.','.$from_outside.')',0);}
  2823. //TODO do a better check on the index pointing to the right item (it is supposed to be working
  2824. // on $ordered_items[] but not sure it's always safe to use with $items[])
  2825. if(empty($item_id)){
  2826. $item_id = $this->escape_string($_REQUEST['id']);
  2827. }
  2828. if(empty($item_id))
  2829. {
  2830. $item_id = $this->get_current_item_id();
  2831. }
  2832. if($this->debug>2){error_log('New LP - save_current() saving item '.$item_id,0);}
  2833. if(is_object($this->items[$item_id])){
  2834. $res = $this->items[$item_id]->save($from_outside,$this->prerequisites_match($item_id));
  2835. //$res = $this->items[$item_id]->save($from_outside);
  2836. $this->autocomplete_parents($item_id);
  2837. $status = $this->items[$item_id]->get_status();
  2838. $this->append_message('new_item_status: '.$status);
  2839. $this->update_queue[$item_id] = $status;
  2840. return $res;
  2841. }
  2842. return false;
  2843. }
  2844. /**
  2845. * Saves the last item seen's ID only in case
  2846. */
  2847. function save_last(){
  2848. if($this->debug>0){error_log('New LP - In learnpath::save_last()',0);}
  2849. $table = Database::get_course_table('lp_view');
  2850. if(isset($this->current)){
  2851. if($this->debug>2){error_log('New LP - Saving current item ('.$this->current.') for later review',0);}
  2852. $sql = "UPDATE $table SET last_item = ".$this->get_current_item_id()." " .
  2853. "WHERE lp_id = ".$this->get_id()." AND user_id = ".$this->get_user_id();
  2854. if($this->debug>2){error_log('New LP - Saving last item seen : '.$sql,0);}
  2855. $res = api_sql_query($sql,__FILE__,__LINE__);
  2856. }
  2857. //save progress
  2858. list($progress,$text) = $this->get_progress_bar_text('%');
  2859. if($progress>=0 AND $progress<=100){
  2860. $progress= (int)$progress;
  2861. $sql = "UPDATE $table SET progress = $progress " .
  2862. "WHERE lp_id = ".$this->get_id()." AND " .
  2863. "user_id = ".$this->get_user_id();
  2864. $res = @mysql_query($sql); //ignore errors as some tables might not have the progress field just yet
  2865. $this->progress_db = $progress;
  2866. }
  2867. }
  2868. /**
  2869. * Sets the current item ID (checks if valid and authorized first)
  2870. * @param integer New item ID. If not given or not authorized, defaults to current
  2871. */
  2872. function set_current_item($item_id=null)
  2873. {
  2874. if($this->debug>0){error_log('New LP - In learnpath::set_current_item('.$item_id.')',0);}
  2875. if(empty($item_id)){
  2876. if($this->debug>2){error_log('New LP - No new current item given, ignore...',0);}
  2877. //do nothing
  2878. }else{
  2879. if($this->debug>2){error_log('New LP - New current item given is '.$item_id.'...',0);}
  2880. $item_id = $this->escape_string($item_id);
  2881. //TODO check in database here
  2882. $this->last = $this->current;
  2883. $this->current = $item_id;
  2884. //TODO update $this->index as well
  2885. foreach($this->ordered_items as $index => $item)
  2886. {
  2887. if($item == $this->current)
  2888. {
  2889. $this->index = $index;
  2890. break;
  2891. }
  2892. }
  2893. if($this->debug>2){error_log('New LP - set_current_item('.$item_id.') done. Index is now : '.$this->index,0);}
  2894. }
  2895. }
  2896. /**
  2897. * Sets the encoding
  2898. * @param string New encoding
  2899. */
  2900. function set_encoding($enc='ISO-8859-1'){
  2901. if($this->debug>0){error_log('New LP - In learnpath::set_encoding()',0);}
  2902. $enc = strtoupper($enc);
  2903. $encodings = array('UTF-8','ISO-8859-1','ISO-8859-15','SHIFT-JIS');
  2904. if(in_array($enc,$encodings)){
  2905. $lp = $this->get_id();
  2906. if($lp!=0){
  2907. $tbl_lp = Database::get_course_table('lp');
  2908. $sql = "UPDATE $tbl_lp SET default_encoding = '$enc' WHERE id = ".$lp;
  2909. $res = api_sql_query($sql);
  2910. return $res;
  2911. }
  2912. }
  2913. return false;
  2914. }
  2915. /**
  2916. * Sets the JS lib setting in the database directly.
  2917. * This is the JavaScript library file this lp needs to load on startup
  2918. * @param string Proximity setting
  2919. */
  2920. function set_jslib($lib=''){
  2921. if($this->debug>0){error_log('New LP - In learnpath::set_jslib()',0);}
  2922. $lp = $this->get_id();
  2923. if($lp!=0){
  2924. $tbl_lp = Database::get_course_table('lp');
  2925. $sql = "UPDATE $tbl_lp SET js_lib = '$lib' WHERE id = ".$lp;
  2926. $res = api_sql_query($sql);
  2927. return $res;
  2928. }else{
  2929. return false;
  2930. }
  2931. }
  2932. /**
  2933. * Sets the name of the LP maker (publisher) (and save)
  2934. * @param string Optional string giving the new content_maker of this learnpath
  2935. */
  2936. function set_maker($name=''){
  2937. if($this->debug>0){error_log('New LP - In learnpath::set_maker()',0);}
  2938. if(empty($name))return false;
  2939. $this->maker = $this->escape_string($name);
  2940. $lp_table = Database::get_course_table('lp');
  2941. $lp_id = $this->get_id();
  2942. $sql = "UPDATE $lp_table SET content_maker = '".$this->maker."' WHERE id = '$lp_id'";
  2943. if($this->debug>2){error_log('New LP - lp updated with new content_maker : '.$this->maker,0);}
  2944. //$res = Database::query($sql);
  2945. $res = api_sql_query($sql);
  2946. return true;
  2947. }
  2948. /**
  2949. * Sets the name of the current learnpath (and save)
  2950. * @param string Optional string giving the new name of this learnpath
  2951. */
  2952. function set_name($name=''){
  2953. if($this->debug>0){error_log('New LP - In learnpath::set_name()',0);}
  2954. if(empty($name))return false;
  2955. $this->name = $this->escape_string($name);
  2956. $lp_table = Database::get_course_table('lp');
  2957. $lp_id = $this->get_id();
  2958. $sql = "UPDATE $lp_table SET name = '".$this->name."' WHERE id = '$lp_id'";
  2959. if($this->debug>2){error_log('New LP - lp updated with new name : '.$this->name,0);}
  2960. //$res = Database::query($sql);
  2961. $res = api_sql_query($sql, __FILE__, __LINE__);
  2962. // if the lp is visible on the homepage, change his name there
  2963. if(mysql_affected_rows())
  2964. {
  2965. $table = Database :: get_course_table(TABLE_TOOL_LIST);
  2966. $sql = 'UPDATE '.$table.' SET
  2967. name = "'.$this->name.'"
  2968. WHERE link = "newscorm/lp_controller.php?action=view&lp_id='.$lp_id.'"';
  2969. api_sql_query($sql, __FILE__, __LINE__);
  2970. }
  2971. return true;
  2972. }
  2973. /**
  2974. * Sets the theme of the LP (local/remote) (and save)
  2975. * @param string Optional string giving the new theme of this learnpath
  2976. * @return bool returns true if theme name is not empty
  2977. */
  2978. function set_theme($name=''){
  2979. if($this->debug>0){error_log('New LP - In learnpath::set_theme()',0);}
  2980. if(empty($name))return false;
  2981. $this->theme = $this->escape_string($name);
  2982. $lp_table = Database::get_course_table('lp');
  2983. $lp_id = $this->get_id();
  2984. $sql = "UPDATE $lp_table SET theme = '".$this->theme."' WHERE id = '$lp_id'";
  2985. if($this->debug>2){error_log('New LP - lp updated with new theme : '.$this->theme,0);}
  2986. //$res = Database::query($sql);
  2987. $res = api_sql_query($sql, __FILE__, __LINE__);
  2988. return true;
  2989. }
  2990. /**
  2991. * Sets the location/proximity of the LP (local/remote) (and save)
  2992. * @param string Optional string giving the new location of this learnpath
  2993. */
  2994. function set_proximity($name=''){
  2995. if($this->debug>0){error_log('New LP - In learnpath::set_proximity()',0);}
  2996. if(empty($name))return false;
  2997. $this->proximity = $this->escape_string($name);
  2998. $lp_table = Database::get_course_table('lp');
  2999. $lp_id = $this->get_id();
  3000. $sql = "UPDATE $lp_table SET content_local = '".$this->proximity."' WHERE id = '$lp_id'";
  3001. if($this->debug>2){error_log('New LP - lp updated with new proximity : '.$this->proximity,0);}
  3002. //$res = Database::query($sql);
  3003. $res = api_sql_query($sql, __FILE__, __LINE__);
  3004. return true;
  3005. }
  3006. /**
  3007. * Sets the previous item ID to a given ID. Generally, this should be set to the previous 'current' item
  3008. * @param integer DB ID of the item
  3009. */
  3010. function set_previous_item($id)
  3011. {
  3012. if($this->debug>0){error_log('New LP - In learnpath::set_previous_item()',0);}
  3013. $this->last = $id;
  3014. }
  3015. /**
  3016. * Sets the object's error message
  3017. * @param string Error message. If empty, reinits the error string
  3018. * @return void
  3019. */
  3020. function set_error_msg($error='')
  3021. {
  3022. if($this->debug>0){error_log('New LP - In learnpath::set_error_msg()',0);}
  3023. if(empty($error)){
  3024. $this->error = '';
  3025. }else{
  3026. $this->error .= $error;
  3027. }
  3028. }
  3029. /**
  3030. * Launches the current item if not 'sco' (starts timer and make sure there is a record ready in the DB)
  3031. *
  3032. */
  3033. function start_current_item($allow_new_attempt=false){
  3034. if($this->debug>0){error_log('New LP - In learnpath::start_current_item()',0);}
  3035. if($this->current != 0 AND
  3036. is_object($this->items[$this->current]))
  3037. {
  3038. $type = $this->get_type();
  3039. $item_type = $this->items[$this->current]->get_type();
  3040. if(
  3041. ($type == 2 && $item_type!='sco')
  3042. OR
  3043. ($type == 3 && $item_type!='au')
  3044. OR
  3045. ($type == 1 && $item_type!=TOOL_QUIZ && $item_type!=TOOL_HOTPOTATOES)
  3046. )
  3047. {
  3048. $this->items[$this->current]->open($allow_new_attempt);
  3049. $this->autocomplete_parents($this->current);
  3050. $prereq_check = $this->prerequisites_match($this->current);
  3051. $this->items[$this->current]->save(false,$prereq_check);
  3052. //$this->update_queue[$this->last] = $this->items[$this->last]->get_status();
  3053. }else{
  3054. //if sco, then it is supposed to have been updated by some other call
  3055. }
  3056. }
  3057. if($this->debug>0){error_log('New LP - End of learnpath::start_current_item()',0);}
  3058. return true;
  3059. }
  3060. /**
  3061. * Stops the processing and counters for the old item (as held in $this->last)
  3062. * @param
  3063. */
  3064. function stop_previous_item(){
  3065. if($this->debug>0){error_log('New LP - In learnpath::stop_previous_item()',0);}
  3066. if($this->last != 0 AND $this->last!=$this->current AND is_object($this->items[$this->last]))
  3067. {
  3068. if($this->debug>2){error_log('New LP - In learnpath::stop_previous_item() - '.$this->last.' is object',0);}
  3069. switch($this->get_type()){
  3070. case '3':
  3071. if($this->items[$this->last]->get_type()!='au')
  3072. {
  3073. if($this->debug>2){error_log('New LP - In learnpath::stop_previous_item() - '.$this->last.' in lp_type 3 is <> au',0);}
  3074. $this->items[$this->last]->close();
  3075. //$this->autocomplete_parents($this->last);
  3076. //$this->update_queue[$this->last] = $this->items[$this->last]->get_status();
  3077. }else{
  3078. if($this->debug>2){error_log('New LP - In learnpath::stop_previous_item() - Item is an AU, saving is managed by AICC signals',0);}
  3079. }
  3080. case '2':
  3081. if($this->items[$this->last]->get_type()!='sco')
  3082. {
  3083. if($this->debug>2){error_log('New LP - In learnpath::stop_previous_item() - '.$this->last.' in lp_type 2 is <> sco',0);}
  3084. $this->items[$this->last]->close();
  3085. //$this->autocomplete_parents($this->last);
  3086. //$this->update_queue[$this->last] = $this->items[$this->last]->get_status();
  3087. }else{
  3088. if($this->debug>2){error_log('New LP - In learnpath::stop_previous_item() - Item is a SCO, saving is managed by SCO signals',0);}
  3089. }
  3090. break;
  3091. case '1':
  3092. default:
  3093. if($this->debug>2){error_log('New LP - In learnpath::stop_previous_item() - '.$this->last.' in lp_type 1 is asset',0);}
  3094. $this->items[$this->last]->close();
  3095. break;
  3096. }
  3097. }else{
  3098. if($this->debug>2){error_log('New LP - In learnpath::stop_previous_item() - No previous element found, ignoring...',0);}
  3099. return false;
  3100. }
  3101. return true;
  3102. }
  3103. /**
  3104. * Updates the default view mode from fullscreen to embedded and inversely
  3105. * @return string The current default view mode ('fullscreen' or 'embedded')
  3106. */
  3107. function update_default_view_mode()
  3108. {
  3109. if($this->debug>0){error_log('New LP - In learnpath::update_default_view_mode()',0);}
  3110. $lp_table = Database::get_course_table('lp');
  3111. $sql = "SELECT * FROM $lp_table WHERE id = ".$this->get_id();
  3112. $res = api_sql_query($sql);
  3113. if(Database::num_rows($res)>0){
  3114. $row = Database::fetch_array($res);
  3115. $view_mode = $row['default_view_mod'];
  3116. if($view_mode == 'fullscreen'){
  3117. $view_mode = 'embedded';
  3118. }elseif($view_mode == 'embedded'){
  3119. $view_mode = 'fullscreen';
  3120. }
  3121. $sql = "UPDATE $lp_table SET default_view_mod = '$view_mode' WHERE id = ".$this->get_id();
  3122. $res = api_sql_query($sql);
  3123. $this->mode = $view_mode;
  3124. return $view_mode;
  3125. }else{
  3126. if($this->debug>2){error_log('New LP - Problem in update_default_view() - could not find LP '.$this->get_id().' in DB',0);}
  3127. }
  3128. return -1;
  3129. }
  3130. /**
  3131. * Updates the default behaviour about auto-commiting SCORM updates
  3132. * @return boolean True if auto-commit has been set to 'on', false otherwise
  3133. */
  3134. function update_default_scorm_commit(){
  3135. if($this->debug>0){error_log('New LP - In learnpath::update_default_scorm_commit()',0);}
  3136. $lp_table = Database::get_course_table('lp');
  3137. $sql = "SELECT * FROM $lp_table WHERE id = ".$this->get_id();
  3138. $res = api_sql_query($sql);
  3139. if(Database::num_rows($res)>0){
  3140. $row = Database::fetch_array($res);
  3141. $force = $row['force_commit'];
  3142. if($force == 1){
  3143. $force = 0;
  3144. $force_return = false;
  3145. }elseif($force == 0){
  3146. $force = 1;
  3147. $force_return = true;
  3148. }
  3149. $sql = "UPDATE $lp_table SET force_commit = $force WHERE id = ".$this->get_id();
  3150. $res = api_sql_query($sql);
  3151. $this->force_commit = $force_return;
  3152. return $force_return;
  3153. }else{
  3154. if($this->debug>2){error_log('New LP - Problem in update_default_scorm_commit() - could not find LP '.$this->get_id().' in DB',0);}
  3155. }
  3156. return -1;
  3157. }
  3158. /**
  3159. * Updates the order of learning paths (goes through all of them by order and fills the gaps)
  3160. * @return bool True on success, false on failure
  3161. */
  3162. function update_display_order()
  3163. {
  3164. $lp_table = Database::get_course_table(TABLE_LP_MAIN);
  3165. $sql = "SELECT * FROM $lp_table ORDER BY display_order";
  3166. $res = api_sql_query($sql);
  3167. if($res === false) return false;
  3168. $lps = array();
  3169. $lp_order = array();
  3170. $num = Database::num_rows($res);
  3171. //first check the order is correct, globally (might be wrong because
  3172. //of versions < 1.8.4)
  3173. if($num>0)
  3174. {
  3175. $i = 1;
  3176. while($row = Database::fetch_array($res))
  3177. {
  3178. if($row['display_order'] != $i)
  3179. { //if we find a gap in the order, we need to fix it
  3180. $need_fix = true;
  3181. $sql_u = "UPDATE $lp_table SET display_order = $i WHERE id = ".$row['id'];
  3182. $res_u = api_sql_query($sql_u);
  3183. }
  3184. $i++;
  3185. }
  3186. }
  3187. return true;
  3188. }
  3189. /**
  3190. * Updates the "prevent_reinit" value that enables control on reinitialising items on second view
  3191. * @return boolean True if prevent_reinit has been set to 'on', false otherwise (or 1 or 0 in this case)
  3192. */
  3193. function update_reinit(){
  3194. if($this->debug>0){error_log('New LP - In learnpath::update_reinit()',0);}
  3195. $lp_table = Database::get_course_table('lp');
  3196. $sql = "SELECT * FROM $lp_table WHERE id = ".$this->get_id();
  3197. $res = api_sql_query($sql);
  3198. if(Database::num_rows($res)>0){
  3199. $row = Database::fetch_array($res);
  3200. $force = $row['prevent_reinit'];
  3201. if($force == 1){
  3202. $force = 0;
  3203. }elseif($force == 0){
  3204. $force = 1;
  3205. }
  3206. $sql = "UPDATE $lp_table SET prevent_reinit = $force WHERE id = ".$this->get_id();
  3207. $res = api_sql_query($sql,__FILE__,__LINE__);
  3208. $this->prevent_reinit = $force;
  3209. return $force;
  3210. }else{
  3211. if($this->debug>2){error_log('New LP - Problem in update_reinit() - could not find LP '.$this->get_id().' in DB',0);}
  3212. }
  3213. return -1;
  3214. }
  3215. /**
  3216. * Updates the "scorm_debug" value that shows or hide the debug window
  3217. * @return boolean True if scorm_debug has been set to 'on', false otherwise (or 1 or 0 in this case)
  3218. */
  3219. function update_scorm_debug(){
  3220. if($this->debug>0){error_log('New LP - In learnpath::update_scorm_debug()',0);}
  3221. $lp_table = Database::get_course_table('lp');
  3222. $sql = "SELECT * FROM $lp_table WHERE id = ".$this->get_id();
  3223. $res = api_sql_query($sql);
  3224. if(Database::num_rows($res)>0){
  3225. $row = Database::fetch_array($res);
  3226. $force = $row['debug'];
  3227. if($force == 1){
  3228. $force = 0;
  3229. }elseif($force == 0){
  3230. $force = 1;
  3231. }
  3232. $sql = "UPDATE $lp_table SET debug = $force WHERE id = ".$this->get_id();
  3233. $res = api_sql_query($sql,__FILE__,__LINE__);
  3234. $this->scorm_debug = $force;
  3235. return $force;
  3236. }else{
  3237. if($this->debug>2){error_log('New LP - Problem in update_scorm_debug() - could not find LP '.$this->get_id().' in DB',0);}
  3238. }
  3239. return -1;
  3240. }
  3241. /**
  3242. * Function that makes a call to the function sort_tree_array and create_tree_array
  3243. *
  3244. * @author Kevin Van Den Haute
  3245. *
  3246. * @param unknown_type $array
  3247. */
  3248. function tree_array($array)
  3249. {
  3250. $array = $this->sort_tree_array($array);
  3251. $this->create_tree_array($array);
  3252. }
  3253. /**
  3254. * Creates an array with the elements of the learning path tree in it
  3255. *
  3256. * @author Kevin Van Den Haute
  3257. *
  3258. * @param array $array
  3259. * @param int $parent
  3260. * @param int $depth
  3261. * @param array $tmp
  3262. */
  3263. function create_tree_array($array, $parent = 0, $depth = -1, $tmp = array())
  3264. {
  3265. if(is_array($array))
  3266. {
  3267. for($i = 0; $i < count($array); $i++)
  3268. {
  3269. if($array[$i]['parent_item_id'] == $parent)
  3270. {
  3271. if(!in_array($array[$i]['parent_item_id'], $tmp))
  3272. {
  3273. $tmp[] = $array[$i]['parent_item_id'];
  3274. $depth++;
  3275. }
  3276. $this->arrMenu[] = array(
  3277. 'id' => $array[$i]['id'],
  3278. 'item_type' => $array[$i]['item_type'],
  3279. 'title' => $array[$i]['title'],
  3280. 'path' => $array[$i]['path'],
  3281. 'description' => $array[$i]['description'],
  3282. 'parent_item_id' => $array[$i]['parent_item_id'],
  3283. 'previous_item_id' => $array[$i]['previous_item_id'],
  3284. 'next_item_id' => $array[$i]['next_item_id'],
  3285. 'min_score' => $array[$i]['min_score'],
  3286. 'max_score' => $array[$i]['max_score'],
  3287. 'mastery_score' => $array[$i]['mastery_score'],
  3288. 'display_order' => $array[$i]['display_order'],
  3289. 'prerequisite' => $array[$i]['prerequisite'],
  3290. 'depth' => $depth
  3291. );
  3292. $this->create_tree_array($array, $array[$i]['id'], $depth, $tmp);
  3293. }
  3294. }
  3295. }
  3296. }
  3297. /**
  3298. * Sorts a multi dimensional array by parent id and display order
  3299. * @author Kevin Van Den Haute
  3300. *
  3301. * @param array $array (array with al the learning path items in it)
  3302. *
  3303. * @return array
  3304. */
  3305. function sort_tree_array($array)
  3306. {
  3307. foreach($array as $key => $row)
  3308. {
  3309. $parent[$key] = $row['parent_item_id'];
  3310. $position[$key] = $row['display_order'];
  3311. }
  3312. if(count($array) > 0)
  3313. array_multisort($parent, SORT_ASC, $position, SORT_ASC, $array);
  3314. return $array;
  3315. }
  3316. /**
  3317. * Function that creates a table structure with a learning path his modules, chapters and documents.
  3318. * Also the actions for the modules, chapters and documents are in this table.
  3319. *
  3320. * @author Kevin Van Den Haute
  3321. *
  3322. * @param int $lp_id
  3323. *
  3324. * @return string
  3325. */
  3326. function overview()
  3327. {
  3328. $return = '';
  3329. $tbl_lp_item = Database::get_course_table('lp_item');
  3330. $sql = "
  3331. SELECT *
  3332. FROM " . $tbl_lp_item . "
  3333. WHERE
  3334. lp_id = " . $this->lp_id;
  3335. $result = api_sql_query($sql, __FILE__, __LINE__);
  3336. $arrLP = array();
  3337. while($row = Database::fetch_array($result))
  3338. {
  3339. $arrLP[] = array(
  3340. 'id' => $row['id'],
  3341. 'item_type' => $row['item_type'],
  3342. 'title' => $row['title'],
  3343. 'description' => $row['description'],
  3344. 'parent_item_id' => $row['parent_item_id'],
  3345. 'previous_item_id' => $row['previous_item_id'],
  3346. 'next_item_id' => $row['next_item_id'],
  3347. 'display_order' => $row['display_order']);
  3348. }
  3349. $this->tree_array($arrLP);
  3350. $arrLP = $this->arrMenu;
  3351. unset($this->arrMenu);
  3352. if(api_is_allowed_to_edit())
  3353. $return .= '<p><a href="' .api_get_self(). '?cidReq=' . $_GET['cidReq'] . '&amp;action=build&amp;lp_id=' . $this->lp_id . '">'.get_lang("Advanced").'</a>&#124;'.get_lang("BasicOverview").'&#124;<a href="lp_controller.php?cidReq='.$_GET['cidReq'].'&action=view&lp_id='.$this->lp_id.'">'.get_lang("Display").'</a></p>';
  3354. $return .= '<table class="data_table">' . "\n";
  3355. $return .= "\t" . '<tr>' . "\n";
  3356. $return .= "\t" . '<th width="75%">'.get_lang("Title").'</th>' . "\n";
  3357. //$return .= "\t" . '<th>'.get_lang("Description").'</th>' . "\n";
  3358. $return .= "\t" . '<th>'.get_lang("Move").'</th>' . "\n";
  3359. $return .= "\t" . '<th>'.get_lang("Actions").'</th>' . "\n";
  3360. $return .= "\t" . '</tr>' . "\n";
  3361. for($i = 0; $i < count($arrLP); $i++)
  3362. {
  3363. if($arrLP[$i]['description'] == '')
  3364. $arrLP[$i]['description'] = '&nbsp;';
  3365. if (($i % 2)==0) { $oddclass="row_odd"; } else { $oddclass="row_even"; }
  3366. $return .= "\t" . '<tr class="'.$oddclass.'">' . "\n";
  3367. $return .= "\t\t" . '<td style="padding-left:' . $arrLP[$i]['depth'] * 10 . 'px;"><img align="left" src="../img/lp_' . $arrLP[$i]['item_type'] . '.png" style="margin-right:3px;" />' . stripslashes($arrLP[$i]['title']) . '</td>' . "\n";
  3368. //$return .= "\t\t" . '<td>' . stripslashes($arrLP[$i]['description']) . '</td>' . "\n";
  3369. if(api_is_allowed_to_edit())
  3370. {
  3371. $return .= "\t\t" . '<td>' . "\n";
  3372. if($arrLP[$i]['previous_item_id'] != 0)
  3373. {
  3374. $return .= "\t\t\t" . '<a href="' .api_get_self(). '?cidReq=' . $_GET['cidReq'] . '&amp;action=move_item&amp;direction=up&amp;id=' . $arrLP[$i]['id'] . '&amp;lp_id=' . $this->lp_id . '">';
  3375. $return .= '<img alt="" src="../img/arrow_up_' . ($arrLP[$i]['depth'] % 3) . '.gif" />';
  3376. $return .= '</a>' . "\n";
  3377. }
  3378. else
  3379. $return .= "\t\t\t" . '<img alt="" src="../img/blanco.png" title="" />' . "\n";
  3380. if($arrLP[$i]['next_item_id'] != 0)
  3381. {
  3382. $return .= "\t\t\t" . '<a href="' .api_get_self(). '?cidReq=' . $_GET['cidReq'] . '&amp;action=move_item&amp;direction=down&amp;id=' . $arrLP[$i]['id'] . '&amp;lp_id=' . $this->lp_id . '">';
  3383. $return .= '<img src="../img/arrow_down_' . ($arrLP[$i]['depth'] % 3) . '.gif" />';
  3384. $return .= '</a>' . "\n";
  3385. }
  3386. else
  3387. $return .= "\t\t\t" . '<img alt="" src="../img/blanco.png" title="" />' . "\n";
  3388. $return .= "\t\t" . '</td>' . "\n";
  3389. $return .= "\t\t" . '<td>' . "\n";
  3390. if($arrLP[$i]['item_type'] != 'dokeos_chapter' && $arrLP[$i]['item_type'] != 'dokeos_module')
  3391. {
  3392. $return .= "\t\t\t" . '<a href="' .api_get_self(). '?cidReq=' . $_GET['cidReq'] . '&amp;action=edit_item&amp;view=build&amp;id=' . $arrLP[$i]['id'] . '&amp;lp_id=' . $this->lp_id . '">';
  3393. $return .= '<img alt="" src="../img/edit.gif" title="' . get_lang('_edit_learnpath_module') . '" />';
  3394. $return .= '</a>' . "\n";
  3395. }
  3396. else
  3397. {
  3398. $return .= "\t\t\t" . '<a href="' .api_get_self(). '?cidReq=' . $_GET['cidReq'] . '&amp;action=edit_item&amp;id=' . $arrLP[$i]['id'] . '&amp;lp_id=' . $this->lp_id . '">';
  3399. $return .= '<img alt="" src="../img/edit.gif" title="' . get_lang('_edit_learnpath_module') . '" />';
  3400. $return .= '</a>' . "\n";
  3401. }
  3402. $return .= "\t\t\t" . '<a href="' .api_get_self(). '?cidReq=' . $_GET['cidReq'] . '&amp;action=delete_item&amp;id=' . $arrLP[$i]['id'] . '&amp;lp_id=' . $this->lp_id . '" onclick="return confirmation(\'' . $arrLP[$i]['title'] . '\');">';
  3403. $return .= '<img alt="" src="../img/delete.gif" title="' . get_lang('_delete_learnpath_module') . '" />';
  3404. $return .= '</a>' . "\n";
  3405. $return .= "\t\t" . '</td>' . "\n";
  3406. }
  3407. $return .= "\t" . '</tr>' . "\n";
  3408. }
  3409. if(count($arrLP) == 0)
  3410. {
  3411. $return .= "\t" . '<tr>' . "\n";
  3412. $return .= "\t\t" . '<td colspan="4">'.get_lang("NoItemsInLp").'</td>' . "\n";
  3413. $return .= "\t" . '</tr>' . "\n";
  3414. }
  3415. $return .= '</table>' . "\n";
  3416. return $return;
  3417. }
  3418. /**
  3419. * This functions builds the LP tree based on data from the database.
  3420. *
  3421. * @return string
  3422. * @uses dtree.js :: necessary javascript for building this tree
  3423. */
  3424. function build_tree()
  3425. {
  3426. $return = "<script type=\"text/javascript\">\n";
  3427. $return .= "\tm = new dTree('m');\n\n";
  3428. $return .= "\tm.config.folderLinks = true;\n";
  3429. $return .= "\tm.config.useCookies = true;\n";
  3430. $return .= "\tm.config.useIcons = true;\n";
  3431. $return .= "\tm.config.useLines = true;\n";
  3432. $return .= "\tm.config.useSelection = true;\n";
  3433. $return .= "\tm.config.useStatustext = false;\n\n";
  3434. $menu = 0;
  3435. $parent = '';
  3436. $return .= "\tm.add(" . $menu . ", -1, '" . addslashes($this->name) . "');\n";
  3437. $tbl_lp_item = Database::get_course_table('lp_item');
  3438. $sql = "
  3439. SELECT *
  3440. FROM " . $tbl_lp_item . "
  3441. WHERE
  3442. lp_id = " . $this->lp_id;
  3443. $result = api_sql_query($sql, __FILE__, __LINE__);
  3444. $arrLP = array();
  3445. while($row = Database::fetch_array($result))
  3446. {
  3447. if($this->encoding=='UTF-8')
  3448. {
  3449. $row['title'] = utf8_decode($row['title']);
  3450. }
  3451. $arrLP[] = array(
  3452. 'id' => $row['id'],
  3453. 'item_type' => $row['item_type'],
  3454. 'title' => addslashes($row['title']),
  3455. 'path' => $row['path'],
  3456. 'description' => $row['description'],
  3457. 'parent_item_id' => $row['parent_item_id'],
  3458. 'previous_item_id' => $row['previous_item_id'],
  3459. 'next_item_id' => $row['next_item_id'],
  3460. 'display_order' => $row['display_order']);
  3461. }
  3462. $this->tree_array($arrLP);
  3463. $arrLP = $this->arrMenu;
  3464. unset($this->arrMenu);
  3465. for($i = 0; $i < count($arrLP); $i++)
  3466. {
  3467. $menu_page = api_get_self() . '?cidReq=' . $_GET['cidReq'] . '&amp;action=view_item&amp;id=' . $arrLP[$i]['id'] . '&amp;lp_id=' . $_SESSION['oLP']->lp_id;
  3468. if(file_exists("../img/lp_" . $arrLP[$i]['item_type'] . ".png"))
  3469. {
  3470. $return .= "\tm.add(" . $arrLP[$i]['id'] . ", " . $arrLP[$i]['parent_item_id'] . ", '" . stripslashes($arrLP[$i]['title']) . "', '" . $menu_page . "', '', '', '../img/lp_" . $arrLP[$i]['item_type'] . ".png', '../img/lp_" . $arrLP[$i]['item_type'] . ".png');\n";
  3471. }
  3472. else if(file_exists("../img/lp_" . $arrLP[$i]['item_type'] . ".gif"))
  3473. {
  3474. $return .= "\tm.add(" . $arrLP[$i]['id'] . ", " . $arrLP[$i]['parent_item_id'] . ", '" . stripslashes($arrLP[$i]['title']) . "', '" . $menu_page . "', '', '', '../img/lp_" . $arrLP[$i]['item_type'] . ".gif', '../img/lp_" . $arrLP[$i]['item_type'] . ".gif');\n";
  3475. }
  3476. else
  3477. {
  3478. $return .= "\tm.add(" . $arrLP[$i]['id'] . ", " . $arrLP[$i]['parent_item_id'] . ", '" . stripslashes($arrLP[$i]['title']) . "', '" . $menu_page . "', '', '', '../img/lp_document.png', '../img/lp_document.png');\n";
  3479. }
  3480. if($menu < $arrLP[$i]['id'])
  3481. $menu = $arrLP[$i]['id'];
  3482. }
  3483. $return .= "\n\tdocument.write(m);\n";
  3484. $return .= "\t if(!m.selectedNode) m.s(1);";
  3485. $return .= "</script>\n";
  3486. return $return;
  3487. }
  3488. /**
  3489. * Create a new document //still needs some finetuning
  3490. *
  3491. * @param array $_course
  3492. * @return string
  3493. */
  3494. function create_document($_course)
  3495. {
  3496. $dir = isset($_GET['dir']) ? $_GET['dir'] : $_POST['dir']; // please do not modify this dirname formatting
  3497. if(strstr($dir, '..'))
  3498. $dir = '/';
  3499. if($dir[0] == '.')
  3500. $dir = substr($dir, 1);
  3501. if($dir[0] != '/')
  3502. $dir = '/'.$dir;
  3503. if($dir[strlen($dir) - 1] != '/')
  3504. $dir .= '/';
  3505. $filepath = api_get_path('SYS_COURSE_PATH') . $_course['path'] . '/document' . $dir;
  3506. if(!is_dir($filepath))
  3507. {
  3508. $filepath = api_get_path('SYS_COURSE_PATH') . $_course['path'] . '/document/';
  3509. $dir = '/';
  3510. }
  3511. //stripslashes before calling replace_dangerous_char() because $_POST['title']
  3512. //is already escaped twice when it gets here
  3513. $title = replace_dangerous_char(stripslashes($_POST['title']));
  3514. $filename = $title;
  3515. $content = $_POST['content_lp'];
  3516. $tmp_filename = $filename;
  3517. $i=0;
  3518. while(file_exists($filepath . $tmp_filename . '.html'))
  3519. $tmp_filename = $filename . '_' . ++$i;
  3520. $filename = $tmp_filename . '.html';
  3521. $content = stripslashes(text_filter($content));
  3522. //if flv player, change absolute paht temporarely to prevent from erasing it in the following lines
  3523. $content = str_replace('flv=h','flv=h|',$content);
  3524. $content = str_replace('flv=/','flv=/|',$content);
  3525. $content = str_replace(api_get_path('WEB_COURSE_PATH'), api_get_path(REL_PATH).'courses/', $content);
  3526. // for flv player : change back the url to absolute
  3527. $content = str_replace('flv=h|','flv=h',$content);
  3528. $content = str_replace('flv=/|','flv=/',$content);
  3529. // for flv player : to prevent edition problem with firefox, we have to use a strange tip (don't blame me please)
  3530. $content = str_replace('</body>','<style type="text/css">body{}</style></body>',$content);
  3531. if(!file_exists($filepath . $filename))
  3532. {
  3533. if($fp = @fopen($filepath . $filename, 'w'))
  3534. {
  3535. fputs($fp, $content);
  3536. fclose($fp);
  3537. $file_size = filesize($filepath . $filename);
  3538. $save_file_path = $dir . $filename;
  3539. $document_id = add_document($_course, $save_file_path, 'file', $file_size, $filename . '.html');
  3540. if($document_id)
  3541. {
  3542. api_item_property_update($_course, TOOL_DOCUMENT, $document_id, 'DocumentAdded', api_get_user_id());
  3543. //update parent folders
  3544. //item_property_update_on_folder($_course, $_GET['dir'], $_user['user_id']);
  3545. $new_comment = (isset($_POST['comment'])) ? trim($_POST['comment']) : '';
  3546. $new_title = (isset($_POST['title'])) ? trim($_POST['title']) : '';
  3547. if($new_comment || $new_title)
  3548. {
  3549. $tbl_doc = Database::get_course_table(TABLE_DOCUMENT);
  3550. $ct = '';
  3551. if($new_comment)
  3552. $ct .= ", comment='" . $new_comment . "'";
  3553. if($new_title)
  3554. $ct .= ", title='" . $new_title . ".html '";
  3555. $sql_update = "
  3556. UPDATE " . $tbl_doc . "
  3557. SET " . substr($ct, 1) . "
  3558. WHERE id = " . $document_id;
  3559. api_sql_query($sql_update, __FILE__, __LINE__);
  3560. }
  3561. }
  3562. return $document_id;
  3563. }
  3564. }
  3565. }
  3566. /**
  3567. * Enter description here...
  3568. *
  3569. * @param array $_course
  3570. */
  3571. function edit_document($_course)
  3572. {
  3573. global $_configuration;
  3574. $dir = isset($_GET['dir']) ? $_GET['dir'] : $_POST['dir']; // please do not modify this dirname formatting
  3575. if(strstr($dir, '..'))
  3576. $dir = '/';
  3577. if($dir[0] == '.')
  3578. $dir = substr($dir, 1);
  3579. if($dir[0] != '/')
  3580. $dir = '/'.$dir;
  3581. if($dir[strlen($dir) - 1] != '/')
  3582. $dir .= '/';
  3583. $filepath = api_get_path('SYS_COURSE_PATH') . $_course['path'] . '/document'.$dir;
  3584. if(!is_dir($filepath))
  3585. {
  3586. $filepath = api_get_path('SYS_COURSE_PATH') . $_course['path'] . '/document/';
  3587. $dir = '/';
  3588. }
  3589. $table_doc = Database::get_course_table(TABLE_DOCUMENT);
  3590. $sql = "
  3591. SELECT path
  3592. FROM " . $table_doc . "
  3593. WHERE id = " . $_POST['path'];
  3594. $res = api_sql_query($sql, __FILE__, __LINE__);
  3595. $row = Database::fetch_array($res);
  3596. $content = stripslashes($_POST['content_lp']);
  3597. $file = $filepath . $row['path'];
  3598. if($fp = @fopen($file, 'w'))
  3599. {
  3600. $content = text_filter($content);
  3601. $content = str_replace(api_get_path('WEB_COURSE_PATH'), $_configuration['url_append'].'/courses/', $content);
  3602. fputs($fp, $content);
  3603. fclose($fp);
  3604. }
  3605. }
  3606. /**
  3607. * Displays the selected item, with a panel for manipulating the item
  3608. *
  3609. * @param int $item_id
  3610. * @param string $msg
  3611. * @return string
  3612. */
  3613. function display_item($item_id, $iframe = true, $msg = '')
  3614. {
  3615. global $_course; //will disappear
  3616. $return = '';
  3617. if(is_numeric($item_id))
  3618. {
  3619. $tbl_lp_item = Database::get_course_table('lp_item');
  3620. $tbl_doc = Database::get_course_table(TABLE_DOCUMENT);
  3621. $sql = "
  3622. SELECT
  3623. lp.*
  3624. FROM " . $tbl_lp_item . " as lp
  3625. WHERE
  3626. lp.id = " . $item_id;
  3627. $result = api_sql_query($sql, __FILE__, __LINE__);
  3628. while($row = Database::fetch_array($result))
  3629. {
  3630. $return .= $this->display_manipulate($item_id, $row['item_type']);
  3631. $return .= '<div style="padding:10px;">';
  3632. if($msg != '')
  3633. $return .= $msg;
  3634. if($this->encoding=='UTF-8')
  3635. {
  3636. $row['title'] = utf8_decode($row['title']);
  3637. }
  3638. $return .= '<p class="lp_title">' . stripslashes($row['title']) . '</p>';
  3639. //$return .= '<p class="lp_text">' . ((trim($row['description']) == '') ? 'no description' : stripslashes($row['description'])) . '</p>';
  3640. //$return .= '<hr />';
  3641. if($row['item_type'] == TOOL_DOCUMENT)
  3642. {
  3643. $tbl_doc = Database :: get_course_table(TABLE_DOCUMENT);
  3644. $sql_doc = "SELECT path FROM " . $tbl_doc . " WHERE id = " . $row['path'];
  3645. $result=api_sql_query($sql_doc);
  3646. $path_file=mysql_result($result,0,0);
  3647. $path_parts = pathinfo($path_file);
  3648. if(in_array($path_parts['extension'],array('html','txt','png', 'jpg', 'JPG', 'jpeg', 'JPEG', 'gif', 'swf')))
  3649. {
  3650. $return .= $this->display_document($row['path'], true, true);
  3651. }
  3652. }
  3653. $return .= '</div>';
  3654. }
  3655. }
  3656. return $return;
  3657. }
  3658. /**
  3659. * Shows the needed forms for editing a specific item
  3660. *
  3661. * @param int $item_id
  3662. * @return string
  3663. */
  3664. function display_edit_item($item_id)
  3665. {
  3666. global $_course; //will disappear
  3667. $return = '';
  3668. if(is_numeric($item_id))
  3669. {
  3670. $tbl_lp_item = Database::get_course_table('lp_item');
  3671. $sql = "
  3672. SELECT *
  3673. FROM " . $tbl_lp_item . "
  3674. WHERE id = " . $item_id;
  3675. $res = api_sql_query($sql, __FILE__, __LINE__);
  3676. $row = Database::fetch_array($res);
  3677. switch($row['item_type'])
  3678. {
  3679. case 'dokeos_chapter': case 'dir' : case 'asset' : case 'sco' :
  3680. if(isset($_GET['view']) && $_GET['view'] == 'build')
  3681. {
  3682. $return .= $this->display_manipulate($item_id, $row['item_type']);
  3683. $return .= $this->display_item_form($row['item_type'], get_lang("EditCurrentChapter").' :', 'edit', $item_id, $row);
  3684. }
  3685. else
  3686. {
  3687. $return .= $this->display_item_small_form($row['item_type'], get_lang("EditCurrentChapter").' :', $row);
  3688. }
  3689. break;
  3690. case TOOL_DOCUMENT:
  3691. $tbl_doc = Database::get_course_table(TABLE_DOCUMENT);
  3692. $sql_step = "
  3693. SELECT
  3694. lp.*,
  3695. doc.path as dir
  3696. FROM " . $tbl_lp_item . " as lp
  3697. LEFT JOIN " . $tbl_doc . " as doc ON doc.id = lp.path
  3698. WHERE
  3699. lp.id = " . $item_id;
  3700. $res_step = api_sql_query($sql_step, __FILE__, __LINE__);
  3701. $row_step = Database::fetch_array($res_step);
  3702. $return .= $this->display_manipulate($item_id, $row['item_type']);
  3703. $return .= $this->display_document_form('edit', $item_id, $row_step);
  3704. break;
  3705. case TOOL_LINK:
  3706. $return .= $this->display_manipulate($item_id, $row['item_type']);
  3707. $return .= $this->display_link_form('edit', $item_id, $row);
  3708. break;
  3709. case 'dokeos_module':
  3710. if(isset($_GET['view']) && $_GET['view'] == 'build')
  3711. {
  3712. $return .= $this->display_manipulate($item_id, $row['item_type']);
  3713. $return .= $this->display_item_form($row['item_type'], get_lang("EditCurrentModule").' :', 'edit', $item_id, $row);
  3714. }
  3715. else
  3716. {
  3717. $return .= $this->display_item_small_form($row['item_type'], get_lang("EditCurrentModule").' :', $row);
  3718. }
  3719. break;
  3720. case TOOL_QUIZ:
  3721. $return .= $this->display_manipulate($item_id, $row['item_type']);
  3722. $return .= $this->display_quiz_form('edit', $item_id, $row);
  3723. break;
  3724. case TOOL_HOTPOTATOES:
  3725. $return .= $this->display_manipulate($item_id, $row['item_type']);
  3726. $return .= $this->display_hotpotatoes_form('edit', $item_id, $row);
  3727. break;
  3728. case TOOL_STUDENTPUBLICATION:
  3729. $return .= $this->display_manipulate($item_id, $row['item_type']);
  3730. $return .= $this->display_student_publication_form('edit', $item_id, $row);
  3731. break;
  3732. case TOOL_FORUM:
  3733. $return .= $this->display_manipulate($item_id, $row['item_type']);
  3734. $return .= $this->display_forum_form('edit', $item_id, $row);
  3735. break;
  3736. case TOOL_THREAD:
  3737. $return .= $this->display_manipulate($item_id, $row['item_type']);
  3738. $return .= $this->display_thread_form('edit', $item_id, $row);
  3739. break;
  3740. }
  3741. }
  3742. return $return;
  3743. }
  3744. /**
  3745. * Function that displays a list with al the resources that could be added to the learning path
  3746. *
  3747. * @return string
  3748. */
  3749. function display_resources()
  3750. {
  3751. global $_course; //TODO: don't use globals
  3752. $return = '<div style="margin:3px 10px;">' . "\n";
  3753. $return .= '<p class="lp_title" style="margin-top:0;">'.get_lang("CreateNewStep").'</p>';
  3754. $return .= '<div><a href="' .api_get_self(). '?cidReq=' . $_GET['cidReq'] . '&amp;action=add_item&amp;type=' . TOOL_DOCUMENT . '&amp;lp_id=' . $_SESSION['oLP']->lp_id . '">'.get_lang("NewDocument").'</a></div>';
  3755. $return .= '<p class="lp_title" style="margin-top:10px;">'.get_lang("UseAnExistingResource").'</p>';
  3756. /* get all the docs */
  3757. $return .= $this->get_documents();
  3758. /* get all the exercises */
  3759. $return .= $this->get_exercises();
  3760. /* get all the links */
  3761. $return .= $this->get_links();
  3762. /* get al the student publications */
  3763. $return .= $this->get_student_publications();
  3764. /* get al the forums */
  3765. $return .= $this->get_forums();
  3766. $return .= '</div>' . "\n";
  3767. return $return;
  3768. }
  3769. /**
  3770. * Returns the extension of a document
  3771. *
  3772. * @param unknown_type $filename
  3773. * @return unknown
  3774. */
  3775. function get_extension($filename)
  3776. {
  3777. $explode = explode('.', $filename);
  3778. return $explode[count($explode) - 1];
  3779. }
  3780. /**
  3781. * Displays a document by id
  3782. *
  3783. * @param unknown_type $id
  3784. * @return unknown
  3785. */
  3786. function display_document($id, $show_title = false, $iframe = true, $edit_link = false)
  3787. {
  3788. global $_course; //temporary
  3789. $return = '';
  3790. $tbl_doc = Database::get_course_table(TABLE_DOCUMENT);
  3791. $sql_doc = "
  3792. SELECT *
  3793. FROM " . $tbl_doc . "
  3794. WHERE id = " . $id;
  3795. $res_doc = api_sql_query($sql_doc, __FILE__, __LINE__);
  3796. $row_doc = Database::fetch_array($res_doc);
  3797. //if($show_title)
  3798. //$return .= '<p class="lp_title">' . $row_doc['title'] . ($edit_link ? ' [ <a href="' .api_get_self(). '?cidReq=' . $_GET['cidReq'] . '&amp;action=add_item&amp;type=' . TOOL_DOCUMENT . '&amp;file=' . $_GET['file'] . '&amp;edit=true&amp;lp_id=' . $_GET['lp_id'] . '">Edit this document</a> ]' : '') . '</p>';
  3799. //TODO: add a path filter
  3800. if($iframe){
  3801. $return .= '<iframe frameborder="0" src="' . api_get_path(WEB_COURSE_PATH) . $_course['path'] . '/document' . str_replace('%2F','/',urlencode($row_doc['path'])) . '?'.api_get_cidreq().'" style="background:#FFFFFF; border:1px solid #CCCCCC; height:490px; width:100%; margin-top: 20px;"></iframe>';
  3802. }
  3803. else{
  3804. $return .= file_get_contents(api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document' . $row_doc['path']);
  3805. }
  3806. return $return;
  3807. }
  3808. /**
  3809. * Enter description here...
  3810. *
  3811. * @param unknown_type $action
  3812. * @param unknown_type $id
  3813. * @param unknown_type $extra_info
  3814. * @return unknown
  3815. */
  3816. function display_quiz_form($action = 'add', $id = 0, $extra_info = '')
  3817. {
  3818. $tbl_lp_item = Database::get_course_table(TABLE_LP_ITEM);
  3819. $tbl_quiz = Database::get_course_table(TABLE_QUIZ_TEST);
  3820. if($id != 0 && is_array($extra_info))
  3821. {
  3822. $item_title = stripslashes($extra_info['title']);
  3823. $item_description = stripslashes($extra_info['description']);
  3824. }
  3825. elseif(is_numeric($extra_info))
  3826. {
  3827. $sql_quiz = "
  3828. SELECT
  3829. title,
  3830. description
  3831. FROM " . $tbl_quiz . "
  3832. WHERE id = " . $extra_info;
  3833. $result = api_sql_query($sql_quiz, __FILE__, __LINE__);
  3834. $row = Database::fetch_array($result);
  3835. $item_title = $row['title'];
  3836. $item_description = $row['description'];
  3837. }
  3838. else
  3839. {
  3840. $item_title = '';
  3841. $item_description = '';
  3842. }
  3843. $return = '<div style="margin:3px 10px;">';
  3844. if($id != 0 && is_array($extra_info))
  3845. $parent = $extra_info['parent_item_id'];
  3846. else
  3847. $parent = 0;
  3848. $sql = "
  3849. SELECT *
  3850. FROM " . $tbl_lp_item . "
  3851. WHERE
  3852. lp_id = " . $this->lp_id;
  3853. $result = api_sql_query($sql, __FILE__, __LINE__);
  3854. $arrLP = array();
  3855. while($row = Database::fetch_array($result))
  3856. {
  3857. $arrLP[] = array(
  3858. 'id' => $row['id'],
  3859. 'item_type' => $row['item_type'],
  3860. 'title' => $row['title'],
  3861. 'path' => $row['path'],
  3862. 'description' => $row['description'],
  3863. 'parent_item_id' => $row['parent_item_id'],
  3864. 'previous_item_id' => $row['previous_item_id'],
  3865. 'next_item_id' => $row['next_item_id'],
  3866. 'display_order' => $row['display_order'],
  3867. 'prerequisite' => $row['prerequisite']);
  3868. }
  3869. $this->tree_array($arrLP);
  3870. $arrLP = $this->arrMenu;
  3871. unset($this->arrMenu);
  3872. if($action == 'add')
  3873. $return .= '<p class="lp_title">'.get_lang("CreateTheExercise").' :</p>' . "\n";
  3874. elseif($action == 'move')
  3875. $return .= '<p class="lp_title">'.get_lang("MoveTheCurrentExercise").' :</p>' . "\n";
  3876. else
  3877. $return .= '<p class="lp_title">'.get_lang("EditCurrentExecice").' :</p>' . "\n";
  3878. if(isset($_GET['edit']) && $_GET['edit'] == 'true')
  3879. {
  3880. $return .= '<div class="lp_message" style="margin-bottom:15px;">';
  3881. $return .= '<p class="lp_title">'.get_lang("Warning").' !</p>';
  3882. $return .= get_lang("WarningEditingDocument");
  3883. $return .= '</div>';
  3884. }
  3885. $return .= '<form method="POST">' . "\n";
  3886. $return .= "\t" . '<table cellpadding="0" cellspacing="0" class="lp_form">' . "\n";
  3887. $return .= "\t\t" . '<tr>' . "\n";
  3888. $return .= "\t\t\t" . '<td class="label"><label for="idParent">'.get_lang("Parent").' :</label></td>' . "\n";
  3889. $return .= "\t\t\t" . '<td class="input">' . "\n";
  3890. $return .= "\t\t\t\t" . '<select id="idParent" name="parent" onchange="load_cbo(this.value);" size="1">';
  3891. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
  3892. $arrHide = array($id);
  3893. for($i = 0; $i < count($arrLP); $i++)
  3894. {
  3895. if($action != 'add')
  3896. {
  3897. 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))
  3898. {
  3899. $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'] . '">' . html_entity_decode(stripslashes($arrLP[$i]['title'])) . '</option>';
  3900. }
  3901. else
  3902. {
  3903. $arrHide[] = $arrLP[$i]['id'];
  3904. }
  3905. }
  3906. else
  3907. {
  3908. if($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
  3909. $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'] . '">' . html_entity_decode(stripslashes($arrLP[$i]['title'])) . '</option>';
  3910. }
  3911. }
  3912. reset($arrLP);
  3913. $return .= "\t\t\t\t" . '</select>';
  3914. $return .= "\t\t\t" . '</td>' . "\n";
  3915. $return .= "\t\t" . '</tr>' . "\n";
  3916. $return .= "\t\t" . '<tr>' . "\n";
  3917. $return .= "\t\t\t" . '<td class="label"><label for="idPosition">'.get_lang("Position").' :</label></td>' . "\n";
  3918. $return .= "\t\t\t" . '<td class="input">' . "\n";
  3919. $return .= "\t\t\t\t" . '<select id="idPosition" name="previous" size="1">';
  3920. $return .= "\t\t\t\t\t" . '<option class="top" value="0">First position</option>';
  3921. for($i = 0; $i < count($arrLP); $i++)
  3922. {
  3923. if($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id)
  3924. {
  3925. if($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  3926. $selected = 'selected="selected" ';
  3927. elseif($action == 'add')
  3928. $selected = 'selected="selected" ';
  3929. else
  3930. $selected = '';
  3931. $return .= "\t\t\t\t\t" . '<option ' . $selected . 'value="' . $arrLP[$i]['id'] . '">'.get_lang("After").' "' . html_entity_decode(stripslashes($arrLP[$i]['title'])) . '"</option>';
  3932. }
  3933. }
  3934. $return .= "\t\t\t\t" . '</select>';
  3935. $return .= "\t\t\t" . '</td>' . "\n";
  3936. $return .= "\t\t" . '</tr>' . "\n";
  3937. if($action != 'move')
  3938. {
  3939. $return .= "\t\t" . '<tr>' . "\n";
  3940. $return .= "\t\t\t" . '<td class="label"><label for="idTitle">'.get_lang("Title").' :</label></td>' . "\n";
  3941. $return .= "\t\t\t" . '<td class="input"><input id="idTitle" name="title" type="text" value="' . $item_title . '" /></td>' . "\n";
  3942. $return .= "\t\t" . '</tr>' . "\n";
  3943. $id_prerequisite=0;
  3944. foreach($arrLP as $key=>$value){
  3945. if($value['id']==$id){
  3946. $id_prerequisite=$value['prerequisite'];
  3947. break;
  3948. }
  3949. }
  3950. $arrHide=array();
  3951. for($i = 0; $i < count($arrLP); $i++)
  3952. {
  3953. if($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter')
  3954. {
  3955. if($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  3956. $s_selected_position=$arrLP[$i]['id'];
  3957. elseif($action == 'add')
  3958. $s_selected_position=0;
  3959. $arrHide[$arrLP[$i]['id']]['value']=html_entity_decode(stripslashes($arrLP[$i]['title']));
  3960. }
  3961. }
  3962. $return .= "\t\t" . '<tr>' . "\n";
  3963. $return .= "\t\t\t" . '<td class="label"><label for="idPrerequisites">'.get_lang("Prerequisites").' :</label></td>' . "\n";
  3964. $return .= "\t\t\t" . '<td class="input"><select name="prerequisites" id="prerequisites" style="background:#F8F8F8; border:1px solid #999999; font-family:Arial, Verdana, Helvetica, sans-serif; font-size:12px; width:300px;"><option value="0">'.get_lang("NoPrerequisites").'</option>';
  3965. foreach($arrHide as $key => $value){
  3966. if($key==$s_selected_position && $action == 'add'){
  3967. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  3968. }
  3969. elseif($key==$id_prerequisite && $action == 'edit'){
  3970. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  3971. }
  3972. else{
  3973. $return .= '<option value="'.$key.'">'.$value['value'].'</option>';
  3974. }
  3975. }
  3976. $return .= "</select></td>";
  3977. $return .= "\t\t" . '</tr>' . "\n";
  3978. $return .= "\t\t" . '<tr>' . "\n";
  3979. //Remove temporaly the test description
  3980. //$return .= "\t\t\t" . '<td class="label"><label for="idDescription">'.get_lang("Description").' :</label></td>' . "\n";
  3981. //$return .= "\t\t\t" . '<td class="input"><textarea id="idDescription" name="description" rows="4">' . $item_description . '</textarea></td>' . "\n";
  3982. $return .= "\t\t" . '</tr>' . "\n";
  3983. }
  3984. $return .= "\t\t" . '<tr>' . "\n";
  3985. $return .= "\t\t\t" . '<td colspan="2"><input class="button" name="submit_button" type="submit" value="OK" /></td>' . "\n";
  3986. $return .= "\t\t" . '</tr>' . "\n";
  3987. $return .= "\t" . '</table>' . "\n";
  3988. if($action == 'move')
  3989. {
  3990. $return .= "\t" . '<input name="title" type="hidden" value="' . $item_title . '" />' . "\n";
  3991. $return .= "\t" . '<input name="description" type="hidden" value="' . $item_description . '" />' . "\n";
  3992. }
  3993. if(is_numeric($extra_info))
  3994. {
  3995. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info . '" />' . "\n";
  3996. }
  3997. elseif(is_array($extra_info))
  3998. {
  3999. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />' . "\n";
  4000. }
  4001. $return .= "\t" . '<input name="type" type="hidden" value="'.TOOL_QUIZ.'" />' . "\n";
  4002. $return .= "\t" . '<input name="post_time" type="hidden" value="' . time() . '" />' . "\n";
  4003. $return .= '</form>' . "\n";
  4004. $return .= '</div>' . "\n";
  4005. return $return;
  4006. }
  4007. /**
  4008. * Addition of Hotpotatoes tests
  4009. * @param string Action
  4010. * @param integer Internal ID of the item
  4011. * @param mixed Extra information - can be an array with title and description indexes
  4012. * @return string HTML structure to display the hotpotatoes addition formular
  4013. */
  4014. function display_hotpotatoes_form($action = 'add', $id = 0, $extra_info = '')
  4015. {
  4016. $uploadPath = DIR_HOTPOTATOES; //defined in main_api
  4017. $tbl_lp_item = Database::get_course_table('lp_item');
  4018. if($id != 0 && is_array($extra_info))
  4019. {
  4020. $item_title = stripslashes($extra_info['title']);
  4021. $item_description = stripslashes($extra_info['description']);
  4022. }
  4023. elseif(is_numeric($extra_info))
  4024. {
  4025. $TBL_DOCUMENT = Database::get_course_table(TABLE_DOCUMENT);
  4026. $sql_hot = "SELECT * FROM ".$TBL_DOCUMENT."
  4027. WHERE path LIKE '".$uploadPath."/%/%htm%'
  4028. ORDER BY id ASC";
  4029. $res_hot = api_sql_query($sql_hot, __FILE__, __LINE__);
  4030. $row = Database::fetch_array($res_hot);
  4031. $item_title = $row['title'];
  4032. $item_description = $row['description'];
  4033. }
  4034. else
  4035. {
  4036. $item_title = '';
  4037. $item_description = '';
  4038. }
  4039. $return = '<div style="margin:3px 10px;">';
  4040. if($id != 0 && is_array($extra_info))
  4041. $parent = $extra_info['parent_item_id'];
  4042. else
  4043. $parent = 0;
  4044. $sql = "
  4045. SELECT *
  4046. FROM " . $tbl_lp_item . "
  4047. WHERE
  4048. lp_id = " . $this->lp_id;
  4049. $result = api_sql_query($sql, __FILE__, __LINE__);
  4050. $arrLP = array();
  4051. while($row = Database::fetch_array($result))
  4052. {
  4053. $arrLP[] = array(
  4054. 'id' => $row['id'],
  4055. 'item_type' => $row['item_type'],
  4056. 'title' => $row['title'],
  4057. 'path' => $row['path'],
  4058. 'description' => $row['description'],
  4059. 'parent_item_id' => $row['parent_item_id'],
  4060. 'previous_item_id' => $row['previous_item_id'],
  4061. 'next_item_id' => $row['next_item_id'],
  4062. 'display_order' => $row['display_order'],
  4063. 'prerequisite' => $row['prerequisite']);
  4064. }
  4065. $this->tree_array($arrLP);
  4066. $arrLP = $this->arrMenu;
  4067. unset($this->arrMenu);
  4068. if($action == 'add')
  4069. $return .= '<p class="lp_title">'.get_lang("CreateTheExercise").' :</p>' . "\n";
  4070. elseif($action == 'move')
  4071. $return .= '<p class="lp_title">'.get_lang("MoveTheCurrentExercise").' :</p>' . "\n";
  4072. else
  4073. $return .= '<p class="lp_title">'.get_lang("EditCurrentExecice").' :</p>' . "\n";
  4074. if(isset($_GET['edit']) && $_GET['edit'] == 'true')
  4075. {
  4076. $return .= '<div class="lp_message" style="margin-bottom:15px;">';
  4077. $return .= '<p class="lp_title">'.get_lang("Warning").' !</p>';
  4078. $return .= get_lang("WarningEditingDocument");
  4079. $return .= '</div>';
  4080. }
  4081. $return .= '<form method="POST">' . "\n";
  4082. $return .= "\t" . '<table cellpadding="0" cellspacing="0" class="lp_form">' . "\n";
  4083. $return .= "\t\t" . '<tr>' . "\n";
  4084. $return .= "\t\t\t" . '<td class="label"><label for="idParent">'.get_lang("Parent").' :</label></td>' . "\n";
  4085. $return .= "\t\t\t" . '<td class="input">' . "\n";
  4086. $return .= "\t\t\t\t" . '<select id="idParent" name="parent" onchange="load_cbo(this.value);" size="1">';
  4087. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
  4088. $arrHide = array($id);
  4089. for($i = 0; $i < count($arrLP); $i++)
  4090. {
  4091. if($action != 'add')
  4092. {
  4093. 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))
  4094. {
  4095. $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'] . '">' . html_entity_decode(stripslashes($arrLP[$i]['title'])) . '</option>';
  4096. }
  4097. else
  4098. {
  4099. $arrHide[] = $arrLP[$i]['id'];
  4100. }
  4101. }
  4102. else
  4103. {
  4104. if($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
  4105. $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'] . '">' . html_entity_decode(stripslashes($arrLP[$i]['title'])) . '</option>';
  4106. }
  4107. }
  4108. reset($arrLP);
  4109. $return .= "\t\t\t\t" . '</select>';
  4110. $return .= "\t\t\t" . '</td>' . "\n";
  4111. $return .= "\t\t" . '</tr>' . "\n";
  4112. $return .= "\t\t" . '<tr>' . "\n";
  4113. $return .= "\t\t\t" . '<td class="label"><label for="idPosition">'.get_lang("Position").' :</label></td>' . "\n";
  4114. $return .= "\t\t\t" . '<td class="input">' . "\n";
  4115. $return .= "\t\t\t\t" . '<select id="idPosition" name="previous" size="1">';
  4116. $return .= "\t\t\t\t\t" . '<option class="top" value="0">First position</option>';
  4117. for($i = 0; $i < count($arrLP); $i++)
  4118. {
  4119. if($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id)
  4120. {
  4121. if($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  4122. $selected = 'selected="selected" ';
  4123. elseif($action == 'add')
  4124. $selected = 'selected="selected" ';
  4125. else
  4126. $selected = '';
  4127. $return .= "\t\t\t\t\t" . '<option ' . $selected . 'value="' . $arrLP[$i]['id'] . '">'.get_lang("After").' "' . html_entity_decode(stripslashes($arrLP[$i]['title'])) . '"</option>';
  4128. }
  4129. }
  4130. $return .= "\t\t\t\t" . '</select>';
  4131. $return .= "\t\t\t" . '</td>' . "\n";
  4132. $return .= "\t\t" . '</tr>' . "\n";
  4133. if($action != 'move')
  4134. {
  4135. $return .= "\t\t" . '<tr>' . "\n";
  4136. $return .= "\t\t\t" . '<td class="label"><label for="idTitle">'.get_lang("Title").' :</label></td>' . "\n";
  4137. $return .= "\t\t\t" . '<td class="input"><input id="idTitle" name="title" type="text" value="' . $item_title . '" /></td>' . "\n";
  4138. $return .= "\t\t" . '</tr>' . "\n";
  4139. $id_prerequisite=0;
  4140. foreach($arrLP as $key=>$value){
  4141. if($value['id']==$id){
  4142. $id_prerequisite=$value['prerequisite'];
  4143. break;
  4144. }
  4145. }
  4146. $arrHide=array();
  4147. for($i = 0; $i < count($arrLP); $i++)
  4148. {
  4149. if($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter')
  4150. {
  4151. if($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  4152. $s_selected_position=$arrLP[$i]['id'];
  4153. elseif($action == 'add')
  4154. $s_selected_position=0;
  4155. $arrHide[$arrLP[$i]['id']]['value']=html_entity_decode(stripslashes($arrLP[$i]['title']));
  4156. }
  4157. }
  4158. $return .= "\t\t" . '<tr>' . "\n";
  4159. $return .= "\t\t\t" . '<td class="label"><label for="idPrerequisites">'.get_lang("Prerequisites").' :</label></td>' . "\n";
  4160. $return .= "\t\t\t" . '<td class="input"><select name="prerequisites" id="prerequisites" style="background:#F8F8F8; border:1px solid #999999; font-family:Arial, Verdana, Helvetica, sans-serif; font-size:12px; width:300px;"><option value="0">'.get_lang("NoPrerequisites").'</option>';
  4161. foreach($arrHide as $key => $value){
  4162. if($key==$s_selected_position && $action == 'add'){
  4163. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  4164. }
  4165. elseif($key==$id_prerequisite && $action == 'edit'){
  4166. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  4167. }
  4168. else{
  4169. $return .= '<option value="'.$key.'">'.$value['value'].'</option>';
  4170. }
  4171. }
  4172. $return .= "</select></td>";
  4173. $return .= "\t\t" . '</tr>' . "\n";
  4174. $return .= "\t\t" . '<tr>' . "\n";
  4175. //Remove temporaly the test description
  4176. //$return .= "\t\t\t" . '<td class="label"><label for="idDescription">'.get_lang("Description").' :</label></td>' . "\n";
  4177. //$return .= "\t\t\t" . '<td class="input"><textarea id="idDescription" name="description" rows="4">' . $item_description . '</textarea></td>' . "\n";
  4178. $return .= "\t\t" . '</tr>' . "\n";
  4179. }
  4180. $return .= "\t\t" . '<tr>' . "\n";
  4181. $return .= "\t\t\t" . '<td colspan="2"><input class="button" name="submit_button" type="submit" value="OK" /></td>' . "\n";
  4182. $return .= "\t\t" . '</tr>' . "\n";
  4183. $return .= "\t" . '</table>' . "\n";
  4184. if($action == 'move')
  4185. {
  4186. $return .= "\t" . '<input name="title" type="hidden" value="' . $item_title . '" />' . "\n";
  4187. $return .= "\t" . '<input name="description" type="hidden" value="' . $item_description . '" />' . "\n";
  4188. }
  4189. if(is_numeric($extra_info))
  4190. {
  4191. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info . '" />' . "\n";
  4192. }
  4193. elseif(is_array($extra_info))
  4194. {
  4195. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />' . "\n";
  4196. }
  4197. $return .= "\t" . '<input name="type" type="hidden" value="'.TOOL_HOTPOTATOES.'" />' . "\n";
  4198. $return .= "\t" . '<input name="post_time" type="hidden" value="' . time() . '" />' . "\n";
  4199. $return .= '</form>' . "\n";
  4200. $return .= '</div>' . "\n";
  4201. return $return;
  4202. }
  4203. //fin du hotpot form
  4204. /**
  4205. * Enter description here...
  4206. *
  4207. * @param unknown_type $action
  4208. * @param unknown_type $id
  4209. * @param unknown_type $extra_info
  4210. * @return unknown
  4211. */
  4212. function display_forum_form($action = 'add', $id = 0, $extra_info = '')
  4213. {
  4214. $tbl_lp_item = Database::get_course_table('lp_item');
  4215. $tbl_forum = Database::get_course_table(TABLE_FORUM);
  4216. if($id != 0 && is_array($extra_info))
  4217. {
  4218. $item_title = stripslashes($extra_info['title']);
  4219. }
  4220. elseif(is_numeric($extra_info))
  4221. {
  4222. $sql_forum = "
  4223. SELECT
  4224. forum_title as title, forum_comment as comment
  4225. FROM " . $tbl_forum . "
  4226. WHERE forum_id = " . $extra_info;
  4227. $result = api_sql_query($sql_forum, __FILE__, __LINE__);
  4228. $row = Database::fetch_array($result);
  4229. $item_title = $row['title'];
  4230. $item_description = $row['comment'];
  4231. }
  4232. else
  4233. {
  4234. $item_title = '';
  4235. $item_description = '';
  4236. }
  4237. $return = '<div style="margin:3px 10px;">';
  4238. if($id != 0 && is_array($extra_info))
  4239. $parent = $extra_info['parent_item_id'];
  4240. else
  4241. $parent = 0;
  4242. $sql = "
  4243. SELECT *
  4244. FROM " . $tbl_lp_item . "
  4245. WHERE
  4246. lp_id = " . $this->lp_id;
  4247. $result = api_sql_query($sql, __FILE__, __LINE__);
  4248. $arrLP = array();
  4249. while($row = Database::fetch_array($result))
  4250. {
  4251. $arrLP[] = array(
  4252. 'id' => $row['id'],
  4253. 'item_type' => $row['item_type'],
  4254. 'title' => $row['title'],
  4255. 'path' => $row['path'],
  4256. 'description' => $row['description'],
  4257. 'parent_item_id' => $row['parent_item_id'],
  4258. 'previous_item_id' => $row['previous_item_id'],
  4259. 'next_item_id' => $row['next_item_id'],
  4260. 'display_order' => $row['display_order'],
  4261. 'prerequisite' => $row['prerequisite']);
  4262. }
  4263. $this->tree_array($arrLP);
  4264. $arrLP = $this->arrMenu;
  4265. unset($this->arrMenu);
  4266. if($action == 'add')
  4267. $return .= '<p class="lp_title">'.get_lang("CreateTheForum").' :</p>' . "\n";
  4268. elseif($action == 'move')
  4269. $return .= '<p class="lp_title">'.get_lang("MoveTheCurrentForum").' :</p>' . "\n";
  4270. else
  4271. $return .= '<p class="lp_title">'.get_lang("EditCurrentForum").' :</p>' . "\n";
  4272. $return .= '<form method="POST">' . "\n";
  4273. $return .= "\t" . '<table cellpadding="0" cellspacing="0" class="lp_form">' . "\n";
  4274. $return .= "\t\t" . '<tr>' . "\n";
  4275. $return .= "\t\t\t" . '<td class="label"><label for="idParent">'.get_lang("Parent").' :</label></td>' . "\n";
  4276. $return .= "\t\t\t" . '<td class="input">' . "\n";
  4277. $return .= "\t\t\t\t" . '<select id="idParent" name="parent" onchange="load_cbo(this.value);" size="1">';
  4278. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
  4279. $arrHide = array($id);
  4280. for($i = 0; $i < count($arrLP); $i++)
  4281. {
  4282. if($action != 'add')
  4283. {
  4284. 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))
  4285. {
  4286. $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'] . '">' . html_entity_decode(stripslashes($arrLP[$i]['title'])) . '</option>';
  4287. }
  4288. else
  4289. {
  4290. $arrHide[] = $arrLP[$i]['id'];
  4291. }
  4292. }
  4293. else
  4294. {
  4295. if($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
  4296. $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'] . '">' . html_entity_decode(stripslashes($arrLP[$i]['title'])) . '</option>';
  4297. }
  4298. }
  4299. reset($arrLP);
  4300. $return .= "\t\t\t\t" . '</select>';
  4301. $return .= "\t\t\t" . '</td>' . "\n";
  4302. $return .= "\t\t" . '</tr>' . "\n";
  4303. $return .= "\t\t" . '<tr>' . "\n";
  4304. $return .= "\t\t\t" . '<td class="label"><label for="idPosition">'.get_lang("Position").' :</label></td>' . "\n";
  4305. $return .= "\t\t\t" . '<td class="input">' . "\n";
  4306. $return .= "\t\t\t\t" . '<select id="idPosition" name="previous" size="1">';
  4307. $return .= "\t\t\t\t\t" . '<option class="top" value="0">First position</option>';
  4308. for($i = 0; $i < count($arrLP); $i++)
  4309. {
  4310. if($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id)
  4311. {
  4312. if($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  4313. $selected = 'selected="selected" ';
  4314. elseif($action == 'add')
  4315. $selected = 'selected="selected" ';
  4316. else
  4317. $selected = '';
  4318. $return .= "\t\t\t\t\t" . '<option ' . $selected . 'value="' . $arrLP[$i]['id'] . '">'.get_lang("After").' "' . html_entity_decode(stripslashes($arrLP[$i]['title'])) . '"</option>';
  4319. }
  4320. }
  4321. $return .= "\t\t\t\t" . '</select>';
  4322. $return .= "\t\t\t" . '</td>' . "\n";
  4323. $return .= "\t\t" . '</tr>' . "\n";
  4324. if($action != 'move')
  4325. {
  4326. $return .= "\t\t" . '<tr>' . "\n";
  4327. $return .= "\t\t\t" . '<td class="label"><label for="idTitle">'.get_lang("Title").' :</label></td>' . "\n";
  4328. $return .= "\t\t\t" . '<td class="input"><input id="idTitle" name="title" type="text" value="' . $item_title . '" /></td>' . "\n";
  4329. $return .= "\t\t" . '</tr>' . "\n";
  4330. $return .= "\t\t" . '<tr>' . "\n";
  4331. //Remove temporaly the test description
  4332. //$return .= "\t\t\t" . '<td class="label"><label for="idDescription">'.get_lang("Description").' :</label></td>' . "\n";
  4333. //$return .= "\t\t\t" . '<td class="input"><textarea id="idDescription" name="description" rows="4">' . $item_description . '</textarea></td>' . "\n";
  4334. $return .= "\t\t" . '</tr>' . "\n";
  4335. $id_prerequisite=0;
  4336. foreach($arrLP as $key=>$value){
  4337. if($value['id']==$id){
  4338. $id_prerequisite=$value['prerequisite'];
  4339. break;
  4340. }
  4341. }
  4342. $arrHide=array();
  4343. for($i = 0; $i < count($arrLP); $i++)
  4344. {
  4345. if($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter')
  4346. {
  4347. if($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  4348. $s_selected_position=$arrLP[$i]['id'];
  4349. elseif($action == 'add')
  4350. $s_selected_position=0;
  4351. $arrHide[$arrLP[$i]['id']]['value']=html_entity_decode(stripslashes($arrLP[$i]['title']));
  4352. }
  4353. }
  4354. $return .= "\t\t" . '<tr>' . "\n";
  4355. $return .= "\t\t\t" . '<td class="label"><label for="idPrerequisites">'.get_lang("Prerequisites").' :</label></td>' . "\n";
  4356. $return .= "\t\t\t" . '<td class="input"><select name="prerequisites" id="prerequisites" style="background:#F8F8F8; border:1px solid #999999; font-family:Arial, Verdana, Helvetica, sans-serif; font-size:12px; width:300px;"><option value="0">'.get_lang("NoPrerequisites").'</option>';
  4357. foreach($arrHide as $key => $value){
  4358. if($key==$s_selected_position && $action == 'add'){
  4359. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  4360. }
  4361. elseif($key==$id_prerequisite && $action == 'edit'){
  4362. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  4363. }
  4364. else{
  4365. $return .= '<option value="'.$key.'">'.$value['value'].'</option>';
  4366. }
  4367. }
  4368. $return .= "</select></td>";
  4369. $return .= "\t\t" . '</tr>' . "\n";
  4370. }
  4371. $return .= "\t\t" . '<tr>' . "\n";
  4372. $return .= "\t\t\t" . '<td colspan="2"><input class="button" name="submit_button" type="submit" value="OK" /></td>' . "\n";
  4373. $return .= "\t\t" . '</tr>' . "\n";
  4374. $return .= "\t" . '</table>' . "\n";
  4375. if($action == 'move')
  4376. {
  4377. $return .= "\t" . '<input name="title" type="hidden" value="' . $item_title . '" />' . "\n";
  4378. $return .= "\t" . '<input name="description" type="hidden" value="' . $item_description . '" />' . "\n";
  4379. }
  4380. if(is_numeric($extra_info))
  4381. {
  4382. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info . '" />' . "\n";
  4383. }
  4384. elseif(is_array($extra_info))
  4385. {
  4386. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />' . "\n";
  4387. }
  4388. $return .= "\t" . '<input name="type" type="hidden" value="'.TOOL_FORUM.'" />' . "\n";
  4389. $return .= "\t" . '<input name="post_time" type="hidden" value="' . time() . '" />' . "\n";
  4390. $return .= '</form>' . "\n";
  4391. $return .= '</div>' . "\n";
  4392. return $return;
  4393. }
  4394. function display_thread_form($action = 'add', $id = 0, $extra_info = '')
  4395. {
  4396. $tbl_lp_item = Database::get_course_table('lp_item');
  4397. $tbl_forum = Database::get_course_table(TABLE_FORUM_THREAD);
  4398. if($id != 0 && is_array($extra_info))
  4399. {
  4400. $item_title = stripslashes($extra_info['title']);
  4401. }
  4402. elseif(is_numeric($extra_info))
  4403. {
  4404. $sql_forum = "
  4405. SELECT
  4406. thread_title as title
  4407. FROM " . $tbl_forum . "
  4408. WHERE thread_id = " . $extra_info;
  4409. $result = api_sql_query($sql_forum, __FILE__, __LINE__);
  4410. $row = Database::fetch_array($result);
  4411. $item_title = $row['title'];
  4412. $item_description = '';
  4413. }
  4414. else
  4415. {
  4416. $item_title = '';
  4417. $item_description = '';
  4418. }
  4419. $return = '<div style="margin:3px 10px;">';
  4420. if($id != 0 && is_array($extra_info))
  4421. $parent = $extra_info['parent_item_id'];
  4422. else
  4423. $parent = 0;
  4424. $sql = "
  4425. SELECT *
  4426. FROM " . $tbl_lp_item . "
  4427. WHERE
  4428. lp_id = " . $this->lp_id;
  4429. $result = api_sql_query($sql, __FILE__, __LINE__);
  4430. $arrLP = array();
  4431. while($row = Database::fetch_array($result))
  4432. {
  4433. $arrLP[] = array(
  4434. 'id' => $row['id'],
  4435. 'item_type' => $row['item_type'],
  4436. 'title' => $row['title'],
  4437. 'path' => $row['path'],
  4438. 'description' => $row['description'],
  4439. 'parent_item_id' => $row['parent_item_id'],
  4440. 'previous_item_id' => $row['previous_item_id'],
  4441. 'next_item_id' => $row['next_item_id'],
  4442. 'display_order' => $row['display_order'],
  4443. 'prerequisite' => $row['prerequisite']);
  4444. }
  4445. $this->tree_array($arrLP);
  4446. $arrLP = $this->arrMenu;
  4447. unset($this->arrMenu);
  4448. if($action == 'add')
  4449. $return .= '<p class="lp_title">'.get_lang("CreateTheForum").' :</p>' . "\n";
  4450. elseif($action == 'move')
  4451. $return .= '<p class="lp_title">'.get_lang("MoveTheCurrentForum").' :</p>' . "\n";
  4452. else
  4453. $return .= '<p class="lp_title">'.get_lang("EditCurrentForum").' :</p>' . "\n";
  4454. $return .= '<form method="POST">' . "\n";
  4455. $return .= "\t" . '<table cellpadding="0" cellspacing="0" class="lp_form">' . "\n";
  4456. $return .= "\t\t" . '<tr>' . "\n";
  4457. $return .= "\t\t\t" . '<td class="label"><label for="idParent">'.get_lang("Parent").' :</label></td>' . "\n";
  4458. $return .= "\t\t\t" . '<td class="input">' . "\n";
  4459. $return .= "\t\t\t\t" . '<select id="idParent" name="parent" onchange="load_cbo(this.value);" size="1">';
  4460. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
  4461. $arrHide = array($id);
  4462. for($i = 0; $i < count($arrLP); $i++)
  4463. {
  4464. if($action != 'add')
  4465. {
  4466. 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))
  4467. {
  4468. $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'] . '">' . html_entity_decode(stripslashes($arrLP[$i]['title'])) . '</option>';
  4469. }
  4470. else
  4471. {
  4472. $arrHide[] = $arrLP[$i]['id'];
  4473. }
  4474. }
  4475. else
  4476. {
  4477. if($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
  4478. $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'] . '">' . html_entity_decode(stripslashes($arrLP[$i]['title'])) . '</option>';
  4479. }
  4480. }
  4481. reset($arrLP);
  4482. $return .= "\t\t\t\t" . '</select>';
  4483. $return .= "\t\t\t" . '</td>' . "\n";
  4484. $return .= "\t\t" . '</tr>' . "\n";
  4485. $return .= "\t\t" . '<tr>' . "\n";
  4486. $return .= "\t\t\t" . '<td class="label"><label for="idPosition">'.get_lang("Position").' :</label></td>' . "\n";
  4487. $return .= "\t\t\t" . '<td class="input">' . "\n";
  4488. $return .= "\t\t\t\t" . '<select id="idPosition" name="previous" size="1">';
  4489. $return .= "\t\t\t\t\t" . '<option class="top" value="0">First position</option>';
  4490. for($i = 0; $i < count($arrLP); $i++)
  4491. {
  4492. if($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id)
  4493. {
  4494. if($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  4495. $selected = 'selected="selected" ';
  4496. elseif($action == 'add')
  4497. $selected = 'selected="selected" ';
  4498. else
  4499. $selected = '';
  4500. $return .= "\t\t\t\t\t" . '<option ' . $selected . 'value="' . $arrLP[$i]['id'] . '">'.get_lang("After").' "' . html_entity_decode(stripslashes($arrLP[$i]['title'])) . '"</option>';
  4501. }
  4502. }
  4503. $return .= "\t\t\t\t" . '</select>';
  4504. $return .= "\t\t\t" . '</td>' . "\n";
  4505. $return .= "\t\t" . '</tr>' . "\n";
  4506. if($action != 'move')
  4507. {
  4508. $return .= "\t\t" . '<tr>' . "\n";
  4509. $return .= "\t\t\t" . '<td class="label"><label for="idTitle">'.get_lang("Title").' :</label></td>' . "\n";
  4510. $return .= "\t\t\t" . '<td class="input"><input id="idTitle" name="title" type="text" value="' . $item_title . '" /></td>' . "\n";
  4511. $return .= "\t\t" . '</tr>' . "\n";
  4512. $return .= "\t\t" . '<tr>' . "\n";
  4513. //Remove temporaly the test description
  4514. //$return .= "\t\t\t" . '<td class="label"><label for="idDescription">'.get_lang("Description").' :</label></td>' . "\n";
  4515. //$return .= "\t\t\t" . '<td class="input"><textarea id="idDescription" name="description" rows="4">' . $item_description . '</textarea></td>' . "\n";
  4516. $return .= "\t\t" . '</tr>' . "\n";
  4517. $id_prerequisite=0;
  4518. foreach($arrLP as $key=>$value){
  4519. if($value['id']==$id){
  4520. $id_prerequisite=$value['prerequisite'];
  4521. break;
  4522. }
  4523. }
  4524. $arrHide=array();
  4525. for($i = 0; $i < count($arrLP); $i++)
  4526. {
  4527. if($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter')
  4528. {
  4529. if($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  4530. $s_selected_position=$arrLP[$i]['id'];
  4531. elseif($action == 'add')
  4532. $s_selected_position=0;
  4533. $arrHide[$arrLP[$i]['id']]['value']=html_entity_decode(stripslashes($arrLP[$i]['title']));
  4534. }
  4535. }
  4536. $return .= "\t\t" . '<tr>' . "\n";
  4537. $return .= "\t\t\t" . '<td class="label"><label for="idPrerequisites">'.get_lang("Prerequisites").' :</label></td>' . "\n";
  4538. $return .= "\t\t\t" . '<td class="input"><select name="prerequisites" id="prerequisites" style="background:#F8F8F8; border:1px solid #999999; font-family:Arial, Verdana, Helvetica, sans-serif; font-size:12px; width:300px;"><option value="0">'.get_lang("NoPrerequisites").'</option>';
  4539. foreach($arrHide as $key => $value){
  4540. if($key==$s_selected_position && $action == 'add'){
  4541. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  4542. }
  4543. elseif($key==$id_prerequisite && $action == 'edit'){
  4544. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  4545. }
  4546. else{
  4547. $return .= '<option value="'.$key.'">'.$value['value'].'</option>';
  4548. }
  4549. }
  4550. $return .= "</select></td>";
  4551. $return .= "\t\t" . '</tr>' . "\n";
  4552. }
  4553. $return .= "\t\t" . '<tr>' . "\n";
  4554. $return .= "\t\t\t" . '<td colspan="2"><input class="button" name="submit_button" type="submit" value="OK" /></td>' . "\n";
  4555. $return .= "\t\t" . '</tr>' . "\n";
  4556. $return .= "\t" . '</table>' . "\n";
  4557. if($action == 'move')
  4558. {
  4559. $return .= "\t" . '<input name="title" type="hidden" value="' . $item_title . '" />' . "\n";
  4560. $return .= "\t" . '<input name="description" type="hidden" value="' . $item_description . '" />' . "\n";
  4561. }
  4562. if(is_numeric($extra_info))
  4563. {
  4564. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info . '" />' . "\n";
  4565. }
  4566. elseif(is_array($extra_info))
  4567. {
  4568. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />' . "\n";
  4569. }
  4570. $return .= "\t" . '<input name="type" type="hidden" value="'.TOOL_THREAD.'" />' . "\n";
  4571. $return .= "\t" . '<input name="post_time" type="hidden" value="' . time() . '" />' . "\n";
  4572. $return .= '</form>' . "\n";
  4573. $return .= '</div>' . "\n";
  4574. return $return;
  4575. }
  4576. /**
  4577. * Enter description here...
  4578. *
  4579. * @param unknown_type $item_type
  4580. * @param unknown_type $title
  4581. * @param unknown_type $action
  4582. * @param unknown_type $id
  4583. * @param unknown_type $extra_info
  4584. * @return unknown
  4585. */
  4586. function display_item_form($item_type, $title = '', $action = 'add', $id = 0, $extra_info = 'new')
  4587. {
  4588. global $_course;
  4589. $tbl_lp_item = Database::get_course_table('lp_item');
  4590. if($id != 0 && is_array($extra_info))
  4591. {
  4592. $item_title = stripslashes($extra_info['title']);
  4593. $item_description = stripslashes($extra_info['description']);
  4594. $item_path = api_get_path(WEB_COURSE_PATH) . $_course['path'].'/scorm/'.$this->path.'/'.stripslashes($extra_info['path']);
  4595. }
  4596. else
  4597. {
  4598. $item_title = '';
  4599. $item_description = '';
  4600. }
  4601. $return = '<div style="margin:3px 10px;">';
  4602. if($id != 0 && is_array($extra_info))
  4603. $parent = $extra_info['parent_item_id'];
  4604. else
  4605. $parent = 0;
  4606. $sql = "
  4607. SELECT *
  4608. FROM " . $tbl_lp_item . "
  4609. WHERE
  4610. lp_id = " . $this->lp_id;
  4611. if($item_type == 'module')
  4612. $sql .= " AND parent_item_id = 0";
  4613. $result = api_sql_query($sql, __FILE__, __LINE__);
  4614. $arrLP = array();
  4615. while($row = Database::fetch_array($result))
  4616. {
  4617. $arrLP[] = array(
  4618. 'id' => $row['id'],
  4619. 'item_type' => $row['item_type'],
  4620. 'title' => $row['title'],
  4621. 'path' => $row['path'],
  4622. 'description' => $row['description'],
  4623. 'parent_item_id' => $row['parent_item_id'],
  4624. 'previous_item_id' => $row['previous_item_id'],
  4625. 'next_item_id' => $row['next_item_id'],
  4626. 'display_order' => $row['display_order']);
  4627. }
  4628. $this->tree_array($arrLP);
  4629. $arrLP = $this->arrMenu;
  4630. unset($this->arrMenu);
  4631. $return .= '<p class="lp_title">' . $title . '</p>' . "\n";
  4632. require_once (api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php');
  4633. $form = new FormValidator('form','POST',api_get_self()."?".$_SERVER["QUERY_STRING"]);
  4634. $defaults["title"]=html_entity_decode($item_title);
  4635. $defaults["description"]=html_entity_decode($item_description);
  4636. $form->addElement('html',$return);
  4637. //$arrHide = array($id);
  4638. $arrHide[0]['value']=$this->name;
  4639. $arrHide[0]['padding']=3;
  4640. if($item_type != 'module' && $item_type != 'dokeos_module')
  4641. {
  4642. for($i = 0; $i < count($arrLP); $i++)
  4643. {
  4644. if($action != 'add'){
  4645. 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)){
  4646. $arrHide[$arrLP[$i]['id']]['value']=html_entity_decode(stripslashes($arrLP[$i]['title']));
  4647. $arrHide[$arrLP[$i]['id']]['padding']=3+ $arrLP[$i]['depth'] * 10;
  4648. if($parent == $arrLP[$i]['id']){
  4649. $s_selected_parent=$arrHide[$arrLP[$i]['id']];
  4650. }
  4651. }
  4652. }
  4653. else{
  4654. if($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir'){
  4655. $arrHide[$arrLP[$i]['id']]['value']=html_entity_decode(stripslashes($arrLP[$i]['title']));
  4656. $arrHide[$arrLP[$i]['id']]['padding']=3+ $arrLP[$i]['depth'] * 10;
  4657. if($parent == $arrLP[$i]['id']){
  4658. $s_selected_parent=$arrHide[$arrLP[$i]['id']];
  4659. }
  4660. }
  4661. }
  4662. }
  4663. $parent_select = &$form->addElement('select', 'parent', get_lang("Parent")." :", '', 'style="background:#F8F8F8; border:1px solid #999999; font-family:Arial, Verdana, Helvetica, sans-serif; font-size:12px; width:300px;" onchange="load_cbo(this.value);"');
  4664. foreach($arrHide as $key => $value){
  4665. $parent_select->addOption($value['value'],$key,'style="padding-left:'.$value['padding'].'px;"');
  4666. }
  4667. $parent_select -> setSelected($s_selected_parent);
  4668. }
  4669. if(is_array($arrLP)) { reset($arrLP); }
  4670. $arrHide=array();
  4671. //POSITION
  4672. for($i = 0; $i < count($arrLP); $i++)
  4673. {
  4674. if($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id)
  4675. {
  4676. if($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  4677. $s_selected_position=$arrLP[$i]['id'];
  4678. elseif($action == 'add')
  4679. $s_selected_position=$arrLP[$i]['id'];
  4680. $arrHide[$arrLP[$i]['id']]['value']=get_lang("After").' "' . html_entity_decode(stripslashes($arrLP[$i]['title']));
  4681. }
  4682. }
  4683. $position = &$form->addElement('select', 'previous', get_lang("Position")." :", '', 'id="idPosition" style="background:#F8F8F8; border:1px solid #999999; font-family:Arial, Verdana, Helvetica, sans-serif; font-size:12px; width:300px;"');
  4684. $position->addOption(get_lang('FirstPosition'),0,'style="padding-left:'.$value['padding'].'px;"');
  4685. foreach($arrHide as $key => $value){
  4686. $position->addOption($value['value'],$key,'style="padding-left:'.$value['padding'].'px;"');
  4687. }
  4688. if(!empty($s_selected_position)) { $position->setSelected($s_selected_position); }
  4689. if(is_array($arrLP)) { reset($arrLP); }
  4690. if($action != 'move'){
  4691. $form->addElement('text','title', get_lang('Title').' :','id="idTitle" style="background:#F8F8F8; border:1px solid #999999; font-family:Arial, Verdana, Helvetica, sans-serif; font-size:12px; padding:1px 2px; width:300px;"');
  4692. //$form->addElement('textarea','description',get_lang("Description").' :', 'id="idDescription" style="background:#F8F8F8; border:1px solid #999999; font-family:Arial, Verdana, Helvetica, sans-serif; font-size:12px; padding:1px 2px; width:300px;"');
  4693. }
  4694. else
  4695. {
  4696. $form->addElement('hidden','title');
  4697. }
  4698. $form->addElement('submit', 'submit_button', get_lang('Ok'), 'style="background:#F8F8F8; border:1px solid #999999; font-family:Arial, Verdana, Helvetica, sans-serif; font-size:12px; padding:1px 2px; width:75px;"');
  4699. if($item_type == 'module' || $item_type == 'dokeos_module')
  4700. {
  4701. $form->addElement('hidden', 'parent', '0');
  4702. }
  4703. $extension = pathinfo($item_path, PATHINFO_EXTENSION);
  4704. if(($item_type=='asset' || $item_type=='sco') && ($extension == 'html' || $extension == 'htm'))
  4705. {
  4706. if($item_type=='sco')
  4707. {
  4708. $form->addElement('html','<script type="text/javascript">alert("'.get_lang('WarningWhenEditingScorm').'")</script>');
  4709. }
  4710. $renderer = $form->defaultRenderer();
  4711. $renderer->setElementTemplate('<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{label}<br />{element}','content_lp');
  4712. $form->addElement('html_editor','content_lp','<a style="cursor:pointer" onclick="launch_templates()"><img src="'.api_get_path(WEB_IMG_PATH).'templates.gif" /></a>');
  4713. $defaults["content_lp"]=file_get_contents($item_path);
  4714. }
  4715. $form->addElement('hidden', 'type', 'dokeos_'.$item_type);
  4716. $form->addElement('hidden', 'post_time', time());
  4717. $form->addElement('html','</div>');
  4718. $form->setDefaults($defaults);
  4719. return $form->return_form();
  4720. }
  4721. /**
  4722. * Enter description here...
  4723. *
  4724. * @param unknown_type $action
  4725. * @param unknown_type $id
  4726. * @param unknown_type $extra_info
  4727. * @return unknown
  4728. */
  4729. function display_document_form($action = 'add', $id = 0, $extra_info = 'new')
  4730. {
  4731. echo '
  4732. <style>
  4733. .row{
  4734. width:100%;
  4735. }
  4736. div.row div.label {
  4737. width: 75px;
  4738. }
  4739. div.row div.formw {
  4740. width: 88%;
  4741. }
  4742. </style>';
  4743. $tbl_lp_item = Database::get_course_table('lp_item');
  4744. $tbl_doc = Database::get_course_table(TABLE_DOCUMENT);
  4745. $path_parts = pathinfo($extra_info['dir']);
  4746. $no_display_edit_textarea=false;
  4747. //If action==edit document
  4748. //We don't display the document form if it's not an editable document (html or txt file)
  4749. if($action=="edit"){
  4750. if(is_array($extra_info)){
  4751. if($path_parts['extension']!="txt" && $path_parts['extension']!="html"){
  4752. $no_display_edit_textarea=true;
  4753. }
  4754. }
  4755. }
  4756. $no_display_add=false;
  4757. //If action==add an existing document
  4758. //We don't display the document form if it's not an editable document (html or txt file)
  4759. if($action=="add"){
  4760. if(is_numeric($extra_info)){
  4761. $sql_doc = "SELECT path FROM " . $tbl_doc . "WHERE id = " . $extra_info;
  4762. $result=api_sql_query($sql_doc);
  4763. $path_file=mysql_result($result,0,0);
  4764. $path_parts = pathinfo($path_file);
  4765. if($path_parts['extension']!="txt" && $path_parts['extension']!="html"){
  4766. $no_display_add=true;
  4767. }
  4768. }
  4769. }
  4770. if($id != 0 && is_array($extra_info))
  4771. {
  4772. $item_title = stripslashes($extra_info['title']);
  4773. $item_description = stripslashes($extra_info['description']);
  4774. if(empty($item_title))
  4775. {
  4776. $path_parts = pathinfo($extra_info['path']);
  4777. $item_title = stripslashes($path_parts['filename']);
  4778. }
  4779. }
  4780. elseif(is_numeric($extra_info))
  4781. {
  4782. $sql_doc = "
  4783. SELECT path, title
  4784. FROM " . $tbl_doc . "
  4785. WHERE id = " . $extra_info;
  4786. $result = api_sql_query($sql_doc, __FILE__, __LINE__);
  4787. $row = Database::fetch_array($result);
  4788. $explode = explode('.', $row['title']);
  4789. if(count($explode)>1){
  4790. for($i = 0; $i < count($explode) - 1; $i++)
  4791. $item_title .= $explode[$i];
  4792. }
  4793. else{
  4794. $item_title=$row['title'];
  4795. }
  4796. $item_title = str_replace('_', ' ', $item_title);
  4797. if(empty($item_title))
  4798. {
  4799. $path_parts = pathinfo($row['path']);
  4800. $item_title = stripslashes($path_parts['filename']);
  4801. }
  4802. }
  4803. else
  4804. {
  4805. $item_title = '';
  4806. $item_description = '';
  4807. }
  4808. $return = '<div style="margin:3px 0px;">';
  4809. if($id != 0 && is_array($extra_info))
  4810. $parent = $extra_info['parent_item_id'];
  4811. else
  4812. $parent = 0;
  4813. $sql = "
  4814. SELECT *
  4815. FROM " . $tbl_lp_item . "
  4816. WHERE
  4817. lp_id = " . $this->lp_id;
  4818. $result = api_sql_query($sql, __FILE__, __LINE__);
  4819. $arrLP = array();
  4820. while($row = Database::fetch_array($result))
  4821. {
  4822. $arrLP[] = array(
  4823. 'id' => $row['id'],
  4824. 'item_type' => $row['item_type'],
  4825. 'title' => $row['title'],
  4826. 'path' => $row['path'],
  4827. 'description' => $row['description'],
  4828. 'parent_item_id' => $row['parent_item_id'],
  4829. 'previous_item_id' => $row['previous_item_id'],
  4830. 'next_item_id' => $row['next_item_id'],
  4831. 'display_order' => $row['display_order'],
  4832. 'prerequisite' => $row['prerequisite']);
  4833. }
  4834. $this->tree_array($arrLP);
  4835. $arrLP = $this->arrMenu;
  4836. unset($this->arrMenu);
  4837. if($action == 'add')
  4838. $return .= '<p class="lp_title">'.get_lang("CreateTheDocument").' :</p>' . "\n";
  4839. elseif($action == 'move')
  4840. $return .= '<p class="lp_title">'.get_lang("MoveTheCurrentDocument").' :</p>' . "\n";
  4841. else
  4842. $return .= '<p class="lp_title">'.get_lang("EditTheCurrentDocument").' :</p>' . "\n";
  4843. if(isset($_GET['edit']) && $_GET['edit'] == 'true')
  4844. {
  4845. $return .= '<div class="lp_message" style="margin-bottom:15px;">';
  4846. $return .= '<p class="lp_title">'.get_lang("Warning").' !</p>';
  4847. $return .= get_lang("WarningEditingDocument");
  4848. $return .= '</div>';
  4849. }
  4850. /*
  4851. if($no_display_add==true){
  4852. $return .= '<div class="lp_message" style="margin-bottom:15px;">';
  4853. $return .= get_lang("CantEditDocument");
  4854. $return .= '</div>';
  4855. return $return;
  4856. }
  4857. */
  4858. require_once (api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php');
  4859. $form = new FormValidator('form','POST',api_get_self()."?".$_SERVER["QUERY_STRING"]);
  4860. $defaults["title"]=html_entity_decode($item_title);
  4861. $defaults["description"]=html_entity_decode($item_description);
  4862. $form->addElement('html',$return);
  4863. //$arrHide = array($id);
  4864. $arrHide[0]['value']=$this->name;
  4865. $arrHide[0]['padding']=3;
  4866. for($i = 0; $i < count($arrLP); $i++)
  4867. {
  4868. if($action != 'add'){
  4869. 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)){
  4870. $arrHide[$arrLP[$i]['id']]['value']=html_entity_decode(stripslashes($arrLP[$i]['title']));
  4871. $arrHide[$arrLP[$i]['id']]['padding']=3+ $arrLP[$i]['depth'] * 10;
  4872. if($parent == $arrLP[$i]['id']){
  4873. $s_selected_parent=$arrHide[$arrLP[$i]['id']];
  4874. }
  4875. }
  4876. }
  4877. else{
  4878. if($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir'){
  4879. $arrHide[$arrLP[$i]['id']]['value']=html_entity_decode(stripslashes($arrLP[$i]['title']));
  4880. $arrHide[$arrLP[$i]['id']]['padding']=3+ $arrLP[$i]['depth'] * 10;
  4881. if($parent == $arrLP[$i]['id']){
  4882. $s_selected_parent=$arrHide[$arrLP[$i]['id']];
  4883. }
  4884. }
  4885. }
  4886. }
  4887. $parent_select = &$form->addElement('select', 'parent', get_lang("Parent")." :", '', 'style="background:#F8F8F8; border:1px solid #999999; font-family:Arial, Verdana, Helvetica, sans-serif; font-size:12px; width:300px;" onchange="load_cbo(this.value);"');
  4888. foreach($arrHide as $key => $value){
  4889. $parent_select->addOption($value['value'],$key,'style="padding-left:'.$value['padding'].'px;"');
  4890. }
  4891. $parent_select -> setSelected($parent);
  4892. if(is_array($arrLP))
  4893. {
  4894. reset($arrLP);
  4895. }
  4896. $arrHide=array();
  4897. //POSITION
  4898. for($i = 0; $i < count($arrLP); $i++)
  4899. {
  4900. if($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id)
  4901. {
  4902. if($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  4903. $s_selected_position=$arrLP[$i]['id'];
  4904. elseif($action == 'add')
  4905. $s_selected_position=$arrLP[$i]['id'];
  4906. $arrHide[$arrLP[$i]['id']]['value']=get_lang("After").' "' . html_entity_decode(stripslashes($arrLP[$i]['title'])).'"';
  4907. }
  4908. }
  4909. $position = &$form->addElement('select', 'previous', get_lang("Position")." :", '', 'id="idPosition" style="background:#F8F8F8; border:1px solid #999999; font-family:Arial, Verdana, Helvetica, sans-serif; font-size:12px; width:300px;"');
  4910. $position->addOption(get_lang("FirstPosition"),0,'style="padding-left:3px;"');
  4911. foreach($arrHide as $key => $value){
  4912. $position->addOption($value['value'],$key,'style="padding-left:'.$value['padding'].'px;"');
  4913. }
  4914. $position -> setSelected($s_selected_position);
  4915. if(is_array($arrLP))
  4916. {
  4917. reset($arrLP);
  4918. }
  4919. if($action != 'move'){
  4920. $form->addElement('text','title', get_lang('Title').' :','id="idTitle" style="background:#F8F8F8; border:1px solid #999999; font-family:Arial, Verdana, Helvetica, sans-serif; font-size:12px; padding:1px 2px; width:300px;"');
  4921. //$form->addElement('textarea','description',get_lang("Description").' :', 'id="idDescription" style="background:#F8F8F8; border:1px solid #999999; font-family:Arial, Verdana, Helvetica, sans-serif; font-size:12px; padding:1px 2px; width:300px;"');
  4922. $id_prerequisite=0;
  4923. if(is_array($arrLP))
  4924. {
  4925. foreach($arrLP as $key=>$value){
  4926. if($value['id']==$id){
  4927. $id_prerequisite=$value['prerequisite'];
  4928. break;
  4929. }
  4930. }
  4931. }
  4932. $select_prerequisites=$form->addElement('select', 'prerequisites', get_lang('Prerequisites'), '', 'id="prerequisites" style="background:#F8F8F8; border:1px solid #999999; font-family:Arial, Verdana, Helvetica, sans-serif; font-size:12px; width:300px;"');
  4933. $select_prerequisites->addOption(get_lang("NoPrerequisites"),0,'style="padding-left:3px;"');
  4934. $arrHide=array();
  4935. for($i = 0; $i < count($arrLP); $i++)
  4936. {
  4937. if($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter')
  4938. {
  4939. if($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  4940. $s_selected_position=$arrLP[$i]['id'];
  4941. elseif($action == 'add')
  4942. $s_selected_position=$arrLP[$i]['id'];
  4943. $arrHide[$arrLP[$i]['id']]['value']=html_entity_decode(stripslashes($arrLP[$i]['title']));
  4944. }
  4945. }
  4946. foreach($arrHide as $key => $value){
  4947. $select_prerequisites->addOption($value['value'],$key,'style="padding-left:'.$value['padding'].'px;"');
  4948. if($key==$s_selected_position && $action == 'add'){
  4949. $select_prerequisites -> setSelected(0);
  4950. }
  4951. elseif($key==$id_prerequisite && $action == 'edit'){
  4952. $select_prerequisites -> setSelected($id_prerequisite);
  4953. }
  4954. }
  4955. if(!$no_display_add)
  4956. {
  4957. if(($extra_info == 'new' || $extra_info['item_type'] == TOOL_DOCUMENT || $_GET['edit'] == 'true'))
  4958. {
  4959. if(isset($_POST['content']))
  4960. $content = stripslashes($_POST['content']);
  4961. elseif(is_array($extra_info)){
  4962. //If it's an html document or a text file
  4963. if(!$no_display_edit_textarea){
  4964. $content = $this->display_document($extra_info['path'], false, false);
  4965. }
  4966. }
  4967. elseif(is_numeric($extra_info))
  4968. $content = $this->display_document($extra_info, false, false);
  4969. else
  4970. $content = '';
  4971. $form->addElement('submit', 'submit_button', get_lang('Ok'), 'style="background:#F8F8F8; border:1px solid #999999; font-family:Arial, Verdana, Helvetica, sans-serif; font-size:12px; padding:1px 2px; width:75px;"');
  4972. if(!$no_display_edit_textarea){
  4973. $renderer = $form->defaultRenderer();
  4974. $renderer->setElementTemplate('<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{label}<br />{element}','content_lp');
  4975. $form->addElement('html_editor','content_lp','<a style="cursor:pointer" onclick="launch_templates()"><img src="'.api_get_path(WEB_IMG_PATH).'templates.gif" /></a>');
  4976. $defaults["content_lp"]=$content;
  4977. }
  4978. }
  4979. elseif(is_numeric($extra_info))
  4980. {
  4981. $form->addElement('submit', 'submit_button', get_lang('Ok'), 'style="background:#F8F8F8; border:1px solid #999999; font-family:Arial, Verdana, Helvetica, sans-serif; font-size:12px; padding:1px 2px; width:75px;"');
  4982. $return = $this->display_document($extra_info, true, true, true);
  4983. $form->addElement('html',$return);
  4984. }
  4985. }
  4986. }
  4987. if($action == 'move')
  4988. {
  4989. $form->addElement('hidden', 'title', $item_title);
  4990. $form->addElement('hidden', 'description', $item_description);
  4991. }
  4992. if(is_numeric($extra_info))
  4993. {
  4994. $form->addElement('submit', 'submit_button', get_lang('Ok'), 'style="background:#F8F8F8; border:1px solid #999999; font-family:Arial, Verdana, Helvetica, sans-serif; font-size:12px; padding:1px 2px; width:75px;"');
  4995. $form->addElement('hidden', 'path', $extra_info);
  4996. }
  4997. elseif(is_array($extra_info))
  4998. {
  4999. $form->addElement('submit', 'submit_button', get_lang('Ok'), 'style="background:#F8F8F8; border:1px solid #999999; font-family:Arial, Verdana, Helvetica, sans-serif; font-size:12px; padding:1px 2px; width:75px;"');
  5000. $form->addElement('hidden', 'path', $extra_info['path']);
  5001. }
  5002. $form->addElement('hidden', 'type', TOOL_DOCUMENT);
  5003. $form->addElement('hidden', 'post_time', time());
  5004. $form->addElement('html','</div>');
  5005. $form->setDefaults($defaults);
  5006. return $form->return_form();
  5007. }
  5008. /**
  5009. * Enter description here...
  5010. *
  5011. * @param unknown_type $action
  5012. * @param unknown_type $id
  5013. * @param unknown_type $extra_info
  5014. */
  5015. function display_link_form($action = 'add', $id = 0, $extra_info = '')
  5016. {
  5017. $tbl_lp_item = Database::get_course_table('lp_item');
  5018. $tbl_link = Database::get_course_table(TABLE_LINK);
  5019. if($id != 0 && is_array($extra_info))
  5020. {
  5021. $item_title = stripslashes($extra_info['title']);
  5022. $item_description = stripslashes($extra_info['description']);
  5023. }
  5024. elseif(is_numeric($extra_info))
  5025. {
  5026. $sql_link = "
  5027. SELECT
  5028. title,
  5029. description,
  5030. url
  5031. FROM " . $tbl_link . "
  5032. WHERE id = " . $extra_info;
  5033. $result = api_sql_query($sql_link, __FILE__, __LINE__);
  5034. $row = Database::fetch_array($result);
  5035. $item_title = $row['title'];
  5036. $item_description = $row['description'];
  5037. $item_url = $row['url'];
  5038. }
  5039. else
  5040. {
  5041. $item_title = '';
  5042. $item_description = '';
  5043. }
  5044. $return = '<div style="margin:3px 10px;">';
  5045. if($id != 0 && is_array($extra_info))
  5046. $parent = $extra_info['parent_item_id'];
  5047. else
  5048. $parent = 0;
  5049. $sql = "
  5050. SELECT *
  5051. FROM " . $tbl_lp_item . "
  5052. WHERE
  5053. lp_id = " . $this->lp_id;
  5054. $result = api_sql_query($sql, __FILE__, __LINE__);
  5055. $arrLP = array();
  5056. while($row = Database::fetch_array($result))
  5057. {
  5058. $arrLP[] = array(
  5059. 'id' => $row['id'],
  5060. 'item_type' => $row['item_type'],
  5061. 'title' => $row['title'],
  5062. 'path' => $row['path'],
  5063. 'description' => $row['description'],
  5064. 'parent_item_id' => $row['parent_item_id'],
  5065. 'previous_item_id' => $row['previous_item_id'],
  5066. 'next_item_id' => $row['next_item_id'],
  5067. 'display_order' => $row['display_order'],
  5068. 'prerequisite' => $row['prerequisite']);
  5069. }
  5070. $this->tree_array($arrLP);
  5071. $arrLP = $this->arrMenu;
  5072. unset($this->arrMenu);
  5073. if($action == 'add')
  5074. $return .= '<p class="lp_title">'.get_lang("CreateTheLink").' :</p>' . "\n";
  5075. elseif($action == 'move')
  5076. $return .= '<p class="lp_title">'.get_lang("MoveCurrentLink").' :</p>' . "\n";
  5077. else
  5078. $return .= '<p class="lp_title">'.get_lang("EditCurrentLink").' :</p>' . "\n";
  5079. $return .= '<form method="POST">' . "\n";
  5080. $return .= "\t" . '<table cellpadding="0" cellspacing="0" class="lp_form">' . "\n";
  5081. $return .= "\t\t" . '<tr>' . "\n";
  5082. $return .= "\t\t\t" . '<td class="label"><label for="idParent">'.get_lang("Parent").' :</label></td>' . "\n";
  5083. $return .= "\t\t\t" . '<td class="input">' . "\n";
  5084. $return .= "\t\t\t\t" . '<select id="idParent" name="parent" onchange="load_cbo(this.value);" size="1">';
  5085. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
  5086. $arrHide = array($id);
  5087. for($i = 0; $i < count($arrLP); $i++)
  5088. {
  5089. if($action != 'add')
  5090. {
  5091. 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))
  5092. {
  5093. $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'] . '">' . html_entity_decode(stripslashes($arrLP[$i]['title'])) . '</option>';
  5094. }
  5095. else
  5096. {
  5097. $arrHide[] = $arrLP[$i]['id'];
  5098. }
  5099. }
  5100. else
  5101. {
  5102. if($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
  5103. $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'] . '">' . html_entity_decode(stripslashes($arrLP[$i]['title'])) . '</option>';
  5104. }
  5105. }
  5106. reset($arrLP);
  5107. $return .= "\t\t\t\t" . '</select>';
  5108. $return .= "\t\t\t" . '</td>' . "\n";
  5109. $return .= "\t\t" . '</tr>' . "\n";
  5110. $return .= "\t\t" . '<tr>' . "\n";
  5111. $return .= "\t\t\t" . '<td class="label"><label for="idPosition">'.get_lang("Position").' :</label></td>' . "\n";
  5112. $return .= "\t\t\t" . '<td class="input">' . "\n";
  5113. $return .= "\t\t\t\t" . '<select id="idPosition" name="previous" size="1">';
  5114. $return .= "\t\t\t\t\t" . '<option class="top" value="0">'.get_lang("FirstPosition").'</option>';
  5115. for($i = 0; $i < count($arrLP); $i++)
  5116. {
  5117. if($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id)
  5118. {
  5119. if($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5120. $selected = 'selected="selected" ';
  5121. elseif($action == 'add')
  5122. $selected = 'selected="selected" ';
  5123. else
  5124. $selected = '';
  5125. $return .= "\t\t\t\t\t" . '<option ' . $selected . 'value="' . $arrLP[$i]['id'] . '">'.get_lang("After").' "' . html_entity_decode(stripslashes($arrLP[$i]['title'])) . '"</option>';
  5126. }
  5127. }
  5128. $return .= "\t\t\t\t" . '</select>';
  5129. $return .= "\t\t\t" . '</td>' . "\n";
  5130. $return .= "\t\t" . '</tr>' . "\n";
  5131. if($action != 'move')
  5132. {
  5133. $return .= "\t\t" . '<tr>' . "\n";
  5134. $return .= "\t\t\t" . '<td class="label"><label for="idTitle">'.get_lang("Title").' :</label></td>' . "\n";
  5135. $return .= "\t\t\t" . '<td class="input"><input id="idTitle" name="title" type="text" value="' . $item_title . '" /></td>' . "\n";
  5136. $return .= "\t\t" . '</tr>' . "\n";
  5137. $return .= "\t\t" . '<tr>' . "\n";
  5138. $return .= "\t\t\t" . '<td class="label"><label for="idDescription">'.get_lang("Description").' :</label></td>' . "\n";
  5139. $return .= "\t\t\t" . '<td class="input"><textarea id="idDescription" name="description" rows="4">' . $item_description . '</textarea></td>' . "\n";
  5140. $return .= "\t\t" . '</tr>' . "\n";
  5141. $return .= "\t\t" . '<tr>' . "\n";
  5142. $return .= "\t\t\t" . '<td class="label"><label for="idURL">'.get_lang("Url").' :</label></td>' . "\n";
  5143. $return .= "\t\t\t" . '<td class="input"><input' . (is_numeric($extra_info) ? ' disabled="disabled"' : '') . ' id="idURL" name="url" type="text" value="' . $item_url . '" /></td>' . "\n";
  5144. $return .= "\t\t" . '</tr>' . "\n";
  5145. $id_prerequisite=0;
  5146. foreach($arrLP as $key=>$value){
  5147. if($value['id']==$id){
  5148. $id_prerequisite=$value['prerequisite'];
  5149. break;
  5150. }
  5151. }
  5152. $arrHide=array();
  5153. for($i = 0; $i < count($arrLP); $i++)
  5154. {
  5155. if($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter')
  5156. {
  5157. if($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5158. $s_selected_position=$arrLP[$i]['id'];
  5159. elseif($action == 'add')
  5160. $s_selected_position=0;
  5161. $arrHide[$arrLP[$i]['id']]['value']=html_entity_decode(stripslashes($arrLP[$i]['title']));
  5162. }
  5163. }
  5164. $return .= "\t\t" . '<tr>' . "\n";
  5165. $return .= "\t\t\t" . '<td class="label"><label for="idPrerequisites">'.get_lang("Prerequisites").' :</label></td>' . "\n";
  5166. $return .= "\t\t\t" . '<td class="input"><select name="prerequisites" id="prerequisites" style="background:#F8F8F8; border:1px solid #999999; font-family:Arial, Verdana, Helvetica, sans-serif; font-size:12px; width:300px;"><option value="0">'.get_lang("NoPrerequisites").'</option>';
  5167. foreach($arrHide as $key => $value){
  5168. if($key==$s_selected_position && $action == 'add'){
  5169. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  5170. }
  5171. elseif($key==$id_prerequisite && $action == 'edit'){
  5172. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  5173. }
  5174. else{
  5175. $return .= '<option value="'.$key.'">'.$value['value'].'</option>';
  5176. }
  5177. }
  5178. $return .= "</select></td>";
  5179. $return .= "\t\t" . '</tr>' . "\n";
  5180. }
  5181. $return .= "\t\t" . '<tr>' . "\n";
  5182. $return .= "\t\t\t" . '<td colspan="2"><input class="button" name="submit_button" type="submit" value="'.get_lang("Ok").'" /></td>' . "\n";
  5183. $return .= "\t\t" . '</tr>' . "\n";
  5184. $return .= "\t" . '</table>' . "\n";
  5185. if($action == 'move')
  5186. {
  5187. $return .= "\t" . '<input name="title" type="hidden" value="' . $item_title . '" />' . "\n";
  5188. $return .= "\t" . '<input name="description" type="hidden" value="' . $item_description . '" />' . "\n";
  5189. }
  5190. if(is_numeric($extra_info))
  5191. {
  5192. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info . '" />' . "\n";
  5193. }
  5194. elseif(is_array($extra_info))
  5195. {
  5196. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />' . "\n";
  5197. }
  5198. $return .= "\t" . '<input name="type" type="hidden" value="'.TOOL_LINK.'" />' . "\n";
  5199. $return .= "\t" . '<input name="post_time" type="hidden" value="' . time() . '" />' . "\n";
  5200. $return .= '</form>' . "\n";
  5201. $return .= '</div>' . "\n";
  5202. return $return;
  5203. }
  5204. /**
  5205. * Enter description here...
  5206. *
  5207. * @param unknown_type $action
  5208. * @param unknown_type $id
  5209. * @param unknown_type $extra_info
  5210. * @return unknown
  5211. */
  5212. function display_student_publication_form($action = 'add', $id = 0, $extra_info = '')
  5213. {
  5214. $tbl_lp_item = Database::get_course_table('lp_item');
  5215. $tbl_publication = Database::get_course_table(TABLE_STUDENT_PUBLICATION);
  5216. if($id != 0 && is_array($extra_info))
  5217. {
  5218. $item_title = stripslashes($extra_info['title']);
  5219. $item_description = stripslashes($extra_info['description']);
  5220. }
  5221. elseif(is_numeric($extra_info))
  5222. {
  5223. $sql_publication = "
  5224. SELECT
  5225. title,
  5226. description
  5227. FROM " . $tbl_publication . "
  5228. WHERE id = " . $extra_info;
  5229. $result = api_sql_query($sql_publication, __FILE__, __LINE__);
  5230. $row = Database::fetch_array($result);
  5231. $item_title = $row['title'];
  5232. }
  5233. else
  5234. {
  5235. $item_title = '';
  5236. }
  5237. $return = '<div style="margin:3px 10px;">';
  5238. if($id != 0 && is_array($extra_info))
  5239. $parent = $extra_info['parent_item_id'];
  5240. else
  5241. $parent = 0;
  5242. $sql = "
  5243. SELECT *
  5244. FROM " . $tbl_lp_item . "
  5245. WHERE
  5246. lp_id = " . $this->lp_id;
  5247. $result = api_sql_query($sql, __FILE__, __LINE__);
  5248. $arrLP = array();
  5249. while($row = Database::fetch_array($result))
  5250. {
  5251. $arrLP[] = array(
  5252. 'id' => $row['id'],
  5253. 'item_type' => $row['item_type'],
  5254. 'title' => $row['title'],
  5255. 'path' => $row['path'],
  5256. 'description' => $row['description'],
  5257. 'parent_item_id' => $row['parent_item_id'],
  5258. 'previous_item_id' => $row['previous_item_id'],
  5259. 'next_item_id' => $row['next_item_id'],
  5260. 'display_order' => $row['display_order'],
  5261. 'prerequisite' => $row['prerequisite']);
  5262. }
  5263. $this->tree_array($arrLP);
  5264. $arrLP = $this->arrMenu;
  5265. unset($this->arrMenu);
  5266. if($action == 'add')
  5267. $return .= '<p class="lp_title">'.get_lang("Student_publication").' :</p>' . "\n";
  5268. elseif($action == 'move')
  5269. $return .= '<p class="lp_title">'.get_lang("MoveCurrentStudentPublication").' :</p>' . "\n";
  5270. else
  5271. $return .= '<p class="lp_title">'.get_lang("EditCurrentStudentPublication").' :</p>' . "\n";
  5272. $return .= '<form method="POST">' . "\n";
  5273. $return .= "\t" . '<table cellpadding="0" cellspacing="0" class="lp_form">' . "\n";
  5274. $return .= "\t\t" . '<tr>' . "\n";
  5275. $return .= "\t\t\t" . '<td class="label"><label for="idParent">'.get_lang("Parent").' :</label></td>' . "\n";
  5276. $return .= "\t\t\t" . '<td class="input">' . "\n";
  5277. $return .= "\t\t\t\t" . '<select id="idParent" name="parent" onchange="load_cbo(this.value);" size="1">';
  5278. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
  5279. $arrHide = array($id);
  5280. for($i = 0; $i < count($arrLP); $i++)
  5281. {
  5282. if($action != 'add')
  5283. {
  5284. 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))
  5285. {
  5286. $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'] . '">' . html_entity_decode(stripslashes($arrLP[$i]['title'])) . '</option>';
  5287. }
  5288. else
  5289. {
  5290. $arrHide[] = $arrLP[$i]['id'];
  5291. }
  5292. }
  5293. else
  5294. {
  5295. if($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
  5296. $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'] . '">' . html_entity_decode(stripslashes($arrLP[$i]['title'])) . '</option>';
  5297. }
  5298. }
  5299. reset($arrLP);
  5300. $return .= "\t\t\t\t" . '</select>';
  5301. $return .= "\t\t\t" . '</td>' . "\n";
  5302. $return .= "\t\t" . '</tr>' . "\n";
  5303. $return .= "\t\t" . '<tr>' . "\n";
  5304. $return .= "\t\t\t" . '<td class="label"><label for="idPosition">'.get_lang("Position").' :</label></td>' . "\n";
  5305. $return .= "\t\t\t" . '<td class="input">' . "\n";
  5306. $return .= "\t\t\t\t" . '<select id="idPosition" name="previous" size="1">';
  5307. $return .= "\t\t\t\t\t" . '<option class="top" value="0">'.get_lang("FirstPosition").'</option>';
  5308. for($i = 0; $i < count($arrLP); $i++)
  5309. {
  5310. if($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id)
  5311. {
  5312. if($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5313. $selected = 'selected="selected" ';
  5314. elseif($action == 'add')
  5315. $selected = 'selected="selected" ';
  5316. else
  5317. $selected = '';
  5318. $return .= "\t\t\t\t\t" . '<option ' . $selected . 'value="' . $arrLP[$i]['id'] . '">'.get_lang("After").' "' . html_entity_decode(stripslashes($arrLP[$i]['title'])) . '"</option>';
  5319. }
  5320. }
  5321. $return .= "\t\t\t\t" . '</select>';
  5322. $return .= "\t\t\t" . '</td>' . "\n";
  5323. $return .= "\t\t" . '</tr>' . "\n";
  5324. if($action != 'move')
  5325. {
  5326. $return .= "\t\t" . '<tr>' . "\n";
  5327. $return .= "\t\t\t" . '<td class="label"><label for="idTitle">'.get_lang("Title").' :</label></td>' . "\n";
  5328. $return .= "\t\t\t" . '<td class="input"><input id="idTitle" name="title" type="text" value="' . $item_title . '" /></td>' . "\n";
  5329. $return .= "\t\t" . '</tr>' . "\n";
  5330. $id_prerequisite=0;
  5331. foreach($arrLP as $key=>$value){
  5332. if($value['id']==$id){
  5333. $id_prerequisite=$value['prerequisite'];
  5334. break;
  5335. }
  5336. }
  5337. $arrHide=array();
  5338. for($i = 0; $i < count($arrLP); $i++)
  5339. {
  5340. if($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter')
  5341. {
  5342. if($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5343. $s_selected_position=$arrLP[$i]['id'];
  5344. elseif($action == 'add')
  5345. $s_selected_position=0;
  5346. $arrHide[$arrLP[$i]['id']]['value']=html_entity_decode(stripslashes($arrLP[$i]['title']));
  5347. }
  5348. }
  5349. $return .= "\t\t" . '<tr>' . "\n";
  5350. $return .= "\t\t\t" . '<td class="label"><label for="idPrerequisites">'.get_lang("Prerequisites").' :</label></td>' . "\n";
  5351. $return .= "\t\t\t" . '<td class="input"><select name="prerequisites" id="prerequisites" style="background:#F8F8F8; border:1px solid #999999; font-family:Arial, Verdana, Helvetica, sans-serif; font-size:12px; width:300px;"><option value="0">'.get_lang("NoPrerequisites").'</option>';
  5352. foreach($arrHide as $key => $value){
  5353. if($key==$s_selected_position && $action == 'add'){
  5354. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  5355. }
  5356. elseif($key==$id_prerequisite && $action == 'edit'){
  5357. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  5358. }
  5359. else{
  5360. $return .= '<option value="'.$key.'">'.$value['value'].'</option>';
  5361. }
  5362. }
  5363. $return .= "</select></td>";
  5364. $return .= "\t\t" . '</tr>' . "\n";
  5365. }
  5366. $return .= "\t\t" . '<tr>' . "\n";
  5367. $return .= "\t\t\t" . '<td colspan="2"><input class="button" name="submit_button" type="submit" value="'.get_lang("Ok").'" /></td>' . "\n";
  5368. $return .= "\t\t" . '</tr>' . "\n";
  5369. $return .= "\t" . '</table>' . "\n";
  5370. if($action == 'move')
  5371. {
  5372. $return .= "\t" . '<input name="title" type="hidden" value="' . $item_title . '" />' . "\n";
  5373. $return .= "\t" . '<input name="description" type="hidden" value="' . $item_description . '" />' . "\n";
  5374. }
  5375. if(is_numeric($extra_info))
  5376. {
  5377. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info . '" />' . "\n";
  5378. }
  5379. elseif(is_array($extra_info))
  5380. {
  5381. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />' . "\n";
  5382. }
  5383. $return .= "\t" . '<input name="type" type="hidden" value="'.TOOL_STUDENTPUBLICATION.'" />' . "\n";
  5384. $return .= "\t" . '<input name="post_time" type="hidden" value="' . time() . '" />' . "\n";
  5385. $return .= '</form>' . "\n";
  5386. $return .= '</div>' . "\n";
  5387. return $return;
  5388. }
  5389. /**
  5390. * Displays the menu for manipulating a step
  5391. *
  5392. * @return unknown
  5393. */
  5394. function display_manipulate($item_id, $item_type = TOOL_DOCUMENT)
  5395. {
  5396. $return = '<div class="lp_manipulate"><table border="0" width="100%"><tr><td valign="top" width="400">';
  5397. switch($item_type)
  5398. {
  5399. case 'dokeos_chapter':
  5400. case 'chapter':
  5401. $lang = get_lang('TitleManipulateChapter');
  5402. break;
  5403. case 'dokeos_module':
  5404. case 'module':
  5405. $lang = get_lang('TitleManipulateModule');
  5406. break;
  5407. case TOOL_DOCUMENT:
  5408. $lang = get_lang('TitleManipulateDocument');
  5409. break;
  5410. case TOOL_LINK:
  5411. case 'link':
  5412. $lang = get_lang('TitleManipulateLink');
  5413. break;
  5414. case TOOL_QUIZ:
  5415. $lang = get_lang('TitleManipulateQuiz');
  5416. break;
  5417. case TOOL_STUDENTPUBLICATION:
  5418. $lang = get_lang('TitleManipulateStudentPublication');
  5419. break;
  5420. }
  5421. $tbl_lp_item = Database::get_course_table('lp_item');
  5422. $sql = "
  5423. SELECT
  5424. description
  5425. FROM " . $tbl_lp_item . " as lp
  5426. WHERE
  5427. lp.id = " . $item_id;
  5428. $result = api_sql_query($sql, __FILE__, __LINE__);
  5429. $s_description=mysql_result($result,0,0);
  5430. $return .= '<p class="lp_title">' . $lang . '</p>';
  5431. $return .= '<a href="' .api_get_self(). '?cidReq=' . $_GET['cidReq'] . '&amp;action=edit_item&amp;view=build&amp;id=' . $item_id . '&amp;lp_id=' . $this->lp_id . '" title="Edit the current item"><img align="absbottom" alt="Edit the current item" src="../img/edit.gif" title="Edit the current item" /> '.get_lang("Edit").'</a>';
  5432. $return .= '<a href="' .api_get_self(). '?cidReq=' . $_GET['cidReq'] . '&amp;action=move_item&amp;view=build&amp;id=' . $item_id . '&amp;lp_id=' . $this->lp_id . '" title="Move the current item"><img align="absbottom" alt="Move the current item" src="../img/deplacer_fichier.gif" title="Move the current item" /> '.get_lang("Move").'</a>';
  5433. // commented for now as prerequisites cannot be added to chapters
  5434. if($item_type != 'dokeos_chapter' && $item_type != 'chapter')
  5435. {
  5436. $return .= '<a href="' .api_get_self(). '?cidReq=' . $_GET['cidReq'] . '&amp;action=edit_item_prereq&amp;view=build&amp;id=' . $item_id . '&amp;lp_id=' . $this->lp_id . '" title="'.get_lang('Prerequisites').'"><img align="absbottom" alt="'.get_lang('Prerequisites').'" src="../img/right.gif" title="'.get_lang('Prerequisites').'" /> '.get_lang('Prerequisites').'</a>';
  5437. }
  5438. $return .= '<a href="' .api_get_self(). '?cidReq=' . $_GET['cidReq'] . '&amp;action=delete_item&amp;view=build&amp;id=' . $item_id . '&amp;lp_id=' . $this->lp_id . '" onclick="return confirmation(\'' . htmlentities($s_description) . '\');" title="Delete the current item"><img alt="Delete the current item" align="absbottom" src="../img/delete.gif" title="Delete the current item" /> '.get_lang("Delete").'</a>';
  5439. //$return .= '<br><br><p class="lp_text">' . ((trim($s_description) == '') ? ''.get_lang("NoDescription").'' : stripslashes(nl2br($s_description))) . '</p>';
  5440. $return.="</td><td valign='top'>";
  5441. // get the audiorecorder. Use of ob_* functions since there are echos in the file
  5442. ob_start();
  5443. $audio_recorder_studentview = 'false';
  5444. $audio_recorder_item_id = $item_id;
  5445. if(api_get_setting('service_ppt2lp','active')=='true' && api_get_setting('service_ppt2lp','path_to_lzx')!=''){
  5446. include('audiorecorder.inc.php');
  5447. }
  5448. $return .= ob_get_contents();
  5449. ob_end_clean();
  5450. // end of audiorecorder include
  5451. $return.="</td></tr></table>";
  5452. $return .= '</div>';
  5453. return $return;
  5454. }
  5455. /**
  5456. * Creates the javascript needed for filling up the checkboxes without page reload
  5457. *
  5458. * @return string
  5459. */
  5460. function create_js()
  5461. {
  5462. $return = '<script language="javascript" type="text/javascript">' . "\n";
  5463. $return .= 'function load_cbo(id){' . "\n";
  5464. $return .= "var cbo = document.getElementById('idPosition');\n";
  5465. $return .= 'for(var i = cbo.length - 1; i > 0; i--)';
  5466. $return .= 'cbo.options[i] = null;'."\n";
  5467. $return .= 'var k=0;'."\n";
  5468. $return .= 'for(var i = 1; i <= child_name[id].length; i++){'."\n";
  5469. $return .= ' cbo.options[i] = new Option(child_name[id][i-1], child_value[id][i-1]);'."\n";
  5470. $return .= 'k=i;';
  5471. $return .= '}' . "\n\n";
  5472. $return .= 'if( typeof cbo != "undefined" ) {cbo.options[k].selected = true;}';
  5473. $return .='}';
  5474. $return .= 'var child_name = new Array();' . "\n";
  5475. $return .= 'var child_value = new Array();' . "\n\n";
  5476. $return .= 'child_name[0] = new Array();' . "\n";
  5477. $return .= 'child_value[0] = new Array();' . "\n\n";
  5478. $tbl_lp_item = Database::get_course_table('lp_item');
  5479. $sql_zero = "
  5480. SELECT *
  5481. FROM " . $tbl_lp_item . "
  5482. WHERE
  5483. lp_id = " . $this->lp_id . " AND
  5484. parent_item_id = 0
  5485. ORDER BY display_order ASC";
  5486. $res_zero = api_sql_query($sql_zero, __FILE__, __LINE__);
  5487. $i = 0;
  5488. while($row_zero = Database::fetch_array($res_zero))
  5489. {
  5490. $return .= 'child_name[0][' . $i . '] = "'.get_lang("After").' \"' . $row_zero['title'] . '\"";' . "\n";
  5491. $return .= 'child_value[0][' . $i++ . '] = "' . $row_zero['id'] . '";' . "\n";
  5492. }
  5493. $return .= "\n";
  5494. $sql = "
  5495. SELECT *
  5496. FROM " . $tbl_lp_item . "
  5497. WHERE
  5498. lp_id = " . $this->lp_id;
  5499. $res = api_sql_query($sql, __FILE__, __LINE__);
  5500. while($row = Database::fetch_array($res))
  5501. {
  5502. $sql_parent = "
  5503. SELECT *
  5504. FROM " . $tbl_lp_item . "
  5505. WHERE parent_item_id = " . $row['id'] . "
  5506. ORDER BY display_order ASC";
  5507. $res_parent = api_sql_query($sql_parent, __FILE__, __LINE__);
  5508. $i = 0;
  5509. $return .= 'child_name[' . $row['id'] . '] = new Array();' . "\n";
  5510. $return .= 'child_value[' . $row['id'] . '] = new Array();' . "\n\n";
  5511. while($row_parent = Database::fetch_array($res_parent))
  5512. {
  5513. $return .= 'child_name[' . $row['id'] . '][' . $i . '] = "'.get_lang("After").' \"' . $row_parent['title'] . '\"";' . "\n";
  5514. $return .= 'child_value[' . $row['id'] . '][' . $i++ . '] = "' . $row_parent['id'] . '";' . "\n";
  5515. }
  5516. $return .= "\n";
  5517. }
  5518. $return .= '</script>' . "\n";
  5519. return $return;
  5520. }
  5521. /**
  5522. * Enter description here...
  5523. *
  5524. * @param unknown_type $item_id
  5525. * @return unknown
  5526. */
  5527. function display_move_item($item_id)
  5528. {
  5529. global $_course; //will disappear
  5530. $return = '';
  5531. if(is_numeric($item_id))
  5532. {
  5533. $tbl_lp_item = Database::get_course_table('lp_item');
  5534. $sql = "
  5535. SELECT *
  5536. FROM " . $tbl_lp_item . "
  5537. WHERE id = " . $item_id;
  5538. $res = api_sql_query($sql, __FILE__, __LINE__);
  5539. $row = Database::fetch_array($res);
  5540. switch($row['item_type'])
  5541. {
  5542. case 'dokeos_chapter': case 'dir' : case 'asset' :
  5543. $return .= $this->display_manipulate($item_id, $row['item_type']);
  5544. $return .= $this->display_item_form($row['item_type'], get_lang('MoveCurrentChapter'), 'move', $item_id, $row);
  5545. break;
  5546. case 'dokeos_module':
  5547. $return .= $this->display_manipulate($item_id, $row['item_type']);
  5548. $return .= $this->display_item_form($row['item_type'], 'Move th current module:', 'move', $item_id, $row);
  5549. break;
  5550. case TOOL_DOCUMENT:
  5551. $return .= $this->display_manipulate($item_id, $row['item_type']);
  5552. $return .= $this->display_document_form('move', $item_id, $row);
  5553. break;
  5554. case TOOL_LINK:
  5555. $return .= $this->display_manipulate($item_id, $row['item_type']);
  5556. $return .= $this->display_link_form('move', $item_id, $row);
  5557. break;
  5558. case TOOL_HOTPOTATOES:
  5559. $return .= $this->display_manipulate($item_id, $row['item_type']);
  5560. $return .= $this->display_link_form('move', $item_id, $row);
  5561. break;
  5562. case TOOL_QUIZ:
  5563. $return .= $this->display_manipulate($item_id, $row['item_type']);
  5564. $return .= $this->display_quiz_form('move', $item_id, $row);
  5565. break;
  5566. case TOOL_STUDENTPUBLICATION:
  5567. $return .= $this->display_manipulate($item_id, $row['item_type']);
  5568. $return .= $this->display_student_publication_form('move', $item_id, $row);
  5569. break;
  5570. case TOOL_FORUM :
  5571. $return .= $this->display_manipulate($item_id, $row['item_type']);
  5572. $return .= $this->display_forum_form('move', $item_id, $row);
  5573. }
  5574. }
  5575. return $return;
  5576. }
  5577. /**
  5578. * Displays a basic form on the overview page for changing the item title and the item description.
  5579. *
  5580. * @param string $item_type
  5581. * @param string $title
  5582. * @param array $data
  5583. * @return string
  5584. */
  5585. function display_item_small_form($item_type, $title = '', $data)
  5586. {
  5587. $return .= '<div class="lp_small_form">' . "\n";
  5588. $return .= '<p class="lp_title">' . $title . '</p>';
  5589. $return .= '<form method="post">' . "\n";
  5590. $return .= '<table cellpadding="0" cellspacing="0" class="lp_form">';
  5591. $return .= "\t\t" . '<tr>' . "\n";
  5592. $return .= "\t\t\t" . '<td class="label"><label for="idTitle">Title:</label></td>' . "\n";
  5593. $return .= "\t\t\t" . '<td class="input"><input class="small_form" id="idTitle" name="title" type="text" value="' . $data['title'] . '" /></td>' . "\n";
  5594. $return .= "\t\t" . '</tr>' . "\n";
  5595. $return .= "\t\t" . '<tr>' . "\n";
  5596. $return .= "\t\t\t" . '<td class="label"><label for="idDescription">Description:</label></td>' . "\n";
  5597. $return .= "\t\t\t" . '<td class="input"><textarea class="small_form" id="idDescription" name="description" rows="4">' . $data['description'] . '</textarea></td>' . "\n";
  5598. $return .= "\t\t" . '</tr>' . "\n";
  5599. $return .= "\t\t" . '<tr>' . "\n";
  5600. $return .= "\t\t\t" . '<td colspan="2"><input class="button small_form" name="submit_button" type="submit" value="OK" /></td>' . "\n";
  5601. $return .= "\t\t" . '</tr>' . "\n";
  5602. $return .= "\t\t" . '</table>' . "\n";
  5603. $return .= "\t" . '<input name="parent" type="hidden" value="' . $data['parent_item_id'] . '"/>' . "\n";
  5604. $return .= "\t" . '<input name="previous" type="hidden" value="' . $data['previous_item_id'] . '"/>' . "\n";
  5605. $return .= '</form>';
  5606. $return .= '</div>';
  5607. return $return;
  5608. }
  5609. /**
  5610. * Enter description here...
  5611. *
  5612. * @param unknown_type $item_id
  5613. * @return unknown
  5614. */
  5615. function display_item_prerequisites_form($item_id)
  5616. {
  5617. $tbl_lp_item = Database::get_course_table('lp_item');
  5618. /* current prerequisite */
  5619. $sql = "
  5620. SELECT *
  5621. FROM " . $tbl_lp_item . "
  5622. WHERE id = " . $item_id;
  5623. $result = api_sql_query($sql, __FILE__, __LINE__);
  5624. $row = Database::fetch_array($result);
  5625. $preq_id = $row['prerequisite'];
  5626. //$preq_mastery = $row['mastery_score'];
  5627. //$preq_max = $row['max_score'];
  5628. $return = $this->display_manipulate($item_id, TOOL_DOCUMENT);
  5629. $return .= '<div style="margin:3px 10px;">';
  5630. $return .= '<p class="lp_title">'.get_lang("AddEditPrerequisites").'</p>';
  5631. $return .= '<form method="POST">';
  5632. $return .= '<table class="lp_form">';
  5633. $return .= '<tr>';
  5634. $return .= '<th></th>';
  5635. $return .= '<th class="exercise">'.get_lang("Minimum").'</th>';
  5636. $return .= '<th class="exercise">'.get_lang("Maximum").'</th>';
  5637. $return .= '</tr>';
  5638. $return .= '<tr>';
  5639. $return .= '<td class="radio" colspan="3">';
  5640. $return .= '<input checked="checked" id="idNone" name="prerequisites" style="margin-left:0; margin-right:10px;" type="radio" />';
  5641. $return .= '<label for="idNone">'.get_lang("None").'</label>';
  5642. $return .= '</td>';
  5643. $return .= '</tr>';
  5644. $sql = "
  5645. SELECT *
  5646. FROM " . $tbl_lp_item . "
  5647. WHERE
  5648. lp_id = " . $this->lp_id;
  5649. $result = api_sql_query($sql, __FILE__, __LINE__);
  5650. $arrLP = array();
  5651. while($row = Database::fetch_array($result))
  5652. {
  5653. $arrLP[] = array(
  5654. 'id' => $row['id'],
  5655. 'item_type' => $row['item_type'],
  5656. 'title' => $row['title'],
  5657. 'ref' => $row['ref'],
  5658. 'description' => $row['description'],
  5659. 'parent_item_id' => $row['parent_item_id'],
  5660. 'previous_item_id' => $row['previous_item_id'],
  5661. 'next_item_id' => $row['next_item_id'],
  5662. 'max_score' => $row['max_score'],
  5663. 'min_score' => $row['min_score'],
  5664. 'mastery_score' => $row['mastery_score'],
  5665. 'next_item_id' => $row['next_item_id'],
  5666. 'display_order' => $row['display_order']);
  5667. if($row['ref'] == $preq_id)
  5668. {
  5669. $preq_mastery = $row['mastery_score'];
  5670. $preq_max = $row['max_score'];
  5671. }
  5672. }
  5673. $this->tree_array($arrLP);
  5674. $arrLP = $this->arrMenu;
  5675. unset($this->arrMenu);
  5676. for($i = 0; $i < count($arrLP); $i++)
  5677. {
  5678. if($arrLP[$i]['id'] == $item_id)
  5679. break;
  5680. $return .= '<tr>';
  5681. $return .= '<td class="radio"' . (($arrLP[$i]['item_type'] != TOOL_QUIZ && $arrLP[$i]['item_type'] != TOOL_HOTPOTATOES) ? ' colspan="3"' : '') . '>';
  5682. $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'] . '" />';
  5683. $return .= '<img alt="" src="../img/lp_' . $arrLP[$i]['item_type'] . '.png" style="margin-right:5px;" title="" />';
  5684. $return .= '<label for="id' . $arrLP[$i]['id'] . '">' . stripslashes($arrLP[$i]['title']) . '</label>';
  5685. $return .= '</td>';
  5686. //$return .= '<td class="radio"' . (($arrLP[$i]['item_type'] != TOOL_HOTPOTATOES) ? ' colspan="3"' : '') . ' />';
  5687. if($arrLP[$i]['item_type'] == TOOL_QUIZ)
  5688. {
  5689. $return .= '<td class="exercise">';
  5690. $return .= '<input maxlength="3" name="min_' . $arrLP[$i]['id'] . '" type="text" value="' . (($arrLP[$i]['id'] == $preq_id) ? $preq_mastery : 0) . '" />';
  5691. $return .= '</td>';
  5692. $return .= '<td class="exercise">';
  5693. $return .= '<input maxlength="3" name="max_' . $arrLP[$i]['id'] . '" type="text" value="' . $arrLP[$i]['max_score'] . '" disabled="true" />';
  5694. $return .= '</td>';
  5695. }
  5696. if($arrLP[$i]['item_type'] == TOOL_HOTPOTATOES)
  5697. {
  5698. $return .= '<td class="exercise">';
  5699. $return .= '<input maxlength="3" name="min_' . $arrLP[$i]['id'] . '" type="text" value="' . (($arrLP[$i]['id'] == $preq_id) ? $preq_mastery : 0) . '" />';
  5700. $return .= '</td>';
  5701. $return .= '<td class="exercise">';
  5702. $return .= '<input maxlength="3" name="max_' . $arrLP[$i]['id'] . '" type="text" value="' . $arrLP[$i]['max_score'] . '" disabled="true" />';
  5703. $return .= '</td>';
  5704. }
  5705. $return .='</tr>';
  5706. }
  5707. $return .= '<tr>';
  5708. $return .= '<td colspan="3">';
  5709. $return .= '<input class="button" name="submit_button" type="submit" value="'.get_lang("Ok").'" /></td>' . "\n";
  5710. $return .= '</td>';
  5711. $return .= '</tr>';
  5712. $return .= '</table>';
  5713. $return .= '</form>';
  5714. $return .= '</div>';
  5715. return $return;
  5716. }
  5717. /**
  5718. * Creates a list with all the documents in it
  5719. *
  5720. * @return string
  5721. */
  5722. function get_documents()
  5723. {
  5724. global $_course;
  5725. $tbl_doc = Database::get_course_table(TABLE_DOCUMENT);
  5726. $sql_doc = "
  5727. SELECT *
  5728. FROM " . $tbl_doc . "
  5729. WHERE
  5730. path NOT LIKE '%_DELETED_%'
  5731. ORDER BY path ASC";
  5732. $res_doc = api_sql_query($sql_doc, __FILE__, __LINE__);
  5733. $return = '<div class="lp_resource_header"' . " onclick=\"if(document.getElementById('resDoc').style.display == 'block') {document.getElementById('resDoc').style.display = 'none';} else {document.getElementById('resDoc').style.display = 'block';}\"" . ' style="cursor:pointer;"><img align="left" alt="" src="../img/lp_' . TOOL_DOCUMENT . '.gif" style="margin-right:5px;" title="" />'.get_lang("Document").'</div>';
  5734. $return .= '<div class="lp_resource_elements" id="resDoc">';
  5735. $resources=api_store_result($res_doc);
  5736. $resources_sorted = array();
  5737. // if you want to debug it, I advise you to do "echo" on the eval statements
  5738. foreach($resources as $resource)
  5739. {
  5740. $resource_paths = explode('/',$resource['path']);
  5741. array_shift($resource_paths);
  5742. $path_to_eval = $last_path = '';
  5743. $is_file = false;
  5744. foreach($resource_paths as $key => $resource_path)
  5745. {
  5746. if(strpos($resource_path,'.')===false && $key != count($resource_paths)-1)
  5747. { // it's a folder
  5748. $path_to_eval .= '["'.$resource_path.'"]["files"]';
  5749. }
  5750. else if(strpos($resource_path,'.')!==false)
  5751. $is_file = true;
  5752. $last_path = $resource_path;
  5753. }
  5754. if($is_file)
  5755. {
  5756. eval('$resources_sorted'.$path_to_eval.'['.$resource['id'].'] = "'.$last_path.'";');
  5757. }
  5758. else
  5759. {
  5760. eval('$resources_sorted'.$path_to_eval.'["'.$last_path.'"]["id"]='.$resource['id'].';');
  5761. }
  5762. }
  5763. $return .=$this->write_resources_tree('', $resources_sorted);
  5764. $return .='</div>';
  5765. if(Database::num_rows($res_doc) == 0)
  5766. $return .= '<div class="lp_resource_element">'.get_lang("NoDocuments").'</div>';
  5767. return $return;
  5768. }
  5769. function write_resources_tree($return, $resources_sorted, $num=0){
  5770. include_once(api_get_path(LIBRARY_PATH).'fileDisplay.lib.php');
  5771. if(count($resources_sorted)>0)
  5772. {
  5773. foreach($resources_sorted as $key=>$resource)
  5774. {
  5775. if(is_int($resource['id']))
  5776. { // it's a folder
  5777. $return .= '<div><div style="margin-left:' . ($num * 15) . 'px;margin-right:5px;"><img style="cursor: pointer;" src="../img/nolines_plus.gif" align="absmiddle" id="img_'.$resource["id"].'" onclick="testResources(\''.$resource["id"].'\',\'img_'.$resource["id"].'\')"><img alt="" src="../img/lp_folder.gif" title="" align="absmiddle" />&nbsp;<span onclick="testResources(\''.$resource["id"].'\',\'img_'.$resource["id"].'\')" style="cursor: pointer;" >'.$key.'</span></div><div style="display: none;" id="'.$resource['id'].'">';
  5778. $return = $this->write_resources_tree($return, $resource['files'], $num+1);
  5779. $return .= "</div></div>\r\n";
  5780. }
  5781. else
  5782. {
  5783. // it's a file
  5784. $icon = choose_image($resource);
  5785. $position = strrpos($icon,'.');
  5786. $icon=substr($icon,0,$position).'_small.gif';
  5787. $return .= '<div><div style="margin-left:' . (($num+1) * 15) . 'px;margin-right:5px;"><a href="' . api_get_self() . '?cidReq=' . $_GET['cidReq'] . '&amp;action=add_item&amp;type=' . TOOL_DOCUMENT . '&amp;file=' . $key . '&amp;lp_id=' . $this->lp_id . '"><img align="left" alt="" src="../img/'.$icon.'" title="" />&nbsp;'.$resource."</a></div></div>\r\n";
  5788. }
  5789. }
  5790. }
  5791. return $return;
  5792. }
  5793. /**
  5794. * Creates a list with all the exercises (quiz) in it
  5795. *
  5796. * @return string
  5797. */
  5798. function get_exercises()
  5799. {
  5800. // new for hotpotatoes
  5801. $uploadPath = DIR_HOTPOTATOES; //defined in main_api
  5802. $tbl_doc = Database::get_course_table(TABLE_DOCUMENT);
  5803. $tbl_quiz = Database::get_course_table(TABLE_QUIZ_TEST);
  5804. $sql_quiz = "
  5805. SELECT *
  5806. FROM " . $tbl_quiz . "
  5807. WHERE active<>'-1'
  5808. ORDER BY title ASC";
  5809. $sql_hot = "SELECT * FROM ".$tbl_doc." " .
  5810. " WHERE path LIKE '".$uploadPath."/%/%htm%'" .
  5811. " ORDER BY id ASC";
  5812. $res_quiz = api_sql_query($sql_quiz, __FILE__, __LINE__);
  5813. $res_hot = api_sql_query($sql_hot, __FILE__, __LINE__);
  5814. $return .= '<div class="lp_resource_header_end"' . " onclick=\"if(document.getElementById('resExercise').style.display == 'block') {document.getElementById('resExercise').style.display = 'none';} else {document.getElementById('resExercise').style.display = 'block';}\"" . ' style="cursor:pointer;"><img align="left" alt="" src="../img/lp_' . TOOL_QUIZ . '.gif" style="margin-right:5px;" title="" />'.get_lang('Quiz').'</div>';
  5815. $return .= '<div class="lp_resource_elements_end" id="resExercise">';
  5816. while ($row_hot = mysql_fetch_array($res_hot))
  5817. {
  5818. $return .= '<div class="lp_resource_element">';
  5819. //display quizhotpotatoes
  5820. $return .= '<img alt="" src="../img/jqz.jpg" style="margin-right:5px;" title="" />';
  5821. $return .= '<a href="' .api_get_self(). '?cidReq=' . $_GET['cidReq'] . '&amp;action=add_item&amp;type=' . TOOL_HOTPOTATOES . '&amp;file=' . $row_hot['id'] . '&amp;lp_id=' . $this->lp_id . '">' . $row_hot['title'] . '</a>';
  5822. //$return .= $row_quiz['title'];
  5823. $return .= '</div>';
  5824. }
  5825. while($row_quiz = Database::fetch_array($res_quiz))
  5826. {
  5827. $return .= '<div class="lp_resource_element">';
  5828. $return .= '<img alt="" src="../img/quizz_small.gif" style="margin-right:5px;" title="" />';
  5829. $return .= '<a href="' .api_get_self(). '?cidReq=' . $_GET['cidReq'] . '&amp;action=add_item&amp;type=' . TOOL_QUIZ . '&amp;file=' . $row_quiz['id'] . '&amp;lp_id=' . $this->lp_id . '">' . $row_quiz['title'] . '</a>';
  5830. //$return .= $row_quiz['title'];
  5831. $return .= '</div>';
  5832. }
  5833. if(Database::num_rows($res_quiz) == 0)
  5834. $return .= '<div class="lp_resource_element">'.get_lang("NoExercisesAvailable").'</div>';
  5835. $return .= '<div class="lp_resource_element">';
  5836. $return .= '<img alt="" src="../img/new_test_small.gif" style="margin-right:5px;" title="" />';
  5837. $return .= '<a href="'.api_get_path(REL_CODE_PATH).'exercice/exercise_admin.php">' . get_lang('NewExercise') . '</a>';
  5838. $return .= '</div>';
  5839. $return .= '</div>';
  5840. return $return;
  5841. }
  5842. /**
  5843. * Creates a list with all the links in it
  5844. *
  5845. * @return string
  5846. */
  5847. function get_links()
  5848. {
  5849. $tbl_link = Database::get_course_table(TABLE_LINK);
  5850. $sql_link = "
  5851. SELECT *
  5852. FROM " . $tbl_link . "
  5853. ORDER BY title ASC";
  5854. $res_link = api_sql_query($sql_link, __FILE__, __LINE__);
  5855. $return .= '<div class="lp_resource_header"' . " onclick=\"if(document.getElementById('resLink').style.display == 'block') {document.getElementById('resLink').style.display = 'none';} else {document.getElementById('resLink').style.display = 'block';}\"" . ' style="cursor:pointer;"><img align="left" alt="" src="../img/lp_' . TOOL_LINK . '.gif" style="margin-right:5px;" title="" />'.get_lang("Links").'</div>';
  5856. $return .= '<div class="lp_resource_elements" id="resLink">';
  5857. while($row_link = Database::fetch_array($res_link))
  5858. {
  5859. $return .= '<div class="lp_resource_element">';
  5860. $return .= '<img align="left" alt="" src="../img/file_html_small.gif" style="margin-right:5px;" title="" />';
  5861. $return .= '<a href="' .api_get_self(). '?cidReq=' . $_GET['cidReq'] . '&amp;action=add_item&amp;type=' . TOOL_LINK . '&amp;file=' . $row_link['id'] . '&amp;lp_id=' . $this->lp_id . '">' . $row_link['title'] . '</a>';
  5862. $return .= '</div>';
  5863. }
  5864. $return .= '<div class="lp_resource_element">';
  5865. $return .= '<img align="left" alt="" src="../img/file_html_new_small.gif" style="margin-right:5px;" title="" />';
  5866. $return .= '<a href="'.api_get_path(REL_CODE_PATH).'link/link.php?'.api_get_cidreq().'&action=addlink" title="' . get_lang('LinkAdd') . '">' . get_lang('LinkAdd') . '</a>';
  5867. $return .= '</div>';
  5868. if(Database::num_rows($res_link) == 0)
  5869. $return .= '<div class="lp_resource_element">'.get_lang("NoLinksAvailable").'</div>';
  5870. $return .= '</div>';
  5871. return $return;
  5872. }
  5873. /**
  5874. * Creates a list with all the student publications in it
  5875. *
  5876. * @return unknown
  5877. */
  5878. function get_student_publications()
  5879. {
  5880. $tbl_student = Database::get_course_table(TABLE_STUDENT_PUBLICATION);
  5881. $sql_student = "
  5882. SELECT *
  5883. FROM " . $tbl_student . "
  5884. ORDER BY title ASC";
  5885. $res_student = api_sql_query($sql_student, __FILE__, __LINE__);
  5886. $return .= '<div class="lp_resource_header"' . " onclick=\"if(document.getElementById('resStudent').style.display == 'block') {document.getElementById('resStudent').style.display = 'none';} else {document.getElementById('resStudent').style.display = 'block';}\"" . ' style="border-bottom:1px solid #999999; cursor:pointer;"><img align="left" alt="" src="../img/lp_' . TOOL_STUDENTPUBLICATION . '.gif" style="margin-right:5px;" title="" />'.get_lang('Student_publication').'</div>';
  5887. $return .= '<div class="lp_resource_elements" id="resStudent" style="border-bottom:1px solid #999999; border-top:0;">';
  5888. $return .= '<div class="lp_resource_element">';
  5889. $return .= '<img align="left" alt="" src="../img/works_small.gif" style="margin-right:5px;" title="" />';
  5890. $return .= '<a href="' .api_get_self(). '?cidReq=' . $_GET['cidReq'] . '&amp;action=add_item&amp;type=' . TOOL_STUDENTPUBLICATION . '&amp;lp_id=' . $this->lp_id . '">' . get_lang('AddAssignmentPage') . '</a>';
  5891. $return .= '</div>';
  5892. $return .= '</div>';
  5893. return $return;
  5894. }
  5895. function get_forums()
  5896. {
  5897. include ('../forum/forumfunction.inc.php');
  5898. include ('../forum/forumconfig.inc.php');
  5899. global $table_forums, $table_threads,$table_posts, $table_item_property, $table_users;
  5900. $table_forums = Database :: get_course_table(TABLE_FORUM);
  5901. $table_threads = Database :: get_course_table(TABLE_FORUM_THREAD);
  5902. $table_posts = Database :: get_course_table(TABLE_FORUM_POST);
  5903. $table_item_property = Database :: get_course_table(TABLE_ITEM_PROPERTY);
  5904. $table_users = Database :: get_main_table(TABLE_MAIN_USER);
  5905. $a_forums = get_forums();
  5906. $return .= '<div class="lp_resource_header"' . " onclick=\"if(document.getElementById('forums').style.display == 'block') {document.getElementById('forums').style.display = 'none';} else {document.getElementById('forums').style.display = 'block';}\"" . ' style="border-bottom:1px solid #999999; cursor:pointer;"><img align="left" alt="" src="../img/lp_forum.gif" style="margin-right:5px;" title="" />'.get_lang('Forums').'</div>';
  5907. $return .= '<div class="lp_resource_elements" id="forums" style="border-bottom:1px solid #999999; border-top:0;">';
  5908. foreach($a_forums as $forum)
  5909. {
  5910. $return .= '<div class="lp_resource_element">';
  5911. $return .= '<script type="text/javascript">
  5912. function toggle_forum(forum_id){
  5913. if(document.getElementById("forum_"+forum_id+"_content").style.display == "none"){
  5914. document.getElementById("forum_"+forum_id+"_content").style.display = "block";
  5915. document.getElementById("forum_"+forum_id+"_opener").src = "'.api_get_path(WEB_IMG_PATH).'remove.gif";
  5916. }
  5917. else {
  5918. document.getElementById("forum_"+forum_id+"_content").style.display = "none";
  5919. document.getElementById("forum_"+forum_id+"_opener").src = "'.api_get_path(WEB_IMG_PATH).'add.gif";
  5920. }
  5921. }
  5922. </script>
  5923. ';
  5924. $return .= '<img align="left" alt="" src="../img/lp_forum.gif" style="margin-right:5px;" title="" />';
  5925. $return .= '<a style="cursor:hand" onclick="toggle_forum('.$forum['forum_id'].')" style="vertical-align:middle"><img src="'.api_get_path(WEB_IMG_PATH).'add.gif" id="forum_'.$forum['forum_id'].'_opener" align="absbottom" /></a>
  5926. <a href="' .api_get_self(). '?cidReq=' . $_GET['cidReq'] . '&amp;action=add_item&amp;type=' . TOOL_FORUM . '&amp;forum_id=' . $forum['forum_id'] . '&amp;lp_id=' . $this->lp_id . '" style="vertical-align:middle">' . $forum['forum_title'] . '</a><ul style="display:none" id="forum_'.$forum['forum_id'].'_content">';
  5927. $a_threads = get_threads($forum['forum_id']);
  5928. if(is_array($a_threads)){
  5929. foreach($a_threads as $thread)
  5930. {
  5931. $return .= '<li><a href="' .api_get_self(). '?cidReq=' . $_GET['cidReq'] . '&amp;action=add_item&amp;type=' . TOOL_THREAD . '&amp;thread_id=' . $thread['thread_id'] . '&amp;lp_id=' . $this->lp_id . '">' . $thread['thread_title'] . '</a></li>';
  5932. }
  5933. }
  5934. $return .= '</ul></div>';
  5935. }
  5936. $return .= '<div class="lp_resource_element">';
  5937. $return .= '<img align="left" alt="" src="../img/forum_new_small.gif" style="margin-right:5px;" title="" />';
  5938. $return .= '<a href="'.api_get_path(REL_CODE_PATH).'forum/index.php?'.api_get_cidreq().'&action=add&amp;content=forum" title="'.get_lang('CreateANewForum').'">'.get_lang('CreateANewForum').'</a>';
  5939. $return .= '</div>';
  5940. return $return;
  5941. }
  5942. /**
  5943. * Exports the learning path as a SCORM package. This is the main function that
  5944. * gathers the content, transforms it, writes the imsmanifest.xml file, zips the
  5945. * whole thing and returns the zip.
  5946. *
  5947. * This method needs to be called in PHP5, as it will fail with non-adequate
  5948. * XML package (like the ones for PHP4), and it is *not* a static method, so
  5949. * you need to call it on a learnpath object.
  5950. * @TODO The method might be redefined later on in the scorm class itself to avoid
  5951. * creating a SCORM structure if there is one already. However, if the initial SCORM
  5952. * path has been modified, it should use the generic method here below.
  5953. * @TODO link this function with the export_lp() function in the same class
  5954. * @param string Optional name of zip file. If none, title of learnpath is
  5955. * domesticated and trailed with ".zip"
  5956. * @return string Returns the zip package string, or null if error
  5957. */
  5958. function scorm_export()
  5959. {
  5960. global $_course;
  5961. if (!class_exists('DomDocument'))
  5962. {
  5963. error_log('DOM functions not supported for PHP version below 5.0',0);
  5964. $this->error = 'PHP DOM functions not supported for PHP versions below 5.0';
  5965. return null;
  5966. }
  5967. //remove memory and time limits as much as possible as this might be a long process...
  5968. if(function_exists('ini_set'))
  5969. {
  5970. $mem = ini_get('memory_limit');
  5971. if(substr($mem,-1,1)=='M')
  5972. {
  5973. $mem_num = substr($mem,0,-1);
  5974. if($mem_num<128)
  5975. {
  5976. ini_set('memory_limit','128M');
  5977. }
  5978. }
  5979. else
  5980. {
  5981. ini_set('memory_limit','128M');
  5982. }
  5983. ini_set('max_execution_time',600);
  5984. //}else{
  5985. //error_log('Scorm export: could not change memory and time limits',0);
  5986. }
  5987. //Create the zip handler (this will remain available throughout the method)
  5988. $garbage_path = api_get_path(GARBAGE_PATH);
  5989. $sys_course_path = api_get_path(SYS_COURSE_PATH);
  5990. $temp_dir_short = uniqid();
  5991. $temp_zip_dir = $garbage_path."/".$temp_dir_short;
  5992. $temp_zip_file = $temp_zip_dir."/".md5(time()).".zip";
  5993. $zip_folder=new PclZip($temp_zip_file);
  5994. $current_course_path = api_get_path(SYS_COURSE_PATH).api_get_course_path();
  5995. $root_path = $main_path = api_get_path(SYS_PATH);
  5996. $files_cleanup = array();
  5997. //place to temporarily stash the zipfiles
  5998. //create the temp dir if it doesn't exist
  5999. //or do a cleanup befor creating the zipfile
  6000. if(!is_dir($temp_zip_dir))
  6001. {
  6002. mkdir($temp_zip_dir);
  6003. }
  6004. else
  6005. {//cleanup: check the temp dir for old files and delete them
  6006. $handle=opendir($temp_zip_dir);
  6007. while (false!==($file = readdir($handle)))
  6008. {
  6009. if ($file != "." && $file != "..")
  6010. {
  6011. unlink("$temp_zip_dir/$file");
  6012. }
  6013. }
  6014. closedir($handle);
  6015. }
  6016. $zip_files = $zip_files_abs = $zip_files_dist = array();
  6017. if(is_dir($current_course_path.'/scorm/'.$this->path) && is_file($current_course_path.'/scorm/'.$this->path.'/imsmanifest.xml'))
  6018. {
  6019. // remove the possible . at the end of the path
  6020. $dest_path_to_lp = substr($this->path, -1) == '.' ? substr($this->path, 0, -1) : $this->path;
  6021. $dest_path_to_scorm_folder = str_replace('//','/',$temp_zip_dir.'/scorm/'.$dest_path_to_lp);
  6022. $perm = api_get_setting('permissions_for_new_directories');
  6023. $perm = octdec(!empty($perm)?$perm:'0770');
  6024. mkdir ($dest_path_to_scorm_folder, $perm, true);
  6025. $zip_files_dist = copyr($current_course_path.'/scorm/'.$this->path, $dest_path_to_scorm_folder, array('imsmanifest'), $zip_files);
  6026. }
  6027. //Build a dummy imsmanifest structure. Do not add to the zip yet (we still need it)
  6028. //This structure is developed following regulations for SCORM 1.2 packaging in the SCORM 1.2 Content
  6029. //Aggregation Model official document, secion "2.3 Content Packaging"
  6030. $xmldoc = new DOMDocument('1.0',$this->encoding);
  6031. $root = $xmldoc->createElement('manifest');
  6032. $root->setAttribute('identifier','SingleCourseManifest');
  6033. $root->setAttribute('version','1.1');
  6034. $root->setAttribute('xmlns','http://www.imsproject.org/xsd/imscp_rootv1p1p2');
  6035. $root->setAttribute('xmlns:adlcp','http://www.adlnet.org/xsd/adlcp_rootv1p2');
  6036. $root->setAttribute('xmlns:xsi','http://www.w3.org/2001/XMLSchema-instance');
  6037. $root->setAttribute('xsi:schemaLocation','http://www.imsproject.org/xsd/imscp_rootv1p1p2 imscp_rootv1p1p2.xsd
  6038. http://www.imsglobal.org/xsd/imsmd_rootv1p2p1 imsmd_rootv1p2p1.xsd
  6039. http://www.adlnet.org/xsd/adlcp_rootv1p2 adlcp_rootv1p2.xsd');
  6040. //Build mandatory sub-root container elements
  6041. $metadata = $xmldoc->createElement('metadata');
  6042. $md_schema = $xmldoc->createElement('schema','ADL SCORM');
  6043. $metadata->appendChild($md_schema);
  6044. $md_schemaversion = $xmldoc->createElement('schemaversion','1.2');
  6045. $metadata->appendChild($md_schemaversion);
  6046. $root->appendChild($metadata);
  6047. $organizations = $xmldoc->createElement('organizations');
  6048. $resources = $xmldoc->createElement('resources');
  6049. //Build the only organization we will use in building our learnpaths
  6050. $organizations->setAttribute('default','dokeos_scorm_export');
  6051. $organization = $xmldoc->createElement('organization');
  6052. $organization->setAttribute('identifier','dokeos_scorm_export');
  6053. //to set the title of the SCORM entity (=organization), we take the name given
  6054. //in Dokeos and convert it to HTML entities using the Dokeos charset (not the
  6055. //learning path charset) as it is the encoding that defines how it is stored
  6056. //in the database. Then we convert it to HTML entities again as the "&" character
  6057. //alone is not authorized in XML (must be &amp;)
  6058. //The title is then decoded twice when extracting (see scorm::parse_manifest)
  6059. global $charset;
  6060. $org_title = $xmldoc->createElement('title',htmlentities(htmlentities($this->get_name(),ENT_QUOTES,$charset)));
  6061. $organization->appendChild($org_title);
  6062. //For each element, add it to the imsmanifest structure, then add it to the zip.
  6063. //Always call the learnpathItem->scorm_export() method to change it to the SCORM
  6064. //format
  6065. $link_updates = array();
  6066. foreach($this->items as $index => $item){
  6067. if(!in_array($item->type , array(TOOL_QUIZ, TOOL_FORUM, TOOL_THREAD, TOOL_LINK, TOOL_STUDENTPUBLICATION)))
  6068. {
  6069. //get included documents from this item
  6070. if($item->type=='sco')
  6071. $inc_docs = $item->get_resources_from_source(null,api_get_path(SYS_COURSE_PATH).api_get_course_path().'/'.'scorm/'.$this->path.'/'.$item->get_path());
  6072. else
  6073. $inc_docs = $item->get_resources_from_source();
  6074. //give a child element <item> to the <organization> element
  6075. $my_item_id = $item->get_id();
  6076. $my_item = $xmldoc->createElement('item');
  6077. $my_item->setAttribute('identifier','ITEM_'.$my_item_id);
  6078. $my_item->setAttribute('identifierref','RESOURCE_'.$my_item_id);
  6079. $my_item->setAttribute('isvisible','true');
  6080. //give a child element <title> to the <item> element
  6081. $my_title = $xmldoc->createElement('title',htmlspecialchars($item->get_title(),ENT_QUOTES));
  6082. $my_item->appendChild($my_title);
  6083. //give a child element <adlcp:prerequisites> to the <item> element
  6084. $my_prereqs = $xmldoc->createElement('adlcp:prerequisites',$this->get_scorm_prereq_string($my_item_id));
  6085. $my_prereqs->setAttribute('type','aicc_script');
  6086. $my_item->appendChild($my_prereqs);
  6087. //give a child element <adlcp:maxtimeallowed> to the <item> element - not yet supported
  6088. //$xmldoc->createElement('adlcp:maxtimeallowed','');
  6089. //give a child element <adlcp:timelimitaction> to the <item> element - not yet supported
  6090. //$xmldoc->createElement('adlcp:timelimitaction','');
  6091. //give a child element <adlcp:datafromlms> to the <item> element - not yet supported
  6092. //$xmldoc->createElement('adlcp:datafromlms','');
  6093. //give a child element <adlcp:masteryscore> to the <item> element
  6094. $my_masteryscore = $xmldoc->createElement('adlcp:masteryscore',$item->masteryscore);
  6095. $my_item->appendChild($my_masteryscore);
  6096. //attach this item to the organization element or hits parent if there is one
  6097. if(!empty($item->parent) && $item->parent!=0)
  6098. {
  6099. $children = $organization->childNodes;
  6100. $possible_parent = &$this->get_scorm_xml_node($children,'ITEM_'.$item->parent);
  6101. if(is_object($possible_parent))
  6102. {
  6103. $possible_parent->appendChild($my_item);
  6104. }
  6105. else
  6106. {
  6107. if($this->debug>0){error_log('Parent ITEM_'.$item->parent.' of item ITEM_'.$my_item_id.' not found');}
  6108. }
  6109. }
  6110. else
  6111. {
  6112. if($this->debug>0){error_log('No parent');}
  6113. $organization->appendChild($my_item);
  6114. }
  6115. //get the path of the file(s) from the course directory root
  6116. $my_file_path = $item->get_file_path('scorm/'.$this->path.'/');
  6117. $my_xml_file_path = htmlentities($my_file_path);
  6118. $my_sub_dir = dirname($my_file_path);
  6119. $my_xml_sub_dir = htmlentities($my_sub_dir);
  6120. //give a <resource> child to the <resources> element
  6121. $my_resource = $xmldoc->createElement('resource');
  6122. $my_resource->setAttribute('identifier','RESOURCE_'.$item->get_id());
  6123. $my_resource->setAttribute('type','webcontent');
  6124. $my_resource->setAttribute('href',$my_xml_file_path);
  6125. //adlcp:scormtype can be either 'sco' or 'asset'
  6126. if($item->type=='sco')
  6127. {
  6128. $my_resource->setAttribute('adlcp:scormtype','sco');
  6129. }
  6130. else
  6131. {
  6132. $my_resource->setAttribute('adlcp:scormtype','asset');
  6133. }
  6134. //xml:base is the base directory to find the files declared in this resource
  6135. $my_resource->setAttribute('xml:base','');
  6136. //give a <file> child to the <resource> element
  6137. $my_file = $xmldoc->createElement('file');
  6138. $my_file->setAttribute('href',$my_xml_file_path);
  6139. $my_resource->appendChild($my_file);
  6140. //dependency to other files - not yet supported
  6141. $i = 1;
  6142. foreach($inc_docs as $doc_info)
  6143. {
  6144. if(count($doc_info)<1 or empty($doc_info[0])){continue;}
  6145. $my_dep = $xmldoc->createElement('resource');
  6146. $res_id = 'RESOURCE_'.$item->get_id().'_'.$i;
  6147. $my_dep->setAttribute('identifier',$res_id);
  6148. $my_dep->setAttribute('type','webcontent');
  6149. $my_dep->setAttribute('adlcp:scormtype','asset');
  6150. $my_dep_file = $xmldoc->createElement('file');
  6151. //check type of URL
  6152. //error_log('Now dealing with '.$doc_info[0].' of type '.$doc_info[1].'-'.$doc_info[2],0);
  6153. if($doc_info[1] == 'remote')
  6154. { //remote file. Save url as is
  6155. $my_dep_file->setAttribute('href',$doc_info[0]);
  6156. $my_dep->setAttribute('xml:base','');
  6157. }elseif($doc_info[1] == 'local'){
  6158. switch($doc_info[2])
  6159. {
  6160. case 'url': //local URL - save path as url for now, don't zip file
  6161. $abs_path = api_get_path(SYS_PATH).str_replace(api_get_path(WEB_PATH),'',$doc_info[0]);
  6162. $current_dir = dirname($abs_path);
  6163. $file_path = realpath($abs_path);
  6164. $my_dep_file->setAttribute('href',$file_path);
  6165. $my_dep->setAttribute('xml:base','');
  6166. if(strstr($file_path,$main_path) !== false)
  6167. {//the calculated real path is really inside the dokeos root path
  6168. //reduce file path to what's under the DocumentRoot
  6169. $file_path = substr($file_path,strlen($root_path));
  6170. //echo $file_path;echo '<br><br>';
  6171. //error_log('Reduced path: '.$file_path,0);
  6172. $zip_files_abs[] = $file_path;
  6173. $link_updates[$my_file_path][] = array('orig'=>$doc_info[0],'dest'=>$file_path);
  6174. $my_dep_file->setAttribute('href',$file_path);
  6175. $my_dep->setAttribute('xml:base','');
  6176. }
  6177. else if (empty($file_path))
  6178. {
  6179. /*$document_root = substr(api_get_path(SYS_PATH), 0, strpos(api_get_path(SYS_PATH),api_get_path(REL_PATH)));
  6180. if(strpos($document_root,-1)=='/')
  6181. {
  6182. $document_root = substr(0, -1, $document_root);
  6183. }*/
  6184. $file_path = $_SERVER['DOCUMENT_ROOT'].$abs_path;
  6185. $file_path = str_replace('//','/',$file_path);
  6186. if(file_exists($file_path))
  6187. {
  6188. $file_path = substr($file_path,strlen($current_dir)); // we get the relative path
  6189. $zip_files[] = $my_sub_dir.'/'.$file_path;
  6190. $link_updates[$my_file_path][] = array('orig'=>$doc_info[0],'dest'=>$file_path);
  6191. $my_dep_file->setAttribute('href',$file_path);
  6192. $my_dep->setAttribute('xml:base','');
  6193. }
  6194. }
  6195. break;
  6196. case 'abs': //absolute path from DocumentRoot. Save file and leave path as is in the zip
  6197. $my_dep_file->setAttribute('href',$doc_info[0]);
  6198. $my_dep->setAttribute('xml:base','');
  6199. //$current_dir = dirname($current_course_path.'/'.$item->get_file_path()).'/';
  6200. $file_path = realpath(api_get_path(SYS_PATH).$doc_info[0]);
  6201. $file_path = str_replace('//','/',$file_path);
  6202. //prepare the current directory path (until just under 'document') with a trailing slash
  6203. $cur_path = substr($current_course_path,-1)=='/'?$current_course_path:$current_course_path.'/';
  6204. //check if the current document is in that path
  6205. if(strstr($file_path,$cur_path) !== false)
  6206. {
  6207. //the document is in that path, now get the relative path
  6208. //to the containing document
  6209. $orig_file_path = dirname($cur_path.$my_file_path).'/';
  6210. $relative_path ='';
  6211. if(strstr($file_path,$cur_path)!==false)
  6212. {
  6213. $relative_path = substr($file_path,strlen($orig_file_path));
  6214. $file_path = substr($file_path,strlen($cur_path));
  6215. }
  6216. else
  6217. {
  6218. //this case is still a problem as it's difficult to calculate a relative path easily
  6219. //might still generate wrong links
  6220. //$file_path = substr($file_path,strlen($cur_path));
  6221. //calculate the directory path to the current file (without trailing slash)
  6222. $my_relative_path = dirname($file_path);
  6223. $my_relative_file = basename($file_path);
  6224. //calculate the directory path to the containing file (without trailing slash)
  6225. $my_orig_file_path = substr($orig_file_path,0,-1);
  6226. $dotdot = '';
  6227. $subdir = '';
  6228. while(strstr($my_relative_path,$my_orig_file_path)===false && (strlen($my_orig_file_path)>1) && (strlen($my_relative_path)>1))
  6229. {
  6230. $my_relative_path2 = dirname($my_relative_path);
  6231. $my_orig_file_path = dirname($my_orig_file_path);
  6232. $subdir = substr($my_relative_path,strlen($my_relative_path2)+1)."/".$subdir;
  6233. $dotdot += '../';
  6234. $my_relative_path = $my_relative_path2;
  6235. }
  6236. $relative_path = $dotdot.$subdir.$my_relative_file;
  6237. }
  6238. //put the current document in the zip (this array is the array
  6239. //that will manage documents already in the course folder - relative)
  6240. $zip_files[] = $file_path;
  6241. //update the links to the current document in the containing document (make them relative)
  6242. $link_updates[$my_file_path][] = array('orig'=>$doc_info[0],'dest'=>$relative_path);
  6243. $my_dep_file->setAttribute('href',$file_path);
  6244. $my_dep->setAttribute('xml:base','');
  6245. }
  6246. elseif(strstr($file_path,$main_path) !== false)
  6247. {//the calculated real path is really inside the dokeos root path
  6248. //reduce file path to what's under the DocumentRoot
  6249. $file_path = substr($file_path,strlen($root_path));
  6250. //echo $file_path;echo '<br><br>';
  6251. //error_log('Reduced path: '.$file_path,0);
  6252. $zip_files_abs[] = $file_path;
  6253. $link_updates[$my_file_path][] = array('orig'=>$doc_info[0],'dest'=>$file_path);
  6254. $my_dep_file->setAttribute('href','document/'.$file_path);
  6255. $my_dep->setAttribute('xml:base','');
  6256. }
  6257. else if (empty($file_path))
  6258. {
  6259. /*$document_root = substr(api_get_path(SYS_PATH), 0, strpos(api_get_path(SYS_PATH),api_get_path(REL_PATH)));
  6260. if(strpos($document_root,-1)=='/')
  6261. {
  6262. $document_root = substr(0, -1, $document_root);
  6263. }*/
  6264. $file_path = $_SERVER['DOCUMENT_ROOT'].$doc_info[0];
  6265. $file_path = str_replace('//','/',$file_path);
  6266. if(file_exists($file_path))
  6267. {
  6268. $file_path = substr($file_path,strlen($current_dir)); // we get the relative path
  6269. $zip_files[] = $my_sub_dir.'/'.$file_path;
  6270. $link_updates[$my_file_path][] = array('orig'=>$doc_info[0],'dest'=>$file_path);
  6271. $my_dep_file->setAttribute('href','document/'.$file_path);
  6272. $my_dep->setAttribute('xml:base','');
  6273. }
  6274. }
  6275. break;
  6276. case 'rel': //path relative to the current document. Save xml:base as current document's directory and save file in zip as subdir.file_path
  6277. if(substr($doc_info[0],0,2)=='..')
  6278. { //relative path going up
  6279. $current_dir = dirname($current_course_path.'/'.$item->get_file_path()).'/';
  6280. $file_path = realpath($current_dir.$doc_info[0]);
  6281. //error_log($file_path.' <-> '.$main_path,0);
  6282. if(strstr($file_path,$main_path) !== false)
  6283. {//the calculated real path is really inside the dokeos root path
  6284. //reduce file path to what's under the DocumentRoot
  6285. $file_path = substr($file_path,strlen($root_path));
  6286. //error_log('Reduced path: '.$file_path,0);
  6287. $zip_files_abs[] = $file_path;
  6288. $link_updates[$my_file_path][] = array('orig'=>$doc_info[0],'dest'=>$file_path);
  6289. $my_dep_file->setAttribute('href','document/'.$file_path);
  6290. $my_dep->setAttribute('xml:base','');
  6291. }
  6292. }else{
  6293. $zip_files[] = $my_sub_dir.'/'.$doc_info[0];
  6294. $my_dep_file->setAttribute('href',$doc_info[0]);
  6295. $my_dep->setAttribute('xml:base',$my_xml_sub_dir);
  6296. }
  6297. break;
  6298. default:
  6299. $my_dep_file->setAttribute('href',$doc_info[0]);
  6300. $my_dep->setAttribute('xml:base','');
  6301. break;
  6302. }
  6303. }
  6304. $my_dep->appendChild($my_dep_file);
  6305. $resources->appendChild($my_dep);
  6306. $dependency = $xmldoc->createElement('dependency');
  6307. $dependency->setAttribute('identifierref',$res_id);
  6308. $my_resource->appendChild($dependency);
  6309. $i++;
  6310. }
  6311. //$my_dependency = $xmldoc->createElement('dependency');
  6312. //$my_dependency->setAttribute('identifierref','');
  6313. $resources->appendChild($my_resource);
  6314. $zip_files[] = $my_file_path;
  6315. //error_log('File '.$my_file_path. ' added to $zip_files',0);
  6316. }
  6317. else
  6318. { // if the item is a quiz or a link or whatever non-exportable, we include a step indicating it
  6319. if($item->type == TOOL_LINK)
  6320. {
  6321. $my_item = $xmldoc->createElement('item');
  6322. $my_item->setAttribute('identifier','ITEM_'.$item->get_id());
  6323. $my_item->setAttribute('identifierref','RESOURCE_'.$item->get_id());
  6324. $my_item->setAttribute('isvisible','true');
  6325. //give a child element <title> to the <item> element
  6326. $my_title = $xmldoc->createElement('title',htmlspecialchars($item->get_title(),ENT_QUOTES));
  6327. $my_item->appendChild($my_title);
  6328. //give a child element <adlcp:prerequisites> to the <item> element
  6329. $my_prereqs = $xmldoc->createElement('adlcp:prerequisites',$item->get_prereq_string());
  6330. $my_prereqs->setAttribute('type','aicc_script');
  6331. $my_item->appendChild($my_prereqs);
  6332. //give a child element <adlcp:maxtimeallowed> to the <item> element - not yet supported
  6333. //$xmldoc->createElement('adlcp:maxtimeallowed','');
  6334. //give a child element <adlcp:timelimitaction> to the <item> element - not yet supported
  6335. //$xmldoc->createElement('adlcp:timelimitaction','');
  6336. //give a child element <adlcp:datafromlms> to the <item> element - not yet supported
  6337. //$xmldoc->createElement('adlcp:datafromlms','');
  6338. //give a child element <adlcp:masteryscore> to the <item> element
  6339. $my_masteryscore = $xmldoc->createElement('adlcp:masteryscore',$item->masteryscore);
  6340. $my_item->appendChild($my_masteryscore);
  6341. //attach this item to the organization element or its parent if there is one
  6342. if(!empty($item->parent) && $item->parent!=0)
  6343. {
  6344. $children = $organization->childNodes;
  6345. for($i=0;$i<$children->length;$i++){
  6346. $item_temp = $children->item($i);
  6347. if ($item_temp -> nodeName == 'item')
  6348. {
  6349. if($item_temp->getAttribute('identifier') == 'ITEM_'.$item->parent)
  6350. {
  6351. $item_temp -> appendChild($my_item);
  6352. }
  6353. }
  6354. }
  6355. }
  6356. else
  6357. {
  6358. $organization->appendChild($my_item);
  6359. }
  6360. $my_file_path = 'link_'.$item->get_id().'.html';
  6361. $sql = 'SELECT url, title FROM '.Database :: get_course_table(TABLE_LINK).' WHERE id='.$item->path;
  6362. $rs = api_sql_query($sql, __FILE__, __LINE__);
  6363. if($link = Database :: fetch_array($rs))
  6364. {
  6365. $url = $link['url'];
  6366. $title = stripslashes($link['title']);
  6367. $links_to_create[$my_file_path] = array('title'=>$title,'url'=>$url);
  6368. $my_xml_file_path = htmlentities($my_file_path);
  6369. $my_sub_dir = dirname($my_file_path);
  6370. $my_xml_sub_dir = htmlentities($my_sub_dir);
  6371. //give a <resource> child to the <resources> element
  6372. $my_resource = $xmldoc->createElement('resource');
  6373. $my_resource->setAttribute('identifier','RESOURCE_'.$item->get_id());
  6374. $my_resource->setAttribute('type','webcontent');
  6375. $my_resource->setAttribute('href',$my_xml_file_path);
  6376. //adlcp:scormtype can be either 'sco' or 'asset'
  6377. $my_resource->setAttribute('adlcp:scormtype','asset');
  6378. //xml:base is the base directory to find the files declared in this resource
  6379. $my_resource->setAttribute('xml:base','');
  6380. //give a <file> child to the <resource> element
  6381. $my_file = $xmldoc->createElement('file');
  6382. $my_file->setAttribute('href',$my_xml_file_path);
  6383. $my_resource->appendChild($my_file);
  6384. $resources->appendChild($my_resource);
  6385. }
  6386. }
  6387. elseif($item->type == TOOL_QUIZ)
  6388. {
  6389. require_once(api_get_path(SYS_CODE_PATH).'exercice/exercise.class.php');
  6390. $exe_id = $item->path; //should be using ref when everything will be cleaned up in this regard
  6391. $exe = new Exercise();
  6392. $exe->read($exe_id);
  6393. $my_item = $xmldoc->createElement('item');
  6394. $my_item->setAttribute('identifier','ITEM_'.$item->get_id());
  6395. $my_item->setAttribute('identifierref','RESOURCE_'.$item->get_id());
  6396. $my_item->setAttribute('isvisible','true');
  6397. //give a child element <title> to the <item> element
  6398. $my_title = $xmldoc->createElement('title',htmlspecialchars($item->get_title(),ENT_QUOTES));
  6399. $my_item->appendChild($my_title);
  6400. //give a child element <adlcp:prerequisites> to the <item> element
  6401. $my_prereqs = $xmldoc->createElement('adlcp:prerequisites',$item->get_prereq_string());
  6402. $my_prereqs->setAttribute('type','aicc_script');
  6403. $my_item->appendChild($my_prereqs);
  6404. //give a child element <adlcp:masteryscore> to the <item> element
  6405. $my_masteryscore = $xmldoc->createElement('adlcp:masteryscore',$item->masteryscore);
  6406. $my_item->appendChild($my_masteryscore);
  6407. //attach this item to the organization element or hits parent if there is one
  6408. if(!empty($item->parent) && $item->parent!=0)
  6409. {
  6410. $children = $organization->childNodes;
  6411. for($i=0;$i<$children->length;$i++){
  6412. $item_temp = $children->item($i);
  6413. if ($item_temp -> nodeName == 'item')
  6414. {
  6415. if($item_temp->getAttribute('identifier') == 'ITEM_'.$item->parent)
  6416. {
  6417. $item_temp -> appendChild($my_item);
  6418. }
  6419. }
  6420. }
  6421. }
  6422. else
  6423. {
  6424. $organization->appendChild($my_item);
  6425. }
  6426. //include export scripts
  6427. require_once(api_get_path(SYS_CODE_PATH).'exercice/export/scorm/scorm_export.php');
  6428. //get the path of the file(s) from the course directory root
  6429. //$my_file_path = $item->get_file_path('scorm/'.$this->path.'/');
  6430. $my_file_path = 'quiz_'.$item->get_id().'.html';
  6431. //write the contents of the exported exercise into a (big) html file
  6432. //to later pack it into the exported SCORM. The file will be removed afterwards
  6433. $contents = export_exercise($exe_id,true);
  6434. $tmp_file_path = $garbage_path.$temp_dir_short.'/'.$my_file_path;
  6435. $res = file_put_contents($tmp_file_path,$contents);
  6436. if($res === false){error_log('Could not write into file '.$tmp_file_path.' '.__FILE__.' '.__LINE__,0);}
  6437. $files_cleanup[] = $tmp_file_path;
  6438. //error_log($tmp_path);die();
  6439. $my_xml_file_path = htmlentities($my_file_path);
  6440. $my_sub_dir = dirname($my_file_path);
  6441. $my_xml_sub_dir = htmlentities($my_sub_dir);
  6442. //give a <resource> child to the <resources> element
  6443. $my_resource = $xmldoc->createElement('resource');
  6444. $my_resource->setAttribute('identifier','RESOURCE_'.$item->get_id());
  6445. $my_resource->setAttribute('type','webcontent');
  6446. $my_resource->setAttribute('href',$my_xml_file_path);
  6447. //adlcp:scormtype can be either 'sco' or 'asset'
  6448. $my_resource->setAttribute('adlcp:scormtype','sco');
  6449. //xml:base is the base directory to find the files declared in this resource
  6450. $my_resource->setAttribute('xml:base','');
  6451. //give a <file> child to the <resource> element
  6452. $my_file = $xmldoc->createElement('file');
  6453. $my_file->setAttribute('href',$my_xml_file_path);
  6454. $my_resource->appendChild($my_file);
  6455. //get included docs
  6456. $inc_docs = $item->get_resources_from_source(null,$tmp_file_path);
  6457. //dependency to other files - not yet supported
  6458. $i = 1;
  6459. foreach($inc_docs as $doc_info)
  6460. {
  6461. if(count($doc_info)<1 or empty($doc_info[0])){continue;}
  6462. $my_dep = $xmldoc->createElement('resource');
  6463. $res_id = 'RESOURCE_'.$item->get_id().'_'.$i;
  6464. $my_dep->setAttribute('identifier',$res_id);
  6465. $my_dep->setAttribute('type','webcontent');
  6466. $my_dep->setAttribute('adlcp:scormtype','asset');
  6467. $my_dep_file = $xmldoc->createElement('file');
  6468. //check type of URL
  6469. //error_log('Now dealing with '.$doc_info[0].' of type '.$doc_info[1].'-'.$doc_info[2],0);
  6470. if($doc_info[1] == 'remote')
  6471. { //remote file. Save url as is
  6472. $my_dep_file->setAttribute('href',$doc_info[0]);
  6473. $my_dep->setAttribute('xml:base','');
  6474. }elseif($doc_info[1] == 'local'){
  6475. switch($doc_info[2])
  6476. {
  6477. case 'url': //local URL - save path as url for now, don't zip file
  6478. //save file but as local file (retrieve from URL)
  6479. $abs_path = api_get_path(SYS_PATH).str_replace(api_get_path(WEB_PATH),'',$doc_info[0]);
  6480. $current_dir = dirname($abs_path);
  6481. $file_path = realpath($abs_path);
  6482. $my_dep_file->setAttribute('href','document/'.$file_path);
  6483. $my_dep->setAttribute('xml:base','');
  6484. if(strstr($file_path,$main_path) !== false)
  6485. {//the calculated real path is really inside the dokeos root path
  6486. //reduce file path to what's under the DocumentRoot
  6487. $file_path = substr($file_path,strlen($root_path));
  6488. //echo $file_path;echo '<br><br>';
  6489. //error_log('Reduced path: '.$file_path,0);
  6490. $zip_files_abs[] = $file_path;
  6491. $link_updates[$my_file_path][] = array('orig'=>$doc_info[0],'dest'=>'document/'.$file_path);
  6492. $my_dep_file->setAttribute('href','document/'.$file_path);
  6493. $my_dep->setAttribute('xml:base','');
  6494. }
  6495. else if (empty($file_path))
  6496. {
  6497. /*$document_root = substr(api_get_path(SYS_PATH), 0, strpos(api_get_path(SYS_PATH),api_get_path(REL_PATH)));
  6498. if(strpos($document_root,-1)=='/')
  6499. {
  6500. $document_root = substr(0, -1, $document_root);
  6501. }*/
  6502. $file_path = $_SERVER['DOCUMENT_ROOT'].$abs_path;
  6503. $file_path = str_replace('//','/',$file_path);
  6504. if(file_exists($file_path))
  6505. {
  6506. $file_path = substr($file_path,strlen($current_dir)); // we get the relative path
  6507. $zip_files[] = $my_sub_dir.'/'.$file_path;
  6508. $link_updates[$my_file_path][] = array('orig'=>$doc_info[0],'dest'=>'document/'.$file_path);
  6509. $my_dep_file->setAttribute('href','document/'.$file_path);
  6510. $my_dep->setAttribute('xml:base','');
  6511. }
  6512. }
  6513. break;
  6514. case 'abs': //absolute path from DocumentRoot. Save file and leave path as is in the zip
  6515. $current_dir = dirname($current_course_path.'/'.$item->get_file_path()).'/';
  6516. $file_path = realpath($doc_info[0]);
  6517. $my_dep_file->setAttribute('href',$file_path);
  6518. $my_dep->setAttribute('xml:base','');
  6519. if(strstr($file_path,$main_path) !== false)
  6520. {//the calculated real path is really inside the dokeos root path
  6521. //reduce file path to what's under the DocumentRoot
  6522. $file_path = substr($file_path,strlen($root_path));
  6523. //echo $file_path;echo '<br><br>';
  6524. //error_log('Reduced path: '.$file_path,0);
  6525. $zip_files_abs[] = $file_path;
  6526. $link_updates[$my_file_path][] = array('orig'=>$doc_info[0],'dest'=>$file_path);
  6527. $my_dep_file->setAttribute('href','document/'.$file_path);
  6528. $my_dep->setAttribute('xml:base','');
  6529. }
  6530. else if (empty($file_path))
  6531. {
  6532. /*$document_root = substr(api_get_path(SYS_PATH), 0, strpos(api_get_path(SYS_PATH),api_get_path(REL_PATH)));
  6533. if(strpos($document_root,-1)=='/')
  6534. {
  6535. $document_root = substr(0, -1, $document_root);
  6536. }*/
  6537. $file_path = $_SERVER['DOCUMENT_ROOT'].$doc_info[0];
  6538. $file_path = str_replace('//','/',$file_path);
  6539. if(file_exists($file_path))
  6540. {
  6541. $file_path = substr($file_path,strlen($current_dir)); // we get the relative path
  6542. $zip_files[] = $my_sub_dir.'/'.$file_path;
  6543. $link_updates[$my_file_path][] = array('orig'=>$doc_info[0],'dest'=>$file_path);
  6544. $my_dep_file->setAttribute('href','document/'.$file_path);
  6545. $my_dep->setAttribute('xml:base','');
  6546. }
  6547. }
  6548. break;
  6549. case 'rel': //path relative to the current document. Save xml:base as current document's directory and save file in zip as subdir.file_path
  6550. if(substr($doc_info[0],0,2)=='..')
  6551. { //relative path going up
  6552. $current_dir = dirname($current_course_path.'/'.$item->get_file_path()).'/';
  6553. $file_path = realpath($current_dir.$doc_info[0]);
  6554. //error_log($file_path.' <-> '.$main_path,0);
  6555. if(strstr($file_path,$main_path) !== false)
  6556. {//the calculated real path is really inside the dokeos root path
  6557. //reduce file path to what's under the DocumentRoot
  6558. $file_path = substr($file_path,strlen($root_path));
  6559. //error_log('Reduced path: '.$file_path,0);
  6560. $zip_files_abs[] = $file_path;
  6561. $link_updates[$my_file_path][] = array('orig'=>$doc_info[0],'dest'=>$file_path);
  6562. $my_dep_file->setAttribute('href','document/'.$file_path);
  6563. $my_dep->setAttribute('xml:base','');
  6564. }
  6565. }else{
  6566. $zip_files[] = $my_sub_dir.'/'.$doc_info[0];
  6567. $my_dep_file->setAttribute('href',$doc_info[0]);
  6568. $my_dep->setAttribute('xml:base',$my_xml_sub_dir);
  6569. }
  6570. break;
  6571. default:
  6572. $my_dep_file->setAttribute('href',$doc_info[0]);
  6573. $my_dep->setAttribute('xml:base','');
  6574. break;
  6575. }
  6576. }
  6577. $my_dep->appendChild($my_dep_file);
  6578. $resources->appendChild($my_dep);
  6579. $dependency = $xmldoc->createElement('dependency');
  6580. $dependency->setAttribute('identifierref',$res_id);
  6581. $my_resource->appendChild($dependency);
  6582. $i++;
  6583. }
  6584. $resources->appendChild($my_resource);
  6585. $zip_files[] = $my_file_path;
  6586. }
  6587. else
  6588. {
  6589. //get the path of the file(s) from the course directory root
  6590. $my_file_path = 'non_exportable.html';
  6591. $my_xml_file_path = htmlentities($my_file_path);
  6592. $my_sub_dir = dirname($my_file_path);
  6593. $my_xml_sub_dir = htmlentities($my_sub_dir);
  6594. //give a <resource> child to the <resources> element
  6595. $my_resource = $xmldoc->createElement('resource');
  6596. $my_resource->setAttribute('identifier','RESOURCE_'.$item->get_id());
  6597. $my_resource->setAttribute('type','webcontent');
  6598. $my_resource->setAttribute('href','document/'.$my_xml_file_path);
  6599. //adlcp:scormtype can be either 'sco' or 'asset'
  6600. $my_resource->setAttribute('adlcp:scormtype','asset');
  6601. //xml:base is the base directory to find the files declared in this resource
  6602. $my_resource->setAttribute('xml:base','');
  6603. //give a <file> child to the <resource> element
  6604. $my_file = $xmldoc->createElement('file');
  6605. $my_file->setAttribute('href','document/'.$my_xml_file_path);
  6606. $my_resource->appendChild($my_file);
  6607. $resources->appendChild($my_resource);
  6608. }
  6609. }
  6610. }
  6611. $organizations->appendChild($organization);
  6612. $root->appendChild($organizations);
  6613. $root->appendChild($resources);
  6614. $xmldoc->appendChild($root);
  6615. //todo: add a readme file here, with a short description and a link to the Reload player
  6616. //then add the file to the zip, then destroy the file (this is done automatically)
  6617. // http://www.reload.ac.uk/scormplayer.html - once done, don't forget to close FS#138
  6618. //error_log(print_r($zip_files,true),0);
  6619. foreach($zip_files as $file_path)
  6620. {
  6621. if(empty($file_path)){continue;}
  6622. //error_log('getting document from '.api_get_path('SYS_COURSE_PATH').$_course['path'].'/'.$file_path.' removing '.api_get_path('SYS_COURSE_PATH').$_course['path'].'/',0);
  6623. $dest_file = $garbage_path.$temp_dir_short.'/'.$file_path;
  6624. $this->create_path($dest_file);
  6625. //error_log('copy '.api_get_path('SYS_COURSE_PATH').$_course['path'].'/'.$file_path.' to '.api_get_path('GARBAGE_PATH').$temp_dir_short.'/'.$file_path,0);
  6626. //echo $main_path.$file_path.'<br>';
  6627. @copy($sys_course_path.$_course['path'].'/'.$file_path,$dest_file);
  6628. //check if the file needs a link update
  6629. if(in_array($file_path,array_keys($link_updates))){
  6630. $string = file_get_contents($dest_file);
  6631. unlink($dest_file);
  6632. foreach($link_updates[$file_path] as $old_new)
  6633. {
  6634. //error_log('Replacing '.$old_new['orig'].' by '.$old_new['dest'].' in '.$file_path,0);
  6635. $string = str_replace($old_new['orig'],$old_new['dest'],$string);
  6636. }
  6637. file_put_contents($dest_file,$string);
  6638. }
  6639. }
  6640. foreach($zip_files_abs as $file_path)
  6641. {
  6642. if(empty($file_path)){continue;}
  6643. //error_log('getting document from '.api_get_path('SYS_COURSE_PATH').$_course['path'].'/'.$file_path.' removing '.api_get_path('SYS_COURSE_PATH').$_course['path'].'/',0);
  6644. $dest_file = $garbage_path.$temp_dir_short.'/document/'.$file_path;
  6645. $this->create_path($dest_file);
  6646. //error_log('Created path '.api_get_path('GARBAGE_PATH').$temp_dir_short.'/document/'.$file_path,0);
  6647. //error_log('copy '.api_get_path('SYS_COURSE_PATH').$_course['path'].'/'.$file_path.' to '.api_get_path('GARBAGE_PATH').$temp_dir_short.'/'.$file_path,0);
  6648. //echo $main_path.$file_path.' - '.$dest_file.'<br>';
  6649. copy($main_path.$file_path,$dest_file);
  6650. //check if the file needs a link update
  6651. if(in_array($file_path,array_keys($link_updates))){
  6652. $string = file_get_contents($dest_file);
  6653. unlink($dest_file);
  6654. foreach($link_updates[$file_path] as $old_new)
  6655. {
  6656. //error_log('Replacing '.$old_new['orig'].' by '.$old_new['dest'].' in '.$file_path,0);
  6657. $string = str_replace($old_new['orig'],$old_new['dest'],$string);
  6658. }
  6659. file_put_contents($dest_file,$string);
  6660. }
  6661. }
  6662. if(is_array($links_to_create))
  6663. {
  6664. foreach($links_to_create as $file=>$link)
  6665. {
  6666. $file_content = '<html><body><div style="text-align:center"><a href="'.$link['url'].'">'.$link['title'].'</a></div></body></html>';
  6667. file_put_contents($garbage_path.$temp_dir_short.'/'.$file, $file_content);
  6668. }
  6669. }
  6670. // add non exportable message explanation
  6671. $lang_not_exportable = get_lang('ThisItemIsNotExportable');
  6672. $file_content =
  6673. <<<EOD
  6674. <html>
  6675. <head>
  6676. <style>
  6677. .error-message {
  6678. font-family: arial, verdana, helvetica, sans-serif;
  6679. border-width: 1px;
  6680. border-style: solid;
  6681. left: 50%;
  6682. margin: 10px auto;
  6683. min-height: 30px;
  6684. padding: 5px;
  6685. right: 50%;
  6686. width: 500px;
  6687. background-color: #FFD1D1;
  6688. border-color: #FF0000;
  6689. color: #000;
  6690. }
  6691. </style>
  6692. <body>
  6693. <div class="error-message">
  6694. $lang_not_exportable
  6695. </div>
  6696. </body>
  6697. </html>
  6698. EOD;
  6699. if(!is_dir($garbage_path.$temp_dir_short.'/document'))
  6700. {
  6701. @mkdir($garbage_path.$temp_dir_short.'/document');
  6702. }
  6703. file_put_contents($garbage_path.$temp_dir_short.'/document/non_exportable.html', $file_content);
  6704. //Add the extra files that go along with a SCORM package
  6705. $main_code_path = api_get_path(SYS_CODE_PATH).'newscorm/packaging/';
  6706. $extra_files = scandir($main_code_path);
  6707. foreach($extra_files as $extra_file)
  6708. {
  6709. if(strpos($extra_file,'.')===0) continue;
  6710. else
  6711. {
  6712. $dest_file = $garbage_path.$temp_dir_short.'/'.$extra_file;
  6713. $this->create_path($dest_file);
  6714. copy($main_code_path.$extra_file,$dest_file);
  6715. }
  6716. }
  6717. //Finalize the imsmanifest structure, add to the zip, then return the zip
  6718. $xmldoc->save($garbage_path.'/'.$temp_dir_short.'/imsmanifest.xml');
  6719. $zip_folder->add($garbage_path.'/'.$temp_dir_short, PCLZIP_OPT_REMOVE_PATH, $garbage_path.'/'.$temp_dir_short.'/');
  6720. //clean possible temporary files
  6721. foreach($files_cleanup as $file)
  6722. {
  6723. $res = unlink($file);
  6724. if($res === false){error_log('Could not delete temp file '.$file.' '.__FILE__.' '.__LINE__,0);}
  6725. }
  6726. //Send file to client
  6727. //$name = 'scorm_export_'.$this->lp_id.'.zip';
  6728. require_once(api_get_path(LIBRARY_PATH).'fileUpload.lib.php');
  6729. $name = preg_replace('([^a-zA-Z0-9_\.])','-',html_entity_decode($this->get_name(),ENT_QUOTES)).'.zip';
  6730. DocumentManager::file_send_for_download($temp_zip_file,true,$name);
  6731. }
  6732. /**
  6733. * Temp function to be moved in main_api or the best place around for this. Creates a file path
  6734. * if it doesn't exist
  6735. */
  6736. function create_path($path){
  6737. $path_bits = split('/',dirname($path));
  6738. $path_built = '/';
  6739. foreach($path_bits as $bit){
  6740. if(!empty($bit)){
  6741. $new_path = $path_built.$bit;
  6742. if(is_dir($new_path)){
  6743. $path_built = $new_path.'/';
  6744. }
  6745. else
  6746. {
  6747. mkdir($new_path);
  6748. $path_built = $new_path.'/';
  6749. }
  6750. }
  6751. }
  6752. }
  6753. }
  6754. ?>