learnpath.class.php 333 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * This (abstract?) class defines the parent attributes and methods for the dokeos 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
  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 Dokeos, 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. /**
  65. * Class constructor. Needs a database handler, a course code and a learnpath id from the database.
  66. * Also builds the list of items into $this->items.
  67. * @param string Course code
  68. * @param integer Learnpath ID
  69. * @param integer User ID
  70. * @return boolean True on success, false on error
  71. */
  72. public function __construct($course, $lp_id, $user_id) {
  73. //check params
  74. //check course code
  75. if ($this->debug>0){error_log('New LP - In learnpath::__construct('.$course.','.$lp_id.','.$user_id.')',0);}
  76. if (empty($course)) {
  77. $this->error = 'Course code is empty';
  78. return false;
  79. } else {
  80. $main_table = Database::get_main_table(TABLE_MAIN_COURSE);
  81. //$course = Database::escape_string($course);
  82. $course = $this->escape_string($course);
  83. $sql = "SELECT * FROM $main_table WHERE code = '$course'";
  84. if($this->debug>2){error_log('New LP - learnpath::__construct() '.__LINE__.' - Querying course: '.$sql,0);}
  85. //$res = Database::query($sql);
  86. $res = Database::query($sql);
  87. if(Database::num_rows($res)>0)
  88. {
  89. $this->cc = $course;
  90. }
  91. else
  92. {
  93. $this->error = 'Course code does not exist in database ('.$sql.')';
  94. return false;
  95. }
  96. }
  97. //check learnpath ID
  98. if (empty($lp_id)) {
  99. $this->error = 'Learnpath ID is empty';
  100. return false;
  101. } else {
  102. //TODO make it flexible to use any course_code (still using env course code here)
  103. $lp_table = Database::get_course_table(TABLE_LP_MAIN);
  104. //$id = Database::escape_integer($id);
  105. $lp_id = $this->escape_string($lp_id);
  106. $sql = "SELECT * FROM $lp_table WHERE id = '$lp_id'";
  107. if($this->debug>2){error_log('New LP - learnpath::__construct() '.__LINE__.' - Querying lp: '.$sql,0);}
  108. //$res = Database::query($sql);
  109. $res = Database::query($sql);
  110. if (Database::num_rows($res)>0) {
  111. $this->lp_id = $lp_id;
  112. $row = Database::fetch_array($res);
  113. $this->type = $row['lp_type'];
  114. $this->name = stripslashes($row['name']);
  115. $this->encoding = $row['default_encoding'];
  116. $this->proximity = $row['content_local'];
  117. $this->theme = $row['theme'];
  118. $this->maker = $row['content_maker'];
  119. $this->prevent_reinit = $row['prevent_reinit'];
  120. $this->license = $row['content_license'];
  121. $this->scorm_debug = $row['debug'];
  122. $this->js_lib = $row['js_lib'];
  123. $this->path = $row['path'];
  124. $this->preview_image= $row['preview_image'];
  125. $this->author= $row['author'];
  126. $this->lp_session_id = $row['session_id'];
  127. if ($this->type == 2) {
  128. if ($row['force_commit'] == 1) {
  129. $this->force_commit = true;
  130. }
  131. }
  132. $this->mode = $row['default_view_mod'];
  133. } else {
  134. $this->error = 'Learnpath ID does not exist in database ('.$sql.')';
  135. return false;
  136. }
  137. }
  138. //check user ID
  139. if (empty($user_id)) {
  140. $this->error = 'User ID is empty';
  141. return false;
  142. } else {
  143. //$main_table = Database::get_main_user_table();
  144. $main_table = Database::get_main_table(TABLE_MAIN_USER);
  145. //$user_id = Database::escape_integer($user_id);
  146. $user_id = $this->escape_string($user_id);
  147. $sql = "SELECT * FROM $main_table WHERE user_id = '$user_id'";
  148. if($this->debug>2){error_log('New LP - learnpath::__construct() '.__LINE__.' - Querying user: '.$sql,0);}
  149. //$res = Database::query($sql);
  150. $res = Database::query($sql);
  151. if (Database::num_rows($res)>0) {
  152. $this->user_id = $user_id;
  153. } else {
  154. $this->error = 'User ID does not exist in database ('.$sql.')';
  155. return false;
  156. }
  157. }
  158. //end of variables checking
  159. $session_id = api_get_session_id();
  160. // get the session condition for learning paths of the base + session
  161. $session = api_get_session_condition($session_id);
  162. //now get the latest attempt from this user on this LP, if available, otherwise create a new one
  163. $lp_table = Database::get_course_table(TABLE_LP_VIEW);
  164. //selecting by view_count descending allows to get the highest view_count first
  165. $sql = "SELECT * FROM $lp_table WHERE lp_id = '$lp_id' AND user_id = '$user_id' $session ORDER BY view_count DESC";
  166. if ($this->debug > 2) {error_log('New LP - learnpath::__construct() ' . __LINE__ . ' - querying lp_view: ' . $sql, 0);}
  167. $res = Database::query($sql);
  168. $view_id = 0; //used later to query lp_item_view
  169. if (Database :: num_rows($res) > 0) {
  170. if ($this->debug > 2) {
  171. error_log('New LP - learnpath::__construct() ' . __LINE__ . ' - Found previous view', 0);
  172. }
  173. $row = Database :: fetch_array($res);
  174. $this->attempt = $row['view_count'];
  175. $this->lp_view_id = $row['id'];
  176. $this->last_item_seen = $row['last_item'];
  177. $this->progress_db = $row['progress'];
  178. $this->lp_view_session_id = $row['session_id'];
  179. } else {
  180. if ($this->debug > 2) {
  181. error_log('New LP - learnpath::__construct() ' . __LINE__ . ' - NOT Found previous view', 0);
  182. }
  183. $this->attempt = 1;
  184. $sql_ins = "INSERT INTO $lp_table (lp_id,user_id,view_count, session_id) VALUES ($lp_id,$user_id,1,$session_id)";
  185. $res_ins = Database::query($sql_ins);
  186. $this->lp_view_id = Database :: insert_id();
  187. if ($this->debug > 2) {
  188. error_log('New LP - learnpath::__construct() ' . __LINE__ . ' - inserting new lp_view: ' . $sql_ins, 0);
  189. }
  190. }
  191. //initialise items
  192. $lp_item_table = Database::get_course_table(TABLE_LP_ITEM);
  193. $sql = "SELECT * FROM $lp_item_table WHERE lp_id = '".$this->lp_id."' ORDER BY parent_item_id, display_order";
  194. $res = Database::query($sql);
  195. while ($row = Database::fetch_array($res)) {
  196. $oItem = '';
  197. //$this->ordered_items[] = $row['id'];
  198. switch ($this->type) {
  199. case 3 : //aicc
  200. $oItem = new aiccItem('db', $row['id']);
  201. if (is_object($oItem)) {
  202. $my_item_id = $oItem->get_id();
  203. $oItem->set_lp_view($this->lp_view_id);
  204. $oItem->set_prevent_reinit($this->prevent_reinit);
  205. // Don't use reference here as the next loop will make the pointed object change
  206. $this->items[$my_item_id] = $oItem;
  207. $this->refs_list[$oItem->ref] = $my_item_id;
  208. if ($this->debug > 2) {
  209. error_log('New LP - learnpath::__construct() - aicc object with id ' . $my_item_id . ' set in items[]', 0);
  210. }
  211. }
  212. break;
  213. case 2 :
  214. require_once 'scorm.class.php';
  215. require_once 'scormItem.class.php';
  216. $oItem = new scormItem('db', $row['id']);
  217. if (is_object($oItem)) {
  218. $my_item_id = $oItem->get_id();
  219. $oItem->set_lp_view($this->lp_view_id);
  220. $oItem->set_prevent_reinit($this->prevent_reinit);
  221. // Don't use reference here as the next loop will make the pointed object change
  222. $this->items[$my_item_id] = $oItem;
  223. $this->refs_list[$oItem->ref] = $my_item_id;
  224. if ($this->debug > 2) {
  225. error_log('New LP - object with id ' . $my_item_id . ' set in items[]', 0);
  226. }
  227. }
  228. break;
  229. case 1 :
  230. default :
  231. require_once 'learnpathItem.class.php';
  232. $oItem = new learnpathItem($row['id'], $user_id);
  233. if (is_object($oItem)) {
  234. $my_item_id = $oItem->get_id();
  235. //$oItem->set_lp_view($this->lp_view_id); moved down to when we are sure the item_view exists
  236. $oItem->set_prevent_reinit($this->prevent_reinit);
  237. // Don't use reference here as the next loop will make the pointed object change
  238. $this->items[$my_item_id] = $oItem;
  239. $this->refs_list[$my_item_id] = $my_item_id;
  240. if ($this->debug > 2) {
  241. error_log('New LP - learnpath::__construct() ' . __LINE__ . ' - object with id ' . $my_item_id . ' set in items[]', 0);
  242. }
  243. }
  244. break;
  245. }
  246. //items is a list of pointers to all items, classified by DB ID, not SCO id
  247. if ($row['parent_item_id'] == 0 OR empty ($this->items[$row['parent_item_id']])) {
  248. $this->items[$row['id']]->set_level(0);
  249. } else {
  250. $level = $this->items[$row['parent_item_id']]->get_level() + 1;
  251. $this->items[$row['id']]->set_level($level);
  252. if (is_object($this->items[$row['parent_item_id']])) {
  253. //items is a list of pointers from item DB ids to item objects
  254. $this->items[$row['parent_item_id']]->add_child($row['id']);
  255. } else {
  256. if ($this->debug > 2) {
  257. error_log('New LP - learnpath::__construct() ' . __LINE__ . ' - The parent item (' . $row['parent_item_id'] . ') of item ' . $row['id'] . ' could not be found', 0);
  258. }
  259. }
  260. }
  261. //get last viewing vars
  262. $lp_item_view_table = Database :: get_course_table(TABLE_LP_ITEM_VIEW);
  263. //this query should only return one or zero result
  264. $sql = "SELECT * " .
  265. "FROM $lp_item_view_table " .
  266. "WHERE lp_view_id = " . $this->lp_view_id . " " .
  267. "AND lp_item_id = " . $row['id'] . " ORDER BY view_count DESC ";
  268. if ($this->debug > 2) {
  269. error_log('New LP - learnpath::__construct() - Selecting item_views: ' . $sql, 0);
  270. }
  271. //get the item status
  272. $res2 = Database::query($sql);
  273. if (Database :: num_rows($res2) > 0) {
  274. //if this learnpath has already been used by this user, get his last attempt count and
  275. //the last item seen back into this object
  276. //$max = 0;
  277. $row2 = Database :: fetch_array($res2);
  278. if ($this->debug > 2) {
  279. error_log('New LP - learnpath::__construct() - Got item_view: ' . print_r($row2, true), 0);
  280. }
  281. $this->items[$row['id']]->set_status($row2['status']);
  282. if (empty ($row2['status'])) {
  283. $this->items[$row['id']]->set_status($this->default_status);
  284. }
  285. //$this->attempt = $row['view_count'];
  286. //$this->last_item = $row['id'];
  287. } else //no item found in lp_item_view for this view
  288. {
  289. //first attempt from this user. Set attempt to 1 and last_item to 0 (first item available)
  290. //TODO if the learnpath has not got attempts activated, always use attempt '1'
  291. //$this->attempt = 1;
  292. //$this->last_item = 0;
  293. $this->items[$row['id']]->set_status($this->default_status);
  294. //Add that row to the lp_item_view table so that we have something to show in the stats page
  295. $sql_ins = "INSERT INTO $lp_item_view_table " .
  296. "(lp_item_id, lp_view_id, view_count, status) VALUES " .
  297. "(" . $row['id'] . "," . $this->lp_view_id . ",1,'not attempted')";
  298. if ($this->debug > 2) {
  299. error_log('New LP - learnpath::__construct() ' . __LINE__ . ' - Inserting blank item_view : ' . $sql_ins, 0);
  300. }
  301. $res_ins = Database::query($sql_ins);
  302. }
  303. //setting the view in the item object
  304. $this->items[$row['id']]->set_lp_view($this->lp_view_id);
  305. }
  306. $this->ordered_items = $this->get_flat_ordered_items_list($this->get_id(), 0);
  307. $this->max_ordered_items = 0;
  308. foreach ($this->ordered_items as $index => $dummy) {
  309. if ($index > $this->max_ordered_items AND !empty ($dummy)) {
  310. $this->max_ordered_items = $index;
  311. }
  312. }
  313. //TODO define the current item better
  314. $this->first();
  315. if ($this->debug > 2) {
  316. error_log('New LP - learnpath::__construct() ' . __LINE__ . ' - End of learnpath constructor for learnpath ' . $this->get_id(), 0);
  317. }
  318. }
  319. /**
  320. * 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
  321. * I found it better to rewrite it. Old function is still available. Added also the possibility to add a description.
  322. *
  323. * @param int $parent
  324. * @param int $previous
  325. * @param string $type
  326. * @param int $id
  327. * @param string $title
  328. * @param string $description
  329. * @return int
  330. */
  331. public function add_item($parent, $previous, $type = 'dokeos_chapter', $id, $title, $description, $prerequisites = 0, $max_time_allowed = 0) {
  332. if ($this->debug > 0) {
  333. error_log('New LP - In learnpath::add_item(' . $parent . ',' . $previous . ',' . $type . ',' . $id . ',' . $title . ')', 0);
  334. }
  335. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  336. $parent = intval($parent);
  337. $previous = intval($previous);
  338. $type = $this->escape_string($type);
  339. $id = intval($id);
  340. $max_time_allowed = $this->escape_string(htmlentities($max_time_allowed));
  341. if (empty ($max_time_allowed)) {
  342. $max_time_allowed = 0;
  343. }
  344. //$title = htmlspecialchars($title, ENT_QUOTES, $charset); // TODO: To be checked for encoding problems.
  345. //$title = $this->escape_string(api_convert_encoding($title, $this->encoding, $charset));
  346. $title = $this->escape_string(api_convert_encoding($title, $this->encoding, api_get_system_encoding()));
  347. $description = $this->escape_string(api_convert_encoding($description, $this->encoding, api_get_system_encoding()));
  348. $sql_count = " SELECT COUNT(id) AS num
  349. FROM " . $tbl_lp_item . "
  350. WHERE lp_id = " . $this->get_id() . " AND parent_item_id = " . $parent;
  351. $res_count = Database::query($sql_count);
  352. $row = Database :: fetch_array($res_count);
  353. $num = $row['num'];
  354. if ($num > 0) {
  355. if ($previous == 0) {
  356. $sql = "SELECT id, next_item_id, display_order
  357. FROM " . $tbl_lp_item . "
  358. WHERE
  359. lp_id = " . $this->get_id() . " AND
  360. parent_item_id = " . $parent . " AND
  361. previous_item_id = 0 OR previous_item_id=" . $parent;
  362. $result = Database::query($sql);
  363. $row = Database :: fetch_array($result);
  364. $tmp_previous = 0;
  365. $next = $row['id'];
  366. $display_order = 0;
  367. } else {
  368. $previous = (int) $previous;
  369. $sql = "
  370. SELECT
  371. id,
  372. previous_item_id,
  373. next_item_id,
  374. display_order
  375. FROM " . $tbl_lp_item . "
  376. WHERE
  377. lp_id = " . $this->get_id() . " AND
  378. id = " . $previous;
  379. $result = Database::query($sql);
  380. $row = Database :: fetch_array($result);
  381. $tmp_previous = $row['id'];
  382. $next = $row['next_item_id'];
  383. $display_order = $row['display_order'];
  384. }
  385. } else {
  386. $tmp_previous = 0;
  387. $next = 0;
  388. $display_order = 0;
  389. }
  390. $new_item_id = -1;
  391. $id = $this->escape_string($id);
  392. if ($type == 'quiz') {
  393. $sql = 'SELECT SUM(ponderation)
  394. FROM ' . Database :: get_course_table(TABLE_QUIZ_QUESTION) . ' as quiz_question
  395. INNER JOIN ' . Database :: get_course_table(TABLE_QUIZ_TEST_QUESTION) . ' as quiz_rel_question
  396. ON quiz_question.id = quiz_rel_question.question_id
  397. AND quiz_rel_question.exercice_id = ' . $id;
  398. $rsQuiz = Database::query($sql);
  399. $max_score = Database :: result($rsQuiz, 0, 0);
  400. } else {
  401. $max_score = 100;
  402. }
  403. if ($prerequisites != 0) {
  404. $sql_ins = "
  405. INSERT INTO " . $tbl_lp_item . " (
  406. lp_id,
  407. item_type,
  408. ref,
  409. title,
  410. description,
  411. path,
  412. max_score,
  413. parent_item_id,
  414. previous_item_id,
  415. next_item_id,
  416. display_order,
  417. prerequisite,
  418. max_time_allowed
  419. ) VALUES (
  420. " . $this->get_id() . ",
  421. '" . $type . "',
  422. '',
  423. '" . $title . "',
  424. '" . $description . "',
  425. '" . $id . "',
  426. '" . $max_score . "',
  427. " . $parent . ",
  428. " . $previous . ",
  429. " . $next . ",
  430. " . ($display_order +1) . ",
  431. " . $prerequisites . ",
  432. " . $max_time_allowed . "
  433. )";
  434. } else {
  435. //insert new item
  436. $sql_ins = "
  437. INSERT INTO " . $tbl_lp_item . " (
  438. lp_id,
  439. item_type,
  440. ref,
  441. title,
  442. description,
  443. path,
  444. max_score,
  445. parent_item_id,
  446. previous_item_id,
  447. next_item_id,
  448. display_order,
  449. max_time_allowed
  450. ) VALUES (
  451. " . $this->get_id() . ",
  452. '" . $type . "',
  453. '',
  454. '" . $title . "',
  455. '" . $description . "',
  456. '" . $id . "',
  457. '" . $max_score . "',
  458. " . $parent . ",
  459. " . $previous . ",
  460. " . $next . ",
  461. " . ($display_order +1) . ",
  462. " . $max_time_allowed . "
  463. )";
  464. }
  465. if ($this->debug > 2) {
  466. error_log('New LP - Inserting dokeos_chapter: ' . $sql_ins, 0);
  467. }
  468. $res_ins = Database::query($sql_ins);
  469. if ($res_ins > 0) {
  470. $new_item_id = Database :: insert_id($res_ins);
  471. //update the item that should come after the new item
  472. $sql_update_next = "
  473. UPDATE " . $tbl_lp_item . "
  474. SET previous_item_id = " . $new_item_id . "
  475. WHERE id = " . $next;
  476. $res_update_next = Database::query($sql_update_next);
  477. //update the item that should be before the new item
  478. $sql_update_previous = "
  479. UPDATE " . $tbl_lp_item . "
  480. SET next_item_id = " . $new_item_id . "
  481. WHERE id = " . $tmp_previous;
  482. $res_update_previous = Database::query($sql_update_previous);
  483. //update all the items after the new item
  484. $sql_update_order = "
  485. UPDATE " . $tbl_lp_item . "
  486. SET display_order = display_order + 1
  487. WHERE
  488. lp_id = " . $this->get_id() . " AND
  489. id <> " . $new_item_id . " AND
  490. parent_item_id = " . $parent . " AND
  491. display_order > " . $display_order;
  492. $res_update_previous = Database::query($sql_update_order);
  493. //update the item that should come after the new item
  494. $sql_update_ref = "
  495. UPDATE " . $tbl_lp_item . "
  496. SET ref = " . $new_item_id . "
  497. WHERE id = " . $new_item_id;
  498. Database::query($sql_update_ref);
  499. }
  500. // upload audio
  501. if (!empty ($_FILES['mp3']['name'])) {
  502. // create the audio folder if it does not exist yet
  503. global $_course;
  504. $filepath = api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document/';
  505. if (!is_dir($filepath . 'audio')) {
  506. mkdir($filepath . 'audio', api_get_permissions_for_new_directories());
  507. $audio_id = add_document($_course, '/audio', 'folder', 0, 'audio');
  508. api_item_property_update($_course, TOOL_DOCUMENT, $audio_id, 'FolderCreated', api_get_user_id(),null,null,null,null,api_get_session_id());
  509. }
  510. // upload the file in the documents tool
  511. include_once api_get_path(LIBRARY_PATH).'fileUpload.lib.php';
  512. $file_path = handle_uploaded_document($_course, $_FILES['mp3'], api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document', '/audio', api_get_user_id(), '', '', '', '', '', false);
  513. // getting the filename only
  514. $file_components = explode('/', $file_path);
  515. $file = $file_components[count($file_components) - 1];
  516. // store the mp3 file in the lp_item table
  517. $sql_insert_audio = "UPDATE $tbl_lp_item SET audio = '" . Database :: escape_string($file) . "' WHERE id = '" . Database :: escape_string($new_item_id) . "'";
  518. Database::query($sql_insert_audio);
  519. }
  520. return $new_item_id;
  521. }
  522. /**
  523. * Static admin function allowing addition of a learnpath to a course.
  524. * @param string Course code
  525. * @param string Learnpath name
  526. * @param string Learnpath description string, if provided
  527. * @param string Type of learnpath (default = 'guess', others = 'dokeos', 'aicc',...)
  528. * @param string Type of files origin (default = 'zip', others = 'dir','web_dir',...)
  529. * @param string Zip file containing the learnpath or directory containing the learnpath
  530. * @return integer The new learnpath ID on success, 0 on failure
  531. */
  532. public function add_lp($course, $name, $description = '', $learnpath = 'guess', $origin = 'zip', $zipname = '') {
  533. global $charset;
  534. //if($this->debug>0){error_log('New LP - In learnpath::add_lp()',0);}
  535. //TODO
  536. $tbl_lp = Database :: get_course_table(TABLE_LP_MAIN);
  537. //check course code exists
  538. //check lp_name doesn't exist, otherwise append something
  539. $i = 0;
  540. $name = learnpath :: escape_string($name);
  541. //session_id
  542. $session_id = api_get_session_id();
  543. $check_name = "SELECT * FROM $tbl_lp WHERE name = '$name'";
  544. //if($this->debug>2){error_log('New LP - Checking the name for new LP: '.$check_name,0);}
  545. $res_name = Database::query($check_name);
  546. while (Database :: num_rows($res_name)) {
  547. //there is already one such name, update the current one a bit
  548. $i++;
  549. $name = $name . ' - ' . $i;
  550. $check_name = "SELECT * FROM $tbl_lp WHERE name = '$name'";
  551. //if($this->debug>2){error_log('New LP - Checking the name for new LP: '.$check_name,0);}
  552. $res_name = Database::query($check_name);
  553. }
  554. //new name does not exist yet; keep it
  555. //escape description
  556. $description = learnpath :: escape_string(api_htmlentities($description, ENT_QUOTES, $charset)); //Kevin: added htmlentities()
  557. $type = 1;
  558. switch ($learnpath) {
  559. case 'guess' :
  560. break;
  561. case 'dokeos' :
  562. $type = 1;
  563. break;
  564. case 'aicc' :
  565. break;
  566. }
  567. switch ($origin) {
  568. case 'zip' :
  569. //check zipname string. If empty, we are currently creating a new Dokeos learnpath
  570. break;
  571. case 'manual' :
  572. default :
  573. $get_max = "SELECT MAX(display_order) FROM $tbl_lp";
  574. $res_max = Database::query($get_max);
  575. if (Database :: num_rows($res_max) < 1) {
  576. $dsp = 1;
  577. } else {
  578. $row = Database :: fetch_array($res_max);
  579. $dsp = $row[0] + 1;
  580. }
  581. $sql_insert = "INSERT INTO $tbl_lp " .
  582. "(lp_type,name,description,path,default_view_mod," .
  583. "default_encoding,display_order,content_maker," .
  584. "content_local,js_lib,session_id) " .
  585. "VALUES ($type,'$name','$description','','embedded'," .
  586. "'UTF-8','$dsp','Chamilo'," .
  587. "'local','','".Database::escape_string($session_id)."')";
  588. //if($this->debug>2){error_log('New LP - Inserting new lp '.$sql_insert,0);}
  589. $res_insert = Database::query($sql_insert);
  590. $id = Database :: insert_id();
  591. if ($id > 0) {
  592. //insert into item_property
  593. api_item_property_update(api_get_course_info(), TOOL_LEARNPATH, $id, 'LearnpathAdded', api_get_user_id());
  594. return $id;
  595. }
  596. break;
  597. }
  598. }
  599. /**
  600. * Appends a message to the message attribute
  601. * @param string Message to append.
  602. */
  603. public function append_message($string) {
  604. if ($this->debug > 0) {
  605. error_log('New LP - In learnpath::append_message()', 0);
  606. }
  607. $this->message .= $string;
  608. }
  609. /**
  610. * Autocompletes the parents of an item in case it's been completed or passed
  611. * @param integer Optional ID of the item from which to look for parents
  612. */
  613. public function autocomplete_parents($item) {
  614. if ($this->debug > 0) {
  615. error_log('New LP - In learnpath::autocomplete_parents()', 0);
  616. }
  617. if (empty ($item)) {
  618. $item = $this->current;
  619. }
  620. $parent_id = $this->items[$item]->get_parent();
  621. if ($this->debug > 2) {
  622. error_log('New LP - autocompleting parent of item ' . $item . ' (item ' . $parent_id . ')', 0);
  623. }
  624. if (is_object($this->items[$item]) and !empty ($parent_id)) {
  625. //if $item points to an object and there is a parent
  626. if ($this->debug > 2) {
  627. error_log('New LP - ' . $item . ' is an item, proceed', 0);
  628. }
  629. $current_item = & $this->items[$item];
  630. $parent = & $this->items[$parent_id]; //get the parent
  631. //new experiment including failed and browsed in completed status
  632. $current_status = $current_item->get_status();
  633. if ($current_item->is_done() || $current_status == 'browsed' || $current_status == 'failed') {
  634. //if the current item is completed or passes or succeeded
  635. $completed = true;
  636. if ($this->debug > 2) {
  637. error_log('New LP - Status of current item is alright', 0);
  638. }
  639. foreach ($parent->get_children() as $child) {
  640. //check all his brothers (his parent's children) for completion status
  641. if ($child != $item) {
  642. if ($this->debug > 2) {
  643. error_log('New LP - Looking at brother with ID ' . $child . ', status is ' . $this->items[$child]->get_status(), 0);
  644. }
  645. //if($this->items[$child]->status_is(array('completed','passed','succeeded')))
  646. //Trying completing parents of failed and browsed items as well
  647. if ($this->items[$child]->status_is(array (
  648. 'completed',
  649. 'passed',
  650. 'succeeded',
  651. 'browsed',
  652. 'failed'
  653. ))) {
  654. //keep completion status to true
  655. } else {
  656. if ($this->debug > 2) {
  657. error_log('New LP - Found one incomplete child of ' . $parent_id . ': ' . $child . ' is ' . $this->items[$child]->get_status(), 0);
  658. }
  659. $completed = false;
  660. }
  661. }
  662. }
  663. if ($completed) { //if all the children were completed
  664. $parent->set_status('completed');
  665. $parent->save(false, $this->prerequisites_match($parent->get_id()));
  666. $this->update_queue[$parent->get_id()] = $parent->get_status();
  667. if ($this->debug > 2) {
  668. error_log('New LP - Added parent to update queue ' . print_r($this->update_queue, true), 0);
  669. }
  670. $this->autocomplete_parents($parent->get_id()); //recursive call
  671. }
  672. } else {
  673. //error_log('New LP - status of current item is not enough to get bothered with it',0);
  674. }
  675. }
  676. }
  677. /**
  678. * Autosaves the current results into the database for the whole learnpath
  679. */
  680. public function autosave() {
  681. if ($this->debug > 0) {
  682. error_log('New LP - In learnpath::autosave()', 0);
  683. }
  684. //TODO add aditionnal save operations for the learnpath itself
  685. }
  686. /**
  687. * Clears the message attribute
  688. */
  689. public function clear_message() {
  690. if ($this->debug > 0) {
  691. error_log('New LP - In learnpath::clear_message()', 0);
  692. }
  693. $this->message = '';
  694. }
  695. /**
  696. * Closes the current resource
  697. *
  698. * Stops the timer
  699. * Saves into the database if required
  700. * Clears the current resource data from this object
  701. * @return boolean True on success, false on failure
  702. */
  703. public function close() {
  704. if ($this->debug > 0) {
  705. error_log('New LP - In learnpath::close()', 0);
  706. }
  707. if (empty ($this->lp_id)) {
  708. $this->error = 'Trying to close this learnpath but no ID is set';
  709. return false;
  710. }
  711. $this->current_time_stop = time();
  712. if ($this->save) {
  713. $learnpath_view_table = Database :: get_course_table(TABLE_LP_VIEW);
  714. /*
  715. $sql = "UPDATE $learnpath_view_table " .
  716. "SET " .
  717. "stop_time = ".$this->current_time_stop.", " .
  718. "score = ".$this->current_score.", ".
  719. "WHERE learnpath_id = '".$this->lp_id."'";
  720. //$res = Database::query($sql);
  721. $res = Database::query($res);
  722. if(Database::affected_rows($res)<1)
  723. {
  724. $this->error = 'Could not update learnpath_view table while closing learnpath';
  725. return false;
  726. }
  727. */
  728. }
  729. $this->ordered_items = array ();
  730. $this->index = 0;
  731. unset ($this->lp_id);
  732. //unset other stuff
  733. return true;
  734. }
  735. /**
  736. * Static admin function allowing removal of a learnpath
  737. * @param string Course code
  738. * @param integer Learnpath ID
  739. * @param string Whether to delete data or keep it (default: 'keep', others: 'remove')
  740. * @return boolean True on success, false on failure (might change that to return number of elements deleted)
  741. */
  742. public function delete($course = null, $id = null, $delete = 'keep') {
  743. //TODO implement a way of getting this to work when the current object is not set
  744. //In clear: implement this in the item class as well (abstract class) and use the given ID in queries
  745. //if(empty($course)){$course = api_get_course_id();}
  746. //if(empty($id)){$id = $this->get_id();}
  747. //If an ID is specifically given and the current LP is not the same,
  748. //prevent delete
  749. if (!empty ($id) && ($id != $this->lp_id)) {
  750. return false;
  751. }
  752. $lp = Database :: get_course_table(TABLE_LP_MAIN);
  753. $lp_item = Database :: get_course_table(TABLE_LP_ITEM); // Proposed by Christophe (clefevre), see below.
  754. $lp_view = Database :: get_course_table(TABLE_LP_VIEW);
  755. $lp_item_view = Database :: get_course_table(TABLE_LP_ITEM_VIEW);
  756. //if($this->debug>0){error_log('New LP - In learnpath::delete()',0);}
  757. //delete lp item id
  758. foreach ($this->items as $id => $dummy) {
  759. //$this->items[$id]->delete();
  760. $sql_del_view = "DELETE FROM $lp_item_view WHERE lp_item_id = '" . $id . "'";
  761. $res_del_item_view = Database::query($sql_del_view);
  762. }
  763. // Proposed by Christophe (nickname: clefevre), see http://www.dokeos.com/forum/viewtopic.php?t=29673
  764. $sql_del_item = "DELETE FROM $lp_item WHERE lp_id = " . $this->lp_id;
  765. $res_del_item = Database::query($sql_del_item);
  766. $sql_del_view = "DELETE FROM $lp_view WHERE lp_id = " . $this->lp_id;
  767. //if($this->debug>2){error_log('New LP - Deleting views bound to lp '.$this->lp_id.': '.$sql_del_view,0);}
  768. $res_del_view = Database::query($sql_del_view);
  769. $this->toggle_publish($this->lp_id, 'i');
  770. //if($this->debug>2){error_log('New LP - Deleting lp '.$this->lp_id.' of type '.$this->type,0);}
  771. if ($this->type == 2 OR $this->type == 3) {
  772. //this is a scorm learning path, delete the files as well
  773. $sql = "SELECT path FROM $lp WHERE id = " . $this->lp_id;
  774. $res = Database::query($sql);
  775. if (Database :: num_rows($res) > 0) {
  776. $row = Database :: fetch_array($res);
  777. $path = $row['path'];
  778. $sql = "SELECT id FROM $lp WHERE path = '$path' AND id != " . $this->lp_id;
  779. $res = Database::query($sql);
  780. if (Database :: num_rows($res) > 0) { //another learning path uses this directory, so don't delete it
  781. if ($this->debug > 2) {
  782. error_log('New LP - In learnpath::delete(), found other LP using path ' . $path . ', keeping directory', 0);
  783. }
  784. } else {
  785. //no other LP uses that directory, delete it
  786. $course_rel_dir = api_get_course_path() . '/scorm/'; //scorm dir web path starting from /courses
  787. $course_scorm_dir = api_get_path(SYS_COURSE_PATH) . $course_rel_dir; //absolute system path for this course
  788. if ($delete == 'remove' && is_dir($course_scorm_dir . $path) and !empty ($course_scorm_dir)) {
  789. if ($this->debug > 2) {
  790. error_log('New LP - In learnpath::delete(), found SCORM, deleting directory: ' . $course_scorm_dir . $path, 0);
  791. }
  792. // Proposed by Christophe (clefevre).
  793. if (strcmp(substr($path, -2), "/.") == 0) {
  794. $path = substr($path, 0, -1); // Remove "." at the end
  795. }
  796. //exec('rm -rf ' . $course_scorm_dir . $path); // See Bug #5208, this is not OS-portable way.
  797. rmdirr($course_scorm_dir . $path);
  798. }
  799. }
  800. }
  801. }
  802. $sql_del_lp = "DELETE FROM $lp WHERE id = " . $this->lp_id;
  803. //if($this->debug>2){error_log('New LP - Deleting lp '.$this->lp_id.': '.$sql_del_lp,0);}
  804. $res_del_lp = Database::query($sql_del_lp);
  805. $this->update_display_order(); //updates the display order of all lps
  806. api_item_property_update(api_get_course_info(), TOOL_LEARNPATH, $this->lp_id, 'delete', api_get_user_id());
  807. require_once '../gradebook/lib/be.inc.php';
  808. $tbl_grade_link = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_LINK);
  809. //delete link of gradebook tool
  810. $sql = 'SELECT gl.id FROM ' . $tbl_grade_link . ' gl WHERE gl.type="4" AND gl.ref_id="' . $id . '";';
  811. $result = Database::query($sql);
  812. $row = Database :: fetch_array($result, 'ASSOC');
  813. //fixing gradebook link deleted see #5229
  814. if (!empty($row['id'])) {
  815. $link = LinkFactory :: load($row['id']);
  816. if ($link[0] != null) {
  817. $link[0]->delete();
  818. }
  819. }
  820. //TODO: also delete items and item-views
  821. if (api_get_setting('search_enabled') == 'true') {
  822. require_once api_get_path(LIBRARY_PATH).'specific_fields_manager.lib.php';
  823. $r = delete_all_values_for_item($this->cc, TOOL_LEARNPATH, $this->lp_id);
  824. }
  825. }
  826. /**
  827. * Removes all the children of one item - dangerous!
  828. * @param integer Element ID of which children have to be removed
  829. * @return integer Total number of children removed
  830. */
  831. public function delete_children_items($id) {
  832. if ($this->debug > 0) {
  833. error_log('New LP - In learnpath::delete_children_items(' . $id . ')', 0);
  834. }
  835. $num = 0;
  836. if (empty ($id) || $id != strval(intval($id))) {
  837. return false;
  838. }
  839. $lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  840. $sql = "SELECT * FROM $lp_item WHERE parent_item_id = $id";
  841. $res = Database::query($sql);
  842. while ($row = Database :: fetch_array($res)) {
  843. $num += $this->delete_children_items($row['id']);
  844. $sql_del = "DELETE FROM $lp_item WHERE id = " . $row['id'];
  845. $res_del = Database::query($sql_del);
  846. $num++;
  847. }
  848. return $num;
  849. }
  850. /**
  851. * Removes an item from the current learnpath
  852. * @param integer Elem ID (0 if first)
  853. * @param integer Whether to remove the resource/data from the system or leave it (default: 'keep', others 'remove')
  854. * @return integer Number of elements moved
  855. * @todo implement resource removal
  856. */
  857. public function delete_item($id, $remove = 'keep') {
  858. if ($this->debug > 0) {
  859. error_log('New LP - In learnpath::delete_item()', 0);
  860. }
  861. //TODO - implement the resource removal
  862. if (empty ($id) || $id != strval(intval($id))) {
  863. return false;
  864. }
  865. //first select item to get previous, next, and display order
  866. $lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  867. $sql_sel = "SELECT * FROM $lp_item WHERE id = $id";
  868. $res_sel = Database::query($sql_sel);
  869. if (Database :: num_rows($res_sel) < 1) {
  870. return false;
  871. }
  872. $row = Database :: fetch_array($res_sel);
  873. $previous = $row['previous_item_id'];
  874. $next = $row['next_item_id'];
  875. $display = $row['display_order'];
  876. $parent = $row['parent_item_id'];
  877. $lp = $row['lp_id'];
  878. //delete children items
  879. $num = $this->delete_children_items($id);
  880. if ($this->debug > 2) {
  881. error_log('New LP - learnpath::delete_item() - deleted ' . $num . ' children of element ' . $id, 0);
  882. }
  883. //now delete the item
  884. $sql_del = "DELETE FROM $lp_item WHERE id = $id";
  885. if ($this->debug > 2) {
  886. error_log('New LP - Deleting item: ' . $sql_del, 0);
  887. }
  888. $res_del = Database::query($sql_del);
  889. //now update surrounding items
  890. $sql_upd = "UPDATE $lp_item SET next_item_id = $next WHERE id = $previous";
  891. $res_upd = Database::query($sql_upd);
  892. $sql_upd = "UPDATE $lp_item SET previous_item_id = $previous WHERE id = $next";
  893. $res_upd = Database::query($sql_upd);
  894. //now update all following items with new display order
  895. $sql_all = "UPDATE $lp_item SET display_order = display_order-1 WHERE lp_id = $lp AND parent_item_id = $parent AND display_order > $display";
  896. $res_all = Database::query($sql_all);
  897. // remove from search engine if enabled
  898. if (api_get_setting('search_enabled') == 'true') {
  899. $tbl_se_ref = Database :: get_main_table(TABLE_MAIN_SEARCH_ENGINE_REF);
  900. $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';
  901. $sql = sprintf($sql, $tbl_se_ref, $this->cc, TOOL_LEARNPATH, $lp, $id);
  902. $res = Database::query($sql);
  903. if (Database :: num_rows($res) > 0) {
  904. $row2 = Database :: fetch_array($res);
  905. require_once api_get_path(LIBRARY_PATH).'search/DokeosIndexer.class.php';
  906. $di = new DokeosIndexer();
  907. $di->remove_document((int) $row2['search_did']);
  908. }
  909. $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';
  910. $sql = sprintf($sql, $tbl_se_ref, $this->cc, TOOL_LEARNPATH, $lp, $id);
  911. Database::query($sql);
  912. }
  913. }
  914. /**
  915. * Updates an item's content in place
  916. * @param integer Element ID
  917. * @param integer Parent item ID
  918. * @param integer Previous item ID
  919. * @param string Item title
  920. * @param string Item description
  921. * @param string Prerequisites (optional)
  922. * @param string Indexing terms (optional)
  923. * @param array The array resulting of the $_FILES[mp3] element
  924. * @return boolean True on success, false on error
  925. */
  926. public function edit_item($id, $parent, $previous, $title, $description, $prerequisites = 0, $audio = NULL, $max_time_allowed = 0) {
  927. global $charset;
  928. if ($this->debug > 0) {
  929. error_log('New LP - In learnpath::edit_item()', 0);
  930. }
  931. if (empty ($max_time_allowed)) {
  932. $max_time_allowed = 0;
  933. }
  934. if (empty ($id) or ($id != strval(intval($id))) or empty ($title)) {
  935. return false;
  936. }
  937. $title = api_convert_encoding($title, $this->encoding, $charset);
  938. $description = api_convert_encoding($description, $this->encoding, $charset);
  939. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  940. $sql_select = "SELECT * FROM " . $tbl_lp_item . " WHERE id = " . $id;
  941. $res_select = Database::query($sql_select);
  942. $row_select = Database :: fetch_array($res_select);
  943. $audio_update_sql = '';
  944. if (is_array($audio) && !empty ($audio['tmp_name']) && $audio['error'] === 0) {
  945. // create the audio folder if it does not exist yet
  946. global $_course;
  947. $filepath = api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document/';
  948. if (!is_dir($filepath . 'audio')) {
  949. mkdir($filepath . 'audio', api_get_permissions_for_new_directories());
  950. $audio_id = add_document($_course, '/audio', 'folder', 0, 'audio');
  951. api_item_property_update($_course, TOOL_DOCUMENT, $audio_id, 'FolderCreated', api_get_user_id(),null,null,null,null,api_get_session_id());
  952. }
  953. //upload file in documents
  954. $pi = pathinfo($audio['name']);
  955. if ($pi['extension'] == 'mp3') {
  956. $c_det = api_get_course_info($this->cc);
  957. $bp = api_get_path(SYS_COURSE_PATH) . $c_det['path'] . '/document';
  958. $path = handle_uploaded_document($c_det, $audio, $bp, '/audio', api_get_user_id(), 0, null, '', 0, 'rename', false, 0);
  959. $path = substr($path, 7);
  960. //update reference in lp_item - audio path is the path from inside de document/audio/ dir
  961. $audio_update_sql = ", audio = '" . Database :: escape_string($path) . "' ";
  962. }
  963. }
  964. $same_parent = ($row_select['parent_item_id'] == $parent) ? true : false;
  965. $same_previous = ($row_select['previous_item_id'] == $previous) ? true : false;
  966. //TODO: htmlspecialchars to be checked for encoding related problems.
  967. if ($same_parent && $same_previous) {
  968. //only update title and description
  969. $sql_update = " UPDATE " . $tbl_lp_item . "
  970. SET title = '" . $this->escape_string($title) . "',
  971. prerequisite = '" . $prerequisites . "',
  972. description = '" . $this->escape_string($description) . "'
  973. " . $audio_update_sql . ",
  974. max_time_allowed = '" . $this->escape_string($max_time_allowed) . "'
  975. WHERE id = " . $id;
  976. $res_update = Database::query($sql_update);
  977. } else {
  978. $old_parent = $row_select['parent_item_id'];
  979. $old_previous = $row_select['previous_item_id'];
  980. $old_next = $row_select['next_item_id'];
  981. $old_order = $row_select['display_order'];
  982. $old_prerequisite = $row_select['prerequisite'];
  983. $old_max_time_allowed = $row_select['max_time_allowed'];
  984. /* BEGIN -- virtually remove the current item id */
  985. /* for the next and previous item it is like the current item doesn't exist anymore */
  986. if ($old_previous != 0) {
  987. $sql_update_next = "
  988. UPDATE " . $tbl_lp_item . "
  989. SET next_item_id = " . $old_next . "
  990. WHERE id = " . $old_previous;
  991. $res_update_next = Database::query($sql_update_next);
  992. //echo '<p>' . $sql_update_next . '</p>';
  993. }
  994. if ($old_next != 0) {
  995. $sql_update_previous = "
  996. UPDATE " . $tbl_lp_item . "
  997. SET previous_item_id = " . $old_previous . "
  998. WHERE id = " . $old_next;
  999. $res_update_previous = Database::query($sql_update_previous);
  1000. //echo '<p>' . $sql_update_previous . '</p>';
  1001. }
  1002. //display_order - 1 for every item with a display_order bigger then the display_order of the current item
  1003. $sql_update_order = "
  1004. UPDATE " . $tbl_lp_item . "
  1005. SET display_order = display_order - 1
  1006. WHERE
  1007. display_order > " . $old_order . " AND lp_id = " . $this->lp_id . " AND
  1008. parent_item_id = " . $old_parent;
  1009. $res_update_order = Database::query($sql_update_order);
  1010. //echo '<p>' . $sql_update_order . '</p>';
  1011. /* END -- virtually remove the current item id */
  1012. /* BEGIN -- update the current item id to his new location */
  1013. if ($previous == 0) {
  1014. //select the data of the item that should come after the current item
  1015. $sql_select_old = "
  1016. SELECT
  1017. id,
  1018. display_order
  1019. FROM " . $tbl_lp_item . "
  1020. WHERE
  1021. lp_id = " . $this->lp_id . " AND
  1022. parent_item_id = " . $parent . " AND
  1023. previous_item_id = " . $previous;
  1024. $res_select_old = Database::query($sql_select_old);
  1025. $row_select_old = Database :: fetch_array($res_select_old);
  1026. //echo '<p>' . $sql_select_old . '</p>';
  1027. //if the new parent didn't have children before
  1028. if (Database :: num_rows($res_select_old) == 0) {
  1029. $new_next = 0;
  1030. $new_order = 1;
  1031. } else {
  1032. $new_next = $row_select_old['id'];
  1033. $new_order = $row_select_old['display_order'];
  1034. }
  1035. //echo 'New next_item_id of current item: ' . $new_next . '<br />';
  1036. //echo 'New previous_item_id of current item: ' . $previous . '<br />';
  1037. //echo 'New display_order of current item: ' . $new_order . '<br />';
  1038. } else {
  1039. //select the data of the item that should come before the current item
  1040. $sql_select_old = "
  1041. SELECT
  1042. next_item_id,
  1043. display_order
  1044. FROM " . $tbl_lp_item . "
  1045. WHERE id = " . $previous;
  1046. $res_select_old = Database::query($sql_select_old);
  1047. $row_select_old = Database :: fetch_array($res_select_old);
  1048. //echo '<p>' . $sql_select_old . '</p>';
  1049. //echo 'New next_item_id of current item: ' . $row_select_old['next_item_id'] . '<br />';
  1050. //echo 'New previous_item_id of current item: ' . $previous . '<br />';
  1051. //echo 'New display_order of current item: ' . ($row_select_old['display_order'] + 1) . '<br />';
  1052. $new_next = $row_select_old['next_item_id'];
  1053. $new_order = $row_select_old['display_order'] + 1;
  1054. }
  1055. //TODO: htmlspecialchars to be checked for encoding related problems.
  1056. //update the current item with the new data
  1057. $sql_update = "
  1058. UPDATE " . $tbl_lp_item . "
  1059. SET
  1060. title = '" . $this->escape_string($title) . "',
  1061. description = '" . $this->escape_string($description) . "',
  1062. parent_item_id = " . $parent . ",
  1063. previous_item_id = " . $previous . ",
  1064. next_item_id = " . $new_next . ",
  1065. display_order = " . $new_order . "
  1066. " . $audio_update_sql . "
  1067. WHERE id = " . $id;
  1068. $res_update_next = Database::query($sql_update);
  1069. //echo '<p>' . $sql_update . '</p>';
  1070. if ($previous != 0) {
  1071. //update the previous item's next_item_id
  1072. $sql_update_previous = "
  1073. UPDATE " . $tbl_lp_item . "
  1074. SET next_item_id = " . $id . "
  1075. WHERE id = " . $previous;
  1076. $res_update_next = Database::query($sql_update_previous);
  1077. //echo '<p>' . $sql_update_previous . '</p>';
  1078. }
  1079. if ($new_next != 0) {
  1080. //update the next item's previous_item_id
  1081. $sql_update_next = "
  1082. UPDATE " . $tbl_lp_item . "
  1083. SET previous_item_id = " . $id . "
  1084. WHERE id = " . $new_next;
  1085. $res_update_next = Database::query($sql_update_next);
  1086. //echo '<p>' . $sql_update_next . '</p>';
  1087. }
  1088. if ($old_prerequisite != $prerequisites) {
  1089. $sql_update_next = "
  1090. UPDATE " . $tbl_lp_item . "
  1091. SET prerequisite = " . $prerequisites . "
  1092. WHERE id = " . $id;
  1093. $res_update_next = Database::query($sql_update_next);
  1094. }
  1095. if ($old_max_time_allowed != $max_time_allowed) {
  1096. $sql_update_max_time_allowed = "
  1097. UPDATE " . $tbl_lp_item . "
  1098. SET max_time_allowed = " . $max_time_allowed . "
  1099. WHERE id = " . $id;
  1100. $res_update_max_time_allowed = Database::query($sql_update_max_time_allowed);
  1101. }
  1102. //update all the items with the same or a bigger display_order than
  1103. //the current item
  1104. $sql_update_order = "
  1105. UPDATE " . $tbl_lp_item . "
  1106. SET display_order = display_order + 1
  1107. WHERE
  1108. lp_id = " . $this->get_id() . " AND
  1109. id <> " . $id . " AND
  1110. parent_item_id = " . $parent . " AND
  1111. display_order >= " . $new_order;
  1112. $res_update_next = Database::query($sql_update_order);
  1113. }
  1114. }
  1115. /**
  1116. * Updates an item's prereq in place
  1117. * @param integer Element ID
  1118. * @param string Prerequisite Element ID
  1119. * @param string Prerequisite item type
  1120. * @param string Prerequisite min score
  1121. * @param string Prerequisite max score
  1122. * @return boolean True on success, false on error
  1123. */
  1124. public function edit_item_prereq($id, $prerequisite_id, $mastery_score = 0, $max_score = 100) {
  1125. if ($this->debug > 0) {
  1126. error_log('New LP - In learnpath::edit_item_prereq(' . $id . ',' . $prerequisite_id . ',' . $mastery_score . ',' . $max_score . ')', 0);
  1127. }
  1128. if (empty ($id) or ($id != strval(intval($id))) or empty ($prerequisite_id)) {
  1129. return false;
  1130. }
  1131. $prerequisite_id = $this->escape_string($prerequisite_id);
  1132. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  1133. if (!is_numeric($mastery_score) || $mastery_score < 0)
  1134. $mastery_score = 0;
  1135. if (!is_numeric($max_score) || $max_score < 0)
  1136. $max_score = 100;
  1137. if ($mastery_score > $max_score)
  1138. $max_score = $mastery_score;
  1139. if (!is_numeric($prerequisite_id))
  1140. $prerequisite_id = 'NULL';
  1141. $sql_upd = " UPDATE " . $tbl_lp_item . "
  1142. SET prerequisite = " . $prerequisite_id . " WHERE id = " . $id;
  1143. $res_upd = Database::query($sql_upd);
  1144. if ($prerequisite_id != 'NULL' && $prerequisite_id != '') {
  1145. $sql_upd = " UPDATE " . $tbl_lp_item . " SET
  1146. mastery_score = " . $mastery_score .
  1147. //", max_score = " . $max_score . " " . //max score cannot be changed in the form anyway - see display_item_prerequisites_form()
  1148. " WHERE ref = '" . $prerequisite_id . "'"; //will this be enough to ensure unicity?
  1149. $res_upd = Database::query($sql_upd);
  1150. }
  1151. //TODO update the item object (can be ignored for now because refreshed)
  1152. return true;
  1153. }
  1154. /**
  1155. * Escapes a string with the available database escape function
  1156. * @param string String to escape
  1157. * @return string String escaped
  1158. */
  1159. public function escape_string($string) {
  1160. //if($this->debug>0){error_log('New LP - In learnpath::escape_string('.$string.')',0);}
  1161. return Database :: escape_string($string);
  1162. }
  1163. /**
  1164. * Static admin function exporting a learnpath into a zip file
  1165. * @param string Export type (scorm, zip, cd)
  1166. * @param string Course code
  1167. * @param integer Learnpath ID
  1168. * @param string Zip file name
  1169. * @return string Zip file path (or false on error)
  1170. */
  1171. public function export_lp($type, $course, $id, $zipname) {
  1172. //if($this->debug>0){error_log('New LP - In learnpath::export_lp()',0);}
  1173. if (empty ($type) OR empty ($course) OR empty ($id) OR empty ($zipname)) {
  1174. return false;
  1175. }
  1176. $url = '';
  1177. switch ($type) {
  1178. case 'scorm' :
  1179. break;
  1180. case 'zip' :
  1181. break;
  1182. case 'cdrom' :
  1183. break;
  1184. }
  1185. return $url;
  1186. }
  1187. /**
  1188. * Gets all the chapters belonging to the same parent as the item/chapter given
  1189. * Can also be called as abstract method
  1190. * @param integer Item ID
  1191. * @return array A list of all the "brother items" (or an empty array on failure)
  1192. */
  1193. public function get_brother_chapters($id) {
  1194. if ($this->debug > 0) {
  1195. error_log('New LP - In learnpath::get_brother_chapters()', 0);
  1196. }
  1197. if (empty ($id) OR $id != strval(intval($id))) {
  1198. return array ();
  1199. }
  1200. $lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  1201. $sql_parent = "SELECT * FROM $lp_item WHERE id = $id AND item_type='dokeos_chapter'";
  1202. $res_parent = Database::query($sql_parent);
  1203. if (Database :: num_rows($res_parent) > 0) {
  1204. $row_parent = Database :: fetch_array($res_parent);
  1205. $parent = $row_parent['parent_item_id'];
  1206. $sql_bros = "SELECT * FROM $lp_item WHERE parent_item_id = $parent AND id = $id AND item_type='dokeos_chapter' ORDER BY display_order";
  1207. $res_bros = Database::query($sql_bros);
  1208. $list = array ();
  1209. while ($row_bro = Database :: fetch_array($res_bros)) {
  1210. $list[] = $row_bro;
  1211. }
  1212. return $list;
  1213. }
  1214. return array ();
  1215. }
  1216. /**
  1217. * Gets all the items belonging to the same parent as the item given
  1218. * Can also be called as abstract method
  1219. * @param integer Item ID
  1220. * @return array A list of all the "brother items" (or an empty array on failure)
  1221. */
  1222. public function get_brother_items($id) {
  1223. if ($this->debug > 0) {
  1224. error_log('New LP - In learnpath::get_brother_items(' . $id . ')', 0);
  1225. }
  1226. if (empty ($id) OR $id != strval(intval($id))) {
  1227. return array ();
  1228. }
  1229. $lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  1230. $sql_parent = "SELECT * FROM $lp_item WHERE id = $id";
  1231. $res_parent = Database::query($sql_parent);
  1232. if (Database :: num_rows($res_parent) > 0) {
  1233. $row_parent = Database :: fetch_array($res_parent);
  1234. $parent = $row_parent['parent_item_id'];
  1235. $sql_bros = "SELECT * FROM $lp_item WHERE parent_item_id = $parent ORDER BY display_order";
  1236. $res_bros = Database::query($sql_bros);
  1237. $list = array ();
  1238. while ($row_bro = Database :: fetch_array($res_bros)) {
  1239. $list[] = $row_bro;
  1240. }
  1241. return $list;
  1242. }
  1243. return array ();
  1244. }
  1245. /**
  1246. * Get the specific prefix index terms of this learning path
  1247. * @return array Array of terms
  1248. */
  1249. public function get_common_index_terms_by_prefix($prefix) {
  1250. require_once api_get_path(LIBRARY_PATH).'specific_fields_manager.lib.php';
  1251. $terms = get_specific_field_values_list_by_prefix($prefix, $this->cc, TOOL_LEARNPATH, $this->lp_id);
  1252. $prefix_terms = array ();
  1253. foreach ($terms as $term) {
  1254. $prefix_terms[] = $term['value'];
  1255. }
  1256. return $prefix_terms;
  1257. }
  1258. /**
  1259. * Gets the number of items currently completed
  1260. * @return integer The number of items currently completed
  1261. */
  1262. public function get_complete_items_count() {
  1263. if ($this->debug > 0) {
  1264. error_log('New LP - In learnpath::get_complete_items_count()', 0);
  1265. }
  1266. $i = 0;
  1267. foreach ($this->items as $id => $dummy) {
  1268. //Trying failed and browsed considered "progressed" as well
  1269. if ($this->items[$id]->status_is(array (
  1270. 'completed',
  1271. 'passed',
  1272. 'succeeded',
  1273. 'browsed',
  1274. 'failed'
  1275. )) && $this->items[$id]->get_type() != 'dokeos_chapter' && $this->items[$id]->get_type() != 'dir') {
  1276. $i++;
  1277. }
  1278. }
  1279. return $i;
  1280. }
  1281. /**
  1282. * Gets the current item ID
  1283. * @return integer The current learnpath item id
  1284. */
  1285. public function get_current_item_id() {
  1286. $current = 0;
  1287. if ($this->debug > 0) {
  1288. error_log('New LP - In learnpath::get_current_item_id()', 0);
  1289. }
  1290. if (!empty ($this->current)) {
  1291. $current = $this->current;
  1292. }
  1293. if ($this->debug > 2) {
  1294. error_log('New LP - In learnpath::get_current_item_id() - Returning ' . $current, 0);
  1295. }
  1296. return $current;
  1297. }
  1298. /**
  1299. * Force to get the first learnpath item id
  1300. * @return integer The current learnpath item id
  1301. */
  1302. public function get_first_item_id() {
  1303. $current = 0;
  1304. if (is_array($this->ordered_items)) {
  1305. $current = $this->ordered_items[0];
  1306. }
  1307. return $current;
  1308. }
  1309. /**
  1310. * Gets the total number of items available for viewing in this SCORM
  1311. * @return integer The total number of items
  1312. */
  1313. public function get_total_items_count() {
  1314. if ($this->debug > 0) {
  1315. error_log('New LP - In learnpath::get_total_items_count()', 0);
  1316. }
  1317. return count($this->items);
  1318. }
  1319. /**
  1320. * Gets the total number of items available for viewing in this SCORM but without chapters
  1321. * @return integer The total no-chapters number of items
  1322. */
  1323. public function get_total_items_count_without_chapters() {
  1324. if ($this->debug > 0) {
  1325. error_log('New LP - In learnpath::get_total_items_count_without_chapters()', 0);
  1326. }
  1327. $total = 0;
  1328. foreach ($this->items as $temp => $temp2) {
  1329. if (!in_array($temp2->get_type(), array (
  1330. 'dokeos_chapter',
  1331. 'chapter',
  1332. 'dir'
  1333. )))
  1334. $total++;
  1335. }
  1336. return $total;
  1337. }
  1338. /**
  1339. * Gets the first element URL.
  1340. * @return string URL to load into the viewer
  1341. */
  1342. public function first() {
  1343. if ($this->debug > 0) {
  1344. error_log('New LP - In learnpath::first()', 0);
  1345. }
  1346. //test if the last_item_seen exists and is not a dir
  1347. if (count($this->ordered_items) == 0) {
  1348. $this->index = 0;
  1349. }
  1350. 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()) {
  1351. if ($this->debug > 2) {
  1352. 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);
  1353. }
  1354. $index = -1;
  1355. foreach ($this->ordered_items as $myindex => $item_id) {
  1356. if ($item_id == $this->last_item_seen) {
  1357. $index = $myindex;
  1358. break;
  1359. }
  1360. }
  1361. if ($index == -1) {
  1362. //index hasn't changed, so item not found - panic (this shouldn't happen)
  1363. if ($this->debug > 2) {
  1364. error_log('New LP - Last item (' . $this->last_item_seen . ') was found in items but not in ordered_items, panic!', 0);
  1365. }
  1366. return false;
  1367. } else {
  1368. $this->last = $this->last_item_seen;
  1369. $this->current = $this->last_item_seen;
  1370. $this->index = $index;
  1371. }
  1372. } else {
  1373. if ($this->debug > 2) {
  1374. error_log('New LP - In learnpath::first() - No last item seen', 0);
  1375. }
  1376. $index = 0;
  1377. //loop through all ordered items and stop at the first item that is
  1378. //not a directory *and* that has not been completed yet
  1379. 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) {
  1380. $index++;
  1381. }
  1382. $this->last = $this->current;
  1383. //current is
  1384. $this->current = $this->ordered_items[$index];
  1385. $this->index = $index;
  1386. if ($this->debug > 2) {
  1387. error_log('New LP - In learnpath::first() - No last item seen. New last = ' . $this->last . '(' . $this->ordered_items[$index] . ')', 0);
  1388. }
  1389. }
  1390. if ($this->debug > 2) {
  1391. error_log('New LP - In learnpath::first() - First item is ' . $this->get_current_item_id());
  1392. }
  1393. }
  1394. /**
  1395. * Gets the information about an item in a format usable as JavaScript to update
  1396. * the JS API by just printing this content into the <head> section of the message frame
  1397. * @param integer Item ID
  1398. * @return string
  1399. */
  1400. public function get_js_info($item_id = '') {
  1401. if ($this->debug > 0) {
  1402. error_log('New LP - In learnpath::get_js_info(' . $item_id . ')', 0);
  1403. }
  1404. $info = '';
  1405. $item_id = $this->escape_string($item_id);
  1406. if (!empty ($item_id) && is_object($this->items[$item_id])) {
  1407. //if item is defined, return values from DB
  1408. $oItem = $this->items[$item_id];
  1409. $info .= '<script language="javascript">';
  1410. $info .= "top.set_score(" . $oItem->get_score() . ");\n";
  1411. $info .= "top.set_max(" . $oItem->get_max() . ");\n";
  1412. $info .= "top.set_min(" . $oItem->get_min() . ");\n";
  1413. $info .= "top.set_lesson_status('" . $oItem->get_status() . "');";
  1414. $info .= "top.set_session_time('" . $oItem->get_scorm_time('js') . "');";
  1415. $info .= "top.set_suspend_data('" . $oItem->get_suspend_data() . "');";
  1416. $info .= "top.set_saved_lesson_status('" . $oItem->get_status() . "');";
  1417. $info .= "top.set_flag_synchronized();";
  1418. $info .= '</script>';
  1419. if ($this->debug > 2) {
  1420. error_log('New LP - in learnpath::get_js_info(' . $item_id . ') - returning: ' . $info, 0);
  1421. }
  1422. return $info;
  1423. } else {
  1424. //if item_id is empty, just update to default SCORM data
  1425. $info .= '<script language="javascript">';
  1426. $info .= "top.set_score(" . learnpathItem :: get_score() . ");\n";
  1427. $info .= "top.set_max(" . learnpathItem :: get_max() . ");\n";
  1428. $info .= "top.set_min(" . learnpathItem :: get_min() . ");\n";
  1429. $info .= "top.set_lesson_status('" . learnpathItem :: get_status() . "');";
  1430. $info .= "top.set_session_time('" . learnpathItem :: get_scorm_time('js') . "');";
  1431. $info .= "top.set_suspend_data('" . learnpathItem :: get_suspend_data() . "');";
  1432. $info .= "top.set_saved_lesson_status('" . learnpathItem :: get_status() . "');";
  1433. $info .= "top.set_flag_synchronized();";
  1434. $info .= '</script>';
  1435. if ($this->debug > 2) {
  1436. error_log('New LP - in learnpath::get_js_info(' . $item_id . ') - returning: ' . $info, 0);
  1437. }
  1438. return $info;
  1439. }
  1440. }
  1441. /**
  1442. * Gets the js library from the database
  1443. * @return string The name of the javascript library to be used
  1444. */
  1445. public function get_js_lib() {
  1446. $lib = '';
  1447. if (!empty ($this->js_lib)) {
  1448. $lib = $this->js_lib;
  1449. }
  1450. return $lib;
  1451. }
  1452. /**
  1453. * Gets the learnpath database ID
  1454. * @return integer Learnpath ID in the lp table
  1455. */
  1456. public function get_id() {
  1457. //if($this->debug>0){error_log('New LP - In learnpath::get_id()',0);}
  1458. if (!empty ($this->lp_id)) {
  1459. return $this->lp_id;
  1460. } else {
  1461. return 0;
  1462. }
  1463. }
  1464. /**
  1465. * Gets the last element URL.
  1466. * @return string URL to load into the viewer
  1467. */
  1468. public function get_last() {
  1469. if ($this->debug > 0) {
  1470. error_log('New LP - In learnpath::get_last()', 0);
  1471. }
  1472. $this->index = count($this->ordered_items) - 1;
  1473. return $this->ordered_items[$this->index];
  1474. }
  1475. /**
  1476. * Gets the navigation bar for the learnpath display screen
  1477. * @return string The HTML string to use as a navigation bar
  1478. */
  1479. public function get_navigation_bar() {
  1480. if ($this->debug > 0) {
  1481. error_log('New LP - In learnpath::get_navigation_bar()', 0);
  1482. }
  1483. //TODO find a good value for the following variables
  1484. $file = '';
  1485. $openDir = '';
  1486. $edoceo = '';
  1487. $time = 0;
  1488. $navbar = '';
  1489. $RequestUri = '';
  1490. $mycurrentitemid = $this->get_current_item_id();
  1491. if ($this->mode == 'fullscreen') {
  1492. $navbar = '<table cellpadding="0" cellspacing="0" align="left">' . "\n" .
  1493. ' <tr> ' . "\n" .
  1494. ' <td>' . "\n" .
  1495. ' <div class="buttons">' . "\n" .
  1496. ' <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" .
  1497. ' <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" .
  1498. ' <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" .
  1499. //' <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" .
  1500. //' <a href="lp_controller.php?action=list" target="_top" title="learnpaths list"><img border="0" src="../img/exit.png" title="Exit"></a>'."\n" .
  1501. ' </div>' . "\n" .
  1502. ' </td>' . "\n" .
  1503. ' </tr>' . "\n" .
  1504. '</table>' . "\n";
  1505. } else {
  1506. $navbar = '<table cellpadding="0" cellspacing="0" align="left">' . "\n" .
  1507. ' <tr> ' . "\n" .
  1508. ' <td>' . "\n" .
  1509. ' <div class="buttons">' . "\n" .
  1510. ' <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" .
  1511. ' <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" .
  1512. ' <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" .
  1513. // ' <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" .
  1514. ' </div>' . "\n" .
  1515. ' </td>' . "\n" .
  1516. ' </tr>' . "\n" .
  1517. '</table>' . "\n";
  1518. }
  1519. return $navbar;
  1520. }
  1521. /**
  1522. * Gets the next resource in queue (url).
  1523. * @return string URL to load into the viewer
  1524. */
  1525. public function get_next_index() {
  1526. if ($this->debug > 0) {
  1527. error_log('New LP - In learnpath::get_next_index()', 0);
  1528. }
  1529. //TODO
  1530. $index = $this->index;
  1531. $index++;
  1532. if ($this->debug > 2) {
  1533. error_log('New LP - Now looking at ordered_items[' . ($index) . '] - type is ' . $this->items[$this->ordered_items[$index]]->type, 0);
  1534. }
  1535. 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) {
  1536. $index++;
  1537. if ($index == $this->max_ordered_items){
  1538. if ($this->items[$this->ordered_items[$index]]->get_type() == 'dir' || $this->items[$this->ordered_items[$index]]->get_type() == 'dokeos_chapter') {
  1539. return $this->index;
  1540. } else {
  1541. return $index;
  1542. }
  1543. }
  1544. }
  1545. if (empty ($this->ordered_items[$index])) {
  1546. return $this->index;
  1547. }
  1548. if ($this->debug > 2) {
  1549. error_log('New LP - index is now ' . $index, 0);
  1550. }
  1551. return $index;
  1552. }
  1553. /**
  1554. * Gets item_id for the next element
  1555. * @return integer Next item (DB) ID
  1556. */
  1557. public function get_next_item_id() {
  1558. if ($this->debug > 0) {
  1559. error_log('New LP - In learnpath::get_next_item_id()', 0);
  1560. }
  1561. $new_index = $this->get_next_index();
  1562. if (!empty ($new_index)) {
  1563. if (isset ($this->ordered_items[$new_index])) {
  1564. if ($this->debug > 2) {
  1565. error_log('New LP - In learnpath::get_next_index() - Returning ' . $this->ordered_items[$new_index], 0);
  1566. }
  1567. return $this->ordered_items[$new_index];
  1568. }
  1569. }
  1570. if ($this->debug > 2) {
  1571. error_log('New LP - In learnpath::get_next_index() - Problem - Returning 0', 0);
  1572. }
  1573. return 0;
  1574. }
  1575. /**
  1576. * Returns the package type ('scorm','aicc','scorm2004','dokeos','ppt'...)
  1577. *
  1578. * Generally, the package provided is in the form of a zip file, so the function
  1579. * has been written to test a zip file. If not a zip, the function will return the
  1580. * default return value: ''
  1581. * @param string the path to the file
  1582. * @param string the original name of the file
  1583. * @return string 'scorm','aicc','scorm2004','dokeos' or '' if the package cannot be recognized
  1584. */
  1585. public function get_package_type($file_path, $file_name) {
  1586. //get name of the zip file without the extension
  1587. $file_info = pathinfo($file_name);
  1588. $filename = $file_info['basename']; //name including extension
  1589. $extension = $file_info['extension']; //extension only
  1590. if (!empty ($_POST['ppt2lp']) && !in_array(strtolower($extension), array (
  1591. 'dll',
  1592. 'exe'
  1593. ))) {
  1594. return 'oogie';
  1595. }
  1596. if (!empty ($_POST['woogie']) && !in_array(strtolower($extension), array (
  1597. 'dll',
  1598. 'exe'
  1599. ))) {
  1600. return 'woogie';
  1601. }
  1602. $file_base_name = str_replace('.' . $extension, '', $filename); //filename without its extension
  1603. $zipFile = new pclZip($file_path);
  1604. // Check the zip content (real size and file extension)
  1605. $zipContentArray = $zipFile->listContent();
  1606. $package_type = '';
  1607. $at_root = false;
  1608. $manifest = '';
  1609. //the following loop should be stopped as soon as we found the right imsmanifest.xml (how to recognize it?)
  1610. if (is_array($zipContentArray) && count($zipContentArray) > 0) {
  1611. foreach ($zipContentArray as $thisContent) {
  1612. if (preg_match('~.(php.*|phtml)$~i', $thisContent['filename'])) {
  1613. //New behaviour: Don't do anything. These files will be removed in scorm::import_package
  1614. }
  1615. elseif (stristr($thisContent['filename'], 'imsmanifest.xml') !== FALSE) {
  1616. $manifest = $thisContent['filename']; //just the relative directory inside scorm/
  1617. $package_type = 'scorm';
  1618. break; //exit the foreach loop
  1619. }
  1620. elseif (preg_match('/aicc\//i', $thisContent['filename'])) {
  1621. //if found an aicc directory... (!= false means it cannot be false (error) or 0 (no match))
  1622. $package_type = 'aicc';
  1623. //break;//don't exit the loop, because if we find an imsmanifest afterwards, we want it, not the AICC
  1624. } else {
  1625. $package_type = '';
  1626. }
  1627. }
  1628. }
  1629. return $package_type;
  1630. }
  1631. /**
  1632. * Gets the previous resource in queue (url). Also initialises time values for this viewing
  1633. * @return string URL to load into the viewer
  1634. */
  1635. public function get_previous_index() {
  1636. if ($this->debug > 0) {
  1637. error_log('New LP - In learnpath::get_previous_index()', 0);
  1638. }
  1639. $index = $this->index;
  1640. if (isset ($this->ordered_items[$index -1])) {
  1641. $index--;
  1642. 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')) {
  1643. $index--;
  1644. if ($index < 0) {
  1645. return $this->index;
  1646. }
  1647. }
  1648. } else {
  1649. if ($this->debug > 2) {
  1650. error_log('New LP - get_previous_index() - there was no previous index available, reusing ' . $index, 0);
  1651. }
  1652. //no previous item
  1653. }
  1654. return $index;
  1655. }
  1656. /**
  1657. * Gets item_id for the next element
  1658. * @return integer Previous item (DB) ID
  1659. */
  1660. public function get_previous_item_id() {
  1661. if ($this->debug > 0) {
  1662. error_log('New LP - In learnpath::get_previous_item_id()', 0);
  1663. }
  1664. $new_index = $this->get_previous_index();
  1665. return $this->ordered_items[$new_index];
  1666. }
  1667. /**
  1668. * Gets the progress value from the progress_db attribute
  1669. * @return integer Current progress value
  1670. */
  1671. public function get_progress() {
  1672. if ($this->debug > 0) {
  1673. error_log('New LP - In learnpath::get_progress()', 0);
  1674. }
  1675. if (!empty ($this->progress_db)) {
  1676. return $this->progress_db;
  1677. }
  1678. return 0;
  1679. }
  1680. /**
  1681. * Gets the progress value from the progress field in the database (allows use as abstract method)
  1682. * @param integer Learnpath ID
  1683. * @param integer User ID
  1684. * @param string Mode of display ('%','abs' or 'both')
  1685. * @param string Course database name (optional, defaults to '')
  1686. * @param boolean Whether to return null if no record was found (true), or 0 (false) (optional, defaults to false)
  1687. * @return integer Current progress value as found in the database
  1688. */
  1689. public function get_db_progress($lp_id, $user_id, $mode = '%', $course_db = '', $sincere = false) {
  1690. //if($this->debug>0){error_log('New LP - In learnpath::get_db_progress()',0);}
  1691. $session_id = api_get_session_id();
  1692. $session_condition = api_get_session_condition($session_id);
  1693. $table = Database :: get_course_table(TABLE_LP_VIEW, $course_db);
  1694. $sql = "SELECT * FROM $table WHERE lp_id = $lp_id AND user_id = $user_id $session_condition";
  1695. $res = Database::query($sql);
  1696. $view_id = 0;
  1697. if (Database :: num_rows($res) > 0) {
  1698. $row = Database :: fetch_array($res);
  1699. $progress = $row['progress'];
  1700. $view_id = $row['id'];
  1701. } else {
  1702. if ($sincere) {
  1703. return null;
  1704. }
  1705. }
  1706. if (empty ($progress)) {
  1707. $progress = '0';
  1708. }
  1709. if ($mode == '%') {
  1710. return $progress . '%';
  1711. } else {
  1712. //get the number of items completed and the number of items total
  1713. $tbl = Database :: get_course_table(TABLE_LP_ITEM, $course_db);
  1714. $sql = "SELECT count(*) FROM $tbl WHERE lp_id = " . $lp_id . "
  1715. AND item_type NOT IN('dokeos_chapter','chapter','dir')";
  1716. $res = Database::query($sql);
  1717. $row = Database :: fetch_array($res);
  1718. $total = $row[0];
  1719. $tbl_item_view = Database :: get_course_table(TABLE_LP_ITEM_VIEW, $course_db);
  1720. $tbl_item = Database :: get_course_table(TABLE_LP_ITEM, $course_db);
  1721. //$sql = "SELECT count(distinct(lp_item_id)) FROM $tbl WHERE lp_view_id = ".$view_id." AND status IN ('passed','completed','succeeded')";
  1722. //trying as also counting browsed and failed items
  1723. $sql = "SELECT count(distinct(lp_item_id))
  1724. FROM $tbl_item_view as item_view
  1725. INNER JOIN $tbl_item as item
  1726. ON item.id = item_view.lp_item_id
  1727. AND item_type NOT IN('dokeos_chapter','chapter','dir')
  1728. WHERE lp_view_id = " . $view_id . "
  1729. AND status IN ('passed','completed','succeeded','browsed','failed')";
  1730. $res = Database::query($sql);
  1731. $row = Database :: fetch_array($res);
  1732. $completed = $row[0];
  1733. if ($mode == 'abs') {
  1734. return $completed . '/' . $total;
  1735. }
  1736. elseif ($mode == 'both') {
  1737. if ($progress < ($completed / ($total ? $total : 1))) {
  1738. $progress = number_format(($completed / ($total ? $total : 1)) * 100, 0);
  1739. }
  1740. return $progress . '% (' . $completed . '/' . $total . ')';
  1741. }
  1742. }
  1743. return $progress;
  1744. }
  1745. /**
  1746. * Returns the HTML necessary to print a mediaplayer block inside a page
  1747. * @return string The mediaplayer HTML
  1748. */
  1749. public function get_mediaplayer($autostart='true') {
  1750. global $_course;
  1751. // Database table definition
  1752. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  1753. $tbl_lp_item_view = Database :: get_course_table(TABLE_LP_ITEM_VIEW);
  1754. // getting all the information about the item
  1755. $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 " .
  1756. "WHERE lp.id = '" . $_SESSION['oLP']->current . "'";
  1757. $result = Database::query($sql);
  1758. $row = Database::fetch_assoc($result);
  1759. $output = '';
  1760. if (!empty ($row['audio'])) {
  1761. $list = $_SESSION['oLP']->get_toc();
  1762. $type_quiz = false;
  1763. foreach($list as $toc) {
  1764. if ($toc['id'] == $_SESSION['oLP']->current && ($toc['type']=='quiz') ) {
  1765. $type_quiz = true;
  1766. }
  1767. }
  1768. if ($type_quiz) {
  1769. if ($_SESSION['oLP']->prevent_reinit == 1) {
  1770. $row['status'] === 'completed' ? $autostart_audio = 'false' : $autostart_audio = 'true';
  1771. } else {
  1772. $autostart_audio = $autostart;
  1773. }
  1774. } else {
  1775. $autostart_audio = 'true';
  1776. }
  1777. // the mp3 player
  1778. $output = '<div id="container">';
  1779. $output .= '<script type="text/javascript" src="../inc/lib/mediaplayer/swfobject.js"></script>';
  1780. $output .= '<script type="text/javascript">
  1781. var s1 = new SWFObject("../inc/lib/mediaplayer/player.swf","ply","250","20","9","#FFFFFF");
  1782. s1.addParam("allowscriptaccess","always");
  1783. s1.addParam("flashvars","file=' . api_get_path(WEB_COURSE_PATH) . $_course['path'] . '/document/audio/' . $row['audio'] . '&autostart=' . $autostart_audio.'");
  1784. s1.write("container");
  1785. </script></div>';
  1786. }
  1787. return $output;
  1788. }
  1789. /**
  1790. * This function check if the learnpath is visible for student after the progress of its prerequisite is completed
  1791. * @param int Learnpath id
  1792. * @param int Student id
  1793. * @return bool True if
  1794. */
  1795. public function is_lp_visible_for_student($lp_id, $student_id) {
  1796. $tbl_learnpath = Database :: get_course_table(TABLE_LP_MAIN);
  1797. // get current prerequisite
  1798. $sql = "SELECT prerequisite FROM $tbl_learnpath WHERE id = $lp_id";
  1799. $rs = Database::query($sql);
  1800. $row = Database :: fetch_array($rs);
  1801. $prerequisite = $row['prerequisite'];
  1802. $is_visible = true;
  1803. $progress = 0;
  1804. if (!empty($prerequisite)) {
  1805. $progress = self::get_db_progress($prerequisite,$student_id,'%');
  1806. $progress = intval($progress);
  1807. if ($progress < 100) {
  1808. $is_visible = false;
  1809. }
  1810. }
  1811. return $is_visible;
  1812. }
  1813. /**
  1814. * Gets a progress bar for the learnpath by counting the number of items in it and the number of items
  1815. * completed so far.
  1816. * @param string Mode in which we want the values
  1817. * @param integer Progress value to display (optional but mandatory if used in abstract context)
  1818. * @param string Text to display near the progress value (optional but mandatory in abstract context)
  1819. * @param boolean true if it comes from a Diplay LP view
  1820. * @return string HTML string containing the progress bar
  1821. */
  1822. public function get_progress_bar($mode = '', $percentage = -1, $text_add = '', $from_lp = false) {
  1823. //if($this->debug>0){error_log('New LP - In learnpath::get_progress_bar('.$mode.','.$percentage.','.$text_add.','.$from_lp.')',0);}
  1824. global $lp_theme_css;
  1825. // Setting up the CSS path of the current style if exists
  1826. if (!empty ($lp_theme_css)) {
  1827. $css_path = api_get_path(WEB_CODE_PATH) . 'css/' . $lp_theme_css . '/images/';
  1828. } else {
  1829. $css_path = '../img/';
  1830. }
  1831. //if($this->debug>0){error_log('New LP - In learnpath::get_progress_bar()',0);}
  1832. if (isset ($this) && is_object($this) && ($percentage == '-1' OR $text_add == '')) {
  1833. list ($percentage, $text_add) = $this->get_progress_bar_text($mode);
  1834. }
  1835. $text = $percentage . $text_add;
  1836. //Default progress bar config
  1837. // times that will be greater or shorter
  1838. $factor = 1.2;
  1839. if ($from_lp)
  1840. $progress_height = '26';
  1841. else
  1842. $progress_height = '16';
  1843. $size = str_replace('%', '', $percentage);
  1844. $output =
  1845. '<table border="0" cellpadding="0" cellspacing="0"><tr><td>' .
  1846. '<img id="progress_img_limit_left" src="' . $css_path . 'bar_1.gif" width="1" height="' . $progress_height . '">' .
  1847. '<img id="progress_img_full" src="' . $css_path . 'bar_1u.gif" width="' . $size * $factor . 'px" height="' . $progress_height . '" id="full_portion">' .
  1848. '<img id="progress_img_limit_middle" src="' . $css_path . 'bar_1m.gif" width="1" height="' . $progress_height . '">';
  1849. if ($percentage <= 98) {
  1850. $output .= '<img id="progress_img_empty" src="' . $css_path . 'bar_1r.gif" width="' . (100 - $size) * $factor . 'px" height="' . $progress_height . '" id="empty_portion">';
  1851. } else {
  1852. $output .= '<img id="progress_img_empty" src="' . $css_path . 'bar_1r.gif" width="0" height="' . $progress_height . '" id="empty_portion">';
  1853. }
  1854. $output .= '<img id="progress_bar_img_limit_right" src="' . $css_path . 'bar_1.gif" width="1" height="' . $progress_height . '"></td></tr></table>' .
  1855. '<div class="progresstext" id="progress_text">' . $text . '</div>';
  1856. return $output;
  1857. }
  1858. /**
  1859. * Gets the progress bar info to display inside the progress bar. Also used by scorm_api.php
  1860. * @param string Mode of display (can be '%' or 'abs').abs means we display a number of completed elements per total elements
  1861. * //@param integer Additional steps to fake as completed
  1862. * @return list Percentage or number and symbol (% or /xx)
  1863. */
  1864. public function get_progress_bar_text($mode = '', $add = 0) {
  1865. if ($this->debug > 0) {
  1866. error_log('New LP - In learnpath::get_progress_bar_text()', 0);
  1867. }
  1868. if (empty ($mode)) {
  1869. $mode = $this->progress_bar_mode;
  1870. }
  1871. $total_items = $this->get_total_items_count_without_chapters();
  1872. if ($this->debug > 2) {
  1873. error_log('New LP - Total items available in this learnpath: ' . $total_items, 0);
  1874. }
  1875. $i = $this->get_complete_items_count();
  1876. if ($this->debug > 2) {
  1877. error_log('New LP - Items completed so far: ' . $i, 0);
  1878. }
  1879. if ($add != 0) {
  1880. $i += $add;
  1881. if ($this->debug > 2) {
  1882. error_log('New LP - Items completed so far (+modifier): ' . $i, 0);
  1883. }
  1884. }
  1885. $text = '';
  1886. if ($i > $total_items) {
  1887. $i = $total_items;
  1888. }
  1889. if ($mode == '%') {
  1890. if ($total_items > 0) {
  1891. $percentage = ((float) $i / (float) $total_items) * 100;
  1892. } else {
  1893. $percentage = 0;
  1894. }
  1895. $percentage = number_format($percentage, 0);
  1896. $text = '%';
  1897. }
  1898. elseif ($mode == 'abs') {
  1899. $percentage = $i;
  1900. $text = '/' . $total_items;
  1901. }
  1902. return array (
  1903. $percentage,
  1904. $text
  1905. );
  1906. }
  1907. /**
  1908. * Gets the progress bar mode
  1909. * @return string The progress bar mode attribute
  1910. */
  1911. public function get_progress_bar_mode() {
  1912. if ($this->debug > 0) {
  1913. error_log('New LP - In learnpath::get_progress_bar_mode()', 0);
  1914. }
  1915. if (!empty ($this->progress_bar_mode)) {
  1916. return $this->progress_bar_mode;
  1917. } else {
  1918. return '%';
  1919. }
  1920. }
  1921. /**
  1922. * Gets the learnpath proximity (remote or local)
  1923. * @return string Learnpath proximity
  1924. */
  1925. public function get_proximity() {
  1926. if ($this->debug > 0) {
  1927. error_log('New LP - In learnpath::get_proximity()', 0);
  1928. }
  1929. if (!empty ($this->proximity)) {
  1930. return $this->proximity;
  1931. } else {
  1932. return '';
  1933. }
  1934. }
  1935. /**
  1936. * Gets the learnpath theme (remote or local)
  1937. * @return string Learnpath theme
  1938. */
  1939. public function get_theme() {
  1940. if ($this->debug > 0) {
  1941. error_log('New LP - In learnpath::get_theme()', 0);
  1942. }
  1943. if (!empty ($this->theme)) {
  1944. return $this->theme;
  1945. } else {
  1946. return '';
  1947. }
  1948. }
  1949. /**
  1950. * Gets the learnpath session id
  1951. * @return string Learnpath theme
  1952. */
  1953. public function get_lp_session_id() {
  1954. if ($this->debug > 0) {
  1955. error_log('New LP - In learnpath::get_lp_session_id()', 0);
  1956. }
  1957. if (!empty ($this->lp_session_id)) {
  1958. return $this->lp_session_id;
  1959. } else {
  1960. return 0;
  1961. }
  1962. }
  1963. /**
  1964. * Gets the learnpath image
  1965. * @return string Web URL of the LP image
  1966. */
  1967. public function get_preview_image() {
  1968. if ($this->debug > 0) {
  1969. error_log('New LP - In learnpath::get_preview_image()', 0);
  1970. }
  1971. if (!empty ($this->preview_image)) {
  1972. return $this->preview_image;
  1973. } else {
  1974. return '';
  1975. }
  1976. }
  1977. /**
  1978. * Gets the learnpath author
  1979. * @return string LP's author
  1980. */
  1981. public function get_author() {
  1982. if ($this->debug > 0) {
  1983. error_log('New LP - In learnpath::get_author()', 0);
  1984. }
  1985. if (!empty ($this->author)) {
  1986. return $this->author;
  1987. } else {
  1988. return '';
  1989. }
  1990. }
  1991. /**
  1992. * Generate a new prerequisites string for a given item. If this item was a sco and
  1993. * its prerequisites were strings (instead of IDs), then transform those strings into
  1994. * IDs, knowing that SCORM IDs are kept in the "ref" field of the lp_item table.
  1995. * Prefix all item IDs that end-up in the prerequisites string by "ITEM_" to use the
  1996. * same rule as the scorm_export() method
  1997. * @param integer Item ID
  1998. * @return string Prerequisites string ready for the export as SCORM
  1999. */
  2000. public function get_scorm_prereq_string($item_id) {
  2001. if ($this->debug > 0) {
  2002. error_log('New LP - In learnpath::get_scorm_prereq_string()', 0);
  2003. }
  2004. if (!is_object($this->items[$item_id])) {
  2005. return false;
  2006. }
  2007. $oItem = $this->items[$item_id];
  2008. $prereq = $oItem->get_prereq_string();
  2009. if (empty ($prereq)) {
  2010. return '';
  2011. }
  2012. 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,
  2013. //then simply return it (with the ITEM_ prefix)
  2014. return 'ITEM_' . $prereq;
  2015. } else {
  2016. if (isset ($this->refs_list[$prereq])) {
  2017. //it's a simple string item from which the ID can be found in the refs list
  2018. //so we can transform it directly to an ID for export
  2019. return 'ITEM_' . $this->refs_list[$prereq];
  2020. } else {
  2021. //last case, if it's a complex form, then find all the IDs (SCORM strings)
  2022. //and replace them, one by one, by the internal IDs (dokeos db)
  2023. //TODO modify the '*' replacement to replace the multiplier in front of it
  2024. //by a space as well
  2025. $find = array (
  2026. '&',
  2027. '|',
  2028. '~',
  2029. '=',
  2030. '<>',
  2031. '{',
  2032. '}',
  2033. '*',
  2034. '(',
  2035. ')'
  2036. );
  2037. $replace = array (
  2038. ' ',
  2039. ' ',
  2040. ' ',
  2041. ' ',
  2042. ' ',
  2043. ' ',
  2044. ' ',
  2045. ' ',
  2046. ' ',
  2047. ' '
  2048. );
  2049. $prereq_mod = str_replace($find, $replace, $prereq);
  2050. $ids = split(' ', $prereq_mod);
  2051. foreach ($ids as $id) {
  2052. $id = trim($id);
  2053. if (isset ($this->refs_list[$id])) {
  2054. $prereq = preg_replace('/[^a-zA-Z_0-9](' . $id . ')[^a-zA-Z_0-9]/', 'ITEM_' . $this->refs_list[$id], $prereq);
  2055. }
  2056. }
  2057. error_log('New LP - In learnpath::get_scorm_prereq_string(): returning modified string: ' . $prereq, 0);
  2058. return $prereq;
  2059. }
  2060. }
  2061. }
  2062. /**
  2063. * Returns the XML DOM document's node
  2064. * @param resource Reference to a list of objects to search for the given ITEM_*
  2065. * @param string The identifier to look for
  2066. * @return mixed The reference to the element found with that identifier. False if not found
  2067. */
  2068. public function get_scorm_xml_node(& $children, $id) {
  2069. for ($i = 0; $i < $children->length; $i++) {
  2070. $item_temp = $children->item($i);
  2071. if ($item_temp->nodeName == 'item') {
  2072. if ($item_temp->getAttribute('identifier') == $id) {
  2073. return $item_temp;
  2074. }
  2075. }
  2076. $subchildren = $item_temp->childNodes;
  2077. if ($subchildren->length > 0) {
  2078. $val = $this->get_scorm_xml_node($subchildren, $id);
  2079. if (is_object($val)) {
  2080. return $val;
  2081. }
  2082. }
  2083. }
  2084. return false;
  2085. }
  2086. /**
  2087. * Returns a usable array of stats related to the current learnpath and user
  2088. * @return array Well-formatted array containing status for the current learnpath
  2089. */
  2090. public function get_stats() {
  2091. if ($this->debug > 0) {
  2092. error_log('New LP - In learnpath::get_stats()', 0);
  2093. }
  2094. //TODO
  2095. }
  2096. /**
  2097. * Static method. Can be re-implemented by children. Gives an array of statistics for
  2098. * the given course (for all learnpaths and all users)
  2099. * @param string Course code
  2100. * @return array Well-formatted array containing status for the course's learnpaths
  2101. */
  2102. public function get_stats_course($course) {
  2103. //if($this->debug>0){error_log('New LP - In learnpath::get_stats_course()',0);}
  2104. //TODO
  2105. }
  2106. /**
  2107. * Static method. Can be re-implemented by children. Gives an array of statistics for
  2108. * the given course and learnpath (for all users)
  2109. * @param string Course code
  2110. * @param integer Learnpath ID
  2111. * @return array Well-formatted array containing status for the specified learnpath
  2112. */
  2113. public function get_stats_lp($course, $lp) {
  2114. //if($this->debug>0){error_log('New LP - In learnpath::get_stats_lp()',0);}
  2115. //TODO
  2116. }
  2117. /**
  2118. * Static method. Can be re-implemented by children. Gives an array of statistics for
  2119. * the given course, learnpath and user.
  2120. * @param string Course code
  2121. * @param integer Learnpath ID
  2122. * @param integer User ID
  2123. * @return array Well-formatted array containing status for the specified learnpath and user
  2124. */
  2125. public function get_stats_lp_user($course, $lp, $user) {
  2126. //if($this->debug>0){error_log('New LP - In learnpath::get_stats_lp_user()',0);}
  2127. //TODO
  2128. }
  2129. /**
  2130. * Static method. Can be re-implemented by children. Gives an array of statistics for
  2131. * the given course and learnpath (for all users)
  2132. * @param string Course code
  2133. * @param integer User ID
  2134. * @return array Well-formatted array containing status for the user's learnpaths
  2135. */
  2136. public function get_stats_user($course, $user) {
  2137. //if($this->debug>0){error_log('New LP - In learnpath::get_stats_user()',0);}
  2138. //TODO
  2139. }
  2140. /**
  2141. * Gets the status list for all LP's items
  2142. * @return array Array of [index] => [item ID => current status]
  2143. */
  2144. public function get_items_status_list() {
  2145. if ($this->debug > 0) {
  2146. error_log('New LP - In learnpath::get_items_status_list()', 0);
  2147. }
  2148. $list = array ();
  2149. foreach ($this->ordered_items as $item_id) {
  2150. $list[] = array (
  2151. $item_id => $this->items[$item_id]->get_status()
  2152. );
  2153. }
  2154. return $list;
  2155. }
  2156. /**
  2157. * Return the number of interactions for the given learnpath Item View ID.
  2158. * This method can be used as static.
  2159. * @param integer Item View ID
  2160. * @return integer Number of interactions
  2161. */
  2162. public function get_interactions_count_from_db($lp_iv_id = 0) {
  2163. if (empty ($lp_iv_id)) {
  2164. return -1;
  2165. }
  2166. $table = Database :: get_course_table(TABLE_LP_IV_INTERACTION);
  2167. $sql = "SELECT count(*) FROM $table WHERE lp_iv_id = $lp_iv_id";
  2168. $res = Database::query($sql);
  2169. $row = Database :: fetch_array($res);
  2170. $num = $row[0];
  2171. return $num;
  2172. }
  2173. /**
  2174. * Return the interactions as an array for the given lp_iv_id.
  2175. * This method can be used as static.
  2176. * @param integer Learnpath Item View ID
  2177. * @return array
  2178. * @todo Transcode labels instead of switching to HTML (which requires to know the encoding of the LP)
  2179. */
  2180. public function get_iv_interactions_array($lp_iv_id = 0) {
  2181. $charset = api_get_setting('platform_charset');
  2182. $list = array ();
  2183. $table = Database :: get_course_table(TABLE_LP_IV_INTERACTION);
  2184. $sql = "SELECT * FROM $table WHERE lp_iv_id = $lp_iv_id ORDER BY order_id ASC";
  2185. $res = Database::query($sql);
  2186. $num = Database :: num_rows($res);
  2187. if ($num > 0) {
  2188. $list[] = array (
  2189. "order_id" => api_htmlentities(get_lang('Order'), ENT_QUOTES, $charset),
  2190. "id" => api_htmlentities(get_lang('InteractionID'), ENT_QUOTES, $charset),
  2191. "type" => api_htmlentities(get_lang('Type'), ENT_QUOTES, $charset),
  2192. "time" => api_htmlentities(get_lang('TimeFinished'), ENT_QUOTES, $charset),
  2193. "correct_responses" => api_htmlentities(get_lang('CorrectAnswers'), ENT_QUOTES, $charset),
  2194. "student_response" => api_htmlentities(get_lang('StudentResponse'), ENT_QUOTES, $charset),
  2195. "result" => api_htmlentities(get_lang('Result'), ENT_QUOTES, $charset),
  2196. "latency" => api_htmlentities(get_lang('LatencyTimeSpent'), ENT_QUOTES, $charset)
  2197. );
  2198. while ($row = Database :: fetch_array($res)) {
  2199. $list[] = array (
  2200. "order_id" => ($row['order_id'] + 1),
  2201. "id" => urldecode($row['interaction_id']), //urldecode because they often have %2F or stuff like that
  2202. "type" => $row['interaction_type'],
  2203. "time" => $row['completion_time'],
  2204. //"correct_responses"=>$row['correct_responses'],
  2205. //hide correct responses from students
  2206. "correct_responses" => '',
  2207. "student_response" => $row['student_response'],
  2208. "result" => $row['result'],
  2209. "latency" => $row['latency']
  2210. );
  2211. }
  2212. }
  2213. return $list;
  2214. }
  2215. /**
  2216. * Return the number of objectives for the given learnpath Item View ID.
  2217. * This method can be used as static.
  2218. * @param integer Item View ID
  2219. * @return integer Number of objectives
  2220. */
  2221. public function get_objectives_count_from_db($lp_iv_id = 0) {
  2222. if (empty ($lp_iv_id)) {
  2223. return -1;
  2224. }
  2225. $table = Database :: get_course_table(TABLE_LP_IV_OBJECTIVE);
  2226. $sql = "SELECT count(*) FROM $table WHERE lp_iv_id = $lp_iv_id";
  2227. $res = Database::query($sql);
  2228. $row = Database :: fetch_array($res);
  2229. $num = $row[0];
  2230. return $num;
  2231. }
  2232. /**
  2233. * Return the objectives as an array for the given lp_iv_id.
  2234. * This method can be used as static.
  2235. * @param integer Learnpath Item View ID
  2236. * @return array
  2237. * @todo Translate labels
  2238. */
  2239. public function get_iv_objectives_array($lp_iv_id = 0) {
  2240. global $charset;
  2241. $list = array ();
  2242. $table = Database :: get_course_table(TABLE_LP_IV_OBJECTIVE);
  2243. $sql = "SELECT * FROM $table WHERE lp_iv_id = $lp_iv_id ORDER BY order_id ASC";
  2244. $res = Database::query($sql);
  2245. $num = Database :: num_rows($res);
  2246. if ($num > 0) {
  2247. $list[] = array (
  2248. "order_id" => api_htmlentities(get_lang('Order'), ENT_QUOTES, $charset),
  2249. "objective_id" => api_htmlentities(get_lang('ObjectiveID'), ENT_QUOTES, $charset),
  2250. "score_raw" => api_htmlentities(get_lang('ObjectiveRawScore'), ENT_QUOTES, $charset),
  2251. "score_max" => api_htmlentities(get_lang('ObjectiveMaxScore'), ENT_QUOTES, $charset),
  2252. "score_min" => api_htmlentities(get_lang('ObjectiveMinScore'), ENT_QUOTES, $charset),
  2253. "status" => api_htmlentities(get_lang('ObjectiveStatus'), ENT_QUOTES, $charset)
  2254. );
  2255. while ($row = Database :: fetch_array($res)) {
  2256. $list[] = array (
  2257. "order_id" => ($row['order_id'] + 1),
  2258. "objective_id" => urldecode($row['objective_id']), //urldecode because they often have %2F or stuff like that
  2259. "score_raw" => $row['score_raw'],
  2260. "score_max" => $row['score_max'],
  2261. "score_min" => $row['score_min'],
  2262. "status" => $row['status']
  2263. );
  2264. }
  2265. }
  2266. return $list;
  2267. }
  2268. /**
  2269. * Generate and return the table of contents for this learnpath. The (flat) table returned can be
  2270. * used by get_html_toc() to be ready to display
  2271. * @return array TOC as a table with 4 elements per row: title, link, status and level
  2272. */
  2273. public function get_toc() {
  2274. if ($this->debug > 0) {
  2275. error_log('New LP - In learnpath::get_toc()', 0);
  2276. }
  2277. $toc = array ();
  2278. //echo "<pre>".print_r($this->items,true)."</pre>";
  2279. foreach ($this->ordered_items as $item_id) {
  2280. if ($this->debug > 2) {
  2281. error_log('New LP - learnpath::get_toc(): getting info for item ' . $item_id, 0);
  2282. }
  2283. //TODO change this link generation and use new function instead
  2284. $toc[] = array (
  2285. 'id' => $item_id,
  2286. 'title' => $this->items[$item_id]->get_title(),
  2287. //'link'=>get_addedresource_link_in_learnpath('document',$item_id,1),
  2288. 'status' => $this->items[$item_id]->get_status(),
  2289. 'level' => $this->items[$item_id]->get_level(),
  2290. 'type' => $this->items[$item_id]->get_type(),
  2291. 'description' => $this->items[$item_id]->get_description(),
  2292. 'path' => $this->items[$item_id]->get_path(),
  2293. );
  2294. }
  2295. if ($this->debug > 2) {
  2296. error_log('New LP - In learnpath::get_toc() - TOC array: ' . print_r($toc, true), 0);
  2297. }
  2298. return $toc;
  2299. }
  2300. /**
  2301. * Generate and return the table of contents for this learnpath. The JS
  2302. * table returned is used inside of scorm_api.php
  2303. * @return string A JS array vairiable construction
  2304. */
  2305. public function get_items_details_as_js($varname='olms.lms_item_types') {
  2306. if ($this->debug > 0) {
  2307. error_log('New LP - In learnpath::get_items_details_as_js()', 0);
  2308. }
  2309. $toc = $varname.' = new Array();';
  2310. //echo "<pre>".print_r($this->items,true)."</pre>";
  2311. foreach ($this->ordered_items as $item_id) {
  2312. if ($this->debug > 2) {
  2313. error_log('New LP - learnpath::get_items_details_as_js(): getting info for item ' . $item_id, 0);
  2314. }
  2315. $toc.= $varname."['i$item_id'] = '".$this->items[$item_id]->get_type()."';";
  2316. }
  2317. if ($this->debug > 2) {
  2318. error_log('New LP - In learnpath::get_items_details_as_js() - TOC array: ' . print_r($toc, true), 0);
  2319. }
  2320. return $toc;
  2321. }
  2322. /**
  2323. * Gets the learning path type
  2324. * @param boolean Return the name? If false, return the ID. Default is false.
  2325. * @return mixed Type ID or name, depending on the parameter
  2326. */
  2327. public function get_type($get_name = false) {
  2328. $res = false;
  2329. if ($this->debug > 0) {
  2330. error_log('New LP - In learnpath::get_type()', 0);
  2331. }
  2332. if (!empty ($this->type)) {
  2333. if ($get_name) {
  2334. //get it from the lp_type table in main db
  2335. } else {
  2336. $res = $this->type;
  2337. }
  2338. }
  2339. if ($this->debug > 2) {
  2340. error_log('New LP - In learnpath::get_type() - Returning ' . ($res ? $res : 'false'), 0);
  2341. }
  2342. return $res;
  2343. }
  2344. /**
  2345. * Gets the learning path type as static method
  2346. * @param boolean Return the name? If false, return the ID. Default is false.
  2347. * @return mixed Type ID or name, depending on the parameter
  2348. */
  2349. public function get_type_static($lp_id = 0) {
  2350. $tbl_lp = Database :: get_course_table(TABLE_LP_MAIN);
  2351. $sql = "SELECT lp_type FROM $tbl_lp WHERE id = '" . $lp_id . "'";
  2352. $res = Database::query($sql);
  2353. if ($res === false) {
  2354. return null;
  2355. }
  2356. if (Database :: num_rows($res) <= 0) {
  2357. return null;
  2358. }
  2359. $row = Database :: fetch_array($res);
  2360. return $row['lp_type'];
  2361. }
  2362. /**
  2363. * Gets a flat list of item IDs ordered for display (level by level ordered by order_display)
  2364. * This method can be used as abstract and is recursive
  2365. * @param integer Learnpath ID
  2366. * @param integer Parent ID of the items to look for
  2367. * @return mixed Ordered list of item IDs or false on error
  2368. */
  2369. public function get_flat_ordered_items_list($lp, $parent = 0) {
  2370. //if($this->debug>0){error_log('New LP - In learnpath::get_flat_ordered_items_list('.$lp.','.$parent.')',0);}
  2371. $list = array ();
  2372. if (empty ($lp)) {
  2373. return false;
  2374. }
  2375. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  2376. $sql = "SELECT * FROM $tbl_lp_item WHERE lp_id = $lp AND parent_item_id = $parent ORDER BY display_order";
  2377. $res = Database::query($sql);
  2378. while ($row = Database :: fetch_array($res)) {
  2379. $sublist = learnpath :: get_flat_ordered_items_list($lp, $row['id']);
  2380. $list[] = $row['id'];
  2381. foreach ($sublist as $item) {
  2382. $list[] = $item;
  2383. }
  2384. }
  2385. return $list;
  2386. }
  2387. /**
  2388. * Uses the table generated by get_toc() and returns an HTML-formatted string ready to display
  2389. * @return string HTML TOC ready to display
  2390. */
  2391. public function get_html_toc() {
  2392. $is_allowed_to_edit = api_is_allowed_to_edit(null,true);
  2393. $charset = api_get_setting('platform_charset');
  2394. $display_action_links_with_icons = false;
  2395. if ($this->debug > 0) {
  2396. error_log('New LP - In learnpath::get_html_toc()', 0);
  2397. }
  2398. $list = $this->get_toc();
  2399. //echo $this->current;
  2400. //$parent = $this->items[$this->current]->get_parent();
  2401. //if(empty($parent)){$parent = $this->ordered_items[$this->items[$this->current]->get_previous_index()];}
  2402. $html = '<div id="scorm_title" class="scorm_title"><div class="scorm_title_text">' . Security::remove_XSS(api_convert_encoding($this->get_name(), $this->encoding, $charset)) . '</div></div>';
  2403. // build, display
  2404. if ($is_allowed_to_edit) {
  2405. $gradebook = Security :: remove_XSS($_GET['gradebook']);
  2406. //var_dump($this->get_lp_session_id());
  2407. if ($this->get_lp_session_id()==api_get_session_id()) {
  2408. $html .= '<div id="actions_lp" class="actions_lp">';
  2409. if ($display_action_links_with_icons) {
  2410. $html .= '<div style = "text-align:center;">';
  2411. $html .= "<a href='lp_controller.php?" . api_get_cidreq() . "&amp;action=build&amp;lp_id=" . $this->lp_id . "' target='_parent'>" . Display :: return_icon('learnpath_build.gif', get_lang('Build')) . ' ' . get_lang('Build') . "</a>";
  2412. $html .= "<a href='lp_controller.php?" . api_get_cidreq() . "&amp;action=admin_view&amp;lp_id=" . $this->lp_id . "' target='_parent'>" . Display :: return_icon('learnpath_organize.gif', get_lang('BasicOverview')) . ' ' . get_lang('BasicOverview') . "</a>";
  2413. $html .= '<span>' . Display :: return_icon('learnpath_view_na.gif', get_lang("Display")) . ' <b>' . get_lang("Display") . '</b></span><br />';
  2414. $html .= '<a href="lp_controller.php?' . api_get_cidreq() . '">'. get_lang('ReturnToLPList') . '</a>';
  2415. $html .= '</div>';
  2416. } else {
  2417. $html .= '<div style = "text-align:center;">';
  2418. $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>";
  2419. $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>";
  2420. $html .= '<span><b>' . get_lang('Display') . '</b></span><br />';
  2421. $html .= '<a href="lp_controller.php?' . api_get_cidreq() . '">'. get_lang('ReturnToLPList') . '</a>';
  2422. $html .= '</div>';
  2423. }
  2424. $html .= '</div>';
  2425. }
  2426. }
  2427. $html .= '<div id="inner_lp_toc" class="inner_lp_toc">' . "\n";
  2428. require_once 'resourcelinker.inc.php';
  2429. //temp variables
  2430. $mycurrentitemid = $this->get_current_item_id();
  2431. $color_counter = 0;
  2432. $i = 0;
  2433. foreach ($list as $item) {
  2434. if ($this->debug > 2) {
  2435. error_log('New LP - learnpath::get_html_toc(): using item ' . $item['id'], 0);
  2436. }
  2437. //TODO complete this
  2438. $icon_name = array (
  2439. 'not attempted' => '../img/notattempted.gif',
  2440. 'incomplete' => '../img/incomplete.gif',
  2441. 'failed' => '../img/failed.gif',
  2442. 'completed' => '../img/completed.gif',
  2443. 'passed' => '../img/passed.gif',
  2444. 'succeeded' => '../img/succeeded.gif',
  2445. 'browsed' => '../img/completed.gif'
  2446. );
  2447. $style = 'scorm_item';
  2448. $scorm_color_background = 'scorm_item';
  2449. $style_item = 'scorm_item';
  2450. $current = false;
  2451. if ($item['id'] == $this->current) {
  2452. $style = 'scorm_item_highlight';
  2453. $scorm_color_background = 'scorm_item_highlight';
  2454. } else
  2455. if ($color_counter % 2 == 0) {
  2456. $scorm_color_background = 'scorm_item_1';
  2457. } else {
  2458. $scorm_color_background = 'scorm_item_2';
  2459. }
  2460. if ($scorm_color_background != '') {
  2461. $html .= '<div id="toc_' . $item['id'] . '" class="' . $scorm_color_background . '">';
  2462. }
  2463. //the anchor will let us center the TOC on the currently viewed item &^D
  2464. if ($item['type'] != 'dokeos_module' AND $item['type'] != 'dokeos_chapter') {
  2465. $html .= '<a name="atoc_' . $item['id'] . '" />';
  2466. $html .= '<div class="' . $style_item . '" style="padding-left: ' . ($item['level'] * 1.5) . 'em; padding-right:' . ($item['level'] / 2) . 'em" title="' . $item['description'] . '" >';
  2467. } else {
  2468. $html .= '<div class="' . $style_item . '" style="padding-left: ' . ($item['level'] * 2) . 'em; padding-right:' . ($item['level'] * 1.5) . 'em" title="' . $item['description'] . '" >';
  2469. }
  2470. $title = $item['title'];
  2471. if (empty ($title)) {
  2472. $title = rl_get_resource_name(api_get_course_id(), $this->get_id(), $item['id']);
  2473. }
  2474. //$title = api_htmlentities($title, ENT_QUOTES, $this->encoding);
  2475. $title = Security::remove_XSS($title);
  2476. if ($item['type'] != 'dokeos_chapter' and $item['type'] != 'dir' AND $item['type'] != 'dokeos_module') {
  2477. //$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>" ;
  2478. $url = $this->get_link('http', $item['id']);
  2479. //$html .= '<a href="'.$url.'" target="content_name" onclick="top.load_item('.$item['id'].',\''.$url.'\');">'.$title.'</a>' ;
  2480. //$html .= '<a href="" onclick="top.load_item('.$item['id'].',\''.$url.'\');return false;">'.$title.'</a>' ;
  2481. //<img align="absbottom" width="13" height="13" src="../img/lp_document.png">&nbsp;background:#aaa;
  2482. $html .= '<a href="" onclick="switch_item(' .
  2483. $mycurrentitemid . ',' .
  2484. $item['id'] . ');' .
  2485. 'return false;" >' . stripslashes($title) . '</a>';
  2486. } elseif ($item['type'] == 'dokeos_module' || $item['type'] == 'dokeos_chapter') {
  2487. $html .= "<img align='absbottom' width='13' height='13' src='../img/lp_dokeos_module.png'>&nbsp;" . stripslashes($title);
  2488. } elseif ($item['type'] == 'dir') {
  2489. $html .= stripslashes($title);
  2490. }
  2491. $tbl_track_e_exercises = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
  2492. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  2493. $user_id = api_get_user_id();
  2494. $course_id = api_get_course_id();
  2495. $sql = "SELECT path FROM $tbl_track_e_exercises, $tbl_lp_item
  2496. WHERE path = '" . $item['path'] . "' AND exe_user_id = '$user_id' AND exe_cours_id = '$course_id' AND path = exe_exo_id AND status <> 'incomplete'";
  2497. $result = Database::query($sql);
  2498. $count = Database :: num_rows($result);
  2499. if ($item['type'] == 'quiz') {
  2500. if ($item['status'] == 'completed') {
  2501. $html .= "&nbsp;<img id='toc_img_" . $item['id'] . "' src='" . $icon_name[$item['status']] . "' alt='" . substr($item['status'], 0, 1) . "' width='12' height='12' />";
  2502. }
  2503. } else {
  2504. if ($item['type'] != 'dokeos_chapter' && $item['type'] != 'dokeos_module' && $item['type'] != 'dir') {
  2505. $html .= "&nbsp;<img id='toc_img_" . $item['id'] . "' src='" . $icon_name[$item['status']] . "' alt='" . substr($item['status'], 0, 1) . "' width='12' height='12' />";
  2506. }
  2507. }
  2508. $html .= "</div>";
  2509. if ($scorm_color_background != '') {
  2510. $html .= '</div>';
  2511. }
  2512. $color_counter++;
  2513. }
  2514. $html .= "</div>\n";
  2515. return $html;
  2516. }
  2517. /**
  2518. * Gets the learnpath maker name - generally the editor's name
  2519. * @return string Learnpath maker name
  2520. */
  2521. public function get_maker() {
  2522. if ($this->debug > 0) {
  2523. error_log('New LP - In learnpath::get_maker()', 0);
  2524. }
  2525. if (!empty ($this->maker)) {
  2526. return $this->maker;
  2527. } else {
  2528. return '';
  2529. }
  2530. }
  2531. /**
  2532. * Gets the user-friendly message stored in $this->message
  2533. * @return string Message
  2534. */
  2535. public function get_message() {
  2536. if ($this->debug > 0) {
  2537. error_log('New LP - In learnpath::get_message()', 0);
  2538. }
  2539. return $this->message;
  2540. }
  2541. /**
  2542. * Gets the learnpath name/title
  2543. * @return string Learnpath name/title
  2544. */
  2545. public function get_name() {
  2546. if ($this->debug > 0) {
  2547. error_log('New LP - In learnpath::get_name()', 0);
  2548. }
  2549. if (!empty ($this->name)) {
  2550. return $this->name;
  2551. } else {
  2552. return 'N/A';
  2553. }
  2554. }
  2555. /**
  2556. * Gets a link to the resource from the present location, depending on item ID.
  2557. * @param string Type of link expected
  2558. * @param integer Learnpath item ID
  2559. * @return string Link to the lp_item resource
  2560. */
  2561. public function get_link($type = 'http', $item_id = null) {
  2562. if ($this->debug > 0) {
  2563. error_log('New LP - In learnpath::get_link(' . $type . ',' . $item_id . ')', 0);
  2564. }
  2565. if (empty($item_id)) {
  2566. if ($this->debug > 2) {
  2567. error_log('New LP - In learnpath::get_link() - no item id given in learnpath::get_link(), using current: ' . $this->get_current_item_id(), 0);
  2568. }
  2569. $item_id = $this->get_current_item_id();
  2570. }
  2571. if (empty ($item_id)) {
  2572. if ($this->debug > 2) {
  2573. error_log('New LP - In learnpath::get_link() - no current item id found in learnpath object', 0);
  2574. }
  2575. //still empty, this means there was no item_id given and we are not in an object context or
  2576. //the object property is empty, return empty link
  2577. $item_id = $this->first();
  2578. return '';
  2579. }
  2580. $file = '';
  2581. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  2582. $lp_item_table = Database :: get_course_table(TABLE_LP_ITEM);
  2583. $lp_item_view_table = Database :: get_course_table(TABLE_LP_ITEM_VIEW);
  2584. $item_id = Database::escape_string($item_id);
  2585. $sel = "SELECT l.lp_type as ltype, l.path as lpath, li.item_type as litype, li.path as lipath, li.parameters as liparams " .
  2586. "FROM $lp_table l, $lp_item_table li WHERE li.id = $item_id AND li.lp_id = l.id";
  2587. if ($this->debug > 2) {
  2588. error_log('New LP - In learnpath::get_link() - selecting item ' . $sel, 0);
  2589. }
  2590. $res = Database::query($sel);
  2591. if (Database :: num_rows($res) > 0) {
  2592. $row = Database :: fetch_array($res);
  2593. //var_dump($row);
  2594. $lp_type = $row['ltype'];
  2595. $lp_path = $row['lpath'];
  2596. $lp_item_type = $row['litype'];
  2597. $lp_item_path = $row['lipath'];
  2598. $lp_item_params = $row['liparams'];
  2599. if (empty ($lp_item_params) && strpos($lp_item_path, '?') !== false) {
  2600. list ($lp_item_path, $lp_item_params) = explode('?', $lp_item_path);
  2601. }
  2602. //$lp_item_params = '?'.$lp_item_params;
  2603. //add ? if none - left commented to give freedom to scorm implementation
  2604. //if(substr($lp_item_params,0,1)!='?'){
  2605. // $lp_item_params = '?'.$lp_item_params;
  2606. //}
  2607. $sys_course_path = api_get_path(SYS_COURSE_PATH) . api_get_course_path();
  2608. if ($type == 'http') {
  2609. $course_path = api_get_path(WEB_COURSE_PATH) . api_get_course_path(); //web path
  2610. } else {
  2611. $course_path = $sys_course_path; //system path
  2612. }
  2613. //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.
  2614. if (in_array($lp_item_type, array('quiz', 'document', 'link', 'forum', 'thread', 'student_publication'))) {
  2615. $lp_type = 1;
  2616. }
  2617. //Now go through the specific cases to get the end of the path
  2618. //@todo use constants instead of int values
  2619. switch ($lp_type) {
  2620. case 1 :
  2621. if ($lp_item_type == 'dokeos_chapter') {
  2622. $file = 'lp_content.php?type=dir';
  2623. } else {
  2624. require_once 'resourcelinker.inc.php';
  2625. $file = rl_get_resource_link_for_learnpath(api_get_course_id(), $this->get_id(), $item_id);
  2626. // check how much attempts of a exercise exits in lp
  2627. $lp_item_id = $this->get_current_item_id();
  2628. $lp_view_id = $this->get_view_id();
  2629. $prevent_reinit = $this->items[$this->current]->get_prevent_reinit();
  2630. $list = $this->get_toc();
  2631. $type_quiz = false;
  2632. foreach ($list as $toc) {
  2633. if ($toc['id'] == $lp_item_id && ($toc['type'] == 'quiz')) {
  2634. $type_quiz = true;
  2635. }
  2636. }
  2637. if ($type_quiz) {
  2638. $lp_item_id = Database :: escape_string($lp_item_id);
  2639. $lp_view_id = Database :: escape_string($lp_view_id);
  2640. $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'";
  2641. $result = Database::query($sql);
  2642. $row_count = Database :: fetch_row($result);
  2643. $count_item_view = (int) $row_count[0];
  2644. $not_multiple_attempt = 0;
  2645. if ($prevent_reinit === 1 && $count_item_view > 0) {
  2646. $not_multiple_attempt = 1;
  2647. }
  2648. $file .= '&not_multiple_attempt=' . $not_multiple_attempt;
  2649. }
  2650. $tmp_array = explode("/", $file);
  2651. $document_name = $tmp_array[count($tmp_array) - 1];
  2652. if (strpos($document_name, '_DELETED_')) {
  2653. $file = 'blank.php?error=document_deleted';
  2654. }
  2655. }
  2656. break;
  2657. case 2 :
  2658. if ($this->debug > 2) {
  2659. error_log('New LP - In learnpath::get_link() ' . __LINE__ . ' - Item type: ' . $lp_item_type, 0);
  2660. }
  2661. if ($lp_item_type != 'dir') {
  2662. //Quite complex here:
  2663. //we want to make sure 'http://' (and similar) links can
  2664. //be loaded as is (withouth the Dokeos path in front) but
  2665. //some contents use this form: resource.htm?resource=http://blablabla
  2666. //which means we have to find a protocol at the path's start, otherwise
  2667. //it should not be considered as an external URL
  2668. //if($this->prerequisites_match($item_id)){
  2669. if (preg_match('#^[a-zA-Z]{2,5}://#', $lp_item_path) != 0) {
  2670. if ($this->debug > 2) {
  2671. error_log('New LP - In learnpath::get_link() ' . __LINE__ . ' - Found match for protocol in ' . $lp_item_path, 0);
  2672. }
  2673. //distant url, return as is
  2674. $file = $lp_item_path;
  2675. } else {
  2676. if ($this->debug > 2) {
  2677. error_log('New LP - In learnpath::get_link() ' . __LINE__ . ' - No starting protocol in ' . $lp_item_path, 0);
  2678. }
  2679. //prevent getting untranslatable urls
  2680. $lp_item_path = preg_replace('/%2F/', '/', $lp_item_path);
  2681. $lp_item_path = preg_replace('/%3A/', ':', $lp_item_path);
  2682. //prepare the path
  2683. $file = $course_path . '/scorm/' . $lp_path . '/' . $lp_item_path;
  2684. //TODO fix this for urls with protocol header
  2685. $file = str_replace('//', '/', $file);
  2686. $file = str_replace(':/', '://', $file);
  2687. if (substr($lp_path, -1) == '/') {
  2688. $lp_path = substr($lp_path, 0, -1);
  2689. }
  2690. if (!is_file(realpath($sys_course_path . '/scorm/' . $lp_path . '/' . $lp_item_path))) {
  2691. //if file not found
  2692. $decoded = html_entity_decode($lp_item_path);
  2693. list ($decoded) = explode('?', $decoded);
  2694. if (!is_file(realpath($sys_course_path . '/scorm/' . $lp_path . '/' . $decoded))) {
  2695. require_once 'resourcelinker.inc.php';
  2696. $file = rl_get_resource_link_for_learnpath(api_get_course_id(), $this->get_id(), $item_id);
  2697. if (empty($file)) {
  2698. $file = 'blank.php?error=document_not_found';
  2699. } else {
  2700. $tmp_array = explode("/", $file);
  2701. $document_name = $tmp_array[count($tmp_array) - 1];
  2702. if (strpos($document_name, '_DELETED_')) {
  2703. $file = 'blank.php?error=document_deleted';
  2704. } else {
  2705. $file = 'blank.php?error=document_not_found';
  2706. }
  2707. }
  2708. } else {
  2709. $file = $course_path . '/scorm/' . $lp_path . '/' . $decoded;
  2710. }
  2711. }
  2712. }
  2713. //}else{
  2714. //prerequisites did not match
  2715. //$file = 'blank.php';
  2716. //}
  2717. //We want to use parameters if they were defined in the imsmanifest
  2718. if ($file != 'blank.php') {
  2719. $file .= (strstr($file, '?') === false ? '?' : '') . $lp_item_params;
  2720. }
  2721. } else {
  2722. $file = 'lp_content.php?type=dir';
  2723. }
  2724. break;
  2725. case 3 :
  2726. if ($this->debug > 2) {
  2727. error_log('New LP - In learnpath::get_link() ' . __LINE__ . ' - Item type: ' . $lp_item_type, 0);
  2728. }
  2729. //formatting AICC HACP append URL
  2730. $aicc_append = '?aicc_sid=' . urlencode(session_id()) . '&aicc_url=' . urlencode(api_get_path(WEB_CODE_PATH) . 'newscorm/aicc_hacp.php') . '&';
  2731. if ($lp_item_type != 'dir') {
  2732. //Quite complex here:
  2733. //we want to make sure 'http://' (and similar) links can
  2734. //be loaded as is (withouth the Dokeos path in front) but
  2735. //some contents use this form: resource.htm?resource=http://blablabla
  2736. //which means we have to find a protocol at the path's start, otherwise
  2737. //it should not be considered as an external URL
  2738. if (preg_match('#^[a-zA-Z]{2,5}://#', $lp_item_path) != 0) {
  2739. if ($this->debug > 2) {
  2740. error_log('New LP - In learnpath::get_link() ' . __LINE__ . ' - Found match for protocol in ' . $lp_item_path, 0);
  2741. }
  2742. //distant url, return as is
  2743. $file = $lp_item_path;
  2744. // Enabled and modified by Ivan Tcholakov, 16-OCT-2008.
  2745. /*
  2746. if(stristr($file,'<servername>')!==false){
  2747. $file = str_replace('<servername>',$course_path.'/scorm/'.$lp_path.'/',$lp_item_path);
  2748. }
  2749. */
  2750. if (stripos($file, '<servername>') !== false) {
  2751. //$file = str_replace('<servername>',$course_path.'/scorm/'.$lp_path.'/',$lp_item_path);
  2752. $web_course_path = str_replace('https://', '', str_replace('http://', '', $course_path));
  2753. $file = str_replace('<servername>', $web_course_path . '/scorm/' . $lp_path, $lp_item_path);
  2754. }
  2755. //
  2756. $file .= $aicc_append;
  2757. } else {
  2758. if ($this->debug > 2) {
  2759. error_log('New LP - In learnpath::get_link() ' . __LINE__ . ' - No starting protocol in ' . $lp_item_path, 0);
  2760. }
  2761. //prevent getting untranslatable urls
  2762. $lp_item_path = preg_replace('/%2F/', '/', $lp_item_path);
  2763. $lp_item_path = preg_replace('/%3A/', ':', $lp_item_path);
  2764. //prepare the path - lp_path might be unusable because it includes the "aicc" subdir name
  2765. $file = $course_path . '/scorm/' . $lp_path . '/' . $lp_item_path;
  2766. //TODO fix this for urls with protocol header
  2767. $file = str_replace('//', '/', $file);
  2768. $file = str_replace(':/', '://', $file);
  2769. $file .= $aicc_append;
  2770. }
  2771. } else {
  2772. $file = 'lp_content.php?type=dir';
  2773. }
  2774. break;
  2775. case 4 :
  2776. break;
  2777. default :
  2778. break;
  2779. }
  2780. }
  2781. if ($this->debug > 2) {
  2782. error_log('New LP - In learnpath::get_link() - returning "' . $file . '" from get_link', 0);
  2783. }
  2784. return $file;
  2785. }
  2786. /**
  2787. * Gets the latest usable view or generate a new one
  2788. * @param integer Optional attempt number. If none given, takes the highest from the lp_view table
  2789. * @return integer DB lp_view id
  2790. */
  2791. public function get_view($attempt_num = 0) {
  2792. if ($this->debug > 0) {
  2793. error_log('New LP - In learnpath::get_view()', 0);
  2794. }
  2795. $search = '';
  2796. //use $attempt_num to enable multi-views management (disabled so far)
  2797. if ($attempt_num != 0 AND intval(strval($attempt_num)) == $attempt_num) {
  2798. $search = 'AND view_count = ' . $attempt_num;
  2799. }
  2800. //when missing $attempt_num, search for a unique lp_view record for this lp and user
  2801. $lp_view_table = Database :: get_course_table(TABLE_LP_VIEW);
  2802. $sql = "SELECT id, view_count FROM $lp_view_table " .
  2803. "WHERE lp_id = " . $this->get_id() . " " .
  2804. "AND user_id = " . $this->get_user_id() . " " .
  2805. $search .
  2806. " ORDER BY view_count DESC";
  2807. $res = Database::query($sql);
  2808. if (Database :: num_rows($res) > 0) {
  2809. $row = Database :: fetch_array($res);
  2810. $this->lp_view_id = $row['id'];
  2811. } else {
  2812. //no database record, create one
  2813. $sql = "INSERT INTO $lp_view_table(lp_id,user_id,view_count)" .
  2814. "VALUES (" . $this->get_id() . "," . $this->get_user_id() . ",1)";
  2815. $res = Database::query($sql);
  2816. $id = Database :: insert_id();
  2817. $this->lp_view_id = $id;
  2818. }
  2819. return $this->lp_view_id;
  2820. }
  2821. /**
  2822. * Gets the current view id
  2823. * @return integer View ID (from lp_view)
  2824. */
  2825. public function get_view_id() {
  2826. if ($this->debug > 0) {
  2827. error_log('New LP - In learnpath::get_view_id()', 0);
  2828. }
  2829. if (!empty ($this->lp_view_id)) {
  2830. return $this->lp_view_id;
  2831. } else {
  2832. return 0;
  2833. }
  2834. }
  2835. /**
  2836. * Gets the update queue
  2837. * @return array Array containing IDs of items to be updated by JavaScript
  2838. */
  2839. public function get_update_queue() {
  2840. if ($this->debug > 0) {
  2841. error_log('New LP - In learnpath::get_update_queue()', 0);
  2842. }
  2843. return $this->update_queue;
  2844. }
  2845. /**
  2846. * Gets the user ID
  2847. * @return integer User ID
  2848. */
  2849. public function get_user_id() {
  2850. if ($this->debug > 0) {
  2851. error_log('New LP - In learnpath::get_user_id()', 0);
  2852. }
  2853. if (!empty ($this->user_id)) {
  2854. return $this->user_id;
  2855. } else {
  2856. return false;
  2857. }
  2858. }
  2859. /**
  2860. * Checks if any of the items has an audio element attached
  2861. * @return bool True or false
  2862. */
  2863. public function has_audio() {
  2864. if ($this->debug > 1) {
  2865. error_log('New LP - In learnpath::has_audio()', 0);
  2866. }
  2867. $has = false;
  2868. foreach ($this->items as $i => $item) {
  2869. if (!empty ($this->items[$i]->audio)) {
  2870. $has = true;
  2871. break;
  2872. }
  2873. }
  2874. return $has;
  2875. }
  2876. /**
  2877. * Logs a message into a file
  2878. * @param string Message to log
  2879. * @return boolean True on success, false on error or if msg empty
  2880. */
  2881. public function log($msg) {
  2882. if ($this->debug > 0) {
  2883. error_log('New LP - In learnpath::log()', 0);
  2884. }
  2885. //TODO
  2886. $this->error .= $msg . "\n";
  2887. return true;
  2888. }
  2889. /**
  2890. * Moves an item up and down at its level
  2891. * @param integer Item to move up and down
  2892. * @param string Direction 'up' or 'down'
  2893. * @return integer New display order, or false on error
  2894. */
  2895. public function move_item($id, $direction) {
  2896. if ($this->debug > 0) {
  2897. error_log('New LP - In learnpath::move_item(' . $id . ',' . $direction . ')', 0);
  2898. }
  2899. if (empty ($id) or empty ($direction)) {
  2900. return false;
  2901. }
  2902. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  2903. $sql_sel = "
  2904. SELECT *
  2905. FROM " . $tbl_lp_item . "
  2906. WHERE id = " . $id;
  2907. $res_sel = Database::query($sql_sel);
  2908. //check if elem exists
  2909. if (Database :: num_rows($res_sel) < 1) {
  2910. return false;
  2911. }
  2912. //gather data
  2913. $row = Database :: fetch_array($res_sel);
  2914. $previous = $row['previous_item_id'];
  2915. $next = $row['next_item_id'];
  2916. $display = $row['display_order'];
  2917. $parent = $row['parent_item_id'];
  2918. $lp = $row['lp_id'];
  2919. //update the item (switch with previous/next one)
  2920. switch ($direction) {
  2921. case 'up' :
  2922. if ($this->debug > 2) {
  2923. error_log('Movement up detected', 0);
  2924. }
  2925. if ($display <= 1) { /*do nothing*/
  2926. } else {
  2927. $sql_sel2 = "SELECT *
  2928. FROM $tbl_lp_item
  2929. WHERE id = $previous";
  2930. if ($this->debug > 2) {
  2931. error_log('Selecting previous: ' . $sql_sel2, 0);
  2932. }
  2933. $res_sel2 = Database::query($sql_sel2);
  2934. if (Database :: num_rows($res_sel2) < 1) {
  2935. $previous_previous = 0;
  2936. }
  2937. //gather data
  2938. $row2 = Database :: fetch_array($res_sel2);
  2939. $previous_previous = $row2['previous_item_id'];
  2940. //update previous_previous item (switch "next" with current)
  2941. if ($previous_previous != 0) {
  2942. $sql_upd2 = "UPDATE $tbl_lp_item SET next_item_id = $id WHERE id = $previous_previous";
  2943. if ($this->debug > 2) {
  2944. error_log($sql_upd2, 0);
  2945. }
  2946. $res_upd2 = Database::query($sql_upd2);
  2947. }
  2948. //update previous item (switch with current)
  2949. if ($previous != 0) {
  2950. $sql_upd2 = "UPDATE $tbl_lp_item SET next_item_id = $next, previous_item_id = $id, display_order = display_order +1 WHERE id = $previous";
  2951. if ($this->debug > 2) {
  2952. error_log($sql_upd2, 0);
  2953. }
  2954. $res_upd2 = Database::query($sql_upd2);
  2955. }
  2956. //update current item (switch with previous)
  2957. if ($id != 0) {
  2958. $sql_upd2 = "UPDATE $tbl_lp_item SET next_item_id = $previous, previous_item_id = $previous_previous, display_order = display_order-1 WHERE id = $id";
  2959. if ($this->debug > 2) {
  2960. error_log($sql_upd2, 0);
  2961. }
  2962. $res_upd2 = Database::query($sql_upd2);
  2963. }
  2964. //update next item (new previous item)
  2965. if ($next != 0) {
  2966. $sql_upd2 = "UPDATE $tbl_lp_item SET previous_item_id = $previous WHERE id = $next";
  2967. if ($this->debug > 2) {
  2968. error_log($sql_upd2, 0);
  2969. }
  2970. $res_upd2 = Database::query($sql_upd2);
  2971. }
  2972. $display = $display -1;
  2973. }
  2974. break;
  2975. case 'down' :
  2976. if ($this->debug > 2) {
  2977. error_log('Movement down detected', 0);
  2978. }
  2979. if ($next == 0) { /*do nothing*/
  2980. } else {
  2981. $sql_sel2 = "SELECT * FROM $tbl_lp_item WHERE id = $next";
  2982. if ($this->debug > 2) {
  2983. error_log('Selecting next: ' . $sql_sel2, 0);
  2984. }
  2985. $res_sel2 = Database::query($sql_sel2);
  2986. if (Database :: num_rows($res_sel2) < 1) {
  2987. $next_next = 0;
  2988. }
  2989. //gather data
  2990. $row2 = Database :: fetch_array($res_sel2);
  2991. $next_next = $row2['next_item_id'];
  2992. //update previous item (switch with current)
  2993. if ($previous != 0) {
  2994. $sql_upd2 = "UPDATE $tbl_lp_item SET next_item_id = $next WHERE id = $previous";
  2995. $res_upd2 = Database::query($sql_upd2);
  2996. }
  2997. //update current item (switch with previous)
  2998. if ($id != 0) {
  2999. $sql_upd2 = "UPDATE $tbl_lp_item SET previous_item_id = $next, next_item_id = $next_next, display_order = display_order+1 WHERE id = $id";
  3000. $res_upd2 = Database::query($sql_upd2);
  3001. }
  3002. //update next item (new previous item)
  3003. if ($next != 0) {
  3004. $sql_upd2 = "UPDATE $tbl_lp_item SET previous_item_id = $previous, next_item_id = $id, display_order = display_order-1 WHERE id = $next";
  3005. $res_upd2 = Database::query($sql_upd2);
  3006. }
  3007. //update next_next item (switch "previous" with current)
  3008. if ($next_next != 0) {
  3009. $sql_upd2 = "UPDATE $tbl_lp_item SET previous_item_id = $id WHERE id = $next_next";
  3010. $res_upd2 = Database::query($sql_upd2);
  3011. }
  3012. $display = $display +1;
  3013. }
  3014. break;
  3015. default :
  3016. return false;
  3017. }
  3018. return $display;
  3019. }
  3020. /**
  3021. * Move a learnpath up (display_order)
  3022. * @param integer Learnpath ID
  3023. */
  3024. public function move_up($lp_id) {
  3025. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3026. $sql = "SELECT * FROM $lp_table ORDER BY display_order";
  3027. $res = Database::query($sql);
  3028. if ($res === false)
  3029. return false;
  3030. $lps = array ();
  3031. $lp_order = array ();
  3032. $num = Database :: num_rows($res);
  3033. //first check the order is correct, globally (might be wrong because
  3034. //of versions < 1.8.4)
  3035. if ($num > 0) {
  3036. $i = 1;
  3037. while ($row = Database :: fetch_array($res)) {
  3038. if ($row['display_order'] != $i) { //if we find a gap in the order, we need to fix it
  3039. $need_fix = true;
  3040. $sql_u = "UPDATE $lp_table SET display_order = $i WHERE id = " . $row['id'];
  3041. $res_u = Database::query($sql_u);
  3042. }
  3043. $row['display_order'] = $i;
  3044. $lps[$row['id']] = $row;
  3045. $lp_order[$i] = $row['id'];
  3046. $i++;
  3047. }
  3048. }
  3049. if ($num > 1) //if there's only one element, no need to sort
  3050. {
  3051. $order = $lps[$lp_id]['display_order'];
  3052. if ($order > 1) //if it's the first element, no need to move up
  3053. {
  3054. $sql_u1 = "UPDATE $lp_table SET display_order = $order WHERE id = " . $lp_order[$order -1];
  3055. $res_u1 = Database::query($sql_u1);
  3056. $sql_u2 = "UPDATE $lp_table SET display_order = " . ($order -1) . " WHERE id = " . $lp_id;
  3057. $res_u2 = Database::query($sql_u2);
  3058. }
  3059. }
  3060. }
  3061. /**
  3062. * Move a learnpath down (display_order)
  3063. * @param integer Learnpath ID
  3064. */
  3065. public function move_down($lp_id) {
  3066. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3067. $sql = "SELECT * FROM $lp_table ORDER BY display_order";
  3068. $res = Database::query($sql);
  3069. if ($res === false)
  3070. return false;
  3071. $lps = array ();
  3072. $lp_order = array ();
  3073. $num = Database :: num_rows($res);
  3074. $max = 0;
  3075. //first check the order is correct, globally (might be wrong because
  3076. //of versions < 1.8.4)
  3077. if ($num > 0) {
  3078. $i = 1;
  3079. while ($row = Database :: fetch_array($res)) {
  3080. $max = $i;
  3081. if ($row['display_order'] != $i) { //if we find a gap in the order, we need to fix it
  3082. $need_fix = true;
  3083. $sql_u = "UPDATE $lp_table SET display_order = $i WHERE id = " . $row['id'];
  3084. $res_u = Database::query($sql_u);
  3085. }
  3086. $row['display_order'] = $i;
  3087. $lps[$row['id']] = $row;
  3088. $lp_order[$i] = $row['id'];
  3089. $i++;
  3090. }
  3091. }
  3092. if ($num > 1) //if there's only one element, no need to sort
  3093. {
  3094. $order = $lps[$lp_id]['display_order'];
  3095. if ($order < $max) //if it's the first element, no need to move up
  3096. {
  3097. $sql_u1 = "UPDATE $lp_table SET display_order = $order WHERE id = " . $lp_order[$order +1];
  3098. $res_u1 = Database::query($sql_u1);
  3099. $sql_u2 = "UPDATE $lp_table SET display_order = " . ($order +1) . " WHERE id = " . $lp_id;
  3100. $res_u2 = Database::query($sql_u2);
  3101. }
  3102. }
  3103. }
  3104. /**
  3105. * Updates learnpath attributes to point to the next element
  3106. * The last part is similar to set_current_item but processing the other way around
  3107. */
  3108. public function next() {
  3109. if ($this->debug > 0) {
  3110. error_log('New LP - In learnpath::next()', 0);
  3111. }
  3112. $this->last = $this->get_current_item_id();
  3113. $this->items[$this->last]->save(false, $this->prerequisites_match($this->last));
  3114. $this->autocomplete_parents($this->last);
  3115. $new_index = $this->get_next_index();
  3116. if ($this->debug > 2) {
  3117. error_log('New LP - New index: ' . $new_index, 0);
  3118. }
  3119. $this->index = $new_index;
  3120. if ($this->debug > 2) {
  3121. error_log('New LP - Now having orderedlist[' . $new_index . '] = ' . $this->ordered_items[$new_index], 0);
  3122. }
  3123. $this->current = $this->ordered_items[$new_index];
  3124. if ($this->debug > 2) {
  3125. error_log('New LP - new item id is ' . $this->current . '-' . $this->get_current_item_id(), 0);
  3126. }
  3127. }
  3128. /**
  3129. * Open a resource = initialise all local variables relative to this resource. Depending on the child
  3130. * class, this might be redefined to allow several behaviours depending on the document type.
  3131. * @param integer Resource ID
  3132. * @return boolean True on success, false otherwise
  3133. */
  3134. public function open($id) {
  3135. if ($this->debug > 0) {
  3136. error_log('New LP - In learnpath::open()', 0);
  3137. }
  3138. //TODO
  3139. //set the current resource attribute to this resource
  3140. //switch on element type (redefine in child class?)
  3141. //set status for this item to "opened"
  3142. //start timer
  3143. //initialise score
  3144. $this->index = 0; //or = the last item seen (see $this->last)
  3145. }
  3146. /**
  3147. * Check that all prerequisites are fulfilled. Returns true and an empty string on succes, returns false
  3148. * and the prerequisite string on error.
  3149. * This function is based on the rules for aicc_script language as described in the SCORM 1.2 CAM documentation page 108.
  3150. * @param integer Optional item ID. If none given, uses the current open item.
  3151. * @return boolean True if prerequisites are matched, false otherwise
  3152. * @return string Empty string if true returned, prerequisites string otherwise.
  3153. */
  3154. public function prerequisites_match($item = null) {
  3155. if ($this->debug > 0) {
  3156. error_log('New LP - In learnpath::prerequisites_match()', 0);
  3157. }
  3158. if (empty ($item)) {
  3159. $item = $this->current;
  3160. }
  3161. if (is_object($this->items[$item])) {
  3162. $prereq_string = $this->items[$item]->get_prereq_string();
  3163. if (empty ($prereq_string)) {
  3164. return true;
  3165. }
  3166. //clean spaces
  3167. $prereq_string = str_replace(' ', '', $prereq_string);
  3168. if ($this->debug > 0) {
  3169. error_log('Found prereq_string: ' . $prereq_string, 0);
  3170. }
  3171. //now send to the parse_prereq() function that will check this component's prerequisites
  3172. $result = $this->items[$item]->parse_prereq($prereq_string, $this->items, $this->refs_list, $this->get_user_id());
  3173. if ($result === false) {
  3174. $this->set_error_msg($this->items[$item]->prereq_alert);
  3175. }
  3176. } else {
  3177. $result = true;
  3178. if ($this->debug > 1) {
  3179. error_log('New LP - $this->items[' . $item . '] was not an object', 0);
  3180. }
  3181. }
  3182. if ($this->debug > 1) {
  3183. error_log('New LP - End of prerequisites_match(). Error message is now ' . $this->error, 0);
  3184. }
  3185. return $result;
  3186. }
  3187. /**
  3188. * Updates learnpath attributes to point to the previous element
  3189. * The last part is similar to set_current_item but processing the other way around
  3190. */
  3191. public function previous() {
  3192. if ($this->debug > 0) {
  3193. error_log('New LP - In learnpath::previous()', 0);
  3194. }
  3195. $this->last = $this->get_current_item_id();
  3196. $this->items[$this->last]->save(false, $this->prerequisites_match($this->last));
  3197. $this->autocomplete_parents($this->last);
  3198. $new_index = $this->get_previous_index();
  3199. $this->index = $new_index;
  3200. $this->current = $this->ordered_items[$new_index];
  3201. }
  3202. /**
  3203. * Publishes a learnpath. This basically means show or hide the learnpath
  3204. * to normal users.
  3205. * Can be used as abstract
  3206. * @param integer Learnpath ID
  3207. * @param string New visibility
  3208. */
  3209. public function toggle_visibility($lp_id, $set_visibility = 1) {
  3210. //if($this->debug>0){error_log('New LP - In learnpath::toggle_visibility()',0);}
  3211. $action = 'visible';
  3212. if ($set_visibility != 1) {
  3213. $action = 'invisible';
  3214. }
  3215. return api_item_property_update(api_get_course_info(), TOOL_LEARNPATH, $lp_id, $action, api_get_user_id());
  3216. }
  3217. /**
  3218. * Publishes a learnpath. This basically means show or hide the learnpath
  3219. * on the course homepage
  3220. * Can be used as abstract
  3221. * @param integer Learnpath ID
  3222. * @param string New visibility
  3223. */
  3224. public function toggle_publish($lp_id, $set_visibility = 'v') {
  3225. //if($this->debug>0){error_log('New LP - In learnpath::toggle_publish()',0);}
  3226. $tbl_lp = Database :: get_course_table(TABLE_LP_MAIN);
  3227. $sql = "SELECT * FROM $tbl_lp where id=$lp_id";
  3228. $result = Database::query($sql);
  3229. $row = Database :: fetch_array($result);
  3230. $name = domesticate($row['name']);
  3231. if ($set_visibility == 'i') {
  3232. $s = $name . " " . get_lang('_no_published');
  3233. $dialogBox = $s;
  3234. $v = 0;
  3235. }
  3236. if ($set_visibility == 'v') {
  3237. $s = $name . " " . get_lang('_published');
  3238. $dialogBox = $s;
  3239. $v = 1;
  3240. }
  3241. $session_id = api_get_session_id();
  3242. $session_condition = api_get_session_condition($session_id);
  3243. $tbl_tool = Database :: get_course_table(TABLE_TOOL_LIST);
  3244. $link = 'newscorm/lp_controller.php?action=view&lp_id=' . $lp_id;
  3245. $sql = "SELECT * FROM $tbl_tool where name='$name' and image='scormbuilder.gif' and link LIKE '$link%' $session_condition";
  3246. $result = Database::query($sql);
  3247. $num = Database :: num_rows($result);
  3248. $row2 = Database :: fetch_array($result);
  3249. //if($this->debug>2){error_log('New LP - '.$sql.' - '.$num,0);}
  3250. if (($set_visibility == 'i') && ($num > 0)) {
  3251. $sql = "DELETE FROM $tbl_tool WHERE (name='$name' and image='scormbuilder.gif' and link LIKE '$link%' $session_condition)";
  3252. }
  3253. elseif (($set_visibility == 'v') && ($num == 0)) {
  3254. $sql = "INSERT INTO $tbl_tool (name, link, image, visibility, admin, address, added_tool, session_id) VALUES ('$name','newscorm/lp_controller.php?action=view&lp_id=$lp_id','scormbuilder.gif','$v','0','pastillegris.gif',0, $session_id)";
  3255. } else {
  3256. //parameter and database incompatible, do nothing
  3257. }
  3258. $result = Database::query($sql);
  3259. //if($this->debug>2){error_log('New LP - Leaving learnpath::toggle_visibility: '.$sql,0);}
  3260. }
  3261. /**
  3262. * Restart the whole learnpath. Return the URL of the first element.
  3263. * Make sure the results are saved with anoter method. This method should probably be
  3264. * redefined in children classes.
  3265. * To use a similar method statically, use the create_new_attempt() method
  3266. * @return string URL to load in the viewer
  3267. */
  3268. public function restart() {
  3269. if ($this->debug > 0) {
  3270. error_log('New LP - In learnpath::restart()', 0);
  3271. }
  3272. //TODO
  3273. //call autosave method to save the current progress
  3274. //$this->index = 0;
  3275. $session_id = api_get_session_id();
  3276. $lp_view_table = Database :: get_course_table(TABLE_LP_VIEW);
  3277. $sql = "INSERT INTO $lp_view_table (lp_id, user_id, view_count, session_id) " .
  3278. "VALUES (" . $this->lp_id . "," . $this->get_user_id() . "," . ($this->attempt + 1) . ", $session_id)";
  3279. if ($this->debug > 2) {
  3280. error_log('New LP - Inserting new lp_view for restart: ' . $sql, 0);
  3281. }
  3282. $res = Database::query($sql);
  3283. if ($view_id = Database :: insert_id($res)) {
  3284. $this->lp_view_id = $view_id;
  3285. $this->attempt = $this->attempt + 1;
  3286. } else {
  3287. $this->error = 'Could not insert into item_view table...';
  3288. return false;
  3289. }
  3290. $this->autocomplete_parents($this->current);
  3291. foreach ($this->items as $index => $dummy) {
  3292. $this->items[$index]->restart();
  3293. $this->items[$index]->set_lp_view($this->lp_view_id);
  3294. }
  3295. $this->first();
  3296. return true;
  3297. }
  3298. /**
  3299. * Saves the current item
  3300. * @return boolean
  3301. */
  3302. public function save_current() {
  3303. if ($this->debug > 0) {
  3304. error_log('New LP - In learnpath::save_current()', 0);
  3305. }
  3306. //TODO do a better check on the index pointing to the right item (it is supposed to be working
  3307. // on $ordered_items[] but not sure it's always safe to use with $items[])
  3308. if ($this->debug > 2) {
  3309. error_log('New LP - save_current() saving item ' . $this->current, 0);
  3310. }
  3311. if ($this->debug > 2) {
  3312. error_log('' . print_r($this->items, true), 0);
  3313. }
  3314. if (is_object($this->items[$this->current])) {
  3315. //$res = $this->items[$this->current]->save(false);
  3316. $res = $this->items[$this->current]->save(false, $this->prerequisites_match($this->current));
  3317. $this->autocomplete_parents($this->current);
  3318. $status = $this->items[$this->current]->get_status();
  3319. $this->append_message('new_item_status: ' . $status);
  3320. $this->update_queue[$this->current] = $status;
  3321. return $res;
  3322. }
  3323. return false;
  3324. }
  3325. /**
  3326. * Saves the given item
  3327. * @param integer Item ID. Optional (will take from $_REQUEST if null)
  3328. * @param boolean Save from url params (true) or from current attributes (false). Optional. Defaults to true
  3329. * @return boolean
  3330. */
  3331. public function save_item($item_id = null, $from_outside = true) {
  3332. if ($this->debug > 0) {
  3333. error_log('New LP - In learnpath::save_item(' . $item_id . ',' . $from_outside . ')', 0);
  3334. }
  3335. //TODO do a better check on the index pointing to the right item (it is supposed to be working
  3336. // on $ordered_items[] but not sure it's always safe to use with $items[])
  3337. if (empty ($item_id)) {
  3338. $item_id = $this->escape_string($_REQUEST['id']);
  3339. }
  3340. if (empty ($item_id)) {
  3341. $item_id = $this->get_current_item_id();
  3342. }
  3343. if ($this->debug > 2) {
  3344. error_log('New LP - save_current() saving item ' . $item_id, 0);
  3345. }
  3346. if (is_object($this->items[$item_id])) {
  3347. $res = $this->items[$item_id]->save($from_outside, $this->prerequisites_match($item_id));
  3348. //$res = $this->items[$item_id]->save($from_outside);
  3349. $this->autocomplete_parents($item_id);
  3350. $status = $this->items[$item_id]->get_status();
  3351. $this->append_message('new_item_status: ' . $status);
  3352. $this->update_queue[$item_id] = $status;
  3353. return $res;
  3354. }
  3355. return false;
  3356. }
  3357. /**
  3358. * Saves the last item seen's ID only in case
  3359. */
  3360. public function save_last()
  3361. {
  3362. if ($this->debug > 0) {
  3363. error_log('New LP - In learnpath::save_last()', 0);
  3364. }
  3365. $session_condition = api_get_session_condition(api_get_session_id(),true,false);
  3366. $table = Database :: get_course_table(TABLE_LP_VIEW);
  3367. if (isset ($this->current)) {
  3368. if ($this->debug > 2) {
  3369. error_log('New LP - Saving current item (' . $this->current . ') for later review', 0);
  3370. }
  3371. $sql = "UPDATE $table SET last_item = " . Database::escape_string($this->get_current_item_id()). " " .
  3372. "WHERE lp_id = " . $this->get_id() . " AND user_id = " . $this->get_user_id().' '.$session_condition;
  3373. if ($this->debug > 2) {
  3374. error_log('New LP - Saving last item seen : ' . $sql, 0);
  3375. }
  3376. $res = Database::query($sql);
  3377. }
  3378. //save progress
  3379. list ($progress, $text) = $this->get_progress_bar_text('%');
  3380. if ($progress >= 0 AND $progress <= 100) {
  3381. $progress = (int) $progress;
  3382. $sql = "UPDATE $table SET progress = $progress " .
  3383. "WHERE lp_id = " . $this->get_id() . " AND " .
  3384. "user_id = " . $this->get_user_id().' '.$session_condition;
  3385. $res = Database::query($sql); //ignore errors as some tables might not have the progress field just yet
  3386. $this->progress_db = $progress;
  3387. }
  3388. }
  3389. /**
  3390. * Sets the current item ID (checks if valid and authorized first)
  3391. * @param integer New item ID. If not given or not authorized, defaults to current
  3392. */
  3393. public function set_current_item($item_id = null) {
  3394. if ($this->debug > 0) {
  3395. error_log('New LP - In learnpath::set_current_item(' . $item_id . ')', 0);
  3396. }
  3397. if (empty ($item_id)) {
  3398. if ($this->debug > 2) {
  3399. error_log('New LP - No new current item given, ignore...', 0);
  3400. }
  3401. //do nothing
  3402. } else {
  3403. if ($this->debug > 2) {
  3404. error_log('New LP - New current item given is ' . $item_id . '...', 0);
  3405. }
  3406. if (is_numeric($item_id)) {
  3407. $item_id = $this->escape_string($item_id);
  3408. //TODO check in database here
  3409. $this->last = $this->current;
  3410. $this->current = $item_id;
  3411. //TODO update $this->index as well
  3412. foreach ($this->ordered_items as $index => $item) {
  3413. if ($item == $this->current) {
  3414. $this->index = $index;
  3415. break;
  3416. }
  3417. }
  3418. if ($this->debug > 2) {
  3419. error_log('New LP - set_current_item(' . $item_id . ') done. Index is now : ' . $this->index, 0);
  3420. }
  3421. } else {
  3422. error_log('New LP - set_current_item(' . $item_id . ') failed. Not a numeric value: ', 0);
  3423. }
  3424. }
  3425. }
  3426. /**
  3427. * Sets the encoding
  3428. * @param string New encoding
  3429. */
  3430. public function set_encoding($enc = 'ISO-8859-15') {
  3431. if ($this->debug > 0) {
  3432. error_log('New LP - In learnpath::set_encoding()', 0);
  3433. }
  3434. $enc = strtoupper($enc);
  3435. $encodings = array (
  3436. 'UTF-8',
  3437. 'ISO-8859-1',
  3438. 'ISO-8859-15',
  3439. 'cp1251',
  3440. 'cp1252',
  3441. 'KOI8-R',
  3442. 'BIG5',
  3443. 'GB2312',
  3444. 'Shift_JIS',
  3445. 'EUC-JP',
  3446. ''
  3447. );
  3448. if (in_array($enc, $encodings)) {
  3449. $lp = $this->get_id();
  3450. if ($lp != 0) {
  3451. $tbl_lp = Database :: get_course_table(TABLE_LP_MAIN);
  3452. $sql = "UPDATE $tbl_lp SET default_encoding = '$enc' WHERE id = " . $lp;
  3453. $res = Database::query($sql);
  3454. return $res;
  3455. }
  3456. }
  3457. return false;
  3458. }
  3459. /**
  3460. * Sets the JS lib setting in the database directly.
  3461. * This is the JavaScript library file this lp needs to load on startup
  3462. * @param string Proximity setting
  3463. * @return boolean True on update success. False otherwise.
  3464. */
  3465. public function set_jslib($lib = '') {
  3466. if ($this->debug > 0) {
  3467. error_log('New LP - In learnpath::set_jslib()', 0);
  3468. }
  3469. $lp = $this->get_id();
  3470. if ($lp != 0) {
  3471. $tbl_lp = Database :: get_course_table(TABLE_LP_MAIN);
  3472. $sql = "UPDATE $tbl_lp SET js_lib = '$lib' WHERE id = " . $lp;
  3473. $res = Database::query($sql);
  3474. return $res;
  3475. } else {
  3476. return false;
  3477. }
  3478. }
  3479. /**
  3480. * Sets the name of the LP maker (publisher) (and save)
  3481. * @param string Optional string giving the new content_maker of this learnpath
  3482. * @return boolean True
  3483. */
  3484. public function set_maker($name = '') {
  3485. if ($this->debug > 0) {
  3486. error_log('New LP - In learnpath::set_maker()', 0);
  3487. }
  3488. if (empty ($name))
  3489. return false;
  3490. $this->maker = $this->escape_string($name);
  3491. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3492. $lp_id = $this->get_id();
  3493. $sql = "UPDATE $lp_table SET content_maker = '" . $this->maker . "' WHERE id = '$lp_id'";
  3494. if ($this->debug > 2) {
  3495. error_log('New LP - lp updated with new content_maker : ' . $this->maker, 0);
  3496. }
  3497. $res = Database::query($sql);
  3498. return true;
  3499. }
  3500. /**
  3501. * Sets the name of the current learnpath (and save)
  3502. * @param string Optional string giving the new name of this learnpath
  3503. * @return boolean True/False
  3504. */
  3505. public function set_name($name = '') {
  3506. if ($this->debug > 0) {
  3507. error_log('New LP - In learnpath::set_name()', 0);
  3508. }
  3509. if (empty ($name))
  3510. return false;
  3511. $this->name = $this->escape_string($name);
  3512. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3513. $lp_id = $this->get_id();
  3514. $sql = "UPDATE $lp_table SET name = '" . $this->name . "' WHERE id = '$lp_id'";
  3515. if ($this->debug > 2) {
  3516. error_log('New LP - lp updated with new name : ' . $this->name, 0);
  3517. }
  3518. $res = Database::query($sql);
  3519. // if the lp is visible on the homepage, change his name there
  3520. if (Database::affected_rows()) {
  3521. $table = Database :: get_course_table(TABLE_TOOL_LIST);
  3522. $sql = 'UPDATE ' . $table . ' SET
  3523. name = "' . $this->name . '"
  3524. WHERE link = "newscorm/lp_controller.php?action=view&lp_id=' . $lp_id . '"';
  3525. Database::query($sql);
  3526. }
  3527. return true;
  3528. }
  3529. /**
  3530. * Set index specified prefix terms for all items in this path
  3531. * @param string Comma-separated list of terms
  3532. * @param char Xapian term prefix
  3533. * @return boolean False on error, true otherwise
  3534. */
  3535. public function set_terms_by_prefix($terms_string, $prefix) {
  3536. if (api_get_setting('search_enabled') !== 'true')
  3537. return FALSE;
  3538. $terms_string = trim($terms_string);
  3539. $terms = explode(',', $terms_string);
  3540. array_walk($terms, 'trim_value');
  3541. $stored_terms = $this->get_common_index_terms_by_prefix($prefix);
  3542. //var_dump($stored_terms);
  3543. //var_dump($terms);
  3544. // don't do anything if no change, verify only at DB, not the search engine
  3545. if ((count(array_diff($terms, $stored_terms)) == 0) && (count(array_diff($stored_terms, $terms)) == 0))
  3546. return FALSE;
  3547. require_once 'xapian.php'; //TODO try catch every xapian use or make wrappers on api
  3548. require_once api_get_path(LIBRARY_PATH).'search/DokeosIndexer.class.php';
  3549. require_once api_get_path(LIBRARY_PATH).'search/xapian/XapianQuery.php';
  3550. require_once api_get_path(LIBRARY_PATH).'search/IndexableChunk.class.php';
  3551. $items_table = Database :: get_course_table(TABLE_LP_ITEM);
  3552. //TODO: make query secure agains XSS : use member attr instead of post var
  3553. $lp_id = intval($_POST['lp_id']);
  3554. $sql = "SELECT * FROM $items_table WHERE lp_id = $lp_id";
  3555. $result = Database::query($sql);
  3556. $di = new DokeosIndexer();
  3557. while ($lp_item = Database :: fetch_array($result)) {
  3558. // get search_did
  3559. $tbl_se_ref = Database :: get_main_table(TABLE_MAIN_SEARCH_ENGINE_REF);
  3560. $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';
  3561. $sql = sprintf($sql, $tbl_se_ref, $this->cc, TOOL_LEARNPATH, $lp_id, $lp_item['id']);
  3562. $res = Database::query($sql);
  3563. if (Database::num_rows($res)>0) {
  3564. $se_ref = Database :: fetch_array($res);
  3565. // compare terms
  3566. $doc = $di->get_document($se_ref['search_did']);
  3567. $xapian_terms = xapian_get_doc_terms($doc, $prefix);
  3568. //var_dump($xapian_terms);
  3569. $xterms = array ();
  3570. foreach ($xapian_terms as $xapian_term) {
  3571. $xterms[] = substr($xapian_term['name'], 1);
  3572. }
  3573. $dterms = $terms;
  3574. $missing_terms = array_diff($dterms, $xterms);
  3575. $deprecated_terms = array_diff($xterms, $dterms);
  3576. // save it to search engine
  3577. foreach ($missing_terms as $term) {
  3578. $doc->add_term($prefix . $term, 1);
  3579. }
  3580. foreach ($deprecated_terms as $term) {
  3581. $doc->remove_term($prefix . $term);
  3582. }
  3583. $di->getDb()->replace_document((int) $se_ref['search_did'], $doc);
  3584. $di->getDb()->flush();
  3585. }
  3586. }
  3587. return true;
  3588. }
  3589. /**
  3590. * Sets the theme of the LP (local/remote) (and save)
  3591. * @param string Optional string giving the new theme of this learnpath
  3592. * @return bool Returns true if theme name is not empty
  3593. */
  3594. public function set_theme($name = '') {
  3595. if ($this->debug > 0) {
  3596. error_log('New LP - In learnpath::set_theme()', 0);
  3597. }
  3598. $this->theme = $this->escape_string($name);
  3599. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3600. $lp_id = $this->get_id();
  3601. $sql = "UPDATE $lp_table SET theme = '" . $this->theme . "' WHERE id = '$lp_id'";
  3602. if ($this->debug > 2) {
  3603. error_log('New LP - lp updated with new theme : ' . $this->theme, 0);
  3604. }
  3605. //$res = Database::query($sql);
  3606. $res = Database::query($sql);
  3607. return true;
  3608. }
  3609. /**
  3610. * Sets the image of an LP (and save)
  3611. * @param string Optional string giving the new image of this learnpath
  3612. * @return bool Returns true if theme name is not empty
  3613. */
  3614. public function set_preview_image($name = '') {
  3615. if ($this->debug > 0) {
  3616. error_log('New LP - In learnpath::set_preview_image()', 0);
  3617. }
  3618. $this->preview_image = $this->escape_string($name);
  3619. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3620. $lp_id = $this->get_id();
  3621. $sql = "UPDATE $lp_table SET preview_image = '" . $this->preview_image . "' WHERE id = '$lp_id'";
  3622. if ($this->debug > 2) {
  3623. error_log('New LP - lp updated with new preview image : ' . $this->preview_image, 0);
  3624. }
  3625. $res = Database::query($sql);
  3626. return true;
  3627. }
  3628. /**
  3629. * Sets the author of a LP (and save)
  3630. * @param string Optional string giving the new author of this learnpath
  3631. * @return bool Returns true if author's name is not empty
  3632. */
  3633. public function set_author($name = '') {
  3634. if ($this->debug > 0) {
  3635. error_log('New LP - In learnpath::set_author()', 0);
  3636. }
  3637. $this->author = $this->escape_string($name);
  3638. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3639. $lp_id = $this->get_id();
  3640. $sql = "UPDATE $lp_table SET author = '" . $this->author . "' WHERE id = '$lp_id'";
  3641. if ($this->debug > 2) {
  3642. error_log('New LP - lp updated with new preview author : ' . $this->author, 0);
  3643. }
  3644. $res = Database::query($sql);
  3645. return true;
  3646. }
  3647. /**
  3648. * Sets the prerequisite of a LP (and save)
  3649. * @param int integer giving the new prerequisite of this learnpath
  3650. * @return bool returns true if prerequisite is not empty
  3651. */
  3652. public function set_prerequisite($prerequisite) {
  3653. if ($this->debug > 0) {
  3654. error_log('New LP - In learnpath::set_prerequisite()', 0);
  3655. }
  3656. $this->prerequisite = intval($prerequisite);
  3657. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3658. $lp_id = $this->get_id();
  3659. $sql = "UPDATE $lp_table SET prerequisite = '".$this->prerequisite."' WHERE id = '$lp_id'";
  3660. if ($this->debug > 2) {
  3661. error_log('New LP - lp updated with new preview requisite : ' . $this->requisite, 0);
  3662. }
  3663. $res = Database::query($sql);
  3664. return true;
  3665. }
  3666. /**
  3667. * Sets the location/proximity of the LP (local/remote) (and save)
  3668. * @param string Optional string giving the new location of this learnpath
  3669. * @return boolean True on success / False on error
  3670. */
  3671. public function set_proximity($name = '') {
  3672. if ($this->debug > 0) {
  3673. error_log('New LP - In learnpath::set_proximity()', 0);
  3674. }
  3675. if (empty ($name))
  3676. return false;
  3677. $this->proximity = $this->escape_string($name);
  3678. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3679. $lp_id = $this->get_id();
  3680. $sql = "UPDATE $lp_table SET content_local = '" . $this->proximity . "' WHERE id = '$lp_id'";
  3681. if ($this->debug > 2) {
  3682. error_log('New LP - lp updated with new proximity : ' . $this->proximity, 0);
  3683. }
  3684. //$res = Database::query($sql);
  3685. $res = Database::query($sql);
  3686. return true;
  3687. }
  3688. /**
  3689. * Sets the previous item ID to a given ID. Generally, this should be set to the previous 'current' item
  3690. * @param integer DB ID of the item
  3691. */
  3692. public function set_previous_item($id) {
  3693. if ($this->debug > 0) {
  3694. error_log('New LP - In learnpath::set_previous_item()', 0);
  3695. }
  3696. $this->last = $id;
  3697. }
  3698. /**
  3699. * Sets the object's error message
  3700. * @param string Error message. If empty, reinits the error string
  3701. * @return void
  3702. */
  3703. public function set_error_msg($error = '') {
  3704. if ($this->debug > 0) {
  3705. error_log('New LP - In learnpath::set_error_msg()', 0);
  3706. }
  3707. if (empty ($error)) {
  3708. $this->error = '';
  3709. } else {
  3710. $this->error .= $error;
  3711. }
  3712. }
  3713. /**
  3714. * Launches the current item if not 'sco' (starts timer and make sure there is a record ready in the DB)
  3715. * @param boolean Whether to allow a new attempt or not
  3716. * @return boolean True
  3717. */
  3718. public function start_current_item($allow_new_attempt = false) {
  3719. if ($this->debug > 0) {
  3720. error_log('New LP - In learnpath::start_current_item()', 0);
  3721. }
  3722. if ($this->current != 0 AND is_object($this->items[$this->current])) {
  3723. $type = $this->get_type();
  3724. $item_type = $this->items[$this->current]->get_type();
  3725. if (($type == 2 && $item_type != 'sco') OR ($type == 3 && $item_type != 'au') OR ($type == 1 && $item_type != TOOL_QUIZ && $item_type != TOOL_HOTPOTATOES)) {
  3726. $this->items[$this->current]->open($allow_new_attempt);
  3727. $this->autocomplete_parents($this->current);
  3728. $prereq_check = $this->prerequisites_match($this->current);
  3729. $this->items[$this->current]->save(false, $prereq_check);
  3730. //$this->update_queue[$this->last] = $this->items[$this->last]->get_status();
  3731. } else {
  3732. //if sco, then it is supposed to have been updated by some other call
  3733. }
  3734. if ($item_type == 'sco') {
  3735. $this->items[$this->current]->restart();
  3736. }
  3737. }
  3738. if ($this->debug > 0) {
  3739. error_log('New LP - End of learnpath::start_current_item()', 0);
  3740. }
  3741. return true;
  3742. }
  3743. /**
  3744. * Stops the processing and counters for the old item (as held in $this->last)
  3745. * @return boolean True/False
  3746. */
  3747. public function stop_previous_item() {
  3748. if ($this->debug > 0) {
  3749. error_log('New LP - In learnpath::stop_previous_item()', 0);
  3750. }
  3751. if ($this->last != 0 AND $this->last != $this->current AND is_object($this->items[$this->last])) {
  3752. if ($this->debug > 2) {
  3753. error_log('New LP - In learnpath::stop_previous_item() - ' . $this->last . ' is object', 0);
  3754. }
  3755. switch ($this->get_type()) {
  3756. case '3' :
  3757. if ($this->items[$this->last]->get_type() != 'au') {
  3758. if ($this->debug > 2) {
  3759. error_log('New LP - In learnpath::stop_previous_item() - ' . $this->last . ' in lp_type 3 is <> au', 0);
  3760. }
  3761. $this->items[$this->last]->close();
  3762. //$this->autocomplete_parents($this->last);
  3763. //$this->update_queue[$this->last] = $this->items[$this->last]->get_status();
  3764. } else {
  3765. if ($this->debug > 2) {
  3766. error_log('New LP - In learnpath::stop_previous_item() - Item is an AU, saving is managed by AICC signals', 0);
  3767. }
  3768. }
  3769. case '2' :
  3770. if ($this->items[$this->last]->get_type() != 'sco') {
  3771. if ($this->debug > 2) {
  3772. error_log('New LP - In learnpath::stop_previous_item() - ' . $this->last . ' in lp_type 2 is <> sco', 0);
  3773. }
  3774. $this->items[$this->last]->close();
  3775. //$this->autocomplete_parents($this->last);
  3776. //$this->update_queue[$this->last] = $this->items[$this->last]->get_status();
  3777. } else {
  3778. if ($this->debug > 2) {
  3779. error_log('New LP - In learnpath::stop_previous_item() - Item is a SCO, saving is managed by SCO signals', 0);
  3780. }
  3781. }
  3782. break;
  3783. case '1' :
  3784. default :
  3785. if ($this->debug > 2) {
  3786. error_log('New LP - In learnpath::stop_previous_item() - ' . $this->last . ' in lp_type 1 is asset', 0);
  3787. }
  3788. $this->items[$this->last]->close();
  3789. break;
  3790. }
  3791. } else {
  3792. if ($this->debug > 2) {
  3793. error_log('New LP - In learnpath::stop_previous_item() - No previous element found, ignoring...', 0);
  3794. }
  3795. return false;
  3796. }
  3797. return true;
  3798. }
  3799. /**
  3800. * Updates the default view mode from fullscreen to embedded and inversely
  3801. * @return string The current default view mode ('fullscreen' or 'embedded')
  3802. */
  3803. public function update_default_view_mode() {
  3804. if ($this->debug > 0) {
  3805. error_log('New LP - In learnpath::update_default_view_mode()', 0);
  3806. }
  3807. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3808. $sql = "SELECT * FROM $lp_table WHERE id = " . $this->get_id();
  3809. $res = Database::query($sql);
  3810. if (Database :: num_rows($res) > 0) {
  3811. $row = Database :: fetch_array($res);
  3812. $view_mode = $row['default_view_mod'];
  3813. if ($view_mode == 'fullscreen') {
  3814. $view_mode = 'embedded';
  3815. } elseif ($view_mode == 'embedded') {
  3816. $view_mode = 'fullscreen';
  3817. }
  3818. $sql = "UPDATE $lp_table SET default_view_mod = '$view_mode' WHERE id = " . $this->get_id();
  3819. $res = Database::query($sql);
  3820. $this->mode = $view_mode;
  3821. return $view_mode;
  3822. } else {
  3823. if ($this->debug > 2) {
  3824. error_log('New LP - Problem in update_default_view() - could not find LP ' . $this->get_id() . ' in DB', 0);
  3825. }
  3826. }
  3827. return -1;
  3828. }
  3829. /**
  3830. * Updates the default behaviour about auto-commiting SCORM updates
  3831. * @return boolean True if auto-commit has been set to 'on', false otherwise
  3832. */
  3833. public function update_default_scorm_commit() {
  3834. if ($this->debug > 0) {
  3835. error_log('New LP - In learnpath::update_default_scorm_commit()', 0);
  3836. }
  3837. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3838. $sql = "SELECT * FROM $lp_table WHERE id = " . $this->get_id();
  3839. $res = Database::query($sql);
  3840. if (Database :: num_rows($res) > 0) {
  3841. $row = Database :: fetch_array($res);
  3842. $force = $row['force_commit'];
  3843. if ($force == 1) {
  3844. $force = 0;
  3845. $force_return = false;
  3846. } elseif ($force == 0) {
  3847. $force = 1;
  3848. $force_return = true;
  3849. }
  3850. $sql = "UPDATE $lp_table SET force_commit = $force WHERE id = " . $this->get_id();
  3851. $res = Database::query($sql);
  3852. $this->force_commit = $force_return;
  3853. return $force_return;
  3854. } else {
  3855. if ($this->debug > 2) {
  3856. error_log('New LP - Problem in update_default_scorm_commit() - could not find LP ' . $this->get_id() . ' in DB', 0);
  3857. }
  3858. }
  3859. return -1;
  3860. }
  3861. /**
  3862. * Updates the order of learning paths (goes through all of them by order and fills the gaps)
  3863. * @return bool True on success, false on failure
  3864. */
  3865. public function update_display_order() {
  3866. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3867. $sql = "SELECT * FROM $lp_table ORDER BY display_order";
  3868. $res = Database::query($sql);
  3869. if ($res === false)
  3870. return false;
  3871. $lps = array ();
  3872. $lp_order = array ();
  3873. $num = Database :: num_rows($res);
  3874. //first check the order is correct, globally (might be wrong because
  3875. //of versions < 1.8.4)
  3876. if ($num > 0) {
  3877. $i = 1;
  3878. while ($row = Database :: fetch_array($res)) {
  3879. if ($row['display_order'] != $i) { //if we find a gap in the order, we need to fix it
  3880. $need_fix = true;
  3881. $sql_u = "UPDATE $lp_table SET display_order = $i WHERE id = " . $row['id'];
  3882. $res_u = Database::query($sql_u);
  3883. }
  3884. $i++;
  3885. }
  3886. }
  3887. return true;
  3888. }
  3889. /**
  3890. * Updates the "prevent_reinit" value that enables control on reinitialising items on second view
  3891. * @return boolean True if prevent_reinit has been set to 'on', false otherwise (or 1 or 0 in this case)
  3892. */
  3893. public function update_reinit() {
  3894. if ($this->debug > 0) {
  3895. error_log('New LP - In learnpath::update_reinit()', 0);
  3896. }
  3897. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3898. $sql = "SELECT * FROM $lp_table WHERE id = " . $this->get_id();
  3899. $res = Database::query($sql);
  3900. if (Database :: num_rows($res) > 0) {
  3901. $row = Database :: fetch_array($res);
  3902. $force = $row['prevent_reinit'];
  3903. if ($force == 1) {
  3904. $force = 0;
  3905. } elseif ($force == 0) {
  3906. $force = 1;
  3907. }
  3908. $sql = "UPDATE $lp_table SET prevent_reinit = $force WHERE id = " . $this->get_id();
  3909. $res = Database::query($sql);
  3910. $this->prevent_reinit = $force;
  3911. return $force;
  3912. } else {
  3913. if ($this->debug > 2) {
  3914. error_log('New LP - Problem in update_reinit() - could not find LP ' . $this->get_id() . ' in DB', 0);
  3915. }
  3916. }
  3917. return -1;
  3918. }
  3919. /**
  3920. * Updates the "scorm_debug" value that shows or hide the debug window
  3921. * @return boolean True if scorm_debug has been set to 'on', false otherwise (or 1 or 0 in this case)
  3922. */
  3923. public function update_scorm_debug() {
  3924. if ($this->debug > 0) {
  3925. error_log('New LP - In learnpath::update_scorm_debug()', 0);
  3926. }
  3927. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3928. $sql = "SELECT * FROM $lp_table WHERE id = " . $this->get_id();
  3929. $res = Database::query($sql);
  3930. if (Database :: num_rows($res) > 0) {
  3931. $row = Database :: fetch_array($res);
  3932. $force = $row['debug'];
  3933. if ($force == 1) {
  3934. $force = 0;
  3935. } elseif ($force == 0) {
  3936. $force = 1;
  3937. }
  3938. $sql = "UPDATE $lp_table SET debug = $force WHERE id = " . $this->get_id();
  3939. $res = Database::query($sql);
  3940. $this->scorm_debug = $force;
  3941. return $force;
  3942. } else {
  3943. if ($this->debug > 2) {
  3944. error_log('New LP - Problem in update_scorm_debug() - could not find LP ' . $this->get_id() . ' in DB', 0);
  3945. }
  3946. }
  3947. return -1;
  3948. }
  3949. /**
  3950. * Function that makes a call to the function sort_tree_array and create_tree_array
  3951. * @author Kevin Van Den Haute
  3952. * @param array
  3953. */
  3954. public function tree_array($array) {
  3955. if ($this->debug > 1) {
  3956. error_log('New LP - In learnpath::tree_array()', 0);
  3957. }
  3958. $array = $this->sort_tree_array($array);
  3959. $this->create_tree_array($array);
  3960. }
  3961. /**
  3962. * Creates an array with the elements of the learning path tree in it
  3963. *
  3964. * @author Kevin Van Den Haute
  3965. * @param array $array
  3966. * @param int $parent
  3967. * @param int $depth
  3968. * @param array $tmp
  3969. */
  3970. public function create_tree_array($array, $parent = 0, $depth = -1, $tmp = array ()) {
  3971. if ($this->debug > 1) {
  3972. error_log('New LP - In learnpath::create_tree_array())', 0);
  3973. }
  3974. if (is_array($array)) {
  3975. for ($i = 0; $i < count($array); $i++) {
  3976. if ($array[$i]['parent_item_id'] == $parent) {
  3977. if (!in_array($array[$i]['parent_item_id'], $tmp)) {
  3978. $tmp[] = $array[$i]['parent_item_id'];
  3979. $depth++;
  3980. }
  3981. $preq = (empty ($array[$i]['prerequisite']) ? '' : $array[$i]['prerequisite']);
  3982. $this->arrMenu[] = array (
  3983. 'id' => $array[$i]['id'],
  3984. 'item_type' => $array[$i]['item_type'],
  3985. 'title' => $array[$i]['title'],
  3986. 'path' => $array[$i]['path'],
  3987. 'description' => $array[$i]['description'],
  3988. 'parent_item_id' => $array[$i]['parent_item_id'],
  3989. 'previous_item_id' => $array[$i]['previous_item_id'],
  3990. 'next_item_id' => $array[$i]['next_item_id'],
  3991. 'min_score' => $array[$i]['min_score'],
  3992. 'max_score' => $array[$i]['max_score'],
  3993. 'mastery_score' => $array[$i]['mastery_score'],
  3994. 'display_order' => $array[$i]['display_order'],
  3995. 'prerequisite' => $preq,
  3996. 'depth' => $depth,
  3997. 'audio' => $array[$i]['audio']
  3998. );
  3999. $this->create_tree_array($array, $array[$i]['id'], $depth, $tmp);
  4000. }
  4001. }
  4002. }
  4003. }
  4004. /**
  4005. * Sorts a multi dimensional array by parent id and display order
  4006. * @author Kevin Van Den Haute
  4007. *
  4008. * @param array $array (array with al the learning path items in it)
  4009. *
  4010. * @return array
  4011. */
  4012. public function sort_tree_array($array) {
  4013. foreach ($array as $key => $row) {
  4014. $parent[$key] = $row['parent_item_id'];
  4015. $position[$key] = $row['display_order'];
  4016. }
  4017. if (count($array) > 0)
  4018. array_multisort($parent, SORT_ASC, $position, SORT_ASC, $array);
  4019. return $array;
  4020. }
  4021. /**
  4022. * Function that creates a table structure with a learning path his modules, chapters and documents.
  4023. * Also the actions for the modules, chapters and documents are in this table.
  4024. * @author Kevin Van Den Haute
  4025. * @param int $lp_id
  4026. * @return string
  4027. */
  4028. public function overview() {
  4029. $is_allowed_to_edit = api_is_allowed_to_edit(null,true);
  4030. $platform_charset = api_get_system_encoding();
  4031. if ($this->debug > 0) {
  4032. error_log('New LP - In learnpath::overview()', 0);
  4033. }
  4034. global $charset, $_course;
  4035. $_SESSION['gradebook'] = Security :: remove_XSS($_GET['gradebook']);
  4036. $return = '';
  4037. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  4038. $sql = "SELECT * FROM " . $tbl_lp_item . "
  4039. WHERE lp_id = " . $this->lp_id;
  4040. $result = Database::query($sql);
  4041. $arrLP = array ();
  4042. while ($row = Database :: fetch_array($result)) {
  4043. $row['title'] = Security :: remove_XSS(api_convert_encoding($row['title'], $platform_charset, $this->encoding));
  4044. $row['description'] = Security :: remove_XSS(api_convert_encoding($row['description'], $platform_charset, $this->encoding));
  4045. $arrLP[] = array (
  4046. 'id' => $row['id'],
  4047. 'item_type' => $row['item_type'],
  4048. 'title' => $row['title'],
  4049. 'path' => $row['path'],
  4050. 'description' => $row['description'],
  4051. 'parent_item_id' => $row['parent_item_id'],
  4052. 'previous_item_id' => $row['previous_item_id'],
  4053. 'next_item_id' => $row['next_item_id'],
  4054. 'max_score' => $row['max_score'],
  4055. 'min_score' => $row['min_score'],
  4056. 'mastery_score' => $row['mastery_score'],
  4057. 'prerequisite' => $row['prerequisite'],
  4058. 'display_order' => $row['display_order'],
  4059. 'audio' => $row['audio']
  4060. );
  4061. }
  4062. $this->tree_array($arrLP);
  4063. $arrLP = $this->arrMenu;
  4064. unset ($this->arrMenu);
  4065. if ($is_allowed_to_edit) {
  4066. $token = Security::get_token();
  4067. $gradebook = Security :: remove_XSS($_GET['gradebook']);
  4068. $return .= '<div class="actions">';
  4069. $return .= '<a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&amp;gradebook=' . $gradebook . '&amp;action=build&amp;lp_id=' . $this->lp_id . '" title="' . get_lang("Build") . '">' . Display :: return_icon('learnpath_build.gif', get_lang('Build')) . ' ' . get_lang('Build') . '</a>';
  4070. $return .= '<span>' . Display :: return_icon('learnpath_organize_na.gif', get_lang('BasicOverview')) . ' <b>' . get_lang('BasicOverview') . '</b></span>';
  4071. $return .= '<a href="lp_controller.php?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&action=view&lp_id=' . $this->lp_id . '">' . Display :: return_icon('learnpath_view.gif', get_lang("Display")) . ' ' . get_lang('Display') . '</a> ' . Display :: return_icon('i.gif');
  4072. $return .= '<a href="lp_controller.php?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&amp;action=edit&amp;lp_id=' . Security :: remove_XSS($_GET['lp_id']) . '">' . Display :: return_icon('edit.gif', get_lang('CourseSettings')) . ' ' . get_lang('CourseSettings') . '</a>';
  4073. $return .= '<a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&amp;action=' . Security :: remove_XSS($_GET['action']) . '&amp;lp_id=' . Security :: remove_XSS($_GET['lp_id']) . '&amp;updateaudio=true">' . Display :: return_icon('audio.gif', get_lang('UpdateAllAudioFragments')) . ' ' . get_lang('UpdateAllAudioFragments') . '</a>';
  4074. $return .= '<a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&amp;gradebook=' . $gradebook . '&amp;action=add_item&amp;type=chapter&amp;lp_id=' . $_SESSION['oLP']->lp_id . '" title="' . get_lang("NewChapter") . '"><img alt="' . get_lang("NewChapter") . '" src="../img/lp_dokeos_chapter_add.gif" title="' . get_lang("NewChapter") . '" />' . get_lang("NewChapter") . '</a>';
  4075. $return .= '<a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&amp;gradebook=' . $gradebook . '&amp;action=add_item&amp;type=step&amp;lp_id=' . $_SESSION['oLP']->lp_id . '" title="' . get_lang("NewStep") . '"><img alt="' . get_lang("NewStep") . '" src="../img/new_test.gif" title="' . get_lang("NewStep") . '" />' . get_lang("NewStep") . '</a>';
  4076. $return .= '</div>';
  4077. }
  4078. // we need to start a form when we want to update all the mp3 files
  4079. if ($_GET['updateaudio'] == 'true' AND count($arrLP) <> 0) {
  4080. $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">';
  4081. $return .= Display :: display_warning_message(get_lang('LeaveEmptyToKeepCurrentFile'));
  4082. }
  4083. $return .= '<table class="data_table">' . "\n";
  4084. $return .= "\t" . '<tr>' . "\n";
  4085. $return .= "\t" . '<th width="60%">' . get_lang("Title") . '</th>' . "\n";
  4086. //$return .= "\t" . '<th>'.get_lang("Description").'</th>' . "\n";
  4087. $return .= "\t" . '<th>' . get_lang("Audio") . '</th>' . "\n";
  4088. $return .= "\t" . '<th>' . get_lang("Move") . '</th>' . "\n";
  4089. $return .= "\t" . '<th>' . get_lang("Actions") . '</th>' . "\n";
  4090. $return .= "\t" . '</tr>' . "\n";
  4091. for ($i = 0; $i < count($arrLP); $i++) {
  4092. $title = $arrLP[$i]['title'];
  4093. if ($arrLP[$i]['description'] == '')
  4094. $arrLP[$i]['description'] = '&nbsp;';
  4095. if (($i % 2) == 0) {
  4096. $oddclass = "row_odd";
  4097. } else {
  4098. $oddclass = "row_even";
  4099. }
  4100. $return .= "\t" . '<tr class="' . $oddclass . '">' . "\n";
  4101. $icon_name = str_replace(' ', '', $arrLP[$i]['item_type']);
  4102. if (file_exists("../img/lp_" . $icon_name . ".png")) {
  4103. $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";
  4104. } else {
  4105. if (file_exists("../img/lp_" . $icon_name . ".gif")) {
  4106. $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";
  4107. } else {
  4108. //$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";
  4109. $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";
  4110. }
  4111. }
  4112. //$return .= "\t\t" . '<td>' . stripslashes($arrLP[$i]['description']) . '</td>' . "\n";
  4113. // The audio column
  4114. $return .= "\t\t" . '<td align="center">';
  4115. if (!$_GET['updateaudio'] OR $_GET['updateaudio'] <> 'true') {
  4116. if (!empty ($arrLP[$i]['audio'])) {
  4117. $return .= '<span id="container' . $i . '"><a href="http://www.macromedia.com/go/getflashplayer">Get the Flash Player</a> to see this player.</span>';
  4118. $return .= '<script type="text/javascript" src="../inc/lib/mediaplayer/swfobject.js"></script>';
  4119. $return .= '<script type="text/javascript">
  4120. var s1 = new SWFObject("../inc/lib/mediaplayer/player.swf","ply","250","20","9","#FFFFFF");
  4121. s1.addParam("allowscriptaccess","always");
  4122. s1.addParam("flashvars","file=../../courses/' . $_course['path'] . '/document/audio/' . $arrLP[$i]['audio'] . '");
  4123. s1.write("container' . $i . '");
  4124. </script>';
  4125. } else {
  4126. $return .= ' - ';
  4127. }
  4128. } else {
  4129. if ($arrLP[$i]['item_type'] != 'dokeos_chapter' && $arrLP[$i]['item_type'] != 'dokeos_module' && $arrLP[$i]['item_type'] != 'dir') {
  4130. $return .= ' <input type="file" name="mp3file' . $arrLP[$i]['id'] . '" id="mp3file" />';
  4131. if (!empty ($arrLP[$i]['audio'])) {
  4132. $return .= '<br />'.Security::remove_XSS($arrLP[$i]['audio']).'<input type="checkbox" name="removemp3' . $arrLP[$i]['id'] . '" id="checkbox' . $arrLP[$i]['id'] . '" />' . get_lang('RemoveAudio');
  4133. }
  4134. }
  4135. }
  4136. $return .= '</td>';
  4137. if ($is_allowed_to_edit) {
  4138. $return .= '<td align="center">';
  4139. if ($arrLP[$i]['previous_item_id'] != 0) {
  4140. $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.'">';
  4141. $return .= '<img style="margin:1px;" alt="" src="../img/arrow_up_' . ($arrLP[$i]['depth'] % 3) . '.gif" title="' . get_lang('MoveUp') . '"/>';
  4142. $return .= '</a>';
  4143. } else
  4144. $return .= '<img alt="" src="../img/blanco.png" title="" />';
  4145. if ($arrLP[$i]['next_item_id'] != 0) {
  4146. $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.'">';
  4147. $return .= '<img style="margin:1px;" src="../img/arrow_down_' . ($arrLP[$i]['depth'] % 3) . '.gif" title="' . get_lang('MoveDown') . '" />';
  4148. $return .= '</a>';
  4149. } else
  4150. $return .= '<img alt="" src="../img/blanco.png" title="" />';
  4151. $return .= '</td>';
  4152. $return .= '<td align="center">';
  4153. if ($arrLP[$i]['item_type'] != 'dokeos_chapter' && $arrLP[$i]['item_type'] != 'dokeos_module') {
  4154. $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'] . '">';
  4155. $return .= '<img style="margin:1px;" alt="" src="../img/edit.gif" title="' . get_lang('_edit_learnpath_module') . '" />';
  4156. $return .= '</a>' . "\n";
  4157. } else {
  4158. $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'] . '">';
  4159. $return .= '<img style="margin:1px;" alt="" src="../img/edit.gif" title="' . get_lang('_edit_learnpath_module') . '" />';
  4160. $return .= '</a>' . "\n";
  4161. }
  4162. $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) . '\');">';
  4163. $return .= '<img style="margin:1px;" alt="" src="../img/delete.gif" title="' . get_lang('_delete_learnpath_module') . '" />';
  4164. $return .= '</a>' . "\n";
  4165. $return .= '</td>';
  4166. }
  4167. $return .= '</tr>';
  4168. }
  4169. if (count($arrLP) == 0) {
  4170. $return .= "\t" . '<tr>' . "\n";
  4171. $return .= "\t\t" . '<td colspan="4">' . get_lang("NoItemsInLp") . '</td>' . "\n";
  4172. $return .= "\t" . '</tr>' . "\n";
  4173. }
  4174. $return .= '</table>' . "\n";
  4175. // we need to close the form when we are updating the mp3 files
  4176. if ($_GET['updateaudio'] == 'true') {
  4177. $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?
  4178. }
  4179. // we need to close the form when we are updating the mp3 files
  4180. if ($_GET['updateaudio'] == 'true' AND count($arrLP) <> 0) {
  4181. $return .= '</form>';
  4182. }
  4183. return $return;
  4184. }
  4185. /**
  4186. * This function builds the action menu
  4187. * @return void
  4188. */
  4189. public function build_action_menu() {
  4190. $gradebook = Security :: remove_XSS($_GET['gradebook']);
  4191. echo '<div class="actions">';
  4192. //echo '<span>'.Display::return_icon('learnpath_build.gif').' '.get_lang('Build').'</span>';
  4193. echo '<span>' . Display :: return_icon('learnpath_build_na.gif', get_lang('Build')) . ' <b>' . get_lang('Build') . '</b></span>';
  4194. echo '<a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&amp;gradebook=' . $gradebook . '&amp;action=admin_view&amp;lp_id=' . $_SESSION['oLP']->lp_id . '" title="' . get_lang("BasicOverview") . '">' . Display :: return_icon('learnpath_organize.gif', get_lang('BasicOverview')) . ' ' . get_lang('BasicOverview') . '</a>';
  4195. echo '<a href="lp_controller.php?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&amp;gradebook=' . $gradebook . '&action=view&lp_id=' . $_SESSION['oLP']->lp_id . '">' . Display :: return_icon('learnpath_view.gif', get_lang('Display')) . ' ' . get_lang('Display') . '</a>';
  4196. Display :: display_icon('i.gif');
  4197. echo '<a href="lp_controller.php?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&amp;action=edit&amp;lp_id=' . Security :: remove_XSS($_GET['lp_id']) . '">' . Display :: return_icon('edit.gif', get_lang('CourseSettings')) . ' ' . get_lang('CourseSettings') . '</a>';
  4198. echo '<a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&amp;action=admin_view&amp;lp_id=' . Security :: remove_XSS($_GET['lp_id']) . '&amp;updateaudio=true">' . Display :: return_icon('audio.gif', get_lang('UpdateAllAudioFragments')) . ' ' . get_lang('UpdateAllAudioFragments') . '</a>';
  4199. echo '<a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&amp;gradebook=' . $gradebook . '&amp;action=add_item&amp;type=chapter&amp;lp_id=' . $_SESSION['oLP']->lp_id . '" title="' . get_lang("NewChapter") . '">' . Display :: return_icon('lp_dokeos_chapter_add.gif', get_lang('NewChapter')) . ' ' . get_lang("NewChapter") . '</a>';
  4200. 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_test.gif', get_lang('NewStep')) . ' ' . get_lang("NewStep") . '</a>';
  4201. echo '</div>';
  4202. }
  4203. /**
  4204. * This functions builds the LP tree based on data from the database.
  4205. * @return string
  4206. * @uses dtree.js :: necessary javascript for building this tree
  4207. */
  4208. public function build_tree() {
  4209. $platform_charset = api_get_system_encoding();
  4210. $return = "<script type=\"text/javascript\">\n";
  4211. $return .= "\tm = new dTree('m');\n\n";
  4212. $return .= "\tm.config.folderLinks = true;\n";
  4213. $return .= "\tm.config.useCookies = true;\n";
  4214. $return .= "\tm.config.useIcons = true;\n";
  4215. $return .= "\tm.config.useLines = true;\n";
  4216. $return .= "\tm.config.useSelection = true;\n";
  4217. $return .= "\tm.config.useStatustext = false;\n\n";
  4218. $menu = 0;
  4219. $parent = '';
  4220. $return .= "\tm.add(" . $menu . ", -1, '" . addslashes(Security::remove_XSS(($this->name))) . "');\n";
  4221. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  4222. $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
  4223. FROM " . $tbl_lp_item . "
  4224. WHERE lp_id = " . Database :: escape_string($this->lp_id);
  4225. $result = Database::query($sql);
  4226. $arrLP = array ();
  4227. while ($row = Database :: fetch_array($result)) {
  4228. $row['title'] = Security :: remove_XSS(api_convert_encoding($row['title'], $platform_charset, $this->encoding));
  4229. $row['description'] = Security :: remove_XSS(api_convert_encoding($row['description'], $platform_charset, $this->encoding));
  4230. $arrLP[] = array (
  4231. 'id' => $row['id'],
  4232. 'item_type' => $row['item_type'],
  4233. 'title' => $row['title'],
  4234. 'path' => $row['path'],
  4235. 'description' => $row['description'],
  4236. 'parent_item_id' => $row['parent_item_id'],
  4237. 'previous_item_id' => $row['previous_item_id'],
  4238. 'next_item_id' => $row['next_item_id'],
  4239. 'max_score' => $row['max_score'],
  4240. 'min_score' => $row['min_score'],
  4241. 'mastery_score' => $row['mastery_score'],
  4242. 'display_order' => $row['display_order']
  4243. );
  4244. }
  4245. $this->tree_array($arrLP);
  4246. $arrLP = $this->arrMenu;
  4247. unset ($this->arrMenu);
  4248. $title = '';
  4249. for ($i = 0; $i < count($arrLP); $i++) {
  4250. $title = addslashes($arrLP[$i]['title']);
  4251. $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;
  4252. $icon_name = str_replace(' ', '', $arrLP[$i]['item_type']);
  4253. if (file_exists("../img/lp_" . $icon_name . ".png")) {
  4254. $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";
  4255. } else
  4256. if (file_exists("../img/lp_" . $icon_name . ".gif")) {
  4257. $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";
  4258. } else {
  4259. $return .= "\tm.add(" . $arrLP[$i]['id'] . ", " . $arrLP[$i]['parent_item_id'] . ", '" . $title . "', '" . $menu_page . "', '', '', '../img/folder_document.gif', '../img/folder_document.gif');\n";
  4260. }
  4261. if ($menu < $arrLP[$i]['id'])
  4262. $menu = $arrLP[$i]['id'];
  4263. }
  4264. $return .= "\n\tdocument.write(m);\n";
  4265. $return .= "\t if(!m.selectedNode) m.s(1);";
  4266. $return .= "</script>\n";
  4267. return $return;
  4268. }
  4269. /**
  4270. * Create a new document //still needs some finetuning
  4271. * @param array $_course
  4272. * @return string
  4273. */
  4274. public function create_document($_course) {
  4275. global $charset;
  4276. $dir = isset ($_GET['dir']) ? $_GET['dir'] : $_POST['dir']; // please do not modify this dirname formatting
  4277. if (strstr($dir, '..'))
  4278. $dir = '/';
  4279. if ($dir[0] == '.')
  4280. $dir = substr($dir, 1);
  4281. if ($dir[0] != '/')
  4282. $dir = '/' . $dir;
  4283. if ($dir[strlen($dir) - 1] != '/')
  4284. $dir .= '/';
  4285. $filepath = api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document' . $dir;
  4286. if (!is_dir($filepath)) {
  4287. $filepath = api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document/';
  4288. $dir = '/';
  4289. }
  4290. //stripslashes before calling replace_dangerous_char() because $_POST['title']
  4291. //is already escaped twice when it gets here
  4292. $title = replace_dangerous_char(stripslashes($_POST['title']));
  4293. $title = disable_dangerous_file($title);
  4294. $filename = $title;
  4295. $content = $_POST['content_lp'];
  4296. $tmp_filename = $filename;
  4297. $i = 0;
  4298. while (file_exists($filepath . $tmp_filename . '.html'))
  4299. $tmp_filename = $filename . '_' . ++ $i;
  4300. $filename = $tmp_filename . '.html';
  4301. $content = stripslashes(text_filter($content));
  4302. $content = str_replace(api_get_path(WEB_COURSE_PATH), api_get_path(REL_PATH) . 'courses/', $content);
  4303. // change the path of mp3 to absolute
  4304. // first regexp deals with ../../../ urls
  4305. $content = preg_replace("|(flashvars=\"file=)(\.+/)+|", "$1" . api_get_path(REL_COURSE_PATH) . $_course['path'] . '/document/', $content);
  4306. //second regexp deals with audio/ urls
  4307. $content = preg_replace("|(flashvars=\"file=)([^/]+)/|", "$1" . api_get_path(REL_COURSE_PATH) . $_course['path'] . '/document/$2/', $content);
  4308. // for flv player : to prevent edition problem with firefox, we have to use a strange tip (don't blame me please)
  4309. $content = str_replace('</body>', '<style type="text/css">body{}</style></body>', $content);
  4310. if (!file_exists($filepath . $filename)) {
  4311. if ($fp = @ fopen($filepath . $filename, 'w')) {
  4312. fputs($fp, $content);
  4313. fclose($fp);
  4314. $file_size = filesize($filepath . $filename);
  4315. $save_file_path = $dir . $filename;
  4316. $document_id = add_document($_course, $save_file_path, 'file', $file_size, $filename . '.html');
  4317. if ($document_id) {
  4318. api_item_property_update($_course, TOOL_DOCUMENT, $document_id, 'DocumentAdded', api_get_user_id(),null,null,null,null,api_get_session_id());
  4319. //update parent folders
  4320. //item_property_update_on_folder($_course, $_GET['dir'], $_user['user_id']);
  4321. $new_comment = (isset ($_POST['comment'])) ? trim($_POST['comment']) : '';
  4322. $new_title = (isset ($_POST['title'])) ? trim($_POST['title']) : '';
  4323. if ($new_comment || $new_title) {
  4324. $tbl_doc = Database :: get_course_table(TABLE_DOCUMENT);
  4325. $ct = '';
  4326. if ($new_comment)
  4327. $ct .= ", comment='" . $new_comment . "'";
  4328. if ($new_title)
  4329. $ct .= ", title='" . Database :: escape_string(htmlspecialchars($new_title, ENT_QUOTES, $charset)) . ".html '";
  4330. $sql_update = "
  4331. UPDATE " . $tbl_doc . "
  4332. SET " . substr($ct, 1) . "
  4333. WHERE id = " . $document_id;
  4334. Database::query($sql_update);
  4335. }
  4336. }
  4337. return $document_id;
  4338. }
  4339. }
  4340. }
  4341. /**
  4342. * Edit a document based on $_POST and $_GET parameters 'dir' and 'path'
  4343. * @param array $_course array
  4344. * @return void
  4345. */
  4346. public function edit_document($_course) {
  4347. global $_configuration;
  4348. $dir = isset ($_GET['dir']) ? $_GET['dir'] : $_POST['dir']; // please do not modify this dirname formatting
  4349. if (strstr($dir, '..'))
  4350. $dir = '/';
  4351. if ($dir[0] == '.')
  4352. $dir = substr($dir, 1);
  4353. if ($dir[0] != '/')
  4354. $dir = '/' . $dir;
  4355. if ($dir[strlen($dir) - 1] != '/')
  4356. $dir .= '/';
  4357. $filepath = api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document' . $dir;
  4358. if (!is_dir($filepath)) {
  4359. $filepath = api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document/';
  4360. $dir = '/';
  4361. }
  4362. $table_doc = Database :: get_course_table(TABLE_DOCUMENT);
  4363. if (isset($_POST['path']) && !empty($_POST['path'])) {
  4364. $sql = "SELECT path
  4365. FROM " . $table_doc . "
  4366. WHERE id = " . Database::escape_string($_POST['path']);
  4367. $res = Database::query($sql);
  4368. $row = Database :: fetch_array($res);
  4369. $content = stripslashes($_POST['content_lp']);
  4370. $file = $filepath . $row['path'];
  4371. if ($fp = @ fopen($file, 'w')) {
  4372. $content = text_filter($content);
  4373. $content = str_replace(api_get_path(WEB_COURSE_PATH), $_configuration['url_append'] . '/courses/', $content);
  4374. // change the path of mp3 to absolute
  4375. // first regexp deals with ../../../ urls
  4376. $content = preg_replace("|(flashvars=\"file=)(\.+/)+|", "$1" . api_get_path(REL_COURSE_PATH) . $_course['path'] . '/document/', $content);
  4377. //second regexp deals with audio/ urls
  4378. $content = preg_replace("|(flashvars=\"file=)([^/]+)/|", "$1" . api_get_path(REL_COURSE_PATH) . $_course['path'] . '/document/$2/', $content);
  4379. fputs($fp, $content);
  4380. fclose($fp);
  4381. }
  4382. }
  4383. }
  4384. /**
  4385. * Displays the selected item, with a panel for manipulating the item
  4386. * @param int $item_id
  4387. * @param string $msg
  4388. * @return string
  4389. */
  4390. public function display_item($item_id, $iframe = true, $msg = '') {
  4391. global $_course; //will disappear
  4392. $return = '';
  4393. if (is_numeric($item_id)) {
  4394. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  4395. $tbl_doc = Database :: get_course_table(TABLE_DOCUMENT);
  4396. $sql = "SELECT lp.* FROM " . $tbl_lp_item . " as lp
  4397. WHERE lp.id = " . Database :: escape_string($item_id);
  4398. $result = Database::query($sql);
  4399. while ($row = Database :: fetch_array($result)) {
  4400. $_SESSION['parent_item_id'] = ($row['item_type'] == 'dokeos_chapter' || $row['item_type'] == 'dokeos_module' || $row['item_type'] == 'dir') ? $item_id : 0;
  4401. //Prevents wrong parent selection for document see Bug#1251
  4402. if ($row['item_type'] != 'dokeos_chapter' || $row['item_type'] != 'dokeos_module') {
  4403. $_SESSION['parent_item_id'] = $row['parent_item_id'];
  4404. }
  4405. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4406. $return .= '<div style="padding:10px;">';
  4407. if ($msg != '')
  4408. $return .= $msg;
  4409. $row['title'] = Security :: remove_XSS(api_convert_encoding($row['title'], api_get_system_encoding(), $this->encoding));
  4410. //$row['title'] = Security::remove_XSS(api_convert_encoding($row['title'], $this->encoding, api_get_system_encoding()));
  4411. $return .= '<p class="lp_title">' . $row['title'] . '</p>';
  4412. //$return .= '<p class="lp_text">' . ((trim($row['description']) == '') ? 'no description' : stripslashes($row['description'])) . '</p>';
  4413. //$return .= '<hr />';
  4414. if ($row['item_type'] == TOOL_DOCUMENT) {
  4415. $tbl_doc = Database :: get_course_table(TABLE_DOCUMENT);
  4416. $sql_doc = "SELECT path FROM " . $tbl_doc . " WHERE id = " . Database :: escape_string($row['path']);
  4417. $result = Database::query($sql_doc);
  4418. $path_file = Database :: result($result, 0, 0);
  4419. $path_parts = pathinfo($path_file);
  4420. if (in_array($path_parts['extension'], array (
  4421. 'html',
  4422. 'txt',
  4423. 'png',
  4424. 'jpg',
  4425. 'JPG',
  4426. 'jpeg',
  4427. 'JPEG',
  4428. 'gif',
  4429. 'swf'
  4430. ))) {
  4431. $return .= $this->display_document($row['path'], true, true);
  4432. }
  4433. }
  4434. $return .= '</div>';
  4435. }
  4436. }
  4437. return $return;
  4438. }
  4439. /**
  4440. * Shows the needed forms for editing a specific item
  4441. * @param int $item_id
  4442. * @return string
  4443. */
  4444. public function display_edit_item($item_id) {
  4445. global $_course; //will disappear
  4446. $return = '';
  4447. if (is_numeric($item_id)) {
  4448. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  4449. $sql = "SELECT *
  4450. FROM " . $tbl_lp_item . "
  4451. WHERE id = " . Database :: escape_string($item_id);
  4452. $res = Database::query($sql);
  4453. $row = Database :: fetch_array($res);
  4454. switch ($row['item_type']) {
  4455. case 'dokeos_chapter' :
  4456. case 'dir' :
  4457. case 'asset' :
  4458. case 'sco' :
  4459. if (isset ($_GET['view']) && $_GET['view'] == 'build') {
  4460. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4461. $return .= $this->display_item_form($row['item_type'], get_lang("EditCurrentChapter") . ' :', 'edit', $item_id, $row);
  4462. } else {
  4463. $return .= $this->display_item_small_form($row['item_type'], get_lang("EditCurrentChapter") . ' :', $row);
  4464. }
  4465. break;
  4466. case TOOL_DOCUMENT :
  4467. $tbl_doc = Database :: get_course_table(TABLE_DOCUMENT);
  4468. $sql_step = " SELECT lp.*, doc.path as dir
  4469. FROM " . $tbl_lp_item . " as lp
  4470. LEFT JOIN " . $tbl_doc . " as doc ON doc.id = lp.path
  4471. WHERE lp.id = " . Database :: escape_string($item_id);
  4472. $res_step = Database::query($sql_step);
  4473. $row_step = Database :: fetch_array($res_step);
  4474. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4475. $return .= $this->display_document_form('edit', $item_id, $row_step);
  4476. break;
  4477. case TOOL_LINK :
  4478. $link_id = (string) $row['path'];
  4479. if (ctype_digit($link_id)) {
  4480. $tbl_link = Database :: get_course_table(TABLE_LINK);
  4481. $sql_select = 'SELECT url FROM ' . $tbl_link . ' WHERE id = ' . Database :: escape_string($link_id);
  4482. $res_link = Database::query($sql_select);
  4483. $row_link = Database :: fetch_array($res_link);
  4484. if (is_array($row_link)) {
  4485. $row['url'] = $row_link['url'];
  4486. }
  4487. }
  4488. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4489. $return .= $this->display_link_form('edit', $item_id, $row);
  4490. break;
  4491. case 'dokeos_module' :
  4492. if (isset ($_GET['view']) && $_GET['view'] == 'build') {
  4493. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4494. $return .= $this->display_item_form($row['item_type'], get_lang("EditCurrentModule") . ' :', 'edit', $item_id, $row);
  4495. } else {
  4496. $return .= $this->display_item_small_form($row['item_type'], get_lang("EditCurrentModule") . ' :', $row);
  4497. }
  4498. break;
  4499. case TOOL_QUIZ :
  4500. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4501. $return .= $this->display_quiz_form('edit', $item_id, $row);
  4502. break;
  4503. case TOOL_HOTPOTATOES :
  4504. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4505. $return .= $this->display_hotpotatoes_form('edit', $item_id, $row);
  4506. break;
  4507. case TOOL_STUDENTPUBLICATION :
  4508. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4509. $return .= $this->display_student_publication_form('edit', $item_id, $row);
  4510. break;
  4511. case TOOL_FORUM :
  4512. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4513. $return .= $this->display_forum_form('edit', $item_id, $row);
  4514. break;
  4515. case TOOL_THREAD :
  4516. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4517. $return .= $this->display_thread_form('edit', $item_id, $row);
  4518. break;
  4519. }
  4520. }
  4521. return $return;
  4522. }
  4523. /**
  4524. * Function that displays a list with al the resources that could be added to the learning path
  4525. * @return string
  4526. */
  4527. public function display_resources() {
  4528. global $_course; //TODO: don't use globals
  4529. $return .= '<div class="sectiontitle">' . get_lang('CreateNewStep') . '</div>';
  4530. $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.
  4531. $return .= '<div class="sectiontitle">' . get_lang('UseAnExistingResource') . '</div>';
  4532. $return .= '<div class="sectioncomment">';
  4533. /* get all the docs */
  4534. $return .= $this->get_documents();
  4535. /* get all the exercises */
  4536. $return .= $this->get_exercises();
  4537. /* get all the links */
  4538. $return .= $this->get_links();
  4539. /* get al the student publications */
  4540. $return .= $this->get_student_publications();
  4541. /* get al the forums */
  4542. $return .= $this->get_forums();
  4543. $return .= '</div>';
  4544. return $return;
  4545. }
  4546. /**
  4547. * Returns the extension of a document
  4548. * @param string filename
  4549. * @return string Extension (part after the last dot)
  4550. */
  4551. public function get_extension($filename) {
  4552. $explode = explode('.', $filename);
  4553. return $explode[count($explode) - 1];
  4554. }
  4555. /**
  4556. * Displays a document by id
  4557. *
  4558. * @param unknown_type $id
  4559. * @return unknown
  4560. */
  4561. public function display_document($id, $show_title = false, $iframe = true, $edit_link = false) {
  4562. global $_course; //temporary
  4563. $return = '';
  4564. $tbl_doc = Database :: get_course_table(TABLE_DOCUMENT);
  4565. $sql_doc = "SELECT * FROM " . $tbl_doc . "
  4566. WHERE id = " . $id;
  4567. $res_doc = Database::query($sql_doc);
  4568. $row_doc = Database :: fetch_array($res_doc);
  4569. //if($show_title)
  4570. //$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>';
  4571. //TODO: add a path filter
  4572. if ($iframe) {
  4573. $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>';
  4574. } else {
  4575. $return .= file_get_contents(api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document' . $row_doc['path']);
  4576. }
  4577. return $return;
  4578. }
  4579. /**
  4580. * Return HTML form to add/edit a quiz
  4581. * @param string Action (add/edit)
  4582. * @param integer Item ID if already exists
  4583. * @param mixed Extra information (quiz ID if integer)
  4584. * @return string HTML form
  4585. */
  4586. public function display_quiz_form($action = 'add', $id = 0, $extra_info = '') {
  4587. global $charset;
  4588. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  4589. $tbl_quiz = Database :: get_course_table(TABLE_QUIZ_TEST);
  4590. if ($id != 0 && is_array($extra_info)) {
  4591. $item_title = stripslashes($extra_info['title']);
  4592. $item_description = stripslashes($extra_info['description']);
  4593. }
  4594. elseif (is_numeric($extra_info)) {
  4595. $sql_quiz = "
  4596. SELECT
  4597. title,
  4598. description
  4599. FROM " . $tbl_quiz . "
  4600. WHERE id = " . $extra_info;
  4601. $result = Database::query($sql_quiz);
  4602. $row = Database :: fetch_array($result);
  4603. $item_title = $row['title'];
  4604. $item_description = $row['description'];
  4605. } else {
  4606. $item_title = '';
  4607. $item_description = '';
  4608. }
  4609. $return = ' <div class="row">
  4610. <div class="form_header">';
  4611. if ($id != 0 && is_array($extra_info))
  4612. $parent = $extra_info['parent_item_id'];
  4613. else
  4614. $parent = 0;
  4615. $sql = "
  4616. SELECT *
  4617. FROM " . $tbl_lp_item . "
  4618. WHERE
  4619. lp_id = " . $this->lp_id;
  4620. $result = Database::query($sql);
  4621. $arrLP = array ();
  4622. while ($row = Database :: fetch_array($result)) {
  4623. $arrLP[] = array (
  4624. 'id' => $row['id'],
  4625. 'item_type' => $row['item_type'],
  4626. 'title' => $row['title'],
  4627. 'path' => $row['path'],
  4628. 'description' => $row['description'],
  4629. 'parent_item_id' => $row['parent_item_id'],
  4630. 'previous_item_id' => $row['previous_item_id'],
  4631. 'next_item_id' => $row['next_item_id'],
  4632. 'display_order' => $row['display_order'],
  4633. 'max_score' => $row['max_score'],
  4634. 'min_score' => $row['min_score'],
  4635. 'mastery_score' => $row['mastery_score'],
  4636. 'prerequisite' => $row['prerequisite'],
  4637. 'max_time_allowed' => $row['max_time_allowed']
  4638. );
  4639. }
  4640. $this->tree_array($arrLP);
  4641. $arrLP = $this->arrMenu;
  4642. unset ($this->arrMenu);
  4643. if ($action == 'add')
  4644. $return .= get_lang("CreateTheExercise") . '&nbsp;:' . "\n";
  4645. elseif ($action == 'move') $return .= get_lang("MoveTheCurrentExercise") . '&nbsp;:' . "\n";
  4646. else
  4647. $return .= get_lang("EditCurrentExecice") . '&nbsp;:' . "\n";
  4648. if (isset ($_GET['edit']) && $_GET['edit'] == 'true') {
  4649. $return .= Display :: return_warning_message('<p class="lp_title">' . get_lang("Warning") . ' !</p>' . get_lang("WarningEditingDocument"));
  4650. }
  4651. $return .= ' </div>
  4652. </div>';
  4653. $return .= '<div class="sectioncomment">';
  4654. $return .= '<form method="POST">' . "\n";
  4655. $return .= "\t" . '<table class="lp_form">' . "\n";
  4656. if ($action != 'move') {
  4657. $return .= "\t\t" . '<tr>' . "\n";
  4658. $return .= "\t\t\t" . '<td class="label"><label for="idTitle">' . get_lang('Title') . '</label></td>' . "\n";
  4659. $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";
  4660. $return .= "\t\t" . '</tr>' . "\n";
  4661. }
  4662. $return .= "\t\t" . '<tr>' . "\n";
  4663. $return .= "\t\t\t" . '<td class="label"><label for="idParent">' . get_lang('Parent') . '</label></td>' . "\n";
  4664. $return .= "\t\t\t" . '<td class="input">' . "\n";
  4665. $return .= "\t\t\t\t" . '<select id="idParent" style="width:100%;" name="parent" onchange="load_cbo(this.value);" class="learnpath_item_form" size="1">';
  4666. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
  4667. $arrHide = array (
  4668. $id
  4669. );
  4670. //$parent_item_id = $_SESSION['parent_item_id'];
  4671. for ($i = 0; $i < count($arrLP); $i++) {
  4672. if ($action != 'add') {
  4673. 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)) {
  4674. $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'] . '">' . api_convert_encoding($arrLP[$i]['title'], $charset, $this->encoding) . '</option>';
  4675. } else {
  4676. $arrHide[] = $arrLP[$i]['id'];
  4677. }
  4678. } else {
  4679. if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
  4680. $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'] . '">' . api_convert_encoding($arrLP[$i]['title'], $charset, $this->encoding) . '</option>';
  4681. }
  4682. }
  4683. if (is_array($arrLP)) {
  4684. reset($arrLP);
  4685. }
  4686. $return .= '</select>';
  4687. $return .= '</td>';
  4688. $return .= '</tr>';
  4689. $return .= '<tr>';
  4690. $return .= "\t\t\t" . '<td class="label"><label for="idPosition">' . get_lang('Position') . '</label></td>' . "\n";
  4691. $return .= "\t\t\t" . '<td class="input">' . "\n";
  4692. $return .= "\t\t\t\t" . '<select class="learnpath_item_form" style="width:100%;" id="idPosition" name="previous" size="1">';
  4693. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . get_lang('FirstPosition') . '</option>';
  4694. for ($i = 0; $i < count($arrLP); $i++) {
  4695. if ($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) {
  4696. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  4697. $selected = 'selected="selected" ';
  4698. elseif ($action == 'add') $selected = 'selected="selected" ';
  4699. else
  4700. $selected = '';
  4701. $return .= "\t\t\t\t\t" . '<option ' . $selected . 'value="' . $arrLP[$i]['id'] . '">' . get_lang("After") . ' "' . api_convert_encoding($arrLP[$i]['title'], $charset, $this->encoding) . '"</option>';
  4702. }
  4703. }
  4704. $return .= "\t\t\t\t" . '</select>';
  4705. $return .= "\t\t\t" . '</td>' . "\n";
  4706. $return .= "\t\t" . '</tr>' . "\n";
  4707. if ($action != 'move') {
  4708. $id_prerequisite = 0;
  4709. if (is_array($arrLP)) {
  4710. foreach ($arrLP as $key => $value) {
  4711. if ($value['id'] == $id) {
  4712. $id_prerequisite = $value['prerequisite'];
  4713. break;
  4714. }
  4715. }
  4716. }
  4717. $arrHide = array ();
  4718. for ($i = 0; $i < count($arrLP); $i++) {
  4719. if ($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter') {
  4720. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  4721. $s_selected_position = $arrLP[$i]['id'];
  4722. elseif ($action == 'add') $s_selected_position = 0;
  4723. $arrHide[$arrLP[$i]['id']]['value'] = api_convert_encoding($arrLP[$i]['title'], $charset, $this->encoding);
  4724. }
  4725. }
  4726. /*//comented the prerequisites, only visible in edit (exercise)
  4727. $return .= "\t\t" . '<tr>' . "\n";
  4728. $return .= "\t\t\t" . '<td class="label"><label for="idPrerequisites">'.get_lang('Prerequisites').'</label></td>' . "\n";
  4729. $return .= "\t\t\t" . '<td class="input"><select name="prerequisites" id="prerequisites" class="learnpath_item_form"><option value="0">'.get_lang("NoPrerequisites").'</option>';
  4730. foreach($arrHide as $key => $value){
  4731. if($key==$s_selected_position && $action == 'add'){
  4732. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  4733. }
  4734. elseif($key==$id_prerequisite && $action == 'edit'){
  4735. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  4736. }
  4737. else{
  4738. $return .= '<option value="'.$key.'">'.$value['value'].'</option>';
  4739. }
  4740. }
  4741. $return .= "</select></td>";
  4742. */
  4743. $return .= "\t\t" . '</tr>' . "\n";
  4744. /*$return .= "\t\t" . '<tr>' . "\n";
  4745. $return .= "\t\t\t" . '<td class="label"><label for="maxTimeAllowed">' . get_lang('MaxTimeAllowed') . '</label></td>' . "\n";
  4746. $return .= "\t\t\t" . '<td class="input"><input name="maxTimeAllowed" style="width:98%;" id="maxTimeAllowed" value="' . $extra_info['max_time_allowed'] . '" /></td>';
  4747. //Remove temporaly the test description
  4748. //$return .= "\t\t\t" . '<td class="label"><label for="idDescription">'.get_lang("Description").' :</label></td>' . "\n";
  4749. //$return .= "\t\t\t" . '<td class="input"><textarea id="idDescription" name="description" rows="4">' . $item_description . '</textarea></td>' . "\n";
  4750. $return .= "\t\t" . '</tr>' . "\n"; */
  4751. }
  4752. $return .= "\t\t" . '<tr>' . "\n";
  4753. if ($action == 'add') {
  4754. $return .= '<td>&nbsp;</td><td><button class="save" name="submit_button" type="submit">' . get_lang('AddExercise') . '</button></td>';
  4755. } else {
  4756. $return .= '<td>&nbsp;</td><td><button class="save" name="submit_button" type="submit">' . get_lang('EditCurrentExecice') . '</button></td>';
  4757. }
  4758. $return .= "\t\t" . '</tr>' . "\n";
  4759. $return .= "\t" . '</table>' . "\n";
  4760. if ($action == 'move') {
  4761. $return .= "\t" . '<input name="title" type="hidden" value="' . $item_title . '" />' . "\n";
  4762. $return .= "\t" . '<input name="description" type="hidden" value="' . $item_description . '" />' . "\n";
  4763. }
  4764. if (is_numeric($extra_info)) {
  4765. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info . '" />' . "\n";
  4766. }
  4767. elseif (is_array($extra_info)) {
  4768. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />' . "\n";
  4769. }
  4770. $return .= "\t" . '<input name="type" type="hidden" value="' . TOOL_QUIZ . '" />' . "\n";
  4771. $return .= "\t" . '<input name="post_time" type="hidden" value="' . time() . '" />' . "\n";
  4772. $return .= '</form>' . "\n";
  4773. $return .= '</div>' . "\n";
  4774. return $return;
  4775. }
  4776. /**
  4777. * Addition of Hotpotatoes tests
  4778. * @param string Action
  4779. * @param integer Internal ID of the item
  4780. * @param mixed Extra information - can be an array with title and description indexes
  4781. * @return string HTML structure to display the hotpotatoes addition formular
  4782. */
  4783. public function display_hotpotatoes_form($action = 'add', $id = 0, $extra_info = '') {
  4784. global $charset;
  4785. $uploadPath = DIR_HOTPOTATOES; //defined in main_api
  4786. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  4787. if ($id != 0 && is_array($extra_info)) {
  4788. $item_title = stripslashes($extra_info['title']);
  4789. $item_description = stripslashes($extra_info['description']);
  4790. }
  4791. elseif (is_numeric($extra_info)) {
  4792. $TBL_DOCUMENT = Database :: get_course_table(TABLE_DOCUMENT);
  4793. $sql_hot = "SELECT * FROM " . $TBL_DOCUMENT . "
  4794. WHERE path LIKE '" . $uploadPath . "/%/%htm%'
  4795. AND id = " . (int) $extra_info . " ORDER BY id ASC";
  4796. $res_hot = Database::query($sql_hot);
  4797. $row = Database :: fetch_array($res_hot);
  4798. $item_title = $row['title'];
  4799. $item_description = $row['description'];
  4800. if (!empty ($row['comment'])) {
  4801. $item_title = $row['comment'];
  4802. }
  4803. } else {
  4804. $item_title = '';
  4805. $item_description = '';
  4806. }
  4807. $item_title = api_convert_encoding($item_title, $charset, $this->encoding);
  4808. $item_description = api_convert_encoding($item_description, $charset, $this->encoding);
  4809. $return = '<div style="margin:3px 12px;">';
  4810. if ($id != 0 && is_array($extra_info))
  4811. $parent = $extra_info['parent_item_id'];
  4812. else
  4813. $parent = 0;
  4814. $sql = "
  4815. SELECT *
  4816. FROM " . $tbl_lp_item . "
  4817. WHERE
  4818. lp_id = " . $this->lp_id;
  4819. $result = Database::query($sql);
  4820. $arrLP = array ();
  4821. while ($row = Database :: fetch_array($result)) {
  4822. $arrLP[] = array (
  4823. 'id' => $row['id'],
  4824. 'item_type' => $row['item_type'],
  4825. 'title' => $row['title'],
  4826. 'path' => $row['path'],
  4827. 'description' => $row['description'],
  4828. 'parent_item_id' => $row['parent_item_id'],
  4829. 'previous_item_id' => $row['previous_item_id'],
  4830. 'next_item_id' => $row['next_item_id'],
  4831. 'display_order' => $row['display_order'],
  4832. 'max_score' => $row['max_score'],
  4833. 'min_score' => $row['min_score'],
  4834. 'mastery_score' => $row['mastery_score'],
  4835. 'prerequisite' => $row['prerequisite'],
  4836. 'max_time_allowed' => $row['max_time_allowed']
  4837. );
  4838. }
  4839. $this->tree_array($arrLP);
  4840. $arrLP = $this->arrMenu;
  4841. unset ($this->arrMenu);
  4842. if ($action == 'add')
  4843. $return .= '<p class="lp_title">' . get_lang("CreateTheExercise") . '&nbsp;:</p>' . "\n";
  4844. elseif ($action == 'move') $return .= '<p class="lp_title">' . get_lang("MoveTheCurrentExercise") . '&nbsp;:</p>' . "\n";
  4845. else
  4846. $return .= '<p class="lp_title">' . get_lang("EditCurrentExecice") . '&nbsp;:</p>' . "\n";
  4847. if (isset ($_GET['edit']) && $_GET['edit'] == 'true') {
  4848. $return .= Display :: return_warning_message('<p class="lp_title">' . get_lang("Warning") . ' !</p>' . get_lang("WarningEditingDocument"));
  4849. }
  4850. $return .= '<form method="POST">' . "\n";
  4851. $return .= "\t" . '<table cellpadding="0" cellspacing="0" class="lp_form">' . "\n";
  4852. $return .= "\t\t" . '<tr>' . "\n";
  4853. $return .= "\t\t\t" . '<td class="label"><label for="idParent">' . get_lang("Parent") . ' :</label></td>' . "\n";
  4854. $return .= "\t\t\t" . '<td class="input">' . "\n";
  4855. $return .= "\t\t\t\t" . '<select id="idParent" name="parent" onchange="load_cbo(this.value);" size="1">';
  4856. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
  4857. $arrHide = array (
  4858. $id
  4859. );
  4860. if (count($arrLP) > 0) {
  4861. for ($i = 0; $i < count($arrLP); $i++) {
  4862. if ($action != 'add') {
  4863. 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)) {
  4864. $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'] . '">' . api_convert_encoding($arrLP[$i]['title'], $charset, $this->encoding) . '</option>';
  4865. } else {
  4866. $arrHide[] = $arrLP[$i]['id'];
  4867. }
  4868. } else {
  4869. if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
  4870. $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'] . '">' . api_convert_encoding($arrLP[$i]['title'], $charset, $this->encoding) . '</option>';
  4871. }
  4872. }
  4873. reset($arrLP);
  4874. }
  4875. $return .= "\t\t\t\t" . '</select>';
  4876. $return .= "\t\t\t" . '</td>' . "\n";
  4877. $return .= "\t\t" . '</tr>' . "\n";
  4878. $return .= "\t\t" . '<tr>' . "\n";
  4879. $return .= "\t\t\t" . '<td class="label"><label for="idPosition">' . get_lang("Position") . ' :</label></td>' . "\n";
  4880. $return .= "\t\t\t" . '<td class="input">' . "\n";
  4881. $return .= "\t\t\t\t" . '<select id="idPosition" name="previous" size="1">';
  4882. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . get_lang('FirstPosition') . '</option>';
  4883. for ($i = 0; $i < count($arrLP); $i++) {
  4884. if ($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) {
  4885. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  4886. $selected = 'selected="selected" ';
  4887. elseif ($action == 'add') $selected = 'selected="selected" ';
  4888. else
  4889. $selected = '';
  4890. $return .= "\t\t\t\t\t" . '<option ' . $selected . 'value="' . $arrLP[$i]['id'] . '">' . get_lang("After") . ' "' . api_convert_encoding($arrLP[$i]['title'], $charset, $this->encoding) . '"</option>';
  4891. }
  4892. }
  4893. $return .= "\t\t\t\t" . '</select>';
  4894. $return .= "\t\t\t" . '</td>' . "\n";
  4895. $return .= "\t\t" . '</tr>' . "\n";
  4896. if ($action != 'move') {
  4897. $return .= "\t\t" . '<tr>' . "\n";
  4898. $return .= "\t\t\t" . '<td class="label"><label for="idTitle">' . get_lang("Title") . ' :</label></td>' . "\n";
  4899. $return .= "\t\t\t" . '<td class="input"><input id="idTitle" name="title" type="text" value="' . $item_title . '" /></td>' . "\n";
  4900. $return .= "\t\t" . '</tr>' . "\n";
  4901. $id_prerequisite = 0;
  4902. if (is_array($arrLP) && count($arrLP) > 0) {
  4903. foreach ($arrLP as $key => $value) {
  4904. if ($value['id'] == $id) {
  4905. $id_prerequisite = $value['prerequisite'];
  4906. break;
  4907. }
  4908. }
  4909. $arrHide = array ();
  4910. for ($i = 0; $i < count($arrLP); $i++) {
  4911. if ($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter') {
  4912. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  4913. $s_selected_position = $arrLP[$i]['id'];
  4914. elseif ($action == 'add') $s_selected_position = 0;
  4915. $arrHide[$arrLP[$i]['id']]['value'] = api_convert_encoding($arrLP[$i]['title'], $charset, $this->encoding);
  4916. }
  4917. }
  4918. }
  4919. $return .= "\t\t" . '<tr>' . "\n";
  4920. //$return .= "\t\t\t" . '<td class="label"><label for="idPrerequisites">'.get_lang("Prerequisites").' :</label></td>' . "\n";
  4921. //$return .= "\t\t\t" . '<td class="input"><select name="prerequisites" id="prerequisites"><option value="0">'.get_lang("NoPrerequisites").'</option>';
  4922. foreach ($arrHide as $key => $value) {
  4923. if ($key == $s_selected_position && $action == 'add') {
  4924. $return .= '<option value="' . $key . '" selected="selected">' . $value['value'] . '</option>';
  4925. }
  4926. elseif ($key == $id_prerequisite && $action == 'edit') {
  4927. $return .= '<option value="' . $key . '" selected="selected">' . $value['value'] . '</option>';
  4928. } else {
  4929. $return .= '<option value="' . $key . '">' . $value['value'] . '</option>';
  4930. }
  4931. }
  4932. $return .= "</select></td>";
  4933. $return .= "\t\t" . '</tr>' . "\n";
  4934. $return .= "\t\t" . '<tr>' . "\n";
  4935. $return .= "\t\t" . '</tr>' . "\n";
  4936. }
  4937. $return .= "\t\t" . '<tr>' . "\n";
  4938. $return .= "\t\t\t" . '<td> &nbsp;</td><td><button class="save" name="submit_button" action="edit" type="submit">' . get_lang('SaveHotpotatoes') . '</button></td>' . "\n";
  4939. $return .= "\t\t" . '</tr>' . "\n";
  4940. $return .= "\t" . '</table>' . "\n";
  4941. if ($action == 'move') {
  4942. $return .= "\t" . '<input name="title" type="hidden" value="' . $item_title . '" />' . "\n";
  4943. $return .= "\t" . '<input name="description" type="hidden" value="' . $item_description . '" />' . "\n";
  4944. }
  4945. if (is_numeric($extra_info)) {
  4946. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info . '" />' . "\n";
  4947. }
  4948. elseif (is_array($extra_info)) {
  4949. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />' . "\n";
  4950. }
  4951. $return .= "\t" . '<input name="type" type="hidden" value="' . TOOL_HOTPOTATOES . '" />' . "\n";
  4952. $return .= "\t" . '<input name="post_time" type="hidden" value="' . time() . '" />' . "\n";
  4953. $return .= '</form>' . "\n";
  4954. $return .= '</div>' . "\n";
  4955. return $return;
  4956. }
  4957. /**
  4958. * Return the form to display the forum edit/add option
  4959. * @param string Action (add/edit)
  4960. * @param integer ID of the lp_item if already exists
  4961. * @param mixed Forum ID or title
  4962. * @return string HTML form
  4963. */
  4964. public function display_forum_form($action = 'add', $id = 0, $extra_info = '') {
  4965. global $charset;
  4966. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  4967. $tbl_forum = Database :: get_course_table(TABLE_FORUM);
  4968. if ($id != 0 && is_array($extra_info)) {
  4969. $item_title = stripslashes($extra_info['title']);
  4970. }
  4971. elseif (is_numeric($extra_info)) {
  4972. $sql_forum = "
  4973. SELECT
  4974. forum_title as title, forum_comment as comment
  4975. FROM " . $tbl_forum . "
  4976. WHERE forum_id = " . $extra_info;
  4977. $result = Database::query($sql_forum);
  4978. $row = Database :: fetch_array($result);
  4979. $item_title = $row['title'];
  4980. $item_description = $row['comment'];
  4981. } else {
  4982. $item_title = '';
  4983. $item_description = '';
  4984. }
  4985. $item_title = api_convert_encoding($item_title, $charset, $this->encoding);
  4986. $item_description = api_convert_encoding($item_description, $charset, $this->encoding);
  4987. $return = ' <div class="row">
  4988. <div class="form_header">';
  4989. if ($id != 0 && is_array($extra_info))
  4990. $parent = $extra_info['parent_item_id'];
  4991. else
  4992. $parent = 0;
  4993. $sql = "
  4994. SELECT *
  4995. FROM " . $tbl_lp_item . "
  4996. WHERE
  4997. lp_id = " . $this->lp_id;
  4998. $result = Database::query($sql);
  4999. $arrLP = array ();
  5000. while ($row = Database :: fetch_array($result)) {
  5001. $arrLP[] = array (
  5002. 'id' => $row['id'],
  5003. 'item_type' => $row['item_type'],
  5004. 'title' => $row['title'],
  5005. 'path' => $row['path'],
  5006. 'description' => $row['description'],
  5007. 'parent_item_id' => $row['parent_item_id'],
  5008. 'previous_item_id' => $row['previous_item_id'],
  5009. 'next_item_id' => $row['next_item_id'],
  5010. 'display_order' => $row['display_order'],
  5011. 'max_score' => $row['max_score'],
  5012. 'min_score' => $row['min_score'],
  5013. 'mastery_score' => $row['mastery_score'],
  5014. 'prerequisite' => $row['prerequisite']
  5015. );
  5016. }
  5017. $this->tree_array($arrLP);
  5018. $arrLP = $this->arrMenu;
  5019. unset ($this->arrMenu);
  5020. if ($action == 'add')
  5021. $return .= get_lang("CreateTheForum") . '&nbsp;:' . "\n";
  5022. elseif ($action == 'move') $return .= get_lang("MoveTheCurrentForum") . '&nbsp;:' . "\n";
  5023. else
  5024. $return .= get_lang("EditCurrentForum") . '&nbsp;:' . "\n";
  5025. $return .= ' </div>
  5026. </div>';
  5027. $return .= '<div class="sectioncomment">';
  5028. $return .= '<form method="POST">' . "\n";
  5029. $return .= "\t" . '<table class="lp_form">' . "\n";
  5030. if ($action != 'move') {
  5031. $return .= "\t\t" . '<tr>' . "\n";
  5032. $return .= "\t\t\t" . '<td class="label"><label for="idTitle">' . get_lang('Title') . '</label></td>' . "\n";
  5033. $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";
  5034. $return .= "\t\t" . '</tr>' . "\n";
  5035. }
  5036. $return .= "\t\t" . '<tr>' . "\n";
  5037. $return .= "\t\t\t" . '<td class="label"><label for="idParent">' . get_lang('Parent') . '</label></td>' . "\n";
  5038. $return .= "\t\t\t" . '<td class="input">' . "\n";
  5039. $return .= "\t\t\t\t" . '<select id="idParent" style="width:100%;" name="parent" onchange="load_cbo(this.value);" class="learnpath_item_form" size="1">';
  5040. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
  5041. $arrHide = array (
  5042. $id
  5043. );
  5044. //$parent_item_id = $_SESSION['parent_item_id'];
  5045. for ($i = 0; $i < count($arrLP); $i++) {
  5046. if ($action != 'add') {
  5047. 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)) {
  5048. $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'] . '">' . api_convert_encoding($arrLP[$i]['title'], $charset, $this->encoding) . '</option>';
  5049. } else {
  5050. $arrHide[] = $arrLP[$i]['id'];
  5051. }
  5052. } else {
  5053. if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
  5054. $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'] . '">' . api_convert_encoding($arrLP[$i]['title'], $charset, $this->encoding) . '</option>';
  5055. }
  5056. }
  5057. if (is_array($arrLP)) {
  5058. reset($arrLP);
  5059. }
  5060. $return .= "\t\t\t\t" . '</select>';
  5061. $return .= "\t\t\t" . '</td>' . "\n";
  5062. $return .= "\t\t" . '</tr>' . "\n";
  5063. $return .= "\t\t" . '<tr>' . "\n";
  5064. $return .= "\t\t\t" . '<td class="label"><label for="idPosition">' . get_lang('Position') . '</label></td>' . "\n";
  5065. $return .= "\t\t\t" . '<td class="input">' . "\n";
  5066. $return .= "\t\t\t\t" . '<select id="idPosition" name="previous" style="width:100%;" size="1" class="learnpath_item_form">';
  5067. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . get_lang('FirstPosition') . '</option>';
  5068. for ($i = 0; $i < count($arrLP); $i++) {
  5069. if ($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) {
  5070. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5071. $selected = 'selected="selected" ';
  5072. elseif ($action == 'add') $selected = 'selected="selected" ';
  5073. else
  5074. $selected = '';
  5075. $return .= "\t\t\t\t\t" . '<option ' . $selected . 'value="' . $arrLP[$i]['id'] . '">' . get_lang("After") . ' "' . api_convert_encoding($arrLP[$i]['title'], $charset, $this->encoding) . '"</option>';
  5076. }
  5077. }
  5078. $return .= "\t\t\t\t" . '</select>';
  5079. $return .= "\t\t\t" . '</td>' . "\n";
  5080. $return .= "\t\t" . '</tr>' . "\n";
  5081. if ($action != 'move') {
  5082. $return .= "\t\t" . '<tr>' . "\n";
  5083. $return .= "\t\t" . '</tr>' . "\n";
  5084. $id_prerequisite = 0;
  5085. if (is_array($arrLP)) {
  5086. foreach ($arrLP as $key => $value) {
  5087. if ($value['id'] == $id) {
  5088. $id_prerequisite = $value['prerequisite'];
  5089. break;
  5090. }
  5091. }
  5092. }
  5093. $arrHide = array ();
  5094. for ($i = 0; $i < count($arrLP); $i++) {
  5095. if ($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter') {
  5096. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5097. $s_selected_position = $arrLP[$i]['id'];
  5098. elseif ($action == 'add') $s_selected_position = 0;
  5099. $arrHide[$arrLP[$i]['id']]['value'] = api_convert_encoding($arrLP[$i]['title'], $charset, $this->encoding);
  5100. }
  5101. }
  5102. $return .= "\t\t" . '</tr>' . "\n";
  5103. }
  5104. $return .= "\t\t" . '<tr>' . "\n";
  5105. if ($action == 'add') {
  5106. $return .= '<td>&nbsp;</td><td><button class="save" name="submit_button" type="submit"> ' . get_lang('AddForumToCourse') . ' </button></td>';
  5107. } else {
  5108. $return .= '<td>&nbsp;</td><td><button class="save" name="submit_button" type="submit"> ' . get_lang('EditCurrentForum') . ' </button></td>';
  5109. }
  5110. $return .= "\t\t" . '</tr>' . "\n";
  5111. $return .= "\t" . '</table>' . "\n";
  5112. if ($action == 'move') {
  5113. $return .= "\t" . '<input name="title" type="hidden" value="' . $item_title . '" />' . "\n";
  5114. $return .= "\t" . '<input name="description" type="hidden" value="' . $item_description . '" />' . "\n";
  5115. }
  5116. if (is_numeric($extra_info)) {
  5117. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info . '" />' . "\n";
  5118. }
  5119. elseif (is_array($extra_info)) {
  5120. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />' . "\n";
  5121. }
  5122. $return .= "\t" . '<input name="type" type="hidden" value="' . TOOL_FORUM . '" />' . "\n";
  5123. $return .= "\t" . '<input name="post_time" type="hidden" value="' . time() . '" />' . "\n";
  5124. $return .= '</form>' . "\n";
  5125. $return .= '</div>' . "\n";
  5126. return $return;
  5127. }
  5128. /**
  5129. * Return HTML form to add/edit forum threads
  5130. * @param string Action (add/edit)
  5131. * @param integer Item ID if already exists in learning path
  5132. * @param mixed Extra information (thread ID if integer)
  5133. * @return string HTML form
  5134. */
  5135. public function display_thread_form($action = 'add', $id = 0, $extra_info = '') {
  5136. global $charset;
  5137. echo '
  5138. <style>
  5139. div.row div.label {
  5140. width:110px;
  5141. }
  5142. div.row div.formw {
  5143. width: 82%;
  5144. }
  5145. </style>';
  5146. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  5147. $tbl_forum = Database :: get_course_table(TABLE_FORUM_THREAD);
  5148. if ($id != 0 && is_array($extra_info)) {
  5149. $item_title = stripslashes($extra_info['title']);
  5150. }
  5151. elseif (is_numeric($extra_info)) {
  5152. $sql_forum = "
  5153. SELECT
  5154. thread_title as title
  5155. FROM " . $tbl_forum . "
  5156. WHERE thread_id = " . $extra_info;
  5157. $result = Database::query($sql_forum);
  5158. $row = Database :: fetch_array($result);
  5159. $item_title = $row['title'];
  5160. $item_description = '';
  5161. } else {
  5162. $item_title = '';
  5163. $item_description = '';
  5164. }
  5165. $item_title = api_convert_encoding($item_title, $charset, $this->encoding);
  5166. $item_description = api_convert_encoding($item_description, $charset, $this->encoding);
  5167. $return = '<div style="margin:3px 12px;">';
  5168. if ($id != 0 && is_array($extra_info))
  5169. $parent = $extra_info['parent_item_id'];
  5170. else
  5171. $parent = 0;
  5172. $sql = "
  5173. SELECT *
  5174. FROM " . $tbl_lp_item . "
  5175. WHERE
  5176. lp_id = " . $this->lp_id;
  5177. $result = Database::query($sql);
  5178. $arrLP = array ();
  5179. while ($row = Database :: fetch_array($result)) {
  5180. $arrLP[] = array (
  5181. 'id' => $row['id'],
  5182. 'item_type' => $row['item_type'],
  5183. 'title' => $row['title'],
  5184. 'path' => $row['path'],
  5185. 'description' => $row['description'],
  5186. 'parent_item_id' => $row['parent_item_id'],
  5187. 'previous_item_id' => $row['previous_item_id'],
  5188. 'next_item_id' => $row['next_item_id'],
  5189. 'display_order' => $row['display_order'],
  5190. 'max_score' => $row['max_score'],
  5191. 'min_score' => $row['min_score'],
  5192. 'mastery_score' => $row['mastery_score'],
  5193. 'prerequisite' => $row['prerequisite']
  5194. );
  5195. }
  5196. $this->tree_array($arrLP);
  5197. $arrLP = $this->arrMenu;
  5198. unset ($this->arrMenu);
  5199. if ($action == 'add')
  5200. $return .= '<p class="lp_title">' . get_lang("CreateTheForum") . '&nbsp;:</p>' . "\n";
  5201. elseif ($action == 'move') $return .= '<p class="lp_title">' . get_lang("MoveTheCurrentForum") . '&nbsp;:</p>' . "\n";
  5202. else
  5203. $return .= '<p class="lp_title">' . get_lang("EditCurrentForum") . '&nbsp;:</p>' . "\n";
  5204. $return .= '<form method="POST">' . "\n";
  5205. $return .= "\t" . '<table cellpadding="0" cellspacing="0" class="lp_form">' . "\n";
  5206. $return .= "\t\t" . '<tr>' . "\n";
  5207. $return .= "\t\t\t" . '<td class="label"><label for="idParent">' . get_lang("Parent") . '&nbsp;:</label></td>' . "\n";
  5208. $return .= "\t\t\t" . '<td class="input">' . "\n";
  5209. $return .= "\t\t\t\t" . '<select id="idParent" name="parent" onchange="load_cbo(this.value);" size="1">';
  5210. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
  5211. $arrHide = array (
  5212. $id
  5213. );
  5214. for ($i = 0; $i < count($arrLP); $i++) {
  5215. if ($action != 'add') {
  5216. 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)) {
  5217. $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'] . '">' . api_convert_encoding($arrLP[$i]['title'], $charset, $this->encoding) . '</option>';
  5218. } else {
  5219. $arrHide[] = $arrLP[$i]['id'];
  5220. }
  5221. } else {
  5222. if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
  5223. $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'] . '">' . api_convert_encoding($arrLP[$i]['title'], $charset, $this->encoding) . '</option>';
  5224. }
  5225. }
  5226. if ($arrLP != null) {
  5227. reset($arrLP);
  5228. }
  5229. $return .= "\t\t\t\t" . '</select>';
  5230. $return .= "\t\t\t" . '</td>' . "\n";
  5231. $return .= "\t\t" . '</tr>' . "\n";
  5232. $return .= "\t\t" . '<tr>' . "\n";
  5233. $return .= "\t\t\t" . '<td class="label"><label for="idPosition">' . get_lang("Position") . '&nbsp;:</label></td>' . "\n";
  5234. $return .= "\t\t\t" . '<td class="input">' . "\n";
  5235. $return .= "\t\t\t\t" . '<select id="idPosition" name="previous" size="1">';
  5236. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . get_lang('FirstPosition') . '</option>';
  5237. for ($i = 0; $i < count($arrLP); $i++) {
  5238. if ($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) {
  5239. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5240. $selected = 'selected="selected" ';
  5241. elseif ($action == 'add') $selected = 'selected="selected" ';
  5242. else
  5243. $selected = '';
  5244. $return .= "\t\t\t\t\t" . '<option ' . $selected . 'value="' . $arrLP[$i]['id'] . '">' . get_lang("After") . ' "' . api_convert_encoding($arrLP[$i]['title'], $charset, $this->encoding) . '"</option>';
  5245. }
  5246. }
  5247. $return .= "\t\t\t\t" . '</select>';
  5248. $return .= "\t\t\t" . '</td>' . "\n";
  5249. $return .= "\t\t" . '</tr>' . "\n";
  5250. if ($action != 'move') {
  5251. $return .= "\t\t" . '<tr>' . "\n";
  5252. $return .= "\t\t\t" . '<td class="label"><label for="idTitle">' . get_lang("Title") . '&nbsp;:</label></td>' . "\n";
  5253. $return .= "\t\t\t" . '<td class="input"><input id="idTitle" name="title" type="text" value="' . $item_title . '" /></td>' . "\n";
  5254. $return .= "\t\t" . '</tr>' . "\n";
  5255. $return .= "\t\t" . '<tr>' . "\n";
  5256. $return .= "\t\t" . '</tr>' . "\n";
  5257. $id_prerequisite = 0;
  5258. if ($arrLP != null) {
  5259. foreach ($arrLP as $key => $value) {
  5260. if ($value['id'] == $id) {
  5261. $id_prerequisite = $value['prerequisite'];
  5262. break;
  5263. }
  5264. }
  5265. }
  5266. $arrHide = array ();
  5267. for ($i = 0; $i < count($arrLP); $i++) {
  5268. if ($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter') {
  5269. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5270. $s_selected_position = $arrLP[$i]['id'];
  5271. elseif ($action == 'add') $s_selected_position = 0;
  5272. $arrHide[$arrLP[$i]['id']]['value'] = api_convert_encoding($arrLP[$i]['title'], $charset, $this->encoding);
  5273. }
  5274. }
  5275. $return .= "\t\t" . '<tr>' . "\n";
  5276. $return .= "\t\t\t" . '<td class="label"><label for="idPrerequisites">' . get_lang("Prerequisites") . '&nbsp;:</label></td>' . "\n";
  5277. $return .= "\t\t\t" . '<td class="input"><select name="prerequisites" id="prerequisites"><option value="0">' . get_lang("NoPrerequisites") . '</option>';
  5278. foreach ($arrHide as $key => $value) {
  5279. if ($key == $s_selected_position && $action == 'add') {
  5280. $return .= '<option value="' . $key . '" selected="selected">' . $value['value'] . '</option>';
  5281. }
  5282. elseif ($key == $id_prerequisite && $action == 'edit') {
  5283. $return .= '<option value="' . $key . '" selected="selected">' . $value['value'] . '</option>';
  5284. } else {
  5285. $return .= '<option value="' . $key . '">' . $value['value'] . '</option>';
  5286. }
  5287. }
  5288. $return .= "</select></td>";
  5289. $return .= "\t\t" . '</tr>' . "\n";
  5290. }
  5291. $return .= "\t\t" . '<tr>' . "\n";
  5292. $return .= "\t\t\t" . '<td colspan="2">
  5293. <button class="save" name="submit_button" type="submit" value="'.get_lang('Ok').'" />'.get_lang('Ok').'</button></td>' . "\n";
  5294. $return .= "\t\t" . '</tr>' . "\n";
  5295. $return .= "\t" . '</table>' . "\n";
  5296. if ($action == 'move') {
  5297. $return .= "\t" . '<input name="title" type="hidden" value="' . $item_title . '" />' . "\n";
  5298. $return .= "\t" . '<input name="description" type="hidden" value="' . $item_description . '" />' . "\n";
  5299. }
  5300. if (is_numeric($extra_info)) {
  5301. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info . '" />' . "\n";
  5302. }
  5303. elseif (is_array($extra_info)) {
  5304. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />' . "\n";
  5305. }
  5306. $return .= "\t" . '<input name="type" type="hidden" value="' . TOOL_THREAD . '" />' . "\n";
  5307. $return .= "\t" . '<input name="post_time" type="hidden" value="' . time() . '" />' . "\n";
  5308. $return .= '</form>' . "\n";
  5309. $return .= '</div>' . "\n";
  5310. return $return;
  5311. }
  5312. /**
  5313. * Return the HTML form to display an item (generally a section/module item)
  5314. * @param string Item type (module/dokeos_module)
  5315. * @param string Title (optional, only when creating)
  5316. * @param string Action ('add'/'edit')
  5317. * @param integer lp_item ID
  5318. * @param mixed Extra info
  5319. * @return string HTML form
  5320. */
  5321. public function display_item_form($item_type, $title = '', $action = 'add', $id = 0, $extra_info = 'new') {
  5322. global $_course;
  5323. global $charset;
  5324. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  5325. if ($id != 0 && is_array($extra_info)) {
  5326. $item_title = $extra_info['title'];
  5327. $item_description = $extra_info['description'];
  5328. $item_path = api_get_path(WEB_COURSE_PATH) . $_course['path'] . '/scorm/' . $this->path . '/' . stripslashes($extra_info['path']);
  5329. } else {
  5330. $item_title = '';
  5331. $item_description = '';
  5332. }
  5333. $return = ' <div class="row">
  5334. <div class="form_header">';
  5335. if ($id != 0 && is_array($extra_info))
  5336. $parent = $extra_info['parent_item_id'];
  5337. else
  5338. $parent = 0;
  5339. $sql = "
  5340. SELECT *
  5341. FROM " . $tbl_lp_item . "
  5342. WHERE lp_id = " . $this->lp_id . " AND id != " . $id . " ";
  5343. if ($item_type == 'module')
  5344. $sql .= " AND parent_item_id = 0";
  5345. $result = Database::query($sql);
  5346. $arrLP = array ();
  5347. while ($row = Database :: fetch_array($result)) {
  5348. $arrLP[] = array (
  5349. 'id' => $row['id'],
  5350. 'item_type' => $row['item_type'],
  5351. 'title' => $row['title'],
  5352. 'path' => $row['path'],
  5353. 'description' => $row['description'],
  5354. 'parent_item_id' => $row['parent_item_id'],
  5355. 'previous_item_id' => $row['previous_item_id'],
  5356. 'next_item_id' => $row['next_item_id'],
  5357. 'max_score' => $row['max_score'],
  5358. 'min_score' => $row['min_score'],
  5359. 'mastery_score' => $row['mastery_score'],
  5360. 'prerequisite' => $row['prerequisite'],
  5361. 'display_order' => $row['display_order']
  5362. );
  5363. }
  5364. $this->tree_array($arrLP);
  5365. $arrLP = $this->arrMenu;
  5366. unset ($this->arrMenu);
  5367. $return .= $title . "\n";
  5368. $return .= ' </div>
  5369. </div>';
  5370. require_once api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php';
  5371. $form = new FormValidator('form', 'POST', api_get_self() . "?" . $_SERVER["QUERY_STRING"]);
  5372. //$defaults["title"] = api_convert_encoding($item_title, $charset, $this->encoding);
  5373. $defaults["title"] = api_html_entity_decode(api_convert_encoding($item_title, $charset, $this->encoding), ENT_QUOTES, $charset);
  5374. $defaults["description"] = api_convert_encoding($item_description, $charset, $this->encoding);
  5375. $form->addElement('html', $return);
  5376. //$arrHide = array($id);
  5377. $arrHide[0]['value'] = Security :: remove_XSS(api_convert_encoding($this->name, api_get_system_encoding(), $_SESSION['oLP']->encoding));
  5378. $arrHide[0]['padding'] = 3;
  5379. $charset = api_get_system_encoding();
  5380. if ($item_type != 'module' && $item_type != 'dokeos_module') {
  5381. for ($i = 0; $i < count($arrLP); $i++) {
  5382. if ($action != 'add') {
  5383. 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)) {
  5384. $arrHide[$arrLP[$i]['id']]['value'] = api_convert_encoding($arrLP[$i]['title'], $charset, $this->encoding);
  5385. $arrHide[$arrLP[$i]['id']]['padding'] = 3 + $arrLP[$i]['depth'] * 10;
  5386. if ($parent == $arrLP[$i]['id']) {
  5387. $s_selected_parent = $arrHide[$arrLP[$i]['id']];
  5388. }
  5389. }
  5390. } else {
  5391. if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir') {
  5392. $arrHide[$arrLP[$i]['id']]['value'] = api_convert_encoding($arrLP[$i]['title'], $charset, $this->encoding);
  5393. $arrHide[$arrLP[$i]['id']]['padding'] = 3 + $arrLP[$i]['depth'] * 10;
  5394. if ($parent == $arrLP[$i]['id']) {
  5395. $s_selected_parent = $arrHide[$arrLP[$i]['id']];
  5396. }
  5397. }
  5398. }
  5399. }
  5400. if ($action != 'move') {
  5401. $form->addElement('text', 'title', get_lang('Title'), 'id="idTitle" class="learnpath_chapter_form" size="40%"');
  5402. $form->applyFilter('title', 'html_filter');
  5403. $form->addRule('title', '<div class="required">' . get_lang('ThisFieldIsRequired'), 'required');
  5404. //$form->addElement('textarea','description',get_lang("Description").' :', 'id="idDescription"');
  5405. } else {
  5406. $form->addElement('hidden', 'title');
  5407. }
  5408. $parent_select = & $form->addElement('select', 'parent', get_lang("Parent"), '', 'class="learnpath_chapter_form" style="width:37%;" id="Parent" onchange="load_cbo(this.value);"');
  5409. foreach ($arrHide as $key => $value) {
  5410. $parent_select->addOption($value['value'], $key, 'style="padding-left:' . $value['padding'] . 'px;"');
  5411. }
  5412. $parent_select->setSelected($s_selected_parent);
  5413. }
  5414. if (is_array($arrLP)) {
  5415. reset($arrLP);
  5416. }
  5417. $arrHide = array ();
  5418. //POSITION
  5419. for ($i = 0; $i < count($arrLP); $i++) {
  5420. if ($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) {
  5421. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5422. $s_selected_position = $arrLP[$i]['id'];
  5423. elseif ($action == 'add') $s_selected_position = $arrLP[$i]['id'];
  5424. $arrHide[$arrLP[$i]['id']]['value'] = get_lang("After") . ' "' . api_convert_encoding($arrLP[$i]['title'], $charset, $this->encoding);
  5425. }
  5426. }
  5427. $position = & $form->addElement('select', 'previous', get_lang('Position'), '', 'id="idPosition" class="learnpath_chapter_form" style="width:37%;"');
  5428. $position->addOption(get_lang('FirstPosition'), 0, 'style="padding-left:' . $value['padding'] . 'px;"');
  5429. foreach ($arrHide as $key => $value) {
  5430. $position->addOption($value['value'] . '"', $key, 'style="padding-left:' . $value['padding'] . 'px;"');
  5431. }
  5432. if (!empty ($s_selected_position)) {
  5433. $position->setSelected($s_selected_position);
  5434. }
  5435. if (is_array($arrLP)) {
  5436. reset($arrLP);
  5437. }
  5438. $form->addElement('style_submit_button', 'submit_button', get_lang('SaveSection'), 'class="save"');
  5439. if ($item_type == 'module' || $item_type == 'dokeos_module') {
  5440. $form->addElement('hidden', 'parent', '0');
  5441. }
  5442. $extension = pathinfo($item_path, PATHINFO_EXTENSION);
  5443. if (($item_type == 'asset' || $item_type == 'sco') && ($extension == 'html' || $extension == 'htm')) {
  5444. if ($item_type == 'sco') {
  5445. $form->addElement('html', '<script type="text/javascript">alert("' . get_lang('WarningWhenEditingScorm') . '")</script>');
  5446. }
  5447. $renderer = $form->defaultRenderer();
  5448. $renderer->setElementTemplate('<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{label}<br />{element}', 'content_lp');
  5449. $form->addElement('html_editor', 'content_lp', '', null, array('ToolbarSet' => 'LearningPathDocuments', 'Width' => '100%', 'Height' => '400', 'FullPage' => true));
  5450. $defaults["content_lp"] = file_get_contents($item_path);
  5451. }
  5452. $form->addElement('hidden', 'type', 'dokeos_' . $item_type);
  5453. $form->addElement('hidden', 'post_time', time());
  5454. $form->setDefaults($defaults);
  5455. return $form->return_form();
  5456. }
  5457. /**
  5458. * Returns the form to update or create a document
  5459. * @param string Action (add/edit)
  5460. * @param integer ID of the lp_item (if already exists)
  5461. * @param mixed Integer if document ID, string if info ('new')
  5462. * @return string HTML form
  5463. */
  5464. public function display_document_form($action = 'add', $id = 0, $extra_info = 'new') {
  5465. global $charset;
  5466. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  5467. $tbl_doc = Database :: get_course_table(TABLE_DOCUMENT);
  5468. $path_parts = pathinfo($extra_info['dir']);
  5469. $no_display_edit_textarea = false;
  5470. //If action==edit document
  5471. //We don't display the document form if it's not an editable document (html or txt file)
  5472. if ($action == "edit") {
  5473. if (is_array($extra_info)) {
  5474. if ($path_parts['extension'] != "txt" && $path_parts['extension'] != "html") {
  5475. $no_display_edit_textarea = true;
  5476. }
  5477. }
  5478. }
  5479. $no_display_add = false;
  5480. //If action==add an existing document
  5481. //We don't display the document form if it's not an editable document (html or txt file)
  5482. if ($action == "add") {
  5483. if (is_numeric($extra_info)) {
  5484. $sql_doc = "SELECT path FROM " . $tbl_doc . "WHERE id = " . Database :: escape_string($extra_info);
  5485. $result = Database::query($sql_doc);
  5486. $path_file = Database :: result($result, 0, 0);
  5487. $path_parts = pathinfo($path_file);
  5488. if ($path_parts['extension'] != "txt" && $path_parts['extension'] != "html") {
  5489. $no_display_add = true;
  5490. }
  5491. }
  5492. }
  5493. if ($id != 0 && is_array($extra_info)) {
  5494. $item_title = stripslashes($extra_info['title']);
  5495. $item_description = stripslashes($extra_info['description']);
  5496. $item_terms = stripslashes($extra_info['terms']);
  5497. if (empty ($item_title)) {
  5498. $path_parts = pathinfo($extra_info['path']);
  5499. $item_title = stripslashes($path_parts['filename']);
  5500. }
  5501. } elseif (is_numeric($extra_info)) {
  5502. $sql_doc = "SELECT path, title FROM " . $tbl_doc . "
  5503. WHERE id = " . Database :: escape_string($extra_info);
  5504. $result = Database::query($sql_doc);
  5505. $row = Database :: fetch_array($result);
  5506. $explode = explode('.', $row['title']);
  5507. if (count($explode) > 1) {
  5508. for ($i = 0; $i < count($explode) - 1; $i++)
  5509. $item_title .= $explode[$i];
  5510. } else {
  5511. $item_title = $row['title'];
  5512. }
  5513. $item_title = str_replace('_', ' ', $item_title);
  5514. if (empty ($item_title)) {
  5515. $path_parts = pathinfo($row['path']);
  5516. $item_title = stripslashes($path_parts['filename']);
  5517. }
  5518. } else {
  5519. $item_title = '';
  5520. $item_description = '';
  5521. }
  5522. $return = ' <div class="row">
  5523. <div class="form_header">';
  5524. if ($id != 0 && is_array($extra_info))
  5525. $parent = $extra_info['parent_item_id'];
  5526. else
  5527. $parent = 0;
  5528. $sql = "SELECT * FROM " . $tbl_lp_item . "
  5529. WHERE lp_id = " . $this->lp_id;
  5530. $result = Database::query($sql);
  5531. $arrLP = array ();
  5532. while ($row = Database :: fetch_array($result)) {
  5533. $arrLP[] = array (
  5534. 'id' => $row['id'],
  5535. 'item_type' => $row['item_type'],
  5536. 'title' => $row['title'],
  5537. 'path' => $row['path'],
  5538. 'description' => $row['description'],
  5539. 'parent_item_id' => $row['parent_item_id'],
  5540. 'previous_item_id' => $row['previous_item_id'],
  5541. 'next_item_id' => $row['next_item_id'],
  5542. 'display_order' => $row['display_order'],
  5543. 'max_score' => $row['max_score'],
  5544. 'min_score' => $row['min_score'],
  5545. 'mastery_score' => $row['mastery_score'],
  5546. 'prerequisite' => $row['prerequisite']
  5547. );
  5548. }
  5549. $this->tree_array($arrLP);
  5550. $arrLP = $this->arrMenu;
  5551. unset ($this->arrMenu);
  5552. if ($action == 'add') {
  5553. $return .= get_lang("CreateTheDocument") . "\n";
  5554. }
  5555. elseif ($action == 'move') {
  5556. $return .= get_lang("MoveTheCurrentDocument") . "\n";
  5557. } else {
  5558. $return .= get_lang("EditTheCurrentDocument") . "\n";
  5559. }
  5560. $return .= '</div>
  5561. </div>';
  5562. if (isset ($_GET['edit']) && $_GET['edit'] == 'true') {
  5563. $return .= Display :: return_warning_message('<strong>' . get_lang("Warning") . ' !</strong><br />' . get_lang("WarningEditingDocument"), false);
  5564. }
  5565. require_once api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php';
  5566. $form = new FormValidator('form', 'POST', api_get_self() . "?" . $_SERVER["QUERY_STRING"], '', 'enctype="multipart/form-data"');
  5567. $defaults["title"] = Security :: remove_XSS(api_convert_encoding($item_title, api_get_system_encoding() ,$this->encoding));
  5568. if (empty ($item_title)) {
  5569. $defaults["title"] = Security::remove_XSS($item_title);
  5570. }
  5571. $defaults["description"] = api_convert_encoding($item_description, $charset, $this->encoding);
  5572. $form->addElement('html', $return);
  5573. if ($action != 'move') {
  5574. $form->addElement('text', 'title', get_lang('Title'), 'id="idTitle" class="learnpath_item_form" size=44%');
  5575. $form->applyFilter('title', 'html_filter');
  5576. }
  5577. //$arrHide = array($id);
  5578. $arrHide[0]['value'] = $this->name;
  5579. $arrHide[0]['padding'] = 3;
  5580. for ($i = 0; $i < count($arrLP); $i++) {
  5581. if ($action != 'add') {
  5582. 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)) {
  5583. $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
  5584. $arrHide[$arrLP[$i]['id']]['padding'] = 3 + $arrLP[$i]['depth'] * 10;
  5585. if ($parent == $arrLP[$i]['id']) {
  5586. $s_selected_parent = $arrHide[$arrLP[$i]['id']];
  5587. }
  5588. }
  5589. } else {
  5590. if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir') {
  5591. $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
  5592. $arrHide[$arrLP[$i]['id']]['padding'] = 3 + $arrLP[$i]['depth'] * 10;
  5593. if ($parent == $arrLP[$i]['id']) {
  5594. $s_selected_parent = $arrHide[$arrLP[$i]['id']];
  5595. }
  5596. }
  5597. }
  5598. }
  5599. $parent_select = & $form->addElement('select', 'parent', get_lang('Parent'), '', 'class="learnpath_item_form" style="width:40%;" onchange="load_cbo(this.value);"');
  5600. $my_count=0;
  5601. foreach ($arrHide as $key => $value) {
  5602. if ($my_count!=0) {
  5603. // the LP name is also the first section and is not in the same charset like the other sections
  5604. $value['value'] = Security :: remove_XSS(api_convert_encoding($value['value'], api_get_system_encoding(), $this->encoding));
  5605. $parent_select->addOption($value['value'], $key, 'style="padding-left:' . $value['padding'] . 'px;"');
  5606. } else {
  5607. $value['value'] = Security :: remove_XSS($value['value']);
  5608. $parent_select->addOption($value['value'], $key, 'style="padding-left:' . $value['padding'] . 'px;"');
  5609. }
  5610. $my_count++;
  5611. }
  5612. if (!empty ($id)) {
  5613. $parent_select->setSelected($parent);
  5614. } else {
  5615. $parent_item_id = $_SESSION['parent_item_id'];
  5616. $parent_select->setSelected($parent_item_id);
  5617. }
  5618. if (is_array($arrLP)) {
  5619. reset($arrLP);
  5620. }
  5621. $arrHide = array ();
  5622. //POSITION
  5623. for ($i = 0; $i < count($arrLP); $i++) {
  5624. if ($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) {
  5625. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5626. $s_selected_position = $arrLP[$i]['id'];
  5627. elseif ($action == 'add') $s_selected_position = $arrLP[$i]['id'];
  5628. $arrHide[$arrLP[$i]['id']]['value'] = get_lang("After") . ' "' . api_convert_encoding($arrLP[$i]['title'], $charset, $this->encoding) . '"';
  5629. }
  5630. }
  5631. $position = & $form->addElement('select', 'previous', get_lang('Position'), '', 'id="idPosition" class="learnpath_item_form" style="width:40%;"');
  5632. $position->addOption(get_lang("FirstPosition"), 0);
  5633. foreach ($arrHide as $key => $value) {
  5634. $position->addOption($value['value'], $key, 'style="padding-left:' . $value['padding'] . 'px;"');
  5635. }
  5636. $position->setSelected($s_selected_position);
  5637. if (is_array($arrLP)) {
  5638. reset($arrLP);
  5639. }
  5640. if ($action != 'move') {
  5641. $id_prerequisite = 0;
  5642. if (is_array($arrLP)) {
  5643. foreach ($arrLP as $key => $value) {
  5644. if ($value['id'] == $id) {
  5645. $id_prerequisite = $value['prerequisite'];
  5646. break;
  5647. }
  5648. }
  5649. }
  5650. //comented the prerequisites, only visible in edit (new document)
  5651. //$select_prerequisites=$form->addElement('select', 'prerequisites', get_lang('Prerequisites'),null,'id="prerequisites" class="learnpath_item_form" style="width:263px;"');
  5652. //$select_prerequisites->addOption(get_lang("NoPrerequisites"),0);
  5653. // form element for uploading an mp3 file
  5654. //$form->addElement('file','mp3',get_lang('UploadMp3audio'),'id="mp3" size="33"');
  5655. //$form->addRule('file', 'The extension of the Song file should be *.mp3', 'filename', '/^.*\.mp3$/');
  5656. /* Code deprecated - moved to lp level (not lp-item)
  5657. if ( api_get_setting('search_enabled') === 'true' )
  5658. {
  5659. //add terms field
  5660. $terms = $form->addElement('text','terms', get_lang('SearchFeatureTerms').'&nbsp;:','id="idTerms" class="learnpath_item_form"');
  5661. $terms->setValue($item_terms);
  5662. }
  5663. */
  5664. $arrHide = array ();
  5665. for ($i = 0; $i < count($arrLP); $i++) {
  5666. if ($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter') {
  5667. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5668. $s_selected_position = $arrLP[$i]['id'];
  5669. elseif ($action == 'add') $s_selected_position = $arrLP[$i]['id'];
  5670. $arrHide[$arrLP[$i]['id']]['value'] = api_convert_encoding($arrLP[$i]['title'], $charset, $this->encoding);
  5671. }
  5672. }
  5673. /* foreach($arrHide as $key => $value){
  5674. $select_prerequisites->addOption($value['value'],$key,'style="padding-left:'.$value['padding'].'px;"');
  5675. if($key==$s_selected_position && $action == 'add'){
  5676. $select_prerequisites -> setSelected(0);
  5677. }
  5678. elseif($key==$id_prerequisite && $action == 'edit'){
  5679. $select_prerequisites -> setSelected($id_prerequisite);
  5680. }
  5681. }
  5682. */
  5683. if (!$no_display_add) {
  5684. if (($extra_info == 'new' || $extra_info['item_type'] == TOOL_DOCUMENT || $_GET['edit'] == 'true')) {
  5685. if (isset ($_POST['content']))
  5686. $content = stripslashes($_POST['content']);
  5687. elseif (is_array($extra_info)) {
  5688. //If it's an html document or a text file
  5689. if (!$no_display_edit_textarea) {
  5690. $content = $this->display_document($extra_info['path'], false, false);
  5691. }
  5692. }
  5693. elseif (is_numeric($extra_info)) $content = $this->display_document($extra_info, false, false);
  5694. else
  5695. $content = '';
  5696. if (!$no_display_edit_textarea) {
  5697. // We need to claculate here some specific settings for the online editor.
  5698. // The calculated settings work for documents in the Documents tool
  5699. // (on the root or in subfolders).
  5700. // For documents in native scorm packages it is unclear whether the
  5701. // online editor should be activated or not.
  5702. $relative_path = $extra_info['dir'];
  5703. if ($relative_path == 'n/') {
  5704. // A new document, it is in the root of the repository.
  5705. $relative_path = '';
  5706. $relative_prefix = '';
  5707. } else {
  5708. // The document already exists. Whe have to determine its relative path towards the repository root.
  5709. $relative_path = explode('/', $relative_path);
  5710. $cnt = count($relative_path) - 2;
  5711. if ($cnt < 0) {
  5712. $cnt = 0;
  5713. }
  5714. $relative_prefix = str_repeat('../', $cnt);
  5715. $relative_path = array_slice($relative_path, 1, $cnt);
  5716. $relative_path = implode('/', $relative_path);
  5717. if (strlen($relative_path) > 0) {
  5718. $relative_path = $relative_path . '/';
  5719. }
  5720. }
  5721. $editor_config = array('ToolbarSet' => 'LearningPathDocuments', 'Width' => '100%', 'Height' => '700', 'FullPage' => true,
  5722. 'CreateDocumentDir' => $relative_prefix,
  5723. 'CreateDocumentWebDir' => api_get_path(WEB_COURSE_PATH) . api_get_course_path() . '/document/',
  5724. 'BaseHref' => api_get_path(WEB_COURSE_PATH) . api_get_course_path() . '/document/' . $relative_path
  5725. );
  5726. if ($_GET['action'] == 'add_item') {
  5727. $class = 'add';
  5728. $text = get_lang('LPCreateDocument');
  5729. } else
  5730. if ($_GET['action'] == 'edit_item') {
  5731. $class = 'save';
  5732. $text = get_lang('SaveDocument');
  5733. }
  5734. $form->addElement('style_submit_button', 'submit_button', $text, 'class="' . $class . '"');
  5735. $renderer = $form->defaultRenderer();
  5736. $renderer->setElementTemplate('<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{label}<br />{element}', 'content_lp');
  5737. $form->addElement('html', '<div style="margin:3px 12px">');
  5738. $form->addElement('html_editor', 'content_lp', '', null, $editor_config);
  5739. $form->addElement('html', '</div>');
  5740. $defaults["content_lp"] = $content;
  5741. }
  5742. }
  5743. elseif (is_numeric($extra_info)) {
  5744. $form->addElement('style_submit_button', 'submit_button', get_lang('SaveDocument'), 'class="save"');
  5745. $return = $this->display_document($extra_info, true, true, true);
  5746. $form->addElement('html', $return);
  5747. }
  5748. }
  5749. }
  5750. if ($action == 'move') {
  5751. $form->addElement('hidden', 'title', $item_title);
  5752. $form->addElement('hidden', 'description', $item_description);
  5753. }
  5754. if (is_numeric($extra_info)) {
  5755. $form->addElement('style_submit_button', 'submit_button', get_lang('SaveDocument'), 'value="submit_button", class="save"');
  5756. $form->addElement('hidden', 'path', $extra_info);
  5757. }
  5758. elseif (is_array($extra_info)) {
  5759. $form->addElement('style_submit_button', 'submit_button', get_lang('SaveDocument'), 'class="save"');
  5760. $form->addElement('hidden', 'path', $extra_info['path']);
  5761. }
  5762. $form->addElement('hidden', 'type', TOOL_DOCUMENT);
  5763. $form->addElement('hidden', 'post_time', time());
  5764. $form->setDefaults($defaults);
  5765. return $form->return_form();
  5766. }
  5767. /**
  5768. * Return HTML form to add/edit a link item
  5769. * @param string Action (add/edit)
  5770. * @param integer Item ID if exists
  5771. * @param mixed Extra info
  5772. * @return string HTML form
  5773. */
  5774. public function display_link_form($action = 'add', $id = 0, $extra_info = '') {
  5775. global $charset;
  5776. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  5777. $tbl_link = Database :: get_course_table(TABLE_LINK);
  5778. if ($id != 0 && is_array($extra_info)) {
  5779. $item_title = stripslashes($extra_info['title']);
  5780. $item_description = stripslashes($extra_info['description']);
  5781. $item_url = stripslashes($extra_info['url']);
  5782. }
  5783. elseif (is_numeric($extra_info)) {
  5784. $sql_link = "
  5785. SELECT
  5786. title,
  5787. description,
  5788. url
  5789. FROM " . $tbl_link . "
  5790. WHERE id = " . $extra_info;
  5791. $result = Database::query($sql_link);
  5792. $row = Database :: fetch_array($result);
  5793. $item_title = $row['title'];
  5794. $item_description = $row['description'];
  5795. $item_url = $row['url'];
  5796. } else {
  5797. $item_title = '';
  5798. $item_description = '';
  5799. $item_url = '';
  5800. }
  5801. $item_title = api_convert_encoding($item_title, $charset, $this->encoding);
  5802. $item_description = api_convert_encoding($item_description, $charset, $this->encoding);
  5803. $return = ' <div class="row">
  5804. <div class="form_header">';
  5805. if ($id != 0 && is_array($extra_info))
  5806. $parent = $extra_info['parent_item_id'];
  5807. else
  5808. $parent = 0;
  5809. $sql = "
  5810. SELECT *
  5811. FROM " . $tbl_lp_item . "
  5812. WHERE
  5813. lp_id = " . $this->lp_id;
  5814. $result = Database::query($sql);
  5815. $arrLP = array ();
  5816. while ($row = Database :: fetch_array($result)) {
  5817. $arrLP[] = array (
  5818. 'id' => $row['id'],
  5819. 'item_type' => $row['item_type'],
  5820. 'title' => $row['title'],
  5821. 'path' => $row['path'],
  5822. 'description' => $row['description'],
  5823. 'parent_item_id' => $row['parent_item_id'],
  5824. 'previous_item_id' => $row['previous_item_id'],
  5825. 'next_item_id' => $row['next_item_id'],
  5826. 'display_order' => $row['display_order'],
  5827. 'max_score' => $row['max_score'],
  5828. 'min_score' => $row['min_score'],
  5829. 'mastery_score' => $row['mastery_score'],
  5830. 'prerequisite' => $row['prerequisite']
  5831. );
  5832. }
  5833. $this->tree_array($arrLP);
  5834. $arrLP = $this->arrMenu;
  5835. unset ($this->arrMenu);
  5836. if ($action == 'add')
  5837. $return .= get_lang("CreateTheLink") . '&nbsp;:' . "\n";
  5838. elseif ($action == 'move') $return .= get_lang("MoveCurrentLink") . '&nbsp;:' . "\n";
  5839. else
  5840. $return .= get_lang("EditCurrentLink") . '&nbsp;:' . "\n";
  5841. $return .= ' </div>
  5842. </div>';
  5843. $return .= '<div class="sectioncomment">';
  5844. $return .= '<form method="POST">' . "\n";
  5845. $return .= "\t" . '<table>' . "\n";
  5846. if ($action != 'move') {
  5847. $return .= "\t\t" . '<tr>' . "\n";
  5848. $return .= "\t\t\t" . '<td class="label"><label for="idTitle">' . get_lang('Title') . '</label></td>' . "\n";
  5849. $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";
  5850. $return .= "\t\t" . '</tr>' . "\n";
  5851. }
  5852. $return .= "\t\t" . '<tr>' . "\n";
  5853. $return .= "\t\t\t" . '<td class="label"><label for="idParent">' . get_lang('Parent') . '</label></td>' . "\n";
  5854. $return .= "\t\t\t" . '<td class="input">' . "\n";
  5855. $return .= "\t\t\t\t" . '<select id="idParent" style="width:100%;" name="parent" onchange="load_cbo(this.value);" class="learnpath_item_form" size="1">';
  5856. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
  5857. $arrHide = array (
  5858. $id
  5859. );
  5860. $parent_item_id = $_SESSION['parent_item_id'];
  5861. for ($i = 0; $i < count($arrLP); $i++) {
  5862. if ($action != 'add') {
  5863. 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)) {
  5864. $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'] . '">' . api_convert_encoding($arrLP[$i]['title'], $charset, $this->encoding) . '</option>';
  5865. } else {
  5866. $arrHide[] = $arrLP[$i]['id'];
  5867. }
  5868. } else {
  5869. if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
  5870. $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'] . '">' . api_convert_encoding($arrLP[$i]['title'], $charset, $this->encoding) . '</option>';
  5871. }
  5872. }
  5873. if (is_array($arrLP)) {
  5874. reset($arrLP);
  5875. }
  5876. $return .= "\t\t\t\t" . '</select>';
  5877. $return .= "\t\t\t" . '</td>' . "\n";
  5878. $return .= "\t\t" . '</tr>' . "\n";
  5879. $return .= "\t\t" . '<tr>' . "\n";
  5880. $return .= "\t\t\t" . '<td class="label"><label for="idPosition">' . get_lang('Position') . '</label></td>' . "\n";
  5881. $return .= "\t\t\t" . '<td class="input">' . "\n";
  5882. $return .= "\t\t\t\t" . '<select id="idPosition" name="previous" style="width:100%;" size="1" class="learnpath_item_form">';
  5883. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . get_lang("FirstPosition") . '</option>';
  5884. for ($i = 0; $i < count($arrLP); $i++) {
  5885. if ($arrLP[$i]['parent_item_id'] == $parent_item_id && $arrLP[$i]['id'] != $id) {
  5886. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5887. $selected = 'selected="selected" ';
  5888. elseif ($action == 'add') $selected = 'selected="selected" ';
  5889. else
  5890. $selected = '';
  5891. $return .= "\t\t\t\t\t" . '<option ' . $selected . 'value="' . $arrLP[$i]['id'] . '">' . get_lang("After") . ' "' . api_convert_encoding($arrLP[$i]['title'], $charset, $this->encoding) . '"</option>';
  5892. }
  5893. }
  5894. $return .= "\t\t\t\t" . '</select>';
  5895. $return .= "\t\t\t" . '</td>' . "\n";
  5896. $return .= "\t\t" . '</tr>' . "\n";
  5897. if ($action != 'move') {
  5898. $return .= "\t\t" . '<tr>' . "\n";
  5899. $return .= "\t\t\t" . '<td class="label"><label for="idURL">' . get_lang('Url') . '</label></td>' . "\n";
  5900. $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";
  5901. $return .= "\t\t" . '</tr>' . "\n";
  5902. $id_prerequisite = 0;
  5903. if (is_array($arrLP)) {
  5904. foreach ($arrLP as $key => $value) {
  5905. if ($value['id'] == $id) {
  5906. $id_prerequisite = $value['prerequisite'];
  5907. break;
  5908. }
  5909. }
  5910. }
  5911. $arrHide = array ();
  5912. for ($i = 0; $i < count($arrLP); $i++) {
  5913. if ($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter') {
  5914. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5915. $s_selected_position = $arrLP[$i]['id'];
  5916. elseif ($action == 'add') $s_selected_position = 0;
  5917. $arrHide[$arrLP[$i]['id']]['value'] = api_convert_encoding($arrLP[$i]['title'], $charset, $this->encoding);
  5918. }
  5919. }
  5920. /*//comented the prerequisites, only visible in edit (link)
  5921. $return .= "\t\t" . '<tr>' . "\n";
  5922. $return .= "\t\t\t" . '<td class="label"><label for="idPrerequisites">'.get_lang('Prerequisites').'</label></td>' . "\n";
  5923. $return .= "\t\t\t" . '<td class="input"><select name="prerequisites" id="prerequisites" class="learnpath_item_form"><option value="0">'.get_lang("NoPrerequisites").'</option>';
  5924. foreach($arrHide as $key => $value)
  5925. {
  5926. if($key==$s_selected_position && $action == 'add')
  5927. {
  5928. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  5929. }
  5930. elseif($key==$id_prerequisite && $action == 'edit'){
  5931. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  5932. }
  5933. else{
  5934. $return .= '<option value="'.$key.'">'.$value['value'].'</option>';
  5935. }
  5936. }
  5937. $return .= "</select></td>";
  5938. */
  5939. $return .= "\t\t" . '</tr>' . "\n";
  5940. }
  5941. $return .= "\t\t" . '<tr>' . "\n";
  5942. if ($action == 'add') {
  5943. $return .= '<td>&nbsp;</td><td><button class="save" name="submit_button" type="submit">' . get_lang('AddLinkToCourse') . '</button></td>';
  5944. } else {
  5945. $return .= '<td>&nbsp;</td><td><button class="save" name="submit_button" type="submit">' . get_lang('EditCurrentLink') . '</button></td>';
  5946. }
  5947. $return .= "\t\t" . '</tr>' . "\n";
  5948. $return .= "\t" . '</table>' . "\n";
  5949. if ($action == 'move') {
  5950. $return .= "\t" . '<input name="title" type="hidden" value="' . $item_title . '" />' . "\n";
  5951. $return .= "\t" . '<input name="description" type="hidden" value="' . $item_description . '" />' . "\n";
  5952. }
  5953. if (is_numeric($extra_info)) {
  5954. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info . '" />' . "\n";
  5955. }
  5956. elseif (is_array($extra_info)) {
  5957. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />' . "\n";
  5958. }
  5959. $return .= "\t" . '<input name="type" type="hidden" value="' . TOOL_LINK . '" />' . "\n";
  5960. $return .= "\t" . '<input name="post_time" type="hidden" value="' . time() . '" />' . "\n";
  5961. $return .= '</form>' . "\n";
  5962. $return .= '</div>' . "\n";
  5963. return $return;
  5964. }
  5965. /**
  5966. * Return HTML form to add/edit a student publication (work)
  5967. * @param string Action (add/edit)
  5968. * @param integer Item ID if already exists
  5969. * @param mixed Extra info (work ID if integer)
  5970. * @return string HTML form
  5971. */
  5972. public function display_student_publication_form($action = 'add', $id = 0, $extra_info = '') {
  5973. global $charset;
  5974. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  5975. $tbl_publication = Database :: get_course_table(TABLE_STUDENT_PUBLICATION);
  5976. if ($id != 0 && is_array($extra_info)) {
  5977. $item_title = stripslashes($extra_info['title']);
  5978. $item_description = stripslashes($extra_info['description']);
  5979. }
  5980. elseif (is_numeric($extra_info)) {
  5981. $sql_publication = "
  5982. SELECT
  5983. title,
  5984. description
  5985. FROM " . $tbl_publication . "
  5986. WHERE id = " . $extra_info;
  5987. $result = Database::query($sql_publication);
  5988. $row = Database :: fetch_array($result);
  5989. $item_title = $row['title'];
  5990. } else {
  5991. $item_title = get_lang('Student_publication');
  5992. }
  5993. $item_title = api_convert_encoding($item_title, $charset, $this->encoding);
  5994. $return = ' <div class="row">
  5995. <div class="form_header">';
  5996. if ($id != 0 && is_array($extra_info))
  5997. $parent = $extra_info['parent_item_id'];
  5998. else
  5999. $parent = 0;
  6000. $sql = "
  6001. SELECT *
  6002. FROM " . $tbl_lp_item . "
  6003. WHERE
  6004. lp_id = " . $this->lp_id;
  6005. $result = Database::query($sql);
  6006. $arrLP = array ();
  6007. while ($row = Database :: fetch_array($result)) {
  6008. $arrLP[] = array (
  6009. 'id' => $row['id'],
  6010. 'item_type' => $row['item_type'],
  6011. 'title' => $row['title'],
  6012. 'path' => $row['path'],
  6013. 'description' => $row['description'],
  6014. 'parent_item_id' => $row['parent_item_id'],
  6015. 'previous_item_id' => $row['previous_item_id'],
  6016. 'next_item_id' => $row['next_item_id'],
  6017. 'display_order' => $row['display_order'],
  6018. 'max_score' => $row['max_score'],
  6019. 'min_score' => $row['min_score'],
  6020. 'mastery_score' => $row['mastery_score'],
  6021. 'prerequisite' => $row['prerequisite']
  6022. );
  6023. }
  6024. $this->tree_array($arrLP);
  6025. $arrLP = $this->arrMenu;
  6026. unset ($this->arrMenu);
  6027. if ($action == 'add')
  6028. $return .= get_lang("Student_publication") . '&nbsp;:' . "\n";
  6029. elseif ($action == 'move') $return .= get_lang("MoveCurrentStudentPublication") . '&nbsp;:' . "\n";
  6030. else
  6031. $return .= get_lang("EditCurrentStudentPublication") . '&nbsp;:' . "\n";
  6032. $return .= ' </div>
  6033. </div>';
  6034. $return .= '<div class="sectioncomment">';
  6035. $return .= '<form method="POST">' . "\n";
  6036. $return .= "\t" . '<table class="lp_form">' . "\n";
  6037. if ($action != 'move') {
  6038. $return .= "\t\t" . '<tr>' . "\n";
  6039. $return .= "\t\t\t" . '<td class="label"><label for="idTitle">' . get_lang('Title') . '</label></td>' . "\n";
  6040. $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";
  6041. $return .= "\t\t" . '</tr>' . "\n";
  6042. }
  6043. $return .= "\t\t" . '<tr>' . "\n";
  6044. $return .= "\t\t\t" . '<td class="label"><label for="idParent">' . get_lang('Parent') . '</label></td>' . "\n";
  6045. $return .= "\t\t\t" . '<td class="input">' . "\n";
  6046. $return .= "\t\t\t\t" . '<select id="idParent" name="parent" style="width:100%;" onchange="load_cbo(this.value);" class="learnpath_item_form" size="1">';
  6047. //$parent_item_id = $_SESSION['parent_item_id'];
  6048. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
  6049. $arrHide = array (
  6050. $id
  6051. );
  6052. for ($i = 0; $i < count($arrLP); $i++) {
  6053. if ($action != 'add') {
  6054. 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)) {
  6055. $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'] . '">' . api_convert_encoding($arrLP[$i]['title'], $charset, $this->encoding) . '</option>';
  6056. } else {
  6057. $arrHide[] = $arrLP[$i]['id'];
  6058. }
  6059. } else {
  6060. if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
  6061. $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'] . '">' . api_convert_encoding($arrLP[$i]['title'], $charset, $this->encoding) . '</option>';
  6062. }
  6063. }
  6064. if (is_array($arrLP)) {
  6065. reset($arrLP);
  6066. }
  6067. $return .= "\t\t\t\t" . '</select>';
  6068. $return .= "\t\t\t" . '</td>' . "\n";
  6069. $return .= "\t\t" . '</tr>' . "\n";
  6070. $return .= "\t\t" . '<tr>' . "\n";
  6071. $return .= "\t\t\t" . '<td class="label"><label for="idPosition">' . get_lang('Position') . '</label></td>' . "\n";
  6072. $return .= "\t\t\t" . '<td class="input">' . "\n";
  6073. $return .= "\t\t\t\t" . '<select id="idPosition" name="previous" style="width:100%;" size="1" class="learnpath_item_form">';
  6074. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . get_lang("FirstPosition") . '</option>';
  6075. for ($i = 0; $i < count($arrLP); $i++) {
  6076. if ($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) {
  6077. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  6078. $selected = 'selected="selected" ';
  6079. elseif ($action == 'add') $selected = 'selected="selected" ';
  6080. else
  6081. $selected = '';
  6082. $return .= "\t\t\t\t\t" . '<option ' . $selected . 'value="' . $arrLP[$i]['id'] . '">' . get_lang("After") . ' "' . api_convert_encoding($arrLP[$i]['title'], $charset, $this->encoding) . '"</option>';
  6083. }
  6084. }
  6085. $return .= "\t\t\t\t" . '</select>';
  6086. $return .= "\t\t\t" . '</td>' . "\n";
  6087. $return .= "\t\t" . '</tr>' . "\n";
  6088. if ($action != 'move') {
  6089. $id_prerequisite = 0;
  6090. if (is_array($arrLP)) {
  6091. foreach ($arrLP as $key => $value) {
  6092. if ($value['id'] == $id) {
  6093. $id_prerequisite = $value['prerequisite'];
  6094. break;
  6095. }
  6096. }
  6097. }
  6098. $arrHide = array ();
  6099. for ($i = 0; $i < count($arrLP); $i++) {
  6100. if ($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter') {
  6101. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  6102. $s_selected_position = $arrLP[$i]['id'];
  6103. elseif ($action == 'add') $s_selected_position = 0;
  6104. $arrHide[$arrLP[$i]['id']]['value'] = api_convert_encoding($arrLP[$i]['title'], $charset, $this->encoding);
  6105. }
  6106. }
  6107. //comented the prerequisites, only visible in edit (work)
  6108. /*
  6109. $return .= "\t\t" . '<tr>' . "\n";
  6110. $return .= "\t\t\t" . '<td class="label"><label for="idPrerequisites">'.get_lang('Prerequisites').'</label></td>' . "\n";
  6111. $return .= "\t\t\t" . '<td class="input"><select name="prerequisites" id="prerequisites" class="learnpath_item_form"><option value="0">'.get_lang("NoPrerequisites").'</option>';
  6112. foreach($arrHide as $key => $value){
  6113. if($key==$s_selected_position && $action == 'add'){
  6114. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  6115. }
  6116. elseif($key==$id_prerequisite && $action == 'edit'){
  6117. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  6118. }
  6119. else{
  6120. $return .= '<option value="'.$key.'">'.$value['value'].'</option>';
  6121. }
  6122. }
  6123. $return .= "</select></td>";
  6124. */
  6125. $return .= "\t\t" . '</tr>' . "\n";
  6126. }
  6127. $return .= "\t\t" . '<tr>' . "\n";
  6128. if ($action == 'add') {
  6129. $return .= '<td>&nbsp</td><td><button class="save" name="submit_button" type="submit">' . get_lang('AddAssignmentToCourse') . '</button></td>';
  6130. } else {
  6131. $return .= '<td>&nbsp</td><td><button class="save" name="submit_button" type="submit">' . get_lang('EditCurrentStudentPublication') . '</button></td>';
  6132. }
  6133. $return .= "\t\t" . '</tr>' . "\n";
  6134. $return .= "\t" . '</table>' . "\n";
  6135. if ($action == 'move') {
  6136. $return .= "\t" . '<input name="title" type="hidden" value="' . $item_title . '" />' . "\n";
  6137. $return .= "\t" . '<input name="description" type="hidden" value="' . $item_description . '" />' . "\n";
  6138. }
  6139. if (is_numeric($extra_info)) {
  6140. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info . '" />' . "\n";
  6141. } elseif (is_array($extra_info)) {
  6142. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />' . "\n";
  6143. }
  6144. $return .= "\t" . '<input name="type" type="hidden" value="' . TOOL_STUDENTPUBLICATION . '" />' . "\n";
  6145. $return .= "\t" . '<input name="post_time" type="hidden" value="' . time() . '" />' . "\n";
  6146. $return .= '</form>' . "\n";
  6147. $return .= '</div>' . "\n";
  6148. return $return;
  6149. }
  6150. /**
  6151. * Displays the menu for manipulating a step
  6152. * @return unknown
  6153. */
  6154. public function display_manipulate($item_id, $item_type = TOOL_DOCUMENT) {
  6155. global $charset, $_course;
  6156. $return = '<div class="actions">';
  6157. switch ($item_type) {
  6158. case 'dokeos_chapter' :
  6159. case 'chapter' :
  6160. //comented the message cause should not show it
  6161. //$lang = get_lang('TitleManipulateChapter');
  6162. break;
  6163. case 'dokeos_module' :
  6164. case 'module' :
  6165. //comented the message cause should not show it
  6166. //$lang = get_lang('TitleManipulateModule');
  6167. break;
  6168. case TOOL_DOCUMENT :
  6169. //comented the message cause should not show it
  6170. //$lang = get_lang('TitleManipulateDocument');
  6171. break;
  6172. case TOOL_LINK :
  6173. case 'link' :
  6174. //comented the message cause should not show it
  6175. //$lang = get_lang('TitleManipulateLink');
  6176. break;
  6177. case TOOL_QUIZ :
  6178. //comented the message cause should not show it
  6179. //$lang = get_lang('TitleManipulateQuiz');
  6180. break;
  6181. case TOOL_STUDENTPUBLICATION :
  6182. //comented the message cause should not show it
  6183. //$lang = get_lang('TitleManipulateStudentPublication');
  6184. break;
  6185. }
  6186. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  6187. $sql = "
  6188. SELECT
  6189. *
  6190. FROM " . $tbl_lp_item . " as lp
  6191. WHERE
  6192. lp.id = " . $item_id;
  6193. $result = Database::query($sql);
  6194. $row = Database::fetch_assoc($result);
  6195. $s_title = $row['title'];
  6196. $s_title = api_convert_encoding($s_title, $charset, $this->encoding);
  6197. // we display an audio player if needed
  6198. if (!empty ($row['audio'])) {
  6199. $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>';
  6200. $return .= '<script type="text/javascript" src="../inc/lib/mediaplayer/swfobject.js"></script>';
  6201. $return .= '<script type="text/javascript">
  6202. var s1 = new SWFObject("../inc/lib/mediaplayer/player.swf","ply","250","20","9","#FFFFFF");
  6203. s1.addParam("allowscriptaccess","always");
  6204. s1.addParam("flashvars","file=../../courses/' . $_course['path'] . '/document/audio/' . $row['audio'] . '&autostart=true");
  6205. s1.write("container");
  6206. </script>';
  6207. }
  6208. //commented ":" for message in step
  6209. //$return .= $lang.': ';
  6210. $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>';
  6211. $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>';
  6212. // commented for now as prerequisites cannot be added to chapters
  6213. if ($item_type != 'dokeos_chapter' && $item_type != 'chapter') {
  6214. $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>';
  6215. }
  6216. $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>';
  6217. //$return .= '<br><br><p class="lp_text">' . ((trim($s_description) == '') ? ''.get_lang("NoDescription").'' : stripslashes(nl2br($s_description))) . '</p>';
  6218. //$return.="</td><td valign='top'>";
  6219. // get the audiorecorder. Use of ob_* functions since there are echos in the file
  6220. ob_start();
  6221. $audio_recorder_studentview = 'false';
  6222. $audio_recorder_item_id = $item_id;
  6223. if (api_get_setting('service_visio', 'active') == 'true') {
  6224. include ('audiorecorder.inc.php');
  6225. }
  6226. $return .= ob_get_contents();
  6227. ob_end_clean();
  6228. // end of audiorecorder include
  6229. $return .= '</div>';
  6230. return $return;
  6231. }
  6232. /**
  6233. * Creates the javascript needed for filling up the checkboxes without page reload
  6234. *
  6235. * @return string
  6236. */
  6237. public function create_js() {
  6238. $return = '<script language="javascript" type="text/javascript">' . "\n";
  6239. $return .= 'function load_cbo(id){' . "\n";
  6240. $return .= "var cbo = document.getElementById('idPosition');\n";
  6241. $return .= 'for(var i = cbo.length - 1; i > 0; i--)';
  6242. $return .= 'cbo.options[i] = null;' . "\n";
  6243. $return .= 'var k=0;' . "\n";
  6244. $return .= 'for(var i = 1; i <= child_name[id].length; i++){' . "\n";
  6245. $return .= ' cbo.options[i] = new Option(child_name[id][i-1], child_value[id][i-1]);' . "\n";
  6246. $return .= 'k=i;';
  6247. $return .= '}' . "\n\n";
  6248. $return .= 'if( typeof cbo != "undefined" ) {cbo.options[k].selected = true;}';
  6249. $return .= '}';
  6250. $return .= 'var child_name = new Array();' . "\n";
  6251. $return .= 'var child_value = new Array();' . "\n\n";
  6252. $return .= 'child_name[0] = new Array();' . "\n";
  6253. $return .= 'child_value[0] = new Array();' . "\n\n";
  6254. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  6255. $sql_zero = "
  6256. SELECT *
  6257. FROM " . $tbl_lp_item . "
  6258. WHERE
  6259. lp_id = " . $this->lp_id . " AND
  6260. parent_item_id = 0
  6261. ORDER BY display_order ASC";
  6262. $res_zero = Database::query($sql_zero);
  6263. global $charset;
  6264. $i = 0;
  6265. while ($row_zero = Database :: fetch_array($res_zero)) {
  6266. $return .= 'child_name[0][' . $i . '] = "' . get_lang("After") . ' \"' . api_convert_encoding($row_zero['title'], $charset, $this->encoding) . '\"";' . "\n";
  6267. $return .= 'child_value[0][' . $i++ . '] = "' . $row_zero['id'] . '";' . "\n";
  6268. }
  6269. $return .= "\n";
  6270. $sql = "
  6271. SELECT *
  6272. FROM " . $tbl_lp_item . "
  6273. WHERE
  6274. lp_id = " . $this->lp_id;
  6275. $res = Database::query($sql);
  6276. while ($row = Database :: fetch_array($res)) {
  6277. $sql_parent = "
  6278. SELECT *
  6279. FROM " . $tbl_lp_item . "
  6280. WHERE parent_item_id = " . $row['id'] . "
  6281. ORDER BY display_order ASC";
  6282. $res_parent = Database::query($sql_parent);
  6283. $i = 0;
  6284. $return .= 'child_name[' . $row['id'] . '] = new Array();' . "\n";
  6285. $return .= 'child_value[' . $row['id'] . '] = new Array();' . "\n\n";
  6286. while ($row_parent = Database :: fetch_array($res_parent)) {
  6287. $return .= 'child_name[' . $row['id'] . '][' . $i . '] = "' . get_lang("After") . ' \"' . api_html_entity_decode(api_convert_encoding ($row_parent['title'], $charset, $this->encoding), ENT_QUOTES, $charset) . '\"";' . "\n";
  6288. $return .= 'child_value[' . $row['id'] . '][' . $i++ . '] = "' . $row_parent['id'] . '";' . "\n";
  6289. }
  6290. $return .= "\n";
  6291. }
  6292. $return .= '</script>' . "\n";
  6293. return $return;
  6294. }
  6295. /**
  6296. * Display the form to allow moving an item
  6297. * @param integer Item ID
  6298. * @return string HTML form
  6299. */
  6300. public function display_move_item($item_id) {
  6301. global $_course; //will disappear
  6302. global $charset;
  6303. $return = '';
  6304. if (is_numeric($item_id)) {
  6305. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  6306. $sql = "SELECT *
  6307. FROM " . $tbl_lp_item . "
  6308. WHERE id = " . $item_id;
  6309. $res = Database::query($sql);
  6310. $row = Database :: fetch_array($res);
  6311. switch ($row['item_type']) {
  6312. case 'dokeos_chapter' :
  6313. case 'dir' :
  6314. case 'asset' :
  6315. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6316. $return .= $this->display_item_form($row['item_type'], get_lang('MoveCurrentChapter'), 'move', $item_id, $row);
  6317. break;
  6318. case 'dokeos_module' :
  6319. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6320. $return .= $this->display_item_form($row['item_type'], 'Move th current module:', 'move', $item_id, $row);
  6321. break;
  6322. case TOOL_DOCUMENT :
  6323. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6324. $return .= $this->display_document_form('move', $item_id, $row);
  6325. break;
  6326. case TOOL_LINK :
  6327. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6328. $return .= $this->display_link_form('move', $item_id, $row);
  6329. break;
  6330. case TOOL_HOTPOTATOES :
  6331. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6332. $return .= $this->display_link_form('move', $item_id, $row);
  6333. break;
  6334. case TOOL_QUIZ :
  6335. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6336. $return .= $this->display_quiz_form('move', $item_id, $row);
  6337. break;
  6338. case TOOL_STUDENTPUBLICATION :
  6339. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6340. $return .= $this->display_student_publication_form('move', $item_id, $row);
  6341. break;
  6342. case TOOL_FORUM :
  6343. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6344. $return .= $this->display_forum_form('move', $item_id, $row);
  6345. break;
  6346. case TOOL_THREAD :
  6347. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6348. $return .= $this->display_forum_form('move', $item_id, $row);
  6349. break;
  6350. }
  6351. }
  6352. return $return;
  6353. }
  6354. /**
  6355. * Displays a basic form on the overview page for changing the item title and the item description.
  6356. * @param string $item_type
  6357. * @param string $title
  6358. * @param array $data
  6359. * @return string
  6360. */
  6361. public function display_item_small_form($item_type, $title = '', $data) {
  6362. global $charset;
  6363. $return .= '<div class="lp_small_form">' . "\n";
  6364. $return .= '<p class="lp_title">' . $title . '</p>';
  6365. $return .= '<form method="post">' . "\n";
  6366. $return .= '<table cellpadding="0" cellspacing="0" class="lp_form">';
  6367. $return .= "\t\t" . '<tr>' . "\n";
  6368. $return .= "\t\t\t" . '<td class="label"><label for="idTitle">Title&nbsp;:</label></td>' . "\n";
  6369. $return .= "\t\t\t" . '<td class="input"><input class="small_form" id="idTitle" name="title" type="text" value="' . api_html_entity_decode(api_convert_encoding(htmlspecialchars($data['title']), $charset, $this->encoding), ENT_QUOTES, $charset) . '" /></td>' . "\n";
  6370. $return .= "\t\t" . '</tr>' . "\n";
  6371. //it said these lines of code - see SVN#11724 and SVN#10770
  6372. //$return .= "\t\t" . '<tr>' . "\n";
  6373. //$return .= "\t\t\t" . '<td class="label"><label for="idDescription">Description&nbsp;:</label></td>' . "\n";
  6374. //$return .= "\t\t\t" . '<td class="input"><textarea class="small_form" id="idDescription" name="description" rows="4">' . $data['description'] . '</textarea></td>' . "\n";
  6375. //$return .= "\t\t" . '</tr>' . "\n";
  6376. $return .= "\t\t" . '<tr>' . "\n";
  6377. $return .= "\t\t\t" . '<td colspan="2"><button class="save" name="submit_button" type="submit">' . get_lang('Save') . '</button></td>' . "\n";
  6378. $return .= "\t\t" . '</tr>' . "\n";
  6379. $return .= "\t\t" . '</table>' . "\n";
  6380. $return .= "\t" . '<input name="parent" type="hidden" value="' . $data['parent_item_id'] . '"/>' . "\n";
  6381. $return .= "\t" . '<input name="previous" type="hidden" value="' . $data['previous_item_id'] . '"/>' . "\n";
  6382. $return .= '</form>';
  6383. $return .= '</div>';
  6384. return $return;
  6385. }
  6386. /**
  6387. * Return HTML form to allow prerequisites selection
  6388. * @param integer Item ID
  6389. * @return string HTML form
  6390. */
  6391. public function display_item_prerequisites_form($item_id) {
  6392. global $charset;
  6393. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  6394. /* current prerequisite */
  6395. $sql = "
  6396. SELECT *
  6397. FROM " . $tbl_lp_item . "
  6398. WHERE id = " . $item_id;
  6399. $result = Database::query($sql);
  6400. $row = Database :: fetch_array($result);
  6401. $preq_id = $row['prerequisite'];
  6402. //$preq_mastery = $row['mastery_score'];
  6403. //$preq_max = $row['max_score'];
  6404. $return = $this->display_manipulate($item_id, TOOL_DOCUMENT);
  6405. $return = ' <div class="row">
  6406. <div class="form_header">';
  6407. $return .= get_lang('AddEditPrerequisites');
  6408. $return .= '</div> </div>';
  6409. $return .= '<div class="sectioncomment">';
  6410. $return .= '<form method="POST">';
  6411. $return .= '<table class="lp_prerequisites" style="border-collapse:collapse;">';
  6412. $return .= '<tr style="border-collapse:collapse;">';
  6413. $return .= '<th height="24" style="border:1px solid gray; background-color:#F0F0F0;">' . get_lang('Prerequisites') . '</th>';
  6414. $return .= '<th width="70" height="24" style="border:1px solid gray; background-color:#F0F0F0;">' . get_lang('Minimum') . '</th>';
  6415. $return .= '<th width="70" height="24" style="border:1px solid gray; background-color:#F0F0F0;">' . get_lang('Maximum') . '</th>';
  6416. $return .= '</tr>';
  6417. //Adding the none option to the prerequisites see http://www.chamilo.org/es/node/146
  6418. $return .= '<tr >';
  6419. $return .= '<td colspan="3" class="radio" style="border:1px solid gray;border-collapse:collapse;">';
  6420. $return .= '<input checked="checked" id="idNone" name="prerequisites" style="margin-left:0; margin-right:10px;" type="radio" />';
  6421. $return .= '<label for="idNone">' . get_lang('None') . '</label>';
  6422. $return .= '</td><td />';
  6423. $return .= '</tr>';
  6424. $sql = "SELECT * FROM " . $tbl_lp_item . " WHERE lp_id = " . $this->lp_id;
  6425. $result = Database::query($sql);
  6426. $arrLP = array ();
  6427. while ($row = Database :: fetch_array($result)) {
  6428. $arrLP[] = array (
  6429. 'id' => $row['id'],
  6430. 'item_type' => $row['item_type'],
  6431. 'title' => api_convert_encoding($row['title'], $charset, $this->encoding),
  6432. 'ref' => $row['ref'],
  6433. 'description' => $row['description'],
  6434. 'parent_item_id' => $row['parent_item_id'],
  6435. 'previous_item_id' => $row['previous_item_id'],
  6436. 'next_item_id' => $row['next_item_id'],
  6437. 'max_score' => $row['max_score'],
  6438. 'min_score' => $row['min_score'],
  6439. 'mastery_score' => $row['mastery_score'],
  6440. 'prerequisite' => $row['prerequisite'],
  6441. 'next_item_id' => $row['next_item_id'],
  6442. 'display_order' => $row['display_order']
  6443. );
  6444. if ($row['ref'] == $preq_id) {
  6445. $preq_mastery = $row['mastery_score'];
  6446. $preq_max = $row['max_score'];
  6447. }
  6448. }
  6449. $this->tree_array($arrLP);
  6450. $arrLP = $this->arrMenu;
  6451. unset ($this->arrMenu);
  6452. for ($i = 0; $i < count($arrLP); $i++) {
  6453. if ($arrLP[$i]['id'] == $item_id)
  6454. break;
  6455. $return .= '<tr >';
  6456. $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"' : '') . '>';
  6457. $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'] . '" />';
  6458. $icon_name = str_replace(' ', '', $arrLP[$i]['item_type']);
  6459. if (file_exists("../img/lp_" . $icon_name . ".png")) {
  6460. $return .= '<img alt="" src="../img/lp_' . $icon_name . '.png" style="margin-right:5px;" title="" />';
  6461. } else
  6462. if (file_exists("../img/lp_" . $icon_name . ".gif")) {
  6463. $return .= '<img alt="" src="../img/lp_' . $icon_name . '.gif" style="margin-right:5px;" title="" />';
  6464. } else {
  6465. $return .= Display::return_icon('folder_document.gif','',array('style'=>'margin-right:5px;'));
  6466. }
  6467. $return .= '<label for="id' . $arrLP[$i]['id'] . '">' . $arrLP[$i]['title'] . '</label>';
  6468. $return .= '</td>';
  6469. //$return .= '<td class="radio"' . (($arrLP[$i]['item_type'] != TOOL_HOTPOTATOES) ? ' colspan="3"' : '') . ' />';
  6470. if ($arrLP[$i]['item_type'] == TOOL_QUIZ) {
  6471. $return .= '<td class="exercise" style="border:1px solid #B0B0B0;">';
  6472. $return .= '<center><input size="4" maxlength="3" name="min_' . $arrLP[$i]['id'] . '" type="text" value="' . (($arrLP[$i]['id'] == $preq_id) ? $preq_mastery : 0) . '" /></center>';
  6473. $return .= '</td>';
  6474. $return .= '<td class="exercise" style="border:1px solid #B0B0B0;">';
  6475. $return .= '<center><input size="4" maxlength="3" name="max_' . $arrLP[$i]['id'] . '" type="text" value="' . $arrLP[$i]['max_score'] . '" disabled="true" /></center>';
  6476. $return .= '</td>';
  6477. }
  6478. if ($arrLP[$i]['item_type'] == TOOL_HOTPOTATOES) {
  6479. $return .= '<td class="exercise" style="border:1px solid #B0B0B0;">';
  6480. $return .= '<center><input size="4" maxlength="3" name="min_' . $arrLP[$i]['id'] . '" type="text" value="' . (($arrLP[$i]['id'] == $preq_id) ? $preq_mastery : 0) . '" /></center>';
  6481. $return .= '</td>';
  6482. $return .= '<td class="exercise" style="border:1px solid #B0B0B0;">';
  6483. $return .= '<center><input size="4" maxlength="3" name="max_' . $arrLP[$i]['id'] . '" type="text" value="' . $arrLP[$i]['max_score'] . '" disabled="true" /></center>';
  6484. $return .= '</td>';
  6485. }
  6486. $return .= '</tr>';
  6487. }
  6488. $return .= '<tr>';
  6489. $return .= '<td colspan="3">';
  6490. $return .= '</td>';
  6491. $return .= '</tr>';
  6492. $return .= '</table>';
  6493. $return .= '<div style="padding-top:3px;">';
  6494. $return .= '<button class="save" name="submit_button" type="submit">' . get_lang("ModifyPrerequisites") . ' </button></td>' . "\n";
  6495. $return .= '</div>';
  6496. $return .= '</form>';
  6497. $return .= '</div>';
  6498. return $return;
  6499. }
  6500. /**
  6501. * Return HTML list to allow prerequisites selection for lp
  6502. * @param integer Item ID
  6503. * @return string HTML form
  6504. */
  6505. public function display_lp_prerequisites_list() {
  6506. global $charset;
  6507. $lp_id = $this->lp_id;
  6508. $tbl_lp = Database :: get_course_table(TABLE_LP_MAIN);
  6509. // get current prerequisite
  6510. $sql = "SELECT * FROM $tbl_lp WHERE id = $lp_id ";
  6511. $result = Database::query($sql);
  6512. $row = Database :: fetch_array($result);
  6513. $preq_id = $row['prerequisite'];
  6514. $session_id = api_get_session_id();
  6515. $session_condition = api_get_session_condition($session_id, false);
  6516. $sql = "SELECT * FROM $tbl_lp $session_condition ORDER BY display_order ";
  6517. $rs = Database::query($sql);
  6518. $return = '';
  6519. $return .= '<select name="prerequisites" >';
  6520. $return .= '<option value="0">'.get_lang('None').'</option>';
  6521. if (Database::num_rows($rs) > 0) {
  6522. while ($row = Database::fetch_array($rs)) {
  6523. if ($row['id'] == $lp_id) {
  6524. continue;
  6525. }
  6526. $return .= '<option value="'.$row['id'].'" '.(($row['id']==$preq_id)?' selected ' : '').'>'.$row['name'].'</option>';
  6527. }
  6528. }
  6529. $return .= '</select>';
  6530. return $return;
  6531. }
  6532. /**
  6533. * Creates a list with all the documents in it
  6534. * @return string
  6535. */
  6536. public function get_documents() {
  6537. global $_course;
  6538. $tbl_doc = Database :: get_course_table(TABLE_DOCUMENT);
  6539. $tbl_item_prop = Database::get_course_table(TABLE_ITEM_PROPERTY);
  6540. $tbl_course = Database::get_main_table(TABLE_MAIN_COURSE);
  6541. $path = '/';
  6542. $path = Database::escape_string(str_replace('_', '\_', $path));
  6543. $added_slash = ($path == '/') ? '' : '/';
  6544. //condition for the session
  6545. $current_session_id = api_get_session_id();
  6546. $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]}')))";
  6547. $sql_doc = "SELECT docs.*
  6548. FROM $tbl_item_prop AS last, $tbl_doc AS docs
  6549. WHERE docs.id = last.ref
  6550. AND docs.path LIKE '".$path.$added_slash."%'
  6551. AND docs.path NOT LIKE '%_DELETED_%'
  6552. AND last.tool = '".TOOL_DOCUMENT."' $condition_session ORDER BY docs.path ASC";
  6553. //$sql_doc = "SELECT * FROM $tbl_doc WHERE path NOT LIKE '%_DELETED_%' ORDER BY path ASC";
  6554. $res_doc = Database::query($sql_doc);
  6555. $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>';
  6556. $return .= '<div class="lp_resource_elements" id="resDoc">';
  6557. $resources = Database::store_result($res_doc);
  6558. $resources_sorted = array ();
  6559. // if you want to debug it, I advise you to do "echo" on the eval statements
  6560. foreach ($resources as $resource) {
  6561. $resource_paths = explode('/', $resource['path']);
  6562. array_shift($resource_paths);
  6563. $path_to_eval = $last_path = '';
  6564. $is_file = false;
  6565. foreach ($resource_paths as $key => $resource_path) {
  6566. if (strpos($resource_path, '.') === false && $key != count($resource_paths) - 1) { // it's a folder
  6567. $path_to_eval .= '["' . $resource_path . '"]["files"]';
  6568. } else
  6569. if (strpos($resource_path, '.') !== false)
  6570. $is_file = true;
  6571. $last_path = $resource_path;
  6572. }
  6573. if ($is_file) {
  6574. //eval ('$resources_sorted' . $path_to_eval . '[' . $resource['id'] . '] = "' . $last_path . '";');
  6575. eval ('$resources_sorted' . $path_to_eval . '[' . $resource['id'] . '] = "' .$resource['title']."/". $last_path. '";');
  6576. } else {
  6577. eval ('$resources_sorted' . $path_to_eval . '["' . $last_path . '"]["id"]=' . $resource['id'] . ';');
  6578. }
  6579. }
  6580. $return .= $this->write_resources_tree($resources_sorted);
  6581. if (Database :: num_rows($res_doc) == 0) {
  6582. $return .= '<div class="lp_resource_element">' . get_lang("NoDocuments") . '</div>';
  6583. }
  6584. $return .= '</div>';
  6585. return $return;
  6586. }
  6587. /**
  6588. * Generate and return an HTML list of resources based on a given array.
  6589. * This list is used to show the course creator a list of available resources to choose from
  6590. * when creating a learning path.
  6591. * @param array Array of elements to add to the list
  6592. * @param integer Enables the tree display by shifting the new elements a certain distance to the right
  6593. * @return string The HTML list
  6594. */
  6595. public function write_resources_tree($resources_sorted, $num = 0) {
  6596. require_once api_get_path(LIBRARY_PATH).'fileDisplay.lib.php';
  6597. if (count($resources_sorted) > 0) {
  6598. foreach ($resources_sorted as $key => $resource) {
  6599. if (is_int($resource['id'])) {
  6600. // it's a folder
  6601. $return .= '<div><div style="margin-left:' . ($num * 15) . 'px;margin-right:5px;"><img style="cursor: pointer;" src="../img/nolines_plus.gif" align="absmiddle" id="img_' . $resource["id"] . '" onclick="testResources(\'' . $resource["id"] . '\',\'img_' . $resource["id"] . '\')"><img alt="" src="../img/lp_folder.gif" title="" align="absmiddle" />&nbsp;<span onclick="testResources(\'' . $resource["id"] . '\',\'img_' . $resource["id"] . '\')" style="cursor: pointer;" >' . $key . '</span></div><div style="display: none;" id="' . $resource['id'] . '">';
  6602. $return .= $this->write_resources_tree($resource['files'], $num +1);
  6603. $return .= '</div></div>';
  6604. } else {
  6605. if (!is_array($resource)) {
  6606. // it's a file
  6607. $icon = choose_image($resource);
  6608. $position = strrpos($icon, '.');
  6609. $icon = substr($icon, 0, $position) . '_small.gif';
  6610. $file_info = explode('/', $resource);
  6611. $my_file_title = $file_info[0];
  6612. $my_file_name = $file_info[1];
  6613. //$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>';
  6614. //Show the "image name" not the filename of the image
  6615. $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"; }
  6616. }
  6617. }
  6618. }
  6619. return $return;
  6620. }
  6621. /**
  6622. * Creates a list with all the exercises (quiz) in it
  6623. * @return string
  6624. */
  6625. public function get_exercises() {
  6626. // new for hotpotatoes
  6627. $uploadPath = DIR_HOTPOTATOES; //defined in main_api
  6628. $tbl_doc = Database :: get_course_table(TABLE_DOCUMENT);
  6629. $tbl_quiz = Database :: get_course_table(TABLE_QUIZ_TEST);
  6630. $session_id = api_get_session_id();
  6631. $condition_session = api_get_session_condition($session_id);
  6632. $sql_quiz = "
  6633. SELECT *
  6634. FROM " . $tbl_quiz . "
  6635. WHERE active<>'-1' $condition_session
  6636. ORDER BY title ASC";
  6637. $sql_hot = "SELECT * FROM " . $tbl_doc . " " .
  6638. " WHERE path LIKE '" . $uploadPath . "/%/%htm%' $condition_session " .
  6639. " ORDER BY id ASC";
  6640. $res_quiz = Database::query($sql_quiz);
  6641. $res_hot = Database::query($sql_hot);
  6642. $return .= '<div class="lp_resource_header"' . " onclick=\"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>';
  6643. $return .= '<div class="lp_resource_elements" id="resExercise">';
  6644. while ($row_hot = Database :: fetch_array($res_hot)) {
  6645. $return .= '<div class="lp_resource_element">';
  6646. //display quizhotpotatoes
  6647. $return .= '<img alt="hp" src="../img/hotpotatoes_s.png" style="margin-right:5px;" title="" width="18px" height="18px" />';
  6648. $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>';
  6649. //$return .= $row_quiz['title'];
  6650. $return .= '</div>';
  6651. }
  6652. while ($row_quiz = Database :: fetch_array($res_quiz)) {
  6653. $return .= '<div class="lp_resource_element">';
  6654. $return .= '<img alt="" src="../img/quizz_small.gif" style="margin-right:5px;" title="" />';
  6655. $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>';
  6656. //$return .= $row_quiz['title'];
  6657. $return .= '</div>';
  6658. }
  6659. if (Database :: num_rows($res_quiz) == 0) {
  6660. $return .= '<div class="lp_resource_element">' . get_lang("NoExercisesAvailable") . '</div>';
  6661. }
  6662. $return .= '<div class="lp_resource_element">';
  6663. $return .= '<img alt="" src="../img/new_test_small.gif" style="margin-right:5px;" title="" />';
  6664. $return .= '<a href="' . api_get_path(REL_CODE_PATH) . 'exercice/exercise_admin.php">' . get_lang('NewExercise') . '</a>';
  6665. $return .= '</div>';
  6666. $return .= '</div>';
  6667. return $return;
  6668. }
  6669. /**
  6670. * Creates a list with all the links in it
  6671. * @return string
  6672. */
  6673. public function get_links() {
  6674. $tbl_link = Database :: get_course_table(TABLE_LINK);
  6675. $session_id = api_get_session_id();
  6676. $condition_session = api_get_session_condition($session_id,false);
  6677. $sql_link = "SELECT * FROM $tbl_link $condition_session ORDER BY title ASC";
  6678. $res_link = Database::query($sql_link);
  6679. $return .= '<div class="lp_resource_header"' . " onclick=\"if(document.getElementById('resLink').style.display == 'block') {document.getElementById('resLink').style.display = 'none';} else {document.getElementById('resLink').style.display = 'block';}\"" . '><img alt="" src="../img/lp_' . TOOL_LINK . '.gif" style="margin-right:5px;" title="" />' . get_lang("Links") . '</div>';
  6680. $return .= '<div class="lp_resource_elements" id="resLink">';
  6681. while ($row_link = Database :: fetch_array($res_link)) {
  6682. $return .= '<div class="lp_resource_element">';
  6683. $return .= '<img alt="" src="../img/lp_link.gif" style="margin-right:5px;" title="" />';
  6684. $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>';
  6685. $return .= '</div>';
  6686. }
  6687. $return .= '<div class="lp_resource_element">';
  6688. $return .= '<img alt="" src="../img/linksnew.gif" style="margin-right:5px;width:16px" title="" />';
  6689. $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>';
  6690. $return .= '</div>';
  6691. if (Database :: num_rows($res_link) == 0)
  6692. $return .= '<div class="lp_resource_element">' . get_lang("NoLinksAvailable") . '</div>';
  6693. $return .= '</div>';
  6694. return $return;
  6695. }
  6696. /**
  6697. * Creates a list with all the student publications in it
  6698. * @return unknown
  6699. */
  6700. public function get_student_publications() {
  6701. $tbl_student = Database :: get_course_table(TABLE_STUDENT_PUBLICATION);
  6702. $session_id = api_get_session_id();
  6703. $condition_session = api_get_session_condition($session_id,false);
  6704. $sql_student = "SELECT * FROM $tbl_student $condition_session ORDER BY title ASC";
  6705. $res_student = Database::query($sql_student);
  6706. $return .= '<div class="lp_resource_header"' . " onclick=\"if(document.getElementById('resStudent').style.display == 'block') {document.getElementById('resStudent').style.display = 'none';} else {document.getElementById('resStudent').style.display = 'block';}\"" . '><img alt="" src="../img/lp_' . TOOL_STUDENTPUBLICATION . '.gif" style="margin-right:5px;" title="" />' . get_lang('Student_publication') . '</div>';
  6707. $return .= '<div class="lp_resource_elements" id="resStudent">';
  6708. $return .= '<div class="lp_resource_element">';
  6709. $return .= '<img align="left" alt="" src="../img/works_small.gif" style="margin-right:5px;" title="" />';
  6710. $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>';
  6711. $return .= '</div>';
  6712. $return .= '</div>';
  6713. return $return;
  6714. }
  6715. /**
  6716. * Creates a list with all the forums in it
  6717. * @return string
  6718. */
  6719. public function get_forums() {
  6720. include '../forum/forumfunction.inc.php';
  6721. include '../forum/forumconfig.inc.php';
  6722. global $table_forums, $table_threads, $table_posts, $table_item_property, $table_users;
  6723. $table_forums = Database :: get_course_table(TABLE_FORUM);
  6724. $table_threads = Database :: get_course_table(TABLE_FORUM_THREAD);
  6725. $table_posts = Database :: get_course_table(TABLE_FORUM_POST);
  6726. $table_item_property = Database :: get_course_table(TABLE_ITEM_PROPERTY);
  6727. $table_users = Database :: get_main_table(TABLE_MAIN_USER);
  6728. $a_forums = get_forums();
  6729. $return .= '<div class="lp_resource_header"' . " onclick=\"if(document.getElementById('forums').style.display == 'block') {document.getElementById('forums').style.display = 'none';} else {document.getElementById('forums').style.display = 'block';}\"" . '><img alt="" src="../img/lp_forum.gif" style="margin-right:5px;" title="" />' . get_lang('Forums') . '</div>';
  6730. $return .= '<div class="lp_resource_elements" style="border:1px solid #999999;" id="forums">';
  6731. foreach ($a_forums as $forum) {
  6732. $return .= '<div class="lp_resource_element">';
  6733. $return .= '<script type="text/javascript">
  6734. function toggle_forum(forum_id){
  6735. if(document.getElementById("forum_"+forum_id+"_content").style.display == "none"){
  6736. document.getElementById("forum_"+forum_id+"_content").style.display = "block";
  6737. document.getElementById("forum_"+forum_id+"_opener").src = "' . api_get_path(WEB_IMG_PATH) . 'remove.gif";
  6738. }
  6739. else {
  6740. document.getElementById("forum_"+forum_id+"_content").style.display = "none";
  6741. document.getElementById("forum_"+forum_id+"_opener").src = "' . api_get_path(WEB_IMG_PATH) . 'add.gif";
  6742. }
  6743. }
  6744. </script>
  6745. ';
  6746. if (!empty($forum['forum_id'])) {
  6747. $return .= '<img alt="" src="../img/lp_forum.gif" style="margin-right:5px;" title="" />';
  6748. $return .= '<a style="cursor:hand" onclick="toggle_forum(' . $forum['forum_id'] . ')" style="vertical-align:middle"><img src="' . api_get_path(WEB_IMG_PATH) . 'add.gif" id="forum_' . $forum['forum_id'] . '_opener" align="absbottom" /></a>
  6749. <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">';
  6750. }
  6751. $a_threads = get_threads($forum['forum_id']);
  6752. if (is_array($a_threads)) {
  6753. foreach ($a_threads as $thread) {
  6754. $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>';
  6755. }
  6756. }
  6757. $return .= '</ul></div>';
  6758. }
  6759. $return .= '<div class="lp_resource_element">';
  6760. $return .= '<img alt="" src="../img/forum_new_small.gif" style="margin-right:5px;" title="" />';
  6761. $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>';
  6762. $return .= '</div>';
  6763. return $return;
  6764. }
  6765. /**
  6766. * Exports the learning path as a SCORM package. This is the main function that
  6767. * gathers the content, transforms it, writes the imsmanifest.xml file, zips the
  6768. * whole thing and returns the zip.
  6769. *
  6770. * This method needs to be called in PHP5, as it will fail with non-adequate
  6771. * XML package (like the ones for PHP4), and it is *not* a static method, so
  6772. * you need to call it on a learnpath object.
  6773. * @TODO The method might be redefined later on in the scorm class itself to avoid
  6774. * creating a SCORM structure if there is one already. However, if the initial SCORM
  6775. * path has been modified, it should use the generic method here below.
  6776. * @TODO link this function with the export_lp() function in the same class
  6777. * @param string Optional name of zip file. If none, title of learnpath is
  6778. * domesticated and trailed with ".zip"
  6779. * @return string Returns the zip package string, or null if error
  6780. */
  6781. public function scorm_export()
  6782. {
  6783. global $_course;
  6784. global $charset;
  6785. if (!class_exists('DomDocument'))
  6786. {
  6787. error_log('DOM functions not supported for PHP version below 5.0',0);
  6788. $this->error = 'PHP DOM functions not supported for PHP versions below 5.0';
  6789. return null;
  6790. }
  6791. //remove memory and time limits as much as possible as this might be a long process...
  6792. if(function_exists('ini_set'))
  6793. {
  6794. $mem = ini_get('memory_limit');
  6795. if(substr($mem,-1,1)=='M')
  6796. {
  6797. $mem_num = substr($mem,0,-1);
  6798. if($mem_num<128)
  6799. {
  6800. ini_set('memory_limit','128M');
  6801. }
  6802. }
  6803. else
  6804. {
  6805. ini_set('memory_limit','128M');
  6806. }
  6807. ini_set('max_execution_time',600);
  6808. //}else{
  6809. //error_log('Scorm export: could not change memory and time limits',0);
  6810. }
  6811. //Create the zip handler (this will remain available throughout the method)
  6812. $archive_path = api_get_path(SYS_ARCHIVE_PATH);
  6813. $sys_course_path = api_get_path(SYS_COURSE_PATH);
  6814. $temp_dir_short = uniqid();
  6815. $temp_zip_dir = $archive_path."/".$temp_dir_short;
  6816. $temp_zip_file = $temp_zip_dir."/".md5(time()).".zip";
  6817. $zip_folder=new PclZip($temp_zip_file);
  6818. $current_course_path = api_get_path(SYS_COURSE_PATH).api_get_course_path();
  6819. $root_path = $main_path = api_get_path(SYS_PATH);
  6820. $files_cleanup = array();
  6821. //place to temporarily stash the zipfiles
  6822. //create the temp dir if it doesn't exist
  6823. //or do a cleanup befor creating the zipfile
  6824. if(!is_dir($temp_zip_dir))
  6825. {
  6826. mkdir($temp_zip_dir, api_get_permissions_for_new_directories());
  6827. }
  6828. else
  6829. {//cleanup: check the temp dir for old files and delete them
  6830. $handle=opendir($temp_zip_dir);
  6831. while (false!==($file = readdir($handle)))
  6832. {
  6833. if ($file != "." && $file != "..")
  6834. {
  6835. unlink("$temp_zip_dir/$file");
  6836. }
  6837. }
  6838. closedir($handle);
  6839. }
  6840. $zip_files = $zip_files_abs = $zip_files_dist = array();
  6841. if(is_dir($current_course_path.'/scorm/'.$this->path) && is_file($current_course_path.'/scorm/'.$this->path.'/imsmanifest.xml'))
  6842. {
  6843. // remove the possible . at the end of the path
  6844. $dest_path_to_lp = substr($this->path, -1) == '.' ? substr($this->path, 0, -1) : $this->path;
  6845. $dest_path_to_scorm_folder = str_replace('//','/',$temp_zip_dir.'/scorm/'.$dest_path_to_lp);
  6846. mkdir($dest_path_to_scorm_folder, api_get_permissions_for_new_directories(), true);
  6847. $zip_files_dist = copyr($current_course_path.'/scorm/'.$this->path, $dest_path_to_scorm_folder, array('imsmanifest'), $zip_files);
  6848. }
  6849. //Build a dummy imsmanifest structure. Do not add to the zip yet (we still need it)
  6850. //This structure is developed following regulations for SCORM 1.2 packaging in the SCORM 1.2 Content
  6851. //Aggregation Model official document, secion "2.3 Content Packaging"
  6852. $xmldoc = new DOMDocument('1.0',$this->encoding);
  6853. $root = $xmldoc->createElement('manifest');
  6854. $root->setAttribute('identifier','SingleCourseManifest');
  6855. $root->setAttribute('version','1.1');
  6856. $root->setAttribute('xmlns','http://www.imsproject.org/xsd/imscp_rootv1p1p2');
  6857. $root->setAttribute('xmlns:adlcp','http://www.adlnet.org/xsd/adlcp_rootv1p2');
  6858. $root->setAttribute('xmlns:xsi','http://www.w3.org/2001/XMLSchema-instance');
  6859. $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');
  6860. //Build mandatory sub-root container elements
  6861. $metadata = $xmldoc->createElement('metadata');
  6862. $md_schema = $xmldoc->createElement('schema','ADL SCORM');
  6863. $metadata->appendChild($md_schema);
  6864. $md_schemaversion = $xmldoc->createElement('schemaversion','1.2');
  6865. $metadata->appendChild($md_schemaversion);
  6866. $root->appendChild($metadata);
  6867. $organizations = $xmldoc->createElement('organizations');
  6868. $resources = $xmldoc->createElement('resources');
  6869. //Build the only organization we will use in building our learnpaths
  6870. $organizations->setAttribute('default','dokeos_scorm_export');
  6871. $organization = $xmldoc->createElement('organization');
  6872. $organization->setAttribute('identifier','dokeos_scorm_export');
  6873. //to set the title of the SCORM entity (=organization), we take the name given
  6874. //in Dokeos and convert it to HTML entities using the Dokeos charset (not the
  6875. //learning path charset) as it is the encoding that defines how it is stored
  6876. //in the database. Then we convert it to HTML entities again as the "&" character
  6877. //alone is not authorized in XML (must be &amp;)
  6878. //The title is then decoded twice when extracting (see scorm::parse_manifest)
  6879. $org_title = $xmldoc->createElement('title',htmlentities(api_htmlentities($this->get_name(),ENT_QUOTES,$charset)));
  6880. $organization->appendChild($org_title);
  6881. //For each element, add it to the imsmanifest structure, then add it to the zip.
  6882. //Always call the learnpathItem->scorm_export() method to change it to the SCORM
  6883. //format
  6884. $link_updates = array();
  6885. foreach($this->items as $index => $item){
  6886. if(!in_array($item->type , array(TOOL_QUIZ, TOOL_FORUM, TOOL_THREAD, TOOL_LINK, TOOL_STUDENTPUBLICATION)))
  6887. {
  6888. //get included documents from this item
  6889. if($item->type=='sco')
  6890. $inc_docs = $item->get_resources_from_source(null,api_get_path(SYS_COURSE_PATH).api_get_course_path().'/'.'scorm/'.$this->path.'/'.$item->get_path());
  6891. else
  6892. $inc_docs = $item->get_resources_from_source();
  6893. //give a child element <item> to the <organization> element
  6894. $my_item_id = $item->get_id();
  6895. $my_item = $xmldoc->createElement('item');
  6896. $my_item->setAttribute('identifier','ITEM_'.$my_item_id);
  6897. $my_item->setAttribute('identifierref','RESOURCE_'.$my_item_id);
  6898. $my_item->setAttribute('isvisible','true');
  6899. //give a child element <title> to the <item> element
  6900. $my_title = $xmldoc->createElement('title',htmlspecialchars($item->get_title(), ENT_QUOTES, $this->encoding));
  6901. $my_item->appendChild($my_title);
  6902. //give a child element <adlcp:prerequisites> to the <item> element
  6903. $my_prereqs = $xmldoc->createElement('adlcp:prerequisites',$this->get_scorm_prereq_string($my_item_id));
  6904. $my_prereqs->setAttribute('type','aicc_script');
  6905. $my_item->appendChild($my_prereqs);
  6906. //give a child element <adlcp:maxtimeallowed> to the <item> element - not yet supported
  6907. //$xmldoc->createElement('adlcp:maxtimeallowed','');
  6908. //give a child element <adlcp:timelimitaction> to the <item> element - not yet supported
  6909. //$xmldoc->createElement('adlcp:timelimitaction','');
  6910. //give a child element <adlcp:datafromlms> to the <item> element - not yet supported
  6911. //$xmldoc->createElement('adlcp:datafromlms','');
  6912. //give a child element <adlcp:masteryscore> to the <item> element
  6913. $my_masteryscore = $xmldoc->createElement('adlcp:masteryscore',$item->get_mastery_score());
  6914. $my_item->appendChild($my_masteryscore);
  6915. //attach this item to the organization element or hits parent if there is one
  6916. if(!empty($item->parent) && $item->parent!=0)
  6917. {
  6918. $children = $organization->childNodes;
  6919. $possible_parent = &$this->get_scorm_xml_node($children,'ITEM_'.$item->parent);
  6920. if(is_object($possible_parent))
  6921. {
  6922. $possible_parent->appendChild($my_item);
  6923. }
  6924. else
  6925. {
  6926. if($this->debug>0){error_log('Parent ITEM_'.$item->parent.' of item ITEM_'.$my_item_id.' not found');}
  6927. }
  6928. }
  6929. else
  6930. {
  6931. if($this->debug>0){error_log('No parent');}
  6932. $organization->appendChild($my_item);
  6933. }
  6934. //get the path of the file(s) from the course directory root
  6935. $my_file_path = $item->get_file_path('scorm/'.$this->path.'/');
  6936. $my_xml_file_path = api_htmlentities($my_file_path, ENT_QUOTES, $this->encoding);
  6937. $my_sub_dir = dirname($my_file_path);
  6938. $my_xml_sub_dir = api_htmlentities($my_sub_dir, ENT_QUOTES, $this->encoding);
  6939. //give a <resource> child to the <resources> element
  6940. $my_resource = $xmldoc->createElement('resource');
  6941. $my_resource->setAttribute('identifier','RESOURCE_'.$item->get_id());
  6942. $my_resource->setAttribute('type','webcontent');
  6943. $my_resource->setAttribute('href',$my_xml_file_path);
  6944. //adlcp:scormtype can be either 'sco' or 'asset'
  6945. if($item->type=='sco')
  6946. {
  6947. $my_resource->setAttribute('adlcp:scormtype','sco');
  6948. }
  6949. else
  6950. {
  6951. $my_resource->setAttribute('adlcp:scormtype','asset');
  6952. }
  6953. //xml:base is the base directory to find the files declared in this resource
  6954. $my_resource->setAttribute('xml:base','');
  6955. //give a <file> child to the <resource> element
  6956. $my_file = $xmldoc->createElement('file');
  6957. $my_file->setAttribute('href',$my_xml_file_path);
  6958. $my_resource->appendChild($my_file);
  6959. //dependency to other files - not yet supported
  6960. $i = 1;
  6961. foreach($inc_docs as $doc_info)
  6962. {
  6963. if(count($doc_info)<1 or empty($doc_info[0])){continue;}
  6964. $my_dep = $xmldoc->createElement('resource');
  6965. $res_id = 'RESOURCE_'.$item->get_id().'_'.$i;
  6966. $my_dep->setAttribute('identifier',$res_id);
  6967. $my_dep->setAttribute('type','webcontent');
  6968. $my_dep->setAttribute('adlcp:scormtype','asset');
  6969. $my_dep_file = $xmldoc->createElement('file');
  6970. //check type of URL
  6971. //error_log(__LINE__.'Now dealing with '.$doc_info[0].' of type '.$doc_info[1].'-'.$doc_info[2],0);
  6972. if($doc_info[1] == 'remote')
  6973. { //remote file. Save url as is
  6974. $my_dep_file->setAttribute('href',$doc_info[0]);
  6975. $my_dep->setAttribute('xml:base','');
  6976. }elseif($doc_info[1] == 'local'){
  6977. switch($doc_info[2])
  6978. {
  6979. case 'url': //local URL - save path as url for now, don't zip file
  6980. $abs_path = api_get_path(SYS_PATH).str_replace(api_get_path(WEB_PATH),'',$doc_info[0]);
  6981. $current_dir = dirname($abs_path);
  6982. $file_path = realpath($abs_path);
  6983. $my_dep_file->setAttribute('href',$file_path);
  6984. $my_dep->setAttribute('xml:base','');
  6985. if(strstr($file_path,$main_path) !== false)
  6986. {//the calculated real path is really inside the dokeos root path
  6987. //reduce file path to what's under the DocumentRoot
  6988. $file_path = substr($file_path,strlen($root_path)-1);
  6989. //echo $file_path;echo '<br><br>';
  6990. //error_log(__LINE__.'Reduced url path: '.$file_path,0);
  6991. $zip_files_abs[] = $file_path;
  6992. $link_updates[$my_file_path][] = array('orig'=>$doc_info[0],'dest'=>$file_path);
  6993. $my_dep_file->setAttribute('href',$file_path);
  6994. $my_dep->setAttribute('xml:base','');
  6995. }
  6996. else if (empty($file_path))
  6997. {
  6998. /*$document_root = substr(api_get_path(SYS_PATH), 0, strpos(api_get_path(SYS_PATH),api_get_path(REL_PATH)));
  6999. if(strpos($document_root,-1)=='/')
  7000. {
  7001. $document_root = substr(0, -1, $document_root);
  7002. }*/
  7003. $file_path = $_SERVER['DOCUMENT_ROOT'].$abs_path;
  7004. $file_path = str_replace('//','/',$file_path);
  7005. if(file_exists($file_path))
  7006. {
  7007. $file_path = substr($file_path,strlen($current_dir)); // we get the relative path
  7008. $zip_files[] = $my_sub_dir.'/'.$file_path;
  7009. $link_updates[$my_file_path][] = array('orig'=>$doc_info[0],'dest'=>$file_path);
  7010. $my_dep_file->setAttribute('href',$file_path);
  7011. $my_dep->setAttribute('xml:base','');
  7012. }
  7013. }
  7014. break;
  7015. case 'abs': //absolute path from DocumentRoot. Save file and leave path as is in the zip
  7016. $my_dep_file->setAttribute('href',$doc_info[0]);
  7017. $my_dep->setAttribute('xml:base','');
  7018. //$current_dir = dirname($current_course_path.'/'.$item->get_file_path()).'/';
  7019. //the next lines fix a bug when using the "subdir" mode of Dokeos, whereas
  7020. //an image path would be constructed as /var/www/subdir/subdir/img/foo.bar
  7021. $abs_img_path_without_subdir = $doc_info[0];
  7022. $relp = api_get_path(REL_PATH); //the url-append config param
  7023. $pos = strpos($abs_img_path_without_subdir,$relp);
  7024. if($pos===0)
  7025. {
  7026. $abs_img_path_without_subdir = '/'.substr($abs_img_path_without_subdir,strlen($relp));
  7027. }
  7028. //$file_path = realpath(api_get_path(SYS_PATH).$doc_info[0]);
  7029. $file_path = realpath(api_get_path(SYS_PATH).$abs_img_path_without_subdir);
  7030. $file_path = str_replace('\\','/',$file_path);
  7031. $file_path = str_replace('//','/',$file_path);
  7032. //error_log(__LINE__.'Abs path: '.$file_path,0);
  7033. //prepare the current directory path (until just under 'document') with a trailing slash
  7034. $cur_path = substr($current_course_path,-1)=='/'?$current_course_path:$current_course_path.'/';
  7035. //check if the current document is in that path
  7036. if(strstr($file_path,$cur_path) !== false)
  7037. {
  7038. //the document is in that path, now get the relative path
  7039. //to the containing document
  7040. $orig_file_path = dirname($cur_path.$my_file_path).'/';
  7041. $relative_path ='';
  7042. if(strstr($file_path,$cur_path)!==false)
  7043. {
  7044. $relative_path = substr($file_path,strlen($orig_file_path));
  7045. $file_path = substr($file_path,strlen($cur_path));
  7046. }
  7047. else
  7048. {
  7049. //this case is still a problem as it's difficult to calculate a relative path easily
  7050. //might still generate wrong links
  7051. //$file_path = substr($file_path,strlen($cur_path));
  7052. //calculate the directory path to the current file (without trailing slash)
  7053. $my_relative_path = dirname($file_path);
  7054. $my_relative_file = basename($file_path);
  7055. //calculate the directory path to the containing file (without trailing slash)
  7056. $my_orig_file_path = substr($orig_file_path,0,-1);
  7057. $dotdot = '';
  7058. $subdir = '';
  7059. while(strstr($my_relative_path,$my_orig_file_path)===false && (strlen($my_orig_file_path)>1) && (strlen($my_relative_path)>1))
  7060. {
  7061. $my_relative_path2 = dirname($my_relative_path);
  7062. $my_orig_file_path = dirname($my_orig_file_path);
  7063. $subdir = substr($my_relative_path,strlen($my_relative_path2)+1)."/".$subdir;
  7064. $dotdot += '../';
  7065. $my_relative_path = $my_relative_path2;
  7066. }
  7067. $relative_path = $dotdot.$subdir.$my_relative_file;
  7068. }
  7069. //put the current document in the zip (this array is the array
  7070. //that will manage documents already in the course folder - relative)
  7071. $zip_files[] = $file_path;
  7072. //update the links to the current document in the containing document (make them relative)
  7073. $link_updates[$my_file_path][] = array('orig'=>$doc_info[0],'dest'=>$relative_path);
  7074. $my_dep_file->setAttribute('href',$file_path);
  7075. $my_dep->setAttribute('xml:base','');
  7076. }
  7077. elseif(strstr($file_path,$main_path) !== false)
  7078. {//the calculated real path is really inside the dokeos root path
  7079. //reduce file path to what's under the DocumentRoot
  7080. $file_path = substr($file_path,strlen($root_path));
  7081. //echo $file_path;echo '<br><br>';
  7082. //error_log('Reduced path: '.$file_path,0);
  7083. $zip_files_abs[] = $file_path;
  7084. $link_updates[$my_file_path][] = array('orig'=>$doc_info[0],'dest'=>$file_path);
  7085. $my_dep_file->setAttribute('href','document/'.$file_path);
  7086. $my_dep->setAttribute('xml:base','');
  7087. }
  7088. else if (empty($file_path))
  7089. {
  7090. /*$document_root = substr(api_get_path(SYS_PATH), 0, strpos(api_get_path(SYS_PATH),api_get_path(REL_PATH)));
  7091. if(strpos($document_root,-1)=='/')
  7092. {
  7093. $document_root = substr(0, -1, $document_root);
  7094. }*/
  7095. $file_path = $_SERVER['DOCUMENT_ROOT'].$doc_info[0];
  7096. $file_path = str_replace('//','/',$file_path);
  7097. if(file_exists($file_path))
  7098. {
  7099. $file_path = substr($file_path,strlen($current_dir)); // we get the relative path
  7100. $zip_files[] = $my_sub_dir.'/'.$file_path;
  7101. $link_updates[$my_file_path][] = array('orig'=>$doc_info[0],'dest'=>$file_path);
  7102. $my_dep_file->setAttribute('href','document/'.$file_path);
  7103. $my_dep->setAttribute('xml:base','');
  7104. }
  7105. }
  7106. break;
  7107. 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
  7108. if(substr($doc_info[0],0,2)=='..')
  7109. { //relative path going up
  7110. $current_dir = dirname($current_course_path.'/'.$item->get_file_path()).'/';
  7111. $file_path = realpath($current_dir.$doc_info[0]);
  7112. //error_log($file_path.' <-> '.$main_path,0);
  7113. if(strstr($file_path,$main_path) !== false)
  7114. {//the calculated real path is really inside the dokeos root path
  7115. //reduce file path to what's under the DocumentRoot
  7116. $file_path = substr($file_path,strlen($root_path));
  7117. //error_log('Reduced path: '.$file_path,0);
  7118. $zip_files_abs[] = $file_path;
  7119. $link_updates[$my_file_path][] = array('orig'=>$doc_info[0],'dest'=>$file_path);
  7120. $my_dep_file->setAttribute('href','document/'.$file_path);
  7121. $my_dep->setAttribute('xml:base','');
  7122. }
  7123. }else{
  7124. $zip_files[] = $my_sub_dir.'/'.$doc_info[0];
  7125. $my_dep_file->setAttribute('href',$doc_info[0]);
  7126. $my_dep->setAttribute('xml:base',$my_xml_sub_dir);
  7127. }
  7128. break;
  7129. default:
  7130. $my_dep_file->setAttribute('href',$doc_info[0]);
  7131. $my_dep->setAttribute('xml:base','');
  7132. break;
  7133. }
  7134. }
  7135. $my_dep->appendChild($my_dep_file);
  7136. $resources->appendChild($my_dep);
  7137. $dependency = $xmldoc->createElement('dependency');
  7138. $dependency->setAttribute('identifierref',$res_id);
  7139. $my_resource->appendChild($dependency);
  7140. $i++;
  7141. }
  7142. //$my_dependency = $xmldoc->createElement('dependency');
  7143. //$my_dependency->setAttribute('identifierref','');
  7144. $resources->appendChild($my_resource);
  7145. $zip_files[] = $my_file_path;
  7146. //error_log('File '.$my_file_path. ' added to $zip_files',0);
  7147. }
  7148. else
  7149. { // if the item is a quiz or a link or whatever non-exportable, we include a step indicating it
  7150. if($item->type == TOOL_LINK)
  7151. {
  7152. $my_item = $xmldoc->createElement('item');
  7153. $my_item->setAttribute('identifier','ITEM_'.$item->get_id());
  7154. $my_item->setAttribute('identifierref','RESOURCE_'.$item->get_id());
  7155. $my_item->setAttribute('isvisible','true');
  7156. //give a child element <title> to the <item> element
  7157. $my_title = $xmldoc->createElement('title',htmlspecialchars($item->get_title(),ENT_QUOTES));
  7158. $my_item->appendChild($my_title);
  7159. //give a child element <adlcp:prerequisites> to the <item> element
  7160. $my_prereqs = $xmldoc->createElement('adlcp:prerequisites',$item->get_prereq_string());
  7161. $my_prereqs->setAttribute('type','aicc_script');
  7162. $my_item->appendChild($my_prereqs);
  7163. //give a child element <adlcp:maxtimeallowed> to the <item> element - not yet supported
  7164. //$xmldoc->createElement('adlcp:maxtimeallowed','');
  7165. //give a child element <adlcp:timelimitaction> to the <item> element - not yet supported
  7166. //$xmldoc->createElement('adlcp:timelimitaction','');
  7167. //give a child element <adlcp:datafromlms> to the <item> element - not yet supported
  7168. //$xmldoc->createElement('adlcp:datafromlms','');
  7169. //give a child element <adlcp:masteryscore> to the <item> element
  7170. $my_masteryscore = $xmldoc->createElement('adlcp:masteryscore',$item->get_mastery_score());
  7171. $my_item->appendChild($my_masteryscore);
  7172. //attach this item to the organization element or its parent if there is one
  7173. if(!empty($item->parent) && $item->parent!=0)
  7174. {
  7175. $children = $organization->childNodes;
  7176. for($i=0;$i<$children->length;$i++){
  7177. $item_temp = $children->item($i);
  7178. if ($item_temp -> nodeName == 'item')
  7179. {
  7180. if($item_temp->getAttribute('identifier') == 'ITEM_'.$item->parent)
  7181. {
  7182. $item_temp -> appendChild($my_item);
  7183. }
  7184. }
  7185. }
  7186. }
  7187. else
  7188. {
  7189. $organization->appendChild($my_item);
  7190. }
  7191. $my_file_path = 'link_'.$item->get_id().'.html';
  7192. $sql = 'SELECT url, title FROM '.Database :: get_course_table(TABLE_LINK).' WHERE id='.$item->path;
  7193. $rs = Database::query($sql);
  7194. if($link = Database :: fetch_array($rs))
  7195. {
  7196. $url = $link['url'];
  7197. $title = stripslashes($link['title']);
  7198. $links_to_create[$my_file_path] = array('title'=>$title,'url'=>$url);
  7199. $my_xml_file_path = api_htmlentities($my_file_path, ENT_QUOTES, $this->encoding);
  7200. $my_sub_dir = dirname($my_file_path);
  7201. $my_xml_sub_dir = api_htmlentities($my_sub_dir, ENT_QUOTES, $this->encoding);
  7202. //give a <resource> child to the <resources> element
  7203. $my_resource = $xmldoc->createElement('resource');
  7204. $my_resource->setAttribute('identifier','RESOURCE_'.$item->get_id());
  7205. $my_resource->setAttribute('type','webcontent');
  7206. $my_resource->setAttribute('href',$my_xml_file_path);
  7207. //adlcp:scormtype can be either 'sco' or 'asset'
  7208. $my_resource->setAttribute('adlcp:scormtype','asset');
  7209. //xml:base is the base directory to find the files declared in this resource
  7210. $my_resource->setAttribute('xml:base','');
  7211. //give a <file> child to the <resource> element
  7212. $my_file = $xmldoc->createElement('file');
  7213. $my_file->setAttribute('href',$my_xml_file_path);
  7214. $my_resource->appendChild($my_file);
  7215. $resources->appendChild($my_resource);
  7216. }
  7217. }
  7218. elseif($item->type == TOOL_QUIZ)
  7219. {
  7220. require_once api_get_path(SYS_CODE_PATH).'exercice/exercise.class.php';
  7221. $exe_id = $item->path; //should be using ref when everything will be cleaned up in this regard
  7222. $exe = new Exercise();
  7223. $exe->read($exe_id);
  7224. $my_item = $xmldoc->createElement('item');
  7225. $my_item->setAttribute('identifier','ITEM_'.$item->get_id());
  7226. $my_item->setAttribute('identifierref','RESOURCE_'.$item->get_id());
  7227. $my_item->setAttribute('isvisible','true');
  7228. //give a child element <title> to the <item> element
  7229. $my_title = $xmldoc->createElement('title',htmlspecialchars($item->get_title(), ENT_QUOTES, $this->encoding));
  7230. $my_item->appendChild($my_title);
  7231. $my_max_score = $xmldoc->createElement('max_score',$item->get_max());
  7232. //$my_item->appendChild($my_max_score);
  7233. //give a child element <adlcp:prerequisites> to the <item> element
  7234. $my_prereqs = $xmldoc->createElement('adlcp:prerequisites',$item->get_prereq_string());
  7235. $my_prereqs->setAttribute('type','aicc_script');
  7236. $my_item->appendChild($my_prereqs);
  7237. //give a child element <adlcp:masteryscore> to the <item> element
  7238. $my_masteryscore = $xmldoc->createElement('adlcp:masteryscore',$item->get_mastery_score());
  7239. $my_item->appendChild($my_masteryscore);
  7240. //attach this item to the organization element or hits parent if there is one
  7241. if(!empty($item->parent) && $item->parent!=0)
  7242. {
  7243. $children = $organization->childNodes;
  7244. for($i=0;$i<$children->length;$i++){
  7245. $item_temp = $children->item($i);
  7246. if ($item_temp -> nodeName == 'item')
  7247. {
  7248. if($item_temp->getAttribute('identifier') == 'ITEM_'.$item->parent)
  7249. {
  7250. $item_temp -> appendChild($my_item);
  7251. }
  7252. }
  7253. }
  7254. }
  7255. else
  7256. {
  7257. $organization->appendChild($my_item);
  7258. }
  7259. //include export scripts
  7260. require_once api_get_path(SYS_CODE_PATH).'exercice/export/scorm/scorm_export.php';
  7261. //get the path of the file(s) from the course directory root
  7262. //$my_file_path = $item->get_file_path('scorm/'.$this->path.'/');
  7263. $my_file_path = 'quiz_'.$item->get_id().'.html';
  7264. //write the contents of the exported exercise into a (big) html file
  7265. //to later pack it into the exported SCORM. The file will be removed afterwards
  7266. $contents = export_exercise($exe_id,true);
  7267. $tmp_file_path = $archive_path.$temp_dir_short.'/'.$my_file_path;
  7268. $res = file_put_contents($tmp_file_path,$contents);
  7269. if($res === false){error_log('Could not write into file '.$tmp_file_path.' '.__FILE__.' '.__LINE__,0);}
  7270. $files_cleanup[] = $tmp_file_path;
  7271. //error_log($tmp_path);die();
  7272. $my_xml_file_path = api_htmlentities($my_file_path, ENT_QUOTES, $this->encoding);
  7273. $my_sub_dir = dirname($my_file_path);
  7274. $my_xml_sub_dir = api_htmlentities($my_sub_dir, ENT_QUOTES, $this->encoding);
  7275. //give a <resource> child to the <resources> element
  7276. $my_resource = $xmldoc->createElement('resource');
  7277. $my_resource->setAttribute('identifier','RESOURCE_'.$item->get_id());
  7278. $my_resource->setAttribute('type','webcontent');
  7279. $my_resource->setAttribute('href',$my_xml_file_path);
  7280. //adlcp:scormtype can be either 'sco' or 'asset'
  7281. $my_resource->setAttribute('adlcp:scormtype','sco');
  7282. //xml:base is the base directory to find the files declared in this resource
  7283. $my_resource->setAttribute('xml:base','');
  7284. //give a <file> child to the <resource> element
  7285. $my_file = $xmldoc->createElement('file');
  7286. $my_file->setAttribute('href',$my_xml_file_path);
  7287. $my_resource->appendChild($my_file);
  7288. //get included docs
  7289. $inc_docs = $item->get_resources_from_source(null,$tmp_file_path);
  7290. //dependency to other files - not yet supported
  7291. $i = 1;
  7292. foreach($inc_docs as $doc_info)
  7293. {
  7294. if(count($doc_info)<1 or empty($doc_info[0])){continue;}
  7295. $my_dep = $xmldoc->createElement('resource');
  7296. $res_id = 'RESOURCE_'.$item->get_id().'_'.$i;
  7297. $my_dep->setAttribute('identifier',$res_id);
  7298. $my_dep->setAttribute('type','webcontent');
  7299. $my_dep->setAttribute('adlcp:scormtype','asset');
  7300. $my_dep_file = $xmldoc->createElement('file');
  7301. //check type of URL
  7302. //error_log(__LINE__.'Now dealing with '.$doc_info[0].' of type '.$doc_info[1].'-'.$doc_info[2],0);
  7303. if($doc_info[1] == 'remote')
  7304. { //remote file. Save url as is
  7305. $my_dep_file->setAttribute('href',$doc_info[0]);
  7306. $my_dep->setAttribute('xml:base','');
  7307. }elseif($doc_info[1] == 'local'){
  7308. switch($doc_info[2])
  7309. {
  7310. case 'url': //local URL - save path as url for now, don't zip file
  7311. //save file but as local file (retrieve from URL)
  7312. $abs_path = api_get_path(SYS_PATH).str_replace(api_get_path(WEB_PATH),'',$doc_info[0]);
  7313. $current_dir = dirname($abs_path);
  7314. $file_path = realpath($abs_path);
  7315. $my_dep_file->setAttribute('href','document/'.$file_path);
  7316. $my_dep->setAttribute('xml:base','');
  7317. if(strstr($file_path,$main_path) !== false)
  7318. {//the calculated real path is really inside the dokeos root path
  7319. //reduce file path to what's under the DocumentRoot
  7320. $file_path = substr($file_path,strlen($root_path));
  7321. //echo $file_path;echo '<br><br>';
  7322. //error_log('Reduced path: '.$file_path,0);
  7323. $zip_files_abs[] = $file_path;
  7324. $link_updates[$my_file_path][] = array('orig'=>$doc_info[0],'dest'=>'document/'.$file_path);
  7325. $my_dep_file->setAttribute('href','document/'.$file_path);
  7326. $my_dep->setAttribute('xml:base','');
  7327. }
  7328. else if (empty($file_path))
  7329. {
  7330. /*$document_root = substr(api_get_path(SYS_PATH), 0, strpos(api_get_path(SYS_PATH),api_get_path(REL_PATH)));
  7331. if(strpos($document_root,-1)=='/')
  7332. {
  7333. $document_root = substr(0, -1, $document_root);
  7334. }*/
  7335. $file_path = $_SERVER['DOCUMENT_ROOT'].$abs_path;
  7336. $file_path = str_replace('//','/',$file_path);
  7337. if(file_exists($file_path))
  7338. {
  7339. $file_path = substr($file_path,strlen($current_dir)); // we get the relative path
  7340. $zip_files[] = $my_sub_dir.'/'.$file_path;
  7341. $link_updates[$my_file_path][] = array('orig'=>$doc_info[0],'dest'=>'document/'.$file_path);
  7342. $my_dep_file->setAttribute('href','document/'.$file_path);
  7343. $my_dep->setAttribute('xml:base','');
  7344. }
  7345. }
  7346. break;
  7347. case 'abs': //absolute path from DocumentRoot. Save file and leave path as is in the zip
  7348. $current_dir = dirname($current_course_path.'/'.$item->get_file_path()).'/';
  7349. $file_path = realpath($doc_info[0]);
  7350. $my_dep_file->setAttribute('href',$file_path);
  7351. $my_dep->setAttribute('xml:base','');
  7352. if(strstr($file_path,$main_path) !== false)
  7353. {//the calculated real path is really inside the dokeos root path
  7354. //reduce file path to what's under the DocumentRoot
  7355. $file_path = substr($file_path,strlen($root_path));
  7356. //echo $file_path;echo '<br><br>';
  7357. //error_log('Reduced path: '.$file_path,0);
  7358. $zip_files_abs[] = $file_path;
  7359. $link_updates[$my_file_path][] = array('orig'=>$doc_info[0],'dest'=>$file_path);
  7360. $my_dep_file->setAttribute('href','document/'.$file_path);
  7361. $my_dep->setAttribute('xml:base','');
  7362. }
  7363. else if (empty($file_path))
  7364. {
  7365. /*$document_root = substr(api_get_path(SYS_PATH), 0, strpos(api_get_path(SYS_PATH),api_get_path(REL_PATH)));
  7366. if(strpos($document_root,-1)=='/')
  7367. {
  7368. $document_root = substr(0, -1, $document_root);
  7369. }*/
  7370. $file_path = $_SERVER['DOCUMENT_ROOT'].$doc_info[0];
  7371. $file_path = str_replace('//','/',$file_path);
  7372. if(file_exists($file_path))
  7373. {
  7374. $file_path = substr($file_path,strlen($current_dir)); // we get the relative path
  7375. $zip_files[] = $my_sub_dir.'/'.$file_path;
  7376. $link_updates[$my_file_path][] = array('orig'=>$doc_info[0],'dest'=>$file_path);
  7377. $my_dep_file->setAttribute('href','document/'.$file_path);
  7378. $my_dep->setAttribute('xml:base','');
  7379. }
  7380. }
  7381. break;
  7382. 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
  7383. if(substr($doc_info[0],0,2)=='..')
  7384. { //relative path going up
  7385. $current_dir = dirname($current_course_path.'/'.$item->get_file_path()).'/';
  7386. $file_path = realpath($current_dir.$doc_info[0]);
  7387. //error_log($file_path.' <-> '.$main_path,0);
  7388. if(strstr($file_path,$main_path) !== false)
  7389. {//the calculated real path is really inside the dokeos root path
  7390. //reduce file path to what's under the DocumentRoot
  7391. $file_path = substr($file_path,strlen($root_path));
  7392. $file_path_dest=$file_path;
  7393. //file path is courses/DOKEOS/document/....
  7394. $info_file_path=explode('/',$file_path);
  7395. if ($info_file_path[0]=='courses') {//add character "/" in file path
  7396. $file_path_dest='document/'.$file_path;
  7397. }
  7398. //error_log('Reduced path: '.$file_path,0);
  7399. $zip_files_abs[] = $file_path;
  7400. $link_updates[$my_file_path][] = array('orig'=>$doc_info[0],'dest'=>$file_path_dest);
  7401. $my_dep_file->setAttribute('href','document/'.$file_path);
  7402. $my_dep->setAttribute('xml:base','');
  7403. }
  7404. }else{
  7405. $zip_files[] = $my_sub_dir.'/'.$doc_info[0];
  7406. $my_dep_file->setAttribute('href',$doc_info[0]);
  7407. $my_dep->setAttribute('xml:base',$my_xml_sub_dir);
  7408. }
  7409. break;
  7410. default:
  7411. $my_dep_file->setAttribute('href',$doc_info[0]);// ../../courses/
  7412. $my_dep->setAttribute('xml:base','');
  7413. break;
  7414. }
  7415. }
  7416. $my_dep->appendChild($my_dep_file);
  7417. $resources->appendChild($my_dep);
  7418. $dependency = $xmldoc->createElement('dependency');
  7419. $dependency->setAttribute('identifierref',$res_id);
  7420. $my_resource->appendChild($dependency);
  7421. $i++;
  7422. }
  7423. $resources->appendChild($my_resource);
  7424. $zip_files[] = $my_file_path;
  7425. }
  7426. else
  7427. {
  7428. //get the path of the file(s) from the course directory root
  7429. $my_file_path = 'non_exportable.html';
  7430. $my_xml_file_path = api_htmlentities($my_file_path, ENT_COMPAT, $this->encoding);
  7431. $my_sub_dir = dirname($my_file_path);
  7432. $my_xml_sub_dir = api_htmlentities($my_sub_dir, ENT_COMPAT, $this->encoding);
  7433. //give a <resource> child to the <resources> element
  7434. $my_resource = $xmldoc->createElement('resource');
  7435. $my_resource->setAttribute('identifier','RESOURCE_'.$item->get_id());
  7436. $my_resource->setAttribute('type','webcontent');
  7437. $my_resource->setAttribute('href','document/'.$my_xml_file_path);
  7438. //adlcp:scormtype can be either 'sco' or 'asset'
  7439. $my_resource->setAttribute('adlcp:scormtype','asset');
  7440. //xml:base is the base directory to find the files declared in this resource
  7441. $my_resource->setAttribute('xml:base','');
  7442. //give a <file> child to the <resource> element
  7443. $my_file = $xmldoc->createElement('file');
  7444. $my_file->setAttribute('href','document/'.$my_xml_file_path);
  7445. $my_resource->appendChild($my_file);
  7446. $resources->appendChild($my_resource);
  7447. }
  7448. }
  7449. }
  7450. $organizations->appendChild($organization);
  7451. $root->appendChild($organizations);
  7452. $root->appendChild($resources);
  7453. $xmldoc->appendChild($root);
  7454. //todo: add a readme file here, with a short description and a link to the Reload player
  7455. //then add the file to the zip, then destroy the file (this is done automatically)
  7456. // http://www.reload.ac.uk/scormplayer.html - once done, don't forget to close FS#138
  7457. //error_log(print_r($zip_files,true),0);
  7458. foreach($zip_files as $file_path)
  7459. {
  7460. if(empty($file_path)){continue;}
  7461. //error_log(__LINE__.'getting document from '.$sys_course_path.$_course['path'].'/'.$file_path.' removing '.$sys_course_path.$_course['path'].'/',0);
  7462. $dest_file = $archive_path.$temp_dir_short.'/'.$file_path;
  7463. $this->create_path($dest_file);
  7464. //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);
  7465. //echo $main_path.$file_path.'<br>';
  7466. @copy($sys_course_path.$_course['path'].'/'.$file_path,$dest_file);
  7467. //check if the file needs a link update
  7468. if(in_array($file_path,array_keys($link_updates))){
  7469. $string = file_get_contents($dest_file);
  7470. unlink($dest_file);
  7471. foreach($link_updates[$file_path] as $old_new)
  7472. {
  7473. //error_log('Replacing '.$old_new['orig'].' by '.$old_new['dest'].' in '.$file_path,0);
  7474. //this is an ugly hack that allows .flv files to be found by the flv player that
  7475. // will be added in document/main/inc/lib/flv_player/flv_player.swf and that needs
  7476. // to find the flv to play in document/main/, so we replace main/ in the flv path by
  7477. // ../../.. to return from inc/lib/flv_player to the document/main path
  7478. if(substr($old_new['dest'],-3)=='flv' && substr($old_new['dest'],0,5)=='main/')
  7479. {
  7480. $old_new['dest'] = str_replace('main/','../../../',$old_new['dest']);
  7481. }
  7482. elseif(substr($old_new['dest'],-3)=='flv' && substr($old_new['dest'],0,6)=='video/')
  7483. {
  7484. $old_new['dest'] = str_replace('video/','../../../../video/',$old_new['dest']);
  7485. }
  7486. $string = str_replace($old_new['orig'],$old_new['dest'],$string);
  7487. }
  7488. file_put_contents($dest_file,$string);
  7489. }
  7490. }
  7491. foreach($zip_files_abs as $file_path)
  7492. {
  7493. if(empty($file_path)){continue;}
  7494. //error_log(__LINE__.'checking existence of '.$main_path.$file_path.'',0);
  7495. if(!is_file($main_path.$file_path) || !is_readable($main_path.$file_path)){continue;}
  7496. //error_log(__LINE__.'getting document from '.$main_path.$file_path.' removing '.api_get_path(SYS_COURSE_PATH).$_course['path'].'/',0);
  7497. $dest_file = $archive_path.$temp_dir_short.'/document/'.$file_path;
  7498. $this->create_path($dest_file);
  7499. //error_log('Created path '.api_get_path(SYS_ARCHIVE_PATH).$temp_dir_short.'/document/'.$file_path,0);
  7500. //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);
  7501. //echo $main_path.$file_path.' - '.$dest_file.'<br>';
  7502. copy($main_path.$file_path,$dest_file);
  7503. //check if the file needs a link update
  7504. if(in_array($file_path,array_keys($link_updates)))
  7505. {
  7506. $string = file_get_contents($dest_file);
  7507. unlink($dest_file);
  7508. foreach($link_updates[$file_path] as $old_new)
  7509. {
  7510. //error_log('Replacing '.$old_new['orig'].' by '.$old_new['dest'].' in '.$file_path,0);
  7511. //this is an ugly hack that allows .flv files to be found by the flv player that
  7512. // will be added in document/main/inc/lib/flv_player/flv_player.swf and that needs
  7513. // to find the flv to play in document/main/, so we replace main/ in the flv path by
  7514. // ../../.. to return from inc/lib/flv_player to the document/main path
  7515. if(substr($old_new['dest'],-3)=='flv' && substr($old_new['dest'],0,5)=='main/')
  7516. {
  7517. $old_new['dest'] = str_replace('main/','../../../',$old_new['dest']);
  7518. }
  7519. $string = str_replace($old_new['orig'],$old_new['dest'],$string);
  7520. }
  7521. file_put_contents($dest_file,$string);
  7522. }
  7523. }
  7524. if(is_array($links_to_create))
  7525. {
  7526. foreach($links_to_create as $file=>$link)
  7527. {
  7528. $file_content = '<html><body><div style="text-align:center"><a href="'.$link['url'].'">'.$link['title'].'</a></div></body></html>';
  7529. file_put_contents($archive_path.$temp_dir_short.'/'.$file, $file_content);
  7530. }
  7531. }
  7532. // add non exportable message explanation
  7533. $lang_not_exportable = get_lang('ThisItemIsNotExportable');
  7534. $file_content =
  7535. <<<EOD
  7536. <html>
  7537. <head>
  7538. <style>
  7539. .error-message {
  7540. font-family: arial, verdana, helvetica, sans-serif;
  7541. border-width: 1px;
  7542. border-style: solid;
  7543. left: 50%;
  7544. margin: 10px auto;
  7545. min-height: 30px;
  7546. padding: 5px;
  7547. right: 50%;
  7548. width: 500px;
  7549. background-color: #FFD1D1;
  7550. border-color: #FF0000;
  7551. color: #000;
  7552. }
  7553. </style>
  7554. <body>
  7555. <div class="error-message">
  7556. $lang_not_exportable
  7557. </div>
  7558. </body>
  7559. </html>
  7560. EOD;
  7561. if(!is_dir($archive_path.$temp_dir_short.'/document'))
  7562. {
  7563. @mkdir($archive_path.$temp_dir_short.'/document', api_get_permissions_for_new_directories());
  7564. }
  7565. file_put_contents($archive_path.$temp_dir_short.'/document/non_exportable.html', $file_content);
  7566. //Add the extra files that go along with a SCORM package
  7567. $main_code_path = api_get_path(SYS_CODE_PATH).'newscorm/packaging/';
  7568. $extra_files = scandir($main_code_path);
  7569. foreach ($extra_files as $extra_file) {
  7570. if (strpos($extra_file, '.') === 0)
  7571. continue;
  7572. else {
  7573. $dest_file = $archive_path . $temp_dir_short . '/' . $extra_file;
  7574. $this->create_path($dest_file);
  7575. copy($main_code_path.$extra_file,$dest_file);
  7576. }
  7577. }
  7578. //Finalize the imsmanifest structure, add to the zip, then return the zip
  7579. $xmldoc->save($archive_path.'/'.$temp_dir_short.'/imsmanifest.xml');
  7580. $zip_folder->add($archive_path.'/'.$temp_dir_short, PCLZIP_OPT_REMOVE_PATH, $archive_path.'/'.$temp_dir_short.'/');
  7581. //clean possible temporary files
  7582. foreach($files_cleanup as $file)
  7583. {
  7584. $res = unlink($file);
  7585. if($res === false){error_log('Could not delete temp file '.$file.' '.__FILE__.' '.__LINE__,0);}
  7586. }
  7587. //Send file to client
  7588. //$name = 'scorm_export_'.$this->lp_id.'.zip';
  7589. require_once api_get_path(LIBRARY_PATH).'fileUpload.lib.php';
  7590. $name = preg_replace('([^a-zA-Z0-9_\.])','-',html_entity_decode($this->get_name(),ENT_QUOTES)).'.zip';
  7591. DocumentManager::file_send_for_download($temp_zip_file,true,$name);
  7592. }
  7593. /**
  7594. * Temp function to be moved in main_api or the best place around for this. Creates a file path
  7595. * if it doesn't exist
  7596. */
  7597. public function create_path($path) {
  7598. $path_bits = split('/', dirname($path));
  7599. // IS_WINDOWS_OS has been defined in main_api.lib.php
  7600. $path_built = IS_WINDOWS_OS ? '' : '/';
  7601. foreach ($path_bits as $bit) {
  7602. if (!empty ($bit)) {
  7603. $new_path = $path_built . $bit;
  7604. if (is_dir($new_path)) {
  7605. $path_built = $new_path . '/';
  7606. } else {
  7607. mkdir($new_path, api_get_permissions_for_new_directories());
  7608. $path_built = $new_path . '/';
  7609. }
  7610. }
  7611. }
  7612. }
  7613. /**
  7614. * Delete the image relative to this learning path. No parameter. Only works on instanciated object.
  7615. * @return boolean The results of the unlink function, or false if there was no image to start with
  7616. */
  7617. public function delete_lp_image() {
  7618. $img = $this->get_preview_image();
  7619. if ($img != '') {
  7620. $del_file = api_get_path(SYS_COURSE_PATH) . api_get_course_path() . '/upload/learning_path/images/' . $img;
  7621. $this->set_preview_image('');
  7622. return @ unlink($del_file);
  7623. } else {
  7624. return false;
  7625. }
  7626. }
  7627. /**
  7628. * Uploads an author image to the upload/learning_path/images directory
  7629. * @param array The image array, coming from the $_FILES superglobal
  7630. * @return boolean True on success, false on error
  7631. */
  7632. public function upload_image($image_array) {
  7633. $image_moved = false;
  7634. if (!empty ($image_array['name'])) {
  7635. $upload_ok = process_uploaded_file($image_array);
  7636. $has_attachment = true;
  7637. } else {
  7638. $image_moved = true;
  7639. }
  7640. if ($upload_ok) {
  7641. if ($has_attachment) {
  7642. $courseDir = api_get_course_path() . '/upload/learning_path/images';
  7643. $sys_course_path = api_get_path(SYS_COURSE_PATH);
  7644. $updir = $sys_course_path . $courseDir;
  7645. // Try to add an extension to the file if it hasn't one
  7646. $new_file_name = add_ext_on_mime(stripslashes($image_array['name']), $image_array['type']);
  7647. if (!filter_extension($new_file_name)) {
  7648. //Display :: display_error_message(get_lang('UplUnableToSaveFileFilteredExtension'));
  7649. $image_moved = false;
  7650. } else {
  7651. $file_extension = explode('.', $image_array['name']);
  7652. $file_extension = strtolower($file_extension[sizeof($file_extension) - 1]);
  7653. $new_file_name = uniqid('') . '.' . $file_extension;
  7654. $new_path = $updir . '/' . $new_file_name;
  7655. //$result= @move_uploaded_file($image_array['tmp_name'], $new_path);
  7656. // resize the image
  7657. include_once api_get_path(LIBRARY_PATH).'image.lib.php';
  7658. $temp = new image($image_array['tmp_name']);
  7659. $picture_infos=@getimagesize($image_array['tmp_name']); // $picture_infos[0]-> width
  7660. if ($picture_infos[0] > 104) {
  7661. $thumbwidth = 104;
  7662. } else {
  7663. $thumbwidth = $picture_infos[0];
  7664. }
  7665. if ($picture_infos[1] > 96) {
  7666. $new_height = 96;
  7667. } else {
  7668. $new_height = $picture_infos[1];
  7669. }
  7670. //$new_height = round(($thumbwidth/$picture_infos[0])*$picture_infos[1]);
  7671. $temp->resize($thumbwidth,$new_height,0);
  7672. $type=$picture_infos[2];
  7673. $result=false;
  7674. switch ($type)
  7675. {
  7676. case 2 :
  7677. $result=$temp->send_image('JPG',$new_path);
  7678. break;
  7679. case 3 :
  7680. $result=$temp->send_image('PNG',$new_path);
  7681. break;
  7682. case 1 :
  7683. $result=$temp->send_image('GIF',$new_path);
  7684. break;
  7685. }
  7686. $temp->resize($thumbwidth, $new_height, 0);
  7687. $type = $picture_infos[2];
  7688. $result = false;
  7689. switch ($type) {
  7690. case 2 :
  7691. $result = $temp->send_image('JPG', $new_path);
  7692. break;
  7693. case 3 :
  7694. $result = $temp->send_image('PNG', $new_path);
  7695. break;
  7696. case 1 :
  7697. $result = $temp->send_image('GIF', $new_path);
  7698. break;
  7699. }
  7700. // Storing the image filename
  7701. if ($result) {
  7702. $image_moved = true;
  7703. $this->set_preview_image($new_file_name);
  7704. return true;
  7705. }
  7706. }
  7707. }
  7708. }
  7709. return false;
  7710. }
  7711. }
  7712. if (!function_exists('trim_value')) {
  7713. function trim_value(& $value) {
  7714. $value = trim($value);
  7715. }
  7716. }