learnpath.class.php 414 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * This (abstract?) class defines the parent attributes and methods for Chamilo learnpaths and scorm
  5. * learnpaths. It is used by the scorm class.
  6. *
  7. * @package chamilo.learnpath
  8. * @author Yannick Warnier <ywarnier@beeznest.org>
  9. * @author Julio Montoya <gugli100@gmail.com> Improvements
  10. * @license GNU/GPL
  11. */
  12. /**
  13. * Defines the learnpath parent class
  14. * @package chamilo.learnpath
  15. */
  16. class learnpath {
  17. public $attempt = 0; // The number for the current ID view.
  18. public $cc; // Course (code) this learnpath is located in. @todo change name for something more comprensible ...
  19. public $current; // Id of the current item the user is viewing.
  20. public $current_score; // The score of the current item.
  21. public $current_time_start; // The time the user loaded this resource (this does not mean he can see it yet).
  22. public $current_time_stop; // The time the user closed this resource.
  23. public $default_status = 'not attempted';
  24. public $encoding = 'UTF-8';
  25. public $error = '';
  26. public $extra_information = ''; // This string can be used by proprietary SCORM contents to store data about the current learnpath.
  27. public $force_commit = false; // For SCORM only - if set to true, will send a scorm LMSCommit() request on each LMSSetValue().
  28. public $index; // The index of the active learnpath_item in $ordered_items array.
  29. public $items = array();
  30. public $last; // item_id of last item viewed in the learning path.
  31. public $last_item_seen = 0; // In case we have already come in this learnpath, reuse the last item seen if authorized.
  32. public $license; // Which license this course has been given - not used yet on 20060522.
  33. public $lp_id; // DB ID for this learnpath.
  34. public $lp_view_id; // DB ID for lp_view
  35. public $log_file; // File where to log learnpath API msg.
  36. public $maker; // Which maker has conceived the content (ENI, Articulate, ...).
  37. public $message = '';
  38. public $mode = 'embedded'; // Holds the video display mode (fullscreen or embedded).
  39. public $name; // Learnpath name (they generally have one).
  40. public $ordered_items = array(); // List of the learnpath items in the order they are to be read.
  41. public $path = ''; // Path inside the scorm directory (if scorm).
  42. public $theme; // The current theme of the learning path.
  43. public $preview_image; // The current image of the learning path.
  44. // Tells if all the items of the learnpath can be tried again. Defaults to "no" (=1).
  45. public $prevent_reinit = 1;
  46. // Describes the mode of progress bar display.
  47. public $progress_bar_mode = '%';
  48. // Percentage progress as saved in the db.
  49. public $progress_db = '0';
  50. public $proximity; // Wether the content is distant or local or unknown.
  51. public $refs_list = array (); //list of items by ref => db_id. Used only for prerequisites match.
  52. // !!!This array (refs_list) is built differently depending on the nature of the LP.
  53. // If SCORM, uses ref, if Chamilo, uses id to keep a unique value.
  54. public $type; //type of learnpath. Could be 'dokeos', 'scorm', 'scorm2004', 'aicc', ...
  55. // TODO: Check if this type variable is useful here (instead of just in the controller script).
  56. public $user_id; //ID of the user that is viewing/using the course
  57. public $update_queue = array();
  58. public $scorm_debug = 0;
  59. public $arrMenu = array(); // Array for the menu items.
  60. public $debug = 0; // Logging level.
  61. public $lp_session_id =0;
  62. public $lp_view_session_id =0; // The specific view might be bound to a session.
  63. public $prerequisite = 0;
  64. public $use_max_score = 100; //Should work as usual
  65. public $created_on = '';
  66. public $modified_on = '';
  67. public $publicated_on = '';
  68. public $expired_on = '';
  69. /**
  70. * Class constructor. Needs a database handler, a course code and a learnpath id from the database.
  71. * Also builds the list of items into $this->items.
  72. * @param string Course code
  73. * @param integer Learnpath ID
  74. * @param integer User ID
  75. * @return boolean True on success, false on error
  76. */
  77. public function __construct($course, $lp_id, $user_id) {
  78. $this->encoding = api_get_system_encoding(); // Chamilo 1.8.8: We intend always to use the system encoding.
  79. // Check params.
  80. // Check course code.
  81. if ($this->debug > 0) {error_log('New LP - In learnpath::__construct('.$course.','.$lp_id.','.$user_id.')', 0); }
  82. if (empty($course)) {
  83. $this->error = 'Course code is empty';
  84. return false;
  85. } else {
  86. $main_table = Database::get_main_table(TABLE_MAIN_COURSE);
  87. //$course = Database::escape_string($course);
  88. $course = $this->escape_string($course);
  89. $sql = "SELECT * FROM $main_table WHERE code = '$course'";
  90. if ($this->debug > 2) { error_log('New LP - learnpath::__construct() '.__LINE__.' - Querying course: '.$sql, 0); }
  91. $res = Database::query($sql);
  92. if (Database::num_rows($res) > 0) {
  93. $this->cc = $course;
  94. } else {
  95. $this->error = 'Course code does not exist in database ('.$sql.')';
  96. return false;
  97. }
  98. }
  99. // Check learnpath ID.
  100. if (empty($lp_id)) {
  101. $this->error = 'Learnpath ID is empty';
  102. return false;
  103. } else {
  104. // TODO: Make it flexible to use any course_code (still using env course code here).
  105. $lp_table = Database::get_course_table(TABLE_LP_MAIN);
  106. //$id = Database::escape_integer($id);
  107. $lp_id = $this->escape_string($lp_id);
  108. $sql = "SELECT * FROM $lp_table WHERE id = '$lp_id'";
  109. if ($this->debug > 2) { error_log('New LP - learnpath::__construct() '.__LINE__.' - Querying lp: '.$sql, 0); }
  110. $res = Database::query($sql);
  111. if (Database::num_rows($res) > 0) {
  112. $this->lp_id = $lp_id;
  113. $row = Database::fetch_array($res);
  114. $this->type = $row['lp_type'];
  115. $this->name = stripslashes($row['name']);
  116. //$this->encoding = $row['default_encoding']; // Chamilo 1.8.8: We intend not to use 'default_encoding' field anymore.
  117. $this->proximity = $row['content_local'];
  118. $this->theme = $row['theme'];
  119. $this->maker = $row['content_maker'];
  120. $this->prevent_reinit = $row['prevent_reinit'];
  121. $this->license = $row['content_license'];
  122. $this->scorm_debug = $row['debug'];
  123. $this->js_lib = $row['js_lib'];
  124. $this->path = $row['path'];
  125. $this->preview_image = $row['preview_image'];
  126. $this->author = $row['author'];
  127. $this->lp_session_id = $row['session_id'];
  128. $this->created_on = $row['created_on'];
  129. $this->modified_on = $row['modified_on'];
  130. if ($row['publicated_on'] != '0000-00-00 00:00:00') {
  131. $this->publicated_on = api_get_local_time($row['publicated_on']);
  132. }
  133. if ($row['expired_on'] != '0000-00-00 00:00:00') {
  134. $this->expired_on = api_get_local_time($row['expired_on']);
  135. }
  136. if ($this->type == 2) {
  137. if ($row['force_commit'] == 1) {
  138. $this->force_commit = true;
  139. }
  140. }
  141. $this->mode = $row['default_view_mod'];
  142. } else {
  143. $this->error = 'Learnpath ID does not exist in database ('.$sql.')';
  144. return false;
  145. }
  146. }
  147. // Check user ID.
  148. if (empty($user_id)) {
  149. $this->error = 'User ID is empty';
  150. return false;
  151. } else {
  152. //$main_table = Database::get_main_user_table();
  153. $main_table = Database::get_main_table(TABLE_MAIN_USER);
  154. //$user_id = Database::escape_integer($user_id);
  155. $user_id = $this->escape_string($user_id);
  156. $sql = "SELECT * FROM $main_table WHERE user_id = '$user_id'";
  157. if ($this->debug > 2) { error_log('New LP - learnpath::__construct() '.__LINE__.' - Querying user: '.$sql, 0); }
  158. $res = Database::query($sql);
  159. if (Database::num_rows($res) > 0) {
  160. $this->user_id = $user_id;
  161. } else {
  162. $this->error = 'User ID does not exist in database ('.$sql.')';
  163. return false;
  164. }
  165. }
  166. // End of variables checking.
  167. $session_id = api_get_session_id();
  168. // Get the session condition for learning paths of the base + session.
  169. $session = api_get_session_condition($session_id);
  170. // Now get the latest attempt from this user on this LP, if available, otherwise create a new one.
  171. $lp_table = Database::get_course_table(TABLE_LP_VIEW);
  172. // Selecting by view_count descending allows to get the highest view_count first.
  173. $sql = "SELECT * FROM $lp_table WHERE lp_id = '$lp_id' AND user_id = '$user_id' $session ORDER BY view_count DESC";
  174. if ($this->debug > 2) { error_log('New LP - learnpath::__construct() ' . __LINE__ . ' - querying lp_view: ' . $sql, 0); }
  175. $res = Database::query($sql);
  176. $view_id = 0; // Used later to query lp_item_view.
  177. if (Database :: num_rows($res) > 0) {
  178. if ($this->debug > 2) {
  179. error_log('New LP - learnpath::__construct() ' . __LINE__ . ' - Found previous view', 0);
  180. }
  181. $row = Database :: fetch_array($res);
  182. $this->attempt = $row['view_count'];
  183. $this->lp_view_id = $row['id'];
  184. $this->last_item_seen = $row['last_item'];
  185. $this->progress_db = $row['progress'];
  186. $this->lp_view_session_id = $row['session_id'];
  187. } else {
  188. if ($this->debug > 2) {
  189. error_log('New LP - learnpath::__construct() ' . __LINE__ . ' - NOT Found previous view', 0);
  190. }
  191. $this->attempt = 1;
  192. $sql_ins = "INSERT INTO $lp_table (lp_id,user_id,view_count, session_id) VALUES ($lp_id,$user_id,1,$session_id)";
  193. $res_ins = Database::query($sql_ins);
  194. $this->lp_view_id = Database :: insert_id();
  195. if ($this->debug > 2) {
  196. error_log('New LP - learnpath::__construct() ' . __LINE__ . ' - inserting new lp_view: ' . $sql_ins, 0);
  197. }
  198. }
  199. // Initialise items.
  200. $lp_item_table = Database::get_course_table(TABLE_LP_ITEM);
  201. $sql = "SELECT * FROM $lp_item_table WHERE lp_id = '".$this->lp_id."' ORDER BY parent_item_id, display_order";
  202. $res = Database::query($sql);
  203. while ($row = Database::fetch_array($res)) {
  204. $oItem = '';
  205. //$this->ordered_items[] = $row['id'];
  206. switch ($this->type) {
  207. case 3: //aicc
  208. $oItem = new aiccItem('db', $row['id']);
  209. if (is_object($oItem)) {
  210. $my_item_id = $oItem->get_id();
  211. $oItem->set_lp_view($this->lp_view_id);
  212. $oItem->set_prevent_reinit($this->prevent_reinit);
  213. // Don't use reference here as the next loop will make the pointed object change.
  214. $this->items[$my_item_id] = $oItem;
  215. $this->refs_list[$oItem->ref] = $my_item_id;
  216. if ($this->debug > 2) {
  217. error_log('New LP - learnpath::__construct() - aicc object with id ' . $my_item_id . ' set in items[]', 0);
  218. }
  219. }
  220. break;
  221. case 2:
  222. require_once 'scorm.class.php';
  223. require_once 'scormItem.class.php';
  224. $oItem = new scormItem('db', $row['id']);
  225. if (is_object($oItem)) {
  226. $my_item_id = $oItem->get_id();
  227. $oItem->set_lp_view($this->lp_view_id);
  228. $oItem->set_prevent_reinit($this->prevent_reinit);
  229. // Don't use reference here as the next loop will make the pointed object change.
  230. $this->items[$my_item_id] = $oItem;
  231. $this->refs_list[$oItem->ref] = $my_item_id;
  232. if ($this->debug > 2) {
  233. error_log('New LP - object with id ' . $my_item_id . ' set in items[]', 0);
  234. }
  235. }
  236. break;
  237. case 1:
  238. default:
  239. require_once 'learnpathItem.class.php';
  240. $oItem = new learnpathItem($row['id'], $user_id);
  241. if (is_object($oItem)) {
  242. $my_item_id = $oItem->get_id();
  243. //$oItem->set_lp_view($this->lp_view_id); // Moved down to when we are sure the item_view exists.
  244. $oItem->set_prevent_reinit($this->prevent_reinit);
  245. // Don't use reference here as the next loop will make the pointed object change.
  246. $this->items[$my_item_id] = $oItem;
  247. $this->refs_list[$my_item_id] = $my_item_id;
  248. if ($this->debug > 2) {
  249. error_log('New LP - learnpath::__construct() ' . __LINE__ . ' - object with id ' . $my_item_id . ' set in items[]', 0);
  250. }
  251. }
  252. break;
  253. }
  254. // Items is a list of pointers to all items, classified by DB ID, not SCO id.
  255. if ($row['parent_item_id'] == 0 || empty ($this->items[$row['parent_item_id']])) {
  256. $this->items[$row['id']]->set_level(0);
  257. } else {
  258. $level = $this->items[$row['parent_item_id']]->get_level() + 1;
  259. $this->items[$row['id']]->set_level($level);
  260. if (is_object($this->items[$row['parent_item_id']])) {
  261. // Items is a list of pointers from item DB ids to item objects.
  262. $this->items[$row['parent_item_id']]->add_child($row['id']);
  263. } else {
  264. if ($this->debug > 2) {
  265. error_log('New LP - learnpath::__construct() ' . __LINE__ . ' - The parent item (' . $row['parent_item_id'] . ') of item ' . $row['id'] . ' could not be found', 0);
  266. }
  267. }
  268. }
  269. // Get last viewing vars.
  270. $lp_item_view_table = Database :: get_course_table(TABLE_LP_ITEM_VIEW);
  271. // This query should only return one or zero result.
  272. $sql = "SELECT * " .
  273. "FROM $lp_item_view_table " .
  274. "WHERE lp_view_id = " . $this->lp_view_id . " " .
  275. "AND lp_item_id = " . $row['id'] . " ORDER BY view_count DESC ";
  276. if ($this->debug > 2) {
  277. error_log('New LP - learnpath::__construct() - Selecting item_views: ' . $sql, 0);
  278. }
  279. // Get the item status.
  280. $res2 = Database::query($sql);
  281. if (Database :: num_rows($res2) > 0) {
  282. // If this learnpath has already been used by this user, get his last attempt count and
  283. // the last item seen back into this object.
  284. //$max = 0;
  285. $row2 = Database :: fetch_array($res2);
  286. if ($this->debug > 2) {
  287. error_log('New LP - learnpath::__construct() - Got item_view: ' . print_r($row2, true), 0);
  288. }
  289. $this->items[$row['id']]->set_status($row2['status']);
  290. if (empty ($row2['status'])) {
  291. $this->items[$row['id']]->set_status($this->default_status);
  292. }
  293. //$this->attempt = $row['view_count'];
  294. //$this->last_item = $row['id'];
  295. } else { // No item has been found in lp_item_view for this view.
  296. // The first attempt of this user. Set attempt to 1 and last_item to 0 (first item available).
  297. // TODO: If the learnpath has not got attempts activated, always use attempt '1'.
  298. //$this->attempt = 1;
  299. //$this->last_item = 0;
  300. $this->items[$row['id']]->set_status($this->default_status);
  301. // Add that row to the lp_item_view table so that we have something to show in the stats page.
  302. $sql_ins = "INSERT INTO $lp_item_view_table " .
  303. "(lp_item_id, lp_view_id, view_count, status) VALUES " .
  304. "(" . $row['id'] . "," . $this->lp_view_id . ",1,'not attempted')";
  305. if ($this->debug > 2) {
  306. error_log('New LP - learnpath::__construct() ' . __LINE__ . ' - Inserting blank item_view : ' . $sql_ins, 0);
  307. }
  308. $res_ins = Database::query($sql_ins);
  309. }
  310. // Setting the view in the item object.
  311. $this->items[$row['id']]->set_lp_view($this->lp_view_id);
  312. }
  313. $this->ordered_items = $this->get_flat_ordered_items_list($this->get_id(), 0);
  314. $this->max_ordered_items = 0;
  315. foreach ($this->ordered_items as $index => $dummy) {
  316. if ($index > $this->max_ordered_items && !empty($dummy)) {
  317. $this->max_ordered_items = $index;
  318. }
  319. }
  320. // TODO: Define the current item better.
  321. $this->first();
  322. if ($this->debug > 2) {
  323. error_log('New LP - learnpath::__construct() ' . __LINE__ . ' - End of learnpath constructor for learnpath ' . $this->get_id(), 0);
  324. }
  325. }
  326. /**
  327. * 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
  328. * I found it better to rewrite it. Old function is still available. Added also the possibility to add a description.
  329. *
  330. * @param int $parent
  331. * @param int $previous
  332. * @param string $type
  333. * @param int resource ID (ref)
  334. * @param string $title
  335. * @param string $description
  336. * @return int
  337. */
  338. public function add_item($parent, $previous, $type = 'dokeos_chapter', $id, $title, $description, $prerequisites = 0, $max_time_allowed = 0) {
  339. if ($this->debug > 0) {
  340. error_log('New LP - In learnpath::add_item(' . $parent . ',' . $previous . ',' . $type . ',' . $id . ',' . $title . ')', 0);
  341. }
  342. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  343. $parent = intval($parent);
  344. $previous = intval($previous);
  345. $type = $this->escape_string($type);
  346. $id = intval($id);
  347. $max_time_allowed = $this->escape_string(htmlentities($max_time_allowed));
  348. if (empty ($max_time_allowed)) {
  349. $max_time_allowed = 0;
  350. }
  351. $title = $this->escape_string($title);
  352. $description = $this->escape_string($description);
  353. $sql_count = " SELECT COUNT(id) AS num
  354. FROM " . $tbl_lp_item . "
  355. WHERE lp_id = " . $this->get_id() . " AND parent_item_id = " . $parent;
  356. $res_count = Database::query($sql_count);
  357. $row = Database :: fetch_array($res_count);
  358. $num = $row['num'];
  359. if ($num > 0) {
  360. if ($previous == 0) {
  361. $sql = "SELECT id, next_item_id, display_order
  362. FROM " . $tbl_lp_item . "
  363. WHERE
  364. lp_id = " . $this->get_id() . " AND
  365. parent_item_id = " . $parent . " AND
  366. previous_item_id = 0 OR previous_item_id=" . $parent;
  367. $result = Database::query($sql);
  368. $row = Database :: fetch_array($result);
  369. $tmp_previous = 0;
  370. $next = $row['id'];
  371. $display_order = 0;
  372. } else {
  373. $previous = (int) $previous;
  374. $sql = "
  375. SELECT
  376. id,
  377. previous_item_id,
  378. next_item_id,
  379. display_order
  380. FROM " . $tbl_lp_item . "
  381. WHERE
  382. lp_id = " . $this->get_id() . " AND
  383. id = " . $previous;
  384. $result = Database::query($sql);
  385. $row = Database :: fetch_array($result);
  386. $tmp_previous = $row['id'];
  387. $next = $row['next_item_id'];
  388. $display_order = $row['display_order'];
  389. }
  390. } else {
  391. $tmp_previous = 0;
  392. $next = 0;
  393. $display_order = 0;
  394. }
  395. $new_item_id = -1;
  396. $id = $this->escape_string($id);
  397. if ($type == 'quiz') {
  398. $sql = 'SELECT SUM(ponderation)
  399. FROM ' . Database :: get_course_table(TABLE_QUIZ_QUESTION) . ' as quiz_question
  400. INNER JOIN ' . Database :: get_course_table(TABLE_QUIZ_TEST_QUESTION) . ' as quiz_rel_question
  401. ON quiz_question.id = quiz_rel_question.question_id
  402. AND quiz_rel_question.exercice_id = ' . $id;
  403. $rsQuiz = Database::query($sql);
  404. $max_score = Database :: result($rsQuiz, 0, 0);
  405. } else {
  406. $max_score = 100;
  407. }
  408. if ($prerequisites != 0) {
  409. $sql_ins = "
  410. INSERT INTO " . $tbl_lp_item . " ( ".
  411. "lp_id, ".
  412. "item_type, ".
  413. "ref, ".
  414. "title, ".
  415. "description, ".
  416. "path, ".
  417. "max_score, ".
  418. "parent_item_id, ".
  419. "previous_item_id, ".
  420. "next_item_id, ".
  421. "display_order, ".
  422. "prerequisite, ".
  423. "max_time_allowed ".
  424. ") VALUES ( ".
  425. $this->get_id() . ", ".
  426. "'" . $type . "', ".
  427. "'', ".
  428. "'" . $title . "', ".
  429. "'" . $description . "', ".
  430. "'" . $id . "', ".
  431. "'" . $max_score . "', ".
  432. $parent . ", ".
  433. $previous . ", ".
  434. $next . ", ".
  435. ($display_order +1) . ", ".
  436. $prerequisites . ", ".
  437. $max_time_allowed .
  438. ")";
  439. } else {
  440. // Insert new item.
  441. $sql_ins = "
  442. INSERT INTO " . $tbl_lp_item . " ( ".
  443. "lp_id, ".
  444. "item_type, ".
  445. "ref, ".
  446. "title, ".
  447. "description, ".
  448. "path, ".
  449. "max_score, ".
  450. "parent_item_id, ".
  451. "previous_item_id, ".
  452. "next_item_id, ".
  453. "display_order, ".
  454. "max_time_allowed ".
  455. ") VALUES (".
  456. $this->get_id() . ",".
  457. "'" . $type . "',".
  458. "'',".
  459. "'" . $title . "',".
  460. "'" . $description . "',".
  461. "'" . $id . "',".
  462. "'" . $max_score . "',".
  463. $parent . ",".
  464. $previous . ",".
  465. $next . ",".
  466. ($display_order +1) . ",".
  467. $max_time_allowed .
  468. ")";
  469. }
  470. if ($this->debug > 2) {
  471. error_log('New LP - Inserting dokeos_chapter: ' . $sql_ins, 0);
  472. }
  473. $res_ins = Database::query($sql_ins);
  474. if ($res_ins > 0) {
  475. $new_item_id = Database :: insert_id($res_ins);
  476. // Update the item that should come after the new item.
  477. $sql_update_next = "
  478. UPDATE " . $tbl_lp_item . "
  479. SET previous_item_id = " . $new_item_id . "
  480. WHERE id = " . $next;
  481. $res_update_next = Database::query($sql_update_next);
  482. // Update the item that should be before the new item.
  483. $sql_update_previous = "
  484. UPDATE " . $tbl_lp_item . "
  485. SET next_item_id = " . $new_item_id . "
  486. WHERE id = " . $tmp_previous;
  487. $res_update_previous = Database::query($sql_update_previous);
  488. // Update all the items after the new item.
  489. $sql_update_order = "
  490. UPDATE " . $tbl_lp_item . "
  491. SET display_order = display_order + 1
  492. WHERE
  493. lp_id = " . $this->get_id() . " AND
  494. id <> " . $new_item_id . " AND
  495. parent_item_id = " . $parent . " AND
  496. display_order > " . $display_order;
  497. $res_update_previous = Database::query($sql_update_order);
  498. // Update the item that should come after the new item.
  499. $sql_update_ref = "
  500. UPDATE " . $tbl_lp_item . "
  501. SET ref = " . $new_item_id . "
  502. WHERE id = " . $new_item_id;
  503. Database::query($sql_update_ref);
  504. }
  505. // Upload audio.
  506. if (!empty ($_FILES['mp3']['name'])) {
  507. // Create the audio folder if it does not exist yet.
  508. global $_course;
  509. $filepath = api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document/';
  510. if (!is_dir($filepath . 'audio')) {
  511. mkdir($filepath . 'audio', api_get_permissions_for_new_directories());
  512. $audio_id = add_document($_course, '/audio', 'folder', 0, 'audio');
  513. api_item_property_update($_course, TOOL_DOCUMENT, $audio_id, 'FolderCreated', api_get_user_id(), null, null, null, null, api_get_session_id());
  514. }
  515. // Upload the file in the documents tool.
  516. include_once api_get_path(LIBRARY_PATH).'fileUpload.lib.php';
  517. $file_path = handle_uploaded_document($_course, $_FILES['mp3'], api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document', '/audio', api_get_user_id(), '', '', '', '', '', false);
  518. // Getting the filename only.
  519. $file_components = explode('/', $file_path);
  520. $file = $file_components[count($file_components) - 1];
  521. // Store the mp3 file in the lp_item table.
  522. $sql_insert_audio = "UPDATE $tbl_lp_item SET audio = '" . Database :: escape_string($file) . "' WHERE id = '" . Database :: escape_string($new_item_id) . "'";
  523. Database::query($sql_insert_audio);
  524. }
  525. return $new_item_id;
  526. }
  527. /**
  528. * Static admin function allowing addition of a learnpath to a course.
  529. * @param string Course code
  530. * @param string Learnpath name
  531. * @param string Learnpath description string, if provided
  532. * @param string Type of learnpath (default = 'guess', others = 'dokeos', 'aicc',...)
  533. * @param string Type of files origin (default = 'zip', others = 'dir','web_dir',...)
  534. * @param string Zip file containing the learnpath or directory containing the learnpath
  535. * @return integer The new learnpath ID on success, 0 on failure
  536. */
  537. public function add_lp($course, $name, $description = '', $learnpath = 'guess', $origin = 'zip', $zipname = '', $publicated_on = '', $expired_on = '') {
  538. global $charset;
  539. //if ($this->debug > 0) { error_log('New LP - In learnpath::add_lp()', 0); }
  540. $tbl_lp = Database :: get_course_table(TABLE_LP_MAIN);
  541. // Check course code exists.
  542. // Check lp_name doesn't exist, otherwise append something.
  543. $i = 0;
  544. $name = learnpath :: escape_string($name);
  545. // Session id.
  546. $session_id = api_get_session_id();
  547. $check_name = "SELECT * FROM $tbl_lp WHERE name = '$name'";
  548. //if ($this->debug > 2) { error_log('New LP - Checking the name for new LP: '.$check_name, 0); }
  549. $res_name = Database::query($check_name);
  550. if ($publicated_on == '0000-00-00 00:00:00' || empty($publicated_on)) {
  551. //by default the publication date is the same that the creation date
  552. $publicated_on = api_get_utc_datetime();
  553. } else {
  554. $publicated_on = Database::escape_string(api_get_utc_datetime($publicated_on));
  555. }
  556. if ($expired_on == '0000-00-00 00:00:00' || empty($expired_on)) {
  557. $expired_on = '';
  558. } else {
  559. $expired_on = Database::escape_string(api_get_utc_datetime($expired_on));
  560. }
  561. while (Database :: num_rows($res_name)) {
  562. // There is already one such name, update the current one a bit.
  563. $i++;
  564. $name = $name . ' - ' . $i;
  565. $check_name = "SELECT * FROM $tbl_lp WHERE name = '$name'";
  566. //if ($this->debug > 2) { error_log('New LP - Checking the name for new LP: '.$check_name, 0); }
  567. $res_name = Database::query($check_name);
  568. }
  569. // New name does not exist yet; keep it.
  570. // Escape description.
  571. $description = learnpath :: escape_string(api_htmlentities($description, ENT_QUOTES, $charset)); // Kevin: added htmlentities().
  572. $type = 1;
  573. switch ($learnpath) {
  574. case 'guess':
  575. break;
  576. case 'chamilo':
  577. $type = 1;
  578. break;
  579. case 'aicc':
  580. break;
  581. }
  582. switch ($origin) {
  583. case 'zip':
  584. // Check zipname string. If empty, we are currently creating a new Chamilo learnpath.
  585. break;
  586. case 'manual':
  587. default:
  588. $get_max = "SELECT MAX(display_order) FROM $tbl_lp";
  589. $res_max = Database::query($get_max);
  590. if (Database :: num_rows($res_max) < 1) {
  591. $dsp = 1;
  592. } else {
  593. $row = Database :: fetch_array($res_max);
  594. $dsp = $row[0] + 1;
  595. }
  596. $sql_insert = "INSERT INTO $tbl_lp (lp_type,name,description,path,default_view_mod, default_encoding,display_order,content_maker,content_local,js_lib,session_id, created_on, publicated_on, expired_on) " .
  597. "VALUES ($type,'$name','$description','','embedded','UTF-8','$dsp','Chamilo','local','','".$session_id."', '".api_get_utc_datetime()."' , '".$publicated_on."' , '".$expired_on."')";
  598. //if ($this->debug > 2) { error_log('New LP - Inserting new lp '.$sql_insert, 0); }
  599. $res_insert = Database::query($sql_insert);
  600. $id = Database :: insert_id();
  601. if ($id > 0) {
  602. // Insert into item_property.
  603. api_item_property_update(api_get_course_info(), TOOL_LEARNPATH, $id, 'LearnpathAdded', api_get_user_id());
  604. return $id;
  605. }
  606. break;
  607. }
  608. }
  609. /**
  610. * Appends a message to the message attribute
  611. * @param string Message to append.
  612. */
  613. public function append_message($string) {
  614. if ($this->debug > 0) {
  615. error_log('New LP - In learnpath::append_message()', 0);
  616. }
  617. $this->message .= $string;
  618. }
  619. /**
  620. * Autocompletes the parents of an item in case it's been completed or passed
  621. * @param integer Optional ID of the item from which to look for parents
  622. */
  623. public function autocomplete_parents($item) {
  624. if ($this->debug > 0) {
  625. error_log('New LP - In learnpath::autocomplete_parents()', 0);
  626. }
  627. if (empty ($item)) {
  628. $item = $this->current;
  629. }
  630. $parent_id = $this->items[$item]->get_parent();
  631. if ($this->debug > 2) {
  632. error_log('New LP - autocompleting parent of item ' . $item . ' (item ' . $parent_id . ')', 0);
  633. }
  634. if (is_object($this->items[$item]) and !empty ($parent_id)) {
  635. // if $item points to an object and there is a parent.
  636. if ($this->debug > 2) {
  637. error_log('New LP - ' . $item . ' is an item, proceed', 0);
  638. }
  639. $current_item = & $this->items[$item];
  640. $parent = & $this->items[$parent_id]; // Get the parent.
  641. // New experiment including failed and browsed in completed status.
  642. $current_status = $current_item->get_status();
  643. if ($current_item->is_done() || $current_status == 'browsed' || $current_status == 'failed') {
  644. // If the current item is completed or passes or succeeded.
  645. $completed = true;
  646. if ($this->debug > 2) {
  647. error_log('New LP - Status of current item is alright', 0);
  648. }
  649. foreach ($parent->get_children() as $child) {
  650. // Check all his brothers (his parent's children) for completion status.
  651. if ($child != $item) {
  652. if ($this->debug > 2) {
  653. error_log('New LP - Looking at brother with ID ' . $child . ', status is ' . $this->items[$child]->get_status(), 0);
  654. }
  655. //if($this->items[$child]->status_is(array('completed','passed','succeeded')))
  656. // Trying completing parents of failed and browsed items as well.
  657. if ($this->items[$child]->status_is(array (
  658. 'completed',
  659. 'passed',
  660. 'succeeded',
  661. 'browsed',
  662. 'failed'
  663. ))) {
  664. // Keep completion status to true.
  665. } else {
  666. if ($this->debug > 2) {
  667. error_log('New LP - Found one incomplete child of ' . $parent_id . ': ' . $child . ' is ' . $this->items[$child]->get_status(), 0);
  668. }
  669. $completed = false;
  670. }
  671. }
  672. }
  673. if ($completed) { // If all the children were completed:
  674. $parent->set_status('completed');
  675. $parent->save(false, $this->prerequisites_match($parent->get_id()));
  676. $this->update_queue[$parent->get_id()] = $parent->get_status();
  677. if ($this->debug > 2) {
  678. error_log('New LP - Added parent to update queue ' . print_r($this->update_queue, true), 0);
  679. }
  680. $this->autocomplete_parents($parent->get_id()); // Recursive call.
  681. }
  682. } else {
  683. //error_log('New LP - status of current item is not enough to get bothered with it', 0);
  684. }
  685. }
  686. }
  687. /**
  688. * Autosaves the current results into the database for the whole learnpath
  689. */
  690. public function autosave() {
  691. if ($this->debug > 0) {
  692. error_log('New LP - In learnpath::autosave()', 0);
  693. }
  694. // TODO: Add save operations for the learnpath itself.
  695. }
  696. /**
  697. * Clears the message attribute
  698. */
  699. public function clear_message() {
  700. if ($this->debug > 0) {
  701. error_log('New LP - In learnpath::clear_message()', 0);
  702. }
  703. $this->message = '';
  704. }
  705. /**
  706. * Closes the current resource
  707. *
  708. * Stops the timer
  709. * Saves into the database if required
  710. * Clears the current resource data from this object
  711. * @return boolean True on success, false on failure
  712. */
  713. public function close() {
  714. if ($this->debug > 0) {
  715. error_log('New LP - In learnpath::close()', 0);
  716. }
  717. if (empty ($this->lp_id)) {
  718. $this->error = 'Trying to close this learnpath but no ID is set';
  719. return false;
  720. }
  721. $this->current_time_stop = time();
  722. if ($this->save) {
  723. $learnpath_view_table = Database :: get_course_table(TABLE_LP_VIEW);
  724. /*
  725. $sql = "UPDATE $learnpath_view_table " .
  726. "SET " .
  727. "stop_time = ".$this->current_time_stop.", " .
  728. "score = ".$this->current_score.", ".
  729. "WHERE learnpath_id = '".$this->lp_id."'";
  730. //$res = Database::query($sql);
  731. $res = Database::query($res);
  732. if (Database::affected_rows($res) < 1) {
  733. $this->error = 'Could not update learnpath_view table while closing learnpath';
  734. return false;
  735. }
  736. */
  737. }
  738. $this->ordered_items = array ();
  739. $this->index = 0;
  740. unset ($this->lp_id);
  741. //unset other stuff
  742. return true;
  743. }
  744. /**
  745. * Static admin function allowing removal of a learnpath
  746. * @param string Course code
  747. * @param integer Learnpath ID
  748. * @param string Whether to delete data or keep it (default: 'keep', others: 'remove')
  749. * @return boolean True on success, false on failure (might change that to return number of elements deleted)
  750. */
  751. public function delete($course = null, $id = null, $delete = 'keep') {
  752. // TODO: Implement a way of getting this to work when the current object is not set.
  753. // In clear: implement this in the item class as well (abstract class) and use the given ID in queries.
  754. //if (empty($course)) { $course = api_get_course_id(); }
  755. //if (empty($id)) { $id = $this->get_id(); }
  756. // If an ID is specifically given and the current LP is not the same, prevent delete.
  757. if (!empty ($id) && ($id != $this->lp_id)) {
  758. return false;
  759. }
  760. $lp = Database :: get_course_table(TABLE_LP_MAIN);
  761. $lp_item = Database :: get_course_table(TABLE_LP_ITEM); // Proposed by Christophe (clefevre), see below.
  762. $lp_view = Database :: get_course_table(TABLE_LP_VIEW);
  763. $lp_item_view = Database :: get_course_table(TABLE_LP_ITEM_VIEW);
  764. //if ($this->debug > 0) { error_log('New LP - In learnpath::delete()', 0); }
  765. // Delete lp item id.
  766. foreach ($this->items as $id => $dummy) {
  767. //$this->items[$id]->delete();
  768. $sql_del_view = "DELETE FROM $lp_item_view WHERE lp_item_id = '" . $id . "'";
  769. $res_del_item_view = Database::query($sql_del_view);
  770. }
  771. // Proposed by Christophe (nickname: clefevre), see http://www.dokeos.com/forum/viewtopic.php?t=29673
  772. $sql_del_item = "DELETE FROM $lp_item WHERE lp_id = " . $this->lp_id;
  773. $res_del_item = Database::query($sql_del_item);
  774. $sql_del_view = "DELETE FROM $lp_view WHERE lp_id = " . $this->lp_id;
  775. //if ($this->debug > 2) { error_log('New LP - Deleting views bound to lp '.$this->lp_id.': '.$sql_del_view, 0); }
  776. $res_del_view = Database::query($sql_del_view);
  777. $this->toggle_publish($this->lp_id, 'i');
  778. //if ($this->debug > 2) { error_log('New LP - Deleting lp '.$this->lp_id.' of type '.$this->type, 0); }
  779. if ($this->type == 2 || $this->type == 3) {
  780. // This is a scorm learning path, delete the files as well.
  781. $sql = "SELECT path FROM $lp WHERE id = " . $this->lp_id;
  782. $res = Database::query($sql);
  783. if (Database :: num_rows($res) > 0) {
  784. $row = Database :: fetch_array($res);
  785. $path = $row['path'];
  786. $sql = "SELECT id FROM $lp WHERE path = '$path' AND id != " . $this->lp_id;
  787. $res = Database::query($sql);
  788. if (Database :: num_rows($res) > 0) { // Another learning path uses this directory, so don't delete it.
  789. if ($this->debug > 2) {
  790. error_log('New LP - In learnpath::delete(), found other LP using path ' . $path . ', keeping directory', 0);
  791. }
  792. } else {
  793. // No other LP uses that directory, delete it.
  794. $course_rel_dir = api_get_course_path() . '/scorm/'; // scorm dir web path starting from /courses
  795. $course_scorm_dir = api_get_path(SYS_COURSE_PATH) . $course_rel_dir; // The absolute system path for this course.
  796. if ($delete == 'remove' && is_dir($course_scorm_dir . $path) and !empty ($course_scorm_dir)) {
  797. if ($this->debug > 2) {
  798. error_log('New LP - In learnpath::delete(), found SCORM, deleting directory: ' . $course_scorm_dir . $path, 0);
  799. }
  800. // Proposed by Christophe (clefevre).
  801. if (strcmp(substr($path, -2), "/.") == 0) {
  802. $path = substr($path, 0, -1); // Remove "." at the end.
  803. }
  804. //exec('rm -rf ' . $course_scorm_dir . $path); // See Bug #5208, this is not OS-portable way.
  805. rmdirr($course_scorm_dir . $path);
  806. }
  807. }
  808. }
  809. }
  810. $sql_del_lp = "DELETE FROM $lp WHERE id = " . $this->lp_id;
  811. //if ($this->debug > 2) { error_log('New LP - Deleting lp '.$this->lp_id.': '.$sql_del_lp, 0); }
  812. $res_del_lp = Database::query($sql_del_lp);
  813. $this->update_display_order(); // Updates the display order of all lps.
  814. api_item_property_update(api_get_course_info(), TOOL_LEARNPATH, $this->lp_id, 'delete', api_get_user_id());
  815. require_once '../gradebook/lib/be.inc.php';
  816. $tbl_grade_link = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_LINK);
  817. // Delete link of gradebook tool.
  818. $sql = 'SELECT gl.id FROM ' . $tbl_grade_link . ' gl WHERE gl.type="4" AND gl.ref_id="' . $id . '";';
  819. $result = Database::query($sql);
  820. $row = Database :: fetch_array($result, 'ASSOC');
  821. // Fixing gradebook link deleted see #5229.
  822. if (!empty($row['id'])) {
  823. $link = LinkFactory :: load($row['id']);
  824. if ($link[0] != null) {
  825. $link[0]->delete();
  826. }
  827. }
  828. // TODO: Also delete items and item-views.
  829. if (api_get_setting('search_enabled') == 'true') {
  830. require_once api_get_path(LIBRARY_PATH).'specific_fields_manager.lib.php';
  831. $r = delete_all_values_for_item($this->cc, TOOL_LEARNPATH, $this->lp_id);
  832. }
  833. }
  834. /**
  835. * Removes all the children of one item - dangerous!
  836. * @param integer Element ID of which children have to be removed
  837. * @return integer Total number of children removed
  838. */
  839. public function delete_children_items($id) {
  840. if ($this->debug > 0) {
  841. error_log('New LP - In learnpath::delete_children_items(' . $id . ')', 0);
  842. }
  843. $num = 0;
  844. if (empty ($id) || $id != strval(intval($id))) {
  845. return false;
  846. }
  847. $lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  848. $sql = "SELECT * FROM $lp_item WHERE parent_item_id = $id";
  849. $res = Database::query($sql);
  850. while ($row = Database :: fetch_array($res)) {
  851. $num += $this->delete_children_items($row['id']);
  852. $sql_del = "DELETE FROM $lp_item WHERE id = " . $row['id'];
  853. $res_del = Database::query($sql_del);
  854. $num++;
  855. }
  856. return $num;
  857. }
  858. /**
  859. * Removes an item from the current learnpath
  860. * @param integer Elem ID (0 if first)
  861. * @param integer Whether to remove the resource/data from the system or leave it (default: 'keep', others 'remove')
  862. * @return integer Number of elements moved
  863. * @todo implement resource removal
  864. */
  865. public function delete_item($id, $remove = 'keep') {
  866. if ($this->debug > 0) {
  867. error_log('New LP - In learnpath::delete_item()', 0);
  868. }
  869. // TODO: Implement the resource removal.
  870. if (empty ($id) || $id != strval(intval($id))) {
  871. return false;
  872. }
  873. // First select item to get previous, next, and display order.
  874. $lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  875. $sql_sel = "SELECT * FROM $lp_item WHERE id = $id";
  876. $res_sel = Database::query($sql_sel);
  877. if (Database :: num_rows($res_sel) < 1) {
  878. return false;
  879. }
  880. $row = Database :: fetch_array($res_sel);
  881. $previous = $row['previous_item_id'];
  882. $next = $row['next_item_id'];
  883. $display = $row['display_order'];
  884. $parent = $row['parent_item_id'];
  885. $lp = $row['lp_id'];
  886. // Delete children items.
  887. $num = $this->delete_children_items($id);
  888. if ($this->debug > 2) {
  889. error_log('New LP - learnpath::delete_item() - deleted ' . $num . ' children of element ' . $id, 0);
  890. }
  891. // Now delete the item.
  892. $sql_del = "DELETE FROM $lp_item WHERE id = $id";
  893. if ($this->debug > 2) {
  894. error_log('New LP - Deleting item: ' . $sql_del, 0);
  895. }
  896. $res_del = Database::query($sql_del);
  897. // Now update surrounding items.
  898. $sql_upd = "UPDATE $lp_item SET next_item_id = $next WHERE id = $previous";
  899. $res_upd = Database::query($sql_upd);
  900. $sql_upd = "UPDATE $lp_item SET previous_item_id = $previous WHERE id = $next";
  901. $res_upd = Database::query($sql_upd);
  902. // Now update all following items with new display order.
  903. $sql_all = "UPDATE $lp_item SET display_order = display_order-1 WHERE lp_id = $lp AND parent_item_id = $parent AND display_order > $display";
  904. $res_all = Database::query($sql_all);
  905. //Removing prerequisites since the item will not longer exist
  906. $sql_all = "UPDATE $lp_item SET prerequisite = '' WHERE prerequisite = $id";
  907. $res_all = Database::query($sql_all);
  908. // Remove from search engine if enabled.
  909. if (api_get_setting('search_enabled') == 'true') {
  910. $tbl_se_ref = Database :: get_main_table(TABLE_MAIN_SEARCH_ENGINE_REF);
  911. $sql = 'SELECT * FROM %s WHERE course_code=\'%s\' AND tool_id=\'%s\' AND ref_id_high_level=%s AND ref_id_second_level=%d LIMIT 1';
  912. $sql = sprintf($sql, $tbl_se_ref, $this->cc, TOOL_LEARNPATH, $lp, $id);
  913. $res = Database::query($sql);
  914. if (Database :: num_rows($res) > 0) {
  915. $row2 = Database :: fetch_array($res);
  916. require_once api_get_path(LIBRARY_PATH).'search/DokeosIndexer.class.php';
  917. $di = new DokeosIndexer();
  918. $di->remove_document((int) $row2['search_did']);
  919. }
  920. $sql = 'DELETE FROM %s WHERE course_code=\'%s\' AND tool_id=\'%s\' AND ref_id_high_level=%s AND ref_id_second_level=%d LIMIT 1';
  921. $sql = sprintf($sql, $tbl_se_ref, $this->cc, TOOL_LEARNPATH, $lp, $id);
  922. Database::query($sql);
  923. }
  924. }
  925. /**
  926. * Updates an item's content in place
  927. * @param integer Element ID
  928. * @param integer Parent item ID
  929. * @param integer Previous item ID
  930. * @param string Item title
  931. * @param string Item description
  932. * @param string Prerequisites (optional)
  933. * @param string Indexing terms (optional)
  934. * @param array The array resulting of the $_FILES[mp3] element
  935. * @return boolean True on success, false on error
  936. */
  937. public function edit_item($id, $parent, $previous, $title, $description, $prerequisites = 0, $audio = null, $max_time_allowed = 0) {
  938. if ($this->debug > 0) {
  939. error_log('New LP - In learnpath::edit_item()', 0);
  940. }
  941. if (empty ($max_time_allowed)) {
  942. $max_time_allowed = 0;
  943. }
  944. if (empty ($id) || ($id != strval(intval($id))) || empty ($title)) {
  945. return false;
  946. }
  947. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  948. $sql_select = "SELECT * FROM " . $tbl_lp_item . " WHERE id = " . $id;
  949. $res_select = Database::query($sql_select);
  950. $row_select = Database :: fetch_array($res_select);
  951. $audio_update_sql = '';
  952. if (is_array($audio) && !empty ($audio['tmp_name']) && $audio['error'] === 0) {
  953. // Create the audio folder if it does not exist yet.
  954. global $_course;
  955. $filepath = api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document/';
  956. if (!is_dir($filepath . 'audio')) {
  957. mkdir($filepath . 'audio', api_get_permissions_for_new_directories());
  958. $audio_id = add_document($_course, '/audio', 'folder', 0, 'audio');
  959. api_item_property_update($_course, TOOL_DOCUMENT, $audio_id, 'FolderCreated', api_get_user_id(), null, null, null, null, api_get_session_id());
  960. }
  961. // Upload file in documents.
  962. $pi = pathinfo($audio['name']);
  963. if ($pi['extension'] == 'mp3') {
  964. $c_det = api_get_course_info($this->cc);
  965. $bp = api_get_path(SYS_COURSE_PATH) . $c_det['path'] . '/document';
  966. $path = handle_uploaded_document($c_det, $audio, $bp, '/audio', api_get_user_id(), 0, null, '', 0, 'rename', false, 0);
  967. $path = substr($path, 7);
  968. // Update reference in lp_item - audio path is the path from inside de document/audio/ dir.
  969. $audio_update_sql = ", audio = '" . Database :: escape_string($path) . "' ";
  970. }
  971. }
  972. $same_parent = ($row_select['parent_item_id'] == $parent) ? true : false;
  973. $same_previous = ($row_select['previous_item_id'] == $previous) ? true : false;
  974. // TODO: htmlspecialchars to be checked for encoding related problems.
  975. if ($same_parent && $same_previous) {
  976. // Only update title and description.
  977. $sql_update = " UPDATE " . $tbl_lp_item . "
  978. SET title = '" . $this->escape_string($title) . "',
  979. prerequisite = '" . $prerequisites . "',
  980. description = '" . $this->escape_string($description) . "'
  981. " . $audio_update_sql . ",
  982. max_time_allowed = '" . $this->escape_string($max_time_allowed) . "'
  983. WHERE id = " . $id;
  984. $res_update = Database::query($sql_update);
  985. } else {
  986. $old_parent = $row_select['parent_item_id'];
  987. $old_previous = $row_select['previous_item_id'];
  988. $old_next = $row_select['next_item_id'];
  989. $old_order = $row_select['display_order'];
  990. $old_prerequisite = $row_select['prerequisite'];
  991. $old_max_time_allowed = $row_select['max_time_allowed'];
  992. /* BEGIN -- virtually remove the current item id */
  993. /* for the next and previous item it is like the current item doesn't exist anymore */
  994. if ($old_previous != 0) {
  995. $sql_update_next = "
  996. UPDATE " . $tbl_lp_item . "
  997. SET next_item_id = " . $old_next . "
  998. WHERE id = " . $old_previous;
  999. $res_update_next = Database::query($sql_update_next);
  1000. //echo '<p>' . $sql_update_next . '</p>';
  1001. }
  1002. if ($old_next != 0) {
  1003. $sql_update_previous = "
  1004. UPDATE " . $tbl_lp_item . "
  1005. SET previous_item_id = " . $old_previous . "
  1006. WHERE id = " . $old_next;
  1007. $res_update_previous = Database::query($sql_update_previous);
  1008. //echo '<p>' . $sql_update_previous . '</p>';
  1009. }
  1010. // display_order - 1 for every item with a display_order bigger then the display_order of the current item.
  1011. $sql_update_order = "
  1012. UPDATE " . $tbl_lp_item . "
  1013. SET display_order = display_order - 1
  1014. WHERE
  1015. display_order > " . $old_order . " AND lp_id = " . $this->lp_id . " AND
  1016. parent_item_id = " . $old_parent;
  1017. $res_update_order = Database::query($sql_update_order);
  1018. //echo '<p>' . $sql_update_order . '</p>';
  1019. /* END -- virtually remove the current item id */
  1020. /* BEGIN -- update the current item id to his new location */
  1021. if ($previous == 0) {
  1022. // Select the data of the item that should come after the current item.
  1023. $sql_select_old = "
  1024. SELECT
  1025. id,
  1026. display_order
  1027. FROM " . $tbl_lp_item . "
  1028. WHERE
  1029. lp_id = " . $this->lp_id . " AND
  1030. parent_item_id = " . $parent . " AND
  1031. previous_item_id = " . $previous;
  1032. $res_select_old = Database::query($sql_select_old);
  1033. $row_select_old = Database :: fetch_array($res_select_old);
  1034. //echo '<p>' . $sql_select_old . '</p>';
  1035. // If the new parent didn't have children before.
  1036. if (Database :: num_rows($res_select_old) == 0) {
  1037. $new_next = 0;
  1038. $new_order = 1;
  1039. } else {
  1040. $new_next = $row_select_old['id'];
  1041. $new_order = $row_select_old['display_order'];
  1042. }
  1043. //echo 'New next_item_id of current item: ' . $new_next . '<br />';
  1044. //echo 'New previous_item_id of current item: ' . $previous . '<br />';
  1045. //echo 'New display_order of current item: ' . $new_order . '<br />';
  1046. } else {
  1047. // Select the data of the item that should come before the current item.
  1048. $sql_select_old = "
  1049. SELECT
  1050. next_item_id,
  1051. display_order
  1052. FROM " . $tbl_lp_item . "
  1053. WHERE id = " . $previous;
  1054. $res_select_old = Database::query($sql_select_old);
  1055. $row_select_old = Database :: fetch_array($res_select_old);
  1056. //echo '<p>' . $sql_select_old . '</p>';
  1057. //echo 'New next_item_id of current item: ' . $row_select_old['next_item_id'] . '<br />';
  1058. //echo 'New previous_item_id of current item: ' . $previous . '<br />';
  1059. //echo 'New display_order of current item: ' . ($row_select_old['display_order'] + 1) . '<br />';
  1060. $new_next = $row_select_old['next_item_id'];
  1061. $new_order = $row_select_old['display_order'] + 1;
  1062. }
  1063. // TODO: htmlspecialchars to be checked for encoding related problems.
  1064. // Update the current item with the new data.
  1065. $sql_update = "
  1066. UPDATE " . $tbl_lp_item . "
  1067. SET
  1068. title = '" . $this->escape_string($title) . "',
  1069. description = '" . $this->escape_string($description) . "',
  1070. parent_item_id = " . $parent . ",
  1071. previous_item_id = " . $previous . ",
  1072. next_item_id = " . $new_next . ",
  1073. display_order = " . $new_order . "
  1074. " . $audio_update_sql . "
  1075. WHERE id = " . $id;
  1076. $res_update_next = Database::query($sql_update);
  1077. //echo '<p>' . $sql_update . '</p>';
  1078. if ($previous != 0) {
  1079. // Update the previous item's next_item_id.
  1080. $sql_update_previous = "
  1081. UPDATE " . $tbl_lp_item . "
  1082. SET next_item_id = " . $id . "
  1083. WHERE id = " . $previous;
  1084. $res_update_next = Database::query($sql_update_previous);
  1085. //echo '<p>' . $sql_update_previous . '</p>';
  1086. }
  1087. if ($new_next != 0) {
  1088. // Update the next item's previous_item_id.
  1089. $sql_update_next = "
  1090. UPDATE " . $tbl_lp_item . "
  1091. SET previous_item_id = " . $id . "
  1092. WHERE id = " . $new_next;
  1093. $res_update_next = Database::query($sql_update_next);
  1094. //echo '<p>' . $sql_update_next . '</p>';
  1095. }
  1096. if ($old_prerequisite != $prerequisites) {
  1097. $sql_update_next = "
  1098. UPDATE " . $tbl_lp_item . "
  1099. SET prerequisite = " . $prerequisites . "
  1100. WHERE id = " . $id;
  1101. $res_update_next = Database::query($sql_update_next);
  1102. }
  1103. if ($old_max_time_allowed != $max_time_allowed) {
  1104. $sql_update_max_time_allowed = "
  1105. UPDATE " . $tbl_lp_item . "
  1106. SET max_time_allowed = " . $max_time_allowed . "
  1107. WHERE id = " . $id;
  1108. $res_update_max_time_allowed = Database::query($sql_update_max_time_allowed);
  1109. }
  1110. // Update all the items with the same or a bigger display_order than the current item.
  1111. $sql_update_order = "
  1112. UPDATE " . $tbl_lp_item . "
  1113. SET display_order = display_order + 1
  1114. WHERE
  1115. lp_id = " . $this->get_id() . " AND
  1116. id <> " . $id . " AND
  1117. parent_item_id = " . $parent . " AND
  1118. display_order >= " . $new_order;
  1119. $res_update_next = Database::query($sql_update_order);
  1120. }
  1121. }
  1122. /**
  1123. * Updates an item's prereq in place
  1124. * @param integer Element ID
  1125. * @param string Prerequisite Element ID
  1126. * @param string Prerequisite item type
  1127. * @param string Prerequisite min score
  1128. * @param string Prerequisite max score
  1129. * @return boolean True on success, false on error
  1130. */
  1131. public function edit_item_prereq($id, $prerequisite_id, $mastery_score = 0, $max_score = 100) {
  1132. if ($this->debug > 0) {
  1133. error_log('New LP - In learnpath::edit_item_prereq(' . $id . ',' . $prerequisite_id . ',' . $mastery_score . ',' . $max_score . ')', 0);
  1134. }
  1135. if (empty ($id) or ($id != strval(intval($id))) or empty ($prerequisite_id)) {
  1136. return false;
  1137. }
  1138. $prerequisite_id = $this->escape_string($prerequisite_id);
  1139. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  1140. if (!is_numeric($mastery_score) || $mastery_score < 0)
  1141. $mastery_score = 0;
  1142. if (!is_numeric($max_score) || $max_score < 0)
  1143. $max_score = 100;
  1144. if ($mastery_score > $max_score)
  1145. $max_score = $mastery_score;
  1146. if (!is_numeric($prerequisite_id))
  1147. $prerequisite_id = 'NULL';
  1148. $sql_upd = " UPDATE " . $tbl_lp_item . "
  1149. SET prerequisite = " . $prerequisite_id . " WHERE id = " . $id;
  1150. $res_upd = Database::query($sql_upd);
  1151. if ($prerequisite_id != 'NULL' && $prerequisite_id != '') {
  1152. $sql_upd = " UPDATE " . $tbl_lp_item . " SET
  1153. mastery_score = " . $mastery_score .
  1154. //", max_score = " . $max_score . " " . // Max score cannot be changed in the form anyway - see display_item_prerequisites_form().
  1155. " WHERE ref = '" . $prerequisite_id . "'"; // Will this be enough to ensure unicity?
  1156. $res_upd = Database::query($sql_upd);
  1157. }
  1158. // TODO: Update the item object (can be ignored for now because refreshed).
  1159. return true;
  1160. }
  1161. /**
  1162. * Escapes a string with the available database escape function
  1163. * @param string String to escape
  1164. * @return string String escaped
  1165. */
  1166. public function escape_string($string) {
  1167. //if ($this->debug > 0) { error_log('New LP - In learnpath::escape_string('.$string.')', 0); }
  1168. return Database :: escape_string($string);
  1169. }
  1170. /**
  1171. * Static admin function exporting a learnpath into a zip file
  1172. * @param string Export type (scorm, zip, cd)
  1173. * @param string Course code
  1174. * @param integer Learnpath ID
  1175. * @param string Zip file name
  1176. * @return string Zip file path (or false on error)
  1177. */
  1178. public function export_lp($type, $course, $id, $zipname) {
  1179. //if ($this->debug > 0) { error_log('New LP - In learnpath::export_lp()', 0); }
  1180. if (empty($type) || empty($course) || empty($id) || empty($zipname)) {
  1181. return false;
  1182. }
  1183. $url = '';
  1184. switch ($type) {
  1185. case 'scorm':
  1186. break;
  1187. case 'zip':
  1188. break;
  1189. case 'cdrom':
  1190. break;
  1191. }
  1192. return $url;
  1193. }
  1194. /**
  1195. * Gets all the chapters belonging to the same parent as the item/chapter given
  1196. * Can also be called as abstract method
  1197. * @param integer Item ID
  1198. * @return array A list of all the "brother items" (or an empty array on failure)
  1199. */
  1200. public function get_brother_chapters($id) {
  1201. if ($this->debug > 0) {
  1202. error_log('New LP - In learnpath::get_brother_chapters()', 0);
  1203. }
  1204. if (empty ($id) OR $id != strval(intval($id))) {
  1205. return array ();
  1206. }
  1207. $lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  1208. $sql_parent = "SELECT * FROM $lp_item WHERE id = $id AND item_type='dokeos_chapter'";
  1209. $res_parent = Database::query($sql_parent);
  1210. if (Database :: num_rows($res_parent) > 0) {
  1211. $row_parent = Database :: fetch_array($res_parent);
  1212. $parent = $row_parent['parent_item_id'];
  1213. $sql_bros = "SELECT * FROM $lp_item WHERE parent_item_id = $parent AND id = $id AND item_type='dokeos_chapter' ORDER BY display_order";
  1214. $res_bros = Database::query($sql_bros);
  1215. $list = array ();
  1216. while ($row_bro = Database :: fetch_array($res_bros)) {
  1217. $list[] = $row_bro;
  1218. }
  1219. return $list;
  1220. }
  1221. return array ();
  1222. }
  1223. /**
  1224. * Gets all the items belonging to the same parent as the item given
  1225. * Can also be called as abstract method
  1226. * @param integer Item ID
  1227. * @return array A list of all the "brother items" (or an empty array on failure)
  1228. */
  1229. public function get_brother_items($id) {
  1230. if ($this->debug > 0) {
  1231. error_log('New LP - In learnpath::get_brother_items(' . $id . ')', 0);
  1232. }
  1233. if (empty ($id) OR $id != strval(intval($id))) {
  1234. return array ();
  1235. }
  1236. $lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  1237. $sql_parent = "SELECT * FROM $lp_item WHERE id = $id";
  1238. $res_parent = Database::query($sql_parent);
  1239. if (Database :: num_rows($res_parent) > 0) {
  1240. $row_parent = Database :: fetch_array($res_parent);
  1241. $parent = $row_parent['parent_item_id'];
  1242. $sql_bros = "SELECT * FROM $lp_item WHERE parent_item_id = $parent ORDER BY display_order";
  1243. $res_bros = Database::query($sql_bros);
  1244. $list = array ();
  1245. while ($row_bro = Database :: fetch_array($res_bros)) {
  1246. $list[] = $row_bro;
  1247. }
  1248. return $list;
  1249. }
  1250. return array ();
  1251. }
  1252. /**
  1253. * Get the specific prefix index terms of this learning path
  1254. * @return array Array of terms
  1255. */
  1256. public function get_common_index_terms_by_prefix($prefix) {
  1257. require_once api_get_path(LIBRARY_PATH).'specific_fields_manager.lib.php';
  1258. $terms = get_specific_field_values_list_by_prefix($prefix, $this->cc, TOOL_LEARNPATH, $this->lp_id);
  1259. $prefix_terms = array();
  1260. foreach ($terms as $term) {
  1261. $prefix_terms[] = $term['value'];
  1262. }
  1263. return $prefix_terms;
  1264. }
  1265. /**
  1266. * Gets the number of items currently completed
  1267. * @return integer The number of items currently completed
  1268. */
  1269. public function get_complete_items_count() {
  1270. if ($this->debug > 0) {
  1271. error_log('New LP - In learnpath::get_complete_items_count()', 0);
  1272. }
  1273. $i = 0;
  1274. foreach ($this->items as $id => $dummy) {
  1275. // Trying failed and browsed considered "progressed" as well.
  1276. if ($this->items[$id]->status_is(array (
  1277. 'completed',
  1278. 'passed',
  1279. 'succeeded',
  1280. 'browsed',
  1281. 'failed'
  1282. )) && $this->items[$id]->get_type() != 'dokeos_chapter' && $this->items[$id]->get_type() != 'dir') {
  1283. $i++;
  1284. }
  1285. }
  1286. return $i;
  1287. }
  1288. /**
  1289. * Gets the current item ID
  1290. * @return integer The current learnpath item id
  1291. */
  1292. public function get_current_item_id() {
  1293. $current = 0;
  1294. if ($this->debug > 0) {
  1295. error_log('New LP - In learnpath::get_current_item_id()', 0);
  1296. }
  1297. if (!empty ($this->current)) {
  1298. $current = $this->current;
  1299. }
  1300. if ($this->debug > 2) {
  1301. error_log('New LP - In learnpath::get_current_item_id() - Returning ' . $current, 0);
  1302. }
  1303. return $current;
  1304. }
  1305. /**
  1306. * Force to get the first learnpath item id
  1307. * @return integer The current learnpath item id
  1308. */
  1309. public function get_first_item_id() {
  1310. $current = 0;
  1311. if (is_array($this->ordered_items)) {
  1312. $current = $this->ordered_items[0];
  1313. }
  1314. return $current;
  1315. }
  1316. /**
  1317. * Gets the total number of items available for viewing in this SCORM
  1318. * @return integer The total number of items
  1319. */
  1320. public function get_total_items_count() {
  1321. if ($this->debug > 0) {
  1322. error_log('New LP - In learnpath::get_total_items_count()', 0);
  1323. }
  1324. return count($this->items);
  1325. }
  1326. /**
  1327. * Gets the total number of items available for viewing in this SCORM but without chapters
  1328. * @return integer The total no-chapters number of items
  1329. */
  1330. public function get_total_items_count_without_chapters() {
  1331. if ($this->debug > 0) {
  1332. error_log('New LP - In learnpath::get_total_items_count_without_chapters()', 0);
  1333. }
  1334. $total = 0;
  1335. foreach ($this->items as $temp => $temp2) {
  1336. if (!in_array($temp2->get_type(), array (
  1337. 'dokeos_chapter',
  1338. 'chapter',
  1339. 'dir'
  1340. )))
  1341. $total++;
  1342. }
  1343. return $total;
  1344. }
  1345. /**
  1346. * Gets the first element URL.
  1347. * @return string URL to load into the viewer
  1348. */
  1349. public function first() {
  1350. if ($this->debug > 0) {
  1351. error_log('New LP - In learnpath::first()', 0);
  1352. }
  1353. // Test if the last_item_seen exists and is not a dir.
  1354. if (count($this->ordered_items) == 0) {
  1355. $this->index = 0;
  1356. }
  1357. if (!empty($this->last_item_seen) && !empty($this->items[$this->last_item_seen]) && $this->items[$this->last_item_seen]->get_type() != 'dir' && $this->items[$this->last_item_seen]->get_type() != 'dokeos_chapter' && !$this->items[$this->last_item_seen]->is_done()) {
  1358. if ($this->debug > 2) {
  1359. 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);
  1360. }
  1361. $index = -1;
  1362. foreach ($this->ordered_items as $myindex => $item_id) {
  1363. if ($item_id == $this->last_item_seen) {
  1364. $index = $myindex;
  1365. break;
  1366. }
  1367. }
  1368. if ($index == -1) {
  1369. // Index hasn't changed, so item not found - panic (this shouldn't happen).
  1370. if ($this->debug > 2) {
  1371. error_log('New LP - Last item (' . $this->last_item_seen . ') was found in items but not in ordered_items, panic!', 0);
  1372. }
  1373. return false;
  1374. } else {
  1375. $this->last = $this->last_item_seen;
  1376. $this->current = $this->last_item_seen;
  1377. $this->index = $index;
  1378. }
  1379. } else {
  1380. if ($this->debug > 2) {
  1381. error_log('New LP - In learnpath::first() - No last item seen', 0);
  1382. }
  1383. $index = 0;
  1384. // Loop through all ordered items and stop at the first item that is
  1385. // not a directory *and* that has not been completed yet.
  1386. while (!empty($this->ordered_items[$index]) AND is_a($this->items[$this->ordered_items[$index]], 'learnpathItem') AND ($this->items[$this->ordered_items[$index]]->get_type() == 'dir' OR $this->items[$this->ordered_items[$index]]->get_type() == 'dokeos_chapter' OR $this->items[$this->ordered_items[$index]]->is_done() === true) AND $index < $this->max_ordered_items) {
  1387. $index++;
  1388. }
  1389. $this->last = $this->current;
  1390. // current is
  1391. $this->current = $this->ordered_items[$index];
  1392. $this->index = $index;
  1393. if ($this->debug > 2) {
  1394. error_log('New LP - In learnpath::first() - No last item seen. New last = ' . $this->last . '(' . $this->ordered_items[$index] . ')', 0);
  1395. }
  1396. }
  1397. if ($this->debug > 2) {
  1398. error_log('New LP - In learnpath::first() - First item is ' . $this->get_current_item_id());
  1399. }
  1400. }
  1401. /**
  1402. * Gets the information about an item in a format usable as JavaScript to update
  1403. * the JS API by just printing this content into the <head> section of the message frame
  1404. * @param integer Item ID
  1405. * @return string
  1406. */
  1407. public function get_js_info($item_id = '') {
  1408. if ($this->debug > 0) {
  1409. error_log('New LP - In learnpath::get_js_info(' . $item_id . ')', 0);
  1410. }
  1411. $info = '';
  1412. $item_id = $this->escape_string($item_id);
  1413. if (!empty($item_id) && is_object($this->items[$item_id])) {
  1414. //if item is defined, return values from DB
  1415. $oItem = $this->items[$item_id];
  1416. $info .= '<script language="javascript">';
  1417. $info .= "top.set_score(" . $oItem->get_score() . ");\n";
  1418. $info .= "top.set_max(" . $oItem->get_max() . ");\n";
  1419. $info .= "top.set_min(" . $oItem->get_min() . ");\n";
  1420. $info .= "top.set_lesson_status('" . $oItem->get_status() . "');";
  1421. $info .= "top.set_session_time('" . $oItem->get_scorm_time('js') . "');";
  1422. $info .= "top.set_suspend_data('" . $oItem->get_suspend_data() . "');";
  1423. $info .= "top.set_saved_lesson_status('" . $oItem->get_status() . "');";
  1424. $info .= "top.set_flag_synchronized();";
  1425. $info .= '</script>';
  1426. if ($this->debug > 2) {
  1427. error_log('New LP - in learnpath::get_js_info(' . $item_id . ') - returning: ' . $info, 0);
  1428. }
  1429. return $info;
  1430. } else {
  1431. // If item_id is empty, just update to default SCORM data.
  1432. $info .= '<script language="javascript">';
  1433. $info .= "top.set_score(" . learnpathItem :: get_score() . ");\n";
  1434. $info .= "top.set_max(" . learnpathItem :: get_max() . ");\n";
  1435. $info .= "top.set_min(" . learnpathItem :: get_min() . ");\n";
  1436. $info .= "top.set_lesson_status('" . learnpathItem :: get_status() . "');";
  1437. $info .= "top.set_session_time('" . learnpathItem :: get_scorm_time('js') . "');";
  1438. $info .= "top.set_suspend_data('" . learnpathItem :: get_suspend_data() . "');";
  1439. $info .= "top.set_saved_lesson_status('" . learnpathItem :: get_status() . "');";
  1440. $info .= "top.set_flag_synchronized();";
  1441. $info .= '</script>';
  1442. if ($this->debug > 2) {
  1443. error_log('New LP - in learnpath::get_js_info(' . $item_id . ') - returning: ' . $info, 0);
  1444. }
  1445. return $info;
  1446. }
  1447. }
  1448. /**
  1449. * Gets the js library from the database
  1450. * @return string The name of the javascript library to be used
  1451. */
  1452. public function get_js_lib() {
  1453. $lib = '';
  1454. if (!empty ($this->js_lib)) {
  1455. $lib = $this->js_lib;
  1456. }
  1457. return $lib;
  1458. }
  1459. /**
  1460. * Gets the learnpath database ID
  1461. * @return integer Learnpath ID in the lp table
  1462. */
  1463. public function get_id() {
  1464. //if ($this->debug > 0) { error_log('New LP - In learnpath::get_id()', 0); }
  1465. if (!empty ($this->lp_id)) {
  1466. return $this->lp_id;
  1467. } else {
  1468. return 0;
  1469. }
  1470. }
  1471. /**
  1472. * Gets the last element URL.
  1473. * @return string URL to load into the viewer
  1474. */
  1475. public function get_last() {
  1476. if ($this->debug > 0) {
  1477. error_log('New LP - In learnpath::get_last()', 0);
  1478. }
  1479. $this->index = count($this->ordered_items) - 1;
  1480. return $this->ordered_items[$this->index];
  1481. }
  1482. /**
  1483. * Gets the navigation bar for the learnpath display screen
  1484. * @return string The HTML string to use as a navigation bar
  1485. */
  1486. public function get_navigation_bar() {
  1487. if ($this->debug > 0) {
  1488. error_log('New LP - In learnpath::get_navigation_bar()', 0);
  1489. }
  1490. // TODO: Find a good value for the following variables.
  1491. $file = '';
  1492. $openDir = '';
  1493. $edoceo = '';
  1494. $time = 0;
  1495. $navbar = '';
  1496. $RequestUri = '';
  1497. $mycurrentitemid = $this->get_current_item_id();
  1498. if ($this->mode == 'fullscreen') {
  1499. $navbar = '<table cellpadding="0" cellspacing="0" align="left">' . "\n" .
  1500. ' <tr> ' . "\n" .
  1501. ' <td>' . "\n" .
  1502. ' <div class="buttons">' . "\n" .
  1503. ' <a href="lp_controller.php?action=stats" onclick="window.parent.API.save_asset();return true;" target="content_name_blank" title="stats" id="stats_link"><img border="0" src="../img/lp_stats.gif" title="' . get_lang('Reporting') . '"></a>' . "\n" .
  1504. ' <a href="" onclick="switch_item(' . $mycurrentitemid . ',\'previous\');return false;" title="previous"><img border="0" src="../img/lp_leftarrow.gif" title="' . get_lang('ScormPrevious') . '"></a>' . "\n" .
  1505. ' <a href="" onclick="switch_item(' . $mycurrentitemid . ',\'next\');return false;" title="next" ><img border="0" src="../img/lp_rightarrow.gif" title="' . get_lang('ScormNext') . '"></a>' . "\n" .
  1506. //' <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" .
  1507. //' <a href="lp_controller.php?action=list" target="_top" title="learnpaths list"><img border="0" src="../img/exit.png" title="Exit"></a>'."\n" .
  1508. ' </div>' . "\n" .
  1509. ' </td>' . "\n" .
  1510. ' </tr>' . "\n" .
  1511. '</table>' . "\n";
  1512. } else {
  1513. $navbar = '<table cellpadding="0" cellspacing="0" align="left">' . "\n" .
  1514. ' <tr> ' . "\n" .
  1515. ' <td>' . "\n" .
  1516. ' <div class="buttons">' . "\n" .
  1517. ' <a href="lp_controller.php?action=stats" onclick="window.parent.API.save_asset();return true;" target="content_name" title="stats" id="stats_link"><img border="0" src="../img/lp_stats.gif" title="' . get_lang('Reporting') . '"></a>' . "\n" .
  1518. ' <a href="" onclick="switch_item(' . $mycurrentitemid . ',\'previous\');return false;" title="previous"><img border="0" src="../img/lp_leftarrow.gif" title="' . get_lang('ScormPrevious') . '"></a>' . "\n" .
  1519. ' <a href="" onclick="switch_item(' . $mycurrentitemid . ',\'next\');return false;" title="next" ><img border="0" src="../img/lp_rightarrow.gif" title="' . get_lang('ScormNext') . '"></a>' . "\n" .
  1520. // ' <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" .
  1521. ' </div>' . "\n" .
  1522. ' </td>' . "\n" .
  1523. ' </tr>' . "\n" .
  1524. '</table>' . "\n";
  1525. }
  1526. return $navbar;
  1527. }
  1528. /**
  1529. * Gets the next resource in queue (url).
  1530. * @return string URL to load into the viewer
  1531. */
  1532. public function get_next_index() {
  1533. if ($this->debug > 0) {
  1534. error_log('New LP - In learnpath::get_next_index()', 0);
  1535. }
  1536. // TODO
  1537. $index = $this->index;
  1538. $index++;
  1539. if ($this->debug > 2) {
  1540. error_log('New LP - Now looking at ordered_items[' . ($index) . '] - type is ' . $this->items[$this->ordered_items[$index]]->type, 0);
  1541. }
  1542. 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) {
  1543. $index++;
  1544. if ($index == $this->max_ordered_items){
  1545. if ($this->items[$this->ordered_items[$index]]->get_type() == 'dir' || $this->items[$this->ordered_items[$index]]->get_type() == 'dokeos_chapter') {
  1546. return $this->index;
  1547. } else {
  1548. return $index;
  1549. }
  1550. }
  1551. }
  1552. if (empty ($this->ordered_items[$index])) {
  1553. return $this->index;
  1554. }
  1555. if ($this->debug > 2) {
  1556. error_log('New LP - index is now ' . $index, 0);
  1557. }
  1558. return $index;
  1559. }
  1560. /**
  1561. * Gets item_id for the next element
  1562. * @return integer Next item (DB) ID
  1563. */
  1564. public function get_next_item_id() {
  1565. if ($this->debug > 0) {
  1566. error_log('New LP - In learnpath::get_next_item_id()', 0);
  1567. }
  1568. $new_index = $this->get_next_index();
  1569. if (!empty ($new_index)) {
  1570. if (isset ($this->ordered_items[$new_index])) {
  1571. if ($this->debug > 2) {
  1572. error_log('New LP - In learnpath::get_next_index() - Returning ' . $this->ordered_items[$new_index], 0);
  1573. }
  1574. return $this->ordered_items[$new_index];
  1575. }
  1576. }
  1577. if ($this->debug > 2) {
  1578. error_log('New LP - In learnpath::get_next_index() - Problem - Returning 0', 0);
  1579. }
  1580. return 0;
  1581. }
  1582. /**
  1583. * Returns the package type ('scorm','aicc','scorm2004','dokeos','ppt'...)
  1584. *
  1585. * Generally, the package provided is in the form of a zip file, so the function
  1586. * has been written to test a zip file. If not a zip, the function will return the
  1587. * default return value: ''
  1588. * @param string the path to the file
  1589. * @param string the original name of the file
  1590. * @return string 'scorm','aicc','scorm2004','dokeos' or '' if the package cannot be recognized
  1591. */
  1592. public function get_package_type($file_path, $file_name) {
  1593. // Get name of the zip file without the extension.
  1594. $file_info = pathinfo($file_name);
  1595. $filename = $file_info['basename']; // Name including extension.
  1596. $extension = $file_info['extension']; // Extension only.
  1597. if (!empty($_POST['ppt2lp']) && !in_array(strtolower($extension), array (
  1598. 'dll',
  1599. 'exe'
  1600. ))) {
  1601. return 'oogie';
  1602. }
  1603. if (!empty($_POST['woogie']) && !in_array(strtolower($extension), array (
  1604. 'dll',
  1605. 'exe'
  1606. ))) {
  1607. return 'woogie';
  1608. }
  1609. $file_base_name = str_replace('.' . $extension, '', $filename); // Filename without its extension.
  1610. $zipFile = new pclZip($file_path);
  1611. // Check the zip content (real size and file extension).
  1612. $zipContentArray = $zipFile->listContent();
  1613. $package_type = '';
  1614. $at_root = false;
  1615. $manifest = '';
  1616. // The following loop should be stopped as soon as we found the right imsmanifest.xml (how to recognize it?).
  1617. if (is_array($zipContentArray) && count($zipContentArray) > 0) {
  1618. foreach ($zipContentArray as $thisContent) {
  1619. if (preg_match('~.(php.*|phtml)$~i', $thisContent['filename'])) {
  1620. // New behaviour: Don't do anything. These files will be removed in scorm::import_package.
  1621. }
  1622. elseif (stristr($thisContent['filename'], 'imsmanifest.xml') !== false) {
  1623. $manifest = $thisContent['filename']; // Just the relative directory inside scorm/
  1624. $package_type = 'scorm';
  1625. break; // Exit the foreach loop.
  1626. }
  1627. elseif (preg_match('/aicc\//i', $thisContent['filename'])) {
  1628. // If found an aicc directory... (!= false means it cannot be false (error) or 0 (no match)).
  1629. $package_type = 'aicc';
  1630. //break; // Don't exit the loop, because if we find an imsmanifest afterwards, we want it, not the AICC.
  1631. } else {
  1632. $package_type = '';
  1633. }
  1634. }
  1635. }
  1636. return $package_type;
  1637. }
  1638. /**
  1639. * Gets the previous resource in queue (url). Also initialises time values for this viewing
  1640. * @return string URL to load into the viewer
  1641. */
  1642. public function get_previous_index() {
  1643. if ($this->debug > 0) {
  1644. error_log('New LP - In learnpath::get_previous_index()', 0);
  1645. }
  1646. $index = $this->index;
  1647. if (isset ($this->ordered_items[$index -1])) {
  1648. $index--;
  1649. 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')) {
  1650. $index--;
  1651. if ($index < 0) {
  1652. return $this->index;
  1653. }
  1654. }
  1655. } else {
  1656. if ($this->debug > 2) {
  1657. error_log('New LP - get_previous_index() - there was no previous index available, reusing ' . $index, 0);
  1658. }
  1659. // There is no previous item.
  1660. }
  1661. return $index;
  1662. }
  1663. /**
  1664. * Gets item_id for the next element
  1665. * @return integer Previous item (DB) ID
  1666. */
  1667. public function get_previous_item_id() {
  1668. if ($this->debug > 0) {
  1669. error_log('New LP - In learnpath::get_previous_item_id()', 0);
  1670. }
  1671. $new_index = $this->get_previous_index();
  1672. return $this->ordered_items[$new_index];
  1673. }
  1674. /**
  1675. * Gets the progress value from the progress_db attribute
  1676. * @return integer Current progress value
  1677. */
  1678. public function get_progress() {
  1679. if ($this->debug > 0) {
  1680. error_log('New LP - In learnpath::get_progress()', 0);
  1681. }
  1682. if (!empty ($this->progress_db)) {
  1683. return $this->progress_db;
  1684. }
  1685. return 0;
  1686. }
  1687. /**
  1688. * Gets the progress value from the progress field in the database (allows use as abstract method)
  1689. * @param integer Learnpath ID
  1690. * @param integer User ID
  1691. * @param string Mode of display ('%','abs' or 'both')
  1692. * @param string Course database name (optional, defaults to '')
  1693. * @param boolean Whether to return null if no record was found (true), or 0 (false) (optional, defaults to false)
  1694. * @return integer Current progress value as found in the database
  1695. */
  1696. public function get_db_progress($lp_id, $user_id, $mode = '%', $course_db = '', $sincere = false,$session_id = 0) {
  1697. //if ($this->debug > 0) { error_log('New LP - In learnpath::get_db_progress()', 0); }
  1698. $session_id = intval($session_id);
  1699. $session_condition = api_get_session_condition($session_id);
  1700. $table = Database :: get_course_table(TABLE_LP_VIEW, $course_db);
  1701. $sql = "SELECT * FROM $table WHERE lp_id = $lp_id AND user_id = $user_id $session_condition";
  1702. $res = Database::query($sql);
  1703. $view_id = 0;
  1704. if (Database :: num_rows($res) > 0) {
  1705. $row = Database :: fetch_array($res);
  1706. $progress = $row['progress'];
  1707. $view_id = $row['id'];
  1708. } else {
  1709. if ($sincere) {
  1710. return null;
  1711. }
  1712. }
  1713. if (empty ($progress)) {
  1714. $progress = '0';
  1715. }
  1716. if ($mode == '%') {
  1717. return $progress . '%';
  1718. } else {
  1719. // Get the number of items completed and the number of items total.
  1720. $tbl = Database :: get_course_table(TABLE_LP_ITEM, $course_db);
  1721. $sql = "SELECT count(*) FROM $tbl WHERE lp_id = " . $lp_id . "
  1722. AND item_type NOT IN('dokeos_chapter','chapter','dir')";
  1723. $res = Database::query($sql);
  1724. $row = Database :: fetch_array($res);
  1725. $total = $row[0];
  1726. $tbl_item_view = Database :: get_course_table(TABLE_LP_ITEM_VIEW, $course_db);
  1727. $tbl_item = Database :: get_course_table(TABLE_LP_ITEM, $course_db);
  1728. //$sql = "SELECT count(distinct(lp_item_id)) FROM $tbl WHERE lp_view_id = ".$view_id." AND status IN ('passed','completed','succeeded')";
  1729. // Trying as also counting browsed and failed items.
  1730. $sql = "SELECT count(distinct(lp_item_id))
  1731. FROM $tbl_item_view as item_view
  1732. INNER JOIN $tbl_item as item
  1733. ON item.id = item_view.lp_item_id
  1734. AND item_type NOT IN('dokeos_chapter','chapter','dir')
  1735. WHERE lp_view_id = " . $view_id . "
  1736. AND status IN ('passed','completed','succeeded','browsed','failed')"; echo '<br />';
  1737. $res = Database::query($sql);
  1738. $row = Database :: fetch_array($res);
  1739. $completed = $row[0];
  1740. if ($mode == 'abs') {
  1741. return $completed . '/' . $total;
  1742. }
  1743. elseif ($mode == 'both') {
  1744. if ($progress < ($completed / ($total ? $total : 1))) {
  1745. $progress = number_format(($completed / ($total ? $total : 1)) * 100, 0);
  1746. }
  1747. return $progress . '% (' . $completed . '/' . $total . ')';
  1748. }
  1749. }
  1750. return $progress;
  1751. }
  1752. /**
  1753. * Returns the HTML necessary to print a mediaplayer block inside a page
  1754. * @return string The mediaplayer HTML
  1755. */
  1756. public function get_mediaplayer($autostart='true') {
  1757. global $_course;
  1758. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  1759. $tbl_lp_item_view = Database :: get_course_table(TABLE_LP_ITEM_VIEW);
  1760. // Getting all the information about the item.
  1761. $sql = "SELECT * FROM " . $tbl_lp_item . " as lp inner join " . $tbl_lp_item_view . " as lp_view on lp.id = lp_view.lp_item_id " .
  1762. "WHERE lp.id = '" . $_SESSION['oLP']->current . "'";
  1763. $result = Database::query($sql);
  1764. $row = Database::fetch_assoc($result);
  1765. $output = '';
  1766. if (!empty ($row['audio'])) {
  1767. $list = $_SESSION['oLP']->get_toc();
  1768. $type_quiz = false;
  1769. foreach($list as $toc) {
  1770. if ($toc['id'] == $_SESSION['oLP']->current && ($toc['type']=='quiz') ) {
  1771. $type_quiz = true;
  1772. }
  1773. }
  1774. if ($type_quiz) {
  1775. if ($_SESSION['oLP']->prevent_reinit == 1) {
  1776. $row['status'] === 'completed' ? $autostart_audio = 'false' : $autostart_audio = 'true';
  1777. } else {
  1778. $autostart_audio = $autostart;
  1779. }
  1780. } else {
  1781. $autostart_audio = 'true';
  1782. }
  1783. // The mp3 player.
  1784. $output = '<div id="container">';
  1785. $output .= '<script type="text/javascript" src="../inc/lib/mediaplayer/swfobject.js"></script>';
  1786. $output .= '<script type="text/javascript">
  1787. var s1 = new SWFObject("../inc/lib/mediaplayer/player.swf","ply","250","20","9","#FFFFFF");
  1788. s1.addParam("allowscriptaccess","always");
  1789. s1.addParam("flashvars","file=' . api_get_path(WEB_COURSE_PATH) . $_course['path'] . '/document/audio/' . $row['audio'] . '&autostart=' . $autostart_audio.'");
  1790. s1.write("container");
  1791. </script></div>';
  1792. }
  1793. return $output;
  1794. }
  1795. /**
  1796. * This function check if the learnpath is visible for student after the progress of its prerequisite is completed
  1797. * @param int Learnpath id
  1798. * @param int Student id
  1799. * @return bool True if
  1800. */
  1801. public function is_lp_visible_for_student($lp_id, $student_id) {
  1802. $tbl_learnpath = Database :: get_course_table(TABLE_LP_MAIN);
  1803. // Get current prerequisite.
  1804. $sql = "SELECT prerequisite FROM $tbl_learnpath WHERE id = $lp_id";
  1805. $rs = Database::query($sql);
  1806. $row = Database :: fetch_array($rs);
  1807. $prerequisite = $row['prerequisite'];
  1808. $is_visible = true;
  1809. $progress = 0;
  1810. if (!empty($prerequisite)) {
  1811. $progress = self::get_db_progress($prerequisite,$student_id,'%', '', false, api_get_session_id());
  1812. $progress = intval($progress);
  1813. if ($progress < 100) {
  1814. $is_visible = false;
  1815. }
  1816. }
  1817. return $is_visible;
  1818. }
  1819. /**
  1820. * Gets a progress bar for the learnpath by counting the number of items in it and the number of items
  1821. * completed so far.
  1822. * @param string Mode in which we want the values
  1823. * @param integer Progress value to display (optional but mandatory if used in abstract context)
  1824. * @param string Text to display near the progress value (optional but mandatory in abstract context)
  1825. * @param boolean true if it comes from a Diplay LP view
  1826. * @return string HTML string containing the progress bar
  1827. */
  1828. public function get_progress_bar($mode = '', $percentage = -1, $text_add = '', $from_lp = false) {
  1829. //if ($this->debug > 0) {error_log('New LP - In learnpath::get_progress_bar('.$mode.','.$percentage.','.$text_add.','.$from_lp.')', 0); }
  1830. global $lp_theme_css;
  1831. // Setting up the CSS path of the current style if exists.
  1832. if (!empty ($lp_theme_css)) {
  1833. $css_path = api_get_path(WEB_CODE_PATH) . 'css/' . $lp_theme_css . '/images/';
  1834. } else {
  1835. $css_path = '../img/';
  1836. }
  1837. //if ($this->debug > 0) { error_log('New LP - In learnpath::get_progress_bar()', 0); }
  1838. if (isset($this) && is_object($this) && ($percentage == '-1' OR $text_add == '')) {
  1839. list($percentage, $text_add) = $this->get_progress_bar_text($mode);
  1840. }
  1841. $text = $percentage . $text_add;
  1842. // Default progress bar config
  1843. // times that will be greater or shorter
  1844. $factor = 1.2;
  1845. if ($from_lp)
  1846. $progress_height = '26';
  1847. else
  1848. $progress_height = '16';
  1849. $size = str_replace('%', '', $percentage);
  1850. $output =
  1851. '<table border="0" cellpadding="0" cellspacing="0"><tr><td>' .
  1852. '<img id="progress_img_limit_left" src="' . $css_path . 'bar_1.gif" width="1" height="' . $progress_height . '">' .
  1853. '<img id="progress_img_full" src="' . $css_path . 'bar_1u.gif" width="' . $size * $factor . 'px" height="' . $progress_height . '" id="full_portion">' .
  1854. '<img id="progress_img_limit_middle" src="' . $css_path . 'bar_1m.gif" width="1" height="' . $progress_height . '">';
  1855. if ($percentage <= 98) {
  1856. $output .= '<img id="progress_img_empty" src="' . $css_path . 'bar_1r.gif" width="' . (100 - $size) * $factor . 'px" height="' . $progress_height . '" id="empty_portion">';
  1857. } else {
  1858. $output .= '<img id="progress_img_empty" src="' . $css_path . 'bar_1r.gif" width="0" height="' . $progress_height . '" id="empty_portion">';
  1859. }
  1860. $output .= '<img id="progress_bar_img_limit_right" src="' . $css_path . 'bar_1.gif" width="1" height="' . $progress_height . '"></td></tr></table>' .
  1861. '<div class="progresstext" id="progress_text">' . $text . '</div>';
  1862. return $output;
  1863. }
  1864. /**
  1865. * Gets the progress bar info to display inside the progress bar. Also used by scorm_api.php
  1866. * @param string Mode of display (can be '%' or 'abs').abs means we display a number of completed elements per total elements
  1867. * @param integer Additional steps to fake as completed
  1868. * @return list Percentage or number and symbol (% or /xx)
  1869. */
  1870. public function get_progress_bar_text($mode = '', $add = 0) {
  1871. if ($this->debug > 0) {
  1872. error_log('New LP - In learnpath::get_progress_bar_text()', 0);
  1873. }
  1874. if (empty ($mode)) {
  1875. $mode = $this->progress_bar_mode;
  1876. }
  1877. $total_items = $this->get_total_items_count_without_chapters();
  1878. if ($this->debug > 2) {
  1879. error_log('New LP - Total items available in this learnpath: ' . $total_items, 0);
  1880. }
  1881. $i = $this->get_complete_items_count();
  1882. if ($this->debug > 2) {
  1883. error_log('New LP - Items completed so far: ' . $i, 0);
  1884. }
  1885. if ($add != 0) {
  1886. $i += $add;
  1887. if ($this->debug > 2) {
  1888. error_log('New LP - Items completed so far (+modifier): ' . $i, 0);
  1889. }
  1890. }
  1891. $text = '';
  1892. if ($i > $total_items) {
  1893. $i = $total_items;
  1894. }
  1895. if ($mode == '%') {
  1896. if ($total_items > 0) {
  1897. $percentage = ((float) $i / (float) $total_items) * 100;
  1898. } else {
  1899. $percentage = 0;
  1900. }
  1901. $percentage = number_format($percentage, 0);
  1902. $text = '%';
  1903. }
  1904. elseif ($mode == 'abs') {
  1905. $percentage = $i;
  1906. $text = '/' . $total_items;
  1907. }
  1908. return array (
  1909. $percentage,
  1910. $text
  1911. );
  1912. }
  1913. /**
  1914. * Gets the progress bar mode
  1915. * @return string The progress bar mode attribute
  1916. */
  1917. public function get_progress_bar_mode() {
  1918. if ($this->debug > 0) {
  1919. error_log('New LP - In learnpath::get_progress_bar_mode()', 0);
  1920. }
  1921. if (!empty ($this->progress_bar_mode)) {
  1922. return $this->progress_bar_mode;
  1923. } else {
  1924. return '%';
  1925. }
  1926. }
  1927. /**
  1928. * Gets the learnpath proximity (remote or local)
  1929. * @return string Learnpath proximity
  1930. */
  1931. public function get_proximity() {
  1932. if ($this->debug > 0) {
  1933. error_log('New LP - In learnpath::get_proximity()', 0);
  1934. }
  1935. if (!empty ($this->proximity)) {
  1936. return $this->proximity;
  1937. } else {
  1938. return '';
  1939. }
  1940. }
  1941. /**
  1942. * Gets the learnpath theme (remote or local)
  1943. * @return string Learnpath theme
  1944. */
  1945. public function get_theme() {
  1946. if ($this->debug > 0) {
  1947. error_log('New LP - In learnpath::get_theme()', 0);
  1948. }
  1949. if (!empty ($this->theme)) {
  1950. return $this->theme;
  1951. } else {
  1952. return '';
  1953. }
  1954. }
  1955. /**
  1956. * Gets the learnpath session id
  1957. * @return string Learnpath theme
  1958. */
  1959. public function get_lp_session_id() {
  1960. if ($this->debug > 0) {
  1961. error_log('New LP - In learnpath::get_lp_session_id()', 0);
  1962. }
  1963. if (!empty ($this->lp_session_id)) {
  1964. return $this->lp_session_id;
  1965. } else {
  1966. return 0;
  1967. }
  1968. }
  1969. /**
  1970. * Gets the learnpath image
  1971. * @return string Web URL of the LP image
  1972. */
  1973. public function get_preview_image() {
  1974. if ($this->debug > 0) {
  1975. error_log('New LP - In learnpath::get_preview_image()', 0);
  1976. }
  1977. if (!empty ($this->preview_image)) {
  1978. return $this->preview_image;
  1979. } else {
  1980. return '';
  1981. }
  1982. }
  1983. /**
  1984. * Gets the learnpath author
  1985. * @return string LP's author
  1986. */
  1987. public function get_author() {
  1988. if ($this->debug > 0) {
  1989. error_log('New LP - In learnpath::get_author()', 0);
  1990. }
  1991. if (!empty ($this->author)) {
  1992. return $this->author;
  1993. } else {
  1994. return '';
  1995. }
  1996. }
  1997. /**
  1998. * Generate a new prerequisites string for a given item. If this item was a sco and
  1999. * its prerequisites were strings (instead of IDs), then transform those strings into
  2000. * IDs, knowing that SCORM IDs are kept in the "ref" field of the lp_item table.
  2001. * Prefix all item IDs that end-up in the prerequisites string by "ITEM_" to use the
  2002. * same rule as the scorm_export() method
  2003. * @param integer Item ID
  2004. * @return string Prerequisites string ready for the export as SCORM
  2005. */
  2006. public function get_scorm_prereq_string($item_id) {
  2007. if ($this->debug > 0) {
  2008. error_log('New LP - In learnpath::get_scorm_prereq_string()', 0);
  2009. }
  2010. if (!is_object($this->items[$item_id])) {
  2011. return false;
  2012. }
  2013. $oItem = $this->items[$item_id];
  2014. $prereq = $oItem->get_prereq_string();
  2015. if (empty ($prereq)) {
  2016. return '';
  2017. }
  2018. if (preg_match('/^\d+$/', $prereq) && is_object($this->items[$prereq])) { // If the prerequisite is a simple integer ID and this ID exists as an item ID,
  2019. // then simply return it (with the ITEM_ prefix).
  2020. return 'ITEM_' . $prereq;
  2021. } else {
  2022. if (isset ($this->refs_list[$prereq])) {
  2023. // It's a simple string item from which the ID can be found in the refs list,
  2024. // so we can transform it directly to an ID for export.
  2025. return 'ITEM_' . $this->refs_list[$prereq];
  2026. } else {
  2027. // The last case, if it's a complex form, then find all the IDs (SCORM strings)
  2028. // and replace them, one by one, by the internal IDs (chamilo db)
  2029. // TODO: Modify the '*' replacement to replace the multiplier in front of it
  2030. // by a space as well.
  2031. $find = array (
  2032. '&',
  2033. '|',
  2034. '~',
  2035. '=',
  2036. '<>',
  2037. '{',
  2038. '}',
  2039. '*',
  2040. '(',
  2041. ')'
  2042. );
  2043. $replace = array (
  2044. ' ',
  2045. ' ',
  2046. ' ',
  2047. ' ',
  2048. ' ',
  2049. ' ',
  2050. ' ',
  2051. ' ',
  2052. ' ',
  2053. ' '
  2054. );
  2055. $prereq_mod = str_replace($find, $replace, $prereq);
  2056. $ids = split(' ', $prereq_mod);
  2057. foreach ($ids as $id) {
  2058. $id = trim($id);
  2059. if (isset ($this->refs_list[$id])) {
  2060. $prereq = preg_replace('/[^a-zA-Z_0-9](' . $id . ')[^a-zA-Z_0-9]/', 'ITEM_' . $this->refs_list[$id], $prereq);
  2061. }
  2062. }
  2063. error_log('New LP - In learnpath::get_scorm_prereq_string(): returning modified string: ' . $prereq, 0);
  2064. return $prereq;
  2065. }
  2066. }
  2067. }
  2068. /**
  2069. * Returns the XML DOM document's node
  2070. * @param resource Reference to a list of objects to search for the given ITEM_*
  2071. * @param string The identifier to look for
  2072. * @return mixed The reference to the element found with that identifier. False if not found
  2073. */
  2074. public function get_scorm_xml_node(& $children, $id) {
  2075. for ($i = 0; $i < $children->length; $i++) {
  2076. $item_temp = $children->item($i);
  2077. if ($item_temp->nodeName == 'item') {
  2078. if ($item_temp->getAttribute('identifier') == $id) {
  2079. return $item_temp;
  2080. }
  2081. }
  2082. $subchildren = $item_temp->childNodes;
  2083. if ($subchildren->length > 0) {
  2084. $val = $this->get_scorm_xml_node($subchildren, $id);
  2085. if (is_object($val)) {
  2086. return $val;
  2087. }
  2088. }
  2089. }
  2090. return false;
  2091. }
  2092. /**
  2093. * Returns a usable array of stats related to the current learnpath and user
  2094. * @return array Well-formatted array containing status for the current learnpath
  2095. */
  2096. public function get_stats() {
  2097. if ($this->debug > 0) {
  2098. error_log('New LP - In learnpath::get_stats()', 0);
  2099. }
  2100. // TODO
  2101. }
  2102. /**
  2103. * Static method. Can be re-implemented by children. Gives an array of statistics for
  2104. * the given course (for all learnpaths and all users)
  2105. * @param string Course code
  2106. * @return array Well-formatted array containing status for the course's learnpaths
  2107. */
  2108. public function get_stats_course($course) {
  2109. //if ($this->debug > 0) { error_log('New LP - In learnpath::get_stats_course()', 0); }
  2110. // TODO
  2111. }
  2112. /**
  2113. * Static method. Can be re-implemented by children. Gives an array of statistics for
  2114. * the given course and learnpath (for all users)
  2115. * @param string Course code
  2116. * @param integer Learnpath ID
  2117. * @return array Well-formatted array containing status for the specified learnpath
  2118. */
  2119. public function get_stats_lp($course, $lp) {
  2120. //if ($this->debug > 0) { error_log('New LP - In learnpath::get_stats_lp()', 0); }
  2121. // TODO
  2122. }
  2123. /**
  2124. * Static method. Can be re-implemented by children. Gives an array of statistics for
  2125. * the given course, learnpath and user.
  2126. * @param string Course code
  2127. * @param integer Learnpath ID
  2128. * @param integer User ID
  2129. * @return array Well-formatted array containing status for the specified learnpath and user
  2130. */
  2131. public function get_stats_lp_user($course, $lp, $user) {
  2132. //if ($this->debug > 0) { error_log('New LP - In learnpath::get_stats_lp_user()', 0); }
  2133. // TODO
  2134. }
  2135. /**
  2136. * Static method. Can be re-implemented by children. Gives an array of statistics for
  2137. * the given course and learnpath (for all users)
  2138. * @param string Course code
  2139. * @param integer User ID
  2140. * @return array Well-formatted array containing status for the user's learnpaths
  2141. */
  2142. public function get_stats_user($course, $user) {
  2143. //if ($this->debug > 0) { error_log('New LP - In learnpath::get_stats_user()', 0); }
  2144. // TODO
  2145. }
  2146. /**
  2147. * Gets the status list for all LP's items
  2148. * @return array Array of [index] => [item ID => current status]
  2149. */
  2150. public function get_items_status_list() {
  2151. if ($this->debug > 0) {
  2152. error_log('New LP - In learnpath::get_items_status_list()', 0);
  2153. }
  2154. $list = array ();
  2155. foreach ($this->ordered_items as $item_id) {
  2156. $list[] = array (
  2157. $item_id => $this->items[$item_id]->get_status()
  2158. );
  2159. }
  2160. return $list;
  2161. }
  2162. /**
  2163. * Return the number of interactions for the given learnpath Item View ID.
  2164. * This method can be used as static.
  2165. * @param integer Item View ID
  2166. * @return integer Number of interactions
  2167. */
  2168. public function get_interactions_count_from_db($lp_iv_id = 0) {
  2169. if (empty ($lp_iv_id)) {
  2170. return -1;
  2171. }
  2172. $table = Database :: get_course_table(TABLE_LP_IV_INTERACTION);
  2173. $sql = "SELECT count(*) FROM $table WHERE lp_iv_id = $lp_iv_id";
  2174. $res = Database::query($sql);
  2175. $row = Database :: fetch_array($res);
  2176. $num = $row[0];
  2177. return $num;
  2178. }
  2179. /**
  2180. * Return the interactions as an array for the given lp_iv_id.
  2181. * This method can be used as static.
  2182. * @param integer Learnpath Item View ID
  2183. * @return array
  2184. * @todo Transcode labels instead of switching to HTML (which requires to know the encoding of the LP)
  2185. */
  2186. public function get_iv_interactions_array($lp_iv_id = 0) {
  2187. $list = array ();
  2188. $table = Database :: get_course_table(TABLE_LP_IV_INTERACTION);
  2189. $sql = "SELECT * FROM $table WHERE lp_iv_id = $lp_iv_id ORDER BY order_id ASC";
  2190. $res = Database::query($sql);
  2191. $num = Database :: num_rows($res);
  2192. if ($num > 0) {
  2193. $list[] = array (
  2194. 'order_id' => api_htmlentities(get_lang('Order'), ENT_QUOTES),
  2195. 'id' => api_htmlentities(get_lang('InteractionID'), ENT_QUOTES),
  2196. 'type' => api_htmlentities(get_lang('Type'), ENT_QUOTES),
  2197. 'time' => api_htmlentities(get_lang('TimeFinished'), ENT_QUOTES),
  2198. 'correct_responses' => api_htmlentities(get_lang('CorrectAnswers'), ENT_QUOTES),
  2199. 'student_response' => api_htmlentities(get_lang('StudentResponse'), ENT_QUOTES),
  2200. 'result' => api_htmlentities(get_lang('Result'), ENT_QUOTES),
  2201. 'latency' => api_htmlentities(get_lang('LatencyTimeSpent'), ENT_QUOTES)
  2202. );
  2203. while ($row = Database :: fetch_array($res)) {
  2204. $list[] = array (
  2205. 'order_id' => ($row['order_id'] + 1),
  2206. 'id' => urldecode($row['interaction_id']), //urldecode because they often have %2F or stuff like that
  2207. 'type' => $row['interaction_type'],
  2208. 'time' => $row['completion_time'],
  2209. //'correct_responses' => $row['correct_responses'],
  2210. 'correct_responses' => '', // Hide correct responses from students.
  2211. 'student_response' => $row['student_response'],
  2212. 'result' => $row['result'],
  2213. 'latency' => $row['latency']
  2214. );
  2215. }
  2216. }
  2217. return $list;
  2218. }
  2219. /**
  2220. * Return the number of objectives for the given learnpath Item View ID.
  2221. * This method can be used as static.
  2222. * @param integer Item View ID
  2223. * @return integer Number of objectives
  2224. */
  2225. public function get_objectives_count_from_db($lp_iv_id = 0) {
  2226. if (empty ($lp_iv_id)) {
  2227. return -1;
  2228. }
  2229. $table = Database :: get_course_table(TABLE_LP_IV_OBJECTIVE);
  2230. $sql = "SELECT count(*) FROM $table WHERE lp_iv_id = $lp_iv_id";
  2231. $res = Database::query($sql);
  2232. $row = Database :: fetch_array($res);
  2233. $num = $row[0];
  2234. return $num;
  2235. }
  2236. /**
  2237. * Return the objectives as an array for the given lp_iv_id.
  2238. * This method can be used as static.
  2239. * @param integer Learnpath Item View ID
  2240. * @return array
  2241. * @todo Translate labels
  2242. */
  2243. public function get_iv_objectives_array($lp_iv_id = 0) {
  2244. $list = array();
  2245. $table = Database :: get_course_table(TABLE_LP_IV_OBJECTIVE);
  2246. $sql = "SELECT * FROM $table WHERE lp_iv_id = $lp_iv_id ORDER BY order_id ASC";
  2247. $res = Database::query($sql);
  2248. $num = Database :: num_rows($res);
  2249. if ($num > 0) {
  2250. $list[] = array (
  2251. 'order_id' => api_htmlentities(get_lang('Order'), ENT_QUOTES),
  2252. 'objective_id' => api_htmlentities(get_lang('ObjectiveID'), ENT_QUOTES),
  2253. 'score_raw' => api_htmlentities(get_lang('ObjectiveRawScore'), ENT_QUOTES),
  2254. 'score_max' => api_htmlentities(get_lang('ObjectiveMaxScore'), ENT_QUOTES),
  2255. 'score_min' => api_htmlentities(get_lang('ObjectiveMinScore'), ENT_QUOTES),
  2256. 'status' => api_htmlentities(get_lang('ObjectiveStatus'), ENT_QUOTES)
  2257. );
  2258. while ($row = Database :: fetch_array($res)) {
  2259. $list[] = array (
  2260. 'order_id' => ($row['order_id'] + 1),
  2261. 'objective_id' => urldecode($row['objective_id']), // urldecode() because they often have %2F or stuff like that.
  2262. 'score_raw' => $row['score_raw'],
  2263. 'score_max' => $row['score_max'],
  2264. 'score_min' => $row['score_min'],
  2265. 'status' => $row['status']
  2266. );
  2267. }
  2268. }
  2269. return $list;
  2270. }
  2271. /**
  2272. * Generate and return the table of contents for this learnpath. The (flat) table returned can be
  2273. * used by get_html_toc() to be ready to display
  2274. * @return array TOC as a table with 4 elements per row: title, link, status and level
  2275. */
  2276. public function get_toc() {
  2277. if ($this->debug > 0) {
  2278. error_log('New LP - In learnpath::get_toc()', 0);
  2279. }
  2280. $toc = array ();
  2281. //echo "<pre>".print_r($this->items,true)."</pre>";
  2282. foreach ($this->ordered_items as $item_id) {
  2283. if ($this->debug > 2) {
  2284. error_log('New LP - learnpath::get_toc(): getting info for item ' . $item_id, 0);
  2285. }
  2286. // TODO: Change this link generation and use new function instead.
  2287. $toc[] = array (
  2288. 'id' => $item_id,
  2289. 'title' => $this->items[$item_id]->get_title(),
  2290. //'link' => get_addedresource_link_in_learnpath('document', $item_id, 1),
  2291. 'status' => $this->items[$item_id]->get_status(),
  2292. 'level' => $this->items[$item_id]->get_level(),
  2293. 'type' => $this->items[$item_id]->get_type(),
  2294. 'description' => $this->items[$item_id]->get_description(),
  2295. 'path' => $this->items[$item_id]->get_path(),
  2296. );
  2297. }
  2298. if ($this->debug > 2) {
  2299. error_log('New LP - In learnpath::get_toc() - TOC array: ' . print_r($toc, true), 0);
  2300. }
  2301. return $toc;
  2302. }
  2303. /**
  2304. * Generate and return the table of contents for this learnpath. The JS
  2305. * table returned is used inside of scorm_api.php
  2306. * @return string A JS array vairiable construction
  2307. */
  2308. public function get_items_details_as_js($varname = 'olms.lms_item_types') {
  2309. if ($this->debug > 0) {
  2310. error_log('New LP - In learnpath::get_items_details_as_js()', 0);
  2311. }
  2312. $toc = $varname.' = new Array();';
  2313. //echo "<pre>".print_r($this->items,true)."</pre>";
  2314. foreach ($this->ordered_items as $item_id) {
  2315. if ($this->debug > 2) {
  2316. error_log('New LP - learnpath::get_items_details_as_js(): getting info for item ' . $item_id, 0);
  2317. }
  2318. $toc.= $varname."['i$item_id'] = '".$this->items[$item_id]->get_type()."';";
  2319. }
  2320. if ($this->debug > 2) {
  2321. error_log('New LP - In learnpath::get_items_details_as_js() - TOC array: ' . print_r($toc, true), 0);
  2322. }
  2323. return $toc;
  2324. }
  2325. /**
  2326. * Gets the learning path type
  2327. * @param boolean Return the name? If false, return the ID. Default is false.
  2328. * @return mixed Type ID or name, depending on the parameter
  2329. */
  2330. public function get_type($get_name = false) {
  2331. $res = false;
  2332. if ($this->debug > 0) {
  2333. error_log('New LP - In learnpath::get_type()', 0);
  2334. }
  2335. if (!empty ($this->type)) {
  2336. if ($get_name) {
  2337. // Get it from the lp_type table in main db.
  2338. } else {
  2339. $res = $this->type;
  2340. }
  2341. }
  2342. if ($this->debug > 2) {
  2343. error_log('New LP - In learnpath::get_type() - Returning ' . ($res ? $res : 'false'), 0);
  2344. }
  2345. return $res;
  2346. }
  2347. /**
  2348. * Gets the learning path type as static method
  2349. * @param boolean Return the name? If false, return the ID. Default is false.
  2350. * @return mixed Type ID or name, depending on the parameter
  2351. */
  2352. public function get_type_static($lp_id = 0) {
  2353. $tbl_lp = Database :: get_course_table(TABLE_LP_MAIN);
  2354. $sql = "SELECT lp_type FROM $tbl_lp WHERE id = '" . $lp_id . "'";
  2355. $res = Database::query($sql);
  2356. if ($res === false) {
  2357. return null;
  2358. }
  2359. if (Database :: num_rows($res) <= 0) {
  2360. return null;
  2361. }
  2362. $row = Database :: fetch_array($res);
  2363. return $row['lp_type'];
  2364. }
  2365. /**
  2366. * Gets a flat list of item IDs ordered for display (level by level ordered by order_display)
  2367. * This method can be used as abstract and is recursive
  2368. * @param integer Learnpath ID
  2369. * @param integer Parent ID of the items to look for
  2370. * @return mixed Ordered list of item IDs or false on error
  2371. */
  2372. public function get_flat_ordered_items_list($lp, $parent = 0) {
  2373. //if ($this->debug > 0) { error_log('New LP - In learnpath::get_flat_ordered_items_list('.$lp.','.$parent.')', 0); }
  2374. $list = array();
  2375. if (empty ($lp)) {
  2376. return false;
  2377. }
  2378. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  2379. $sql = "SELECT * FROM $tbl_lp_item WHERE lp_id = $lp AND parent_item_id = $parent ORDER BY display_order";
  2380. $res = Database::query($sql);
  2381. while ($row = Database :: fetch_array($res)) {
  2382. $sublist = learnpath :: get_flat_ordered_items_list($lp, $row['id']);
  2383. $list[] = $row['id'];
  2384. foreach ($sublist as $item) {
  2385. $list[] = $item;
  2386. }
  2387. }
  2388. return $list;
  2389. }
  2390. /**
  2391. * Uses the table generated by get_toc() and returns an HTML-formatted string ready to display
  2392. * @return string HTML TOC ready to display
  2393. */
  2394. public function get_html_toc() {
  2395. $is_allowed_to_edit = api_is_allowed_to_edit(null, true);
  2396. $charset = api_get_system_encoding();
  2397. $display_action_links_with_icons = false;
  2398. if ($this->debug > 0) {
  2399. error_log('New LP - In learnpath::get_html_toc()', 0);
  2400. }
  2401. $list = $this->get_toc();
  2402. //echo $this->current;
  2403. //$parent = $this->items[$this->current]->get_parent();
  2404. //if (empty($parent)) { $parent = $this->ordered_items[$this->items[$this->current]->get_previous_index()]; }
  2405. $html = '<div id="scorm_title" class="scorm_title"><div class="scorm_title_text">' . Security::remove_XSS($this->get_name()) . '</div></div>';
  2406. // Build, display.
  2407. if ($is_allowed_to_edit) {
  2408. $gradebook = Security :: remove_XSS($_GET['gradebook']);
  2409. //var_dump($this->get_lp_session_id());
  2410. if ($this->get_lp_session_id() == api_get_session_id()) {
  2411. $html .= '<div id="actions_lp" class="actions_lp">';
  2412. if ($display_action_links_with_icons) {
  2413. $html .= '<div style = "text-align:center;">';
  2414. $html .= "<a href='lp_controller.php?" . api_get_cidreq() . "&amp;action=build&amp;lp_id=" . $this->lp_id . "' target='_parent'>" . Display :: return_icon('learnpath_build.gif', get_lang('Build')) . ' ' . get_lang('Build') . "</a>";
  2415. $html .= "<a href='lp_controller.php?" . api_get_cidreq() . "&amp;action=admin_view&amp;lp_id=" . $this->lp_id . "' target='_parent'>" . Display :: return_icon('learnpath_organize.gif', get_lang('BasicOverview')) . ' ' . get_lang('BasicOverview') . "</a>";
  2416. $html .= '<span>' . Display :: return_icon('learnpath_view_na.gif', get_lang('Display')) . ' <b>' . get_lang('Display') . '</b></span><br />';
  2417. $html .= '<a href="lp_controller.php?' . api_get_cidreq() . '">'. get_lang('ReturnToLPList') . '</a>';
  2418. $html .= '</div>';
  2419. } else {
  2420. $html .= '<div style = "text-align:center;">';
  2421. $html .= "<a href='lp_controller.php?" . api_get_cidreq() . "&amp;gradebook=$gradebook&amp;action=build&amp;lp_id=" . $this->lp_id . "' target='_parent'>" . get_lang('Build') . "</a>";
  2422. $html .= "<a href='lp_controller.php?" . api_get_cidreq() . "&amp;action=admin_view&amp;lp_id=" . $this->lp_id . "' target='_parent'>" . get_lang('BasicOverview') . "</a>";
  2423. $html .= '<span><b>' . get_lang('Display') . '</b></span><br />';
  2424. $html .= '<a href="lp_controller.php?' . api_get_cidreq() . '">'. get_lang('ReturnToLPList') . '</a>';
  2425. $html .= '</div>';
  2426. }
  2427. $html .= '</div>';
  2428. }
  2429. }
  2430. $html .= '<div id="inner_lp_toc" class="inner_lp_toc">' . "\n";
  2431. require_once 'resourcelinker.inc.php';
  2432. // Temporary variables.
  2433. $mycurrentitemid = $this->get_current_item_id();
  2434. $color_counter = 0;
  2435. $i = 0;
  2436. foreach ($list as $item) {
  2437. if ($this->debug > 2) {
  2438. error_log('New LP - learnpath::get_html_toc(): using item ' . $item['id'], 0);
  2439. }
  2440. // TODO: Complete this.
  2441. $icon_name = array (
  2442. 'not attempted' => '../img/notattempted.gif',
  2443. 'incomplete' => '../img/incomplete.gif',
  2444. 'failed' => '../img/failed.gif',
  2445. 'completed' => '../img/completed.gif',
  2446. 'passed' => '../img/passed.gif',
  2447. 'succeeded' => '../img/succeeded.gif',
  2448. 'browsed' => '../img/completed.gif'
  2449. );
  2450. $style = 'scorm_item';
  2451. $scorm_color_background = 'scorm_item';
  2452. $style_item = 'scorm_item';
  2453. $current = false;
  2454. if ($item['id'] == $this->current) {
  2455. $style = 'scorm_item_highlight';
  2456. $scorm_color_background = 'scorm_item_highlight';
  2457. } else
  2458. if ($color_counter % 2 == 0) {
  2459. $scorm_color_background = 'scorm_item_1';
  2460. } else {
  2461. $scorm_color_background = 'scorm_item_2';
  2462. }
  2463. if ($scorm_color_background != '') {
  2464. $html .= '<div id="toc_' . $item['id'] . '" class="' . $scorm_color_background . '">';
  2465. }
  2466. // The anchor will let us center the TOC on the currently viewed item &^D
  2467. if ($item['type'] != 'dokeos_module' && $item['type'] != 'dokeos_chapter') {
  2468. $html .= '<a name="atoc_' . $item['id'] . '" />';
  2469. $html .= '<div class="' . $style_item . '" style="padding-left: ' . ($item['level'] * 1.5) . 'em; padding-right:' . ($item['level'] / 2) . 'em" title="' . $item['description'] . '" >';
  2470. } else {
  2471. $html .= '<div class="' . $style_item . '" style="padding-left: ' . ($item['level'] * 2) . 'em; padding-right:' . ($item['level'] * 1.5) . 'em" title="' . $item['description'] . '" >';
  2472. }
  2473. $title = $item['title'];
  2474. if (empty ($title)) {
  2475. $title = rl_get_resource_name(api_get_course_id(), $this->get_id(), $item['id']);
  2476. }
  2477. $title = Security::remove_XSS($title);
  2478. if ($item['type'] != 'dokeos_chapter' && $item['type'] != 'dir' && $item['type'] != 'dokeos_module') {
  2479. //$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>" ;
  2480. $url = $this->get_link('http', $item['id']);
  2481. //$html .= '<a href="'.$url.'" target="content_name" onclick="top.load_item('.$item['id'].',\''.$url.'\');">'.$title.'</a>' ;
  2482. //$html .= '<a href="" onclick="top.load_item('.$item['id'].',\''.$url.'\');return false;">'.$title.'</a>' ;
  2483. //<img align="absbottom" width="13" height="13" src="../img/lp_document.png">&nbsp;background:#aaa;
  2484. $html .= '<a href="" onclick="switch_item(' .
  2485. $mycurrentitemid . ',' .
  2486. $item['id'] . ');' .
  2487. 'return false;" >' . stripslashes($title) . '</a>';
  2488. } elseif ($item['type'] == 'dokeos_module' || $item['type'] == 'dokeos_chapter') {
  2489. $html .= "<img align='absbottom' width='13' height='13' src='../img/lp_dokeos_module.png'>&nbsp;" . stripslashes($title);
  2490. } elseif ($item['type'] == 'dir') {
  2491. $html .= stripslashes($title);
  2492. }
  2493. $tbl_track_e_exercises = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
  2494. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  2495. $user_id = api_get_user_id();
  2496. $course_id = api_get_course_id();
  2497. $sql = "SELECT path FROM $tbl_track_e_exercises, $tbl_lp_item
  2498. WHERE path = '" . $item['path'] . "' AND exe_user_id = '$user_id' AND exe_cours_id = '$course_id' AND path = exe_exo_id AND status <> 'incomplete'";
  2499. $result = Database::query($sql);
  2500. $count = Database :: num_rows($result);
  2501. if ($item['type'] == 'quiz') {
  2502. if ($item['status'] == 'completed') {
  2503. $html .= "&nbsp;<img id='toc_img_" . $item['id'] . "' src='" . $icon_name[$item['status']] . "' alt='" . substr($item['status'], 0, 1) . "' width='12' height='12' />";
  2504. }
  2505. } else {
  2506. if ($item['type'] != 'dokeos_chapter' && $item['type'] != 'dokeos_module' && $item['type'] != 'dir') {
  2507. $html .= "&nbsp;<img id='toc_img_" . $item['id'] . "' src='" . $icon_name[$item['status']] . "' alt='" . substr($item['status'], 0, 1) . "' width='12' height='12' />";
  2508. }
  2509. }
  2510. $html .= "</div>";
  2511. if ($scorm_color_background != '') {
  2512. $html .= '</div>';
  2513. }
  2514. $color_counter++;
  2515. }
  2516. $html .= "</div>\n";
  2517. return $html;
  2518. }
  2519. /**
  2520. * Gets the learnpath maker name - generally the editor's name
  2521. * @return string Learnpath maker name
  2522. */
  2523. public function get_maker() {
  2524. if ($this->debug > 0) {
  2525. error_log('New LP - In learnpath::get_maker()', 0);
  2526. }
  2527. if (!empty ($this->maker)) {
  2528. return $this->maker;
  2529. } else {
  2530. return '';
  2531. }
  2532. }
  2533. /**
  2534. * Gets the user-friendly message stored in $this->message
  2535. * @return string Message
  2536. */
  2537. public function get_message() {
  2538. if ($this->debug > 0) {
  2539. error_log('New LP - In learnpath::get_message()', 0);
  2540. }
  2541. return $this->message;
  2542. }
  2543. /**
  2544. * Gets the learnpath name/title
  2545. * @return string Learnpath name/title
  2546. */
  2547. public function get_name() {
  2548. if ($this->debug > 0) {
  2549. error_log('New LP - In learnpath::get_name()', 0);
  2550. }
  2551. if (!empty ($this->name)) {
  2552. return $this->name;
  2553. } else {
  2554. return 'N/A';
  2555. }
  2556. }
  2557. /**
  2558. * Gets a link to the resource from the present location, depending on item ID.
  2559. * @param string Type of link expected
  2560. * @param integer Learnpath item ID
  2561. * @return string Link to the lp_item resource
  2562. */
  2563. public function get_link($type = 'http', $item_id = null) {
  2564. if ($this->debug > 0) {
  2565. error_log('New LP - In learnpath::get_link(' . $type . ',' . $item_id . ')', 0);
  2566. }
  2567. if (empty($item_id)) {
  2568. if ($this->debug > 2) {
  2569. error_log('New LP - In learnpath::get_link() - no item id given in learnpath::get_link(), using current: ' . $this->get_current_item_id(), 0);
  2570. }
  2571. $item_id = $this->get_current_item_id();
  2572. }
  2573. if (empty ($item_id)) {
  2574. if ($this->debug > 2) {
  2575. error_log('New LP - In learnpath::get_link() - no current item id found in learnpath object', 0);
  2576. }
  2577. //still empty, this means there was no item_id given and we are not in an object context or
  2578. //the object property is empty, return empty link
  2579. $item_id = $this->first();
  2580. return '';
  2581. }
  2582. $file = '';
  2583. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  2584. $lp_item_table = Database :: get_course_table(TABLE_LP_ITEM);
  2585. $lp_item_view_table = Database :: get_course_table(TABLE_LP_ITEM_VIEW);
  2586. $item_id = Database::escape_string($item_id);
  2587. $sel = "SELECT l.lp_type as ltype, l.path as lpath, li.item_type as litype, li.path as lipath, li.parameters as liparams " .
  2588. "FROM $lp_table l, $lp_item_table li WHERE li.id = $item_id AND li.lp_id = l.id";
  2589. if ($this->debug > 2) {
  2590. error_log('New LP - In learnpath::get_link() - selecting item ' . $sel, 0);
  2591. }
  2592. $res = Database::query($sel);
  2593. if (Database :: num_rows($res) > 0) {
  2594. $row = Database :: fetch_array($res);
  2595. //var_dump($row);
  2596. $lp_type = $row['ltype'];
  2597. $lp_path = $row['lpath'];
  2598. $lp_item_type = $row['litype'];
  2599. $lp_item_path = $row['lipath'];
  2600. $lp_item_params = $row['liparams'];
  2601. if (empty ($lp_item_params) && strpos($lp_item_path, '?') !== false) {
  2602. list ($lp_item_path, $lp_item_params) = explode('?', $lp_item_path);
  2603. }
  2604. //$lp_item_params = '?'.$lp_item_params;
  2605. //add ? if none - left commented to give freedom to scorm implementation
  2606. //if(substr($lp_item_params,0,1)!='?'){
  2607. // $lp_item_params = '?'.$lp_item_params;
  2608. //}
  2609. $sys_course_path = api_get_path(SYS_COURSE_PATH) . api_get_course_path();
  2610. if ($type == 'http') {
  2611. $course_path = api_get_path(WEB_COURSE_PATH) . api_get_course_path(); //web path
  2612. } else {
  2613. $course_path = $sys_course_path; //system path
  2614. }
  2615. // Fixed issue BT#1272 - If the item type is a Chamilo Item (quiz, link, etc), then change the lp type to thread it as a normal Chamilo LP not a SCO.
  2616. if (in_array($lp_item_type, array('quiz', 'document', 'link', 'forum', 'thread', 'student_publication'))) {
  2617. $lp_type = 1;
  2618. }
  2619. // Now go through the specific cases to get the end of the path.
  2620. // @todo Use constants instead of int values.
  2621. switch ($lp_type) {
  2622. case 1 :
  2623. if ($lp_item_type == 'dokeos_chapter') {
  2624. $file = 'lp_content.php?type=dir';
  2625. } else {
  2626. require_once 'resourcelinker.inc.php';
  2627. $file = rl_get_resource_link_for_learnpath(api_get_course_id(), $this->get_id(), $item_id);
  2628. // check how much attempts of a exercise exits in lp
  2629. $lp_item_id = $this->get_current_item_id();
  2630. $lp_view_id = $this->get_view_id();
  2631. $prevent_reinit = $this->items[$this->current]->get_prevent_reinit();
  2632. $list = $this->get_toc();
  2633. $type_quiz = false;
  2634. foreach ($list as $toc) {
  2635. if ($toc['id'] == $lp_item_id && ($toc['type'] == 'quiz')) {
  2636. $type_quiz = true;
  2637. }
  2638. }
  2639. if ($type_quiz) {
  2640. $lp_item_id = Database :: escape_string($lp_item_id);
  2641. $lp_view_id = Database :: escape_string($lp_view_id);
  2642. $sql = "SELECT count(*) FROM $lp_item_view_table WHERE lp_item_id='" . (int) $lp_item_id . "' AND lp_view_id ='" . (int) $lp_view_id . "' AND status='completed'";
  2643. $result = Database::query($sql);
  2644. $row_count = Database :: fetch_row($result);
  2645. $count_item_view = (int) $row_count[0];
  2646. $not_multiple_attempt = 0;
  2647. if ($prevent_reinit === 1 && $count_item_view > 0) {
  2648. $not_multiple_attempt = 1;
  2649. }
  2650. $file .= '&not_multiple_attempt=' . $not_multiple_attempt;
  2651. }
  2652. $tmp_array = explode('/', $file);
  2653. $document_name = $tmp_array[count($tmp_array) - 1];
  2654. if (strpos($document_name, '_DELETED_')) {
  2655. $file = 'blank.php?error=document_deleted';
  2656. }
  2657. }
  2658. break;
  2659. case 2 :
  2660. if ($this->debug > 2) {
  2661. error_log('New LP - In learnpath::get_link() ' . __LINE__ . ' - Item type: ' . $lp_item_type, 0);
  2662. }
  2663. if ($lp_item_type != 'dir') {
  2664. // Quite complex here:
  2665. // We want to make sure 'http://' (and similar) links can
  2666. // be loaded as is (withouth the Chamilo path in front) but
  2667. // some contents use this form: resource.htm?resource=http://blablabla
  2668. // which means we have to find a protocol at the path's start, otherwise
  2669. // it should not be considered as an external URL.
  2670. //if ($this->prerequisites_match($item_id)) {
  2671. if (preg_match('#^[a-zA-Z]{2,5}://#', $lp_item_path) != 0) {
  2672. if ($this->debug > 2) {
  2673. error_log('New LP - In learnpath::get_link() ' . __LINE__ . ' - Found match for protocol in ' . $lp_item_path, 0);
  2674. }
  2675. // Distant url, return as is.
  2676. $file = $lp_item_path;
  2677. } else {
  2678. if ($this->debug > 2) {
  2679. error_log('New LP - In learnpath::get_link() ' . __LINE__ . ' - No starting protocol in ' . $lp_item_path, 0);
  2680. }
  2681. // Prevent getting untranslatable urls.
  2682. $lp_item_path = preg_replace('/%2F/', '/', $lp_item_path);
  2683. $lp_item_path = preg_replace('/%3A/', ':', $lp_item_path);
  2684. // Prepare the path.
  2685. $file = $course_path . '/scorm/' . $lp_path . '/' . $lp_item_path;
  2686. // TODO: Fix this for urls with protocol header.
  2687. $file = str_replace('//', '/', $file);
  2688. $file = str_replace(':/', '://', $file);
  2689. if (substr($lp_path, -1) == '/') {
  2690. $lp_path = substr($lp_path, 0, -1);
  2691. }
  2692. if (!is_file(realpath($sys_course_path . '/scorm/' . $lp_path . '/' . $lp_item_path))) {
  2693. // if file not found.
  2694. $decoded = html_entity_decode($lp_item_path);
  2695. list ($decoded) = explode('?', $decoded);
  2696. if (!is_file(realpath($sys_course_path . '/scorm/' . $lp_path . '/' . $decoded))) {
  2697. require_once 'resourcelinker.inc.php';
  2698. $file = rl_get_resource_link_for_learnpath(api_get_course_id(), $this->get_id(), $item_id);
  2699. if (empty($file)) {
  2700. $file = 'blank.php?error=document_not_found';
  2701. } else {
  2702. $tmp_array = explode('/', $file);
  2703. $document_name = $tmp_array[count($tmp_array) - 1];
  2704. if (strpos($document_name, '_DELETED_')) {
  2705. $file = 'blank.php?error=document_deleted';
  2706. } else {
  2707. $file = 'blank.php?error=document_not_found';
  2708. }
  2709. }
  2710. } else {
  2711. $file = $course_path . '/scorm/' . $lp_path . '/' . $decoded;
  2712. }
  2713. }
  2714. }
  2715. //}else{
  2716. //prerequisites did not match
  2717. //$file = 'blank.php';
  2718. //}
  2719. // We want to use parameters if they were defined in the imsmanifest.
  2720. if ($file != 'blank.php') {
  2721. $file .= (strstr($file, '?') === false ? '?' : '') . $lp_item_params;
  2722. }
  2723. } else {
  2724. $file = 'lp_content.php?type=dir';
  2725. }
  2726. break;
  2727. case 3 :
  2728. if ($this->debug > 2) {
  2729. error_log('New LP - In learnpath::get_link() ' . __LINE__ . ' - Item type: ' . $lp_item_type, 0);
  2730. }
  2731. // Formatting AICC HACP append URL.
  2732. $aicc_append = '?aicc_sid=' . urlencode(session_id()) . '&aicc_url=' . urlencode(api_get_path(WEB_CODE_PATH) . 'newscorm/aicc_hacp.php') . '&';
  2733. if ($lp_item_type != 'dir') {
  2734. // Quite complex here:
  2735. // We want to make sure 'http://' (and similar) links can
  2736. // be loaded as is (withouth the Chamilo path in front) but
  2737. // some contents use this form: resource.htm?resource=http://blablabla
  2738. // which means we have to find a protocol at the path's start, otherwise
  2739. // it should not be considered as an external URL.
  2740. if (preg_match('#^[a-zA-Z]{2,5}://#', $lp_item_path) != 0) {
  2741. if ($this->debug > 2) {
  2742. error_log('New LP - In learnpath::get_link() ' . __LINE__ . ' - Found match for protocol in ' . $lp_item_path, 0);
  2743. }
  2744. // Distant url, return as is.
  2745. $file = $lp_item_path;
  2746. // Enabled and modified by Ivan Tcholakov, 16-OCT-2008.
  2747. /*
  2748. if (stristr($file,'<servername>') !== false) {
  2749. $file = str_replace('<servername>', $course_path.'/scorm/'.$lp_path.'/', $lp_item_path);
  2750. }
  2751. */
  2752. if (stripos($file, '<servername>') !== false) {
  2753. //$file = str_replace('<servername>',$course_path.'/scorm/'.$lp_path.'/',$lp_item_path);
  2754. $web_course_path = str_replace('https://', '', str_replace('http://', '', $course_path));
  2755. $file = str_replace('<servername>', $web_course_path . '/scorm/' . $lp_path, $lp_item_path);
  2756. }
  2757. //
  2758. $file .= $aicc_append;
  2759. } else {
  2760. if ($this->debug > 2) {
  2761. error_log('New LP - In learnpath::get_link() ' . __LINE__ . ' - No starting protocol in ' . $lp_item_path, 0);
  2762. }
  2763. // Prevent getting untranslatable urls.
  2764. $lp_item_path = preg_replace('/%2F/', '/', $lp_item_path);
  2765. $lp_item_path = preg_replace('/%3A/', ':', $lp_item_path);
  2766. // Prepare the path - lp_path might be unusable because it includes the "aicc" subdir name.
  2767. $file = $course_path . '/scorm/' . $lp_path . '/' . $lp_item_path;
  2768. // TODO: Fix this for urls with protocol header.
  2769. $file = str_replace('//', '/', $file);
  2770. $file = str_replace(':/', '://', $file);
  2771. $file .= $aicc_append;
  2772. }
  2773. } else {
  2774. $file = 'lp_content.php?type=dir';
  2775. }
  2776. break;
  2777. case 4 :
  2778. break;
  2779. default :
  2780. break;
  2781. }
  2782. }
  2783. if ($this->debug > 2) {
  2784. error_log('New LP - In learnpath::get_link() - returning "' . $file . '" from get_link', 0);
  2785. }
  2786. return $file;
  2787. }
  2788. /**
  2789. * Gets the latest usable view or generate a new one
  2790. * @param integer Optional attempt number. If none given, takes the highest from the lp_view table
  2791. * @return integer DB lp_view id
  2792. */
  2793. public function get_view($attempt_num = 0) {
  2794. if ($this->debug > 0) {
  2795. error_log('New LP - In learnpath::get_view()', 0);
  2796. }
  2797. $search = '';
  2798. // Use $attempt_num to enable multi-views management (disabled so far).
  2799. if ($attempt_num != 0 AND intval(strval($attempt_num)) == $attempt_num) {
  2800. $search = 'AND view_count = ' . $attempt_num;
  2801. }
  2802. // When missing $attempt_num, search for a unique lp_view record for this lp and user.
  2803. $lp_view_table = Database :: get_course_table(TABLE_LP_VIEW);
  2804. $sql = "SELECT id, view_count FROM $lp_view_table " .
  2805. "WHERE lp_id = " . $this->get_id() . " " .
  2806. "AND user_id = " . $this->get_user_id() . " " .
  2807. $search .
  2808. " ORDER BY view_count DESC";
  2809. $res = Database::query($sql);
  2810. if (Database :: num_rows($res) > 0) {
  2811. $row = Database :: fetch_array($res);
  2812. $this->lp_view_id = $row['id'];
  2813. } else {
  2814. // There is no database record, create one.
  2815. $sql = "INSERT INTO $lp_view_table(lp_id,user_id,view_count)" .
  2816. "VALUES (" . $this->get_id() . "," . $this->get_user_id() . ",1)";
  2817. $res = Database::query($sql);
  2818. $id = Database :: insert_id();
  2819. $this->lp_view_id = $id;
  2820. }
  2821. return $this->lp_view_id;
  2822. }
  2823. /**
  2824. * Gets the current view id
  2825. * @return integer View ID (from lp_view)
  2826. */
  2827. public function get_view_id() {
  2828. if ($this->debug > 0) {
  2829. error_log('New LP - In learnpath::get_view_id()', 0);
  2830. }
  2831. if (!empty ($this->lp_view_id)) {
  2832. return $this->lp_view_id;
  2833. } else {
  2834. return 0;
  2835. }
  2836. }
  2837. /**
  2838. * Gets the update queue
  2839. * @return array Array containing IDs of items to be updated by JavaScript
  2840. */
  2841. public function get_update_queue() {
  2842. if ($this->debug > 0) {
  2843. error_log('New LP - In learnpath::get_update_queue()', 0);
  2844. }
  2845. return $this->update_queue;
  2846. }
  2847. /**
  2848. * Gets the user ID
  2849. * @return integer User ID
  2850. */
  2851. public function get_user_id() {
  2852. if ($this->debug > 0) {
  2853. error_log('New LP - In learnpath::get_user_id()', 0);
  2854. }
  2855. if (!empty ($this->user_id)) {
  2856. return $this->user_id;
  2857. } else {
  2858. return false;
  2859. }
  2860. }
  2861. /**
  2862. * Checks if any of the items has an audio element attached
  2863. * @return bool True or false
  2864. */
  2865. public function has_audio() {
  2866. if ($this->debug > 1) {
  2867. error_log('New LP - In learnpath::has_audio()', 0);
  2868. }
  2869. $has = false;
  2870. foreach ($this->items as $i => $item) {
  2871. if (!empty ($this->items[$i]->audio)) {
  2872. $has = true;
  2873. break;
  2874. }
  2875. }
  2876. return $has;
  2877. }
  2878. /**
  2879. * Logs a message into a file
  2880. * @param string Message to log
  2881. * @return boolean True on success, false on error or if msg empty
  2882. */
  2883. public function log($msg) {
  2884. if ($this->debug > 0) {
  2885. error_log('New LP - In learnpath::log()', 0);
  2886. }
  2887. // TODO
  2888. $this->error .= $msg . "\n";
  2889. return true;
  2890. }
  2891. /**
  2892. * Moves an item up and down at its level
  2893. * @param integer Item to move up and down
  2894. * @param string Direction 'up' or 'down'
  2895. * @return integer New display order, or false on error
  2896. */
  2897. public function move_item($id, $direction) {
  2898. if ($this->debug > 0) {
  2899. error_log('New LP - In learnpath::move_item(' . $id . ',' . $direction . ')', 0);
  2900. }
  2901. if (empty ($id) or empty ($direction)) {
  2902. return false;
  2903. }
  2904. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  2905. $sql_sel = "
  2906. SELECT *
  2907. FROM " . $tbl_lp_item . "
  2908. WHERE id = " . $id;
  2909. $res_sel = Database::query($sql_sel);
  2910. // Check if elem exists.
  2911. if (Database :: num_rows($res_sel) < 1) {
  2912. return false;
  2913. }
  2914. // Gather data.
  2915. $row = Database :: fetch_array($res_sel);
  2916. $previous = $row['previous_item_id'];
  2917. $next = $row['next_item_id'];
  2918. $display = $row['display_order'];
  2919. $parent = $row['parent_item_id'];
  2920. $lp = $row['lp_id'];
  2921. // Update the item (switch with previous/next one).
  2922. switch ($direction) {
  2923. case 'up' :
  2924. if ($this->debug > 2) {
  2925. error_log('Movement up detected', 0);
  2926. }
  2927. if ($display <= 1) { /*do nothing*/
  2928. } else {
  2929. $sql_sel2 = "SELECT *
  2930. FROM $tbl_lp_item
  2931. WHERE id = $previous";
  2932. if ($this->debug > 2) {
  2933. error_log('Selecting previous: ' . $sql_sel2, 0);
  2934. }
  2935. $res_sel2 = Database::query($sql_sel2);
  2936. if (Database :: num_rows($res_sel2) < 1) {
  2937. $previous_previous = 0;
  2938. }
  2939. // Gather data.
  2940. $row2 = Database :: fetch_array($res_sel2);
  2941. $previous_previous = $row2['previous_item_id'];
  2942. // Update previous_previous item (switch "next" with current).
  2943. if ($previous_previous != 0) {
  2944. $sql_upd2 = "UPDATE $tbl_lp_item SET next_item_id = $id WHERE id = $previous_previous";
  2945. if ($this->debug > 2) {
  2946. error_log($sql_upd2, 0);
  2947. }
  2948. $res_upd2 = Database::query($sql_upd2);
  2949. }
  2950. // Update previous item (switch with current).
  2951. if ($previous != 0) {
  2952. $sql_upd2 = "UPDATE $tbl_lp_item SET next_item_id = $next, previous_item_id = $id, display_order = display_order +1 WHERE id = $previous";
  2953. if ($this->debug > 2) {
  2954. error_log($sql_upd2, 0);
  2955. }
  2956. $res_upd2 = Database::query($sql_upd2);
  2957. }
  2958. // Update current item (switch with previous).
  2959. if ($id != 0) {
  2960. $sql_upd2 = "UPDATE $tbl_lp_item SET next_item_id = $previous, previous_item_id = $previous_previous, display_order = display_order-1 WHERE id = $id";
  2961. if ($this->debug > 2) {
  2962. error_log($sql_upd2, 0);
  2963. }
  2964. $res_upd2 = Database::query($sql_upd2);
  2965. }
  2966. // Update next item (new previous item).
  2967. if ($next != 0) {
  2968. $sql_upd2 = "UPDATE $tbl_lp_item SET previous_item_id = $previous WHERE id = $next";
  2969. if ($this->debug > 2) {
  2970. error_log($sql_upd2, 0);
  2971. }
  2972. $res_upd2 = Database::query($sql_upd2);
  2973. }
  2974. $display = $display -1;
  2975. }
  2976. break;
  2977. case 'down' :
  2978. if ($this->debug > 2) {
  2979. error_log('Movement down detected', 0);
  2980. }
  2981. if ($next == 0) { /* Do nothing. */
  2982. } else {
  2983. $sql_sel2 = "SELECT * FROM $tbl_lp_item WHERE id = $next";
  2984. if ($this->debug > 2) {
  2985. error_log('Selecting next: ' . $sql_sel2, 0);
  2986. }
  2987. $res_sel2 = Database::query($sql_sel2);
  2988. if (Database :: num_rows($res_sel2) < 1) {
  2989. $next_next = 0;
  2990. }
  2991. // Gather data.
  2992. $row2 = Database :: fetch_array($res_sel2);
  2993. $next_next = $row2['next_item_id'];
  2994. // Update previous item (switch with current).
  2995. if ($previous != 0) {
  2996. $sql_upd2 = "UPDATE $tbl_lp_item SET next_item_id = $next WHERE id = $previous";
  2997. $res_upd2 = Database::query($sql_upd2);
  2998. }
  2999. // Update current item (switch with previous).
  3000. if ($id != 0) {
  3001. $sql_upd2 = "UPDATE $tbl_lp_item SET previous_item_id = $next, next_item_id = $next_next, display_order = display_order+1 WHERE id = $id";
  3002. $res_upd2 = Database::query($sql_upd2);
  3003. }
  3004. // Update next item (new previous item).
  3005. if ($next != 0) {
  3006. $sql_upd2 = "UPDATE $tbl_lp_item SET previous_item_id = $previous, next_item_id = $id, display_order = display_order-1 WHERE id = $next";
  3007. $res_upd2 = Database::query($sql_upd2);
  3008. }
  3009. // Update next_next item (switch "previous" with current).
  3010. if ($next_next != 0) {
  3011. $sql_upd2 = "UPDATE $tbl_lp_item SET previous_item_id = $id WHERE id = $next_next";
  3012. $res_upd2 = Database::query($sql_upd2);
  3013. }
  3014. $display = $display +1;
  3015. }
  3016. break;
  3017. default :
  3018. return false;
  3019. }
  3020. return $display;
  3021. }
  3022. /**
  3023. * Move a learnpath up (display_order)
  3024. * @param integer Learnpath ID
  3025. */
  3026. public function move_up($lp_id) {
  3027. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3028. $sql = "SELECT * FROM $lp_table ORDER BY display_order";
  3029. $res = Database::query($sql);
  3030. if ($res === false)
  3031. return false;
  3032. $lps = array ();
  3033. $lp_order = array ();
  3034. $num = Database :: num_rows($res);
  3035. // First check the order is correct, globally (might be wrong because
  3036. // of versions < 1.8.4)
  3037. if ($num > 0) {
  3038. $i = 1;
  3039. while ($row = Database :: fetch_array($res)) {
  3040. if ($row['display_order'] != $i) { // If we find a gap in the order, we need to fix it.
  3041. $need_fix = true;
  3042. $sql_u = "UPDATE $lp_table SET display_order = $i WHERE id = " . $row['id'];
  3043. $res_u = Database::query($sql_u);
  3044. }
  3045. $row['display_order'] = $i;
  3046. $lps[$row['id']] = $row;
  3047. $lp_order[$i] = $row['id'];
  3048. $i++;
  3049. }
  3050. }
  3051. if ($num > 1) { // If there's only one element, no need to sort.
  3052. $order = $lps[$lp_id]['display_order'];
  3053. if ($order > 1) { // If it's the first element, no need to move up.
  3054. $sql_u1 = "UPDATE $lp_table SET display_order = $order WHERE id = " . $lp_order[$order - 1];
  3055. $res_u1 = Database::query($sql_u1);
  3056. $sql_u2 = "UPDATE $lp_table SET display_order = " . ($order - 1) . " WHERE id = " . $lp_id;
  3057. $res_u2 = Database::query($sql_u2);
  3058. }
  3059. }
  3060. }
  3061. /**
  3062. * Move a learnpath down (display_order)
  3063. * @param integer Learnpath ID
  3064. */
  3065. public function move_down($lp_id) {
  3066. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3067. $sql = "SELECT * FROM $lp_table ORDER BY display_order";
  3068. $res = Database::query($sql);
  3069. if ($res === false)
  3070. return false;
  3071. $lps = array ();
  3072. $lp_order = array ();
  3073. $num = Database :: num_rows($res);
  3074. $max = 0;
  3075. // First check the order is correct, globally (might be wrong because
  3076. // of versions < 1.8.4).
  3077. if ($num > 0) {
  3078. $i = 1;
  3079. while ($row = Database :: fetch_array($res)) {
  3080. $max = $i;
  3081. if ($row['display_order'] != $i) { // If we find a gap in the order, we need to fix it.
  3082. $need_fix = true;
  3083. $sql_u = "UPDATE $lp_table SET display_order = $i WHERE id = " . $row['id'];
  3084. $res_u = Database::query($sql_u);
  3085. }
  3086. $row['display_order'] = $i;
  3087. $lps[$row['id']] = $row;
  3088. $lp_order[$i] = $row['id'];
  3089. $i++;
  3090. }
  3091. }
  3092. if ($num > 1) { // If there's only one element, no need to sort.
  3093. $order = $lps[$lp_id]['display_order'];
  3094. if ($order < $max) { // If it's the first element, no need to move up.
  3095. $sql_u1 = "UPDATE $lp_table SET display_order = $order WHERE id = " . $lp_order[$order + 1];
  3096. $res_u1 = Database::query($sql_u1);
  3097. $sql_u2 = "UPDATE $lp_table SET display_order = " . ($order + 1) . " WHERE id = " . $lp_id;
  3098. $res_u2 = Database::query($sql_u2);
  3099. }
  3100. }
  3101. }
  3102. /**
  3103. * Updates learnpath attributes to point to the next element
  3104. * The last part is similar to set_current_item but processing the other way around
  3105. */
  3106. public function next() {
  3107. if ($this->debug > 0) {
  3108. error_log('New LP - In learnpath::next()', 0);
  3109. }
  3110. $this->last = $this->get_current_item_id();
  3111. $this->items[$this->last]->save(false, $this->prerequisites_match($this->last));
  3112. $this->autocomplete_parents($this->last);
  3113. $new_index = $this->get_next_index();
  3114. if ($this->debug > 2) {
  3115. error_log('New LP - New index: ' . $new_index, 0);
  3116. }
  3117. $this->index = $new_index;
  3118. if ($this->debug > 2) {
  3119. error_log('New LP - Now having orderedlist[' . $new_index . '] = ' . $this->ordered_items[$new_index], 0);
  3120. }
  3121. $this->current = $this->ordered_items[$new_index];
  3122. if ($this->debug > 2) {
  3123. error_log('New LP - new item id is ' . $this->current . '-' . $this->get_current_item_id(), 0);
  3124. }
  3125. }
  3126. /**
  3127. * Open a resource = initialise all local variables relative to this resource. Depending on the child
  3128. * class, this might be redefined to allow several behaviours depending on the document type.
  3129. * @param integer Resource ID
  3130. * @return boolean True on success, false otherwise
  3131. */
  3132. public function open($id) {
  3133. if ($this->debug > 0) {
  3134. error_log('New LP - In learnpath::open()', 0);
  3135. }
  3136. // TODO:
  3137. // set the current resource attribute to this resource
  3138. // switch on element type (redefine in child class?)
  3139. // set status for this item to "opened"
  3140. // start timer
  3141. // initialise score
  3142. $this->index = 0; //or = the last item seen (see $this->last)
  3143. }
  3144. /**
  3145. * Check that all prerequisites are fulfilled. Returns true and an empty string on succes, returns false
  3146. * and the prerequisite string on error.
  3147. * This function is based on the rules for aicc_script language as described in the SCORM 1.2 CAM documentation page 108.
  3148. * @param integer Optional item ID. If none given, uses the current open item.
  3149. * @return boolean True if prerequisites are matched, false otherwise
  3150. * @return string Empty string if true returned, prerequisites string otherwise.
  3151. */
  3152. public function prerequisites_match($item = null) {
  3153. if ($this->debug > 0) {
  3154. error_log('New LP - In learnpath::prerequisites_match()', 0);
  3155. }
  3156. if (empty ($item)) {
  3157. $item = $this->current;
  3158. }
  3159. if (is_object($this->items[$item])) {
  3160. $prereq_string = $this->items[$item]->get_prereq_string();
  3161. if (empty ($prereq_string)) {
  3162. return true;
  3163. }
  3164. // Clean spaces.
  3165. $prereq_string = str_replace(' ', '', $prereq_string);
  3166. if ($this->debug > 0) {
  3167. error_log('Found prereq_string: ' . $prereq_string, 0);
  3168. }
  3169. // Now send to the parse_prereq() function that will check this component's prerequisites.
  3170. $result = $this->items[$item]->parse_prereq($prereq_string, $this->items, $this->refs_list, $this->get_user_id());
  3171. if ($result === false) {
  3172. $this->set_error_msg($this->items[$item]->prereq_alert);
  3173. }
  3174. } else {
  3175. $result = true;
  3176. if ($this->debug > 1) {
  3177. error_log('New LP - $this->items[' . $item . '] was not an object', 0);
  3178. }
  3179. }
  3180. if ($this->debug > 1) {
  3181. error_log('New LP - End of prerequisites_match(). Error message is now ' . $this->error, 0);
  3182. }
  3183. return $result;
  3184. }
  3185. /**
  3186. * Updates learnpath attributes to point to the previous element
  3187. * The last part is similar to set_current_item but processing the other way around
  3188. */
  3189. public function previous() {
  3190. if ($this->debug > 0) {
  3191. error_log('New LP - In learnpath::previous()', 0);
  3192. }
  3193. $this->last = $this->get_current_item_id();
  3194. $this->items[$this->last]->save(false, $this->prerequisites_match($this->last));
  3195. $this->autocomplete_parents($this->last);
  3196. $new_index = $this->get_previous_index();
  3197. $this->index = $new_index;
  3198. $this->current = $this->ordered_items[$new_index];
  3199. }
  3200. /**
  3201. * Publishes a learnpath. This basically means show or hide the learnpath
  3202. * to normal users.
  3203. * Can be used as abstract
  3204. * @param integer Learnpath ID
  3205. * @param string New visibility
  3206. */
  3207. public function toggle_visibility($lp_id, $set_visibility = 1) {
  3208. //if ($this->debug > 0) { error_log('New LP - In learnpath::toggle_visibility()', 0); }
  3209. $action = 'visible';
  3210. if ($set_visibility != 1) {
  3211. $action = 'invisible';
  3212. }
  3213. return api_item_property_update(api_get_course_info(), TOOL_LEARNPATH, $lp_id, $action, api_get_user_id());
  3214. }
  3215. /**
  3216. * Publishes a learnpath. This basically means show or hide the learnpath
  3217. * on the course homepage
  3218. * Can be used as abstract
  3219. * @param integer Learnpath ID
  3220. * @param string New visibility
  3221. */
  3222. public function toggle_publish($lp_id, $set_visibility = 'v') {
  3223. //if ($this->debug > 0) { error_log('New LP - In learnpath::toggle_publish()', 0); }
  3224. $tbl_lp = Database :: get_course_table(TABLE_LP_MAIN);
  3225. $sql = "SELECT * FROM $tbl_lp where id=$lp_id";
  3226. $result = Database::query($sql);
  3227. $row = Database :: fetch_array($result);
  3228. $name = domesticate($row['name']);
  3229. if ($set_visibility == 'i') {
  3230. $s = $name . " " . get_lang('_no_published');
  3231. $dialogBox = $s;
  3232. $v = 0;
  3233. }
  3234. if ($set_visibility == 'v') {
  3235. $s = $name . " " . get_lang('_published');
  3236. $dialogBox = $s;
  3237. $v = 1;
  3238. }
  3239. $session_id = api_get_session_id();
  3240. $session_condition = api_get_session_condition($session_id);
  3241. $tbl_tool = Database :: get_course_table(TABLE_TOOL_LIST);
  3242. $link = 'newscorm/lp_controller.php?action=view&lp_id=' . $lp_id;
  3243. $sql = "SELECT * FROM $tbl_tool where name='$name' and image='scormbuilder.gif' and link LIKE '$link%' $session_condition";
  3244. $result = Database::query($sql);
  3245. $num = Database :: num_rows($result);
  3246. $row2 = Database :: fetch_array($result);
  3247. //if ($this->debug > 2) { error_log('New LP - '.$sql.' - '.$num, 0); }
  3248. if (($set_visibility == 'i') && ($num > 0)) {
  3249. $sql = "DELETE FROM $tbl_tool WHERE (name='$name' and image='scormbuilder.gif' and link LIKE '$link%' $session_condition)";
  3250. }
  3251. elseif (($set_visibility == 'v') && ($num == 0)) {
  3252. $sql = "INSERT INTO $tbl_tool (name, link, image, visibility, admin, address, added_tool, session_id) VALUES ('$name','newscorm/lp_controller.php?action=view&lp_id=$lp_id','scormbuilder.gif','$v','0','pastillegris.gif',0, $session_id)";
  3253. } else {
  3254. // Parameter and database incompatible, do nothing.
  3255. }
  3256. $result = Database::query($sql);
  3257. //if ($this->debug > 2) { error_log('New LP - Leaving learnpath::toggle_visibility: '.$sql, 0); }
  3258. }
  3259. /**
  3260. * Restart the whole learnpath. Return the URL of the first element.
  3261. * Make sure the results are saved with anoter method. This method should probably be
  3262. * redefined in children classes.
  3263. * To use a similar method statically, use the create_new_attempt() method
  3264. * @return string URL to load in the viewer
  3265. */
  3266. public function restart() {
  3267. if ($this->debug > 0) {
  3268. error_log('New LP - In learnpath::restart()', 0);
  3269. }
  3270. // TODO
  3271. // Call autosave method to save the current progress.
  3272. //$this->index = 0;
  3273. $session_id = api_get_session_id();
  3274. $lp_view_table = Database :: get_course_table(TABLE_LP_VIEW);
  3275. $sql = "INSERT INTO $lp_view_table (lp_id, user_id, view_count, session_id) " .
  3276. "VALUES (" . $this->lp_id . "," . $this->get_user_id() . "," . ($this->attempt + 1) . ", $session_id)";
  3277. if ($this->debug > 2) {
  3278. error_log('New LP - Inserting new lp_view for restart: ' . $sql, 0);
  3279. }
  3280. $res = Database::query($sql);
  3281. if ($view_id = Database :: insert_id($res)) {
  3282. $this->lp_view_id = $view_id;
  3283. $this->attempt = $this->attempt + 1;
  3284. } else {
  3285. $this->error = 'Could not insert into item_view table...';
  3286. return false;
  3287. }
  3288. $this->autocomplete_parents($this->current);
  3289. foreach ($this->items as $index => $dummy) {
  3290. $this->items[$index]->restart();
  3291. $this->items[$index]->set_lp_view($this->lp_view_id);
  3292. }
  3293. $this->first();
  3294. return true;
  3295. }
  3296. /**
  3297. * Saves the current item
  3298. * @return boolean
  3299. */
  3300. public function save_current() {
  3301. if ($this->debug > 0) {
  3302. error_log('New LP - In learnpath::save_current()', 0);
  3303. }
  3304. // TODO: Do a better check on the index pointing to the right item (it is supposed to be working
  3305. // on $ordered_items[] but not sure it's always safe to use with $items[]).
  3306. if ($this->debug > 2) {
  3307. error_log('New LP - save_current() saving item ' . $this->current, 0);
  3308. }
  3309. if ($this->debug > 2) {
  3310. error_log('' . print_r($this->items, true), 0);
  3311. }
  3312. if (is_object($this->items[$this->current])) {
  3313. //$res = $this->items[$this->current]->save(false);
  3314. $res = $this->items[$this->current]->save(false, $this->prerequisites_match($this->current));
  3315. $this->autocomplete_parents($this->current);
  3316. $status = $this->items[$this->current]->get_status();
  3317. $this->append_message('new_item_status: ' . $status);
  3318. $this->update_queue[$this->current] = $status;
  3319. return $res;
  3320. }
  3321. return false;
  3322. }
  3323. /**
  3324. * Saves the given item
  3325. * @param integer Item ID. Optional (will take from $_REQUEST if null)
  3326. * @param boolean Save from url params (true) or from current attributes (false). Optional. Defaults to true
  3327. * @return boolean
  3328. */
  3329. public function save_item($item_id = null, $from_outside = true) {
  3330. if ($this->debug > 0) {
  3331. error_log('New LP - In learnpath::save_item(' . $item_id . ',' . $from_outside . ')', 0);
  3332. }
  3333. // TODO: Do a better check on the index pointing to the right item (it is supposed to be working
  3334. // on $ordered_items[] but not sure it's always safe to use with $items[]).
  3335. if (empty ($item_id)) {
  3336. $item_id = $this->escape_string($_REQUEST['id']);
  3337. }
  3338. if (empty ($item_id)) {
  3339. $item_id = $this->get_current_item_id();
  3340. }
  3341. if ($this->debug > 2) {
  3342. error_log('New LP - save_current() saving item ' . $item_id, 0);
  3343. }
  3344. if (is_object($this->items[$item_id])) {
  3345. $res = $this->items[$item_id]->save($from_outside, $this->prerequisites_match($item_id));
  3346. //$res = $this->items[$item_id]->save($from_outside);
  3347. $this->autocomplete_parents($item_id);
  3348. $status = $this->items[$item_id]->get_status();
  3349. $this->append_message('new_item_status: ' . $status);
  3350. $this->update_queue[$item_id] = $status;
  3351. return $res;
  3352. }
  3353. return false;
  3354. }
  3355. /**
  3356. * Saves the last item seen's ID only in case
  3357. */
  3358. public function save_last() {
  3359. if ($this->debug > 0) {
  3360. error_log('New LP - In learnpath::save_last()', 0);
  3361. }
  3362. $session_condition = api_get_session_condition(api_get_session_id(), true, false);
  3363. $table = Database :: get_course_table(TABLE_LP_VIEW);
  3364. if (isset ($this->current)) {
  3365. if ($this->debug > 2) {
  3366. error_log('New LP - Saving current item (' . $this->current . ') for later review', 0);
  3367. }
  3368. $sql = "UPDATE $table SET last_item = " . Database::escape_string($this->get_current_item_id()). " " .
  3369. "WHERE lp_id = " . $this->get_id() . " AND user_id = " . $this->get_user_id().' '.$session_condition;
  3370. if ($this->debug > 2) {
  3371. error_log('New LP - Saving last item seen : ' . $sql, 0);
  3372. }
  3373. $res = Database::query($sql);
  3374. }
  3375. // Save progress.
  3376. list($progress, $text) = $this->get_progress_bar_text('%');
  3377. if ($progress >= 0 && $progress <= 100) {
  3378. $progress = (int) $progress;
  3379. $sql = "UPDATE $table SET progress = $progress " .
  3380. "WHERE lp_id = " . $this->get_id() . " AND " .
  3381. "user_id = " . $this->get_user_id().' '.$session_condition;
  3382. $res = Database::query($sql); // Ignore errors as some tables might not have the progress field just yet.
  3383. $this->progress_db = $progress;
  3384. }
  3385. }
  3386. /**
  3387. * Sets the current item ID (checks if valid and authorized first)
  3388. * @param integer New item ID. If not given or not authorized, defaults to current
  3389. */
  3390. public function set_current_item($item_id = null) {
  3391. if ($this->debug > 0) {
  3392. error_log('New LP - In learnpath::set_current_item(' . $item_id . ')', 0);
  3393. }
  3394. if (empty ($item_id)) {
  3395. if ($this->debug > 2) {
  3396. error_log('New LP - No new current item given, ignore...', 0);
  3397. }
  3398. // Do nothing.
  3399. } else {
  3400. if ($this->debug > 2) {
  3401. error_log('New LP - New current item given is ' . $item_id . '...', 0);
  3402. }
  3403. if (is_numeric($item_id)) {
  3404. $item_id = $this->escape_string($item_id);
  3405. // TODO: Check in database here.
  3406. $this->last = $this->current;
  3407. $this->current = $item_id;
  3408. // TODO: Update $this->index as well.
  3409. foreach ($this->ordered_items as $index => $item) {
  3410. if ($item == $this->current) {
  3411. $this->index = $index;
  3412. break;
  3413. }
  3414. }
  3415. if ($this->debug > 2) {
  3416. error_log('New LP - set_current_item(' . $item_id . ') done. Index is now : ' . $this->index, 0);
  3417. }
  3418. } else {
  3419. error_log('New LP - set_current_item(' . $item_id . ') failed. Not a numeric value: ', 0);
  3420. }
  3421. }
  3422. }
  3423. /**
  3424. * Sets the encoding
  3425. * @param string New encoding
  3426. * TODO (as of Chamilo 1.8.8): Check in the future whether this method is needed.
  3427. */
  3428. public function set_encoding($enc = 'UTF-8') {
  3429. if ($this->debug > 0) {
  3430. error_log('New LP - In learnpath::set_encoding()', 0);
  3431. }
  3432. /* // Deprecated code (Chamilo 1.8.8).
  3433. $enc = strtoupper($enc);
  3434. $encodings = array (
  3435. 'UTF-8',
  3436. 'ISO-8859-1',
  3437. 'ISO-8859-15',
  3438. 'cp1251',
  3439. 'cp1252',
  3440. 'KOI8-R',
  3441. 'BIG5',
  3442. 'GB2312',
  3443. 'Shift_JIS',
  3444. 'EUC-JP',
  3445. ''
  3446. );
  3447. if (in_array($enc, $encodings)) { // TODO: Incorrect comparison, fix it.
  3448. $lp = $this->get_id();
  3449. if ($lp != 0) {
  3450. $tbl_lp = Database :: get_course_table(TABLE_LP_MAIN);
  3451. $sql = "UPDATE $tbl_lp SET default_encoding = '$enc' WHERE id = " . $lp;
  3452. $res = Database::query($sql);
  3453. return $res;
  3454. }
  3455. }
  3456. return false;
  3457. */
  3458. $enc = api_refine_encoding_id($enc);
  3459. if (empty($enc)) {
  3460. $enc = api_get_system_encoding();
  3461. }
  3462. if (api_is_encoding_supported($enc)) {
  3463. $lp = $this->get_id();
  3464. if ($lp != 0) {
  3465. $tbl_lp = Database :: get_course_table(TABLE_LP_MAIN);
  3466. $sql = "UPDATE $tbl_lp SET default_encoding = '$enc' WHERE id = " . $lp;
  3467. $res = Database::query($sql);
  3468. return $res;
  3469. }
  3470. }
  3471. return false;
  3472. }
  3473. /**
  3474. * Sets the JS lib setting in the database directly.
  3475. * This is the JavaScript library file this lp needs to load on startup
  3476. * @param string Proximity setting
  3477. * @return boolean True on update success. False otherwise.
  3478. */
  3479. public function set_jslib($lib = '') {
  3480. if ($this->debug > 0) {
  3481. error_log('New LP - In learnpath::set_jslib()', 0);
  3482. }
  3483. $lp = $this->get_id();
  3484. if ($lp != 0) {
  3485. $tbl_lp = Database :: get_course_table(TABLE_LP_MAIN);
  3486. $sql = "UPDATE $tbl_lp SET js_lib = '$lib' WHERE id = " . $lp;
  3487. $res = Database::query($sql);
  3488. return $res;
  3489. } else {
  3490. return false;
  3491. }
  3492. }
  3493. /**
  3494. * Sets the name of the LP maker (publisher) (and save)
  3495. * @param string Optional string giving the new content_maker of this learnpath
  3496. * @return boolean True
  3497. */
  3498. public function set_maker($name = '') {
  3499. if ($this->debug > 0) {
  3500. error_log('New LP - In learnpath::set_maker()', 0);
  3501. }
  3502. if (empty ($name))
  3503. return false;
  3504. $this->maker = $this->escape_string($name);
  3505. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3506. $lp_id = $this->get_id();
  3507. $sql = "UPDATE $lp_table SET content_maker = '" . $this->maker . "' WHERE id = '$lp_id'";
  3508. if ($this->debug > 2) {
  3509. error_log('New LP - lp updated with new content_maker : ' . $this->maker, 0);
  3510. }
  3511. $res = Database::query($sql);
  3512. return true;
  3513. }
  3514. /**
  3515. * Sets the name of the current learnpath (and save)
  3516. * @param string Optional string giving the new name of this learnpath
  3517. * @return boolean True/False
  3518. */
  3519. public function set_name($name = '') {
  3520. if ($this->debug > 0) {
  3521. error_log('New LP - In learnpath::set_name()', 0);
  3522. }
  3523. if (empty ($name))
  3524. return false;
  3525. $this->name = $this->escape_string($name);
  3526. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3527. $lp_id = $this->get_id();
  3528. $sql = "UPDATE $lp_table SET name = '" . $this->name . "' WHERE id = '$lp_id'";
  3529. if ($this->debug > 2) {
  3530. error_log('New LP - lp updated with new name : ' . $this->name, 0);
  3531. }
  3532. $res = Database::query($sql);
  3533. // If the lp is visible on the homepage, change his name there.
  3534. if (Database::affected_rows()) {
  3535. $table = Database :: get_course_table(TABLE_TOOL_LIST);
  3536. $sql = 'UPDATE ' . $table . ' SET
  3537. name = "' . $this->name . '"
  3538. WHERE link = "newscorm/lp_controller.php?action=view&lp_id=' . $lp_id . '"';
  3539. Database::query($sql);
  3540. }
  3541. return true;
  3542. }
  3543. /**
  3544. * Set index specified prefix terms for all items in this path
  3545. * @param string Comma-separated list of terms
  3546. * @param char Xapian term prefix
  3547. * @return boolean False on error, true otherwise
  3548. */
  3549. public function set_terms_by_prefix($terms_string, $prefix) {
  3550. if (api_get_setting('search_enabled') !== 'true')
  3551. return false;
  3552. $terms_string = trim($terms_string);
  3553. $terms = explode(',', $terms_string);
  3554. array_walk($terms, 'trim_value');
  3555. $stored_terms = $this->get_common_index_terms_by_prefix($prefix);
  3556. //var_dump($stored_terms);
  3557. //var_dump($terms);
  3558. // Don't do anything if no change, verify only at DB, not the search engine.
  3559. if ((count(array_diff($terms, $stored_terms)) == 0) && (count(array_diff($stored_terms, $terms)) == 0))
  3560. return false;
  3561. require_once 'xapian.php'; // TODO: Try catch every xapian use or make wrappers on API.
  3562. require_once api_get_path(LIBRARY_PATH).'search/DokeosIndexer.class.php';
  3563. require_once api_get_path(LIBRARY_PATH).'search/xapian/XapianQuery.php';
  3564. require_once api_get_path(LIBRARY_PATH).'search/IndexableChunk.class.php';
  3565. $items_table = Database :: get_course_table(TABLE_LP_ITEM);
  3566. // TODO: Make query secure agains XSS : use member attr instead of post var.
  3567. $lp_id = intval($_POST['lp_id']);
  3568. $sql = "SELECT * FROM $items_table WHERE lp_id = $lp_id";
  3569. $result = Database::query($sql);
  3570. $di = new DokeosIndexer();
  3571. while ($lp_item = Database :: fetch_array($result)) {
  3572. // Get search_did.
  3573. $tbl_se_ref = Database :: get_main_table(TABLE_MAIN_SEARCH_ENGINE_REF);
  3574. $sql = 'SELECT * FROM %s WHERE course_code=\'%s\' AND tool_id=\'%s\' AND ref_id_high_level=%s AND ref_id_second_level=%d LIMIT 1';
  3575. $sql = sprintf($sql, $tbl_se_ref, $this->cc, TOOL_LEARNPATH, $lp_id, $lp_item['id']);
  3576. $res = Database::query($sql);
  3577. if (Database::num_rows($res) > 0) {
  3578. $se_ref = Database :: fetch_array($res);
  3579. // Compare terms.
  3580. $doc = $di->get_document($se_ref['search_did']);
  3581. $xapian_terms = xapian_get_doc_terms($doc, $prefix);
  3582. //var_dump($xapian_terms);
  3583. $xterms = array ();
  3584. foreach ($xapian_terms as $xapian_term) {
  3585. $xterms[] = substr($xapian_term['name'], 1);
  3586. }
  3587. $dterms = $terms;
  3588. $missing_terms = array_diff($dterms, $xterms);
  3589. $deprecated_terms = array_diff($xterms, $dterms);
  3590. // Save it to search engine.
  3591. foreach ($missing_terms as $term) {
  3592. $doc->add_term($prefix . $term, 1);
  3593. }
  3594. foreach ($deprecated_terms as $term) {
  3595. $doc->remove_term($prefix . $term);
  3596. }
  3597. $di->getDb()->replace_document((int) $se_ref['search_did'], $doc);
  3598. $di->getDb()->flush();
  3599. }
  3600. }
  3601. return true;
  3602. }
  3603. /**
  3604. * Sets the theme of the LP (local/remote) (and save)
  3605. * @param string Optional string giving the new theme of this learnpath
  3606. * @return bool Returns true if theme name is not empty
  3607. */
  3608. public function set_theme($name = '') {
  3609. if ($this->debug > 0) {
  3610. error_log('New LP - In learnpath::set_theme()', 0);
  3611. }
  3612. $this->theme = $this->escape_string($name);
  3613. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3614. $lp_id = $this->get_id();
  3615. $sql = "UPDATE $lp_table SET theme = '" . $this->theme . "' WHERE id = '$lp_id'";
  3616. if ($this->debug > 2) {
  3617. error_log('New LP - lp updated with new theme : ' . $this->theme, 0);
  3618. }
  3619. //$res = Database::query($sql);
  3620. $res = Database::query($sql);
  3621. return true;
  3622. }
  3623. /**
  3624. * Sets the image of an LP (and save)
  3625. * @param string Optional string giving the new image of this learnpath
  3626. * @return bool Returns true if theme name is not empty
  3627. */
  3628. public function set_preview_image($name = '') {
  3629. if ($this->debug > 0) {
  3630. error_log('New LP - In learnpath::set_preview_image()', 0);
  3631. }
  3632. $this->preview_image = $this->escape_string($name);
  3633. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3634. $lp_id = $this->get_id();
  3635. $sql = "UPDATE $lp_table SET preview_image = '" . $this->preview_image . "' WHERE id = '$lp_id'";
  3636. if ($this->debug > 2) {
  3637. error_log('New LP - lp updated with new preview image : ' . $this->preview_image, 0);
  3638. }
  3639. $res = Database::query($sql);
  3640. return true;
  3641. }
  3642. /**
  3643. * Sets the author of a LP (and save)
  3644. * @param string Optional string giving the new author of this learnpath
  3645. * @return bool Returns true if author's name is not empty
  3646. */
  3647. public function set_author($name = '') {
  3648. if ($this->debug > 0) {
  3649. error_log('New LP - In learnpath::set_author()', 0);
  3650. }
  3651. $this->author = $this->escape_string($name);
  3652. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3653. $lp_id = $this->get_id();
  3654. $sql = "UPDATE $lp_table SET author = '" . $this->author . "' WHERE id = '$lp_id'";
  3655. if ($this->debug > 2) {
  3656. error_log('New LP - lp updated with new preview author : ' . $this->author, 0);
  3657. }
  3658. $res = Database::query($sql);
  3659. return true;
  3660. }
  3661. /**
  3662. * Sets the prerequisite of a LP (and save)
  3663. * @param int integer giving the new prerequisite of this learnpath
  3664. * @return bool returns true if prerequisite is not empty
  3665. */
  3666. public function set_prerequisite($prerequisite) {
  3667. if ($this->debug > 0) {
  3668. error_log('New LP - In learnpath::set_prerequisite()', 0);
  3669. }
  3670. $this->prerequisite = intval($prerequisite);
  3671. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3672. $lp_id = $this->get_id();
  3673. $sql = "UPDATE $lp_table SET prerequisite = '".$this->prerequisite."' WHERE id = '$lp_id'";
  3674. if ($this->debug > 2) {
  3675. error_log('New LP - lp updated with new preview requisite : ' . $this->requisite, 0);
  3676. }
  3677. $res = Database::query($sql);
  3678. return true;
  3679. }
  3680. /**
  3681. * Sets the location/proximity of the LP (local/remote) (and save)
  3682. * @param string Optional string giving the new location of this learnpath
  3683. * @return boolean True on success / False on error
  3684. */
  3685. public function set_proximity($name = '') {
  3686. if ($this->debug > 0) {
  3687. error_log('New LP - In learnpath::set_proximity()', 0);
  3688. }
  3689. if (empty ($name))
  3690. return false;
  3691. $this->proximity = $this->escape_string($name);
  3692. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3693. $lp_id = $this->get_id();
  3694. $sql = "UPDATE $lp_table SET content_local = '" . $this->proximity . "' WHERE id = '$lp_id'";
  3695. if ($this->debug > 2) {
  3696. error_log('New LP - lp updated with new proximity : ' . $this->proximity, 0);
  3697. }
  3698. $res = Database::query($sql);
  3699. return true;
  3700. }
  3701. /**
  3702. * Sets the previous item ID to a given ID. Generally, this should be set to the previous 'current' item
  3703. * @param integer DB ID of the item
  3704. */
  3705. public function set_previous_item($id) {
  3706. if ($this->debug > 0) {
  3707. error_log('New LP - In learnpath::set_previous_item()', 0);
  3708. }
  3709. $this->last = $id;
  3710. }
  3711. /**
  3712. * Sets use_max_score
  3713. * @param string Optional string giving the new location of this learnpath
  3714. * @return boolean True on success / False on error
  3715. */
  3716. public function set_use_max_score($use_max_score = 1) {
  3717. if ($this->debug > 0) {
  3718. error_log('New LP - In learnpath::set_use_max_score()', 0);
  3719. }
  3720. if ($use_max_score) {
  3721. $use_max_score = 1;
  3722. } else {
  3723. $use_max_score = 0;
  3724. }
  3725. $this->use_max_score = $this->escape_string($use_max_score);
  3726. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3727. $lp_id = $this->get_id();
  3728. $sql = "UPDATE $lp_table SET use_max_score = '" . $this->use_max_score . "' WHERE id = '$lp_id'";
  3729. if ($this->debug > 2) {
  3730. error_log('New LP - lp updated with new use_max_score : ' . $this->use_max_score, 0);
  3731. }
  3732. $res = Database::query($sql);
  3733. return true;
  3734. }
  3735. /**
  3736. * Sets and saves the expired_on date
  3737. * @param string Optional string giving the new author of this learnpath
  3738. * @return bool Returns true if author's name is not empty
  3739. */
  3740. public function set_expired_on($expired_on) {
  3741. if ($this->debug > 0) {
  3742. error_log('New LP - In learnpath::set_expired_on()', 0);
  3743. }
  3744. if (!empty($expired_on)) {
  3745. $this->expired_on = $this->escape_string(api_get_utc_datetime($expired_on));
  3746. } else {
  3747. $this->expired_on = '';
  3748. }
  3749. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3750. $lp_id = $this->get_id();
  3751. $sql = "UPDATE $lp_table SET expired_on = '" . $this->expired_on . "' WHERE id = '$lp_id'";
  3752. if ($this->debug > 2) {
  3753. error_log('New LP - lp updated with new expired_on : ' . $this->expired_on, 0);
  3754. }
  3755. $res = Database::query($sql);
  3756. return true;
  3757. }
  3758. /**
  3759. * Sets and saves the publicated_on date
  3760. * @param string Optional string giving the new author of this learnpath
  3761. * @return bool Returns true if author's name is not empty
  3762. */
  3763. public function set_publicated_on($publicated_on) {
  3764. if ($this->debug > 0) {
  3765. error_log('New LP - In learnpath::set_expired_on()', 0);
  3766. }
  3767. if (!empty($publicated_on)) {
  3768. $this->publicated_on = $this->escape_string(api_get_utc_datetime($publicated_on));
  3769. } else {
  3770. $this->publicated_on = '';
  3771. }
  3772. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3773. $lp_id = $this->get_id();
  3774. $sql = "UPDATE $lp_table SET publicated_on = '" . $this->publicated_on . "' WHERE id = '$lp_id'";
  3775. if ($this->debug > 2) {
  3776. error_log('New LP - lp updated with new publicated_on : ' . $this->publicated_on, 0);
  3777. }
  3778. $res = Database::query($sql);
  3779. return true;
  3780. }
  3781. /**
  3782. * Sets and saves the expired_on date
  3783. * @param string Optional string giving the new author of this learnpath
  3784. * @return bool Returns true if author's name is not empty
  3785. */
  3786. public function set_modified_on() {
  3787. if ($this->debug > 0) {
  3788. error_log('New LP - In learnpath::set_expired_on()', 0);
  3789. }
  3790. $this->modified_on = api_get_utc_datetime();
  3791. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3792. $lp_id = $this->get_id();
  3793. $sql = "UPDATE $lp_table SET modified_on = '" . $this->modified_on . "' WHERE id = '$lp_id'";
  3794. if ($this->debug > 2) {
  3795. error_log('New LP - lp updated with new expired_on : ' . $this->modified_on, 0);
  3796. }
  3797. $res = Database::query($sql);
  3798. return true;
  3799. }
  3800. /**
  3801. * Sets the object's error message
  3802. * @param string Error message. If empty, reinits the error string
  3803. * @return void
  3804. */
  3805. public function set_error_msg($error = '') {
  3806. if ($this->debug > 0) {
  3807. error_log('New LP - In learnpath::set_error_msg()', 0);
  3808. }
  3809. if (empty ($error)) {
  3810. $this->error = '';
  3811. } else {
  3812. $this->error .= $error;
  3813. }
  3814. }
  3815. /**
  3816. * Launches the current item if not 'sco' (starts timer and make sure there is a record ready in the DB)
  3817. * @param boolean Whether to allow a new attempt or not
  3818. * @return boolean True
  3819. */
  3820. public function start_current_item($allow_new_attempt = false) {
  3821. if ($this->debug > 0) {
  3822. error_log('New LP - In learnpath::start_current_item()', 0);
  3823. }
  3824. if ($this->current != 0 AND is_object($this->items[$this->current])) {
  3825. $type = $this->get_type();
  3826. $item_type = $this->items[$this->current]->get_type();
  3827. if (($type == 2 && $item_type != 'sco') OR ($type == 3 && $item_type != 'au') OR ($type == 1 && $item_type != TOOL_QUIZ && $item_type != TOOL_HOTPOTATOES)) {
  3828. $this->items[$this->current]->open($allow_new_attempt);
  3829. $this->autocomplete_parents($this->current);
  3830. $prereq_check = $this->prerequisites_match($this->current);
  3831. $this->items[$this->current]->save(false, $prereq_check);
  3832. //$this->update_queue[$this->last] = $this->items[$this->last]->get_status();
  3833. } else {
  3834. // If sco, then it is supposed to have been updated by some other call.
  3835. }
  3836. if ($item_type == 'sco') {
  3837. $this->items[$this->current]->restart();
  3838. }
  3839. }
  3840. if ($this->debug > 0) {
  3841. error_log('New LP - End of learnpath::start_current_item()', 0);
  3842. }
  3843. return true;
  3844. }
  3845. /**
  3846. * Stops the processing and counters for the old item (as held in $this->last)
  3847. * @return boolean True/False
  3848. */
  3849. public function stop_previous_item() {
  3850. if ($this->debug > 0) {
  3851. error_log('New LP - In learnpath::stop_previous_item()', 0);
  3852. }
  3853. if ($this->last != 0 && $this->last != $this->current && is_object($this->items[$this->last])) {
  3854. if ($this->debug > 2) {
  3855. error_log('New LP - In learnpath::stop_previous_item() - ' . $this->last . ' is object', 0);
  3856. }
  3857. switch ($this->get_type()) {
  3858. case '3' :
  3859. if ($this->items[$this->last]->get_type() != 'au') {
  3860. if ($this->debug > 2) {
  3861. error_log('New LP - In learnpath::stop_previous_item() - ' . $this->last . ' in lp_type 3 is <> au', 0);
  3862. }
  3863. $this->items[$this->last]->close();
  3864. //$this->autocomplete_parents($this->last);
  3865. //$this->update_queue[$this->last] = $this->items[$this->last]->get_status();
  3866. } else {
  3867. if ($this->debug > 2) {
  3868. error_log('New LP - In learnpath::stop_previous_item() - Item is an AU, saving is managed by AICC signals', 0);
  3869. }
  3870. }
  3871. case '2' :
  3872. if ($this->items[$this->last]->get_type() != 'sco') {
  3873. if ($this->debug > 2) {
  3874. error_log('New LP - In learnpath::stop_previous_item() - ' . $this->last . ' in lp_type 2 is <> sco', 0);
  3875. }
  3876. $this->items[$this->last]->close();
  3877. //$this->autocomplete_parents($this->last);
  3878. //$this->update_queue[$this->last] = $this->items[$this->last]->get_status();
  3879. } else {
  3880. if ($this->debug > 2) {
  3881. error_log('New LP - In learnpath::stop_previous_item() - Item is a SCO, saving is managed by SCO signals', 0);
  3882. }
  3883. }
  3884. break;
  3885. case '1' :
  3886. default :
  3887. if ($this->debug > 2) {
  3888. error_log('New LP - In learnpath::stop_previous_item() - ' . $this->last . ' in lp_type 1 is asset', 0);
  3889. }
  3890. $this->items[$this->last]->close();
  3891. break;
  3892. }
  3893. } else {
  3894. if ($this->debug > 2) {
  3895. error_log('New LP - In learnpath::stop_previous_item() - No previous element found, ignoring...', 0);
  3896. }
  3897. return false;
  3898. }
  3899. return true;
  3900. }
  3901. /**
  3902. * Updates the default view mode from fullscreen to embedded and inversely
  3903. * @return string The current default view mode ('fullscreen' or 'embedded')
  3904. */
  3905. public function update_default_view_mode() {
  3906. if ($this->debug > 0) {
  3907. error_log('New LP - In learnpath::update_default_view_mode()', 0);
  3908. }
  3909. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3910. $sql = "SELECT * FROM $lp_table WHERE id = " . $this->get_id();
  3911. $res = Database::query($sql);
  3912. if (Database :: num_rows($res) > 0) {
  3913. $row = Database :: fetch_array($res);
  3914. $view_mode = $row['default_view_mod'];
  3915. if ($view_mode == 'fullscreen') {
  3916. $view_mode = 'embedded';
  3917. } elseif ($view_mode == 'embedded') {
  3918. $view_mode = 'fullscreen';
  3919. }
  3920. $sql = "UPDATE $lp_table SET default_view_mod = '$view_mode' WHERE id = " . $this->get_id();
  3921. $res = Database::query($sql);
  3922. $this->mode = $view_mode;
  3923. return $view_mode;
  3924. } else {
  3925. if ($this->debug > 2) {
  3926. error_log('New LP - Problem in update_default_view() - could not find LP ' . $this->get_id() . ' in DB', 0);
  3927. }
  3928. }
  3929. return -1;
  3930. }
  3931. /**
  3932. * Updates the default behaviour about auto-commiting SCORM updates
  3933. * @return boolean True if auto-commit has been set to 'on', false otherwise
  3934. */
  3935. public function update_default_scorm_commit() {
  3936. if ($this->debug > 0) {
  3937. error_log('New LP - In learnpath::update_default_scorm_commit()', 0);
  3938. }
  3939. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3940. $sql = "SELECT * FROM $lp_table WHERE id = " . $this->get_id();
  3941. $res = Database::query($sql);
  3942. if (Database :: num_rows($res) > 0) {
  3943. $row = Database :: fetch_array($res);
  3944. $force = $row['force_commit'];
  3945. if ($force == 1) {
  3946. $force = 0;
  3947. $force_return = false;
  3948. } elseif ($force == 0) {
  3949. $force = 1;
  3950. $force_return = true;
  3951. }
  3952. $sql = "UPDATE $lp_table SET force_commit = $force WHERE id = " . $this->get_id();
  3953. $res = Database::query($sql);
  3954. $this->force_commit = $force_return;
  3955. return $force_return;
  3956. } else {
  3957. if ($this->debug > 2) {
  3958. error_log('New LP - Problem in update_default_scorm_commit() - could not find LP ' . $this->get_id() . ' in DB', 0);
  3959. }
  3960. }
  3961. return -1;
  3962. }
  3963. /**
  3964. * Updates the order of learning paths (goes through all of them by order and fills the gaps)
  3965. * @return bool True on success, false on failure
  3966. */
  3967. public function update_display_order() {
  3968. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3969. $sql = "SELECT * FROM $lp_table ORDER BY display_order";
  3970. $res = Database::query($sql);
  3971. if ($res === false)
  3972. return false;
  3973. $lps = array ();
  3974. $lp_order = array ();
  3975. $num = Database :: num_rows($res);
  3976. // First check the order is correct, globally (might be wrong because
  3977. // of versions < 1.8.4).
  3978. if ($num > 0) {
  3979. $i = 1;
  3980. while ($row = Database :: fetch_array($res)) {
  3981. if ($row['display_order'] != $i) { // If we find a gap in the order, we need to fix it.
  3982. $need_fix = true;
  3983. $sql_u = "UPDATE $lp_table SET display_order = $i WHERE id = " . $row['id'];
  3984. $res_u = Database::query($sql_u);
  3985. }
  3986. $i++;
  3987. }
  3988. }
  3989. return true;
  3990. }
  3991. /**
  3992. * Updates the "prevent_reinit" value that enables control on reinitialising items on second view
  3993. * @return boolean True if prevent_reinit has been set to 'on', false otherwise (or 1 or 0 in this case)
  3994. */
  3995. public function update_reinit() {
  3996. if ($this->debug > 0) {
  3997. error_log('New LP - In learnpath::update_reinit()', 0);
  3998. }
  3999. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  4000. $sql = "SELECT * FROM $lp_table WHERE id = " . $this->get_id();
  4001. $res = Database::query($sql);
  4002. if (Database :: num_rows($res) > 0) {
  4003. $row = Database :: fetch_array($res);
  4004. $force = $row['prevent_reinit'];
  4005. if ($force == 1) {
  4006. $force = 0;
  4007. } elseif ($force == 0) {
  4008. $force = 1;
  4009. }
  4010. $sql = "UPDATE $lp_table SET prevent_reinit = $force WHERE id = " . $this->get_id();
  4011. $res = Database::query($sql);
  4012. $this->prevent_reinit = $force;
  4013. return $force;
  4014. } else {
  4015. if ($this->debug > 2) {
  4016. error_log('New LP - Problem in update_reinit() - could not find LP ' . $this->get_id() . ' in DB', 0);
  4017. }
  4018. }
  4019. return -1;
  4020. }
  4021. /**
  4022. * Updates the "scorm_debug" value that shows or hide the debug window
  4023. * @return boolean True if scorm_debug has been set to 'on', false otherwise (or 1 or 0 in this case)
  4024. */
  4025. public function update_scorm_debug() {
  4026. if ($this->debug > 0) {
  4027. error_log('New LP - In learnpath::update_scorm_debug()', 0);
  4028. }
  4029. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  4030. $sql = "SELECT * FROM $lp_table WHERE id = " . $this->get_id();
  4031. $res = Database::query($sql);
  4032. if (Database :: num_rows($res) > 0) {
  4033. $row = Database :: fetch_array($res);
  4034. $force = $row['debug'];
  4035. if ($force == 1) {
  4036. $force = 0;
  4037. } elseif ($force == 0) {
  4038. $force = 1;
  4039. }
  4040. $sql = "UPDATE $lp_table SET debug = $force WHERE id = " . $this->get_id();
  4041. $res = Database::query($sql);
  4042. $this->scorm_debug = $force;
  4043. return $force;
  4044. } else {
  4045. if ($this->debug > 2) {
  4046. error_log('New LP - Problem in update_scorm_debug() - could not find LP ' . $this->get_id() . ' in DB', 0);
  4047. }
  4048. }
  4049. return -1;
  4050. }
  4051. /**
  4052. * Function that makes a call to the function sort_tree_array and create_tree_array
  4053. * @author Kevin Van Den Haute
  4054. * @param array
  4055. */
  4056. public function tree_array($array) {
  4057. if ($this->debug > 1) {
  4058. error_log('New LP - In learnpath::tree_array()', 0);
  4059. }
  4060. $array = $this->sort_tree_array($array);
  4061. $this->create_tree_array($array);
  4062. }
  4063. /**
  4064. * Creates an array with the elements of the learning path tree in it
  4065. *
  4066. * @author Kevin Van Den Haute
  4067. * @param array $array
  4068. * @param int $parent
  4069. * @param int $depth
  4070. * @param array $tmp
  4071. */
  4072. public function create_tree_array($array, $parent = 0, $depth = -1, $tmp = array ()) {
  4073. if ($this->debug > 1) {
  4074. error_log('New LP - In learnpath::create_tree_array())', 0);
  4075. }
  4076. if (is_array($array)) {
  4077. for ($i = 0; $i < count($array); $i++) {
  4078. if ($array[$i]['parent_item_id'] == $parent) {
  4079. if (!in_array($array[$i]['parent_item_id'], $tmp)) {
  4080. $tmp[] = $array[$i]['parent_item_id'];
  4081. $depth++;
  4082. }
  4083. $preq = (empty($array[$i]['prerequisite']) ? '' : $array[$i]['prerequisite']);
  4084. $this->arrMenu[] = array (
  4085. 'id' => $array[$i]['id'],
  4086. 'item_type' => $array[$i]['item_type'],
  4087. 'title' => $array[$i]['title'],
  4088. 'path' => $array[$i]['path'],
  4089. 'description' => $array[$i]['description'],
  4090. 'parent_item_id' => $array[$i]['parent_item_id'],
  4091. 'previous_item_id' => $array[$i]['previous_item_id'],
  4092. 'next_item_id' => $array[$i]['next_item_id'],
  4093. 'min_score' => $array[$i]['min_score'],
  4094. 'max_score' => $array[$i]['max_score'],
  4095. 'mastery_score' => $array[$i]['mastery_score'],
  4096. 'display_order' => $array[$i]['display_order'],
  4097. 'prerequisite' => $preq,
  4098. 'depth' => $depth,
  4099. 'audio' => $array[$i]['audio']
  4100. );
  4101. $this->create_tree_array($array, $array[$i]['id'], $depth, $tmp);
  4102. }
  4103. }
  4104. }
  4105. }
  4106. /**
  4107. * Sorts a multi dimensional array by parent id and display order
  4108. * @author Kevin Van Den Haute
  4109. *
  4110. * @param array $array (array with al the learning path items in it)
  4111. *
  4112. * @return array
  4113. */
  4114. public function sort_tree_array($array) {
  4115. foreach ($array as $key => $row) {
  4116. $parent[$key] = $row['parent_item_id'];
  4117. $position[$key] = $row['display_order'];
  4118. }
  4119. if (count($array) > 0)
  4120. array_multisort($parent, SORT_ASC, $position, SORT_ASC, $array);
  4121. return $array;
  4122. }
  4123. /**
  4124. * Function that creates a table structure with a learning path his modules, chapters and documents.
  4125. * Also the actions for the modules, chapters and documents are in this table.
  4126. * @author Kevin Van Den Haute
  4127. * @param int $lp_id
  4128. * @return string
  4129. */
  4130. public function overview() {
  4131. $is_allowed_to_edit = api_is_allowed_to_edit(null,true);
  4132. if ($this->debug > 0) {
  4133. error_log('New LP - In learnpath::overview()', 0);
  4134. }
  4135. global $charset, $_course;
  4136. $_SESSION['gradebook'] = Security :: remove_XSS($_GET['gradebook']);
  4137. $return = '';
  4138. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  4139. $sql = "SELECT * FROM " . $tbl_lp_item . "
  4140. WHERE lp_id = " . $this->lp_id;
  4141. $result = Database::query($sql);
  4142. $arrLP = array ();
  4143. while ($row = Database :: fetch_array($result)) {
  4144. $row['title'] = Security :: remove_XSS($row['title']);
  4145. $row['description'] = Security :: remove_XSS($row['description']);
  4146. $arrLP[] = array (
  4147. 'id' => $row['id'],
  4148. 'item_type' => $row['item_type'],
  4149. 'title' => $row['title'],
  4150. 'path' => $row['path'],
  4151. 'description' => $row['description'],
  4152. 'parent_item_id' => $row['parent_item_id'],
  4153. 'previous_item_id' => $row['previous_item_id'],
  4154. 'next_item_id' => $row['next_item_id'],
  4155. 'max_score' => $row['max_score'],
  4156. 'min_score' => $row['min_score'],
  4157. 'mastery_score' => $row['mastery_score'],
  4158. 'prerequisite' => $row['prerequisite'],
  4159. 'display_order' => $row['display_order'],
  4160. 'audio' => $row['audio']
  4161. );
  4162. }
  4163. $this->tree_array($arrLP);
  4164. $arrLP = $this->arrMenu;
  4165. unset ($this->arrMenu);
  4166. if ($is_allowed_to_edit) {
  4167. $token = Security::get_token();
  4168. $gradebook = Security :: remove_XSS($_GET['gradebook']);
  4169. $return .= '<div class="actions">';
  4170. $return .= '<a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&amp;gradebook=' . $gradebook . '&amp;action=build&amp;lp_id=' . $this->lp_id . '" title="' . get_lang('Build') . '">' . Display :: return_icon('learnpath_build.gif', get_lang('Build')) . ' ' . get_lang('Build') . '</a>';
  4171. $return .= '<span>' . Display :: return_icon('learnpath_organize_na.gif', get_lang('BasicOverview')) . ' <b>' . get_lang('BasicOverview') . '</b></span>';
  4172. $return .= '<a href="lp_controller.php?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&action=view&lp_id=' . $this->lp_id . '">' . Display :: return_icon('learnpath_view.gif', get_lang('Display')) . ' ' . get_lang('Display') . '</a> ' . Display :: return_icon('i.gif');
  4173. $return .= '<a href="lp_controller.php?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&amp;action=edit&amp;lp_id=' . Security :: remove_XSS($_GET['lp_id']) . '">' . Display :: return_icon('edit.gif', get_lang('CourseSettings')) . ' ' . get_lang('CourseSettings') . '</a>';
  4174. $return .= '<a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&amp;action=' . Security :: remove_XSS($_GET['action']) . '&amp;lp_id=' . Security :: remove_XSS($_GET['lp_id']) . '&amp;updateaudio=true">' . Display :: return_icon('audio.gif', get_lang('UpdateAllAudioFragments')) . ' ' . get_lang('UpdateAllAudioFragments') . '</a>';
  4175. $return .= '<a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&amp;gradebook=' . $gradebook . '&amp;action=add_item&amp;type=chapter&amp;lp_id=' . $_SESSION['oLP']->lp_id . '" title="' . get_lang('NewChapter') . '"><img alt="' . get_lang('NewChapter') . '" src="../img/lp_dokeos_chapter_add.gif" title="' . get_lang('NewChapter') . '" />' . get_lang('NewChapter') . '</a>';
  4176. $return .= '<a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&amp;gradebook=' . $gradebook . '&amp;action=add_item&amp;type=step&amp;lp_id=' . $_SESSION['oLP']->lp_id . '" title="' . get_lang('NewStep') . '"><img alt="' . get_lang('NewStep') . '" src="../img/more.png" title="' . get_lang('NewStep') . '" />' . get_lang('NewStep') . '</a>';
  4177. $return .= '</div>';
  4178. }
  4179. // we need to start a form when we want to update all the mp3 files
  4180. if ($_GET['updateaudio'] == 'true' AND count($arrLP) <> 0) {
  4181. $return .= '<form action="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&amp;action=' . Security :: remove_XSS($_GET['action']) . '&amp;lp_id=' . Security :: remove_XSS($_GET['lp_id']) . '" method="post" enctype="multipart/form-data" name="updatemp3" id="updatemp3">';
  4182. $return .= Display :: display_warning_message(get_lang('LeaveEmptyToKeepCurrentFile'));
  4183. }
  4184. $return .= '<table class="data_table">' . "\n";
  4185. $return .= "\t" . '<tr>' . "\n";
  4186. $return .= "\t" . '<th width="60%">' . get_lang('Title') . '</th>' . "\n";
  4187. //$return .= "\t" . '<th>'.get_lang('Description').'</th>' . "\n";
  4188. $return .= "\t" . '<th>' . get_lang('Audio') . '</th>' . "\n";
  4189. $return .= "\t" . '<th>' . get_lang('Move') . '</th>' . "\n";
  4190. $return .= "\t" . '<th>' . get_lang('Actions') . '</th>' . "\n";
  4191. $return .= "\t" . '</tr>' . "\n";
  4192. for ($i = 0; $i < count($arrLP); $i++) {
  4193. $title = $arrLP[$i]['title'];
  4194. if ($arrLP[$i]['description'] == '')
  4195. $arrLP[$i]['description'] = '&nbsp;';
  4196. if (($i % 2) == 0) {
  4197. $oddclass = 'row_odd';
  4198. } else {
  4199. $oddclass = 'row_even';
  4200. }
  4201. $return .= "\t" . '<tr class="' . $oddclass . '">' . "\n";
  4202. $icon_name = str_replace(' ', '', $arrLP[$i]['item_type']);
  4203. if (file_exists('../img/lp_' . $icon_name . '.png')) {
  4204. $return .= "\t\t" . '<td style="padding-left:' . $arrLP[$i]['depth'] * 10 . 'px;"><img align="left" src="../img/lp_' . $icon_name . '.png" style="margin-right:3px;" />' . $title . '</td>' . "\n";
  4205. } else {
  4206. if (file_exists('../img/lp_' . $icon_name . '.gif')) {
  4207. $return .= "\t\t" . '<td style="padding-left:' . $arrLP[$i]['depth'] * 10 . 'px;"><img align="left" src="../img/lp_' . $icon_name . '.gif" style="margin-right:3px;" />' . $title . '</td>' . "\n";
  4208. } else {
  4209. //$return .= "\t\t" . '<td style="padding-left:' . $arrLP[$i]['depth'] * 10 . 'px;">' . Display::display_icon('folder_document.gif','',array('style'=>'margin-right:3px;')) . $title . '</td>' . "\n";
  4210. $return .= "\t\t" . '<td style="padding-left:' . $arrLP[$i]['depth'] * 10 . 'px;"><img align="left" src="../img/folder_document.gif" style="margin-right:3px;" />' . $title . '</td>' . "\n";
  4211. }
  4212. }
  4213. //$return .= "\t\t" . '<td>' . stripslashes($arrLP[$i]['description']) . '</td>' . "\n";
  4214. // The audio column.
  4215. $return .= "\t\t" . '<td align="center">';
  4216. if (!$_GET['updateaudio'] OR $_GET['updateaudio'] <> 'true') {
  4217. if (!empty ($arrLP[$i]['audio'])) {
  4218. $return .= '<span id="container' . $i . '"><a href="http://www.macromedia.com/go/getflashplayer">Get the Flash Player</a> to see this player.</span>';
  4219. $return .= '<script type="text/javascript" src="../inc/lib/mediaplayer/swfobject.js"></script>';
  4220. $return .= '<script type="text/javascript">
  4221. var s1 = new SWFObject("../inc/lib/mediaplayer/player.swf","ply","250","20","9","#FFFFFF");
  4222. s1.addParam("allowscriptaccess","always");
  4223. s1.addParam("flashvars","file=../../courses/' . $_course['path'] . '/document/audio/' . $arrLP[$i]['audio'] . '");
  4224. s1.write("container' . $i . '");
  4225. </script>';
  4226. } else {
  4227. $return .= ' - ';
  4228. }
  4229. } else {
  4230. if ($arrLP[$i]['item_type'] != 'dokeos_chapter' && $arrLP[$i]['item_type'] != 'dokeos_module' && $arrLP[$i]['item_type'] != 'dir') {
  4231. $return .= ' <input type="file" name="mp3file' . $arrLP[$i]['id'] . '" id="mp3file" />';
  4232. if (!empty ($arrLP[$i]['audio'])) {
  4233. $return .= '<br />'.Security::remove_XSS($arrLP[$i]['audio']).'<input type="checkbox" name="removemp3' . $arrLP[$i]['id'] . '" id="checkbox' . $arrLP[$i]['id'] . '" />' . get_lang('RemoveAudio');
  4234. }
  4235. }
  4236. }
  4237. $return .= '</td>';
  4238. if ($is_allowed_to_edit) {
  4239. $return .= '<td align="center">';
  4240. if ($arrLP[$i]['previous_item_id'] != 0) {
  4241. $return .= '<a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&amp;action=move_item&amp;direction=up&amp;id=' . $arrLP[$i]['id'] . '&amp;lp_id=' . $this->lp_id . '&amp;sec_token='.$token.'">';
  4242. $return .= '<img style="margin:1px;" alt="" src="../img/arrow_up_' . ($arrLP[$i]['depth'] % 3) . '.gif" title="' . get_lang('MoveUp') . '"/>';
  4243. $return .= '</a>';
  4244. } else
  4245. $return .= '<img alt="" src="../img/blanco.png" title="" />';
  4246. if ($arrLP[$i]['next_item_id'] != 0) {
  4247. $return .= '<a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']). '&amp;action=move_item&amp;direction=down&amp;id=' . $arrLP[$i]['id'] . '&amp;lp_id=' . $this->lp_id . '&amp;sec_token='.$token.'">';
  4248. $return .= '<img style="margin:1px;" src="../img/arrow_down_' . ($arrLP[$i]['depth'] % 3) . '.gif" title="' . get_lang('MoveDown') . '" />';
  4249. $return .= '</a>';
  4250. } else
  4251. $return .= '<img alt="" src="../img/blanco.png" title="" />';
  4252. $return .= '</td>';
  4253. $return .= '<td align="center">';
  4254. if ($arrLP[$i]['item_type'] != 'dokeos_chapter' && $arrLP[$i]['item_type'] != 'dokeos_module') {
  4255. $return .= "\t\t\t" . '<a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&amp;action=edit_item&amp;view=build&amp;id=' . $arrLP[$i]['id'] . '&amp;lp_id=' . $this->lp_id . '&amp;path_item=' . $arrLP[$i]['path'] . '">';
  4256. $return .= '<img style="margin:1px;" alt="" src="../img/edit.gif" title="' . get_lang('_edit_learnpath_module') . '" />';
  4257. $return .= '</a>' . "\n";
  4258. } else {
  4259. $return .= "\t\t\t" . '<a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&amp;action=edit_item&amp;id=' . $arrLP[$i]['id'] . '&amp;lp_id=' . $this->lp_id . '&amp;path_item=' . $arrLP[$i]['path'] . '">';
  4260. $return .= '<img style="margin:1px;" alt="" src="../img/edit.gif" title="' . get_lang('_edit_learnpath_module') . '" />';
  4261. $return .= '</a>' . "\n";
  4262. }
  4263. $return .= "\t\t\t" . '<a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&amp;action=delete_item&amp;id=' . $arrLP[$i]['id'] . '&amp;lp_id=' . $this->lp_id . '" onclick="return confirmation(\'' . addslashes($title) . '\');">';
  4264. $return .= '<img style="margin:1px;" alt="" src="../img/delete.gif" title="' . get_lang('_delete_learnpath_module') . '" />';
  4265. $return .= '</a>' . "\n";
  4266. $return .= '</td>';
  4267. }
  4268. $return .= '</tr>';
  4269. }
  4270. if (count($arrLP) == 0) {
  4271. $return .= "\t" . '<tr>' . "\n";
  4272. $return .= "\t\t" . '<td colspan="4">' . get_lang('NoItemsInLp') . '</td>' . "\n";
  4273. $return .= "\t" . '</tr>' . "\n";
  4274. }
  4275. $return .= '</table>' . "\n";
  4276. // We need to close the form when we are updating the mp3 files.
  4277. if ($_GET['updateaudio'] == 'true') {
  4278. $return .= '<div style="margin:40px 0; float:right;"><button class="save" type="submit" name="save_audio" id="save_audio">' . get_lang('SaveAudioAndOrganization') . '</button></div>'; // TODO: What kind of language variable is this?
  4279. }
  4280. // We need to close the form when we are updating the mp3 files.
  4281. if ($_GET['updateaudio'] == 'true' && count($arrLP) != 0) {
  4282. $return .= '</form>';
  4283. }
  4284. return $return;
  4285. }
  4286. /**
  4287. * This function builds the action menu
  4288. * @return void
  4289. */
  4290. public function build_action_menu() {
  4291. $gradebook = Security :: remove_XSS($_GET['gradebook']);
  4292. echo '<div class="actions">';
  4293. //echo '<span>'.Display::return_icon('learnpath_build.gif').' '.get_lang('Build').'</span>';
  4294. echo '<span>' . Display :: return_icon('learnpath_build_na.gif', get_lang('Build')) . ' <b>' . get_lang('Build') . '</b></span>';
  4295. echo '<a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&amp;gradebook=' . $gradebook . '&amp;action=admin_view&amp;lp_id=' . $_SESSION['oLP']->lp_id . '" title="' . get_lang('BasicOverview') . '">' . Display :: return_icon('learnpath_organize.gif', get_lang('BasicOverview')) . ' ' . get_lang('BasicOverview') . '</a>';
  4296. echo '<a href="lp_controller.php?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&amp;gradebook=' . $gradebook . '&action=view&lp_id=' . $_SESSION['oLP']->lp_id . '">' . Display :: return_icon('learnpath_view.gif', get_lang('Display')) . ' ' . get_lang('Display') . '</a>';
  4297. Display :: display_icon('i.gif');
  4298. echo '<a href="lp_controller.php?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&amp;action=edit&amp;lp_id=' . Security :: remove_XSS($_GET['lp_id']) . '">' . Display :: return_icon('edit.gif', get_lang('CourseSettings')) . ' ' . get_lang('CourseSettings') . '</a>';
  4299. echo '<a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&amp;action=admin_view&amp;lp_id=' . Security :: remove_XSS($_GET['lp_id']) . '&amp;updateaudio=true">' . Display :: return_icon('audio.gif', get_lang('UpdateAllAudioFragments')) . ' ' . get_lang('UpdateAllAudioFragments') . '</a>';
  4300. echo '<a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&amp;gradebook=' . $gradebook . '&amp;action=add_item&amp;type=chapter&amp;lp_id=' . $_SESSION['oLP']->lp_id . '" title="' . get_lang('NewChapter') . '">' . Display :: return_icon('lp_dokeos_chapter_add.gif', get_lang('NewChapter')) . ' ' . get_lang('NewChapter') . '</a>';
  4301. echo '<a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&amp;gradebook=' . $gradebook . '&amp;action=add_item&amp;type=step&amp;lp_id=' . $_SESSION['oLP']->lp_id . '" title="' . get_lang('NewStep') . '">' . Display :: return_icon('more.png', get_lang('NewStep')) . ' ' . get_lang('NewStep') . '</a>';
  4302. echo '</div>';
  4303. }
  4304. /**
  4305. * This functions builds the LP tree based on data from the database.
  4306. * @return string
  4307. * @uses dtree.js :: necessary javascript for building this tree
  4308. */
  4309. public function build_tree() {
  4310. $return = "<script type=\"text/javascript\">\n";
  4311. $return .= "\tm = new dTree('m');\n\n";
  4312. $return .= "\tm.config.folderLinks = true;\n";
  4313. $return .= "\tm.config.useCookies = true;\n";
  4314. $return .= "\tm.config.useIcons = true;\n";
  4315. $return .= "\tm.config.useLines = true;\n";
  4316. $return .= "\tm.config.useSelection = true;\n";
  4317. $return .= "\tm.config.useStatustext = false;\n\n";
  4318. $menu = 0;
  4319. $parent = '';
  4320. $return .= "\tm.add(" . $menu . ", -1, '" . addslashes(Security::remove_XSS(($this->name))) . "');\n";
  4321. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  4322. $sql = " SELECT id, title, description, item_type, path, parent_item_id, previous_item_id, next_item_id, max_score, min_score, mastery_score, display_order
  4323. FROM " . $tbl_lp_item . "
  4324. WHERE lp_id = " . Database :: escape_string($this->lp_id);
  4325. $result = Database::query($sql);
  4326. $arrLP = array ();
  4327. while ($row = Database :: fetch_array($result)) {
  4328. $row['title'] = Security :: remove_XSS($row['title']);
  4329. $row['description'] = Security :: remove_XSS($row['description']);
  4330. $arrLP[] = array (
  4331. 'id' => $row['id'],
  4332. 'item_type' => $row['item_type'],
  4333. 'title' => $row['title'],
  4334. 'path' => $row['path'],
  4335. 'description' => $row['description'],
  4336. 'parent_item_id' => $row['parent_item_id'],
  4337. 'previous_item_id' => $row['previous_item_id'],
  4338. 'next_item_id' => $row['next_item_id'],
  4339. 'max_score' => $row['max_score'],
  4340. 'min_score' => $row['min_score'],
  4341. 'mastery_score' => $row['mastery_score'],
  4342. 'display_order' => $row['display_order']
  4343. );
  4344. }
  4345. $this->tree_array($arrLP);
  4346. $arrLP = $this->arrMenu;
  4347. unset ($this->arrMenu);
  4348. $title = '';
  4349. for ($i = 0; $i < count($arrLP); $i++) {
  4350. $title = addslashes($arrLP[$i]['title']);
  4351. $menu_page = api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&amp;action=view_item&amp;id=' . $arrLP[$i]['id'] . '&amp;lp_id=' . $_SESSION['oLP']->lp_id;
  4352. $icon_name = str_replace(' ', '', $arrLP[$i]['item_type']);
  4353. if (file_exists('../img/lp_' . $icon_name . '.png')) {
  4354. $return .= "\tm.add(" . $arrLP[$i]['id'] . ", " . $arrLP[$i]['parent_item_id'] . ", '" . $title . "', '" . $menu_page . "', '', '', '../img/lp_" . $icon_name . ".png', '../img/lp_" . $icon_name . ".png');\n";
  4355. } else
  4356. if (file_exists('../img/lp_' . $icon_name . '.gif')) {
  4357. $return .= "\tm.add(" . $arrLP[$i]['id'] . ", " . $arrLP[$i]['parent_item_id'] . ", '" . $title . "', '" . $menu_page . "', '', '', '../img/lp_" . $icon_name . ".gif', '../img/lp_" . $icon_name . ".gif');\n";
  4358. } else {
  4359. $return .= "\tm.add(" . $arrLP[$i]['id'] . ", " . $arrLP[$i]['parent_item_id'] . ", '" . $title . "', '" . $menu_page . "', '', '', '../img/folder_document.gif', '../img/folder_document.gif');\n";
  4360. }
  4361. if ($menu < $arrLP[$i]['id'])
  4362. $menu = $arrLP[$i]['id'];
  4363. }
  4364. $return .= "\n\tdocument.write(m);\n";
  4365. $return .= "\t if(!m.selectedNode) m.s(1);";
  4366. $return .= "</script>\n";
  4367. return $return;
  4368. }
  4369. /**
  4370. * Create a new document //still needs some finetuning
  4371. * @param array $_course
  4372. * @return string
  4373. */
  4374. public function create_document($_course) {
  4375. global $charset;
  4376. $dir = isset ($_GET['dir']) ? $_GET['dir'] : $_POST['dir']; // Please, do not modify this dirname formatting.
  4377. if (strstr($dir, '..'))
  4378. $dir = '/';
  4379. if ($dir[0] == '.')
  4380. $dir = substr($dir, 1);
  4381. if ($dir[0] != '/')
  4382. $dir = '/' . $dir;
  4383. if ($dir[strlen($dir) - 1] != '/')
  4384. $dir .= '/';
  4385. $filepath = api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document' . $dir;
  4386. if (!is_dir($filepath)) {
  4387. $filepath = api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document/';
  4388. $dir = '/';
  4389. }
  4390. // stripslashes() before calling replace_dangerous_char() because $_POST['title']
  4391. // is already escaped twice when it gets here.
  4392. $title = replace_dangerous_char(stripslashes($_POST['title']));
  4393. $title = disable_dangerous_file($title);
  4394. $filename = $title;
  4395. $content = $_POST['content_lp'];
  4396. $tmp_filename = $filename;
  4397. $i = 0;
  4398. while (file_exists($filepath . $tmp_filename . '.html'))
  4399. $tmp_filename = $filename . '_' . ++ $i;
  4400. $filename = $tmp_filename . '.html';
  4401. $content = stripslashes(text_filter($content));
  4402. $content = str_replace(api_get_path(WEB_COURSE_PATH), api_get_path(REL_PATH) . 'courses/', $content);
  4403. // Change the path of mp3 to absolute.
  4404. // The first regexp deals with ../../../ urls.
  4405. $content = preg_replace("|(flashvars=\"file=)(\.+/)+|", "$1" . api_get_path(REL_COURSE_PATH) . $_course['path'] . '/document/', $content);
  4406. // The second regexp deals with audio/ urls.
  4407. $content = preg_replace("|(flashvars=\"file=)([^/]+)/|", "$1" . api_get_path(REL_COURSE_PATH) . $_course['path'] . '/document/$2/', $content);
  4408. // For flv player: To prevent edition problem with firefox, we have to use a strange tip (don't blame me please).
  4409. $content = str_replace('</body>', '<style type="text/css">body{}</style></body>', $content);
  4410. if (!file_exists($filepath . $filename)) {
  4411. if ($fp = @ fopen($filepath . $filename, 'w')) {
  4412. fputs($fp, $content);
  4413. fclose($fp);
  4414. $file_size = filesize($filepath . $filename);
  4415. $save_file_path = $dir . $filename;
  4416. $document_id = add_document($_course, $save_file_path, 'file', $file_size, $filename . '.html');
  4417. if ($document_id) {
  4418. api_item_property_update($_course, TOOL_DOCUMENT, $document_id, 'DocumentAdded', api_get_user_id(), null, null, null, null, api_get_session_id());
  4419. // Update parent folders.
  4420. //item_property_update_on_folder($_course, $_GET['dir'], $_user['user_id']);
  4421. $new_comment = (isset($_POST['comment'])) ? trim($_POST['comment']) : '';
  4422. $new_title = (isset($_POST['title'])) ? trim($_POST['title']) : '';
  4423. if ($new_comment || $new_title) {
  4424. $tbl_doc = Database :: get_course_table(TABLE_DOCUMENT);
  4425. $ct = '';
  4426. if ($new_comment)
  4427. $ct .= ", comment='" . $new_comment . "'";
  4428. if ($new_title)
  4429. $ct .= ", title='" . Database :: escape_string(htmlspecialchars($new_title, ENT_QUOTES, $charset)) . ".html '";
  4430. $sql_update = "
  4431. UPDATE " . $tbl_doc . "
  4432. SET " . substr($ct, 1) . "
  4433. WHERE id = " . $document_id;
  4434. Database::query($sql_update);
  4435. }
  4436. }
  4437. return $document_id;
  4438. }
  4439. }
  4440. }
  4441. /**
  4442. * Edit a document based on $_POST and $_GET parameters 'dir' and 'path'
  4443. * @param array $_course array
  4444. * @return void
  4445. */
  4446. public function edit_document($_course) {
  4447. global $_configuration;
  4448. $dir = isset ($_GET['dir']) ? $_GET['dir'] : $_POST['dir']; // Please, do not modify this dirname formatting.
  4449. if (strstr($dir, '..'))
  4450. $dir = '/';
  4451. if ($dir[0] == '.')
  4452. $dir = substr($dir, 1);
  4453. if ($dir[0] != '/')
  4454. $dir = '/' . $dir;
  4455. if ($dir[strlen($dir) - 1] != '/')
  4456. $dir .= '/';
  4457. $filepath = api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document' . $dir;
  4458. if (!is_dir($filepath)) {
  4459. $filepath = api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document/';
  4460. $dir = '/';
  4461. }
  4462. $table_doc = Database :: get_course_table(TABLE_DOCUMENT);
  4463. if (isset($_POST['path']) && !empty($_POST['path'])) {
  4464. $sql = "SELECT path
  4465. FROM " . $table_doc . "
  4466. WHERE id = " . Database::escape_string($_POST['path']);
  4467. $res = Database::query($sql);
  4468. $row = Database :: fetch_array($res);
  4469. $content = stripslashes($_POST['content_lp']);
  4470. $file = $filepath . $row['path'];
  4471. if ($fp = @ fopen($file, 'w')) {
  4472. $content = text_filter($content);
  4473. $content = str_replace(api_get_path(WEB_COURSE_PATH), $_configuration['url_append'] . '/courses/', $content);
  4474. // Change the path of mp3 to absolute.
  4475. // The first regexp deals with ../../../ urls.
  4476. $content = preg_replace("|(flashvars=\"file=)(\.+/)+|", "$1" . api_get_path(REL_COURSE_PATH) . $_course['path'] . '/document/', $content);
  4477. // The second regexp deals with audio/ urls.
  4478. $content = preg_replace("|(flashvars=\"file=)([^/]+)/|", "$1" . api_get_path(REL_COURSE_PATH) . $_course['path'] . '/document/$2/', $content);
  4479. fputs($fp, $content);
  4480. fclose($fp);
  4481. }
  4482. }
  4483. }
  4484. /**
  4485. * Displays the selected item, with a panel for manipulating the item
  4486. * @param int $item_id
  4487. * @param string $msg
  4488. * @return string
  4489. */
  4490. public function display_item($item_id, $iframe = true, $msg = '') {
  4491. global $_course; // It will disappear.
  4492. $return = '';
  4493. if (is_numeric($item_id)) {
  4494. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  4495. $tbl_doc = Database :: get_course_table(TABLE_DOCUMENT);
  4496. $sql = "SELECT lp.* FROM " . $tbl_lp_item . " as lp
  4497. WHERE lp.id = " . Database :: escape_string($item_id);
  4498. $result = Database::query($sql);
  4499. while ($row = Database :: fetch_array($result)) {
  4500. $_SESSION['parent_item_id'] = ($row['item_type'] == 'dokeos_chapter' || $row['item_type'] == 'dokeos_module' || $row['item_type'] == 'dir') ? $item_id : 0;
  4501. // Prevents wrong parent selection for document, see Bug#1251.
  4502. if ($row['item_type'] != 'dokeos_chapter' || $row['item_type'] != 'dokeos_module') {
  4503. $_SESSION['parent_item_id'] = $row['parent_item_id'];
  4504. }
  4505. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4506. $return .= '<div style="padding:10px;">';
  4507. if ($msg != '')
  4508. $return .= $msg;
  4509. $return .= '<p class="lp_title">' . $row['title'] . '</p>';
  4510. //$return .= '<p class="lp_text">' . ((trim($row['description']) == '') ? 'no description' : stripslashes($row['description'])) . '</p>';
  4511. //$return .= '<hr />';
  4512. if ($row['item_type'] == TOOL_DOCUMENT) {
  4513. $tbl_doc = Database :: get_course_table(TABLE_DOCUMENT);
  4514. $sql_doc = "SELECT path FROM " . $tbl_doc . " WHERE id = " . Database :: escape_string($row['path']);
  4515. $result = Database::query($sql_doc);
  4516. $path_file = Database :: result($result, 0, 0);
  4517. $path_parts = pathinfo($path_file);
  4518. // TODO: Correct the following naive comparisons, also, htm extension is missing.
  4519. if (in_array($path_parts['extension'], array (
  4520. 'html',
  4521. 'txt',
  4522. 'png',
  4523. 'jpg',
  4524. 'JPG',
  4525. 'jpeg',
  4526. 'JPEG',
  4527. 'gif',
  4528. 'swf'
  4529. ))) {
  4530. $return .= $this->display_document($row['path'], true, true);
  4531. }
  4532. }
  4533. $return .= '</div>';
  4534. }
  4535. }
  4536. return $return;
  4537. }
  4538. /**
  4539. * Shows the needed forms for editing a specific item
  4540. * @param int $item_id
  4541. * @return string
  4542. */
  4543. public function display_edit_item($item_id) {
  4544. global $_course; // It will disappear.
  4545. $return = '';
  4546. if (is_numeric($item_id)) {
  4547. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  4548. $sql = "SELECT *
  4549. FROM " . $tbl_lp_item . "
  4550. WHERE id = " . Database :: escape_string($item_id);
  4551. $res = Database::query($sql);
  4552. $row = Database :: fetch_array($res);
  4553. switch ($row['item_type']) {
  4554. case 'dokeos_chapter' :
  4555. case 'dir' :
  4556. case 'asset' :
  4557. case 'sco' :
  4558. if (isset ($_GET['view']) && $_GET['view'] == 'build') {
  4559. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4560. $return .= $this->display_item_form($row['item_type'], get_lang('EditCurrentChapter') . ' :', 'edit', $item_id, $row);
  4561. } else {
  4562. $return .= $this->display_item_small_form($row['item_type'], get_lang('EditCurrentChapter') . ' :', $row);
  4563. }
  4564. break;
  4565. case TOOL_DOCUMENT :
  4566. $tbl_doc = Database :: get_course_table(TABLE_DOCUMENT);
  4567. $sql_step = " SELECT lp.*, doc.path as dir
  4568. FROM " . $tbl_lp_item . " as lp
  4569. LEFT JOIN " . $tbl_doc . " as doc ON doc.id = lp.path
  4570. WHERE lp.id = " . Database :: escape_string($item_id);
  4571. $res_step = Database::query($sql_step);
  4572. $row_step = Database :: fetch_array($res_step);
  4573. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4574. $return .= $this->display_document_form('edit', $item_id, $row_step);
  4575. break;
  4576. case TOOL_LINK :
  4577. $link_id = (string) $row['path'];
  4578. if (ctype_digit($link_id)) {
  4579. $tbl_link = Database :: get_course_table(TABLE_LINK);
  4580. $sql_select = 'SELECT url FROM ' . $tbl_link . ' WHERE id = ' . Database :: escape_string($link_id);
  4581. $res_link = Database::query($sql_select);
  4582. $row_link = Database :: fetch_array($res_link);
  4583. if (is_array($row_link)) {
  4584. $row['url'] = $row_link['url'];
  4585. }
  4586. }
  4587. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4588. $return .= $this->display_link_form('edit', $item_id, $row);
  4589. break;
  4590. case 'dokeos_module' :
  4591. if (isset ($_GET['view']) && $_GET['view'] == 'build') {
  4592. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4593. $return .= $this->display_item_form($row['item_type'], get_lang('EditCurrentModule') . ' :', 'edit', $item_id, $row);
  4594. } else {
  4595. $return .= $this->display_item_small_form($row['item_type'], get_lang('EditCurrentModule') . ' :', $row);
  4596. }
  4597. break;
  4598. case TOOL_QUIZ :
  4599. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4600. $return .= $this->display_quiz_form('edit', $item_id, $row);
  4601. break;
  4602. case TOOL_HOTPOTATOES :
  4603. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4604. $return .= $this->display_hotpotatoes_form('edit', $item_id, $row);
  4605. break;
  4606. case TOOL_STUDENTPUBLICATION :
  4607. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4608. $return .= $this->display_student_publication_form('edit', $item_id, $row);
  4609. break;
  4610. case TOOL_FORUM :
  4611. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4612. $return .= $this->display_forum_form('edit', $item_id, $row);
  4613. break;
  4614. case TOOL_THREAD :
  4615. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4616. $return .= $this->display_thread_form('edit', $item_id, $row);
  4617. break;
  4618. }
  4619. }
  4620. return $return;
  4621. }
  4622. /**
  4623. * Function that displays a list with al the resources that could be added to the learning path
  4624. * @return string
  4625. */
  4626. public function display_resources() {
  4627. global $_course; // TODO: Don't use globals.
  4628. $return .= '<div class="sectiontitle">' . get_lang('CreateNewStep') . '</div>';
  4629. $return .= '<div class="sectioncomment"><a href="' . api_get_self() . '?cidReq=' . $_GET['cidReq'] . '&amp;action=add_item&amp;type=' . TOOL_DOCUMENT . '&amp;lp_id=' . $_SESSION['oLP']->lp_id . '">' . '<img title="Nuevo documento" src="../img/new_doc.gif" alt="Nuevo documento"/> ' . get_lang('NewDocument') . '</a></div>'; // TODO: A hardcoded Spanish text is here.
  4630. $return .= '<div class="sectiontitle">' . get_lang('UseAnExistingResource') . '</div>';
  4631. $return .= '<div class="sectioncomment">';
  4632. /* Get all the docs. */
  4633. $return .= $this->get_documents();
  4634. /* Get all the exercises. */
  4635. $return .= $this->get_exercises();
  4636. /* Get all the links. */
  4637. $return .= $this->get_links();
  4638. /* Get al the student publications. */
  4639. $return .= $this->get_student_publications();
  4640. /* Get al the forums. */
  4641. $return .= $this->get_forums();
  4642. $return .= '</div>';
  4643. return $return;
  4644. }
  4645. /**
  4646. * Returns the extension of a document
  4647. * @param string filename
  4648. * @return string Extension (part after the last dot)
  4649. */
  4650. public function get_extension($filename) {
  4651. $explode = explode('.', $filename);
  4652. return $explode[count($explode) - 1];
  4653. }
  4654. /**
  4655. * Displays a document by id
  4656. *
  4657. * @param unknown_type $id
  4658. * @return unknown
  4659. */
  4660. public function display_document($id, $show_title = false, $iframe = true, $edit_link = false) {
  4661. global $_course; // It is temporary.
  4662. $return = '';
  4663. $tbl_doc = Database :: get_course_table(TABLE_DOCUMENT);
  4664. $sql_doc = "SELECT * FROM " . $tbl_doc . "
  4665. WHERE id = " . $id;
  4666. $res_doc = Database::query($sql_doc);
  4667. $row_doc = Database :: fetch_array($res_doc);
  4668. //if ($show_title)
  4669. //$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>';
  4670. // TODO: Add a path filter.
  4671. if ($iframe) {
  4672. $return .= '<iframe id="learnpath_preview_frame" frameborder="0" height="400" width="100%" scrolling="auto" src="' . api_get_path(WEB_COURSE_PATH) . $_course['path'] . '/document' . str_replace('%2F', '/', urlencode($row_doc['path'])) . '?' . api_get_cidreq() . '"></iframe>';
  4673. } else {
  4674. $return .= file_get_contents(api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document' . $row_doc['path']);
  4675. }
  4676. return $return;
  4677. }
  4678. /**
  4679. * Return HTML form to add/edit a quiz
  4680. * @param string Action (add/edit)
  4681. * @param integer Item ID if already exists
  4682. * @param mixed Extra information (quiz ID if integer)
  4683. * @return string HTML form
  4684. */
  4685. public function display_quiz_form($action = 'add', $id = 0, $extra_info = '') {
  4686. global $charset;
  4687. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  4688. $tbl_quiz = Database :: get_course_table(TABLE_QUIZ_TEST);
  4689. if ($id != 0 && is_array($extra_info)) {
  4690. $item_title = stripslashes($extra_info['title']);
  4691. $item_description = stripslashes($extra_info['description']);
  4692. }
  4693. elseif (is_numeric($extra_info)) {
  4694. $sql_quiz = "
  4695. SELECT
  4696. title,
  4697. description
  4698. FROM " . $tbl_quiz . "
  4699. WHERE id = " . $extra_info;
  4700. $result = Database::query($sql_quiz);
  4701. $row = Database :: fetch_array($result);
  4702. $item_title = $row['title'];
  4703. $item_description = $row['description'];
  4704. } else {
  4705. $item_title = '';
  4706. $item_description = '';
  4707. }
  4708. $return = ' <div class="row">
  4709. <div class="form_header">';
  4710. if ($id != 0 && is_array($extra_info))
  4711. $parent = $extra_info['parent_item_id'];
  4712. else
  4713. $parent = 0;
  4714. $sql = "
  4715. SELECT *
  4716. FROM " . $tbl_lp_item . "
  4717. WHERE
  4718. lp_id = " . $this->lp_id;
  4719. $result = Database::query($sql);
  4720. $arrLP = array ();
  4721. while ($row = Database :: fetch_array($result)) {
  4722. $arrLP[] = array (
  4723. 'id' => $row['id'],
  4724. 'item_type' => $row['item_type'],
  4725. 'title' => $row['title'],
  4726. 'path' => $row['path'],
  4727. 'description' => $row['description'],
  4728. 'parent_item_id' => $row['parent_item_id'],
  4729. 'previous_item_id' => $row['previous_item_id'],
  4730. 'next_item_id' => $row['next_item_id'],
  4731. 'display_order' => $row['display_order'],
  4732. 'max_score' => $row['max_score'],
  4733. 'min_score' => $row['min_score'],
  4734. 'mastery_score' => $row['mastery_score'],
  4735. 'prerequisite' => $row['prerequisite'],
  4736. 'max_time_allowed' => $row['max_time_allowed']
  4737. );
  4738. }
  4739. $this->tree_array($arrLP);
  4740. $arrLP = $this->arrMenu;
  4741. unset ($this->arrMenu);
  4742. if ($action == 'add')
  4743. $return .= get_lang('CreateTheExercise') . '&nbsp;:' . "\n";
  4744. elseif ($action == 'move') $return .= get_lang('MoveTheCurrentExercise') . '&nbsp;:' . "\n";
  4745. else
  4746. $return .= get_lang('EditCurrentExecice') . '&nbsp;:' . "\n";
  4747. if (isset ($_GET['edit']) && $_GET['edit'] == 'true') {
  4748. $return .= Display :: return_warning_message('<p class="lp_title">' . get_lang('Warning') . ' !</p>' . get_lang('WarningEditingDocument'));
  4749. }
  4750. $return .= ' </div>
  4751. </div>';
  4752. $return .= '<div class="sectioncomment">';
  4753. $return .= '<form method="POST">' . "\n";
  4754. $return .= "\t" . '<table class="lp_form">' . "\n";
  4755. if ($action != 'move') {
  4756. $return .= "\t\t" . '<tr>' . "\n";
  4757. $return .= "\t\t\t" . '<td class="label"><label for="idTitle">' . get_lang('Title') . '</label></td>' . "\n";
  4758. $return .= "\t\t\t" . '<td class="input"><input id="idTitle" name="title" size="44" type="text" class="learnpath_item_form" value="' . $item_title . '" /></td>' . "\n";
  4759. $return .= "\t\t" . '</tr>' . "\n";
  4760. }
  4761. $return .= "\t\t" . '<tr>' . "\n";
  4762. $return .= "\t\t\t" . '<td class="label"><label for="idParent">' . get_lang('Parent') . '</label></td>' . "\n";
  4763. $return .= "\t\t\t" . '<td class="input">' . "\n";
  4764. $return .= "\t\t\t\t" . '<select id="idParent" style="width:100%;" name="parent" onchange="javascript: load_cbo(this.value);" class="learnpath_item_form" size="1">';
  4765. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
  4766. $arrHide = array (
  4767. $id
  4768. );
  4769. //$parent_item_id = $_SESSION['parent_item_id'];
  4770. for ($i = 0; $i < count($arrLP); $i++) {
  4771. if ($action != 'add') {
  4772. 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)) {
  4773. $return .= "\t\t\t\t\t" . '<option ' . (($parent == $arrLP[$i]['id']) ? 'selected="selected" ' : '') . 'style="padding-left:' . ($arrLP[$i]['depth'] * 10) . 'px;" value="' . $arrLP[$i]['id'] . '">' . $arrLP[$i]['title'] . '</option>';
  4774. } else {
  4775. $arrHide[] = $arrLP[$i]['id'];
  4776. }
  4777. } else {
  4778. if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
  4779. $return .= "\t\t\t\t\t" . '<option ' . (($parent == $arrLP[$i]['id']) ? 'selected="selected" ' : '') . 'style="padding-left:' . ($arrLP[$i]['depth'] * 10) . 'px;" value="' . $arrLP[$i]['id'] . '">' . $arrLP[$i]['title'] . '</option>';
  4780. }
  4781. }
  4782. if (is_array($arrLP)) {
  4783. reset($arrLP);
  4784. }
  4785. $return .= '</select>';
  4786. $return .= '</td>';
  4787. $return .= '</tr>';
  4788. $return .= '<tr>';
  4789. $return .= "\t\t\t" . '<td class="label"><label for="idPosition">' . get_lang('Position') . '</label></td>' . "\n";
  4790. $return .= "\t\t\t" . '<td class="input">' . "\n";
  4791. $return .= "\t\t\t\t" . '<select class="learnpath_item_form" style="width:100%;" id="idPosition" name="previous" size="1">';
  4792. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . get_lang('FirstPosition') . '</option>';
  4793. for ($i = 0; $i < count($arrLP); $i++) {
  4794. if ($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) {
  4795. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  4796. $selected = 'selected="selected" ';
  4797. elseif ($action == 'add') $selected = 'selected="selected" ';
  4798. else
  4799. $selected = '';
  4800. $return .= "\t\t\t\t\t" . '<option ' . $selected . 'value="' . $arrLP[$i]['id'] . '">' . get_lang('After') . ' "' . $arrLP[$i]['title'] . '"</option>';
  4801. }
  4802. }
  4803. $return .= "\t\t\t\t" . '</select>';
  4804. $return .= "\t\t\t" . '</td>' . "\n";
  4805. $return .= "\t\t" . '</tr>' . "\n";
  4806. if ($action != 'move') {
  4807. $id_prerequisite = 0;
  4808. if (is_array($arrLP)) {
  4809. foreach ($arrLP as $key => $value) {
  4810. if ($value['id'] == $id) {
  4811. $id_prerequisite = $value['prerequisite'];
  4812. break;
  4813. }
  4814. }
  4815. }
  4816. $arrHide = array ();
  4817. for ($i = 0; $i < count($arrLP); $i++) {
  4818. if ($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter') {
  4819. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  4820. $s_selected_position = $arrLP[$i]['id'];
  4821. elseif ($action == 'add') $s_selected_position = 0;
  4822. $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
  4823. }
  4824. }
  4825. /*// Commented the prerequisites, only visible in edit (exercise).
  4826. $return .= "\t\t" . '<tr>' . "\n";
  4827. $return .= "\t\t\t" . '<td class="label"><label for="idPrerequisites">'.get_lang('Prerequisites').'</label></td>' . "\n";
  4828. $return .= "\t\t\t" . '<td class="input"><select name="prerequisites" id="prerequisites" class="learnpath_item_form"><option value="0">'.get_lang('NoPrerequisites').'</option>';
  4829. foreach($arrHide as $key => $value){
  4830. if($key==$s_selected_position && $action == 'add'){
  4831. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  4832. }
  4833. elseif($key==$id_prerequisite && $action == 'edit'){
  4834. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  4835. }
  4836. else{
  4837. $return .= '<option value="'.$key.'">'.$value['value'].'</option>';
  4838. }
  4839. }
  4840. $return .= "</select></td>";
  4841. */
  4842. $return .= "\t\t" . '</tr>' . "\n";
  4843. /*$return .= "\t\t" . '<tr>' . "\n";
  4844. $return .= "\t\t\t" . '<td class="label"><label for="maxTimeAllowed">' . get_lang('MaxTimeAllowed') . '</label></td>' . "\n";
  4845. $return .= "\t\t\t" . '<td class="input"><input name="maxTimeAllowed" style="width:98%;" id="maxTimeAllowed" value="' . $extra_info['max_time_allowed'] . '" /></td>';
  4846. // Remove temporarily the test description.
  4847. //$return .= "\t\t\t" . '<td class="label"><label for="idDescription">'.get_lang('Description').' :</label></td>' . "\n";
  4848. //$return .= "\t\t\t" . '<td class="input"><textarea id="idDescription" name="description" rows="4">' . $item_description . '</textarea></td>' . "\n";
  4849. $return .= "\t\t" . '</tr>' . "\n"; */
  4850. }
  4851. $return .= "\t\t" . '<tr>' . "\n";
  4852. if ($action == 'add') {
  4853. $return .= '<td>&nbsp;</td><td><button class="save" name="submit_button" type="submit">' . get_lang('AddExercise') . '</button></td>';
  4854. } else {
  4855. $return .= '<td>&nbsp;</td><td><button class="save" name="submit_button" type="submit">' . get_lang('EditCurrentExecice') . '</button></td>';
  4856. }
  4857. $return .= "\t\t" . '</tr>' . "\n";
  4858. $return .= "\t" . '</table>' . "\n";
  4859. if ($action == 'move') {
  4860. $return .= "\t" . '<input name="title" type="hidden" value="' . $item_title . '" />' . "\n";
  4861. $return .= "\t" . '<input name="description" type="hidden" value="' . $item_description . '" />' . "\n";
  4862. }
  4863. if (is_numeric($extra_info)) {
  4864. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info . '" />' . "\n";
  4865. }
  4866. elseif (is_array($extra_info)) {
  4867. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />' . "\n";
  4868. }
  4869. $return .= "\t" . '<input name="type" type="hidden" value="' . TOOL_QUIZ . '" />' . "\n";
  4870. $return .= "\t" . '<input name="post_time" type="hidden" value="' . time() . '" />' . "\n";
  4871. $return .= '</form>' . "\n";
  4872. $return .= '</div>' . "\n";
  4873. return $return;
  4874. }
  4875. /**
  4876. * Addition of Hotpotatoes tests
  4877. * @param string Action
  4878. * @param integer Internal ID of the item
  4879. * @param mixed Extra information - can be an array with title and description indexes
  4880. * @return string HTML structure to display the hotpotatoes addition formular
  4881. */
  4882. public function display_hotpotatoes_form($action = 'add', $id = 0, $extra_info = '') {
  4883. global $charset;
  4884. $uploadPath = DIR_HOTPOTATOES; //defined in main_api
  4885. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  4886. if ($id != 0 && is_array($extra_info)) {
  4887. $item_title = stripslashes($extra_info['title']);
  4888. $item_description = stripslashes($extra_info['description']);
  4889. }
  4890. elseif (is_numeric($extra_info)) {
  4891. $TBL_DOCUMENT = Database :: get_course_table(TABLE_DOCUMENT);
  4892. $sql_hot = "SELECT * FROM " . $TBL_DOCUMENT . "
  4893. WHERE path LIKE '" . $uploadPath . "/%/%htm%'
  4894. AND id = " . (int) $extra_info . " ORDER BY id ASC";
  4895. $res_hot = Database::query($sql_hot);
  4896. $row = Database :: fetch_array($res_hot);
  4897. $item_title = $row['title'];
  4898. $item_description = $row['description'];
  4899. if (!empty ($row['comment'])) {
  4900. $item_title = $row['comment'];
  4901. }
  4902. } else {
  4903. $item_title = '';
  4904. $item_description = '';
  4905. }
  4906. $return = '<div style="margin:3px 12px;">';
  4907. if ($id != 0 && is_array($extra_info))
  4908. $parent = $extra_info['parent_item_id'];
  4909. else
  4910. $parent = 0;
  4911. $sql = "
  4912. SELECT *
  4913. FROM " . $tbl_lp_item . "
  4914. WHERE
  4915. lp_id = " . $this->lp_id;
  4916. $result = Database::query($sql);
  4917. $arrLP = array ();
  4918. while ($row = Database :: fetch_array($result)) {
  4919. $arrLP[] = array (
  4920. 'id' => $row['id'],
  4921. 'item_type' => $row['item_type'],
  4922. 'title' => $row['title'],
  4923. 'path' => $row['path'],
  4924. 'description' => $row['description'],
  4925. 'parent_item_id' => $row['parent_item_id'],
  4926. 'previous_item_id' => $row['previous_item_id'],
  4927. 'next_item_id' => $row['next_item_id'],
  4928. 'display_order' => $row['display_order'],
  4929. 'max_score' => $row['max_score'],
  4930. 'min_score' => $row['min_score'],
  4931. 'mastery_score' => $row['mastery_score'],
  4932. 'prerequisite' => $row['prerequisite'],
  4933. 'max_time_allowed' => $row['max_time_allowed']
  4934. );
  4935. }
  4936. $this->tree_array($arrLP);
  4937. $arrLP = $this->arrMenu;
  4938. unset ($this->arrMenu);
  4939. if ($action == 'add')
  4940. $return .= '<p class="lp_title">' . get_lang('CreateTheExercise') . '&nbsp;:</p>' . "\n";
  4941. elseif ($action == 'move') $return .= '<p class="lp_title">' . get_lang('MoveTheCurrentExercise') . '&nbsp;:</p>' . "\n";
  4942. else
  4943. $return .= '<p class="lp_title">' . get_lang('EditCurrentExecice') . '&nbsp;:</p>' . "\n";
  4944. if (isset ($_GET['edit']) && $_GET['edit'] == 'true') {
  4945. $return .= Display :: return_warning_message('<p class="lp_title">' . get_lang('Warning') . ' !</p>' . get_lang('WarningEditingDocument'));
  4946. }
  4947. $return .= '<form method="POST">' . "\n";
  4948. $return .= "\t" . '<table cellpadding="0" cellspacing="0" class="lp_form">' . "\n";
  4949. $return .= "\t\t" . '<tr>' . "\n";
  4950. $return .= "\t\t\t" . '<td class="label"><label for="idParent">' . get_lang('Parent') . ' :</label></td>' . "\n";
  4951. $return .= "\t\t\t" . '<td class="input">' . "\n";
  4952. $return .= "\t\t\t\t" . '<select id="idParent" name="parent" onchange="javascript: load_cbo(this.value);" size="1">';
  4953. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
  4954. $arrHide = array (
  4955. $id
  4956. );
  4957. if (count($arrLP) > 0) {
  4958. for ($i = 0; $i < count($arrLP); $i++) {
  4959. if ($action != 'add') {
  4960. 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)) {
  4961. $return .= "\t\t\t\t\t" . '<option ' . (($parent == $arrLP[$i]['id']) ? 'selected="selected" ' : '') . 'style="padding-left:' . ($arrLP[$i]['depth'] * 10) . 'px;" value="' . $arrLP[$i]['id'] . '">' . $arrLP[$i]['title'] . '</option>';
  4962. } else {
  4963. $arrHide[] = $arrLP[$i]['id'];
  4964. }
  4965. } else {
  4966. if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
  4967. $return .= "\t\t\t\t\t" . '<option ' . (($parent == $arrLP[$i]['id']) ? 'selected="selected" ' : '') . 'style="padding-left:' . ($arrLP[$i]['depth'] * 10) . 'px;" value="' . $arrLP[$i]['id'] . '">' . $arrLP[$i]['title'] . '</option>';
  4968. }
  4969. }
  4970. reset($arrLP);
  4971. }
  4972. $return .= "\t\t\t\t" . '</select>';
  4973. $return .= "\t\t\t" . '</td>' . "\n";
  4974. $return .= "\t\t" . '</tr>' . "\n";
  4975. $return .= "\t\t" . '<tr>' . "\n";
  4976. $return .= "\t\t\t" . '<td class="label"><label for="idPosition">' . get_lang('Position') . ' :</label></td>' . "\n";
  4977. $return .= "\t\t\t" . '<td class="input">' . "\n";
  4978. $return .= "\t\t\t\t" . '<select id="idPosition" name="previous" size="1">';
  4979. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . get_lang('FirstPosition') . '</option>';
  4980. for ($i = 0; $i < count($arrLP); $i++) {
  4981. if ($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) {
  4982. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  4983. $selected = 'selected="selected" ';
  4984. elseif ($action == 'add') $selected = 'selected="selected" ';
  4985. else
  4986. $selected = '';
  4987. $return .= "\t\t\t\t\t" . '<option ' . $selected . 'value="' . $arrLP[$i]['id'] . '">' . get_lang('After') . ' "' . $arrLP[$i]['title'] . '"</option>';
  4988. }
  4989. }
  4990. $return .= "\t\t\t\t" . '</select>';
  4991. $return .= "\t\t\t" . '</td>' . "\n";
  4992. $return .= "\t\t" . '</tr>' . "\n";
  4993. if ($action != 'move') {
  4994. $return .= "\t\t" . '<tr>' . "\n";
  4995. $return .= "\t\t\t" . '<td class="label"><label for="idTitle">' . get_lang('Title') . ' :</label></td>' . "\n";
  4996. $return .= "\t\t\t" . '<td class="input"><input id="idTitle" name="title" type="text" value="' . $item_title . '" /></td>' . "\n";
  4997. $return .= "\t\t" . '</tr>' . "\n";
  4998. $id_prerequisite = 0;
  4999. if (is_array($arrLP) && count($arrLP) > 0) {
  5000. foreach ($arrLP as $key => $value) {
  5001. if ($value['id'] == $id) {
  5002. $id_prerequisite = $value['prerequisite'];
  5003. break;
  5004. }
  5005. }
  5006. $arrHide = array ();
  5007. for ($i = 0; $i < count($arrLP); $i++) {
  5008. if ($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter') {
  5009. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5010. $s_selected_position = $arrLP[$i]['id'];
  5011. elseif ($action == 'add') $s_selected_position = 0;
  5012. $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
  5013. }
  5014. }
  5015. }
  5016. $return .= "\t\t" . '<tr>' . "\n";
  5017. //$return .= "\t\t\t" . '<td class="label"><label for="idPrerequisites">'.get_lang('Prerequisites').' :</label></td>' . "\n";
  5018. //$return .= "\t\t\t" . '<td class="input"><select name="prerequisites" id="prerequisites"><option value="0">'.get_lang('NoPrerequisites').'</option>';
  5019. foreach ($arrHide as $key => $value) {
  5020. if ($key == $s_selected_position && $action == 'add') {
  5021. $return .= '<option value="' . $key . '" selected="selected">' . $value['value'] . '</option>';
  5022. }
  5023. elseif ($key == $id_prerequisite && $action == 'edit') {
  5024. $return .= '<option value="' . $key . '" selected="selected">' . $value['value'] . '</option>';
  5025. } else {
  5026. $return .= '<option value="' . $key . '">' . $value['value'] . '</option>';
  5027. }
  5028. }
  5029. $return .= "</select></td>";
  5030. $return .= "\t\t" . '</tr>' . "\n";
  5031. $return .= "\t\t" . '<tr>' . "\n";
  5032. $return .= "\t\t" . '</tr>' . "\n";
  5033. }
  5034. $return .= "\t\t" . '<tr>' . "\n";
  5035. $return .= "\t\t\t" . '<td> &nbsp;</td><td><button class="save" name="submit_button" action="edit" type="submit">' . get_lang('SaveHotpotatoes') . '</button></td>' . "\n";
  5036. $return .= "\t\t" . '</tr>' . "\n";
  5037. $return .= "\t" . '</table>' . "\n";
  5038. if ($action == 'move') {
  5039. $return .= "\t" . '<input name="title" type="hidden" value="' . $item_title . '" />' . "\n";
  5040. $return .= "\t" . '<input name="description" type="hidden" value="' . $item_description . '" />' . "\n";
  5041. }
  5042. if (is_numeric($extra_info)) {
  5043. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info . '" />' . "\n";
  5044. }
  5045. elseif (is_array($extra_info)) {
  5046. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />' . "\n";
  5047. }
  5048. $return .= "\t" . '<input name="type" type="hidden" value="' . TOOL_HOTPOTATOES . '" />' . "\n";
  5049. $return .= "\t" . '<input name="post_time" type="hidden" value="' . time() . '" />' . "\n";
  5050. $return .= '</form>' . "\n";
  5051. $return .= '</div>' . "\n";
  5052. return $return;
  5053. }
  5054. /**
  5055. * Return the form to display the forum edit/add option
  5056. * @param string Action (add/edit)
  5057. * @param integer ID of the lp_item if already exists
  5058. * @param mixed Forum ID or title
  5059. * @return string HTML form
  5060. */
  5061. public function display_forum_form($action = 'add', $id = 0, $extra_info = '') {
  5062. global $charset;
  5063. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  5064. $tbl_forum = Database :: get_course_table(TABLE_FORUM);
  5065. if ($id != 0 && is_array($extra_info)) {
  5066. $item_title = stripslashes($extra_info['title']);
  5067. }
  5068. elseif (is_numeric($extra_info)) {
  5069. $sql_forum = "
  5070. SELECT
  5071. forum_title as title, forum_comment as comment
  5072. FROM " . $tbl_forum . "
  5073. WHERE forum_id = " . $extra_info;
  5074. $result = Database::query($sql_forum);
  5075. $row = Database :: fetch_array($result);
  5076. $item_title = $row['title'];
  5077. $item_description = $row['comment'];
  5078. } else {
  5079. $item_title = '';
  5080. $item_description = '';
  5081. }
  5082. $return = ' <div class="row">
  5083. <div class="form_header">';
  5084. if ($id != 0 && is_array($extra_info))
  5085. $parent = $extra_info['parent_item_id'];
  5086. else
  5087. $parent = 0;
  5088. $sql = "
  5089. SELECT *
  5090. FROM " . $tbl_lp_item . "
  5091. WHERE
  5092. lp_id = " . $this->lp_id;
  5093. $result = Database::query($sql);
  5094. $arrLP = array ();
  5095. while ($row = Database :: fetch_array($result)) {
  5096. $arrLP[] = array (
  5097. 'id' => $row['id'],
  5098. 'item_type' => $row['item_type'],
  5099. 'title' => $row['title'],
  5100. 'path' => $row['path'],
  5101. 'description' => $row['description'],
  5102. 'parent_item_id' => $row['parent_item_id'],
  5103. 'previous_item_id' => $row['previous_item_id'],
  5104. 'next_item_id' => $row['next_item_id'],
  5105. 'display_order' => $row['display_order'],
  5106. 'max_score' => $row['max_score'],
  5107. 'min_score' => $row['min_score'],
  5108. 'mastery_score' => $row['mastery_score'],
  5109. 'prerequisite' => $row['prerequisite']
  5110. );
  5111. }
  5112. $this->tree_array($arrLP);
  5113. $arrLP = $this->arrMenu;
  5114. unset ($this->arrMenu);
  5115. if ($action == 'add')
  5116. $return .= get_lang('CreateTheForum') . '&nbsp;:' . "\n";
  5117. elseif ($action == 'move') $return .= get_lang('MoveTheCurrentForum') . '&nbsp;:' . "\n";
  5118. else
  5119. $return .= get_lang('EditCurrentForum') . '&nbsp;:' . "\n";
  5120. $return .= ' </div>
  5121. </div>';
  5122. $return .= '<div class="sectioncomment">';
  5123. $return .= '<form method="POST">' . "\n";
  5124. $return .= "\t" . '<table class="lp_form">' . "\n";
  5125. if ($action != 'move') {
  5126. $return .= "\t\t" . '<tr>' . "\n";
  5127. $return .= "\t\t\t" . '<td class="label"><label for="idTitle">' . get_lang('Title') . '</label></td>' . "\n";
  5128. $return .= "\t\t\t" . '<td class="input"><input id="idTitle" size="44" name="title" type="text" value="' . $item_title . '" class="learnpath_item_form" /></td>' . "\n";
  5129. $return .= "\t\t" . '</tr>' . "\n";
  5130. }
  5131. $return .= "\t\t" . '<tr>' . "\n";
  5132. $return .= "\t\t\t" . '<td class="label"><label for="idParent">' . get_lang('Parent') . '</label></td>' . "\n";
  5133. $return .= "\t\t\t" . '<td class="input">' . "\n";
  5134. $return .= "\t\t\t\t" . '<select id="idParent" style="width:100%;" name="parent" onchange="javascript: load_cbo(this.value);" class="learnpath_item_form" size="1">';
  5135. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
  5136. $arrHide = array (
  5137. $id
  5138. );
  5139. //$parent_item_id = $_SESSION['parent_item_id'];
  5140. for ($i = 0; $i < count($arrLP); $i++) {
  5141. if ($action != 'add') {
  5142. 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)) {
  5143. $return .= "\t\t\t\t\t" . '<option ' . (($parent == $arrLP[$i]['id']) ? 'selected="selected" ' : '') . 'style="padding-left:' . ($arrLP[$i]['depth'] * 10) . 'px;" value="' . $arrLP[$i]['id'] . '">' . $arrLP[$i]['title'] . '</option>';
  5144. } else {
  5145. $arrHide[] = $arrLP[$i]['id'];
  5146. }
  5147. } else {
  5148. if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
  5149. $return .= "\t\t\t\t\t" . '<option ' . (($parent == $arrLP[$i]['id']) ? 'selected="selected" ' : '') . 'style="padding-left:' . ($arrLP[$i]['depth'] * 10) . 'px;" value="' . $arrLP[$i]['id'] . '">' . $arrLP[$i]['title'] . '</option>';
  5150. }
  5151. }
  5152. if (is_array($arrLP)) {
  5153. reset($arrLP);
  5154. }
  5155. $return .= "\t\t\t\t" . '</select>';
  5156. $return .= "\t\t\t" . '</td>' . "\n";
  5157. $return .= "\t\t" . '</tr>' . "\n";
  5158. $return .= "\t\t" . '<tr>' . "\n";
  5159. $return .= "\t\t\t" . '<td class="label"><label for="idPosition">' . get_lang('Position') . '</label></td>' . "\n";
  5160. $return .= "\t\t\t" . '<td class="input">' . "\n";
  5161. $return .= "\t\t\t\t" . '<select id="idPosition" name="previous" style="width:100%;" size="1" class="learnpath_item_form">';
  5162. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . get_lang('FirstPosition') . '</option>';
  5163. for ($i = 0; $i < count($arrLP); $i++) {
  5164. if ($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) {
  5165. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5166. $selected = 'selected="selected" ';
  5167. elseif ($action == 'add') $selected = 'selected="selected" ';
  5168. else
  5169. $selected = '';
  5170. $return .= "\t\t\t\t\t" . '<option ' . $selected . 'value="' . $arrLP[$i]['id'] . '">' . get_lang('After') . ' "' . $arrLP[$i]['title'] . '"</option>';
  5171. }
  5172. }
  5173. $return .= "\t\t\t\t" . '</select>';
  5174. $return .= "\t\t\t" . '</td>' . "\n";
  5175. $return .= "\t\t" . '</tr>' . "\n";
  5176. if ($action != 'move') {
  5177. $return .= "\t\t" . '<tr>' . "\n";
  5178. $return .= "\t\t" . '</tr>' . "\n";
  5179. $id_prerequisite = 0;
  5180. if (is_array($arrLP)) {
  5181. foreach ($arrLP as $key => $value) {
  5182. if ($value['id'] == $id) {
  5183. $id_prerequisite = $value['prerequisite'];
  5184. break;
  5185. }
  5186. }
  5187. }
  5188. $arrHide = array ();
  5189. for ($i = 0; $i < count($arrLP); $i++) {
  5190. if ($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter') {
  5191. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5192. $s_selected_position = $arrLP[$i]['id'];
  5193. elseif ($action == 'add') $s_selected_position = 0;
  5194. $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
  5195. }
  5196. }
  5197. $return .= "\t\t" . '</tr>' . "\n";
  5198. }
  5199. $return .= "\t\t" . '<tr>' . "\n";
  5200. if ($action == 'add') {
  5201. $return .= '<td>&nbsp;</td><td><button class="save" name="submit_button" type="submit"> ' . get_lang('AddForumToCourse') . ' </button></td>';
  5202. } else {
  5203. $return .= '<td>&nbsp;</td><td><button class="save" name="submit_button" type="submit"> ' . get_lang('EditCurrentForum') . ' </button></td>';
  5204. }
  5205. $return .= "\t\t" . '</tr>' . "\n";
  5206. $return .= "\t" . '</table>' . "\n";
  5207. if ($action == 'move') {
  5208. $return .= "\t" . '<input name="title" type="hidden" value="' . $item_title . '" />' . "\n";
  5209. $return .= "\t" . '<input name="description" type="hidden" value="' . $item_description . '" />' . "\n";
  5210. }
  5211. if (is_numeric($extra_info)) {
  5212. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info . '" />' . "\n";
  5213. }
  5214. elseif (is_array($extra_info)) {
  5215. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />' . "\n";
  5216. }
  5217. $return .= "\t" . '<input name="type" type="hidden" value="' . TOOL_FORUM . '" />' . "\n";
  5218. $return .= "\t" . '<input name="post_time" type="hidden" value="' . time() . '" />' . "\n";
  5219. $return .= '</form>' . "\n";
  5220. $return .= '</div>' . "\n";
  5221. return $return;
  5222. }
  5223. /**
  5224. * Return HTML form to add/edit forum threads
  5225. * @param string Action (add/edit)
  5226. * @param integer Item ID if already exists in learning path
  5227. * @param mixed Extra information (thread ID if integer)
  5228. * @return string HTML form
  5229. */
  5230. public function display_thread_form($action = 'add', $id = 0, $extra_info = '') {
  5231. global $charset;
  5232. echo '
  5233. <style>
  5234. div.row div.label {
  5235. width:110px;
  5236. }
  5237. div.row div.formw {
  5238. width: 82%;
  5239. }
  5240. </style>';
  5241. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  5242. $tbl_forum = Database :: get_course_table(TABLE_FORUM_THREAD);
  5243. if ($id != 0 && is_array($extra_info)) {
  5244. $item_title = stripslashes($extra_info['title']);
  5245. }
  5246. elseif (is_numeric($extra_info)) {
  5247. $sql_forum = "
  5248. SELECT
  5249. thread_title as title
  5250. FROM " . $tbl_forum . "
  5251. WHERE thread_id = " . $extra_info;
  5252. $result = Database::query($sql_forum);
  5253. $row = Database :: fetch_array($result);
  5254. $item_title = $row['title'];
  5255. $item_description = '';
  5256. } else {
  5257. $item_title = '';
  5258. $item_description = '';
  5259. }
  5260. $return = '<div style="margin:3px 12px;">';
  5261. if ($id != 0 && is_array($extra_info))
  5262. $parent = $extra_info['parent_item_id'];
  5263. else
  5264. $parent = 0;
  5265. $sql = "
  5266. SELECT *
  5267. FROM " . $tbl_lp_item . "
  5268. WHERE
  5269. lp_id = " . $this->lp_id;
  5270. $result = Database::query($sql);
  5271. $arrLP = array ();
  5272. while ($row = Database :: fetch_array($result)) {
  5273. $arrLP[] = array (
  5274. 'id' => $row['id'],
  5275. 'item_type' => $row['item_type'],
  5276. 'title' => $row['title'],
  5277. 'path' => $row['path'],
  5278. 'description' => $row['description'],
  5279. 'parent_item_id' => $row['parent_item_id'],
  5280. 'previous_item_id' => $row['previous_item_id'],
  5281. 'next_item_id' => $row['next_item_id'],
  5282. 'display_order' => $row['display_order'],
  5283. 'max_score' => $row['max_score'],
  5284. 'min_score' => $row['min_score'],
  5285. 'mastery_score' => $row['mastery_score'],
  5286. 'prerequisite' => $row['prerequisite']
  5287. );
  5288. }
  5289. $this->tree_array($arrLP);
  5290. $arrLP = $this->arrMenu;
  5291. unset ($this->arrMenu);
  5292. if ($action == 'add')
  5293. $return .= '<p class="lp_title">' . get_lang('CreateTheForum') . '&nbsp;:</p>' . "\n";
  5294. elseif ($action == 'move') $return .= '<p class="lp_title">' . get_lang('MoveTheCurrentForum') . '&nbsp;:</p>' . "\n";
  5295. else
  5296. $return .= '<p class="lp_title">' . get_lang('EditCurrentForum') . '&nbsp;:</p>' . "\n";
  5297. $return .= '<form method="POST">' . "\n";
  5298. $return .= "\t" . '<table cellpadding="0" cellspacing="0" class="lp_form">' . "\n";
  5299. $return .= "\t\t" . '<tr>' . "\n";
  5300. $return .= "\t\t\t" . '<td class="label"><label for="idParent">' . get_lang('Parent') . '&nbsp;:</label></td>' . "\n";
  5301. $return .= "\t\t\t" . '<td class="input">' . "\n";
  5302. $return .= "\t\t\t\t" . '<select id="idParent" name="parent" onchange="javascript: load_cbo(this.value);" size="1">';
  5303. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
  5304. $arrHide = array (
  5305. $id
  5306. );
  5307. for ($i = 0; $i < count($arrLP); $i++) {
  5308. if ($action != 'add') {
  5309. 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)) {
  5310. $return .= "\t\t\t\t\t" . '<option ' . (($parent == $arrLP[$i]['id']) ? 'selected="selected" ' : '') . 'style="padding-left:' . ($arrLP[$i]['depth'] * 10) . 'px;" value="' . $arrLP[$i]['id'] . '">' . $arrLP[$i]['title'] . '</option>';
  5311. } else {
  5312. $arrHide[] = $arrLP[$i]['id'];
  5313. }
  5314. } else {
  5315. if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
  5316. $return .= "\t\t\t\t\t" . '<option ' . (($parent == $arrLP[$i]['id']) ? 'selected="selected" ' : '') . 'style="padding-left:' . ($arrLP[$i]['depth'] * 10) . 'px;" value="' . $arrLP[$i]['id'] . '">' . $arrLP[$i]['title'] . '</option>';
  5317. }
  5318. }
  5319. if ($arrLP != null) {
  5320. reset($arrLP);
  5321. }
  5322. $return .= "\t\t\t\t" . '</select>';
  5323. $return .= "\t\t\t" . '</td>' . "\n";
  5324. $return .= "\t\t" . '</tr>' . "\n";
  5325. $return .= "\t\t" . '<tr>' . "\n";
  5326. $return .= "\t\t\t" . '<td class="label"><label for="idPosition">' . get_lang('Position') . '&nbsp;:</label></td>' . "\n";
  5327. $return .= "\t\t\t" . '<td class="input">' . "\n";
  5328. $return .= "\t\t\t\t" . '<select id="idPosition" name="previous" size="1">';
  5329. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . get_lang('FirstPosition') . '</option>';
  5330. for ($i = 0; $i < count($arrLP); $i++) {
  5331. if ($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) {
  5332. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5333. $selected = 'selected="selected" ';
  5334. elseif ($action == 'add') $selected = 'selected="selected" ';
  5335. else
  5336. $selected = '';
  5337. $return .= "\t\t\t\t\t" . '<option ' . $selected . 'value="' . $arrLP[$i]['id'] . '">' . get_lang('After') . ' "' . $arrLP[$i]['title'] . '"</option>';
  5338. }
  5339. }
  5340. $return .= "\t\t\t\t" . '</select>';
  5341. $return .= "\t\t\t" . '</td>' . "\n";
  5342. $return .= "\t\t" . '</tr>' . "\n";
  5343. if ($action != 'move') {
  5344. $return .= "\t\t" . '<tr>' . "\n";
  5345. $return .= "\t\t\t" . '<td class="label"><label for="idTitle">' . get_lang('Title') . '&nbsp;:</label></td>' . "\n";
  5346. $return .= "\t\t\t" . '<td class="input"><input id="idTitle" name="title" type="text" value="' . $item_title . '" /></td>' . "\n";
  5347. $return .= "\t\t" . '</tr>' . "\n";
  5348. $return .= "\t\t" . '<tr>' . "\n";
  5349. $return .= "\t\t" . '</tr>' . "\n";
  5350. $id_prerequisite = 0;
  5351. if ($arrLP != null) {
  5352. foreach ($arrLP as $key => $value) {
  5353. if ($value['id'] == $id) {
  5354. $id_prerequisite = $value['prerequisite'];
  5355. break;
  5356. }
  5357. }
  5358. }
  5359. $arrHide = array();
  5360. for ($i = 0; $i < count($arrLP); $i++) {
  5361. if ($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter') {
  5362. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5363. $s_selected_position = $arrLP[$i]['id'];
  5364. elseif ($action == 'add') $s_selected_position = 0;
  5365. $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
  5366. }
  5367. }
  5368. $return .= "\t\t" . '<tr>' . "\n";
  5369. $return .= "\t\t\t" . '<td class="label"><label for="idPrerequisites">' . get_lang('Prerequisites') . '&nbsp;:</label></td>' . "\n";
  5370. $return .= "\t\t\t" . '<td class="input"><select name="prerequisites" id="prerequisites"><option value="0">' . get_lang('NoPrerequisites') . '</option>';
  5371. foreach ($arrHide as $key => $value) {
  5372. if ($key == $s_selected_position && $action == 'add') {
  5373. $return .= '<option value="' . $key . '" selected="selected">' . $value['value'] . '</option>';
  5374. }
  5375. elseif ($key == $id_prerequisite && $action == 'edit') {
  5376. $return .= '<option value="' . $key . '" selected="selected">' . $value['value'] . '</option>';
  5377. } else {
  5378. $return .= '<option value="' . $key . '">' . $value['value'] . '</option>';
  5379. }
  5380. }
  5381. $return .= "</select></td>";
  5382. $return .= "\t\t" . '</tr>' . "\n";
  5383. }
  5384. $return .= "\t\t" . '<tr>' . "\n";
  5385. $return .= "\t\t\t" . '<td colspan="2">
  5386. <button class="save" name="submit_button" type="submit" value="'.get_lang('Ok').'" />'.get_lang('Ok').'</button></td>' . "\n";
  5387. $return .= "\t\t" . '</tr>' . "\n";
  5388. $return .= "\t" . '</table>' . "\n";
  5389. if ($action == 'move') {
  5390. $return .= "\t" . '<input name="title" type="hidden" value="' . $item_title . '" />' . "\n";
  5391. $return .= "\t" . '<input name="description" type="hidden" value="' . $item_description . '" />' . "\n";
  5392. }
  5393. if (is_numeric($extra_info)) {
  5394. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info . '" />' . "\n";
  5395. }
  5396. elseif (is_array($extra_info)) {
  5397. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />' . "\n";
  5398. }
  5399. $return .= "\t" . '<input name="type" type="hidden" value="' . TOOL_THREAD . '" />' . "\n";
  5400. $return .= "\t" . '<input name="post_time" type="hidden" value="' . time() . '" />' . "\n";
  5401. $return .= '</form>' . "\n";
  5402. $return .= '</div>' . "\n";
  5403. return $return;
  5404. }
  5405. /**
  5406. * Return the HTML form to display an item (generally a section/module item)
  5407. * @param string Item type (module/dokeos_module)
  5408. * @param string Title (optional, only when creating)
  5409. * @param string Action ('add'/'edit')
  5410. * @param integer lp_item ID
  5411. * @param mixed Extra info
  5412. * @return string HTML form
  5413. */
  5414. public function display_item_form($item_type, $title = '', $action = 'add', $id = 0, $extra_info = 'new') {
  5415. global $_course;
  5416. global $charset;
  5417. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  5418. if ($id != 0 && is_array($extra_info)) {
  5419. $item_title = $extra_info['title'];
  5420. $item_description = $extra_info['description'];
  5421. $item_path = api_get_path(WEB_COURSE_PATH) . $_course['path'] . '/scorm/' . $this->path . '/' . stripslashes($extra_info['path']);
  5422. } else {
  5423. $item_title = '';
  5424. $item_description = '';
  5425. }
  5426. $return = ' <div class="row">
  5427. <div class="form_header">';
  5428. if ($id != 0 && is_array($extra_info))
  5429. $parent = $extra_info['parent_item_id'];
  5430. else
  5431. $parent = 0;
  5432. $sql = "
  5433. SELECT *
  5434. FROM " . $tbl_lp_item . "
  5435. WHERE lp_id = " . $this->lp_id . " AND id != " . $id . " ";
  5436. if ($item_type == 'module')
  5437. $sql .= " AND parent_item_id = 0";
  5438. $result = Database::query($sql);
  5439. $arrLP = array ();
  5440. while ($row = Database :: fetch_array($result)) {
  5441. $arrLP[] = array (
  5442. 'id' => $row['id'],
  5443. 'item_type' => $row['item_type'],
  5444. 'title' => $row['title'],
  5445. 'path' => $row['path'],
  5446. 'description' => $row['description'],
  5447. 'parent_item_id' => $row['parent_item_id'],
  5448. 'previous_item_id' => $row['previous_item_id'],
  5449. 'next_item_id' => $row['next_item_id'],
  5450. 'max_score' => $row['max_score'],
  5451. 'min_score' => $row['min_score'],
  5452. 'mastery_score' => $row['mastery_score'],
  5453. 'prerequisite' => $row['prerequisite'],
  5454. 'display_order' => $row['display_order']
  5455. );
  5456. }
  5457. $this->tree_array($arrLP);
  5458. $arrLP = $this->arrMenu;
  5459. unset ($this->arrMenu);
  5460. $return .= $title . "\n";
  5461. $return .= ' </div>
  5462. </div>';
  5463. require_once api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php';
  5464. $form = new FormValidator('form', 'POST', api_get_self() . '?' . $_SERVER['QUERY_STRING']);
  5465. $defaults['title'] = api_html_entity_decode($item_title, ENT_QUOTES, $charset);
  5466. $defaults['description'] = $item_description;
  5467. $form->addElement('html', $return);
  5468. //$arrHide = array($id);
  5469. $arrHide[0]['value'] = Security :: remove_XSS($this->name);
  5470. $arrHide[0]['padding'] = 3;
  5471. $charset = api_get_system_encoding();
  5472. if ($item_type != 'module' && $item_type != 'dokeos_module') {
  5473. for ($i = 0; $i < count($arrLP); $i++) {
  5474. if ($action != 'add') {
  5475. 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)) {
  5476. $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
  5477. $arrHide[$arrLP[$i]['id']]['padding'] = 3 + $arrLP[$i]['depth'] * 10;
  5478. if ($parent == $arrLP[$i]['id']) {
  5479. $s_selected_parent = $arrHide[$arrLP[$i]['id']];
  5480. }
  5481. }
  5482. } else {
  5483. if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir') {
  5484. $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
  5485. $arrHide[$arrLP[$i]['id']]['padding'] = 3 + $arrLP[$i]['depth'] * 10;
  5486. if ($parent == $arrLP[$i]['id']) {
  5487. $s_selected_parent = $arrHide[$arrLP[$i]['id']];
  5488. }
  5489. }
  5490. }
  5491. }
  5492. if ($action != 'move') {
  5493. $form->addElement('text', 'title', get_lang('Title'), 'id="idTitle" class="learnpath_chapter_form" size="40%"');
  5494. $form->applyFilter('title', 'html_filter');
  5495. $form->addRule('title', '<div class="required">' . get_lang('ThisFieldIsRequired'), 'required');
  5496. //$form->addElement('textarea', 'description', get_lang('Description').' :', 'id="idDescription"');
  5497. } else {
  5498. $form->addElement('hidden', 'title');
  5499. }
  5500. $parent_select = & $form->addElement('select', 'parent', get_lang('Parent'), '', 'class="learnpath_chapter_form" style="width:37%;" id="Parent" onchange="javascript: load_cbo(this.value);"');
  5501. foreach ($arrHide as $key => $value) {
  5502. $parent_select->addOption($value['value'], $key, 'style="padding-left:' . $value['padding'] . 'px;"');
  5503. }
  5504. $parent_select->setSelected($s_selected_parent);
  5505. }
  5506. if (is_array($arrLP)) {
  5507. reset($arrLP);
  5508. }
  5509. $arrHide = array ();
  5510. // POSITION
  5511. for ($i = 0; $i < count($arrLP); $i++) {
  5512. if ($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) {
  5513. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5514. $s_selected_position = $arrLP[$i]['id'];
  5515. elseif ($action == 'add') $s_selected_position = $arrLP[$i]['id'];
  5516. $arrHide[$arrLP[$i]['id']]['value'] = get_lang('After') . ' "' . $arrLP[$i]['title'] . '"';
  5517. }
  5518. }
  5519. $position = & $form->addElement('select', 'previous', get_lang('Position'), '', 'id="idPosition" class="learnpath_chapter_form" style="width:37%;"');
  5520. $position->addOption(get_lang('FirstPosition'), 0, 'style="padding-left:' . $value['padding'] . 'px;"');
  5521. foreach ($arrHide as $key => $value) {
  5522. $position->addOption($value['value'] . '"', $key, 'style="padding-left:' . $value['padding'] . 'px;"');
  5523. }
  5524. if (!empty ($s_selected_position)) {
  5525. $position->setSelected($s_selected_position);
  5526. }
  5527. if (is_array($arrLP)) {
  5528. reset($arrLP);
  5529. }
  5530. $form->addElement('style_submit_button', 'submit_button', get_lang('SaveSection'), 'class="save"');
  5531. if ($item_type == 'module' || $item_type == 'dokeos_module') {
  5532. $form->addElement('hidden', 'parent', '0');
  5533. }
  5534. $extension = pathinfo($item_path, PATHINFO_EXTENSION);
  5535. if (($item_type == 'asset' || $item_type == 'sco') && ($extension == 'html' || $extension == 'htm')) {
  5536. if ($item_type == 'sco') {
  5537. $form->addElement('html', '<script type="text/javascript">alert("' . get_lang('WarningWhenEditingScorm') . '")</script>');
  5538. }
  5539. $renderer = $form->defaultRenderer();
  5540. $renderer->setElementTemplate('<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{label}<br />{element}', 'content_lp');
  5541. $form->addElement('html_editor', 'content_lp', '', null, array('ToolbarSet' => 'LearningPathDocuments', 'Width' => '100%', 'Height' => '400', 'FullPage' => true));
  5542. $defaults['content_lp'] = file_get_contents($item_path);
  5543. }
  5544. $form->addElement('hidden', 'type', 'dokeos_' . $item_type);
  5545. $form->addElement('hidden', 'post_time', time());
  5546. $form->setDefaults($defaults);
  5547. return $form->return_form();
  5548. }
  5549. /**
  5550. * Returns the form to update or create a document
  5551. * @param string Action (add/edit)
  5552. * @param integer ID of the lp_item (if already exists)
  5553. * @param mixed Integer if document ID, string if info ('new')
  5554. * @return string HTML form
  5555. */
  5556. public function display_document_form($action = 'add', $id = 0, $extra_info = 'new') {
  5557. global $charset;
  5558. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  5559. $tbl_doc = Database :: get_course_table(TABLE_DOCUMENT);
  5560. $path_parts = pathinfo($extra_info['dir']);
  5561. $no_display_edit_textarea = false;
  5562. //If action==edit document
  5563. //We don't display the document form if it's not an editable document (html or txt file)
  5564. if ($action == "edit") {
  5565. if (is_array($extra_info)) {
  5566. if ($path_parts['extension'] != "txt" && $path_parts['extension'] != "html") {
  5567. $no_display_edit_textarea = true;
  5568. }
  5569. }
  5570. }
  5571. $no_display_add = false;
  5572. // If action==add an existing document
  5573. // We don't display the document form if it's not an editable document (html or txt file).
  5574. if ($action == "add") {
  5575. if (is_numeric($extra_info)) {
  5576. $sql_doc = "SELECT path FROM " . $tbl_doc . "WHERE id = " . Database :: escape_string($extra_info);
  5577. $result = Database::query($sql_doc);
  5578. $path_file = Database :: result($result, 0, 0);
  5579. $path_parts = pathinfo($path_file);
  5580. if ($path_parts['extension'] != "txt" && $path_parts['extension'] != "html") {
  5581. $no_display_add = true;
  5582. }
  5583. }
  5584. }
  5585. if ($id != 0 && is_array($extra_info)) {
  5586. $item_title = stripslashes($extra_info['title']);
  5587. $item_description = stripslashes($extra_info['description']);
  5588. $item_terms = stripslashes($extra_info['terms']);
  5589. if (empty ($item_title)) {
  5590. $path_parts = pathinfo($extra_info['path']);
  5591. $item_title = stripslashes($path_parts['filename']);
  5592. }
  5593. } elseif (is_numeric($extra_info)) {
  5594. $sql_doc = "SELECT path, title FROM " . $tbl_doc . "
  5595. WHERE id = " . Database :: escape_string($extra_info);
  5596. $result = Database::query($sql_doc);
  5597. $row = Database :: fetch_array($result);
  5598. $explode = explode('.', $row['title']);
  5599. if (count($explode) > 1) {
  5600. for ($i = 0; $i < count($explode) - 1; $i++)
  5601. $item_title .= $explode[$i];
  5602. } else {
  5603. $item_title = $row['title'];
  5604. }
  5605. $item_title = str_replace('_', ' ', $item_title);
  5606. if (empty ($item_title)) {
  5607. $path_parts = pathinfo($row['path']);
  5608. $item_title = stripslashes($path_parts['filename']);
  5609. }
  5610. } else {
  5611. $item_title = '';
  5612. $item_description = '';
  5613. }
  5614. $return = ' <div class="row">
  5615. <div class="form_header">';
  5616. if ($id != 0 && is_array($extra_info))
  5617. $parent = $extra_info['parent_item_id'];
  5618. else
  5619. $parent = 0;
  5620. $sql = "SELECT * FROM " . $tbl_lp_item . "
  5621. WHERE lp_id = " . $this->lp_id;
  5622. $result = Database::query($sql);
  5623. $arrLP = array ();
  5624. while ($row = Database :: fetch_array($result)) {
  5625. $arrLP[] = array (
  5626. 'id' => $row['id'],
  5627. 'item_type' => $row['item_type'],
  5628. 'title' => $row['title'],
  5629. 'path' => $row['path'],
  5630. 'description' => $row['description'],
  5631. 'parent_item_id' => $row['parent_item_id'],
  5632. 'previous_item_id' => $row['previous_item_id'],
  5633. 'next_item_id' => $row['next_item_id'],
  5634. 'display_order' => $row['display_order'],
  5635. 'max_score' => $row['max_score'],
  5636. 'min_score' => $row['min_score'],
  5637. 'mastery_score' => $row['mastery_score'],
  5638. 'prerequisite' => $row['prerequisite']
  5639. );
  5640. }
  5641. $this->tree_array($arrLP);
  5642. $arrLP = $this->arrMenu;
  5643. unset ($this->arrMenu);
  5644. if ($action == 'add') {
  5645. $return .= get_lang('CreateTheDocument') . "\n";
  5646. }
  5647. elseif ($action == 'move') {
  5648. $return .= get_lang('MoveTheCurrentDocument') . "\n";
  5649. } else {
  5650. $return .= get_lang('EditTheCurrentDocument') . "\n";
  5651. }
  5652. $return .= '</div>
  5653. </div>';
  5654. if (isset ($_GET['edit']) && $_GET['edit'] == 'true') {
  5655. $return .= Display :: return_warning_message('<strong>' . get_lang('Warning') . ' !</strong><br />' . get_lang('WarningEditingDocument'), false);
  5656. }
  5657. require_once api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php';
  5658. $form = new FormValidator('form', 'POST', api_get_self() . '?' . $_SERVER['QUERY_STRING'], '', 'enctype="multipart/form-data"');
  5659. $defaults['title'] = Security :: remove_XSS($item_title);
  5660. if (empty($item_title)) {
  5661. $defaults['title'] = Security::remove_XSS($item_title);
  5662. }
  5663. $defaults['description'] = $item_description;
  5664. $form->addElement('html', $return);
  5665. if ($action != 'move') {
  5666. $form->addElement('text', 'title', get_lang('Title'), 'id="idTitle" class="learnpath_item_form" size=44%');
  5667. $form->applyFilter('title', 'html_filter');
  5668. }
  5669. //$arrHide = array($id);
  5670. $arrHide[0]['value'] = $this->name;
  5671. $arrHide[0]['padding'] = 3;
  5672. for ($i = 0; $i < count($arrLP); $i++) {
  5673. if ($action != 'add') {
  5674. 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)) {
  5675. $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
  5676. $arrHide[$arrLP[$i]['id']]['padding'] = 3 + $arrLP[$i]['depth'] * 10;
  5677. if ($parent == $arrLP[$i]['id']) {
  5678. $s_selected_parent = $arrHide[$arrLP[$i]['id']];
  5679. }
  5680. }
  5681. } else {
  5682. if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir') {
  5683. $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
  5684. $arrHide[$arrLP[$i]['id']]['padding'] = 3 + $arrLP[$i]['depth'] * 10;
  5685. if ($parent == $arrLP[$i]['id']) {
  5686. $s_selected_parent = $arrHide[$arrLP[$i]['id']];
  5687. }
  5688. }
  5689. }
  5690. }
  5691. $parent_select = & $form->addElement('select', 'parent', get_lang('Parent'), '', 'class="learnpath_item_form" style="width:40%;" onchange="javascript: load_cbo(this.value);"');
  5692. $my_count=0;
  5693. foreach ($arrHide as $key => $value) {
  5694. if ($my_count!=0) {
  5695. // The LP name is also the first section and is not in the same charset like the other sections.
  5696. $value['value'] = Security :: remove_XSS($value['value']);
  5697. $parent_select->addOption($value['value'], $key, 'style="padding-left:' . $value['padding'] . 'px;"');
  5698. } else {
  5699. $value['value'] = Security :: remove_XSS($value['value']);
  5700. $parent_select->addOption($value['value'], $key, 'style="padding-left:' . $value['padding'] . 'px;"');
  5701. }
  5702. $my_count++;
  5703. }
  5704. if (!empty ($id)) {
  5705. $parent_select->setSelected($parent);
  5706. } else {
  5707. $parent_item_id = $_SESSION['parent_item_id'];
  5708. $parent_select->setSelected($parent_item_id);
  5709. }
  5710. if (is_array($arrLP)) {
  5711. reset($arrLP);
  5712. }
  5713. $arrHide = array ();
  5714. //POSITION
  5715. for ($i = 0; $i < count($arrLP); $i++) {
  5716. if ($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) {
  5717. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5718. $s_selected_position = $arrLP[$i]['id'];
  5719. elseif ($action == 'add') $s_selected_position = $arrLP[$i]['id'];
  5720. $arrHide[$arrLP[$i]['id']]['value'] = get_lang('After') . ' "' . $arrLP[$i]['title'] . '"';
  5721. }
  5722. }
  5723. $position = & $form->addElement('select', 'previous', get_lang('Position'), '', 'id="idPosition" class="learnpath_item_form" style="width:40%;"');
  5724. $position->addOption(get_lang('FirstPosition'), 0);
  5725. foreach ($arrHide as $key => $value) {
  5726. $position->addOption($value['value'], $key, 'style="padding-left:' . $value['padding'] . 'px;"');
  5727. }
  5728. $position->setSelected($s_selected_position);
  5729. if (is_array($arrLP)) {
  5730. reset($arrLP);
  5731. }
  5732. if ($action != 'move') {
  5733. $id_prerequisite = 0;
  5734. if (is_array($arrLP)) {
  5735. foreach ($arrLP as $key => $value) {
  5736. if ($value['id'] == $id) {
  5737. $id_prerequisite = $value['prerequisite'];
  5738. break;
  5739. }
  5740. }
  5741. }
  5742. // Commented the prerequisites, only visible in edit (new document).
  5743. //$select_prerequisites=$form->addElement('select', 'prerequisites', get_lang('Prerequisites'),null,'id="prerequisites" class="learnpath_item_form" style="width:263px;"');
  5744. //$select_prerequisites->addOption(get_lang('NoPrerequisites'), 0);
  5745. // Form element for uploading an mp3 file.
  5746. //$form->addElement('file','mp3',get_lang('UploadMp3audio'),'id="mp3" size="33"');
  5747. //$form->addRule('file', 'The extension of the Song file should be *.mp3', 'filename', '/^.*\.mp3$/');
  5748. /* Code deprecated - moved to lp level (not lp-item).
  5749. if (api_get_setting('search_enabled') === 'true') {
  5750. //add terms field
  5751. $terms = $form->addElement('text', 'terms', get_lang('SearchFeatureTerms').'&nbsp;:', 'id="idTerms" class="learnpath_item_form"');
  5752. $terms->setValue($item_terms);
  5753. }
  5754. */
  5755. $arrHide = array ();
  5756. for ($i = 0; $i < count($arrLP); $i++) {
  5757. if ($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter') {
  5758. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5759. $s_selected_position = $arrLP[$i]['id'];
  5760. elseif ($action == 'add') $s_selected_position = $arrLP[$i]['id'];
  5761. $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
  5762. }
  5763. }
  5764. /* foreach ($arrHide as $key => $value) {
  5765. $select_prerequisites->addOption($value['value'], $key, 'style="padding-left:'.$value['padding'].'px;"');
  5766. if ($key == $s_selected_position && $action == 'add') {
  5767. $select_prerequisites -> setSelected(0);
  5768. }
  5769. elseif ($key == $id_prerequisite && $action == 'edit') {
  5770. $select_prerequisites -> setSelected($id_prerequisite);
  5771. }
  5772. }
  5773. */
  5774. if (!$no_display_add) {
  5775. if (($extra_info == 'new' || $extra_info['item_type'] == TOOL_DOCUMENT || $_GET['edit'] == 'true')) {
  5776. if (isset ($_POST['content']))
  5777. $content = stripslashes($_POST['content']);
  5778. elseif (is_array($extra_info)) {
  5779. //If it's an html document or a text file
  5780. if (!$no_display_edit_textarea) {
  5781. $content = $this->display_document($extra_info['path'], false, false);
  5782. }
  5783. }
  5784. elseif (is_numeric($extra_info)) $content = $this->display_document($extra_info, false, false);
  5785. else
  5786. $content = '';
  5787. if (!$no_display_edit_textarea) {
  5788. // We need to claculate here some specific settings for the online editor.
  5789. // The calculated settings work for documents in the Documents tool
  5790. // (on the root or in subfolders).
  5791. // For documents in native scorm packages it is unclear whether the
  5792. // online editor should be activated or not.
  5793. $relative_path = $extra_info['dir'];
  5794. if ($relative_path == 'n/') {
  5795. // A new document, it is in the root of the repository.
  5796. $relative_path = '';
  5797. $relative_prefix = '';
  5798. } else {
  5799. // The document already exists. Whe have to determine its relative path towards the repository root.
  5800. $relative_path = explode('/', $relative_path);
  5801. $cnt = count($relative_path) - 2;
  5802. if ($cnt < 0) {
  5803. $cnt = 0;
  5804. }
  5805. $relative_prefix = str_repeat('../', $cnt);
  5806. $relative_path = array_slice($relative_path, 1, $cnt);
  5807. $relative_path = implode('/', $relative_path);
  5808. if (strlen($relative_path) > 0) {
  5809. $relative_path = $relative_path . '/';
  5810. }
  5811. }
  5812. $editor_config = array('ToolbarSet' => 'LearningPathDocuments', 'Width' => '100%', 'Height' => '700', 'FullPage' => true,
  5813. 'CreateDocumentDir' => $relative_prefix,
  5814. 'CreateDocumentWebDir' => api_get_path(WEB_COURSE_PATH) . api_get_course_path() . '/document/',
  5815. 'BaseHref' => api_get_path(WEB_COURSE_PATH) . api_get_course_path() . '/document/' . $relative_path
  5816. );
  5817. if ($_GET['action'] == 'add_item') {
  5818. $class = 'add';
  5819. $text = get_lang('LPCreateDocument');
  5820. } else
  5821. if ($_GET['action'] == 'edit_item') {
  5822. $class = 'save';
  5823. $text = get_lang('SaveDocument');
  5824. }
  5825. $form->addElement('style_submit_button', 'submit_button', $text, 'class="' . $class . '"');
  5826. $renderer = $form->defaultRenderer();
  5827. $renderer->setElementTemplate('<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{label}<br />{element}', 'content_lp');
  5828. $form->addElement('html', '<div style="margin:3px 12px">');
  5829. $form->addElement('html_editor', 'content_lp', '', null, $editor_config);
  5830. $form->addElement('html', '</div>');
  5831. $defaults['content_lp'] = $content;
  5832. }
  5833. }
  5834. elseif (is_numeric($extra_info)) {
  5835. $form->addElement('style_submit_button', 'submit_button', get_lang('SaveDocument'), 'class="save"');
  5836. $return = $this->display_document($extra_info, true, true, true);
  5837. $form->addElement('html', $return);
  5838. }
  5839. }
  5840. }
  5841. if ($action == 'move') {
  5842. $form->addElement('hidden', 'title', $item_title);
  5843. $form->addElement('hidden', 'description', $item_description);
  5844. }
  5845. if (is_numeric($extra_info)) {
  5846. $form->addElement('style_submit_button', 'submit_button', get_lang('SaveDocument'), 'value="submit_button", class="save"');
  5847. $form->addElement('hidden', 'path', $extra_info);
  5848. }
  5849. elseif (is_array($extra_info)) {
  5850. $form->addElement('style_submit_button', 'submit_button', get_lang('SaveDocument'), 'class="save"');
  5851. $form->addElement('hidden', 'path', $extra_info['path']);
  5852. }
  5853. $form->addElement('hidden', 'type', TOOL_DOCUMENT);
  5854. $form->addElement('hidden', 'post_time', time());
  5855. $form->setDefaults($defaults);
  5856. return $form->return_form();
  5857. }
  5858. /**
  5859. * Return HTML form to add/edit a link item
  5860. * @param string Action (add/edit)
  5861. * @param integer Item ID if exists
  5862. * @param mixed Extra info
  5863. * @return string HTML form
  5864. */
  5865. public function display_link_form($action = 'add', $id = 0, $extra_info = '') {
  5866. global $charset;
  5867. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  5868. $tbl_link = Database :: get_course_table(TABLE_LINK);
  5869. if ($id != 0 && is_array($extra_info)) {
  5870. $item_title = stripslashes($extra_info['title']);
  5871. $item_description = stripslashes($extra_info['description']);
  5872. $item_url = stripslashes($extra_info['url']);
  5873. }
  5874. elseif (is_numeric($extra_info)) {
  5875. $sql_link = "
  5876. SELECT
  5877. title,
  5878. description,
  5879. url
  5880. FROM " . $tbl_link . "
  5881. WHERE id = " . $extra_info;
  5882. $result = Database::query($sql_link);
  5883. $row = Database :: fetch_array($result);
  5884. $item_title = $row['title'];
  5885. $item_description = $row['description'];
  5886. $item_url = $row['url'];
  5887. } else {
  5888. $item_title = '';
  5889. $item_description = '';
  5890. $item_url = '';
  5891. }
  5892. $return = ' <div class="row">
  5893. <div class="form_header">';
  5894. if ($id != 0 && is_array($extra_info))
  5895. $parent = $extra_info['parent_item_id'];
  5896. else
  5897. $parent = 0;
  5898. $sql = "
  5899. SELECT *
  5900. FROM " . $tbl_lp_item . "
  5901. WHERE
  5902. lp_id = " . $this->lp_id;
  5903. $result = Database::query($sql);
  5904. $arrLP = array ();
  5905. while ($row = Database :: fetch_array($result)) {
  5906. $arrLP[] = array (
  5907. 'id' => $row['id'],
  5908. 'item_type' => $row['item_type'],
  5909. 'title' => $row['title'],
  5910. 'path' => $row['path'],
  5911. 'description' => $row['description'],
  5912. 'parent_item_id' => $row['parent_item_id'],
  5913. 'previous_item_id' => $row['previous_item_id'],
  5914. 'next_item_id' => $row['next_item_id'],
  5915. 'display_order' => $row['display_order'],
  5916. 'max_score' => $row['max_score'],
  5917. 'min_score' => $row['min_score'],
  5918. 'mastery_score' => $row['mastery_score'],
  5919. 'prerequisite' => $row['prerequisite']
  5920. );
  5921. }
  5922. $this->tree_array($arrLP);
  5923. $arrLP = $this->arrMenu;
  5924. unset ($this->arrMenu);
  5925. if ($action == 'add')
  5926. $return .= get_lang('CreateTheLink') . '&nbsp;:' . "\n";
  5927. elseif ($action == 'move') $return .= get_lang('MoveCurrentLink') . '&nbsp;:' . "\n";
  5928. else
  5929. $return .= get_lang('EditCurrentLink') . '&nbsp;:' . "\n";
  5930. $return .= ' </div>
  5931. </div>';
  5932. $return .= '<div class="sectioncomment">';
  5933. $return .= '<form method="POST">' . "\n";
  5934. $return .= "\t" . '<table>' . "\n";
  5935. if ($action != 'move') {
  5936. $return .= "\t\t" . '<tr>' . "\n";
  5937. $return .= "\t\t\t" . '<td class="label"><label for="idTitle">' . get_lang('Title') . '</label></td>' . "\n";
  5938. $return .= "\t\t\t" . '<td class="input"><input id="idTitle" name="title" size="44" type="text" value="' . $item_title . '" class="learnpath_item_form"/></td>' . "\n";
  5939. $return .= "\t\t" . '</tr>' . "\n";
  5940. }
  5941. $return .= "\t\t" . '<tr>' . "\n";
  5942. $return .= "\t\t\t" . '<td class="label"><label for="idParent">' . get_lang('Parent') . '</label></td>' . "\n";
  5943. $return .= "\t\t\t" . '<td class="input">' . "\n";
  5944. $return .= "\t\t\t\t" . '<select id="idParent" style="width:100%;" name="parent" onchange="javascript: load_cbo(this.value);" class="learnpath_item_form" size="1">';
  5945. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
  5946. $arrHide = array (
  5947. $id
  5948. );
  5949. $parent_item_id = $_SESSION['parent_item_id'];
  5950. for ($i = 0; $i < count($arrLP); $i++) {
  5951. if ($action != 'add') {
  5952. 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)) {
  5953. $return .= "\t\t\t\t\t" . '<option ' . (($parent == $arrLP[$i]['id']) ? 'selected="selected" ' : '') . 'style="padding-left:' . ($arrLP[$i]['depth'] * 10) . 'px;" value="' . $arrLP[$i]['id'] . '">' . $arrLP[$i]['title'] . '</option>';
  5954. } else {
  5955. $arrHide[] = $arrLP[$i]['id'];
  5956. }
  5957. } else {
  5958. if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
  5959. $return .= "\t\t\t\t\t" . '<option ' . (($parent_item_id == $arrLP[$i]['id']) ? 'selected="selected" ' : '') . 'style="padding-left:' . ($arrLP[$i]['depth'] * 10) . 'px;" value="' . $arrLP[$i]['id'] . '">' . $arrLP[$i]['title'] . '</option>';
  5960. }
  5961. }
  5962. if (is_array($arrLP)) {
  5963. reset($arrLP);
  5964. }
  5965. $return .= "\t\t\t\t" . '</select>';
  5966. $return .= "\t\t\t" . '</td>' . "\n";
  5967. $return .= "\t\t" . '</tr>' . "\n";
  5968. $return .= "\t\t" . '<tr>' . "\n";
  5969. $return .= "\t\t\t" . '<td class="label"><label for="idPosition">' . get_lang('Position') . '</label></td>' . "\n";
  5970. $return .= "\t\t\t" . '<td class="input">' . "\n";
  5971. $return .= "\t\t\t\t" . '<select id="idPosition" name="previous" style="width:100%;" size="1" class="learnpath_item_form">';
  5972. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . get_lang('FirstPosition') . '</option>';
  5973. for ($i = 0; $i < count($arrLP); $i++) {
  5974. if ($arrLP[$i]['parent_item_id'] == $parent_item_id && $arrLP[$i]['id'] != $id) {
  5975. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5976. $selected = 'selected="selected" ';
  5977. elseif ($action == 'add') $selected = 'selected="selected" ';
  5978. else
  5979. $selected = '';
  5980. $return .= "\t\t\t\t\t" . '<option ' . $selected . 'value="' . $arrLP[$i]['id'] . '">' . get_lang('After') . ' "' . $arrLP[$i]['title'] . '"</option>';
  5981. }
  5982. }
  5983. $return .= "\t\t\t\t" . '</select>';
  5984. $return .= "\t\t\t" . '</td>' . "\n";
  5985. $return .= "\t\t" . '</tr>' . "\n";
  5986. if ($action != 'move') {
  5987. $return .= "\t\t" . '<tr>' . "\n";
  5988. $return .= "\t\t\t" . '<td class="label"><label for="idURL">' . get_lang('Url') . '</label></td>' . "\n";
  5989. $return .= "\t\t\t" . '<td class="input"><input' . (is_numeric($extra_info) ? ' disabled="disabled"' : '') . ' id="idURL" name="url" style="width:99%;" type="text" value="' . $item_url . '" class="learnpath_item_form" /></td>' . "\n";
  5990. $return .= "\t\t" . '</tr>' . "\n";
  5991. $id_prerequisite = 0;
  5992. if (is_array($arrLP)) {
  5993. foreach ($arrLP as $key => $value) {
  5994. if ($value['id'] == $id) {
  5995. $id_prerequisite = $value['prerequisite'];
  5996. break;
  5997. }
  5998. }
  5999. }
  6000. $arrHide = array ();
  6001. for ($i = 0; $i < count($arrLP); $i++) {
  6002. if ($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter') {
  6003. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  6004. $s_selected_position = $arrLP[$i]['id'];
  6005. elseif ($action == 'add') $s_selected_position = 0;
  6006. $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
  6007. }
  6008. }
  6009. /*// Commented the prerequisites, only visible in edit (link).
  6010. $return .= "\t\t" . '<tr>' . "\n";
  6011. $return .= "\t\t\t" . '<td class="label"><label for="idPrerequisites">'.get_lang('Prerequisites').'</label></td>' . "\n";
  6012. $return .= "\t\t\t" . '<td class="input"><select name="prerequisites" id="prerequisites" class="learnpath_item_form"><option value="0">'.get_lang('NoPrerequisites').'</option>';
  6013. foreach($arrHide as $key => $value) {
  6014. if ($key == $s_selected_position && $action == 'add') {
  6015. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  6016. }
  6017. elseif ($key == $id_prerequisite && $action == 'edit') {
  6018. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  6019. }
  6020. else {
  6021. $return .= '<option value="'.$key.'">'.$value['value'].'</option>';
  6022. }
  6023. }
  6024. $return .= "</select></td>";
  6025. */
  6026. $return .= "\t\t" . '</tr>' . "\n";
  6027. }
  6028. $return .= "\t\t" . '<tr>' . "\n";
  6029. if ($action == 'add') {
  6030. $return .= '<td>&nbsp;</td><td><button class="save" name="submit_button" type="submit">' . get_lang('AddLinkToCourse') . '</button></td>';
  6031. } else {
  6032. $return .= '<td>&nbsp;</td><td><button class="save" name="submit_button" type="submit">' . get_lang('EditCurrentLink') . '</button></td>';
  6033. }
  6034. $return .= "\t\t" . '</tr>' . "\n";
  6035. $return .= "\t" . '</table>' . "\n";
  6036. if ($action == 'move') {
  6037. $return .= "\t" . '<input name="title" type="hidden" value="' . $item_title . '" />' . "\n";
  6038. $return .= "\t" . '<input name="description" type="hidden" value="' . $item_description . '" />' . "\n";
  6039. }
  6040. if (is_numeric($extra_info)) {
  6041. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info . '" />' . "\n";
  6042. }
  6043. elseif (is_array($extra_info)) {
  6044. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />' . "\n";
  6045. }
  6046. $return .= "\t" . '<input name="type" type="hidden" value="' . TOOL_LINK . '" />' . "\n";
  6047. $return .= "\t" . '<input name="post_time" type="hidden" value="' . time() . '" />' . "\n";
  6048. $return .= '</form>' . "\n";
  6049. $return .= '</div>' . "\n";
  6050. return $return;
  6051. }
  6052. /**
  6053. * Return HTML form to add/edit a student publication (work)
  6054. * @param string Action (add/edit)
  6055. * @param integer Item ID if already exists
  6056. * @param mixed Extra info (work ID if integer)
  6057. * @return string HTML form
  6058. */
  6059. public function display_student_publication_form($action = 'add', $id = 0, $extra_info = '') {
  6060. global $charset;
  6061. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  6062. $tbl_publication = Database :: get_course_table(TABLE_STUDENT_PUBLICATION);
  6063. if ($id != 0 && is_array($extra_info)) {
  6064. $item_title = stripslashes($extra_info['title']);
  6065. $item_description = stripslashes($extra_info['description']);
  6066. }
  6067. elseif (is_numeric($extra_info)) {
  6068. $sql_publication = "
  6069. SELECT
  6070. title,
  6071. description
  6072. FROM " . $tbl_publication . "
  6073. WHERE id = " . $extra_info;
  6074. $result = Database::query($sql_publication);
  6075. $row = Database :: fetch_array($result);
  6076. $item_title = $row['title'];
  6077. } else {
  6078. $item_title = get_lang('Student_publication');
  6079. }
  6080. $return = ' <div class="row">
  6081. <div class="form_header">';
  6082. if ($id != 0 && is_array($extra_info))
  6083. $parent = $extra_info['parent_item_id'];
  6084. else
  6085. $parent = 0;
  6086. $sql = "
  6087. SELECT *
  6088. FROM " . $tbl_lp_item . "
  6089. WHERE
  6090. lp_id = " . $this->lp_id;
  6091. $result = Database::query($sql);
  6092. $arrLP = array ();
  6093. while ($row = Database :: fetch_array($result)) {
  6094. $arrLP[] = array (
  6095. 'id' => $row['id'],
  6096. 'item_type' => $row['item_type'],
  6097. 'title' => $row['title'],
  6098. 'path' => $row['path'],
  6099. 'description' => $row['description'],
  6100. 'parent_item_id' => $row['parent_item_id'],
  6101. 'previous_item_id' => $row['previous_item_id'],
  6102. 'next_item_id' => $row['next_item_id'],
  6103. 'display_order' => $row['display_order'],
  6104. 'max_score' => $row['max_score'],
  6105. 'min_score' => $row['min_score'],
  6106. 'mastery_score' => $row['mastery_score'],
  6107. 'prerequisite' => $row['prerequisite']
  6108. );
  6109. }
  6110. $this->tree_array($arrLP);
  6111. $arrLP = $this->arrMenu;
  6112. unset ($this->arrMenu);
  6113. if ($action == 'add')
  6114. $return .= get_lang('Student_publication') . '&nbsp;:' . "\n";
  6115. elseif ($action == 'move') $return .= get_lang('MoveCurrentStudentPublication') . '&nbsp;:' . "\n";
  6116. else
  6117. $return .= get_lang('EditCurrentStudentPublication') . '&nbsp;:' . "\n";
  6118. $return .= ' </div>
  6119. </div>';
  6120. $return .= '<div class="sectioncomment">';
  6121. $return .= '<form method="POST">' . "\n";
  6122. $return .= "\t" . '<table class="lp_form">' . "\n";
  6123. if ($action != 'move') {
  6124. $return .= "\t\t" . '<tr>' . "\n";
  6125. $return .= "\t\t\t" . '<td class="label"><label for="idTitle">' . get_lang('Title') . '</label></td>' . "\n";
  6126. $return .= "\t\t\t" . '<td class="input"><input id="idTitle" name="title" size="44" type="text" value="' . $item_title . '" class="learnpath_item_form" /></td>' . "\n";
  6127. $return .= "\t\t" . '</tr>' . "\n";
  6128. }
  6129. $return .= "\t\t" . '<tr>' . "\n";
  6130. $return .= "\t\t\t" . '<td class="label"><label for="idParent">' . get_lang('Parent') . '</label></td>' . "\n";
  6131. $return .= "\t\t\t" . '<td class="input">' . "\n";
  6132. $return .= "\t\t\t\t" . '<select id="idParent" name="parent" style="width:100%;" onchange="javascript: load_cbo(this.value);" class="learnpath_item_form" size="1">';
  6133. //$parent_item_id = $_SESSION['parent_item_id'];
  6134. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
  6135. $arrHide = array (
  6136. $id
  6137. );
  6138. for ($i = 0; $i < count($arrLP); $i++) {
  6139. if ($action != 'add') {
  6140. 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)) {
  6141. $return .= "\t\t\t\t\t" . '<option ' . (($parent == $arrLP[$i]['id']) ? 'selected="selected" ' : '') . 'style="padding-left:' . ($arrLP[$i]['depth'] * 10) . 'px;" value="' . $arrLP[$i]['id'] . '">' . $arrLP[$i]['title'] . '</option>';
  6142. } else {
  6143. $arrHide[] = $arrLP[$i]['id'];
  6144. }
  6145. } else {
  6146. if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
  6147. $return .= "\t\t\t\t\t" . '<option ' . (($parent == $arrLP[$i]['id']) ? 'selected="selected" ' : '') . 'style="padding-left:' . ($arrLP[$i]['depth'] * 10) . 'px;" value="' . $arrLP[$i]['id'] . '">' . $arrLP[$i]['title'] . '</option>';
  6148. }
  6149. }
  6150. if (is_array($arrLP)) {
  6151. reset($arrLP);
  6152. }
  6153. $return .= "\t\t\t\t" . '</select>';
  6154. $return .= "\t\t\t" . '</td>' . "\n";
  6155. $return .= "\t\t" . '</tr>' . "\n";
  6156. $return .= "\t\t" . '<tr>' . "\n";
  6157. $return .= "\t\t\t" . '<td class="label"><label for="idPosition">' . get_lang('Position') . '</label></td>' . "\n";
  6158. $return .= "\t\t\t" . '<td class="input">' . "\n";
  6159. $return .= "\t\t\t\t" . '<select id="idPosition" name="previous" style="width:100%;" size="1" class="learnpath_item_form">';
  6160. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . get_lang('FirstPosition') . '</option>';
  6161. for ($i = 0; $i < count($arrLP); $i++) {
  6162. if ($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) {
  6163. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  6164. $selected = 'selected="selected" ';
  6165. elseif ($action == 'add') $selected = 'selected="selected" ';
  6166. else
  6167. $selected = '';
  6168. $return .= "\t\t\t\t\t" . '<option ' . $selected . 'value="' . $arrLP[$i]['id'] . '">' . get_lang('After') . ' "' . $arrLP[$i]['title'] . '"</option>';
  6169. }
  6170. }
  6171. $return .= "\t\t\t\t" . '</select>';
  6172. $return .= "\t\t\t" . '</td>' . "\n";
  6173. $return .= "\t\t" . '</tr>' . "\n";
  6174. if ($action != 'move') {
  6175. $id_prerequisite = 0;
  6176. if (is_array($arrLP)) {
  6177. foreach ($arrLP as $key => $value) {
  6178. if ($value['id'] == $id) {
  6179. $id_prerequisite = $value['prerequisite'];
  6180. break;
  6181. }
  6182. }
  6183. }
  6184. $arrHide = array ();
  6185. for ($i = 0; $i < count($arrLP); $i++) {
  6186. if ($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter') {
  6187. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  6188. $s_selected_position = $arrLP[$i]['id'];
  6189. elseif ($action == 'add') $s_selected_position = 0;
  6190. $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
  6191. }
  6192. }
  6193. // Commented the prerequisites, only visible in edit (work).
  6194. /*
  6195. $return .= "\t\t" . '<tr>' . "\n";
  6196. $return .= "\t\t\t" . '<td class="label"><label for="idPrerequisites">'.get_lang('Prerequisites').'</label></td>' . "\n";
  6197. $return .= "\t\t\t" . '<td class="input"><select name="prerequisites" id="prerequisites" class="learnpath_item_form"><option value="0">'.get_lang('NoPrerequisites').'</option>';
  6198. foreach($arrHide as $key => $value) {
  6199. if ($key == $s_selected_position && $action == 'add') {
  6200. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  6201. }
  6202. elseif ($key == $id_prerequisite && $action == 'edit') {
  6203. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  6204. }
  6205. else {
  6206. $return .= '<option value="'.$key.'">'.$value['value'].'</option>';
  6207. }
  6208. }
  6209. $return .= "</select></td>";
  6210. */
  6211. $return .= "\t\t" . '</tr>' . "\n";
  6212. }
  6213. $return .= "\t\t" . '<tr>' . "\n";
  6214. if ($action == 'add') {
  6215. $return .= '<td>&nbsp</td><td><button class="save" name="submit_button" type="submit">' . get_lang('AddAssignmentToCourse') . '</button></td>';
  6216. } else {
  6217. $return .= '<td>&nbsp</td><td><button class="save" name="submit_button" type="submit">' . get_lang('EditCurrentStudentPublication') . '</button></td>';
  6218. }
  6219. $return .= "\t\t" . '</tr>' . "\n";
  6220. $return .= "\t" . '</table>' . "\n";
  6221. if ($action == 'move') {
  6222. $return .= "\t" . '<input name="title" type="hidden" value="' . $item_title . '" />' . "\n";
  6223. $return .= "\t" . '<input name="description" type="hidden" value="' . $item_description . '" />' . "\n";
  6224. }
  6225. if (is_numeric($extra_info)) {
  6226. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info . '" />' . "\n";
  6227. } elseif (is_array($extra_info)) {
  6228. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />' . "\n";
  6229. }
  6230. $return .= "\t" . '<input name="type" type="hidden" value="' . TOOL_STUDENTPUBLICATION . '" />' . "\n";
  6231. $return .= "\t" . '<input name="post_time" type="hidden" value="' . time() . '" />' . "\n";
  6232. $return .= '</form>' . "\n";
  6233. $return .= '</div>' . "\n";
  6234. return $return;
  6235. }
  6236. /**
  6237. * Displays the menu for manipulating a step
  6238. * @return unknown
  6239. */
  6240. public function display_manipulate($item_id, $item_type = TOOL_DOCUMENT) {
  6241. global $charset, $_course;
  6242. $return = '<div class="actions">';
  6243. switch ($item_type) {
  6244. case 'dokeos_chapter' :
  6245. case 'chapter' :
  6246. // Commented the message cause should not show it.
  6247. //$lang = get_lang('TitleManipulateChapter');
  6248. break;
  6249. case 'dokeos_module' :
  6250. case 'module' :
  6251. // Commented the message cause should not show it.
  6252. //$lang = get_lang('TitleManipulateModule');
  6253. break;
  6254. case TOOL_DOCUMENT :
  6255. // Commented the message cause should not show it.
  6256. //$lang = get_lang('TitleManipulateDocument');
  6257. break;
  6258. case TOOL_LINK :
  6259. case 'link' :
  6260. // Commented the message cause should not show it.
  6261. //$lang = get_lang('TitleManipulateLink');
  6262. break;
  6263. case TOOL_QUIZ :
  6264. // Commented the message cause should not show it.
  6265. //$lang = get_lang('TitleManipulateQuiz');
  6266. break;
  6267. case TOOL_STUDENTPUBLICATION :
  6268. // Commented the message cause should not show it.
  6269. //$lang = get_lang('TitleManipulateStudentPublication');
  6270. break;
  6271. }
  6272. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  6273. $sql = "
  6274. SELECT
  6275. *
  6276. FROM " . $tbl_lp_item . " as lp
  6277. WHERE
  6278. lp.id = " . $item_id;
  6279. $result = Database::query($sql);
  6280. $row = Database::fetch_assoc($result);
  6281. $s_title = $row['title'];
  6282. // We display an audio player if needed.
  6283. if (!empty ($row['audio'])) {
  6284. $return .= '<div class="lp_mediaplayer" id="container"><a href="http://www.macromedia.com/go/getflashplayer">Get the Flash Player</a> to see this player.</div>';
  6285. $return .= '<script type="text/javascript" src="../inc/lib/mediaplayer/swfobject.js"></script>';
  6286. $return .= '<script type="text/javascript">
  6287. var s1 = new SWFObject("../inc/lib/mediaplayer/player.swf","ply","250","20","9","#FFFFFF");
  6288. s1.addParam("allowscriptaccess","always");
  6289. s1.addParam("flashvars","file=../../courses/' . $_course['path'] . '/document/audio/' . $row['audio'] . '&autostart=true");
  6290. s1.write("container");
  6291. </script>';
  6292. }
  6293. // Commented ":" for message in step.
  6294. //$return .= $lang.': ';
  6295. $return .= '<a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&amp;action=edit_item&amp;view=build&amp;id=' . $item_id . '&amp;lp_id=' . $this->lp_id . '&path_item=' . $row['path'] . '" title="' . get_lang('Edit') . '"><img align="absbottom" alt="Edit the current item" src="../img/edit.gif" title="' . get_lang('Edit') . '" /> ' . get_lang('Edit') . '</a>';
  6296. $return .= '<a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_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="' . get_lang('Move') . '" /> ' . get_lang('Move') . '</a>';
  6297. // Commented for now as prerequisites cannot be added to chapters.
  6298. if ($item_type != 'dokeos_chapter' && $item_type != 'chapter') {
  6299. $return .= '<a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_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>';
  6300. }
  6301. $return .= '<a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&amp;action=delete_item&amp;view=build&amp;id=' . $item_id . '&amp;lp_id=' . $this->lp_id . '" onclick="return confirmation(\'' . addslashes($s_title) . '\');" title="Delete the current item"><img alt="Delete the current item" align="absbottom" src="../img/delete.gif" title="' . get_lang('Delete') . '" /> ' . get_lang('Delete') . '</a>';
  6302. //$return .= '<br /><br /><p class="lp_text">' . ((trim($s_description) == '') ? ''.get_lang('NoDescription').'' : stripslashes(nl2br($s_description))) . '</p>';
  6303. //$return.="</td><td valign='top'>";
  6304. // Get the audiorecorder. Use of ob_* functions since there are echos in the file.
  6305. ob_start();
  6306. $audio_recorder_studentview = 'false';
  6307. $audio_recorder_item_id = $item_id;
  6308. if (api_get_setting('service_visio', 'active') == 'true') {
  6309. include 'audiorecorder.inc.php';
  6310. }
  6311. $return .= ob_get_contents();
  6312. ob_end_clean();
  6313. // End of audiorecorder include.
  6314. $return .= '</div>';
  6315. return $return;
  6316. }
  6317. /**
  6318. * Creates the javascript needed for filling up the checkboxes without page reload
  6319. *
  6320. * @return string
  6321. */
  6322. public function create_js() {
  6323. $return = '<script language="javascript" type="text/javascript">' . "\n";
  6324. $return .= 'function load_cbo(id){' . "\n";
  6325. $return .= "var cbo = document.getElementById('idPosition');\n";
  6326. $return .= 'for(var i = cbo.length - 1; i > 0; i--)';
  6327. $return .= 'cbo.options[i] = null;' . "\n";
  6328. $return .= 'var k=0;' . "\n";
  6329. $return .= 'for(var i = 1; i <= child_name[id].length; i++){' . "\n";
  6330. $return .= ' cbo.options[i] = new Option(child_name[id][i-1], child_value[id][i-1]);' . "\n";
  6331. $return .= 'k=i;';
  6332. $return .= '}' . "\n\n";
  6333. $return .= 'if( typeof cbo != "undefined" ) {cbo.options[k].selected = true;}';
  6334. $return .= '}';
  6335. $return .= 'var child_name = new Array();' . "\n";
  6336. $return .= 'var child_value = new Array();' . "\n\n";
  6337. $return .= 'child_name[0] = new Array();' . "\n";
  6338. $return .= 'child_value[0] = new Array();' . "\n\n";
  6339. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  6340. $sql_zero = "
  6341. SELECT *
  6342. FROM " . $tbl_lp_item . "
  6343. WHERE
  6344. lp_id = " . $this->lp_id . " AND
  6345. parent_item_id = 0
  6346. ORDER BY display_order ASC";
  6347. $res_zero = Database::query($sql_zero);
  6348. global $charset;
  6349. $i = 0;
  6350. while ($row_zero = Database :: fetch_array($res_zero)) {
  6351. $return .= 'child_name[0][' . $i . '] = "' . get_lang('After') . ' \"' . $row_zero['title'] . '\"";' . "\n";
  6352. $return .= 'child_value[0][' . $i++ . '] = "' . $row_zero['id'] . '";' . "\n";
  6353. }
  6354. $return .= "\n";
  6355. $sql = "
  6356. SELECT *
  6357. FROM " . $tbl_lp_item . "
  6358. WHERE
  6359. lp_id = " . $this->lp_id;
  6360. $res = Database::query($sql);
  6361. while ($row = Database :: fetch_array($res)) {
  6362. $sql_parent = "
  6363. SELECT *
  6364. FROM " . $tbl_lp_item . "
  6365. WHERE parent_item_id = " . $row['id'] . "
  6366. ORDER BY display_order ASC";
  6367. $res_parent = Database::query($sql_parent);
  6368. $i = 0;
  6369. $return .= 'child_name[' . $row['id'] . '] = new Array();' . "\n";
  6370. $return .= 'child_value[' . $row['id'] . '] = new Array();' . "\n\n";
  6371. while ($row_parent = Database :: fetch_array($res_parent)) {
  6372. $return .= 'child_name[' . $row['id'] . '][' . $i . '] = "' . get_lang('After') . ' \"' . api_html_entity_decode($row_parent['title'], ENT_QUOTES) . '\"";' . "\n";
  6373. $return .= 'child_value[' . $row['id'] . '][' . $i++ . '] = "' . $row_parent['id'] . '";' . "\n";
  6374. }
  6375. $return .= "\n";
  6376. }
  6377. $return .= '</script>' . "\n";
  6378. return $return;
  6379. }
  6380. /**
  6381. * Display the form to allow moving an item
  6382. * @param integer Item ID
  6383. * @return string HTML form
  6384. */
  6385. public function display_move_item($item_id) {
  6386. global $_course; //will disappear
  6387. global $charset;
  6388. $return = '';
  6389. if (is_numeric($item_id)) {
  6390. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  6391. $sql = "SELECT *
  6392. FROM " . $tbl_lp_item . "
  6393. WHERE id = " . $item_id;
  6394. $res = Database::query($sql);
  6395. $row = Database :: fetch_array($res);
  6396. switch ($row['item_type']) {
  6397. case 'dokeos_chapter' :
  6398. case 'dir' :
  6399. case 'asset' :
  6400. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6401. $return .= $this->display_item_form($row['item_type'], get_lang('MoveCurrentChapter'), 'move', $item_id, $row);
  6402. break;
  6403. case 'dokeos_module' :
  6404. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6405. $return .= $this->display_item_form($row['item_type'], 'Move th current module:', 'move', $item_id, $row);
  6406. break;
  6407. case TOOL_DOCUMENT :
  6408. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6409. $return .= $this->display_document_form('move', $item_id, $row);
  6410. break;
  6411. case TOOL_LINK :
  6412. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6413. $return .= $this->display_link_form('move', $item_id, $row);
  6414. break;
  6415. case TOOL_HOTPOTATOES :
  6416. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6417. $return .= $this->display_link_form('move', $item_id, $row);
  6418. break;
  6419. case TOOL_QUIZ :
  6420. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6421. $return .= $this->display_quiz_form('move', $item_id, $row);
  6422. break;
  6423. case TOOL_STUDENTPUBLICATION :
  6424. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6425. $return .= $this->display_student_publication_form('move', $item_id, $row);
  6426. break;
  6427. case TOOL_FORUM :
  6428. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6429. $return .= $this->display_forum_form('move', $item_id, $row);
  6430. break;
  6431. case TOOL_THREAD :
  6432. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6433. $return .= $this->display_forum_form('move', $item_id, $row);
  6434. break;
  6435. }
  6436. }
  6437. return $return;
  6438. }
  6439. /**
  6440. * Displays a basic form on the overview page for changing the item title and the item description.
  6441. * @param string $item_type
  6442. * @param string $title
  6443. * @param array $data
  6444. * @return string
  6445. */
  6446. public function display_item_small_form($item_type, $title = '', $data) {
  6447. global $charset;
  6448. $return .= '<div class="lp_small_form">' . "\n";
  6449. $return .= '<p class="lp_title">' . $title . '</p>';
  6450. $return .= '<form method="post">' . "\n";
  6451. $return .= '<table cellpadding="0" cellspacing="0" class="lp_form">';
  6452. $return .= "\t\t" . '<tr>' . "\n";
  6453. $return .= "\t\t\t" . '<td class="label"><label for="idTitle">Title&nbsp;:</label></td>' . "\n";
  6454. $return .= "\t\t\t" . '<td class="input"><input class="small_form" id="idTitle" name="title" type="text" value="' . api_html_entity_decode($data['title'], ENT_QUOTES) . '" /></td>' . "\n";
  6455. $return .= "\t\t" . '</tr>' . "\n";
  6456. // It said these lines of code - see SVN#11724 and SVN#10770
  6457. //$return .= "\t\t" . '<tr>' . "\n";
  6458. //$return .= "\t\t\t" . '<td class="label"><label for="idDescription">Description&nbsp;:</label></td>' . "\n";
  6459. //$return .= "\t\t\t" . '<td class="input"><textarea class="small_form" id="idDescription" name="description" rows="4">' . $data['description'] . '</textarea></td>' . "\n";
  6460. //$return .= "\t\t" . '</tr>' . "\n";
  6461. $return .= "\t\t" . '<tr>' . "\n";
  6462. $return .= "\t\t\t" . '<td colspan="2"><button class="save" name="submit_button" type="submit">' . get_lang('Save') . '</button></td>' . "\n";
  6463. $return .= "\t\t" . '</tr>' . "\n";
  6464. $return .= "\t\t" . '</table>' . "\n";
  6465. $return .= "\t" . '<input name="parent" type="hidden" value="' . $data['parent_item_id'] . '"/>' . "\n";
  6466. $return .= "\t" . '<input name="previous" type="hidden" value="' . $data['previous_item_id'] . '"/>' . "\n";
  6467. $return .= '</form>';
  6468. $return .= '</div>';
  6469. return $return;
  6470. }
  6471. /**
  6472. * Return HTML form to allow prerequisites selection
  6473. * @param integer Item ID
  6474. * @return string HTML form
  6475. */
  6476. public function display_item_prerequisites_form($item_id) {
  6477. global $charset;
  6478. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  6479. /* Current prerequisite */
  6480. $sql = "
  6481. SELECT *
  6482. FROM " . $tbl_lp_item . "
  6483. WHERE id = " . $item_id;
  6484. $result = Database::query($sql);
  6485. $row = Database :: fetch_array($result);
  6486. $preq_id = $row['prerequisite'];
  6487. //$preq_mastery = $row['mastery_score'];
  6488. //$preq_max = $row['max_score'];
  6489. $return = $this->display_manipulate($item_id, TOOL_DOCUMENT);
  6490. $return = ' <div class="row">
  6491. <div class="form_header">';
  6492. $return .= get_lang('AddEditPrerequisites');
  6493. $return .= '</div> </div>';
  6494. $return .= '<div class="sectioncomment">';
  6495. $return .= '<form method="POST">';
  6496. $return .= '<table class="lp_prerequisites" style="border-collapse:collapse;">';
  6497. $return .= '<tr style="border-collapse:collapse;">';
  6498. $return .= '<th height="24" style="border:1px solid gray; background-color:#F0F0F0;">' . get_lang('Prerequisites') . '</th>';
  6499. $return .= '<th width="70" height="24" style="border:1px solid gray; background-color:#F0F0F0;">' . get_lang('Minimum') . '</th>';
  6500. $return .= '<th width="70" height="24" style="border:1px solid gray; background-color:#F0F0F0;">' . get_lang('Maximum') . '</th>';
  6501. $return .= '</tr>';
  6502. // Adding the none option to the prerequisites see http://www.chamilo.org/es/node/146
  6503. $return .= '<tr >';
  6504. $return .= '<td colspan="3" class="radio" style="border:1px solid gray;border-collapse:collapse;">';
  6505. $return .= '<input checked="checked" id="idNone" name="prerequisites" style="margin-left:0; margin-right:10px;" type="radio" />';
  6506. $return .= '<label for="idNone">' . get_lang('None') . '</label>';
  6507. $return .= '</td><td />';
  6508. $return .= '</tr>';
  6509. $sql = "SELECT * FROM " . $tbl_lp_item . " WHERE lp_id = " . $this->lp_id;
  6510. $result = Database::query($sql);
  6511. $arrLP = array ();
  6512. while ($row = Database :: fetch_array($result)) {
  6513. $arrLP[] = array (
  6514. 'id' => $row['id'],
  6515. 'item_type' => $row['item_type'],
  6516. 'title' => $row['title'],
  6517. 'ref' => $row['ref'],
  6518. 'description' => $row['description'],
  6519. 'parent_item_id' => $row['parent_item_id'],
  6520. 'previous_item_id' => $row['previous_item_id'],
  6521. 'next_item_id' => $row['next_item_id'],
  6522. 'max_score' => $row['max_score'],
  6523. 'min_score' => $row['min_score'],
  6524. 'mastery_score' => $row['mastery_score'],
  6525. 'prerequisite' => $row['prerequisite'],
  6526. 'next_item_id' => $row['next_item_id'],
  6527. 'display_order' => $row['display_order']
  6528. );
  6529. if ($row['ref'] == $preq_id) {
  6530. $preq_mastery = $row['mastery_score'];
  6531. $preq_max = $row['max_score'];
  6532. }
  6533. }
  6534. $this->tree_array($arrLP);
  6535. $arrLP = $this->arrMenu;
  6536. unset ($this->arrMenu);
  6537. for ($i = 0; $i < count($arrLP); $i++) {
  6538. if ($arrLP[$i]['id'] == $item_id)
  6539. break;
  6540. $return .= '<tr >';
  6541. $return .= '<td style="border:1px solid #B0B0B0; border-collapse:collapse; height:25px; padding: 3px 5px 3px 3px;" class="radio"' . (($arrLP[$i]['item_type'] != TOOL_QUIZ && $arrLP[$i]['item_type'] != TOOL_HOTPOTATOES) ? ' colspan="3"' : '') . '>';
  6542. $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'] . '" />';
  6543. $icon_name = str_replace(' ', '', $arrLP[$i]['item_type']);
  6544. if (file_exists('../img/lp_' . $icon_name . '.png')) {
  6545. $return .= '<img alt="" src="../img/lp_' . $icon_name . '.png" style="margin-right:5px;" title="" />';
  6546. } else
  6547. if (file_exists('../img/lp_' . $icon_name . '.gif')) {
  6548. $return .= '<img alt="" src="../img/lp_' . $icon_name . '.gif" style="margin-right:5px;" title="" />';
  6549. } else {
  6550. $return .= Display::return_icon('folder_document.gif','',array('style'=>'margin-right:5px;'));
  6551. }
  6552. $return .= '<label for="id' . $arrLP[$i]['id'] . '">' . $arrLP[$i]['title'] . '</label>';
  6553. $return .= '</td>';
  6554. //$return .= '<td class="radio"' . (($arrLP[$i]['item_type'] != TOOL_HOTPOTATOES) ? ' colspan="3"' : '') . ' />';
  6555. if ($arrLP[$i]['item_type'] == TOOL_QUIZ) {
  6556. $return .= '<td class="exercise" style="border:1px solid #B0B0B0;">';
  6557. $return .= '<center><input size="4" maxlength="3" name="min_' . $arrLP[$i]['id'] . '" type="text" value="' . (($arrLP[$i]['id'] == $preq_id) ? $preq_mastery : 0) . '" /></center>';
  6558. $return .= '</td>';
  6559. $return .= '<td class="exercise" style="border:1px solid #B0B0B0;">';
  6560. $return .= '<center><input size="4" maxlength="3" name="max_' . $arrLP[$i]['id'] . '" type="text" value="' . $arrLP[$i]['max_score'] . '" disabled="true" /></center>';
  6561. $return .= '</td>';
  6562. }
  6563. if ($arrLP[$i]['item_type'] == TOOL_HOTPOTATOES) {
  6564. $return .= '<td class="exercise" style="border:1px solid #B0B0B0;">';
  6565. $return .= '<center><input size="4" maxlength="3" name="min_' . $arrLP[$i]['id'] . '" type="text" value="' . (($arrLP[$i]['id'] == $preq_id) ? $preq_mastery : 0) . '" /></center>';
  6566. $return .= '</td>';
  6567. $return .= '<td class="exercise" style="border:1px solid #B0B0B0;">';
  6568. $return .= '<center><input size="4" maxlength="3" name="max_' . $arrLP[$i]['id'] . '" type="text" value="' . $arrLP[$i]['max_score'] . '" disabled="true" /></center>';
  6569. $return .= '</td>';
  6570. }
  6571. $return .= '</tr>';
  6572. }
  6573. $return .= '<tr>';
  6574. $return .= '<td colspan="3">';
  6575. $return .= '</td>';
  6576. $return .= '</tr>';
  6577. $return .= '</table>';
  6578. $return .= '<div style="padding-top:3px;">';
  6579. $return .= '<button class="save" name="submit_button" type="submit">' . get_lang('ModifyPrerequisites') . ' </button></td>' . "\n";
  6580. $return .= '</div>';
  6581. $return .= '</form>';
  6582. $return .= '</div>';
  6583. return $return;
  6584. }
  6585. /**
  6586. * Return HTML list to allow prerequisites selection for lp
  6587. * @param integer Item ID
  6588. * @return string HTML form
  6589. */
  6590. public function display_lp_prerequisites_list() {
  6591. global $charset;
  6592. $lp_id = $this->lp_id;
  6593. $tbl_lp = Database :: get_course_table(TABLE_LP_MAIN);
  6594. // get current prerequisite
  6595. $sql = "SELECT * FROM $tbl_lp WHERE id = $lp_id ";
  6596. $result = Database::query($sql);
  6597. $row = Database :: fetch_array($result);
  6598. $preq_id = $row['prerequisite'];
  6599. $session_id = api_get_session_id();
  6600. $session_condition = api_get_session_condition($session_id, false);
  6601. $sql = "SELECT * FROM $tbl_lp $session_condition ORDER BY display_order ";
  6602. $rs = Database::query($sql);
  6603. $return = '';
  6604. $return .= '<select name="prerequisites" >';
  6605. $return .= '<option value="0">'.get_lang('None').'</option>';
  6606. if (Database::num_rows($rs) > 0) {
  6607. while ($row = Database::fetch_array($rs)) {
  6608. if ($row['id'] == $lp_id) {
  6609. continue;
  6610. }
  6611. $return .= '<option value="'.$row['id'].'" '.(($row['id']==$preq_id)?' selected ' : '').'>'.$row['name'].'</option>';
  6612. }
  6613. }
  6614. $return .= '</select>';
  6615. return $return;
  6616. }
  6617. /**
  6618. * Creates a list with all the documents in it
  6619. * @return string
  6620. */
  6621. public function get_documents() {
  6622. global $_course;
  6623. $tbl_doc = Database :: get_course_table(TABLE_DOCUMENT);
  6624. $tbl_item_prop = Database::get_course_table(TABLE_ITEM_PROPERTY);
  6625. $tbl_course = Database::get_main_table(TABLE_MAIN_COURSE);
  6626. $path = '/';
  6627. $path = Database::escape_string(str_replace('_', '\_', $path));
  6628. $added_slash = ($path == '/') ? '' : '/';
  6629. //condition for the session
  6630. $current_session_id = api_get_session_id();
  6631. $condition_session = " AND (id_session = '$current_session_id' OR (id_session = '0' AND insert_date <= (SELECT creation_date FROM $tbl_course WHERE code = '{$_course[id]}')))";
  6632. $sql_doc = "SELECT docs.*
  6633. FROM $tbl_item_prop AS last, $tbl_doc AS docs
  6634. WHERE docs.id = last.ref
  6635. AND docs.path LIKE '".$path.$added_slash."%'
  6636. AND docs.path NOT LIKE '%_DELETED_%'
  6637. AND last.tool = '".TOOL_DOCUMENT."' $condition_session ORDER BY docs.path ASC";
  6638. //$sql_doc = "SELECT * FROM $tbl_doc WHERE path NOT LIKE '%_DELETED_%' ORDER BY path ASC";
  6639. $res_doc = Database::query($sql_doc);
  6640. $return = '<div class="lp_resource_header"' . " onclick=\"if(document.getElementById('resDoc').style.display == 'block') {document.getElementById('resDoc').style.display = 'none';} else {document.getElementById('resDoc').style.display = 'block';}\"" . '>'.Display::return_icon('folder_document.gif',get_lang('Documents'),array('style'=>'margin-right:5px;', 'height' => '16px')).' '. get_lang('Documents') . '</div>';
  6641. $return .= '<div class="lp_resource_elements" id="resDoc">';
  6642. $resources = Database::store_result($res_doc);
  6643. $resources_sorted = array();
  6644. // If you want to debug it, I advise you to do "echo" on the eval statements.
  6645. foreach ($resources as $resource) {
  6646. $resource_paths = explode('/', $resource['path']);
  6647. array_shift($resource_paths);
  6648. $path_to_eval = $last_path = '';
  6649. $is_file = false;
  6650. foreach ($resource_paths as $key => $resource_path) {
  6651. if (strpos($resource_path, '.') === false && $key != count($resource_paths) - 1) { // It's a folder.
  6652. $path_to_eval .= '["' . $resource_path . '"]["files"]';
  6653. } else
  6654. if (strpos($resource_path, '.') !== false)
  6655. $is_file = true;
  6656. $last_path = $resource_path;
  6657. }
  6658. if ($is_file) {
  6659. //eval ('$resources_sorted' . $path_to_eval . '[' . $resource['id'] . '] = "' . $last_path . '";');
  6660. //for backward compatibility
  6661. if (empty($resource['title'])) {
  6662. $resource['title'] = basename($resource['path']);
  6663. }
  6664. eval ('$resources_sorted' . $path_to_eval . '[' . $resource['id'] . '] = "' .$resource['title']."/". $last_path. '";');
  6665. } else {
  6666. eval ('$resources_sorted' . $path_to_eval . '["' . $last_path . '"]["id"]=' . $resource['id'] . ';');
  6667. }
  6668. }
  6669. $return .= $this->write_resources_tree($resources_sorted);
  6670. if (Database :: num_rows($res_doc) == 0) {
  6671. $return .= '<div class="lp_resource_element">' . get_lang('NoDocuments') . '</div>';
  6672. }
  6673. $return .= '</div>';
  6674. return $return;
  6675. }
  6676. /**
  6677. * Generate and return an HTML list of resources based on a given array.
  6678. * This list is used to show the course creator a list of available resources to choose from
  6679. * when creating a learning path.
  6680. * @param array Array of elements to add to the list
  6681. * @param integer Enables the tree display by shifting the new elements a certain distance to the right
  6682. * @return string The HTML list
  6683. */
  6684. public function write_resources_tree($resources_sorted, $num = 0) {
  6685. require_once api_get_path(LIBRARY_PATH).'fileDisplay.lib.php';
  6686. if (count($resources_sorted) > 0) {
  6687. foreach ($resources_sorted as $key => $resource) {
  6688. if (is_int($resource['id'])) {
  6689. // It's a folder.
  6690. $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="javascript: testResources(\'' . $resource['id'] . '\',\'img_' . $resource['id'] . '\')"><img alt="" src="../img/lp_folder.gif" title="" align="absmiddle" />&nbsp;<span onclick="javascript: testResources(\'' . $resource['id'] . '\',\'img_' . $resource['id'] . '\')" style="cursor: pointer;" >' . $key . '</span></div><div style="display: none;" id="' . $resource['id'] . '">';
  6691. $return .= $this->write_resources_tree($resource['files'], $num +1);
  6692. $return .= '</div></div>';
  6693. } else {
  6694. if (!is_array($resource)) {
  6695. // It's a file.
  6696. $icon = choose_image($resource);
  6697. $position = strrpos($icon, '.');
  6698. $icon = substr($icon, 0, $position) . '_small.gif';
  6699. $file_info = explode('/', $resource);
  6700. $my_file_title = $file_info[0];
  6701. $my_file_name = $file_info[1];
  6702. //$return .= '<div><div style="margin-left:' . (($num +1) * 15) . 'px;margin-right:5px;"><a href="' . api_get_self() . '?cidReq=' . $_GET['cidReq'] . '&amp;action=add_item&amp;type=' . TOOL_DOCUMENT . '&amp;file=' . $key . '&amp;lp_id=' . $this->lp_id . '"><img alt="" src="../img/' . $icon . '" title="" />&nbsp;' . $resource .'</a></div></div>';
  6703. // Show the "image name" not the filename of the image.
  6704. $return .= '<div><div style="margin-left:' . (($num +1) * 15) . 'px;margin-right:5px;"><a href="' . api_get_self() . '?cidReq=' . Security::remove_XSS($_GET['cidReq']) . '&amp;action=add_item&amp;type=' . TOOL_DOCUMENT . '&amp;file=' . $key . '&amp;lp_id=' . $this->lp_id . '"><img alt="" src="../img/' . $icon . '" title="" />&nbsp;' . $my_file_title . "</a></div></div>\r\n"; }
  6705. }
  6706. }
  6707. }
  6708. return $return;
  6709. }
  6710. /**
  6711. * Creates a list with all the exercises (quiz) in it
  6712. * @return string
  6713. */
  6714. public function get_exercises() {
  6715. // New for hotpotatoes.
  6716. $uploadPath = DIR_HOTPOTATOES; //defined in main_api
  6717. $tbl_doc = Database :: get_course_table(TABLE_DOCUMENT);
  6718. $tbl_quiz = Database :: get_course_table(TABLE_QUIZ_TEST);
  6719. $session_id = api_get_session_id();
  6720. $condition_session = api_get_session_condition($session_id);
  6721. $sql_quiz = "
  6722. SELECT *
  6723. FROM " . $tbl_quiz . "
  6724. WHERE active<>'-1' $condition_session
  6725. ORDER BY title ASC";
  6726. $sql_hot = "SELECT * FROM " . $tbl_doc . " " .
  6727. " WHERE path LIKE '" . $uploadPath . "/%/%htm%' $condition_session " .
  6728. " ORDER BY id ASC";
  6729. $res_quiz = Database::query($sql_quiz);
  6730. $res_hot = Database::query($sql_hot);
  6731. $return .= '<div class="lp_resource_header"' . " onclick=\"javascript: if(document.getElementById('resExercise').style.display == 'block') {document.getElementById('resExercise').style.display = 'none';} else {document.getElementById('resExercise').style.display = 'block';}\"" . ' ><img align="left" alt="" src="../img/lp_' . TOOL_QUIZ . '.gif" style="margin-right:5px;" title="" />' . get_lang('Quiz') . '</div>';
  6732. $return .= '<div class="lp_resource_elements" id="resExercise">';
  6733. while ($row_hot = Database :: fetch_array($res_hot)) {
  6734. $return .= '<div class="lp_resource_element">';
  6735. // Display quizhotpotatoes.
  6736. $return .= '<img alt="hp" src="../img/hotpotatoes_s.png" style="margin-right:5px;" title="" width="18px" height="18px" />';
  6737. $return .= '<a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&amp;action=add_item&amp;type=' . TOOL_HOTPOTATOES . '&amp;file=' . $row_hot['id'] . '&amp;lp_id=' . $this->lp_id . '">' . ((!empty ($row_hot['comment'])) ? $row_hot['comment'] : Security :: remove_XSS($row_hot['title'])) . '</a>';
  6738. //$return .= $row_quiz['title'];
  6739. $return .= '</div>';
  6740. }
  6741. while ($row_quiz = Database :: fetch_array($res_quiz)) {
  6742. $return .= '<div class="lp_resource_element">';
  6743. $return .= '<img alt="" src="../img/quizz_small.gif" style="margin-right:5px;" title="" />';
  6744. $return .= '<a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&amp;action=add_item&amp;type=' . TOOL_QUIZ . '&amp;file=' . $row_quiz['id'] . '&amp;lp_id=' . $this->lp_id . '">' . Security :: remove_XSS($row_quiz['title']) . '</a>';
  6745. //$return .= $row_quiz['title'];
  6746. $return .= '</div>';
  6747. }
  6748. if (Database :: num_rows($res_quiz) == 0) {
  6749. $return .= '<div class="lp_resource_element">' . get_lang('NoExercisesAvailable') . '</div>';
  6750. }
  6751. $return .= '<div class="lp_resource_element">';
  6752. $return .= '<img alt="" src="../img/new_test_small.gif" style="margin-right:5px;" title="" />';
  6753. $return .= '<a href="' . api_get_path(REL_CODE_PATH) . 'exercice/exercise_admin.php">' . get_lang('NewExercise') . '</a>';
  6754. $return .= '</div>';
  6755. $return .= '</div>';
  6756. return $return;
  6757. }
  6758. /**
  6759. * Creates a list with all the links in it
  6760. * @return string
  6761. */
  6762. public function get_links() {
  6763. $tbl_link = Database :: get_course_table(TABLE_LINK);
  6764. $session_id = api_get_session_id();
  6765. $condition_session = api_get_session_condition($session_id,false);
  6766. $sql_link = "SELECT * FROM $tbl_link $condition_session ORDER BY title ASC";
  6767. $res_link = Database::query($sql_link);
  6768. $return .= '<div class="lp_resource_header"' . " onclick=\"javascript: if(document.getElementById('resLink').style.display == 'block') {document.getElementById('resLink').style.display = 'none';} else {document.getElementById('resLink').style.display = 'block';}\"" . '><img alt="" src="../img/lp_' . TOOL_LINK . '.gif" style="margin-right:5px;" title="" />' . get_lang('Links') . '</div>';
  6769. $return .= '<div class="lp_resource_elements" id="resLink">';
  6770. while ($row_link = Database :: fetch_array($res_link)) {
  6771. $return .= '<div class="lp_resource_element">';
  6772. $return .= '<img alt="" src="../img/lp_link.gif" style="margin-right:5px;" title="" />';
  6773. $return .= '<a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&amp;action=add_item&amp;type=' . TOOL_LINK . '&amp;file=' . $row_link['id'] . '&amp;lp_id=' . $this->lp_id . '">' . $row_link['title'] . '</a>';
  6774. $return .= '</div>';
  6775. }
  6776. $return .= '<div class="lp_resource_element">';
  6777. $return .= '<img alt="" src="../img/linksnew.gif" style="margin-right:5px;width:16px" title="" />';
  6778. $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>';
  6779. $return .= '</div>';
  6780. if (Database :: num_rows($res_link) == 0)
  6781. $return .= '<div class="lp_resource_element">' . get_lang('NoLinksAvailable') . '</div>';
  6782. $return .= '</div>';
  6783. return $return;
  6784. }
  6785. /**
  6786. * Creates a list with all the student publications in it
  6787. * @return unknown
  6788. */
  6789. public function get_student_publications() {
  6790. $tbl_student = Database :: get_course_table(TABLE_STUDENT_PUBLICATION);
  6791. $session_id = api_get_session_id();
  6792. $condition_session = api_get_session_condition($session_id, false);
  6793. $sql_student = "SELECT * FROM $tbl_student $condition_session ORDER BY title ASC";
  6794. $res_student = Database::query($sql_student);
  6795. $return .= '<div class="lp_resource_header"' . " onclick=\"javascript: if(document.getElementById('resStudent').style.display == 'block') {document.getElementById('resStudent').style.display = 'none';} else {document.getElementById('resStudent').style.display = 'block';}\"" . '><img alt="" src="../img/lp_' . TOOL_STUDENTPUBLICATION . '.gif" style="margin-right:5px;" title="" />' . get_lang('Student_publication') . '</div>';
  6796. $return .= '<div class="lp_resource_elements" id="resStudent">';
  6797. $return .= '<div class="lp_resource_element">';
  6798. $return .= '<img align="left" alt="" src="../img/works_small.gif" style="margin-right:5px;" title="" />';
  6799. $return .= '<a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&amp;action=add_item&amp;type=' . TOOL_STUDENTPUBLICATION . '&amp;lp_id=' . $this->lp_id . '">' . get_lang('AddAssignmentPage') . '</a>';
  6800. $return .= '</div>';
  6801. $return .= '</div>';
  6802. return $return;
  6803. }
  6804. /**
  6805. * Creates a list with all the forums in it
  6806. * @return string
  6807. */
  6808. public function get_forums() {
  6809. include '../forum/forumfunction.inc.php';
  6810. include '../forum/forumconfig.inc.php';
  6811. global $table_forums, $table_threads, $table_posts, $table_item_property, $table_users;
  6812. $table_forums = Database :: get_course_table(TABLE_FORUM);
  6813. $table_threads = Database :: get_course_table(TABLE_FORUM_THREAD);
  6814. $table_posts = Database :: get_course_table(TABLE_FORUM_POST);
  6815. $table_item_property = Database :: get_course_table(TABLE_ITEM_PROPERTY);
  6816. $table_users = Database :: get_main_table(TABLE_MAIN_USER);
  6817. $a_forums = get_forums();
  6818. $return .= '<div class="lp_resource_header"' . " onclick=\"javascript: if(document.getElementById('forums').style.display == 'block') {document.getElementById('forums').style.display = 'none';} else {document.getElementById('forums').style.display = 'block';}\"" . '><img alt="" src="../img/lp_forum.gif" style="margin-right:5px;" title="" />' . get_lang('Forums') . '</div>';
  6819. $return .= '<div class="lp_resource_elements" style="border:1px solid #999999;" id="forums">';
  6820. foreach ($a_forums as $forum) {
  6821. $return .= '<div class="lp_resource_element">';
  6822. $return .= '<script type="text/javascript">
  6823. function toggle_forum(forum_id){
  6824. if(document.getElementById("forum_"+forum_id+"_content").style.display == "none"){
  6825. document.getElementById("forum_"+forum_id+"_content").style.display = "block";
  6826. document.getElementById("forum_"+forum_id+"_opener").src = "' . api_get_path(WEB_IMG_PATH) . 'remove.gif";
  6827. }
  6828. else {
  6829. document.getElementById("forum_"+forum_id+"_content").style.display = "none";
  6830. document.getElementById("forum_"+forum_id+"_opener").src = "' . api_get_path(WEB_IMG_PATH) . 'add.gif";
  6831. }
  6832. }
  6833. </script>
  6834. ';
  6835. if (!empty($forum['forum_id'])) {
  6836. $return .= '<img alt="" src="../img/lp_forum.gif" style="margin-right:5px;" title="" />';
  6837. $return .= '<a style="cursor:hand" onclick="javascript: toggle_forum(' . $forum['forum_id'] . ')" style="vertical-align:middle"><img src="' . api_get_path(WEB_IMG_PATH) . 'add.gif" id="forum_' . $forum['forum_id'] . '_opener" align="absbottom" /></a>
  6838. <a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&amp;action=add_item&amp;type=' . TOOL_FORUM . '&amp;forum_id=' . $forum['forum_id'] . '&amp;lp_id=' . $this->lp_id . '" style="vertical-align:middle">' . Security :: remove_XSS($forum['forum_title']) . '</a><ul style="display:none" id="forum_' . $forum['forum_id'] . '_content">';
  6839. }
  6840. $a_threads = get_threads($forum['forum_id']);
  6841. if (is_array($a_threads)) {
  6842. foreach ($a_threads as $thread) {
  6843. $return .= '<li><a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&amp;action=add_item&amp;type=' . TOOL_THREAD . '&amp;thread_id=' . $thread['thread_id'] . '&amp;lp_id=' . $this->lp_id . '">' . Security :: remove_XSS($thread['thread_title']) . '</a></li>';
  6844. }
  6845. }
  6846. $return .= '</ul></div>';
  6847. }
  6848. $return .= '<div class="lp_resource_element">';
  6849. $return .= '<img alt="" src="../img/forum_new_small.gif" style="margin-right:5px;" title="" />';
  6850. $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>';
  6851. $return .= '</div>';
  6852. return $return;
  6853. }
  6854. /**
  6855. * // TODO: The output encoding should be equal to the system encoding.
  6856. *
  6857. * Exports the learning path as a SCORM package. This is the main function that
  6858. * gathers the content, transforms it, writes the imsmanifest.xml file, zips the
  6859. * whole thing and returns the zip.
  6860. *
  6861. * This method needs to be called in PHP5, as it will fail with non-adequate
  6862. * XML package (like the ones for PHP4), and it is *not* a static method, so
  6863. * you need to call it on a learnpath object.
  6864. * @TODO The method might be redefined later on in the scorm class itself to avoid
  6865. * creating a SCORM structure if there is one already. However, if the initial SCORM
  6866. * path has been modified, it should use the generic method here below.
  6867. * @TODO link this function with the export_lp() function in the same class
  6868. * @param string Optional name of zip file. If none, title of learnpath is
  6869. * domesticated and trailed with ".zip"
  6870. * @return string Returns the zip package string, or null if error
  6871. */
  6872. public function scorm_export() {
  6873. global $_course;
  6874. // Remove memory and time limits as much as possible as this might be a long process...
  6875. if (function_exists('ini_set')) {
  6876. $mem = ini_get('memory_limit');
  6877. if (substr($mem, -1, 1) == 'M') {
  6878. $mem_num = substr($mem, 0, -1);
  6879. if ($mem_num < 128) {
  6880. ini_set('memory_limit', '128M');
  6881. }
  6882. } else {
  6883. ini_set('memory_limit', '128M');
  6884. }
  6885. ini_set('max_execution_time', 600);
  6886. //} else {
  6887. //error_log('Scorm export: could not change memory and time limits', 0);
  6888. }
  6889. // Create the zip handler (this will remain available throughout the method).
  6890. $archive_path = api_get_path(SYS_ARCHIVE_PATH);
  6891. $sys_course_path = api_get_path(SYS_COURSE_PATH);
  6892. $temp_dir_short = uniqid();
  6893. $temp_zip_dir = $archive_path.'/'.$temp_dir_short;
  6894. $temp_zip_file = $temp_zip_dir.'/'.md5(time()).'.zip';
  6895. $zip_folder = new PclZip($temp_zip_file);
  6896. $current_course_path = api_get_path(SYS_COURSE_PATH).api_get_course_path();
  6897. $root_path = $main_path = api_get_path(SYS_PATH);
  6898. $files_cleanup = array();
  6899. // Place to temporarily stash the zipfiles.
  6900. // create the temp dir if it doesn't exist
  6901. // or do a cleanup befor creating the zipfile.
  6902. if (!is_dir($temp_zip_dir)) {
  6903. mkdir($temp_zip_dir, api_get_permissions_for_new_directories());
  6904. } else {
  6905. // Cleanup: Check the temp dir for old files and delete them.
  6906. $handle = opendir($temp_zip_dir);
  6907. while (false !== ($file = readdir($handle))) {
  6908. if ($file != '.' && $file != '..') {
  6909. unlink("$temp_zip_dir/$file");
  6910. }
  6911. }
  6912. closedir($handle);
  6913. }
  6914. $zip_files = $zip_files_abs = $zip_files_dist = array();
  6915. if (is_dir($current_course_path.'/scorm/'.$this->path) && is_file($current_course_path.'/scorm/'.$this->path.'/imsmanifest.xml')) {
  6916. // Remove the possible . at the end of the path.
  6917. $dest_path_to_lp = substr($this->path, -1) == '.' ? substr($this->path, 0, -1) : $this->path;
  6918. $dest_path_to_scorm_folder = str_replace('//','/',$temp_zip_dir.'/scorm/'.$dest_path_to_lp);
  6919. mkdir($dest_path_to_scorm_folder, api_get_permissions_for_new_directories(), true);
  6920. $zip_files_dist = copyr($current_course_path.'/scorm/'.$this->path, $dest_path_to_scorm_folder, array('imsmanifest'), $zip_files);
  6921. }
  6922. // Build a dummy imsmanifest structure. Do not add to the zip yet (we still need it).
  6923. // This structure is developed following regulations for SCORM 1.2 packaging in the SCORM 1.2 Content
  6924. // Aggregation Model official document, secion "2.3 Content Packaging".
  6925. $xmldoc = new DOMDocument('1.0'); // We are going to build a UTF-8 encoded manifest. Later we will recode it to the desired (and supported) encoding.
  6926. $root = $xmldoc->createElement('manifest');
  6927. $root->setAttribute('identifier', 'SingleCourseManifest');
  6928. $root->setAttribute('version', '1.1');
  6929. $root->setAttribute('xmlns', 'http://www.imsproject.org/xsd/imscp_rootv1p1p2');
  6930. $root->setAttribute('xmlns:adlcp', 'http://www.adlnet.org/xsd/adlcp_rootv1p2');
  6931. $root->setAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance');
  6932. $root->setAttribute('xsi:schemaLocation', 'http://www.imsproject.org/xsd/imscp_rootv1p1p2 imscp_rootv1p1p2.xsd http://www.imsglobal.org/xsd/imsmd_rootv1p2p1 imsmd_rootv1p2p1.xsd http://www.adlnet.org/xsd/adlcp_rootv1p2 adlcp_rootv1p2.xsd');
  6933. // Build mandatory sub-root container elements.
  6934. $metadata = $xmldoc->createElement('metadata');
  6935. $md_schema = $xmldoc->createElement('schema', 'ADL SCORM');
  6936. $metadata->appendChild($md_schema);
  6937. $md_schemaversion = $xmldoc->createElement('schemaversion', '1.2');
  6938. $metadata->appendChild($md_schemaversion);
  6939. $root->appendChild($metadata);
  6940. $organizations = $xmldoc->createElement('organizations');
  6941. $resources = $xmldoc->createElement('resources');
  6942. // Build the only organization we will use in building our learnpaths.
  6943. $organizations->setAttribute('default', 'chamilo_scorm_export');
  6944. $organization = $xmldoc->createElement('organization');
  6945. $organization->setAttribute('identifier', 'chamilo_scorm_export');
  6946. // To set the title of the SCORM entity (=organization), we take the name given
  6947. // in Chamilo and convert it to HTML entities using the Chamilo charset (not the
  6948. // learning path charset) as it is the encoding that defines how it is stored
  6949. // in the database. Then we convert it to HTML entities again as the "&" character
  6950. // alone is not authorized in XML (must be &amp;).
  6951. // The title is then decoded twice when extracting (see scorm::parse_manifest).
  6952. $org_title = $xmldoc->createElement('title', api_utf8_encode($this->get_name()));
  6953. $organization->appendChild($org_title);
  6954. // For each element, add it to the imsmanifest structure, then add it to the zip.
  6955. // Always call the learnpathItem->scorm_export() method to change it to the SCORM format.
  6956. $link_updates = array();
  6957. foreach ($this->items as $index => $item) {
  6958. if (!in_array($item->type, array(TOOL_QUIZ, TOOL_FORUM, TOOL_THREAD, TOOL_LINK, TOOL_STUDENTPUBLICATION))) {
  6959. // Get included documents from this item.
  6960. if ($item->type == 'sco')
  6961. $inc_docs = $item->get_resources_from_source(null, api_get_path(SYS_COURSE_PATH).api_get_course_path().'/'.'scorm/'.$this->path.'/'.$item->get_path());
  6962. else
  6963. $inc_docs = $item->get_resources_from_source();
  6964. // Give a child element <item> to the <organization> element.
  6965. $my_item_id = $item->get_id();
  6966. $my_item = $xmldoc->createElement('item');
  6967. $my_item->setAttribute('identifier', 'ITEM_'.$my_item_id);
  6968. $my_item->setAttribute('identifierref', 'RESOURCE_'.$my_item_id);
  6969. $my_item->setAttribute('isvisible', 'true');
  6970. // Give a child element <title> to the <item> element.
  6971. $my_title = $xmldoc->createElement('title', htmlspecialchars(api_utf8_encode($item->get_title()), ENT_QUOTES, 'UTF-8'));
  6972. $my_item->appendChild($my_title);
  6973. // Give a child element <adlcp:prerequisites> to the <item> element.
  6974. $my_prereqs = $xmldoc->createElement('adlcp:prerequisites', $this->get_scorm_prereq_string($my_item_id));
  6975. $my_prereqs->setAttribute('type', 'aicc_script');
  6976. $my_item->appendChild($my_prereqs);
  6977. // Give a child element <adlcp:maxtimeallowed> to the <item> element - not yet supported.
  6978. //$xmldoc->createElement('adlcp:maxtimeallowed','');
  6979. // Give a child element <adlcp:timelimitaction> to the <item> element - not yet supported.
  6980. //$xmldoc->createElement('adlcp:timelimitaction','');
  6981. // Give a child element <adlcp:datafromlms> to the <item> element - not yet supported.
  6982. //$xmldoc->createElement('adlcp:datafromlms','');
  6983. // Give a child element <adlcp:masteryscore> to the <item> element.
  6984. $my_masteryscore = $xmldoc->createElement('adlcp:masteryscore', $item->get_mastery_score());
  6985. $my_item->appendChild($my_masteryscore);
  6986. // Attach this item to the organization element or hits parent if there is one.
  6987. if (!empty($item->parent) && $item->parent != 0) {
  6988. $children = $organization->childNodes;
  6989. $possible_parent = &$this->get_scorm_xml_node($children, 'ITEM_'.$item->parent);
  6990. if (is_object($possible_parent)) {
  6991. $possible_parent->appendChild($my_item);
  6992. } else {
  6993. if ($this->debug > 0) { error_log('Parent ITEM_'.$item->parent.' of item ITEM_'.$my_item_id.' not found'); }
  6994. }
  6995. } else {
  6996. if ($this->debug > 0) { error_log('No parent'); }
  6997. $organization->appendChild($my_item);
  6998. }
  6999. // Get the path of the file(s) from the course directory root.
  7000. $my_file_path = $item->get_file_path('scorm/'.$this->path.'/');
  7001. //$my_xml_file_path = api_htmlentities(api_utf8_encode($my_file_path), ENT_QUOTES, 'UTF-8');
  7002. $my_xml_file_path = $my_file_path;
  7003. $my_sub_dir = dirname($my_file_path);
  7004. $my_sub_dir = str_replace('\\', '/', $my_sub_dir);
  7005. //$my_xml_sub_dir = api_htmlentities(api_utf8_encode($my_sub_dir), ENT_QUOTES, 'UTF-8');
  7006. $my_xml_sub_dir = $my_sub_dir;
  7007. // Give a <resource> child to the <resources> element
  7008. $my_resource = $xmldoc->createElement('resource');
  7009. $my_resource->setAttribute('identifier', 'RESOURCE_'.$item->get_id());
  7010. $my_resource->setAttribute('type', 'webcontent');
  7011. $my_resource->setAttribute('href', $my_xml_file_path);
  7012. // adlcp:scormtype can be either 'sco' or 'asset'.
  7013. if ($item->type == 'sco') {
  7014. $my_resource->setAttribute('adlcp:scormtype', 'sco');
  7015. } else {
  7016. $my_resource->setAttribute('adlcp:scormtype', 'asset');
  7017. }
  7018. // xml:base is the base directory to find the files declared in this resource.
  7019. $my_resource->setAttribute('xml:base', '');
  7020. // Give a <file> child to the <resource> element.
  7021. $my_file = $xmldoc->createElement('file');
  7022. $my_file->setAttribute('href', $my_xml_file_path);
  7023. $my_resource->appendChild($my_file);
  7024. // Dependency to other files - not yet supported.
  7025. $i = 1;
  7026. foreach ($inc_docs as $doc_info) {
  7027. if (count($doc_info) < 1 || empty($doc_info[0])) { continue; }
  7028. $my_dep = $xmldoc->createElement('resource');
  7029. $res_id = 'RESOURCE_'.$item->get_id().'_'.$i;
  7030. $my_dep->setAttribute('identifier', $res_id);
  7031. $my_dep->setAttribute('type', 'webcontent');
  7032. $my_dep->setAttribute('adlcp:scormtype', 'asset');
  7033. $my_dep_file = $xmldoc->createElement('file');
  7034. // Check type of URL.
  7035. //error_log(__LINE__.'Now dealing with '.$doc_info[0].' of type '.$doc_info[1].'-'.$doc_info[2], 0);
  7036. if ($doc_info[1] == 'remote') {
  7037. // Remote file. Save url as is.
  7038. $my_dep_file->setAttribute('href', $doc_info[0]);
  7039. $my_dep->setAttribute('xml:base', '');
  7040. } elseif ($doc_info[1] == 'local') {
  7041. switch ($doc_info[2]) {
  7042. case 'url': // Local URL - save path as url for now, don't zip file.
  7043. $abs_path = api_get_path(SYS_PATH).str_replace(api_get_path(WEB_PATH), '', $doc_info[0]);
  7044. $current_dir = dirname($abs_path);
  7045. $current_dir = str_replace('\\', '/', $current_dir);
  7046. $file_path = realpath($abs_path);
  7047. $file_path = str_replace('\\', '/', $file_path);
  7048. $my_dep_file->setAttribute('href', $file_path);
  7049. $my_dep->setAttribute('xml:base', '');
  7050. if (strstr($file_path, $main_path) !== false) {
  7051. // The calculated real path is really inside Chamilo's root path.
  7052. // Reduce file path to what's under the DocumentRoot.
  7053. $file_path = substr($file_path, strlen($root_path) - 1);
  7054. //echo $file_path;echo '<br /><br />';
  7055. //error_log(__LINE__.'Reduced url path: '.$file_path, 0);
  7056. $zip_files_abs[] = $file_path;
  7057. $link_updates[$my_file_path][] = array('orig' => $doc_info[0], 'dest' => $file_path);
  7058. $my_dep_file->setAttribute('href', $file_path);
  7059. $my_dep->setAttribute('xml:base', '');
  7060. }
  7061. elseif (empty($file_path)) {
  7062. /*$document_root = substr(api_get_path(SYS_PATH), 0, strpos(api_get_path(SYS_PATH), api_get_path(REL_PATH)));
  7063. if (strpos($document_root, -1) == '/') {
  7064. $document_root = substr(0, -1, $document_root);
  7065. }*/
  7066. $file_path = $_SERVER['DOCUMENT_ROOT'].$abs_path;
  7067. $file_path = str_replace('//', '/', $file_path);
  7068. if (file_exists($file_path)) {
  7069. $file_path = substr($file_path, strlen($current_dir)); // We get the relative path.
  7070. $zip_files[] = $my_sub_dir.'/'.$file_path;
  7071. $link_updates[$my_file_path][] = array('orig' => $doc_info[0], 'dest' => $file_path);
  7072. $my_dep_file->setAttribute('href', $file_path);
  7073. $my_dep->setAttribute('xml:base', '');
  7074. }
  7075. }
  7076. break;
  7077. case 'abs': // Absolute path from DocumentRoot. Save file and leave path as is in the zip.
  7078. $my_dep_file->setAttribute('href', $doc_info[0]);
  7079. $my_dep->setAttribute('xml:base', '');
  7080. //$current_dir = str_replace('\\', '/', dirname($current_course_path.'/'.$item->get_file_path())).'/';
  7081. // The next lines fix a bug when using the "subdir" mode of Chamilo, whereas
  7082. // an image path would be constructed as /var/www/subdir/subdir/img/foo.bar
  7083. $abs_img_path_without_subdir = $doc_info[0];
  7084. $relp = api_get_path(REL_PATH); // The url-append config param.
  7085. $pos = strpos($abs_img_path_without_subdir, $relp);
  7086. if ($pos === 0) {
  7087. $abs_img_path_without_subdir = '/'.substr($abs_img_path_without_subdir, strlen($relp));
  7088. }
  7089. //$file_path = realpath(api_get_path(SYS_PATH).$doc_info[0]);
  7090. $file_path = realpath(api_get_path(SYS_PATH).$abs_img_path_without_subdir);
  7091. $file_path = str_replace('\\', '/', $file_path);
  7092. $file_path = str_replace('//', '/', $file_path);
  7093. //error_log(__LINE__.'Abs path: '.$file_path, 0);
  7094. // Prepare the current directory path (until just under 'document') with a trailing slash.
  7095. $cur_path = substr($current_course_path, -1) == '/' ? $current_course_path : $current_course_path.'/';
  7096. // Check if the current document is in that path.
  7097. if (strstr($file_path, $cur_path) !== false) {
  7098. // The document is in that path, now get the relative path
  7099. // to the containing document.
  7100. $orig_file_path = dirname($cur_path.$my_file_path).'/';
  7101. $orig_file_path = str_replace('\\', '/', $orig_file_path);
  7102. $relative_path = '';
  7103. if (strstr($file_path, $cur_path) !== false) {
  7104. $relative_path = substr($file_path, strlen($orig_file_path));
  7105. $file_path = substr($file_path, strlen($cur_path));
  7106. } else {
  7107. // This case is still a problem as it's difficult to calculate a relative path easily
  7108. // might still generate wrong links.
  7109. //$file_path = substr($file_path,strlen($cur_path));
  7110. // Calculate the directory path to the current file (without trailing slash).
  7111. $my_relative_path = dirname($file_path);
  7112. $my_relative_path = str_replace('\\', '/', $my_relative_path);
  7113. $my_relative_file = basename($file_path);
  7114. // Calculate the directory path to the containing file (without trailing slash).
  7115. $my_orig_file_path = substr($orig_file_path, 0, -1);
  7116. $dotdot = '';
  7117. $subdir = '';
  7118. while (strstr($my_relative_path, $my_orig_file_path) === false && (strlen($my_orig_file_path) > 1) && (strlen($my_relative_path) > 1)) {
  7119. $my_relative_path2 = dirname($my_relative_path);
  7120. $my_relative_path2 = str_replace('\\', '/', $my_relative_path2);
  7121. $my_orig_file_path = dirname($my_orig_file_path);
  7122. $my_orig_file_path = str_replace('\\', '/', $my_orig_file_path);
  7123. $subdir = substr($my_relative_path, strlen($my_relative_path2) + 1).'/'.$subdir;
  7124. $dotdot += '../';
  7125. $my_relative_path = $my_relative_path2;
  7126. }
  7127. $relative_path = $dotdot.$subdir.$my_relative_file;
  7128. }
  7129. // Put the current document in the zip (this array is the array
  7130. // that will manage documents already in the course folder - relative).
  7131. $zip_files[] = $file_path;
  7132. // Update the links to the current document in the containing document (make them relative).
  7133. $link_updates[$my_file_path][] = array('orig' => $doc_info[0], 'dest' => $relative_path);
  7134. $my_dep_file->setAttribute('href', $file_path);
  7135. $my_dep->setAttribute('xml:base', '');
  7136. }
  7137. elseif (strstr($file_path,$main_path) !== false) {
  7138. // The calculated real path is really inside Chamilo's root path.
  7139. // Reduce file path to what's under the DocumentRoot.
  7140. $file_path = substr($file_path, strlen($root_path));
  7141. //echo $file_path;echo '<br /><br />';
  7142. //error_log('Reduced path: '.$file_path, 0);
  7143. $zip_files_abs[] = $file_path;
  7144. $link_updates[$my_file_path][] = array('orig' => $doc_info[0], 'dest' => $file_path);
  7145. $my_dep_file->setAttribute('href', 'document/'.$file_path);
  7146. $my_dep->setAttribute('xml:base', '');
  7147. }
  7148. elseif (empty($file_path)) {
  7149. /*$document_root = substr(api_get_path(SYS_PATH), 0, strpos(api_get_path(SYS_PATH), api_get_path(REL_PATH)));
  7150. if(strpos($document_root,-1) == '/') {
  7151. $document_root = substr(0, -1, $document_root);
  7152. }*/
  7153. $file_path = $_SERVER['DOCUMENT_ROOT'].$doc_info[0];
  7154. $file_path = str_replace('//', '/', $file_path);
  7155. if (file_exists($file_path)) {
  7156. $file_path = substr($file_path,strlen($current_dir)); // We get the relative path.
  7157. $zip_files[] = $my_sub_dir.'/'.$file_path;
  7158. $link_updates[$my_file_path][] = array('orig' => $doc_info[0], 'dest' => $file_path);
  7159. $my_dep_file->setAttribute('href','document/'.$file_path);
  7160. $my_dep->setAttribute('xml:base', '');
  7161. }
  7162. }
  7163. break;
  7164. 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
  7165. if (substr($doc_info[0], 0, 2) == '..') {
  7166. // Relative path going up.
  7167. $current_dir = dirname($current_course_path.'/'.$item->get_file_path()).'/';
  7168. $current_dir = str_replace('\\', '/', $current_dir);
  7169. $file_path = realpath($current_dir.$doc_info[0]);
  7170. $file_path = str_replace('\\', '/', $file_path);
  7171. //error_log($file_path.' <-> '.$main_path,0);
  7172. if (strstr($file_path, $main_path) !== false) {
  7173. // The calculated real path is really inside Chamilo's root path.
  7174. // Reduce file path to what's under the DocumentRoot.
  7175. $file_path = substr($file_path, strlen($root_path));
  7176. //error_log('Reduced path: '.$file_path, 0);
  7177. $zip_files_abs[] = $file_path;
  7178. $link_updates[$my_file_path][] = array('orig' => $doc_info[0], 'dest' => $file_path);
  7179. $my_dep_file->setAttribute('href', 'document/'.$file_path);
  7180. $my_dep->setAttribute('xml:base', '');
  7181. }
  7182. } else {
  7183. $zip_files[] = $my_sub_dir.'/'.$doc_info[0];
  7184. $my_dep_file->setAttribute('href', $doc_info[0]);
  7185. $my_dep->setAttribute('xml:base', $my_xml_sub_dir);
  7186. }
  7187. break;
  7188. default:
  7189. $my_dep_file->setAttribute('href', $doc_info[0]);
  7190. $my_dep->setAttribute('xml:base', '');
  7191. break;
  7192. }
  7193. }
  7194. $my_dep->appendChild($my_dep_file);
  7195. $resources->appendChild($my_dep);
  7196. $dependency = $xmldoc->createElement('dependency');
  7197. $dependency->setAttribute('identifierref', $res_id);
  7198. $my_resource->appendChild($dependency);
  7199. $i++;
  7200. }
  7201. //$my_dependency = $xmldoc->createElement('dependency');
  7202. //$my_dependency->setAttribute('identifierref', '');
  7203. $resources->appendChild($my_resource);
  7204. $zip_files[] = $my_file_path;
  7205. //error_log('File '.$my_file_path. ' added to $zip_files', 0);
  7206. } else {
  7207. // If the item is a quiz or a link or whatever non-exportable, we include a step indicating it.
  7208. if ($item->type == TOOL_LINK) {
  7209. $my_item = $xmldoc->createElement('item');
  7210. $my_item->setAttribute('identifier', 'ITEM_'.$item->get_id());
  7211. $my_item->setAttribute('identifierref', 'RESOURCE_'.$item->get_id());
  7212. $my_item->setAttribute('isvisible', 'true');
  7213. // Give a child element <title> to the <item> element.
  7214. $my_title = $xmldoc->createElement('title', htmlspecialchars(api_utf8_encode($item->get_title()), ENT_QUOTES, 'UTF-8'));
  7215. $my_item->appendChild($my_title);
  7216. // Give a child element <adlcp:prerequisites> to the <item> element.
  7217. $my_prereqs = $xmldoc->createElement('adlcp:prerequisites', $item->get_prereq_string());
  7218. $my_prereqs->setAttribute('type', 'aicc_script');
  7219. $my_item->appendChild($my_prereqs);
  7220. // Give a child element <adlcp:maxtimeallowed> to the <item> element - not yet supported.
  7221. //$xmldoc->createElement('adlcp:maxtimeallowed', '');
  7222. // Give a child element <adlcp:timelimitaction> to the <item> element - not yet supported.
  7223. //$xmldoc->createElement('adlcp:timelimitaction', '');
  7224. // Give a child element <adlcp:datafromlms> to the <item> element - not yet supported.
  7225. //$xmldoc->createElement('adlcp:datafromlms', '');
  7226. // Give a child element <adlcp:masteryscore> to the <item> element.
  7227. $my_masteryscore = $xmldoc->createElement('adlcp:masteryscore', $item->get_mastery_score());
  7228. $my_item->appendChild($my_masteryscore);
  7229. // Attach this item to the organization element or its parent if there is one.
  7230. if (!empty($item->parent) && $item->parent != 0) {
  7231. $children = $organization->childNodes;
  7232. for ($i = 0; $i < $children->length; $i++) {
  7233. $item_temp = $children->item($i);
  7234. if ($item_temp -> nodeName == 'item') {
  7235. if ($item_temp->getAttribute('identifier') == 'ITEM_'.$item->parent) {
  7236. $item_temp -> appendChild($my_item);
  7237. }
  7238. }
  7239. }
  7240. } else {
  7241. $organization->appendChild($my_item);
  7242. }
  7243. $my_file_path = 'link_'.$item->get_id().'.html';
  7244. $sql = 'SELECT url, title FROM '.Database :: get_course_table(TABLE_LINK).' WHERE id='.$item->path;
  7245. $rs = Database::query($sql);
  7246. if ($link = Database :: fetch_array($rs)) {
  7247. $url = $link['url'];
  7248. $title = stripslashes($link['title']);
  7249. $links_to_create[$my_file_path] = array('title' => $title, 'url' => $url);
  7250. //$my_xml_file_path = api_htmlentities(api_utf8_encode($my_file_path), ENT_QUOTES, 'UTF-8');
  7251. $my_xml_file_path = $my_file_path;
  7252. $my_sub_dir = dirname($my_file_path);
  7253. $my_sub_dir = str_replace('\\', '/', $my_sub_dir);
  7254. //$my_xml_sub_dir = api_htmlentities(api_utf8_encode($my_sub_dir), ENT_QUOTES, 'UTF-8');
  7255. $my_xml_sub_dir = $my_sub_dir;
  7256. // Give a <resource> child to the <resources> element.
  7257. $my_resource = $xmldoc->createElement('resource');
  7258. $my_resource->setAttribute('identifier', 'RESOURCE_'.$item->get_id());
  7259. $my_resource->setAttribute('type', 'webcontent');
  7260. $my_resource->setAttribute('href', $my_xml_file_path);
  7261. // adlcp:scormtype can be either 'sco' or 'asset'.
  7262. $my_resource->setAttribute('adlcp:scormtype', 'asset');
  7263. // xml:base is the base directory to find the files declared in this resource.
  7264. $my_resource->setAttribute('xml:base', '');
  7265. // give a <file> child to the <resource> element.
  7266. $my_file = $xmldoc->createElement('file');
  7267. $my_file->setAttribute('href', $my_xml_file_path);
  7268. $my_resource->appendChild($my_file);
  7269. $resources->appendChild($my_resource);
  7270. }
  7271. }
  7272. elseif ($item->type == TOOL_QUIZ) {
  7273. require_once api_get_path(SYS_CODE_PATH).'exercice/exercise.class.php';
  7274. $exe_id = $item->path; // Should be using ref when everything will be cleaned up in this regard.
  7275. $exe = new Exercise();
  7276. $exe->read($exe_id);
  7277. $my_item = $xmldoc->createElement('item');
  7278. $my_item->setAttribute('identifier', 'ITEM_'.$item->get_id());
  7279. $my_item->setAttribute('identifierref', 'RESOURCE_'.$item->get_id());
  7280. $my_item->setAttribute('isvisible', 'true');
  7281. // Give a child element <title> to the <item> element.
  7282. $my_title = $xmldoc->createElement('title', htmlspecialchars(api_utf8_encode($item->get_title()), ENT_QUOTES, 'UTF-8'));
  7283. $my_item->appendChild($my_title);
  7284. $my_max_score = $xmldoc->createElement('max_score', $item->get_max());
  7285. //$my_item->appendChild($my_max_score);
  7286. // Give a child element <adlcp:prerequisites> to the <item> element.
  7287. $my_prereqs = $xmldoc->createElement('adlcp:prerequisites', $item->get_prereq_string());
  7288. $my_prereqs->setAttribute('type','aicc_script');
  7289. $my_item->appendChild($my_prereqs);
  7290. // Give a child element <adlcp:masteryscore> to the <item> element.
  7291. $my_masteryscore = $xmldoc->createElement('adlcp:masteryscore', $item->get_mastery_score());
  7292. $my_item->appendChild($my_masteryscore);
  7293. // Attach this item to the organization element or hits parent if there is one.
  7294. if (!empty($item->parent) && $item->parent != 0) {
  7295. $children = $organization->childNodes;
  7296. for ($i = 0; $i < $children->length; $i++) {
  7297. $item_temp = $children->item($i);
  7298. if ($item_temp -> nodeName == 'item') {
  7299. if ($item_temp->getAttribute('identifier') == 'ITEM_'.$item->parent) {
  7300. $item_temp -> appendChild($my_item);
  7301. }
  7302. }
  7303. }
  7304. } else {
  7305. $organization->appendChild($my_item);
  7306. }
  7307. // Include export scripts.
  7308. require_once api_get_path(SYS_CODE_PATH).'exercice/export/scorm/scorm_export.php';
  7309. // Get the path of the file(s) from the course directory root
  7310. //$my_file_path = $item->get_file_path('scorm/'.$this->path.'/');
  7311. $my_file_path = 'quiz_'.$item->get_id().'.html';
  7312. // Write the contents of the exported exercise into a (big) html file
  7313. // to later pack it into the exported SCORM. The file will be removed afterwards.
  7314. $contents = export_exercise($exe_id,true);
  7315. $tmp_file_path = $archive_path.$temp_dir_short.'/'.$my_file_path;
  7316. $res = file_put_contents($tmp_file_path, $contents);
  7317. if ($res === false) { error_log('Could not write into file '.$tmp_file_path.' '.__FILE__.' '.__LINE__, 0); }
  7318. $files_cleanup[] = $tmp_file_path;
  7319. //error_log($tmp_path); die();
  7320. //$my_xml_file_path = api_htmlentities(api_utf8_encode($my_file_path), ENT_QUOTES, 'UTF-8');
  7321. $my_xml_file_path = $my_file_path;
  7322. $my_sub_dir = dirname($my_file_path);
  7323. $my_sub_dir = str_replace('\\', '/', $my_sub_dir);
  7324. //$my_xml_sub_dir = api_htmlentities(api_utf8_encode($my_sub_dir), ENT_QUOTES, 'UTF-8');
  7325. $my_xml_sub_dir = $my_sub_dir;
  7326. // Give a <resource> child to the <resources> element.
  7327. $my_resource = $xmldoc->createElement('resource');
  7328. $my_resource->setAttribute('identifier', 'RESOURCE_'.$item->get_id());
  7329. $my_resource->setAttribute('type', 'webcontent');
  7330. $my_resource->setAttribute('href', $my_xml_file_path);
  7331. // adlcp:scormtype can be either 'sco' or 'asset'.
  7332. $my_resource->setAttribute('adlcp:scormtype', 'sco');
  7333. // xml:base is the base directory to find the files declared in this resource.
  7334. $my_resource->setAttribute('xml:base', '');
  7335. // Give a <file> child to the <resource> element.
  7336. $my_file = $xmldoc->createElement('file');
  7337. $my_file->setAttribute('href', $my_xml_file_path);
  7338. $my_resource->appendChild($my_file);
  7339. // Get included docs.
  7340. $inc_docs = $item->get_resources_from_source(null,$tmp_file_path);
  7341. // Dependency to other files - not yet supported.
  7342. $i = 1;
  7343. foreach ($inc_docs as $doc_info) {
  7344. if (count($doc_info) < 1 || empty($doc_info[0])) { continue; }
  7345. $my_dep = $xmldoc->createElement('resource');
  7346. $res_id = 'RESOURCE_'.$item->get_id().'_'.$i;
  7347. $my_dep->setAttribute('identifier', $res_id);
  7348. $my_dep->setAttribute('type', 'webcontent');
  7349. $my_dep->setAttribute('adlcp:scormtype', 'asset');
  7350. $my_dep_file = $xmldoc->createElement('file');
  7351. // Check type of URL.
  7352. //error_log(__LINE__.'Now dealing with '.$doc_info[0].' of type '.$doc_info[1].'-'.$doc_info[2], 0);
  7353. if ($doc_info[1] == 'remote') {
  7354. // Remote file. Save url as is.
  7355. $my_dep_file->setAttribute('href', $doc_info[0]);
  7356. $my_dep->setAttribute('xml:base', '');
  7357. } elseif ($doc_info[1] == 'local') {
  7358. switch ($doc_info[2]) {
  7359. case 'url': // Local URL - save path as url for now, don't zip file.
  7360. // Save file but as local file (retrieve from URL).
  7361. $abs_path = api_get_path(SYS_PATH).str_replace(api_get_path(WEB_PATH), '', $doc_info[0]);
  7362. $current_dir = dirname($abs_path);
  7363. $current_dir = str_replace('\\', '/', $current_dir);
  7364. $file_path = realpath($abs_path);
  7365. $file_path = str_replace('\\', '/', $file_path);
  7366. $my_dep_file->setAttribute('href', 'document/'.$file_path);
  7367. $my_dep->setAttribute('xml:base', '');
  7368. if (strstr($file_path, $main_path) !== false) {
  7369. // The calculated real path is really inside the chamilo root path.
  7370. // Reduce file path to what's under the DocumentRoot.
  7371. $file_path = substr($file_path, strlen($root_path));
  7372. //echo $file_path;echo '<br /><br />';
  7373. //error_log('Reduced path: '.$file_path, 0);
  7374. $zip_files_abs[] = $file_path;
  7375. $link_updates[$my_file_path][] = array('orig' => $doc_info[0], 'dest' => 'document/'.$file_path);
  7376. $my_dep_file->setAttribute('href', 'document/'.$file_path);
  7377. $my_dep->setAttribute('xml:base', '');
  7378. }
  7379. elseif (empty($file_path)) {
  7380. /*$document_root = substr(api_get_path(SYS_PATH), 0, strpos(api_get_path(SYS_PATH),api_get_path(REL_PATH)));
  7381. if (strpos($document_root,-1) == '/') {
  7382. $document_root = substr(0, -1, $document_root);
  7383. }*/
  7384. $file_path = $_SERVER['DOCUMENT_ROOT'].$abs_path;
  7385. $file_path = str_replace('//', '/', $file_path);
  7386. if (file_exists($file_path)) {
  7387. $file_path = substr($file_path, strlen($current_dir)); // We get the relative path.
  7388. $zip_files[] = $my_sub_dir.'/'.$file_path;
  7389. $link_updates[$my_file_path][] = array('orig' => $doc_info[0], 'dest' => 'document/'.$file_path);
  7390. $my_dep_file->setAttribute('href', 'document/'.$file_path);
  7391. $my_dep->setAttribute('xml:base', '');
  7392. }
  7393. }
  7394. break;
  7395. case 'abs': // Absolute path from DocumentRoot. Save file and leave path as is in the zip.
  7396. $current_dir = dirname($current_course_path.'/'.$item->get_file_path()).'/';
  7397. $current_dir = str_replace('\\', '/', $current_dir);
  7398. $file_path = realpath($doc_info[0]);
  7399. $file_path = str_replace('\\', '/', $file_path);
  7400. $my_dep_file->setAttribute('href', $file_path);
  7401. $my_dep->setAttribute('xml:base', '');
  7402. if (strstr($file_path,$main_path) !== false) {
  7403. // The calculated real path is really inside the chamilo root path.
  7404. // Reduce file path to what's under the DocumentRoot.
  7405. $file_path = substr($file_path, strlen($root_path));
  7406. //echo $file_path;echo '<br /><br />';
  7407. //error_log('Reduced path: '.$file_path, 0);
  7408. $zip_files_abs[] = $file_path;
  7409. $link_updates[$my_file_path][] = array('orig' => $doc_info[0], 'dest' => $file_path);
  7410. $my_dep_file->setAttribute('href', 'document/'.$file_path);
  7411. $my_dep->setAttribute('xml:base', '');
  7412. }
  7413. elseif (empty($file_path)) {
  7414. /*$document_root = substr(api_get_path(SYS_PATH), 0, strpos(api_get_path(SYS_PATH), api_get_path(REL_PATH)));
  7415. if (strpos($document_root,-1) == '/') {
  7416. $document_root = substr(0, -1, $document_root);
  7417. }*/
  7418. $file_path = $_SERVER['DOCUMENT_ROOT'].$doc_info[0];
  7419. $file_path = str_replace('//', '/', $file_path);
  7420. if (file_exists($file_path)) {
  7421. $file_path = substr($file_path,strlen($current_dir)); // We get the relative path.
  7422. $zip_files[] = $my_sub_dir.'/'.$file_path;
  7423. $link_updates[$my_file_path][] = array('orig' => $doc_info[0], 'dest' => $file_path);
  7424. $my_dep_file->setAttribute('href', 'document/'.$file_path);
  7425. $my_dep->setAttribute('xml:base', '');
  7426. }
  7427. }
  7428. break;
  7429. 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
  7430. if (substr($doc_info[0], 0, 2) == '..') {
  7431. // Relative path going up.
  7432. $current_dir = dirname($current_course_path.'/'.$item->get_file_path()).'/';
  7433. $current_dir = str_replace('\\', '/', $current_dir);
  7434. $file_path = realpath($current_dir.$doc_info[0]);
  7435. $file_path = str_replace('\\', '/', $file_path);
  7436. //error_log($file_path.' <-> '.$main_path, 0);
  7437. if (strstr($file_path, $main_path) !== false) {
  7438. // The calculated real path is really inside Chamilo's root path.
  7439. // Reduce file path to what's under the DocumentRoot.
  7440. $file_path = substr($file_path, strlen($root_path));
  7441. $file_path_dest = $file_path;
  7442. // File path is courses/CHAMILO/document/....
  7443. $info_file_path = explode('/', $file_path);
  7444. if ($info_file_path[0] == 'courses') { // Add character "/" in file path.
  7445. $file_path_dest = 'document/'.$file_path;
  7446. }
  7447. //error_log('Reduced path: '.$file_path, 0);
  7448. $zip_files_abs[] = $file_path;
  7449. $link_updates[$my_file_path][] = array('orig' => $doc_info[0], 'dest' => $file_path_dest);
  7450. $my_dep_file->setAttribute('href', 'document/'.$file_path);
  7451. $my_dep->setAttribute('xml:base', '');
  7452. }
  7453. } else {
  7454. $zip_files[] = $my_sub_dir.'/'.$doc_info[0];
  7455. $my_dep_file->setAttribute('href', $doc_info[0]);
  7456. $my_dep->setAttribute('xml:base', $my_xml_sub_dir);
  7457. }
  7458. break;
  7459. default:
  7460. $my_dep_file->setAttribute('href', $doc_info[0]); // ../../courses/
  7461. $my_dep->setAttribute('xml:base', '');
  7462. break;
  7463. }
  7464. }
  7465. $my_dep->appendChild($my_dep_file);
  7466. $resources->appendChild($my_dep);
  7467. $dependency = $xmldoc->createElement('dependency');
  7468. $dependency->setAttribute('identifierref', $res_id);
  7469. $my_resource->appendChild($dependency);
  7470. $i++;
  7471. }
  7472. $resources->appendChild($my_resource);
  7473. $zip_files[] = $my_file_path;
  7474. } else {
  7475. // Get the path of the file(s) from the course directory root
  7476. $my_file_path = 'non_exportable.html';
  7477. //$my_xml_file_path = api_htmlentities(api_utf8_encode($my_file_path), ENT_COMPAT, 'UTF-8');
  7478. $my_xml_file_path = $my_file_path;
  7479. $my_sub_dir = dirname($my_file_path);
  7480. $my_sub_dir = str_replace('\\', '/', $my_sub_dir);
  7481. //$my_xml_sub_dir = api_htmlentities(api_utf8_encode($my_sub_dir), ENT_COMPAT, 'UTF-8');
  7482. $my_xml_sub_dir = $my_sub_dir;
  7483. // Give a <resource> child to the <resources> element.
  7484. $my_resource = $xmldoc->createElement('resource');
  7485. $my_resource->setAttribute('identifier', 'RESOURCE_'.$item->get_id());
  7486. $my_resource->setAttribute('type', 'webcontent');
  7487. $my_resource->setAttribute('href', 'document/'.$my_xml_file_path);
  7488. // adlcp:scormtype can be either 'sco' or 'asset'.
  7489. $my_resource->setAttribute('adlcp:scormtype', 'asset');
  7490. // xml:base is the base directory to find the files declared in this resource.
  7491. $my_resource->setAttribute('xml:base', '');
  7492. // Give a <file> child to the <resource> element.
  7493. $my_file = $xmldoc->createElement('file');
  7494. $my_file->setAttribute('href', 'document/'.$my_xml_file_path);
  7495. $my_resource->appendChild($my_file);
  7496. $resources->appendChild($my_resource);
  7497. }
  7498. }
  7499. }
  7500. $organizations->appendChild($organization);
  7501. $root->appendChild($organizations);
  7502. $root->appendChild($resources);
  7503. $xmldoc->appendChild($root);
  7504. // TODO: Add a readme file here, with a short description and a link to the Reload player
  7505. // then add the file to the zip, then destroy the file (this is done automatically).
  7506. // http://www.reload.ac.uk/scormplayer.html - once done, don't forget to close FS#138
  7507. //error_log(print_r($zip_files,true), 0);
  7508. foreach ($zip_files as $file_path) {
  7509. if (empty($file_path)) { continue; }
  7510. //error_log(__LINE__.'getting document from '.$sys_course_path.$_course['path'].'/'.$file_path.' removing '.$sys_course_path.$_course['path'].'/',0);
  7511. $dest_file = $archive_path.$temp_dir_short.'/'.$file_path;
  7512. $this->create_path($dest_file);
  7513. //error_log('copy '.api_get_path(SYS_COURSE_PATH).$_course['path'].'/'.$file_path.' to '.api_get_path(SYS_ARCHIVE_PATH).$temp_dir_short.'/'.$file_path,0);
  7514. //echo $main_path.$file_path.'<br />';
  7515. @copy($sys_course_path.$_course['path'].'/'.$file_path, $dest_file);
  7516. // Check if the file needs a link update.
  7517. if (in_array($file_path, array_keys($link_updates))) {
  7518. $string = file_get_contents($dest_file);
  7519. unlink($dest_file);
  7520. foreach ($link_updates[$file_path] as $old_new) {
  7521. //error_log('Replacing '.$old_new['orig'].' by '.$old_new['dest'].' in '.$file_path, 0);
  7522. // This is an ugly hack that allows .flv files to be found by the flv player that
  7523. // will be added in document/main/inc/lib/flv_player/flv_player.swf and that needs
  7524. // to find the flv to play in document/main/, so we replace main/ in the flv path by
  7525. // ../../.. to return from inc/lib/flv_player to the document/main path.
  7526. if (substr($old_new['dest'], -3) == 'flv' && substr($old_new['dest'], 0, 5) == 'main/') {
  7527. $old_new['dest'] = str_replace('main/', '../../../', $old_new['dest']);
  7528. }
  7529. elseif (substr($old_new['dest'], -3) == 'flv' && substr($old_new['dest'], 0, 6) == 'video/') {
  7530. $old_new['dest'] = str_replace('video/', '../../../../video/', $old_new['dest']);
  7531. }
  7532. $string = str_replace($old_new['orig'], $old_new['dest'], $string);
  7533. }
  7534. file_put_contents($dest_file, $string);
  7535. }
  7536. }
  7537. foreach ($zip_files_abs as $file_path) {
  7538. if (empty($file_path)) { continue; }
  7539. //error_log(__LINE__.'checking existence of '.$main_path.$file_path.'', 0);
  7540. if (!is_file($main_path.$file_path) || !is_readable($main_path.$file_path)) { continue; }
  7541. //error_log(__LINE__.'getting document from '.$main_path.$file_path.' removing '.api_get_path(SYS_COURSE_PATH).$_course['path'].'/', 0);
  7542. $dest_file = $archive_path.$temp_dir_short.'/document/'.$file_path;
  7543. $this->create_path($dest_file);
  7544. //error_log('Created path '.api_get_path(SYS_ARCHIVE_PATH).$temp_dir_short.'/document/'.$file_path, 0);
  7545. //error_log('copy '.api_get_path(SYS_COURSE_PATH).$_course['path'].'/'.$file_path.' to '.api_get_path(SYS_ARCHIVE_PATH).$temp_dir_short.'/'.$file_path, 0);
  7546. //echo $main_path.$file_path.' - '.$dest_file.'<br />';
  7547. copy($main_path.$file_path, $dest_file);
  7548. // Check if the file needs a link update.
  7549. if (in_array($file_path, array_keys($link_updates))) {
  7550. $string = file_get_contents($dest_file);
  7551. unlink($dest_file);
  7552. foreach ($link_updates[$file_path] as $old_new) {
  7553. //error_log('Replacing '.$old_new['orig'].' by '.$old_new['dest'].' in '.$file_path, 0);
  7554. // This is an ugly hack that allows .flv files to be found by the flv player that
  7555. // will be added in document/main/inc/lib/flv_player/flv_player.swf and that needs
  7556. // to find the flv to play in document/main/, so we replace main/ in the flv path by
  7557. // ../../.. to return from inc/lib/flv_player to the document/main path.
  7558. if (substr($old_new['dest'], -3) == 'flv' && substr($old_new['dest'], 0, 5) == 'main/') {
  7559. $old_new['dest'] = str_replace('main/', '../../../', $old_new['dest']);
  7560. }
  7561. $string = str_replace($old_new['orig'], $old_new['dest'], $string);
  7562. }
  7563. file_put_contents($dest_file, $string);
  7564. }
  7565. }
  7566. if (is_array($links_to_create)) {
  7567. foreach ($links_to_create as $file => $link) {
  7568. $file_content = '<!DOCTYPE html
  7569. PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  7570. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  7571. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="'.api_get_language_isocode().'" lang="'.api_get_language_isocode().'">
  7572. <head>
  7573. <title>'.$link['title'].'</title>
  7574. <meta http-equiv="Content-Type" content="text/html; charset='.api_get_system_encoding().'" />
  7575. </head>
  7576. <body dir="'.api_get_text_direction().'">
  7577. <div style="text-align:center"><a href="'.$link['url'].'">'.$link['title'].'</a></div>
  7578. </body>
  7579. </html>';
  7580. file_put_contents($archive_path.$temp_dir_short.'/'.$file, $file_content);
  7581. }
  7582. }
  7583. // Add non exportable message explanation.
  7584. $lang_not_exportable = get_lang('ThisItemIsNotExportable');
  7585. $file_content = '<!DOCTYPE html
  7586. PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  7587. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  7588. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="'.api_get_language_isocode().'" lang="'.api_get_language_isocode().'">
  7589. <head>
  7590. <title>'.$lang_not_exportable.'</title>
  7591. <meta http-equiv="Content-Type" content="text/html; charset='.api_get_system_encoding().'" />
  7592. </head>
  7593. <body dir="'.api_get_text_direction().'">
  7594. ';
  7595. $file_content .=
  7596. <<<EOD
  7597. <style>
  7598. .error-message {
  7599. font-family: arial, verdana, helvetica, sans-serif;
  7600. border-width: 1px;
  7601. border-style: solid;
  7602. left: 50%;
  7603. margin: 10px auto;
  7604. min-height: 30px;
  7605. padding: 5px;
  7606. right: 50%;
  7607. width: 500px;
  7608. background-color: #FFD1D1;
  7609. border-color: #FF0000;
  7610. color: #000;
  7611. }
  7612. </style>
  7613. <body>
  7614. <div class="error-message">
  7615. $lang_not_exportable
  7616. </div>
  7617. </body>
  7618. </html>
  7619. EOD;
  7620. if (!is_dir($archive_path.$temp_dir_short.'/document')) {
  7621. @mkdir($archive_path.$temp_dir_short.'/document', api_get_permissions_for_new_directories());
  7622. }
  7623. file_put_contents($archive_path.$temp_dir_short.'/document/non_exportable.html', $file_content);
  7624. // Add the extra files that go along with a SCORM package.
  7625. $main_code_path = api_get_path(SYS_CODE_PATH).'newscorm/packaging/';
  7626. $extra_files = scandir($main_code_path);
  7627. foreach ($extra_files as $extra_file) {
  7628. if (strpos($extra_file, '.') === 0)
  7629. continue;
  7630. else {
  7631. $dest_file = $archive_path . $temp_dir_short . '/' . $extra_file;
  7632. $this->create_path($dest_file);
  7633. copy($main_code_path.$extra_file, $dest_file);
  7634. }
  7635. }
  7636. // Finalize the imsmanifest structure, add to the zip, then return the zip.
  7637. $manifest = @$xmldoc->saveXML();
  7638. $manifest = api_utf8_decode_xml($manifest); // The manifest gets the system encoding now.
  7639. file_put_contents($archive_path.'/'.$temp_dir_short.'/imsmanifest.xml', $manifest);
  7640. $zip_folder->add($archive_path.'/'.$temp_dir_short, PCLZIP_OPT_REMOVE_PATH, $archive_path.'/'.$temp_dir_short.'/');
  7641. // Clean possible temporary files.
  7642. foreach ($files_cleanup as $file) {
  7643. $res = unlink($file);
  7644. if ($res === false) { error_log('Could not delete temp file '.$file.' '.__FILE__.' '.__LINE__, 0); }
  7645. }
  7646. // Send file to client.
  7647. //$name = 'scorm_export_'.$this->lp_id.'.zip';
  7648. require_once api_get_path(LIBRARY_PATH).'fileUpload.lib.php';
  7649. $name = replace_dangerous_char($this->get_name()).'.zip';
  7650. DocumentManager::file_send_for_download($temp_zip_file, true, $name);
  7651. }
  7652. public function scorm_export_to_pdf($lp_id) {
  7653. $lp_id = intval($lp_id);
  7654. $files_to_export = array();
  7655. $course_data = api_get_course_info($this->cc);
  7656. if (!empty($course_data)) {
  7657. $scorm_path = api_get_path(SYS_COURSE_PATH).$course_data['path'].'/scorm/'.$this->path;
  7658. require_once api_get_path(LIBRARY_PATH).'document.lib.php';
  7659. foreach($this->items as $item) {
  7660. //Getting documents from a LP with chamilo documents
  7661. switch ($item->type) {
  7662. case 'document':
  7663. $file_data = DocumentManager::get_document_data_by_id($item->path, $this->cc);
  7664. $file_path = api_get_path(SYS_COURSE_PATH).$course_data['path'].'/document'.$file_data['path'];
  7665. if (file_exists($file_path)) {
  7666. $files_to_export[] = $file_path;
  7667. }
  7668. break;
  7669. case 'sco':
  7670. $file_path = $scorm_path.'/'.$item->path;
  7671. if (file_exists($file_path)) {
  7672. $files_to_export[] = $file_path;
  7673. }
  7674. break;
  7675. }
  7676. }
  7677. require_once api_get_path(LIBRARY_PATH).'pdf.lib.php';
  7678. $pdf = new PDF();
  7679. $result = $pdf->html_to_pdf($files_to_export, $this->name, $this->cc);
  7680. return $result;
  7681. }
  7682. return false;
  7683. }
  7684. /**
  7685. * Temp function to be moved in main_api or the best place around for this. Creates a file path
  7686. * if it doesn't exist
  7687. */
  7688. public function create_path($path) {
  7689. $path_bits = split('/', dirname($path));
  7690. // IS_WINDOWS_OS has been defined in main_api.lib.php
  7691. $path_built = IS_WINDOWS_OS ? '' : '/';
  7692. foreach ($path_bits as $bit) {
  7693. if (!empty ($bit)) {
  7694. $new_path = $path_built . $bit;
  7695. if (is_dir($new_path)) {
  7696. $path_built = $new_path . '/';
  7697. } else {
  7698. mkdir($new_path, api_get_permissions_for_new_directories());
  7699. $path_built = $new_path . '/';
  7700. }
  7701. }
  7702. }
  7703. }
  7704. /**
  7705. * Delete the image relative to this learning path. No parameter. Only works on instanciated object.
  7706. * @return boolean The results of the unlink function, or false if there was no image to start with
  7707. */
  7708. public function delete_lp_image() {
  7709. $img = $this->get_preview_image();
  7710. if ($img != '') {
  7711. $del_file = api_get_path(SYS_COURSE_PATH) . api_get_course_path() . '/upload/learning_path/images/' . $img;
  7712. $this->set_preview_image('');
  7713. return @ unlink($del_file);
  7714. } else {
  7715. return false;
  7716. }
  7717. }
  7718. /**
  7719. * Uploads an author image to the upload/learning_path/images directory
  7720. * @param array The image array, coming from the $_FILES superglobal
  7721. * @return boolean True on success, false on error
  7722. */
  7723. public function upload_image($image_array) {
  7724. $image_moved = false;
  7725. if (!empty ($image_array['name'])) {
  7726. $upload_ok = process_uploaded_file($image_array);
  7727. $has_attachment = true;
  7728. } else {
  7729. $image_moved = true;
  7730. }
  7731. if ($upload_ok) {
  7732. if ($has_attachment) {
  7733. $courseDir = api_get_course_path() . '/upload/learning_path/images';
  7734. $sys_course_path = api_get_path(SYS_COURSE_PATH);
  7735. $updir = $sys_course_path . $courseDir;
  7736. // Try to add an extension to the file if it hasn't one.
  7737. $new_file_name = add_ext_on_mime(stripslashes($image_array['name']), $image_array['type']);
  7738. if (!filter_extension($new_file_name)) {
  7739. //Display :: display_error_message(get_lang('UplUnableToSaveFileFilteredExtension'));
  7740. $image_moved = false;
  7741. } else {
  7742. $file_extension = explode('.', $image_array['name']);
  7743. $file_extension = strtolower($file_extension[sizeof($file_extension) - 1]);
  7744. $new_file_name = uniqid('') . '.' . $file_extension;
  7745. $new_path = $updir . '/' . $new_file_name;
  7746. //$result = @move_uploaded_file($image_array['tmp_name'], $new_path);
  7747. // Resize the image.
  7748. include_once api_get_path(LIBRARY_PATH).'image.lib.php';
  7749. $temp = new image($image_array['tmp_name']);
  7750. $picture_infos = @getimagesize($image_array['tmp_name']); // $picture_infos[0]-> width
  7751. if ($picture_infos[0] > 104) {
  7752. $thumbwidth = 104;
  7753. } else {
  7754. $thumbwidth = $picture_infos[0];
  7755. }
  7756. if ($picture_infos[1] > 96) {
  7757. $new_height = 96;
  7758. } else {
  7759. $new_height = $picture_infos[1];
  7760. }
  7761. //$new_height = round(($thumbwidth/$picture_infos[0])*$picture_infos[1]);
  7762. $temp->resize($thumbwidth,$new_height, 0);
  7763. $type = $picture_infos[2];
  7764. $result = false;
  7765. switch ($type) {
  7766. case 2 :
  7767. $result = $temp->send_image('JPG', $new_path);
  7768. break;
  7769. case 3 :
  7770. $result = $temp->send_image('PNG', $new_path);
  7771. break;
  7772. case 1 :
  7773. $result = $temp->send_image('GIF', $new_path);
  7774. break;
  7775. }
  7776. $temp->resize($thumbwidth, $new_height, 0);
  7777. $type = $picture_infos[2];
  7778. $result = false;
  7779. switch ($type) {
  7780. case 2 :
  7781. $result = $temp->send_image('JPG', $new_path);
  7782. break;
  7783. case 3 :
  7784. $result = $temp->send_image('PNG', $new_path);
  7785. break;
  7786. case 1 :
  7787. $result = $temp->send_image('GIF', $new_path);
  7788. break;
  7789. }
  7790. // Storing the image filename.
  7791. if ($result) {
  7792. $image_moved = true;
  7793. $this->set_preview_image($new_file_name);
  7794. return true;
  7795. }
  7796. }
  7797. }
  7798. }
  7799. return false;
  7800. }
  7801. public function set_autolunch($lp_id, $status) {
  7802. $lp_id = intval($lp_id);
  7803. $status = intval($status);
  7804. $lp_table = Database::get_course_table(TABLE_LP_MAIN);
  7805. //Setting everything to autolunch = 0
  7806. $attributes['autolunch'] = 0;
  7807. $where = array('session_id = ? '=> api_get_session_id());
  7808. Database::update($lp_table, $attributes,$where);
  7809. if ($status == 1) {
  7810. //Setting my lp_id to autolunch = 1
  7811. $attributes['autolunch'] = 1;
  7812. $where = array('id = ? AND session_id = ? '=> array($lp_id, api_get_session_id()));
  7813. Database::update_query($lp_table, $attributes, $where );
  7814. }
  7815. }
  7816. }
  7817. if (!function_exists('trim_value')) {
  7818. function trim_value(& $value) {
  7819. $value = trim($value);
  7820. }
  7821. }