learnpath.class.php 418 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731
  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 = 1; // 1 or 0
  65. public $created_on = '';
  66. public $modified_on = '';
  67. public $publicated_on = '';
  68. public $expired_on = '';
  69. /**
  70. * Class constructor. Needs a database handler, a course code and a learnpath id from the database.
  71. * Also builds the list of items into $this->items.
  72. * @param string Course code
  73. * @param integer Learnpath ID
  74. * @param integer User ID
  75. * @return boolean True on success, false on error
  76. */
  77. public function __construct($course, $lp_id, $user_id) {
  78. $this->encoding = api_get_system_encoding(); // Chamilo 1.8.8: We intend always to use the system encoding.
  79. // Check params.
  80. // Check course code.
  81. $course_db = '';
  82. if ($this->debug > 0) {error_log('New LP - In learnpath::__construct('.$course.','.$lp_id.','.$user_id.')', 0); }
  83. if (empty($course)) {
  84. $this->error = 'Course code is empty';
  85. return false;
  86. } else {
  87. $main_table = Database::get_main_table(TABLE_MAIN_COURSE);
  88. //$course = Database::escape_string($course);
  89. $course = $this->escape_string($course);
  90. $sql = "SELECT * FROM $main_table WHERE code = '$course'";
  91. if ($this->debug > 2) { error_log('New LP - learnpath::__construct() '.__LINE__.' - Querying course: '.$sql, 0); }
  92. $res = Database::query($sql);
  93. if (Database::num_rows($res) > 0) {
  94. $this->cc = $course;
  95. $row_course = Database::fetch_array($res);
  96. $course_db = $row_course['db_name'];
  97. } else {
  98. $this->error = 'Course code does not exist in database ('.$sql.')';
  99. return false;
  100. }
  101. }
  102. // Check learnpath ID.
  103. if (empty($lp_id)) {
  104. $this->error = 'Learnpath ID is empty';
  105. return false;
  106. } else {
  107. // TODO: Make it flexible to use any course_code (still using env course code here).
  108. $lp_table = Database::get_course_table(TABLE_LP_MAIN, $course_db);
  109. //$id = Database::escape_integer($id);
  110. $lp_id = $this->escape_string($lp_id);
  111. $sql = "SELECT * FROM $lp_table WHERE id = '$lp_id'";
  112. if ($this->debug > 2) { error_log('New LP - learnpath::__construct() '.__LINE__.' - Querying lp: '.$sql, 0); }
  113. $res = Database::query($sql);
  114. if (Database::num_rows($res) > 0) {
  115. $this->lp_id = $lp_id;
  116. $row = Database::fetch_array($res);
  117. $this->type = $row['lp_type'];
  118. $this->name = stripslashes($row['name']);
  119. //$this->encoding = $row['default_encoding']; // Chamilo 1.8.8: We intend not to use 'default_encoding' field anymore.
  120. $this->proximity = $row['content_local'];
  121. $this->theme = $row['theme'];
  122. $this->maker = $row['content_maker'];
  123. $this->prevent_reinit = $row['prevent_reinit'];
  124. $this->license = $row['content_license'];
  125. $this->scorm_debug = $row['debug'];
  126. $this->js_lib = $row['js_lib'];
  127. $this->path = $row['path'];
  128. $this->preview_image = $row['preview_image'];
  129. $this->author = $row['author'];
  130. $this->lp_session_id = $row['session_id'];
  131. $this->use_max_score = $row['use_max_score'];
  132. $this->created_on = $row['created_on'];
  133. $this->modified_on = $row['modified_on'];
  134. if ($row['publicated_on'] != '0000-00-00 00:00:00') {
  135. $this->publicated_on = $row['publicated_on'];
  136. }
  137. if ($row['expired_on'] != '0000-00-00 00:00:00') {
  138. $this->expired_on = $row['expired_on'];
  139. }
  140. if ($this->type == 2) {
  141. if ($row['force_commit'] == 1) {
  142. $this->force_commit = true;
  143. }
  144. }
  145. $this->mode = $row['default_view_mod'];
  146. } else {
  147. $this->error = 'Learnpath ID does not exist in database ('.$sql.')';
  148. return false;
  149. }
  150. }
  151. // Check user ID.
  152. if (empty($user_id)) {
  153. $this->error = 'User ID is empty';
  154. return false;
  155. } else {
  156. //$main_table = Database::get_main_user_table();
  157. $main_table = Database::get_main_table(TABLE_MAIN_USER);
  158. //$user_id = Database::escape_integer($user_id);
  159. $user_id = $this->escape_string($user_id);
  160. $sql = "SELECT * FROM $main_table WHERE user_id = '$user_id'";
  161. if ($this->debug > 2) { error_log('New LP - learnpath::__construct() '.__LINE__.' - Querying user: '.$sql, 0); }
  162. $res = Database::query($sql);
  163. if (Database::num_rows($res) > 0) {
  164. $this->user_id = $user_id;
  165. } else {
  166. $this->error = 'User ID does not exist in database ('.$sql.')';
  167. return false;
  168. }
  169. }
  170. // End of variables checking.
  171. $session_id = api_get_session_id();
  172. // Get the session condition for learning paths of the base + session.
  173. $session = api_get_session_condition($session_id);
  174. // Now get the latest attempt from this user on this LP, if available, otherwise create a new one.
  175. $lp_table = Database::get_course_table(TABLE_LP_VIEW, $course_db);
  176. // Selecting by view_count descending allows to get the highest view_count first.
  177. $sql = "SELECT * FROM $lp_table WHERE lp_id = '$lp_id' AND user_id = '$user_id' $session ORDER BY view_count DESC";
  178. if ($this->debug > 2) { error_log('New LP - learnpath::__construct() ' . __LINE__ . ' - querying lp_view: ' . $sql, 0); }
  179. $res = Database::query($sql);
  180. $view_id = 0; // Used later to query lp_item_view.
  181. if (Database :: num_rows($res) > 0) {
  182. if ($this->debug > 2) {
  183. error_log('New LP - learnpath::__construct() ' . __LINE__ . ' - Found previous view', 0);
  184. }
  185. $row = Database :: fetch_array($res);
  186. $this->attempt = $row['view_count'];
  187. $this->lp_view_id = $row['id'];
  188. $this->last_item_seen = $row['last_item'];
  189. $this->progress_db = $row['progress'];
  190. $this->lp_view_session_id = $row['session_id'];
  191. } else {
  192. if ($this->debug > 2) {
  193. error_log('New LP - learnpath::__construct() ' . __LINE__ . ' - NOT Found previous view', 0);
  194. }
  195. $this->attempt = 1;
  196. $sql_ins = "INSERT INTO $lp_table (lp_id,user_id,view_count, session_id) VALUES ($lp_id,$user_id,1,$session_id)";
  197. $res_ins = Database::query($sql_ins);
  198. $this->lp_view_id = Database :: insert_id();
  199. if ($this->debug > 2) {
  200. error_log('New LP - learnpath::__construct() ' . __LINE__ . ' - inserting new lp_view: ' . $sql_ins, 0);
  201. }
  202. }
  203. // Initialise items.
  204. $lp_item_table = Database::get_course_table(TABLE_LP_ITEM, $course_db);
  205. $sql = "SELECT * FROM $lp_item_table WHERE lp_id = '".$this->lp_id."' ORDER BY parent_item_id, display_order";
  206. $res = Database::query($sql);
  207. while ($row = Database::fetch_array($res)) {
  208. $oItem = '';
  209. //$this->ordered_items[] = $row['id'];
  210. switch ($this->type) {
  211. case 3: //aicc
  212. $oItem = new aiccItem('db', $row['id'], $course_db);
  213. if (is_object($oItem)) {
  214. $my_item_id = $oItem->get_id();
  215. $oItem->set_lp_view($this->lp_view_id, $course_db);
  216. $oItem->set_prevent_reinit($this->prevent_reinit);
  217. // Don't use reference here as the next loop will make the pointed object change.
  218. $this->items[$my_item_id] = $oItem;
  219. $this->refs_list[$oItem->ref] = $my_item_id;
  220. if ($this->debug > 2) {
  221. error_log('New LP - learnpath::__construct() - aicc object with id ' . $my_item_id . ' set in items[]', 0);
  222. }
  223. }
  224. break;
  225. case 2:
  226. require_once 'scorm.class.php';
  227. require_once 'scormItem.class.php';
  228. $oItem = new scormItem('db', $row['id'], $course_db);
  229. if (is_object($oItem)) {
  230. $my_item_id = $oItem->get_id();
  231. $oItem->set_lp_view($this->lp_view_id, $course_db);
  232. $oItem->set_prevent_reinit($this->prevent_reinit);
  233. // Don't use reference here as the next loop will make the pointed object change.
  234. error_log('my_item_id->'.$my_item_id);
  235. $this->items[$my_item_id] = $oItem;
  236. $this->refs_list[$oItem->ref] = $my_item_id;
  237. if ($this->debug > 2) {
  238. error_log('New LP - object with id ' . $my_item_id . ' set in items[]', 0);
  239. }
  240. }
  241. break;
  242. case 1:
  243. default:
  244. require_once 'learnpathItem.class.php';
  245. $oItem = new learnpathItem($row['id'], $user_id, $course_db);
  246. if (is_object($oItem)) {
  247. $my_item_id = $oItem->get_id();
  248. //$oItem->set_lp_view($this->lp_view_id); // Moved down to when we are sure the item_view exists.
  249. $oItem->set_prevent_reinit($this->prevent_reinit);
  250. // Don't use reference here as the next loop will make the pointed object change.
  251. $this->items[$my_item_id] = $oItem;
  252. $this->refs_list[$my_item_id] = $my_item_id;
  253. if ($this->debug > 2) {
  254. error_log('New LP - learnpath::__construct() ' . __LINE__ . ' - object with id ' . $my_item_id . ' set in items[]', 0);
  255. }
  256. }
  257. break;
  258. }
  259. // Items is a list of pointers to all items, classified by DB ID, not SCO id.
  260. if ($row['parent_item_id'] == 0 || empty ($this->items[$row['parent_item_id']])) {
  261. if (is_object($this->items[$row['id']])) {
  262. $this->items[$row['id']]->set_level(0);
  263. }
  264. } else {
  265. $level = $this->items[$row['parent_item_id']]->get_level() + 1;
  266. $this->items[$row['id']]->set_level($level);
  267. if (is_object($this->items[$row['parent_item_id']])) {
  268. // Items is a list of pointers from item DB ids to item objects.
  269. $this->items[$row['parent_item_id']]->add_child($row['id']);
  270. } else {
  271. if ($this->debug > 2) {
  272. error_log('New LP - learnpath::__construct() ' . __LINE__ . ' - The parent item (' . $row['parent_item_id'] . ') of item ' . $row['id'] . ' could not be found', 0);
  273. }
  274. }
  275. }
  276. // Get last viewing vars.
  277. $lp_item_view_table = Database :: get_course_table(TABLE_LP_ITEM_VIEW, $course_db);
  278. // This query should only return one or zero result.
  279. $sql = "SELECT * " .
  280. "FROM $lp_item_view_table " .
  281. "WHERE lp_view_id = " . $this->lp_view_id . " " .
  282. "AND lp_item_id = " . $row['id'] . " ORDER BY view_count DESC ";
  283. if ($this->debug > 2) {
  284. error_log('New LP - learnpath::__construct() - Selecting item_views: ' . $sql, 0);
  285. }
  286. // Get the item status.
  287. $res2 = Database::query($sql);
  288. if (Database :: num_rows($res2) > 0) {
  289. // If this learnpath has already been used by this user, get his last attempt count and
  290. // the last item seen back into this object.
  291. //$max = 0;
  292. $row2 = Database :: fetch_array($res2);
  293. if ($this->debug > 2) {
  294. error_log('New LP - learnpath::__construct() - Got item_view: ' . print_r($row2, true), 0);
  295. }
  296. if (is_object($this->items[$row['id']])) {
  297. $this->items[$row['id']]->set_status($row2['status']);
  298. if (empty ($row2['status'])) {
  299. $this->items[$row['id']]->set_status($this->default_status);
  300. }
  301. }
  302. //$this->attempt = $row['view_count'];
  303. //$this->last_item = $row['id'];
  304. } else { // No item has been found in lp_item_view for this view.
  305. // The first attempt of this user. Set attempt to 1 and last_item to 0 (first item available).
  306. // TODO: If the learnpath has not got attempts activated, always use attempt '1'.
  307. //$this->attempt = 1;
  308. //$this->last_item = 0;
  309. if (is_object($this->items[$row['id']])) {
  310. $this->items[$row['id']]->set_status($this->default_status);
  311. }
  312. // Add that row to the lp_item_view table so that we have something to show in the stats page.
  313. $sql_ins = "INSERT INTO $lp_item_view_table " .
  314. "(lp_item_id, lp_view_id, view_count, status) VALUES " .
  315. "(" . $row['id'] . "," . $this->lp_view_id . ",1,'not attempted')";
  316. if ($this->debug > 2) {
  317. error_log('New LP - learnpath::__construct() ' . __LINE__ . ' - Inserting blank item_view : ' . $sql_ins, 0);
  318. }
  319. $res_ins = Database::query($sql_ins);
  320. }
  321. // Setting the view in the item object.
  322. if (is_object($this->items[$row['id']])) {
  323. $this->items[$row['id']]->set_lp_view($this->lp_view_id, $course_db);
  324. }
  325. }
  326. $this->ordered_items = $this->get_flat_ordered_items_list($this->get_id(), 0, $course_db);
  327. $this->max_ordered_items = 0;
  328. foreach ($this->ordered_items as $index => $dummy) {
  329. if ($index > $this->max_ordered_items && !empty($dummy)) {
  330. $this->max_ordered_items = $index;
  331. }
  332. }
  333. // TODO: Define the current item better.
  334. $this->first();
  335. if ($this->debug > 2) {
  336. error_log('New LP - learnpath::__construct() ' . __LINE__ . ' - End of learnpath constructor for learnpath ' . $this->get_id(), 0);
  337. }
  338. }
  339. /**
  340. * 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
  341. * I found it better to rewrite it. Old function is still available. Added also the possibility to add a description.
  342. *
  343. * @param int $parent
  344. * @param int $previous
  345. * @param string $type
  346. * @param int resource ID (ref)
  347. * @param string $title
  348. * @param string $description
  349. * @return int
  350. */
  351. public function add_item($parent, $previous, $type = 'dokeos_chapter', $id, $title, $description, $prerequisites = 0, $max_time_allowed = 0) {
  352. if ($this->debug > 0) {
  353. error_log('New LP - In learnpath::add_item(' . $parent . ',' . $previous . ',' . $type . ',' . $id . ',' . $title . ')', 0);
  354. }
  355. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  356. $parent = intval($parent);
  357. $previous = intval($previous);
  358. $type = $this->escape_string($type);
  359. $id = intval($id);
  360. $max_time_allowed = $this->escape_string(htmlentities($max_time_allowed));
  361. if (empty ($max_time_allowed)) {
  362. $max_time_allowed = 0;
  363. }
  364. $title = $this->escape_string($title);
  365. $description = $this->escape_string($description);
  366. $sql_count = " SELECT COUNT(id) AS num
  367. FROM " . $tbl_lp_item . "
  368. WHERE lp_id = " . $this->get_id() . " AND parent_item_id = " . $parent;
  369. $res_count = Database::query($sql_count);
  370. $row = Database :: fetch_array($res_count);
  371. $num = $row['num'];
  372. if ($num > 0) {
  373. if ($previous == 0) {
  374. $sql = "SELECT id, next_item_id, display_order
  375. FROM " . $tbl_lp_item . "
  376. WHERE
  377. lp_id = " . $this->get_id() . " AND
  378. parent_item_id = " . $parent . " AND
  379. previous_item_id = 0 OR previous_item_id=" . $parent;
  380. $result = Database::query($sql);
  381. $row = Database :: fetch_array($result);
  382. $tmp_previous = 0;
  383. $next = $row['id'];
  384. $display_order = 0;
  385. } else {
  386. $previous = (int) $previous;
  387. $sql = "
  388. SELECT
  389. id,
  390. previous_item_id,
  391. next_item_id,
  392. display_order
  393. FROM " . $tbl_lp_item . "
  394. WHERE
  395. lp_id = " . $this->get_id() . " AND
  396. id = " . $previous;
  397. $result = Database::query($sql);
  398. $row = Database :: fetch_array($result);
  399. $tmp_previous = $row['id'];
  400. $next = $row['next_item_id'];
  401. $display_order = $row['display_order'];
  402. }
  403. } else {
  404. $tmp_previous = 0;
  405. $next = 0;
  406. $display_order = 0;
  407. }
  408. $new_item_id = -1;
  409. $id = $this->escape_string($id);
  410. if ($type == 'quiz') {
  411. $sql = 'SELECT SUM(ponderation)
  412. FROM ' . Database :: get_course_table(TABLE_QUIZ_QUESTION) . ' as quiz_question
  413. INNER JOIN ' . Database :: get_course_table(TABLE_QUIZ_TEST_QUESTION) . ' as quiz_rel_question
  414. ON quiz_question.id = quiz_rel_question.question_id
  415. AND quiz_rel_question.exercice_id = ' . $id;
  416. $rsQuiz = Database::query($sql);
  417. $max_score = Database :: result($rsQuiz, 0, 0);
  418. } else {
  419. $max_score = 100;
  420. }
  421. if ($prerequisites != 0) {
  422. $sql_ins = "
  423. INSERT INTO " . $tbl_lp_item . " ( ".
  424. "lp_id, ".
  425. "item_type, ".
  426. "ref, ".
  427. "title, ".
  428. "description, ".
  429. "path, ".
  430. "max_score, ".
  431. "parent_item_id, ".
  432. "previous_item_id, ".
  433. "next_item_id, ".
  434. "display_order, ".
  435. "prerequisite, ".
  436. "max_time_allowed ".
  437. ") VALUES ( ".
  438. $this->get_id() . ", ".
  439. "'" . $type . "', ".
  440. "'', ".
  441. "'" . $title . "', ".
  442. "'" . $description . "', ".
  443. "'" . $id . "', ".
  444. "'" . $max_score . "', ".
  445. $parent . ", ".
  446. $previous . ", ".
  447. $next . ", ".
  448. ($display_order +1) . ", ".
  449. $prerequisites . ", ".
  450. $max_time_allowed .
  451. ")";
  452. } else {
  453. // Insert new item.
  454. $sql_ins = "
  455. INSERT INTO " . $tbl_lp_item . " ( ".
  456. "lp_id, ".
  457. "item_type, ".
  458. "ref, ".
  459. "title, ".
  460. "description, ".
  461. "path, ".
  462. "max_score, ".
  463. "parent_item_id, ".
  464. "previous_item_id, ".
  465. "next_item_id, ".
  466. "display_order, ".
  467. "max_time_allowed ".
  468. ") VALUES (".
  469. $this->get_id() . ",".
  470. "'" . $type . "',".
  471. "'',".
  472. "'" . $title . "',".
  473. "'" . $description . "',".
  474. "'" . $id . "',".
  475. "'" . $max_score . "',".
  476. $parent . ",".
  477. $previous . ",".
  478. $next . ",".
  479. ($display_order +1) . ",".
  480. $max_time_allowed .
  481. ")";
  482. }
  483. if ($this->debug > 2) {
  484. error_log('New LP - Inserting dokeos_chapter: ' . $sql_ins, 0);
  485. }
  486. $res_ins = Database::query($sql_ins);
  487. if ($res_ins > 0) {
  488. $new_item_id = Database :: insert_id($res_ins);
  489. // Update the item that should come after the new item.
  490. $sql_update_next = "
  491. UPDATE " . $tbl_lp_item . "
  492. SET previous_item_id = " . $new_item_id . "
  493. WHERE id = " . $next;
  494. $res_update_next = Database::query($sql_update_next);
  495. // Update the item that should be before the new item.
  496. $sql_update_previous = "
  497. UPDATE " . $tbl_lp_item . "
  498. SET next_item_id = " . $new_item_id . "
  499. WHERE id = " . $tmp_previous;
  500. $res_update_previous = Database::query($sql_update_previous);
  501. // Update all the items after the new item.
  502. $sql_update_order = "
  503. UPDATE " . $tbl_lp_item . "
  504. SET display_order = display_order + 1
  505. WHERE
  506. lp_id = " . $this->get_id() . " AND
  507. id <> " . $new_item_id . " AND
  508. parent_item_id = " . $parent . " AND
  509. display_order > " . $display_order;
  510. $res_update_previous = Database::query($sql_update_order);
  511. // Update the item that should come after the new item.
  512. $sql_update_ref = "
  513. UPDATE " . $tbl_lp_item . "
  514. SET ref = " . $new_item_id . "
  515. WHERE id = " . $new_item_id;
  516. Database::query($sql_update_ref);
  517. }
  518. // Upload audio.
  519. if (!empty ($_FILES['mp3']['name'])) {
  520. // Create the audio folder if it does not exist yet.
  521. global $_course;
  522. $filepath = api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document/';
  523. if (!is_dir($filepath . 'audio')) {
  524. mkdir($filepath . 'audio', api_get_permissions_for_new_directories());
  525. $audio_id = add_document($_course, '/audio', 'folder', 0, 'audio');
  526. api_item_property_update($_course, TOOL_DOCUMENT, $audio_id, 'FolderCreated', api_get_user_id(), null, null, null, null, api_get_session_id());
  527. }
  528. // Upload the file in the documents tool.
  529. include_once api_get_path(LIBRARY_PATH).'fileUpload.lib.php';
  530. $file_path = handle_uploaded_document($_course, $_FILES['mp3'], api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document', '/audio', api_get_user_id(), '', '', '', '', '', false);
  531. // Getting the filename only.
  532. $file_components = explode('/', $file_path);
  533. $file = $file_components[count($file_components) - 1];
  534. // Store the mp3 file in the lp_item table.
  535. $sql_insert_audio = "UPDATE $tbl_lp_item SET audio = '" . Database :: escape_string($file) . "' WHERE id = '" . Database :: escape_string($new_item_id) . "'";
  536. Database::query($sql_insert_audio);
  537. }
  538. return $new_item_id;
  539. }
  540. /**
  541. * Static admin function allowing addition of a learnpath to a course.
  542. * @param string Course code
  543. * @param string Learnpath name
  544. * @param string Learnpath description string, if provided
  545. * @param string Type of learnpath (default = 'guess', others = 'dokeos', 'aicc',...)
  546. * @param string Type of files origin (default = 'zip', others = 'dir','web_dir',...)
  547. * @param string Zip file containing the learnpath or directory containing the learnpath
  548. * @return integer The new learnpath ID on success, 0 on failure
  549. */
  550. public function add_lp($course, $name, $description = '', $learnpath = 'guess', $origin = 'zip', $zipname = '', $publicated_on = '', $expired_on = '') {
  551. global $charset;
  552. //if ($this->debug > 0) { error_log('New LP - In learnpath::add_lp()', 0); }
  553. $tbl_lp = Database :: get_course_table(TABLE_LP_MAIN);
  554. // Check course code exists.
  555. // Check lp_name doesn't exist, otherwise append something.
  556. $i = 0;
  557. $name = learnpath :: escape_string($name);
  558. // Session id.
  559. $session_id = api_get_session_id();
  560. $check_name = "SELECT * FROM $tbl_lp WHERE name = '$name'";
  561. //if ($this->debug > 2) { error_log('New LP - Checking the name for new LP: '.$check_name, 0); }
  562. $res_name = Database::query($check_name);
  563. if ($publicated_on == '0000-00-00 00:00:00' || empty($publicated_on)) {
  564. //by default the publication date is the same that the creation date
  565. $publicated_on = api_get_utc_datetime();
  566. } else {
  567. $publicated_on = Database::escape_string(api_get_utc_datetime($publicated_on));
  568. }
  569. if ($expired_on == '0000-00-00 00:00:00' || empty($expired_on)) {
  570. $expired_on = '';
  571. } else {
  572. $expired_on = Database::escape_string(api_get_utc_datetime($expired_on));
  573. }
  574. while (Database :: num_rows($res_name)) {
  575. // There is already one such name, update the current one a bit.
  576. $i++;
  577. $name = $name . ' - ' . $i;
  578. $check_name = "SELECT * FROM $tbl_lp WHERE name = '$name'";
  579. //if ($this->debug > 2) { error_log('New LP - Checking the name for new LP: '.$check_name, 0); }
  580. $res_name = Database::query($check_name);
  581. }
  582. // New name does not exist yet; keep it.
  583. // Escape description.
  584. $description = learnpath :: escape_string(api_htmlentities($description, ENT_QUOTES, $charset)); // Kevin: added htmlentities().
  585. $type = 1;
  586. switch ($learnpath) {
  587. case 'guess':
  588. break;
  589. case 'dokeos':
  590. case 'chamilo':
  591. $type = 1;
  592. break;
  593. case 'aicc':
  594. break;
  595. }
  596. switch ($origin) {
  597. case 'zip':
  598. // Check zipname string. If empty, we are currently creating a new Chamilo learnpath.
  599. break;
  600. case 'manual':
  601. default:
  602. $get_max = "SELECT MAX(display_order) FROM $tbl_lp";
  603. $res_max = Database::query($get_max);
  604. if (Database :: num_rows($res_max) < 1) {
  605. $dsp = 1;
  606. } else {
  607. $row = Database :: fetch_array($res_max);
  608. $dsp = $row[0] + 1;
  609. }
  610. $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) " .
  611. "VALUES ($type,'$name','$description','','embedded','UTF-8','$dsp','Chamilo','local','','".$session_id."', '".api_get_utc_datetime()."' , '".$publicated_on."' , '".$expired_on."')";
  612. //if ($this->debug > 2) { error_log('New LP - Inserting new lp '.$sql_insert, 0); }
  613. $res_insert = Database::query($sql_insert);
  614. $id = Database :: insert_id();
  615. if ($id > 0) {
  616. // Insert into item_property.
  617. api_item_property_update(api_get_course_info(), TOOL_LEARNPATH, $id, 'LearnpathAdded', api_get_user_id());
  618. return $id;
  619. }
  620. break;
  621. }
  622. }
  623. /**
  624. * Appends a message to the message attribute
  625. * @param string Message to append.
  626. */
  627. public function append_message($string) {
  628. if ($this->debug > 0) {
  629. error_log('New LP - In learnpath::append_message()', 0);
  630. }
  631. $this->message .= $string;
  632. }
  633. /**
  634. * Autocompletes the parents of an item in case it's been completed or passed
  635. * @param integer Optional ID of the item from which to look for parents
  636. */
  637. public function autocomplete_parents($item) {
  638. if ($this->debug > 0) {
  639. error_log('New LP - In learnpath::autocomplete_parents()', 0);
  640. }
  641. if (empty ($item)) {
  642. $item = $this->current;
  643. }
  644. $parent_id = $this->items[$item]->get_parent();
  645. if ($this->debug > 2) {
  646. error_log('New LP - autocompleting parent of item ' . $item . ' (item ' . $parent_id . ')', 0);
  647. }
  648. if (is_object($this->items[$item]) and !empty ($parent_id)) {
  649. // if $item points to an object and there is a parent.
  650. if ($this->debug > 2) {
  651. error_log('New LP - ' . $item . ' is an item, proceed', 0);
  652. }
  653. $current_item = & $this->items[$item];
  654. $parent = & $this->items[$parent_id]; // Get the parent.
  655. // New experiment including failed and browsed in completed status.
  656. $current_status = $current_item->get_status();
  657. if ($current_item->is_done() || $current_status == 'browsed' || $current_status == 'failed') {
  658. // If the current item is completed or passes or succeeded.
  659. $completed = true;
  660. if ($this->debug > 2) {
  661. error_log('New LP - Status of current item is alright', 0);
  662. }
  663. foreach ($parent->get_children() as $child) {
  664. // Check all his brothers (his parent's children) for completion status.
  665. if ($child != $item) {
  666. if ($this->debug > 2) {
  667. error_log('New LP - Looking at brother with ID ' . $child . ', status is ' . $this->items[$child]->get_status(), 0);
  668. }
  669. //if($this->items[$child]->status_is(array('completed','passed','succeeded')))
  670. // Trying completing parents of failed and browsed items as well.
  671. if ($this->items[$child]->status_is(array (
  672. 'completed',
  673. 'passed',
  674. 'succeeded',
  675. 'browsed',
  676. 'failed'
  677. ))) {
  678. // Keep completion status to true.
  679. } else {
  680. if ($this->debug > 2) {
  681. error_log('New LP - Found one incomplete child of ' . $parent_id . ': ' . $child . ' is ' . $this->items[$child]->get_status(), 0);
  682. }
  683. $completed = false;
  684. }
  685. }
  686. }
  687. if ($completed) { // If all the children were completed:
  688. $parent->set_status('completed');
  689. $parent->save(false, $this->prerequisites_match($parent->get_id()));
  690. $this->update_queue[$parent->get_id()] = $parent->get_status();
  691. if ($this->debug > 2) {
  692. error_log('New LP - Added parent to update queue ' . print_r($this->update_queue, true), 0);
  693. }
  694. $this->autocomplete_parents($parent->get_id()); // Recursive call.
  695. }
  696. } else {
  697. //error_log('New LP - status of current item is not enough to get bothered with it', 0);
  698. }
  699. }
  700. }
  701. /**
  702. * Autosaves the current results into the database for the whole learnpath
  703. */
  704. public function autosave() {
  705. if ($this->debug > 0) {
  706. error_log('New LP - In learnpath::autosave()', 0);
  707. }
  708. // TODO: Add save operations for the learnpath itself.
  709. }
  710. /**
  711. * Clears the message attribute
  712. */
  713. public function clear_message() {
  714. if ($this->debug > 0) {
  715. error_log('New LP - In learnpath::clear_message()', 0);
  716. }
  717. $this->message = '';
  718. }
  719. /**
  720. * Closes the current resource
  721. *
  722. * Stops the timer
  723. * Saves into the database if required
  724. * Clears the current resource data from this object
  725. * @return boolean True on success, false on failure
  726. */
  727. public function close() {
  728. if ($this->debug > 0) {
  729. error_log('New LP - In learnpath::close()', 0);
  730. }
  731. if (empty ($this->lp_id)) {
  732. $this->error = 'Trying to close this learnpath but no ID is set';
  733. return false;
  734. }
  735. $this->current_time_stop = time();
  736. if ($this->save) {
  737. $learnpath_view_table = Database :: get_course_table(TABLE_LP_VIEW);
  738. /*
  739. $sql = "UPDATE $learnpath_view_table " .
  740. "SET " .
  741. "stop_time = ".$this->current_time_stop.", " .
  742. "score = ".$this->current_score.", ".
  743. "WHERE learnpath_id = '".$this->lp_id."'";
  744. //$res = Database::query($sql);
  745. $res = Database::query($res);
  746. if (Database::affected_rows($res) < 1) {
  747. $this->error = 'Could not update learnpath_view table while closing learnpath';
  748. return false;
  749. }
  750. */
  751. }
  752. $this->ordered_items = array ();
  753. $this->index = 0;
  754. unset ($this->lp_id);
  755. //unset other stuff
  756. return true;
  757. }
  758. /**
  759. * Static admin function allowing removal of a learnpath
  760. * @param string Course code
  761. * @param integer Learnpath ID
  762. * @param string Whether to delete data or keep it (default: 'keep', others: 'remove')
  763. * @return boolean True on success, false on failure (might change that to return number of elements deleted)
  764. */
  765. public function delete($course = null, $id = null, $delete = 'keep') {
  766. // TODO: Implement a way of getting this to work when the current object is not set.
  767. // In clear: implement this in the item class as well (abstract class) and use the given ID in queries.
  768. //if (empty($course)) { $course = api_get_course_id(); }
  769. //if (empty($id)) { $id = $this->get_id(); }
  770. // If an ID is specifically given and the current LP is not the same, prevent delete.
  771. if (!empty ($id) && ($id != $this->lp_id)) {
  772. return false;
  773. }
  774. $lp = Database :: get_course_table(TABLE_LP_MAIN);
  775. $lp_item = Database :: get_course_table(TABLE_LP_ITEM); // Proposed by Christophe (clefevre), see below.
  776. $lp_view = Database :: get_course_table(TABLE_LP_VIEW);
  777. $lp_item_view = Database :: get_course_table(TABLE_LP_ITEM_VIEW);
  778. //if ($this->debug > 0) { error_log('New LP - In learnpath::delete()', 0); }
  779. // Delete lp item id.
  780. foreach ($this->items as $id => $dummy) {
  781. //$this->items[$id]->delete();
  782. $sql_del_view = "DELETE FROM $lp_item_view WHERE lp_item_id = '" . $id . "'";
  783. $res_del_item_view = Database::query($sql_del_view);
  784. }
  785. // Proposed by Christophe (nickname: clefevre), see http://www.dokeos.com/forum/viewtopic.php?t=29673
  786. $sql_del_item = "DELETE FROM $lp_item WHERE lp_id = " . $this->lp_id;
  787. $res_del_item = Database::query($sql_del_item);
  788. $sql_del_view = "DELETE FROM $lp_view WHERE lp_id = " . $this->lp_id;
  789. //if ($this->debug > 2) { error_log('New LP - Deleting views bound to lp '.$this->lp_id.': '.$sql_del_view, 0); }
  790. $res_del_view = Database::query($sql_del_view);
  791. $this->toggle_publish($this->lp_id, 'i');
  792. //if ($this->debug > 2) { error_log('New LP - Deleting lp '.$this->lp_id.' of type '.$this->type, 0); }
  793. if ($this->type == 2 || $this->type == 3) {
  794. // This is a scorm learning path, delete the files as well.
  795. $sql = "SELECT path FROM $lp WHERE id = " . $this->lp_id;
  796. $res = Database::query($sql);
  797. if (Database :: num_rows($res) > 0) {
  798. $row = Database :: fetch_array($res);
  799. $path = $row['path'];
  800. $sql = "SELECT id FROM $lp WHERE path = '$path' AND id != " . $this->lp_id;
  801. $res = Database::query($sql);
  802. if (Database :: num_rows($res) > 0) { // Another learning path uses this directory, so don't delete it.
  803. if ($this->debug > 2) {
  804. error_log('New LP - In learnpath::delete(), found other LP using path ' . $path . ', keeping directory', 0);
  805. }
  806. } else {
  807. // No other LP uses that directory, delete it.
  808. $course_rel_dir = api_get_course_path() . '/scorm/'; // scorm dir web path starting from /courses
  809. $course_scorm_dir = api_get_path(SYS_COURSE_PATH) . $course_rel_dir; // The absolute system path for this course.
  810. if ($delete == 'remove' && is_dir($course_scorm_dir . $path) and !empty ($course_scorm_dir)) {
  811. if ($this->debug > 2) {
  812. error_log('New LP - In learnpath::delete(), found SCORM, deleting directory: ' . $course_scorm_dir . $path, 0);
  813. }
  814. // Proposed by Christophe (clefevre).
  815. if (strcmp(substr($path, -2), "/.") == 0) {
  816. $path = substr($path, 0, -1); // Remove "." at the end.
  817. }
  818. //exec('rm -rf ' . $course_scorm_dir . $path); // See Bug #5208, this is not OS-portable way.
  819. rmdirr($course_scorm_dir . $path);
  820. }
  821. }
  822. }
  823. }
  824. $sql_del_lp = "DELETE FROM $lp WHERE id = " . $this->lp_id;
  825. //if ($this->debug > 2) { error_log('New LP - Deleting lp '.$this->lp_id.': '.$sql_del_lp, 0); }
  826. $res_del_lp = Database::query($sql_del_lp);
  827. $this->update_display_order(); // Updates the display order of all lps.
  828. api_item_property_update(api_get_course_info(), TOOL_LEARNPATH, $this->lp_id, 'delete', api_get_user_id());
  829. require_once '../gradebook/lib/be.inc.php';
  830. $tbl_grade_link = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_LINK);
  831. // Delete link of gradebook tool.
  832. $sql = 'SELECT gl.id FROM ' . $tbl_grade_link . ' gl WHERE gl.type="4" AND gl.ref_id="' . $id . '";';
  833. $result = Database::query($sql);
  834. $row = Database :: fetch_array($result, 'ASSOC');
  835. // Fixing gradebook link deleted see #5229.
  836. if (!empty($row['id'])) {
  837. $link = LinkFactory :: load($row['id']);
  838. if ($link[0] != null) {
  839. $link[0]->delete();
  840. }
  841. }
  842. if (api_get_setting('search_enabled') == 'true') {
  843. require_once api_get_path(LIBRARY_PATH).'specific_fields_manager.lib.php';
  844. $r = delete_all_values_for_item($this->cc, TOOL_LEARNPATH, $this->lp_id);
  845. }
  846. }
  847. /**
  848. * Removes all the children of one item - dangerous!
  849. * @param integer Element ID of which children have to be removed
  850. * @return integer Total number of children removed
  851. */
  852. public function delete_children_items($id) {
  853. if ($this->debug > 0) {
  854. error_log('New LP - In learnpath::delete_children_items(' . $id . ')', 0);
  855. }
  856. $num = 0;
  857. if (empty ($id) || $id != strval(intval($id))) {
  858. return false;
  859. }
  860. $lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  861. $sql = "SELECT * FROM $lp_item WHERE parent_item_id = $id";
  862. $res = Database::query($sql);
  863. while ($row = Database :: fetch_array($res)) {
  864. $num += $this->delete_children_items($row['id']);
  865. $sql_del = "DELETE FROM $lp_item WHERE id = " . $row['id'];
  866. $res_del = Database::query($sql_del);
  867. $num++;
  868. }
  869. return $num;
  870. }
  871. /**
  872. * Removes an item from the current learnpath
  873. * @param integer Elem ID (0 if first)
  874. * @param integer Whether to remove the resource/data from the system or leave it (default: 'keep', others 'remove')
  875. * @return integer Number of elements moved
  876. * @todo implement resource removal
  877. */
  878. public function delete_item($id, $remove = 'keep') {
  879. if ($this->debug > 0) {
  880. error_log('New LP - In learnpath::delete_item()', 0);
  881. }
  882. // TODO: Implement the resource removal.
  883. if (empty ($id) || $id != strval(intval($id))) {
  884. return false;
  885. }
  886. // First select item to get previous, next, and display order.
  887. $lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  888. $sql_sel = "SELECT * FROM $lp_item WHERE id = $id";
  889. $res_sel = Database::query($sql_sel);
  890. if (Database :: num_rows($res_sel) < 1) {
  891. return false;
  892. }
  893. $row = Database :: fetch_array($res_sel);
  894. $previous = $row['previous_item_id'];
  895. $next = $row['next_item_id'];
  896. $display = $row['display_order'];
  897. $parent = $row['parent_item_id'];
  898. $lp = $row['lp_id'];
  899. // Delete children items.
  900. $num = $this->delete_children_items($id);
  901. if ($this->debug > 2) {
  902. error_log('New LP - learnpath::delete_item() - deleted ' . $num . ' children of element ' . $id, 0);
  903. }
  904. // Now delete the item.
  905. $sql_del = "DELETE FROM $lp_item WHERE id = $id";
  906. if ($this->debug > 2) {
  907. error_log('New LP - Deleting item: ' . $sql_del, 0);
  908. }
  909. $res_del = Database::query($sql_del);
  910. // Now update surrounding items.
  911. $sql_upd = "UPDATE $lp_item SET next_item_id = $next WHERE id = $previous";
  912. $res_upd = Database::query($sql_upd);
  913. $sql_upd = "UPDATE $lp_item SET previous_item_id = $previous WHERE id = $next";
  914. $res_upd = Database::query($sql_upd);
  915. // Now update all following items with new display order.
  916. $sql_all = "UPDATE $lp_item SET display_order = display_order-1 WHERE lp_id = $lp AND parent_item_id = $parent AND display_order > $display";
  917. $res_all = Database::query($sql_all);
  918. //Removing prerequisites since the item will not longer exist
  919. $sql_all = "UPDATE $lp_item SET prerequisite = '' WHERE prerequisite = $id";
  920. $res_all = Database::query($sql_all);
  921. // Remove from search engine if enabled.
  922. if (api_get_setting('search_enabled') == 'true') {
  923. $tbl_se_ref = Database :: get_main_table(TABLE_MAIN_SEARCH_ENGINE_REF);
  924. $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';
  925. $sql = sprintf($sql, $tbl_se_ref, $this->cc, TOOL_LEARNPATH, $lp, $id);
  926. $res = Database::query($sql);
  927. if (Database :: num_rows($res) > 0) {
  928. $row2 = Database :: fetch_array($res);
  929. require_once api_get_path(LIBRARY_PATH).'search/DokeosIndexer.class.php';
  930. $di = new DokeosIndexer();
  931. $di->remove_document((int) $row2['search_did']);
  932. }
  933. $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';
  934. $sql = sprintf($sql, $tbl_se_ref, $this->cc, TOOL_LEARNPATH, $lp, $id);
  935. Database::query($sql);
  936. }
  937. }
  938. /**
  939. * Updates an item's content in place
  940. * @param integer Element ID
  941. * @param integer Parent item ID
  942. * @param integer Previous item ID
  943. * @param string Item title
  944. * @param string Item description
  945. * @param string Prerequisites (optional)
  946. * @param string Indexing terms (optional)
  947. * @param array The array resulting of the $_FILES[mp3] element
  948. * @return boolean True on success, false on error
  949. */
  950. public function edit_item($id, $parent, $previous, $title, $description, $prerequisites = 0, $audio = null, $max_time_allowed = 0) {
  951. if ($this->debug > 0) {
  952. error_log('New LP - In learnpath::edit_item()', 0);
  953. }
  954. if (empty ($max_time_allowed)) {
  955. $max_time_allowed = 0;
  956. }
  957. if (empty ($id) || ($id != strval(intval($id))) || empty ($title)) {
  958. return false;
  959. }
  960. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  961. $sql_select = "SELECT * FROM " . $tbl_lp_item . " WHERE id = " . $id;
  962. $res_select = Database::query($sql_select);
  963. $row_select = Database :: fetch_array($res_select);
  964. $audio_update_sql = '';
  965. if (is_array($audio) && !empty ($audio['tmp_name']) && $audio['error'] === 0) {
  966. // Create the audio folder if it does not exist yet.
  967. global $_course;
  968. $filepath = api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document/';
  969. if (!is_dir($filepath . 'audio')) {
  970. mkdir($filepath . 'audio', api_get_permissions_for_new_directories());
  971. $audio_id = add_document($_course, '/audio', 'folder', 0, 'audio');
  972. api_item_property_update($_course, TOOL_DOCUMENT, $audio_id, 'FolderCreated', api_get_user_id(), null, null, null, null, api_get_session_id());
  973. }
  974. // Upload file in documents.
  975. $pi = pathinfo($audio['name']);
  976. if ($pi['extension'] == 'mp3') {
  977. $c_det = api_get_course_info($this->cc);
  978. $bp = api_get_path(SYS_COURSE_PATH) . $c_det['path'] . '/document';
  979. $path = handle_uploaded_document($c_det, $audio, $bp, '/audio', api_get_user_id(), 0, null, '', 0, 'rename', false, 0);
  980. $path = substr($path, 7);
  981. // Update reference in lp_item - audio path is the path from inside de document/audio/ dir.
  982. $audio_update_sql = ", audio = '" . Database :: escape_string($path) . "' ";
  983. }
  984. }
  985. $same_parent = ($row_select['parent_item_id'] == $parent) ? true : false;
  986. $same_previous = ($row_select['previous_item_id'] == $previous) ? true : false;
  987. // TODO: htmlspecialchars to be checked for encoding related problems.
  988. if ($same_parent && $same_previous) {
  989. // Only update title and description.
  990. $sql_update = " UPDATE " . $tbl_lp_item . "
  991. SET title = '" . $this->escape_string($title) . "',
  992. prerequisite = '" . $prerequisites . "',
  993. description = '" . $this->escape_string($description) . "'
  994. " . $audio_update_sql . ",
  995. max_time_allowed = '" . $this->escape_string($max_time_allowed) . "'
  996. WHERE id = " . $id;
  997. $res_update = Database::query($sql_update);
  998. } else {
  999. $old_parent = $row_select['parent_item_id'];
  1000. $old_previous = $row_select['previous_item_id'];
  1001. $old_next = $row_select['next_item_id'];
  1002. $old_order = $row_select['display_order'];
  1003. $old_prerequisite = $row_select['prerequisite'];
  1004. $old_max_time_allowed = $row_select['max_time_allowed'];
  1005. /* BEGIN -- virtually remove the current item id */
  1006. /* for the next and previous item it is like the current item doesn't exist anymore */
  1007. if ($old_previous != 0) {
  1008. $sql_update_next = "
  1009. UPDATE " . $tbl_lp_item . "
  1010. SET next_item_id = " . $old_next . "
  1011. WHERE id = " . $old_previous;
  1012. $res_update_next = Database::query($sql_update_next);
  1013. //echo '<p>' . $sql_update_next . '</p>';
  1014. }
  1015. if ($old_next != 0) {
  1016. $sql_update_previous = "
  1017. UPDATE " . $tbl_lp_item . "
  1018. SET previous_item_id = " . $old_previous . "
  1019. WHERE id = " . $old_next;
  1020. $res_update_previous = Database::query($sql_update_previous);
  1021. //echo '<p>' . $sql_update_previous . '</p>';
  1022. }
  1023. // display_order - 1 for every item with a display_order bigger then the display_order of the current item.
  1024. $sql_update_order = "
  1025. UPDATE " . $tbl_lp_item . "
  1026. SET display_order = display_order - 1
  1027. WHERE
  1028. display_order > " . $old_order . " AND lp_id = " . $this->lp_id . " AND
  1029. parent_item_id = " . $old_parent;
  1030. $res_update_order = Database::query($sql_update_order);
  1031. //echo '<p>' . $sql_update_order . '</p>';
  1032. /* END -- virtually remove the current item id */
  1033. /* BEGIN -- update the current item id to his new location */
  1034. if ($previous == 0) {
  1035. // Select the data of the item that should come after the current item.
  1036. $sql_select_old = "
  1037. SELECT
  1038. id,
  1039. display_order
  1040. FROM " . $tbl_lp_item . "
  1041. WHERE
  1042. lp_id = " . $this->lp_id . " AND
  1043. parent_item_id = " . $parent . " AND
  1044. previous_item_id = " . $previous;
  1045. $res_select_old = Database::query($sql_select_old);
  1046. $row_select_old = Database :: fetch_array($res_select_old);
  1047. //echo '<p>' . $sql_select_old . '</p>';
  1048. // If the new parent didn't have children before.
  1049. if (Database :: num_rows($res_select_old) == 0) {
  1050. $new_next = 0;
  1051. $new_order = 1;
  1052. } else {
  1053. $new_next = $row_select_old['id'];
  1054. $new_order = $row_select_old['display_order'];
  1055. }
  1056. //echo 'New next_item_id of current item: ' . $new_next . '<br />';
  1057. //echo 'New previous_item_id of current item: ' . $previous . '<br />';
  1058. //echo 'New display_order of current item: ' . $new_order . '<br />';
  1059. } else {
  1060. // Select the data of the item that should come before the current item.
  1061. $sql_select_old = "
  1062. SELECT
  1063. next_item_id,
  1064. display_order
  1065. FROM " . $tbl_lp_item . "
  1066. WHERE id = " . $previous;
  1067. $res_select_old = Database::query($sql_select_old);
  1068. $row_select_old = Database :: fetch_array($res_select_old);
  1069. //echo '<p>' . $sql_select_old . '</p>';
  1070. //echo 'New next_item_id of current item: ' . $row_select_old['next_item_id'] . '<br />';
  1071. //echo 'New previous_item_id of current item: ' . $previous . '<br />';
  1072. //echo 'New display_order of current item: ' . ($row_select_old['display_order'] + 1) . '<br />';
  1073. $new_next = $row_select_old['next_item_id'];
  1074. $new_order = $row_select_old['display_order'] + 1;
  1075. }
  1076. // TODO: htmlspecialchars to be checked for encoding related problems.
  1077. // Update the current item with the new data.
  1078. $sql_update = "
  1079. UPDATE " . $tbl_lp_item . "
  1080. SET
  1081. title = '" . $this->escape_string($title) . "',
  1082. description = '" . $this->escape_string($description) . "',
  1083. parent_item_id = " . $parent . ",
  1084. previous_item_id = " . $previous . ",
  1085. next_item_id = " . $new_next . ",
  1086. display_order = " . $new_order . "
  1087. " . $audio_update_sql . "
  1088. WHERE id = " . $id;
  1089. $res_update_next = Database::query($sql_update);
  1090. //echo '<p>' . $sql_update . '</p>';
  1091. if ($previous != 0) {
  1092. // Update the previous item's next_item_id.
  1093. $sql_update_previous = "
  1094. UPDATE " . $tbl_lp_item . "
  1095. SET next_item_id = " . $id . "
  1096. WHERE id = " . $previous;
  1097. $res_update_next = Database::query($sql_update_previous);
  1098. //echo '<p>' . $sql_update_previous . '</p>';
  1099. }
  1100. if ($new_next != 0) {
  1101. // Update the next item's previous_item_id.
  1102. $sql_update_next = "
  1103. UPDATE " . $tbl_lp_item . "
  1104. SET previous_item_id = " . $id . "
  1105. WHERE id = " . $new_next;
  1106. $res_update_next = Database::query($sql_update_next);
  1107. //echo '<p>' . $sql_update_next . '</p>';
  1108. }
  1109. if ($old_prerequisite != $prerequisites) {
  1110. $sql_update_next = "
  1111. UPDATE " . $tbl_lp_item . "
  1112. SET prerequisite = " . $prerequisites . "
  1113. WHERE id = " . $id;
  1114. $res_update_next = Database::query($sql_update_next);
  1115. }
  1116. if ($old_max_time_allowed != $max_time_allowed) {
  1117. $sql_update_max_time_allowed = "
  1118. UPDATE " . $tbl_lp_item . "
  1119. SET max_time_allowed = " . $max_time_allowed . "
  1120. WHERE id = " . $id;
  1121. $res_update_max_time_allowed = Database::query($sql_update_max_time_allowed);
  1122. }
  1123. // Update all the items with the same or a bigger display_order than the current item.
  1124. $sql_update_order = "
  1125. UPDATE " . $tbl_lp_item . "
  1126. SET display_order = display_order + 1
  1127. WHERE
  1128. lp_id = " . $this->get_id() . " AND
  1129. id <> " . $id . " AND
  1130. parent_item_id = " . $parent . " AND
  1131. display_order >= " . $new_order;
  1132. $res_update_next = Database::query($sql_update_order);
  1133. }
  1134. }
  1135. /**
  1136. * Updates an item's prereq in place
  1137. * @param integer Element ID
  1138. * @param string Prerequisite Element ID
  1139. * @param string Prerequisite item type
  1140. * @param string Prerequisite min score
  1141. * @param string Prerequisite max score
  1142. * @return boolean True on success, false on error
  1143. */
  1144. public function edit_item_prereq($id, $prerequisite_id, $mastery_score = 0, $max_score = 100) {
  1145. if ($this->debug > 0) {
  1146. error_log('New LP - In learnpath::edit_item_prereq(' . $id . ',' . $prerequisite_id . ',' . $mastery_score . ',' . $max_score . ')', 0);
  1147. }
  1148. if (empty ($id) or ($id != strval(intval($id))) or empty ($prerequisite_id)) {
  1149. return false;
  1150. }
  1151. $prerequisite_id = $this->escape_string($prerequisite_id);
  1152. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  1153. if (!is_numeric($mastery_score) || $mastery_score < 0)
  1154. $mastery_score = 0;
  1155. if (!is_numeric($max_score) || $max_score < 0)
  1156. $max_score = 100;
  1157. if ($mastery_score > $max_score)
  1158. $max_score = $mastery_score;
  1159. if (!is_numeric($prerequisite_id))
  1160. $prerequisite_id = 'NULL';
  1161. $sql_upd = " UPDATE " . $tbl_lp_item . "
  1162. SET prerequisite = " . $prerequisite_id . " WHERE id = " . $id;
  1163. $res_upd = Database::query($sql_upd);
  1164. if ($prerequisite_id != 'NULL' && $prerequisite_id != '') {
  1165. $sql_upd = " UPDATE " . $tbl_lp_item . " SET
  1166. mastery_score = " . $mastery_score .
  1167. //", max_score = " . $max_score . " " . // Max score cannot be changed in the form anyway - see display_item_prerequisites_form().
  1168. " WHERE ref = '" . $prerequisite_id . "'"; // Will this be enough to ensure unicity?
  1169. $res_upd = Database::query($sql_upd);
  1170. }
  1171. // TODO: Update the item object (can be ignored for now because refreshed).
  1172. return true;
  1173. }
  1174. /**
  1175. * Escapes a string with the available database escape function
  1176. * @param string String to escape
  1177. * @return string String escaped
  1178. */
  1179. public function escape_string($string) {
  1180. //if ($this->debug > 0) { error_log('New LP - In learnpath::escape_string('.$string.')', 0); }
  1181. return Database :: escape_string($string);
  1182. }
  1183. /**
  1184. * Static admin function exporting a learnpath into a zip file
  1185. * @param string Export type (scorm, zip, cd)
  1186. * @param string Course code
  1187. * @param integer Learnpath ID
  1188. * @param string Zip file name
  1189. * @return string Zip file path (or false on error)
  1190. */
  1191. public function export_lp($type, $course, $id, $zipname) {
  1192. //if ($this->debug > 0) { error_log('New LP - In learnpath::export_lp()', 0); }
  1193. if (empty($type) || empty($course) || empty($id) || empty($zipname)) {
  1194. return false;
  1195. }
  1196. $url = '';
  1197. switch ($type) {
  1198. case 'scorm':
  1199. break;
  1200. case 'zip':
  1201. break;
  1202. case 'cdrom':
  1203. break;
  1204. }
  1205. return $url;
  1206. }
  1207. /**
  1208. * Gets all the chapters belonging to the same parent as the item/chapter given
  1209. * Can also be called as abstract method
  1210. * @param integer Item ID
  1211. * @return array A list of all the "brother items" (or an empty array on failure)
  1212. */
  1213. public function get_brother_chapters($id) {
  1214. if ($this->debug > 0) {
  1215. error_log('New LP - In learnpath::get_brother_chapters()', 0);
  1216. }
  1217. if (empty ($id) OR $id != strval(intval($id))) {
  1218. return array ();
  1219. }
  1220. $lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  1221. $sql_parent = "SELECT * FROM $lp_item WHERE id = $id AND item_type='dokeos_chapter'";
  1222. $res_parent = Database::query($sql_parent);
  1223. if (Database :: num_rows($res_parent) > 0) {
  1224. $row_parent = Database :: fetch_array($res_parent);
  1225. $parent = $row_parent['parent_item_id'];
  1226. $sql_bros = "SELECT * FROM $lp_item WHERE parent_item_id = $parent AND id = $id AND item_type='dokeos_chapter' ORDER BY display_order";
  1227. $res_bros = Database::query($sql_bros);
  1228. $list = array ();
  1229. while ($row_bro = Database :: fetch_array($res_bros)) {
  1230. $list[] = $row_bro;
  1231. }
  1232. return $list;
  1233. }
  1234. return array ();
  1235. }
  1236. /**
  1237. * Gets all the items belonging to the same parent as the item given
  1238. * Can also be called as abstract method
  1239. * @param integer Item ID
  1240. * @return array A list of all the "brother items" (or an empty array on failure)
  1241. */
  1242. public function get_brother_items($id) {
  1243. if ($this->debug > 0) {
  1244. error_log('New LP - In learnpath::get_brother_items(' . $id . ')', 0);
  1245. }
  1246. if (empty ($id) OR $id != strval(intval($id))) {
  1247. return array ();
  1248. }
  1249. $lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  1250. $sql_parent = "SELECT * FROM $lp_item WHERE id = $id";
  1251. $res_parent = Database::query($sql_parent);
  1252. if (Database :: num_rows($res_parent) > 0) {
  1253. $row_parent = Database :: fetch_array($res_parent);
  1254. $parent = $row_parent['parent_item_id'];
  1255. $sql_bros = "SELECT * FROM $lp_item WHERE parent_item_id = $parent ORDER BY display_order";
  1256. $res_bros = Database::query($sql_bros);
  1257. $list = array ();
  1258. while ($row_bro = Database :: fetch_array($res_bros)) {
  1259. $list[] = $row_bro;
  1260. }
  1261. return $list;
  1262. }
  1263. return array ();
  1264. }
  1265. /**
  1266. * Get the specific prefix index terms of this learning path
  1267. * @return array Array of terms
  1268. */
  1269. public function get_common_index_terms_by_prefix($prefix) {
  1270. require_once api_get_path(LIBRARY_PATH).'specific_fields_manager.lib.php';
  1271. $terms = get_specific_field_values_list_by_prefix($prefix, $this->cc, TOOL_LEARNPATH, $this->lp_id);
  1272. $prefix_terms = array();
  1273. if (!empty($terms)) {
  1274. foreach ($terms as $term) {
  1275. $prefix_terms[] = $term['value'];
  1276. }
  1277. }
  1278. return $prefix_terms;
  1279. }
  1280. /**
  1281. * Gets the number of items currently completed
  1282. * @return integer The number of items currently completed
  1283. */
  1284. public function get_complete_items_count() {
  1285. if ($this->debug > 0) {
  1286. error_log('New LP - In learnpath::get_complete_items_count()', 0);
  1287. }
  1288. $i = 0;
  1289. foreach ($this->items as $id => $dummy) {
  1290. // Trying failed and browsed considered "progressed" as well.
  1291. if ($this->items[$id]->status_is(array (
  1292. 'completed',
  1293. 'passed',
  1294. 'succeeded',
  1295. 'browsed',
  1296. 'failed'
  1297. )) && $this->items[$id]->get_type() != 'dokeos_chapter' && $this->items[$id]->get_type() != 'dir') {
  1298. $i++;
  1299. }
  1300. }
  1301. return $i;
  1302. }
  1303. /**
  1304. * Gets the current item ID
  1305. * @return integer The current learnpath item id
  1306. */
  1307. public function get_current_item_id() {
  1308. $current = 0;
  1309. if ($this->debug > 0) {
  1310. error_log('New LP - In learnpath::get_current_item_id()', 0);
  1311. }
  1312. if (!empty ($this->current)) {
  1313. $current = $this->current;
  1314. }
  1315. if ($this->debug > 2) {
  1316. error_log('New LP - In learnpath::get_current_item_id() - Returning ' . $current, 0);
  1317. }
  1318. return $current;
  1319. }
  1320. /**
  1321. * Force to get the first learnpath item id
  1322. * @return integer The current learnpath item id
  1323. */
  1324. public function get_first_item_id() {
  1325. $current = 0;
  1326. if (is_array($this->ordered_items)) {
  1327. $current = $this->ordered_items[0];
  1328. }
  1329. return $current;
  1330. }
  1331. /**
  1332. * Gets the total number of items available for viewing in this SCORM
  1333. * @return integer The total number of items
  1334. */
  1335. public function get_total_items_count() {
  1336. if ($this->debug > 0) {
  1337. error_log('New LP - In learnpath::get_total_items_count()', 0);
  1338. }
  1339. return count($this->items);
  1340. }
  1341. /**
  1342. * Gets the total number of items available for viewing in this SCORM but without chapters
  1343. * @return integer The total no-chapters number of items
  1344. */
  1345. public function get_total_items_count_without_chapters() {
  1346. if ($this->debug > 0) {
  1347. error_log('New LP - In learnpath::get_total_items_count_without_chapters()', 0);
  1348. }
  1349. $total = 0;
  1350. foreach ($this->items as $temp => $temp2) {
  1351. if (!in_array($temp2->get_type(), array (
  1352. 'dokeos_chapter',
  1353. 'chapter',
  1354. 'dir'
  1355. )))
  1356. $total++;
  1357. }
  1358. return $total;
  1359. }
  1360. /**
  1361. * Gets the first element URL.
  1362. * @return string URL to load into the viewer
  1363. */
  1364. public function first() {
  1365. if ($this->debug > 0) {
  1366. error_log('New LP - In learnpath::first()', 0);
  1367. }
  1368. // Test if the last_item_seen exists and is not a dir.
  1369. if (count($this->ordered_items) == 0) {
  1370. $this->index = 0;
  1371. }
  1372. 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()) {
  1373. if ($this->debug > 2) {
  1374. 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);
  1375. }
  1376. $index = -1;
  1377. foreach ($this->ordered_items as $myindex => $item_id) {
  1378. if ($item_id == $this->last_item_seen) {
  1379. $index = $myindex;
  1380. break;
  1381. }
  1382. }
  1383. if ($index == -1) {
  1384. // Index hasn't changed, so item not found - panic (this shouldn't happen).
  1385. if ($this->debug > 2) {
  1386. error_log('New LP - Last item (' . $this->last_item_seen . ') was found in items but not in ordered_items, panic!', 0);
  1387. }
  1388. return false;
  1389. } else {
  1390. $this->last = $this->last_item_seen;
  1391. $this->current = $this->last_item_seen;
  1392. $this->index = $index;
  1393. }
  1394. } else {
  1395. if ($this->debug > 2) {
  1396. error_log('New LP - In learnpath::first() - No last item seen', 0);
  1397. }
  1398. $index = 0;
  1399. // Loop through all ordered items and stop at the first item that is
  1400. // not a directory *and* that has not been completed yet.
  1401. 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) {
  1402. $index++;
  1403. }
  1404. $this->last = $this->current;
  1405. // current is
  1406. $this->current = $this->ordered_items[$index];
  1407. $this->index = $index;
  1408. if ($this->debug > 2) {
  1409. error_log('New LP - In learnpath::first() - No last item seen. New last = ' . $this->last . '(' . $this->ordered_items[$index] . ')', 0);
  1410. }
  1411. }
  1412. if ($this->debug > 2) {
  1413. error_log('New LP - In learnpath::first() - First item is ' . $this->get_current_item_id());
  1414. }
  1415. }
  1416. /**
  1417. * Gets the information about an item in a format usable as JavaScript to update
  1418. * the JS API by just printing this content into the <head> section of the message frame
  1419. * @param integer Item ID
  1420. * @return string
  1421. */
  1422. public function get_js_info($item_id = '') {
  1423. if ($this->debug > 0) {
  1424. error_log('New LP - In learnpath::get_js_info(' . $item_id . ')', 0);
  1425. }
  1426. $info = '';
  1427. $item_id = $this->escape_string($item_id);
  1428. if (!empty($item_id) && is_object($this->items[$item_id])) {
  1429. //if item is defined, return values from DB
  1430. $oItem = $this->items[$item_id];
  1431. $info .= '<script language="javascript">';
  1432. $info .= "top.set_score(" . $oItem->get_score() . ");\n";
  1433. $info .= "top.set_max(" . $oItem->get_max() . ");\n";
  1434. $info .= "top.set_min(" . $oItem->get_min() . ");\n";
  1435. $info .= "top.set_lesson_status('" . $oItem->get_status() . "');";
  1436. $info .= "top.set_session_time('" . $oItem->get_scorm_time('js') . "');";
  1437. $info .= "top.set_suspend_data('" . $oItem->get_suspend_data() . "');";
  1438. $info .= "top.set_saved_lesson_status('" . $oItem->get_status() . "');";
  1439. $info .= "top.set_flag_synchronized();";
  1440. $info .= '</script>';
  1441. if ($this->debug > 2) {
  1442. error_log('New LP - in learnpath::get_js_info(' . $item_id . ') - returning: ' . $info, 0);
  1443. }
  1444. return $info;
  1445. } else {
  1446. // If item_id is empty, just update to default SCORM data.
  1447. $info .= '<script language="javascript">';
  1448. $info .= "top.set_score(" . learnpathItem :: get_score() . ");\n";
  1449. $info .= "top.set_max(" . learnpathItem :: get_max() . ");\n";
  1450. $info .= "top.set_min(" . learnpathItem :: get_min() . ");\n";
  1451. $info .= "top.set_lesson_status('" . learnpathItem :: get_status() . "');";
  1452. $info .= "top.set_session_time('" . learnpathItem :: get_scorm_time('js') . "');";
  1453. $info .= "top.set_suspend_data('" . learnpathItem :: get_suspend_data() . "');";
  1454. $info .= "top.set_saved_lesson_status('" . learnpathItem :: get_status() . "');";
  1455. $info .= "top.set_flag_synchronized();";
  1456. $info .= '</script>';
  1457. if ($this->debug > 2) {
  1458. error_log('New LP - in learnpath::get_js_info(' . $item_id . ') - returning: ' . $info, 0);
  1459. }
  1460. return $info;
  1461. }
  1462. }
  1463. /**
  1464. * Gets the js library from the database
  1465. * @return string The name of the javascript library to be used
  1466. */
  1467. public function get_js_lib() {
  1468. $lib = '';
  1469. if (!empty ($this->js_lib)) {
  1470. $lib = $this->js_lib;
  1471. }
  1472. return $lib;
  1473. }
  1474. /**
  1475. * Gets the learnpath database ID
  1476. * @return integer Learnpath ID in the lp table
  1477. */
  1478. public function get_id() {
  1479. //if ($this->debug > 0) { error_log('New LP - In learnpath::get_id()', 0); }
  1480. if (!empty ($this->lp_id)) {
  1481. return $this->lp_id;
  1482. } else {
  1483. return 0;
  1484. }
  1485. }
  1486. /**
  1487. * Gets the last element URL.
  1488. * @return string URL to load into the viewer
  1489. */
  1490. public function get_last() {
  1491. if ($this->debug > 0) {
  1492. error_log('New LP - In learnpath::get_last()', 0);
  1493. }
  1494. $this->index = count($this->ordered_items) - 1;
  1495. return $this->ordered_items[$this->index];
  1496. }
  1497. /**
  1498. * Gets the navigation bar for the learnpath display screen
  1499. * @return string The HTML string to use as a navigation bar
  1500. */
  1501. public function get_navigation_bar() {
  1502. if ($this->debug > 0) {
  1503. error_log('New LP - In learnpath::get_navigation_bar()', 0);
  1504. }
  1505. // TODO: Find a good value for the following variables.
  1506. $file = '';
  1507. $openDir = '';
  1508. $edoceo = '';
  1509. $time = 0;
  1510. $navbar = '';
  1511. $RequestUri = '';
  1512. $mycurrentitemid = $this->get_current_item_id();
  1513. if ($this->mode == 'fullscreen') {
  1514. $navbar = '<table cellpadding="0" cellspacing="0" align="left">' . "\n" .
  1515. ' <tr> ' . "\n" .
  1516. ' <td>' . "\n" .
  1517. ' <div class="buttons">' . "\n" .
  1518. ' <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" .
  1519. ' <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" .
  1520. ' <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" .
  1521. //' <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" .
  1522. //' <a href="lp_controller.php?action=list" target="_top" title="learnpaths list"><img border="0" src="../img/exit.png" title="Exit"></a>'."\n" .
  1523. ' </div>' . "\n" .
  1524. ' </td>' . "\n" .
  1525. ' </tr>' . "\n" .
  1526. '</table>' . "\n";
  1527. } else {
  1528. $navbar = '<table cellpadding="0" cellspacing="0" align="left">' . "\n" .
  1529. ' <tr> ' . "\n" .
  1530. ' <td>' . "\n" .
  1531. ' <div class="buttons">' . "\n" .
  1532. ' <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" .
  1533. ' <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" .
  1534. ' <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" .
  1535. // ' <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" .
  1536. ' </div>' . "\n" .
  1537. ' </td>' . "\n" .
  1538. ' </tr>' . "\n" .
  1539. '</table>' . "\n";
  1540. }
  1541. return $navbar;
  1542. }
  1543. /**
  1544. * Gets the next resource in queue (url).
  1545. * @return string URL to load into the viewer
  1546. */
  1547. public function get_next_index() {
  1548. if ($this->debug > 0) {
  1549. error_log('New LP - In learnpath::get_next_index()', 0);
  1550. }
  1551. // TODO
  1552. $index = $this->index;
  1553. $index++;
  1554. if ($this->debug > 2) {
  1555. error_log('New LP - Now looking at ordered_items[' . ($index) . '] - type is ' . $this->items[$this->ordered_items[$index]]->type, 0);
  1556. }
  1557. 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) {
  1558. $index++;
  1559. if ($index == $this->max_ordered_items){
  1560. if ($this->items[$this->ordered_items[$index]]->get_type() == 'dir' || $this->items[$this->ordered_items[$index]]->get_type() == 'dokeos_chapter') {
  1561. return $this->index;
  1562. } else {
  1563. return $index;
  1564. }
  1565. }
  1566. }
  1567. if (empty ($this->ordered_items[$index])) {
  1568. return $this->index;
  1569. }
  1570. if ($this->debug > 2) {
  1571. error_log('New LP - index is now ' . $index, 0);
  1572. }
  1573. return $index;
  1574. }
  1575. /**
  1576. * Gets item_id for the next element
  1577. * @return integer Next item (DB) ID
  1578. */
  1579. public function get_next_item_id() {
  1580. if ($this->debug > 0) {
  1581. error_log('New LP - In learnpath::get_next_item_id()', 0);
  1582. }
  1583. $new_index = $this->get_next_index();
  1584. if (!empty ($new_index)) {
  1585. if (isset ($this->ordered_items[$new_index])) {
  1586. if ($this->debug > 2) {
  1587. error_log('New LP - In learnpath::get_next_index() - Returning ' . $this->ordered_items[$new_index], 0);
  1588. }
  1589. return $this->ordered_items[$new_index];
  1590. }
  1591. }
  1592. if ($this->debug > 2) {
  1593. error_log('New LP - In learnpath::get_next_index() - Problem - Returning 0', 0);
  1594. }
  1595. return 0;
  1596. }
  1597. /**
  1598. * Returns the package type ('scorm','aicc','scorm2004','dokeos','ppt'...)
  1599. *
  1600. * Generally, the package provided is in the form of a zip file, so the function
  1601. * has been written to test a zip file. If not a zip, the function will return the
  1602. * default return value: ''
  1603. * @param string the path to the file
  1604. * @param string the original name of the file
  1605. * @return string 'scorm','aicc','scorm2004','dokeos' or '' if the package cannot be recognized
  1606. */
  1607. public function get_package_type($file_path, $file_name) {
  1608. // Get name of the zip file without the extension.
  1609. $file_info = pathinfo($file_name);
  1610. $filename = $file_info['basename']; // Name including extension.
  1611. $extension = $file_info['extension']; // Extension only.
  1612. if (!empty($_POST['ppt2lp']) && !in_array(strtolower($extension), array (
  1613. 'dll',
  1614. 'exe'
  1615. ))) {
  1616. return 'oogie';
  1617. }
  1618. if (!empty($_POST['woogie']) && !in_array(strtolower($extension), array (
  1619. 'dll',
  1620. 'exe'
  1621. ))) {
  1622. return 'woogie';
  1623. }
  1624. $file_base_name = str_replace('.' . $extension, '', $filename); // Filename without its extension.
  1625. $zipFile = new pclZip($file_path);
  1626. // Check the zip content (real size and file extension).
  1627. $zipContentArray = $zipFile->listContent();
  1628. $package_type = '';
  1629. $at_root = false;
  1630. $manifest = '';
  1631. // The following loop should be stopped as soon as we found the right imsmanifest.xml (how to recognize it?).
  1632. if (is_array($zipContentArray) && count($zipContentArray) > 0) {
  1633. foreach ($zipContentArray as $thisContent) {
  1634. if (preg_match('~.(php.*|phtml)$~i', $thisContent['filename'])) {
  1635. // New behaviour: Don't do anything. These files will be removed in scorm::import_package.
  1636. }
  1637. elseif (stristr($thisContent['filename'], 'imsmanifest.xml') !== false) {
  1638. $manifest = $thisContent['filename']; // Just the relative directory inside scorm/
  1639. $package_type = 'scorm';
  1640. break; // Exit the foreach loop.
  1641. }
  1642. elseif (preg_match('/aicc\//i', $thisContent['filename'])) {
  1643. // If found an aicc directory... (!= false means it cannot be false (error) or 0 (no match)).
  1644. $package_type = 'aicc';
  1645. //break; // Don't exit the loop, because if we find an imsmanifest afterwards, we want it, not the AICC.
  1646. } else {
  1647. $package_type = '';
  1648. }
  1649. }
  1650. }
  1651. return $package_type;
  1652. }
  1653. /**
  1654. * Gets the previous resource in queue (url). Also initialises time values for this viewing
  1655. * @return string URL to load into the viewer
  1656. */
  1657. public function get_previous_index() {
  1658. if ($this->debug > 0) {
  1659. error_log('New LP - In learnpath::get_previous_index()', 0);
  1660. }
  1661. $index = $this->index;
  1662. if (isset ($this->ordered_items[$index -1])) {
  1663. $index--;
  1664. 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')) {
  1665. $index--;
  1666. if ($index < 0) {
  1667. return $this->index;
  1668. }
  1669. }
  1670. } else {
  1671. if ($this->debug > 2) {
  1672. error_log('New LP - get_previous_index() - there was no previous index available, reusing ' . $index, 0);
  1673. }
  1674. // There is no previous item.
  1675. }
  1676. return $index;
  1677. }
  1678. /**
  1679. * Gets item_id for the next element
  1680. * @return integer Previous item (DB) ID
  1681. */
  1682. public function get_previous_item_id() {
  1683. if ($this->debug > 0) {
  1684. error_log('New LP - In learnpath::get_previous_item_id()', 0);
  1685. }
  1686. $new_index = $this->get_previous_index();
  1687. return $this->ordered_items[$new_index];
  1688. }
  1689. /**
  1690. * Gets the progress value from the progress_db attribute
  1691. * @return integer Current progress value
  1692. */
  1693. public function get_progress() {
  1694. if ($this->debug > 0) {
  1695. error_log('New LP - In learnpath::get_progress()', 0);
  1696. }
  1697. if (!empty ($this->progress_db)) {
  1698. return $this->progress_db;
  1699. }
  1700. return 0;
  1701. }
  1702. /**
  1703. * Gets the progress value from the progress field in the database (allows use as abstract method)
  1704. * @param integer Learnpath ID
  1705. * @param integer User ID
  1706. * @param string Mode of display ('%','abs' or 'both')
  1707. * @param string Course database name (optional, defaults to '')
  1708. * @param boolean Whether to return null if no record was found (true), or 0 (false) (optional, defaults to false)
  1709. * @return integer Current progress value as found in the database
  1710. */
  1711. public function get_db_progress($lp_id, $user_id, $mode = '%', $course_db = '', $sincere = false,$session_id = 0) {
  1712. //if ($this->debug > 0) { error_log('New LP - In learnpath::get_db_progress()', 0); }
  1713. $session_id = intval($session_id);
  1714. $session_condition = api_get_session_condition($session_id);
  1715. $table = Database :: get_course_table(TABLE_LP_VIEW, $course_db);
  1716. $sql = "SELECT * FROM $table WHERE lp_id = $lp_id AND user_id = $user_id $session_condition";
  1717. $res = Database::query($sql);
  1718. $view_id = 0;
  1719. if (Database :: num_rows($res) > 0) {
  1720. $row = Database :: fetch_array($res);
  1721. $progress = $row['progress'];
  1722. $view_id = $row['id'];
  1723. } else {
  1724. if ($sincere) {
  1725. return null;
  1726. }
  1727. }
  1728. if (empty ($progress)) {
  1729. $progress = '0';
  1730. }
  1731. if ($mode == '%') {
  1732. return $progress . '%';
  1733. } else {
  1734. // Get the number of items completed and the number of items total.
  1735. $tbl = Database :: get_course_table(TABLE_LP_ITEM, $course_db);
  1736. $sql = "SELECT count(*) FROM $tbl WHERE lp_id = " . $lp_id . "
  1737. AND item_type NOT IN('dokeos_chapter','chapter','dir')";
  1738. $res = Database::query($sql);
  1739. $row = Database :: fetch_array($res);
  1740. $total = $row[0];
  1741. $tbl_item_view = Database :: get_course_table(TABLE_LP_ITEM_VIEW, $course_db);
  1742. $tbl_item = Database :: get_course_table(TABLE_LP_ITEM, $course_db);
  1743. //$sql = "SELECT count(distinct(lp_item_id)) FROM $tbl WHERE lp_view_id = ".$view_id." AND status IN ('passed','completed','succeeded')";
  1744. // Trying as also counting browsed and failed items.
  1745. $sql = "SELECT count(distinct(lp_item_id))
  1746. FROM $tbl_item_view as item_view
  1747. INNER JOIN $tbl_item as item
  1748. ON item.id = item_view.lp_item_id
  1749. AND item_type NOT IN('dokeos_chapter','chapter','dir')
  1750. WHERE lp_view_id = " . $view_id . "
  1751. AND status IN ('passed','completed','succeeded','browsed','failed')"; //echo '<br />';
  1752. $res = Database::query($sql);
  1753. $row = Database :: fetch_array($res);
  1754. $completed = $row[0];
  1755. if ($mode == 'abs') {
  1756. return $completed . '/' . $total;
  1757. }
  1758. elseif ($mode == 'both') {
  1759. if ($progress < ($completed / ($total ? $total : 1))) {
  1760. $progress = number_format(($completed / ($total ? $total : 1)) * 100, 0);
  1761. }
  1762. return $progress . '% (' . $completed . '/' . $total . ')';
  1763. }
  1764. }
  1765. return $progress;
  1766. }
  1767. /**
  1768. * Returns the HTML necessary to print a mediaplayer block inside a page
  1769. * @return string The mediaplayer HTML
  1770. */
  1771. public function get_mediaplayer($autostart='true') {
  1772. global $_course;
  1773. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  1774. $tbl_lp_item_view = Database :: get_course_table(TABLE_LP_ITEM_VIEW);
  1775. // Getting all the information about the item.
  1776. $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 " .
  1777. "WHERE lp.id = '" . $_SESSION['oLP']->current . "'";
  1778. $result = Database::query($sql);
  1779. $row = Database::fetch_assoc($result);
  1780. $output = '';
  1781. if (!empty ($row['audio'])) {
  1782. $list = $_SESSION['oLP']->get_toc();
  1783. $type_quiz = false;
  1784. foreach($list as $toc) {
  1785. if ($toc['id'] == $_SESSION['oLP']->current && ($toc['type']=='quiz') ) {
  1786. $type_quiz = true;
  1787. }
  1788. }
  1789. if ($type_quiz) {
  1790. if ($_SESSION['oLP']->prevent_reinit == 1) {
  1791. $row['status'] === 'completed' ? $autostart_audio = 'false' : $autostart_audio = 'true';
  1792. } else {
  1793. $autostart_audio = $autostart;
  1794. }
  1795. } else {
  1796. $autostart_audio = 'true';
  1797. }
  1798. // The mp3 player.
  1799. $output = '<div id="container">';
  1800. $output .= '<script type="text/javascript" src="../inc/lib/mediaplayer/swfobject.js"></script>';
  1801. $output .= '<script type="text/javascript">
  1802. var s1 = new SWFObject("../inc/lib/mediaplayer/player.swf","ply","250","20","9","#FFFFFF");
  1803. s1.addParam("allowscriptaccess","always");
  1804. s1.addParam("flashvars","file=' . api_get_path(WEB_COURSE_PATH) . $_course['path'] . '/document/audio/' . $row['audio'] . '&autostart=' . $autostart_audio.'");
  1805. s1.write("container");
  1806. </script></div>';
  1807. }
  1808. return $output;
  1809. }
  1810. /**
  1811. * This function checks if the learnpath is visible for student after the progress of its prerequisite is completed, and considering time availability
  1812. * @param int Learnpath id
  1813. * @param int Student id
  1814. * @param string Course code (optional)
  1815. * @return bool True if
  1816. */
  1817. public function is_lp_visible_for_student($lp_id, $student_id, $course = null) {
  1818. $lp_id = (int)$lp_id;
  1819. $course = api_get_course_info($course);
  1820. $tbl_learnpath = Database :: get_course_table(TABLE_LP_MAIN,$course['dbName']);
  1821. // Get current prerequisite
  1822. $sql = "SELECT id, prerequisite, publicated_on, expired_on FROM $tbl_learnpath WHERE id = $lp_id";
  1823. $rs = Database::query($sql);
  1824. if (Database::num_rows($rs)>0) {
  1825. $row = Database::fetch_array($rs);
  1826. $prerequisite = $row['prerequisite'];
  1827. $find = array(' ','-',':');
  1828. $from = str_replace($find,'',api_get_local_time($row['publicated_on']));
  1829. $to = str_replace($find,'',api_get_local_time($row['expired_on']));
  1830. $is_visible = true;
  1831. $progress = 0;
  1832. if (!empty($prerequisite)) {
  1833. $progress = self::get_db_progress($prerequisite,$student_id,'%', '', false, api_get_session_id());
  1834. $progress = intval($progress);
  1835. if ($progress < 100) {
  1836. $is_visible = false;
  1837. }
  1838. }
  1839. // Also check the time availability of the learning path
  1840. if ($is_visible) {
  1841. $now = str_replace($find,'',api_get_local_time());
  1842. if ((($row['publicated_on']!='0000-00-00 00:00:00') && ($now<$from)) or (($row['expired_on']!='0000-00-00 00:00:00') && ($now>$to))) {
  1843. $is_visible = false;
  1844. }
  1845. }
  1846. return $is_visible;
  1847. }
  1848. return false;
  1849. }
  1850. /**
  1851. * Gets a progress bar for the learnpath by counting the number of items in it and the number of items
  1852. * completed so far.
  1853. * @param string Mode in which we want the values
  1854. * @param integer Progress value to display (optional but mandatory if used in abstract context)
  1855. * @param string Text to display near the progress value (optional but mandatory in abstract context)
  1856. * @param boolean true if it comes from a Diplay LP view
  1857. * @return string HTML string containing the progress bar
  1858. */
  1859. public function get_progress_bar($mode = '', $percentage = -1, $text_add = '', $from_lp = false) {
  1860. //if ($this->debug > 0) {error_log('New LP - In learnpath::get_progress_bar('.$mode.','.$percentage.','.$text_add.','.$from_lp.')', 0); }
  1861. global $lp_theme_css;
  1862. // Setting up the CSS path of the current style if exists.
  1863. if (!empty ($lp_theme_css)) {
  1864. $css_path = api_get_path(WEB_CODE_PATH) . 'css/' . $lp_theme_css . '/images/';
  1865. } else {
  1866. $css_path = '../img/';
  1867. }
  1868. //if ($this->debug > 0) { error_log('New LP - In learnpath::get_progress_bar()', 0); }
  1869. if (isset($this) && is_object($this) && ($percentage == '-1' OR $text_add == '')) {
  1870. list($percentage, $text_add) = $this->get_progress_bar_text($mode);
  1871. }
  1872. $text = $percentage . $text_add;
  1873. // Default progress bar config
  1874. // times that will be greater or shorter
  1875. $factor = 1.2;
  1876. if ($from_lp)
  1877. $progress_height = '26';
  1878. else
  1879. $progress_height = '16';
  1880. $size = str_replace('%', '', $percentage);
  1881. $output =
  1882. '<table border="0" cellpadding="0" cellspacing="0"><tr><td>' .
  1883. '<img id="progress_img_limit_left" src="' . $css_path . 'bar_1.gif" width="1" height="' . $progress_height . '">' .
  1884. '<img id="progress_img_full" src="' . $css_path . 'bar_1u.gif" width="' . $size * $factor . 'px" height="' . $progress_height . '" id="full_portion">' .
  1885. '<img id="progress_img_limit_middle" src="' . $css_path . 'bar_1m.gif" width="1" height="' . $progress_height . '">';
  1886. if ($percentage <= 98) {
  1887. $output .= '<img id="progress_img_empty" src="' . $css_path . 'bar_1r.gif" width="' . (100 - $size) * $factor . 'px" height="' . $progress_height . '" id="empty_portion">';
  1888. } else {
  1889. $output .= '<img id="progress_img_empty" src="' . $css_path . 'bar_1r.gif" width="0" height="' . $progress_height . '" id="empty_portion">';
  1890. }
  1891. $output .= '<img id="progress_bar_img_limit_right" src="' . $css_path . 'bar_1.gif" width="1" height="' . $progress_height . '"></td></tr></table>' .
  1892. '<div class="progresstext" id="progress_text">' . $text . '</div>';
  1893. return $output;
  1894. }
  1895. /**
  1896. * Gets the progress bar info to display inside the progress bar. Also used by scorm_api.php
  1897. * @param string Mode of display (can be '%' or 'abs').abs means we display a number of completed elements per total elements
  1898. * @param integer Additional steps to fake as completed
  1899. * @return list Percentage or number and symbol (% or /xx)
  1900. */
  1901. public function get_progress_bar_text($mode = '', $add = 0) {
  1902. if ($this->debug > 0) {
  1903. error_log('New LP - In learnpath::get_progress_bar_text()', 0);
  1904. }
  1905. if (empty ($mode)) {
  1906. $mode = $this->progress_bar_mode;
  1907. }
  1908. $total_items = $this->get_total_items_count_without_chapters();
  1909. if ($this->debug > 2) {
  1910. error_log('New LP - Total items available in this learnpath: ' . $total_items, 0);
  1911. }
  1912. $i = $this->get_complete_items_count();
  1913. if ($this->debug > 2) {
  1914. error_log('New LP - Items completed so far: ' . $i, 0);
  1915. }
  1916. if ($add != 0) {
  1917. $i += $add;
  1918. if ($this->debug > 2) {
  1919. error_log('New LP - Items completed so far (+modifier): ' . $i, 0);
  1920. }
  1921. }
  1922. $text = '';
  1923. if ($i > $total_items) {
  1924. $i = $total_items;
  1925. }
  1926. if ($mode == '%') {
  1927. if ($total_items > 0) {
  1928. $percentage = ((float) $i / (float) $total_items) * 100;
  1929. } else {
  1930. $percentage = 0;
  1931. }
  1932. $percentage = number_format($percentage, 0);
  1933. $text = '%';
  1934. }
  1935. elseif ($mode == 'abs') {
  1936. $percentage = $i;
  1937. $text = '/' . $total_items;
  1938. }
  1939. return array (
  1940. $percentage,
  1941. $text
  1942. );
  1943. }
  1944. /**
  1945. * Gets the progress bar mode
  1946. * @return string The progress bar mode attribute
  1947. */
  1948. public function get_progress_bar_mode() {
  1949. if ($this->debug > 0) {
  1950. error_log('New LP - In learnpath::get_progress_bar_mode()', 0);
  1951. }
  1952. if (!empty ($this->progress_bar_mode)) {
  1953. return $this->progress_bar_mode;
  1954. } else {
  1955. return '%';
  1956. }
  1957. }
  1958. /**
  1959. * Gets the learnpath proximity (remote or local)
  1960. * @return string Learnpath proximity
  1961. */
  1962. public function get_proximity() {
  1963. if ($this->debug > 0) {
  1964. error_log('New LP - In learnpath::get_proximity()', 0);
  1965. }
  1966. if (!empty ($this->proximity)) {
  1967. return $this->proximity;
  1968. } else {
  1969. return '';
  1970. }
  1971. }
  1972. /**
  1973. * Gets the learnpath theme (remote or local)
  1974. * @return string Learnpath theme
  1975. */
  1976. public function get_theme() {
  1977. if ($this->debug > 0) {
  1978. error_log('New LP - In learnpath::get_theme()', 0);
  1979. }
  1980. if (!empty ($this->theme)) {
  1981. return $this->theme;
  1982. } else {
  1983. return '';
  1984. }
  1985. }
  1986. /**
  1987. * Gets the learnpath session id
  1988. * @return string Learnpath theme
  1989. */
  1990. public function get_lp_session_id() {
  1991. if ($this->debug > 0) {
  1992. error_log('New LP - In learnpath::get_lp_session_id()', 0);
  1993. }
  1994. if (!empty ($this->lp_session_id)) {
  1995. return $this->lp_session_id;
  1996. } else {
  1997. return 0;
  1998. }
  1999. }
  2000. /**
  2001. * Gets the learnpath image
  2002. * @return string Web URL of the LP image
  2003. */
  2004. public function get_preview_image() {
  2005. if ($this->debug > 0) {
  2006. error_log('New LP - In learnpath::get_preview_image()', 0);
  2007. }
  2008. if (!empty ($this->preview_image)) {
  2009. return $this->preview_image;
  2010. } else {
  2011. return '';
  2012. }
  2013. }
  2014. /**
  2015. * Gets the learnpath author
  2016. * @return string LP's author
  2017. */
  2018. public function get_author() {
  2019. if ($this->debug > 0) {
  2020. error_log('New LP - In learnpath::get_author()', 0);
  2021. }
  2022. if (!empty ($this->author)) {
  2023. return $this->author;
  2024. } else {
  2025. return '';
  2026. }
  2027. }
  2028. /**
  2029. * Generate a new prerequisites string for a given item. If this item was a sco and
  2030. * its prerequisites were strings (instead of IDs), then transform those strings into
  2031. * IDs, knowing that SCORM IDs are kept in the "ref" field of the lp_item table.
  2032. * Prefix all item IDs that end-up in the prerequisites string by "ITEM_" to use the
  2033. * same rule as the scorm_export() method
  2034. * @param integer Item ID
  2035. * @return string Prerequisites string ready for the export as SCORM
  2036. */
  2037. public function get_scorm_prereq_string($item_id) {
  2038. if ($this->debug > 0) {
  2039. error_log('New LP - In learnpath::get_scorm_prereq_string()', 0);
  2040. }
  2041. if (!is_object($this->items[$item_id])) {
  2042. return false;
  2043. }
  2044. $oItem = $this->items[$item_id];
  2045. $prereq = $oItem->get_prereq_string();
  2046. if (empty ($prereq)) {
  2047. return '';
  2048. }
  2049. 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,
  2050. // then simply return it (with the ITEM_ prefix).
  2051. return 'ITEM_' . $prereq;
  2052. } else {
  2053. if (isset ($this->refs_list[$prereq])) {
  2054. // It's a simple string item from which the ID can be found in the refs list,
  2055. // so we can transform it directly to an ID for export.
  2056. return 'ITEM_' . $this->refs_list[$prereq];
  2057. } else {
  2058. // The last case, if it's a complex form, then find all the IDs (SCORM strings)
  2059. // and replace them, one by one, by the internal IDs (chamilo db)
  2060. // TODO: Modify the '*' replacement to replace the multiplier in front of it
  2061. // by a space as well.
  2062. $find = array (
  2063. '&',
  2064. '|',
  2065. '~',
  2066. '=',
  2067. '<>',
  2068. '{',
  2069. '}',
  2070. '*',
  2071. '(',
  2072. ')'
  2073. );
  2074. $replace = array (
  2075. ' ',
  2076. ' ',
  2077. ' ',
  2078. ' ',
  2079. ' ',
  2080. ' ',
  2081. ' ',
  2082. ' ',
  2083. ' ',
  2084. ' '
  2085. );
  2086. $prereq_mod = str_replace($find, $replace, $prereq);
  2087. $ids = split(' ', $prereq_mod);
  2088. foreach ($ids as $id) {
  2089. $id = trim($id);
  2090. if (isset ($this->refs_list[$id])) {
  2091. $prereq = preg_replace('/[^a-zA-Z_0-9](' . $id . ')[^a-zA-Z_0-9]/', 'ITEM_' . $this->refs_list[$id], $prereq);
  2092. }
  2093. }
  2094. error_log('New LP - In learnpath::get_scorm_prereq_string(): returning modified string: ' . $prereq, 0);
  2095. return $prereq;
  2096. }
  2097. }
  2098. }
  2099. /**
  2100. * Returns the XML DOM document's node
  2101. * @param resource Reference to a list of objects to search for the given ITEM_*
  2102. * @param string The identifier to look for
  2103. * @return mixed The reference to the element found with that identifier. False if not found
  2104. */
  2105. public function get_scorm_xml_node(& $children, $id) {
  2106. for ($i = 0; $i < $children->length; $i++) {
  2107. $item_temp = $children->item($i);
  2108. if ($item_temp->nodeName == 'item') {
  2109. if ($item_temp->getAttribute('identifier') == $id) {
  2110. return $item_temp;
  2111. }
  2112. }
  2113. $subchildren = $item_temp->childNodes;
  2114. if ($subchildren->length > 0) {
  2115. $val = $this->get_scorm_xml_node($subchildren, $id);
  2116. if (is_object($val)) {
  2117. return $val;
  2118. }
  2119. }
  2120. }
  2121. return false;
  2122. }
  2123. /**
  2124. * Returns a usable array of stats related to the current learnpath and user
  2125. * @return array Well-formatted array containing status for the current learnpath
  2126. */
  2127. public function get_stats() {
  2128. if ($this->debug > 0) {
  2129. error_log('New LP - In learnpath::get_stats()', 0);
  2130. }
  2131. // TODO
  2132. }
  2133. /**
  2134. * Static method. Can be re-implemented by children. Gives an array of statistics for
  2135. * the given course (for all learnpaths and all users)
  2136. * @param string Course code
  2137. * @return array Well-formatted array containing status for the course's learnpaths
  2138. */
  2139. public function get_stats_course($course) {
  2140. //if ($this->debug > 0) { error_log('New LP - In learnpath::get_stats_course()', 0); }
  2141. // TODO
  2142. }
  2143. /**
  2144. * Static method. Can be re-implemented by children. Gives an array of statistics for
  2145. * the given course and learnpath (for all users)
  2146. * @param string Course code
  2147. * @param integer Learnpath ID
  2148. * @return array Well-formatted array containing status for the specified learnpath
  2149. */
  2150. public function get_stats_lp($course, $lp) {
  2151. //if ($this->debug > 0) { error_log('New LP - In learnpath::get_stats_lp()', 0); }
  2152. // TODO
  2153. }
  2154. /**
  2155. * Static method. Can be re-implemented by children. Gives an array of statistics for
  2156. * the given course, learnpath and user.
  2157. * @param string Course code
  2158. * @param integer Learnpath ID
  2159. * @param integer User ID
  2160. * @return array Well-formatted array containing status for the specified learnpath and user
  2161. */
  2162. public function get_stats_lp_user($course, $lp, $user) {
  2163. //if ($this->debug > 0) { error_log('New LP - In learnpath::get_stats_lp_user()', 0); }
  2164. // TODO
  2165. }
  2166. /**
  2167. * Static method. Can be re-implemented by children. Gives an array of statistics for
  2168. * the given course and learnpath (for all users)
  2169. * @param string Course code
  2170. * @param integer User ID
  2171. * @return array Well-formatted array containing status for the user's learnpaths
  2172. */
  2173. public function get_stats_user($course, $user) {
  2174. //if ($this->debug > 0) { error_log('New LP - In learnpath::get_stats_user()', 0); }
  2175. // TODO
  2176. }
  2177. /**
  2178. * Gets the status list for all LP's items
  2179. * @return array Array of [index] => [item ID => current status]
  2180. */
  2181. public function get_items_status_list() {
  2182. if ($this->debug > 0) {
  2183. error_log('New LP - In learnpath::get_items_status_list()', 0);
  2184. }
  2185. $list = array ();
  2186. foreach ($this->ordered_items as $item_id) {
  2187. $list[] = array (
  2188. $item_id => $this->items[$item_id]->get_status()
  2189. );
  2190. }
  2191. return $list;
  2192. }
  2193. /**
  2194. * Return the number of interactions for the given learnpath Item View ID.
  2195. * This method can be used as static.
  2196. * @param integer Item View ID
  2197. * @return integer Number of interactions
  2198. */
  2199. public function get_interactions_count_from_db($lp_iv_id = 0) {
  2200. if (empty ($lp_iv_id)) {
  2201. return -1;
  2202. }
  2203. $table = Database :: get_course_table(TABLE_LP_IV_INTERACTION);
  2204. $sql = "SELECT count(*) FROM $table WHERE lp_iv_id = $lp_iv_id";
  2205. $res = Database::query($sql);
  2206. $row = Database :: fetch_array($res);
  2207. $num = $row[0];
  2208. return $num;
  2209. }
  2210. /**
  2211. * Return the interactions as an array for the given lp_iv_id.
  2212. * This method can be used as static.
  2213. * @param integer Learnpath Item View ID
  2214. * @return array
  2215. * @todo Transcode labels instead of switching to HTML (which requires to know the encoding of the LP)
  2216. */
  2217. public function get_iv_interactions_array($lp_iv_id = 0) {
  2218. $list = array ();
  2219. $table = Database :: get_course_table(TABLE_LP_IV_INTERACTION);
  2220. $sql = "SELECT * FROM $table WHERE lp_iv_id = $lp_iv_id ORDER BY order_id ASC";
  2221. $res = Database::query($sql);
  2222. $num = Database :: num_rows($res);
  2223. if ($num > 0) {
  2224. $list[] = array (
  2225. 'order_id' => api_htmlentities(get_lang('Order'), ENT_QUOTES),
  2226. 'id' => api_htmlentities(get_lang('InteractionID'), ENT_QUOTES),
  2227. 'type' => api_htmlentities(get_lang('Type'), ENT_QUOTES),
  2228. 'time' => api_htmlentities(get_lang('TimeFinished'), ENT_QUOTES),
  2229. 'correct_responses' => api_htmlentities(get_lang('CorrectAnswers'), ENT_QUOTES),
  2230. 'student_response' => api_htmlentities(get_lang('StudentResponse'), ENT_QUOTES),
  2231. 'result' => api_htmlentities(get_lang('Result'), ENT_QUOTES),
  2232. 'latency' => api_htmlentities(get_lang('LatencyTimeSpent'), ENT_QUOTES)
  2233. );
  2234. while ($row = Database :: fetch_array($res)) {
  2235. $list[] = array (
  2236. 'order_id' => ($row['order_id'] + 1),
  2237. 'id' => urldecode($row['interaction_id']), //urldecode because they often have %2F or stuff like that
  2238. 'type' => $row['interaction_type'],
  2239. 'time' => $row['completion_time'],
  2240. //'correct_responses' => $row['correct_responses'],
  2241. 'correct_responses' => '', // Hide correct responses from students.
  2242. 'student_response' => $row['student_response'],
  2243. 'result' => $row['result'],
  2244. 'latency' => $row['latency']
  2245. );
  2246. }
  2247. }
  2248. return $list;
  2249. }
  2250. /**
  2251. * Return the number of objectives for the given learnpath Item View ID.
  2252. * This method can be used as static.
  2253. * @param integer Item View ID
  2254. * @return integer Number of objectives
  2255. */
  2256. public function get_objectives_count_from_db($lp_iv_id = 0) {
  2257. if (empty ($lp_iv_id)) {
  2258. return -1;
  2259. }
  2260. $table = Database :: get_course_table(TABLE_LP_IV_OBJECTIVE);
  2261. $sql = "SELECT count(*) FROM $table WHERE lp_iv_id = $lp_iv_id";
  2262. $res = Database::query($sql);
  2263. $row = Database :: fetch_array($res);
  2264. $num = $row[0];
  2265. return $num;
  2266. }
  2267. /**
  2268. * Return the objectives as an array for the given lp_iv_id.
  2269. * This method can be used as static.
  2270. * @param integer Learnpath Item View ID
  2271. * @return array
  2272. * @todo Translate labels
  2273. */
  2274. public function get_iv_objectives_array($lp_iv_id = 0) {
  2275. $list = array();
  2276. $table = Database :: get_course_table(TABLE_LP_IV_OBJECTIVE);
  2277. $sql = "SELECT * FROM $table WHERE lp_iv_id = $lp_iv_id ORDER BY order_id ASC";
  2278. $res = Database::query($sql);
  2279. $num = Database :: num_rows($res);
  2280. if ($num > 0) {
  2281. $list[] = array (
  2282. 'order_id' => api_htmlentities(get_lang('Order'), ENT_QUOTES),
  2283. 'objective_id' => api_htmlentities(get_lang('ObjectiveID'), ENT_QUOTES),
  2284. 'score_raw' => api_htmlentities(get_lang('ObjectiveRawScore'), ENT_QUOTES),
  2285. 'score_max' => api_htmlentities(get_lang('ObjectiveMaxScore'), ENT_QUOTES),
  2286. 'score_min' => api_htmlentities(get_lang('ObjectiveMinScore'), ENT_QUOTES),
  2287. 'status' => api_htmlentities(get_lang('ObjectiveStatus'), ENT_QUOTES)
  2288. );
  2289. while ($row = Database :: fetch_array($res)) {
  2290. $list[] = array (
  2291. 'order_id' => ($row['order_id'] + 1),
  2292. 'objective_id' => urldecode($row['objective_id']), // urldecode() because they often have %2F or stuff like that.
  2293. 'score_raw' => $row['score_raw'],
  2294. 'score_max' => $row['score_max'],
  2295. 'score_min' => $row['score_min'],
  2296. 'status' => $row['status']
  2297. );
  2298. }
  2299. }
  2300. return $list;
  2301. }
  2302. /**
  2303. * Generate and return the table of contents for this learnpath. The (flat) table returned can be
  2304. * used by get_html_toc() to be ready to display
  2305. * @return array TOC as a table with 4 elements per row: title, link, status and level
  2306. */
  2307. public function get_toc() {
  2308. if ($this->debug > 0) {
  2309. error_log('New LP - In learnpath::get_toc()', 0);
  2310. }
  2311. $toc = array ();
  2312. //echo "<pre>".print_r($this->items,true)."</pre>";
  2313. foreach ($this->ordered_items as $item_id) {
  2314. if ($this->debug > 2) {
  2315. error_log('New LP - learnpath::get_toc(): getting info for item ' . $item_id, 0);
  2316. }
  2317. // TODO: Change this link generation and use new function instead.
  2318. $toc[] = array (
  2319. 'id' => $item_id,
  2320. 'title' => $this->items[$item_id]->get_title(),
  2321. //'link' => get_addedresource_link_in_learnpath('document', $item_id, 1),
  2322. 'status' => $this->items[$item_id]->get_status(),
  2323. 'level' => $this->items[$item_id]->get_level(),
  2324. 'type' => $this->items[$item_id]->get_type(),
  2325. 'description' => $this->items[$item_id]->get_description(),
  2326. 'path' => $this->items[$item_id]->get_path(),
  2327. );
  2328. }
  2329. if ($this->debug > 2) {
  2330. error_log('New LP - In learnpath::get_toc() - TOC array: ' . print_r($toc, true), 0);
  2331. }
  2332. return $toc;
  2333. }
  2334. /**
  2335. * Generate and return the table of contents for this learnpath. The JS
  2336. * table returned is used inside of scorm_api.php
  2337. * @return string A JS array vairiable construction
  2338. */
  2339. public function get_items_details_as_js($varname = 'olms.lms_item_types') {
  2340. if ($this->debug > 0) {
  2341. error_log('New LP - In learnpath::get_items_details_as_js()', 0);
  2342. }
  2343. $toc = $varname.' = new Array();';
  2344. //echo "<pre>".print_r($this->items,true)."</pre>";
  2345. foreach ($this->ordered_items as $item_id) {
  2346. if ($this->debug > 2) {
  2347. error_log('New LP - learnpath::get_items_details_as_js(): getting info for item ' . $item_id, 0);
  2348. }
  2349. $toc.= $varname."['i$item_id'] = '".$this->items[$item_id]->get_type()."';";
  2350. }
  2351. if ($this->debug > 2) {
  2352. error_log('New LP - In learnpath::get_items_details_as_js() - TOC array: ' . print_r($toc, true), 0);
  2353. }
  2354. return $toc;
  2355. }
  2356. /**
  2357. * Gets the learning path type
  2358. * @param boolean Return the name? If false, return the ID. Default is false.
  2359. * @return mixed Type ID or name, depending on the parameter
  2360. */
  2361. public function get_type($get_name = false) {
  2362. $res = false;
  2363. if ($this->debug > 0) {
  2364. error_log('New LP - In learnpath::get_type()', 0);
  2365. }
  2366. if (!empty ($this->type)) {
  2367. if ($get_name) {
  2368. // Get it from the lp_type table in main db.
  2369. } else {
  2370. $res = $this->type;
  2371. }
  2372. }
  2373. if ($this->debug > 2) {
  2374. error_log('New LP - In learnpath::get_type() - Returning ' . ($res ? $res : 'false'), 0);
  2375. }
  2376. return $res;
  2377. }
  2378. /**
  2379. * Gets the learning path type as static method
  2380. * @param boolean Return the name? If false, return the ID. Default is false.
  2381. * @return mixed Type ID or name, depending on the parameter
  2382. */
  2383. public function get_type_static($lp_id = 0) {
  2384. $tbl_lp = Database :: get_course_table(TABLE_LP_MAIN);
  2385. $sql = "SELECT lp_type FROM $tbl_lp WHERE id = '" . $lp_id . "'";
  2386. $res = Database::query($sql);
  2387. if ($res === false) {
  2388. return null;
  2389. }
  2390. if (Database :: num_rows($res) <= 0) {
  2391. return null;
  2392. }
  2393. $row = Database :: fetch_array($res);
  2394. return $row['lp_type'];
  2395. }
  2396. /**
  2397. * Gets a flat list of item IDs ordered for display (level by level ordered by order_display)
  2398. * This method can be used as abstract and is recursive
  2399. * @param integer Learnpath ID
  2400. * @param integer Parent ID of the items to look for
  2401. * @return mixed Ordered list of item IDs or false on error
  2402. */
  2403. public function get_flat_ordered_items_list($lp, $parent = 0, $course_db = '') {
  2404. //if ($this->debug > 0) { error_log('New LP - In learnpath::get_flat_ordered_items_list('.$lp.','.$parent.')', 0); }
  2405. $list = array();
  2406. if (empty ($lp)) {
  2407. return false;
  2408. }
  2409. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM, $course_db);
  2410. $sql = "SELECT * FROM $tbl_lp_item WHERE lp_id = $lp AND parent_item_id = $parent ORDER BY display_order";
  2411. $res = Database::query($sql);
  2412. while ($row = Database :: fetch_array($res)) {
  2413. $sublist = learnpath :: get_flat_ordered_items_list($lp, $row['id'], $course_db);
  2414. $list[] = $row['id'];
  2415. foreach ($sublist as $item) {
  2416. $list[] = $item;
  2417. }
  2418. }
  2419. return $list;
  2420. }
  2421. /**
  2422. * Uses the table generated by get_toc() and returns an HTML-formatted string ready to display
  2423. * @return string HTML TOC ready to display
  2424. */
  2425. public function get_html_toc() {
  2426. $is_allowed_to_edit = api_is_allowed_to_edit(null, true);
  2427. $charset = api_get_system_encoding();
  2428. $display_action_links_with_icons = false;
  2429. if ($this->debug > 0) {
  2430. error_log('New LP - In learnpath::get_html_toc()', 0);
  2431. }
  2432. $list = $this->get_toc();
  2433. //echo $this->current;
  2434. //$parent = $this->items[$this->current]->get_parent();
  2435. //if (empty($parent)) { $parent = $this->ordered_items[$this->items[$this->current]->get_previous_index()]; }
  2436. $html = '<div id="scorm_title" class="scorm_title"><div class="scorm_title_text">' . Security::remove_XSS($this->get_name()) . '</div></div>';
  2437. // Build, display.
  2438. if ($is_allowed_to_edit) {
  2439. $gradebook = Security :: remove_XSS($_GET['gradebook']);
  2440. //var_dump($this->get_lp_session_id());
  2441. if ($this->get_lp_session_id() == api_get_session_id()) {
  2442. $html .= '<div id="actions_lp" class="actions_lp">';
  2443. if ($display_action_links_with_icons) {
  2444. $html .= '<div style = "text-align:center;">';
  2445. $html .= "<a href='lp_controller.php?" . api_get_cidreq() . "&amp;action=build&amp;lp_id=" . $this->lp_id . "' target='_parent'>" . Display :: return_icon('build_learnpath.png', get_lang('Build'),'','32')."</a>";
  2446. $html .= "<a href='lp_controller.php?" . api_get_cidreq() . "&amp;action=admin_view&amp;lp_id=" . $this->lp_id . "' target='_parent'>" . Display :: return_icon('move_learnpath.png', get_lang('BasicOverview'),'','32')."</a>";
  2447. $html .= '<span>' . Display :: return_icon('view_remove_na.png', get_lang('Display'),'','32').'</span><br />';
  2448. $html .= '<a href="lp_controller.php?' . api_get_cidreq() . '">'. get_lang('ReturnToLPList') . '</a>';
  2449. $html .= '</div>';
  2450. } else {
  2451. $html .= '<div style = "text-align:center;">';
  2452. $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>";
  2453. $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>";
  2454. $html .= '<span><b>' . get_lang('Display') . '</b></span><br />';
  2455. $html .= '<a href="lp_controller.php?' . api_get_cidreq() . '">'. get_lang('ReturnToLPList') . '</a>';
  2456. $html .= '</div>';
  2457. }
  2458. $html .= '</div>';
  2459. }
  2460. }
  2461. $html .= '<div id="inner_lp_toc" class="inner_lp_toc">' . "\n";
  2462. require_once 'resourcelinker.inc.php';
  2463. // Temporary variables.
  2464. $mycurrentitemid = $this->get_current_item_id();
  2465. $color_counter = 0;
  2466. $i = 0;
  2467. foreach ($list as $item) {
  2468. if ($this->debug > 2) {
  2469. error_log('New LP - learnpath::get_html_toc(): using item ' . $item['id'], 0);
  2470. }
  2471. // TODO: Complete this.
  2472. $icon_name = array (
  2473. 'not attempted' => '../img/notattempted.gif',
  2474. 'incomplete' => '../img/incomplete.gif',
  2475. 'failed' => '../img/failed.gif',
  2476. 'completed' => '../img/completed.gif',
  2477. 'passed' => '../img/passed.gif',
  2478. 'succeeded' => '../img/succeeded.gif',
  2479. 'browsed' => '../img/completed.gif'
  2480. );
  2481. $style = 'scorm_item';
  2482. $scorm_color_background = 'scorm_item';
  2483. $style_item = 'scorm_item';
  2484. $current = false;
  2485. if ($item['id'] == $this->current) {
  2486. $style = 'scorm_item_highlight';
  2487. $scorm_color_background = 'scorm_item_highlight';
  2488. } else
  2489. if ($color_counter % 2 == 0) {
  2490. $scorm_color_background = 'scorm_item_1';
  2491. } else {
  2492. $scorm_color_background = 'scorm_item_2';
  2493. }
  2494. if ($scorm_color_background != '') {
  2495. $html .= '<div id="toc_' . $item['id'] . '" class="' . $scorm_color_background . '">';
  2496. }
  2497. // The anchor will let us center the TOC on the currently viewed item &^D
  2498. if ($item['type'] != 'dokeos_module' && $item['type'] != 'dokeos_chapter') {
  2499. $html .= '<a name="atoc_' . $item['id'] . '" />';
  2500. $html .= '<div class="' . $style_item . '" style="padding-left: ' . ($item['level'] * 1.5) . 'em; padding-right:' . ($item['level'] / 2) . 'em" title="' . $item['description'] . '" >';
  2501. } else {
  2502. $html .= '<div class="' . $style_item . '" style="padding-left: ' . ($item['level'] * 2) . 'em; padding-right:' . ($item['level'] * 1.5) . 'em" title="' . $item['description'] . '" >';
  2503. }
  2504. $title = $item['title'];
  2505. if (empty ($title)) {
  2506. $title = rl_get_resource_name(api_get_course_id(), $this->get_id(), $item['id']);
  2507. }
  2508. $title = Security::remove_XSS($title);
  2509. if ($item['type'] != 'dokeos_chapter' && $item['type'] != 'dir' && $item['type'] != 'dokeos_module') {
  2510. //$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>" ;
  2511. $url = $this->get_link('http', $item['id']);
  2512. //$html .= '<a href="'.$url.'" target="content_name" onClick="top.load_item('.$item['id'].',\''.$url.'\');">'.$title.'</a>' ;
  2513. //$html .= '<a href="" onClick="top.load_item('.$item['id'].',\''.$url.'\');return false;">'.$title.'</a>' ;
  2514. //<img align="absbottom" width="13" height="13" src="../img/lp_document.png">&nbsp;background:#aaa;
  2515. $html .= '<a href="" onClick="switch_item(' .
  2516. $mycurrentitemid . ',' .
  2517. $item['id'] . ');' .
  2518. 'return false;" >' . stripslashes($title) . '</a>';
  2519. } elseif ($item['type'] == 'dokeos_module' || $item['type'] == 'dokeos_chapter') {
  2520. $html .= "<img align='absbottom' width='13' height='13' src='../img/lp_dokeos_module.png'>&nbsp;" . stripslashes($title);
  2521. } elseif ($item['type'] == 'dir') {
  2522. $html .= stripslashes($title);
  2523. }
  2524. $tbl_track_e_exercises = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
  2525. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  2526. $user_id = api_get_user_id();
  2527. $course_id = api_get_course_id();
  2528. $sql = "SELECT path FROM $tbl_track_e_exercises, $tbl_lp_item
  2529. WHERE path = '" . $item['path'] . "' AND exe_user_id = '$user_id' AND exe_cours_id = '$course_id' AND path = exe_exo_id AND status <> 'incomplete'";
  2530. $result = Database::query($sql);
  2531. $count = Database :: num_rows($result);
  2532. if ($item['type'] == 'quiz') {
  2533. if ($item['status'] == 'completed') {
  2534. $html .= "&nbsp;<img id='toc_img_" . $item['id'] . "' src='" . $icon_name[$item['status']] . "' alt='" . substr($item['status'], 0, 1) . "' width='12' height='12' />";
  2535. }
  2536. } else {
  2537. if ($item['type'] != 'dokeos_chapter' && $item['type'] != 'dokeos_module' && $item['type'] != 'dir') {
  2538. $html .= "&nbsp;<img id='toc_img_" . $item['id'] . "' src='" . $icon_name[$item['status']] . "' alt='" . substr($item['status'], 0, 1) . "' width='12' height='12' />";
  2539. }
  2540. }
  2541. $html .= "</div>";
  2542. if ($scorm_color_background != '') {
  2543. $html .= '</div>';
  2544. }
  2545. $color_counter++;
  2546. }
  2547. $html .= "</div>\n";
  2548. return $html;
  2549. }
  2550. /**
  2551. * Gets the learnpath maker name - generally the editor's name
  2552. * @return string Learnpath maker name
  2553. */
  2554. public function get_maker() {
  2555. if ($this->debug > 0) {
  2556. error_log('New LP - In learnpath::get_maker()', 0);
  2557. }
  2558. if (!empty ($this->maker)) {
  2559. return $this->maker;
  2560. } else {
  2561. return '';
  2562. }
  2563. }
  2564. /**
  2565. * Gets the user-friendly message stored in $this->message
  2566. * @return string Message
  2567. */
  2568. public function get_message() {
  2569. if ($this->debug > 0) {
  2570. error_log('New LP - In learnpath::get_message()', 0);
  2571. }
  2572. return $this->message;
  2573. }
  2574. /**
  2575. * Gets the learnpath name/title
  2576. * @return string Learnpath name/title
  2577. */
  2578. public function get_name() {
  2579. if ($this->debug > 0) {
  2580. error_log('New LP - In learnpath::get_name()', 0);
  2581. }
  2582. if (!empty ($this->name)) {
  2583. return $this->name;
  2584. } else {
  2585. return 'N/A';
  2586. }
  2587. }
  2588. /**
  2589. * Gets a link to the resource from the present location, depending on item ID.
  2590. * @param string Type of link expected
  2591. * @param integer Learnpath item ID
  2592. * @return string Link to the lp_item resource
  2593. */
  2594. public function get_link($type = 'http', $item_id = null) {
  2595. if ($this->debug > 0) {
  2596. error_log('New LP - In learnpath::get_link(' . $type . ',' . $item_id . ')', 0);
  2597. }
  2598. if (empty($item_id)) {
  2599. if ($this->debug > 2) {
  2600. error_log('New LP - In learnpath::get_link() - no item id given in learnpath::get_link(), using current: ' . $this->get_current_item_id(), 0);
  2601. }
  2602. $item_id = $this->get_current_item_id();
  2603. }
  2604. if (empty ($item_id)) {
  2605. if ($this->debug > 2) {
  2606. error_log('New LP - In learnpath::get_link() - no current item id found in learnpath object', 0);
  2607. }
  2608. //still empty, this means there was no item_id given and we are not in an object context or
  2609. //the object property is empty, return empty link
  2610. $item_id = $this->first();
  2611. return '';
  2612. }
  2613. $file = '';
  2614. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  2615. $lp_item_table = Database :: get_course_table(TABLE_LP_ITEM);
  2616. $lp_item_view_table = Database :: get_course_table(TABLE_LP_ITEM_VIEW);
  2617. $item_id = Database::escape_string($item_id);
  2618. $sel = "SELECT l.lp_type as ltype, l.path as lpath, li.item_type as litype, li.path as lipath, li.parameters as liparams " .
  2619. "FROM $lp_table l, $lp_item_table li WHERE li.id = $item_id AND li.lp_id = l.id";
  2620. if ($this->debug > 2) {
  2621. error_log('New LP - In learnpath::get_link() - selecting item ' . $sel, 0);
  2622. }
  2623. $res = Database::query($sel);
  2624. if (Database :: num_rows($res) > 0) {
  2625. $row = Database :: fetch_array($res);
  2626. //var_dump($row);
  2627. $lp_type = $row['ltype'];
  2628. $lp_path = $row['lpath'];
  2629. $lp_item_type = $row['litype'];
  2630. $lp_item_path = $row['lipath'];
  2631. $lp_item_params = $row['liparams'];
  2632. if (empty ($lp_item_params) && strpos($lp_item_path, '?') !== false) {
  2633. list ($lp_item_path, $lp_item_params) = explode('?', $lp_item_path);
  2634. }
  2635. //$lp_item_params = '?'.$lp_item_params;
  2636. //add ? if none - left commented to give freedom to scorm implementation
  2637. //if(substr($lp_item_params,0,1)!='?'){
  2638. // $lp_item_params = '?'.$lp_item_params;
  2639. //}
  2640. $sys_course_path = api_get_path(SYS_COURSE_PATH) . api_get_course_path();
  2641. if ($type == 'http') {
  2642. $course_path = api_get_path(WEB_COURSE_PATH) . api_get_course_path(); //web path
  2643. } else {
  2644. $course_path = $sys_course_path; //system path
  2645. }
  2646. // 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.
  2647. if (in_array($lp_item_type, array('quiz', 'document', 'link', 'forum', 'thread', 'student_publication'))) {
  2648. $lp_type = 1;
  2649. }
  2650. // Now go through the specific cases to get the end of the path.
  2651. // @todo Use constants instead of int values.
  2652. switch ($lp_type) {
  2653. case 1 :
  2654. if ($lp_item_type == 'dokeos_chapter') {
  2655. $file = 'lp_content.php?type=dir';
  2656. } else {
  2657. require_once 'resourcelinker.inc.php';
  2658. $file = rl_get_resource_link_for_learnpath(api_get_course_id(), $this->get_id(), $item_id);
  2659. // check how much attempts of a exercise exits in lp
  2660. $lp_item_id = $this->get_current_item_id();
  2661. $lp_view_id = $this->get_view_id();
  2662. $prevent_reinit = $this->items[$this->current]->get_prevent_reinit();
  2663. $list = $this->get_toc();
  2664. $type_quiz = false;
  2665. foreach ($list as $toc) {
  2666. if ($toc['id'] == $lp_item_id && ($toc['type'] == 'quiz')) {
  2667. $type_quiz = true;
  2668. }
  2669. }
  2670. if ($type_quiz) {
  2671. $lp_item_id = Database :: escape_string($lp_item_id);
  2672. $lp_view_id = Database :: escape_string($lp_view_id);
  2673. $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'";
  2674. $result = Database::query($sql);
  2675. $row_count = Database :: fetch_row($result);
  2676. $count_item_view = (int) $row_count[0];
  2677. $not_multiple_attempt = 0;
  2678. if ($prevent_reinit === 1 && $count_item_view > 0) {
  2679. $not_multiple_attempt = 1;
  2680. }
  2681. $file .= '&not_multiple_attempt=' . $not_multiple_attempt;
  2682. }
  2683. $tmp_array = explode('/', $file);
  2684. $document_name = $tmp_array[count($tmp_array) - 1];
  2685. if (strpos($document_name, '_DELETED_')) {
  2686. $file = 'blank.php?error=document_deleted';
  2687. }
  2688. }
  2689. break;
  2690. case 2 :
  2691. if ($this->debug > 2) {
  2692. error_log('New LP - In learnpath::get_link() ' . __LINE__ . ' - Item type: ' . $lp_item_type, 0);
  2693. }
  2694. if ($lp_item_type != 'dir') {
  2695. // Quite complex here:
  2696. // We want to make sure 'http://' (and similar) links can
  2697. // be loaded as is (withouth the Chamilo path in front) but
  2698. // some contents use this form: resource.htm?resource=http://blablabla
  2699. // which means we have to find a protocol at the path's start, otherwise
  2700. // it should not be considered as an external URL.
  2701. //if ($this->prerequisites_match($item_id)) {
  2702. if (preg_match('#^[a-zA-Z]{2,5}://#', $lp_item_path) != 0) {
  2703. if ($this->debug > 2) {
  2704. error_log('New LP - In learnpath::get_link() ' . __LINE__ . ' - Found match for protocol in ' . $lp_item_path, 0);
  2705. }
  2706. // Distant url, return as is.
  2707. $file = $lp_item_path;
  2708. } else {
  2709. if ($this->debug > 2) {
  2710. error_log('New LP - In learnpath::get_link() ' . __LINE__ . ' - No starting protocol in ' . $lp_item_path, 0);
  2711. }
  2712. // Prevent getting untranslatable urls.
  2713. $lp_item_path = preg_replace('/%2F/', '/', $lp_item_path);
  2714. $lp_item_path = preg_replace('/%3A/', ':', $lp_item_path);
  2715. // Prepare the path.
  2716. $file = $course_path . '/scorm/' . $lp_path . '/' . $lp_item_path;
  2717. // TODO: Fix this for urls with protocol header.
  2718. $file = str_replace('//', '/', $file);
  2719. $file = str_replace(':/', '://', $file);
  2720. if (substr($lp_path, -1) == '/') {
  2721. $lp_path = substr($lp_path, 0, -1);
  2722. }
  2723. if (!is_file(realpath($sys_course_path . '/scorm/' . $lp_path . '/' . $lp_item_path))) {
  2724. // if file not found.
  2725. $decoded = html_entity_decode($lp_item_path);
  2726. list ($decoded) = explode('?', $decoded);
  2727. if (!is_file(realpath($sys_course_path . '/scorm/' . $lp_path . '/' . $decoded))) {
  2728. require_once 'resourcelinker.inc.php';
  2729. $file = rl_get_resource_link_for_learnpath(api_get_course_id(), $this->get_id(), $item_id);
  2730. if (empty($file)) {
  2731. $file = 'blank.php?error=document_not_found';
  2732. } else {
  2733. $tmp_array = explode('/', $file);
  2734. $document_name = $tmp_array[count($tmp_array) - 1];
  2735. if (strpos($document_name, '_DELETED_')) {
  2736. $file = 'blank.php?error=document_deleted';
  2737. } else {
  2738. $file = 'blank.php?error=document_not_found';
  2739. }
  2740. }
  2741. } else {
  2742. $file = $course_path . '/scorm/' . $lp_path . '/' . $decoded;
  2743. }
  2744. }
  2745. }
  2746. //}else{
  2747. //prerequisites did not match
  2748. //$file = 'blank.php';
  2749. //}
  2750. // We want to use parameters if they were defined in the imsmanifest.
  2751. if ($file != 'blank.php') {
  2752. $file .= (strstr($file, '?') === false ? '?' : '') . $lp_item_params;
  2753. }
  2754. } else {
  2755. $file = 'lp_content.php?type=dir';
  2756. }
  2757. break;
  2758. case 3 :
  2759. if ($this->debug > 2) {
  2760. error_log('New LP - In learnpath::get_link() ' . __LINE__ . ' - Item type: ' . $lp_item_type, 0);
  2761. }
  2762. // Formatting AICC HACP append URL.
  2763. $aicc_append = '?aicc_sid=' . urlencode(session_id()) . '&aicc_url=' . urlencode(api_get_path(WEB_CODE_PATH) . 'newscorm/aicc_hacp.php') . '&';
  2764. if ($lp_item_type != 'dir') {
  2765. // Quite complex here:
  2766. // We want to make sure 'http://' (and similar) links can
  2767. // be loaded as is (withouth the Chamilo path in front) but
  2768. // some contents use this form: resource.htm?resource=http://blablabla
  2769. // which means we have to find a protocol at the path's start, otherwise
  2770. // it should not be considered as an external URL.
  2771. if (preg_match('#^[a-zA-Z]{2,5}://#', $lp_item_path) != 0) {
  2772. if ($this->debug > 2) {
  2773. error_log('New LP - In learnpath::get_link() ' . __LINE__ . ' - Found match for protocol in ' . $lp_item_path, 0);
  2774. }
  2775. // Distant url, return as is.
  2776. $file = $lp_item_path;
  2777. // Enabled and modified by Ivan Tcholakov, 16-OCT-2008.
  2778. /*
  2779. if (stristr($file,'<servername>') !== false) {
  2780. $file = str_replace('<servername>', $course_path.'/scorm/'.$lp_path.'/', $lp_item_path);
  2781. }
  2782. */
  2783. if (stripos($file, '<servername>') !== false) {
  2784. //$file = str_replace('<servername>',$course_path.'/scorm/'.$lp_path.'/',$lp_item_path);
  2785. $web_course_path = str_replace('https://', '', str_replace('http://', '', $course_path));
  2786. $file = str_replace('<servername>', $web_course_path . '/scorm/' . $lp_path, $lp_item_path);
  2787. }
  2788. //
  2789. $file .= $aicc_append;
  2790. } else {
  2791. if ($this->debug > 2) {
  2792. error_log('New LP - In learnpath::get_link() ' . __LINE__ . ' - No starting protocol in ' . $lp_item_path, 0);
  2793. }
  2794. // Prevent getting untranslatable urls.
  2795. $lp_item_path = preg_replace('/%2F/', '/', $lp_item_path);
  2796. $lp_item_path = preg_replace('/%3A/', ':', $lp_item_path);
  2797. // Prepare the path - lp_path might be unusable because it includes the "aicc" subdir name.
  2798. $file = $course_path . '/scorm/' . $lp_path . '/' . $lp_item_path;
  2799. // TODO: Fix this for urls with protocol header.
  2800. $file = str_replace('//', '/', $file);
  2801. $file = str_replace(':/', '://', $file);
  2802. $file .= $aicc_append;
  2803. }
  2804. } else {
  2805. $file = 'lp_content.php?type=dir';
  2806. }
  2807. break;
  2808. case 4 :
  2809. break;
  2810. default :
  2811. break;
  2812. }
  2813. }
  2814. if ($this->debug > 2) {
  2815. error_log('New LP - In learnpath::get_link() - returning "' . $file . '" from get_link', 0);
  2816. }
  2817. return $file;
  2818. }
  2819. /**
  2820. * Gets the latest usable view or generate a new one
  2821. * @param integer Optional attempt number. If none given, takes the highest from the lp_view table
  2822. * @return integer DB lp_view id
  2823. */
  2824. public function get_view($attempt_num = 0) {
  2825. if ($this->debug > 0) {
  2826. error_log('New LP - In learnpath::get_view()', 0);
  2827. }
  2828. $search = '';
  2829. // Use $attempt_num to enable multi-views management (disabled so far).
  2830. if ($attempt_num != 0 AND intval(strval($attempt_num)) == $attempt_num) {
  2831. $search = 'AND view_count = ' . $attempt_num;
  2832. }
  2833. // When missing $attempt_num, search for a unique lp_view record for this lp and user.
  2834. $lp_view_table = Database :: get_course_table(TABLE_LP_VIEW);
  2835. $sql = "SELECT id, view_count FROM $lp_view_table " .
  2836. "WHERE lp_id = " . $this->get_id() . " " .
  2837. "AND user_id = " . $this->get_user_id() . " " .
  2838. $search .
  2839. " ORDER BY view_count DESC";
  2840. $res = Database::query($sql);
  2841. if (Database :: num_rows($res) > 0) {
  2842. $row = Database :: fetch_array($res);
  2843. $this->lp_view_id = $row['id'];
  2844. } else {
  2845. // There is no database record, create one.
  2846. $sql = "INSERT INTO $lp_view_table(lp_id,user_id,view_count)" .
  2847. "VALUES (" . $this->get_id() . "," . $this->get_user_id() . ",1)";
  2848. $res = Database::query($sql);
  2849. $id = Database :: insert_id();
  2850. $this->lp_view_id = $id;
  2851. }
  2852. return $this->lp_view_id;
  2853. }
  2854. /**
  2855. * Gets the current view id
  2856. * @return integer View ID (from lp_view)
  2857. */
  2858. public function get_view_id() {
  2859. if ($this->debug > 0) {
  2860. error_log('New LP - In learnpath::get_view_id()', 0);
  2861. }
  2862. if (!empty ($this->lp_view_id)) {
  2863. return $this->lp_view_id;
  2864. } else {
  2865. return 0;
  2866. }
  2867. }
  2868. /**
  2869. * Gets the update queue
  2870. * @return array Array containing IDs of items to be updated by JavaScript
  2871. */
  2872. public function get_update_queue() {
  2873. if ($this->debug > 0) {
  2874. error_log('New LP - In learnpath::get_update_queue()', 0);
  2875. }
  2876. return $this->update_queue;
  2877. }
  2878. /**
  2879. * Gets the user ID
  2880. * @return integer User ID
  2881. */
  2882. public function get_user_id() {
  2883. if ($this->debug > 0) {
  2884. error_log('New LP - In learnpath::get_user_id()', 0);
  2885. }
  2886. if (!empty ($this->user_id)) {
  2887. return $this->user_id;
  2888. } else {
  2889. return false;
  2890. }
  2891. }
  2892. /**
  2893. * Checks if any of the items has an audio element attached
  2894. * @return bool True or false
  2895. */
  2896. public function has_audio() {
  2897. if ($this->debug > 1) {
  2898. error_log('New LP - In learnpath::has_audio()', 0);
  2899. }
  2900. $has = false;
  2901. foreach ($this->items as $i => $item) {
  2902. if (!empty ($this->items[$i]->audio)) {
  2903. $has = true;
  2904. break;
  2905. }
  2906. }
  2907. return $has;
  2908. }
  2909. /**
  2910. * Logs a message into a file
  2911. * @param string Message to log
  2912. * @return boolean True on success, false on error or if msg empty
  2913. */
  2914. public function log($msg) {
  2915. if ($this->debug > 0) {
  2916. error_log('New LP - In learnpath::log()', 0);
  2917. }
  2918. // TODO
  2919. $this->error .= $msg . "\n";
  2920. return true;
  2921. }
  2922. /**
  2923. * Moves an item up and down at its level
  2924. * @param integer Item to move up and down
  2925. * @param string Direction 'up' or 'down'
  2926. * @return integer New display order, or false on error
  2927. */
  2928. public function move_item($id, $direction) {
  2929. if ($this->debug > 0) {
  2930. error_log('New LP - In learnpath::move_item(' . $id . ',' . $direction . ')', 0);
  2931. }
  2932. if (empty ($id) or empty ($direction)) {
  2933. return false;
  2934. }
  2935. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  2936. $sql_sel = "
  2937. SELECT *
  2938. FROM " . $tbl_lp_item . "
  2939. WHERE id = " . $id;
  2940. $res_sel = Database::query($sql_sel);
  2941. // Check if elem exists.
  2942. if (Database :: num_rows($res_sel) < 1) {
  2943. return false;
  2944. }
  2945. // Gather data.
  2946. $row = Database :: fetch_array($res_sel);
  2947. $previous = $row['previous_item_id'];
  2948. $next = $row['next_item_id'];
  2949. $display = $row['display_order'];
  2950. $parent = $row['parent_item_id'];
  2951. $lp = $row['lp_id'];
  2952. // Update the item (switch with previous/next one).
  2953. switch ($direction) {
  2954. case 'up' :
  2955. if ($this->debug > 2) {
  2956. error_log('Movement up detected', 0);
  2957. }
  2958. if ($display <= 1) { /*do nothing*/
  2959. } else {
  2960. $sql_sel2 = "SELECT *
  2961. FROM $tbl_lp_item
  2962. WHERE id = $previous";
  2963. if ($this->debug > 2) {
  2964. error_log('Selecting previous: ' . $sql_sel2, 0);
  2965. }
  2966. $res_sel2 = Database::query($sql_sel2);
  2967. if (Database :: num_rows($res_sel2) < 1) {
  2968. $previous_previous = 0;
  2969. }
  2970. // Gather data.
  2971. $row2 = Database :: fetch_array($res_sel2);
  2972. $previous_previous = $row2['previous_item_id'];
  2973. // Update previous_previous item (switch "next" with current).
  2974. if ($previous_previous != 0) {
  2975. $sql_upd2 = "UPDATE $tbl_lp_item SET next_item_id = $id WHERE id = $previous_previous";
  2976. if ($this->debug > 2) {
  2977. error_log($sql_upd2, 0);
  2978. }
  2979. $res_upd2 = Database::query($sql_upd2);
  2980. }
  2981. // Update previous item (switch with current).
  2982. if ($previous != 0) {
  2983. $sql_upd2 = "UPDATE $tbl_lp_item SET next_item_id = $next, previous_item_id = $id, display_order = display_order +1 WHERE id = $previous";
  2984. if ($this->debug > 2) {
  2985. error_log($sql_upd2, 0);
  2986. }
  2987. $res_upd2 = Database::query($sql_upd2);
  2988. }
  2989. // Update current item (switch with previous).
  2990. if ($id != 0) {
  2991. $sql_upd2 = "UPDATE $tbl_lp_item SET next_item_id = $previous, previous_item_id = $previous_previous, display_order = display_order-1 WHERE id = $id";
  2992. if ($this->debug > 2) {
  2993. error_log($sql_upd2, 0);
  2994. }
  2995. $res_upd2 = Database::query($sql_upd2);
  2996. }
  2997. // Update next item (new previous item).
  2998. if ($next != 0) {
  2999. $sql_upd2 = "UPDATE $tbl_lp_item SET previous_item_id = $previous WHERE id = $next";
  3000. if ($this->debug > 2) {
  3001. error_log($sql_upd2, 0);
  3002. }
  3003. $res_upd2 = Database::query($sql_upd2);
  3004. }
  3005. $display = $display -1;
  3006. }
  3007. break;
  3008. case 'down' :
  3009. if ($this->debug > 2) {
  3010. error_log('Movement down detected', 0);
  3011. }
  3012. if ($next == 0) { /* Do nothing. */
  3013. } else {
  3014. $sql_sel2 = "SELECT * FROM $tbl_lp_item WHERE id = $next";
  3015. if ($this->debug > 2) {
  3016. error_log('Selecting next: ' . $sql_sel2, 0);
  3017. }
  3018. $res_sel2 = Database::query($sql_sel2);
  3019. if (Database :: num_rows($res_sel2) < 1) {
  3020. $next_next = 0;
  3021. }
  3022. // Gather data.
  3023. $row2 = Database :: fetch_array($res_sel2);
  3024. $next_next = $row2['next_item_id'];
  3025. // Update previous item (switch with current).
  3026. if ($previous != 0) {
  3027. $sql_upd2 = "UPDATE $tbl_lp_item SET next_item_id = $next WHERE id = $previous";
  3028. $res_upd2 = Database::query($sql_upd2);
  3029. }
  3030. // Update current item (switch with previous).
  3031. if ($id != 0) {
  3032. $sql_upd2 = "UPDATE $tbl_lp_item SET previous_item_id = $next, next_item_id = $next_next, display_order = display_order+1 WHERE id = $id";
  3033. $res_upd2 = Database::query($sql_upd2);
  3034. }
  3035. // Update next item (new previous item).
  3036. if ($next != 0) {
  3037. $sql_upd2 = "UPDATE $tbl_lp_item SET previous_item_id = $previous, next_item_id = $id, display_order = display_order-1 WHERE id = $next";
  3038. $res_upd2 = Database::query($sql_upd2);
  3039. }
  3040. // Update next_next item (switch "previous" with current).
  3041. if ($next_next != 0) {
  3042. $sql_upd2 = "UPDATE $tbl_lp_item SET previous_item_id = $id WHERE id = $next_next";
  3043. $res_upd2 = Database::query($sql_upd2);
  3044. }
  3045. $display = $display +1;
  3046. }
  3047. break;
  3048. default :
  3049. return false;
  3050. }
  3051. return $display;
  3052. }
  3053. /**
  3054. * Move a learnpath up (display_order)
  3055. * @param integer Learnpath ID
  3056. */
  3057. public function move_up($lp_id) {
  3058. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3059. $sql = "SELECT * FROM $lp_table ORDER BY display_order";
  3060. $res = Database::query($sql);
  3061. if ($res === false)
  3062. return false;
  3063. $lps = array ();
  3064. $lp_order = array ();
  3065. $num = Database :: num_rows($res);
  3066. // First check the order is correct, globally (might be wrong because
  3067. // of versions < 1.8.4)
  3068. if ($num > 0) {
  3069. $i = 1;
  3070. while ($row = Database :: fetch_array($res)) {
  3071. if ($row['display_order'] != $i) { // If we find a gap in the order, we need to fix it.
  3072. $need_fix = true;
  3073. $sql_u = "UPDATE $lp_table SET display_order = $i WHERE id = " . $row['id'];
  3074. $res_u = Database::query($sql_u);
  3075. }
  3076. $row['display_order'] = $i;
  3077. $lps[$row['id']] = $row;
  3078. $lp_order[$i] = $row['id'];
  3079. $i++;
  3080. }
  3081. }
  3082. if ($num > 1) { // If there's only one element, no need to sort.
  3083. $order = $lps[$lp_id]['display_order'];
  3084. if ($order > 1) { // If it's the first element, no need to move up.
  3085. $sql_u1 = "UPDATE $lp_table SET display_order = $order WHERE id = " . $lp_order[$order - 1];
  3086. $res_u1 = Database::query($sql_u1);
  3087. $sql_u2 = "UPDATE $lp_table SET display_order = " . ($order - 1) . " WHERE id = " . $lp_id;
  3088. $res_u2 = Database::query($sql_u2);
  3089. }
  3090. }
  3091. }
  3092. /**
  3093. * Move a learnpath down (display_order)
  3094. * @param integer Learnpath ID
  3095. */
  3096. public function move_down($lp_id) {
  3097. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3098. $sql = "SELECT * FROM $lp_table ORDER BY display_order";
  3099. $res = Database::query($sql);
  3100. if ($res === false)
  3101. return false;
  3102. $lps = array ();
  3103. $lp_order = array ();
  3104. $num = Database :: num_rows($res);
  3105. $max = 0;
  3106. // First check the order is correct, globally (might be wrong because
  3107. // of versions < 1.8.4).
  3108. if ($num > 0) {
  3109. $i = 1;
  3110. while ($row = Database :: fetch_array($res)) {
  3111. $max = $i;
  3112. if ($row['display_order'] != $i) { // If we find a gap in the order, we need to fix it.
  3113. $need_fix = true;
  3114. $sql_u = "UPDATE $lp_table SET display_order = $i WHERE id = " . $row['id'];
  3115. $res_u = Database::query($sql_u);
  3116. }
  3117. $row['display_order'] = $i;
  3118. $lps[$row['id']] = $row;
  3119. $lp_order[$i] = $row['id'];
  3120. $i++;
  3121. }
  3122. }
  3123. if ($num > 1) { // If there's only one element, no need to sort.
  3124. $order = $lps[$lp_id]['display_order'];
  3125. if ($order < $max) { // If it's the first element, no need to move up.
  3126. $sql_u1 = "UPDATE $lp_table SET display_order = $order WHERE id = " . $lp_order[$order + 1];
  3127. $res_u1 = Database::query($sql_u1);
  3128. $sql_u2 = "UPDATE $lp_table SET display_order = " . ($order + 1) . " WHERE id = " . $lp_id;
  3129. $res_u2 = Database::query($sql_u2);
  3130. }
  3131. }
  3132. }
  3133. /**
  3134. * Updates learnpath attributes to point to the next element
  3135. * The last part is similar to set_current_item but processing the other way around
  3136. */
  3137. public function next() {
  3138. if ($this->debug > 0) {
  3139. error_log('New LP - In learnpath::next()', 0);
  3140. }
  3141. $this->last = $this->get_current_item_id();
  3142. $this->items[$this->last]->save(false, $this->prerequisites_match($this->last));
  3143. $this->autocomplete_parents($this->last);
  3144. $new_index = $this->get_next_index();
  3145. if ($this->debug > 2) {
  3146. error_log('New LP - New index: ' . $new_index, 0);
  3147. }
  3148. $this->index = $new_index;
  3149. if ($this->debug > 2) {
  3150. error_log('New LP - Now having orderedlist[' . $new_index . '] = ' . $this->ordered_items[$new_index], 0);
  3151. }
  3152. $this->current = $this->ordered_items[$new_index];
  3153. if ($this->debug > 2) {
  3154. error_log('New LP - new item id is ' . $this->current . '-' . $this->get_current_item_id(), 0);
  3155. }
  3156. }
  3157. /**
  3158. * Open a resource = initialise all local variables relative to this resource. Depending on the child
  3159. * class, this might be redefined to allow several behaviours depending on the document type.
  3160. * @param integer Resource ID
  3161. * @return boolean True on success, false otherwise
  3162. */
  3163. public function open($id) {
  3164. if ($this->debug > 0) {
  3165. error_log('New LP - In learnpath::open()', 0);
  3166. }
  3167. // TODO:
  3168. // set the current resource attribute to this resource
  3169. // switch on element type (redefine in child class?)
  3170. // set status for this item to "opened"
  3171. // start timer
  3172. // initialise score
  3173. $this->index = 0; //or = the last item seen (see $this->last)
  3174. }
  3175. /**
  3176. * Check that all prerequisites are fulfilled. Returns true and an empty string on succes, returns false
  3177. * and the prerequisite string on error.
  3178. * This function is based on the rules for aicc_script language as described in the SCORM 1.2 CAM documentation page 108.
  3179. * @param integer Optional item ID. If none given, uses the current open item.
  3180. * @return boolean True if prerequisites are matched, false otherwise
  3181. * @return string Empty string if true returned, prerequisites string otherwise.
  3182. */
  3183. public function prerequisites_match($item = null) {
  3184. if ($this->debug > 0) {
  3185. error_log('New LP - In learnpath::prerequisites_match()', 0);
  3186. }
  3187. if (empty ($item)) {
  3188. $item = $this->current;
  3189. }
  3190. if (is_object($this->items[$item])) {
  3191. $prereq_string = $this->items[$item]->get_prereq_string();
  3192. if (empty ($prereq_string)) {
  3193. return true;
  3194. }
  3195. // Clean spaces.
  3196. $prereq_string = str_replace(' ', '', $prereq_string);
  3197. if ($this->debug > 0) {
  3198. error_log('Found prereq_string: ' . $prereq_string, 0);
  3199. }
  3200. // Now send to the parse_prereq() function that will check this component's prerequisites.
  3201. $result = $this->items[$item]->parse_prereq($prereq_string, $this->items, $this->refs_list, $this->get_user_id());
  3202. if ($result === false) {
  3203. $this->set_error_msg($this->items[$item]->prereq_alert);
  3204. }
  3205. } else {
  3206. $result = true;
  3207. if ($this->debug > 1) {
  3208. error_log('New LP - $this->items[' . $item . '] was not an object', 0);
  3209. }
  3210. }
  3211. if ($this->debug > 1) {
  3212. error_log('New LP - End of prerequisites_match(). Error message is now ' . $this->error, 0);
  3213. }
  3214. return $result;
  3215. }
  3216. /**
  3217. * Updates learnpath attributes to point to the previous element
  3218. * The last part is similar to set_current_item but processing the other way around
  3219. */
  3220. public function previous() {
  3221. if ($this->debug > 0) {
  3222. error_log('New LP - In learnpath::previous()', 0);
  3223. }
  3224. $this->last = $this->get_current_item_id();
  3225. $this->items[$this->last]->save(false, $this->prerequisites_match($this->last));
  3226. $this->autocomplete_parents($this->last);
  3227. $new_index = $this->get_previous_index();
  3228. $this->index = $new_index;
  3229. $this->current = $this->ordered_items[$new_index];
  3230. }
  3231. /**
  3232. * Publishes a learnpath. This basically means show or hide the learnpath
  3233. * to normal users.
  3234. * Can be used as abstract
  3235. * @param integer Learnpath ID
  3236. * @param string New visibility
  3237. */
  3238. public function toggle_visibility($lp_id, $set_visibility = 1) {
  3239. //if ($this->debug > 0) { error_log('New LP - In learnpath::toggle_visibility()', 0); }
  3240. $action = 'visible';
  3241. if ($set_visibility != 1) {
  3242. $action = 'invisible';
  3243. }
  3244. return api_item_property_update(api_get_course_info(), TOOL_LEARNPATH, $lp_id, $action, api_get_user_id());
  3245. }
  3246. /**
  3247. * Publishes a learnpath. This basically means show or hide the learnpath
  3248. * on the course homepage
  3249. * Can be used as abstract
  3250. * @param integer Learnpath id
  3251. * @param string New visibility (v/s - visible/invisible)
  3252. */
  3253. public function toggle_publish($lp_id, $set_visibility = 'v') {
  3254. //if ($this->debug > 0) { error_log('New LP - In learnpath::toggle_publish()', 0); }
  3255. $tbl_lp = Database :: get_course_table(TABLE_LP_MAIN);
  3256. $sql = "SELECT * FROM $tbl_lp where id=$lp_id";
  3257. $result = Database::query($sql);
  3258. $row = Database :: fetch_array($result);
  3259. $name = domesticate($row['name']);
  3260. if ($set_visibility == 'i') {
  3261. $s = $name . " " . get_lang('_no_published');
  3262. $dialogBox = $s;
  3263. $v = 0;
  3264. }
  3265. if ($set_visibility == 'v') {
  3266. $s = $name . " " . get_lang('_published');
  3267. $dialogBox = $s;
  3268. $v = 1;
  3269. }
  3270. $session_id = api_get_session_id();
  3271. $session_condition = api_get_session_condition($session_id);
  3272. $tbl_tool = Database :: get_course_table(TABLE_TOOL_LIST);
  3273. $link = 'newscorm/lp_controller.php?action=view&lp_id=' . $lp_id.'&id_session='.$session_id;
  3274. $sql = "SELECT * FROM $tbl_tool where name='$name' and image='scormbuilder.gif' and link LIKE '$link%' $session_condition";
  3275. $result = Database::query($sql);
  3276. $num = Database :: num_rows($result);
  3277. $row2 = Database :: fetch_array($result);
  3278. //if ($this->debug > 2) { error_log('New LP - '.$sql.' - '.$num, 0); }
  3279. if (($set_visibility == 'i') && ($num > 0)) {
  3280. $sql = "DELETE FROM $tbl_tool WHERE (name='$name' and image='scormbuilder.gif' and link LIKE '$link%' $session_condition)";
  3281. } elseif (($set_visibility == 'v') && ($num == 0)) {
  3282. $sql = "INSERT INTO $tbl_tool (name, link, image, visibility, admin, address, added_tool, session_id) VALUES ('$name','$link','scormbuilder.gif','$v','0','pastillegris.gif',0, $session_id)";
  3283. } else {
  3284. // Parameter and database incompatible, do nothing.
  3285. }
  3286. $result = Database::query($sql);
  3287. //if ($this->debug > 2) { error_log('New LP - Leaving learnpath::toggle_visibility: '.$sql, 0); }
  3288. }
  3289. /**
  3290. * Restart the whole learnpath. Return the URL of the first element.
  3291. * Make sure the results are saved with anoter method. This method should probably be
  3292. * redefined in children classes.
  3293. * To use a similar method statically, use the create_new_attempt() method
  3294. * @return string URL to load in the viewer
  3295. */
  3296. public function restart() {
  3297. if ($this->debug > 0) {
  3298. error_log('New LP - In learnpath::restart()', 0);
  3299. }
  3300. // TODO
  3301. // Call autosave method to save the current progress.
  3302. //$this->index = 0;
  3303. $session_id = api_get_session_id();
  3304. $lp_view_table = Database :: get_course_table(TABLE_LP_VIEW);
  3305. $sql = "INSERT INTO $lp_view_table (lp_id, user_id, view_count, session_id) " .
  3306. "VALUES (" . $this->lp_id . "," . $this->get_user_id() . "," . ($this->attempt + 1) . ", $session_id)";
  3307. if ($this->debug > 2) {
  3308. error_log('New LP - Inserting new lp_view for restart: ' . $sql, 0);
  3309. }
  3310. $res = Database::query($sql);
  3311. if ($view_id = Database :: insert_id($res)) {
  3312. $this->lp_view_id = $view_id;
  3313. $this->attempt = $this->attempt + 1;
  3314. } else {
  3315. $this->error = 'Could not insert into item_view table...';
  3316. return false;
  3317. }
  3318. $this->autocomplete_parents($this->current);
  3319. foreach ($this->items as $index => $dummy) {
  3320. $this->items[$index]->restart();
  3321. $this->items[$index]->set_lp_view($this->lp_view_id);
  3322. }
  3323. $this->first();
  3324. return true;
  3325. }
  3326. /**
  3327. * Saves the current item
  3328. * @return boolean
  3329. */
  3330. public function save_current() {
  3331. if ($this->debug > 0) {
  3332. error_log('New LP - In learnpath::save_current()', 0);
  3333. }
  3334. // TODO: Do a better check on the index pointing to the right item (it is supposed to be working
  3335. // on $ordered_items[] but not sure it's always safe to use with $items[]).
  3336. if ($this->debug > 2) {
  3337. error_log('New LP - save_current() saving item ' . $this->current, 0);
  3338. }
  3339. if ($this->debug > 2) {
  3340. error_log('' . print_r($this->items, true), 0);
  3341. }
  3342. if (is_object($this->items[$this->current])) {
  3343. //$res = $this->items[$this->current]->save(false);
  3344. $res = $this->items[$this->current]->save(false, $this->prerequisites_match($this->current));
  3345. $this->autocomplete_parents($this->current);
  3346. $status = $this->items[$this->current]->get_status();
  3347. $this->append_message('new_item_status: ' . $status);
  3348. $this->update_queue[$this->current] = $status;
  3349. return $res;
  3350. }
  3351. return false;
  3352. }
  3353. /**
  3354. * Saves the given item
  3355. * @param integer Item ID. Optional (will take from $_REQUEST if null)
  3356. * @param boolean Save from url params (true) or from current attributes (false). Optional. Defaults to true
  3357. * @return boolean
  3358. */
  3359. public function save_item($item_id = null, $from_outside = true) {
  3360. if ($this->debug > 0) {
  3361. error_log('New LP - In learnpath::save_item(' . $item_id . ',' . $from_outside . ')', 0);
  3362. }
  3363. // TODO: Do a better check on the index pointing to the right item (it is supposed to be working
  3364. // on $ordered_items[] but not sure it's always safe to use with $items[]).
  3365. if (empty ($item_id)) {
  3366. $item_id = $this->escape_string($_REQUEST['id']);
  3367. }
  3368. if (empty ($item_id)) {
  3369. $item_id = $this->get_current_item_id();
  3370. }
  3371. if ($this->debug > 2) {
  3372. error_log('New LP - save_current() saving item ' . $item_id, 0);
  3373. }
  3374. if (is_object($this->items[$item_id])) {
  3375. $res = $this->items[$item_id]->save($from_outside, $this->prerequisites_match($item_id));
  3376. //$res = $this->items[$item_id]->save($from_outside);
  3377. $this->autocomplete_parents($item_id);
  3378. $status = $this->items[$item_id]->get_status();
  3379. $this->append_message('new_item_status: ' . $status);
  3380. $this->update_queue[$item_id] = $status;
  3381. return $res;
  3382. }
  3383. return false;
  3384. }
  3385. /**
  3386. * Saves the last item seen's ID only in case
  3387. */
  3388. public function save_last() {
  3389. if ($this->debug > 0) {
  3390. error_log('New LP - In learnpath::save_last()', 0);
  3391. }
  3392. $session_condition = api_get_session_condition(api_get_session_id(), true, false);
  3393. $table = Database :: get_course_table(TABLE_LP_VIEW);
  3394. if (isset ($this->current)) {
  3395. if ($this->debug > 2) {
  3396. error_log('New LP - Saving current item (' . $this->current . ') for later review', 0);
  3397. }
  3398. $sql = "UPDATE $table SET last_item = " . Database::escape_string($this->get_current_item_id()). " " .
  3399. "WHERE lp_id = " . $this->get_id() . " AND user_id = " . $this->get_user_id().' '.$session_condition;
  3400. if ($this->debug > 2) {
  3401. error_log('New LP - Saving last item seen : ' . $sql, 0);
  3402. }
  3403. $res = Database::query($sql);
  3404. }
  3405. // Save progress.
  3406. list($progress, $text) = $this->get_progress_bar_text('%');
  3407. if ($progress >= 0 && $progress <= 100) {
  3408. $progress = (int) $progress;
  3409. $sql = "UPDATE $table SET progress = $progress " .
  3410. "WHERE lp_id = " . $this->get_id() . " AND " .
  3411. "user_id = " . $this->get_user_id().' '.$session_condition;
  3412. $res = Database::query($sql); // Ignore errors as some tables might not have the progress field just yet.
  3413. $this->progress_db = $progress;
  3414. }
  3415. }
  3416. /**
  3417. * Sets the current item ID (checks if valid and authorized first)
  3418. * @param integer New item ID. If not given or not authorized, defaults to current
  3419. */
  3420. public function set_current_item($item_id = null) {
  3421. if ($this->debug > 0) {
  3422. error_log('New LP - In learnpath::set_current_item(' . $item_id . ')', 0);
  3423. }
  3424. if (empty ($item_id)) {
  3425. if ($this->debug > 2) {
  3426. error_log('New LP - No new current item given, ignore...', 0);
  3427. }
  3428. // Do nothing.
  3429. } else {
  3430. if ($this->debug > 2) {
  3431. error_log('New LP - New current item given is ' . $item_id . '...', 0);
  3432. }
  3433. if (is_numeric($item_id)) {
  3434. $item_id = $this->escape_string($item_id);
  3435. // TODO: Check in database here.
  3436. $this->last = $this->current;
  3437. $this->current = $item_id;
  3438. // TODO: Update $this->index as well.
  3439. foreach ($this->ordered_items as $index => $item) {
  3440. if ($item == $this->current) {
  3441. $this->index = $index;
  3442. break;
  3443. }
  3444. }
  3445. if ($this->debug > 2) {
  3446. error_log('New LP - set_current_item(' . $item_id . ') done. Index is now : ' . $this->index, 0);
  3447. }
  3448. } else {
  3449. error_log('New LP - set_current_item(' . $item_id . ') failed. Not a numeric value: ', 0);
  3450. }
  3451. }
  3452. }
  3453. /**
  3454. * Sets the encoding
  3455. * @param string New encoding
  3456. * TODO (as of Chamilo 1.8.8): Check in the future whether this method is needed.
  3457. */
  3458. public function set_encoding($enc = 'UTF-8') {
  3459. if ($this->debug > 0) {
  3460. error_log('New LP - In learnpath::set_encoding()', 0);
  3461. }
  3462. /* // Deprecated code (Chamilo 1.8.8).
  3463. $enc = strtoupper($enc);
  3464. $encodings = array (
  3465. 'UTF-8',
  3466. 'ISO-8859-1',
  3467. 'ISO-8859-15',
  3468. 'cp1251',
  3469. 'cp1252',
  3470. 'KOI8-R',
  3471. 'BIG5',
  3472. 'GB2312',
  3473. 'Shift_JIS',
  3474. 'EUC-JP',
  3475. ''
  3476. );
  3477. if (in_array($enc, $encodings)) { // TODO: Incorrect comparison, fix it.
  3478. $lp = $this->get_id();
  3479. if ($lp != 0) {
  3480. $tbl_lp = Database :: get_course_table(TABLE_LP_MAIN);
  3481. $sql = "UPDATE $tbl_lp SET default_encoding = '$enc' WHERE id = " . $lp;
  3482. $res = Database::query($sql);
  3483. return $res;
  3484. }
  3485. }
  3486. return false;
  3487. */
  3488. $enc = api_refine_encoding_id($enc);
  3489. if (empty($enc)) {
  3490. $enc = api_get_system_encoding();
  3491. }
  3492. if (api_is_encoding_supported($enc)) {
  3493. $lp = $this->get_id();
  3494. if ($lp != 0) {
  3495. $tbl_lp = Database :: get_course_table(TABLE_LP_MAIN);
  3496. $sql = "UPDATE $tbl_lp SET default_encoding = '$enc' WHERE id = " . $lp;
  3497. $res = Database::query($sql);
  3498. return $res;
  3499. }
  3500. }
  3501. return false;
  3502. }
  3503. /**
  3504. * Sets the JS lib setting in the database directly.
  3505. * This is the JavaScript library file this lp needs to load on startup
  3506. * @param string Proximity setting
  3507. * @return boolean True on update success. False otherwise.
  3508. */
  3509. public function set_jslib($lib = '') {
  3510. if ($this->debug > 0) {
  3511. error_log('New LP - In learnpath::set_jslib()', 0);
  3512. }
  3513. $lp = $this->get_id();
  3514. if ($lp != 0) {
  3515. $tbl_lp = Database :: get_course_table(TABLE_LP_MAIN);
  3516. $sql = "UPDATE $tbl_lp SET js_lib = '$lib' WHERE id = " . $lp;
  3517. $res = Database::query($sql);
  3518. return $res;
  3519. } else {
  3520. return false;
  3521. }
  3522. }
  3523. /**
  3524. * Sets the name of the LP maker (publisher) (and save)
  3525. * @param string Optional string giving the new content_maker of this learnpath
  3526. * @return boolean True
  3527. */
  3528. public function set_maker($name = '') {
  3529. if ($this->debug > 0) {
  3530. error_log('New LP - In learnpath::set_maker()', 0);
  3531. }
  3532. if (empty ($name))
  3533. return false;
  3534. $this->maker = $this->escape_string($name);
  3535. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3536. $lp_id = $this->get_id();
  3537. $sql = "UPDATE $lp_table SET content_maker = '" . $this->maker . "' WHERE id = '$lp_id'";
  3538. if ($this->debug > 2) {
  3539. error_log('New LP - lp updated with new content_maker : ' . $this->maker, 0);
  3540. }
  3541. $res = Database::query($sql);
  3542. return true;
  3543. }
  3544. /**
  3545. * Sets the name of the current learnpath (and save)
  3546. * @param string Optional string giving the new name of this learnpath
  3547. * @return boolean True/False
  3548. */
  3549. public function set_name($name = '') {
  3550. if ($this->debug > 0) {
  3551. error_log('New LP - In learnpath::set_name()', 0);
  3552. }
  3553. if (empty ($name))
  3554. return false;
  3555. $this->name = $this->escape_string($name);
  3556. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3557. $lp_id = $this->get_id();
  3558. $sql = "UPDATE $lp_table SET name = '" . $this->name . "' WHERE id = '$lp_id'";
  3559. if ($this->debug > 2) {
  3560. error_log('New LP - lp updated with new name : ' . $this->name, 0);
  3561. }
  3562. $res = Database::query($sql);
  3563. // If the lp is visible on the homepage, change his name there.
  3564. if (Database::affected_rows()) {
  3565. $table = Database :: get_course_table(TABLE_TOOL_LIST);
  3566. $sql = 'UPDATE ' . $table . ' SET
  3567. name = "' . $this->name . '"
  3568. WHERE link = "newscorm/lp_controller.php?action=view&lp_id=' . $lp_id . '"';
  3569. Database::query($sql);
  3570. }
  3571. return true;
  3572. }
  3573. /**
  3574. * Set index specified prefix terms for all items in this path
  3575. * @param string Comma-separated list of terms
  3576. * @param char Xapian term prefix
  3577. * @return boolean False on error, true otherwise
  3578. */
  3579. public function set_terms_by_prefix($terms_string, $prefix) {
  3580. if (api_get_setting('search_enabled') !== 'true')
  3581. return false;
  3582. $terms_string = trim($terms_string);
  3583. $terms = explode(',', $terms_string);
  3584. array_walk($terms, 'trim_value');
  3585. $stored_terms = $this->get_common_index_terms_by_prefix($prefix);
  3586. //var_dump($stored_terms);
  3587. //var_dump($terms);
  3588. // Don't do anything if no change, verify only at DB, not the search engine.
  3589. if ((count(array_diff($terms, $stored_terms)) == 0) && (count(array_diff($stored_terms, $terms)) == 0))
  3590. return false;
  3591. require_once 'xapian.php'; // TODO: Try catch every xapian use or make wrappers on API.
  3592. require_once api_get_path(LIBRARY_PATH).'search/DokeosIndexer.class.php';
  3593. require_once api_get_path(LIBRARY_PATH).'search/xapian/XapianQuery.php';
  3594. require_once api_get_path(LIBRARY_PATH).'search/IndexableChunk.class.php';
  3595. $items_table = Database :: get_course_table(TABLE_LP_ITEM);
  3596. // TODO: Make query secure agains XSS : use member attr instead of post var.
  3597. $lp_id = intval($_POST['lp_id']);
  3598. $sql = "SELECT * FROM $items_table WHERE lp_id = $lp_id";
  3599. $result = Database::query($sql);
  3600. $di = new DokeosIndexer();
  3601. while ($lp_item = Database :: fetch_array($result)) {
  3602. // Get search_did.
  3603. $tbl_se_ref = Database :: get_main_table(TABLE_MAIN_SEARCH_ENGINE_REF);
  3604. $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';
  3605. $sql = sprintf($sql, $tbl_se_ref, $this->cc, TOOL_LEARNPATH, $lp_id, $lp_item['id']);
  3606. //echo $sql; echo '<br>';
  3607. $res = Database::query($sql);
  3608. if (Database::num_rows($res) > 0) {
  3609. $se_ref = Database :: fetch_array($res);
  3610. // Compare terms.
  3611. $doc = $di->get_document($se_ref['search_did']);
  3612. $xapian_terms = xapian_get_doc_terms($doc, $prefix);
  3613. $xterms = array ();
  3614. foreach ($xapian_terms as $xapian_term) {
  3615. $xterms[] = substr($xapian_term['name'], 1);
  3616. }
  3617. $dterms = $terms;
  3618. $missing_terms = array_diff($dterms, $xterms);
  3619. $deprecated_terms = array_diff($xterms, $dterms);
  3620. // Save it to search engine.
  3621. foreach ($missing_terms as $term) {
  3622. $doc->add_term($prefix . $term, 1);
  3623. }
  3624. foreach ($deprecated_terms as $term) {
  3625. $doc->remove_term($prefix . $term);
  3626. }
  3627. $di->getDb()->replace_document((int) $se_ref['search_did'], $doc);
  3628. $di->getDb()->flush();
  3629. } else {
  3630. //@todo What we should do here?
  3631. }
  3632. }
  3633. return true;
  3634. }
  3635. /**
  3636. * Sets the theme of the LP (local/remote) (and save)
  3637. * @param string Optional string giving the new theme of this learnpath
  3638. * @return bool Returns true if theme name is not empty
  3639. */
  3640. public function set_theme($name = '') {
  3641. if ($this->debug > 0) {
  3642. error_log('New LP - In learnpath::set_theme()', 0);
  3643. }
  3644. $this->theme = $this->escape_string($name);
  3645. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3646. $lp_id = $this->get_id();
  3647. $sql = "UPDATE $lp_table SET theme = '" . $this->theme . "' WHERE id = '$lp_id'";
  3648. if ($this->debug > 2) {
  3649. error_log('New LP - lp updated with new theme : ' . $this->theme, 0);
  3650. }
  3651. //$res = Database::query($sql);
  3652. $res = Database::query($sql);
  3653. return true;
  3654. }
  3655. /**
  3656. * Sets the image of an LP (and save)
  3657. * @param string Optional string giving the new image of this learnpath
  3658. * @return bool Returns true if theme name is not empty
  3659. */
  3660. public function set_preview_image($name = '') {
  3661. if ($this->debug > 0) {
  3662. error_log('New LP - In learnpath::set_preview_image()', 0);
  3663. }
  3664. $this->preview_image = $this->escape_string($name);
  3665. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3666. $lp_id = $this->get_id();
  3667. $sql = "UPDATE $lp_table SET preview_image = '" . $this->preview_image . "' WHERE id = '$lp_id'";
  3668. if ($this->debug > 2) {
  3669. error_log('New LP - lp updated with new preview image : ' . $this->preview_image, 0);
  3670. }
  3671. $res = Database::query($sql);
  3672. return true;
  3673. }
  3674. /**
  3675. * Sets the author of a LP (and save)
  3676. * @param string Optional string giving the new author of this learnpath
  3677. * @return bool Returns true if author's name is not empty
  3678. */
  3679. public function set_author($name = '') {
  3680. if ($this->debug > 0) {
  3681. error_log('New LP - In learnpath::set_author()', 0);
  3682. }
  3683. $this->author = $this->escape_string($name);
  3684. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3685. $lp_id = $this->get_id();
  3686. $sql = "UPDATE $lp_table SET author = '" . $this->author . "' WHERE id = '$lp_id'";
  3687. if ($this->debug > 2) {
  3688. error_log('New LP - lp updated with new preview author : ' . $this->author, 0);
  3689. }
  3690. $res = Database::query($sql);
  3691. return true;
  3692. }
  3693. /**
  3694. * Sets the prerequisite of a LP (and save)
  3695. * @param int integer giving the new prerequisite of this learnpath
  3696. * @return bool returns true if prerequisite is not empty
  3697. */
  3698. public function set_prerequisite($prerequisite) {
  3699. if ($this->debug > 0) {
  3700. error_log('New LP - In learnpath::set_prerequisite()', 0);
  3701. }
  3702. $this->prerequisite = intval($prerequisite);
  3703. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3704. $lp_id = $this->get_id();
  3705. $sql = "UPDATE $lp_table SET prerequisite = '".$this->prerequisite."' WHERE id = '$lp_id'";
  3706. if ($this->debug > 2) {
  3707. error_log('New LP - lp updated with new preview requisite : ' . $this->requisite, 0);
  3708. }
  3709. $res = Database::query($sql);
  3710. return true;
  3711. }
  3712. /**
  3713. * Sets the location/proximity of the LP (local/remote) (and save)
  3714. * @param string Optional string giving the new location of this learnpath
  3715. * @return boolean True on success / False on error
  3716. */
  3717. public function set_proximity($name = '') {
  3718. if ($this->debug > 0) {
  3719. error_log('New LP - In learnpath::set_proximity()', 0);
  3720. }
  3721. if (empty ($name))
  3722. return false;
  3723. $this->proximity = $this->escape_string($name);
  3724. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3725. $lp_id = $this->get_id();
  3726. $sql = "UPDATE $lp_table SET content_local = '" . $this->proximity . "' WHERE id = '$lp_id'";
  3727. if ($this->debug > 2) {
  3728. error_log('New LP - lp updated with new proximity : ' . $this->proximity, 0);
  3729. }
  3730. $res = Database::query($sql);
  3731. return true;
  3732. }
  3733. /**
  3734. * Sets the previous item ID to a given ID. Generally, this should be set to the previous 'current' item
  3735. * @param integer DB ID of the item
  3736. */
  3737. public function set_previous_item($id) {
  3738. if ($this->debug > 0) {
  3739. error_log('New LP - In learnpath::set_previous_item()', 0);
  3740. }
  3741. $this->last = $id;
  3742. }
  3743. /**
  3744. * Sets use_max_score
  3745. * @param string Optional string giving the new location of this learnpath
  3746. * @return boolean True on success / False on error
  3747. */
  3748. public function set_use_max_score($use_max_score = 1) {
  3749. if ($this->debug > 0) {
  3750. error_log('New LP - In learnpath::set_use_max_score()', 0);
  3751. }
  3752. $use_max_score = intval($use_max_score);
  3753. $this->use_max_score = $use_max_score;
  3754. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3755. $lp_id = $this->get_id();
  3756. $sql = "UPDATE $lp_table SET use_max_score = '" . $this->use_max_score . "' WHERE id = '$lp_id'";
  3757. if ($this->debug > 2) {
  3758. error_log('New LP - lp updated with new use_max_score : ' . $this->use_max_score, 0);
  3759. }
  3760. $res = Database::query($sql);
  3761. return true;
  3762. }
  3763. /**
  3764. * Sets and saves the expired_on date
  3765. * @param string Optional string giving the new author of this learnpath
  3766. * @return bool Returns true if author's name is not empty
  3767. */
  3768. public function set_expired_on($expired_on) {
  3769. if ($this->debug > 0) {
  3770. error_log('New LP - In learnpath::set_expired_on()', 0);
  3771. }
  3772. if (!empty($expired_on)) {
  3773. $this->expired_on = $this->escape_string(api_get_utc_datetime($expired_on));
  3774. } else {
  3775. $this->expired_on = '';
  3776. }
  3777. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3778. $lp_id = $this->get_id();
  3779. $sql = "UPDATE $lp_table SET expired_on = '" . $this->expired_on . "' WHERE id = '$lp_id'";
  3780. if ($this->debug > 2) {
  3781. error_log('New LP - lp updated with new expired_on : ' . $this->expired_on, 0);
  3782. }
  3783. $res = Database::query($sql);
  3784. return true;
  3785. }
  3786. /**
  3787. * Sets and saves the publicated_on date
  3788. * @param string Optional string giving the new author of this learnpath
  3789. * @return bool Returns true if author's name is not empty
  3790. */
  3791. public function set_publicated_on($publicated_on) {
  3792. if ($this->debug > 0) {
  3793. error_log('New LP - In learnpath::set_expired_on()', 0);
  3794. }
  3795. if (!empty($publicated_on)) {
  3796. $this->publicated_on = $this->escape_string(api_get_utc_datetime($publicated_on));
  3797. } else {
  3798. $this->publicated_on = '';
  3799. }
  3800. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3801. $lp_id = $this->get_id();
  3802. $sql = "UPDATE $lp_table SET publicated_on = '" . $this->publicated_on . "' WHERE id = '$lp_id'";
  3803. if ($this->debug > 2) {
  3804. error_log('New LP - lp updated with new publicated_on : ' . $this->publicated_on, 0);
  3805. }
  3806. $res = Database::query($sql);
  3807. return true;
  3808. }
  3809. /**
  3810. * Sets and saves the expired_on date
  3811. * @param string Optional string giving the new author of this learnpath
  3812. * @return bool Returns true if author's name is not empty
  3813. */
  3814. public function set_modified_on() {
  3815. if ($this->debug > 0) {
  3816. error_log('New LP - In learnpath::set_expired_on()', 0);
  3817. }
  3818. $this->modified_on = api_get_utc_datetime();
  3819. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3820. $lp_id = $this->get_id();
  3821. $sql = "UPDATE $lp_table SET modified_on = '" . $this->modified_on . "' WHERE id = '$lp_id'";
  3822. if ($this->debug > 2) {
  3823. error_log('New LP - lp updated with new expired_on : ' . $this->modified_on, 0);
  3824. }
  3825. $res = Database::query($sql);
  3826. return true;
  3827. }
  3828. /**
  3829. * Sets the object's error message
  3830. * @param string Error message. If empty, reinits the error string
  3831. * @return void
  3832. */
  3833. public function set_error_msg($error = '') {
  3834. if ($this->debug > 0) {
  3835. error_log('New LP - In learnpath::set_error_msg()', 0);
  3836. }
  3837. if (empty ($error)) {
  3838. $this->error = '';
  3839. } else {
  3840. $this->error .= $error;
  3841. }
  3842. }
  3843. /**
  3844. * Launches the current item if not 'sco' (starts timer and make sure there is a record ready in the DB)
  3845. * @param boolean Whether to allow a new attempt or not
  3846. * @return boolean True
  3847. */
  3848. public function start_current_item($allow_new_attempt = false) {
  3849. if ($this->debug > 0) {
  3850. error_log('New LP - In learnpath::start_current_item()', 0);
  3851. }
  3852. if ($this->current != 0 AND is_object($this->items[$this->current])) {
  3853. $type = $this->get_type();
  3854. $item_type = $this->items[$this->current]->get_type();
  3855. if (($type == 2 && $item_type != 'sco') OR ($type == 3 && $item_type != 'au') OR ($type == 1 && $item_type != TOOL_QUIZ && $item_type != TOOL_HOTPOTATOES)) {
  3856. $this->items[$this->current]->open($allow_new_attempt);
  3857. $this->autocomplete_parents($this->current);
  3858. $prereq_check = $this->prerequisites_match($this->current);
  3859. $this->items[$this->current]->save(false, $prereq_check);
  3860. //$this->update_queue[$this->last] = $this->items[$this->last]->get_status();
  3861. } else {
  3862. // If sco, then it is supposed to have been updated by some other call.
  3863. }
  3864. if ($item_type == 'sco') {
  3865. $this->items[$this->current]->restart();
  3866. }
  3867. }
  3868. if ($this->debug > 0) {
  3869. error_log('New LP - End of learnpath::start_current_item()', 0);
  3870. }
  3871. return true;
  3872. }
  3873. /**
  3874. * Stops the processing and counters for the old item (as held in $this->last)
  3875. * @return boolean True/False
  3876. */
  3877. public function stop_previous_item() {
  3878. if ($this->debug > 0) {
  3879. error_log('New LP - In learnpath::stop_previous_item()', 0);
  3880. }
  3881. if ($this->last != 0 && $this->last != $this->current && is_object($this->items[$this->last])) {
  3882. if ($this->debug > 2) {
  3883. error_log('New LP - In learnpath::stop_previous_item() - ' . $this->last . ' is object', 0);
  3884. }
  3885. switch ($this->get_type()) {
  3886. case '3' :
  3887. if ($this->items[$this->last]->get_type() != 'au') {
  3888. if ($this->debug > 2) {
  3889. error_log('New LP - In learnpath::stop_previous_item() - ' . $this->last . ' in lp_type 3 is <> au', 0);
  3890. }
  3891. $this->items[$this->last]->close();
  3892. //$this->autocomplete_parents($this->last);
  3893. //$this->update_queue[$this->last] = $this->items[$this->last]->get_status();
  3894. } else {
  3895. if ($this->debug > 2) {
  3896. error_log('New LP - In learnpath::stop_previous_item() - Item is an AU, saving is managed by AICC signals', 0);
  3897. }
  3898. }
  3899. case '2' :
  3900. if ($this->items[$this->last]->get_type() != 'sco') {
  3901. if ($this->debug > 2) {
  3902. error_log('New LP - In learnpath::stop_previous_item() - ' . $this->last . ' in lp_type 2 is <> sco', 0);
  3903. }
  3904. $this->items[$this->last]->close();
  3905. //$this->autocomplete_parents($this->last);
  3906. //$this->update_queue[$this->last] = $this->items[$this->last]->get_status();
  3907. } else {
  3908. if ($this->debug > 2) {
  3909. error_log('New LP - In learnpath::stop_previous_item() - Item is a SCO, saving is managed by SCO signals', 0);
  3910. }
  3911. }
  3912. break;
  3913. case '1' :
  3914. default :
  3915. if ($this->debug > 2) {
  3916. error_log('New LP - In learnpath::stop_previous_item() - ' . $this->last . ' in lp_type 1 is asset', 0);
  3917. }
  3918. $this->items[$this->last]->close();
  3919. break;
  3920. }
  3921. } else {
  3922. if ($this->debug > 2) {
  3923. error_log('New LP - In learnpath::stop_previous_item() - No previous element found, ignoring...', 0);
  3924. }
  3925. return false;
  3926. }
  3927. return true;
  3928. }
  3929. /**
  3930. * Updates the default view mode from fullscreen to embedded and inversely
  3931. * @return string The current default view mode ('fullscreen' or 'embedded')
  3932. */
  3933. public function update_default_view_mode() {
  3934. if ($this->debug > 0) {
  3935. error_log('New LP - In learnpath::update_default_view_mode()', 0);
  3936. }
  3937. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3938. $sql = "SELECT * FROM $lp_table WHERE id = " . $this->get_id();
  3939. $res = Database::query($sql);
  3940. if (Database :: num_rows($res) > 0) {
  3941. $row = Database :: fetch_array($res);
  3942. $view_mode = $row['default_view_mod'];
  3943. if ($view_mode == 'fullscreen') {
  3944. $view_mode = 'embedded';
  3945. } elseif ($view_mode == 'embedded') {
  3946. $view_mode = 'embedframe';
  3947. } elseif ($view_mode == 'embedframe') {
  3948. $view_mode = 'fullscreen';
  3949. }
  3950. $sql = "UPDATE $lp_table SET default_view_mod = '$view_mode' WHERE id = " . $this->get_id();
  3951. $res = Database::query($sql);
  3952. $this->mode = $view_mode;
  3953. return $view_mode;
  3954. } else {
  3955. if ($this->debug > 2) {
  3956. error_log('New LP - Problem in update_default_view() - could not find LP ' . $this->get_id() . ' in DB', 0);
  3957. }
  3958. }
  3959. return -1;
  3960. }
  3961. /**
  3962. * Updates the default behaviour about auto-commiting SCORM updates
  3963. * @return boolean True if auto-commit has been set to 'on', false otherwise
  3964. */
  3965. public function update_default_scorm_commit() {
  3966. if ($this->debug > 0) {
  3967. error_log('New LP - In learnpath::update_default_scorm_commit()', 0);
  3968. }
  3969. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3970. $sql = "SELECT * FROM $lp_table WHERE id = " . $this->get_id();
  3971. $res = Database::query($sql);
  3972. if (Database :: num_rows($res) > 0) {
  3973. $row = Database :: fetch_array($res);
  3974. $force = $row['force_commit'];
  3975. if ($force == 1) {
  3976. $force = 0;
  3977. $force_return = false;
  3978. } elseif ($force == 0) {
  3979. $force = 1;
  3980. $force_return = true;
  3981. }
  3982. $sql = "UPDATE $lp_table SET force_commit = $force WHERE id = " . $this->get_id();
  3983. $res = Database::query($sql);
  3984. $this->force_commit = $force_return;
  3985. return $force_return;
  3986. } else {
  3987. if ($this->debug > 2) {
  3988. error_log('New LP - Problem in update_default_scorm_commit() - could not find LP ' . $this->get_id() . ' in DB', 0);
  3989. }
  3990. }
  3991. return -1;
  3992. }
  3993. /**
  3994. * Updates the order of learning paths (goes through all of them by order and fills the gaps)
  3995. * @return bool True on success, false on failure
  3996. */
  3997. public function update_display_order() {
  3998. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3999. $sql = "SELECT * FROM $lp_table ORDER BY display_order";
  4000. $res = Database::query($sql);
  4001. if ($res === false)
  4002. return false;
  4003. $lps = array ();
  4004. $lp_order = array ();
  4005. $num = Database :: num_rows($res);
  4006. // First check the order is correct, globally (might be wrong because
  4007. // of versions < 1.8.4).
  4008. if ($num > 0) {
  4009. $i = 1;
  4010. while ($row = Database :: fetch_array($res)) {
  4011. if ($row['display_order'] != $i) { // If we find a gap in the order, we need to fix it.
  4012. $need_fix = true;
  4013. $sql_u = "UPDATE $lp_table SET display_order = $i WHERE id = " . $row['id'];
  4014. $res_u = Database::query($sql_u);
  4015. }
  4016. $i++;
  4017. }
  4018. }
  4019. return true;
  4020. }
  4021. /**
  4022. * Updates the "prevent_reinit" value that enables control on reinitialising items on second view
  4023. * @return boolean True if prevent_reinit has been set to 'on', false otherwise (or 1 or 0 in this case)
  4024. */
  4025. public function update_reinit() {
  4026. if ($this->debug > 0) {
  4027. error_log('New LP - In learnpath::update_reinit()', 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['prevent_reinit'];
  4035. if ($force == 1) {
  4036. $force = 0;
  4037. } elseif ($force == 0) {
  4038. $force = 1;
  4039. }
  4040. $sql = "UPDATE $lp_table SET prevent_reinit = $force WHERE id = " . $this->get_id();
  4041. $res = Database::query($sql);
  4042. $this->prevent_reinit = $force;
  4043. return $force;
  4044. } else {
  4045. if ($this->debug > 2) {
  4046. error_log('New LP - Problem in update_reinit() - could not find LP ' . $this->get_id() . ' in DB', 0);
  4047. }
  4048. }
  4049. return -1;
  4050. }
  4051. /**
  4052. * Updates the "scorm_debug" value that shows or hide the debug window
  4053. * @return boolean True if scorm_debug has been set to 'on', false otherwise (or 1 or 0 in this case)
  4054. */
  4055. public function update_scorm_debug() {
  4056. if ($this->debug > 0) {
  4057. error_log('New LP - In learnpath::update_scorm_debug()', 0);
  4058. }
  4059. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  4060. $sql = "SELECT * FROM $lp_table WHERE id = " . $this->get_id();
  4061. $res = Database::query($sql);
  4062. if (Database :: num_rows($res) > 0) {
  4063. $row = Database :: fetch_array($res);
  4064. $force = $row['debug'];
  4065. if ($force == 1) {
  4066. $force = 0;
  4067. } elseif ($force == 0) {
  4068. $force = 1;
  4069. }
  4070. $sql = "UPDATE $lp_table SET debug = $force WHERE id = " . $this->get_id();
  4071. $res = Database::query($sql);
  4072. $this->scorm_debug = $force;
  4073. return $force;
  4074. } else {
  4075. if ($this->debug > 2) {
  4076. error_log('New LP - Problem in update_scorm_debug() - could not find LP ' . $this->get_id() . ' in DB', 0);
  4077. }
  4078. }
  4079. return -1;
  4080. }
  4081. /**
  4082. * Function that makes a call to the function sort_tree_array and create_tree_array
  4083. * @author Kevin Van Den Haute
  4084. * @param array
  4085. */
  4086. public function tree_array($array) {
  4087. if ($this->debug > 1) {
  4088. error_log('New LP - In learnpath::tree_array()', 0);
  4089. }
  4090. $array = $this->sort_tree_array($array);
  4091. $this->create_tree_array($array);
  4092. }
  4093. /**
  4094. * Creates an array with the elements of the learning path tree in it
  4095. *
  4096. * @author Kevin Van Den Haute
  4097. * @param array $array
  4098. * @param int $parent
  4099. * @param int $depth
  4100. * @param array $tmp
  4101. */
  4102. public function create_tree_array($array, $parent = 0, $depth = -1, $tmp = array ()) {
  4103. if ($this->debug > 1) {
  4104. error_log('New LP - In learnpath::create_tree_array())', 0);
  4105. }
  4106. if (is_array($array)) {
  4107. for ($i = 0; $i < count($array); $i++) {
  4108. if ($array[$i]['parent_item_id'] == $parent) {
  4109. if (!in_array($array[$i]['parent_item_id'], $tmp)) {
  4110. $tmp[] = $array[$i]['parent_item_id'];
  4111. $depth++;
  4112. }
  4113. $preq = (empty($array[$i]['prerequisite']) ? '' : $array[$i]['prerequisite']);
  4114. $this->arrMenu[] = array (
  4115. 'id' => $array[$i]['id'],
  4116. 'item_type' => $array[$i]['item_type'],
  4117. 'title' => $array[$i]['title'],
  4118. 'path' => $array[$i]['path'],
  4119. 'description' => $array[$i]['description'],
  4120. 'parent_item_id' => $array[$i]['parent_item_id'],
  4121. 'previous_item_id' => $array[$i]['previous_item_id'],
  4122. 'next_item_id' => $array[$i]['next_item_id'],
  4123. 'min_score' => $array[$i]['min_score'],
  4124. 'max_score' => $array[$i]['max_score'],
  4125. 'mastery_score' => $array[$i]['mastery_score'],
  4126. 'display_order' => $array[$i]['display_order'],
  4127. 'prerequisite' => $preq,
  4128. 'depth' => $depth,
  4129. 'audio' => $array[$i]['audio']
  4130. );
  4131. $this->create_tree_array($array, $array[$i]['id'], $depth, $tmp);
  4132. }
  4133. }
  4134. }
  4135. }
  4136. /**
  4137. * Sorts a multi dimensional array by parent id and display order
  4138. * @author Kevin Van Den Haute
  4139. *
  4140. * @param array $array (array with al the learning path items in it)
  4141. *
  4142. * @return array
  4143. */
  4144. public function sort_tree_array($array) {
  4145. foreach ($array as $key => $row) {
  4146. $parent[$key] = $row['parent_item_id'];
  4147. $position[$key] = $row['display_order'];
  4148. }
  4149. if (count($array) > 0)
  4150. array_multisort($parent, SORT_ASC, $position, SORT_ASC, $array);
  4151. return $array;
  4152. }
  4153. /**
  4154. * Function that creates a table structure with a learning path his modules, chapters and documents.
  4155. * Also the actions for the modules, chapters and documents are in this table.
  4156. * @author Kevin Van Den Haute
  4157. * @param int $lp_id
  4158. * @return string
  4159. */
  4160. public function overview() {
  4161. $is_allowed_to_edit = api_is_allowed_to_edit(null,true);
  4162. if ($this->debug > 0) {
  4163. error_log('New LP - In learnpath::overview()', 0);
  4164. }
  4165. global $charset, $_course;
  4166. $_SESSION['gradebook'] = Security :: remove_XSS($_GET['gradebook']);
  4167. $return = '';
  4168. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  4169. $sql = "SELECT * FROM " . $tbl_lp_item . "
  4170. WHERE lp_id = " . $this->lp_id;
  4171. $result = Database::query($sql);
  4172. $arrLP = array ();
  4173. while ($row = Database :: fetch_array($result)) {
  4174. $row['title'] = Security :: remove_XSS($row['title']);
  4175. $row['description'] = Security :: remove_XSS($row['description']);
  4176. $arrLP[] = array (
  4177. 'id' => $row['id'],
  4178. 'item_type' => $row['item_type'],
  4179. 'title' => $row['title'],
  4180. 'path' => $row['path'],
  4181. 'description' => $row['description'],
  4182. 'parent_item_id' => $row['parent_item_id'],
  4183. 'previous_item_id' => $row['previous_item_id'],
  4184. 'next_item_id' => $row['next_item_id'],
  4185. 'max_score' => $row['max_score'],
  4186. 'min_score' => $row['min_score'],
  4187. 'mastery_score' => $row['mastery_score'],
  4188. 'prerequisite' => $row['prerequisite'],
  4189. 'display_order' => $row['display_order'],
  4190. 'audio' => $row['audio']
  4191. );
  4192. }
  4193. $this->tree_array($arrLP);
  4194. $arrLP = $this->arrMenu;
  4195. unset ($this->arrMenu);
  4196. if ($is_allowed_to_edit) {
  4197. $token = Security::get_token();
  4198. $gradebook = Security :: remove_XSS($_GET['gradebook']);
  4199. $return .= '<div class="actions">';
  4200. $return .= '<a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&amp;gradebook=' . $gradebook . '&amp;action=build&amp;lp_id=' . $this->lp_id . '" title="' . get_lang('Build') . '">' . Display :: return_icon('build_learnpath.png', get_lang('Build'),'','32').'</a>';
  4201. $return .= '<span>' . Display :: return_icon('move_learnpath_na.png', get_lang('BasicOverview'),'','32').'</span>';
  4202. $return .= '<a href="lp_controller.php?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&action=view&lp_id=' . $this->lp_id . '">' . Display :: return_icon('view_left_right.png', get_lang('Display'),'','32').'</a>';
  4203. $return .= ' '.Display :: return_icon('i.gif');
  4204. $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') . '">
  4205. '. Display :: return_icon('new_learnigpath_object.png', get_lang('NewStep'),'','32').'</a>';
  4206. $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') . '">
  4207. '. Display :: return_icon('add_learnpath_section.png', get_lang('NewChapter'),'','32').'</a>';
  4208. $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('settings.png', get_lang('CourseSettings'),'','32').'</a>';
  4209. $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('upload_audio.png', get_lang('UpdateAllAudioFragments'),'','32').'</a>';
  4210. $return .= '</div>';
  4211. }
  4212. // we need to start a form when we want to update all the mp3 files
  4213. if ($_GET['updateaudio'] == 'true' AND count($arrLP) <> 0) {
  4214. $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">';
  4215. $return .= Display :: display_warning_message(get_lang('LeaveEmptyToKeepCurrentFile'));
  4216. }
  4217. $return .= '<table class="data_table">' . "\n";
  4218. $return .= "\t" . '<tr>' . "\n";
  4219. $return .= "\t" . '<th width="60%">' . get_lang('Title') . '</th>' . "\n";
  4220. //$return .= "\t" . '<th>'.get_lang('Description').'</th>' . "\n";
  4221. $return .= "\t" . '<th>' . get_lang('Audio') . '</th>' . "\n";
  4222. $return .= "\t" . '<th>' . get_lang('Move') . '</th>' . "\n";
  4223. $return .= "\t" . '<th>' . get_lang('Actions') . '</th>' . "\n";
  4224. $return .= "\t" . '</tr>' . "\n";
  4225. for ($i = 0; $i < count($arrLP); $i++) {
  4226. $title = $arrLP[$i]['title'];
  4227. if ($arrLP[$i]['description'] == '')
  4228. $arrLP[$i]['description'] = '&nbsp;';
  4229. if (($i % 2) == 0) {
  4230. $oddclass = 'row_odd';
  4231. } else {
  4232. $oddclass = 'row_even';
  4233. }
  4234. $return .= "\t" . '<tr class="' . $oddclass . '">' . "\n";
  4235. $icon_name = str_replace(' ', '', $arrLP[$i]['item_type']);
  4236. if (file_exists('../img/lp_' . $icon_name . '.png')) {
  4237. $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";
  4238. } else {
  4239. if (file_exists('../img/lp_' . $icon_name . '.gif')) {
  4240. $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";
  4241. } else {
  4242. //$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";
  4243. $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";
  4244. }
  4245. }
  4246. //$return .= "\t\t" . '<td>' . stripslashes($arrLP[$i]['description']) . '</td>' . "\n";
  4247. // The audio column.
  4248. $return .= "\t\t" . '<td align="center">';
  4249. if (!$_GET['updateaudio'] OR $_GET['updateaudio'] <> 'true') {
  4250. if (!empty ($arrLP[$i]['audio'])) {
  4251. $return .= '<span id="container' . $i . '"><a href="http://www.macromedia.com/go/getflashplayer">Get the Flash Player</a> to see this player.</span>';
  4252. $return .= '<script type="text/javascript" src="../inc/lib/mediaplayer/swfobject.js"></script>';
  4253. $return .= '<script type="text/javascript">
  4254. var s1 = new SWFObject("../inc/lib/mediaplayer/player.swf","ply","250","20","9","#FFFFFF");
  4255. s1.addParam("allowscriptaccess","always");
  4256. s1.addParam("flashvars","file=../../courses/' . $_course['path'] . '/document/audio/' . $arrLP[$i]['audio'] . '");
  4257. s1.write("container' . $i . '");
  4258. </script>';
  4259. } else {
  4260. $return .= ' - ';
  4261. }
  4262. } else {
  4263. if ($arrLP[$i]['item_type'] != 'dokeos_chapter' && $arrLP[$i]['item_type'] != 'dokeos_module' && $arrLP[$i]['item_type'] != 'dir') {
  4264. $return .= ' <input type="file" name="mp3file' . $arrLP[$i]['id'] . '" id="mp3file" />';
  4265. if (!empty ($arrLP[$i]['audio'])) {
  4266. $return .= '<br />'.Security::remove_XSS($arrLP[$i]['audio']).'<input type="checkbox" name="removemp3' . $arrLP[$i]['id'] . '" id="checkbox' . $arrLP[$i]['id'] . '" />' . get_lang('RemoveAudio');
  4267. }
  4268. }
  4269. }
  4270. $return .= '</td>';
  4271. if ($is_allowed_to_edit) {
  4272. $return .= '<td align="center">';
  4273. if ($arrLP[$i]['previous_item_id'] != 0) {
  4274. $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.'">';
  4275. $return .= '<img style="margin:1px;" alt="" src="../img/arrow_up_' . ($arrLP[$i]['depth'] % 3) . '.gif" title="' . get_lang('MoveUp') . '"/>';
  4276. $return .= '</a>';
  4277. } else
  4278. $return .= '<img alt="" src="../img/blanco.png" title="" />';
  4279. if ($arrLP[$i]['next_item_id'] != 0) {
  4280. $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.'">';
  4281. $return .= '<img style="margin:1px;" src="../img/arrow_down_' . ($arrLP[$i]['depth'] % 3) . '.gif" title="' . get_lang('MoveDown') . '" />';
  4282. $return .= '</a>';
  4283. } else
  4284. $return .= '<img alt="" src="../img/blanco.png" title="" />';
  4285. $return .= '</td>';
  4286. $return .= '<td align="center">';
  4287. if ($arrLP[$i]['item_type'] != 'dokeos_chapter' && $arrLP[$i]['item_type'] != 'dokeos_module') {
  4288. $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'] . '">';
  4289. $return .= '<img style="margin:1px;" alt="" src="../img/edit.gif" title="' . get_lang('_edit_learnpath_module') . '" />';
  4290. $return .= '</a>' . "\n";
  4291. } else {
  4292. $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'] . '">';
  4293. $return .= '<img style="margin:1px;" alt="" src="../img/edit.gif" title="' . get_lang('_edit_learnpath_module') . '" />';
  4294. $return .= '</a>' . "\n";
  4295. }
  4296. $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) . '\');">';
  4297. $return .= '<img style="margin:1px;" alt="" src="../img/delete.gif" title="' . get_lang('_delete_learnpath_module') . '" />';
  4298. $return .= '</a>' . "\n";
  4299. $return .= '</td>';
  4300. }
  4301. $return .= '</tr>';
  4302. }
  4303. if (count($arrLP) == 0) {
  4304. $return .= "\t" . '<tr>' . "\n";
  4305. $return .= "\t\t" . '<td colspan="4">' . get_lang('NoItemsInLp') . '</td>' . "\n";
  4306. $return .= "\t" . '</tr>' . "\n";
  4307. }
  4308. $return .= '</table>' . "\n";
  4309. // We need to close the form when we are updating the mp3 files.
  4310. if ($_GET['updateaudio'] == 'true') {
  4311. $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?
  4312. }
  4313. // We need to close the form when we are updating the mp3 files.
  4314. if ($_GET['updateaudio'] == 'true' && count($arrLP) != 0) {
  4315. $return .= '</form>';
  4316. }
  4317. return $return;
  4318. }
  4319. /**
  4320. * This function builds the action menu
  4321. * @return void
  4322. */
  4323. public function build_action_menu() {
  4324. $gradebook = Security :: remove_XSS($_GET['gradebook']);
  4325. echo '<div class="actions">';
  4326. //echo '<span>'.Display::return_icon('build_learnpath.png','-','','32').' '.get_lang('Build').'</span>';
  4327. echo '<span>' . Display :: return_icon('build_learnpath_na.png', get_lang('Build'),'','32').'</span>';
  4328. echo '<a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&amp;gradebook=' . $gradebook . '&amp;action=admin_view&amp;lp_id=' . $_SESSION['oLP']->lp_id . '" title="' . get_lang('BasicOverview') . '">' . Display :: return_icon('move_learnpath.png', get_lang('BasicOverview'),'','32').'</a>';
  4329. echo '<a href="lp_controller.php?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&amp;gradebook=' . $gradebook . '&action=view&lp_id=' . $_SESSION['oLP']->lp_id . '">' . Display :: return_icon('view_left_right.png', get_lang('Display'),'','32').'</a> ';
  4330. Display :: display_icon('i.gif');
  4331. echo '<a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&amp;gradebook=' . $gradebook . '&amp;action=add_item&amp;type=step&amp;lp_id=' . $_SESSION['oLP']->lp_id . '" title="' . get_lang('NewStep') . '">' . Display :: return_icon('new_learnigpath_object.png', get_lang('NewStep'),'','32').'</a>';
  4332. echo '<a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&amp;gradebook=' . $gradebook . '&amp;action=add_item&amp;type=chapter&amp;lp_id=' . $_SESSION['oLP']->lp_id . '" title="' . get_lang('NewChapter') . '">' . Display :: return_icon('add_learnpath_section.png', get_lang('NewChapter'),'','32').'</a>';
  4333. 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('settings.png', get_lang('CourseSettings'),'','32').'</a>';
  4334. 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('upload_audio.png', get_lang('UpdateAllAudioFragments'),'','32').'</a>';
  4335. echo '</div>';
  4336. }
  4337. /**
  4338. * This functions builds the LP tree based on data from the database.
  4339. * @return string
  4340. * @uses dtree.js :: necessary javascript for building this tree
  4341. */
  4342. public function build_tree() {
  4343. $return = "<script type=\"text/javascript\">\n";
  4344. $return .= "\tm = new dTree('m');\n\n";
  4345. $return .= "\tm.config.folderLinks = true;\n";
  4346. $return .= "\tm.config.useCookies = true;\n";
  4347. $return .= "\tm.config.useIcons = true;\n";
  4348. $return .= "\tm.config.useLines = true;\n";
  4349. $return .= "\tm.config.useSelection = true;\n";
  4350. $return .= "\tm.config.useStatustext = false;\n\n";
  4351. $menu = 0;
  4352. $parent = '';
  4353. $return .= "\tm.add(" . $menu . ", -1, '" . addslashes(Security::remove_XSS(($this->name))) . "');\n";
  4354. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  4355. $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
  4356. FROM " . $tbl_lp_item . "
  4357. WHERE lp_id = " . Database :: escape_string($this->lp_id);
  4358. $result = Database::query($sql);
  4359. $arrLP = array ();
  4360. while ($row = Database :: fetch_array($result)) {
  4361. $row['title'] = Security :: remove_XSS($row['title']);
  4362. $row['description'] = Security :: remove_XSS($row['description']);
  4363. $arrLP[] = array (
  4364. 'id' => $row['id'],
  4365. 'item_type' => $row['item_type'],
  4366. 'title' => $row['title'],
  4367. 'path' => $row['path'],
  4368. 'description' => $row['description'],
  4369. 'parent_item_id' => $row['parent_item_id'],
  4370. 'previous_item_id' => $row['previous_item_id'],
  4371. 'next_item_id' => $row['next_item_id'],
  4372. 'max_score' => $row['max_score'],
  4373. 'min_score' => $row['min_score'],
  4374. 'mastery_score' => $row['mastery_score'],
  4375. 'display_order' => $row['display_order']
  4376. );
  4377. }
  4378. $this->tree_array($arrLP);
  4379. $arrLP = $this->arrMenu;
  4380. unset ($this->arrMenu);
  4381. $title = '';
  4382. for ($i = 0; $i < count($arrLP); $i++) {
  4383. $title = addslashes($arrLP[$i]['title']);
  4384. $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;
  4385. $icon_name = str_replace(' ', '', $arrLP[$i]['item_type']);
  4386. if (file_exists('../img/lp_' . $icon_name . '.png')) {
  4387. $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";
  4388. } else
  4389. if (file_exists('../img/lp_' . $icon_name . '.gif')) {
  4390. $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";
  4391. } else {
  4392. $return .= "\tm.add(" . $arrLP[$i]['id'] . ", " . $arrLP[$i]['parent_item_id'] . ", '" . $title . "', '" . $menu_page . "', '', '', '../img/folder_document.gif', '../img/folder_document.gif');\n";
  4393. }
  4394. if ($menu < $arrLP[$i]['id'])
  4395. $menu = $arrLP[$i]['id'];
  4396. }
  4397. $return .= "\n\tdocument.write(m);\n";
  4398. $return .= "\t if(!m.selectedNode) m.s(1);";
  4399. $return .= "</script>\n";
  4400. return $return;
  4401. }
  4402. /**
  4403. * Create a new document //still needs some finetuning
  4404. * @param array $_course
  4405. * @return string
  4406. */
  4407. public function create_document($_course) {
  4408. global $charset;
  4409. $dir = isset ($_GET['dir']) ? $_GET['dir'] : $_POST['dir']; // Please, do not modify this dirname formatting.
  4410. if (strstr($dir, '..'))
  4411. $dir = '/';
  4412. if ($dir[0] == '.')
  4413. $dir = substr($dir, 1);
  4414. if ($dir[0] != '/')
  4415. $dir = '/' . $dir;
  4416. if ($dir[strlen($dir) - 1] != '/')
  4417. $dir .= '/';
  4418. $filepath = api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document' . $dir;
  4419. if (!is_dir($filepath)) {
  4420. $filepath = api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document/';
  4421. $dir = '/';
  4422. }
  4423. // stripslashes() before calling replace_dangerous_char() because $_POST['title']
  4424. // is already escaped twice when it gets here.
  4425. $title = replace_dangerous_char(stripslashes($_POST['title']));
  4426. $title = disable_dangerous_file($title);
  4427. $filename = $title;
  4428. $content = $_POST['content_lp'];
  4429. $tmp_filename = $filename;
  4430. $i = 0;
  4431. while (file_exists($filepath . $tmp_filename . '.html'))
  4432. $tmp_filename = $filename . '_' . ++ $i;
  4433. $filename = $tmp_filename . '.html';
  4434. $content = stripslashes(text_filter($content));
  4435. $content = str_replace(api_get_path(WEB_COURSE_PATH), api_get_path(REL_PATH) . 'courses/', $content);
  4436. // Change the path of mp3 to absolute.
  4437. // The first regexp deals with ../../../ urls.
  4438. $content = preg_replace("|(flashvars=\"file=)(\.+/)+|", "$1" . api_get_path(REL_COURSE_PATH) . $_course['path'] . '/document/', $content);
  4439. // The second regexp deals with audio/ urls.
  4440. $content = preg_replace("|(flashvars=\"file=)([^/]+)/|", "$1" . api_get_path(REL_COURSE_PATH) . $_course['path'] . '/document/$2/', $content);
  4441. // For flv player: To prevent edition problem with firefox, we have to use a strange tip (don't blame me please).
  4442. $content = str_replace('</body>', '<style type="text/css">body{}</style></body>', $content);
  4443. if (!file_exists($filepath . $filename)) {
  4444. if ($fp = @ fopen($filepath . $filename, 'w')) {
  4445. fputs($fp, $content);
  4446. fclose($fp);
  4447. $file_size = filesize($filepath . $filename);
  4448. $save_file_path = $dir . $filename;
  4449. $document_id = add_document($_course, $save_file_path, 'file', $file_size, $filename . '.html');
  4450. if ($document_id) {
  4451. api_item_property_update($_course, TOOL_DOCUMENT, $document_id, 'DocumentAdded', api_get_user_id(), null, null, null, null, api_get_session_id());
  4452. // Update parent folders.
  4453. //item_property_update_on_folder($_course, $_GET['dir'], $_user['user_id']);
  4454. $new_comment = (isset($_POST['comment'])) ? trim($_POST['comment']) : '';
  4455. $new_title = (isset($_POST['title'])) ? trim($_POST['title']) : '';
  4456. if ($new_comment || $new_title) {
  4457. $tbl_doc = Database :: get_course_table(TABLE_DOCUMENT);
  4458. $ct = '';
  4459. if ($new_comment)
  4460. $ct .= ", comment='" . $new_comment . "'";
  4461. if ($new_title)
  4462. $ct .= ", title='" . Database :: escape_string(htmlspecialchars($new_title, ENT_QUOTES, $charset)) . ".html '";
  4463. $sql_update = "
  4464. UPDATE " . $tbl_doc . "
  4465. SET " . substr($ct, 1) . "
  4466. WHERE id = " . $document_id;
  4467. Database::query($sql_update);
  4468. }
  4469. }
  4470. return $document_id;
  4471. }
  4472. }
  4473. }
  4474. /**
  4475. * Edit a document based on $_POST and $_GET parameters 'dir' and 'path'
  4476. * @param array $_course array
  4477. * @return void
  4478. */
  4479. public function edit_document($_course) {
  4480. global $_configuration;
  4481. $dir = isset ($_GET['dir']) ? $_GET['dir'] : $_POST['dir']; // Please, do not modify this dirname formatting.
  4482. if (strstr($dir, '..'))
  4483. $dir = '/';
  4484. if ($dir[0] == '.')
  4485. $dir = substr($dir, 1);
  4486. if ($dir[0] != '/')
  4487. $dir = '/' . $dir;
  4488. if ($dir[strlen($dir) - 1] != '/')
  4489. $dir .= '/';
  4490. $filepath = api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document' . $dir;
  4491. if (!is_dir($filepath)) {
  4492. $filepath = api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document/';
  4493. $dir = '/';
  4494. }
  4495. $table_doc = Database :: get_course_table(TABLE_DOCUMENT);
  4496. if (isset($_POST['path']) && !empty($_POST['path'])) {
  4497. $sql = "SELECT path
  4498. FROM " . $table_doc . "
  4499. WHERE id = " . Database::escape_string($_POST['path']);
  4500. $res = Database::query($sql);
  4501. $row = Database :: fetch_array($res);
  4502. $content = stripslashes($_POST['content_lp']);
  4503. $file = $filepath . $row['path'];
  4504. if ($fp = @ fopen($file, 'w')) {
  4505. $content = text_filter($content);
  4506. $content = str_replace(api_get_path(WEB_COURSE_PATH), $_configuration['url_append'] . '/courses/', $content);
  4507. // Change the path of mp3 to absolute.
  4508. // The first regexp deals with ../../../ urls.
  4509. $content = preg_replace("|(flashvars=\"file=)(\.+/)+|", "$1" . api_get_path(REL_COURSE_PATH) . $_course['path'] . '/document/', $content);
  4510. // The second regexp deals with audio/ urls.
  4511. $content = preg_replace("|(flashvars=\"file=)([^/]+)/|", "$1" . api_get_path(REL_COURSE_PATH) . $_course['path'] . '/document/$2/', $content);
  4512. fputs($fp, $content);
  4513. fclose($fp);
  4514. }
  4515. }
  4516. }
  4517. /**
  4518. * Displays the selected item, with a panel for manipulating the item
  4519. * @param int $item_id
  4520. * @param string $msg
  4521. * @return string
  4522. */
  4523. public function display_item($item_id, $iframe = true, $msg = '') {
  4524. global $_course; // It will disappear.
  4525. $return = '';
  4526. if (is_numeric($item_id)) {
  4527. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  4528. $tbl_doc = Database :: get_course_table(TABLE_DOCUMENT);
  4529. $sql = "SELECT lp.* FROM " . $tbl_lp_item . " as lp
  4530. WHERE lp.id = " . Database :: escape_string($item_id);
  4531. $result = Database::query($sql);
  4532. while ($row = Database :: fetch_array($result)) {
  4533. $_SESSION['parent_item_id'] = ($row['item_type'] == 'dokeos_chapter' || $row['item_type'] == 'dokeos_module' || $row['item_type'] == 'dir') ? $item_id : 0;
  4534. // Prevents wrong parent selection for document, see Bug#1251.
  4535. if ($row['item_type'] != 'dokeos_chapter' || $row['item_type'] != 'dokeos_module') {
  4536. $_SESSION['parent_item_id'] = $row['parent_item_id'];
  4537. }
  4538. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4539. $return .= '<div style="padding:10px;">';
  4540. if ($msg != '')
  4541. $return .= $msg;
  4542. $return .= '<p class="lp_title">' . $row['title'] . '</p>';
  4543. //$return .= '<p class="lp_text">' . ((trim($row['description']) == '') ? 'no description' : stripslashes($row['description'])) . '</p>';
  4544. //$return .= '<hr />';
  4545. switch ($row['item_type']) {
  4546. case TOOL_QUIZ:
  4547. if (!empty($row['path'])) {
  4548. require_once api_get_path(SYS_CODE_PATH).'exercice/exercise.class.php';
  4549. $exercise = new Exercise();
  4550. $exercise->read($row['path']);
  4551. // $exercise_url = api_get_path(WEB_CODE_PATH).'exercice/admin.php?exerciseId='.$exercise->id.'&'.api_get_cidReq().'&id_session='.api_get_session_id();
  4552. $return .=$exercise->description.'<br />';
  4553. //$return .=Display::url($exercise_url, $exercise_url).'<br />';*/
  4554. }
  4555. break;
  4556. case TOOL_DOCUMENT:
  4557. $tbl_doc = Database :: get_course_table(TABLE_DOCUMENT);
  4558. $sql_doc = "SELECT path FROM " . $tbl_doc . " WHERE id = " . Database :: escape_string($row['path']);
  4559. $result = Database::query($sql_doc);
  4560. $path_file = Database :: result($result, 0, 0);
  4561. $path_parts = pathinfo($path_file);
  4562. // TODO: Correct the following naive comparisons, also, htm extension is missing.
  4563. if (in_array($path_parts['extension'], array (
  4564. 'html',
  4565. 'txt',
  4566. 'png',
  4567. 'jpg',
  4568. 'JPG',
  4569. 'jpeg',
  4570. 'JPEG',
  4571. 'gif',
  4572. 'swf'
  4573. ))) {
  4574. $return .= $this->display_document($row['path'], true, true);
  4575. }
  4576. break;
  4577. }
  4578. $return .= '</div>';
  4579. }
  4580. }
  4581. return $return;
  4582. }
  4583. /**
  4584. * Shows the needed forms for editing a specific item
  4585. * @param int $item_id
  4586. * @return string
  4587. */
  4588. public function display_edit_item($item_id) {
  4589. global $_course; // It will disappear.
  4590. $return = '';
  4591. if (is_numeric($item_id)) {
  4592. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  4593. $sql = "SELECT *
  4594. FROM " . $tbl_lp_item . "
  4595. WHERE id = " . Database :: escape_string($item_id);
  4596. $res = Database::query($sql);
  4597. $row = Database :: fetch_array($res);
  4598. switch ($row['item_type']) {
  4599. case 'dokeos_chapter' :
  4600. case 'dir' :
  4601. case 'asset' :
  4602. case 'sco' :
  4603. if (isset ($_GET['view']) && $_GET['view'] == 'build') {
  4604. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4605. $return .= $this->display_item_form($row['item_type'], get_lang('EditCurrentChapter') . ' :', 'edit', $item_id, $row);
  4606. } else {
  4607. $return .= $this->display_item_small_form($row['item_type'], get_lang('EditCurrentChapter') . ' :', $row);
  4608. }
  4609. break;
  4610. case TOOL_DOCUMENT :
  4611. $tbl_doc = Database :: get_course_table(TABLE_DOCUMENT);
  4612. $sql_step = " SELECT lp.*, doc.path as dir
  4613. FROM " . $tbl_lp_item . " as lp
  4614. LEFT JOIN " . $tbl_doc . " as doc ON doc.id = lp.path
  4615. WHERE lp.id = " . Database :: escape_string($item_id);
  4616. $res_step = Database::query($sql_step);
  4617. $row_step = Database :: fetch_array($res_step);
  4618. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4619. $return .= $this->display_document_form('edit', $item_id, $row_step);
  4620. break;
  4621. case TOOL_LINK :
  4622. $link_id = (string) $row['path'];
  4623. if (ctype_digit($link_id)) {
  4624. $tbl_link = Database :: get_course_table(TABLE_LINK);
  4625. $sql_select = 'SELECT url FROM ' . $tbl_link . ' WHERE id = ' . Database :: escape_string($link_id);
  4626. $res_link = Database::query($sql_select);
  4627. $row_link = Database :: fetch_array($res_link);
  4628. if (is_array($row_link)) {
  4629. $row['url'] = $row_link['url'];
  4630. }
  4631. }
  4632. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4633. $return .= $this->display_link_form('edit', $item_id, $row);
  4634. break;
  4635. case 'dokeos_module' :
  4636. if (isset ($_GET['view']) && $_GET['view'] == 'build') {
  4637. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4638. $return .= $this->display_item_form($row['item_type'], get_lang('EditCurrentModule') . ' :', 'edit', $item_id, $row);
  4639. } else {
  4640. $return .= $this->display_item_small_form($row['item_type'], get_lang('EditCurrentModule') . ' :', $row);
  4641. }
  4642. break;
  4643. case TOOL_QUIZ :
  4644. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4645. $return .= $this->display_quiz_form('edit', $item_id, $row);
  4646. break;
  4647. case TOOL_HOTPOTATOES :
  4648. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4649. $return .= $this->display_hotpotatoes_form('edit', $item_id, $row);
  4650. break;
  4651. case TOOL_STUDENTPUBLICATION :
  4652. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4653. $return .= $this->display_student_publication_form('edit', $item_id, $row);
  4654. break;
  4655. case TOOL_FORUM :
  4656. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4657. $return .= $this->display_forum_form('edit', $item_id, $row);
  4658. break;
  4659. case TOOL_THREAD :
  4660. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4661. $return .= $this->display_thread_form('edit', $item_id, $row);
  4662. break;
  4663. }
  4664. }
  4665. return $return;
  4666. }
  4667. /**
  4668. * Function that displays a list with al the resources that could be added to the learning path
  4669. * @return string
  4670. */
  4671. public function display_resources() {
  4672. global $_course; // TODO: Don't use globals.
  4673. $return .= '<div class="sectiontitle">' . get_lang('CreateNewStep') . '</div>';
  4674. $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.
  4675. $return .= '<div class="sectiontitle">' . get_lang('UseAnExistingResource') . '</div>';
  4676. $return .= '<div class="sectioncomment">';
  4677. /* Get all the docs. */
  4678. $return .= $this->get_documents();
  4679. /* Get all the exercises. */
  4680. $return .= $this->get_exercises();
  4681. /* Get all the links. */
  4682. $return .= $this->get_links();
  4683. /* Get al the student publications. */
  4684. $return .= $this->get_student_publications();
  4685. /* Get al the forums. */
  4686. $return .= $this->get_forums();
  4687. $return .= '</div>';
  4688. return $return;
  4689. }
  4690. /**
  4691. * Returns the extension of a document
  4692. * @param string filename
  4693. * @return string Extension (part after the last dot)
  4694. */
  4695. public function get_extension($filename) {
  4696. $explode = explode('.', $filename);
  4697. return $explode[count($explode) - 1];
  4698. }
  4699. /**
  4700. * Displays a document by id
  4701. *
  4702. * @param unknown_type $id
  4703. * @return unknown
  4704. */
  4705. public function display_document($id, $show_title = false, $iframe = true, $edit_link = false) {
  4706. global $_course; // It is temporary.
  4707. $return = '';
  4708. $tbl_doc = Database :: get_course_table(TABLE_DOCUMENT);
  4709. $sql_doc = "SELECT * FROM " . $tbl_doc . "
  4710. WHERE id = " . $id;
  4711. $res_doc = Database::query($sql_doc);
  4712. $row_doc = Database :: fetch_array($res_doc);
  4713. //if ($show_title)
  4714. //$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>';
  4715. // TODO: Add a path filter.
  4716. if ($iframe) {
  4717. $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>';
  4718. } else {
  4719. $return .= file_get_contents(api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document' . $row_doc['path']);
  4720. }
  4721. return $return;
  4722. }
  4723. /**
  4724. * Return HTML form to add/edit a quiz
  4725. * @param string Action (add/edit)
  4726. * @param integer Item ID if already exists
  4727. * @param mixed Extra information (quiz ID if integer)
  4728. * @return string HTML form
  4729. */
  4730. public function display_quiz_form($action = 'add', $id = 0, $extra_info = '') {
  4731. global $charset;
  4732. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  4733. $tbl_quiz = Database :: get_course_table(TABLE_QUIZ_TEST);
  4734. if ($id != 0 && is_array($extra_info)) {
  4735. $item_title = stripslashes($extra_info['title']);
  4736. $item_description = stripslashes($extra_info['description']);
  4737. }
  4738. elseif (is_numeric($extra_info)) {
  4739. $sql_quiz = "
  4740. SELECT
  4741. title,
  4742. description
  4743. FROM " . $tbl_quiz . "
  4744. WHERE id = " . $extra_info;
  4745. $result = Database::query($sql_quiz);
  4746. $row = Database :: fetch_array($result);
  4747. $item_title = $row['title'];
  4748. $item_description = $row['description'];
  4749. } else {
  4750. $item_title = '';
  4751. $item_description = '';
  4752. }
  4753. $return = ' <div class="row">
  4754. <div class="form_header">';
  4755. if ($id != 0 && is_array($extra_info))
  4756. $parent = $extra_info['parent_item_id'];
  4757. else
  4758. $parent = 0;
  4759. $sql = "
  4760. SELECT *
  4761. FROM " . $tbl_lp_item . "
  4762. WHERE
  4763. lp_id = " . $this->lp_id;
  4764. $result = Database::query($sql);
  4765. $arrLP = array ();
  4766. while ($row = Database :: fetch_array($result)) {
  4767. $arrLP[] = array (
  4768. 'id' => $row['id'],
  4769. 'item_type' => $row['item_type'],
  4770. 'title' => $row['title'],
  4771. 'path' => $row['path'],
  4772. 'description' => $row['description'],
  4773. 'parent_item_id' => $row['parent_item_id'],
  4774. 'previous_item_id' => $row['previous_item_id'],
  4775. 'next_item_id' => $row['next_item_id'],
  4776. 'display_order' => $row['display_order'],
  4777. 'max_score' => $row['max_score'],
  4778. 'min_score' => $row['min_score'],
  4779. 'mastery_score' => $row['mastery_score'],
  4780. 'prerequisite' => $row['prerequisite'],
  4781. 'max_time_allowed' => $row['max_time_allowed']
  4782. );
  4783. }
  4784. $this->tree_array($arrLP);
  4785. $arrLP = $this->arrMenu;
  4786. unset ($this->arrMenu);
  4787. if ($action == 'add')
  4788. $return .= get_lang('CreateTheExercise') . '&nbsp;:' . "\n";
  4789. elseif ($action == 'move') $return .= get_lang('MoveTheCurrentExercise') . '&nbsp;:' . "\n";
  4790. else
  4791. $return .= get_lang('EditCurrentExecice') . '&nbsp;:' . "\n";
  4792. if (isset ($_GET['edit']) && $_GET['edit'] == 'true') {
  4793. $return .= Display :: return_warning_message('<p class="lp_title">' . get_lang('Warning') . ' !</p>' . get_lang('WarningEditingDocument'));
  4794. }
  4795. $return .= ' </div>
  4796. </div>';
  4797. $return .= '<div class="sectioncomment">';
  4798. $return .= '<form method="POST">' . "\n";
  4799. $return .= "\t" . '<table class="lp_form">' . "\n";
  4800. if ($action != 'move') {
  4801. $return .= "\t\t" . '<tr>' . "\n";
  4802. $return .= "\t\t\t" . '<td class="label"><label for="idTitle">' . get_lang('Title') . '</label></td>' . "\n";
  4803. $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";
  4804. $return .= "\t\t" . '</tr>' . "\n";
  4805. }
  4806. $return .= "\t\t" . '<tr>' . "\n";
  4807. $return .= "\t\t\t" . '<td class="label"><label for="idParent">' . get_lang('Parent') . '</label></td>' . "\n";
  4808. $return .= "\t\t\t" . '<td class="input">' . "\n";
  4809. $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">';
  4810. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
  4811. $arrHide = array (
  4812. $id
  4813. );
  4814. //$parent_item_id = $_SESSION['parent_item_id'];
  4815. for ($i = 0; $i < count($arrLP); $i++) {
  4816. if ($action != 'add') {
  4817. 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)) {
  4818. $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>';
  4819. } else {
  4820. $arrHide[] = $arrLP[$i]['id'];
  4821. }
  4822. } else {
  4823. if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
  4824. $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>';
  4825. }
  4826. }
  4827. if (is_array($arrLP)) {
  4828. reset($arrLP);
  4829. }
  4830. $return .= '</select>';
  4831. $return .= '</td>';
  4832. $return .= '</tr>';
  4833. $return .= '<tr>';
  4834. $return .= "\t\t\t" . '<td class="label"><label for="idPosition">' . get_lang('Position') . '</label></td>' . "\n";
  4835. $return .= "\t\t\t" . '<td class="input">' . "\n";
  4836. $return .= "\t\t\t\t" . '<select class="learnpath_item_form" style="width:100%;" id="idPosition" name="previous" size="1">';
  4837. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . get_lang('FirstPosition') . '</option>';
  4838. for ($i = 0; $i < count($arrLP); $i++) {
  4839. if ($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) {
  4840. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  4841. $selected = 'selected="selected" ';
  4842. elseif ($action == 'add') $selected = 'selected="selected" ';
  4843. else
  4844. $selected = '';
  4845. $return .= "\t\t\t\t\t" . '<option ' . $selected . 'value="' . $arrLP[$i]['id'] . '">' . get_lang('After') . ' "' . $arrLP[$i]['title'] . '"</option>';
  4846. }
  4847. }
  4848. $return .= "\t\t\t\t" . '</select>';
  4849. $return .= "\t\t\t" . '</td>' . "\n";
  4850. $return .= "\t\t" . '</tr>' . "\n";
  4851. if ($action != 'move') {
  4852. $id_prerequisite = 0;
  4853. if (is_array($arrLP)) {
  4854. foreach ($arrLP as $key => $value) {
  4855. if ($value['id'] == $id) {
  4856. $id_prerequisite = $value['prerequisite'];
  4857. break;
  4858. }
  4859. }
  4860. }
  4861. $arrHide = array ();
  4862. for ($i = 0; $i < count($arrLP); $i++) {
  4863. if ($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter') {
  4864. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  4865. $s_selected_position = $arrLP[$i]['id'];
  4866. elseif ($action == 'add') $s_selected_position = 0;
  4867. $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
  4868. }
  4869. }
  4870. /*// Commented the prerequisites, only visible in edit (exercise).
  4871. $return .= "\t\t" . '<tr>' . "\n";
  4872. $return .= "\t\t\t" . '<td class="label"><label for="idPrerequisites">'.get_lang('Prerequisites').'</label></td>' . "\n";
  4873. $return .= "\t\t\t" . '<td class="input"><select name="prerequisites" id="prerequisites" class="learnpath_item_form"><option value="0">'.get_lang('NoPrerequisites').'</option>';
  4874. foreach($arrHide as $key => $value){
  4875. if($key==$s_selected_position && $action == 'add'){
  4876. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  4877. }
  4878. elseif($key==$id_prerequisite && $action == 'edit'){
  4879. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  4880. }
  4881. else{
  4882. $return .= '<option value="'.$key.'">'.$value['value'].'</option>';
  4883. }
  4884. }
  4885. $return .= "</select></td>";
  4886. */
  4887. $return .= "\t\t" . '</tr>' . "\n";
  4888. /*$return .= "\t\t" . '<tr>' . "\n";
  4889. $return .= "\t\t\t" . '<td class="label"><label for="maxTimeAllowed">' . get_lang('MaxTimeAllowed') . '</label></td>' . "\n";
  4890. $return .= "\t\t\t" . '<td class="input"><input name="maxTimeAllowed" style="width:98%;" id="maxTimeAllowed" value="' . $extra_info['max_time_allowed'] . '" /></td>';
  4891. // Remove temporarily the test description.
  4892. //$return .= "\t\t\t" . '<td class="label"><label for="idDescription">'.get_lang('Description').' :</label></td>' . "\n";
  4893. //$return .= "\t\t\t" . '<td class="input"><textarea id="idDescription" name="description" rows="4">' . $item_description . '</textarea></td>' . "\n";
  4894. $return .= "\t\t" . '</tr>' . "\n"; */
  4895. }
  4896. $return .= "\t\t" . '<tr>' . "\n";
  4897. if ($action == 'add') {
  4898. $return .= '<td>&nbsp;</td><td><button class="save" name="submit_button" type="submit">' . get_lang('AddExercise') . '</button></td>';
  4899. } else {
  4900. $return .= '<td>&nbsp;</td><td><button class="save" name="submit_button" type="submit">' . get_lang('EditCurrentExecice') . '</button></td>';
  4901. }
  4902. $return .= "\t\t" . '</tr>' . "\n";
  4903. $return .= "\t" . '</table>' . "\n";
  4904. if ($action == 'move') {
  4905. $return .= "\t" . '<input name="title" type="hidden" value="' . $item_title . '" />' . "\n";
  4906. $return .= "\t" . '<input name="description" type="hidden" value="' . $item_description . '" />' . "\n";
  4907. }
  4908. if (is_numeric($extra_info)) {
  4909. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info . '" />' . "\n";
  4910. }
  4911. elseif (is_array($extra_info)) {
  4912. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />' . "\n";
  4913. }
  4914. $return .= "\t" . '<input name="type" type="hidden" value="' . TOOL_QUIZ . '" />' . "\n";
  4915. $return .= "\t" . '<input name="post_time" type="hidden" value="' . time() . '" />' . "\n";
  4916. $return .= '</form>' . "\n";
  4917. $return .= '</div>' . "\n";
  4918. return $return;
  4919. }
  4920. /**
  4921. * Addition of Hotpotatoes tests
  4922. * @param string Action
  4923. * @param integer Internal ID of the item
  4924. * @param mixed Extra information - can be an array with title and description indexes
  4925. * @return string HTML structure to display the hotpotatoes addition formular
  4926. */
  4927. public function display_hotpotatoes_form($action = 'add', $id = 0, $extra_info = '') {
  4928. global $charset;
  4929. $uploadPath = DIR_HOTPOTATOES; //defined in main_api
  4930. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  4931. if ($id != 0 && is_array($extra_info)) {
  4932. $item_title = stripslashes($extra_info['title']);
  4933. $item_description = stripslashes($extra_info['description']);
  4934. }
  4935. elseif (is_numeric($extra_info)) {
  4936. $TBL_DOCUMENT = Database :: get_course_table(TABLE_DOCUMENT);
  4937. $sql_hot = "SELECT * FROM " . $TBL_DOCUMENT . "
  4938. WHERE path LIKE '" . $uploadPath . "/%/%htm%'
  4939. AND id = " . (int) $extra_info . " ORDER BY id ASC";
  4940. $res_hot = Database::query($sql_hot);
  4941. $row = Database :: fetch_array($res_hot);
  4942. $item_title = $row['title'];
  4943. $item_description = $row['description'];
  4944. if (!empty ($row['comment'])) {
  4945. $item_title = $row['comment'];
  4946. }
  4947. } else {
  4948. $item_title = '';
  4949. $item_description = '';
  4950. }
  4951. $return = '<div style="margin:3px 12px;">';
  4952. if ($id != 0 && is_array($extra_info))
  4953. $parent = $extra_info['parent_item_id'];
  4954. else
  4955. $parent = 0;
  4956. $sql = "
  4957. SELECT *
  4958. FROM " . $tbl_lp_item . "
  4959. WHERE
  4960. lp_id = " . $this->lp_id;
  4961. $result = Database::query($sql);
  4962. $arrLP = array ();
  4963. while ($row = Database :: fetch_array($result)) {
  4964. $arrLP[] = array (
  4965. 'id' => $row['id'],
  4966. 'item_type' => $row['item_type'],
  4967. 'title' => $row['title'],
  4968. 'path' => $row['path'],
  4969. 'description' => $row['description'],
  4970. 'parent_item_id' => $row['parent_item_id'],
  4971. 'previous_item_id' => $row['previous_item_id'],
  4972. 'next_item_id' => $row['next_item_id'],
  4973. 'display_order' => $row['display_order'],
  4974. 'max_score' => $row['max_score'],
  4975. 'min_score' => $row['min_score'],
  4976. 'mastery_score' => $row['mastery_score'],
  4977. 'prerequisite' => $row['prerequisite'],
  4978. 'max_time_allowed' => $row['max_time_allowed']
  4979. );
  4980. }
  4981. $this->tree_array($arrLP);
  4982. $arrLP = $this->arrMenu;
  4983. unset ($this->arrMenu);
  4984. if ($action == 'add')
  4985. $return .= '<p class="lp_title">' . get_lang('CreateTheExercise') . '&nbsp;:</p>' . "\n";
  4986. elseif ($action == 'move') $return .= '<p class="lp_title">' . get_lang('MoveTheCurrentExercise') . '&nbsp;:</p>' . "\n";
  4987. else
  4988. $return .= '<p class="lp_title">' . get_lang('EditCurrentExecice') . '&nbsp;:</p>' . "\n";
  4989. if (isset ($_GET['edit']) && $_GET['edit'] == 'true') {
  4990. $return .= Display :: return_warning_message('<p class="lp_title">' . get_lang('Warning') . ' !</p>' . get_lang('WarningEditingDocument'));
  4991. }
  4992. $return .= '<form method="POST">' . "\n";
  4993. $return .= "\t" . '<table cellpadding="0" cellspacing="0" class="lp_form">' . "\n";
  4994. $return .= "\t\t" . '<tr>' . "\n";
  4995. $return .= "\t\t\t" . '<td class="label"><label for="idParent">' . get_lang('Parent') . ' :</label></td>' . "\n";
  4996. $return .= "\t\t\t" . '<td class="input">' . "\n";
  4997. $return .= "\t\t\t\t" . '<select id="idParent" name="parent" onChange="javascript: load_cbo(this.value);" size="1">';
  4998. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
  4999. $arrHide = array (
  5000. $id
  5001. );
  5002. if (count($arrLP) > 0) {
  5003. for ($i = 0; $i < count($arrLP); $i++) {
  5004. if ($action != 'add') {
  5005. 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)) {
  5006. $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>';
  5007. } else {
  5008. $arrHide[] = $arrLP[$i]['id'];
  5009. }
  5010. } else {
  5011. if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
  5012. $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>';
  5013. }
  5014. }
  5015. reset($arrLP);
  5016. }
  5017. $return .= "\t\t\t\t" . '</select>';
  5018. $return .= "\t\t\t" . '</td>' . "\n";
  5019. $return .= "\t\t" . '</tr>' . "\n";
  5020. $return .= "\t\t" . '<tr>' . "\n";
  5021. $return .= "\t\t\t" . '<td class="label"><label for="idPosition">' . get_lang('Position') . ' :</label></td>' . "\n";
  5022. $return .= "\t\t\t" . '<td class="input">' . "\n";
  5023. $return .= "\t\t\t\t" . '<select id="idPosition" name="previous" size="1">';
  5024. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . get_lang('FirstPosition') . '</option>';
  5025. for ($i = 0; $i < count($arrLP); $i++) {
  5026. if ($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) {
  5027. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5028. $selected = 'selected="selected" ';
  5029. elseif ($action == 'add') $selected = 'selected="selected" ';
  5030. else
  5031. $selected = '';
  5032. $return .= "\t\t\t\t\t" . '<option ' . $selected . 'value="' . $arrLP[$i]['id'] . '">' . get_lang('After') . ' "' . $arrLP[$i]['title'] . '"</option>';
  5033. }
  5034. }
  5035. $return .= "\t\t\t\t" . '</select>';
  5036. $return .= "\t\t\t" . '</td>' . "\n";
  5037. $return .= "\t\t" . '</tr>' . "\n";
  5038. if ($action != 'move') {
  5039. $return .= "\t\t" . '<tr>' . "\n";
  5040. $return .= "\t\t\t" . '<td class="label"><label for="idTitle">' . get_lang('Title') . ' :</label></td>' . "\n";
  5041. $return .= "\t\t\t" . '<td class="input"><input id="idTitle" name="title" type="text" value="' . $item_title . '" /></td>' . "\n";
  5042. $return .= "\t\t" . '</tr>' . "\n";
  5043. $id_prerequisite = 0;
  5044. if (is_array($arrLP) && count($arrLP) > 0) {
  5045. foreach ($arrLP as $key => $value) {
  5046. if ($value['id'] == $id) {
  5047. $id_prerequisite = $value['prerequisite'];
  5048. break;
  5049. }
  5050. }
  5051. $arrHide = array ();
  5052. for ($i = 0; $i < count($arrLP); $i++) {
  5053. if ($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter') {
  5054. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5055. $s_selected_position = $arrLP[$i]['id'];
  5056. elseif ($action == 'add') $s_selected_position = 0;
  5057. $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
  5058. }
  5059. }
  5060. }
  5061. $return .= "\t\t" . '<tr>' . "\n";
  5062. //$return .= "\t\t\t" . '<td class="label"><label for="idPrerequisites">'.get_lang('Prerequisites').' :</label></td>' . "\n";
  5063. //$return .= "\t\t\t" . '<td class="input"><select name="prerequisites" id="prerequisites"><option value="0">'.get_lang('NoPrerequisites').'</option>';
  5064. foreach ($arrHide as $key => $value) {
  5065. if ($key == $s_selected_position && $action == 'add') {
  5066. $return .= '<option value="' . $key . '" selected="selected">' . $value['value'] . '</option>';
  5067. }
  5068. elseif ($key == $id_prerequisite && $action == 'edit') {
  5069. $return .= '<option value="' . $key . '" selected="selected">' . $value['value'] . '</option>';
  5070. } else {
  5071. $return .= '<option value="' . $key . '">' . $value['value'] . '</option>';
  5072. }
  5073. }
  5074. $return .= "</select></td>";
  5075. $return .= "\t\t" . '</tr>' . "\n";
  5076. $return .= "\t\t" . '<tr>' . "\n";
  5077. $return .= "\t\t" . '</tr>' . "\n";
  5078. }
  5079. $return .= "\t\t" . '<tr>' . "\n";
  5080. $return .= "\t\t\t" . '<td>&nbsp; </td><td><button class="save" name="submit_button" action="edit" type="submit">' . get_lang('SaveHotpotatoes') . '</button></td>' . "\n";
  5081. $return .= "\t\t" . '</tr>' . "\n";
  5082. $return .= "\t" . '</table>' . "\n";
  5083. if ($action == 'move') {
  5084. $return .= "\t" . '<input name="title" type="hidden" value="' . $item_title . '" />' . "\n";
  5085. $return .= "\t" . '<input name="description" type="hidden" value="' . $item_description . '" />' . "\n";
  5086. }
  5087. if (is_numeric($extra_info)) {
  5088. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info . '" />' . "\n";
  5089. }
  5090. elseif (is_array($extra_info)) {
  5091. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />' . "\n";
  5092. }
  5093. $return .= "\t" . '<input name="type" type="hidden" value="' . TOOL_HOTPOTATOES . '" />' . "\n";
  5094. $return .= "\t" . '<input name="post_time" type="hidden" value="' . time() . '" />' . "\n";
  5095. $return .= '</form>' . "\n";
  5096. $return .= '</div>' . "\n";
  5097. return $return;
  5098. }
  5099. /**
  5100. * Return the form to display the forum edit/add option
  5101. * @param string Action (add/edit)
  5102. * @param integer ID of the lp_item if already exists
  5103. * @param mixed Forum ID or title
  5104. * @return string HTML form
  5105. */
  5106. public function display_forum_form($action = 'add', $id = 0, $extra_info = '') {
  5107. global $charset;
  5108. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  5109. $tbl_forum = Database :: get_course_table(TABLE_FORUM);
  5110. if ($id != 0 && is_array($extra_info)) {
  5111. $item_title = stripslashes($extra_info['title']);
  5112. }
  5113. elseif (is_numeric($extra_info)) {
  5114. $sql_forum = "
  5115. SELECT
  5116. forum_title as title, forum_comment as comment
  5117. FROM " . $tbl_forum . "
  5118. WHERE forum_id = " . $extra_info;
  5119. $result = Database::query($sql_forum);
  5120. $row = Database :: fetch_array($result);
  5121. $item_title = $row['title'];
  5122. $item_description = $row['comment'];
  5123. } else {
  5124. $item_title = '';
  5125. $item_description = '';
  5126. }
  5127. $return = ' <div class="row">
  5128. <div class="form_header">';
  5129. if ($id != 0 && is_array($extra_info))
  5130. $parent = $extra_info['parent_item_id'];
  5131. else
  5132. $parent = 0;
  5133. $sql = "
  5134. SELECT *
  5135. FROM " . $tbl_lp_item . "
  5136. WHERE
  5137. lp_id = " . $this->lp_id;
  5138. $result = Database::query($sql);
  5139. $arrLP = array ();
  5140. while ($row = Database :: fetch_array($result)) {
  5141. $arrLP[] = array (
  5142. 'id' => $row['id'],
  5143. 'item_type' => $row['item_type'],
  5144. 'title' => $row['title'],
  5145. 'path' => $row['path'],
  5146. 'description' => $row['description'],
  5147. 'parent_item_id' => $row['parent_item_id'],
  5148. 'previous_item_id' => $row['previous_item_id'],
  5149. 'next_item_id' => $row['next_item_id'],
  5150. 'display_order' => $row['display_order'],
  5151. 'max_score' => $row['max_score'],
  5152. 'min_score' => $row['min_score'],
  5153. 'mastery_score' => $row['mastery_score'],
  5154. 'prerequisite' => $row['prerequisite']
  5155. );
  5156. }
  5157. $this->tree_array($arrLP);
  5158. $arrLP = $this->arrMenu;
  5159. unset ($this->arrMenu);
  5160. if ($action == 'add')
  5161. $return .= get_lang('CreateTheForum') . '&nbsp;:' . "\n";
  5162. elseif ($action == 'move') $return .= get_lang('MoveTheCurrentForum') . '&nbsp;:' . "\n";
  5163. else
  5164. $return .= get_lang('EditCurrentForum') . '&nbsp;:' . "\n";
  5165. $return .= ' </div>
  5166. </div>';
  5167. $return .= '<div class="sectioncomment">';
  5168. $return .= '<form method="POST">' . "\n";
  5169. $return .= "\t" . '<table class="lp_form">' . "\n";
  5170. if ($action != 'move') {
  5171. $return .= "\t\t" . '<tr>' . "\n";
  5172. $return .= "\t\t\t" . '<td class="label"><label for="idTitle">' . get_lang('Title') . '</label></td>' . "\n";
  5173. $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";
  5174. $return .= "\t\t" . '</tr>' . "\n";
  5175. }
  5176. $return .= "\t\t" . '<tr>' . "\n";
  5177. $return .= "\t\t\t" . '<td class="label"><label for="idParent">' . get_lang('Parent') . '</label></td>' . "\n";
  5178. $return .= "\t\t\t" . '<td class="input">' . "\n";
  5179. $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">';
  5180. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
  5181. $arrHide = array (
  5182. $id
  5183. );
  5184. //$parent_item_id = $_SESSION['parent_item_id'];
  5185. for ($i = 0; $i < count($arrLP); $i++) {
  5186. if ($action != 'add') {
  5187. 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)) {
  5188. $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>';
  5189. } else {
  5190. $arrHide[] = $arrLP[$i]['id'];
  5191. }
  5192. } else {
  5193. if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
  5194. $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>';
  5195. }
  5196. }
  5197. if (is_array($arrLP)) {
  5198. reset($arrLP);
  5199. }
  5200. $return .= "\t\t\t\t" . '</select>';
  5201. $return .= "\t\t\t" . '</td>' . "\n";
  5202. $return .= "\t\t" . '</tr>' . "\n";
  5203. $return .= "\t\t" . '<tr>' . "\n";
  5204. $return .= "\t\t\t" . '<td class="label"><label for="idPosition">' . get_lang('Position') . '</label></td>' . "\n";
  5205. $return .= "\t\t\t" . '<td class="input">' . "\n";
  5206. $return .= "\t\t\t\t" . '<select id="idPosition" name="previous" style="width:100%;" size="1" class="learnpath_item_form">';
  5207. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . get_lang('FirstPosition') . '</option>';
  5208. for ($i = 0; $i < count($arrLP); $i++) {
  5209. if ($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) {
  5210. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5211. $selected = 'selected="selected" ';
  5212. elseif ($action == 'add') $selected = 'selected="selected" ';
  5213. else
  5214. $selected = '';
  5215. $return .= "\t\t\t\t\t" . '<option ' . $selected . 'value="' . $arrLP[$i]['id'] . '">' . get_lang('After') . ' "' . $arrLP[$i]['title'] . '"</option>';
  5216. }
  5217. }
  5218. $return .= "\t\t\t\t" . '</select>';
  5219. $return .= "\t\t\t" . '</td>' . "\n";
  5220. $return .= "\t\t" . '</tr>' . "\n";
  5221. if ($action != 'move') {
  5222. $return .= "\t\t" . '<tr>' . "\n";
  5223. $return .= "\t\t" . '</tr>' . "\n";
  5224. $id_prerequisite = 0;
  5225. if (is_array($arrLP)) {
  5226. foreach ($arrLP as $key => $value) {
  5227. if ($value['id'] == $id) {
  5228. $id_prerequisite = $value['prerequisite'];
  5229. break;
  5230. }
  5231. }
  5232. }
  5233. $arrHide = array ();
  5234. for ($i = 0; $i < count($arrLP); $i++) {
  5235. if ($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter') {
  5236. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5237. $s_selected_position = $arrLP[$i]['id'];
  5238. elseif ($action == 'add') $s_selected_position = 0;
  5239. $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
  5240. }
  5241. }
  5242. $return .= "\t\t" . '</tr>' . "\n";
  5243. }
  5244. $return .= "\t\t" . '<tr>' . "\n";
  5245. if ($action == 'add') {
  5246. $return .= '<td>&nbsp;</td><td><button class="save" name="submit_button" type="submit"> ' . get_lang('AddForumToCourse') . ' </button></td>';
  5247. } else {
  5248. $return .= '<td>&nbsp;</td><td><button class="save" name="submit_button" type="submit"> ' . get_lang('EditCurrentForum') . ' </button></td>';
  5249. }
  5250. $return .= "\t\t" . '</tr>' . "\n";
  5251. $return .= "\t" . '</table>' . "\n";
  5252. if ($action == 'move') {
  5253. $return .= "\t" . '<input name="title" type="hidden" value="' . $item_title . '" />' . "\n";
  5254. $return .= "\t" . '<input name="description" type="hidden" value="' . $item_description . '" />' . "\n";
  5255. }
  5256. if (is_numeric($extra_info)) {
  5257. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info . '" />' . "\n";
  5258. }
  5259. elseif (is_array($extra_info)) {
  5260. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />' . "\n";
  5261. }
  5262. $return .= "\t" . '<input name="type" type="hidden" value="' . TOOL_FORUM . '" />' . "\n";
  5263. $return .= "\t" . '<input name="post_time" type="hidden" value="' . time() . '" />' . "\n";
  5264. $return .= '</form>' . "\n";
  5265. $return .= '</div>' . "\n";
  5266. return $return;
  5267. }
  5268. /**
  5269. * Return HTML form to add/edit forum threads
  5270. * @param string Action (add/edit)
  5271. * @param integer Item ID if already exists in learning path
  5272. * @param mixed Extra information (thread ID if integer)
  5273. * @return string HTML form
  5274. */
  5275. public function display_thread_form($action = 'add', $id = 0, $extra_info = '') {
  5276. global $charset;
  5277. echo '
  5278. <style>
  5279. div.row div.label {
  5280. width:110px;
  5281. }
  5282. div.row div.formw {
  5283. width: 82%;
  5284. }
  5285. </style>';
  5286. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  5287. $tbl_forum = Database :: get_course_table(TABLE_FORUM_THREAD);
  5288. if ($id != 0 && is_array($extra_info)) {
  5289. $item_title = stripslashes($extra_info['title']);
  5290. }
  5291. elseif (is_numeric($extra_info)) {
  5292. $sql_forum = "
  5293. SELECT
  5294. thread_title as title
  5295. FROM " . $tbl_forum . "
  5296. WHERE thread_id = " . $extra_info;
  5297. $result = Database::query($sql_forum);
  5298. $row = Database :: fetch_array($result);
  5299. $item_title = $row['title'];
  5300. $item_description = '';
  5301. } else {
  5302. $item_title = '';
  5303. $item_description = '';
  5304. }
  5305. $return = '<div style="margin:3px 12px;">';
  5306. if ($id != 0 && is_array($extra_info))
  5307. $parent = $extra_info['parent_item_id'];
  5308. else
  5309. $parent = 0;
  5310. $sql = "
  5311. SELECT *
  5312. FROM " . $tbl_lp_item . "
  5313. WHERE
  5314. lp_id = " . $this->lp_id;
  5315. $result = Database::query($sql);
  5316. $arrLP = array ();
  5317. while ($row = Database :: fetch_array($result)) {
  5318. $arrLP[] = array (
  5319. 'id' => $row['id'],
  5320. 'item_type' => $row['item_type'],
  5321. 'title' => $row['title'],
  5322. 'path' => $row['path'],
  5323. 'description' => $row['description'],
  5324. 'parent_item_id' => $row['parent_item_id'],
  5325. 'previous_item_id' => $row['previous_item_id'],
  5326. 'next_item_id' => $row['next_item_id'],
  5327. 'display_order' => $row['display_order'],
  5328. 'max_score' => $row['max_score'],
  5329. 'min_score' => $row['min_score'],
  5330. 'mastery_score' => $row['mastery_score'],
  5331. 'prerequisite' => $row['prerequisite']
  5332. );
  5333. }
  5334. $this->tree_array($arrLP);
  5335. $arrLP = $this->arrMenu;
  5336. unset ($this->arrMenu);
  5337. if ($action == 'add')
  5338. $return .= '<p class="lp_title">' . get_lang('CreateTheForum') . '&nbsp;:</p>' . "\n";
  5339. elseif ($action == 'move') $return .= '<p class="lp_title">' . get_lang('MoveTheCurrentForum') . '&nbsp;:</p>' . "\n";
  5340. else
  5341. $return .= '<p class="lp_title">' . get_lang('EditCurrentForum') . '&nbsp;:</p>' . "\n";
  5342. $return .= '<form method="POST">' . "\n";
  5343. $return .= "\t" . '<table cellpadding="0" cellspacing="0" class="lp_form">' . "\n";
  5344. $return .= "\t\t" . '<tr>' . "\n";
  5345. $return .= "\t\t\t" . '<td class="label"><label for="idParent">' . get_lang('Parent') . '&nbsp;:</label></td>' . "\n";
  5346. $return .= "\t\t\t" . '<td class="input">' . "\n";
  5347. $return .= "\t\t\t\t" . '<select id="idParent" name="parent" onChange="javascript: load_cbo(this.value);" size="1">';
  5348. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
  5349. $arrHide = array (
  5350. $id
  5351. );
  5352. for ($i = 0; $i < count($arrLP); $i++) {
  5353. if ($action != 'add') {
  5354. 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)) {
  5355. $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>';
  5356. } else {
  5357. $arrHide[] = $arrLP[$i]['id'];
  5358. }
  5359. } else {
  5360. if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
  5361. $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>';
  5362. }
  5363. }
  5364. if ($arrLP != null) {
  5365. reset($arrLP);
  5366. }
  5367. $return .= "\t\t\t\t" . '</select>';
  5368. $return .= "\t\t\t" . '</td>' . "\n";
  5369. $return .= "\t\t" . '</tr>' . "\n";
  5370. $return .= "\t\t" . '<tr>' . "\n";
  5371. $return .= "\t\t\t" . '<td class="label"><label for="idPosition">' . get_lang('Position') . '&nbsp;:</label></td>' . "\n";
  5372. $return .= "\t\t\t" . '<td class="input">' . "\n";
  5373. $return .= "\t\t\t\t" . '<select id="idPosition" name="previous" size="1">';
  5374. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . get_lang('FirstPosition') . '</option>';
  5375. for ($i = 0; $i < count($arrLP); $i++) {
  5376. if ($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) {
  5377. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5378. $selected = 'selected="selected" ';
  5379. elseif ($action == 'add') $selected = 'selected="selected" ';
  5380. else
  5381. $selected = '';
  5382. $return .= "\t\t\t\t\t" . '<option ' . $selected . 'value="' . $arrLP[$i]['id'] . '">' . get_lang('After') . ' "' . $arrLP[$i]['title'] . '"</option>';
  5383. }
  5384. }
  5385. $return .= "\t\t\t\t" . '</select>';
  5386. $return .= "\t\t\t" . '</td>' . "\n";
  5387. $return .= "\t\t" . '</tr>' . "\n";
  5388. if ($action != 'move') {
  5389. $return .= "\t\t" . '<tr>' . "\n";
  5390. $return .= "\t\t\t" . '<td class="label"><label for="idTitle">' . get_lang('Title') . '&nbsp;:</label></td>' . "\n";
  5391. $return .= "\t\t\t" . '<td class="input"><input id="idTitle" name="title" type="text" value="' . $item_title . '" /></td>' . "\n";
  5392. $return .= "\t\t" . '</tr>' . "\n";
  5393. $return .= "\t\t" . '<tr>' . "\n";
  5394. $return .= "\t\t" . '</tr>' . "\n";
  5395. $id_prerequisite = 0;
  5396. if ($arrLP != null) {
  5397. foreach ($arrLP as $key => $value) {
  5398. if ($value['id'] == $id) {
  5399. $id_prerequisite = $value['prerequisite'];
  5400. break;
  5401. }
  5402. }
  5403. }
  5404. $arrHide = array();
  5405. for ($i = 0; $i < count($arrLP); $i++) {
  5406. if ($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter') {
  5407. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5408. $s_selected_position = $arrLP[$i]['id'];
  5409. elseif ($action == 'add') $s_selected_position = 0;
  5410. $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
  5411. }
  5412. }
  5413. $return .= "\t\t" . '<tr>' . "\n";
  5414. $return .= "\t\t\t" . '<td class="label"><label for="idPrerequisites">' . get_lang('Prerequisites') . '&nbsp;:</label></td>' . "\n";
  5415. $return .= "\t\t\t" . '<td class="input"><select name="prerequisites" id="prerequisites"><option value="0">' . get_lang('NoPrerequisites') . '</option>';
  5416. foreach ($arrHide as $key => $value) {
  5417. if ($key == $s_selected_position && $action == 'add') {
  5418. $return .= '<option value="' . $key . '" selected="selected">' . $value['value'] . '</option>';
  5419. }
  5420. elseif ($key == $id_prerequisite && $action == 'edit') {
  5421. $return .= '<option value="' . $key . '" selected="selected">' . $value['value'] . '</option>';
  5422. } else {
  5423. $return .= '<option value="' . $key . '">' . $value['value'] . '</option>';
  5424. }
  5425. }
  5426. $return .= "</select></td>";
  5427. $return .= "\t\t" . '</tr>' . "\n";
  5428. }
  5429. $return .= "\t\t" . '<tr>' . "\n";
  5430. $return .= "\t\t\t" . '<td colspan="2">
  5431. <button class="save" name="submit_button" type="submit" value="'.get_lang('Ok').'" />'.get_lang('Ok').'</button></td>' . "\n";
  5432. $return .= "\t\t" . '</tr>' . "\n";
  5433. $return .= "\t" . '</table>' . "\n";
  5434. if ($action == 'move') {
  5435. $return .= "\t" . '<input name="title" type="hidden" value="' . $item_title . '" />' . "\n";
  5436. $return .= "\t" . '<input name="description" type="hidden" value="' . $item_description . '" />' . "\n";
  5437. }
  5438. if (is_numeric($extra_info)) {
  5439. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info . '" />' . "\n";
  5440. }
  5441. elseif (is_array($extra_info)) {
  5442. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />' . "\n";
  5443. }
  5444. $return .= "\t" . '<input name="type" type="hidden" value="' . TOOL_THREAD . '" />' . "\n";
  5445. $return .= "\t" . '<input name="post_time" type="hidden" value="' . time() . '" />' . "\n";
  5446. $return .= '</form>' . "\n";
  5447. $return .= '</div>' . "\n";
  5448. return $return;
  5449. }
  5450. /**
  5451. * Return the HTML form to display an item (generally a section/module item)
  5452. * @param string Item type (module/dokeos_module)
  5453. * @param string Title (optional, only when creating)
  5454. * @param string Action ('add'/'edit')
  5455. * @param integer lp_item ID
  5456. * @param mixed Extra info
  5457. * @return string HTML form
  5458. */
  5459. public function display_item_form($item_type, $title = '', $action = 'add', $id = 0, $extra_info = 'new') {
  5460. global $_course;
  5461. global $charset;
  5462. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  5463. if ($id != 0 && is_array($extra_info)) {
  5464. $item_title = $extra_info['title'];
  5465. $item_description = $extra_info['description'];
  5466. $item_path = api_get_path(WEB_COURSE_PATH) . $_course['path'] . '/scorm/' . $this->path . '/' . stripslashes($extra_info['path']);
  5467. } else {
  5468. $item_title = '';
  5469. $item_description = '';
  5470. }
  5471. $return = ' <div class="row">
  5472. <div class="form_header">';
  5473. if ($id != 0 && is_array($extra_info))
  5474. $parent = $extra_info['parent_item_id'];
  5475. else
  5476. $parent = 0;
  5477. $sql = "
  5478. SELECT *
  5479. FROM " . $tbl_lp_item . "
  5480. WHERE lp_id = " . $this->lp_id . " AND id != " . $id . " ";
  5481. if ($item_type == 'module')
  5482. $sql .= " AND parent_item_id = 0";
  5483. $result = Database::query($sql);
  5484. $arrLP = array ();
  5485. while ($row = Database :: fetch_array($result)) {
  5486. $arrLP[] = array (
  5487. 'id' => $row['id'],
  5488. 'item_type' => $row['item_type'],
  5489. 'title' => $row['title'],
  5490. 'path' => $row['path'],
  5491. 'description' => $row['description'],
  5492. 'parent_item_id' => $row['parent_item_id'],
  5493. 'previous_item_id' => $row['previous_item_id'],
  5494. 'next_item_id' => $row['next_item_id'],
  5495. 'max_score' => $row['max_score'],
  5496. 'min_score' => $row['min_score'],
  5497. 'mastery_score' => $row['mastery_score'],
  5498. 'prerequisite' => $row['prerequisite'],
  5499. 'display_order' => $row['display_order']
  5500. );
  5501. }
  5502. $this->tree_array($arrLP);
  5503. $arrLP = $this->arrMenu;
  5504. unset ($this->arrMenu);
  5505. $return .= $title . "\n";
  5506. $return .= ' </div>
  5507. </div>';
  5508. require_once api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php';
  5509. $form = new FormValidator('form', 'POST', api_get_self() . '?' . $_SERVER['QUERY_STRING']);
  5510. $defaults['title'] = api_html_entity_decode($item_title, ENT_QUOTES, $charset);
  5511. $defaults['description'] = $item_description;
  5512. $form->addElement('html', $return);
  5513. //$arrHide = array($id);
  5514. $arrHide[0]['value'] = Security :: remove_XSS($this->name);
  5515. $arrHide[0]['padding'] = 3;
  5516. $charset = api_get_system_encoding();
  5517. if ($item_type != 'module' && $item_type != 'dokeos_module') {
  5518. for ($i = 0; $i < count($arrLP); $i++) {
  5519. if ($action != 'add') {
  5520. 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)) {
  5521. $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
  5522. $arrHide[$arrLP[$i]['id']]['padding'] = 3 + $arrLP[$i]['depth'] * 10;
  5523. if ($parent == $arrLP[$i]['id']) {
  5524. $s_selected_parent = $arrHide[$arrLP[$i]['id']];
  5525. }
  5526. }
  5527. } else {
  5528. if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir') {
  5529. $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
  5530. $arrHide[$arrLP[$i]['id']]['padding'] = 3 + $arrLP[$i]['depth'] * 10;
  5531. if ($parent == $arrLP[$i]['id']) {
  5532. $s_selected_parent = $arrHide[$arrLP[$i]['id']];
  5533. }
  5534. }
  5535. }
  5536. }
  5537. if ($action != 'move') {
  5538. $form->addElement('text', 'title', get_lang('Title'), 'id="idTitle" class="learnpath_chapter_form" size="40%"');
  5539. $form->applyFilter('title', 'html_filter');
  5540. $form->addRule('title', '<div class="required">' . get_lang('ThisFieldIsRequired'), 'required');
  5541. //$form->addElement('textarea', 'description', get_lang('Description').' :', 'id="idDescription"');
  5542. } else {
  5543. $form->addElement('hidden', 'title');
  5544. }
  5545. $parent_select = & $form->addElement('select', 'parent', get_lang('Parent'), '', 'class="learnpath_chapter_form" style="width:37%;" id="Parent" onchange="javascript: load_cbo(this.value);"');
  5546. foreach ($arrHide as $key => $value) {
  5547. $parent_select->addOption($value['value'], $key, 'style="padding-left:' . $value['padding'] . 'px;"');
  5548. }
  5549. $parent_select->setSelected($s_selected_parent);
  5550. }
  5551. if (is_array($arrLP)) {
  5552. reset($arrLP);
  5553. }
  5554. $arrHide = array ();
  5555. // POSITION
  5556. for ($i = 0; $i < count($arrLP); $i++) {
  5557. if ($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) {
  5558. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5559. $s_selected_position = $arrLP[$i]['id'];
  5560. elseif ($action == 'add') $s_selected_position = $arrLP[$i]['id'];
  5561. $arrHide[$arrLP[$i]['id']]['value'] = get_lang('After') . ' "' . $arrLP[$i]['title'] . '"';
  5562. }
  5563. }
  5564. $position = & $form->addElement('select', 'previous', get_lang('Position'), '', 'id="idPosition" class="learnpath_chapter_form" style="width:37%;"');
  5565. $position->addOption(get_lang('FirstPosition'), 0, 'style="padding-left:' . $value['padding'] . 'px;"');
  5566. foreach ($arrHide as $key => $value) {
  5567. $position->addOption($value['value'] . '"', $key, 'style="padding-left:' . $value['padding'] . 'px;"');
  5568. }
  5569. if (!empty ($s_selected_position)) {
  5570. $position->setSelected($s_selected_position);
  5571. }
  5572. if (is_array($arrLP)) {
  5573. reset($arrLP);
  5574. }
  5575. $form->addElement('style_submit_button', 'submit_button', get_lang('SaveSection'), 'class="save"');
  5576. if ($item_type == 'module' || $item_type == 'dokeos_module') {
  5577. $form->addElement('hidden', 'parent', '0');
  5578. }
  5579. $extension = pathinfo($item_path, PATHINFO_EXTENSION);
  5580. if (($item_type == 'asset' || $item_type == 'sco') && ($extension == 'html' || $extension == 'htm')) {
  5581. if ($item_type == 'sco') {
  5582. $form->addElement('html', '<script type="text/javascript">alert("' . get_lang('WarningWhenEditingScorm') . '")</script>');
  5583. }
  5584. $renderer = $form->defaultRenderer();
  5585. $renderer->setElementTemplate('<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{label}<br />{element}', 'content_lp');
  5586. $form->addElement('html_editor', 'content_lp', '', null, array('ToolbarSet' => 'LearningPathDocuments', 'Width' => '100%', 'Height' => '400', 'FullPage' => true));
  5587. $defaults['content_lp'] = file_get_contents($item_path);
  5588. }
  5589. $form->addElement('hidden', 'type', 'dokeos_' . $item_type);
  5590. $form->addElement('hidden', 'post_time', time());
  5591. $form->setDefaults($defaults);
  5592. return $form->return_form();
  5593. }
  5594. /**
  5595. * Returns the form to update or create a document
  5596. * @param string Action (add/edit)
  5597. * @param integer ID of the lp_item (if already exists)
  5598. * @param mixed Integer if document ID, string if info ('new')
  5599. * @return string HTML form
  5600. */
  5601. public function display_document_form($action = 'add', $id = 0, $extra_info = 'new') {
  5602. global $charset;
  5603. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  5604. $tbl_doc = Database :: get_course_table(TABLE_DOCUMENT);
  5605. $path_parts = pathinfo($extra_info['dir']);
  5606. $no_display_edit_textarea = false;
  5607. //If action==edit document
  5608. //We don't display the document form if it's not an editable document (html or txt file)
  5609. if ($action == "edit") {
  5610. if (is_array($extra_info)) {
  5611. if ($path_parts['extension'] != "txt" && $path_parts['extension'] != "html") {
  5612. $no_display_edit_textarea = true;
  5613. }
  5614. }
  5615. }
  5616. $no_display_add = false;
  5617. // If action==add an existing document
  5618. // We don't display the document form if it's not an editable document (html or txt file).
  5619. if ($action == "add") {
  5620. if (is_numeric($extra_info)) {
  5621. $sql_doc = "SELECT path FROM " . $tbl_doc . "WHERE id = " . Database :: escape_string($extra_info);
  5622. $result = Database::query($sql_doc);
  5623. $path_file = Database :: result($result, 0, 0);
  5624. $path_parts = pathinfo($path_file);
  5625. if ($path_parts['extension'] != "txt" && $path_parts['extension'] != "html") {
  5626. $no_display_add = true;
  5627. }
  5628. }
  5629. }
  5630. if ($id != 0 && is_array($extra_info)) {
  5631. $item_title = stripslashes($extra_info['title']);
  5632. $item_description = stripslashes($extra_info['description']);
  5633. $item_terms = stripslashes($extra_info['terms']);
  5634. if (empty ($item_title)) {
  5635. $path_parts = pathinfo($extra_info['path']);
  5636. $item_title = stripslashes($path_parts['filename']);
  5637. }
  5638. } elseif (is_numeric($extra_info)) {
  5639. $sql_doc = "SELECT path, title FROM " . $tbl_doc . "
  5640. WHERE id = " . Database :: escape_string($extra_info);
  5641. $result = Database::query($sql_doc);
  5642. $row = Database :: fetch_array($result);
  5643. $explode = explode('.', $row['title']);
  5644. if (count($explode) > 1) {
  5645. for ($i = 0; $i < count($explode) - 1; $i++)
  5646. $item_title .= $explode[$i];
  5647. } else {
  5648. $item_title = $row['title'];
  5649. }
  5650. $item_title = str_replace('_', ' ', $item_title);
  5651. if (empty ($item_title)) {
  5652. $path_parts = pathinfo($row['path']);
  5653. $item_title = stripslashes($path_parts['filename']);
  5654. }
  5655. } else {
  5656. $item_title = '';
  5657. $item_description = '';
  5658. }
  5659. $return = ' <div class="row">
  5660. <div class="form_header">';
  5661. if ($id != 0 && is_array($extra_info))
  5662. $parent = $extra_info['parent_item_id'];
  5663. else
  5664. $parent = 0;
  5665. $sql = "SELECT * FROM " . $tbl_lp_item . "
  5666. WHERE lp_id = " . $this->lp_id;
  5667. $result = Database::query($sql);
  5668. $arrLP = array ();
  5669. while ($row = Database :: fetch_array($result)) {
  5670. $arrLP[] = array (
  5671. 'id' => $row['id'],
  5672. 'item_type' => $row['item_type'],
  5673. 'title' => $row['title'],
  5674. 'path' => $row['path'],
  5675. 'description' => $row['description'],
  5676. 'parent_item_id' => $row['parent_item_id'],
  5677. 'previous_item_id' => $row['previous_item_id'],
  5678. 'next_item_id' => $row['next_item_id'],
  5679. 'display_order' => $row['display_order'],
  5680. 'max_score' => $row['max_score'],
  5681. 'min_score' => $row['min_score'],
  5682. 'mastery_score' => $row['mastery_score'],
  5683. 'prerequisite' => $row['prerequisite']
  5684. );
  5685. }
  5686. $this->tree_array($arrLP);
  5687. $arrLP = $this->arrMenu;
  5688. unset ($this->arrMenu);
  5689. if ($action == 'add') {
  5690. $return .= get_lang('CreateTheDocument') . "\n";
  5691. }
  5692. elseif ($action == 'move') {
  5693. $return .= get_lang('MoveTheCurrentDocument') . "\n";
  5694. } else {
  5695. $return .= get_lang('EditTheCurrentDocument') . "\n";
  5696. }
  5697. $return .= '</div>
  5698. </div>';
  5699. if (isset ($_GET['edit']) && $_GET['edit'] == 'true') {
  5700. $return .= Display :: return_warning_message('<strong>' . get_lang('Warning') . ' !</strong><br />' . get_lang('WarningEditingDocument'), false);
  5701. }
  5702. require_once api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php';
  5703. $form = new FormValidator('form', 'POST', api_get_self() . '?' . $_SERVER['QUERY_STRING'], '', 'enctype="multipart/form-data"');
  5704. $defaults['title'] = Security :: remove_XSS($item_title);
  5705. if (empty($item_title)) {
  5706. $defaults['title'] = Security::remove_XSS($item_title);
  5707. }
  5708. $defaults['description'] = $item_description;
  5709. $form->addElement('html', $return);
  5710. if ($action != 'move') {
  5711. $form->addElement('text', 'title', get_lang('Title'), 'id="idTitle" class="learnpath_item_form" size=44%');
  5712. $form->applyFilter('title', 'html_filter');
  5713. }
  5714. //$arrHide = array($id);
  5715. $arrHide[0]['value'] = $this->name;
  5716. $arrHide[0]['padding'] = 3;
  5717. for ($i = 0; $i < count($arrLP); $i++) {
  5718. if ($action != 'add') {
  5719. 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)) {
  5720. $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
  5721. $arrHide[$arrLP[$i]['id']]['padding'] = 3 + $arrLP[$i]['depth'] * 10;
  5722. if ($parent == $arrLP[$i]['id']) {
  5723. $s_selected_parent = $arrHide[$arrLP[$i]['id']];
  5724. }
  5725. }
  5726. } else {
  5727. if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir') {
  5728. $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
  5729. $arrHide[$arrLP[$i]['id']]['padding'] = 3 + $arrLP[$i]['depth'] * 10;
  5730. if ($parent == $arrLP[$i]['id']) {
  5731. $s_selected_parent = $arrHide[$arrLP[$i]['id']];
  5732. }
  5733. }
  5734. }
  5735. }
  5736. $parent_select = & $form->addElement('select', 'parent', get_lang('Parent'), '', 'class="learnpath_item_form" style="width:40%;" onchange="javascript: load_cbo(this.value);"');
  5737. $my_count=0;
  5738. foreach ($arrHide as $key => $value) {
  5739. if ($my_count!=0) {
  5740. // The LP name is also the first section and is not in the same charset like the other sections.
  5741. $value['value'] = Security :: remove_XSS($value['value']);
  5742. $parent_select->addOption($value['value'], $key, 'style="padding-left:' . $value['padding'] . 'px;"');
  5743. } else {
  5744. $value['value'] = Security :: remove_XSS($value['value']);
  5745. $parent_select->addOption($value['value'], $key, 'style="padding-left:' . $value['padding'] . 'px;"');
  5746. }
  5747. $my_count++;
  5748. }
  5749. if (!empty ($id)) {
  5750. $parent_select->setSelected($parent);
  5751. } else {
  5752. $parent_item_id = $_SESSION['parent_item_id'];
  5753. $parent_select->setSelected($parent_item_id);
  5754. }
  5755. if (is_array($arrLP)) {
  5756. reset($arrLP);
  5757. }
  5758. $arrHide = array ();
  5759. //POSITION
  5760. for ($i = 0; $i < count($arrLP); $i++) {
  5761. if ($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) {
  5762. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5763. $s_selected_position = $arrLP[$i]['id'];
  5764. elseif ($action == 'add') $s_selected_position = $arrLP[$i]['id'];
  5765. $arrHide[$arrLP[$i]['id']]['value'] = get_lang('After') . ' "' . $arrLP[$i]['title'] . '"';
  5766. }
  5767. }
  5768. $position = & $form->addElement('select', 'previous', get_lang('Position'), '', 'id="idPosition" class="learnpath_item_form" style="width:40%;"');
  5769. $position->addOption(get_lang('FirstPosition'), 0);
  5770. foreach ($arrHide as $key => $value) {
  5771. $position->addOption($value['value'], $key, 'style="padding-left:' . $value['padding'] . 'px;"');
  5772. }
  5773. $position->setSelected($s_selected_position);
  5774. if (is_array($arrLP)) {
  5775. reset($arrLP);
  5776. }
  5777. if ($action != 'move') {
  5778. $id_prerequisite = 0;
  5779. if (is_array($arrLP)) {
  5780. foreach ($arrLP as $key => $value) {
  5781. if ($value['id'] == $id) {
  5782. $id_prerequisite = $value['prerequisite'];
  5783. break;
  5784. }
  5785. }
  5786. }
  5787. // Commented the prerequisites, only visible in edit (new document).
  5788. //$select_prerequisites=$form->addElement('select', 'prerequisites', get_lang('Prerequisites'),null,'id="prerequisites" class="learnpath_item_form" style="width:263px;"');
  5789. //$select_prerequisites->addOption(get_lang('NoPrerequisites'), 0);
  5790. // Form element for uploading an mp3 file.
  5791. //$form->addElement('file','mp3',get_lang('UploadMp3audio'),'id="mp3" size="33"');
  5792. //$form->addRule('file', 'The extension of the Song file should be *.mp3', 'filename', '/^.*\.mp3$/');
  5793. /* Code deprecated - moved to lp level (not lp-item).
  5794. if (api_get_setting('search_enabled') === 'true') {
  5795. //add terms field
  5796. $terms = $form->addElement('text', 'terms', get_lang('SearchFeatureTerms').'&nbsp;:', 'id="idTerms" class="learnpath_item_form"');
  5797. $terms->setValue($item_terms);
  5798. }
  5799. */
  5800. $arrHide = array ();
  5801. for ($i = 0; $i < count($arrLP); $i++) {
  5802. if ($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter') {
  5803. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5804. $s_selected_position = $arrLP[$i]['id'];
  5805. elseif ($action == 'add') $s_selected_position = $arrLP[$i]['id'];
  5806. $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
  5807. }
  5808. }
  5809. /* foreach ($arrHide as $key => $value) {
  5810. $select_prerequisites->addOption($value['value'], $key, 'style="padding-left:'.$value['padding'].'px;"');
  5811. if ($key == $s_selected_position && $action == 'add') {
  5812. $select_prerequisites -> setSelected(0);
  5813. }
  5814. elseif ($key == $id_prerequisite && $action == 'edit') {
  5815. $select_prerequisites -> setSelected($id_prerequisite);
  5816. }
  5817. }
  5818. */
  5819. if (!$no_display_add) {
  5820. if (($extra_info == 'new' || $extra_info['item_type'] == TOOL_DOCUMENT || $_GET['edit'] == 'true')) {
  5821. if (isset ($_POST['content']))
  5822. $content = stripslashes($_POST['content']);
  5823. elseif (is_array($extra_info)) {
  5824. //If it's an html document or a text file
  5825. if (!$no_display_edit_textarea) {
  5826. $content = $this->display_document($extra_info['path'], false, false);
  5827. }
  5828. }
  5829. elseif (is_numeric($extra_info)) $content = $this->display_document($extra_info, false, false);
  5830. else
  5831. $content = '';
  5832. if (!$no_display_edit_textarea) {
  5833. // We need to claculate here some specific settings for the online editor.
  5834. // The calculated settings work for documents in the Documents tool
  5835. // (on the root or in subfolders).
  5836. // For documents in native scorm packages it is unclear whether the
  5837. // online editor should be activated or not.
  5838. $relative_path = $extra_info['dir'];
  5839. if ($relative_path == 'n/') {
  5840. // A new document, it is in the root of the repository.
  5841. $relative_path = '';
  5842. $relative_prefix = '';
  5843. } else {
  5844. // The document already exists. Whe have to determine its relative path towards the repository root.
  5845. $relative_path = explode('/', $relative_path);
  5846. $cnt = count($relative_path) - 2;
  5847. if ($cnt < 0) {
  5848. $cnt = 0;
  5849. }
  5850. $relative_prefix = str_repeat('../', $cnt);
  5851. $relative_path = array_slice($relative_path, 1, $cnt);
  5852. $relative_path = implode('/', $relative_path);
  5853. if (strlen($relative_path) > 0) {
  5854. $relative_path = $relative_path . '/';
  5855. }
  5856. }
  5857. $editor_config = array('ToolbarSet' => 'LearningPathDocuments', 'Width' => '100%', 'Height' => '700', 'FullPage' => true,
  5858. 'CreateDocumentDir' => $relative_prefix,
  5859. 'CreateDocumentWebDir' => api_get_path(WEB_COURSE_PATH) . api_get_course_path() . '/document/',
  5860. 'BaseHref' => api_get_path(WEB_COURSE_PATH) . api_get_course_path() . '/document/' . $relative_path
  5861. );
  5862. if ($_GET['action'] == 'add_item') {
  5863. $class = 'add';
  5864. $text = get_lang('LPCreateDocument');
  5865. } else
  5866. if ($_GET['action'] == 'edit_item') {
  5867. $class = 'save';
  5868. $text = get_lang('SaveDocument');
  5869. }
  5870. $form->addElement('style_submit_button', 'submit_button', $text, 'class="' . $class . '"');
  5871. $renderer = $form->defaultRenderer();
  5872. $renderer->setElementTemplate('<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{label}<br />{element}', 'content_lp');
  5873. $form->addElement('html', '<div style="margin:3px 12px">');
  5874. $form->addElement('html_editor', 'content_lp', '', null, $editor_config);
  5875. $form->addElement('html', '</div>');
  5876. $defaults['content_lp'] = $content;
  5877. }
  5878. }
  5879. elseif (is_numeric($extra_info)) {
  5880. $form->addElement('style_submit_button', 'submit_button', get_lang('SaveDocument'), 'class="save"');
  5881. $return = $this->display_document($extra_info, true, true, true);
  5882. $form->addElement('html', $return);
  5883. }
  5884. }
  5885. }
  5886. if ($action == 'move') {
  5887. $form->addElement('hidden', 'title', $item_title);
  5888. $form->addElement('hidden', 'description', $item_description);
  5889. }
  5890. if (is_numeric($extra_info)) {
  5891. $form->addElement('style_submit_button', 'submit_button', get_lang('SaveDocument'), 'value="submit_button", class="save"');
  5892. $form->addElement('hidden', 'path', $extra_info);
  5893. }
  5894. elseif (is_array($extra_info)) {
  5895. $form->addElement('style_submit_button', 'submit_button', get_lang('SaveDocument'), 'class="save"');
  5896. $form->addElement('hidden', 'path', $extra_info['path']);
  5897. }
  5898. $form->addElement('hidden', 'type', TOOL_DOCUMENT);
  5899. $form->addElement('hidden', 'post_time', time());
  5900. $form->setDefaults($defaults);
  5901. return $form->return_form();
  5902. }
  5903. /**
  5904. * Return HTML form to add/edit a link item
  5905. * @param string Action (add/edit)
  5906. * @param integer Item ID if exists
  5907. * @param mixed Extra info
  5908. * @return string HTML form
  5909. */
  5910. public function display_link_form($action = 'add', $id = 0, $extra_info = '') {
  5911. global $charset;
  5912. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  5913. $tbl_link = Database :: get_course_table(TABLE_LINK);
  5914. if ($id != 0 && is_array($extra_info)) {
  5915. $item_title = stripslashes($extra_info['title']);
  5916. $item_description = stripslashes($extra_info['description']);
  5917. $item_url = stripslashes($extra_info['url']);
  5918. }
  5919. elseif (is_numeric($extra_info)) {
  5920. $sql_link = "
  5921. SELECT
  5922. title,
  5923. description,
  5924. url
  5925. FROM " . $tbl_link . "
  5926. WHERE id = " . $extra_info;
  5927. $result = Database::query($sql_link);
  5928. $row = Database :: fetch_array($result);
  5929. $item_title = $row['title'];
  5930. $item_description = $row['description'];
  5931. $item_url = $row['url'];
  5932. } else {
  5933. $item_title = '';
  5934. $item_description = '';
  5935. $item_url = '';
  5936. }
  5937. $return = ' <div class="row">
  5938. <div class="form_header">';
  5939. if ($id != 0 && is_array($extra_info))
  5940. $parent = $extra_info['parent_item_id'];
  5941. else
  5942. $parent = 0;
  5943. $sql = "
  5944. SELECT *
  5945. FROM " . $tbl_lp_item . "
  5946. WHERE
  5947. lp_id = " . $this->lp_id;
  5948. $result = Database::query($sql);
  5949. $arrLP = array ();
  5950. while ($row = Database :: fetch_array($result)) {
  5951. $arrLP[] = array (
  5952. 'id' => $row['id'],
  5953. 'item_type' => $row['item_type'],
  5954. 'title' => $row['title'],
  5955. 'path' => $row['path'],
  5956. 'description' => $row['description'],
  5957. 'parent_item_id' => $row['parent_item_id'],
  5958. 'previous_item_id' => $row['previous_item_id'],
  5959. 'next_item_id' => $row['next_item_id'],
  5960. 'display_order' => $row['display_order'],
  5961. 'max_score' => $row['max_score'],
  5962. 'min_score' => $row['min_score'],
  5963. 'mastery_score' => $row['mastery_score'],
  5964. 'prerequisite' => $row['prerequisite']
  5965. );
  5966. }
  5967. $this->tree_array($arrLP);
  5968. $arrLP = $this->arrMenu;
  5969. unset ($this->arrMenu);
  5970. if ($action == 'add')
  5971. $return .= get_lang('CreateTheLink') . '&nbsp;:' . "\n";
  5972. elseif ($action == 'move') $return .= get_lang('MoveCurrentLink') . '&nbsp;:' . "\n";
  5973. else
  5974. $return .= get_lang('EditCurrentLink') . '&nbsp;:' . "\n";
  5975. $return .= ' </div>
  5976. </div>';
  5977. $return .= '<div class="sectioncomment">';
  5978. $return .= '<form method="POST">' . "\n";
  5979. $return .= "\t" . '<table>' . "\n";
  5980. if ($action != 'move') {
  5981. $return .= "\t\t" . '<tr>' . "\n";
  5982. $return .= "\t\t\t" . '<td class="label"><label for="idTitle">' . get_lang('Title') . '</label></td>' . "\n";
  5983. $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";
  5984. $return .= "\t\t" . '</tr>' . "\n";
  5985. }
  5986. $return .= "\t\t" . '<tr>' . "\n";
  5987. $return .= "\t\t\t" . '<td class="label"><label for="idParent">' . get_lang('Parent') . '</label></td>' . "\n";
  5988. $return .= "\t\t\t" . '<td class="input">' . "\n";
  5989. $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">';
  5990. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
  5991. $arrHide = array (
  5992. $id
  5993. );
  5994. $parent_item_id = $_SESSION['parent_item_id'];
  5995. for ($i = 0; $i < count($arrLP); $i++) {
  5996. if ($action != 'add') {
  5997. 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)) {
  5998. $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>';
  5999. } else {
  6000. $arrHide[] = $arrLP[$i]['id'];
  6001. }
  6002. } else {
  6003. if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
  6004. $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>';
  6005. }
  6006. }
  6007. if (is_array($arrLP)) {
  6008. reset($arrLP);
  6009. }
  6010. $return .= "\t\t\t\t" . '</select>';
  6011. $return .= "\t\t\t" . '</td>' . "\n";
  6012. $return .= "\t\t" . '</tr>' . "\n";
  6013. $return .= "\t\t" . '<tr>' . "\n";
  6014. $return .= "\t\t\t" . '<td class="label"><label for="idPosition">' . get_lang('Position') . '</label></td>' . "\n";
  6015. $return .= "\t\t\t" . '<td class="input">' . "\n";
  6016. $return .= "\t\t\t\t" . '<select id="idPosition" name="previous" style="width:100%;" size="1" class="learnpath_item_form">';
  6017. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . get_lang('FirstPosition') . '</option>';
  6018. for ($i = 0; $i < count($arrLP); $i++) {
  6019. if ($arrLP[$i]['parent_item_id'] == $parent_item_id && $arrLP[$i]['id'] != $id) {
  6020. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  6021. $selected = 'selected="selected" ';
  6022. elseif ($action == 'add') $selected = 'selected="selected" ';
  6023. else
  6024. $selected = '';
  6025. $return .= "\t\t\t\t\t" . '<option ' . $selected . 'value="' . $arrLP[$i]['id'] . '">' . get_lang('After') . ' "' . $arrLP[$i]['title'] . '"</option>';
  6026. }
  6027. }
  6028. $return .= "\t\t\t\t" . '</select>';
  6029. $return .= "\t\t\t" . '</td>' . "\n";
  6030. $return .= "\t\t" . '</tr>' . "\n";
  6031. if ($action != 'move') {
  6032. $return .= "\t\t" . '<tr>' . "\n";
  6033. $return .= "\t\t\t" . '<td class="label"><label for="idURL">' . get_lang('Url') . '</label></td>' . "\n";
  6034. $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";
  6035. $return .= "\t\t" . '</tr>' . "\n";
  6036. $id_prerequisite = 0;
  6037. if (is_array($arrLP)) {
  6038. foreach ($arrLP as $key => $value) {
  6039. if ($value['id'] == $id) {
  6040. $id_prerequisite = $value['prerequisite'];
  6041. break;
  6042. }
  6043. }
  6044. }
  6045. $arrHide = array ();
  6046. for ($i = 0; $i < count($arrLP); $i++) {
  6047. if ($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter') {
  6048. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  6049. $s_selected_position = $arrLP[$i]['id'];
  6050. elseif ($action == 'add') $s_selected_position = 0;
  6051. $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
  6052. }
  6053. }
  6054. /*// Commented the prerequisites, only visible in edit (link).
  6055. $return .= "\t\t" . '<tr>' . "\n";
  6056. $return .= "\t\t\t" . '<td class="label"><label for="idPrerequisites">'.get_lang('Prerequisites').'</label></td>' . "\n";
  6057. $return .= "\t\t\t" . '<td class="input"><select name="prerequisites" id="prerequisites" class="learnpath_item_form"><option value="0">'.get_lang('NoPrerequisites').'</option>';
  6058. foreach($arrHide as $key => $value) {
  6059. if ($key == $s_selected_position && $action == 'add') {
  6060. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  6061. }
  6062. elseif ($key == $id_prerequisite && $action == 'edit') {
  6063. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  6064. }
  6065. else {
  6066. $return .= '<option value="'.$key.'">'.$value['value'].'</option>';
  6067. }
  6068. }
  6069. $return .= "</select></td>";
  6070. */
  6071. $return .= "\t\t" . '</tr>' . "\n";
  6072. }
  6073. $return .= "\t\t" . '<tr>' . "\n";
  6074. if ($action == 'add') {
  6075. $return .= '<td>&nbsp;</td><td><button class="save" name="submit_button" type="submit">' . get_lang('AddLinkToCourse') . '</button></td>';
  6076. } else {
  6077. $return .= '<td>&nbsp;</td><td><button class="save" name="submit_button" type="submit">' . get_lang('EditCurrentLink') . '</button></td>';
  6078. }
  6079. $return .= "\t\t" . '</tr>' . "\n";
  6080. $return .= "\t" . '</table>' . "\n";
  6081. if ($action == 'move') {
  6082. $return .= "\t" . '<input name="title" type="hidden" value="' . $item_title . '" />' . "\n";
  6083. $return .= "\t" . '<input name="description" type="hidden" value="' . $item_description . '" />' . "\n";
  6084. }
  6085. if (is_numeric($extra_info)) {
  6086. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info . '" />' . "\n";
  6087. }
  6088. elseif (is_array($extra_info)) {
  6089. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />' . "\n";
  6090. }
  6091. $return .= "\t" . '<input name="type" type="hidden" value="' . TOOL_LINK . '" />' . "\n";
  6092. $return .= "\t" . '<input name="post_time" type="hidden" value="' . time() . '" />' . "\n";
  6093. $return .= '</form>' . "\n";
  6094. $return .= '</div>' . "\n";
  6095. return $return;
  6096. }
  6097. /**
  6098. * Return HTML form to add/edit a student publication (work)
  6099. * @param string Action (add/edit)
  6100. * @param integer Item ID if already exists
  6101. * @param mixed Extra info (work ID if integer)
  6102. * @return string HTML form
  6103. */
  6104. public function display_student_publication_form($action = 'add', $id = 0, $extra_info = '') {
  6105. global $charset;
  6106. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  6107. $tbl_publication = Database :: get_course_table(TABLE_STUDENT_PUBLICATION);
  6108. if ($id != 0 && is_array($extra_info)) {
  6109. $item_title = stripslashes($extra_info['title']);
  6110. $item_description = stripslashes($extra_info['description']);
  6111. }
  6112. elseif (is_numeric($extra_info)) {
  6113. $sql_publication = "
  6114. SELECT
  6115. title,
  6116. description
  6117. FROM " . $tbl_publication . "
  6118. WHERE id = " . $extra_info;
  6119. $result = Database::query($sql_publication);
  6120. $row = Database :: fetch_array($result);
  6121. $item_title = $row['title'];
  6122. } else {
  6123. $item_title = get_lang('Student_publication');
  6124. }
  6125. $return = ' <div class="row">
  6126. <div class="form_header">';
  6127. if ($id != 0 && is_array($extra_info))
  6128. $parent = $extra_info['parent_item_id'];
  6129. else
  6130. $parent = 0;
  6131. $sql = "
  6132. SELECT *
  6133. FROM " . $tbl_lp_item . "
  6134. WHERE
  6135. lp_id = " . $this->lp_id;
  6136. $result = Database::query($sql);
  6137. $arrLP = array ();
  6138. while ($row = Database :: fetch_array($result)) {
  6139. $arrLP[] = array (
  6140. 'id' => $row['id'],
  6141. 'item_type' => $row['item_type'],
  6142. 'title' => $row['title'],
  6143. 'path' => $row['path'],
  6144. 'description' => $row['description'],
  6145. 'parent_item_id' => $row['parent_item_id'],
  6146. 'previous_item_id' => $row['previous_item_id'],
  6147. 'next_item_id' => $row['next_item_id'],
  6148. 'display_order' => $row['display_order'],
  6149. 'max_score' => $row['max_score'],
  6150. 'min_score' => $row['min_score'],
  6151. 'mastery_score' => $row['mastery_score'],
  6152. 'prerequisite' => $row['prerequisite']
  6153. );
  6154. }
  6155. $this->tree_array($arrLP);
  6156. $arrLP = $this->arrMenu;
  6157. unset ($this->arrMenu);
  6158. if ($action == 'add')
  6159. $return .= get_lang('Student_publication') . '&nbsp;:' . "\n";
  6160. elseif ($action == 'move') $return .= get_lang('MoveCurrentStudentPublication') . '&nbsp;:' . "\n";
  6161. else
  6162. $return .= get_lang('EditCurrentStudentPublication') . '&nbsp;:' . "\n";
  6163. $return .= ' </div>
  6164. </div>';
  6165. $return .= '<div class="sectioncomment">';
  6166. $return .= '<form method="POST">' . "\n";
  6167. $return .= "\t" . '<table class="lp_form">' . "\n";
  6168. if ($action != 'move') {
  6169. $return .= "\t\t" . '<tr>' . "\n";
  6170. $return .= "\t\t\t" . '<td class="label"><label for="idTitle">' . get_lang('Title') . '</label></td>' . "\n";
  6171. $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";
  6172. $return .= "\t\t" . '</tr>' . "\n";
  6173. }
  6174. $return .= "\t\t" . '<tr>' . "\n";
  6175. $return .= "\t\t\t" . '<td class="label"><label for="idParent">' . get_lang('Parent') . '</label></td>' . "\n";
  6176. $return .= "\t\t\t" . '<td class="input">' . "\n";
  6177. $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">';
  6178. //$parent_item_id = $_SESSION['parent_item_id'];
  6179. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
  6180. $arrHide = array (
  6181. $id
  6182. );
  6183. for ($i = 0; $i < count($arrLP); $i++) {
  6184. if ($action != 'add') {
  6185. 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)) {
  6186. $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>';
  6187. } else {
  6188. $arrHide[] = $arrLP[$i]['id'];
  6189. }
  6190. } else {
  6191. if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
  6192. $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>';
  6193. }
  6194. }
  6195. if (is_array($arrLP)) {
  6196. reset($arrLP);
  6197. }
  6198. $return .= "\t\t\t\t" . '</select>';
  6199. $return .= "\t\t\t" . '</td>' . "\n";
  6200. $return .= "\t\t" . '</tr>' . "\n";
  6201. $return .= "\t\t" . '<tr>' . "\n";
  6202. $return .= "\t\t\t" . '<td class="label"><label for="idPosition">' . get_lang('Position') . '</label></td>' . "\n";
  6203. $return .= "\t\t\t" . '<td class="input">' . "\n";
  6204. $return .= "\t\t\t\t" . '<select id="idPosition" name="previous" style="width:100%;" size="1" class="learnpath_item_form">';
  6205. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . get_lang('FirstPosition') . '</option>';
  6206. for ($i = 0; $i < count($arrLP); $i++) {
  6207. if ($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) {
  6208. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  6209. $selected = 'selected="selected" ';
  6210. elseif ($action == 'add') $selected = 'selected="selected" ';
  6211. else
  6212. $selected = '';
  6213. $return .= "\t\t\t\t\t" . '<option ' . $selected . 'value="' . $arrLP[$i]['id'] . '">' . get_lang('After') . ' "' . $arrLP[$i]['title'] . '"</option>';
  6214. }
  6215. }
  6216. $return .= "\t\t\t\t" . '</select>';
  6217. $return .= "\t\t\t" . '</td>' . "\n";
  6218. $return .= "\t\t" . '</tr>' . "\n";
  6219. if ($action != 'move') {
  6220. $id_prerequisite = 0;
  6221. if (is_array($arrLP)) {
  6222. foreach ($arrLP as $key => $value) {
  6223. if ($value['id'] == $id) {
  6224. $id_prerequisite = $value['prerequisite'];
  6225. break;
  6226. }
  6227. }
  6228. }
  6229. $arrHide = array ();
  6230. for ($i = 0; $i < count($arrLP); $i++) {
  6231. if ($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter') {
  6232. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  6233. $s_selected_position = $arrLP[$i]['id'];
  6234. elseif ($action == 'add') $s_selected_position = 0;
  6235. $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
  6236. }
  6237. }
  6238. // Commented the prerequisites, only visible in edit (work).
  6239. /*
  6240. $return .= "\t\t" . '<tr>' . "\n";
  6241. $return .= "\t\t\t" . '<td class="label"><label for="idPrerequisites">'.get_lang('Prerequisites').'</label></td>' . "\n";
  6242. $return .= "\t\t\t" . '<td class="input"><select name="prerequisites" id="prerequisites" class="learnpath_item_form"><option value="0">'.get_lang('NoPrerequisites').'</option>';
  6243. foreach($arrHide as $key => $value) {
  6244. if ($key == $s_selected_position && $action == 'add') {
  6245. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  6246. }
  6247. elseif ($key == $id_prerequisite && $action == 'edit') {
  6248. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  6249. }
  6250. else {
  6251. $return .= '<option value="'.$key.'">'.$value['value'].'</option>';
  6252. }
  6253. }
  6254. $return .= "</select></td>";
  6255. */
  6256. $return .= "\t\t" . '</tr>' . "\n";
  6257. }
  6258. $return .= "\t\t" . '<tr>' . "\n";
  6259. if ($action == 'add') {
  6260. $return .= '<td>&nbsp</td><td><button class="save" name="submit_button" type="submit">' . get_lang('AddAssignmentToCourse') . '</button></td>';
  6261. } else {
  6262. $return .= '<td>&nbsp</td><td><button class="save" name="submit_button" type="submit">' . get_lang('EditCurrentStudentPublication') . '</button></td>';
  6263. }
  6264. $return .= "\t\t" . '</tr>' . "\n";
  6265. $return .= "\t" . '</table>' . "\n";
  6266. if ($action == 'move') {
  6267. $return .= "\t" . '<input name="title" type="hidden" value="' . $item_title . '" />' . "\n";
  6268. $return .= "\t" . '<input name="description" type="hidden" value="' . $item_description . '" />' . "\n";
  6269. }
  6270. if (is_numeric($extra_info)) {
  6271. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info . '" />' . "\n";
  6272. } elseif (is_array($extra_info)) {
  6273. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />' . "\n";
  6274. }
  6275. $return .= "\t" . '<input name="type" type="hidden" value="' . TOOL_STUDENTPUBLICATION . '" />' . "\n";
  6276. $return .= "\t" . '<input name="post_time" type="hidden" value="' . time() . '" />' . "\n";
  6277. $return .= '</form>' . "\n";
  6278. $return .= '</div>' . "\n";
  6279. return $return;
  6280. }
  6281. /**
  6282. * Displays the menu for manipulating a step
  6283. * @return unknown
  6284. */
  6285. public function display_manipulate($item_id, $item_type = TOOL_DOCUMENT) {
  6286. global $charset, $_course;
  6287. $return = '<div class="actions">';
  6288. switch ($item_type) {
  6289. case 'dokeos_chapter' :
  6290. case 'chapter' :
  6291. // Commented the message cause should not show it.
  6292. //$lang = get_lang('TitleManipulateChapter');
  6293. break;
  6294. case 'dokeos_module' :
  6295. case 'module' :
  6296. // Commented the message cause should not show it.
  6297. //$lang = get_lang('TitleManipulateModule');
  6298. break;
  6299. case TOOL_DOCUMENT :
  6300. // Commented the message cause should not show it.
  6301. //$lang = get_lang('TitleManipulateDocument');
  6302. break;
  6303. case TOOL_LINK :
  6304. case 'link' :
  6305. // Commented the message cause should not show it.
  6306. //$lang = get_lang('TitleManipulateLink');
  6307. break;
  6308. case TOOL_QUIZ :
  6309. // Commented the message cause should not show it.
  6310. //$lang = get_lang('TitleManipulateQuiz');
  6311. break;
  6312. case TOOL_STUDENTPUBLICATION :
  6313. // Commented the message cause should not show it.
  6314. //$lang = get_lang('TitleManipulateStudentPublication');
  6315. break;
  6316. }
  6317. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  6318. $sql = "
  6319. SELECT
  6320. *
  6321. FROM " . $tbl_lp_item . " as lp
  6322. WHERE
  6323. lp.id = " . $item_id;
  6324. $result = Database::query($sql);
  6325. $row = Database::fetch_assoc($result);
  6326. $s_title = $row['title'];
  6327. // We display an audio player if needed.
  6328. if (!empty ($row['audio'])) {
  6329. $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>';
  6330. $return .= '<script type="text/javascript" src="../inc/lib/mediaplayer/swfobject.js"></script>';
  6331. $return .= '<script type="text/javascript">
  6332. var s1 = new SWFObject("../inc/lib/mediaplayer/player.swf","ply","250","20","9","#FFFFFF");
  6333. s1.addParam("allowscriptaccess","always");
  6334. s1.addParam("flashvars","file=../../courses/' . $_course['path'] . '/document/audio/' . $row['audio'] . '&autostart=true");
  6335. s1.write("container");
  6336. </script>';
  6337. }
  6338. // Commented ":" for message in step.
  6339. //$return .= $lang.': ';
  6340. $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>';
  6341. $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>';
  6342. // Commented for now as prerequisites cannot be added to chapters.
  6343. if ($item_type != 'dokeos_chapter' && $item_type != 'chapter') {
  6344. $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>';
  6345. }
  6346. $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>';
  6347. //$return .= '<br /><br /><p class="lp_text">' . ((trim($s_description) == '') ? ''.get_lang('NoDescription').'' : stripslashes(nl2br($s_description))) . '</p>';
  6348. //$return.="</td><td valign='top'>";
  6349. // Get the audiorecorder. Use of ob_* functions since there are echos in the file.
  6350. ob_start();
  6351. $audio_recorder_studentview = 'false';
  6352. $audio_recorder_item_id = $item_id;
  6353. if (api_get_setting('service_visio', 'active') == 'true') {
  6354. include 'audiorecorder.inc.php';
  6355. }
  6356. $return .= ob_get_contents();
  6357. ob_end_clean();
  6358. // End of audiorecorder include.
  6359. $return .= '</div>';
  6360. return $return;
  6361. }
  6362. /**
  6363. * Creates the javascript needed for filling up the checkboxes without page reload
  6364. *
  6365. * @return string
  6366. */
  6367. public function create_js() {
  6368. $return = '<script language="javascript" type="text/javascript">' . "\n";
  6369. $return .= 'function load_cbo(id){' . "\n";
  6370. $return .= "var cbo = document.getElementById('idPosition');\n";
  6371. $return .= 'for(var i = cbo.length - 1; i > 0; i--)';
  6372. $return .= 'cbo.options[i] = null;' . "\n";
  6373. $return .= 'var k=0;' . "\n";
  6374. $return .= 'for(var i = 1; i <= child_name[id].length; i++){' . "\n";
  6375. $return .= ' cbo.options[i] = new Option(child_name[id][i-1], child_value[id][i-1]);' . "\n";
  6376. $return .= 'k=i;';
  6377. $return .= '}' . "\n\n";
  6378. $return .= 'if( typeof cbo != "undefined" ) {cbo.options[k].selected = true;}';
  6379. $return .= '}';
  6380. $return .= 'var child_name = new Array();' . "\n";
  6381. $return .= 'var child_value = new Array();' . "\n\n";
  6382. $return .= 'child_name[0] = new Array();' . "\n";
  6383. $return .= 'child_value[0] = new Array();' . "\n\n";
  6384. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  6385. $sql_zero = "
  6386. SELECT *
  6387. FROM " . $tbl_lp_item . "
  6388. WHERE
  6389. lp_id = " . $this->lp_id . " AND
  6390. parent_item_id = 0
  6391. ORDER BY display_order ASC";
  6392. $res_zero = Database::query($sql_zero);
  6393. global $charset;
  6394. $i = 0;
  6395. while ($row_zero = Database :: fetch_array($res_zero)) {
  6396. $return .= 'child_name[0][' . $i . '] = "' . get_lang('After') . ' \"' . $row_zero['title'] . '\"";' . "\n";
  6397. $return .= 'child_value[0][' . $i++ . '] = "' . $row_zero['id'] . '";' . "\n";
  6398. }
  6399. $return .= "\n";
  6400. $sql = "
  6401. SELECT *
  6402. FROM " . $tbl_lp_item . "
  6403. WHERE
  6404. lp_id = " . $this->lp_id;
  6405. $res = Database::query($sql);
  6406. while ($row = Database :: fetch_array($res)) {
  6407. $sql_parent = "
  6408. SELECT *
  6409. FROM " . $tbl_lp_item . "
  6410. WHERE parent_item_id = " . $row['id'] . "
  6411. ORDER BY display_order ASC";
  6412. $res_parent = Database::query($sql_parent);
  6413. $i = 0;
  6414. $return .= 'child_name[' . $row['id'] . '] = new Array();' . "\n";
  6415. $return .= 'child_value[' . $row['id'] . '] = new Array();' . "\n\n";
  6416. while ($row_parent = Database :: fetch_array($res_parent)) {
  6417. $return .= 'child_name[' . $row['id'] . '][' . $i . '] = "' . get_lang('After') . ' \"' . api_html_entity_decode($row_parent['title'], ENT_QUOTES) . '\"";' . "\n";
  6418. $return .= 'child_value[' . $row['id'] . '][' . $i++ . '] = "' . $row_parent['id'] . '";' . "\n";
  6419. }
  6420. $return .= "\n";
  6421. }
  6422. $return .= '</script>' . "\n";
  6423. return $return;
  6424. }
  6425. /**
  6426. * Display the form to allow moving an item
  6427. * @param integer Item ID
  6428. * @return string HTML form
  6429. */
  6430. public function display_move_item($item_id) {
  6431. global $_course; //will disappear
  6432. global $charset;
  6433. $return = '';
  6434. if (is_numeric($item_id)) {
  6435. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  6436. $sql = "SELECT *
  6437. FROM " . $tbl_lp_item . "
  6438. WHERE id = " . $item_id;
  6439. $res = Database::query($sql);
  6440. $row = Database :: fetch_array($res);
  6441. switch ($row['item_type']) {
  6442. case 'dokeos_chapter' :
  6443. case 'dir' :
  6444. case 'asset' :
  6445. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6446. $return .= $this->display_item_form($row['item_type'], get_lang('MoveCurrentChapter'), 'move', $item_id, $row);
  6447. break;
  6448. case 'dokeos_module' :
  6449. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6450. $return .= $this->display_item_form($row['item_type'], 'Move th current module:', 'move', $item_id, $row);
  6451. break;
  6452. case TOOL_DOCUMENT :
  6453. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6454. $return .= $this->display_document_form('move', $item_id, $row);
  6455. break;
  6456. case TOOL_LINK :
  6457. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6458. $return .= $this->display_link_form('move', $item_id, $row);
  6459. break;
  6460. case TOOL_HOTPOTATOES :
  6461. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6462. $return .= $this->display_link_form('move', $item_id, $row);
  6463. break;
  6464. case TOOL_QUIZ :
  6465. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6466. $return .= $this->display_quiz_form('move', $item_id, $row);
  6467. break;
  6468. case TOOL_STUDENTPUBLICATION :
  6469. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6470. $return .= $this->display_student_publication_form('move', $item_id, $row);
  6471. break;
  6472. case TOOL_FORUM :
  6473. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6474. $return .= $this->display_forum_form('move', $item_id, $row);
  6475. break;
  6476. case TOOL_THREAD :
  6477. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6478. $return .= $this->display_forum_form('move', $item_id, $row);
  6479. break;
  6480. }
  6481. }
  6482. return $return;
  6483. }
  6484. /**
  6485. * Displays a basic form on the overview page for changing the item title and the item description.
  6486. * @param string $item_type
  6487. * @param string $title
  6488. * @param array $data
  6489. * @return string
  6490. */
  6491. public function display_item_small_form($item_type, $title = '', $data) {
  6492. global $charset;
  6493. $return .= '<div class="lp_small_form">' . "\n";
  6494. $return .= '<p class="lp_title">' . $title . '</p>';
  6495. $return .= '<form method="post">' . "\n";
  6496. $return .= '<table cellpadding="0" cellspacing="0" class="lp_form">';
  6497. $return .= "\t\t" . '<tr>' . "\n";
  6498. $return .= "\t\t\t" . '<td class="label"><label for="idTitle">Title&nbsp;:</label></td>' . "\n";
  6499. $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";
  6500. $return .= "\t\t" . '</tr>' . "\n";
  6501. // It said these lines of code - see SVN#11724 and SVN#10770
  6502. //$return .= "\t\t" . '<tr>' . "\n";
  6503. //$return .= "\t\t\t" . '<td class="label"><label for="idDescription">Description&nbsp;:</label></td>' . "\n";
  6504. //$return .= "\t\t\t" . '<td class="input"><textarea class="small_form" id="idDescription" name="description" rows="4">' . $data['description'] . '</textarea></td>' . "\n";
  6505. //$return .= "\t\t" . '</tr>' . "\n";
  6506. $return .= "\t\t" . '<tr>' . "\n";
  6507. $return .= "\t\t\t" . '<td colspan="2"><button class="save" name="submit_button" type="submit">' . get_lang('Save') . '</button></td>' . "\n";
  6508. $return .= "\t\t" . '</tr>' . "\n";
  6509. $return .= "\t\t" . '</table>' . "\n";
  6510. $return .= "\t" . '<input name="parent" type="hidden" value="' . $data['parent_item_id'] . '"/>' . "\n";
  6511. $return .= "\t" . '<input name="previous" type="hidden" value="' . $data['previous_item_id'] . '"/>' . "\n";
  6512. $return .= '</form>';
  6513. $return .= '</div>';
  6514. return $return;
  6515. }
  6516. /**
  6517. * Return HTML form to allow prerequisites selection
  6518. * @param integer Item ID
  6519. * @return string HTML form
  6520. */
  6521. public function display_item_prerequisites_form($item_id) {
  6522. global $charset;
  6523. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  6524. /* Current prerequisite */
  6525. $sql = "
  6526. SELECT *
  6527. FROM " . $tbl_lp_item . "
  6528. WHERE id = " . $item_id;
  6529. $result = Database::query($sql);
  6530. $row = Database :: fetch_array($result);
  6531. $preq_id = $row['prerequisite'];
  6532. //$preq_mastery = $row['mastery_score'];
  6533. //$preq_max = $row['max_score'];
  6534. $return = $this->display_manipulate($item_id, TOOL_DOCUMENT);
  6535. $return = ' <div class="row">
  6536. <div class="form_header">';
  6537. $return .= get_lang('AddEditPrerequisites');
  6538. $return .= '</div> </div>';
  6539. $return .= '<div class="sectioncomment">';
  6540. $return .= '<form method="POST">';
  6541. $return .= '<table class="lp_prerequisites" style="border-collapse:collapse;">';
  6542. $return .= '<tr style="border-collapse:collapse;">';
  6543. $return .= '<th height="24" style="border:1px solid gray; background-color:#F0F0F0;">' . get_lang('Prerequisites') . '</th>';
  6544. $return .= '<th width="70" height="24" style="border:1px solid gray; background-color:#F0F0F0;">' . get_lang('Minimum') . '</th>';
  6545. $return .= '<th width="70" height="24" style="border:1px solid gray; background-color:#F0F0F0;">' . get_lang('Maximum') . '</th>';
  6546. $return .= '</tr>';
  6547. // Adding the none option to the prerequisites see http://www.chamilo.org/es/node/146
  6548. $return .= '<tr >';
  6549. $return .= '<td colspan="3" class="radio" style="border:1px solid gray;border-collapse:collapse;">';
  6550. $return .= '<input checked="checked" id="idNone" name="prerequisites" style="margin-left:0; margin-right:10px;" type="radio" />';
  6551. $return .= '<label for="idNone">' . get_lang('None') . '</label>';
  6552. $return .= '</td><td />';
  6553. $return .= '</tr>';
  6554. $sql = "SELECT * FROM " . $tbl_lp_item . " WHERE lp_id = " . $this->lp_id;
  6555. $result = Database::query($sql);
  6556. $arrLP = array ();
  6557. while ($row = Database :: fetch_array($result)) {
  6558. $arrLP[] = array (
  6559. 'id' => $row['id'],
  6560. 'item_type' => $row['item_type'],
  6561. 'title' => $row['title'],
  6562. 'ref' => $row['ref'],
  6563. 'description' => $row['description'],
  6564. 'parent_item_id' => $row['parent_item_id'],
  6565. 'previous_item_id' => $row['previous_item_id'],
  6566. 'next_item_id' => $row['next_item_id'],
  6567. 'max_score' => $row['max_score'],
  6568. 'min_score' => $row['min_score'],
  6569. 'mastery_score' => $row['mastery_score'],
  6570. 'prerequisite' => $row['prerequisite'],
  6571. 'next_item_id' => $row['next_item_id'],
  6572. 'display_order' => $row['display_order']
  6573. );
  6574. if ($row['ref'] == $preq_id) {
  6575. $preq_mastery = $row['mastery_score'];
  6576. $preq_max = $row['max_score'];
  6577. }
  6578. }
  6579. $this->tree_array($arrLP);
  6580. $arrLP = $this->arrMenu;
  6581. unset ($this->arrMenu);
  6582. for ($i = 0; $i < count($arrLP); $i++) {
  6583. if ($arrLP[$i]['id'] == $item_id)
  6584. break;
  6585. $return .= '<tr >';
  6586. $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"' : '') . '>';
  6587. $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'] . '" />';
  6588. $icon_name = str_replace(' ', '', $arrLP[$i]['item_type']);
  6589. if (file_exists('../img/lp_' . $icon_name . '.png')) {
  6590. $return .= '<img alt="" src="../img/lp_' . $icon_name . '.png" style="margin-right:5px;" title="" />';
  6591. } else
  6592. if (file_exists('../img/lp_' . $icon_name . '.gif')) {
  6593. $return .= '<img alt="" src="../img/lp_' . $icon_name . '.gif" style="margin-right:5px;" title="" />';
  6594. } else {
  6595. $return .= Display::return_icon('folder_document.gif','',array('style'=>'margin-right:5px;'));
  6596. }
  6597. $return .= '<label for="id' . $arrLP[$i]['id'] . '">' . $arrLP[$i]['title'] . '</label>';
  6598. $return .= '</td>';
  6599. //$return .= '<td class="radio"' . (($arrLP[$i]['item_type'] != TOOL_HOTPOTATOES) ? ' colspan="3"' : '') . ' />';
  6600. if ($arrLP[$i]['item_type'] == TOOL_QUIZ) {
  6601. $return .= '<td class="exercise" style="border:1px solid #B0B0B0;">';
  6602. $return .= '<center><input size="4" maxlength="3" name="min_' . $arrLP[$i]['id'] . '" type="text" value="' . (($arrLP[$i]['id'] == $preq_id) ? $preq_mastery : 0) . '" /></center>';
  6603. $return .= '</td>';
  6604. $return .= '<td class="exercise" style="border:1px solid #B0B0B0;">';
  6605. $return .= '<center><input size="4" maxlength="3" name="max_' . $arrLP[$i]['id'] . '" type="text" value="' . $arrLP[$i]['max_score'] . '" disabled="true" /></center>';
  6606. $return .= '</td>';
  6607. }
  6608. if ($arrLP[$i]['item_type'] == TOOL_HOTPOTATOES) {
  6609. $return .= '<td class="exercise" style="border:1px solid #B0B0B0;">';
  6610. $return .= '<center><input size="4" maxlength="3" name="min_' . $arrLP[$i]['id'] . '" type="text" value="' . (($arrLP[$i]['id'] == $preq_id) ? $preq_mastery : 0) . '" /></center>';
  6611. $return .= '</td>';
  6612. $return .= '<td class="exercise" style="border:1px solid #B0B0B0;">';
  6613. $return .= '<center><input size="4" maxlength="3" name="max_' . $arrLP[$i]['id'] . '" type="text" value="' . $arrLP[$i]['max_score'] . '" disabled="true" /></center>';
  6614. $return .= '</td>';
  6615. }
  6616. $return .= '</tr>';
  6617. }
  6618. $return .= '<tr>';
  6619. $return .= '<td colspan="3">';
  6620. $return .= '</td>';
  6621. $return .= '</tr>';
  6622. $return .= '</table>';
  6623. $return .= '<div style="padding-top:3px;">';
  6624. $return .= '<button class="save" name="submit_button" type="submit">' . get_lang('ModifyPrerequisites') . ' </button></td>' . "\n";
  6625. $return .= '</div>';
  6626. $return .= '</form>';
  6627. $return .= '</div>';
  6628. return $return;
  6629. }
  6630. /**
  6631. * Return HTML list to allow prerequisites selection for lp
  6632. * @param integer Item ID
  6633. * @return string HTML form
  6634. */
  6635. public function display_lp_prerequisites_list() {
  6636. global $charset;
  6637. $lp_id = $this->lp_id;
  6638. $tbl_lp = Database :: get_course_table(TABLE_LP_MAIN);
  6639. // get current prerequisite
  6640. $sql = "SELECT * FROM $tbl_lp WHERE id = $lp_id ";
  6641. $result = Database::query($sql);
  6642. $row = Database :: fetch_array($result);
  6643. $preq_id = $row['prerequisite'];
  6644. $session_id = api_get_session_id();
  6645. $session_condition = api_get_session_condition($session_id, false);
  6646. $sql = "SELECT * FROM $tbl_lp $session_condition ORDER BY display_order ";
  6647. $rs = Database::query($sql);
  6648. $return = '';
  6649. $return .= '<select name="prerequisites" >';
  6650. $return .= '<option value="0">'.get_lang('None').'</option>';
  6651. if (Database::num_rows($rs) > 0) {
  6652. while ($row = Database::fetch_array($rs)) {
  6653. if ($row['id'] == $lp_id) {
  6654. continue;
  6655. }
  6656. $return .= '<option value="'.$row['id'].'" '.(($row['id']==$preq_id)?' selected ' : '').'>'.$row['name'].'</option>';
  6657. }
  6658. }
  6659. $return .= '</select>';
  6660. return $return;
  6661. }
  6662. /**
  6663. * Creates a list with all the documents in it
  6664. * @return string
  6665. */
  6666. public function get_documents() {
  6667. global $_course;
  6668. $tbl_doc = Database :: get_course_table(TABLE_DOCUMENT);
  6669. $tbl_item_prop = Database::get_course_table(TABLE_ITEM_PROPERTY);
  6670. $tbl_course = Database::get_main_table(TABLE_MAIN_COURSE);
  6671. $path = '/';
  6672. $path = Database::escape_string(str_replace('_', '\_', $path));
  6673. $added_slash = ($path == '/') ? '' : '/';
  6674. //condition for the session
  6675. $current_session_id = api_get_session_id();
  6676. $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]}')))";
  6677. $sql_doc = "SELECT docs.*
  6678. FROM $tbl_item_prop AS last, $tbl_doc AS docs
  6679. WHERE docs.id = last.ref
  6680. AND docs.path LIKE '".$path.$added_slash."%'
  6681. AND docs.path NOT LIKE '%_DELETED_%'
  6682. AND last.tool = '".TOOL_DOCUMENT."' $condition_session ORDER BY docs.path ASC";
  6683. //$sql_doc = "SELECT * FROM $tbl_doc WHERE path NOT LIKE '%_DELETED_%' ORDER BY path ASC";
  6684. $res_doc = Database::query($sql_doc);
  6685. $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>';
  6686. $return .= '<div class="lp_resource_elements" id="resDoc">';
  6687. $resources = Database::store_result($res_doc);
  6688. $resources_sorted = array();
  6689. // If you want to debug it, I advise you to do "echo" on the eval statements.
  6690. foreach ($resources as $resource) {
  6691. $resource_paths = explode('/', $resource['path']);
  6692. array_shift($resource_paths);
  6693. $path_to_eval = $last_path = '';
  6694. $is_file = false;
  6695. foreach ($resource_paths as $key => $resource_path) {
  6696. if (strpos($resource_path, '.') === false && $key != count($resource_paths) - 1) { // It's a folder.
  6697. $path_to_eval .= '["' . $resource_path . '"]["files"]';
  6698. } else
  6699. if (strpos($resource_path, '.') !== false)
  6700. $is_file = true;
  6701. $last_path = $resource_path;
  6702. }
  6703. if ($is_file) {
  6704. //eval ('$resources_sorted' . $path_to_eval . '[' . $resource['id'] . '] = "' . $last_path . '";');
  6705. //for backward compatibility
  6706. if (empty($resource['title'])) {
  6707. $resource['title'] = basename($resource['path']);
  6708. }
  6709. eval ('$resources_sorted' . $path_to_eval . '[' . $resource['id'] . '] = "' .$resource['title']."/". $last_path. '";');
  6710. } else {
  6711. eval ('$resources_sorted' . $path_to_eval . '["' . $last_path . '"]["id"]=' . $resource['id'] . ';');
  6712. }
  6713. }
  6714. $return .= $this->write_resources_tree($resources_sorted);
  6715. if (Database :: num_rows($res_doc) == 0) {
  6716. $return .= '<div class="lp_resource_element">' . get_lang('NoDocuments') . '</div>';
  6717. }
  6718. $return .= '</div>';
  6719. return $return;
  6720. }
  6721. /**
  6722. * Generate and return an HTML list of resources based on a given array.
  6723. * This list is used to show the course creator a list of available resources to choose from
  6724. * when creating a learning path.
  6725. * @param array Array of elements to add to the list
  6726. * @param integer Enables the tree display by shifting the new elements a certain distance to the right
  6727. * @return string The HTML list
  6728. */
  6729. public function write_resources_tree($resources_sorted, $num = 0) {
  6730. require_once api_get_path(LIBRARY_PATH).'fileDisplay.lib.php';
  6731. if (count($resources_sorted) > 0) {
  6732. foreach ($resources_sorted as $key => $resource) {
  6733. if (is_int($resource['id'])) {
  6734. // It's a folder.
  6735. //hide some folders
  6736. if (in_array($key, array('shared_folder','chat_files', 'HotPotatoes_files', 'css', 'certificates'))){
  6737. continue;
  6738. }elseif(preg_match('/_groupdocs/', $key)){
  6739. continue;
  6740. }elseif(preg_match('/sf_user_/', $key)){
  6741. continue;
  6742. }elseif(preg_match('/shared_folder_session_/', $key)){
  6743. continue;
  6744. }
  6745. //trad some titles
  6746. if ($key=='images'){
  6747. $key=get_lang('Images');
  6748. }
  6749. elseif($key=='gallery'){
  6750. $key=get_lang('Gallery');
  6751. }
  6752. elseif($key=='flash'){
  6753. $key=get_lang('Flash');
  6754. }
  6755. elseif($key=='audio'){
  6756. $key=get_lang('Audio');
  6757. }
  6758. elseif($key=='video'){
  6759. $key=get_lang('Video');
  6760. }
  6761. $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'] . '">';
  6762. $return .= $this->write_resources_tree($resource['files'], $num +1);
  6763. $return .= '</div></div>';
  6764. } else {
  6765. if (!is_array($resource)) {
  6766. // It's a file.
  6767. $icon = choose_image($resource);
  6768. $position = strrpos($icon, '.');
  6769. $icon = substr($icon, 0, $position) . '_small.gif';
  6770. $file_info = explode('/', $resource);
  6771. $my_file_title = $file_info[0];
  6772. $my_file_name = $file_info[1];
  6773. //$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>';
  6774. // Show the "image name" not the filename of the image.
  6775. $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"; }
  6776. }
  6777. }
  6778. }
  6779. return $return;
  6780. }
  6781. /**
  6782. * Creates a list with all the exercises (quiz) in it
  6783. * @return string
  6784. */
  6785. public function get_exercises() {
  6786. // New for hotpotatoes.
  6787. $uploadPath = DIR_HOTPOTATOES; //defined in main_api
  6788. $tbl_doc = Database :: get_course_table(TABLE_DOCUMENT);
  6789. $tbl_quiz = Database :: get_course_table(TABLE_QUIZ_TEST);
  6790. $session_id = api_get_session_id();
  6791. $condition_session = api_get_session_condition($session_id);
  6792. $sql_quiz = "
  6793. SELECT *
  6794. FROM " . $tbl_quiz . "
  6795. WHERE active<>'-1' $condition_session
  6796. ORDER BY title ASC";
  6797. $sql_hot = "SELECT * FROM " . $tbl_doc . " " .
  6798. " WHERE path LIKE '" . $uploadPath . "/%/%htm%' $condition_session " .
  6799. " ORDER BY id ASC";
  6800. $res_quiz = Database::query($sql_quiz);
  6801. $res_hot = Database::query($sql_hot);
  6802. $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>';
  6803. $return .= '<div class="lp_resource_elements" id="resExercise">';
  6804. while ($row_hot = Database :: fetch_array($res_hot)) {
  6805. $return .= '<div class="lp_resource_element">';
  6806. // Display quizhotpotatoes.
  6807. $return .= '<img alt="hp" src="../img/hotpotatoes_s.png" style="margin-right:5px;" title="" width="18px" height="18px" />';
  6808. $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>';
  6809. //$return .= $row_quiz['title'];
  6810. $return .= '</div>';
  6811. }
  6812. while ($row_quiz = Database :: fetch_array($res_quiz)) {
  6813. $return .= '<div class="lp_resource_element">';
  6814. $return .= '<img alt="" src="../img/quizz_small.gif" style="margin-right:5px;" title="" />';
  6815. $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>';
  6816. //$return .= $row_quiz['title'];
  6817. $return .= '</div>';
  6818. }
  6819. if (Database :: num_rows($res_quiz) == 0) {
  6820. $return .= '<div class="lp_resource_element">' . get_lang('NoExercisesAvailable') . '</div>';
  6821. }
  6822. $return .= '<div class="lp_resource_element">';
  6823. $return .= '<img alt="" src="../img/new_test_small.gif" style="margin-right:5px;" title="" />';
  6824. $return .= '<a href="' . api_get_path(REL_CODE_PATH) . 'exercice/exercise_admin.php">' . get_lang('NewExercise') . '</a>';
  6825. $return .= '</div>';
  6826. $return .= '</div>';
  6827. return $return;
  6828. }
  6829. /**
  6830. * Creates a list with all the links in it
  6831. * @return string
  6832. */
  6833. public function get_links() {
  6834. $tbl_link = Database :: get_course_table(TABLE_LINK);
  6835. $session_id = api_get_session_id();
  6836. $condition_session = api_get_session_condition($session_id,false);
  6837. $sql_link = "SELECT * FROM $tbl_link $condition_session ORDER BY title ASC";
  6838. $res_link = Database::query($sql_link);
  6839. $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>';
  6840. $return .= '<div class="lp_resource_elements" id="resLink">';
  6841. while ($row_link = Database :: fetch_array($res_link)) {
  6842. $return .= '<div class="lp_resource_element">';
  6843. $return .= '<img alt="" src="../img/lp_link.gif" style="margin-right:5px;" title="" />';
  6844. $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>';
  6845. $return .= '</div>';
  6846. }
  6847. $return .= '<div class="lp_resource_element">';
  6848. $return .= '<img alt="" src="../img/linksnew.gif" style="margin-right:5px;width:16px" title="" />';
  6849. $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>';
  6850. $return .= '</div>';
  6851. if (Database :: num_rows($res_link) == 0)
  6852. $return .= '<div class="lp_resource_element">' . get_lang('NoLinksAvailable') . '</div>';
  6853. $return .= '</div>';
  6854. return $return;
  6855. }
  6856. /**
  6857. * Creates a list with all the student publications in it
  6858. * @return unknown
  6859. */
  6860. public function get_student_publications() {
  6861. $tbl_student = Database :: get_course_table(TABLE_STUDENT_PUBLICATION);
  6862. $session_id = api_get_session_id();
  6863. $condition_session = api_get_session_condition($session_id, false);
  6864. $sql_student = "SELECT * FROM $tbl_student $condition_session ORDER BY title ASC";
  6865. $res_student = Database::query($sql_student);
  6866. $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>';
  6867. $return .= '<div class="lp_resource_elements" id="resStudent">';
  6868. $return .= '<div class="lp_resource_element">';
  6869. $return .= '<img align="left" alt="" src="../img/works_small.gif" style="margin-right:5px;" title="" />';
  6870. $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>';
  6871. $return .= '</div>';
  6872. $return .= '</div>';
  6873. return $return;
  6874. }
  6875. /**
  6876. * Creates a list with all the forums in it
  6877. * @return string
  6878. */
  6879. public function get_forums() {
  6880. include '../forum/forumfunction.inc.php';
  6881. include '../forum/forumconfig.inc.php';
  6882. global $table_forums, $table_threads, $table_posts, $table_item_property, $table_users;
  6883. $table_forums = Database :: get_course_table(TABLE_FORUM);
  6884. $table_threads = Database :: get_course_table(TABLE_FORUM_THREAD);
  6885. $table_posts = Database :: get_course_table(TABLE_FORUM_POST);
  6886. $table_item_property = Database :: get_course_table(TABLE_ITEM_PROPERTY);
  6887. $table_users = Database :: get_main_table(TABLE_MAIN_USER);
  6888. $a_forums = get_forums();
  6889. $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>';
  6890. $return .= '<div class="lp_resource_elements" style="border:1px solid #999999;" id="forums">';
  6891. foreach ($a_forums as $forum) {
  6892. $return .= '<div class="lp_resource_element">';
  6893. $return .= '<script type="text/javascript">
  6894. function toggle_forum(forum_id){
  6895. if(document.getElementById("forum_"+forum_id+"_content").style.display == "none"){
  6896. document.getElementById("forum_"+forum_id+"_content").style.display = "block";
  6897. document.getElementById("forum_"+forum_id+"_opener").src = "' . api_get_path(WEB_IMG_PATH) . 'remove.gif";
  6898. }
  6899. else {
  6900. document.getElementById("forum_"+forum_id+"_content").style.display = "none";
  6901. document.getElementById("forum_"+forum_id+"_opener").src = "' . api_get_path(WEB_IMG_PATH) . 'add.gif";
  6902. }
  6903. }
  6904. </script>
  6905. ';
  6906. if (!empty($forum['forum_id'])) {
  6907. $return .= '<img alt="" src="../img/lp_forum.gif" style="margin-right:5px;" title="" />';
  6908. $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>
  6909. <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">';
  6910. }
  6911. $a_threads = get_threads($forum['forum_id']);
  6912. if (is_array($a_threads)) {
  6913. foreach ($a_threads as $thread) {
  6914. $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>';
  6915. }
  6916. }
  6917. $return .= '</ul></div>';
  6918. }
  6919. $return .= '<div class="lp_resource_element">';
  6920. $return .= '<img alt="" src="../img/forum_new_small.gif" style="margin-right:5px;" title="" />';
  6921. $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>';
  6922. $return .= '</div>';
  6923. return $return;
  6924. }
  6925. /**
  6926. * // TODO: The output encoding should be equal to the system encoding.
  6927. *
  6928. * Exports the learning path as a SCORM package. This is the main function that
  6929. * gathers the content, transforms it, writes the imsmanifest.xml file, zips the
  6930. * whole thing and returns the zip.
  6931. *
  6932. * This method needs to be called in PHP5, as it will fail with non-adequate
  6933. * XML package (like the ones for PHP4), and it is *not* a static method, so
  6934. * you need to call it on a learnpath object.
  6935. * @TODO The method might be redefined later on in the scorm class itself to avoid
  6936. * creating a SCORM structure if there is one already. However, if the initial SCORM
  6937. * path has been modified, it should use the generic method here below.
  6938. * @TODO link this function with the export_lp() function in the same class
  6939. * @param string Optional name of zip file. If none, title of learnpath is
  6940. * domesticated and trailed with ".zip"
  6941. * @return string Returns the zip package string, or null if error
  6942. */
  6943. public function scorm_export() {
  6944. global $_course;
  6945. // Remove memory and time limits as much as possible as this might be a long process...
  6946. if (function_exists('ini_set')) {
  6947. $mem = ini_get('memory_limit');
  6948. if (substr($mem, -1, 1) == 'M') {
  6949. $mem_num = substr($mem, 0, -1);
  6950. if ($mem_num < 128) {
  6951. ini_set('memory_limit', '128M');
  6952. }
  6953. } else {
  6954. ini_set('memory_limit', '128M');
  6955. }
  6956. ini_set('max_execution_time', 600);
  6957. //} else {
  6958. //error_log('Scorm export: could not change memory and time limits', 0);
  6959. }
  6960. // Create the zip handler (this will remain available throughout the method).
  6961. $archive_path = api_get_path(SYS_ARCHIVE_PATH);
  6962. $sys_course_path = api_get_path(SYS_COURSE_PATH);
  6963. $temp_dir_short = uniqid();
  6964. $temp_zip_dir = $archive_path.'/'.$temp_dir_short;
  6965. $temp_zip_file = $temp_zip_dir.'/'.md5(time()).'.zip';
  6966. $zip_folder = new PclZip($temp_zip_file);
  6967. $current_course_path = api_get_path(SYS_COURSE_PATH).api_get_course_path();
  6968. $root_path = $main_path = api_get_path(SYS_PATH);
  6969. $files_cleanup = array();
  6970. // Place to temporarily stash the zipfiles.
  6971. // create the temp dir if it doesn't exist
  6972. // or do a cleanup befor creating the zipfile.
  6973. if (!is_dir($temp_zip_dir)) {
  6974. mkdir($temp_zip_dir, api_get_permissions_for_new_directories());
  6975. } else {
  6976. // Cleanup: Check the temp dir for old files and delete them.
  6977. $handle = opendir($temp_zip_dir);
  6978. while (false !== ($file = readdir($handle))) {
  6979. if ($file != '.' && $file != '..') {
  6980. unlink("$temp_zip_dir/$file");
  6981. }
  6982. }
  6983. closedir($handle);
  6984. }
  6985. $zip_files = $zip_files_abs = $zip_files_dist = array();
  6986. if (is_dir($current_course_path.'/scorm/'.$this->path) && is_file($current_course_path.'/scorm/'.$this->path.'/imsmanifest.xml')) {
  6987. // Remove the possible . at the end of the path.
  6988. $dest_path_to_lp = substr($this->path, -1) == '.' ? substr($this->path, 0, -1) : $this->path;
  6989. $dest_path_to_scorm_folder = str_replace('//','/',$temp_zip_dir.'/scorm/'.$dest_path_to_lp);
  6990. mkdir($dest_path_to_scorm_folder, api_get_permissions_for_new_directories(), true);
  6991. $zip_files_dist = copyr($current_course_path.'/scorm/'.$this->path, $dest_path_to_scorm_folder, array('imsmanifest'), $zip_files);
  6992. }
  6993. // Build a dummy imsmanifest structure. Do not add to the zip yet (we still need it).
  6994. // This structure is developed following regulations for SCORM 1.2 packaging in the SCORM 1.2 Content
  6995. // Aggregation Model official document, secion "2.3 Content Packaging".
  6996. $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.
  6997. $root = $xmldoc->createElement('manifest');
  6998. $root->setAttribute('identifier', 'SingleCourseManifest');
  6999. $root->setAttribute('version', '1.1');
  7000. $root->setAttribute('xmlns', 'http://www.imsproject.org/xsd/imscp_rootv1p1p2');
  7001. $root->setAttribute('xmlns:adlcp', 'http://www.adlnet.org/xsd/adlcp_rootv1p2');
  7002. $root->setAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance');
  7003. $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');
  7004. // Build mandatory sub-root container elements.
  7005. $metadata = $xmldoc->createElement('metadata');
  7006. $md_schema = $xmldoc->createElement('schema', 'ADL SCORM');
  7007. $metadata->appendChild($md_schema);
  7008. $md_schemaversion = $xmldoc->createElement('schemaversion', '1.2');
  7009. $metadata->appendChild($md_schemaversion);
  7010. $root->appendChild($metadata);
  7011. $organizations = $xmldoc->createElement('organizations');
  7012. $resources = $xmldoc->createElement('resources');
  7013. // Build the only organization we will use in building our learnpaths.
  7014. $organizations->setAttribute('default', 'chamilo_scorm_export');
  7015. $organization = $xmldoc->createElement('organization');
  7016. $organization->setAttribute('identifier', 'chamilo_scorm_export');
  7017. // To set the title of the SCORM entity (=organization), we take the name given
  7018. // in Chamilo and convert it to HTML entities using the Chamilo charset (not the
  7019. // learning path charset) as it is the encoding that defines how it is stored
  7020. // in the database. Then we convert it to HTML entities again as the "&" character
  7021. // alone is not authorized in XML (must be &amp;).
  7022. // The title is then decoded twice when extracting (see scorm::parse_manifest).
  7023. $org_title = $xmldoc->createElement('title', api_utf8_encode($this->get_name()));
  7024. $organization->appendChild($org_title);
  7025. // For each element, add it to the imsmanifest structure, then add it to the zip.
  7026. // Always call the learnpathItem->scorm_export() method to change it to the SCORM format.
  7027. $link_updates = array();
  7028. foreach ($this->items as $index => $item) {
  7029. if (!in_array($item->type, array(TOOL_QUIZ, TOOL_FORUM, TOOL_THREAD, TOOL_LINK, TOOL_STUDENTPUBLICATION))) {
  7030. // Get included documents from this item.
  7031. if ($item->type == 'sco')
  7032. $inc_docs = $item->get_resources_from_source(null, api_get_path(SYS_COURSE_PATH).api_get_course_path().'/'.'scorm/'.$this->path.'/'.$item->get_path());
  7033. else
  7034. $inc_docs = $item->get_resources_from_source();
  7035. // Give a child element <item> to the <organization> element.
  7036. $my_item_id = $item->get_id();
  7037. $my_item = $xmldoc->createElement('item');
  7038. $my_item->setAttribute('identifier', 'ITEM_'.$my_item_id);
  7039. $my_item->setAttribute('identifierref', 'RESOURCE_'.$my_item_id);
  7040. $my_item->setAttribute('isvisible', 'true');
  7041. // Give a child element <title> to the <item> element.
  7042. $my_title = $xmldoc->createElement('title', htmlspecialchars(api_utf8_encode($item->get_title()), ENT_QUOTES, 'UTF-8'));
  7043. $my_item->appendChild($my_title);
  7044. // Give a child element <adlcp:prerequisites> to the <item> element.
  7045. $my_prereqs = $xmldoc->createElement('adlcp:prerequisites', $this->get_scorm_prereq_string($my_item_id));
  7046. $my_prereqs->setAttribute('type', 'aicc_script');
  7047. $my_item->appendChild($my_prereqs);
  7048. // Give a child element <adlcp:maxtimeallowed> to the <item> element - not yet supported.
  7049. //$xmldoc->createElement('adlcp:maxtimeallowed','');
  7050. // Give a child element <adlcp:timelimitaction> to the <item> element - not yet supported.
  7051. //$xmldoc->createElement('adlcp:timelimitaction','');
  7052. // Give a child element <adlcp:datafromlms> to the <item> element - not yet supported.
  7053. //$xmldoc->createElement('adlcp:datafromlms','');
  7054. // Give a child element <adlcp:masteryscore> to the <item> element.
  7055. $my_masteryscore = $xmldoc->createElement('adlcp:masteryscore', $item->get_mastery_score());
  7056. $my_item->appendChild($my_masteryscore);
  7057. // Attach this item to the organization element or hits parent if there is one.
  7058. if (!empty($item->parent) && $item->parent != 0) {
  7059. $children = $organization->childNodes;
  7060. $possible_parent = &$this->get_scorm_xml_node($children, 'ITEM_'.$item->parent);
  7061. if (is_object($possible_parent)) {
  7062. $possible_parent->appendChild($my_item);
  7063. } else {
  7064. if ($this->debug > 0) { error_log('Parent ITEM_'.$item->parent.' of item ITEM_'.$my_item_id.' not found'); }
  7065. }
  7066. } else {
  7067. if ($this->debug > 0) { error_log('No parent'); }
  7068. $organization->appendChild($my_item);
  7069. }
  7070. // Get the path of the file(s) from the course directory root.
  7071. $my_file_path = $item->get_file_path('scorm/'.$this->path.'/');
  7072. //$my_xml_file_path = api_htmlentities(api_utf8_encode($my_file_path), ENT_QUOTES, 'UTF-8');
  7073. $my_xml_file_path = $my_file_path;
  7074. $my_sub_dir = dirname($my_file_path);
  7075. $my_sub_dir = str_replace('\\', '/', $my_sub_dir);
  7076. //$my_xml_sub_dir = api_htmlentities(api_utf8_encode($my_sub_dir), ENT_QUOTES, 'UTF-8');
  7077. $my_xml_sub_dir = $my_sub_dir;
  7078. // Give a <resource> child to the <resources> element
  7079. $my_resource = $xmldoc->createElement('resource');
  7080. $my_resource->setAttribute('identifier', 'RESOURCE_'.$item->get_id());
  7081. $my_resource->setAttribute('type', 'webcontent');
  7082. $my_resource->setAttribute('href', $my_xml_file_path);
  7083. // adlcp:scormtype can be either 'sco' or 'asset'.
  7084. if ($item->type == 'sco') {
  7085. $my_resource->setAttribute('adlcp:scormtype', 'sco');
  7086. } else {
  7087. $my_resource->setAttribute('adlcp:scormtype', 'asset');
  7088. }
  7089. // xml:base is the base directory to find the files declared in this resource.
  7090. $my_resource->setAttribute('xml:base', '');
  7091. // Give a <file> child to the <resource> element.
  7092. $my_file = $xmldoc->createElement('file');
  7093. $my_file->setAttribute('href', $my_xml_file_path);
  7094. $my_resource->appendChild($my_file);
  7095. // Dependency to other files - not yet supported.
  7096. $i = 1;
  7097. foreach ($inc_docs as $doc_info) {
  7098. if (count($doc_info) < 1 || empty($doc_info[0])) { continue; }
  7099. $my_dep = $xmldoc->createElement('resource');
  7100. $res_id = 'RESOURCE_'.$item->get_id().'_'.$i;
  7101. $my_dep->setAttribute('identifier', $res_id);
  7102. $my_dep->setAttribute('type', 'webcontent');
  7103. $my_dep->setAttribute('adlcp:scormtype', 'asset');
  7104. $my_dep_file = $xmldoc->createElement('file');
  7105. // Check type of URL.
  7106. //error_log(__LINE__.'Now dealing with '.$doc_info[0].' of type '.$doc_info[1].'-'.$doc_info[2], 0);
  7107. if ($doc_info[1] == 'remote') {
  7108. // Remote file. Save url as is.
  7109. $my_dep_file->setAttribute('href', $doc_info[0]);
  7110. $my_dep->setAttribute('xml:base', '');
  7111. } elseif ($doc_info[1] == 'local') {
  7112. switch ($doc_info[2]) {
  7113. case 'url': // Local URL - save path as url for now, don't zip file.
  7114. $abs_path = api_get_path(SYS_PATH).str_replace(api_get_path(WEB_PATH), '', $doc_info[0]);
  7115. $current_dir = dirname($abs_path);
  7116. $current_dir = str_replace('\\', '/', $current_dir);
  7117. $file_path = realpath($abs_path);
  7118. $file_path = str_replace('\\', '/', $file_path);
  7119. $my_dep_file->setAttribute('href', $file_path);
  7120. $my_dep->setAttribute('xml:base', '');
  7121. if (strstr($file_path, $main_path) !== false) {
  7122. // The calculated real path is really inside Chamilo's root path.
  7123. // Reduce file path to what's under the DocumentRoot.
  7124. $file_path = substr($file_path, strlen($root_path) - 1);
  7125. //echo $file_path;echo '<br /><br />';
  7126. //error_log(__LINE__.'Reduced url path: '.$file_path, 0);
  7127. $zip_files_abs[] = $file_path;
  7128. $link_updates[$my_file_path][] = array('orig' => $doc_info[0], 'dest' => $file_path);
  7129. $my_dep_file->setAttribute('href', $file_path);
  7130. $my_dep->setAttribute('xml:base', '');
  7131. }
  7132. elseif (empty($file_path)) {
  7133. /*$document_root = substr(api_get_path(SYS_PATH), 0, strpos(api_get_path(SYS_PATH), api_get_path(REL_PATH)));
  7134. if (strpos($document_root, -1) == '/') {
  7135. $document_root = substr(0, -1, $document_root);
  7136. }*/
  7137. $file_path = $_SERVER['DOCUMENT_ROOT'].$abs_path;
  7138. $file_path = str_replace('//', '/', $file_path);
  7139. if (file_exists($file_path)) {
  7140. $file_path = substr($file_path, strlen($current_dir)); // We get the relative path.
  7141. $zip_files[] = $my_sub_dir.'/'.$file_path;
  7142. $link_updates[$my_file_path][] = array('orig' => $doc_info[0], 'dest' => $file_path);
  7143. $my_dep_file->setAttribute('href', $file_path);
  7144. $my_dep->setAttribute('xml:base', '');
  7145. }
  7146. }
  7147. break;
  7148. case 'abs': // Absolute path from DocumentRoot. Save file and leave path as is in the zip.
  7149. $my_dep_file->setAttribute('href', $doc_info[0]);
  7150. $my_dep->setAttribute('xml:base', '');
  7151. //$current_dir = str_replace('\\', '/', dirname($current_course_path.'/'.$item->get_file_path())).'/';
  7152. // The next lines fix a bug when using the "subdir" mode of Chamilo, whereas
  7153. // an image path would be constructed as /var/www/subdir/subdir/img/foo.bar
  7154. $abs_img_path_without_subdir = $doc_info[0];
  7155. $relp = api_get_path(REL_PATH); // The url-append config param.
  7156. $pos = strpos($abs_img_path_without_subdir, $relp);
  7157. if ($pos === 0) {
  7158. $abs_img_path_without_subdir = '/'.substr($abs_img_path_without_subdir, strlen($relp));
  7159. }
  7160. //$file_path = realpath(api_get_path(SYS_PATH).$doc_info[0]);
  7161. $file_path = realpath(api_get_path(SYS_PATH).$abs_img_path_without_subdir);
  7162. $file_path = str_replace('\\', '/', $file_path);
  7163. $file_path = str_replace('//', '/', $file_path);
  7164. //error_log(__LINE__.'Abs path: '.$file_path, 0);
  7165. // Prepare the current directory path (until just under 'document') with a trailing slash.
  7166. $cur_path = substr($current_course_path, -1) == '/' ? $current_course_path : $current_course_path.'/';
  7167. // Check if the current document is in that path.
  7168. if (strstr($file_path, $cur_path) !== false) {
  7169. // The document is in that path, now get the relative path
  7170. // to the containing document.
  7171. $orig_file_path = dirname($cur_path.$my_file_path).'/';
  7172. $orig_file_path = str_replace('\\', '/', $orig_file_path);
  7173. $relative_path = '';
  7174. if (strstr($file_path, $cur_path) !== false) {
  7175. $relative_path = substr($file_path, strlen($orig_file_path));
  7176. $file_path = substr($file_path, strlen($cur_path));
  7177. } else {
  7178. // This case is still a problem as it's difficult to calculate a relative path easily
  7179. // might still generate wrong links.
  7180. //$file_path = substr($file_path,strlen($cur_path));
  7181. // Calculate the directory path to the current file (without trailing slash).
  7182. $my_relative_path = dirname($file_path);
  7183. $my_relative_path = str_replace('\\', '/', $my_relative_path);
  7184. $my_relative_file = basename($file_path);
  7185. // Calculate the directory path to the containing file (without trailing slash).
  7186. $my_orig_file_path = substr($orig_file_path, 0, -1);
  7187. $dotdot = '';
  7188. $subdir = '';
  7189. while (strstr($my_relative_path, $my_orig_file_path) === false && (strlen($my_orig_file_path) > 1) && (strlen($my_relative_path) > 1)) {
  7190. $my_relative_path2 = dirname($my_relative_path);
  7191. $my_relative_path2 = str_replace('\\', '/', $my_relative_path2);
  7192. $my_orig_file_path = dirname($my_orig_file_path);
  7193. $my_orig_file_path = str_replace('\\', '/', $my_orig_file_path);
  7194. $subdir = substr($my_relative_path, strlen($my_relative_path2) + 1).'/'.$subdir;
  7195. $dotdot += '../';
  7196. $my_relative_path = $my_relative_path2;
  7197. }
  7198. $relative_path = $dotdot.$subdir.$my_relative_file;
  7199. }
  7200. // Put the current document in the zip (this array is the array
  7201. // that will manage documents already in the course folder - relative).
  7202. $zip_files[] = $file_path;
  7203. // Update the links to the current document in the containing document (make them relative).
  7204. $link_updates[$my_file_path][] = array('orig' => $doc_info[0], 'dest' => $relative_path);
  7205. $my_dep_file->setAttribute('href', $file_path);
  7206. $my_dep->setAttribute('xml:base', '');
  7207. }
  7208. elseif (strstr($file_path,$main_path) !== false) {
  7209. // The calculated real path is really inside Chamilo's root path.
  7210. // Reduce file path to what's under the DocumentRoot.
  7211. $file_path = substr($file_path, strlen($root_path));
  7212. //echo $file_path;echo '<br /><br />';
  7213. //error_log('Reduced path: '.$file_path, 0);
  7214. $zip_files_abs[] = $file_path;
  7215. $link_updates[$my_file_path][] = array('orig' => $doc_info[0], 'dest' => $file_path);
  7216. $my_dep_file->setAttribute('href', 'document/'.$file_path);
  7217. $my_dep->setAttribute('xml:base', '');
  7218. }
  7219. elseif (empty($file_path)) {
  7220. /*$document_root = substr(api_get_path(SYS_PATH), 0, strpos(api_get_path(SYS_PATH), api_get_path(REL_PATH)));
  7221. if(strpos($document_root,-1) == '/') {
  7222. $document_root = substr(0, -1, $document_root);
  7223. }*/
  7224. $file_path = $_SERVER['DOCUMENT_ROOT'].$doc_info[0];
  7225. $file_path = str_replace('//', '/', $file_path);
  7226. if (file_exists($file_path)) {
  7227. $file_path = substr($file_path,strlen($current_dir)); // We get the relative path.
  7228. $zip_files[] = $my_sub_dir.'/'.$file_path;
  7229. $link_updates[$my_file_path][] = array('orig' => $doc_info[0], 'dest' => $file_path);
  7230. $my_dep_file->setAttribute('href','document/'.$file_path);
  7231. $my_dep->setAttribute('xml:base', '');
  7232. }
  7233. }
  7234. break;
  7235. 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
  7236. if (substr($doc_info[0], 0, 2) == '..') {
  7237. // Relative path going up.
  7238. $current_dir = dirname($current_course_path.'/'.$item->get_file_path()).'/';
  7239. $current_dir = str_replace('\\', '/', $current_dir);
  7240. $file_path = realpath($current_dir.$doc_info[0]);
  7241. $file_path = str_replace('\\', '/', $file_path);
  7242. //error_log($file_path.' <-> '.$main_path,0);
  7243. if (strstr($file_path, $main_path) !== false) {
  7244. // The calculated real path is really inside Chamilo's root path.
  7245. // Reduce file path to what's under the DocumentRoot.
  7246. $file_path = substr($file_path, strlen($root_path));
  7247. //error_log('Reduced path: '.$file_path, 0);
  7248. $zip_files_abs[] = $file_path;
  7249. $link_updates[$my_file_path][] = array('orig' => $doc_info[0], 'dest' => $file_path);
  7250. $my_dep_file->setAttribute('href', 'document/'.$file_path);
  7251. $my_dep->setAttribute('xml:base', '');
  7252. }
  7253. } else {
  7254. $zip_files[] = $my_sub_dir.'/'.$doc_info[0];
  7255. $my_dep_file->setAttribute('href', $doc_info[0]);
  7256. $my_dep->setAttribute('xml:base', $my_xml_sub_dir);
  7257. }
  7258. break;
  7259. default:
  7260. $my_dep_file->setAttribute('href', $doc_info[0]);
  7261. $my_dep->setAttribute('xml:base', '');
  7262. break;
  7263. }
  7264. }
  7265. $my_dep->appendChild($my_dep_file);
  7266. $resources->appendChild($my_dep);
  7267. $dependency = $xmldoc->createElement('dependency');
  7268. $dependency->setAttribute('identifierref', $res_id);
  7269. $my_resource->appendChild($dependency);
  7270. $i++;
  7271. }
  7272. //$my_dependency = $xmldoc->createElement('dependency');
  7273. //$my_dependency->setAttribute('identifierref', '');
  7274. $resources->appendChild($my_resource);
  7275. $zip_files[] = $my_file_path;
  7276. //error_log('File '.$my_file_path. ' added to $zip_files', 0);
  7277. } else {
  7278. // If the item is a quiz or a link or whatever non-exportable, we include a step indicating it.
  7279. if ($item->type == TOOL_LINK) {
  7280. $my_item = $xmldoc->createElement('item');
  7281. $my_item->setAttribute('identifier', 'ITEM_'.$item->get_id());
  7282. $my_item->setAttribute('identifierref', 'RESOURCE_'.$item->get_id());
  7283. $my_item->setAttribute('isvisible', 'true');
  7284. // Give a child element <title> to the <item> element.
  7285. $my_title = $xmldoc->createElement('title', htmlspecialchars(api_utf8_encode($item->get_title()), ENT_QUOTES, 'UTF-8'));
  7286. $my_item->appendChild($my_title);
  7287. // Give a child element <adlcp:prerequisites> to the <item> element.
  7288. $my_prereqs = $xmldoc->createElement('adlcp:prerequisites', $item->get_prereq_string());
  7289. $my_prereqs->setAttribute('type', 'aicc_script');
  7290. $my_item->appendChild($my_prereqs);
  7291. // Give a child element <adlcp:maxtimeallowed> to the <item> element - not yet supported.
  7292. //$xmldoc->createElement('adlcp:maxtimeallowed', '');
  7293. // Give a child element <adlcp:timelimitaction> to the <item> element - not yet supported.
  7294. //$xmldoc->createElement('adlcp:timelimitaction', '');
  7295. // Give a child element <adlcp:datafromlms> to the <item> element - not yet supported.
  7296. //$xmldoc->createElement('adlcp:datafromlms', '');
  7297. // Give a child element <adlcp:masteryscore> to the <item> element.
  7298. $my_masteryscore = $xmldoc->createElement('adlcp:masteryscore', $item->get_mastery_score());
  7299. $my_item->appendChild($my_masteryscore);
  7300. // Attach this item to the organization element or its parent if there is one.
  7301. if (!empty($item->parent) && $item->parent != 0) {
  7302. $children = $organization->childNodes;
  7303. for ($i = 0; $i < $children->length; $i++) {
  7304. $item_temp = $children->item($i);
  7305. if ($item_temp -> nodeName == 'item') {
  7306. if ($item_temp->getAttribute('identifier') == 'ITEM_'.$item->parent) {
  7307. $item_temp -> appendChild($my_item);
  7308. }
  7309. }
  7310. }
  7311. } else {
  7312. $organization->appendChild($my_item);
  7313. }
  7314. $my_file_path = 'link_'.$item->get_id().'.html';
  7315. $sql = 'SELECT url, title FROM '.Database :: get_course_table(TABLE_LINK).' WHERE id='.$item->path;
  7316. $rs = Database::query($sql);
  7317. if ($link = Database :: fetch_array($rs)) {
  7318. $url = $link['url'];
  7319. $title = stripslashes($link['title']);
  7320. $links_to_create[$my_file_path] = array('title' => $title, 'url' => $url);
  7321. //$my_xml_file_path = api_htmlentities(api_utf8_encode($my_file_path), ENT_QUOTES, 'UTF-8');
  7322. $my_xml_file_path = $my_file_path;
  7323. $my_sub_dir = dirname($my_file_path);
  7324. $my_sub_dir = str_replace('\\', '/', $my_sub_dir);
  7325. //$my_xml_sub_dir = api_htmlentities(api_utf8_encode($my_sub_dir), ENT_QUOTES, 'UTF-8');
  7326. $my_xml_sub_dir = $my_sub_dir;
  7327. // Give a <resource> child to the <resources> element.
  7328. $my_resource = $xmldoc->createElement('resource');
  7329. $my_resource->setAttribute('identifier', 'RESOURCE_'.$item->get_id());
  7330. $my_resource->setAttribute('type', 'webcontent');
  7331. $my_resource->setAttribute('href', $my_xml_file_path);
  7332. // adlcp:scormtype can be either 'sco' or 'asset'.
  7333. $my_resource->setAttribute('adlcp:scormtype', 'asset');
  7334. // xml:base is the base directory to find the files declared in this resource.
  7335. $my_resource->setAttribute('xml:base', '');
  7336. // give a <file> child to the <resource> element.
  7337. $my_file = $xmldoc->createElement('file');
  7338. $my_file->setAttribute('href', $my_xml_file_path);
  7339. $my_resource->appendChild($my_file);
  7340. $resources->appendChild($my_resource);
  7341. }
  7342. }
  7343. elseif ($item->type == TOOL_QUIZ) {
  7344. require_once api_get_path(SYS_CODE_PATH).'exercice/exercise.class.php';
  7345. $exe_id = $item->path; // Should be using ref when everything will be cleaned up in this regard.
  7346. $exe = new Exercise();
  7347. $exe->read($exe_id);
  7348. $my_item = $xmldoc->createElement('item');
  7349. $my_item->setAttribute('identifier', 'ITEM_'.$item->get_id());
  7350. $my_item->setAttribute('identifierref', 'RESOURCE_'.$item->get_id());
  7351. $my_item->setAttribute('isvisible', 'true');
  7352. // Give a child element <title> to the <item> element.
  7353. $my_title = $xmldoc->createElement('title', htmlspecialchars(api_utf8_encode($item->get_title()), ENT_QUOTES, 'UTF-8'));
  7354. $my_item->appendChild($my_title);
  7355. $my_max_score = $xmldoc->createElement('max_score', $item->get_max());
  7356. //$my_item->appendChild($my_max_score);
  7357. // Give a child element <adlcp:prerequisites> to the <item> element.
  7358. $my_prereqs = $xmldoc->createElement('adlcp:prerequisites', $item->get_prereq_string());
  7359. $my_prereqs->setAttribute('type','aicc_script');
  7360. $my_item->appendChild($my_prereqs);
  7361. // Give a child element <adlcp:masteryscore> to the <item> element.
  7362. $my_masteryscore = $xmldoc->createElement('adlcp:masteryscore', $item->get_mastery_score());
  7363. $my_item->appendChild($my_masteryscore);
  7364. // Attach this item to the organization element or hits parent if there is one.
  7365. if (!empty($item->parent) && $item->parent != 0) {
  7366. $children = $organization->childNodes;
  7367. for ($i = 0; $i < $children->length; $i++) {
  7368. $item_temp = $children->item($i);
  7369. if ($item_temp -> nodeName == 'item') {
  7370. if ($item_temp->getAttribute('identifier') == 'ITEM_'.$item->parent) {
  7371. $item_temp -> appendChild($my_item);
  7372. }
  7373. }
  7374. }
  7375. } else {
  7376. $organization->appendChild($my_item);
  7377. }
  7378. // Include export scripts.
  7379. require_once api_get_path(SYS_CODE_PATH).'exercice/export/scorm/scorm_export.php';
  7380. // Get the path of the file(s) from the course directory root
  7381. //$my_file_path = $item->get_file_path('scorm/'.$this->path.'/');
  7382. $my_file_path = 'quiz_'.$item->get_id().'.html';
  7383. // Write the contents of the exported exercise into a (big) html file
  7384. // to later pack it into the exported SCORM. The file will be removed afterwards.
  7385. $contents = export_exercise($exe_id,true);
  7386. $tmp_file_path = $archive_path.$temp_dir_short.'/'.$my_file_path;
  7387. $res = file_put_contents($tmp_file_path, $contents);
  7388. if ($res === false) { error_log('Could not write into file '.$tmp_file_path.' '.__FILE__.' '.__LINE__, 0); }
  7389. $files_cleanup[] = $tmp_file_path;
  7390. //error_log($tmp_path); die();
  7391. //$my_xml_file_path = api_htmlentities(api_utf8_encode($my_file_path), ENT_QUOTES, 'UTF-8');
  7392. $my_xml_file_path = $my_file_path;
  7393. $my_sub_dir = dirname($my_file_path);
  7394. $my_sub_dir = str_replace('\\', '/', $my_sub_dir);
  7395. //$my_xml_sub_dir = api_htmlentities(api_utf8_encode($my_sub_dir), ENT_QUOTES, 'UTF-8');
  7396. $my_xml_sub_dir = $my_sub_dir;
  7397. // Give a <resource> child to the <resources> element.
  7398. $my_resource = $xmldoc->createElement('resource');
  7399. $my_resource->setAttribute('identifier', 'RESOURCE_'.$item->get_id());
  7400. $my_resource->setAttribute('type', 'webcontent');
  7401. $my_resource->setAttribute('href', $my_xml_file_path);
  7402. // adlcp:scormtype can be either 'sco' or 'asset'.
  7403. $my_resource->setAttribute('adlcp:scormtype', 'sco');
  7404. // xml:base is the base directory to find the files declared in this resource.
  7405. $my_resource->setAttribute('xml:base', '');
  7406. // Give a <file> child to the <resource> element.
  7407. $my_file = $xmldoc->createElement('file');
  7408. $my_file->setAttribute('href', $my_xml_file_path);
  7409. $my_resource->appendChild($my_file);
  7410. // Get included docs.
  7411. $inc_docs = $item->get_resources_from_source(null,$tmp_file_path);
  7412. // Dependency to other files - not yet supported.
  7413. $i = 1;
  7414. foreach ($inc_docs as $doc_info) {
  7415. if (count($doc_info) < 1 || empty($doc_info[0])) { continue; }
  7416. $my_dep = $xmldoc->createElement('resource');
  7417. $res_id = 'RESOURCE_'.$item->get_id().'_'.$i;
  7418. $my_dep->setAttribute('identifier', $res_id);
  7419. $my_dep->setAttribute('type', 'webcontent');
  7420. $my_dep->setAttribute('adlcp:scormtype', 'asset');
  7421. $my_dep_file = $xmldoc->createElement('file');
  7422. // Check type of URL.
  7423. //error_log(__LINE__.'Now dealing with '.$doc_info[0].' of type '.$doc_info[1].'-'.$doc_info[2], 0);
  7424. if ($doc_info[1] == 'remote') {
  7425. // Remote file. Save url as is.
  7426. $my_dep_file->setAttribute('href', $doc_info[0]);
  7427. $my_dep->setAttribute('xml:base', '');
  7428. } elseif ($doc_info[1] == 'local') {
  7429. switch ($doc_info[2]) {
  7430. case 'url': // Local URL - save path as url for now, don't zip file.
  7431. // Save file but as local file (retrieve from URL).
  7432. $abs_path = api_get_path(SYS_PATH).str_replace(api_get_path(WEB_PATH), '', $doc_info[0]);
  7433. $current_dir = dirname($abs_path);
  7434. $current_dir = str_replace('\\', '/', $current_dir);
  7435. $file_path = realpath($abs_path);
  7436. $file_path = str_replace('\\', '/', $file_path);
  7437. $my_dep_file->setAttribute('href', 'document/'.$file_path);
  7438. $my_dep->setAttribute('xml:base', '');
  7439. if (strstr($file_path, $main_path) !== false) {
  7440. // The calculated real path is really inside the chamilo root path.
  7441. // Reduce file path to what's under the DocumentRoot.
  7442. $file_path = substr($file_path, strlen($root_path));
  7443. //echo $file_path;echo '<br /><br />';
  7444. //error_log('Reduced path: '.$file_path, 0);
  7445. $zip_files_abs[] = $file_path;
  7446. $link_updates[$my_file_path][] = array('orig' => $doc_info[0], 'dest' => 'document/'.$file_path);
  7447. $my_dep_file->setAttribute('href', 'document/'.$file_path);
  7448. $my_dep->setAttribute('xml:base', '');
  7449. }
  7450. elseif (empty($file_path)) {
  7451. /*$document_root = substr(api_get_path(SYS_PATH), 0, strpos(api_get_path(SYS_PATH),api_get_path(REL_PATH)));
  7452. if (strpos($document_root,-1) == '/') {
  7453. $document_root = substr(0, -1, $document_root);
  7454. }*/
  7455. $file_path = $_SERVER['DOCUMENT_ROOT'].$abs_path;
  7456. $file_path = str_replace('//', '/', $file_path);
  7457. if (file_exists($file_path)) {
  7458. $file_path = substr($file_path, strlen($current_dir)); // We get the relative path.
  7459. $zip_files[] = $my_sub_dir.'/'.$file_path;
  7460. $link_updates[$my_file_path][] = array('orig' => $doc_info[0], 'dest' => 'document/'.$file_path);
  7461. $my_dep_file->setAttribute('href', 'document/'.$file_path);
  7462. $my_dep->setAttribute('xml:base', '');
  7463. }
  7464. }
  7465. break;
  7466. case 'abs': // Absolute path from DocumentRoot. Save file and leave path as is in the zip.
  7467. $current_dir = dirname($current_course_path.'/'.$item->get_file_path()).'/';
  7468. $current_dir = str_replace('\\', '/', $current_dir);
  7469. $file_path = realpath($doc_info[0]);
  7470. $file_path = str_replace('\\', '/', $file_path);
  7471. $my_dep_file->setAttribute('href', $file_path);
  7472. $my_dep->setAttribute('xml:base', '');
  7473. if (strstr($file_path,$main_path) !== false) {
  7474. // The calculated real path is really inside the chamilo root path.
  7475. // Reduce file path to what's under the DocumentRoot.
  7476. $file_path = substr($file_path, strlen($root_path));
  7477. //echo $file_path;echo '<br /><br />';
  7478. //error_log('Reduced path: '.$file_path, 0);
  7479. $zip_files_abs[] = $file_path;
  7480. $link_updates[$my_file_path][] = array('orig' => $doc_info[0], 'dest' => $file_path);
  7481. $my_dep_file->setAttribute('href', 'document/'.$file_path);
  7482. $my_dep->setAttribute('xml:base', '');
  7483. }
  7484. elseif (empty($file_path)) {
  7485. /*$document_root = substr(api_get_path(SYS_PATH), 0, strpos(api_get_path(SYS_PATH), api_get_path(REL_PATH)));
  7486. if (strpos($document_root,-1) == '/') {
  7487. $document_root = substr(0, -1, $document_root);
  7488. }*/
  7489. $file_path = $_SERVER['DOCUMENT_ROOT'].$doc_info[0];
  7490. $file_path = str_replace('//', '/', $file_path);
  7491. if (file_exists($file_path)) {
  7492. $file_path = substr($file_path,strlen($current_dir)); // We get the relative path.
  7493. $zip_files[] = $my_sub_dir.'/'.$file_path;
  7494. $link_updates[$my_file_path][] = array('orig' => $doc_info[0], 'dest' => $file_path);
  7495. $my_dep_file->setAttribute('href', 'document/'.$file_path);
  7496. $my_dep->setAttribute('xml:base', '');
  7497. }
  7498. }
  7499. break;
  7500. 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
  7501. if (substr($doc_info[0], 0, 2) == '..') {
  7502. // Relative path going up.
  7503. $current_dir = dirname($current_course_path.'/'.$item->get_file_path()).'/';
  7504. $current_dir = str_replace('\\', '/', $current_dir);
  7505. $file_path = realpath($current_dir.$doc_info[0]);
  7506. $file_path = str_replace('\\', '/', $file_path);
  7507. //error_log($file_path.' <-> '.$main_path, 0);
  7508. if (strstr($file_path, $main_path) !== false) {
  7509. // The calculated real path is really inside Chamilo's root path.
  7510. // Reduce file path to what's under the DocumentRoot.
  7511. $file_path = substr($file_path, strlen($root_path));
  7512. $file_path_dest = $file_path;
  7513. // File path is courses/CHAMILO/document/....
  7514. $info_file_path = explode('/', $file_path);
  7515. if ($info_file_path[0] == 'courses') { // Add character "/" in file path.
  7516. $file_path_dest = 'document/'.$file_path;
  7517. }
  7518. //error_log('Reduced path: '.$file_path, 0);
  7519. $zip_files_abs[] = $file_path;
  7520. $link_updates[$my_file_path][] = array('orig' => $doc_info[0], 'dest' => $file_path_dest);
  7521. $my_dep_file->setAttribute('href', 'document/'.$file_path);
  7522. $my_dep->setAttribute('xml:base', '');
  7523. }
  7524. } else {
  7525. $zip_files[] = $my_sub_dir.'/'.$doc_info[0];
  7526. $my_dep_file->setAttribute('href', $doc_info[0]);
  7527. $my_dep->setAttribute('xml:base', $my_xml_sub_dir);
  7528. }
  7529. break;
  7530. default:
  7531. $my_dep_file->setAttribute('href', $doc_info[0]); // ../../courses/
  7532. $my_dep->setAttribute('xml:base', '');
  7533. break;
  7534. }
  7535. }
  7536. $my_dep->appendChild($my_dep_file);
  7537. $resources->appendChild($my_dep);
  7538. $dependency = $xmldoc->createElement('dependency');
  7539. $dependency->setAttribute('identifierref', $res_id);
  7540. $my_resource->appendChild($dependency);
  7541. $i++;
  7542. }
  7543. $resources->appendChild($my_resource);
  7544. $zip_files[] = $my_file_path;
  7545. } else {
  7546. // Get the path of the file(s) from the course directory root
  7547. $my_file_path = 'non_exportable.html';
  7548. //$my_xml_file_path = api_htmlentities(api_utf8_encode($my_file_path), ENT_COMPAT, 'UTF-8');
  7549. $my_xml_file_path = $my_file_path;
  7550. $my_sub_dir = dirname($my_file_path);
  7551. $my_sub_dir = str_replace('\\', '/', $my_sub_dir);
  7552. //$my_xml_sub_dir = api_htmlentities(api_utf8_encode($my_sub_dir), ENT_COMPAT, 'UTF-8');
  7553. $my_xml_sub_dir = $my_sub_dir;
  7554. // Give a <resource> child to the <resources> element.
  7555. $my_resource = $xmldoc->createElement('resource');
  7556. $my_resource->setAttribute('identifier', 'RESOURCE_'.$item->get_id());
  7557. $my_resource->setAttribute('type', 'webcontent');
  7558. $my_resource->setAttribute('href', 'document/'.$my_xml_file_path);
  7559. // adlcp:scormtype can be either 'sco' or 'asset'.
  7560. $my_resource->setAttribute('adlcp:scormtype', 'asset');
  7561. // xml:base is the base directory to find the files declared in this resource.
  7562. $my_resource->setAttribute('xml:base', '');
  7563. // Give a <file> child to the <resource> element.
  7564. $my_file = $xmldoc->createElement('file');
  7565. $my_file->setAttribute('href', 'document/'.$my_xml_file_path);
  7566. $my_resource->appendChild($my_file);
  7567. $resources->appendChild($my_resource);
  7568. }
  7569. }
  7570. }
  7571. $organizations->appendChild($organization);
  7572. $root->appendChild($organizations);
  7573. $root->appendChild($resources);
  7574. $xmldoc->appendChild($root);
  7575. // TODO: Add a readme file here, with a short description and a link to the Reload player
  7576. // then add the file to the zip, then destroy the file (this is done automatically).
  7577. // http://www.reload.ac.uk/scormplayer.html - once done, don't forget to close FS#138
  7578. //error_log(print_r($zip_files,true), 0);
  7579. foreach ($zip_files as $file_path) {
  7580. if (empty($file_path)) { continue; }
  7581. //error_log(__LINE__.'getting document from '.$sys_course_path.$_course['path'].'/'.$file_path.' removing '.$sys_course_path.$_course['path'].'/',0);
  7582. $dest_file = $archive_path.$temp_dir_short.'/'.$file_path;
  7583. $this->create_path($dest_file);
  7584. //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);
  7585. //echo $main_path.$file_path.'<br />';
  7586. @copy($sys_course_path.$_course['path'].'/'.$file_path, $dest_file);
  7587. // Check if the file needs a link update.
  7588. if (in_array($file_path, array_keys($link_updates))) {
  7589. $string = file_get_contents($dest_file);
  7590. unlink($dest_file);
  7591. foreach ($link_updates[$file_path] as $old_new) {
  7592. //error_log('Replacing '.$old_new['orig'].' by '.$old_new['dest'].' in '.$file_path, 0);
  7593. // This is an ugly hack that allows .flv files to be found by the flv player that
  7594. // will be added in document/main/inc/lib/flv_player/flv_player.swf and that needs
  7595. // to find the flv to play in document/main/, so we replace main/ in the flv path by
  7596. // ../../.. to return from inc/lib/flv_player to the document/main path.
  7597. if (substr($old_new['dest'], -3) == 'flv' && substr($old_new['dest'], 0, 5) == 'main/') {
  7598. $old_new['dest'] = str_replace('main/', '../../../', $old_new['dest']);
  7599. }
  7600. elseif (substr($old_new['dest'], -3) == 'flv' && substr($old_new['dest'], 0, 6) == 'video/') {
  7601. $old_new['dest'] = str_replace('video/', '../../../../video/', $old_new['dest']);
  7602. }
  7603. $string = str_replace($old_new['orig'], $old_new['dest'], $string);
  7604. }
  7605. file_put_contents($dest_file, $string);
  7606. }
  7607. }
  7608. foreach ($zip_files_abs as $file_path) {
  7609. if (empty($file_path)) { continue; }
  7610. //error_log(__LINE__.'checking existence of '.$main_path.$file_path.'', 0);
  7611. if (!is_file($main_path.$file_path) || !is_readable($main_path.$file_path)) { continue; }
  7612. //error_log(__LINE__.'getting document from '.$main_path.$file_path.' removing '.api_get_path(SYS_COURSE_PATH).$_course['path'].'/', 0);
  7613. $dest_file = $archive_path.$temp_dir_short.'/document/'.$file_path;
  7614. $this->create_path($dest_file);
  7615. //error_log('Created path '.api_get_path(SYS_ARCHIVE_PATH).$temp_dir_short.'/document/'.$file_path, 0);
  7616. //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);
  7617. //echo $main_path.$file_path.' - '.$dest_file.'<br />';
  7618. copy($main_path.$file_path, $dest_file);
  7619. // Check if the file needs a link update.
  7620. if (in_array($file_path, array_keys($link_updates))) {
  7621. $string = file_get_contents($dest_file);
  7622. unlink($dest_file);
  7623. foreach ($link_updates[$file_path] as $old_new) {
  7624. //error_log('Replacing '.$old_new['orig'].' by '.$old_new['dest'].' in '.$file_path, 0);
  7625. // This is an ugly hack that allows .flv files to be found by the flv player that
  7626. // will be added in document/main/inc/lib/flv_player/flv_player.swf and that needs
  7627. // to find the flv to play in document/main/, so we replace main/ in the flv path by
  7628. // ../../.. to return from inc/lib/flv_player to the document/main path.
  7629. if (substr($old_new['dest'], -3) == 'flv' && substr($old_new['dest'], 0, 5) == 'main/') {
  7630. $old_new['dest'] = str_replace('main/', '../../../', $old_new['dest']);
  7631. }
  7632. $string = str_replace($old_new['orig'], $old_new['dest'], $string);
  7633. }
  7634. file_put_contents($dest_file, $string);
  7635. }
  7636. }
  7637. if (is_array($links_to_create)) {
  7638. foreach ($links_to_create as $file => $link) {
  7639. $file_content = '<!DOCTYPE html
  7640. PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  7641. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  7642. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="'.api_get_language_isocode().'" lang="'.api_get_language_isocode().'">
  7643. <head>
  7644. <title>'.$link['title'].'</title>
  7645. <meta http-equiv="Content-Type" content="text/html; charset='.api_get_system_encoding().'" />
  7646. </head>
  7647. <body dir="'.api_get_text_direction().'">
  7648. <div style="text-align:center"><a href="'.$link['url'].'">'.$link['title'].'</a></div>
  7649. </body>
  7650. </html>';
  7651. file_put_contents($archive_path.$temp_dir_short.'/'.$file, $file_content);
  7652. }
  7653. }
  7654. // Add non exportable message explanation.
  7655. $lang_not_exportable = get_lang('ThisItemIsNotExportable');
  7656. $file_content = '<!DOCTYPE html
  7657. PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  7658. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  7659. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="'.api_get_language_isocode().'" lang="'.api_get_language_isocode().'">
  7660. <head>
  7661. <title>'.$lang_not_exportable.'</title>
  7662. <meta http-equiv="Content-Type" content="text/html; charset='.api_get_system_encoding().'" />
  7663. </head>
  7664. <body dir="'.api_get_text_direction().'">
  7665. ';
  7666. $file_content .=
  7667. <<<EOD
  7668. <style>
  7669. .error-message {
  7670. font-family: arial, verdana, helvetica, sans-serif;
  7671. border-width: 1px;
  7672. border-style: solid;
  7673. left: 50%;
  7674. margin: 10px auto;
  7675. min-height: 30px;
  7676. padding: 5px;
  7677. right: 50%;
  7678. width: 500px;
  7679. background-color: #FFD1D1;
  7680. border-color: #FF0000;
  7681. color: #000;
  7682. }
  7683. </style>
  7684. <body>
  7685. <div class="error-message">
  7686. $lang_not_exportable
  7687. </div>
  7688. </body>
  7689. </html>
  7690. EOD;
  7691. if (!is_dir($archive_path.$temp_dir_short.'/document')) {
  7692. @mkdir($archive_path.$temp_dir_short.'/document', api_get_permissions_for_new_directories());
  7693. }
  7694. file_put_contents($archive_path.$temp_dir_short.'/document/non_exportable.html', $file_content);
  7695. // Add the extra files that go along with a SCORM package.
  7696. $main_code_path = api_get_path(SYS_CODE_PATH).'newscorm/packaging/';
  7697. $extra_files = scandir($main_code_path);
  7698. foreach ($extra_files as $extra_file) {
  7699. if (strpos($extra_file, '.') === 0)
  7700. continue;
  7701. else {
  7702. $dest_file = $archive_path . $temp_dir_short . '/' . $extra_file;
  7703. $this->create_path($dest_file);
  7704. copy($main_code_path.$extra_file, $dest_file);
  7705. }
  7706. }
  7707. // Finalize the imsmanifest structure, add to the zip, then return the zip.
  7708. $manifest = @$xmldoc->saveXML();
  7709. $manifest = api_utf8_decode_xml($manifest); // The manifest gets the system encoding now.
  7710. file_put_contents($archive_path.'/'.$temp_dir_short.'/imsmanifest.xml', $manifest);
  7711. $zip_folder->add($archive_path.'/'.$temp_dir_short, PCLZIP_OPT_REMOVE_PATH, $archive_path.'/'.$temp_dir_short.'/');
  7712. // Clean possible temporary files.
  7713. foreach ($files_cleanup as $file) {
  7714. $res = unlink($file);
  7715. if ($res === false) { error_log('Could not delete temp file '.$file.' '.__FILE__.' '.__LINE__, 0); }
  7716. }
  7717. // Send file to client.
  7718. //$name = 'scorm_export_'.$this->lp_id.'.zip';
  7719. require_once api_get_path(LIBRARY_PATH).'fileUpload.lib.php';
  7720. $name = replace_dangerous_char($this->get_name()).'.zip';
  7721. DocumentManager::file_send_for_download($temp_zip_file, true, $name);
  7722. }
  7723. public function scorm_export_to_pdf($lp_id) {
  7724. $lp_id = intval($lp_id);
  7725. $files_to_export = array();
  7726. $course_data = api_get_course_info($this->cc);
  7727. if (!empty($course_data)) {
  7728. $scorm_path = api_get_path(SYS_COURSE_PATH).$course_data['path'].'/scorm/'.$this->path;
  7729. require_once api_get_path(LIBRARY_PATH).'document.lib.php';
  7730. $list = $this->get_flat_ordered_items_list($lp_id);
  7731. foreach($list as $item_id) {
  7732. $item = $this->items[$item_id];
  7733. //Getting documents from a LP with chamilo documents
  7734. switch ($item->type) {
  7735. case 'document':
  7736. $file_data = DocumentManager::get_document_data_by_id($item->path, $this->cc);
  7737. $file_path = api_get_path(SYS_COURSE_PATH).$course_data['path'].'/document'.$file_data['path'];
  7738. if (file_exists($file_path)) {
  7739. $files_to_export[] = array('title'=>$item->get_title(),'path'=>$file_path);
  7740. }
  7741. break;
  7742. case 'sco':
  7743. $file_path = $scorm_path.'/'.$item->path;
  7744. if (file_exists($file_path)) {
  7745. $files_to_export[] = array('title'=>$item->get_title(),'path'=>$file_path);
  7746. }
  7747. break;
  7748. case 'dokeos_chapter':
  7749. case 'dir':
  7750. case 'chapter':
  7751. $files_to_export[] = array('title'=>$item->get_title(),'path'=>null);
  7752. break;
  7753. }
  7754. }
  7755. require_once api_get_path(LIBRARY_PATH).'pdf.lib.php';
  7756. $pdf = new PDF();
  7757. $result = $pdf->html_to_pdf($files_to_export, $this->name, $this->cc, true);
  7758. return $result;
  7759. }
  7760. return false;
  7761. }
  7762. /**
  7763. * Temp function to be moved in main_api or the best place around for this. Creates a file path
  7764. * if it doesn't exist
  7765. */
  7766. public function create_path($path) {
  7767. $path_bits = split('/', dirname($path));
  7768. // IS_WINDOWS_OS has been defined in main_api.lib.php
  7769. $path_built = IS_WINDOWS_OS ? '' : '/';
  7770. foreach ($path_bits as $bit) {
  7771. if (!empty ($bit)) {
  7772. $new_path = $path_built . $bit;
  7773. if (is_dir($new_path)) {
  7774. $path_built = $new_path . '/';
  7775. } else {
  7776. mkdir($new_path, api_get_permissions_for_new_directories());
  7777. $path_built = $new_path . '/';
  7778. }
  7779. }
  7780. }
  7781. }
  7782. /**
  7783. * Delete the image relative to this learning path. No parameter. Only works on instanciated object.
  7784. * @return boolean The results of the unlink function, or false if there was no image to start with
  7785. */
  7786. public function delete_lp_image() {
  7787. $img = $this->get_preview_image();
  7788. if ($img != '') {
  7789. $del_file = api_get_path(SYS_COURSE_PATH) . api_get_course_path() . '/upload/learning_path/images/' . $img;
  7790. $this->set_preview_image('');
  7791. return @ unlink($del_file);
  7792. } else {
  7793. return false;
  7794. }
  7795. }
  7796. /**
  7797. * Uploads an author image to the upload/learning_path/images directory
  7798. * @param array The image array, coming from the $_FILES superglobal
  7799. * @return boolean True on success, false on error
  7800. */
  7801. public function upload_image($image_array) {
  7802. $image_moved = false;
  7803. if (!empty ($image_array['name'])) {
  7804. $upload_ok = process_uploaded_file($image_array);
  7805. $has_attachment = true;
  7806. } else {
  7807. $image_moved = true;
  7808. }
  7809. if ($upload_ok) {
  7810. if ($has_attachment) {
  7811. $courseDir = api_get_course_path() . '/upload/learning_path/images';
  7812. $sys_course_path = api_get_path(SYS_COURSE_PATH);
  7813. $updir = $sys_course_path . $courseDir;
  7814. // Try to add an extension to the file if it hasn't one.
  7815. $new_file_name = add_ext_on_mime(stripslashes($image_array['name']), $image_array['type']);
  7816. if (!filter_extension($new_file_name)) {
  7817. //Display :: display_error_message(get_lang('UplUnableToSaveFileFilteredExtension'));
  7818. $image_moved = false;
  7819. } else {
  7820. $file_extension = explode('.', $image_array['name']);
  7821. $file_extension = strtolower($file_extension[sizeof($file_extension) - 1]);
  7822. $new_file_name = uniqid('') . '.' . $file_extension;
  7823. $new_path = $updir . '/' . $new_file_name;
  7824. //$result = @move_uploaded_file($image_array['tmp_name'], $new_path);
  7825. // Resize the image.
  7826. include_once api_get_path(LIBRARY_PATH).'image.lib.php';
  7827. $temp = new image($image_array['tmp_name']);
  7828. $picture_infos = @getimagesize($image_array['tmp_name']); // $picture_infos[0]-> width
  7829. if ($picture_infos[0] > 104) {
  7830. $thumbwidth = 104;
  7831. } else {
  7832. $thumbwidth = $picture_infos[0];
  7833. }
  7834. if ($picture_infos[1] > 96) {
  7835. $new_height = 96;
  7836. } else {
  7837. $new_height = $picture_infos[1];
  7838. }
  7839. //$new_height = round(($thumbwidth/$picture_infos[0])*$picture_infos[1]);
  7840. $temp->resize($thumbwidth,$new_height, 0);
  7841. $type = $picture_infos[2];
  7842. $result = false;
  7843. switch ($type) {
  7844. case 2 :
  7845. $result = $temp->send_image('JPG', $new_path);
  7846. break;
  7847. case 3 :
  7848. $result = $temp->send_image('PNG', $new_path);
  7849. break;
  7850. case 1 :
  7851. $result = $temp->send_image('GIF', $new_path);
  7852. break;
  7853. }
  7854. $temp->resize($thumbwidth, $new_height, 0);
  7855. $type = $picture_infos[2];
  7856. $result = false;
  7857. switch ($type) {
  7858. case 2 :
  7859. $result = $temp->send_image('JPG', $new_path);
  7860. break;
  7861. case 3 :
  7862. $result = $temp->send_image('PNG', $new_path);
  7863. break;
  7864. case 1 :
  7865. $result = $temp->send_image('GIF', $new_path);
  7866. break;
  7867. }
  7868. // Storing the image filename.
  7869. if ($result) {
  7870. $image_moved = true;
  7871. $this->set_preview_image($new_file_name);
  7872. return true;
  7873. }
  7874. }
  7875. }
  7876. }
  7877. return false;
  7878. }
  7879. public function set_autolunch($lp_id, $status) {
  7880. $lp_id = intval($lp_id);
  7881. $status = intval($status);
  7882. $lp_table = Database::get_course_table(TABLE_LP_MAIN);
  7883. //Setting everything to autolunch = 0
  7884. $attributes['autolunch'] = 0;
  7885. $where = array('session_id = ? '=> api_get_session_id());
  7886. Database::update($lp_table, $attributes,$where);
  7887. if ($status == 1) {
  7888. //Setting my lp_id to autolunch = 1
  7889. $attributes['autolunch'] = 1;
  7890. $where = array('id = ? AND session_id = ? '=> array($lp_id, api_get_session_id()));
  7891. Database::update($lp_table, $attributes, $where );
  7892. }
  7893. }
  7894. }
  7895. if (!function_exists('trim_value')) {
  7896. function trim_value(& $value) {
  7897. $value = trim($value);
  7898. }
  7899. }